Lines Matching +full:forward +full:- +full:channel
3 * Copyright (c) 2002-2008 Damien Miller <djm@openbsd.org>
53 #include "openbsd-compat/sys-queue.h"
97 /* Context for global channel callback */
99 u_int cid; /* channel id */
101 int fid; /* forward id */
105 int muxserver_sock = -1;
119 static Channel *mux_listener_channel = NULL;
154 Channel *, struct sshbuf *, struct sshbuf *);
156 Channel *, struct sshbuf *, struct sshbuf *);
158 Channel *, struct sshbuf *, struct sshbuf *);
160 Channel *, struct sshbuf *, struct sshbuf *);
162 Channel *, struct sshbuf *, struct sshbuf *);
164 Channel *, struct sshbuf *, struct sshbuf *);
166 Channel *, struct sshbuf *, struct sshbuf *);
168 Channel *, struct sshbuf *, struct sshbuf *);
170 Channel *, struct sshbuf *, struct sshbuf *);
174 int (*handler)(struct ssh *, u_int, Channel *,
189 /* Cleanup callback fired on closure of mux client _session_ channel */
193 Channel *cc, *c = channel_by_id(ssh, cid); in mux_master_session_cleanup_cb()
195 debug3_f("entering for channel %d", cid); in mux_master_session_cleanup_cb()
198 if (c->ctl_chan != -1) { in mux_master_session_cleanup_cb()
199 if ((cc = channel_by_id(ssh, c->ctl_chan)) == NULL) in mux_master_session_cleanup_cb()
200 fatal_f("channel %d missing control channel %d", in mux_master_session_cleanup_cb()
201 c->self, c->ctl_chan); in mux_master_session_cleanup_cb()
202 c->ctl_chan = -1; in mux_master_session_cleanup_cb()
203 cc->ctl_child_id = 0; in mux_master_session_cleanup_cb()
204 cc->have_ctl_child_id = 0; in mux_master_session_cleanup_cb()
207 channel_cancel_cleanup(ssh, c->self); in mux_master_session_cleanup_cb()
210 /* Cleanup callback fired on closure of mux client _control_ channel */
214 Channel *sc, *c = channel_by_id(ssh, cid); in mux_master_control_cleanup_cb()
216 debug3_f("entering for channel %d", cid); in mux_master_control_cleanup_cb()
219 if (c->have_ctl_child_id) { in mux_master_control_cleanup_cb()
220 if ((sc = channel_by_id(ssh, c->ctl_child_id)) == NULL) in mux_master_control_cleanup_cb()
221 fatal_f("channel %d missing session channel %u", in mux_master_control_cleanup_cb()
222 c->self, c->ctl_child_id); in mux_master_control_cleanup_cb()
223 c->ctl_child_id = 0; in mux_master_control_cleanup_cb()
224 c->have_ctl_child_id = 0; in mux_master_control_cleanup_cb()
225 sc->ctl_chan = -1; in mux_master_control_cleanup_cb()
226 if (sc->type != SSH_CHANNEL_OPEN && in mux_master_control_cleanup_cb()
227 sc->type != SSH_CHANNEL_OPENING) { in mux_master_control_cleanup_cb()
228 debug2_f("channel %d: not open", sc->self); in mux_master_control_cleanup_cb()
231 if (sc->istate == CHAN_INPUT_OPEN) in mux_master_control_cleanup_cb()
233 if (sc->ostate == CHAN_OUTPUT_OPEN) in mux_master_control_cleanup_cb()
237 channel_cancel_cleanup(ssh, c->self); in mux_master_control_cleanup_cb()
250 ret = snprintf(name, sizeof(name), "%.*s", (int)(cp - env), env); in env_permitted()
267 Channel *c, struct sshbuf *m, struct sshbuf *reply) in mux_master_process_hello()
270 struct mux_master_state *state = (struct mux_master_state *)c->mux_ctx; in mux_master_process_hello()
274 fatal_f("channel %d: c->mux_ctx == NULL", c->self); in mux_master_process_hello()
275 if (state->hello_rcvd) { in mux_master_process_hello()
277 return -1; in mux_master_process_hello()
281 return -1; in mux_master_process_hello()
286 return -1; in mux_master_process_hello()
288 debug2_f("channel %d client version %u", c->self, ver); in mux_master_process_hello()
298 return -1; in mux_master_process_hello()
304 state->hello_rcvd = 1; in mux_master_process_hello()
333 Channel *c, struct sshbuf *m, struct sshbuf *reply) in mux_master_process_new_session()
335 Channel *nc; in mux_master_process_new_session()
343 cctx->term = NULL; in mux_master_process_new_session()
344 cctx->rid = rid; in mux_master_process_new_session()
346 cctx->env = NULL; in mux_master_process_new_session()
349 (r = sshbuf_get_u32(m, &cctx->want_tty)) != 0 || in mux_master_process_new_session()
350 (r = sshbuf_get_u32(m, &cctx->want_x_fwd)) != 0 || in mux_master_process_new_session()
351 (r = sshbuf_get_u32(m, &cctx->want_agent_fwd)) != 0 || in mux_master_process_new_session()
352 (r = sshbuf_get_u32(m, &cctx->want_subsys)) != 0 || in mux_master_process_new_session()
354 (r = sshbuf_get_cstring(m, &cctx->term, NULL)) != 0 || in mux_master_process_new_session()
359 free(cctx->env[j]); in mux_master_process_new_session()
360 free(cctx->env); in mux_master_process_new_session()
361 free(cctx->term); in mux_master_process_new_session()
364 return -1; in mux_master_process_new_session()
375 cctx->env = xreallocarray(cctx->env, env_len + 2, in mux_master_process_new_session()
376 sizeof(*cctx->env)); in mux_master_process_new_session()
377 cctx->env[env_len++] = cp; in mux_master_process_new_session()
378 cctx->env[env_len] = NULL; in mux_master_process_new_session()
386 debug2_f("channel %d: request tty %d, X %d, agent %d, subsys %d, " in mux_master_process_new_session()
387 "term \"%s\", cmd \"%s\", env %u", c->self, in mux_master_process_new_session()
388 cctx->want_tty, cctx->want_x_fwd, cctx->want_agent_fwd, in mux_master_process_new_session()
389 cctx->want_subsys, cctx->term, cmd, env_len); in mux_master_process_new_session()
391 if ((cctx->cmd = sshbuf_new()) == NULL) in mux_master_process_new_session()
393 if ((r = sshbuf_put(cctx->cmd, cmd, strlen(cmd))) != 0) in mux_master_process_new_session()
400 if ((new_fd[i] = mm_receive_fd(c->sock)) == -1) { in mux_master_process_new_session()
405 free(cctx->env[j]); in mux_master_process_new_session()
406 free(cctx->env); in mux_master_process_new_session()
407 free(cctx->term); in mux_master_process_new_session()
408 sshbuf_free(cctx->cmd); in mux_master_process_new_session()
412 return -1; in mux_master_process_new_session()
420 if (c->have_ctl_child_id) { in mux_master_process_new_session()
428 free(cctx->term); in mux_master_process_new_session()
431 free(cctx->env[i]); in mux_master_process_new_session()
432 free(cctx->env); in mux_master_process_new_session()
434 sshbuf_free(cctx->cmd); in mux_master_process_new_session()
450 if (cctx->want_tty && tcgetattr(new_fd[0], &cctx->tio) == -1) in mux_master_process_new_session()
455 if (cctx->want_tty) { in mux_master_process_new_session()
462 CHAN_EXTENDED_WRITE, "client-session", CHANNEL_NONBLOCK_STDIO); in mux_master_process_new_session()
464 nc->ctl_chan = c->self; /* link session -> control channel */ in mux_master_process_new_session()
465 c->ctl_child_id = nc->self; /* link control -> session channel */ in mux_master_process_new_session()
466 c->have_ctl_child_id = 1; in mux_master_process_new_session()
468 if (cctx->want_tty && escape_char != 0xffffffff) { in mux_master_process_new_session()
469 channel_register_filter(ssh, nc->self, in mux_master_process_new_session()
475 debug2_f("channel_new: %d linked to control channel %d", in mux_master_process_new_session()
476 nc->self, nc->ctl_chan); in mux_master_process_new_session()
478 channel_send_open(ssh, nc->self); in mux_master_process_new_session()
479 channel_register_open_confirm(ssh, nc->self, mux_session_confirm, cctx); in mux_master_process_new_session()
480 c->mux_pause = 1; /* stop handling messages until open_confirm done */ in mux_master_process_new_session()
481 channel_register_cleanup(ssh, nc->self, in mux_master_process_new_session()
490 Channel *c, struct sshbuf *m, struct sshbuf *reply) in mux_master_process_alive_check()
494 debug2_f("channel %d: alive check", c->self); in mux_master_process_alive_check()
507 Channel *c, struct sshbuf *m, struct sshbuf *reply) in mux_master_process_terminate()
509 debug2_f("channel %d: terminate request", c->self); in mux_master_process_terminate()
524 /* XXX exit happens too soon - message never makes it to client */ in mux_master_process_terminate()
529 format_forward(u_int ftype, struct Forward *fwd) in format_forward()
535 xasprintf(&ret, "local forward %.200s:%d -> %.200s:%d", in format_forward()
536 (fwd->listen_path != NULL) ? fwd->listen_path : in format_forward()
537 (fwd->listen_host == NULL) ? in format_forward()
539 fwd->listen_host, fwd->listen_port, in format_forward()
540 (fwd->connect_path != NULL) ? fwd->connect_path : in format_forward()
541 fwd->connect_host, fwd->connect_port); in format_forward()
544 xasprintf(&ret, "dynamic forward %.200s:%d -> *", in format_forward()
545 (fwd->listen_host == NULL) ? in format_forward()
547 fwd->listen_host, fwd->listen_port); in format_forward()
550 xasprintf(&ret, "remote forward %.200s:%d -> %.200s:%d", in format_forward()
551 (fwd->listen_path != NULL) ? fwd->listen_path : in format_forward()
552 (fwd->listen_host == NULL) ? in format_forward()
553 "LOCALHOST" : fwd->listen_host, in format_forward()
554 fwd->listen_port, in format_forward()
555 (fwd->connect_path != NULL) ? fwd->connect_path : in format_forward()
556 fwd->connect_host, fwd->connect_port); in format_forward()
559 fatal_f("unknown forward type %u", ftype); in format_forward()
575 compare_forward(struct Forward *a, struct Forward *b) in compare_forward()
577 if (!compare_host(a->listen_host, b->listen_host)) in compare_forward()
579 if (!compare_host(a->listen_path, b->listen_path)) in compare_forward()
581 if (a->listen_port != b->listen_port) in compare_forward()
583 if (!compare_host(a->connect_host, b->connect_host)) in compare_forward()
585 if (!compare_host(a->connect_path, b->connect_path)) in compare_forward()
587 if (a->connect_port != b->connect_port) in compare_forward()
598 struct Forward *rfwd; in mux_confirm_remote_forward()
599 Channel *c; in mux_confirm_remote_forward()
604 if ((c = channel_by_id(ssh, fctx->cid)) == NULL) { in mux_confirm_remote_forward()
605 /* no channel for reply */ in mux_confirm_remote_forward()
606 error_f("unknown channel"); in mux_confirm_remote_forward()
611 if (fctx->fid >= options.num_remote_forwards || in mux_confirm_remote_forward()
612 (options.remote_forwards[fctx->fid].connect_path == NULL && in mux_confirm_remote_forward()
613 options.remote_forwards[fctx->fid].connect_host == NULL)) { in mux_confirm_remote_forward()
614 xasprintf(&failmsg, "unknown forwarding id %d", fctx->fid); in mux_confirm_remote_forward()
617 rfwd = &options.remote_forwards[fctx->fid]; in mux_confirm_remote_forward()
620 rfwd->listen_port, rfwd->connect_path ? rfwd->connect_path : in mux_confirm_remote_forward()
621 rfwd->connect_host, rfwd->connect_port); in mux_confirm_remote_forward()
623 if (rfwd->listen_port == 0) { in mux_confirm_remote_forward()
628 "mux remote forward to %s:%d", port, in mux_confirm_remote_forward()
629 rfwd->connect_host, rfwd->connect_port); in mux_confirm_remote_forward()
631 rfwd->allocated_port = (int)port; in mux_confirm_remote_forward()
632 debug("Allocated port %u for mux remote forward" in mux_confirm_remote_forward()
633 " to %s:%d", rfwd->allocated_port, in mux_confirm_remote_forward()
634 rfwd->connect_host, rfwd->connect_port); in mux_confirm_remote_forward()
637 (r = sshbuf_put_u32(out, fctx->rid)) != 0 || in mux_confirm_remote_forward()
639 rfwd->allocated_port)) != 0) in mux_confirm_remote_forward()
641 channel_update_permission(ssh, rfwd->handle, in mux_confirm_remote_forward()
642 rfwd->allocated_port); in mux_confirm_remote_forward()
644 reply_ok(out, fctx->rid); in mux_confirm_remote_forward()
648 if (rfwd->listen_port == 0) in mux_confirm_remote_forward()
649 channel_update_permission(ssh, rfwd->handle, -1); in mux_confirm_remote_forward()
650 if (rfwd->listen_path != NULL) in mux_confirm_remote_forward()
652 "listen path %s", rfwd->listen_path); in mux_confirm_remote_forward()
655 "listen port %d", rfwd->listen_port); in mux_confirm_remote_forward()
658 "connect %s:%d", rfwd->listen_port, in mux_confirm_remote_forward()
659 rfwd->connect_path ? rfwd->connect_path : in mux_confirm_remote_forward()
660 rfwd->connect_host, rfwd->connect_port); in mux_confirm_remote_forward()
662 free(rfwd->listen_host); in mux_confirm_remote_forward()
663 free(rfwd->listen_path); in mux_confirm_remote_forward()
664 free(rfwd->connect_host); in mux_confirm_remote_forward()
665 free(rfwd->connect_path); in mux_confirm_remote_forward()
670 reply_error(out, MUX_S_FAILURE, fctx->rid, failmsg); in mux_confirm_remote_forward()
673 if ((r = sshbuf_put_stringb(c->output, out)) != 0) in mux_confirm_remote_forward()
676 if (c->mux_pause <= 0) in mux_confirm_remote_forward()
677 fatal_f("mux_pause %d", c->mux_pause); in mux_confirm_remote_forward()
678 c->mux_pause = 0; /* start processing messages again */ in mux_confirm_remote_forward()
683 Channel *c, struct sshbuf *m, struct sshbuf *reply) in mux_master_process_open_fwd()
685 struct Forward fwd; in mux_master_process_open_fwd()
694 /* XXX - lport/cport check redundant */ in mux_master_process_open_fwd()
703 ret = -1; in mux_master_process_open_fwd()
727 debug2_f("channel %d: request %s", c->self, in mux_master_process_open_fwd()
824 fctx->cid = c->self; in mux_master_process_open_fwd()
825 fctx->rid = rid; in mux_master_process_open_fwd()
826 fctx->fid = options.num_remote_forwards - 1; in mux_master_process_open_fwd()
830 c->mux_pause = 1; /* wait for mux_confirm_remote_forward */ in mux_master_process_open_fwd()
848 Channel *c, struct sshbuf *m, struct sshbuf *reply) in mux_master_process_close_fwd()
850 struct Forward fwd, *found_fwd; in mux_master_process_close_fwd()
868 ret = -1; in mux_master_process_close_fwd()
893 debug2_f("channel %d: request cancel %s", c->self, in mux_master_process_close_fwd()
929 if (channel_request_rforward_cancel(ssh, found_fwd) == -1) in mux_master_process_close_fwd()
934 &options.fwd_opts) == -1) in mux_master_process_close_fwd()
942 free(found_fwd->listen_host); in mux_master_process_close_fwd()
943 free(found_fwd->listen_path); in mux_master_process_close_fwd()
944 free(found_fwd->connect_host); in mux_master_process_close_fwd()
945 free(found_fwd->connect_path); in mux_master_process_close_fwd()
946 found_fwd->listen_host = found_fwd->connect_host = NULL; in mux_master_process_close_fwd()
947 found_fwd->listen_path = found_fwd->connect_path = NULL; in mux_master_process_close_fwd()
948 found_fwd->listen_port = found_fwd->connect_port = 0; in mux_master_process_close_fwd()
960 Channel *c, struct sshbuf *m, struct sshbuf *reply) in mux_master_process_stdio_fwd()
962 Channel *nc; in mux_master_process_stdio_fwd()
973 return -1; in mux_master_process_stdio_fwd()
982 return -1; in mux_master_process_stdio_fwd()
985 debug2_f("channel %d: stdio fwd to %s:%d", c->self, chost, cport); in mux_master_process_stdio_fwd()
989 if ((new_fd[i] = mm_receive_fd(c->sock)) == -1) { in mux_master_process_stdio_fwd()
998 return -1; in mux_master_process_stdio_fwd()
1005 if (c->have_ctl_child_id) { in mux_master_process_stdio_fwd()
1019 ok = ask_permission("Allow forward to path %s", chost); in mux_master_process_stdio_fwd()
1021 ok = ask_permission("Allow forward to [%s]:%d? ", in mux_master_process_stdio_fwd()
1036 nc->ctl_chan = c->self; /* link session -> control channel */ in mux_master_process_stdio_fwd()
1037 c->ctl_child_id = nc->self; /* link control -> session channel */ in mux_master_process_stdio_fwd()
1038 c->have_ctl_child_id = 1; in mux_master_process_stdio_fwd()
1040 debug2_f("channel_new: %d control %d", nc->self, nc->ctl_chan); in mux_master_process_stdio_fwd()
1042 channel_register_cleanup(ssh, nc->self, in mux_master_process_stdio_fwd()
1046 cctx->rid = rid; in mux_master_process_stdio_fwd()
1047 channel_register_open_confirm(ssh, nc->self, mux_stdio_confirm, cctx); in mux_master_process_stdio_fwd()
1048 c->mux_pause = 1; /* stop handling messages until open_confirm done */ in mux_master_process_stdio_fwd()
1059 Channel *c, *cc; in mux_stdio_confirm()
1066 fatal_f("no channel for id %d", id); in mux_stdio_confirm()
1067 if ((cc = channel_by_id(ssh, c->ctl_chan)) == NULL) in mux_stdio_confirm()
1068 fatal_f("channel %d lacks control channel %d", in mux_stdio_confirm()
1069 id, c->ctl_chan); in mux_stdio_confirm()
1075 reply_error(reply, MUX_S_FAILURE, cctx->rid, in mux_stdio_confirm()
1084 (r = sshbuf_put_u32(reply, cctx->rid)) != 0 || in mux_stdio_confirm()
1085 (r = sshbuf_put_u32(reply, c->self)) != 0) in mux_stdio_confirm()
1090 if ((r = sshbuf_put_stringb(cc->output, reply)) != 0) in mux_stdio_confirm()
1094 if (cc->mux_pause <= 0) in mux_stdio_confirm()
1095 fatal_f("mux_pause %d", cc->mux_pause); in mux_stdio_confirm()
1096 cc->mux_pause = 0; /* start processing messages again */ in mux_stdio_confirm()
1097 c->open_confirm_ctx = NULL; in mux_stdio_confirm()
1103 Channel *c, struct sshbuf *m, struct sshbuf *reply) in mux_master_process_stop_listening()
1105 debug_f("channel %d: stop listening", c->self); in mux_master_process_stop_listening()
1124 muxserver_sock = -1; in mux_master_process_stop_listening()
1133 Channel *c, struct sshbuf *m, struct sshbuf *reply) in mux_master_process_proxy()
1137 debug_f("channel %d: proxy request", c->self); in mux_master_process_proxy()
1139 c->mux_rcb = channel_proxy_downstream; in mux_master_process_proxy()
1147 /* Channel callbacks fired on read/write from mux client fd */
1149 mux_master_read_cb(struct ssh *ssh, Channel *c) in mux_master_read_cb()
1151 struct mux_master_state *state = (struct mux_master_state *)c->mux_ctx; in mux_master_read_cb()
1154 int r, ret = -1; in mux_master_read_cb()
1160 if (c->mux_ctx == NULL) { in mux_master_read_cb()
1162 c->mux_ctx = state; in mux_master_read_cb()
1163 channel_register_cleanup(ssh, c->self, in mux_master_read_cb()
1171 if ((r = sshbuf_put_stringb(c->output, out)) != 0) in mux_master_read_cb()
1173 debug3_f("channel %d: hello sent", c->self); in mux_master_read_cb()
1178 /* Channel code ensures that we receive whole packets */ in mux_master_read_cb()
1179 if ((r = sshbuf_froms(c->input, &in)) != 0) { in mux_master_read_cb()
1187 debug3_f("channel %d packet type 0x%08x len %zu", c->self, in mux_master_read_cb()
1193 if (!state->hello_rcvd) { in mux_master_read_cb()
1216 (r = sshbuf_put_stringb(c->output, out)) != 0) in mux_master_read_cb()
1225 mux_exit_message(struct ssh *ssh, Channel *c, int exitval) in mux_exit_message()
1228 Channel *mux_chan; in mux_exit_message()
1231 debug3_f("channel %d: exit message, exitval %d", c->self, exitval); in mux_exit_message()
1233 if ((mux_chan = channel_by_id(ssh, c->ctl_chan)) == NULL) in mux_exit_message()
1234 fatal_f("channel %d missing mux %d", c->self, c->ctl_chan); in mux_exit_message()
1240 (r = sshbuf_put_u32(m, c->self)) != 0 || in mux_exit_message()
1242 (r = sshbuf_put_stringb(mux_chan->output, m)) != 0) in mux_exit_message()
1248 mux_tty_alloc_failed(struct ssh *ssh, Channel *c) in mux_tty_alloc_failed()
1251 Channel *mux_chan; in mux_tty_alloc_failed()
1254 debug3_f("channel %d: TTY alloc failed", c->self); in mux_tty_alloc_failed()
1256 if ((mux_chan = channel_by_id(ssh, c->ctl_chan)) == NULL) in mux_tty_alloc_failed()
1257 fatal_f("channel %d missing mux %d", c->self, c->ctl_chan); in mux_tty_alloc_failed()
1263 (r = sshbuf_put_u32(m, c->self)) != 0 || in mux_tty_alloc_failed()
1264 (r = sshbuf_put_stringb(mux_chan->output, m)) != 0) in mux_tty_alloc_failed()
1286 * Use a temporary path before listen so we can pseudo-atomically in muxserver_listen()
1291 for (i = 0; i < sizeof(rbuf) - 1; i++) { in muxserver_listen()
1294 (r < 26*2) ? 'A' + r - 26 : in muxserver_listen()
1295 '0' + r - 26 - 26; in muxserver_listen()
1297 rbuf[sizeof(rbuf) - 1] = '\0'; in muxserver_listen()
1311 if (muxserver_sock != -1) { in muxserver_listen()
1313 muxserver_sock = -1; in muxserver_listen()
1345 SSH_CHANNEL_MUX_LISTENER, muxserver_sock, muxserver_sock, -1, in muxserver_listen()
1348 mux_listener_channel->mux_rcb = mux_master_read_cb; in muxserver_listen()
1349 debug3_f("mux listener channel %d fd %d", in muxserver_listen()
1350 mux_listener_channel->self, mux_listener_channel->sock); in muxserver_listen()
1359 Channel *c, *cc; in mux_session_confirm()
1366 fatal_f("no channel for id %d", id); in mux_session_confirm()
1367 if ((cc = channel_by_id(ssh, c->ctl_chan)) == NULL) in mux_session_confirm()
1368 fatal_f("channel %d lacks control channel %d", in mux_session_confirm()
1369 id, c->ctl_chan); in mux_session_confirm()
1375 reply_error(reply, MUX_S_FAILURE, cctx->rid, in mux_session_confirm()
1381 if (cctx->want_x_fwd && options.forward_x11 && display != NULL) { in mux_session_confirm()
1399 if (cctx->want_agent_fwd && options.forward_agent) { in mux_session_confirm()
1401 channel_request_start(ssh, id, "auth-agent-req@openssh.com", 0); in mux_session_confirm()
1406 client_session2_setup(ssh, id, cctx->want_tty, cctx->want_subsys, in mux_session_confirm()
1407 cctx->term, &cctx->tio, c->rfd, cctx->cmd, cctx->env); in mux_session_confirm()
1412 (r = sshbuf_put_u32(reply, cctx->rid)) != 0 || in mux_session_confirm()
1413 (r = sshbuf_put_u32(reply, c->self)) != 0) in mux_session_confirm()
1418 if ((r = sshbuf_put_stringb(cc->output, reply)) != 0) in mux_session_confirm()
1422 if (cc->mux_pause <= 0) in mux_session_confirm()
1423 fatal_f("mux_pause %d", cc->mux_pause); in mux_session_confirm()
1424 cc->mux_pause = 0; /* start processing messages again */ in mux_session_confirm()
1425 c->open_confirm_ctx = NULL; in mux_session_confirm()
1426 sshbuf_free(cctx->cmd); in mux_session_confirm()
1427 free(cctx->term); in mux_session_confirm()
1428 if (cctx->env != NULL) { in mux_session_confirm()
1429 for (i = 0; cctx->env[i] != NULL; i++) in mux_session_confirm()
1430 free(cctx->env[i]); in mux_session_confirm()
1431 free(cctx->env); in mux_session_confirm()
1446 * Relay signal handler - used to pass some signals from mux client to
1473 return -1; in mux_client_read()
1475 len = read(fd, p + have, need - have); in mux_client_read()
1476 if (len == -1) { in mux_client_read()
1483 &muxclient_terminate) == -1 && in mux_client_read()
1485 return -1; /* timeout */ in mux_client_read()
1490 return -1; in mux_client_read()
1495 return -1; in mux_client_read()
1525 return -1; in mux_client_write_packet()
1527 len = write(fd, ptr + have, need - have); in mux_client_write_packet()
1528 if (len == -1) { in mux_client_write_packet()
1534 (void)poll(&pfd, 1, -1); in mux_client_write_packet()
1542 return -1; in mux_client_write_packet()
1548 return -1; in mux_client_write_packet()
1572 return -1; in mux_client_read_packet_timeout()
1580 return -1; in mux_client_read_packet_timeout()
1592 return mux_client_read_packet_timeout(fd, m, -1); in mux_client_read_packet()
1600 int r, ret = -1; in mux_client_hello_exchange()
1762 mux_client_forward(int fd, int cancel_flag, u_int ftype, struct Forward *fwd) in mux_client_forward()
1776 if (fwd->listen_path != NULL) in mux_client_forward()
1777 lhost = fwd->listen_path; in mux_client_forward()
1778 else if (fwd->listen_host == NULL) in mux_client_forward()
1780 else if (*fwd->listen_host == '\0') in mux_client_forward()
1783 lhost = fwd->listen_host; in mux_client_forward()
1785 if (fwd->connect_path != NULL) in mux_client_forward()
1786 chost = fwd->connect_path; in mux_client_forward()
1787 else if (fwd->connect_host == NULL) in mux_client_forward()
1790 chost = fwd->connect_host; in mux_client_forward()
1798 (r = sshbuf_put_u32(m, fwd->listen_port)) != 0 || in mux_client_forward()
1800 (r = sshbuf_put_u32(m, fwd->connect_port)) != 0) in mux_client_forward()
1811 return -1; in mux_client_forward()
1827 if ((r = sshbuf_get_u32(m, &fwd->allocated_port)) != 0) in mux_client_forward()
1829 verbose("Allocated port %u for remote forward to %s:%d", in mux_client_forward()
1830 fwd->allocated_port, in mux_client_forward()
1831 fwd->connect_host ? fwd->connect_host : "", in mux_client_forward()
1832 fwd->connect_port); in mux_client_forward()
1834 fprintf(stdout, "%i\n", fwd->allocated_port); in mux_client_forward()
1841 return -1; in mux_client_forward()
1847 return -1; in mux_client_forward()
1872 ret = -1; in mux_client_forwards()
1877 ret = -1; in mux_client_forwards()
1896 return -1; in mux_client_request_session()
1901 if (options.stdin_null && stdfd_devnull(1, 0, 0) == -1) in mux_client_request_session()
1944 if (mm_send_fd(fd, STDIN_FILENO) == -1 || in mux_client_request_session()
1945 mm_send_fd(fd, STDOUT_FILENO) == -1 || in mux_client_request_session()
1946 mm_send_fd(fd, STDERR_FILENO) == -1) in mux_client_request_session()
1956 return -1; in mux_client_request_session()
1977 return -1; in mux_client_request_session()
1983 return -1; in mux_client_request_session()
1987 return -1; in mux_client_request_session()
1991 if (pledge("stdio proc tty", NULL) == -1) in mux_client_request_session()
2125 return -1; in mux_client_request_stdio_fwd()
2130 if (options.stdin_null && stdfd_devnull(1, 0, 0) == -1) in mux_client_request_stdio_fwd()
2146 if (mm_send_fd(fd, STDIN_FILENO) == -1 || in mux_client_request_stdio_fwd()
2147 mm_send_fd(fd, STDOUT_FILENO) == -1) in mux_client_request_stdio_fwd()
2150 if (pledge("stdio proc tty", NULL) == -1) in mux_client_request_stdio_fwd()
2154 debug3_f("stdio forward request sent"); in mux_client_request_stdio_fwd()
2162 return -1; in mux_client_request_stdio_fwd()
2190 return -1; in mux_client_request_stdio_fwd()
2267 int sock, timeout = options.connection_timeout, timeout_ms = -1; in muxclient()
2280 debug("auto-mux: Trying existing master at '%s'", path); in muxclient()
2285 return -1; in muxclient()
2296 if ((sock = socket(PF_UNIX, SOCK_STREAM, 0)) == -1) in muxclient()
2299 if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) == -1) { in muxclient()
2319 return -1; in muxclient()
2330 return -1; in muxclient()
2346 fatal_f("master forward request failed"); in muxclient()
2350 error_f("master forward request failed"); in muxclient()
2351 return -1; in muxclient()
2354 return -1; in muxclient()
2365 error_f("master cancel forward request failed"); in muxclient()