Compatibility with (broken) sftp version 2 protocols

This commit is contained in:
Aris Adamantiadis
2009-10-23 12:19:22 +02:00
parent 792def7a65
commit be4f695c5c

View File

@@ -740,20 +740,35 @@ static sftp_status_message parse_status_msg(sftp_message msg){
ZERO_STRUCTP(status); ZERO_STRUCTP(status);
status->id = msg->id; status->id = msg->id;
if ((buffer_get_u32(msg->payload,&status->status) != 4) || if (buffer_get_u32(msg->payload,&status->status) != 4){
(status->error = buffer_get_ssh_string(msg->payload)) == NULL ||
(status->lang = buffer_get_ssh_string(msg->payload)) == NULL) {
string_free(status->error);
/* status->lang never get allocated if something failed */
SAFE_FREE(status); SAFE_FREE(status);
ssh_set_error(msg->sftp->session, SSH_FATAL, ssh_set_error(msg->sftp->session, SSH_FATAL,
"Invalid SSH_FXP_STATUS message"); "Invalid SSH_FXP_STATUS message");
return NULL; return NULL;
} }
status->error = buffer_get_ssh_string(msg->payload);
status->lang = buffer_get_ssh_string(msg->payload);
if(status->error != NULL || status->lang != NULL){
if(msg->sftp->version >=3){
/* These are mandatory from version 3 */
string_free(status->error);
/* status->lang never get allocated if something failed */
SAFE_FREE(status);
ssh_set_error(msg->sftp->session, SSH_FATAL,
"Invalid SSH_FXP_STATUS message");
return NULL;
}
}
status->status = ntohl(status->status); status->status = ntohl(status->status);
status->errormsg = string_to_char(status->error); if(status->error)
status->langmsg = string_to_char(status->lang); status->errormsg = string_to_char(status->error);
else
status->errormsg = strdup("No error message in packet");
if(status->lang)
status->langmsg = string_to_char(status->lang);
else
status->langmsg = strdup("");
if (status->errormsg == NULL || status->langmsg == NULL) { if (status->errormsg == NULL || status->langmsg == NULL) {
status_msg_free(status); status_msg_free(status);
return NULL; return NULL;
@@ -1054,7 +1069,7 @@ static sftp_attributes sftp_parse_attr_4(sftp_session sftp, ssh_buffer buf,
return attr; return attr;
} }
/* Version 3 code. it is the only one really supported (the draft for the 4 misses clarifications) */ /* sftp version 0-3 code. It is different from the v4 */
/* maybe a paste of the draft is better than the code */ /* maybe a paste of the draft is better than the code */
/* /*
uint32 flags uint32 flags
@@ -1256,6 +1271,9 @@ sftp_attributes sftp_parse_attr(sftp_session session, ssh_buffer buf,
case 4: case 4:
return sftp_parse_attr_4(session, buf, expectname); return sftp_parse_attr_4(session, buf, expectname);
case 3: case 3:
case 2:
case 1:
case 0:
return sftp_parse_attr_3(session, buf, expectname); return sftp_parse_attr_3(session, buf, expectname);
default: default:
ssh_set_error(session->session, SSH_FATAL, ssh_set_error(session->session, SSH_FATAL,
@@ -2451,7 +2469,10 @@ char *sftp_readlink(sftp_session sftp, const char *path) {
if (sftp == NULL || path == NULL) { if (sftp == NULL || path == NULL) {
return NULL; return NULL;
} }
if (sftp->version < 3){
ssh_set_error(sftp,SSH_REQUEST_DENIED,"sftp version %d does not support sftp_readlink",sftp->version);
return NULL;
}
buffer = buffer_new(); buffer = buffer_new();
if (buffer == NULL) { if (buffer == NULL) {
return NULL; return NULL;
@@ -2614,6 +2635,10 @@ sftp_statvfs_t sftp_statvfs(sftp_session sftp, const char *path) {
if (sftp == NULL || path == NULL) { if (sftp == NULL || path == NULL) {
return NULL; return NULL;
} }
if (sftp->version < 3){
ssh_set_error(sftp,SSH_REQUEST_DENIED,"sftp version %d does not support sftp_statvfs",sftp->version);
return NULL;
}
buffer = buffer_new(); buffer = buffer_new();
if (buffer == NULL) { if (buffer == NULL) {