=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/ssh/ssh.c,v retrieving revision 1.522 retrieving revision 1.523 diff -u -r1.522 -r1.523 --- src/usr.bin/ssh/ssh.c 2020/04/03 02:27:12 1.522 +++ src/usr.bin/ssh/ssh.c 2020/04/03 02:40:32 1.523 @@ -1,4 +1,4 @@ -/* $OpenBSD: ssh.c,v 1.522 2020/04/03 02:27:12 dtucker Exp $ */ +/* $OpenBSD: ssh.c,v 1.523 2020/04/03 02:40:32 djm Exp $ */ /* * Author: Tatu Ylonen * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland @@ -181,7 +181,7 @@ int subsystem_flag = 0; /* # of replies received for global requests */ -static int remote_forward_confirms_received = 0; +static int forward_confirms_pending = -1; /* mux.c */ extern int muxserver_sock; @@ -1646,6 +1646,16 @@ fatal("daemon() failed: %.200s", strerror(errno)); } +static void +forwarding_success(void) +{ + if (forward_confirms_pending > 0 && --forward_confirms_pending == 0) { + debug("All forwarding requests processed"); + if (fork_after_authentication_flag) + fork_postauth(); + } +} + /* Callback for remote forward global requests */ static void ssh_confirm_remote_forward(struct ssh *ssh, int type, u_int32_t seq, void *ctxt) @@ -1705,11 +1715,7 @@ "for listen port %d", rfwd->listen_port); } } - if (++remote_forward_confirms_received == options.num_remote_forwards) { - debug("All remote forwarding requests processed"); - if (fork_after_authentication_flag) - fork_postauth(); - } + forwarding_success(); } static void @@ -1727,6 +1733,19 @@ } static void +ssh_tun_confirm(struct ssh *ssh, int id, int success, void *arg) +{ + if (!success) { + error("Tunnel forwarding failed"); + if (options.exit_on_forward_failure) + cleanup_exit(255); + } + + debug("%s: tunnel forward established, id=%d", __func__, id); + forwarding_success(); +} + +static void ssh_init_stdio_forwarding(struct ssh *ssh) { Channel *c; @@ -1789,32 +1808,29 @@ options.remote_forwards[i].connect_path : options.remote_forwards[i].connect_host, options.remote_forwards[i].connect_port); - options.remote_forwards[i].handle = + if ((options.remote_forwards[i].handle = channel_request_remote_forwarding(ssh, - &options.remote_forwards[i]); - if (options.remote_forwards[i].handle < 0) { - if (options.exit_on_forward_failure) - fatal("Could not request remote forwarding."); - else - logit("Warning: Could not request remote " - "forwarding."); - } else { + &options.remote_forwards[i])) >= 0) { client_register_global_confirm( ssh_confirm_remote_forward, &options.remote_forwards[i]); - } + forward_confirms_pending++; + } else if (options.exit_on_forward_failure) + fatal("Could not request remote forwarding."); + else + logit("Warning: Could not request remote forwarding."); } /* Initiate tunnel forwarding. */ if (options.tun_open != SSH_TUNMODE_NO) { if ((*ifname = client_request_tun_fwd(ssh, options.tun_open, options.tun_local, - options.tun_remote)) == NULL) { - if (options.exit_on_forward_failure) - fatal("Could not request tunnel forwarding."); - else - error("Could not request tunnel forwarding."); - } + options.tun_remote, ssh_tun_confirm, NULL)) != NULL) + forward_confirms_pending++; + else if (options.exit_on_forward_failure) + fatal("Could not request tunnel forwarding."); + else + error("Could not request tunnel forwarding."); } }