Improve sftp_canonicalize_path().
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@614 7dcaeef0-15fb-0310-b436-a5af3365683c
Этот коммит содержится в:
родитель
367f4b999a
Коммит
2b4efa171e
111
libssh/sftp.c
111
libssh/sftp.c
@ -2203,51 +2203,74 @@ int sftp_utimes(SFTP_SESSION *sftp, const char *file,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* another code written by Nick */
|
/* another code written by Nick */
|
||||||
char *sftp_canonicalize_path(SFTP_SESSION *sftp, const char *path)
|
char *sftp_canonicalize_path(SFTP_SESSION *sftp, const char *path) {
|
||||||
{
|
STATUS_MESSAGE *status = NULL;
|
||||||
u32 id = sftp_get_new_id(sftp);
|
SFTP_MESSAGE *msg = NULL;
|
||||||
BUFFER *buffer = buffer_new();
|
STRING *name = NULL;
|
||||||
STRING *pathstr = string_from_char(path);
|
STRING *pathstr;
|
||||||
STRING *name = NULL;
|
BUFFER *buffer;
|
||||||
SFTP_MESSAGE *msg = NULL;
|
char *cname;
|
||||||
STATUS_MESSAGE *status = NULL;
|
u32 ignored;
|
||||||
char *cname;
|
u32 id;
|
||||||
u32 ignored;
|
|
||||||
|
|
||||||
buffer_add_u32(buffer, id);
|
buffer = buffer_new();
|
||||||
buffer_add_ssh_string(buffer, pathstr);
|
if (buffer == NULL) {
|
||||||
free(pathstr);
|
return NULL;
|
||||||
sftp_packet_write(sftp, SSH_FXP_REALPATH, buffer);
|
}
|
||||||
buffer_free(buffer);
|
|
||||||
while (!msg)
|
pathstr = string_from_char(path);
|
||||||
{
|
if (pathstr == NULL) {
|
||||||
if (sftp_read_and_dispatch(sftp))
|
buffer_free(buffer);
|
||||||
return NULL;
|
return NULL;
|
||||||
msg = sftp_dequeue(sftp, id);
|
}
|
||||||
}
|
|
||||||
if (msg->packet_type == SSH_FXP_NAME) /* good response */
|
id = sftp_get_new_id(sftp);
|
||||||
{
|
if (buffer_add_u32(buffer, id) < 0 ||
|
||||||
buffer_get_u32(msg->payload, &ignored); /* we don't care about "count" */
|
buffer_add_ssh_string(buffer, pathstr) < 0 ||
|
||||||
name = buffer_get_ssh_string(msg->payload); /* we only care about the file name string */
|
sftp_packet_write(sftp, SSH_FXP_REALPATH, buffer) < 0) {
|
||||||
cname = string_to_char(name);
|
buffer_free(buffer);
|
||||||
free(name);
|
string_free(pathstr);
|
||||||
return cname;
|
return NULL;
|
||||||
}
|
}
|
||||||
else if (msg->packet_type == SSH_FXP_STATUS) /* bad response (error) */
|
buffer_free(buffer);
|
||||||
{
|
string_free(pathstr);
|
||||||
status = parse_status_msg(msg);
|
|
||||||
sftp_message_free(msg);
|
while (msg == NULL) {
|
||||||
if (!status)
|
if (sftp_read_and_dispatch(sftp) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
ssh_set_error(sftp->session,SSH_REQUEST_DENIED, "sftp server: %s", status->errormsg);
|
}
|
||||||
status_msg_free(status);
|
msg = sftp_dequeue(sftp, id);
|
||||||
}
|
}
|
||||||
else /* this shouldn't happen */
|
|
||||||
{
|
if (msg->packet_type == SSH_FXP_NAME) {
|
||||||
ssh_set_error(sftp->session,SSH_FATAL, "Received message %d when attempting to set stats", msg->packet_type);
|
/* we don't care about "count" */
|
||||||
sftp_message_free(msg);
|
buffer_get_u32(msg->payload, &ignored);
|
||||||
}
|
/* we only care about the file name string */
|
||||||
return NULL;
|
name = buffer_get_ssh_string(msg->payload);
|
||||||
|
sftp_message_free(msg);
|
||||||
|
if (name == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
cname = string_to_char(name);
|
||||||
|
string_free(name);
|
||||||
|
|
||||||
|
return cname;
|
||||||
|
} else if (msg->packet_type == SSH_FXP_STATUS) { /* bad response (error) */
|
||||||
|
status = parse_status_msg(msg);
|
||||||
|
sftp_message_free(msg);
|
||||||
|
if (status == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
ssh_set_error(sftp->session, SSH_REQUEST_DENIED,
|
||||||
|
"SFTP server: %s", status->errormsg);
|
||||||
|
status_msg_free(status);
|
||||||
|
} else { /* this shouldn't happen */
|
||||||
|
ssh_set_error(sftp->session, SSH_FATAL,
|
||||||
|
"Received message %d when attempting to set stats", msg->packet_type);
|
||||||
|
sftp_message_free(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SFTP_ATTRIBUTES *sftp_xstat(SFTP_SESSION *sftp, const char *path, int param){
|
static SFTP_ATTRIBUTES *sftp_xstat(SFTP_SESSION *sftp, const char *path, int param){
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user