Mercurial > dropbear
comparison cli-main.c @ 33:f789045062e6
Progressing client support
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Tue, 27 Jul 2004 16:30:46 +0000 |
parents | 0969767bca0d |
children | b4874d772210 |
comparison
equal
deleted
inserted
replaced
32:8fd0cdbb5b1b | 33:f789045062e6 |
---|---|
1 #include <includes.h> | 1 #include "includes.h" |
2 #include "dbutil.h" | |
3 #include "runopts.h" | |
4 #include "session.h" | |
2 | 5 |
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 | |
3 int main(int argc, char ** argv) { | 13 int main(int argc, char ** argv) { |
14 #endif | |
4 | 15 |
5 int sock; | 16 int sock; |
6 char* error = NULL; | 17 char* error = NULL; |
7 char* hostandport; | 18 char* hostandport; |
8 int len; | 19 int len; |
9 | 20 |
10 _dropbear_exit = cli_dropbear_exit; | 21 _dropbear_exit = cli_dropbear_exit; |
11 _dropbear_log = cli_dropbear_log; | 22 _dropbear_log = cli_dropbear_log; |
12 | 23 |
13 cli_getopts(argc, argv); | 24 cli_getopts(argc, argv); |
25 | |
26 TRACE(("user='%s' host='%s' port='%s'", cli_opts.username, | |
27 cli_opts.remotehost, cli_opts.remoteport)); | |
14 | 28 |
15 sock = connect_remote(cli_opts.remotehost, cli_opts.remoteport, | 29 sock = connect_remote(cli_opts.remotehost, cli_opts.remoteport, |
16 0, &error); | 30 0, &error); |
17 | 31 |
18 if (sock < 0) { | 32 if (sock < 0) { |
21 | 35 |
22 /* Set up the host:port log */ | 36 /* Set up the host:port log */ |
23 len = strlen(cli_opts.remotehost); | 37 len = strlen(cli_opts.remotehost); |
24 len += 10; /* 16 bit port and leeway*/ | 38 len += 10; /* 16 bit port and leeway*/ |
25 hostandport = (char*)m_malloc(len); | 39 hostandport = (char*)m_malloc(len); |
26 snprintf(hostandport, len, "%s%d", | 40 snprintf(hostandport, len, "%s:%s", |
27 cli_opts.remotehost, cli_opts.remoteport); | 41 cli_opts.remotehost, cli_opts.remoteport); |
28 | 42 |
29 cli_session(sock, hostandport); | 43 cli_session(sock, hostandport); |
30 | 44 |
31 /* not reached */ | 45 /* not reached */ |
32 return -1; | 46 return -1; |
33 } | 47 } |
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 } |