33
|
1 #include "includes.h" |
|
2 #include "dbutil.h" |
|
3 #include "runopts.h" |
|
4 #include "session.h" |
26
|
5 |
33
|
6 static void cli_dropbear_exit(int exitcode, const char* format, va_list param); |
|
7 static void cli_dropbear_log(int priority, const char* format, va_list param); |
|
8 |
|
9 #if defined(DBMULTI_dbclient) || !defined(DROPBEAR_MULTI) |
|
10 #if defined(DBMULTI_dbclient) && defined(DROPBEAR_MULTI) |
|
11 int cli_main(int argc, char ** argv) { |
|
12 #else |
26
|
13 int main(int argc, char ** argv) { |
33
|
14 #endif |
26
|
15 |
|
16 int sock; |
|
17 char* error = NULL; |
|
18 char* hostandport; |
|
19 int len; |
|
20 |
|
21 _dropbear_exit = cli_dropbear_exit; |
|
22 _dropbear_log = cli_dropbear_log; |
|
23 |
|
24 cli_getopts(argc, argv); |
|
25 |
33
|
26 TRACE(("user='%s' host='%s' port='%s'", cli_opts.username, |
|
27 cli_opts.remotehost, cli_opts.remoteport)); |
|
28 |
26
|
29 sock = connect_remote(cli_opts.remotehost, cli_opts.remoteport, |
|
30 0, &error); |
|
31 |
|
32 if (sock < 0) { |
|
33 dropbear_exit("%s", error); |
|
34 } |
|
35 |
|
36 /* Set up the host:port log */ |
|
37 len = strlen(cli_opts.remotehost); |
|
38 len += 10; /* 16 bit port and leeway*/ |
|
39 hostandport = (char*)m_malloc(len); |
33
|
40 snprintf(hostandport, len, "%s:%s", |
26
|
41 cli_opts.remotehost, cli_opts.remoteport); |
|
42 |
|
43 cli_session(sock, hostandport); |
|
44 |
|
45 /* not reached */ |
|
46 return -1; |
|
47 } |
33
|
48 #endif /* DBMULTI stuff */ |
|
49 |
|
50 static void cli_dropbear_exit(int exitcode, const char* format, va_list param) { |
|
51 |
|
52 char fmtbuf[300]; |
|
53 |
|
54 if (!sessinitdone) { |
|
55 snprintf(fmtbuf, sizeof(fmtbuf), "exited: %s", |
|
56 format); |
|
57 } else { |
|
58 snprintf(fmtbuf, sizeof(fmtbuf), |
|
59 "connection to %s@%s:%s exited: %s", |
|
60 cli_opts.username, cli_opts.remotehost, |
|
61 cli_opts.remoteport, format); |
|
62 } |
|
63 |
|
64 _dropbear_log(LOG_INFO, fmtbuf, param); |
|
65 |
|
66 common_session_cleanup(); |
|
67 exit(exitcode); |
|
68 } |
|
69 |
|
70 static void cli_dropbear_log(int priority, const char* format, va_list param) { |
|
71 |
|
72 char printbuf[1024]; |
|
73 |
|
74 vsnprintf(printbuf, sizeof(printbuf), format, param); |
|
75 |
|
76 fprintf(stderr, "Dropbear: %s\n", printbuf); |
|
77 |
|
78 } |