comparison cli-main.c @ 1741:d1b279aa5ed1 fuzz

Get client fuzzer building and starting (fails straight away)
author Matt Johnston <matt@ucc.asn.au>
date Sun, 18 Oct 2020 12:17:39 +0800
parents 789466c5956b
children f0a524208d97
comparison
equal deleted inserted replaced
1740:dfbe947bdf0d 1741:d1b279aa5ed1
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 */