Skip to content

Commit

Permalink
install: Fix METALOG ouptut for numeric -o and -g args
Browse files Browse the repository at this point in the history
install's -o and -g flags both accept a name or a numeric argument.
In -U -M (non-root METALOG) mode it always emitted uname= and gname= in
the METALOG, but these are not appropriate for numeric IDs.

If the -o and/or -u arguments parse as an ID, emit uid= and/or gid=
respectively.

Note that if an argument is valid as both a name and numeric ID we will
prefer the name in normal (non -U -M) mode and the ID in -U -M mode.  We
don't want to require a passwd db in non-root mode, and entirely-numeric
user or group names are a terrible idea so just accept this discrepancy.

PR:		284119
Reviewed by:	jlduran
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D48504

(cherry picked from commit 4b04f5d)
(cherry picked from commit 90702fb)
  • Loading branch information
emaste committed Feb 19, 2025
1 parent ab964a1 commit 9b270b4
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions usr.bin/xinstall/xinstall.c
Original file line number Diff line number Diff line change
Expand Up @@ -1410,10 +1410,22 @@ metadata_log(const char *path, const char *type, struct timespec *ts,
p = buf;
/* Print details. */
fprintf(metafp, ".%s%s type=%s", *p ? "/" : "", p, type);
if (owner)
fprintf(metafp, " uname=%s", owner);
if (group)
fprintf(metafp, " gname=%s", group);
if (owner) {
id_t id;

if (parseid(owner, &id))
fprintf(metafp, " uid=%jd", (intmax_t)id);
else
fprintf(metafp, " uname=%s", owner);
}
if (group) {
id_t id;

if (parseid(group, &id))
fprintf(metafp, " gid=%jd", (intmax_t)id);
else
fprintf(metafp, " gname=%s", group);
}
fprintf(metafp, " mode=%#o", mode);
if (slink) {
strsnvis(buf, buflen, slink, VIS_CSTYLE, extra);
Expand Down

0 comments on commit 9b270b4

Please sign in to comment.