comparison cli-session.c @ 1219:84cf9062718d coverity

merge
author Matt Johnston <matt@ucc.asn.au>
date Tue, 15 Dec 2015 22:24:34 +0800
parents bf626d259eb1
children 854f39ff5105 9169e4e7cbee
comparison
equal deleted inserted replaced
1196:a29559086628 1219:84cf9062718d
39 #include "crypto_desc.h" 39 #include "crypto_desc.h"
40 #include "netio.h" 40 #include "netio.h"
41 41
42 static void cli_remoteclosed() ATTRIB_NORETURN; 42 static void cli_remoteclosed() ATTRIB_NORETURN;
43 static void cli_sessionloop(); 43 static void cli_sessionloop();
44 static void cli_session_init(); 44 static void cli_session_init(pid_t proxy_cmd_pid);
45 static void cli_finished() ATTRIB_NORETURN; 45 static void cli_finished() ATTRIB_NORETURN;
46 static void recv_msg_service_accept(void); 46 static void recv_msg_service_accept(void);
47 static void cli_session_cleanup(void); 47 static void cli_session_cleanup(void);
48 static void recv_msg_global_request_cli(void); 48 static void recv_msg_global_request_cli(void);
49 49
102 } 102 }
103 myses->sock_in = myses->sock_out = sock; 103 myses->sock_in = myses->sock_out = sock;
104 update_channel_prio(); 104 update_channel_prio();
105 } 105 }
106 106
107 void cli_session(int sock_in, int sock_out, struct dropbear_progress_connection *progress) { 107 void cli_session(int sock_in, int sock_out, struct dropbear_progress_connection *progress, pid_t proxy_cmd_pid) {
108 108
109 common_session_init(sock_in, sock_out); 109 common_session_init(sock_in, sock_out);
110 110
111 if (progress) { 111 if (progress) {
112 connect_set_writequeue(progress, &ses.writequeue); 112 connect_set_writequeue(progress, &ses.writequeue);
113 } 113 }
114 114
115 chaninitialise(cli_chantypes); 115 chaninitialise(cli_chantypes);
116 116
117 /* Set up cli_ses vars */ 117 /* Set up cli_ses vars */
118 cli_session_init(); 118 cli_session_init(proxy_cmd_pid);
119
120 119
121 /* Ready to go */ 120 /* Ready to go */
122 sessinitdone = 1; 121 sessinitdone = 1;
123 122
124 /* Exchange identification */ 123 /* Exchange identification */
138 static void cli_send_kex_first_guess() { 137 static void cli_send_kex_first_guess() {
139 send_msg_kexdh_init(); 138 send_msg_kexdh_init();
140 } 139 }
141 #endif 140 #endif
142 141
143 static void cli_session_init() { 142 static void cli_session_init(pid_t proxy_cmd_pid) {
144 143
145 cli_ses.state = STATE_NOTHING; 144 cli_ses.state = STATE_NOTHING;
146 cli_ses.kex_state = KEX_NOTHING; 145 cli_ses.kex_state = KEX_NOTHING;
147 146
148 cli_ses.tty_raw_mode = 0; 147 cli_ses.tty_raw_mode = 0;
157 cli_ses.stderrcopy = dup(STDERR_FILENO); 156 cli_ses.stderrcopy = dup(STDERR_FILENO);
158 cli_ses.stderrflags = fcntl(STDERR_FILENO, F_GETFL, 0); 157 cli_ses.stderrflags = fcntl(STDERR_FILENO, F_GETFL, 0);
159 158
160 cli_ses.retval = EXIT_SUCCESS; /* Assume it's clean if we don't get a 159 cli_ses.retval = EXIT_SUCCESS; /* Assume it's clean if we don't get a
161 specific exit status */ 160 specific exit status */
161 cli_ses.proxy_cmd_pid = proxy_cmd_pid;
162 TRACE(("proxy command PID='%d'", proxy_cmd_pid));
162 163
163 /* Auth */ 164 /* Auth */
164 cli_ses.lastprivkey = NULL; 165 cli_ses.lastprivkey = NULL;
165 cli_ses.lastauthtype = 0; 166 cli_ses.lastauthtype = 0;
166 167
266 cli_ses.state = USERAUTH_REQ_SENT; 267 cli_ses.state = USERAUTH_REQ_SENT;
267 TRACE(("leave cli_sessionloop: cli_auth_try")) 268 TRACE(("leave cli_sessionloop: cli_auth_try"))
268 return; 269 return;
269 270
270 case USERAUTH_SUCCESS_RCVD: 271 case USERAUTH_SUCCESS_RCVD:
272 #ifndef DISABLE_SYSLOG
273 if (opts.usingsyslog) {
274 dropbear_log(LOG_INFO, "Authentication succeeded.");
275 }
276 #endif
271 277
272 #ifdef DROPBEAR_NONE_CIPHER 278 #ifdef DROPBEAR_NONE_CIPHER
273 if (cli_ses.cipher_none_after_auth) 279 if (cli_ses.cipher_none_after_auth)
274 { 280 {
275 set_algo_usable(sshciphers, "none", 1); 281 set_algo_usable(sshciphers, "none", 1);
332 338
333 TRACE2(("leave cli_sessionloop: fell out")) 339 TRACE2(("leave cli_sessionloop: fell out"))
334 340
335 } 341 }
336 342
343 void kill_proxy_command(void) {
344 /*
345 * Send SIGHUP to proxy command if used. We don't wait() in
346 * case it hangs and instead rely on init to reap the child
347 */
348 if (cli_ses.proxy_cmd_pid > 1) {
349 TRACE(("killing proxy command with PID='%d'", cli_ses.proxy_cmd_pid));
350 kill(cli_ses.proxy_cmd_pid, SIGHUP);
351 }
352 }
353
337 static void cli_session_cleanup(void) { 354 static void cli_session_cleanup(void) {
338 355
339 if (!sessinitdone) { 356 if (!sessinitdone) {
340 return; 357 return;
341 } 358 }
359
360 kill_proxy_command();
342 361
343 /* Set std{in,out,err} back to non-blocking - busybox ash dies nastily if 362 /* Set std{in,out,err} back to non-blocking - busybox ash dies nastily if
344 * we don't revert the flags */ 363 * we don't revert the flags */
345 fcntl(cli_ses.stdincopy, F_SETFL, cli_ses.stdinflags); 364 fcntl(cli_ses.stdincopy, F_SETFL, cli_ses.stdinflags);
346 fcntl(cli_ses.stdoutcopy, F_SETFL, cli_ses.stdoutflags); 365 fcntl(cli_ses.stdoutcopy, F_SETFL, cli_ses.stdoutflags);