|
Lines 886-891
check_agent_present(void)
Link Here
|
| 886 |
} |
886 |
} |
| 887 |
|
887 |
|
| 888 |
static int |
888 |
static int |
|
|
889 |
ssh_control_listener(void) |
| 890 |
{ |
| 891 |
struct sockaddr_un addr; |
| 892 |
mode_t old_umask; |
| 893 |
int addr_len; |
| 894 |
|
| 895 |
if (options.control_path == NULL || |
| 896 |
options.control_master == SSHCTL_MASTER_NO || |
| 897 |
control_fd != -1) |
| 898 |
return 1; |
| 899 |
|
| 900 |
debug("trying to set up multiplex master socket"); |
| 901 |
|
| 902 |
memset(&addr, '\0', sizeof(addr)); |
| 903 |
addr.sun_family = AF_UNIX; |
| 904 |
addr_len = offsetof(struct sockaddr_un, sun_path) + |
| 905 |
strlen(options.control_path) + 1; |
| 906 |
|
| 907 |
if (strlcpy(addr.sun_path, options.control_path, |
| 908 |
sizeof(addr.sun_path)) >= sizeof(addr.sun_path)) |
| 909 |
fatal("ControlPath too long"); |
| 910 |
|
| 911 |
if ((control_fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) |
| 912 |
fatal("%s socket(): %s", __func__, strerror(errno)); |
| 913 |
|
| 914 |
old_umask = umask(0177); |
| 915 |
if (bind(control_fd, (struct sockaddr *)&addr, addr_len) == -1) { |
| 916 |
control_fd = -1; |
| 917 |
if (errno != EINVAL && errno != EADDRINUSE) |
| 918 |
fatal("%s bind(): %s", __func__, strerror(errno)); |
| 919 |
return 0; |
| 920 |
} |
| 921 |
umask(old_umask); |
| 922 |
|
| 923 |
if (listen(control_fd, 64) == -1) |
| 924 |
fatal("%s listen(): %s", __func__, strerror(errno)); |
| 925 |
|
| 926 |
set_nonblock(control_fd); |
| 927 |
|
| 928 |
debug("control master listening on %s", options.control_path); |
| 929 |
return 1; |
| 930 |
} |
| 931 |
|
| 932 |
static int |
| 889 |
ssh_session(void) |
933 |
ssh_session(void) |
| 890 |
{ |
934 |
{ |
| 891 |
int type; |
935 |
int type; |
|
Lines 994-999
ssh_session(void)
Link Here
|
| 994 |
|
1038 |
|
| 995 |
/* Initiate port forwardings. */ |
1039 |
/* Initiate port forwardings. */ |
| 996 |
ssh_init_forwarding(); |
1040 |
ssh_init_forwarding(); |
|
|
1041 |
if (!ssh_control_listener()) |
| 1042 |
fatal("control master socket %s already exists", |
| 1043 |
options.control_path); |
| 997 |
|
1044 |
|
| 998 |
/* If requested, let ssh continue in the background. */ |
1045 |
/* If requested, let ssh continue in the background. */ |
| 999 |
if (fork_after_authentication_flag) |
1046 |
if (fork_after_authentication_flag) |
|
Lines 1065-1112
client_global_request_reply_fwd(int type
Link Here
|
| 1065 |
} |
1112 |
} |
| 1066 |
} |
1113 |
} |
| 1067 |
|
1114 |
|
| 1068 |
static void |
|
|
| 1069 |
ssh_control_listener(void) |
| 1070 |
{ |
| 1071 |
struct sockaddr_un addr; |
| 1072 |
mode_t old_umask; |
| 1073 |
int addr_len; |
| 1074 |
|
| 1075 |
if (options.control_path == NULL || |
| 1076 |
options.control_master == SSHCTL_MASTER_NO) |
| 1077 |
return; |
| 1078 |
|
| 1079 |
debug("setting up multiplex master socket"); |
| 1080 |
|
| 1081 |
memset(&addr, '\0', sizeof(addr)); |
| 1082 |
addr.sun_family = AF_UNIX; |
| 1083 |
addr_len = offsetof(struct sockaddr_un, sun_path) + |
| 1084 |
strlen(options.control_path) + 1; |
| 1085 |
|
| 1086 |
if (strlcpy(addr.sun_path, options.control_path, |
| 1087 |
sizeof(addr.sun_path)) >= sizeof(addr.sun_path)) |
| 1088 |
fatal("ControlPath too long"); |
| 1089 |
|
| 1090 |
if ((control_fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) |
| 1091 |
fatal("%s socket(): %s", __func__, strerror(errno)); |
| 1092 |
|
| 1093 |
old_umask = umask(0177); |
| 1094 |
if (bind(control_fd, (struct sockaddr *)&addr, addr_len) == -1) { |
| 1095 |
control_fd = -1; |
| 1096 |
if (errno == EINVAL || errno == EADDRINUSE) |
| 1097 |
fatal("ControlSocket %s already exists", |
| 1098 |
options.control_path); |
| 1099 |
else |
| 1100 |
fatal("%s bind(): %s", __func__, strerror(errno)); |
| 1101 |
} |
| 1102 |
umask(old_umask); |
| 1103 |
|
| 1104 |
if (listen(control_fd, 64) == -1) |
| 1105 |
fatal("%s listen(): %s", __func__, strerror(errno)); |
| 1106 |
|
| 1107 |
set_nonblock(control_fd); |
| 1108 |
} |
| 1109 |
|
| 1110 |
/* request pty/x11/agent/tcpfwd/shell for channel */ |
1115 |
/* request pty/x11/agent/tcpfwd/shell for channel */ |
| 1111 |
static void |
1116 |
static void |
| 1112 |
ssh_session2_setup(int id, void *arg) |
1117 |
ssh_session2_setup(int id, void *arg) |
|
Lines 1375-1381
control_client(const char *path)
Link Here
|
| 1375 |
switch (options.control_master) { |
1380 |
switch (options.control_master) { |
| 1376 |
case SSHCTL_MASTER_AUTO: |
1381 |
case SSHCTL_MASTER_AUTO: |
| 1377 |
case SSHCTL_MASTER_AUTO_ASK: |
1382 |
case SSHCTL_MASTER_AUTO_ASK: |
| 1378 |
debug("auto-mux: Trying existing master"); |
1383 |
/* see if we can create a control master socket |
|
|
1384 |
to avoid a race between two auto clients */ |
| 1385 |
if (mux_command == SSHMUX_COMMAND_OPEN && |
| 1386 |
ssh_control_listener()) |
| 1387 |
return; |
| 1388 |
debug("trying to connect to control master socket %s", |
| 1389 |
options.control_path); |
| 1379 |
/* FALLTHROUGH */ |
1390 |
/* FALLTHROUGH */ |
| 1380 |
case SSHCTL_MASTER_NO: |
1391 |
case SSHCTL_MASTER_NO: |
| 1381 |
break; |
1392 |
break; |
|
Lines 1522-1527
control_client(const char *path)
Link Here
|
| 1522 |
signal(SIGTERM, control_client_sighandler); |
1533 |
signal(SIGTERM, control_client_sighandler); |
| 1523 |
signal(SIGWINCH, control_client_sigrelay); |
1534 |
signal(SIGWINCH, control_client_sigrelay); |
| 1524 |
|
1535 |
|
|
|
1536 |
debug("connected to control master; waiting for exit"); |
| 1537 |
|
| 1525 |
if (tty_flag) |
1538 |
if (tty_flag) |
| 1526 |
enter_raw_mode(); |
1539 |
enter_raw_mode(); |
| 1527 |
|
1540 |
|