Hi maintainer, Currently, when using ls, only the first 8 characters of the username and group name are printed, with the rest being truncated. However, there are often long usernames and group names, and limiting them to 8 characters can cause confusion and potential security vulnerabilities. Therefore, it would be beneficial to be able to print the full username/group name when using ls.
I'm sending the patch I've mentioned for this. Can I hear your opinion? Br-Matthew Chae
From d35996d07fd4a45054e71ec0696c733077f8008c Mon Sep 17 00:00:00 2001 From: Matthew Chae <matth...@axis.com> Date: Mon, 19 Feb 2024 14:53:27 +0100 Subject: [PATCH] Print full username and groupname for ls command As we currently have quite a lot of long usernames and groupnames. It would be nice to be able to print full username/groupname when using ls. This affects options -l and -g of ls command. Reviewed-by: Christopher Wong <christopher.w...@axis.com> Signed-off-by: Matthew(Sukyoung) Chae <matth...@axis.com> --- coreutils/ls.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/coreutils/ls.c b/coreutils/ls.c index b69b80460..46bfbb424 100644 --- a/coreutils/ls.c +++ b/coreutils/ls.c @@ -475,7 +475,9 @@ static unsigned print_name(const char *name) * Note that only columnar output uses return value, * -l and -1 modes don't care. */ -static NOINLINE unsigned display_single(const struct dnode *dn) +static NOINLINE unsigned display_single(const struct dnode *dn, + size_t uname_max_length, + size_t gname_max_length) { unsigned column = 0; char *lpath; @@ -526,11 +528,14 @@ static NOINLINE unsigned display_single(const struct dnode *dn) #if ENABLE_FEATURE_LS_USERNAME else { if (opt & OPT_g) { - column += printf("%-8.8s ", + column += printf("%-*.*s ", + gname_max_length, gname_max_length, get_cached_groupname(dn->dn_gid)); } else { - column += printf("%-8.8s %-8.8s ", + column += printf("%-*.*s %-*.*s ", + uname_max_length, uname_max_length, get_cached_username(dn->dn_uid), + gname_max_length, gname_max_length, get_cached_groupname(dn->dn_gid)); } } @@ -647,6 +652,8 @@ static void display_files(struct dnode **dn, unsigned nfiles) unsigned column; unsigned nexttab; unsigned column_width = 0; /* used only by coulmnal output */ + size_t uname_max_length = 8; + size_t gname_max_length = 8; if (option_mask32 & (OPT_l|OPT_1)) { ncols = 1; @@ -674,6 +681,24 @@ static void display_files(struct dnode **dn, unsigned nfiles) ncols = 1; } + if (option_mask32 & OPT_l) { + for (i = 0; dn[i]; i++) { + const char *p1 = get_cached_username(dn[i]->dn_uid); + const char *p2 = p1; + while (*p1 != '\0') { + p1++; + } + uname_max_length = MAX(uname_max_length, p1 - p2); + + p1 = get_cached_username(dn[i]->dn_gid); + p2 = p1; + while (*p1 != '\0') { + p1++; + } + gname_max_length = MAX(gname_max_length, p1 - p2); + } + } + column = 0; nexttab = 0; for (row = 0; row < nrows; row++) { @@ -690,7 +715,7 @@ static void display_files(struct dnode **dn, unsigned nfiles) column += nexttab; } nexttab = column + column_width; - column += display_single(dn[i]); + column += display_single(dn[i], uname_max_length, gname_max_length); } } putchar('\n'); -- 2.30.2
_______________________________________________ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox