Date: Thu, 30 Oct 2025 10:38:50 GMT From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= <des@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: c071bcda44b7 - stable/14 - id: Add -d and -s options Message-ID: <202510301038.59UAcoFS082699@gitrepo.freebsd.org>
index | next in thread | raw e-mail
The branch stable/14 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=c071bcda44b792d8abc36d1315a9b4152c5cbda2 commit c071bcda44b792d8abc36d1315a9b4152c5cbda2 Author: Dag-Erling Smørgrav <des@FreeBSD.org> AuthorDate: 2025-10-28 16:51:56 +0000 Commit: Dag-Erling Smørgrav <des@FreeBSD.org> CommitDate: 2025-10-30 10:38:19 +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 (cherry picked from commit f41b1eb637f576634be0df9d657f46aa57afea59) --- 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 eab875c635ef..a03926e702e4 100644 --- a/usr.bin/id/id.1 +++ b/usr.bin/id/id.1 @@ -30,7 +30,7 @@ .\" .\" @(#)id.1 8.1 (Berkeley) 6/6/93 .\" -.Dd March 5, 2011 +.Dd October 23, 2025 .Dt ID 1 .Os .Sh NAME @@ -52,12 +52,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 @@ -92,6 +98,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 @@ -130,6 +138,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 @@ -176,8 +186,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 818b53a04e2d..238c6f2bf709 100644 --- a/usr.bin/id/id.c +++ b/usr.bin/id/id.c @@ -67,6 +67,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 *); @@ -81,7 +83,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]; @@ -90,10 +92,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 = ""; @@ -126,6 +128,9 @@ main(int argc, char *argv[]) case 'c': cflag = true; break; + case 'd': + dflag = true; + break; case 'g': gflag = true; break; @@ -138,6 +143,9 @@ main(int argc, char *argv[]) case 'r': rflag = true; break; + case 's': + sflag = true; + break; case 'u': uflag = true; break; @@ -154,6 +162,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)) @@ -197,6 +207,11 @@ main(int argc, char *argv[]) exit(0); } + if (dflag) { + dir(pw); + exit(0); + } + if (Gflag) { group(pw, nflag); exit(0); @@ -217,6 +232,11 @@ main(int argc, char *argv[]) exit(0); } + if (sflag) { + shell(pw); + exit(0); + } + id_print(pw); exit(0); } @@ -476,6 +496,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) { @@ -493,8 +533,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); }home | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202510301038.59UAcoFS082699>
