summaryrefslogtreecommitdiff
path: root/sftp-server.c
diff options
context:
space:
mode:
Diffstat (limited to 'sftp-server.c')
-rw-r--r--sftp-server.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/sftp-server.c b/sftp-server.c
index 9d01c7d79..c8858147a 100644
--- a/sftp-server.c
+++ b/sftp-server.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sftp-server.c,v 1.94 2011/06/17 21:46:16 djm Exp $ */ 1/* $OpenBSD: sftp-server.c,v 1.95 2013/01/03 12:54:49 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 *
@@ -1402,7 +1402,7 @@ sftp_server_main(int argc, char **argv, struct passwd *user_pw)
1402 int in, out, max, ch, skipargs = 0, log_stderr = 0; 1402 int in, out, max, ch, skipargs = 0, log_stderr = 0;
1403 ssize_t len, olen, set_size; 1403 ssize_t len, olen, set_size;
1404 SyslogFacility log_facility = SYSLOG_FACILITY_AUTH; 1404 SyslogFacility log_facility = SYSLOG_FACILITY_AUTH;
1405 char *cp, buf[4*4096]; 1405 char *cp, *homedir = NULL, buf[4*4096];
1406 long mask; 1406 long mask;
1407 1407
1408 extern char *optarg; 1408 extern char *optarg;
@@ -1411,7 +1411,9 @@ sftp_server_main(int argc, char **argv, struct passwd *user_pw)
1411 __progname = ssh_get_progname(argv[0]); 1411 __progname = ssh_get_progname(argv[0]);
1412 log_init(__progname, log_level, log_facility, log_stderr); 1412 log_init(__progname, log_level, log_facility, log_stderr);
1413 1413
1414 while (!skipargs && (ch = getopt(argc, argv, "f:l:u:cehR")) != -1) { 1414 pw = pwcopy(user_pw);
1415
1416 while (!skipargs && (ch = getopt(argc, argv, "d:f:l:u:cehR")) != -1) {
1415 switch (ch) { 1417 switch (ch) {
1416 case 'R': 1418 case 'R':
1417 readonly = 1; 1419 readonly = 1;
@@ -1436,6 +1438,12 @@ sftp_server_main(int argc, char **argv, struct passwd *user_pw)
1436 if (log_facility == SYSLOG_FACILITY_NOT_SET) 1438 if (log_facility == SYSLOG_FACILITY_NOT_SET)
1437 error("Invalid log facility \"%s\"", optarg); 1439 error("Invalid log facility \"%s\"", optarg);
1438 break; 1440 break;
1441 case 'd':
1442 cp = tilde_expand_filename(optarg, user_pw->pw_uid);
1443 homedir = percent_expand(cp, "d", user_pw->pw_dir,
1444 "u", user_pw->pw_name, (char *)NULL);
1445 free(cp);
1446 break;
1439 case 'u': 1447 case 'u':
1440 errno = 0; 1448 errno = 0;
1441 mask = strtol(optarg, &cp, 8); 1449 mask = strtol(optarg, &cp, 8);
@@ -1463,8 +1471,6 @@ sftp_server_main(int argc, char **argv, struct passwd *user_pw)
1463 } else 1471 } else
1464 client_addr = xstrdup("UNKNOWN"); 1472 client_addr = xstrdup("UNKNOWN");
1465 1473
1466 pw = pwcopy(user_pw);
1467
1468 logit("session opened for local user %s from [%s]", 1474 logit("session opened for local user %s from [%s]",
1469 pw->pw_name, client_addr); 1475 pw->pw_name, client_addr);
1470 1476
@@ -1489,6 +1495,13 @@ sftp_server_main(int argc, char **argv, struct passwd *user_pw)
1489 rset = (fd_set *)xmalloc(set_size); 1495 rset = (fd_set *)xmalloc(set_size);
1490 wset = (fd_set *)xmalloc(set_size); 1496 wset = (fd_set *)xmalloc(set_size);
1491 1497
1498 if (homedir != NULL) {
1499 if (chdir(homedir) != 0) {
1500 error("chdir to \"%s\" failed: %s", homedir,
1501 strerror(errno));
1502 }
1503 }
1504
1492 for (;;) { 1505 for (;;) {
1493 memset(rset, 0, set_size); 1506 memset(rset, 0, set_size);
1494 memset(wset, 0, set_size); 1507 memset(wset, 0, set_size);