sftp: Reformat sftp_xstat()
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Этот коммит содержится в:
родитель
336c097ae7
Коммит
b00a0578f9
154
src/sftp.c
154
src/sftp.c
@ -3065,88 +3065,90 @@ char *sftp_canonicalize_path(sftp_session sftp, const char *path)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static sftp_attributes sftp_xstat(sftp_session sftp, const char *path,
|
static sftp_attributes sftp_xstat(sftp_session sftp,
|
||||||
int param) {
|
const char *path,
|
||||||
sftp_status_message status = NULL;
|
int param)
|
||||||
sftp_message msg = NULL;
|
{
|
||||||
ssh_string pathstr;
|
sftp_status_message status = NULL;
|
||||||
ssh_buffer buffer;
|
sftp_message msg = NULL;
|
||||||
uint32_t id;
|
ssh_string pathstr;
|
||||||
int rc;
|
ssh_buffer buffer;
|
||||||
|
uint32_t id;
|
||||||
|
int rc;
|
||||||
|
|
||||||
if (path == NULL) {
|
if (path == NULL) {
|
||||||
ssh_set_error_invalid(sftp->session);
|
ssh_set_error_invalid(sftp->session);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
buffer = ssh_buffer_new();
|
|
||||||
if (buffer == NULL) {
|
|
||||||
ssh_set_error_oom(sftp->session);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
pathstr = ssh_string_from_char(path);
|
|
||||||
if (pathstr == NULL) {
|
|
||||||
ssh_set_error_oom(sftp->session);
|
|
||||||
ssh_buffer_free(buffer);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
rc = ssh_buffer_allocate_size(buffer,
|
|
||||||
sizeof(uint32_t) * 2 +
|
|
||||||
ssh_string_len(pathstr));
|
|
||||||
if (rc < 0) {
|
|
||||||
ssh_set_error_oom(sftp->session);
|
|
||||||
ssh_buffer_free(buffer);
|
|
||||||
ssh_string_free(pathstr);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
id = sftp_get_new_id(sftp);
|
|
||||||
if (ssh_buffer_add_u32(buffer, htonl(id)) < 0 ||
|
|
||||||
ssh_buffer_add_ssh_string(buffer, pathstr) < 0) {
|
|
||||||
ssh_set_error_oom(sftp->session);
|
|
||||||
ssh_buffer_free(buffer);
|
|
||||||
ssh_string_free(pathstr);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
if (sftp_packet_write(sftp, param, buffer) < 0) {
|
|
||||||
ssh_buffer_free(buffer);
|
|
||||||
ssh_string_free(pathstr);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
ssh_buffer_free(buffer);
|
|
||||||
ssh_string_free(pathstr);
|
|
||||||
|
|
||||||
while (msg == NULL) {
|
|
||||||
if (sftp_read_and_dispatch(sftp) < 0) {
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
msg = sftp_dequeue(sftp, id);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msg->packet_type == SSH_FXP_ATTRS) {
|
buffer = ssh_buffer_new();
|
||||||
sftp_attributes attr = sftp_parse_attr(sftp, msg->payload, 0);
|
if (buffer == NULL) {
|
||||||
|
ssh_set_error_oom(sftp->session);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
pathstr = ssh_string_from_char(path);
|
||||||
|
if (pathstr == NULL) {
|
||||||
|
ssh_set_error_oom(sftp->session);
|
||||||
|
ssh_buffer_free(buffer);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = ssh_buffer_allocate_size(buffer,
|
||||||
|
sizeof(uint32_t) * 2 +
|
||||||
|
ssh_string_len(pathstr));
|
||||||
|
if (rc < 0) {
|
||||||
|
ssh_set_error_oom(sftp->session);
|
||||||
|
ssh_buffer_free(buffer);
|
||||||
|
ssh_string_free(pathstr);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
id = sftp_get_new_id(sftp);
|
||||||
|
if (ssh_buffer_add_u32(buffer, htonl(id)) < 0 ||
|
||||||
|
ssh_buffer_add_ssh_string(buffer, pathstr) < 0) {
|
||||||
|
ssh_set_error_oom(sftp->session);
|
||||||
|
ssh_buffer_free(buffer);
|
||||||
|
ssh_string_free(pathstr);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (sftp_packet_write(sftp, param, buffer) < 0) {
|
||||||
|
ssh_buffer_free(buffer);
|
||||||
|
ssh_string_free(pathstr);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
ssh_buffer_free(buffer);
|
||||||
|
ssh_string_free(pathstr);
|
||||||
|
|
||||||
|
while (msg == NULL) {
|
||||||
|
if (sftp_read_and_dispatch(sftp) < 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
msg = sftp_dequeue(sftp, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg->packet_type == SSH_FXP_ATTRS) {
|
||||||
|
sftp_attributes attr = sftp_parse_attr(sftp, msg->payload, 0);
|
||||||
|
sftp_message_free(msg);
|
||||||
|
|
||||||
|
return attr;
|
||||||
|
} else if (msg->packet_type == SSH_FXP_STATUS) {
|
||||||
|
status = parse_status_msg(msg);
|
||||||
|
sftp_message_free(msg);
|
||||||
|
if (status == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
sftp_set_error(sftp, status->status);
|
||||||
|
ssh_set_error(sftp->session, SSH_REQUEST_DENIED,
|
||||||
|
"SFTP server: %s", status->errormsg);
|
||||||
|
status_msg_free(status);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
ssh_set_error(sftp->session, SSH_FATAL,
|
||||||
|
"Received mesg %d during stat()", msg->packet_type);
|
||||||
sftp_message_free(msg);
|
sftp_message_free(msg);
|
||||||
|
|
||||||
return attr;
|
|
||||||
} else if (msg->packet_type == SSH_FXP_STATUS) {
|
|
||||||
status = parse_status_msg(msg);
|
|
||||||
sftp_message_free(msg);
|
|
||||||
if (status == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
sftp_set_error(sftp, status->status);
|
|
||||||
ssh_set_error(sftp->session, SSH_REQUEST_DENIED,
|
|
||||||
"SFTP server: %s", status->errormsg);
|
|
||||||
status_msg_free(status);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
ssh_set_error(sftp->session, SSH_FATAL,
|
|
||||||
"Received mesg %d during stat()", msg->packet_type);
|
|
||||||
sftp_message_free(msg);
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sftp_attributes sftp_stat(sftp_session session, const char *path) {
|
sftp_attributes sftp_stat(sftp_session session, const char *path) {
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user