version 1.107, 2013/10/10 12:13:29 |
version 1.108, 2013/10/10 12:13:56 |
|
|
int server_client_assume_paste(struct session *); |
int server_client_assume_paste(struct session *); |
|
|
int server_client_msg_dispatch(struct client *); |
int server_client_msg_dispatch(struct client *); |
void server_client_msg_command(struct client *, struct msg_command_data *); |
void server_client_msg_command(struct client *, struct imsg *); |
void server_client_msg_identify( |
void server_client_msg_identify( |
struct client *, struct msg_identify_data *, int); |
struct client *, struct msg_identify_data *, int); |
void server_client_msg_shell(struct client *); |
void server_client_msg_shell(struct client *); |
|
|
server_client_msg_dispatch(struct client *c) |
server_client_msg_dispatch(struct client *c) |
{ |
{ |
struct imsg imsg; |
struct imsg imsg; |
struct msg_command_data commanddata; |
|
struct msg_identify_data identifydata; |
struct msg_identify_data identifydata; |
struct msg_environ_data environdata; |
struct msg_environ_data environdata; |
struct msg_stdin_data stdindata; |
struct msg_stdin_data stdindata; |
|
const char *data; |
ssize_t n, datalen; |
ssize_t n, datalen; |
|
|
if ((n = imsg_read(&c->ibuf)) == -1 || n == 0) |
if ((n = imsg_read(&c->ibuf)) == -1 || n == 0) |
|
|
return (-1); |
return (-1); |
if (n == 0) |
if (n == 0) |
return (0); |
return (0); |
|
|
|
data = imsg.data; |
datalen = imsg.hdr.len - IMSG_HEADER_SIZE; |
datalen = imsg.hdr.len - IMSG_HEADER_SIZE; |
|
|
if (imsg.hdr.peerid != PROTOCOL_VERSION) { |
if (imsg.hdr.peerid != PROTOCOL_VERSION) { |
|
|
|
|
log_debug("got %d from client %d", imsg.hdr.type, c->ibuf.fd); |
log_debug("got %d from client %d", imsg.hdr.type, c->ibuf.fd); |
switch (imsg.hdr.type) { |
switch (imsg.hdr.type) { |
case MSG_COMMAND: |
|
if (datalen != sizeof commanddata) |
|
fatalx("bad MSG_COMMAND size"); |
|
memcpy(&commanddata, imsg.data, sizeof commanddata); |
|
|
|
server_client_msg_command(c, &commanddata); |
|
break; |
|
case MSG_IDENTIFY: |
case MSG_IDENTIFY: |
if (datalen != sizeof identifydata) |
if (datalen != sizeof identifydata) |
fatalx("bad MSG_IDENTIFY size"); |
fatalx("bad MSG_IDENTIFY size"); |
|
|
|
|
server_client_msg_identify(c, &identifydata, imsg.fd); |
server_client_msg_identify(c, &identifydata, imsg.fd); |
break; |
break; |
|
case MSG_COMMAND: |
|
server_client_msg_command(c, &imsg); |
|
break; |
case MSG_STDIN: |
case MSG_STDIN: |
if (datalen != sizeof stdindata) |
if (datalen != sizeof stdindata) |
fatalx("bad MSG_STDIN size"); |
fatalx("bad MSG_STDIN size"); |
memcpy(&stdindata, imsg.data, sizeof stdindata); |
memcpy(&stdindata, data, sizeof stdindata); |
|
|
if (c->stdin_callback == NULL) |
if (c->stdin_callback == NULL) |
break; |
break; |
|
|
|
|
/* Handle command message. */ |
/* Handle command message. */ |
void |
void |
server_client_msg_command(struct client *c, struct msg_command_data *data) |
server_client_msg_command(struct client *c, struct imsg *imsg) |
{ |
{ |
struct cmd_list *cmdlist = NULL; |
struct msg_command_data data; |
int argc; |
char *buf; |
char **argv, *cause; |
size_t len; |
|
struct cmd_list *cmdlist = NULL; |
|
int argc; |
|
char **argv, *cause; |
|
|
argc = data->argc; |
if (imsg->hdr.len - IMSG_HEADER_SIZE < sizeof data) |
data->argv[(sizeof data->argv) - 1] = '\0'; |
fatalx("bad MSG_COMMAND size"); |
if (cmd_unpack_argv(data->argv, sizeof data->argv, argc, &argv) != 0) { |
memcpy(&data, imsg->data, sizeof data); |
|
|
|
buf = (char*)imsg->data + sizeof data; |
|
len = imsg->hdr.len - IMSG_HEADER_SIZE - sizeof data; |
|
if (len > 0 && buf[len - 1] != '\0') |
|
fatalx("bad MSG_COMMAND string"); |
|
|
|
argc = data.argc; |
|
if (cmd_unpack_argv(buf, len, argc, &argv) != 0) { |
cmdq_error(c->cmdq, "command too long"); |
cmdq_error(c->cmdq, "command too long"); |
goto error; |
goto error; |
} |
} |