Mailing List Archive

[PATCH] sftp-server: support home-directory request
Add support to the sftp-server for the home-directory extension defined
in [1]. 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 clients.

I wrote this before expand-path@openssh.com existed, so posting it if
only to not be totally wasted effort. I'd understand if people would
prefer not to implement this at all, but if there is interest, I can
see about unifying the two functions a bit.

[1] https://tools.ietf.org/html/draft-ietf-secsh-filexfer-extensions-00#section-7
---
PROTOCOL | 20 ++++++++++++++++++++
sftp-server.c | 29 +++++++++++++++++++++++++++++
2 files changed, 49 insertions(+)

diff --git a/PROTOCOL b/PROTOCOL
index 2d50b5cb0528..7a035994489b 100644
--- a/PROTOCOL
+++ b/PROTOCOL
@@ -613,6 +613,26 @@ This request is identical to the "copy-data" request documented in:

https://tools.ietf.org/html/draft-ietf-secsh-filexfer-extensions-00#section-7

+4.11. sftp: Extension request "home-directory"
+
+This request asks the server to expand the specified user's home directory.
+An empty username implies the current user. This can be used by the client
+to expand ~/ type paths locally.
+
+ byte SSH_FXP_EXTENDED
+ uint32 id
+ string "home-directory"
+ string username
+
+This extension is advertised in the SSH_FXP_VERSION hello with version
+"1".
+
+This provides similar information as the "expand-path@openssh.com" extension.
+
+This request is identical to the "home-directory" request documented in:
+
+https://datatracker.ietf.org/doc/html/draft-ietf-secsh-filexfer-extensions-00#section-5
+
5. Miscellaneous changes

5.1 Public key format
diff --git a/sftp-server.c b/sftp-server.c
index 3dd19d4c81db..3aea751a9d67 100644
--- a/sftp-server.c
+++ b/sftp-server.c
@@ -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);
@@ -1684,6 +1688,31 @@ process_extended_copy_data(u_int32_t id)
send_status(id, status);
}

+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)
{
--
2.34.1

_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
Re: [PATCH] sftp-server: support home-directory request [ In reply to ]
On 31 Mar 2022 02:20, Mike Frysinger wrote:
> Add support to the sftp-server for the home-directory extension defined
> in [1]. 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 clients.
>
> I wrote this before expand-path@openssh.com existed, so posting it if
> only to not be totally wasted effort. I'd understand if people would
> prefer not to implement this at all, but if there is interest, I can
> see about unifying the two functions a bit.
>
> [1] https://tools.ietf.org/html/draft-ietf-secsh-filexfer-extensions-00#section-7

ping ... should still apply cleanly to latest source tree
-mike
Re: [PATCH] sftp-server: support home-directory request [ In reply to ]
looks ok to me

On Thu, 4 Aug 2022 at 13:39, Mike Frysinger <vapier@gentoo.org> wrote:
>
> On 31 Mar 2022 02:20, Mike Frysinger wrote:
> > Add support to the sftp-server for the home-directory extension defined
> > in [1]. 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 clients.
> >
> > I wrote this before expand-path@openssh.com existed, so posting it if
> > only to not be totally wasted effort. I'd understand if people would
> > prefer not to implement this at all, but if there is interest, I can
> > see about unifying the two functions a bit.
> >
> > [1] https://tools.ietf.org/html/draft-ietf-secsh-filexfer-extensions-00#section-7
>
> ping ... should still apply cleanly to latest source tree
> -mike
> _______________________________________________
> openssh-unix-dev mailing list
> openssh-unix-dev@mindrot.org
> https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev



--
Darren Tucker (dtucker at dtucker.net)
GPG key 11EAA6FA / A86E 3E07 5B19 5880 E860 37F4 9357 ECEF 11EA A6FA (new)
Good judgement comes with experience. Unfortunately, the experience
usually comes from bad judgement.
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
Re: [PATCH] sftp-server: support home-directory request [ In reply to ]
committed as 730a80609

On Fri, 12 Aug 2022, Darren Tucker wrote:

> looks ok to me
>
> On Thu, 4 Aug 2022 at 13:39, Mike Frysinger <vapier@gentoo.org> wrote:
> >
> > On 31 Mar 2022 02:20, Mike Frysinger wrote:
> > > Add support to the sftp-server for the home-directory extension defined
> > > in [1]. 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 clients.
> > >
> > > I wrote this before expand-path@openssh.com existed, so posting it if
> > > only to not be totally wasted effort. I'd understand if people would
> > > prefer not to implement this at all, but if there is interest, I can
> > > see about unifying the two functions a bit.
> > >
> > > [1] https://tools.ietf.org/html/draft-ietf-secsh-filexfer-extensions-00#section-7
> >
> > ping ... should still apply cleanly to latest source tree
> > -mike
> > _______________________________________________
> > openssh-unix-dev mailing list
> > openssh-unix-dev@mindrot.org
> > https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
>
>
>
> --
> Darren Tucker (dtucker at dtucker.net)
> GPG key 11EAA6FA / A86E 3E07 5B19 5880 E860 37F4 9357 ECEF 11EA A6FA (new)
> Good judgement comes with experience. Unfortunately, the experience
> usually comes from bad judgement.
> _______________________________________________
> openssh-unix-dev mailing list
> openssh-unix-dev@mindrot.org
> https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
>
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev