xref: /minix3/usr.bin/id/id.c (revision 4b9cc932b7efaa73ee38ffe96aaefe8d5cd30735)
1*4b9cc932SThomas Cort /*-
2*4b9cc932SThomas Cort  * Copyright (c) 1991, 1993
3*4b9cc932SThomas Cort  *	The Regents of the University of California.  All rights reserved.
4*4b9cc932SThomas Cort  *
5*4b9cc932SThomas Cort  * Redistribution and use in source and binary forms, with or without
6*4b9cc932SThomas Cort  * modification, are permitted provided that the following conditions
7*4b9cc932SThomas Cort  * are met:
8*4b9cc932SThomas Cort  * 1. Redistributions of source code must retain the above copyright
9*4b9cc932SThomas Cort  *    notice, this list of conditions and the following disclaimer.
10*4b9cc932SThomas Cort  * 2. Redistributions in binary form must reproduce the above copyright
11*4b9cc932SThomas Cort  *    notice, this list of conditions and the following disclaimer in the
12*4b9cc932SThomas Cort  *    documentation and/or other materials provided with the distribution.
13*4b9cc932SThomas Cort  * 3. Neither the name of the University nor the names of its contributors
14*4b9cc932SThomas Cort  *    may be used to endorse or promote products derived from this software
15*4b9cc932SThomas Cort  *    without specific prior written permission.
16*4b9cc932SThomas Cort  *
17*4b9cc932SThomas Cort  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18*4b9cc932SThomas Cort  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19*4b9cc932SThomas Cort  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20*4b9cc932SThomas Cort  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21*4b9cc932SThomas Cort  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22*4b9cc932SThomas Cort  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23*4b9cc932SThomas Cort  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24*4b9cc932SThomas Cort  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25*4b9cc932SThomas Cort  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26*4b9cc932SThomas Cort  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27*4b9cc932SThomas Cort  * SUCH DAMAGE.
28*4b9cc932SThomas Cort  */
29*4b9cc932SThomas Cort 
30*4b9cc932SThomas Cort #include <sys/cdefs.h>
31*4b9cc932SThomas Cort #ifndef lint
32*4b9cc932SThomas Cort __COPYRIGHT("@(#) Copyright (c) 1991, 1993\
33*4b9cc932SThomas Cort  The Regents of the University of California.  All rights reserved.");
34*4b9cc932SThomas Cort #endif /* not lint */
35*4b9cc932SThomas Cort 
36*4b9cc932SThomas Cort #ifndef lint
37*4b9cc932SThomas Cort #if 0
38*4b9cc932SThomas Cort static char sccsid[] = "@(#)id.c	8.3 (Berkeley) 4/28/95";
39*4b9cc932SThomas Cort #else
40*4b9cc932SThomas Cort __RCSID("$NetBSD: id.c,v 1.32 2011/09/16 15:39:26 joerg Exp $");
41*4b9cc932SThomas Cort #endif
42*4b9cc932SThomas Cort #endif /* not lint */
43*4b9cc932SThomas Cort 
44*4b9cc932SThomas Cort #include <sys/param.h>
45*4b9cc932SThomas Cort 
46*4b9cc932SThomas Cort #include <err.h>
47*4b9cc932SThomas Cort #include <errno.h>
48*4b9cc932SThomas Cort #include <grp.h>
49*4b9cc932SThomas Cort #include <pwd.h>
50*4b9cc932SThomas Cort #include <stdio.h>
51*4b9cc932SThomas Cort #include <stdlib.h>
52*4b9cc932SThomas Cort #include <string.h>
53*4b9cc932SThomas Cort #include <unistd.h>
54*4b9cc932SThomas Cort 
55*4b9cc932SThomas Cort static void current(void);
56*4b9cc932SThomas Cort static void pretty(struct passwd *);
57*4b9cc932SThomas Cort static void group(struct passwd *, int);
58*4b9cc932SThomas Cort __dead static void usage(void);
59*4b9cc932SThomas Cort static void user(struct passwd *);
60*4b9cc932SThomas Cort static struct passwd *who(char *);
61*4b9cc932SThomas Cort 
62*4b9cc932SThomas Cort static int maxgroups;
63*4b9cc932SThomas Cort static gid_t *groups;
64*4b9cc932SThomas Cort 
65*4b9cc932SThomas Cort int
main(int argc,char * argv[])66*4b9cc932SThomas Cort main(int argc, char *argv[])
67*4b9cc932SThomas Cort {
68*4b9cc932SThomas Cort 	struct group *gr;
69*4b9cc932SThomas Cort 	struct passwd *pw;
70*4b9cc932SThomas Cort 	int ch, id;
71*4b9cc932SThomas Cort 	int Gflag, gflag, nflag, pflag, rflag, uflag;
72*4b9cc932SThomas Cort 	const char *opts;
73*4b9cc932SThomas Cort 
74*4b9cc932SThomas Cort 	Gflag = gflag = nflag = pflag = rflag = uflag = 0;
75*4b9cc932SThomas Cort 
76*4b9cc932SThomas Cort 	if (strcmp(getprogname(), "groups") == 0) {
77*4b9cc932SThomas Cort 		Gflag = 1;
78*4b9cc932SThomas Cort 		nflag = 1;
79*4b9cc932SThomas Cort 		opts = "";
80*4b9cc932SThomas Cort 		if (argc > 2)
81*4b9cc932SThomas Cort 			usage();
82*4b9cc932SThomas Cort 	} else if (strcmp(getprogname(), "whoami") == 0) {
83*4b9cc932SThomas Cort 		uflag = 1;
84*4b9cc932SThomas Cort 		nflag = 1;
85*4b9cc932SThomas Cort 		opts = "";
86*4b9cc932SThomas Cort 		if (argc > 1)
87*4b9cc932SThomas Cort 			usage();
88*4b9cc932SThomas Cort 	} else
89*4b9cc932SThomas Cort 		opts = "Ggnpru";
90*4b9cc932SThomas Cort 
91*4b9cc932SThomas Cort 	while ((ch = getopt(argc, argv, opts)) != -1)
92*4b9cc932SThomas Cort 		switch (ch) {
93*4b9cc932SThomas Cort 		case 'G':
94*4b9cc932SThomas Cort 			Gflag = 1;
95*4b9cc932SThomas Cort 			break;
96*4b9cc932SThomas Cort 		case 'g':
97*4b9cc932SThomas Cort 			gflag = 1;
98*4b9cc932SThomas Cort 			break;
99*4b9cc932SThomas Cort 		case 'n':
100*4b9cc932SThomas Cort 			nflag = 1;
101*4b9cc932SThomas Cort 			break;
102*4b9cc932SThomas Cort 		case 'p':
103*4b9cc932SThomas Cort 			pflag = 1;
104*4b9cc932SThomas Cort 			break;
105*4b9cc932SThomas Cort 		case 'r':
106*4b9cc932SThomas Cort 			rflag = 1;
107*4b9cc932SThomas Cort 			break;
108*4b9cc932SThomas Cort 		case 'u':
109*4b9cc932SThomas Cort 			uflag = 1;
110*4b9cc932SThomas Cort 			break;
111*4b9cc932SThomas Cort 		case '?':
112*4b9cc932SThomas Cort 		default:
113*4b9cc932SThomas Cort 			usage();
114*4b9cc932SThomas Cort 		}
115*4b9cc932SThomas Cort 	argc -= optind;
116*4b9cc932SThomas Cort 	argv += optind;
117*4b9cc932SThomas Cort 
118*4b9cc932SThomas Cort 	switch (Gflag + gflag + pflag + uflag) {
119*4b9cc932SThomas Cort 	case 1:
120*4b9cc932SThomas Cort 		break;
121*4b9cc932SThomas Cort 	case 0:
122*4b9cc932SThomas Cort 		if (!nflag && !rflag)
123*4b9cc932SThomas Cort 			break;
124*4b9cc932SThomas Cort 		/* FALLTHROUGH */
125*4b9cc932SThomas Cort 	default:
126*4b9cc932SThomas Cort 		usage();
127*4b9cc932SThomas Cort 	}
128*4b9cc932SThomas Cort 
129*4b9cc932SThomas Cort 	if (strcmp(opts, "") != 0 && argc > 1)
130*4b9cc932SThomas Cort 		usage();
131*4b9cc932SThomas Cort 
132*4b9cc932SThomas Cort 	pw = *argv ? who(*argv) : NULL;
133*4b9cc932SThomas Cort 
134*4b9cc932SThomas Cort 	maxgroups = sysconf(_SC_NGROUPS_MAX);
135*4b9cc932SThomas Cort 	if ((groups = malloc((maxgroups + 1) * sizeof(gid_t))) == NULL)
136*4b9cc932SThomas Cort 		err(1, NULL);
137*4b9cc932SThomas Cort 
138*4b9cc932SThomas Cort 	if (gflag) {
139*4b9cc932SThomas Cort 		id = pw ? pw->pw_gid : rflag ? getgid() : getegid();
140*4b9cc932SThomas Cort 		if (nflag && (gr = getgrgid(id)))
141*4b9cc932SThomas Cort 			(void)printf("%s\n", gr->gr_name);
142*4b9cc932SThomas Cort 		else
143*4b9cc932SThomas Cort 			(void)printf("%u\n", id);
144*4b9cc932SThomas Cort 		goto done;
145*4b9cc932SThomas Cort 	}
146*4b9cc932SThomas Cort 
147*4b9cc932SThomas Cort 	if (uflag) {
148*4b9cc932SThomas Cort 		id = pw ? pw->pw_uid : rflag ? getuid() : geteuid();
149*4b9cc932SThomas Cort 		if (nflag && (pw = getpwuid(id)))
150*4b9cc932SThomas Cort 			(void)printf("%s\n", pw->pw_name);
151*4b9cc932SThomas Cort 		else
152*4b9cc932SThomas Cort 			(void)printf("%u\n", id);
153*4b9cc932SThomas Cort 		goto done;
154*4b9cc932SThomas Cort 	}
155*4b9cc932SThomas Cort 
156*4b9cc932SThomas Cort 	if (Gflag) {
157*4b9cc932SThomas Cort 		group(pw, nflag);
158*4b9cc932SThomas Cort 		goto done;
159*4b9cc932SThomas Cort 	}
160*4b9cc932SThomas Cort 
161*4b9cc932SThomas Cort 	if (pflag) {
162*4b9cc932SThomas Cort 		pretty(pw);
163*4b9cc932SThomas Cort 		goto done;
164*4b9cc932SThomas Cort 	}
165*4b9cc932SThomas Cort 
166*4b9cc932SThomas Cort 	if (pw)
167*4b9cc932SThomas Cort 		user(pw);
168*4b9cc932SThomas Cort 	else
169*4b9cc932SThomas Cort 		current();
170*4b9cc932SThomas Cort done:
171*4b9cc932SThomas Cort 	free(groups);
172*4b9cc932SThomas Cort 
173*4b9cc932SThomas Cort 	return 0;
174*4b9cc932SThomas Cort }
175*4b9cc932SThomas Cort 
176*4b9cc932SThomas Cort static void
pretty(struct passwd * pw)177*4b9cc932SThomas Cort pretty(struct passwd *pw)
178*4b9cc932SThomas Cort {
179*4b9cc932SThomas Cort 	struct group *gr;
180*4b9cc932SThomas Cort 	u_int eid, rid;
181*4b9cc932SThomas Cort 	char *login;
182*4b9cc932SThomas Cort 
183*4b9cc932SThomas Cort 	if (pw) {
184*4b9cc932SThomas Cort 		(void)printf("uid\t%s\n", pw->pw_name);
185*4b9cc932SThomas Cort 		(void)printf("groups\t");
186*4b9cc932SThomas Cort 		group(pw, 1);
187*4b9cc932SThomas Cort 	} else {
188*4b9cc932SThomas Cort 		if ((login = getlogin()) == NULL)
189*4b9cc932SThomas Cort 			err(1, "getlogin");
190*4b9cc932SThomas Cort 
191*4b9cc932SThomas Cort 		pw = getpwuid(rid = getuid());
192*4b9cc932SThomas Cort 		if (pw == NULL || strcmp(login, pw->pw_name))
193*4b9cc932SThomas Cort 			(void)printf("login\t%s\n", login);
194*4b9cc932SThomas Cort 		if (pw)
195*4b9cc932SThomas Cort 			(void)printf("uid\t%s\n", pw->pw_name);
196*4b9cc932SThomas Cort 		else
197*4b9cc932SThomas Cort 			(void)printf("uid\t%u\n", rid);
198*4b9cc932SThomas Cort 
199*4b9cc932SThomas Cort 		if ((eid = geteuid()) != rid) {
200*4b9cc932SThomas Cort 			if ((pw = getpwuid(eid)) != NULL)
201*4b9cc932SThomas Cort 				(void)printf("euid\t%s\n", pw->pw_name);
202*4b9cc932SThomas Cort 			else
203*4b9cc932SThomas Cort 				(void)printf("euid\t%u\n", eid);
204*4b9cc932SThomas Cort 		}
205*4b9cc932SThomas Cort 		if ((rid = getgid()) != (eid = getegid())) {
206*4b9cc932SThomas Cort 			if ((gr = getgrgid(rid)) != NULL)
207*4b9cc932SThomas Cort 				(void)printf("rgid\t%s\n", gr->gr_name);
208*4b9cc932SThomas Cort 			else
209*4b9cc932SThomas Cort 				(void)printf("rgid\t%u\n", rid);
210*4b9cc932SThomas Cort 		}
211*4b9cc932SThomas Cort 		(void)printf("groups\t");
212*4b9cc932SThomas Cort 		group(NULL, 1);
213*4b9cc932SThomas Cort 	}
214*4b9cc932SThomas Cort }
215*4b9cc932SThomas Cort 
216*4b9cc932SThomas Cort static void
current(void)217*4b9cc932SThomas Cort current(void)
218*4b9cc932SThomas Cort {
219*4b9cc932SThomas Cort 	struct group *gr;
220*4b9cc932SThomas Cort 	struct passwd *pw;
221*4b9cc932SThomas Cort 	gid_t gid, egid, lastid;
222*4b9cc932SThomas Cort 	uid_t uid, euid;
223*4b9cc932SThomas Cort 	int cnt, ngroups;
224*4b9cc932SThomas Cort 	const char *fmt;
225*4b9cc932SThomas Cort 
226*4b9cc932SThomas Cort 	uid = getuid();
227*4b9cc932SThomas Cort 	(void)printf("uid=%ju", (uintmax_t)uid);
228*4b9cc932SThomas Cort 	if ((pw = getpwuid(uid)) != NULL)
229*4b9cc932SThomas Cort 		(void)printf("(%s)", pw->pw_name);
230*4b9cc932SThomas Cort 	gid = getgid();
231*4b9cc932SThomas Cort 	(void)printf(" gid=%ju", (uintmax_t)gid);
232*4b9cc932SThomas Cort 	if ((gr = getgrgid(gid)) != NULL)
233*4b9cc932SThomas Cort 		(void)printf("(%s)", gr->gr_name);
234*4b9cc932SThomas Cort 	if ((euid = geteuid()) != uid) {
235*4b9cc932SThomas Cort 		(void)printf(" euid=%ju", (uintmax_t)euid);
236*4b9cc932SThomas Cort 		if ((pw = getpwuid(euid)) != NULL)
237*4b9cc932SThomas Cort 			(void)printf("(%s)", pw->pw_name);
238*4b9cc932SThomas Cort 	}
239*4b9cc932SThomas Cort 	if ((egid = getegid()) != gid) {
240*4b9cc932SThomas Cort 		(void)printf(" egid=%ju", (uintmax_t)egid);
241*4b9cc932SThomas Cort 		if ((gr = getgrgid(egid)) != NULL)
242*4b9cc932SThomas Cort 			(void)printf("(%s)", gr->gr_name);
243*4b9cc932SThomas Cort 	}
244*4b9cc932SThomas Cort 	if ((ngroups = getgroups(maxgroups, groups)) != 0) {
245*4b9cc932SThomas Cort 		for (fmt = " groups=%ju", lastid = -1, cnt = 0; cnt < ngroups;
246*4b9cc932SThomas Cort 		    fmt = ",%ju", lastid = gid, cnt++) {
247*4b9cc932SThomas Cort 			gid = groups[cnt];
248*4b9cc932SThomas Cort 			if (lastid == gid)
249*4b9cc932SThomas Cort 				continue;
250*4b9cc932SThomas Cort 			(void)printf(fmt, (uintmax_t)gid);
251*4b9cc932SThomas Cort 			if ((gr = getgrgid(gid)) != NULL)
252*4b9cc932SThomas Cort 				(void)printf("(%s)", gr->gr_name);
253*4b9cc932SThomas Cort 		}
254*4b9cc932SThomas Cort 	}
255*4b9cc932SThomas Cort 	(void)printf("\n");
256*4b9cc932SThomas Cort }
257*4b9cc932SThomas Cort 
258*4b9cc932SThomas Cort static void
user(struct passwd * pw)259*4b9cc932SThomas Cort user(struct passwd *pw)
260*4b9cc932SThomas Cort {
261*4b9cc932SThomas Cort 	struct group *gr;
262*4b9cc932SThomas Cort 	const char *fmt;
263*4b9cc932SThomas Cort 	int cnt, id, lastid, ngroups;
264*4b9cc932SThomas Cort 	gid_t *glist = groups;
265*4b9cc932SThomas Cort 
266*4b9cc932SThomas Cort 	id = pw->pw_uid;
267*4b9cc932SThomas Cort 	(void)printf("uid=%u(%s)", id, pw->pw_name);
268*4b9cc932SThomas Cort 	(void)printf(" gid=%lu", (u_long)pw->pw_gid);
269*4b9cc932SThomas Cort 	if ((gr = getgrgid(pw->pw_gid)) != NULL)
270*4b9cc932SThomas Cort 		(void)printf("(%s)", gr->gr_name);
271*4b9cc932SThomas Cort 	ngroups = maxgroups + 1;
272*4b9cc932SThomas Cort 	if (getgrouplist(pw->pw_name, pw->pw_gid, glist, &ngroups) == -1) {
273*4b9cc932SThomas Cort 		glist = malloc(ngroups * sizeof(gid_t));
274*4b9cc932SThomas Cort 		(void) getgrouplist(pw->pw_name, pw->pw_gid, glist, &ngroups);
275*4b9cc932SThomas Cort 	}
276*4b9cc932SThomas Cort 	for (fmt = " groups=%u", lastid = -1, cnt = 0; cnt < ngroups;
277*4b9cc932SThomas Cort 	    fmt=",%u", lastid = id, cnt++) {
278*4b9cc932SThomas Cort 		id = glist[cnt];
279*4b9cc932SThomas Cort 		if (lastid == id)
280*4b9cc932SThomas Cort 			continue;
281*4b9cc932SThomas Cort 		(void)printf(fmt, id);
282*4b9cc932SThomas Cort 		if ((gr = getgrgid(id)) != NULL)
283*4b9cc932SThomas Cort 			(void)printf("(%s)", gr->gr_name);
284*4b9cc932SThomas Cort 	}
285*4b9cc932SThomas Cort 	(void)printf("\n");
286*4b9cc932SThomas Cort 	if (glist != groups)
287*4b9cc932SThomas Cort 		free(glist);
288*4b9cc932SThomas Cort }
289*4b9cc932SThomas Cort 
290*4b9cc932SThomas Cort static void
group(struct passwd * pw,int nflag)291*4b9cc932SThomas Cort group(struct passwd *pw, int nflag)
292*4b9cc932SThomas Cort {
293*4b9cc932SThomas Cort 	struct group *gr;
294*4b9cc932SThomas Cort 	int cnt, ngroups;
295*4b9cc932SThomas Cort 	gid_t id, lastid;
296*4b9cc932SThomas Cort 	const char *fmt;
297*4b9cc932SThomas Cort 	gid_t *glist = groups;
298*4b9cc932SThomas Cort 
299*4b9cc932SThomas Cort 	if (pw) {
300*4b9cc932SThomas Cort 		ngroups = maxgroups;
301*4b9cc932SThomas Cort 		if (getgrouplist(pw->pw_name, pw->pw_gid, glist, &ngroups)
302*4b9cc932SThomas Cort 		    == -1) {
303*4b9cc932SThomas Cort 			glist = malloc(ngroups * sizeof(gid_t));
304*4b9cc932SThomas Cort 			(void) getgrouplist(pw->pw_name, pw->pw_gid, glist,
305*4b9cc932SThomas Cort 					    &ngroups);
306*4b9cc932SThomas Cort 		}
307*4b9cc932SThomas Cort 	} else {
308*4b9cc932SThomas Cort 		glist[0] = getgid();
309*4b9cc932SThomas Cort 		ngroups = getgroups(maxgroups, glist + 1) + 1;
310*4b9cc932SThomas Cort 	}
311*4b9cc932SThomas Cort 	fmt = nflag ? "%s" : "%u";
312*4b9cc932SThomas Cort 	for (lastid = -1, cnt = 0; cnt < ngroups; ++cnt) {
313*4b9cc932SThomas Cort 		if (lastid == (id = glist[cnt]) || (cnt && id == glist[0]))
314*4b9cc932SThomas Cort 			continue;
315*4b9cc932SThomas Cort 		if (nflag) {
316*4b9cc932SThomas Cort 			if ((gr = getgrgid(id)) != NULL)
317*4b9cc932SThomas Cort 				(void)printf(fmt, gr->gr_name);
318*4b9cc932SThomas Cort 			else
319*4b9cc932SThomas Cort 				(void)printf(*fmt == ' ' ? " %u" : "%u",
320*4b9cc932SThomas Cort 				    id);
321*4b9cc932SThomas Cort 			fmt = " %s";
322*4b9cc932SThomas Cort 		} else {
323*4b9cc932SThomas Cort 			(void)printf(fmt, id);
324*4b9cc932SThomas Cort 			fmt = " %u";
325*4b9cc932SThomas Cort 		}
326*4b9cc932SThomas Cort 		lastid = id;
327*4b9cc932SThomas Cort 	}
328*4b9cc932SThomas Cort 	(void)printf("\n");
329*4b9cc932SThomas Cort 	if (glist != groups)
330*4b9cc932SThomas Cort 		free(glist);
331*4b9cc932SThomas Cort }
332*4b9cc932SThomas Cort 
333*4b9cc932SThomas Cort static struct passwd *
who(char * u)334*4b9cc932SThomas Cort who(char *u)
335*4b9cc932SThomas Cort {
336*4b9cc932SThomas Cort 	struct passwd *pw;
337*4b9cc932SThomas Cort 	long id;
338*4b9cc932SThomas Cort 	char *ep;
339*4b9cc932SThomas Cort 
340*4b9cc932SThomas Cort 	/*
341*4b9cc932SThomas Cort 	 * Translate user argument into a pw pointer.  First, try to
342*4b9cc932SThomas Cort 	 * get it as specified.  If that fails, try it as a number.
343*4b9cc932SThomas Cort 	 */
344*4b9cc932SThomas Cort 	if ((pw = getpwnam(u)) != NULL)
345*4b9cc932SThomas Cort 		return pw;
346*4b9cc932SThomas Cort 	id = strtol(u, &ep, 10);
347*4b9cc932SThomas Cort 	if (*u && !*ep && (pw = getpwuid(id)))
348*4b9cc932SThomas Cort 		return pw;
349*4b9cc932SThomas Cort 	errx(1, "%s: No such user", u);
350*4b9cc932SThomas Cort 	/* NOTREACHED */
351*4b9cc932SThomas Cort 	return NULL;
352*4b9cc932SThomas Cort }
353*4b9cc932SThomas Cort 
354*4b9cc932SThomas Cort static void
usage(void)355*4b9cc932SThomas Cort usage(void)
356*4b9cc932SThomas Cort {
357*4b9cc932SThomas Cort 
358*4b9cc932SThomas Cort 	if (strcmp(getprogname(), "groups") == 0) {
359*4b9cc932SThomas Cort 		(void)fprintf(stderr, "usage: groups [user]\n");
360*4b9cc932SThomas Cort 	} else if (strcmp(getprogname(), "whoami") == 0) {
361*4b9cc932SThomas Cort 		(void)fprintf(stderr, "usage: whoami\n");
362*4b9cc932SThomas Cort 	} else {
363*4b9cc932SThomas Cort 		(void)fprintf(stderr, "usage: id [user]\n");
364*4b9cc932SThomas Cort 		(void)fprintf(stderr, "       id -G [-n] [user]\n");
365*4b9cc932SThomas Cort 		(void)fprintf(stderr, "       id -g [-nr] [user]\n");
366*4b9cc932SThomas Cort 		(void)fprintf(stderr, "       id -p [user]\n");
367*4b9cc932SThomas Cort 		(void)fprintf(stderr, "       id -u [-nr] [user]\n");
368*4b9cc932SThomas Cort 	}
369*4b9cc932SThomas Cort 	exit(1);
370*4b9cc932SThomas Cort }
371