summaryrefslogtreecommitdiff
path: root/sftp-server.c
diff options
context:
space:
mode:
Diffstat (limited to 'sftp-server.c')
-rw-r--r--sftp-server.c34
1 files changed, 25 insertions, 9 deletions
diff --git a/sftp-server.c b/sftp-server.c
index 64777beff..76edebc5a 100644
--- a/sftp-server.c
+++ b/sftp-server.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sftp-server.c,v 1.71 2007/01/03 07:22:36 stevesk Exp $ */ 1/* $OpenBSD: sftp-server.c,v 1.73 2007/05/17 07:55:29 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 *
@@ -319,7 +319,8 @@ handle_log_close(int handle, char *emsg)
319 logit("%s%sclose \"%s\" bytes read %llu written %llu", 319 logit("%s%sclose \"%s\" bytes read %llu written %llu",
320 emsg == NULL ? "" : emsg, emsg == NULL ? "" : " ", 320 emsg == NULL ? "" : emsg, emsg == NULL ? "" : " ",
321 handle_to_name(handle), 321 handle_to_name(handle),
322 handle_bytes_read(handle), handle_bytes_write(handle)); 322 (unsigned long long)handle_bytes_read(handle),
323 (unsigned long long)handle_bytes_write(handle));
323 } else { 324 } else {
324 logit("%s%sclosedir \"%s\"", 325 logit("%s%sclosedir \"%s\"",
325 emsg == NULL ? "" : emsg, emsg == NULL ? "" : " ", 326 emsg == NULL ? "" : emsg, emsg == NULL ? "" : " ",
@@ -702,7 +703,8 @@ process_setstat(void)
702 a = get_attrib(); 703 a = get_attrib();
703 debug("request %u: setstat name \"%s\"", id, name); 704 debug("request %u: setstat name \"%s\"", id, name);
704 if (a->flags & SSH2_FILEXFER_ATTR_SIZE) { 705 if (a->flags & SSH2_FILEXFER_ATTR_SIZE) {
705 logit("set \"%s\" size %llu", name, a->size); 706 logit("set \"%s\" size %llu",
707 name, (unsigned long long)a->size);
706 ret = truncate(name, a->size); 708 ret = truncate(name, a->size);
707 if (ret == -1) 709 if (ret == -1)
708 status = errno_to_portable(errno); 710 status = errno_to_portable(errno);
@@ -754,7 +756,8 @@ process_fsetstat(void)
754 char *name = handle_to_name(handle); 756 char *name = handle_to_name(handle);
755 757
756 if (a->flags & SSH2_FILEXFER_ATTR_SIZE) { 758 if (a->flags & SSH2_FILEXFER_ATTR_SIZE) {
757 logit("set \"%s\" size %llu", name, a->size); 759 logit("set \"%s\" size %llu",
760 name, (unsigned long long)a->size);
758 ret = ftruncate(fd, a->size); 761 ret = ftruncate(fd, a->size);
759 if (ret == -1) 762 if (ret == -1)
760 status = errno_to_portable(errno); 763 status = errno_to_portable(errno);
@@ -1211,7 +1214,7 @@ main(int argc, char **argv)
1211 int in, out, max, ch, skipargs = 0, log_stderr = 0; 1214 int in, out, max, ch, skipargs = 0, log_stderr = 0;
1212 ssize_t len, olen, set_size; 1215 ssize_t len, olen, set_size;
1213 SyslogFacility log_facility = SYSLOG_FACILITY_AUTH; 1216 SyslogFacility log_facility = SYSLOG_FACILITY_AUTH;
1214 char *cp; 1217 char *cp, buf[4*4096];
1215 1218
1216 extern char *optarg; 1219 extern char *optarg;
1217 extern char *__progname; 1220 extern char *__progname;
@@ -1295,7 +1298,15 @@ main(int argc, char **argv)
1295 memset(rset, 0, set_size); 1298 memset(rset, 0, set_size);
1296 memset(wset, 0, set_size); 1299 memset(wset, 0, set_size);
1297 1300
1298 FD_SET(in, rset); 1301 /*
1302 * Ensure that we can read a full buffer and handle
1303 * the worst-case length packet it can generate,
1304 * otherwise apply backpressure by stopping reads.
1305 */
1306 if (buffer_check_alloc(&iqueue, sizeof(buf)) &&
1307 buffer_check_alloc(&oqueue, SFTP_MAX_MSG_LENGTH))
1308 FD_SET(in, rset);
1309
1299 olen = buffer_len(&oqueue); 1310 olen = buffer_len(&oqueue);
1300 if (olen > 0) 1311 if (olen > 0)
1301 FD_SET(out, wset); 1312 FD_SET(out, wset);
@@ -1309,7 +1320,6 @@ main(int argc, char **argv)
1309 1320
1310 /* copy stdin to iqueue */ 1321 /* copy stdin to iqueue */
1311 if (FD_ISSET(in, rset)) { 1322 if (FD_ISSET(in, rset)) {
1312 char buf[4*4096];
1313 len = read(in, buf, sizeof buf); 1323 len = read(in, buf, sizeof buf);
1314 if (len == 0) { 1324 if (len == 0) {
1315 debug("read eof"); 1325 debug("read eof");
@@ -1331,7 +1341,13 @@ main(int argc, char **argv)
1331 buffer_consume(&oqueue, len); 1341 buffer_consume(&oqueue, len);
1332 } 1342 }
1333 } 1343 }
1334 /* process requests from client */ 1344
1335 process(); 1345 /*
1346 * Process requests from client if we can fit the results
1347 * into the output buffer, otherwise stop processing input
1348 * and let the output queue drain.
1349 */
1350 if (buffer_check_alloc(&oqueue, SFTP_MAX_MSG_LENGTH))
1351 process();
1336 } 1352 }
1337} 1353}