From: millert Date: Tue, 19 May 2015 16:03:19 +0000 (+0000) Subject: Add -c flag to display the user's login class. OK espie@ X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=fb094e13d4c7f21b3e90675b17d69b7512fbee69;p=openbsd Add -c flag to display the user's login class. OK espie@ --- diff --git a/usr.bin/id/id.1 b/usr.bin/id/id.1 index ba4b1bcdda3..35728ee53ee 100644 --- a/usr.bin/id/id.1 +++ b/usr.bin/id/id.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: id.1,v 1.17 2010/09/03 11:09:29 jmc Exp $ +.\" $OpenBSD: id.1,v 1.18 2015/05/19 16:03:19 millert Exp $ .\" $NetBSD: id.1,v 1.5 1995/09/28 08:05:40 perry Exp $ .\" .\" Copyright (c) 1991, 1993, 1994 @@ -33,7 +33,7 @@ .\" .\" @(#)id.1 8.2 (Berkeley) 5/5/94 .\" -.Dd $Mdocdate: September 3 2010 $ +.Dd $Mdocdate: May 19 2015 $ .Dt ID 1 .Os .Sh NAME @@ -43,6 +43,9 @@ .Nm id .Op Ar user .Nm id +.Fl c +.Op Ar user +.Nm id .Fl G Op Fl n .Op Ar user .Nm id @@ -70,6 +73,9 @@ In this case, the real and effective IDs are assumed to be the same. .Pp The options are as follows: .Bl -tag -width Ds +.It Fl c +Display the login class of the real user ID or the specified +.Ar user . .It Fl G Display the different group IDs (effective, real and supplementary) as whitespace separated numbers, in no particular order. @@ -104,6 +110,10 @@ ID is displayed as a name, preceded by the keyword The list of groups to which the user belongs is then displayed as names, preceded by the keyword .Dq groups . +If there is a login class specified for the user in the +.Xr passwd 5 +database, it is displayed, preceded by the keyword +.Dq class . Each display is on a separate line. .It Fl r Display the real ID for the @@ -117,7 +127,8 @@ Display the effective user ID as a number. .Sh EXIT STATUS .Ex -std id .Sh SEE ALSO -.Xr who 1 +.Xr who 1 , +.Xr login.conf 5 .Sh STANDARDS The .Nm @@ -125,9 +136,9 @@ utility is compliant with the .St -p1003.1-2008 specification. .Pp -The flag -.Op Fl p -is an extension to that specification. +The flags +.Op Fl cp +are extensions to that specification. .Sh HISTORY The historic diff --git a/usr.bin/id/id.c b/usr.bin/id/id.c index 45461b3457a..f22ccff8bcb 100644 --- a/usr.bin/id/id.c +++ b/usr.bin/id/id.c @@ -1,4 +1,4 @@ -/* $OpenBSD: id.c,v 1.22 2015/01/16 06:40:08 deraadt Exp $ */ +/* $OpenBSD: id.c,v 1.23 2015/05/19 16:03:19 millert Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -38,6 +38,7 @@ #include #include #include +#include void current(void); void pretty(struct passwd *); @@ -52,12 +53,12 @@ main(int argc, char *argv[]) { struct group *gr; struct passwd *pw; - int Gflag, ch, gflag, nflag, pflag, rflag, uflag; + int ch, cflag, Gflag, gflag, nflag, pflag, rflag, uflag; uid_t uid; gid_t gid; const char *opts; - Gflag = gflag = nflag = pflag = rflag = uflag = 0; + cflag = Gflag = gflag = nflag = pflag = rflag = uflag = 0; if (strcmp(getprogname(), "groups") == 0) { Gflag = 1; @@ -72,10 +73,13 @@ main(int argc, char *argv[]) if (argc > 1) usage(); } else - opts = "Ggnpru"; + opts = "cGgnpru"; while ((ch = getopt(argc, argv, opts)) != -1) switch(ch) { + case 'c': + cflag = 1; + break; case 'G': Gflag = 1; break; @@ -101,7 +105,7 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; - switch (Gflag + gflag + pflag + uflag) { + switch (cflag + Gflag + gflag + pflag + uflag) { case 1: break; case 0: @@ -117,6 +121,16 @@ main(int argc, char *argv[]) pw = *argv ? who(*argv) : NULL; + if (cflag) { + if (pw == NULL) + pw = getpwuid(getuid()); + if (pw != NULL && pw->pw_class != NULL && *pw->pw_class != '\0') + (void)printf("%s\n", pw->pw_class); + else + (void)printf("%s\n", LOGIN_DEFCLASS); + exit(0); + } + if (gflag) { gid = pw ? pw->pw_gid : rflag ? getgid() : getegid(); if (nflag && (gr = getgrgid(gid))) @@ -190,6 +204,8 @@ pretty(struct passwd *pw) (void)printf("groups\t"); group(NULL, 1); } + if (pw != NULL && pw->pw_class != NULL && *pw->pw_class != '\0') + (void)printf("class\t%s\n", pw->pw_class); } void @@ -325,6 +341,7 @@ usage(void) (void)fprintf(stderr, "usage: whoami\n"); } else { (void)fprintf(stderr, "usage: id [user]\n"); + (void)fprintf(stderr, " id -c [user]\n"); (void)fprintf(stderr, " id -G [-n] [user]\n"); (void)fprintf(stderr, " id -g [-nr] [user]\n"); (void)fprintf(stderr, " id -p [user]\n");