diff --git a/sftp-common.c b/sftp-common.c index 3ad57673d..50f1bbafb 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 2e778a9ca..421a78f78 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 65547029d..25f953489 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 24568aade..2d1186ac2 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 * @@ -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 {