acl_id_to_name.c: Fix printing of uids and gids

uid_t and gid_t are uint32_t (unsigned 32bit integers).
They are printed as signed integers when calling getfacl
(and other tools using the acl_to_text() libc function).
This causes uid/gids larger than 2G (214783648) to print
as negative numbers
- which causes problem with setfacl since the acl_from_text()
  libc function fails on negative numbers.

Reviewed by:	rmacklem
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D57179
This commit is contained in:
Peter Eriksson
2026-05-25 12:44:41 -07:00
committed by Rick Macklem
parent 4d80d4913e
commit 6e7c10c79d
2 changed files with 4 additions and 4 deletions
+2 -2
View File
@@ -67,7 +67,7 @@ _posix1e_acl_id_to_name(acl_tag_t tag, uid_t id, ssize_t buf_len, char *buf,
else
p = getpwuid(id);
if (!p)
i = snprintf(buf, buf_len, "%d", id);
i = snprintf(buf, buf_len, "%ju", (uintmax_t)id);
else
i = snprintf(buf, buf_len, "%s", p->pw_name);
@@ -83,7 +83,7 @@ _posix1e_acl_id_to_name(acl_tag_t tag, uid_t id, ssize_t buf_len, char *buf,
else
g = getgrgid(id);
if (g == NULL)
i = snprintf(buf, buf_len, "%d", id);
i = snprintf(buf, buf_len, "%ju", (uintmax_t)id);
else
i = snprintf(buf, buf_len, "%s", g->gr_name);
+2 -2
View File
@@ -69,7 +69,7 @@ format_who(char *str, size_t size, const acl_entry_t entry, int numeric)
else
pwd = NULL;
if (pwd == NULL)
snprintf(str, size, "user:%d", (unsigned int)*id);
snprintf(str, size, "user:%ju", (uintmax_t)*id);
else
snprintf(str, size, "user:%s", pwd->pw_name);
acl_free(id);
@@ -89,7 +89,7 @@ format_who(char *str, size_t size, const acl_entry_t entry, int numeric)
else
grp = NULL;
if (grp == NULL)
snprintf(str, size, "group:%d", (unsigned int)*id);
snprintf(str, size, "group:%ju", (uintmax_t)*id);
else
snprintf(str, size, "group:%s", grp->gr_name);
acl_free(id);