diff options
Diffstat (limited to 'usr.bin/groups/groups.c')
| -rw-r--r-- | usr.bin/groups/groups.c | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/usr.bin/groups/groups.c b/usr.bin/groups/groups.c index 6c1660575fcc..4ac8ae9a970b 100644 --- a/usr.bin/groups/groups.c +++ b/usr.bin/groups/groups.c @@ -46,33 +46,24 @@ static char sccsid[] = "@(#)groups.c 5.4 (Berkeley) 6/1/90"; */ #include <sys/param.h> +#include <unistd.h> #include <grp.h> #include <pwd.h> #include <stdio.h> -int groups[NGROUPS]; main(argc, argv) int argc; char *argv[]; { - int ngroups, i; - char *sep = ""; - struct group *gr; + register struct passwd *pw; if (argc > 1) showgroups(argv[1]); - ngroups = getgroups(NGROUPS, groups); - for (i = 0; i < ngroups; i++) { - gr = getgrgid(groups[i]); - if (gr == NULL) - printf("%s%d", sep, groups[i]); - else - printf("%s%s", sep, gr->gr_name); - sep = " "; - } - printf("\n"); - exit(0); + else if((pw = getpwuid(getuid())) != NULL) + showgroups(pw->pw_name); + fprintf(stderr, "groups: no such user.\n"); + exit(1); } showgroups(user) @@ -83,6 +74,10 @@ showgroups(user) register char **cp; char *sep = ""; + if (!user) { + fprintf(stderr, "groups: no user name.\n"); + exit(1); + } if ((pw = getpwnam(user)) == NULL) { fprintf(stderr, "groups: no such user.\n"); exit(1); |
