diff options
Diffstat (limited to 'sftp-server.c')
-rw-r--r-- | sftp-server.c | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/sftp-server.c b/sftp-server.c index 9d01c7d79..cce074a56 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.96 2013/01/04 19:26:38 jmc 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 | * |
@@ -1390,7 +1390,8 @@ sftp_server_usage(void) | |||
1390 | extern char *__progname; | 1390 | extern char *__progname; |
1391 | 1391 | ||
1392 | fprintf(stderr, | 1392 | fprintf(stderr, |
1393 | "usage: %s [-ehR] [-f log_facility] [-l log_level] [-u umask]\n", | 1393 | "usage: %s [-ehR] [-d start_directory] [-f log_facility] " |
1394 | "[-l log_level]\n\t[-u umask]\n", | ||
1394 | __progname); | 1395 | __progname); |
1395 | exit(1); | 1396 | exit(1); |
1396 | } | 1397 | } |
@@ -1402,7 +1403,7 @@ sftp_server_main(int argc, char **argv, struct passwd *user_pw) | |||
1402 | int in, out, max, ch, skipargs = 0, log_stderr = 0; | 1403 | int in, out, max, ch, skipargs = 0, log_stderr = 0; |
1403 | ssize_t len, olen, set_size; | 1404 | ssize_t len, olen, set_size; |
1404 | SyslogFacility log_facility = SYSLOG_FACILITY_AUTH; | 1405 | SyslogFacility log_facility = SYSLOG_FACILITY_AUTH; |
1405 | char *cp, buf[4*4096]; | 1406 | char *cp, *homedir = NULL, buf[4*4096]; |
1406 | long mask; | 1407 | long mask; |
1407 | 1408 | ||
1408 | extern char *optarg; | 1409 | extern char *optarg; |
@@ -1411,7 +1412,9 @@ sftp_server_main(int argc, char **argv, struct passwd *user_pw) | |||
1411 | __progname = ssh_get_progname(argv[0]); | 1412 | __progname = ssh_get_progname(argv[0]); |
1412 | log_init(__progname, log_level, log_facility, log_stderr); | 1413 | log_init(__progname, log_level, log_facility, log_stderr); |
1413 | 1414 | ||
1414 | while (!skipargs && (ch = getopt(argc, argv, "f:l:u:cehR")) != -1) { | 1415 | pw = pwcopy(user_pw); |
1416 | |||
1417 | while (!skipargs && (ch = getopt(argc, argv, "d:f:l:u:cehR")) != -1) { | ||
1415 | switch (ch) { | 1418 | switch (ch) { |
1416 | case 'R': | 1419 | case 'R': |
1417 | readonly = 1; | 1420 | readonly = 1; |
@@ -1436,6 +1439,12 @@ sftp_server_main(int argc, char **argv, struct passwd *user_pw) | |||
1436 | if (log_facility == SYSLOG_FACILITY_NOT_SET) | 1439 | if (log_facility == SYSLOG_FACILITY_NOT_SET) |
1437 | error("Invalid log facility \"%s\"", optarg); | 1440 | error("Invalid log facility \"%s\"", optarg); |
1438 | break; | 1441 | break; |
1442 | case 'd': | ||
1443 | cp = tilde_expand_filename(optarg, user_pw->pw_uid); | ||
1444 | homedir = percent_expand(cp, "d", user_pw->pw_dir, | ||
1445 | "u", user_pw->pw_name, (char *)NULL); | ||
1446 | free(cp); | ||
1447 | break; | ||
1439 | case 'u': | 1448 | case 'u': |
1440 | errno = 0; | 1449 | errno = 0; |
1441 | mask = strtol(optarg, &cp, 8); | 1450 | mask = strtol(optarg, &cp, 8); |
@@ -1463,8 +1472,6 @@ sftp_server_main(int argc, char **argv, struct passwd *user_pw) | |||
1463 | } else | 1472 | } else |
1464 | client_addr = xstrdup("UNKNOWN"); | 1473 | client_addr = xstrdup("UNKNOWN"); |
1465 | 1474 | ||
1466 | pw = pwcopy(user_pw); | ||
1467 | |||
1468 | logit("session opened for local user %s from [%s]", | 1475 | logit("session opened for local user %s from [%s]", |
1469 | pw->pw_name, client_addr); | 1476 | pw->pw_name, client_addr); |
1470 | 1477 | ||
@@ -1489,6 +1496,13 @@ sftp_server_main(int argc, char **argv, struct passwd *user_pw) | |||
1489 | rset = (fd_set *)xmalloc(set_size); | 1496 | rset = (fd_set *)xmalloc(set_size); |
1490 | wset = (fd_set *)xmalloc(set_size); | 1497 | wset = (fd_set *)xmalloc(set_size); |
1491 | 1498 | ||
1499 | if (homedir != NULL) { | ||
1500 | if (chdir(homedir) != 0) { | ||
1501 | error("chdir to \"%s\" failed: %s", homedir, | ||
1502 | strerror(errno)); | ||
1503 | } | ||
1504 | } | ||
1505 | |||
1492 | for (;;) { | 1506 | for (;;) { |
1493 | memset(rset, 0, set_size); | 1507 | memset(rset, 0, set_size); |
1494 | memset(wset, 0, set_size); | 1508 | memset(wset, 0, set_size); |