Bug 256554 - /usr/bin/id -c returns current users's login class, not specified user's
Summary: /usr/bin/id -c returns current users's login class, not specified user's
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 13.0-RELEASE
Hardware: Any Any
: --- Affects Many People
Assignee: Alan Somers
URL: https://reviews.freebsd.org/D30734
Keywords:
Depends on:
Blocks:
 
Reported: 2021-06-11 16:32 UTC by Alan Somers
Modified: 2021-07-04 04:15 UTC (History)
0 users

See Also:
asomers: mfc-stable13+
asomers: mfc-stable12+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alan Somers freebsd_committer 2021-06-11 16:32:58 UTC
It's tempting to run "id -c somebody" to get somebody's login class.  Such an invocation seems to work.  But it actually returns the login class of the current user, not "somebody".  The man page and git history suggests that this is the intended behavior.  However, I believe it is a bug to accept and ignore a user argument.  Instead, id should return an error if a user is specified along with "-c".

Steps to reproduce:
# Create a user with a non-default login class
> sudo pw useradd testy -L russian
# Try to lookup his login class.  It's wrong!
> id -c testy
default
# su to testy and lookup his current login class.  It's right.
> sudo su -m testy
% id -c
russian
Comment 1 commit-hook freebsd_committer 2021-06-15 12:52:50 UTC
A commit in branch main references this bug:

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

commit 4a06e9377398b34922f8a67d7cb3ea980b95bde8
Author:     Alan Somers <asomers@FreeBSD.org>
AuthorDate: 2021-06-11 16:38:07 +0000
Commit:     Alan Somers <asomers@FreeBSD.org>
CommitDate: 2021-06-15 12:51:16 +0000

    id: sanitize arguments better

    The -[AMc] flags ignore the user argument.  Better if id rejects
    invocations that include a user argument along with any of those flags.

    PR:             256554
    MFC after:      2 weeks
    Reviewed by:    trasz
    Sponsored by:   Axcient
    Differential Revision: https://reviews.freebsd.org/D30734

 usr.bin/id/id.c | 2 ++
 1 file changed, 2 insertions(+)
Comment 2 commit-hook freebsd_committer 2021-07-03 23:30:42 UTC
A commit in branch stable/13 references this bug:

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

commit bc997ea6b81eace14f999e782502ae060687db2c
Author:     Alan Somers <asomers@FreeBSD.org>
AuthorDate: 2021-06-11 16:38:07 +0000
Commit:     Alan Somers <asomers@FreeBSD.org>
CommitDate: 2021-07-03 23:29:41 +0000

    id: sanitize arguments better

    The -[AMc] flags ignore the user argument.  Better if id rejects
    invocations that include a user argument along with any of those flags.

    PR:             256554
    Reviewed by:    trasz
    Sponsored by:   Axcient
    Differential Revision: https://reviews.freebsd.org/D30734

    (cherry picked from commit 4a06e9377398b34922f8a67d7cb3ea980b95bde8)

 usr.bin/id/id.c | 2 ++
 1 file changed, 2 insertions(+)
Comment 3 commit-hook freebsd_committer 2021-07-04 04:15:27 UTC
A commit in branch stable/12 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=5d7ae6fbb117fde20189db763a9561e97c2af35c

commit 5d7ae6fbb117fde20189db763a9561e97c2af35c
Author:     Alan Somers <asomers@FreeBSD.org>
AuthorDate: 2021-06-11 16:38:07 +0000
Commit:     Alan Somers <asomers@FreeBSD.org>
CommitDate: 2021-07-04 04:14:06 +0000

    id: sanitize arguments better

    The -[AMc] flags ignore the user argument.  Better if id rejects
    invocations that include a user argument along with any of those flags.

    PR:             256554
    Reviewed by:    trasz
    Sponsored by:   Axcient
    Differential Revision: https://reviews.freebsd.org/D30734

    (cherry picked from commit 4a06e9377398b34922f8a67d7cb3ea980b95bde8)

 usr.bin/id/id.c | 2 ++
 1 file changed, 2 insertions(+)