version 1.40, 2013/04/22 01:17:18 |
version 1.41, 2013/05/17 00:13:13 |
|
|
char *value = buffer_get_string_ret(m, NULL); |
char *value = buffer_get_string_ret(m, NULL); |
|
|
if (name == NULL || value == NULL) { |
if (name == NULL || value == NULL) { |
if (name != NULL) |
free(name); |
xfree(name); |
|
goto malf; |
goto malf; |
} |
} |
debug2("Unrecognised slave extension \"%s\"", name); |
debug2("Unrecognised slave extension \"%s\"", name); |
xfree(name); |
free(name); |
xfree(value); |
free(value); |
} |
} |
state->hello_rcvd = 1; |
state->hello_rcvd = 1; |
return 0; |
return 0; |
|
|
(cctx->term = buffer_get_string_ret(m, &len)) == NULL || |
(cctx->term = buffer_get_string_ret(m, &len)) == NULL || |
(cmd = buffer_get_string_ret(m, &len)) == NULL) { |
(cmd = buffer_get_string_ret(m, &len)) == NULL) { |
malf: |
malf: |
if (cmd != NULL) |
free(cmd); |
xfree(cmd); |
free(reserved); |
if (reserved != NULL) |
|
xfree(reserved); |
|
for (j = 0; j < env_len; j++) |
for (j = 0; j < env_len; j++) |
xfree(cctx->env[j]); |
free(cctx->env[j]); |
if (env_len > 0) |
free(cctx->env); |
xfree(cctx->env); |
free(cctx->term); |
if (cctx->term != NULL) |
free(cctx); |
xfree(cctx->term); |
|
xfree(cctx); |
|
error("%s: malformed message", __func__); |
error("%s: malformed message", __func__); |
return -1; |
return -1; |
} |
} |
xfree(reserved); |
free(reserved); |
reserved = NULL; |
reserved = NULL; |
|
|
while (buffer_len(m) > 0) { |
while (buffer_len(m) > 0) { |
|
|
if ((cp = buffer_get_string_ret(m, &len)) == NULL) |
if ((cp = buffer_get_string_ret(m, &len)) == NULL) |
goto malf; |
goto malf; |
if (!env_permitted(cp)) { |
if (!env_permitted(cp)) { |
xfree(cp); |
free(cp); |
continue; |
continue; |
} |
} |
cctx->env = xrealloc(cctx->env, env_len + 2, |
cctx->env = xrealloc(cctx->env, env_len + 2, |
|
|
|
|
buffer_init(&cctx->cmd); |
buffer_init(&cctx->cmd); |
buffer_append(&cctx->cmd, cmd, strlen(cmd)); |
buffer_append(&cctx->cmd, cmd, strlen(cmd)); |
xfree(cmd); |
free(cmd); |
cmd = NULL; |
cmd = NULL; |
|
|
/* Gather fds from client */ |
/* Gather fds from client */ |
|
|
for (j = 0; j < i; j++) |
for (j = 0; j < i; j++) |
close(new_fd[j]); |
close(new_fd[j]); |
for (j = 0; j < env_len; j++) |
for (j = 0; j < env_len; j++) |
xfree(cctx->env[j]); |
free(cctx->env[j]); |
if (env_len > 0) |
free(cctx->env); |
xfree(cctx->env); |
free(cctx->term); |
xfree(cctx->term); |
|
buffer_free(&cctx->cmd); |
buffer_free(&cctx->cmd); |
xfree(cctx); |
free(cctx); |
|
|
/* prepare reply */ |
/* prepare reply */ |
buffer_put_int(r, MUX_S_FAILURE); |
buffer_put_int(r, MUX_S_FAILURE); |
|
|
close(new_fd[0]); |
close(new_fd[0]); |
close(new_fd[1]); |
close(new_fd[1]); |
close(new_fd[2]); |
close(new_fd[2]); |
xfree(cctx->term); |
free(cctx->term); |
if (env_len != 0) { |
if (env_len != 0) { |
for (i = 0; i < env_len; i++) |
for (i = 0; i < env_len; i++) |
xfree(cctx->env[i]); |
free(cctx->env[i]); |
xfree(cctx->env); |
free(cctx->env); |
} |
} |
buffer_free(&cctx->cmd); |
buffer_free(&cctx->cmd); |
xfree(cctx); |
free(cctx); |
return 0; |
return 0; |
} |
} |
|
|
|
|
buffer_put_int(&out, MUX_S_FAILURE); |
buffer_put_int(&out, MUX_S_FAILURE); |
buffer_put_int(&out, fctx->rid); |
buffer_put_int(&out, fctx->rid); |
buffer_put_cstring(&out, failmsg); |
buffer_put_cstring(&out, failmsg); |
xfree(failmsg); |
free(failmsg); |
out: |
out: |
buffer_put_string(&c->output, buffer_ptr(&out), buffer_len(&out)); |
buffer_put_string(&c->output, buffer_ptr(&out), buffer_len(&out)); |
buffer_free(&out); |
buffer_free(&out); |
|
|
} |
} |
|
|
if (*fwd.listen_host == '\0') { |
if (*fwd.listen_host == '\0') { |
xfree(fwd.listen_host); |
free(fwd.listen_host); |
fwd.listen_host = NULL; |
fwd.listen_host = NULL; |
} |
} |
if (*fwd.connect_host == '\0') { |
if (*fwd.connect_host == '\0') { |
xfree(fwd.connect_host); |
free(fwd.connect_host); |
fwd.connect_host = NULL; |
fwd.connect_host = NULL; |
} |
} |
|
|
|
|
ftype != MUX_FWD_DYNAMIC) { |
ftype != MUX_FWD_DYNAMIC) { |
logit("%s: invalid forwarding type %u", __func__, ftype); |
logit("%s: invalid forwarding type %u", __func__, ftype); |
invalid: |
invalid: |
if (fwd.listen_host) |
free(fwd.listen_host); |
xfree(fwd.listen_host); |
free(fwd.connect_host); |
if (fwd.connect_host) |
|
xfree(fwd.connect_host); |
|
buffer_put_int(r, MUX_S_FAILURE); |
buffer_put_int(r, MUX_S_FAILURE); |
buffer_put_int(r, rid); |
buffer_put_int(r, rid); |
buffer_put_cstring(r, "Invalid forwarding request"); |
buffer_put_cstring(r, "Invalid forwarding request"); |
|
|
buffer_put_int(r, MUX_S_OK); |
buffer_put_int(r, MUX_S_OK); |
buffer_put_int(r, rid); |
buffer_put_int(r, rid); |
out: |
out: |
if (fwd_desc != NULL) |
free(fwd_desc); |
xfree(fwd_desc); |
|
if (freefwd) { |
if (freefwd) { |
if (fwd.listen_host != NULL) |
free(fwd.listen_host); |
xfree(fwd.listen_host); |
free(fwd.connect_host); |
if (fwd.connect_host != NULL) |
|
xfree(fwd.connect_host); |
|
} |
} |
return ret; |
return ret; |
} |
} |
|
|
} |
} |
|
|
if (*fwd.listen_host == '\0') { |
if (*fwd.listen_host == '\0') { |
xfree(fwd.listen_host); |
free(fwd.listen_host); |
fwd.listen_host = NULL; |
fwd.listen_host = NULL; |
} |
} |
if (*fwd.connect_host == '\0') { |
if (*fwd.connect_host == '\0') { |
xfree(fwd.connect_host); |
free(fwd.connect_host); |
fwd.connect_host = NULL; |
fwd.connect_host = NULL; |
} |
} |
|
|
|
|
buffer_put_int(r, MUX_S_OK); |
buffer_put_int(r, MUX_S_OK); |
buffer_put_int(r, rid); |
buffer_put_int(r, rid); |
|
|
if (found_fwd->listen_host != NULL) |
free(found_fwd->listen_host); |
xfree(found_fwd->listen_host); |
free(found_fwd->connect_host); |
if (found_fwd->connect_host != NULL) |
|
xfree(found_fwd->connect_host); |
|
found_fwd->listen_host = found_fwd->connect_host = NULL; |
found_fwd->listen_host = found_fwd->connect_host = NULL; |
found_fwd->listen_port = found_fwd->connect_port = 0; |
found_fwd->listen_port = found_fwd->connect_port = 0; |
} else { |
} else { |
|
|
buffer_put_cstring(r, error_reason); |
buffer_put_cstring(r, error_reason); |
} |
} |
out: |
out: |
if (fwd_desc != NULL) |
free(fwd_desc); |
xfree(fwd_desc); |
free(fwd.listen_host); |
if (fwd.listen_host != NULL) |
free(fwd.connect_host); |
xfree(fwd.listen_host); |
|
if (fwd.connect_host != NULL) |
|
xfree(fwd.connect_host); |
|
|
|
return ret; |
return ret; |
} |
} |
|
|
if ((reserved = buffer_get_string_ret(m, NULL)) == NULL || |
if ((reserved = buffer_get_string_ret(m, NULL)) == NULL || |
(chost = buffer_get_string_ret(m, NULL)) == NULL || |
(chost = buffer_get_string_ret(m, NULL)) == NULL || |
buffer_get_int_ret(&cport, m) != 0) { |
buffer_get_int_ret(&cport, m) != 0) { |
if (reserved != NULL) |
free(reserved); |
xfree(reserved); |
free(chost); |
if (chost != NULL) |
|
xfree(chost); |
|
error("%s: malformed message", __func__); |
error("%s: malformed message", __func__); |
return -1; |
return -1; |
} |
} |
xfree(reserved); |
free(reserved); |
|
|
debug2("%s: channel %d: request stdio fwd to %s:%u", |
debug2("%s: channel %d: request stdio fwd to %s:%u", |
__func__, c->self, chost, cport); |
__func__, c->self, chost, cport); |
|
|
__func__, i); |
__func__, i); |
for (j = 0; j < i; j++) |
for (j = 0; j < i; j++) |
close(new_fd[j]); |
close(new_fd[j]); |
xfree(chost); |
free(chost); |
|
|
/* prepare reply */ |
/* prepare reply */ |
buffer_put_int(r, MUX_S_FAILURE); |
buffer_put_int(r, MUX_S_FAILURE); |
|
|
cleanup: |
cleanup: |
close(new_fd[0]); |
close(new_fd[0]); |
close(new_fd[1]); |
close(new_fd[1]); |
xfree(chost); |
free(chost); |
return 0; |
return 0; |
} |
} |
|
|
|
|
if (mux_listener_channel != NULL) { |
if (mux_listener_channel != NULL) { |
channel_free(mux_listener_channel); |
channel_free(mux_listener_channel); |
client_stop_mux(); |
client_stop_mux(); |
xfree(options.control_path); |
free(options.control_path); |
options.control_path = NULL; |
options.control_path = NULL; |
mux_listener_channel = NULL; |
mux_listener_channel = NULL; |
muxserver_sock = -1; |
muxserver_sock = -1; |
|
|
close(muxserver_sock); |
close(muxserver_sock); |
muxserver_sock = -1; |
muxserver_sock = -1; |
} |
} |
xfree(orig_control_path); |
free(orig_control_path); |
xfree(options.control_path); |
free(options.control_path); |
options.control_path = NULL; |
options.control_path = NULL; |
options.control_master = SSHCTL_MASTER_NO; |
options.control_master = SSHCTL_MASTER_NO; |
return; |
return; |
|
|
goto disable_mux_master; |
goto disable_mux_master; |
} |
} |
unlink(options.control_path); |
unlink(options.control_path); |
xfree(options.control_path); |
free(options.control_path); |
options.control_path = orig_control_path; |
options.control_path = orig_control_path; |
|
|
set_nonblock(muxserver_sock); |
set_nonblock(muxserver_sock); |
|
|
cc->mux_pause = 0; /* start processing messages again */ |
cc->mux_pause = 0; /* start processing messages again */ |
c->open_confirm_ctx = NULL; |
c->open_confirm_ctx = NULL; |
buffer_free(&cctx->cmd); |
buffer_free(&cctx->cmd); |
xfree(cctx->term); |
free(cctx->term); |
if (cctx->env != NULL) { |
if (cctx->env != NULL) { |
for (i = 0; cctx->env[i] != NULL; i++) |
for (i = 0; cctx->env[i] != NULL; i++) |
xfree(cctx->env[i]); |
free(cctx->env[i]); |
xfree(cctx->env); |
free(cctx->env); |
} |
} |
xfree(cctx); |
free(cctx); |
} |
} |
|
|
/* ** Multiplexing client support */ |
/* ** Multiplexing client support */ |
|
|
char *value = buffer_get_string(&m, NULL); |
char *value = buffer_get_string(&m, NULL); |
|
|
debug2("Unrecognised master extension \"%s\"", name); |
debug2("Unrecognised master extension \"%s\"", name); |
xfree(name); |
free(name); |
xfree(value); |
free(value); |
} |
} |
buffer_free(&m); |
buffer_free(&m); |
return 0; |
return 0; |
|
|
fwd_desc = format_forward(ftype, fwd); |
fwd_desc = format_forward(ftype, fwd); |
debug("Requesting %s %s", |
debug("Requesting %s %s", |
cancel_flag ? "cancellation of" : "forwarding of", fwd_desc); |
cancel_flag ? "cancellation of" : "forwarding of", fwd_desc); |
xfree(fwd_desc); |
free(fwd_desc); |
|
|
buffer_init(&m); |
buffer_init(&m); |
buffer_put_int(&m, cancel_flag ? MUX_C_CLOSE_FWD : MUX_C_OPEN_FWD); |
buffer_put_int(&m, cancel_flag ? MUX_C_CLOSE_FWD : MUX_C_OPEN_FWD); |