Mercurial > dropbear
comparison cli-session.c @ 1209:ab7d9c12caa7
Merge pull request #17 from annulen/kill_proxy_cmd
Client: kill proxy command when exiting application.
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Tue, 15 Dec 2015 21:40:32 +0800 |
parents | fb58cf341951 |
children | bf626d259eb1 |
comparison
equal
deleted
inserted
replaced
1207:81063d78fe69 | 1209:ab7d9c12caa7 |
---|---|
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 |
332 | 333 |
333 TRACE2(("leave cli_sessionloop: fell out")) | 334 TRACE2(("leave cli_sessionloop: fell out")) |
334 | 335 |
335 } | 336 } |
336 | 337 |
338 void kill_proxy_command(void) { | |
339 /* | |
340 * Send SIGHUP to proxy command if used. We don't wait() in | |
341 * case it hangs and instead rely on init to reap the child | |
342 */ | |
343 if (cli_ses.proxy_cmd_pid > 1) { | |
344 TRACE(("killing proxy command with PID='%d'", cli_ses.proxy_cmd_pid)); | |
345 kill(cli_ses.proxy_cmd_pid, SIGHUP); | |
346 } | |
347 } | |
348 | |
337 static void cli_session_cleanup(void) { | 349 static void cli_session_cleanup(void) { |
338 | 350 |
339 if (!sessinitdone) { | 351 if (!sessinitdone) { |
340 return; | 352 return; |
341 } | 353 } |
354 | |
355 kill_proxy_command(); | |
342 | 356 |
343 /* Set std{in,out,err} back to non-blocking - busybox ash dies nastily if | 357 /* Set std{in,out,err} back to non-blocking - busybox ash dies nastily if |
344 * we don't revert the flags */ | 358 * we don't revert the flags */ |
345 fcntl(cli_ses.stdincopy, F_SETFL, cli_ses.stdinflags); | 359 fcntl(cli_ses.stdincopy, F_SETFL, cli_ses.stdinflags); |
346 fcntl(cli_ses.stdoutcopy, F_SETFL, cli_ses.stdoutflags); | 360 fcntl(cli_ses.stdoutcopy, F_SETFL, cli_ses.stdoutflags); |