diff options
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | sftp-server.8 | 16 | ||||
-rw-r--r-- | sftp-server.c | 23 |
3 files changed, 36 insertions, 7 deletions
@@ -19,6 +19,10 @@ | |||
19 | - djm@cvs.openbsd.org 2013/01/03 12:49:01 | 19 | - djm@cvs.openbsd.org 2013/01/03 12:49:01 |
20 | [PROTOCOL] | 20 | [PROTOCOL] |
21 | fix description of MAC calculation for EtM modes; ok markus@ | 21 | fix description of MAC calculation for EtM modes; ok markus@ |
22 | - djm@cvs.openbsd.org 2013/01/03 12:54:49 | ||
23 | [sftp-server.8 sftp-server.c] | ||
24 | allow specification of an alternate start directory for sftp-server(8) | ||
25 | "I like this" markus@ | ||
22 | 26 | ||
23 | 20121217 | 27 | 20121217 |
24 | - (dtucker) [Makefile.in] Add some scaffolding so that the new regress | 28 | - (dtucker) [Makefile.in] Add some scaffolding so that the new regress |
diff --git a/sftp-server.8 b/sftp-server.8 index bb19c15e1..4d15f1249 100644 --- a/sftp-server.8 +++ b/sftp-server.8 | |||
@@ -1,4 +1,4 @@ | |||
1 | .\" $OpenBSD: sftp-server.8,v 1.19 2010/01/09 03:36:00 jmc Exp $ | 1 | .\" $OpenBSD: sftp-server.8,v 1.20 2013/01/03 12:54:49 djm Exp $ |
2 | .\" | 2 | .\" |
3 | .\" Copyright (c) 2000 Markus Friedl. All rights reserved. | 3 | .\" Copyright (c) 2000 Markus Friedl. All rights reserved. |
4 | .\" | 4 | .\" |
@@ -22,7 +22,7 @@ | |||
22 | .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 22 | .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
23 | .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 | .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 | .\" | 24 | .\" |
25 | .Dd $Mdocdate: January 9 2010 $ | 25 | .Dd $Mdocdate: January 3 2013 $ |
26 | .Dt SFTP-SERVER 8 | 26 | .Dt SFTP-SERVER 8 |
27 | .Os | 27 | .Os |
28 | .Sh NAME | 28 | .Sh NAME |
@@ -31,6 +31,7 @@ | |||
31 | .Sh SYNOPSIS | 31 | .Sh SYNOPSIS |
32 | .Nm sftp-server | 32 | .Nm sftp-server |
33 | .Op Fl ehR | 33 | .Op Fl ehR |
34 | .Op Fl d Ar start_directory | ||
34 | .Op Fl f Ar log_facility | 35 | .Op Fl f Ar log_facility |
35 | .Op Fl l Ar log_level | 36 | .Op Fl l Ar log_level |
36 | .Op Fl u Ar umask | 37 | .Op Fl u Ar umask |
@@ -56,6 +57,17 @@ for more information. | |||
56 | .Pp | 57 | .Pp |
57 | Valid options are: | 58 | Valid options are: |
58 | .Bl -tag -width Ds | 59 | .Bl -tag -width Ds |
60 | .It Fl d | ||
61 | specifies an alternate starting directory for users. | ||
62 | The pathname may contain the following tokens that are expanded at runtime: | ||
63 | %% is replaced by a literal '%', | ||
64 | %h is replaced by the home directory of the user being authenticated, | ||
65 | and %u is replaced by the username of that user. | ||
66 | The default is to use the user's home directory. | ||
67 | This option is useful in conjunction with the | ||
68 | .Xr sshd_config 5 | ||
69 | .Cm ChrootDirectory | ||
70 | option. | ||
59 | .It Fl e | 71 | .It Fl e |
60 | Causes | 72 | Causes |
61 | .Nm | 73 | .Nm |
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); |