|
Lines 132-141
muxserver_listen(void)
Link Here
|
| 132 |
old_umask = umask(0177); |
132 |
old_umask = umask(0177); |
| 133 |
if (bind(muxserver_sock, (struct sockaddr *)&addr, addr.sun_len) == -1) { |
133 |
if (bind(muxserver_sock, (struct sockaddr *)&addr, addr.sun_len) == -1) { |
| 134 |
muxserver_sock = -1; |
134 |
muxserver_sock = -1; |
| 135 |
if (errno == EINVAL || errno == EADDRINUSE) |
135 |
if (errno == EINVAL || errno == EADDRINUSE) { |
| 136 |
fatal("ControlSocket %s already exists", |
136 |
error("ControlSocket %s already exists, " |
| 137 |
options.control_path); |
137 |
"disabling multiplexing", options.control_path); |
| 138 |
else |
138 |
close(muxserver_sock); |
|
|
139 |
muxserver_sock = -1; |
| 140 |
xfree(options.control_path); |
| 141 |
options.control_path = NULL; |
| 142 |
options.control_master = SSHCTL_MASTER_NO; |
| 143 |
return; |
| 144 |
} else |
| 139 |
fatal("%s bind(): %s", __func__, strerror(errno)); |
145 |
fatal("%s bind(): %s", __func__, strerror(errno)); |
| 140 |
} |
146 |
} |
| 141 |
umask(old_umask); |
147 |
umask(old_umask); |
|
Lines 487-493
muxclient(const char *path)
Link Here
|
| 487 |
Buffer m; |
493 |
Buffer m; |
| 488 |
char *term; |
494 |
char *term; |
| 489 |
extern char **environ; |
495 |
extern char **environ; |
| 490 |
u_int flags; |
496 |
u_int allowed, flags; |
| 491 |
|
497 |
|
| 492 |
if (muxclient_command == 0) |
498 |
if (muxclient_command == 0) |
| 493 |
muxclient_command = SSHMUX_COMMAND_OPEN; |
499 |
muxclient_command = SSHMUX_COMMAND_OPEN; |
|
Lines 558-574
muxclient(const char *path)
Link Here
|
| 558 |
/* Send our command to server */ |
564 |
/* Send our command to server */ |
| 559 |
buffer_put_int(&m, muxclient_command); |
565 |
buffer_put_int(&m, muxclient_command); |
| 560 |
buffer_put_int(&m, flags); |
566 |
buffer_put_int(&m, flags); |
| 561 |
if (ssh_msg_send(sock, SSHMUX_VER, &m) == -1) |
567 |
if (ssh_msg_send(sock, SSHMUX_VER, &m) == -1) { |
| 562 |
fatal("%s: msg_send", __func__); |
568 |
error("%s: msg_send", __func__); |
|
|
569 |
muxerr: |
| 570 |
close(sock); |
| 571 |
buffer_free(&m); |
| 572 |
if (muxclient_command != SSHMUX_COMMAND_OPEN) |
| 573 |
cleanup_exit(255); |
| 574 |
logit("Falling back to non-multiplexed connection"); |
| 575 |
xfree(options.control_path); |
| 576 |
options.control_path = NULL; |
| 577 |
options.control_master = SSHCTL_MASTER_NO; |
| 578 |
return; |
| 579 |
} |
| 563 |
buffer_clear(&m); |
580 |
buffer_clear(&m); |
| 564 |
|
581 |
|
| 565 |
/* Get authorisation status and PID of controlee */ |
582 |
/* Get authorisation status and PID of controlee */ |
| 566 |
if (ssh_msg_recv(sock, &m) == -1) |
583 |
if (ssh_msg_recv(sock, &m) == -1) { |
| 567 |
fatal("%s: msg_recv", __func__); |
584 |
error("%s: msg_recv", __func__); |
| 568 |
if (buffer_get_char(&m) != SSHMUX_VER) |
585 |
goto muxerr; |
| 569 |
fatal("%s: wrong version", __func__); |
586 |
} |
| 570 |
if (buffer_get_int(&m) != 1) |
587 |
if (buffer_get_char(&m) != SSHMUX_VER) { |
| 571 |
fatal("Connection to master denied"); |
588 |
error("%s: wrong version", __func__); |
|
|
589 |
goto muxerr; |
| 590 |
} |
| 591 |
if (buffer_get_int_ret(&allowed, &m) != 0) { |
| 592 |
error("%s: bad server reply", __func__); |
| 593 |
goto muxerr; |
| 594 |
} |
| 595 |
if (allowed != 1) { |
| 596 |
error("Connection to master denied"); |
| 597 |
goto muxerr; |
| 598 |
} |
| 572 |
muxserver_pid = buffer_get_int(&m); |
599 |
muxserver_pid = buffer_get_int(&m); |
| 573 |
|
600 |
|
| 574 |
buffer_clear(&m); |
601 |
buffer_clear(&m); |
|
Lines 612-624
muxclient(const char *path)
Link Here
|
| 612 |
fatal("unrecognised muxclient_command %d", muxclient_command); |
639 |
fatal("unrecognised muxclient_command %d", muxclient_command); |
| 613 |
} |
640 |
} |
| 614 |
|
641 |
|
| 615 |
if (ssh_msg_send(sock, SSHMUX_VER, &m) == -1) |
642 |
if (ssh_msg_send(sock, SSHMUX_VER, &m) == -1) { |
| 616 |
fatal("%s: msg_send", __func__); |
643 |
error("%s: msg_send", __func__); |
|
|
644 |
goto muxerr; |
| 645 |
} |
| 617 |
|
646 |
|
| 618 |
if (mm_send_fd(sock, STDIN_FILENO) == -1 || |
647 |
if (mm_send_fd(sock, STDIN_FILENO) == -1 || |
| 619 |
mm_send_fd(sock, STDOUT_FILENO) == -1 || |
648 |
mm_send_fd(sock, STDOUT_FILENO) == -1 || |
| 620 |
mm_send_fd(sock, STDERR_FILENO) == -1) |
649 |
mm_send_fd(sock, STDERR_FILENO) == -1) { |
| 621 |
fatal("%s: send fds failed", __func__); |
650 |
error("%s: send fds failed", __func__); |
|
|
651 |
goto muxerr; |
| 652 |
} |
| 653 |
|
| 654 |
/* |
| 655 |
* Mux errors are non-recoverable from this point as the master |
| 656 |
* has ownership of the session now. |
| 657 |
*/ |
| 622 |
|
658 |
|
| 623 |
/* Wait for reply, so master has a chance to gather ttymodes */ |
659 |
/* Wait for reply, so master has a chance to gather ttymodes */ |
| 624 |
buffer_clear(&m); |
660 |
buffer_clear(&m); |