Lines Matching +full:mux +full:- +full:int +full:- +full:port
1 /* $OpenBSD: mux.c,v 1.101 2023/11/23 03:37:05 dtucker Exp $ */
3 * Copyright (c) 2002-2008 Damien Miller <djm@openbsd.org>
53 #include "openbsd-compat/sys-queue.h"
74 extern int tty_flag;
102 int fid; /* forward id */
106 int muxserver_sock = -1;
123 int hello_rcvd;
126 /* mux protocol messages */
151 static void mux_session_confirm(struct ssh *, int, int, void *);
152 static void mux_stdio_confirm(struct ssh *, int, int, void *);
154 static int mux_master_process_hello(struct ssh *, u_int,
156 static int mux_master_process_new_session(struct ssh *, u_int,
158 static int mux_master_process_alive_check(struct ssh *, u_int,
160 static int mux_master_process_terminate(struct ssh *, u_int,
162 static int mux_master_process_open_fwd(struct ssh *, u_int,
164 static int mux_master_process_close_fwd(struct ssh *, u_int,
166 static int mux_master_process_stdio_fwd(struct ssh *, u_int,
168 static int mux_master_process_stop_listening(struct ssh *, u_int,
170 static int mux_master_process_proxy(struct ssh *, u_int,
175 int (*handler)(struct ssh *, u_int, Channel *,
190 /* Cleanup callback fired on closure of mux client _session_ channel */
192 mux_master_session_cleanup_cb(struct ssh *ssh, int cid, int force, void *unused) in mux_master_session_cleanup_cb()
199 if (c->ctl_chan != -1) { in mux_master_session_cleanup_cb()
200 if ((cc = channel_by_id(ssh, c->ctl_chan)) == NULL) in mux_master_session_cleanup_cb()
202 c->self, c->ctl_chan); in mux_master_session_cleanup_cb()
203 c->ctl_chan = -1; in mux_master_session_cleanup_cb()
204 cc->remote_id = 0; in mux_master_session_cleanup_cb()
205 cc->have_remote_id = 0; in mux_master_session_cleanup_cb()
208 channel_cancel_cleanup(ssh, c->self); in mux_master_session_cleanup_cb()
211 /* Cleanup callback fired on closure of mux client _control_ channel */
213 mux_master_control_cleanup_cb(struct ssh *ssh, int cid, int force, void *unused) in mux_master_control_cleanup_cb()
220 if (c->have_remote_id) { in mux_master_control_cleanup_cb()
221 if ((sc = channel_by_id(ssh, c->remote_id)) == NULL) in mux_master_control_cleanup_cb()
223 c->self, c->remote_id); in mux_master_control_cleanup_cb()
224 c->remote_id = 0; in mux_master_control_cleanup_cb()
225 c->have_remote_id = 0; in mux_master_control_cleanup_cb()
226 sc->ctl_chan = -1; in mux_master_control_cleanup_cb()
227 if (sc->type != SSH_CHANNEL_OPEN && in mux_master_control_cleanup_cb()
228 sc->type != SSH_CHANNEL_OPENING) { in mux_master_control_cleanup_cb()
229 debug2_f("channel %d: not open", sc->self); in mux_master_control_cleanup_cb()
232 if (sc->istate == CHAN_INPUT_OPEN) in mux_master_control_cleanup_cb()
234 if (sc->ostate == CHAN_OUTPUT_OPEN) in mux_master_control_cleanup_cb()
238 channel_cancel_cleanup(ssh, c->self); in mux_master_control_cleanup_cb()
241 /* Check mux client environment variables before passing them to mux master. */
242 static int
246 int ret; in env_permitted()
251 ret = snprintf(name, sizeof(name), "%.*s", (int)(cp - env), env); in env_permitted()
264 /* Mux master protocol message handlers */
266 static int
271 struct mux_master_state *state = (struct mux_master_state *)c->mux_ctx; in mux_master_process_hello()
272 int r; in mux_master_process_hello()
275 fatal_f("channel %d: c->mux_ctx == NULL", c->self); in mux_master_process_hello()
276 if (state->hello_rcvd) { in mux_master_process_hello()
278 return -1; in mux_master_process_hello()
282 return -1; in mux_master_process_hello()
287 return -1; in mux_master_process_hello()
289 debug2_f("channel %d client version %u", c->self, ver); in mux_master_process_hello()
299 return -1; in mux_master_process_hello()
305 state->hello_rcvd = 1; in mux_master_process_hello()
313 int r; in reply_ok()
324 int r; in reply_error()
332 static int
340 int r, new_fd[3]; in mux_master_process_new_session()
344 cctx->term = NULL; in mux_master_process_new_session()
345 cctx->rid = rid; in mux_master_process_new_session()
347 cctx->env = NULL; in mux_master_process_new_session()
350 (r = sshbuf_get_u32(m, &cctx->want_tty)) != 0 || in mux_master_process_new_session()
351 (r = sshbuf_get_u32(m, &cctx->want_x_fwd)) != 0 || in mux_master_process_new_session()
352 (r = sshbuf_get_u32(m, &cctx->want_agent_fwd)) != 0 || in mux_master_process_new_session()
353 (r = sshbuf_get_u32(m, &cctx->want_subsys)) != 0 || in mux_master_process_new_session()
355 (r = sshbuf_get_cstring(m, &cctx->term, NULL)) != 0 || in mux_master_process_new_session()
360 free(cctx->env[j]); in mux_master_process_new_session()
361 free(cctx->env); in mux_master_process_new_session()
362 free(cctx->term); in mux_master_process_new_session()
365 return -1; in mux_master_process_new_session()
376 cctx->env = xreallocarray(cctx->env, env_len + 2, in mux_master_process_new_session()
377 sizeof(*cctx->env)); in mux_master_process_new_session()
378 cctx->env[env_len++] = cp; in mux_master_process_new_session()
379 cctx->env[env_len] = NULL; in mux_master_process_new_session()
388 "term \"%s\", cmd \"%s\", env %u", c->self, in mux_master_process_new_session()
389 cctx->want_tty, cctx->want_x_fwd, cctx->want_agent_fwd, in mux_master_process_new_session()
390 cctx->want_subsys, cctx->term, cmd, env_len); in mux_master_process_new_session()
392 if ((cctx->cmd = sshbuf_new()) == NULL) in mux_master_process_new_session()
394 if ((r = sshbuf_put(cctx->cmd, cmd, strlen(cmd))) != 0) in mux_master_process_new_session()
401 if ((new_fd[i] = mm_receive_fd(c->sock)) == -1) { in mux_master_process_new_session()
406 free(cctx->env[j]); in mux_master_process_new_session()
407 free(cctx->env); in mux_master_process_new_session()
408 free(cctx->term); in mux_master_process_new_session()
409 sshbuf_free(cctx->cmd); in mux_master_process_new_session()
413 return -1; in mux_master_process_new_session()
421 if (c->have_remote_id) { in mux_master_process_new_session()
429 free(cctx->term); in mux_master_process_new_session()
432 free(cctx->env[i]); in mux_master_process_new_session()
433 free(cctx->env); in mux_master_process_new_session()
435 sshbuf_free(cctx->cmd); in mux_master_process_new_session()
451 if (cctx->want_tty && tcgetattr(new_fd[0], &cctx->tio) == -1) in mux_master_process_new_session()
456 if (cctx->want_tty) { in mux_master_process_new_session()
463 CHAN_EXTENDED_WRITE, "client-session", CHANNEL_NONBLOCK_STDIO); in mux_master_process_new_session()
465 nc->ctl_chan = c->self; /* link session -> control channel */ in mux_master_process_new_session()
466 c->remote_id = nc->self; /* link control -> session channel */ in mux_master_process_new_session()
467 c->have_remote_id = 1; in mux_master_process_new_session()
469 if (cctx->want_tty && escape_char != 0xffffffff) { in mux_master_process_new_session()
470 channel_register_filter(ssh, nc->self, in mux_master_process_new_session()
473 client_new_escape_filter_ctx((int)escape_char)); in mux_master_process_new_session()
477 nc->self, nc->ctl_chan); in mux_master_process_new_session()
479 channel_send_open(ssh, nc->self); in mux_master_process_new_session()
480 channel_register_open_confirm(ssh, nc->self, mux_session_confirm, cctx); in mux_master_process_new_session()
481 c->mux_pause = 1; /* stop handling messages until open_confirm done */ in mux_master_process_new_session()
482 channel_register_cleanup(ssh, nc->self, in mux_master_process_new_session()
489 static int
493 int r; in mux_master_process_alive_check()
495 debug2_f("channel %d: alive check", c->self); in mux_master_process_alive_check()
506 static int
510 debug2_f("channel %d: terminate request", c->self); in mux_master_process_terminate()
525 /* XXX exit happens too soon - message never makes it to client */ in mux_master_process_terminate()
536 xasprintf(&ret, "local forward %.200s:%d -> %.200s:%d", in format_forward()
537 (fwd->listen_path != NULL) ? fwd->listen_path : in format_forward()
538 (fwd->listen_host == NULL) ? in format_forward()
540 fwd->listen_host, fwd->listen_port, in format_forward()
541 (fwd->connect_path != NULL) ? fwd->connect_path : in format_forward()
542 fwd->connect_host, fwd->connect_port); in format_forward()
545 xasprintf(&ret, "dynamic forward %.200s:%d -> *", in format_forward()
546 (fwd->listen_host == NULL) ? in format_forward()
548 fwd->listen_host, fwd->listen_port); in format_forward()
551 xasprintf(&ret, "remote forward %.200s:%d -> %.200s:%d", in format_forward()
552 (fwd->listen_path != NULL) ? fwd->listen_path : in format_forward()
553 (fwd->listen_host == NULL) ? in format_forward()
554 "LOCALHOST" : fwd->listen_host, in format_forward()
555 fwd->listen_port, in format_forward()
556 (fwd->connect_path != NULL) ? fwd->connect_path : in format_forward()
557 fwd->connect_host, fwd->connect_port); in format_forward()
565 static int
575 static int
578 if (!compare_host(a->listen_host, b->listen_host)) in compare_forward()
580 if (!compare_host(a->listen_path, b->listen_path)) in compare_forward()
582 if (a->listen_port != b->listen_port) in compare_forward()
584 if (!compare_host(a->connect_host, b->connect_host)) in compare_forward()
586 if (!compare_host(a->connect_path, b->connect_path)) in compare_forward()
588 if (a->connect_port != b->connect_port) in compare_forward()
595 mux_confirm_remote_forward(struct ssh *ssh, int type, u_int32_t seq, void *ctxt) in mux_confirm_remote_forward()
602 u_int port; in mux_confirm_remote_forward() local
603 int r; in mux_confirm_remote_forward()
605 if ((c = channel_by_id(ssh, fctx->cid)) == NULL) { in mux_confirm_remote_forward()
612 if (fctx->fid >= options.num_remote_forwards || in mux_confirm_remote_forward()
613 (options.remote_forwards[fctx->fid].connect_path == NULL && in mux_confirm_remote_forward()
614 options.remote_forwards[fctx->fid].connect_host == NULL)) { in mux_confirm_remote_forward()
615 xasprintf(&failmsg, "unknown forwarding id %d", fctx->fid); in mux_confirm_remote_forward()
618 rfwd = &options.remote_forwards[fctx->fid]; in mux_confirm_remote_forward()
621 rfwd->listen_port, rfwd->connect_path ? rfwd->connect_path : in mux_confirm_remote_forward()
622 rfwd->connect_host, rfwd->connect_port); in mux_confirm_remote_forward()
624 if (rfwd->listen_port == 0) { in mux_confirm_remote_forward()
625 if ((r = sshpkt_get_u32(ssh, &port)) != 0) in mux_confirm_remote_forward()
626 fatal_fr(r, "parse port"); in mux_confirm_remote_forward()
627 if (port > 65535) { in mux_confirm_remote_forward()
628 fatal("Invalid allocated port %u for " in mux_confirm_remote_forward()
629 "mux remote forward to %s:%d", port, in mux_confirm_remote_forward()
630 rfwd->connect_host, rfwd->connect_port); in mux_confirm_remote_forward()
632 rfwd->allocated_port = (int)port; in mux_confirm_remote_forward()
633 debug("Allocated port %u for mux remote forward" in mux_confirm_remote_forward()
634 " to %s:%d", rfwd->allocated_port, in mux_confirm_remote_forward()
635 rfwd->connect_host, rfwd->connect_port); in mux_confirm_remote_forward()
638 (r = sshbuf_put_u32(out, fctx->rid)) != 0 || in mux_confirm_remote_forward()
640 rfwd->allocated_port)) != 0) in mux_confirm_remote_forward()
642 channel_update_permission(ssh, rfwd->handle, in mux_confirm_remote_forward()
643 rfwd->allocated_port); in mux_confirm_remote_forward()
645 reply_ok(out, fctx->rid); in mux_confirm_remote_forward()
649 if (rfwd->listen_port == 0) in mux_confirm_remote_forward()
650 channel_update_permission(ssh, rfwd->handle, -1); in mux_confirm_remote_forward()
651 if (rfwd->listen_path != NULL) in mux_confirm_remote_forward()
652 xasprintf(&failmsg, "remote port forwarding failed for " in mux_confirm_remote_forward()
653 "listen path %s", rfwd->listen_path); in mux_confirm_remote_forward()
655 xasprintf(&failmsg, "remote port forwarding failed for " in mux_confirm_remote_forward()
656 "listen port %d", rfwd->listen_port); in mux_confirm_remote_forward()
659 "connect %s:%d", rfwd->listen_port, in mux_confirm_remote_forward()
660 rfwd->connect_path ? rfwd->connect_path : in mux_confirm_remote_forward()
661 rfwd->connect_host, rfwd->connect_port); in mux_confirm_remote_forward()
663 free(rfwd->listen_host); in mux_confirm_remote_forward()
664 free(rfwd->listen_path); in mux_confirm_remote_forward()
665 free(rfwd->connect_host); in mux_confirm_remote_forward()
666 free(rfwd->connect_path); in mux_confirm_remote_forward()
671 reply_error(out, MUX_S_FAILURE, fctx->rid, failmsg); in mux_confirm_remote_forward()
674 if ((r = sshbuf_put_stringb(c->output, out)) != 0) in mux_confirm_remote_forward()
677 if (c->mux_pause <= 0) in mux_confirm_remote_forward()
678 fatal_f("mux_pause %d", c->mux_pause); in mux_confirm_remote_forward()
679 c->mux_pause = 0; /* start processing messages again */ in mux_confirm_remote_forward()
682 static int
691 int r, i, ret = 0, freefwd = 1; in mux_master_process_open_fwd()
695 /* XXX - lport/cport check redundant */ in mux_master_process_open_fwd()
704 ret = -1; in mux_master_process_open_fwd()
728 debug2_f("channel %d: request %s", c->self, in mux_master_process_open_fwd()
747 logit_f("invalid listen port %u", fwd.listen_port); in mux_master_process_open_fwd()
754 logit_f("invalid connect port %u", in mux_master_process_open_fwd()
784 debug2_f("found allocated port"); in mux_master_process_open_fwd()
812 "Port forwarding failed"); in mux_master_process_open_fwd()
825 fctx->cid = c->self; in mux_master_process_open_fwd()
826 fctx->rid = rid; in mux_master_process_open_fwd()
827 fctx->fid = options.num_remote_forwards - 1; in mux_master_process_open_fwd()
831 c->mux_pause = 1; /* wait for mux_confirm_remote_forward */ in mux_master_process_open_fwd()
847 static int
856 int r, i, ret = 0; in mux_master_process_close_fwd()
869 ret = -1; in mux_master_process_close_fwd()
894 debug2_f("channel %d: request cancel %s", c->self, in mux_master_process_close_fwd()
922 error_reason = "port not forwarded"; in mux_master_process_close_fwd()
925 * This shouldn't fail unless we confused the host/port in mux_master_process_close_fwd()
928 * to use the actual listen port. in mux_master_process_close_fwd()
930 if (channel_request_rforward_cancel(ssh, found_fwd) == -1) in mux_master_process_close_fwd()
931 error_reason = "port not in permitted opens"; in mux_master_process_close_fwd()
935 &options.fwd_opts) == -1) in mux_master_process_close_fwd()
936 error_reason = "port not found"; in mux_master_process_close_fwd()
943 free(found_fwd->listen_host); in mux_master_process_close_fwd()
944 free(found_fwd->listen_path); in mux_master_process_close_fwd()
945 free(found_fwd->connect_host); in mux_master_process_close_fwd()
946 free(found_fwd->connect_path); in mux_master_process_close_fwd()
947 found_fwd->listen_host = found_fwd->connect_host = NULL; in mux_master_process_close_fwd()
948 found_fwd->listen_path = found_fwd->connect_path = NULL; in mux_master_process_close_fwd()
949 found_fwd->listen_port = found_fwd->connect_port = 0; in mux_master_process_close_fwd()
959 static int
966 int ok = 0, cport, r, new_fd[2]; in mux_master_process_stdio_fwd()
974 return -1; in mux_master_process_stdio_fwd()
979 cport = (int)_cport; in mux_master_process_stdio_fwd()
982 error_f("invalid port 0x%x", _cport); in mux_master_process_stdio_fwd()
983 return -1; in mux_master_process_stdio_fwd()
986 debug2_f("channel %d: stdio fwd to %s:%d", c->self, chost, cport); in mux_master_process_stdio_fwd()
990 if ((new_fd[i] = mm_receive_fd(c->sock)) == -1) { in mux_master_process_stdio_fwd()
999 return -1; in mux_master_process_stdio_fwd()
1006 if (c->have_remote_id) { in mux_master_process_stdio_fwd()
1037 nc->ctl_chan = c->self; /* link session -> control channel */ in mux_master_process_stdio_fwd()
1038 c->remote_id = nc->self; /* link control -> session channel */ in mux_master_process_stdio_fwd()
1039 c->have_remote_id = 1; in mux_master_process_stdio_fwd()
1041 debug2_f("channel_new: %d control %d", nc->self, nc->ctl_chan); in mux_master_process_stdio_fwd()
1043 channel_register_cleanup(ssh, nc->self, in mux_master_process_stdio_fwd()
1047 cctx->rid = rid; in mux_master_process_stdio_fwd()
1048 channel_register_open_confirm(ssh, nc->self, mux_stdio_confirm, cctx); in mux_master_process_stdio_fwd()
1049 c->mux_pause = 1; /* stop handling messages until open_confirm done */ in mux_master_process_stdio_fwd()
1055 /* Callback on open confirmation in mux master for a mux stdio fwd session. */
1057 mux_stdio_confirm(struct ssh *ssh, int id, int success, void *arg) in mux_stdio_confirm()
1062 int r; in mux_stdio_confirm()
1068 if ((cc = channel_by_id(ssh, c->ctl_chan)) == NULL) in mux_stdio_confirm()
1070 id, c->ctl_chan); in mux_stdio_confirm()
1076 reply_error(reply, MUX_S_FAILURE, cctx->rid, in mux_stdio_confirm()
1085 (r = sshbuf_put_u32(reply, cctx->rid)) != 0 || in mux_stdio_confirm()
1086 (r = sshbuf_put_u32(reply, c->self)) != 0) in mux_stdio_confirm()
1091 if ((r = sshbuf_put_stringb(cc->output, reply)) != 0) in mux_stdio_confirm()
1095 if (cc->mux_pause <= 0) in mux_stdio_confirm()
1096 fatal_f("mux_pause %d", cc->mux_pause); in mux_stdio_confirm()
1097 cc->mux_pause = 0; /* start processing messages again */ in mux_stdio_confirm()
1098 c->open_confirm_ctx = NULL; in mux_stdio_confirm()
1102 static int
1106 debug_f("channel %d: stop listening", c->self); in mux_master_process_stop_listening()
1125 muxserver_sock = -1; in mux_master_process_stop_listening()
1132 static int
1136 int r; in mux_master_process_proxy()
1138 debug_f("channel %d: proxy request", c->self); in mux_master_process_proxy()
1140 c->mux_rcb = channel_proxy_downstream; in mux_master_process_proxy()
1148 /* Channel callbacks fired on read/write from mux client fd */
1149 static int
1152 struct mux_master_state *state = (struct mux_master_state *)c->mux_ctx; in mux_master_read_cb()
1155 int r, ret = -1; in mux_master_read_cb()
1161 if (c->mux_ctx == NULL) { in mux_master_read_cb()
1163 c->mux_ctx = state; in mux_master_read_cb()
1164 channel_register_cleanup(ssh, c->self, in mux_master_read_cb()
1172 if ((r = sshbuf_put_stringb(c->output, out)) != 0) in mux_master_read_cb()
1174 debug3_f("channel %d: hello sent", c->self); in mux_master_read_cb()
1180 if ((r = sshbuf_froms(c->input, &in)) != 0) { in mux_master_read_cb()
1188 debug3_f("channel %d packet type 0x%08x len %zu", c->self, in mux_master_read_cb()
1194 if (!state->hello_rcvd) { in mux_master_read_cb()
1211 error_f("unsupported mux message 0x%08x", type); in mux_master_read_cb()
1217 (r = sshbuf_put_stringb(c->output, out)) != 0) in mux_master_read_cb()
1226 mux_exit_message(struct ssh *ssh, Channel *c, int exitval) in mux_exit_message()
1230 int r; in mux_exit_message()
1232 debug3_f("channel %d: exit message, exitval %d", c->self, exitval); in mux_exit_message()
1234 if ((mux_chan = channel_by_id(ssh, c->ctl_chan)) == NULL) in mux_exit_message()
1235 fatal_f("channel %d missing mux %d", c->self, c->ctl_chan); in mux_exit_message()
1241 (r = sshbuf_put_u32(m, c->self)) != 0 || in mux_exit_message()
1243 (r = sshbuf_put_stringb(mux_chan->output, m)) != 0) in mux_exit_message()
1253 int r; in mux_tty_alloc_failed()
1255 debug3_f("channel %d: TTY alloc failed", c->self); in mux_tty_alloc_failed()
1257 if ((mux_chan = channel_by_id(ssh, c->ctl_chan)) == NULL) in mux_tty_alloc_failed()
1258 fatal_f("channel %d missing mux %d", c->self, c->ctl_chan); in mux_tty_alloc_failed()
1264 (r = sshbuf_put_u32(m, c->self)) != 0 || in mux_tty_alloc_failed()
1265 (r = sshbuf_put_stringb(mux_chan->output, m)) != 0) in mux_tty_alloc_failed()
1270 /* Prepare a mux master to listen on a Unix domain socket. */
1278 int oerrno; in muxserver_listen()
1287 * Use a temporary path before listen so we can pseudo-atomically in muxserver_listen()
1292 for (i = 0; i < sizeof(rbuf) - 1; i++) { in muxserver_listen()
1295 (r < 26*2) ? 'A' + r - 26 : in muxserver_listen()
1296 '0' + r - 26 - 26; in muxserver_listen()
1298 rbuf[sizeof(rbuf) - 1] = '\0'; in muxserver_listen()
1312 if (muxserver_sock != -1) { in muxserver_listen()
1314 muxserver_sock = -1; in muxserver_listen()
1327 /* Now atomically "move" the mux socket into position */ in muxserver_listen()
1330 fatal_f("link mux listener %s => %s: %s", in muxserver_listen()
1345 mux_listener_channel = channel_new(ssh, "mux listener", in muxserver_listen()
1346 SSH_CHANNEL_MUX_LISTENER, muxserver_sock, muxserver_sock, -1, in muxserver_listen()
1349 mux_listener_channel->mux_rcb = mux_master_read_cb; in muxserver_listen()
1350 debug3_f("mux listener channel %d fd %d", in muxserver_listen()
1351 mux_listener_channel->self, mux_listener_channel->sock); in muxserver_listen()
1354 /* Callback on open confirmation in mux master for a mux client session. */
1356 mux_session_confirm(struct ssh *ssh, int id, int success, void *arg) in mux_session_confirm()
1361 int i, r; in mux_session_confirm()
1368 if ((cc = channel_by_id(ssh, c->ctl_chan)) == NULL) in mux_session_confirm()
1370 id, c->ctl_chan); in mux_session_confirm()
1376 reply_error(reply, MUX_S_FAILURE, cctx->rid, in mux_session_confirm()
1382 if (cctx->want_x_fwd && options.forward_x11 && display != NULL) { in mux_session_confirm()
1400 if (cctx->want_agent_fwd && options.forward_agent) { in mux_session_confirm()
1402 channel_request_start(ssh, id, "auth-agent-req@openssh.com", 0); in mux_session_confirm()
1407 client_session2_setup(ssh, id, cctx->want_tty, cctx->want_subsys, in mux_session_confirm()
1408 cctx->term, &cctx->tio, c->rfd, cctx->cmd, cctx->env); in mux_session_confirm()
1413 (r = sshbuf_put_u32(reply, cctx->rid)) != 0 || in mux_session_confirm()
1414 (r = sshbuf_put_u32(reply, c->self)) != 0) in mux_session_confirm()
1419 if ((r = sshbuf_put_stringb(cc->output, reply)) != 0) in mux_session_confirm()
1423 if (cc->mux_pause <= 0) in mux_session_confirm()
1424 fatal_f("mux_pause %d", cc->mux_pause); in mux_session_confirm()
1425 cc->mux_pause = 0; /* start processing messages again */ in mux_session_confirm()
1426 c->open_confirm_ctx = NULL; in mux_session_confirm()
1427 sshbuf_free(cctx->cmd); in mux_session_confirm()
1428 free(cctx->term); in mux_session_confirm()
1429 if (cctx->env != NULL) { in mux_session_confirm()
1430 for (i = 0; cctx->env[i] != NULL; i++) in mux_session_confirm()
1431 free(cctx->env[i]); in mux_session_confirm()
1432 free(cctx->env); in mux_session_confirm()
1441 control_client_sighandler(int signo) in control_client_sighandler()
1447 * Relay signal handler - used to pass some signals from mux client to
1448 * mux master.
1451 control_client_sigrelay(int signo) in control_client_sigrelay()
1453 int save_errno = errno; in control_client_sigrelay()
1461 static int
1462 mux_client_read(int fd, struct sshbuf *b, size_t need, int timeout_ms) in mux_client_read()
1467 int r; in mux_client_read()
1474 return -1; in mux_client_read()
1476 len = read(fd, p + have, need - have); in mux_client_read()
1477 if (len == -1) { in mux_client_read()
1484 &muxclient_terminate) == -1 && in mux_client_read()
1486 return -1; /* timeout */ in mux_client_read()
1491 return -1; in mux_client_read()
1496 return -1; in mux_client_read()
1503 static int
1504 mux_client_write_packet(int fd, struct sshbuf *m) in mux_client_write_packet()
1508 int r, oerrno, len; in mux_client_write_packet()
1526 return -1; in mux_client_write_packet()
1528 len = write(fd, ptr + have, need - have); in mux_client_write_packet()
1529 if (len == -1) { in mux_client_write_packet()
1535 (void)poll(&pfd, 1, -1); in mux_client_write_packet()
1543 return -1; in mux_client_write_packet()
1549 return -1; in mux_client_write_packet()
1557 static int
1558 mux_client_read_packet_timeout(int fd, struct sshbuf *m, int timeout_ms) in mux_client_read_packet_timeout()
1563 int r, oerrno; in mux_client_read_packet_timeout()
1573 return -1; in mux_client_read_packet_timeout()
1581 return -1; in mux_client_read_packet_timeout()
1590 static int
1591 mux_client_read_packet(int fd, struct sshbuf *m) in mux_client_read_packet()
1593 return mux_client_read_packet_timeout(fd, m, -1); in mux_client_read_packet()
1596 static int
1597 mux_client_hello_exchange(int fd, int timeout_ms) in mux_client_hello_exchange()
1601 int r, ret = -1; in mux_client_hello_exchange()
1657 mux_client_request_alive(int fd) in mux_client_request_alive()
1662 int r; in mux_client_request_alive()
1708 mux_client_request_terminate(int fd) in mux_client_request_terminate()
1713 int r; in mux_client_request_terminate()
1762 static int
1763 mux_client_forward(int fd, int cancel_flag, u_int ftype, struct Forward *fwd) in mux_client_forward()
1769 int r; in mux_client_forward()
1777 if (fwd->listen_path != NULL) in mux_client_forward()
1778 lhost = fwd->listen_path; in mux_client_forward()
1779 else if (fwd->listen_host == NULL) in mux_client_forward()
1781 else if (*fwd->listen_host == '\0') in mux_client_forward()
1784 lhost = fwd->listen_host; in mux_client_forward()
1786 if (fwd->connect_path != NULL) in mux_client_forward()
1787 chost = fwd->connect_path; in mux_client_forward()
1788 else if (fwd->connect_host == NULL) in mux_client_forward()
1791 chost = fwd->connect_host; in mux_client_forward()
1799 (r = sshbuf_put_u32(m, fwd->listen_port)) != 0 || in mux_client_forward()
1801 (r = sshbuf_put_u32(m, fwd->connect_port)) != 0) in mux_client_forward()
1812 return -1; in mux_client_forward()
1828 if ((r = sshbuf_get_u32(m, &fwd->allocated_port)) != 0) in mux_client_forward()
1829 fatal_fr(r, "parse port"); in mux_client_forward()
1830 verbose("Allocated port %u for remote forward to %s:%d", in mux_client_forward()
1831 fwd->allocated_port, in mux_client_forward()
1832 fwd->connect_host ? fwd->connect_host : "", in mux_client_forward()
1833 fwd->connect_port); in mux_client_forward()
1835 fprintf(stdout, "%i\n", fwd->allocated_port); in mux_client_forward()
1842 return -1; in mux_client_forward()
1848 return -1; in mux_client_forward()
1858 static int
1859 mux_client_forwards(int fd, int cancel_flag) in mux_client_forwards()
1861 int i, ret = 0; in mux_client_forwards()
1873 ret = -1; in mux_client_forwards()
1878 ret = -1; in mux_client_forwards()
1883 static int
1884 mux_client_request_session(int fd) in mux_client_request_session()
1891 int r, rawmode = 0; in mux_client_request_session()
1897 return -1; in mux_client_request_session()
1902 if (options.stdin_null && stdfd_devnull(1, 0, 0) == -1) in mux_client_request_session()
1945 if (mm_send_fd(fd, STDIN_FILENO) == -1 || in mux_client_request_session()
1946 mm_send_fd(fd, STDOUT_FILENO) == -1 || in mux_client_request_session()
1947 mm_send_fd(fd, STDERR_FILENO) == -1) in mux_client_request_session()
1957 return -1; in mux_client_request_session()
1978 return -1; in mux_client_request_session()
1984 return -1; in mux_client_request_session()
1988 return -1; in mux_client_request_session()
1992 if (pledge("stdio proc tty", NULL) == -1) in mux_client_request_session()
2073 static int
2074 mux_client_proxy(int fd) in mux_client_proxy()
2079 int r; in mux_client_proxy()
2114 static int
2115 mux_client_request_stdio_fwd(int fd) in mux_client_request_stdio_fwd()
2120 int r; in mux_client_request_stdio_fwd()
2126 return -1; in mux_client_request_stdio_fwd()
2131 if (options.stdin_null && stdfd_devnull(1, 0, 0) == -1) in mux_client_request_stdio_fwd()
2147 if (mm_send_fd(fd, STDIN_FILENO) == -1 || in mux_client_request_stdio_fwd()
2148 mm_send_fd(fd, STDOUT_FILENO) == -1) in mux_client_request_stdio_fwd()
2151 if (pledge("stdio proc tty", NULL) == -1) in mux_client_request_stdio_fwd()
2163 return -1; in mux_client_request_stdio_fwd()
2191 return -1; in mux_client_request_stdio_fwd()
2214 mux_client_request_stop_listening(int fd) in mux_client_request_stop_listening()
2219 int r; in mux_client_request_stop_listening()
2264 int
2268 int sock, timeout = options.connection_timeout, timeout_ms = -1; in muxclient()
2281 debug("auto-mux: Trying existing master at '%s'", path); in muxclient()
2286 return -1; in muxclient()
2295 (unsigned int)sizeof(addr.sun_path)); in muxclient()
2297 if ((sock = socket(PF_UNIX, SOCK_STREAM, 0)) == -1) in muxclient()
2300 if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) == -1) { in muxclient()
2320 return -1; in muxclient()
2331 return -1; in muxclient()
2352 return -1; in muxclient()
2355 return -1; in muxclient()