2 // Copyright (C) 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #include "gnashconfig.h"
24 //#include <netinet/in.h>
26 #include <sys/types.h>
29 #include <sys/types.h>
36 #include "as_object.h"
44 #include "arg_parser.h"
45 #include "sshclient.h"
46 #include "sshserver.h"
49 using namespace gnash
;
52 static void usage (void);
54 static TestState runtest
;
58 static void test_client();
59 static void test_server();
60 static void test_channels();
61 static SSHClient client
;
64 LogFile
& dbglogfile
= LogFile::getDefaultInstance();
67 main(int argc
, char *argv
[])
69 bool servermode
= false;
71 const Arg_parser::Option opts
[] =
73 { 'h', "help", Arg_parser::no
},
74 { 'v', "verbose", Arg_parser::no
},
75 { 's', "hostname", Arg_parser::yes
},
76 { 'o', "port", Arg_parser::yes
},
77 { 'p', "password", Arg_parser::yes
},
78 { 'u', "user", Arg_parser::yes
},
79 { 'd', "dss", Arg_parser::no
},
80 { 'r', "rsa", Arg_parser::no
},
81 { 'f', "sftp", Arg_parser::no
},
82 { 'a', "raw", Arg_parser::no
},
83 { 'n', "netdebug", Arg_parser::no
},
84 { 'c', "daemon", Arg_parser::no
},
87 Arg_parser
parser(argc
, argv
, opts
);
88 if( ! parser
.error().empty() ) {
89 cout
<< parser
.error() << endl
;
93 for( int i
= 0; i
< parser
.arguments(); ++i
) {
94 const int code
= parser
.code(i
);
101 dbglogfile
.setVerbosity();
102 log_debug(_("Verbose output turned on"));
105 client
.setHostname(parser
.argument(i
));
106 log_debug(_("Hostname for SSH connection is: %s"),
107 client
.getHostname());
110 net
.setPort(parser
.argument
<short>(i
));
111 log_debug(_("Port for SSH connections is: %hd"),
115 client
.setPassword(parser
.argument(i
));
116 log_debug(_("SSH password is: %s"),
117 client
.getPassword());
120 client
.setUser(parser
.argument(i
));
121 log_debug(_("SSH user is: %s"),
125 client
.setAuthType(SSHClient::DSS
);
126 log_debug(_("SSH Authentication type is: %d"),
127 client
.getAuthType());
130 client
.setAuthType(SSHClient::RSA
);
131 log_debug(_("SSH Authentication type is: %d"),
132 client
.getAuthType());
135 client
.setTransportType(SSHClient::RAW
);
136 log_debug(_("SSH Transport type is: %d"),
137 client
.getTransportType());
140 client
.setTransportType(SSHClient::SFTP
);
141 log_debug(_("SSH Transport type is: %d"),
142 client
.getTransportType());
145 net
.toggleDebug(true);
149 log_debug(_("Enabling SSH server mode"));
152 infile
= parser
.argument(i
);
153 log_debug(_("Input file for testing the SSH connection is: %s"), infile
);
158 catch (Arg_parser::ArgParserException
&e
) {
159 cerr
<< _("Error parsing command line options: ") << e
.what() << endl
;
160 cerr
<< _("This is a Gnash bug.") << endl
;
174 static void test_client()
179 // Make a tcp/ip connect to the server
180 if (net
.createClient(client
.getHostname(), SSH_PORT
) == false) {
181 log_error("Can't connect to server %s", client
.getHostname());
184 if (client
.sshConnect(net
.getFileFd())) {
185 runtest
.pass("Connected to SSH server");
187 runtest
.fail("Couldn't connect to SSH server");
191 if (client
.openChannel()) {
192 runtest
.pass("Opened a new channel");
194 runtest
.fail("Couldn't open a new channel");
198 client
.closeChannel();
199 if (client
.getChannel() == 0) {
200 runtest
.pass("Closed the current channel");
202 runtest
.fail("Couldn't close the current channel");
207 runtest
.unresolved("Couldn't shutdown SSH connection");
209 if (client
.sshShutdown()) {
210 runtest
.pass("Shutdown SSH connection");
212 runtest
.fail("Couldn't shutdown SSH connection");
218 static void test_server()
226 static void test_channels()
234 cerr
<< "This program tests SSH support in the libnet library." << endl
;
235 cerr
<< "Usage: test_ssh [hvsocpkwar]" << endl
;
236 cerr
<< "-h\tHelp" << endl
;
237 cerr
<< "-v\tVerbose" << endl
;
238 cerr
<< "-s\thostname" << endl
;
239 cerr
<< "-o\tPort" << endl
;
240 cerr
<< "-p\tPassword" << endl
;
241 cerr
<< "-u\tUser" << endl
;
242 cerr
<< "-r\tUse RSA" << endl
;
243 cerr
<< "-d\tUse DSS" << endl
;
244 cerr
<< "-f\tUse SFTP for transport" << endl
;
245 cerr
<< "-a\tUse RAW for transport" << endl
;
246 cerr
<< "-n\tEnable network debug" << endl
<< endl
;
247 cerr
<< "-c\tEnable SSH Server" << endl
<< endl
;
249 cerr
<< "Libssh version is: " << ssh_version(0) << endl
;
256 main(int /*argc*/, char /* *argv[]*/)
259 cerr
<< "This program needs to have DejaGnu installed!" << endl
;