|
Lines 119-124
int no_shell_flag = 0;
Link Here
|
| 119 |
int stdin_null_flag = 0; |
119 |
int stdin_null_flag = 0; |
| 120 |
|
120 |
|
| 121 |
/* |
121 |
/* |
|
|
122 |
* Flag indicating that the current process should be backgrounded and |
| 123 |
* a new slave launched in the foreground for ControlPersist. |
| 124 |
*/ |
| 125 |
int need_controlpersist_detach = 0; |
| 126 |
|
| 127 |
/* Copies of flags for ControlPersist foreground slave */ |
| 128 |
int ostdin_null_flag, ono_shell_flag, ono_tty_flag, otty_flag; |
| 129 |
|
| 130 |
/* |
| 122 |
* Flag indicating that ssh should fork after authentication. This is useful |
131 |
* Flag indicating that ssh should fork after authentication. This is useful |
| 123 |
* so that the passphrase can be entered manually, and then ssh goes to the |
132 |
* so that the passphrase can be entered manually, and then ssh goes to the |
| 124 |
* background. |
133 |
* background. |
|
Lines 719-724
main(int ac, char **av)
Link Here
|
| 719 |
fatal("No ControlPath specified for \"-O\" command"); |
728 |
fatal("No ControlPath specified for \"-O\" command"); |
| 720 |
if (options.control_path != NULL) |
729 |
if (options.control_path != NULL) |
| 721 |
muxclient(options.control_path); |
730 |
muxclient(options.control_path); |
|
|
731 |
/* If muxclient() can connect to a master socket, |
| 732 |
* then it doesn't return. */ |
| 722 |
|
733 |
|
| 723 |
timeout_ms = options.connection_timeout * 1000; |
734 |
timeout_ms = options.connection_timeout * 1000; |
| 724 |
|
735 |
|
|
Lines 858-863
main(int ac, char **av)
Link Here
|
| 858 |
return exit_status; |
869 |
return exit_status; |
| 859 |
} |
870 |
} |
| 860 |
|
871 |
|
|
|
872 |
static void |
| 873 |
control_persist_detach(void) |
| 874 |
{ |
| 875 |
pid_t pid; |
| 876 |
|
| 877 |
debug("%s: backgrounding master process", __func__); |
| 878 |
|
| 879 |
/* |
| 880 |
* master (current process) into the background, and make the |
| 881 |
* foreground process a client of the backgrounded master. |
| 882 |
*/ |
| 883 |
switch ((pid = fork())) { |
| 884 |
case -1: |
| 885 |
fatal("%s: fork: %s", __func__, strerror(errno)); |
| 886 |
case 0: |
| 887 |
/* Child: master process continues mainloop */ |
| 888 |
break; |
| 889 |
default: |
| 890 |
/* Parent: set up mux slave to connect to backgrounded master */ |
| 891 |
debug2("%s: background process is %ld", __func__, (long)pid); |
| 892 |
stdin_null_flag = ostdin_null_flag; |
| 893 |
no_shell_flag = ono_shell_flag; |
| 894 |
no_tty_flag = ono_tty_flag; |
| 895 |
tty_flag = otty_flag; |
| 896 |
close(muxserver_sock); |
| 897 |
muxserver_sock = -1; |
| 898 |
muxclient(options.control_path); |
| 899 |
/* muxclient() doesn't return on success. */ |
| 900 |
fatal("Failed to connect to new control master"); |
| 901 |
} |
| 902 |
} |
| 903 |
|
| 904 |
/* Do fork() after authentication. Used by "ssh -f" */ |
| 905 |
static void |
| 906 |
fork_postauth(void) |
| 907 |
{ |
| 908 |
if (need_controlpersist_detach) |
| 909 |
control_persist_detach(); |
| 910 |
debug("forking to background"); |
| 911 |
fork_after_authentication_flag = 0; |
| 912 |
if (daemon(1, 1) < 0) |
| 913 |
fatal("daemon() failed: %.200s", strerror(errno)); |
| 914 |
} |
| 915 |
|
| 861 |
/* Callback for remote forward global requests */ |
916 |
/* Callback for remote forward global requests */ |
| 862 |
static void |
917 |
static void |
| 863 |
ssh_confirm_remote_forward(int type, u_int32_t seq, void *ctxt) |
918 |
ssh_confirm_remote_forward(int type, u_int32_t seq, void *ctxt) |
|
Lines 885-896
ssh_confirm_remote_forward(int type, u_i
Link Here
|
| 885 |
} |
940 |
} |
| 886 |
if (++remote_forward_confirms_received == options.num_remote_forwards) { |
941 |
if (++remote_forward_confirms_received == options.num_remote_forwards) { |
| 887 |
debug("All remote forwarding requests processed"); |
942 |
debug("All remote forwarding requests processed"); |
| 888 |
if (fork_after_authentication_flag) { |
943 |
if (fork_after_authentication_flag) |
| 889 |
fork_after_authentication_flag = 0; |
944 |
fork_postauth(); |
| 890 |
if (daemon(1, 1) < 0) |
|
|
| 891 |
fatal("daemon() failed: %.200s", |
| 892 |
strerror(errno)); |
| 893 |
} |
| 894 |
} |
945 |
} |
| 895 |
} |
946 |
} |
| 896 |
|
947 |
|
|
Lines 1134-1145
ssh_session(void)
Link Here
|
| 1134 |
* If requested and we are not interested in replies to remote |
1185 |
* If requested and we are not interested in replies to remote |
| 1135 |
* forwarding requests, then let ssh continue in the background. |
1186 |
* forwarding requests, then let ssh continue in the background. |
| 1136 |
*/ |
1187 |
*/ |
| 1137 |
if (fork_after_authentication_flag && |
1188 |
if (fork_after_authentication_flag) { |
| 1138 |
(!options.exit_on_forward_failure || |
1189 |
if (options.exit_on_forward_failure && |
| 1139 |
options.num_remote_forwards == 0)) { |
1190 |
options.num_remote_forwards > 0) { |
| 1140 |
fork_after_authentication_flag = 0; |
1191 |
debug("deferring postauth fork until remote forward " |
| 1141 |
if (daemon(1, 1) < 0) |
1192 |
"confirmation received"); |
| 1142 |
fatal("daemon() failed: %.200s", strerror(errno)); |
1193 |
} else |
|
|
1194 |
fork_postauth(); |
| 1143 |
} |
1195 |
} |
| 1144 |
|
1196 |
|
| 1145 |
/* |
1197 |
/* |
|
Lines 1262-1267
ssh_session2(void)
Link Here
|
| 1262 |
/* XXX should be pre-session */ |
1314 |
/* XXX should be pre-session */ |
| 1263 |
ssh_init_forwarding(); |
1315 |
ssh_init_forwarding(); |
| 1264 |
|
1316 |
|
|
|
1317 |
/* Start listening for multiplex clients */ |
| 1318 |
muxserver_listen(); |
| 1319 |
|
| 1320 |
/* |
| 1321 |
* If we are in control persist mode, then prepare to background |
| 1322 |
* ourselves and have a foreground client attach as a control |
| 1323 |
* slave. NB. we must save copies of the flags that we override for |
| 1324 |
* the backgrounding, since we defer attachment of the slave until |
| 1325 |
* after the connection is fully established (in particular, |
| 1326 |
* async rfwd replies have been received for ExitOnForwardFailure). |
| 1327 |
*/ |
| 1328 |
if (options.control_persist && muxserver_sock != -1) { |
| 1329 |
ostdin_null_flag = stdin_null_flag; |
| 1330 |
ono_shell_flag = no_shell_flag; |
| 1331 |
ono_tty_flag = no_tty_flag; |
| 1332 |
otty_flag = tty_flag; |
| 1333 |
stdin_null_flag = 1; |
| 1334 |
no_shell_flag = 1; |
| 1335 |
no_tty_flag = 1; |
| 1336 |
tty_flag = 0; |
| 1337 |
if (!fork_after_authentication_flag) |
| 1338 |
need_controlpersist_detach = 1; |
| 1339 |
fork_after_authentication_flag = 1; |
| 1340 |
} |
| 1341 |
|
| 1265 |
if (!no_shell_flag || (datafellows & SSH_BUG_DUMMYCHAN)) |
1342 |
if (!no_shell_flag || (datafellows & SSH_BUG_DUMMYCHAN)) |
| 1266 |
id = ssh_session2_open(); |
1343 |
id = ssh_session2_open(); |
| 1267 |
|
1344 |
|
|
Lines 1280-1298
ssh_session2(void)
Link Here
|
| 1280 |
options.permit_local_command) |
1357 |
options.permit_local_command) |
| 1281 |
ssh_local_cmd(options.local_command); |
1358 |
ssh_local_cmd(options.local_command); |
| 1282 |
|
1359 |
|
| 1283 |
/* Start listening for multiplex clients */ |
|
|
| 1284 |
muxserver_listen(); |
| 1285 |
|
| 1286 |
/* |
1360 |
/* |
| 1287 |
* If requested and we are not interested in replies to remote |
1361 |
* If requested and we are not interested in replies to remote |
| 1288 |
* forwarding requests, then let ssh continue in the background. |
1362 |
* forwarding requests, then let ssh continue in the background. |
| 1289 |
*/ |
1363 |
*/ |
| 1290 |
if (fork_after_authentication_flag && |
1364 |
if (fork_after_authentication_flag) { |
| 1291 |
(!options.exit_on_forward_failure || |
1365 |
if (options.exit_on_forward_failure && |
| 1292 |
options.num_remote_forwards == 0)) { |
1366 |
options.num_remote_forwards > 0) { |
| 1293 |
fork_after_authentication_flag = 0; |
1367 |
debug("deferring postauth fork until remote forward " |
| 1294 |
if (daemon(1, 1) < 0) |
1368 |
"confirmation received"); |
| 1295 |
fatal("daemon() failed: %.200s", strerror(errno)); |
1369 |
} else |
|
|
1370 |
fork_postauth(); |
| 1296 |
} |
1371 |
} |
| 1297 |
|
1372 |
|
| 1298 |
if (options.use_roaming) |
1373 |
if (options.use_roaming) |