Bug 284119 - install(1): numeric -o / -g args produce uname and gname in METALOG
Summary: install(1): numeric -o / -g args produce uname and gname in METALOG
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: Ed Maste
URL: https://reviews.freebsd.org/D48504
Keywords:
Depends on:
Blocks:
 
Reported: 2025-01-17 19:15 UTC by Ed Maste
Modified: 2025-02-11 22:11 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ed Maste freebsd_committer freebsd_triage 2025-01-17 19:15:04 UTC
install -U -M can pass the owner and group through to the METALOG:

$ install -U -M /dev/stdout -o root -g wheel /usr/bin/true /tmp
./tmp/true type=file uname=root gname=wheel mode=0755 size=5008

install also accepts numeric uid and gid.  These should produce uid= and gid= in the METALOG, but we still get uname and gname:

$ install -U -M /dev/stdout -o 0 -g 0 /usr/bin/true /tmp
./tmp/true type=file uname=0 gname=0 mode=0755 size=5008

In normal (non -U) mode we attempt to look up the name, and parse it as an id if that fails:

        if (owner != NULL && !dounpriv) {
                if (uid_from_user(owner, &uid) == -1) {
                        id_t id;
                        if (!parseid(owner, &id))
                                errx(1, "unknown user %s", owner);
                        uid = id;
                }
        } else
                uid = (uid_t)-1;

Something similar is needed for -U -M mode
Comment 1 commit-hook freebsd_committer freebsd_triage 2025-01-21 12:48:36 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=4b04f5d7e8a2bb0488ad5804ecaf45cef5b1d46f

commit 4b04f5d7e8a2bb0488ad5804ecaf45cef5b1d46f
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2025-01-17 19:14:22 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2025-01-21 12:47:48 +0000

    install: Fix METALOG ouptut for numeric -o and -g args

    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

 usr.bin/xinstall/xinstall.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
Comment 2 Ed Maste freebsd_committer freebsd_triage 2025-01-21 13:38:47 UTC
NetBSD committed a different version of this patch.  I imagine we will have more changes here (for PR 283355, and the ability to select one or both of uid/gid and uname/gname), so left it like this for now.
Comment 3 commit-hook freebsd_committer freebsd_triage 2025-02-11 21:28:56 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=90702fb5de14c34e2404bd1f58706a067ac459bc

commit 90702fb5de14c34e2404bd1f58706a067ac459bc
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2025-01-17 19:14:22 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2025-02-11 21:27:17 +0000

    install: Fix METALOG ouptut for numeric -o and -g args

    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 4b04f5d7e8a2bb0488ad5804ecaf45cef5b1d46f)

 usr.bin/xinstall/xinstall.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)