version 1.87, 2009/06/22 05:39:28 |
version 1.88, 2009/08/14 18:17:49 |
|
|
u_int exts; |
u_int exts; |
}; |
}; |
|
|
|
static char * |
|
get_handle(int fd, u_int expected_id, u_int *len, const char *errfmt, ...) |
|
__attribute__((format(printf, 4, 5))); |
|
|
static void |
static void |
send_msg(int fd, Buffer *m) |
send_msg(int fd, Buffer *m) |
{ |
{ |
|
|
} |
} |
|
|
static char * |
static char * |
get_handle(int fd, u_int expected_id, u_int *len) |
get_handle(int fd, u_int expected_id, u_int *len, const char *errfmt, ...) |
{ |
{ |
Buffer msg; |
Buffer msg; |
u_int type, id; |
u_int type, id; |
char *handle; |
char *handle, errmsg[256]; |
|
va_list args; |
|
int status; |
|
|
|
va_start(args, errfmt); |
|
if (errfmt != NULL) |
|
vsnprintf(errmsg, sizeof(errmsg), errfmt, args); |
|
va_end(args); |
|
|
buffer_init(&msg); |
buffer_init(&msg); |
get_msg(fd, &msg); |
get_msg(fd, &msg); |
type = buffer_get_char(&msg); |
type = buffer_get_char(&msg); |
id = buffer_get_int(&msg); |
id = buffer_get_int(&msg); |
|
|
if (id != expected_id) |
if (id != expected_id) |
fatal("ID mismatch (%u != %u)", id, expected_id); |
fatal("%s: ID mismatch (%u != %u)", |
|
errfmt == NULL ? __func__ : errmsg, id, expected_id); |
if (type == SSH2_FXP_STATUS) { |
if (type == SSH2_FXP_STATUS) { |
int status = buffer_get_int(&msg); |
status = buffer_get_int(&msg); |
|
if (errfmt != NULL) |
error("Couldn't get handle: %s", fx2txt(status)); |
error("%s: %s", errmsg, fx2txt(status)); |
buffer_free(&msg); |
buffer_free(&msg); |
return(NULL); |
return(NULL); |
} else if (type != SSH2_FXP_HANDLE) |
} else if (type != SSH2_FXP_HANDLE) |
fatal("Expected SSH2_FXP_HANDLE(%u) packet, got %u", |
fatal("%s: Expected SSH2_FXP_HANDLE(%u) packet, got %u", |
SSH2_FXP_HANDLE, type); |
errfmt == NULL ? __func__ : errmsg, SSH2_FXP_HANDLE, type); |
|
|
handle = buffer_get_string(&msg, len); |
handle = buffer_get_string(&msg, len); |
buffer_free(&msg); |
buffer_free(&msg); |
|
|
|
|
buffer_clear(&msg); |
buffer_clear(&msg); |
|
|
handle = get_handle(conn->fd_in, id, &handle_len); |
handle = get_handle(conn->fd_in, id, &handle_len, |
|
"remote readdir(\"%s\")", path); |
if (handle == NULL) |
if (handle == NULL) |
return(-1); |
return(-1); |
|
|
|
|
send_msg(conn->fd_out, &msg); |
send_msg(conn->fd_out, &msg); |
debug3("Sent message SSH2_FXP_OPEN I:%u P:%s", id, remote_path); |
debug3("Sent message SSH2_FXP_OPEN I:%u P:%s", id, remote_path); |
|
|
handle = get_handle(conn->fd_in, id, &handle_len); |
handle = get_handle(conn->fd_in, id, &handle_len, |
|
"remote open(\"%s\")", remote_path); |
if (handle == NULL) { |
if (handle == NULL) { |
buffer_free(&msg); |
buffer_free(&msg); |
return(-1); |
return(-1); |
|
|
|
|
buffer_clear(&msg); |
buffer_clear(&msg); |
|
|
handle = get_handle(conn->fd_in, id, &handle_len); |
handle = get_handle(conn->fd_in, id, &handle_len, |
|
"remote open(\"%s\")", remote_path); |
if (handle == NULL) { |
if (handle == NULL) { |
close(local_fd); |
close(local_fd); |
buffer_free(&msg); |
buffer_free(&msg); |