From nobody Mon Aug 4 23:10:12 2025 X-Original-To: dev-commits-src-all@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 4bwsj069qgz63dhc; Mon, 04 Aug 2025 23:10:12 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4bwsj03Gp7z3XcT; Mon, 04 Aug 2025 23:10:12 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1754349012; 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=0zhvZPaYB1RjU1sZEiQWCLge87BXyHgbaTgBnv6l5/I=; b=YRqeBN0P6d4BNDy/Cubrs0ZHy1mLg2UCo4Pp9v5s85i5bKfXnZ/N7jQD9277xehBQMLrcG dKBVGel/pKhs6kpxtRVTbDNJn9ge1Y1jh/VyVR9+iRXLAOZl1uyiTylivJBlejxOhmLyEF VwT7s69ogW9oD+4SfEVaQ98ziNDukwOhZnyePzZORZvq54x7jB5/a08+ldXX7dtsTrh80R FtlyZ+JbXYIjgOt6Nrz8QyKwTjpr2O4Aje/0VB207LorFxtlpvmBjJ5JQ/EO0AVzyUAD19 gE3yyGxSRAZhbEuwsUFZmMzEBYGxFSUibG8UVpc0W1Y7NY/SiT+Kxv2GAuxBeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1754349012; 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=0zhvZPaYB1RjU1sZEiQWCLge87BXyHgbaTgBnv6l5/I=; b=diN1GBax7XV/4uzWvxJLlIac3O4QGZpFvVPwxyiT2JjzqSXsE/ZD1D6djFb87/BcttFJl2 oacP/jybA5c/rVPFULnLl2jCuDPcwI9MytED0xK2spPEb7kDYRl9WguZh2ZU92lkP2CcS7 l2sDvdWv1ImXen70tW63gp3W9H4F9QNt5hA5ybk0BNAuA4uNFH3GggVWGkC1EatU6ZPHiD kfQum2tVnzOh7ulBDmxASvEcSJXZSh2ErYpFRHliAaMI0EM3e99L8qsY+Xrw3itT+veyZX MHmkqTDPDWXo/qz2WlslbL2+TiBO/d89BWM/NJWHtwIcRzt/D64CR2f8j5WaKA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1754349012; a=rsa-sha256; cv=none; b=UZ7SrSnYCVIa6QB1LYUSUgGRfAu66g7g6ismMfvQX7/Koh5feLt5fIg5fbaEaTUbcLS5Hp 9yyPvZXFhUQ/8AUQy3ItOyVaFQAoWWBTmA/+et3WBkLBmol5EZVlet/Dwf21HCSGSD/J6t ekMwq5LcR1dVG5Ierx51u7QsSRI0skJzmqOJ96INGKRKZ+X8a9GD4Nj4Pql6Z8gIagYt0C bj9dC1noy9pzr/gfTpZkTixnSSWYBbS62yTw82OOUmTvfk7AT2/tRlBR/755Ez5/C94FNz zGLjoirR9AqDukPKwUqh0vdFeDvXMVhCb6lwoYPVv5HmTavaL5vfSDskPkNWpQ== 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 4bwsj00zXGz17dH; Mon, 04 Aug 2025 23:10:12 +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 574NAC5K082677; Mon, 4 Aug 2025 23:10:12 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 574NACFQ082674; Mon, 4 Aug 2025 23:10:12 GMT (envelope-from git) Date: Mon, 4 Aug 2025 23:10:12 GMT Message-Id: <202508042310.574NACFQ082674@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: 90b315233a33 - main - id: revert to historical and documented behavior for `id` List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 90b315233a3362b7427e2d2649eaa8acf0da197a Auto-Submitted: auto-generated The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=90b315233a3362b7427e2d2649eaa8acf0da197a commit 90b315233a3362b7427e2d2649eaa8acf0da197a Author: Kyle Evans AuthorDate: 2025-08-04 23:09:58 +0000 Commit: Kyle Evans CommitDate: 2025-08-04 23:09:58 +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 --- 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 dfd2e89a7e78..7112e0dddb91 100644 --- a/usr.bin/id/id.c +++ b/usr.bin/id/id.c @@ -40,13 +40,14 @@ #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 @@ -202,14 +203,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); } @@ -254,7 +248,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; @@ -263,21 +257,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); } @@ -285,19 +282,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);