Index: src/usr.bin/id/id.1 =================================================================== RCS file: /home/ncvs/src/usr.bin/id/id.1,v retrieving revision 1.13 diff -u -r1.13 id.1 --- src/usr.bin/id/id.1 18 May 2004 20:36:54 -0000 1.13 +++ src/usr.bin/id/id.1 19 May 2004 06:57:23 -0000 @@ -43,23 +43,30 @@ .Nd return user identity .Sh SYNOPSIS .Nm +.Op Fl a .Op Ar user .Nm -.Fl G Op Fl n +.Fl G Op Fl an .Op Ar user .Nm .Fl M .Nm .Fl P +.Op Fl a .Op Ar user .Nm -.Fl g Op Fl nr +.Fl g +.Op Fl a | Fl r +.Op Fl n .Op Ar user .Nm .Fl p +.Op Fl a .Op Ar user .Nm -.Fl u Op Fl nr +.Fl u +.Op Fl a | Fl r +.Op Fl n .Op Ar user .Sh DESCRIPTION The @@ -84,6 +91,10 @@ Display the MAC label of the current prorcess. .It Fl P Display the id as a password file entry. +.It Fl a +Display information about all system users, not just about the calling process. +This flag cannot be used together with +.Fl r . .It Fl g Display the effective group ID as a number. .It Fl n @@ -122,6 +133,8 @@ and .Fl u options instead of the effective ID. +This flag cannot be used together with +.Fl a . .It Fl u Display the effective user ID as a number. .El Index: src/usr.bin/id/id.c =================================================================== RCS file: /home/ncvs/src/usr.bin/id/id.c,v retrieving revision 1.21 diff -u -r1.21 id.c --- src/usr.bin/id/id.c 19 May 2004 21:06:36 -0000 1.21 +++ src/usr.bin/id/id.c 20 May 2004 10:13:57 -0000 @@ -57,6 +57,9 @@ #include #include +int Gflag, Mflag, Pflag, aflag, gflag, nflag, pflag, rflag, uflag; + +int id_doit(struct passwd *); void current(void); void pline(struct passwd *); void pretty(struct passwd *); @@ -72,13 +75,10 @@ int main(int argc, char *argv[]) { - struct group *gr; struct passwd *pw; - int Gflag, Mflag, Pflag, ch, gflag, id, nflag, pflag, rflag, uflag; + int ch; const char *myname; - Gflag = Mflag = Pflag = gflag = nflag = pflag = rflag = uflag = 0; - myname = strrchr(argv[0], '/'); myname = (myname != NULL) ? myname + 1 : argv[0]; if (strcmp(myname, "groups") == 0) { @@ -91,7 +91,7 @@ } while ((ch = getopt(argc, argv, - (isgroups || iswhoami) ? "" : "PGMgnpru")) != -1) + (isgroups || iswhoami) ? "" : "PGMagnpru")) != -1) switch(ch) { case 'G': Gflag = 1; @@ -102,6 +102,9 @@ case 'P': Pflag = 1; break; + case 'a': + aflag = 1; + break; case 'g': gflag = 1; break; @@ -127,6 +130,9 @@ if (iswhoami && argc > 0) usage(); + if (aflag && (rflag || (argc != 0))) + usage(); + switch(Gflag + Pflag + gflag + pflag + uflag) { case 1: break; @@ -138,7 +144,22 @@ usage(); } - pw = *argv ? who(*argv) : NULL; + if (!aflag) { + pw = *argv ? who(*argv) : NULL; + id_doit(pw); + } else { + while ((pw = getpwent()) != NULL) + id_doit(pw); + } + return (0); +} + +int +id_doit(pw) + struct passwd *pw; +{ + struct group *gr; + int id; if (Mflag && pw != NULL) usage(); @@ -149,7 +170,7 @@ (void)printf("%s\n", gr->gr_name); else (void)printf("%u\n", id); - exit(0); + return (0); } if (uflag) { @@ -158,12 +179,12 @@ (void)printf("%s\n", pw->pw_name); else (void)printf("%u\n", id); - exit(0); + return (0); } if (Gflag) { group(pw, nflag); - exit(0); + return (0); } if (Mflag) { @@ -173,19 +194,19 @@ if (Pflag) { pline(pw); - exit(0); + return (0); } if (pflag) { pretty(pw); - exit(0); + return (0); } if (pw) user(pw); - else + else if (!aflag) current(); - exit(0); + return (0); } void @@ -297,7 +318,7 @@ } void -group(struct passwd *pw, int nflag) +group(struct passwd *pw, int name) { struct group *gr; int cnt, id, lastid, ngroups; @@ -311,11 +332,11 @@ groups[0] = getgid(); ngroups = getgroups(NGROUPS, groups + 1) + 1; } - fmt = nflag ? "%s" : "%u"; + fmt = name ? "%s" : "%u"; for (lastid = -1, cnt = 0; cnt < ngroups; ++cnt) { if (lastid == (id = groups[cnt])) continue; - if (nflag) { + if (name) { if ((gr = getgrgid(id))) (void)printf(fmt, gr->gr_name); else @@ -402,12 +423,12 @@ (void)fprintf(stderr, "usage: whoami\n"); else (void)fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n", - "usage: id [user]", - " id -G [-n] [user]", + "usage: id [-a] [user]", + " id -G [-an] [user]", " id -M", - " id -P [user]", - " id -g [-nr] [user]", - " id -p [user]", - " id -u [-nr] [user]"); + " id -P [-a] [user]", + " id -g [-a | -r] [-n] [user]", + " id -p [-a] [user]", + " id -u [-a | -r] [-n] [user]"); exit(1); }