dumb coding mistake, id -p wasn't calling group() correctly
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Tue, 12 Nov 1991 09:46:46 +0000 (01:46 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Tue, 12 Nov 1991 09:46:46 +0000 (01:46 -0800)
SCCS-vsn: usr.bin/id/id.c 5.5

usr/src/usr.bin/id/id.c

index 2c48ffc..18fa862 100644 (file)
@@ -12,7 +12,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)id.c       5.4 (Berkeley) %G%";
+static char sccsid[] = "@(#)id.c       5.5 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -126,9 +126,11 @@ pretty(pw)
        u_int eid, rid;
        char *login;
 
        u_int eid, rid;
        char *login;
 
-       if (pw)
+       if (pw) {
                (void)printf("uid\t%s\n", pw->pw_name);
                (void)printf("uid\t%s\n", pw->pw_name);
-       else {
+               (void)printf("groups\t");
+               group(pw, 1);
+       } else {
                if ((login = getlogin()) == NULL)
                        err("getlogin: %s", strerror(errno));
 
                if ((login = getlogin()) == NULL)
                        err("getlogin: %s", strerror(errno));
 
@@ -150,9 +152,9 @@ pretty(pw)
                                (void)printf("rgid\t%s\n", gr->gr_name);
                        else
                                (void)printf("rgid\t%u\n", rid);
                                (void)printf("rgid\t%s\n", gr->gr_name);
                        else
                                (void)printf("rgid\t%u\n", rid);
+               (void)printf("groups\t");
+               group(NULL, 1);
        }
        }
-       (void)printf("groups\t");
-       group(pw, 1);
 }
 
 void
 }
 
 void
@@ -228,7 +230,7 @@ group(pw, nflag)
        int nflag;
 {
        struct group *gr;
        int nflag;
 {
        struct group *gr;
-       int id, lastid, ngroups, groups[NGROUPS + 1];
+       int cnt, id, lastid, ngroups, groups[NGROUPS + 1];
        char *fmt, *name, **p;
 
        fmt = nflag ? "%s" : "%u";
        char *fmt, *name, **p;
 
        fmt = nflag ? "%s" : "%u";
@@ -250,8 +252,8 @@ group(pw, nflag)
        } else {
                groups[0] = getgid();
                ngroups = getgroups(NGROUPS, groups + 1) + 1;
        } else {
                groups[0] = getgid();
                ngroups = getgroups(NGROUPS, groups + 1) + 1;
-               for (lastid = -1; --ngroups >= 0;) {
-                       if (lastid == (id = groups[ngroups]))
+               for (lastid = -1, cnt = 0; cnt < ngroups; ++cnt) {
+                       if (lastid == (id = groups[cnt]))
                                continue;
                        if (nflag) {
                                if (gr = getgrgid(id))
                                continue;
                        if (nflag) {
                                if (gr = getgrgid(id))