comparison cli-main.c @ 1745:a6824c54962a

Merge fuzz branch
author Matt Johnston <matt@ucc.asn.au>
date Sun, 18 Oct 2020 22:53:44 +0800
parents d1b279aa5ed1
children f0a524208d97
comparison
equal deleted inserted replaced
1738:4f13df974cf4 1745:a6824c54962a
29 #include "runopts.h" 29 #include "runopts.h"
30 #include "session.h" 30 #include "session.h"
31 #include "dbrandom.h" 31 #include "dbrandom.h"
32 #include "crypto_desc.h" 32 #include "crypto_desc.h"
33 #include "netio.h" 33 #include "netio.h"
34 34 #include "fuzz.h"
35 static void cli_dropbear_exit(int exitcode, const char* format, va_list param) ATTRIB_NORETURN;
36 static void cli_dropbear_log(int priority, const char* format, va_list param);
37 35
38 #if DROPBEAR_CLI_PROXYCMD 36 #if DROPBEAR_CLI_PROXYCMD
39 static void cli_proxy_cmd(int *sock_in, int *sock_out, pid_t *pid_out); 37 static void cli_proxy_cmd(int *sock_in, int *sock_out, pid_t *pid_out);
40 static void kill_proxy_sighandler(int signo); 38 static void kill_proxy_sighandler(int signo);
41 #endif 39 #endif
96 /* not reached */ 94 /* not reached */
97 return -1; 95 return -1;
98 } 96 }
99 #endif /* DBMULTI stuff */ 97 #endif /* DBMULTI stuff */
100 98
101 static void cli_dropbear_exit(int exitcode, const char* format, va_list param) {
102 char exitmsg[150];
103 char fullmsg[300];
104
105 /* Note that exit message must be rendered before session cleanup */
106
107 /* Render the formatted exit message */
108 vsnprintf(exitmsg, sizeof(exitmsg), format, param);
109 TRACE(("Exited, cleaning up: %s", exitmsg))
110
111 /* Add the prefix depending on session/auth state */
112 if (!ses.init_done) {
113 snprintf(fullmsg, sizeof(fullmsg), "Exited: %s", exitmsg);
114 } else {
115 snprintf(fullmsg, sizeof(fullmsg),
116 "Connection to %s@%s:%s exited: %s",
117 cli_opts.username, cli_opts.remotehost,
118 cli_opts.remoteport, exitmsg);
119 }
120
121 /* Do the cleanup first, since then the terminal will be reset */
122 session_cleanup();
123 /* Avoid printing onwards from terminal cruft */
124 fprintf(stderr, "\n");
125
126 dropbear_log(LOG_INFO, "%s", fullmsg);
127 exit(exitcode);
128 }
129
130 static void cli_dropbear_log(int priority,
131 const char* format, va_list param) {
132
133 char printbuf[1024];
134 const char *name;
135
136 name = cli_opts.progname;
137 if (!name) {
138 name = "dbclient";
139 }
140
141 vsnprintf(printbuf, sizeof(printbuf), format, param);
142
143 #ifndef DISABLE_SYSLOG
144 if (opts.usingsyslog) {
145 syslog(priority, "%s", printbuf);
146 }
147 #endif
148
149 fprintf(stderr, "%s: %s\n", name, printbuf);
150 fflush(stderr);
151 }
152
153 static void exec_proxy_cmd(const void *user_data_cmd) { 99 static void exec_proxy_cmd(const void *user_data_cmd) {
154 const char *cmd = user_data_cmd; 100 const char *cmd = user_data_cmd;
155 char *usershell; 101 char *usershell;
156 102
157 usershell = m_strdup(get_user_shell()); 103 usershell = m_strdup(get_user_shell());
197 143
198 static void kill_proxy_sighandler(int UNUSED(signo)) { 144 static void kill_proxy_sighandler(int UNUSED(signo)) {
199 kill_proxy_command(); 145 kill_proxy_command();
200 _exit(1); 146 _exit(1);
201 } 147 }
148
202 #endif /* DROPBEAR_CLI_PROXYCMD */ 149 #endif /* DROPBEAR_CLI_PROXYCMD */