comparison cli-main.c @ 641:2b1bb792cd4d dropbear-tfm

- Update tfm changes to current default tip
author Matt Johnston <matt@ucc.asn.au>
date Mon, 21 Nov 2011 19:52:28 +0800
parents 00eca37e47e8
children 70811267715c 7f604f9b3756
comparison
equal deleted inserted replaced
640:76097ec1a29a 641:2b1bb792cd4d
27 #include "includes.h" 27 #include "includes.h"
28 #include "dbutil.h" 28 #include "dbutil.h"
29 #include "runopts.h" 29 #include "runopts.h"
30 #include "session.h" 30 #include "session.h"
31 31
32 static void cli_dropbear_exit(int exitcode, const char* format, va_list param); 32 static void cli_dropbear_exit(int exitcode, const char* format, va_list param) ATTRIB_NORETURN;
33 static void cli_dropbear_log(int priority, const char* format, va_list param); 33 static void cli_dropbear_log(int priority, const char* format, va_list param);
34 34
35 #ifdef ENABLE_CLI_PROXYCMD
35 static void cli_proxy_cmd(int *sock_in, int *sock_out); 36 static void cli_proxy_cmd(int *sock_in, int *sock_out);
37 #endif
36 38
37 #if defined(DBMULTI_dbclient) || !defined(DROPBEAR_MULTI) 39 #if defined(DBMULTI_dbclient) || !defined(DROPBEAR_MULTI)
38 #if defined(DBMULTI_dbclient) && defined(DROPBEAR_MULTI) 40 #if defined(DBMULTI_dbclient) && defined(DROPBEAR_MULTI)
39 int cli_main(int argc, char ** argv) { 41 int cli_main(int argc, char ** argv) {
40 #else 42 #else
41 int main(int argc, char ** argv) { 43 int main(int argc, char ** argv) {
42 #endif 44 #endif
43 45
44 int sock_in, sock_out; 46 int sock_in, sock_out;
45 char* error = NULL; 47 char* error = NULL;
46 char* hostandport;
47 int len;
48 48
49 _dropbear_exit = cli_dropbear_exit; 49 _dropbear_exit = cli_dropbear_exit;
50 _dropbear_log = cli_dropbear_log; 50 _dropbear_log = cli_dropbear_log;
51 51
52 disallow_core(); 52 disallow_core();
61 } 61 }
62 62
63 #ifdef ENABLE_CLI_PROXYCMD 63 #ifdef ENABLE_CLI_PROXYCMD
64 if (cli_opts.proxycmd) { 64 if (cli_opts.proxycmd) {
65 cli_proxy_cmd(&sock_in, &sock_out); 65 cli_proxy_cmd(&sock_in, &sock_out);
66 m_free(cli_opts.proxycmd);
66 } else 67 } else
67 #endif 68 #endif
68 { 69 {
69 int sock = connect_remote(cli_opts.remotehost, cli_opts.remoteport, 70 int sock = connect_remote(cli_opts.remotehost, cli_opts.remoteport,
70 0, &error); 71 0, &error);
73 74
74 if (sock_in < 0) { 75 if (sock_in < 0) {
75 dropbear_exit("%s", error); 76 dropbear_exit("%s", error);
76 } 77 }
77 78
78 /* Set up the host:port log */ 79 cli_session(sock_in, sock_out);
79 len = strlen(cli_opts.remotehost);
80 len += 10; /* 16 bit port and leeway*/
81 hostandport = (char*)m_malloc(len);
82 snprintf(hostandport, len, "%s:%s",
83 cli_opts.remotehost, cli_opts.remoteport);
84
85 cli_session(sock_in, sock_out, hostandport);
86 80
87 /* not reached */ 81 /* not reached */
88 return -1; 82 return -1;
89 } 83 }
90 #endif /* DBMULTI stuff */ 84 #endif /* DBMULTI stuff */
92 static void cli_dropbear_exit(int exitcode, const char* format, va_list param) { 86 static void cli_dropbear_exit(int exitcode, const char* format, va_list param) {
93 87
94 char fmtbuf[300]; 88 char fmtbuf[300];
95 89
96 if (!sessinitdone) { 90 if (!sessinitdone) {
97 snprintf(fmtbuf, sizeof(fmtbuf), "exited: %s", 91 snprintf(fmtbuf, sizeof(fmtbuf), "Exited: %s",
98 format); 92 format);
99 } else { 93 } else {
100 snprintf(fmtbuf, sizeof(fmtbuf), 94 snprintf(fmtbuf, sizeof(fmtbuf),
101 "connection to %s@%s:%s exited: %s", 95 "Connection to %s@%s:%s exited: %s",
102 cli_opts.username, cli_opts.remotehost, 96 cli_opts.username, cli_opts.remotehost,
103 cli_opts.remoteport, format); 97 cli_opts.remoteport, format);
104 } 98 }
105 99
106 /* Do the cleanup first, since then the terminal will be reset */ 100 /* Do the cleanup first, since then the terminal will be reset */
130 usershell = m_strdup(get_user_shell()); 124 usershell = m_strdup(get_user_shell());
131 run_shell_command(cmd, ses.maxfd, usershell); 125 run_shell_command(cmd, ses.maxfd, usershell);
132 dropbear_exit("Failed to run '%s'\n", cmd); 126 dropbear_exit("Failed to run '%s'\n", cmd);
133 } 127 }
134 128
129 #ifdef ENABLE_CLI_PROXYCMD
135 static void cli_proxy_cmd(int *sock_in, int *sock_out) { 130 static void cli_proxy_cmd(int *sock_in, int *sock_out) {
136 int ret; 131 int ret;
137 132
138 fill_passwd(cli_opts.own_user); 133 fill_passwd(cli_opts.own_user);
139 134
142 if (ret == DROPBEAR_FAILURE) { 137 if (ret == DROPBEAR_FAILURE) {
143 dropbear_exit("Failed running proxy command"); 138 dropbear_exit("Failed running proxy command");
144 *sock_in = *sock_out = -1; 139 *sock_in = *sock_out = -1;
145 } 140 }
146 } 141 }
142 #endif // ENABLE_CLI_PROXYCMD