version 1.92, 2010/07/19 03:16:33 |
version 1.93, 2010/09/22 22:58:51 |
|
|
/* XXX: copy between two remote sites */ |
/* XXX: copy between two remote sites */ |
|
|
#include <sys/types.h> |
#include <sys/types.h> |
|
#include <sys/poll.h> |
#include <sys/queue.h> |
#include <sys/queue.h> |
#include <sys/stat.h> |
#include <sys/stat.h> |
#include <sys/time.h> |
#include <sys/time.h> |
|
|
#define SFTP_EXT_STATVFS 0x00000002 |
#define SFTP_EXT_STATVFS 0x00000002 |
#define SFTP_EXT_FSTATVFS 0x00000004 |
#define SFTP_EXT_FSTATVFS 0x00000004 |
u_int exts; |
u_int exts; |
|
u_int64_t limit_kbps; |
|
struct bwlimit bwlimit_in, bwlimit_out; |
}; |
}; |
|
|
static char * |
static char * |
get_handle(int fd, u_int expected_id, u_int *len, const char *errfmt, ...) |
get_handle(struct sftp_conn *conn, u_int expected_id, u_int *len, |
__attribute__((format(printf, 4, 5))); |
const char *errfmt, ...) __attribute__((format(printf, 4, 5))); |
|
|
|
/* ARGSUSED */ |
|
static int |
|
sftpio(void *_bwlimit, size_t amount) |
|
{ |
|
struct bwlimit *bwlimit = (struct bwlimit *)_bwlimit; |
|
|
|
bandwidth_limit(bwlimit, amount); |
|
return 0; |
|
} |
|
|
static void |
static void |
send_msg(int fd, Buffer *m) |
send_msg(struct sftp_conn *conn, Buffer *m) |
{ |
{ |
u_char mlen[4]; |
u_char mlen[4]; |
struct iovec iov[2]; |
struct iovec iov[2]; |
|
|
iov[1].iov_base = buffer_ptr(m); |
iov[1].iov_base = buffer_ptr(m); |
iov[1].iov_len = buffer_len(m); |
iov[1].iov_len = buffer_len(m); |
|
|
if (atomiciov(writev, fd, iov, 2) != buffer_len(m) + sizeof(mlen)) |
if (atomiciov6(writev, conn->fd_out, iov, 2, |
|
conn->limit_kbps > 0 ? sftpio : NULL, &conn->bwlimit_out) != |
|
buffer_len(m) + sizeof(mlen)) |
fatal("Couldn't send packet: %s", strerror(errno)); |
fatal("Couldn't send packet: %s", strerror(errno)); |
|
|
buffer_clear(m); |
buffer_clear(m); |
} |
} |
|
|
static void |
static void |
get_msg(int fd, Buffer *m) |
get_msg(struct sftp_conn *conn, Buffer *m) |
{ |
{ |
u_int msg_len; |
u_int msg_len; |
|
|
buffer_append_space(m, 4); |
buffer_append_space(m, 4); |
if (atomicio(read, fd, buffer_ptr(m), 4) != 4) { |
if (atomicio6(read, conn->fd_in, buffer_ptr(m), 4, |
|
conn->limit_kbps > 0 ? sftpio : NULL, &conn->bwlimit_in) != 4) { |
if (errno == EPIPE) |
if (errno == EPIPE) |
fatal("Connection closed"); |
fatal("Connection closed"); |
else |
else |
|
|
fatal("Received message too long %u", msg_len); |
fatal("Received message too long %u", msg_len); |
|
|
buffer_append_space(m, msg_len); |
buffer_append_space(m, msg_len); |
if (atomicio(read, fd, buffer_ptr(m), msg_len) != msg_len) { |
if (atomicio6(read, conn->fd_in, buffer_ptr(m), msg_len, |
|
conn->limit_kbps > 0 ? sftpio : NULL, &conn->bwlimit_in) |
|
!= msg_len) { |
if (errno == EPIPE) |
if (errno == EPIPE) |
fatal("Connection closed"); |
fatal("Connection closed"); |
else |
else |
|
|
} |
} |
|
|
static void |
static void |
send_string_request(int fd, u_int id, u_int code, char *s, |
send_string_request(struct sftp_conn *conn, u_int id, u_int code, char *s, |
u_int len) |
u_int len) |
{ |
{ |
Buffer msg; |
Buffer msg; |
|
|
buffer_put_char(&msg, code); |
buffer_put_char(&msg, code); |
buffer_put_int(&msg, id); |
buffer_put_int(&msg, id); |
buffer_put_string(&msg, s, len); |
buffer_put_string(&msg, s, len); |
send_msg(fd, &msg); |
send_msg(conn, &msg); |
debug3("Sent message fd %d T:%u I:%u", fd, code, id); |
debug3("Sent message fd %d T:%u I:%u", conn->fd_out, code, id); |
buffer_free(&msg); |
buffer_free(&msg); |
} |
} |
|
|
static void |
static void |
send_string_attrs_request(int fd, u_int id, u_int code, char *s, |
send_string_attrs_request(struct sftp_conn *conn, u_int id, u_int code, |
u_int len, Attrib *a) |
char *s, u_int len, Attrib *a) |
{ |
{ |
Buffer msg; |
Buffer msg; |
|
|
|
|
buffer_put_int(&msg, id); |
buffer_put_int(&msg, id); |
buffer_put_string(&msg, s, len); |
buffer_put_string(&msg, s, len); |
encode_attrib(&msg, a); |
encode_attrib(&msg, a); |
send_msg(fd, &msg); |
send_msg(conn, &msg); |
debug3("Sent message fd %d T:%u I:%u", fd, code, id); |
debug3("Sent message fd %d T:%u I:%u", conn->fd_out, code, id); |
buffer_free(&msg); |
buffer_free(&msg); |
} |
} |
|
|
static u_int |
static u_int |
get_status(int fd, u_int expected_id) |
get_status(struct sftp_conn *conn, u_int expected_id) |
{ |
{ |
Buffer msg; |
Buffer msg; |
u_int type, id, status; |
u_int type, id, status; |
|
|
buffer_init(&msg); |
buffer_init(&msg); |
get_msg(fd, &msg); |
get_msg(conn, &msg); |
type = buffer_get_char(&msg); |
type = buffer_get_char(&msg); |
id = buffer_get_int(&msg); |
id = buffer_get_int(&msg); |
|
|
|
|
|
|
debug3("SSH2_FXP_STATUS %u", status); |
debug3("SSH2_FXP_STATUS %u", status); |
|
|
return(status); |
return status; |
} |
} |
|
|
static char * |
static char * |
get_handle(int fd, u_int expected_id, u_int *len, const char *errfmt, ...) |
get_handle(struct sftp_conn *conn, u_int expected_id, u_int *len, |
|
const char *errfmt, ...) |
{ |
{ |
Buffer msg; |
Buffer msg; |
u_int type, id; |
u_int type, id; |
|
|
va_end(args); |
va_end(args); |
|
|
buffer_init(&msg); |
buffer_init(&msg); |
get_msg(fd, &msg); |
get_msg(conn, &msg); |
type = buffer_get_char(&msg); |
type = buffer_get_char(&msg); |
id = buffer_get_int(&msg); |
id = buffer_get_int(&msg); |
|
|
|
|
} |
} |
|
|
static Attrib * |
static Attrib * |
get_decode_stat(int fd, u_int expected_id, int quiet) |
get_decode_stat(struct sftp_conn *conn, u_int expected_id, int quiet) |
{ |
{ |
Buffer msg; |
Buffer msg; |
u_int type, id; |
u_int type, id; |
Attrib *a; |
Attrib *a; |
|
|
buffer_init(&msg); |
buffer_init(&msg); |
get_msg(fd, &msg); |
get_msg(conn, &msg); |
|
|
type = buffer_get_char(&msg); |
type = buffer_get_char(&msg); |
id = buffer_get_int(&msg); |
id = buffer_get_int(&msg); |
|
|
} |
} |
|
|
static int |
static int |
get_decode_statvfs(int fd, struct sftp_statvfs *st, u_int expected_id, |
get_decode_statvfs(struct sftp_conn *conn, struct sftp_statvfs *st, |
int quiet) |
u_int expected_id, int quiet) |
{ |
{ |
Buffer msg; |
Buffer msg; |
u_int type, id, flag; |
u_int type, id, flag; |
|
|
buffer_init(&msg); |
buffer_init(&msg); |
get_msg(fd, &msg); |
get_msg(conn, &msg); |
|
|
type = buffer_get_char(&msg); |
type = buffer_get_char(&msg); |
id = buffer_get_int(&msg); |
id = buffer_get_int(&msg); |
|
|
} |
} |
|
|
struct sftp_conn * |
struct sftp_conn * |
do_init(int fd_in, int fd_out, u_int transfer_buflen, u_int num_requests) |
do_init(int fd_in, int fd_out, u_int transfer_buflen, u_int num_requests, |
|
u_int64_t limit_kbps) |
{ |
{ |
u_int type, exts = 0; |
u_int type; |
int version; |
|
Buffer msg; |
Buffer msg; |
struct sftp_conn *ret; |
struct sftp_conn *ret; |
|
|
|
ret = xmalloc(sizeof(*ret)); |
|
ret->fd_in = fd_in; |
|
ret->fd_out = fd_out; |
|
ret->transfer_buflen = transfer_buflen; |
|
ret->num_requests = num_requests; |
|
ret->exts = 0; |
|
ret->limit_kbps = 0; |
|
|
buffer_init(&msg); |
buffer_init(&msg); |
buffer_put_char(&msg, SSH2_FXP_INIT); |
buffer_put_char(&msg, SSH2_FXP_INIT); |
buffer_put_int(&msg, SSH2_FILEXFER_VERSION); |
buffer_put_int(&msg, SSH2_FILEXFER_VERSION); |
send_msg(fd_out, &msg); |
send_msg(ret, &msg); |
|
|
buffer_clear(&msg); |
buffer_clear(&msg); |
|
|
get_msg(fd_in, &msg); |
get_msg(ret, &msg); |
|
|
/* Expecting a VERSION reply */ |
/* Expecting a VERSION reply */ |
if ((type = buffer_get_char(&msg)) != SSH2_FXP_VERSION) { |
if ((type = buffer_get_char(&msg)) != SSH2_FXP_VERSION) { |
|
|
buffer_free(&msg); |
buffer_free(&msg); |
return(NULL); |
return(NULL); |
} |
} |
version = buffer_get_int(&msg); |
ret->version = buffer_get_int(&msg); |
|
|
debug2("Remote version: %d", version); |
debug2("Remote version: %u", ret->version); |
|
|
/* Check for extensions */ |
/* Check for extensions */ |
while (buffer_len(&msg) > 0) { |
while (buffer_len(&msg) > 0) { |
|
|
|
|
if (strcmp(name, "posix-rename@openssh.com") == 0 && |
if (strcmp(name, "posix-rename@openssh.com") == 0 && |
strcmp(value, "1") == 0) { |
strcmp(value, "1") == 0) { |
exts |= SFTP_EXT_POSIX_RENAME; |
ret->exts |= SFTP_EXT_POSIX_RENAME; |
known = 1; |
known = 1; |
} else if (strcmp(name, "statvfs@openssh.com") == 0 && |
} else if (strcmp(name, "statvfs@openssh.com") == 0 && |
strcmp(value, "2") == 0) { |
strcmp(value, "2") == 0) { |
exts |= SFTP_EXT_STATVFS; |
ret->exts |= SFTP_EXT_STATVFS; |
known = 1; |
known = 1; |
} if (strcmp(name, "fstatvfs@openssh.com") == 0 && |
} if (strcmp(name, "fstatvfs@openssh.com") == 0 && |
strcmp(value, "2") == 0) { |
strcmp(value, "2") == 0) { |
exts |= SFTP_EXT_FSTATVFS; |
ret->exts |= SFTP_EXT_FSTATVFS; |
known = 1; |
known = 1; |
} |
} |
if (known) { |
if (known) { |
|
|
|
|
buffer_free(&msg); |
buffer_free(&msg); |
|
|
ret = xmalloc(sizeof(*ret)); |
|
ret->fd_in = fd_in; |
|
ret->fd_out = fd_out; |
|
ret->transfer_buflen = transfer_buflen; |
|
ret->num_requests = num_requests; |
|
ret->version = version; |
|
ret->msg_id = 1; |
|
ret->exts = exts; |
|
|
|
/* Some filexfer v.0 servers don't support large packets */ |
/* Some filexfer v.0 servers don't support large packets */ |
if (version == 0) |
if (ret->version == 0) |
ret->transfer_buflen = MIN(ret->transfer_buflen, 20480); |
ret->transfer_buflen = MIN(ret->transfer_buflen, 20480); |
|
|
return(ret); |
ret->limit_kbps = limit_kbps; |
|
if (ret->limit_kbps > 0) { |
|
bandwidth_limit_init(&ret->bwlimit_in, ret->limit_kbps, |
|
ret->transfer_buflen); |
|
bandwidth_limit_init(&ret->bwlimit_out, ret->limit_kbps, |
|
ret->transfer_buflen); |
|
} |
|
|
|
return ret; |
} |
} |
|
|
u_int |
u_int |
sftp_proto_version(struct sftp_conn *conn) |
sftp_proto_version(struct sftp_conn *conn) |
{ |
{ |
return(conn->version); |
return conn->version; |
} |
} |
|
|
int |
int |
|
|
buffer_put_char(&msg, SSH2_FXP_CLOSE); |
buffer_put_char(&msg, SSH2_FXP_CLOSE); |
buffer_put_int(&msg, id); |
buffer_put_int(&msg, id); |
buffer_put_string(&msg, handle, handle_len); |
buffer_put_string(&msg, handle, handle_len); |
send_msg(conn->fd_out, &msg); |
send_msg(conn, &msg); |
debug3("Sent message SSH2_FXP_CLOSE I:%u", id); |
debug3("Sent message SSH2_FXP_CLOSE I:%u", id); |
|
|
status = get_status(conn->fd_in, id); |
status = get_status(conn, id); |
if (status != SSH2_FX_OK) |
if (status != SSH2_FX_OK) |
error("Couldn't close file: %s", fx2txt(status)); |
error("Couldn't close file: %s", fx2txt(status)); |
|
|
buffer_free(&msg); |
buffer_free(&msg); |
|
|
return(status); |
return status; |
} |
} |
|
|
|
|
|
|
buffer_put_char(&msg, SSH2_FXP_OPENDIR); |
buffer_put_char(&msg, SSH2_FXP_OPENDIR); |
buffer_put_int(&msg, id); |
buffer_put_int(&msg, id); |
buffer_put_cstring(&msg, path); |
buffer_put_cstring(&msg, path); |
send_msg(conn->fd_out, &msg); |
send_msg(conn, &msg); |
|
|
buffer_clear(&msg); |
buffer_clear(&msg); |
|
|
handle = get_handle(conn->fd_in, id, &handle_len, |
handle = get_handle(conn, id, &handle_len, |
"remote readdir(\"%s\")", path); |
"remote readdir(\"%s\")", path); |
if (handle == NULL) |
if (handle == NULL) |
return(-1); |
return -1; |
|
|
if (dir) { |
if (dir) { |
ents = 0; |
ents = 0; |
|
|
buffer_put_char(&msg, SSH2_FXP_READDIR); |
buffer_put_char(&msg, SSH2_FXP_READDIR); |
buffer_put_int(&msg, id); |
buffer_put_int(&msg, id); |
buffer_put_string(&msg, handle, handle_len); |
buffer_put_string(&msg, handle, handle_len); |
send_msg(conn->fd_out, &msg); |
send_msg(conn, &msg); |
|
|
buffer_clear(&msg); |
buffer_clear(&msg); |
|
|
get_msg(conn->fd_in, &msg); |
get_msg(conn, &msg); |
|
|
type = buffer_get_char(&msg); |
type = buffer_get_char(&msg); |
id = buffer_get_int(&msg); |
id = buffer_get_int(&msg); |
|
|
**dir = NULL; |
**dir = NULL; |
} |
} |
|
|
return(0); |
return 0; |
} |
} |
|
|
int |
int |
|
|
debug2("Sending SSH2_FXP_REMOVE \"%s\"", path); |
debug2("Sending SSH2_FXP_REMOVE \"%s\"", path); |
|
|
id = conn->msg_id++; |
id = conn->msg_id++; |
send_string_request(conn->fd_out, id, SSH2_FXP_REMOVE, path, |
send_string_request(conn, id, SSH2_FXP_REMOVE, path, strlen(path)); |
strlen(path)); |
status = get_status(conn, id); |
status = get_status(conn->fd_in, id); |
|
if (status != SSH2_FX_OK) |
if (status != SSH2_FX_OK) |
error("Couldn't delete file: %s", fx2txt(status)); |
error("Couldn't delete file: %s", fx2txt(status)); |
return(status); |
return(status); |
|
|
u_int status, id; |
u_int status, id; |
|
|
id = conn->msg_id++; |
id = conn->msg_id++; |
send_string_attrs_request(conn->fd_out, id, SSH2_FXP_MKDIR, path, |
send_string_attrs_request(conn, id, SSH2_FXP_MKDIR, path, |
strlen(path), a); |
strlen(path), a); |
|
|
status = get_status(conn->fd_in, id); |
status = get_status(conn, id); |
if (status != SSH2_FX_OK && printflag) |
if (status != SSH2_FX_OK && printflag) |
error("Couldn't create directory: %s", fx2txt(status)); |
error("Couldn't create directory: %s", fx2txt(status)); |
|
|
|
|
u_int status, id; |
u_int status, id; |
|
|
id = conn->msg_id++; |
id = conn->msg_id++; |
send_string_request(conn->fd_out, id, SSH2_FXP_RMDIR, path, |
send_string_request(conn, id, SSH2_FXP_RMDIR, path, |
strlen(path)); |
strlen(path)); |
|
|
status = get_status(conn->fd_in, id); |
status = get_status(conn, id); |
if (status != SSH2_FX_OK) |
if (status != SSH2_FX_OK) |
error("Couldn't remove directory: %s", fx2txt(status)); |
error("Couldn't remove directory: %s", fx2txt(status)); |
|
|
|
|
|
|
id = conn->msg_id++; |
id = conn->msg_id++; |
|
|
send_string_request(conn->fd_out, id, |
send_string_request(conn, id, |
conn->version == 0 ? SSH2_FXP_STAT_VERSION_0 : SSH2_FXP_STAT, |
conn->version == 0 ? SSH2_FXP_STAT_VERSION_0 : SSH2_FXP_STAT, |
path, strlen(path)); |
path, strlen(path)); |
|
|
return(get_decode_stat(conn->fd_in, id, quiet)); |
return(get_decode_stat(conn, id, quiet)); |
} |
} |
|
|
Attrib * |
Attrib * |
|
|
} |
} |
|
|
id = conn->msg_id++; |
id = conn->msg_id++; |
send_string_request(conn->fd_out, id, SSH2_FXP_LSTAT, path, |
send_string_request(conn, id, SSH2_FXP_LSTAT, path, |
strlen(path)); |
strlen(path)); |
|
|
return(get_decode_stat(conn->fd_in, id, quiet)); |
return(get_decode_stat(conn, id, quiet)); |
} |
} |
|
|
#ifdef notyet |
#ifdef notyet |
|
|
u_int id; |
u_int id; |
|
|
id = conn->msg_id++; |
id = conn->msg_id++; |
send_string_request(conn->fd_out, id, SSH2_FXP_FSTAT, handle, |
send_string_request(conn, id, SSH2_FXP_FSTAT, handle, |
handle_len); |
handle_len); |
|
|
return(get_decode_stat(conn->fd_in, id, quiet)); |
return(get_decode_stat(conn, id, quiet)); |
} |
} |
#endif |
#endif |
|
|
|
|
u_int status, id; |
u_int status, id; |
|
|
id = conn->msg_id++; |
id = conn->msg_id++; |
send_string_attrs_request(conn->fd_out, id, SSH2_FXP_SETSTAT, path, |
send_string_attrs_request(conn, id, SSH2_FXP_SETSTAT, path, |
strlen(path), a); |
strlen(path), a); |
|
|
status = get_status(conn->fd_in, id); |
status = get_status(conn, id); |
if (status != SSH2_FX_OK) |
if (status != SSH2_FX_OK) |
error("Couldn't setstat on \"%s\": %s", path, |
error("Couldn't setstat on \"%s\": %s", path, |
fx2txt(status)); |
fx2txt(status)); |
|
|
u_int status, id; |
u_int status, id; |
|
|
id = conn->msg_id++; |
id = conn->msg_id++; |
send_string_attrs_request(conn->fd_out, id, SSH2_FXP_FSETSTAT, handle, |
send_string_attrs_request(conn, id, SSH2_FXP_FSETSTAT, handle, |
handle_len, a); |
handle_len, a); |
|
|
status = get_status(conn->fd_in, id); |
status = get_status(conn, id); |
if (status != SSH2_FX_OK) |
if (status != SSH2_FX_OK) |
error("Couldn't fsetstat: %s", fx2txt(status)); |
error("Couldn't fsetstat: %s", fx2txt(status)); |
|
|
|
|
Attrib *a; |
Attrib *a; |
|
|
expected_id = id = conn->msg_id++; |
expected_id = id = conn->msg_id++; |
send_string_request(conn->fd_out, id, SSH2_FXP_REALPATH, path, |
send_string_request(conn, id, SSH2_FXP_REALPATH, path, |
strlen(path)); |
strlen(path)); |
|
|
buffer_init(&msg); |
buffer_init(&msg); |
|
|
get_msg(conn->fd_in, &msg); |
get_msg(conn, &msg); |
type = buffer_get_char(&msg); |
type = buffer_get_char(&msg); |
id = buffer_get_int(&msg); |
id = buffer_get_int(&msg); |
|
|
|
|
} |
} |
buffer_put_cstring(&msg, oldpath); |
buffer_put_cstring(&msg, oldpath); |
buffer_put_cstring(&msg, newpath); |
buffer_put_cstring(&msg, newpath); |
send_msg(conn->fd_out, &msg); |
send_msg(conn, &msg); |
debug3("Sent message %s \"%s\" -> \"%s\"", |
debug3("Sent message %s \"%s\" -> \"%s\"", |
(conn->exts & SFTP_EXT_POSIX_RENAME) ? "posix-rename@openssh.com" : |
(conn->exts & SFTP_EXT_POSIX_RENAME) ? "posix-rename@openssh.com" : |
"SSH2_FXP_RENAME", oldpath, newpath); |
"SSH2_FXP_RENAME", oldpath, newpath); |
buffer_free(&msg); |
buffer_free(&msg); |
|
|
status = get_status(conn->fd_in, id); |
status = get_status(conn, id); |
if (status != SSH2_FX_OK) |
if (status != SSH2_FX_OK) |
error("Couldn't rename file \"%s\" to \"%s\": %s", oldpath, |
error("Couldn't rename file \"%s\" to \"%s\": %s", oldpath, |
newpath, fx2txt(status)); |
newpath, fx2txt(status)); |
|
|
buffer_put_int(&msg, id); |
buffer_put_int(&msg, id); |
buffer_put_cstring(&msg, oldpath); |
buffer_put_cstring(&msg, oldpath); |
buffer_put_cstring(&msg, newpath); |
buffer_put_cstring(&msg, newpath); |
send_msg(conn->fd_out, &msg); |
send_msg(conn, &msg); |
debug3("Sent message SSH2_FXP_SYMLINK \"%s\" -> \"%s\"", oldpath, |
debug3("Sent message SSH2_FXP_SYMLINK \"%s\" -> \"%s\"", oldpath, |
newpath); |
newpath); |
buffer_free(&msg); |
buffer_free(&msg); |
|
|
status = get_status(conn->fd_in, id); |
status = get_status(conn, id); |
if (status != SSH2_FX_OK) |
if (status != SSH2_FX_OK) |
error("Couldn't symlink file \"%s\" to \"%s\": %s", oldpath, |
error("Couldn't symlink file \"%s\" to \"%s\": %s", oldpath, |
newpath, fx2txt(status)); |
newpath, fx2txt(status)); |
|
|
Attrib *a; |
Attrib *a; |
|
|
expected_id = id = conn->msg_id++; |
expected_id = id = conn->msg_id++; |
send_string_request(conn->fd_out, id, SSH2_FXP_READLINK, path, |
send_string_request(conn, id, SSH2_FXP_READLINK, path, strlen(path)); |
strlen(path)); |
|
|
|
buffer_init(&msg); |
buffer_init(&msg); |
|
|
get_msg(conn->fd_in, &msg); |
get_msg(conn, &msg); |
type = buffer_get_char(&msg); |
type = buffer_get_char(&msg); |
id = buffer_get_int(&msg); |
id = buffer_get_int(&msg); |
|
|
|
|
buffer_put_int(&msg, id); |
buffer_put_int(&msg, id); |
buffer_put_cstring(&msg, "statvfs@openssh.com"); |
buffer_put_cstring(&msg, "statvfs@openssh.com"); |
buffer_put_cstring(&msg, path); |
buffer_put_cstring(&msg, path); |
send_msg(conn->fd_out, &msg); |
send_msg(conn, &msg); |
buffer_free(&msg); |
buffer_free(&msg); |
|
|
return get_decode_statvfs(conn->fd_in, st, id, quiet); |
return get_decode_statvfs(conn, st, id, quiet); |
} |
} |
|
|
#ifdef notyet |
#ifdef notyet |
|
|
buffer_put_int(&msg, id); |
buffer_put_int(&msg, id); |
buffer_put_cstring(&msg, "fstatvfs@openssh.com"); |
buffer_put_cstring(&msg, "fstatvfs@openssh.com"); |
buffer_put_string(&msg, handle, handle_len); |
buffer_put_string(&msg, handle, handle_len); |
send_msg(conn->fd_out, &msg); |
send_msg(conn, &msg); |
buffer_free(&msg); |
buffer_free(&msg); |
|
|
return get_decode_statvfs(conn->fd_in, st, id, quiet); |
return get_decode_statvfs(conn, st, id, quiet); |
} |
} |
#endif |
#endif |
|
|
static void |
static void |
send_read_request(int fd_out, u_int id, u_int64_t offset, u_int len, |
send_read_request(struct sftp_conn *conn, u_int id, u_int64_t offset, |
char *handle, u_int handle_len) |
u_int len, char *handle, u_int handle_len) |
{ |
{ |
Buffer msg; |
Buffer msg; |
|
|
|
|
buffer_put_string(&msg, handle, handle_len); |
buffer_put_string(&msg, handle, handle_len); |
buffer_put_int64(&msg, offset); |
buffer_put_int64(&msg, offset); |
buffer_put_int(&msg, len); |
buffer_put_int(&msg, len); |
send_msg(fd_out, &msg); |
send_msg(conn, &msg); |
buffer_free(&msg); |
buffer_free(&msg); |
} |
} |
|
|
|
|
buffer_put_int(&msg, SSH2_FXF_READ); |
buffer_put_int(&msg, SSH2_FXF_READ); |
attrib_clear(&junk); /* Send empty attributes */ |
attrib_clear(&junk); /* Send empty attributes */ |
encode_attrib(&msg, &junk); |
encode_attrib(&msg, &junk); |
send_msg(conn->fd_out, &msg); |
send_msg(conn, &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, id, &handle_len, |
"remote open(\"%s\")", remote_path); |
"remote open(\"%s\")", remote_path); |
if (handle == NULL) { |
if (handle == NULL) { |
buffer_free(&msg); |
buffer_free(&msg); |
|
|
offset += buflen; |
offset += buflen; |
num_req++; |
num_req++; |
TAILQ_INSERT_TAIL(&requests, req, tq); |
TAILQ_INSERT_TAIL(&requests, req, tq); |
send_read_request(conn->fd_out, req->id, req->offset, |
send_read_request(conn, req->id, req->offset, |
req->len, handle, handle_len); |
req->len, handle, handle_len); |
} |
} |
|
|
buffer_clear(&msg); |
buffer_clear(&msg); |
get_msg(conn->fd_in, &msg); |
get_msg(conn, &msg); |
type = buffer_get_char(&msg); |
type = buffer_get_char(&msg); |
id = buffer_get_int(&msg); |
id = buffer_get_int(&msg); |
debug3("Received reply T:%u I:%u R:%d", type, id, max_req); |
debug3("Received reply T:%u I:%u R:%d", type, id, max_req); |
|
|
req->id = conn->msg_id++; |
req->id = conn->msg_id++; |
req->len -= len; |
req->len -= len; |
req->offset += len; |
req->offset += len; |
send_read_request(conn->fd_out, req->id, |
send_read_request(conn, req->id, |
req->offset, req->len, handle, handle_len); |
req->offset, req->len, handle, handle_len); |
/* Reduce the request size */ |
/* Reduce the request size */ |
if (len < buflen) |
if (len < buflen) |
|
|
buffer_put_cstring(&msg, remote_path); |
buffer_put_cstring(&msg, remote_path); |
buffer_put_int(&msg, SSH2_FXF_WRITE|SSH2_FXF_CREAT|SSH2_FXF_TRUNC); |
buffer_put_int(&msg, SSH2_FXF_WRITE|SSH2_FXF_CREAT|SSH2_FXF_TRUNC); |
encode_attrib(&msg, &a); |
encode_attrib(&msg, &a); |
send_msg(conn->fd_out, &msg); |
send_msg(conn, &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); |
|
|
buffer_clear(&msg); |
buffer_clear(&msg); |
|
|
handle = get_handle(conn->fd_in, id, &handle_len, |
handle = get_handle(conn, id, &handle_len, |
"remote open(\"%s\")", remote_path); |
"remote open(\"%s\")", remote_path); |
if (handle == NULL) { |
if (handle == NULL) { |
close(local_fd); |
close(local_fd); |
|
|
buffer_put_string(&msg, handle, handle_len); |
buffer_put_string(&msg, handle, handle_len); |
buffer_put_int64(&msg, offset); |
buffer_put_int64(&msg, offset); |
buffer_put_string(&msg, data, len); |
buffer_put_string(&msg, data, len); |
send_msg(conn->fd_out, &msg); |
send_msg(conn, &msg); |
debug3("Sent message SSH2_FXP_WRITE I:%u O:%llu S:%u", |
debug3("Sent message SSH2_FXP_WRITE I:%u O:%llu S:%u", |
id, (unsigned long long)offset, len); |
id, (unsigned long long)offset, len); |
} else if (TAILQ_FIRST(&acks) == NULL) |
} else if (TAILQ_FIRST(&acks) == NULL) |
|
|
u_int r_id; |
u_int r_id; |
|
|
buffer_clear(&msg); |
buffer_clear(&msg); |
get_msg(conn->fd_in, &msg); |
get_msg(conn, &msg); |
type = buffer_get_char(&msg); |
type = buffer_get_char(&msg); |
r_id = buffer_get_int(&msg); |
r_id = buffer_get_int(&msg); |
|
|