version 1.119, 2020/07/17 03:51:32 |
version 1.120, 2020/10/18 11:32:02 |
|
|
int r; |
int r; |
|
|
if ((r = sshbuf_put_stringb(oqueue, m)) != 0) |
if ((r = sshbuf_put_stringb(oqueue, m)) != 0) |
fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
fatal_fr(r, "enqueue"); |
sshbuf_reset(m); |
sshbuf_reset(m); |
} |
} |
|
|
|
|
(status != SSH2_FX_OK && status != SSH2_FX_EOF)) |
(status != SSH2_FX_OK && status != SSH2_FX_EOF)) |
logit("sent status %s", status_to_message(status)); |
logit("sent status %s", status_to_message(status)); |
if ((msg = sshbuf_new()) == NULL) |
if ((msg = sshbuf_new()) == NULL) |
fatal("%s: sshbuf_new failed", __func__); |
fatal_f("sshbuf_new failed"); |
if ((r = sshbuf_put_u8(msg, SSH2_FXP_STATUS)) != 0 || |
if ((r = sshbuf_put_u8(msg, SSH2_FXP_STATUS)) != 0 || |
(r = sshbuf_put_u32(msg, id)) != 0 || |
(r = sshbuf_put_u32(msg, id)) != 0 || |
(r = sshbuf_put_u32(msg, status)) != 0) |
(r = sshbuf_put_u32(msg, status)) != 0) |
fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
fatal_fr(r, "compose"); |
if (version >= 3) { |
if (version >= 3) { |
if ((r = sshbuf_put_cstring(msg, |
if ((r = sshbuf_put_cstring(msg, |
status_to_message(status))) != 0 || |
status_to_message(status))) != 0 || |
(r = sshbuf_put_cstring(msg, "")) != 0) |
(r = sshbuf_put_cstring(msg, "")) != 0) |
fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
fatal_fr(r, "compose message"); |
} |
} |
send_msg(msg); |
send_msg(msg); |
sshbuf_free(msg); |
sshbuf_free(msg); |
|
|
int r; |
int r; |
|
|
if ((msg = sshbuf_new()) == NULL) |
if ((msg = sshbuf_new()) == NULL) |
fatal("%s: sshbuf_new failed", __func__); |
fatal_f("sshbuf_new failed"); |
if ((r = sshbuf_put_u8(msg, type)) != 0 || |
if ((r = sshbuf_put_u8(msg, type)) != 0 || |
(r = sshbuf_put_u32(msg, id)) != 0 || |
(r = sshbuf_put_u32(msg, id)) != 0 || |
(r = sshbuf_put_string(msg, data, dlen)) != 0) |
(r = sshbuf_put_string(msg, data, dlen)) != 0) |
fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
fatal_fr(r, "compose"); |
send_msg(msg); |
send_msg(msg); |
sshbuf_free(msg); |
sshbuf_free(msg); |
} |
} |
|
|
int i, r; |
int i, r; |
|
|
if ((msg = sshbuf_new()) == NULL) |
if ((msg = sshbuf_new()) == NULL) |
fatal("%s: sshbuf_new failed", __func__); |
fatal_f("sshbuf_new failed"); |
if ((r = sshbuf_put_u8(msg, SSH2_FXP_NAME)) != 0 || |
if ((r = sshbuf_put_u8(msg, SSH2_FXP_NAME)) != 0 || |
(r = sshbuf_put_u32(msg, id)) != 0 || |
(r = sshbuf_put_u32(msg, id)) != 0 || |
(r = sshbuf_put_u32(msg, count)) != 0) |
(r = sshbuf_put_u32(msg, count)) != 0) |
fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
fatal_fr(r, "compose"); |
debug("request %u: sent names count %d", id, count); |
debug("request %u: sent names count %d", id, count); |
for (i = 0; i < count; i++) { |
for (i = 0; i < count; i++) { |
if ((r = sshbuf_put_cstring(msg, stats[i].name)) != 0 || |
if ((r = sshbuf_put_cstring(msg, stats[i].name)) != 0 || |
(r = sshbuf_put_cstring(msg, stats[i].long_name)) != 0 || |
(r = sshbuf_put_cstring(msg, stats[i].long_name)) != 0 || |
(r = encode_attrib(msg, &stats[i].attrib)) != 0) |
(r = encode_attrib(msg, &stats[i].attrib)) != 0) |
fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
fatal_fr(r, "compose filenames/attrib"); |
} |
} |
send_msg(msg); |
send_msg(msg); |
sshbuf_free(msg); |
sshbuf_free(msg); |
|
|
|
|
debug("request %u: sent attrib have 0x%x", id, a->flags); |
debug("request %u: sent attrib have 0x%x", id, a->flags); |
if ((msg = sshbuf_new()) == NULL) |
if ((msg = sshbuf_new()) == NULL) |
fatal("%s: sshbuf_new failed", __func__); |
fatal_f("sshbuf_new failed"); |
if ((r = sshbuf_put_u8(msg, SSH2_FXP_ATTRS)) != 0 || |
if ((r = sshbuf_put_u8(msg, SSH2_FXP_ATTRS)) != 0 || |
(r = sshbuf_put_u32(msg, id)) != 0 || |
(r = sshbuf_put_u32(msg, id)) != 0 || |
(r = encode_attrib(msg, a)) != 0) |
(r = encode_attrib(msg, a)) != 0) |
fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
fatal_fr(r, "compose"); |
send_msg(msg); |
send_msg(msg); |
sshbuf_free(msg); |
sshbuf_free(msg); |
} |
} |
|
|
flag |= (st->f_flag & ST_NOSUID) ? SSH2_FXE_STATVFS_ST_NOSUID : 0; |
flag |= (st->f_flag & ST_NOSUID) ? SSH2_FXE_STATVFS_ST_NOSUID : 0; |
|
|
if ((msg = sshbuf_new()) == NULL) |
if ((msg = sshbuf_new()) == NULL) |
fatal("%s: sshbuf_new failed", __func__); |
fatal_f("sshbuf_new failed"); |
if ((r = sshbuf_put_u8(msg, SSH2_FXP_EXTENDED_REPLY)) != 0 || |
if ((r = sshbuf_put_u8(msg, SSH2_FXP_EXTENDED_REPLY)) != 0 || |
(r = sshbuf_put_u32(msg, id)) != 0 || |
(r = sshbuf_put_u32(msg, id)) != 0 || |
(r = sshbuf_put_u64(msg, st->f_bsize)) != 0 || |
(r = sshbuf_put_u64(msg, st->f_bsize)) != 0 || |
|
|
(r = sshbuf_put_u64(msg, st->f_fsid)) != 0 || |
(r = sshbuf_put_u64(msg, st->f_fsid)) != 0 || |
(r = sshbuf_put_u64(msg, flag)) != 0 || |
(r = sshbuf_put_u64(msg, flag)) != 0 || |
(r = sshbuf_put_u64(msg, st->f_namemax)) != 0) |
(r = sshbuf_put_u64(msg, st->f_namemax)) != 0) |
fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
fatal_fr(r, "compose"); |
send_msg(msg); |
send_msg(msg); |
sshbuf_free(msg); |
sshbuf_free(msg); |
} |
} |
|
|
int r; |
int r; |
|
|
if ((r = sshbuf_get_u32(iqueue, &version)) != 0) |
if ((r = sshbuf_get_u32(iqueue, &version)) != 0) |
fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
fatal_fr(r, "parse"); |
verbose("received client version %u", version); |
verbose("received client version %u", version); |
if ((msg = sshbuf_new()) == NULL) |
if ((msg = sshbuf_new()) == NULL) |
fatal("%s: sshbuf_new failed", __func__); |
fatal_f("sshbuf_new failed"); |
if ((r = sshbuf_put_u8(msg, SSH2_FXP_VERSION)) != 0 || |
if ((r = sshbuf_put_u8(msg, SSH2_FXP_VERSION)) != 0 || |
(r = sshbuf_put_u32(msg, SSH2_FILEXFER_VERSION)) != 0 || |
(r = sshbuf_put_u32(msg, SSH2_FILEXFER_VERSION)) != 0 || |
/* POSIX rename extension */ |
/* POSIX rename extension */ |
|
|
(r = sshbuf_put_cstring(msg, "1")) != 0 || /* version */ |
(r = sshbuf_put_cstring(msg, "1")) != 0 || /* version */ |
(r = sshbuf_put_cstring(msg, "lsetstat@openssh.com")) != 0 || |
(r = sshbuf_put_cstring(msg, "lsetstat@openssh.com")) != 0 || |
(r = sshbuf_put_cstring(msg, "1")) != 0) /* version */ |
(r = sshbuf_put_cstring(msg, "1")) != 0) /* version */ |
fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
fatal_fr(r, "compose"); |
send_msg(msg); |
send_msg(msg); |
sshbuf_free(msg); |
sshbuf_free(msg); |
} |
} |
|
|
if ((r = sshbuf_get_cstring(iqueue, &name, NULL)) != 0 || |
if ((r = sshbuf_get_cstring(iqueue, &name, NULL)) != 0 || |
(r = sshbuf_get_u32(iqueue, &pflags)) != 0 || /* portable flags */ |
(r = sshbuf_get_u32(iqueue, &pflags)) != 0 || /* portable flags */ |
(r = decode_attrib(iqueue, &a)) != 0) |
(r = decode_attrib(iqueue, &a)) != 0) |
fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
fatal_fr(r, "parse"); |
|
|
debug3("request %u: open flags %d", id, pflags); |
debug3("request %u: open flags %d", id, pflags); |
flags = flags_from_portable(pflags); |
flags = flags_from_portable(pflags); |
|
|
int r, handle, ret, status = SSH2_FX_FAILURE; |
int r, handle, ret, status = SSH2_FX_FAILURE; |
|
|
if ((r = get_handle(iqueue, &handle)) != 0) |
if ((r = get_handle(iqueue, &handle)) != 0) |
fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
fatal_fr(r, "parse"); |
|
|
debug3("request %u: close handle %u", id, handle); |
debug3("request %u: close handle %u", id, handle); |
handle_log_close(handle, NULL); |
handle_log_close(handle, NULL); |
|
|
if ((r = get_handle(iqueue, &handle)) != 0 || |
if ((r = get_handle(iqueue, &handle)) != 0 || |
(r = sshbuf_get_u64(iqueue, &off)) != 0 || |
(r = sshbuf_get_u64(iqueue, &off)) != 0 || |
(r = sshbuf_get_u32(iqueue, &len)) != 0) |
(r = sshbuf_get_u32(iqueue, &len)) != 0) |
fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
fatal_fr(r, "parse"); |
|
|
debug("request %u: read \"%s\" (handle %d) off %llu len %d", |
debug("request %u: read \"%s\" (handle %d) off %llu len %d", |
id, handle_to_name(handle), handle, (unsigned long long)off, len); |
id, handle_to_name(handle), handle, (unsigned long long)off, len); |
|
|
if ((r = get_handle(iqueue, &handle)) != 0 || |
if ((r = get_handle(iqueue, &handle)) != 0 || |
(r = sshbuf_get_u64(iqueue, &off)) != 0 || |
(r = sshbuf_get_u64(iqueue, &off)) != 0 || |
(r = sshbuf_get_string(iqueue, &data, &len)) != 0) |
(r = sshbuf_get_string(iqueue, &data, &len)) != 0) |
fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
fatal_fr(r, "parse"); |
|
|
debug("request %u: write \"%s\" (handle %d) off %llu len %zu", |
debug("request %u: write \"%s\" (handle %d) off %llu len %zu", |
id, handle_to_name(handle), handle, (unsigned long long)off, len); |
id, handle_to_name(handle), handle, (unsigned long long)off, len); |
|
|
if (!(handle_to_flags(handle) & O_APPEND) && |
if (!(handle_to_flags(handle) & O_APPEND) && |
lseek(fd, off, SEEK_SET) == -1) { |
lseek(fd, off, SEEK_SET) == -1) { |
status = errno_to_portable(errno); |
status = errno_to_portable(errno); |
error("%s: seek failed", __func__); |
error_f("seek failed"); |
} else { |
} else { |
/* XXX ATOMICIO ? */ |
/* XXX ATOMICIO ? */ |
ret = write(fd, data, len); |
ret = write(fd, data, len); |
if (ret == -1) { |
if (ret == -1) { |
error("%s: write: %s", __func__, |
error_f("write: %s", strerror(errno)); |
strerror(errno)); |
|
status = errno_to_portable(errno); |
status = errno_to_portable(errno); |
} else if ((size_t)ret == len) { |
} else if ((size_t)ret == len) { |
status = SSH2_FX_OK; |
status = SSH2_FX_OK; |
handle_update_write(handle, ret); |
handle_update_write(handle, ret); |
} else { |
} else { |
debug2("%s: nothing at all written", __func__); |
debug2_f("nothing at all written"); |
status = SSH2_FX_FAILURE; |
status = SSH2_FX_FAILURE; |
} |
} |
} |
} |
|
|
int r, status = SSH2_FX_FAILURE; |
int r, status = SSH2_FX_FAILURE; |
|
|
if ((r = sshbuf_get_cstring(iqueue, &name, NULL)) != 0) |
if ((r = sshbuf_get_cstring(iqueue, &name, NULL)) != 0) |
fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
fatal_fr(r, "parse"); |
|
|
debug3("request %u: %sstat", id, do_lstat ? "l" : ""); |
debug3("request %u: %sstat", id, do_lstat ? "l" : ""); |
verbose("%sstat name \"%s\"", do_lstat ? "l" : "", name); |
verbose("%sstat name \"%s\"", do_lstat ? "l" : "", name); |
|
|
int fd, r, handle, status = SSH2_FX_FAILURE; |
int fd, r, handle, status = SSH2_FX_FAILURE; |
|
|
if ((r = get_handle(iqueue, &handle)) != 0) |
if ((r = get_handle(iqueue, &handle)) != 0) |
fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
fatal_fr(r, "parse"); |
debug("request %u: fstat \"%s\" (handle %u)", |
debug("request %u: fstat \"%s\" (handle %u)", |
id, handle_to_name(handle), handle); |
id, handle_to_name(handle), handle); |
fd = handle_to_fd(handle); |
fd = handle_to_fd(handle); |
|
|
|
|
if ((r = sshbuf_get_cstring(iqueue, &name, NULL)) != 0 || |
if ((r = sshbuf_get_cstring(iqueue, &name, NULL)) != 0 || |
(r = decode_attrib(iqueue, &a)) != 0) |
(r = decode_attrib(iqueue, &a)) != 0) |
fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
fatal_fr(r, "parse"); |
|
|
debug("request %u: setstat name \"%s\"", id, name); |
debug("request %u: setstat name \"%s\"", id, name); |
if (a.flags & SSH2_FILEXFER_ATTR_SIZE) { |
if (a.flags & SSH2_FILEXFER_ATTR_SIZE) { |
|
|
|
|
if ((r = get_handle(iqueue, &handle)) != 0 || |
if ((r = get_handle(iqueue, &handle)) != 0 || |
(r = decode_attrib(iqueue, &a)) != 0) |
(r = decode_attrib(iqueue, &a)) != 0) |
fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
fatal_fr(r, "parse"); |
|
|
debug("request %u: fsetstat handle %d", id, handle); |
debug("request %u: fsetstat handle %d", id, handle); |
fd = handle_to_fd(handle); |
fd = handle_to_fd(handle); |
|
|
int r, handle, status = SSH2_FX_FAILURE; |
int r, handle, status = SSH2_FX_FAILURE; |
|
|
if ((r = sshbuf_get_cstring(iqueue, &path, NULL)) != 0) |
if ((r = sshbuf_get_cstring(iqueue, &path, NULL)) != 0) |
fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
fatal_fr(r, "parse"); |
|
|
debug3("request %u: opendir", id); |
debug3("request %u: opendir", id); |
logit("opendir \"%s\"", path); |
logit("opendir \"%s\"", path); |
|
|
int r, handle; |
int r, handle; |
|
|
if ((r = get_handle(iqueue, &handle)) != 0) |
if ((r = get_handle(iqueue, &handle)) != 0) |
fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
fatal_fr(r, "parse"); |
|
|
debug("request %u: readdir \"%s\" (handle %d)", id, |
debug("request %u: readdir \"%s\" (handle %d)", id, |
handle_to_name(handle), handle); |
handle_to_name(handle), handle); |
|
|
int r, status = SSH2_FX_FAILURE; |
int r, status = SSH2_FX_FAILURE; |
|
|
if ((r = sshbuf_get_cstring(iqueue, &name, NULL)) != 0) |
if ((r = sshbuf_get_cstring(iqueue, &name, NULL)) != 0) |
fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
fatal_fr(r, "parse"); |
|
|
debug3("request %u: remove", id); |
debug3("request %u: remove", id); |
logit("remove name \"%s\"", name); |
logit("remove name \"%s\"", name); |
|
|
|
|
if ((r = sshbuf_get_cstring(iqueue, &name, NULL)) != 0 || |
if ((r = sshbuf_get_cstring(iqueue, &name, NULL)) != 0 || |
(r = decode_attrib(iqueue, &a)) != 0) |
(r = decode_attrib(iqueue, &a)) != 0) |
fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
fatal_fr(r, "parse"); |
|
|
mode = (a.flags & SSH2_FILEXFER_ATTR_PERMISSIONS) ? |
mode = (a.flags & SSH2_FILEXFER_ATTR_PERMISSIONS) ? |
a.perm & 07777 : 0777; |
a.perm & 07777 : 0777; |
|
|
int r, status; |
int r, status; |
|
|
if ((r = sshbuf_get_cstring(iqueue, &name, NULL)) != 0) |
if ((r = sshbuf_get_cstring(iqueue, &name, NULL)) != 0) |
fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
fatal_fr(r, "parse"); |
|
|
debug3("request %u: rmdir", id); |
debug3("request %u: rmdir", id); |
logit("rmdir name \"%s\"", name); |
logit("rmdir name \"%s\"", name); |
|
|
int r; |
int r; |
|
|
if ((r = sshbuf_get_cstring(iqueue, &path, NULL)) != 0) |
if ((r = sshbuf_get_cstring(iqueue, &path, NULL)) != 0) |
fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
fatal_fr(r, "parse"); |
|
|
if (path[0] == '\0') { |
if (path[0] == '\0') { |
free(path); |
free(path); |
|
|
|
|
if ((r = sshbuf_get_cstring(iqueue, &oldpath, NULL)) != 0 || |
if ((r = sshbuf_get_cstring(iqueue, &oldpath, NULL)) != 0 || |
(r = sshbuf_get_cstring(iqueue, &newpath, NULL)) != 0) |
(r = sshbuf_get_cstring(iqueue, &newpath, NULL)) != 0) |
fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
fatal_fr(r, "parse"); |
|
|
debug3("request %u: rename", id); |
debug3("request %u: rename", id); |
logit("rename old \"%s\" new \"%s\"", oldpath, newpath); |
logit("rename old \"%s\" new \"%s\"", oldpath, newpath); |
|
|
char *path; |
char *path; |
|
|
if ((r = sshbuf_get_cstring(iqueue, &path, NULL)) != 0) |
if ((r = sshbuf_get_cstring(iqueue, &path, NULL)) != 0) |
fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
fatal_fr(r, "parse"); |
|
|
debug3("request %u: readlink", id); |
debug3("request %u: readlink", id); |
verbose("readlink \"%s\"", path); |
verbose("readlink \"%s\"", path); |
|
|
|
|
if ((r = sshbuf_get_cstring(iqueue, &oldpath, NULL)) != 0 || |
if ((r = sshbuf_get_cstring(iqueue, &oldpath, NULL)) != 0 || |
(r = sshbuf_get_cstring(iqueue, &newpath, NULL)) != 0) |
(r = sshbuf_get_cstring(iqueue, &newpath, NULL)) != 0) |
fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
fatal_fr(r, "parse"); |
|
|
debug3("request %u: symlink", id); |
debug3("request %u: symlink", id); |
logit("symlink old \"%s\" new \"%s\"", oldpath, newpath); |
logit("symlink old \"%s\" new \"%s\"", oldpath, newpath); |
|
|
|
|
if ((r = sshbuf_get_cstring(iqueue, &oldpath, NULL)) != 0 || |
if ((r = sshbuf_get_cstring(iqueue, &oldpath, NULL)) != 0 || |
(r = sshbuf_get_cstring(iqueue, &newpath, NULL)) != 0) |
(r = sshbuf_get_cstring(iqueue, &newpath, NULL)) != 0) |
fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
fatal_fr(r, "parse"); |
|
|
debug3("request %u: posix-rename", id); |
debug3("request %u: posix-rename", id); |
logit("posix-rename old \"%s\" new \"%s\"", oldpath, newpath); |
logit("posix-rename old \"%s\" new \"%s\"", oldpath, newpath); |
|
|
int r; |
int r; |
|
|
if ((r = sshbuf_get_cstring(iqueue, &path, NULL)) != 0) |
if ((r = sshbuf_get_cstring(iqueue, &path, NULL)) != 0) |
fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
fatal_fr(r, "parse"); |
debug3("request %u: statvfs", id); |
debug3("request %u: statvfs", id); |
logit("statvfs \"%s\"", path); |
logit("statvfs \"%s\"", path); |
|
|
|
|
struct statvfs st; |
struct statvfs st; |
|
|
if ((r = get_handle(iqueue, &handle)) != 0) |
if ((r = get_handle(iqueue, &handle)) != 0) |
fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
fatal_fr(r, "parse"); |
debug("request %u: fstatvfs \"%s\" (handle %u)", |
debug("request %u: fstatvfs \"%s\" (handle %u)", |
id, handle_to_name(handle), handle); |
id, handle_to_name(handle), handle); |
if ((fd = handle_to_fd(handle)) < 0) { |
if ((fd = handle_to_fd(handle)) < 0) { |
|
|
|
|
if ((r = sshbuf_get_cstring(iqueue, &oldpath, NULL)) != 0 || |
if ((r = sshbuf_get_cstring(iqueue, &oldpath, NULL)) != 0 || |
(r = sshbuf_get_cstring(iqueue, &newpath, NULL)) != 0) |
(r = sshbuf_get_cstring(iqueue, &newpath, NULL)) != 0) |
fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
fatal_fr(r, "parse"); |
|
|
debug3("request %u: hardlink", id); |
debug3("request %u: hardlink", id); |
logit("hardlink old \"%s\" new \"%s\"", oldpath, newpath); |
logit("hardlink old \"%s\" new \"%s\"", oldpath, newpath); |
|
|
int handle, fd, r, status = SSH2_FX_OP_UNSUPPORTED; |
int handle, fd, r, status = SSH2_FX_OP_UNSUPPORTED; |
|
|
if ((r = get_handle(iqueue, &handle)) != 0) |
if ((r = get_handle(iqueue, &handle)) != 0) |
fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
fatal_fr(r, "parse"); |
debug3("request %u: fsync (handle %u)", id, handle); |
debug3("request %u: fsync (handle %u)", id, handle); |
verbose("fsync \"%s\"", handle_to_name(handle)); |
verbose("fsync \"%s\"", handle_to_name(handle)); |
if ((fd = handle_to_fd(handle)) < 0) |
if ((fd = handle_to_fd(handle)) < 0) |
|
|
|
|
if ((r = sshbuf_get_cstring(iqueue, &name, NULL)) != 0 || |
if ((r = sshbuf_get_cstring(iqueue, &name, NULL)) != 0 || |
(r = decode_attrib(iqueue, &a)) != 0) |
(r = decode_attrib(iqueue, &a)) != 0) |
fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
fatal_fr(r, "parse"); |
|
|
debug("request %u: lsetstat name \"%s\"", id, name); |
debug("request %u: lsetstat name \"%s\"", id, name); |
if (a.flags & SSH2_FILEXFER_ATTR_SIZE) { |
if (a.flags & SSH2_FILEXFER_ATTR_SIZE) { |
|
|
int i, r; |
int i, r; |
|
|
if ((r = sshbuf_get_cstring(iqueue, &request, NULL)) != 0) |
if ((r = sshbuf_get_cstring(iqueue, &request, NULL)) != 0) |
fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
fatal_fr(r, "parse"); |
for (i = 0; extended_handlers[i].handler != NULL; i++) { |
for (i = 0; extended_handlers[i].handler != NULL; i++) { |
if (strcmp(request, extended_handlers[i].ext_name) == 0) { |
if (strcmp(request, extended_handlers[i].ext_name) == 0) { |
if (!request_permitted(&extended_handlers[i])) |
if (!request_permitted(&extended_handlers[i])) |
|
|
if (buf_len < msg_len + 4) |
if (buf_len < msg_len + 4) |
return; |
return; |
if ((r = sshbuf_consume(iqueue, 4)) != 0) |
if ((r = sshbuf_consume(iqueue, 4)) != 0) |
fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
fatal_fr(r, "consume"); |
buf_len -= 4; |
buf_len -= 4; |
if ((r = sshbuf_get_u8(iqueue, &type)) != 0) |
if ((r = sshbuf_get_u8(iqueue, &type)) != 0) |
fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
fatal_fr(r, "parse type"); |
|
|
switch (type) { |
switch (type) { |
case SSH2_FXP_INIT: |
case SSH2_FXP_INIT: |
|
|
if (!init_done) |
if (!init_done) |
fatal("Received extended request before init"); |
fatal("Received extended request before init"); |
if ((r = sshbuf_get_u32(iqueue, &id)) != 0) |
if ((r = sshbuf_get_u32(iqueue, &id)) != 0) |
fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
fatal_fr(r, "parse extended ID"); |
process_extended(id); |
process_extended(id); |
break; |
break; |
default: |
default: |
if (!init_done) |
if (!init_done) |
fatal("Received %u request before init", type); |
fatal("Received %u request before init", type); |
if ((r = sshbuf_get_u32(iqueue, &id)) != 0) |
if ((r = sshbuf_get_u32(iqueue, &id)) != 0) |
fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
fatal_fr(r, "parse ID"); |
for (i = 0; handlers[i].handler != NULL; i++) { |
for (i = 0; handlers[i].handler != NULL; i++) { |
if (type == handlers[i].type) { |
if (type == handlers[i].type) { |
if (!request_permitted(&handlers[i])) { |
if (!request_permitted(&handlers[i])) { |
|
|
} |
} |
if (msg_len > consumed && |
if (msg_len > consumed && |
(r = sshbuf_consume(iqueue, msg_len - consumed)) != 0) |
(r = sshbuf_consume(iqueue, msg_len - consumed)) != 0) |
fatal("%s: buffer error: %s", __func__, ssh_err(r)); |
fatal_fr(r, "consume"); |
} |
} |
|
|
/* Cleanup handler that logs active handles upon normal exit */ |
/* Cleanup handler that logs active handles upon normal exit */ |
|
|
max = out; |
max = out; |
|
|
if ((iqueue = sshbuf_new()) == NULL) |
if ((iqueue = sshbuf_new()) == NULL) |
fatal("%s: sshbuf_new failed", __func__); |
fatal_f("sshbuf_new failed"); |
if ((oqueue = sshbuf_new()) == NULL) |
if ((oqueue = sshbuf_new()) == NULL) |
fatal("%s: sshbuf_new failed", __func__); |
fatal_f("sshbuf_new failed"); |
|
|
rset = xcalloc(howmany(max + 1, NFDBITS), sizeof(fd_mask)); |
rset = xcalloc(howmany(max + 1, NFDBITS), sizeof(fd_mask)); |
wset = xcalloc(howmany(max + 1, NFDBITS), sizeof(fd_mask)); |
wset = xcalloc(howmany(max + 1, NFDBITS), sizeof(fd_mask)); |
|
|
SFTP_MAX_MSG_LENGTH)) == 0) |
SFTP_MAX_MSG_LENGTH)) == 0) |
FD_SET(in, rset); |
FD_SET(in, rset); |
else if (r != SSH_ERR_NO_BUFFER_SPACE) |
else if (r != SSH_ERR_NO_BUFFER_SPACE) |
fatal("%s: sshbuf_check_reserve failed: %s", |
fatal_fr(r, "reserve"); |
__func__, ssh_err(r)); |
|
|
|
olen = sshbuf_len(oqueue); |
olen = sshbuf_len(oqueue); |
if (olen > 0) |
if (olen > 0) |
|
|
} else if (len == -1) { |
} else if (len == -1) { |
error("read: %s", strerror(errno)); |
error("read: %s", strerror(errno)); |
sftp_server_cleanup_exit(1); |
sftp_server_cleanup_exit(1); |
} else if ((r = sshbuf_put(iqueue, buf, len)) != 0) { |
} else if ((r = sshbuf_put(iqueue, buf, len)) != 0) |
fatal("%s: buffer error: %s", |
fatal_fr(r, "sshbuf_put"); |
__func__, ssh_err(r)); |
|
} |
|
} |
} |
/* send oqueue to stdout */ |
/* send oqueue to stdout */ |
if (FD_ISSET(out, wset)) { |
if (FD_ISSET(out, wset)) { |
|
|
if (len == -1) { |
if (len == -1) { |
error("write: %s", strerror(errno)); |
error("write: %s", strerror(errno)); |
sftp_server_cleanup_exit(1); |
sftp_server_cleanup_exit(1); |
} else if ((r = sshbuf_consume(oqueue, len)) != 0) { |
} else if ((r = sshbuf_consume(oqueue, len)) != 0) |
fatal("%s: buffer error: %s", |
fatal_fr(r, "consume"); |
__func__, ssh_err(r)); |
|
} |
|
} |
} |
|
|
/* |
/* |
|
|
if (r == 0) |
if (r == 0) |
process(); |
process(); |
else if (r != SSH_ERR_NO_BUFFER_SPACE) |
else if (r != SSH_ERR_NO_BUFFER_SPACE) |
fatal("%s: sshbuf_check_reserve: %s", |
fatal_fr(r, "reserve"); |
__func__, ssh_err(r)); |
|
} |
} |
} |
} |