1
1

buffers: adapt sftpserver.c to ssh_buffer_(un)pack()

Reviewed-by: Andreas Schneider <asn@samba.org>
Этот коммит содержится в:
Aris Adamantiadis 2014-04-22 18:46:45 +02:00 коммит произвёл Andreas Schneider
родитель c341da03d3
Коммит 7bd62dd652

Просмотреть файл

@ -42,7 +42,7 @@ sftp_client_message sftp_get_client_message(sftp_session sftp) {
sftp_packet packet; sftp_packet packet;
sftp_client_message msg; sftp_client_message msg;
ssh_buffer payload; ssh_buffer payload;
ssh_string tmp; int rc;
msg = malloc(sizeof (struct sftp_client_message_struct)); msg = malloc(sizeof (struct sftp_client_message_struct));
if (msg == NULL) { if (msg == NULL) {
@ -81,25 +81,24 @@ sftp_client_message sftp_get_client_message(sftp_session sftp) {
} }
break; break;
case SSH_FXP_READ: case SSH_FXP_READ:
msg->handle = buffer_get_ssh_string(payload); rc = ssh_buffer_unpack(payload,
if (msg->handle == NULL) { "Sqd",
&msg->handle,
&msg->offset,
&msg->len);
if (rc != SSH_OK) {
ssh_set_error_oom(session); ssh_set_error_oom(session);
sftp_client_message_free(msg); sftp_client_message_free(msg);
return NULL; return NULL;
} }
buffer_get_u64(payload, &msg->offset);
buffer_get_u32(payload, &msg->len);
break; break;
case SSH_FXP_WRITE: case SSH_FXP_WRITE:
msg->handle = buffer_get_ssh_string(payload); rc = ssh_buffer_unpack(payload,
if (msg->handle == NULL) { "SqS",
ssh_set_error_oom(session); &msg->handle,
sftp_client_message_free(msg); &msg->offset,
return NULL; &msg->data);
} if (rc != SSH_OK) {
buffer_get_u64(payload, &msg->offset);
msg->data = buffer_get_ssh_string(payload);
if (msg->data == NULL) {
ssh_set_error_oom(session); ssh_set_error_oom(session);
sftp_client_message_free(msg); sftp_client_message_free(msg);
return NULL; return NULL;
@ -110,15 +109,10 @@ sftp_client_message sftp_get_client_message(sftp_session sftp) {
case SSH_FXP_OPENDIR: case SSH_FXP_OPENDIR:
case SSH_FXP_READLINK: case SSH_FXP_READLINK:
case SSH_FXP_REALPATH: case SSH_FXP_REALPATH:
tmp = buffer_get_ssh_string(payload); rc = ssh_buffer_unpack(payload,
if (tmp == NULL) { "s",
ssh_set_error_oom(session); &msg->filename);
sftp_client_message_free(msg); if (rc != SSH_OK) {
return NULL;
}
msg->filename = ssh_string_to_char(tmp);
ssh_string_free(tmp);
if (msg->filename == NULL) {
ssh_set_error_oom(session); ssh_set_error_oom(session);
sftp_client_message_free(msg); sftp_client_message_free(msg);
return NULL; return NULL;
@ -126,21 +120,11 @@ sftp_client_message sftp_get_client_message(sftp_session sftp) {
break; break;
case SSH_FXP_RENAME: case SSH_FXP_RENAME:
case SSH_FXP_SYMLINK: case SSH_FXP_SYMLINK:
tmp = buffer_get_ssh_string(payload); rc = ssh_buffer_unpack(payload,
if (tmp == NULL) { "sS",
ssh_set_error_oom(session); &msg->filename,
sftp_client_message_free(msg); &msg->data);
return NULL; if (rc != SSH_OK) {
}
msg->filename = ssh_string_to_char(tmp);
ssh_string_free(tmp);
if (msg->filename == NULL) {
ssh_set_error_oom(session);
sftp_client_message_free(msg);
return NULL;
}
msg->data = buffer_get_ssh_string(payload);
if (msg->data == NULL) {
ssh_set_error_oom(session); ssh_set_error_oom(session);
sftp_client_message_free(msg); sftp_client_message_free(msg);
return NULL; return NULL;
@ -148,15 +132,10 @@ sftp_client_message sftp_get_client_message(sftp_session sftp) {
break; break;
case SSH_FXP_MKDIR: case SSH_FXP_MKDIR:
case SSH_FXP_SETSTAT: case SSH_FXP_SETSTAT:
tmp = buffer_get_ssh_string(payload); rc = ssh_buffer_unpack(payload,
if (tmp == NULL) { "s",
ssh_set_error_oom(session); &msg->filename);
sftp_client_message_free(msg); if (rc != SSH_OK) {
return NULL;
}
msg->filename=ssh_string_to_char(tmp);
ssh_string_free(tmp);
if (msg->filename == NULL) {
ssh_set_error_oom(session); ssh_set_error_oom(session);
sftp_client_message_free(msg); sftp_client_message_free(msg);
return NULL; return NULL;
@ -184,38 +163,28 @@ sftp_client_message sftp_get_client_message(sftp_session sftp) {
break; break;
case SSH_FXP_LSTAT: case SSH_FXP_LSTAT:
case SSH_FXP_STAT: case SSH_FXP_STAT:
tmp = buffer_get_ssh_string(payload); rc = ssh_buffer_unpack(payload,
if (tmp == NULL) { "s",
ssh_set_error_oom(session); &msg->filename);
sftp_client_message_free(msg); if (rc != SSH_OK) {
return NULL;
}
msg->filename = ssh_string_to_char(tmp);
ssh_string_free(tmp);
if (msg->filename == NULL) {
ssh_set_error_oom(session); ssh_set_error_oom(session);
sftp_client_message_free(msg); sftp_client_message_free(msg);
return NULL; return NULL;
} }
if(sftp->version > 3) { if(sftp->version > 3) {
buffer_get_u32(payload,&msg->flags); ssh_buffer_unpack(payload, "d", &msg->flags);
} }
break; break;
case SSH_FXP_OPEN: case SSH_FXP_OPEN:
tmp=buffer_get_ssh_string(payload); rc = ssh_buffer_unpack(payload,
if (tmp == NULL) { "sd",
&msg->filename,
&msg->flags);
if (rc != SSH_OK) {
ssh_set_error_oom(session); ssh_set_error_oom(session);
sftp_client_message_free(msg); sftp_client_message_free(msg);
return NULL; return NULL;
} }
msg->filename = ssh_string_to_char(tmp);
ssh_string_free(tmp);
if (msg->filename == NULL) {
ssh_set_error_oom(session);
sftp_client_message_free(msg);
return NULL;
}
buffer_get_u32(payload,&msg->flags);
msg->attr = sftp_parse_attr(sftp, payload, 0); msg->attr = sftp_parse_attr(sftp, payload, 0);
if (msg->attr == NULL) { if (msg->attr == NULL) {
ssh_set_error_oom(session); ssh_set_error_oom(session);
@ -224,13 +193,15 @@ sftp_client_message sftp_get_client_message(sftp_session sftp) {
} }
break; break;
case SSH_FXP_FSTAT: case SSH_FXP_FSTAT:
msg->handle = buffer_get_ssh_string(payload); rc = ssh_buffer_unpack(payload,
if (msg->handle == NULL) { "Sd",
&msg->handle,
&msg->flags);
if (rc != SSH_OK) {
ssh_set_error_oom(session); ssh_set_error_oom(session);
sftp_client_message_free(msg); sftp_client_message_free(msg);
return NULL; return NULL;
} }
buffer_get_u32(payload, &msg->flags);
break; break;
default: default:
ssh_set_error(sftp->session, SSH_FATAL, ssh_set_error(sftp->session, SSH_FATAL,
@ -239,9 +210,6 @@ sftp_client_message sftp_get_client_message(sftp_session sftp) {
return NULL; return NULL;
} }
msg->flags = ntohl(msg->flags);
msg->offset = ntohll(msg->offset);
msg->len = ntohl(msg->len);
sftp_packet_free(packet); sftp_packet_free(packet);
return msg; return msg;