version 1.115, 2019/06/06 05:13:13 |
version 1.116, 2019/06/28 13:35:04 |
|
|
status = SSH2_FX_PERMISSION_DENIED; |
status = SSH2_FX_PERMISSION_DENIED; |
} else { |
} else { |
fd = open(name, flags, mode); |
fd = open(name, flags, mode); |
if (fd < 0) { |
if (fd == -1) { |
status = errno_to_portable(errno); |
status = errno_to_portable(errno); |
} else { |
} else { |
handle = handle_new(HANDLE_FILE, name, fd, flags, NULL); |
handle = handle_new(HANDLE_FILE, name, fd, flags, NULL); |
|
|
} |
} |
fd = handle_to_fd(handle); |
fd = handle_to_fd(handle); |
if (fd >= 0) { |
if (fd >= 0) { |
if (lseek(fd, off, SEEK_SET) < 0) { |
if (lseek(fd, off, SEEK_SET) == -1) { |
error("process_read: seek failed"); |
error("process_read: seek failed"); |
status = errno_to_portable(errno); |
status = errno_to_portable(errno); |
} else { |
} else { |
ret = read(fd, buf, len); |
ret = read(fd, buf, len); |
if (ret < 0) { |
if (ret == -1) { |
status = errno_to_portable(errno); |
status = errno_to_portable(errno); |
} else if (ret == 0) { |
} else if (ret == 0) { |
status = SSH2_FX_EOF; |
status = SSH2_FX_EOF; |
|
|
status = SSH2_FX_FAILURE; |
status = SSH2_FX_FAILURE; |
else { |
else { |
if (!(handle_to_flags(handle) & O_APPEND) && |
if (!(handle_to_flags(handle) & O_APPEND) && |
lseek(fd, off, SEEK_SET) < 0) { |
lseek(fd, off, SEEK_SET) == -1) { |
status = errno_to_portable(errno); |
status = errno_to_portable(errno); |
error("process_write: seek failed"); |
error("process_write: seek failed"); |
} else { |
} else { |
/* XXX ATOMICIO ? */ |
/* XXX ATOMICIO ? */ |
ret = write(fd, data, len); |
ret = write(fd, data, len); |
if (ret < 0) { |
if (ret == -1) { |
error("process_write: write failed"); |
error("process_write: write failed"); |
status = errno_to_portable(errno); |
status = errno_to_portable(errno); |
} else if ((size_t)ret == len) { |
} else if ((size_t)ret == len) { |
|
|
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); |
r = do_lstat ? lstat(name, &st) : stat(name, &st); |
r = do_lstat ? lstat(name, &st) : stat(name, &st); |
if (r < 0) { |
if (r == -1) { |
status = errno_to_portable(errno); |
status = errno_to_portable(errno); |
} else { |
} else { |
stat_to_attrib(&st, &a); |
stat_to_attrib(&st, &a); |
|
|
fd = handle_to_fd(handle); |
fd = handle_to_fd(handle); |
if (fd >= 0) { |
if (fd >= 0) { |
r = fstat(fd, &st); |
r = fstat(fd, &st); |
if (r < 0) { |
if (r == -1) { |
status = errno_to_portable(errno); |
status = errno_to_portable(errno); |
} else { |
} else { |
stat_to_attrib(&st, &a); |
stat_to_attrib(&st, &a); |
|
|
/* XXX OVERFLOW ? */ |
/* XXX OVERFLOW ? */ |
snprintf(pathname, sizeof pathname, "%s%s%s", path, |
snprintf(pathname, sizeof pathname, "%s%s%s", path, |
strcmp(path, "/") ? "/" : "", dp->d_name); |
strcmp(path, "/") ? "/" : "", dp->d_name); |
if (lstat(pathname, &st) < 0) |
if (lstat(pathname, &st) == -1) |
continue; |
continue; |
stat_to_attrib(&st, &(stats[count].attrib)); |
stat_to_attrib(&st, &(stats[count].attrib)); |
stats[count].name = xstrdup(dp->d_name); |
stats[count].name = xstrdup(dp->d_name); |
|
|
if (olen > 0) |
if (olen > 0) |
FD_SET(out, wset); |
FD_SET(out, wset); |
|
|
if (select(max+1, rset, wset, NULL, NULL) < 0) { |
if (select(max+1, rset, wset, NULL, NULL) == -1) { |
if (errno == EINTR) |
if (errno == EINTR) |
continue; |
continue; |
error("select: %s", strerror(errno)); |
error("select: %s", strerror(errno)); |
|
|
if (len == 0) { |
if (len == 0) { |
debug("read eof"); |
debug("read eof"); |
sftp_server_cleanup_exit(0); |
sftp_server_cleanup_exit(0); |
} else if (len < 0) { |
} 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) { |
|
|
/* send oqueue to stdout */ |
/* send oqueue to stdout */ |
if (FD_ISSET(out, wset)) { |
if (FD_ISSET(out, wset)) { |
len = write(out, sshbuf_ptr(oqueue), olen); |
len = write(out, sshbuf_ptr(oqueue), olen); |
if (len < 0) { |
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) { |