From nobody Tue Oct 28 16:52:22 2025 X-Original-To: dev-commits-src-main@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 4cwxHq707Yz6D9dn; Tue, 28 Oct 2025 16:52:23 +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 4cwxHp6qLjz49xG; Tue, 28 Oct 2025 16:52:22 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1761670343; 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=yraWSBJBkHDhvsyzQPzSK98AZKXZ/zSHkGXYgQjvsJc=; b=Yumpvi0DqBTeulsdZh92AzOnoPJodq3EznUBN2rGYNVcraihaa61IrRR8YFjru56G1Hdpt RM39J6C1V/WyCY36xQEMq3VPKIsKV4pSsrUSuzB/gqQm5Dk7aGKdM6x88beER3EMMKE7Jb BndMVi9rWZXh/HCgXN5nHeU2Oh53NVHNFYEsjzPhyZIkp2oCQOGD3Zk0h4n2pxjg1/EIgl QaD0TjNDZMKvhRDB1wWRIZ8KSRz/lsQTqha7/d9ElzwZbupy7z/03+zQMUFZFVQwU4Dwym 6M+IJ3rACOhM+cANY/bxaflZKQK2uH2XeNRbHsBZxV3n7kPPh9+Wi8tuHhmFfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1761670343; 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=yraWSBJBkHDhvsyzQPzSK98AZKXZ/zSHkGXYgQjvsJc=; b=kHEyKlfDhEe6fFu5LeRZTUNcK7iUlBWbwcLLnSXnSwxgQKAfH4nphbblV+TdsjdNqKI25D MlSfXqmmVM3icvLytx8tnT8UYmk5erq+QEK2LIgGGDzt4dr5w2ObzdYJpeh1JgZpPleDyT ELi9yPqt/YQeeOsZ2+096E4eRjTt6crxgiuUtcL0cHMeazMsBILSgESefNLbVrTjx9XXRH YfKs6wg65yloMH+m77zLolZClNU1K4dNQueh9KA8CmDJGZoRq3BBUq8ae6/8E4rUaHwqZH IVfqsQoak6GNxHTTn5pKmjOv1+jcJKktTFnicAg4WX2o5aEgYvpmdN7gLMqUBA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1761670343; a=rsa-sha256; cv=none; b=r8cXJE3M5Jw8WLzApLE32p8tV3GIMCU+wQLuubgFq8z/KpggMipKLTGP33fltKrKSrYgmL yxZoUiwicwWdIhwX90q8ccY7gcHTiIxw3usze5CItbt9uey+A6JZxTKCh8EttE+pR3+LFG gXD5xad9bJuMPw6N/uN7zh9uzXygN2ZgQQ1zou4Dfgf4Ljc2E2Ac8mm2KYxxfnhUsEwpvB ZotMt9oCQCcNo9+xXHRBewltsFvUARUxqPLf9fpKmdqFAJISBQVDY5Mznnk0EPG9yuE4Hg X+4kAMwIOnTOGYl5iSTNPQMRVjJ2XRZshGqnkRlvF9qMWwIr7WK1bdt0CsVzrQ== 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 4cwxHp6PzvzymT; Tue, 28 Oct 2025 16:52:22 +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 59SGqMlH066812; Tue, 28 Oct 2025 16:52:22 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 59SGqMvQ066809; Tue, 28 Oct 2025 16:52:22 GMT (envelope-from git) Date: Tue, 28 Oct 2025 16:52:22 GMT Message-Id: <202510281652.59SGqMvQ066809@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= Subject: git: f41b1eb637f5 - main - id: Add -d and -s options List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: f41b1eb637f576634be0df9d657f46aa57afea59 Auto-Submitted: auto-generated The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=f41b1eb637f576634be0df9d657f46aa57afea59 commit f41b1eb637f576634be0df9d657f46aa57afea59 Author: Dag-Erling Smørgrav AuthorDate: 2025-10-28 16:51:56 +0000 Commit: Dag-Erling Smørgrav CommitDate: 2025-10-28 16:52:07 +0000 id: Add -d and -s options These options may not be combined with any other options and print the current or specified user's home directory and shell respectively. Reviewed by: imp, bcr Differential Revision: https://reviews.freebsd.org/D53301 --- usr.bin/id/id.1 | 28 +++++++++++++++++++++++++--- usr.bin/id/id.c | 48 +++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 70 insertions(+), 6 deletions(-) diff --git a/usr.bin/id/id.1 b/usr.bin/id/id.1 index b8dafb6650b0..62c941f84798 100644 --- a/usr.bin/id/id.1 +++ b/usr.bin/id/id.1 @@ -28,7 +28,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd March 5, 2011 +.Dd October 23, 2025 .Dt ID 1 .Os .Sh NAME @@ -50,12 +50,18 @@ .Nm .Fl c .Nm +.Fl d +.Op Ar user +.Nm .Fl g Op Fl nr .Op Ar user .Nm .Fl p .Op Ar user .Nm +.Fl s +.Op Ar user +.Nm .Fl u Op Fl nr .Op Ar user .Sh DESCRIPTION @@ -90,6 +96,8 @@ Ignored for compatibility with other implementations. .It Fl c Display current login class. +.It Fl d +Display the home directory of the current or specified user. .It Fl g Display the effective group ID as a number. .It Fl n @@ -128,6 +136,8 @@ Display the real ID for the and .Fl u options instead of the effective ID. +.It Fl s +Display the shell of the current or specified user. .It Fl u Display the effective user ID as a number. .El @@ -174,8 +184,20 @@ bob pts/5 Dec 4 19:51 .Sh STANDARDS The .Nm -function is expected to conform to -.St -p1003.2 . +utility is expected to conform to +.St -p1003.1-2024 . +The +.Fl A , +.Fl M , +.Fl P , +.Fl c , +.Fl d , +.Fl p , +and +.Fl s +options are +.Fx +extensions. .Sh HISTORY The historic diff --git a/usr.bin/id/id.c b/usr.bin/id/id.c index a326aa14c7c7..5f9d2670caa3 100644 --- a/usr.bin/id/id.c +++ b/usr.bin/id/id.c @@ -55,6 +55,8 @@ static void auditid(void); #endif static void group(struct passwd *, bool); static void maclabel(void); +static void dir(struct passwd *); +static void shell(struct passwd *); static void usage(void); static struct passwd *who(char *); @@ -69,7 +71,7 @@ main(int argc, char *argv[]) bool Aflag; #endif bool Gflag, Mflag, Pflag; - bool cflag, gflag, nflag, pflag, rflag, uflag; + bool cflag, dflag, gflag, nflag, pflag, rflag, sflag, uflag; int ch, combo, error, id; const char *myname, *optstr; char loginclass[MAXLOGNAME]; @@ -78,10 +80,10 @@ main(int argc, char *argv[]) Aflag = false; #endif Gflag = Mflag = Pflag = false; - cflag = gflag = nflag = pflag = rflag = uflag = false; + cflag = dflag = gflag = nflag = pflag = rflag = sflag = uflag = false; myname = getprogname(); - optstr = "AGMPacgnpru"; + optstr = "AGMPacdgnprsu"; if (strcmp(myname, "groups") == 0) { isgroups = true; optstr = ""; @@ -114,6 +116,9 @@ main(int argc, char *argv[]) case 'c': cflag = true; break; + case 'd': + dflag = true; + break; case 'g': gflag = true; break; @@ -126,6 +131,9 @@ main(int argc, char *argv[]) case 'r': rflag = true; break; + case 's': + sflag = true; + break; case 'u': uflag = true; break; @@ -142,6 +150,8 @@ main(int argc, char *argv[]) usage(); combo = Aflag + Gflag + Mflag + Pflag + gflag + pflag + uflag; + if (combo + dflag + sflag > 1) + usage(); if (combo > 1) usage(); if (combo == 0 && (nflag || rflag)) @@ -185,6 +195,11 @@ main(int argc, char *argv[]) exit(0); } + if (dflag) { + dir(pw); + exit(0); + } + if (Gflag) { group(pw, nflag); exit(0); @@ -205,6 +220,11 @@ main(int argc, char *argv[]) exit(0); } + if (sflag) { + shell(pw); + exit(0); + } + id_print(pw); exit(0); } @@ -464,6 +484,26 @@ pline(struct passwd *pw) pw->pw_dir, pw->pw_shell); } +static void +dir(struct passwd *pw) +{ + if (pw == NULL) { + if ((pw = getpwuid(getuid())) == NULL) + err(1, "getpwuid"); + } + printf("%s\n", pw->pw_dir); +} + +static void +shell(struct passwd *pw) +{ + if (pw == NULL) { + if ((pw = getpwuid(getuid())) == NULL) + err(1, "getpwuid"); + } + printf("%s\n", pw->pw_shell); +} + static void usage(void) { @@ -481,8 +521,10 @@ usage(void) " id -M\n" " id -P [user]\n" " id -c\n" + " id -d [user]\n" " id -g [-nr] [user]\n" " id -p [user]\n" + " id -s [user]\n" " id -u [-nr] [user]\n"); exit(1); }