summaryrefslogtreecommitdiffstats
path: root/sftp-server.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2022-08-12 07:20:28 +0200
committerDamien Miller <djm@mindrot.org>2022-08-12 07:22:37 +0200
commit730a80609472ee0451c99482d75c9c41f3ebc42d (patch)
tree7e00dba967a9479745f9ec26a83b8a53f1403f48 /sftp-server.c
parentReplace deprecated ubuntu-18.04 runners with 22.04 (diff)
downloadopenssh-730a80609472ee0451c99482d75c9c41f3ebc42d.tar.xz
openssh-730a80609472ee0451c99482d75c9c41f3ebc42d.zip
upstream: sftp-server: support home-directory request
Add support to the sftp-server for the home-directory extension defined in draft-ietf-secsh-filexfer-extensions-00. This overlaps a bit with the existing expand-path@openssh.com, but uses a more official protocol name, and so is a bit more likely to be implemented by non-OpenSSH clients. From Mike Frysinger, ok dtucker@ OpenBSD-Commit-ID: bfc580d05cc0c817831ae7ecbac4a481c23566ab
Diffstat (limited to 'sftp-server.c')
-rw-r--r--sftp-server.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/sftp-server.c b/sftp-server.c
index 3dd19d4c8..85f4345e9 100644
--- a/sftp-server.c
+++ b/sftp-server.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sftp-server.c,v 1.140 2022/03/31 03:05:49 djm Exp $ */
+/* $OpenBSD: sftp-server.c,v 1.141 2022/08/12 05:20:28 djm Exp $ */
/*
* Copyright (c) 2000-2004 Markus Friedl. All rights reserved.
*
@@ -121,6 +121,7 @@ static void process_extended_lsetstat(u_int32_t id);
static void process_extended_limits(u_int32_t id);
static void process_extended_expand(u_int32_t id);
static void process_extended_copy_data(u_int32_t id);
+static void process_extended_home_directory(u_int32_t id);
static void process_extended(u_int32_t id);
struct sftp_handler {
@@ -167,6 +168,8 @@ static const struct sftp_handler extended_handlers[] = {
{ "expand-path", "expand-path@openssh.com", 0,
process_extended_expand, 0 },
{ "copy-data", "copy-data", 0, process_extended_copy_data, 1 },
+ { "home-directory", "home-directory", 0,
+ process_extended_home_directory, 0 },
{ NULL, NULL, 0, NULL, 0 }
};
@@ -724,6 +727,7 @@ process_init(void)
compose_extension(msg, "limits@openssh.com", "1");
compose_extension(msg, "expand-path@openssh.com", "1");
compose_extension(msg, "copy-data", "1");
+ compose_extension(msg, "home-directory", "1");
send_msg(msg);
sshbuf_free(msg);
@@ -1685,6 +1689,31 @@ process_extended_copy_data(u_int32_t id)
}
static void
+process_extended_home_directory(u_int32_t id)
+{
+ char *username;
+ struct passwd *user_pw;
+ int r;
+ Stat s;
+
+ if ((r = sshbuf_get_cstring(iqueue, &username, NULL)) != 0)
+ fatal_fr(r, "parse");
+
+ debug3("request %u: home-directory \"%s\"", id, username);
+ if ((user_pw = getpwnam(username)) == NULL) {
+ send_status(id, errno_to_portable(errno));
+ goto out;
+ }
+
+ verbose("home-directory \"%s\"", pw->pw_dir);
+ attrib_clear(&s.attrib);
+ s.name = s.long_name = pw->pw_dir;
+ send_names(id, 1, &s);
+ out:
+ free(username);
+}
+
+static void
process_extended(u_int32_t id)
{
char *request;