-.\" $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
.\"
.\" @(#)id.1 8.2 (Berkeley) 5/5/94
.\"
-.Dd $Mdocdate: September 3 2010 $
+.Dd $Mdocdate: May 19 2015 $
.Dt ID 1
.Os
.Sh NAME
.Nm id
.Op Ar user
.Nm id
+.Fl c
+.Op Ar user
+.Nm id
.Fl G Op Fl n
.Op Ar user
.Nm id
.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.
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
.Sh EXIT STATUS
.Ex -std id
.Sh SEE ALSO
-.Xr who 1
+.Xr who 1 ,
+.Xr login.conf 5
.Sh STANDARDS
The
.Nm
.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
-/* $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
#include <string.h>
#include <unistd.h>
#include <limits.h>
+#include <login_cap.h>
void current(void);
void pretty(struct passwd *);
{
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;
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;
argc -= optind;
argv += optind;
- switch (Gflag + gflag + pflag + uflag) {
+ switch (cflag + Gflag + gflag + pflag + uflag) {
case 1:
break;
case 0:
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)))
(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
(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");