summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2022-09-19 10:41:58 +0000
committerDamien Miller <djm@mindrot.org>2022-09-19 20:49:13 +1000
commit488f6e1c582212c2374a4bf8cd1b703d2e70fb8b (patch)
treed5f1d8e0dd2a49e53b78726c22800a24f21cd283
parent74b77f7497dba3a58315c8f308883de448078057 (diff)
upstream: extend sftp-common.c:extend ls_file() to support supplied
user/group names; ok markus@ OpenBSD-Commit-ID: c70c70498b1fdcf158531117e405b6245863bfb0
-rw-r--r--sftp-common.c18
-rw-r--r--sftp-common.h5
-rw-r--r--sftp-server.c5
-rw-r--r--sftp.c6
4 files changed, 20 insertions, 14 deletions
diff --git a/sftp-common.c b/sftp-common.c
index 3ad57673..50f1bbaf 100644
--- a/sftp-common.c
+++ b/sftp-common.c
@@ -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);
diff --git a/sftp-common.h b/sftp-common.h
index 2e778a9c..421a78f7 100644
--- a/sftp-common.h
+++ b/sftp-common.h
@@ -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);
diff --git a/sftp-server.c b/sftp-server.c
index 65547029..25f95348 100644
--- a/sftp-server.c
+++ b/sftp-server.c
@@ -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 24568aad..2d1186ac 100644
--- 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 {