comparison cli-session.c @ 399:a707e6148060

merge of '5fdf69ca60d1683cdd9f4c2595134bed26394834' and '6b61c50f4cf888bea302ac8fcf5dbb573b443251'
author Matt Johnston <matt@ucc.asn.au>
date Sat, 03 Feb 2007 08:20:34 +0000
parents d965110e3f5c
children c216212001fc
comparison
equal deleted inserted replaced
394:17d097fc111c 399:a707e6148060
74 NULL /* Null termination */ 74 NULL /* Null termination */
75 }; 75 };
76 76
77 void cli_session(int sock, char* remotehost) { 77 void cli_session(int sock, char* remotehost) {
78 78
79 seedrandom();
80
79 crypto_init(); 81 crypto_init();
82
80 common_session_init(sock, remotehost); 83 common_session_init(sock, remotehost);
81 84
82 chaninitialise(cli_chantypes); 85 chaninitialise(cli_chantypes);
83
84 86
85 /* Set up cli_ses vars */ 87 /* Set up cli_ses vars */
86 cli_session_init(); 88 cli_session_init();
87 89
88 /* Ready to go */ 90 /* Ready to go */
89 sessinitdone = 1; 91 sessinitdone = 1;
90 92
91 /* Exchange identification */ 93 /* Exchange identification */
92 session_identification(); 94 session_identification();
93 95
94 seedrandom();
95
96 send_msg_kexinit(); 96 send_msg_kexinit();
97
98 /* XXX here we do stuff differently */
99 97
100 session_loop(cli_sessionloop); 98 session_loop(cli_sessionloop);
101 99
102 /* Not reached */ 100 /* Not reached */
103 101
212 cli_ses.state = SESSION_RUNNING; 210 cli_ses.state = SESSION_RUNNING;
213 return; 211 return;
214 */ 212 */
215 213
216 case USERAUTH_SUCCESS_RCVD: 214 case USERAUTH_SUCCESS_RCVD:
215
216 if (cli_opts.backgrounded) {
217 int devnull;
218 // keeping stdin open steals input from the terminal and
219 // is confusing, though stdout/stderr could be useful.
220 devnull = open(_PATH_DEVNULL, O_RDONLY);
221 if (devnull < 0) {
222 dropbear_exit("opening /dev/null: %d %s",
223 errno, strerror(errno));
224 }
225 dup2(devnull, STDIN_FILENO);
226 if (daemon(0, 1) < 0) {
227 dropbear_exit("Backgrounding failed: %d %s",
228 errno, strerror(errno));
229 }
230 }
231
217 #ifdef ENABLE_CLI_LOCALTCPFWD 232 #ifdef ENABLE_CLI_LOCALTCPFWD
218 setup_localtcp(); 233 setup_localtcp();
219 #endif 234 #endif
220 #ifdef ENABLE_CLI_REMOTETCPFWD 235 #ifdef ENABLE_CLI_REMOTETCPFWD
221 setup_remotetcp(); 236 setup_remotetcp();
222 #endif 237 #endif
223 cli_send_chansess_request(); 238 if (!cli_opts.no_cmd) {
224 TRACE(("leave cli_sessionloop: cli_send_chansess_request")) 239 cli_send_chansess_request();
240 }
241 TRACE(("leave cli_sessionloop: running"))
225 cli_ses.state = SESSION_RUNNING; 242 cli_ses.state = SESSION_RUNNING;
226 return; 243 return;
227 244
228 case SESSION_RUNNING: 245 case SESSION_RUNNING:
229 if (ses.chancount < 1) { 246 if (ses.chancount < 1 && !cli_opts.no_cmd) {
230 cli_finished(); 247 cli_finished();
231 } 248 }
232 249
233 if (cli_ses.winchange) { 250 if (cli_ses.winchange) {
234 cli_chansess_winchange(); 251 cli_chansess_winchange();