Page MenuHomeFreeBSD

id: revert to historical and documented behavior for `id`
ClosedPublic

Authored by kevans on Aug 1 2025, 8:50 PM.
Tags
None
Referenced Files
F128857325: D51689.diff
Mon, Sep 15, 4:05 AM
Unknown Object (File)
Wed, Sep 10, 1:01 PM
Unknown Object (File)
Tue, Sep 9, 5:10 PM
Unknown Object (File)
Fri, Sep 5, 3:13 AM
Unknown Object (File)
Mon, Sep 1, 7:36 AM
Unknown Object (File)
Mon, Aug 25, 6:24 PM
Unknown Object (File)
Sun, Aug 24, 6:00 PM
Unknown Object (File)
Thu, Aug 21, 5:01 AM
Subscribers

Details

Summary

The manpage claims that we display the credentials for the calling
process if no user/flags are specified, but this has not been true since
r145628 / 68b9b81e792a9108d. Currently, we display:

  • uid from the calling process
  • gid from /etc/passwd
  • egid from the calling process, if different from that gid
  • supplementary groups from the calling process

This doesn't really match the description in the manpage, and it doesn't
match other implementations. Fix it to use the current process
credentials for the gid as well.

Drop the extra arguments to id_print(), since these facts can be derived
from whether we're displaying live data (pw == NULL) or not.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

kevans requested review of this revision.Aug 1 2025, 8:50 PM

Hey, I had noticed that problem a few years ago, and had put it in my TODO list.

I would only request one change (please see inline comment).

usr.bin/id/id.c
290–292

Before this change, we would set pw to non-NULL even in the case of not passing a user as an argument in the command line provided the current real user ID corresponded to some name in the password database, so we would go into the first branch of the if, actually printing a user name. Now, we go through the second branch, and won't print a name in any case.

In addition to that, POSIX requires printing IDs and names.

So, unless most other implementations do not do that (I did not check), I'd add code in this second branch that tries fetching the corresponding PW DB entry and print the user name from it.

Oh, and not doing so would also be inconsistent with what we do with groups (calls to getgrgid() below).

kevans marked an inline comment as done.

Don't drop printing the username in the process, track at the front whether we
were called with db info to render and fetch our entry from the passwd db in
the other case.

One more simplification: no need to call getuid(), we already did earlier

This revision is now accepted and ready to land.Aug 4 2025, 7:56 PM