mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-11 02:38:09 +09:00
Improve sftp_setstat().
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@612 7dcaeef0-15fb-0310-b436-a5af3365683c
This commit is contained in:
@@ -2097,25 +2097,43 @@ int sftp_setstat(SFTP_SESSION *sftp, const char *file, SFTP_ATTRIBUTES *attr) {
|
|||||||
SFTP_MESSAGE *msg = NULL;
|
SFTP_MESSAGE *msg = NULL;
|
||||||
STATUS_MESSAGE *status = NULL;
|
STATUS_MESSAGE *status = NULL;
|
||||||
|
|
||||||
buffer_add_u32(buffer, id);
|
buffer = buffer_new();
|
||||||
buffer_add_ssh_string(buffer, path);
|
if (buffer == NULL) {
|
||||||
free(path);
|
|
||||||
if (buffer_add_attributes(buffer, attr) < 0) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
sftp_packet_write(sftp, SSH_FXP_SETSTAT, buffer);
|
|
||||||
|
path = string_from_char(file);
|
||||||
|
if (path == NULL) {
|
||||||
buffer_free(buffer);
|
buffer_free(buffer);
|
||||||
while (!msg) {
|
|
||||||
if (sftp_read_and_dispatch(sftp))
|
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
id = sftp_get_new_id(sftp);
|
||||||
|
if (buffer_add_u32(buffer, id) < 0 ||
|
||||||
|
buffer_add_ssh_string(buffer, path) < 0 ||
|
||||||
|
buffer_add_attributes(buffer, attr) < 0 ||
|
||||||
|
sftp_packet_write(sftp, SSH_FXP_SETSTAT, buffer) < 0) {
|
||||||
|
buffer_free(buffer);
|
||||||
|
string_free(path);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
buffer_free(buffer);
|
||||||
|
string_free(path);
|
||||||
|
|
||||||
|
while (msg == NULL) {
|
||||||
|
if (sftp_read_and_dispatch(sftp) < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
msg = sftp_dequeue(sftp, id);
|
msg = sftp_dequeue(sftp, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* By specification, this command only returns SSH_FXP_STATUS */
|
||||||
if (msg->packet_type == SSH_FXP_STATUS) {
|
if (msg->packet_type == SSH_FXP_STATUS) {
|
||||||
/* by specification, this command's only supposed to return SSH_FXP_STATUS */
|
|
||||||
status = parse_status_msg(msg);
|
status = parse_status_msg(msg);
|
||||||
sftp_message_free(msg);
|
sftp_message_free(msg);
|
||||||
if (!status)
|
if (status == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
sftp_set_error(sftp, status->status);
|
sftp_set_error(sftp, status->status);
|
||||||
switch (status->status) {
|
switch (status->status) {
|
||||||
case SSH_FX_OK:
|
case SSH_FX_OK:
|
||||||
@@ -2124,14 +2142,20 @@ int sftp_setstat(SFTP_SESSION *sftp, const char *file, SFTP_ATTRIBUTES *attr) {
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* status should be SSH_FX_OK if the command was successful, if it didn't, then there was an error */
|
/*
|
||||||
ssh_set_error(sftp->session,SSH_REQUEST_DENIED, "sftp server: %s", status->errormsg);
|
* The status should be SSH_FX_OK if the command was successful, if it
|
||||||
|
* didn't, then there was an error
|
||||||
|
*/
|
||||||
|
ssh_set_error(sftp->session, SSH_REQUEST_DENIED,
|
||||||
|
"SFTP server: %s", status->errormsg);
|
||||||
status_msg_free(status);
|
status_msg_free(status);
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
ssh_set_error(sftp->session,SSH_FATAL, "Received message %d when attempting to set stats", msg->packet_type);
|
ssh_set_error(sftp->session, SSH_FATAL,
|
||||||
|
"Received message %d when attempting to set stats", msg->packet_type);
|
||||||
sftp_message_free(msg);
|
sftp_message_free(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user