]> git.ipfire.org Git - thirdparty/openssh-portable.git/commitdiff
upstream: extend sftp-common.c:extend ls_file() to support supplied
authordjm@openbsd.org <djm@openbsd.org>
Mon, 19 Sep 2022 10:41:58 +0000 (10:41 +0000)
committerDamien Miller <djm@mindrot.org>
Mon, 19 Sep 2022 10:49:13 +0000 (20:49 +1000)
user/group names; ok markus@

OpenBSD-Commit-ID: c70c70498b1fdcf158531117e405b6245863bfb0

sftp-common.c
sftp-common.h
sftp-server.c
sftp.c

index 3ad57673d41ef2b2c44e86bf88f1214943a7a98a..50f1bbafb4bc5a5de7de14554953ab30df8769b9 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: sftp-common.c,v 1.32 2020/10/18 11:32:02 djm Exp $ */
+/* $OpenBSD: sftp-common.c,v 1.33 2022/09/19 10:41:58 djm Exp $ */
 /*
  * Copyright (c) 2001 Markus Friedl.  All rights reserved.
  * Copyright (c) 2001 Damien Miller.  All rights reserved.
@@ -212,21 +212,25 @@ fx2txt(int status)
  * drwxr-xr-x    5 markus   markus       1024 Jan 13 18:39 .ssh
  */
 char *
-ls_file(const char *name, const struct stat *st, int remote, int si_units)
+ls_file(const char *name, const struct stat *st, int remote, int si_units,
+    const char *user, const char *group)
 {
        int ulen, glen, sz = 0;
        struct tm *ltime = localtime(&st->st_mtime);
-       const char *user, *group;
        char buf[1024], lc[8], mode[11+1], tbuf[12+1], ubuf[11+1], gbuf[11+1];
        char sbuf[FMT_SCALED_STRSIZE];
        time_t now;
 
        strmode(st->st_mode, mode);
        if (remote) {
-               snprintf(ubuf, sizeof ubuf, "%u", (u_int)st->st_uid);
-               user = ubuf;
-               snprintf(gbuf, sizeof gbuf, "%u", (u_int)st->st_gid);
-               group = gbuf;
+               if (user == NULL) {
+                       snprintf(ubuf, sizeof ubuf, "%u", (u_int)st->st_uid);
+                       user = ubuf;
+               }
+               if (group == NULL) {
+                       snprintf(gbuf, sizeof gbuf, "%u", (u_int)st->st_gid);
+                       group = gbuf;
+               }
                strlcpy(lc, "?", sizeof(lc));
        } else {
                user = user_from_uid(st->st_uid, 0);
index 2e778a9ca0ba29dff2c0b9f3eaf8413e298f5ec6..421a78f78822d4c10b73486dbae3a7277352f106 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: sftp-common.h,v 1.12 2015/01/14 13:54:13 djm Exp $ */
+/* $OpenBSD: sftp-common.h,v 1.13 2022/09/19 10:41:58 djm Exp $ */
 
 /*
  * Copyright (c) 2001 Markus Friedl.  All rights reserved.
@@ -47,6 +47,7 @@ void   stat_to_attrib(const struct stat *, Attrib *);
 void    attrib_to_stat(const Attrib *, struct stat *);
 int     decode_attrib(struct sshbuf *, Attrib *);
 int     encode_attrib(struct sshbuf *, const Attrib *);
-char   *ls_file(const char *, const struct stat *, int, int);
+char   *ls_file(const char *, const struct stat *, int, int,
+    const char *, const char *);
 
 const char *fx2txt(int);
index 65547029dff703b8c9d9b74b1b3951a78c9dfeb5..25f9534897596736e017ac5dd2d2e05f6b137570 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: sftp-server.c,v 1.143 2022/09/19 10:40:52 djm Exp $ */
+/* $OpenBSD: sftp-server.c,v 1.144 2022/09/19 10:41:58 djm Exp $ */
 /*
  * Copyright (c) 2000-2004 Markus Friedl.  All rights reserved.
  *
@@ -1161,7 +1161,8 @@ process_readdir(u_int32_t id)
                                continue;
                        stat_to_attrib(&st, &(stats[count].attrib));
                        stats[count].name = xstrdup(dp->d_name);
-                       stats[count].long_name = ls_file(dp->d_name, &st, 0, 0);
+                       stats[count].long_name = ls_file(dp->d_name, &st,
+                           0, 0, NULL, NULL);
                        count++;
                        /* send up to 100 entries in one message */
                        /* XXX check packet size instead */
diff --git a/sftp.c b/sftp.c
index 24568aaded795305002bba35b353c1828047f3f7..2d1186ac298070adc2349cd2a94b409b3c6fcfa7 100644 (file)
--- a/sftp.c
+++ b/sftp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sftp.c,v 1.220 2022/09/16 03:33:14 djm Exp $ */
+/* $OpenBSD: sftp.c,v 1.221 2022/09/19 10:41:58 djm Exp $ */
 /*
  * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
  *
@@ -889,7 +889,7 @@ do_ls_dir(struct sftp_conn *conn, const char *path,
                                memset(&sb, 0, sizeof(sb));
                                attrib_to_stat(&d[n]->a, &sb);
                                lname = ls_file(fname, &sb, 1,
-                                   (lflag & LS_SI_UNITS));
+                                   (lflag & LS_SI_UNITS), NULL, NULL);
                                mprintf("%s\n", lname);
                                free(lname);
                        } else
@@ -1026,7 +1026,7 @@ do_globbed_ls(struct sftp_conn *conn, const char *path,
                                continue;
                        }
                        lname = ls_file(fname, g.gl_statv[i], 1,
-                           (lflag & LS_SI_UNITS));
+                           (lflag & LS_SI_UNITS), NULL, NULL);
                        mprintf("%s\n", lname);
                        free(lname);
                } else {