summaryrefslogtreecommitdiff
path: root/sftp-server.c
diff options
context:
space:
mode:
Diffstat (limited to 'sftp-server.c')
-rw-r--r--sftp-server.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/sftp-server.c b/sftp-server.c
index 19a132bd9..359204fa7 100644
--- a/sftp-server.c
+++ b/sftp-server.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sftp-server.c,v 1.114 2019/01/16 23:22:10 djm Exp $ */ 1/* $OpenBSD: sftp-server.c,v 1.117 2019/07/05 04:55:40 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2000-2004 Markus Friedl. All rights reserved. 3 * Copyright (c) 2000-2004 Markus Friedl. All rights reserved.
4 * 4 *
@@ -51,6 +51,8 @@
51#include "sftp.h" 51#include "sftp.h"
52#include "sftp-common.h" 52#include "sftp-common.h"
53 53
54char *sftp_realpath(const char *, char *); /* sftp-realpath.c */
55
54/* Our verbosity */ 56/* Our verbosity */
55static LogLevel log_level = SYSLOG_LEVEL_ERROR; 57static LogLevel log_level = SYSLOG_LEVEL_ERROR;
56 58
@@ -701,7 +703,7 @@ process_open(u_int32_t id)
701 status = SSH2_FX_PERMISSION_DENIED; 703 status = SSH2_FX_PERMISSION_DENIED;
702 } else { 704 } else {
703 fd = open(name, flags, mode); 705 fd = open(name, flags, mode);
704 if (fd < 0) { 706 if (fd == -1) {
705 status = errno_to_portable(errno); 707 status = errno_to_portable(errno);
706 } else { 708 } else {
707 handle = handle_new(HANDLE_FILE, name, fd, flags, NULL); 709 handle = handle_new(HANDLE_FILE, name, fd, flags, NULL);
@@ -754,12 +756,12 @@ process_read(u_int32_t id)
754 } 756 }
755 fd = handle_to_fd(handle); 757 fd = handle_to_fd(handle);
756 if (fd >= 0) { 758 if (fd >= 0) {
757 if (lseek(fd, off, SEEK_SET) < 0) { 759 if (lseek(fd, off, SEEK_SET) == -1) {
758 error("process_read: seek failed"); 760 error("process_read: seek failed");
759 status = errno_to_portable(errno); 761 status = errno_to_portable(errno);
760 } else { 762 } else {
761 ret = read(fd, buf, len); 763 ret = read(fd, buf, len);
762 if (ret < 0) { 764 if (ret == -1) {
763 status = errno_to_portable(errno); 765 status = errno_to_portable(errno);
764 } else if (ret == 0) { 766 } else if (ret == 0) {
765 status = SSH2_FX_EOF; 767 status = SSH2_FX_EOF;
@@ -795,13 +797,13 @@ process_write(u_int32_t id)
795 status = SSH2_FX_FAILURE; 797 status = SSH2_FX_FAILURE;
796 else { 798 else {
797 if (!(handle_to_flags(handle) & O_APPEND) && 799 if (!(handle_to_flags(handle) & O_APPEND) &&
798 lseek(fd, off, SEEK_SET) < 0) { 800 lseek(fd, off, SEEK_SET) == -1) {
799 status = errno_to_portable(errno); 801 status = errno_to_portable(errno);
800 error("process_write: seek failed"); 802 error("process_write: seek failed");
801 } else { 803 } else {
802/* XXX ATOMICIO ? */ 804/* XXX ATOMICIO ? */
803 ret = write(fd, data, len); 805 ret = write(fd, data, len);
804 if (ret < 0) { 806 if (ret == -1) {
805 error("process_write: write failed"); 807 error("process_write: write failed");
806 status = errno_to_portable(errno); 808 status = errno_to_portable(errno);
807 } else if ((size_t)ret == len) { 809 } else if ((size_t)ret == len) {
@@ -831,7 +833,7 @@ process_do_stat(u_int32_t id, int do_lstat)
831 debug3("request %u: %sstat", id, do_lstat ? "l" : ""); 833 debug3("request %u: %sstat", id, do_lstat ? "l" : "");
832 verbose("%sstat name \"%s\"", do_lstat ? "l" : "", name); 834 verbose("%sstat name \"%s\"", do_lstat ? "l" : "", name);
833 r = do_lstat ? lstat(name, &st) : stat(name, &st); 835 r = do_lstat ? lstat(name, &st) : stat(name, &st);
834 if (r < 0) { 836 if (r == -1) {
835 status = errno_to_portable(errno); 837 status = errno_to_portable(errno);
836 } else { 838 } else {
837 stat_to_attrib(&st, &a); 839 stat_to_attrib(&st, &a);
@@ -869,7 +871,7 @@ process_fstat(u_int32_t id)
869 fd = handle_to_fd(handle); 871 fd = handle_to_fd(handle);
870 if (fd >= 0) { 872 if (fd >= 0) {
871 r = fstat(fd, &st); 873 r = fstat(fd, &st);
872 if (r < 0) { 874 if (r == -1) {
873 status = errno_to_portable(errno); 875 status = errno_to_portable(errno);
874 } else { 876 } else {
875 stat_to_attrib(&st, &a); 877 stat_to_attrib(&st, &a);
@@ -1079,7 +1081,7 @@ process_readdir(u_int32_t id)
1079/* XXX OVERFLOW ? */ 1081/* XXX OVERFLOW ? */
1080 snprintf(pathname, sizeof pathname, "%s%s%s", path, 1082 snprintf(pathname, sizeof pathname, "%s%s%s", path,
1081 strcmp(path, "/") ? "/" : "", dp->d_name); 1083 strcmp(path, "/") ? "/" : "", dp->d_name);
1082 if (lstat(pathname, &st) < 0) 1084 if (lstat(pathname, &st) == -1)
1083 continue; 1085 continue;
1084 stat_to_attrib(&st, &(stats[count].attrib)); 1086 stat_to_attrib(&st, &(stats[count].attrib));
1085 stats[count].name = xstrdup(dp->d_name); 1087 stats[count].name = xstrdup(dp->d_name);
@@ -1174,7 +1176,7 @@ process_realpath(u_int32_t id)
1174 } 1176 }
1175 debug3("request %u: realpath", id); 1177 debug3("request %u: realpath", id);
1176 verbose("realpath \"%s\"", path); 1178 verbose("realpath \"%s\"", path);
1177 if (realpath(path, resolvedname) == NULL) { 1179 if (sftp_realpath(path, resolvedname) == NULL) {
1178 send_status(id, errno_to_portable(errno)); 1180 send_status(id, errno_to_portable(errno));
1179 } else { 1181 } else {
1180 Stat s; 1182 Stat s;
@@ -1574,7 +1576,6 @@ sftp_server_main(int argc, char **argv, struct passwd *user_pw)
1574 extern char *optarg; 1576 extern char *optarg;
1575 extern char *__progname; 1577 extern char *__progname;
1576 1578
1577 ssh_malloc_init(); /* must be called before any mallocs */
1578 __progname = ssh_get_progname(argv[0]); 1579 __progname = ssh_get_progname(argv[0]);
1579 log_init(__progname, log_level, log_facility, log_stderr); 1580 log_init(__progname, log_level, log_facility, log_stderr);
1580 1581
@@ -1727,7 +1728,7 @@ sftp_server_main(int argc, char **argv, struct passwd *user_pw)
1727 if (olen > 0) 1728 if (olen > 0)
1728 FD_SET(out, wset); 1729 FD_SET(out, wset);
1729 1730
1730 if (select(max+1, rset, wset, NULL, NULL) < 0) { 1731 if (select(max+1, rset, wset, NULL, NULL) == -1) {
1731 if (errno == EINTR) 1732 if (errno == EINTR)
1732 continue; 1733 continue;
1733 error("select: %s", strerror(errno)); 1734 error("select: %s", strerror(errno));
@@ -1740,7 +1741,7 @@ sftp_server_main(int argc, char **argv, struct passwd *user_pw)
1740 if (len == 0) { 1741 if (len == 0) {
1741 debug("read eof"); 1742 debug("read eof");
1742 sftp_server_cleanup_exit(0); 1743 sftp_server_cleanup_exit(0);
1743 } else if (len < 0) { 1744 } else if (len == -1) {
1744 error("read: %s", strerror(errno)); 1745 error("read: %s", strerror(errno));
1745 sftp_server_cleanup_exit(1); 1746 sftp_server_cleanup_exit(1);
1746 } else if ((r = sshbuf_put(iqueue, buf, len)) != 0) { 1747 } else if ((r = sshbuf_put(iqueue, buf, len)) != 0) {
@@ -1751,7 +1752,7 @@ sftp_server_main(int argc, char **argv, struct passwd *user_pw)
1751 /* send oqueue to stdout */ 1752 /* send oqueue to stdout */
1752 if (FD_ISSET(out, wset)) { 1753 if (FD_ISSET(out, wset)) {
1753 len = write(out, sshbuf_ptr(oqueue), olen); 1754 len = write(out, sshbuf_ptr(oqueue), olen);
1754 if (len < 0) { 1755 if (len == -1) {
1755 error("write: %s", strerror(errno)); 1756 error("write: %s", strerror(errno));
1756 sftp_server_cleanup_exit(1); 1757 sftp_server_cleanup_exit(1);
1757 } else if ((r = sshbuf_consume(oqueue, len)) != 0) { 1758 } else if ((r = sshbuf_consume(oqueue, len)) != 0) {