From nobody Thu Oct 30 10:38:48 2025 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4cy0vr6mb4z6FStK; Thu, 30 Oct 2025 10:38:48 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4cy0vr5KXcz41Jy; Thu, 30 Oct 2025 10:38:48 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1761820728; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Isi7hHauQDJTQ5L2qPiPaN2KAFEJM4Uh8fQ8A4R+GKI=; b=Huh5nqRMYn3uPty9FYQnQkMwersPeMncxtyrbR3kaCEV8bRxg8iqg+21OSFuOqFcod5seo fFOuvUaZJ4OPiMvRe4kZzBZPLlkj3xFeh9udGgleinRzb8XXsfZuWKT09CMKSF8pXxiJ+4 G2p7Hg/KcnjOiKKC21c4invAUiiZgLqHp71brQwNix9JX55StBDhj/Z+/LXwlxWujT8TOD DqhPVr2CYxnIe/q7LYbN2FcMjIYiwhD8MtHrrG3IIkQm3Pa7INuErQHdbXo1f6mDT5rC8F 4ZcyvYe9yQ8n6DGdybfLTPuikEY0DuE4q8Fa+lD0tWab6SZMZJQ37xSiKso5mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1761820728; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Isi7hHauQDJTQ5L2qPiPaN2KAFEJM4Uh8fQ8A4R+GKI=; b=jwyQ0/DgY3jq5mjLGgSqGFaIPayROLaQqcETLWHQOi0TTrJEtktOZsZ0eyfkLsK0qVz45A 7oRRcMNJaj/YzH37x/pwB+Pj64TtA9sEqqgTRuCuirLnj1pmDun7A+8tZ+vfieUb5SCLoO yMS2Khg2IVNNBlRha/zazd1h5A0NOp90NQ1wbMvPUWiJ0h5JNGIYVNw3CWvZ/JWowpi+Wq Dj7rVinvd8FQGHeEikb/viWKb0Yi2hRUmUZvdcuaLmvNHkiKCMYU93ZoSUlDctKeZonwhb DHhRPGiX+aX9qTXso+eBIIo3hrrDINpSEjwrIG/RcZd7rWX1Ws7eZ2dUr+EiNQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1761820728; a=rsa-sha256; cv=none; b=mqulvE4vPZl0W4JGha4WM7iQARyOzmqpuOEpwrG780yfwzbzmflu+TUEGgT/64oBWFLHKc 9mWgL411aBc5c7VoCQNa18Lln7aN4L8Oe2X0HFoA/oGfnwrk5NhJtvgXG0/KhqpR7WMDa0 hMM7skLz23v4dnaglTbNa+bPeOEmOZHn5ggUC3DgP48tqD+C03aQtaz8Y8I9in2vss9/V1 IJ1GLK31qAWtqjGVpYjoHSy1NXu+HDaKrxNlA6vlu6hBdXkfQArZm/ddLcp9fyimVPpG4s PNZFaMx6469hLRBcUsI8hp6ghoxU4Z9N0K1LMbbML6BNuWIMfpWEkIZ0wt+wtw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4cy0vr4Nh1z2wB; Thu, 30 Oct 2025 10:38:48 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 59UAcmJ0082626; Thu, 30 Oct 2025 10:38:48 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 59UAcmkH082623; Thu, 30 Oct 2025 10:38:48 GMT (envelope-from git) Date: Thu, 30 Oct 2025 10:38:48 GMT Message-Id: <202510301038.59UAcmkH082623@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: 299eb4333692 - stable/14 - id: revert to historical and documented behavior for `id` List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: des X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 299eb433369202502ba7ceccb3fd2b3f6fdb1afe Auto-Submitted: auto-generated The branch stable/14 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=299eb433369202502ba7ceccb3fd2b3f6fdb1afe commit 299eb433369202502ba7ceccb3fd2b3f6fdb1afe Author: Kyle Evans AuthorDate: 2025-08-04 23:09:58 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2025-10-30 10:38:19 +0000 id: revert to historical and documented behavior for `id` 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. Reviewed by: olce Differential Revision: https://reviews.freebsd.org/D51689 (cherry picked from commit 90b315233a3362b7427e2d2649eaa8acf0da197a) --- usr.bin/id/id.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/usr.bin/id/id.c b/usr.bin/id/id.c index 772558191306..2cc4a00e4d48 100644 --- a/usr.bin/id/id.c +++ b/usr.bin/id/id.c @@ -52,13 +52,14 @@ static char sccsid[] = "@(#)id.c 8.2 (Berkeley) 2/16/94"; #include #include #include +#include #include #include #include #include #include -static void id_print(struct passwd *, int, int, int); +static void id_print(struct passwd *); static void pline(struct passwd *); static void pretty(struct passwd *); #ifdef USE_BSM_AUDIT @@ -214,14 +215,7 @@ main(int argc, char *argv[]) exit(0); } - if (pw) { - id_print(pw, 1, 0, 0); - } - else { - id = getuid(); - pw = getpwuid(id); - id_print(pw, 0, 1, 1); - } + id_print(pw); exit(0); } @@ -266,7 +260,7 @@ pretty(struct passwd *pw) } static void -id_print(struct passwd *pw, int use_ggl, int p_euid, int p_egid) +id_print(struct passwd *pw) { struct group *gr; gid_t gid, egid, lastgid; @@ -275,21 +269,24 @@ id_print(struct passwd *pw, int use_ggl, int p_euid, int p_egid) long ngroups_max; gid_t *groups; const char *fmt; + bool print_dbinfo; - if (pw != NULL) { + print_dbinfo = pw != NULL; + if (print_dbinfo) { uid = pw->pw_uid; gid = pw->pw_gid; } else { uid = getuid(); gid = getgid(); + pw = getpwuid(uid); } ngroups_max = sysconf(_SC_NGROUPS_MAX) + 1; if ((groups = malloc(sizeof(gid_t) * ngroups_max)) == NULL) err(1, "malloc"); - if (use_ggl && pw != NULL) { + if (print_dbinfo) { ngroups = ngroups_max; getgrouplist(pw->pw_name, gid, groups, &ngroups); } @@ -297,19 +294,23 @@ id_print(struct passwd *pw, int use_ggl, int p_euid, int p_egid) ngroups = getgroups(ngroups_max, groups); } + /* + * We always resolve uids and gids where we can to a name, even if we + * are printing the running process credentials, to be nice. + */ if (pw != NULL) printf("uid=%u(%s)", uid, pw->pw_name); - else - printf("uid=%u", getuid()); + else + printf("uid=%u", uid); printf(" gid=%u", gid); if ((gr = getgrgid(gid))) (void)printf("(%s)", gr->gr_name); - if (p_euid && (euid = geteuid()) != uid) { + if (!print_dbinfo && (euid = geteuid()) != uid) { (void)printf(" euid=%u", euid); if ((pw = getpwuid(euid))) (void)printf("(%s)", pw->pw_name); } - if (p_egid && (egid = getegid()) != gid) { + if (!print_dbinfo && (egid = getegid()) != gid) { (void)printf(" egid=%u", egid); if ((gr = getgrgid(egid))) (void)printf("(%s)", gr->gr_name);