1: /*
   2:  * Copyright (c) 1980 Regents of the University of California.
   3:  * All rights reserved.  The Berkeley software License Agreement
   4:  * specifies the terms and conditions for redistribution.
   5:  */
   6: 
   7: #ifndef lint
   8: char copyright[] =
   9: "@(#) Copyright (c) 1980 Regents of the University of California.\n\
  10:  All rights reserved.\n";
  11: #endif not lint
  12: 
  13: #ifndef lint
  14: static char sccsid[] = "@(#)groups.c	5.1 (Berkeley) 5/31/85";
  15: #endif not lint
  16: 
  17: /*
  18:  * groups
  19:  */
  20: 
  21: #include <sys/param.h>
  22: #include <grp.h>
  23: #include <pwd.h>
  24: #include <stdio.h>
  25: 
  26: int groups[NGROUPS];
  27: 
  28: main(argc, argv)
  29:     int argc;
  30:     char *argv[];
  31: {
  32:     int ngroups, i;
  33:     char *sep = "";
  34:     struct group *gr;
  35: 
  36:     if (argc > 1)
  37:         showgroups(argv[1]);
  38:     ngroups = getgroups(NGROUPS, groups);
  39:     for (i = 0; i < ngroups; i++) {
  40:         gr = getgrgid(groups[i]);
  41:         if (gr == NULL)
  42:             printf("%s%d", sep, groups[i]);
  43:         else
  44:             printf("%s%s", sep, gr->gr_name);
  45:         sep = " ";
  46:     }
  47:     printf("\n");
  48:     exit(0);
  49: }
  50: 
  51: showgroups(user)
  52:     register char *user;
  53: {
  54:     register struct group *gr;
  55:     register struct passwd *pw;
  56:     register char **cp;
  57:     char *sep = "";
  58: 
  59:     if ((pw = getpwnam(user)) == NULL) {
  60:         fprintf(stderr, "No such user\n");
  61:         exit(1);
  62:     }
  63:     while (gr = getgrent()) {
  64:         if (pw->pw_gid == gr->gr_gid) {
  65:             printf("%s%s", sep, gr->gr_name);
  66:             sep = " ";
  67:             continue;
  68:         }
  69:         for (cp = gr->gr_mem; cp && *cp; cp++)
  70:             if (strcmp(*cp, user) == 0) {
  71:                 printf("%s%s", sep, gr->gr_name);
  72:                 sep = " ";
  73:                 break;
  74:             }
  75:     }
  76:     printf("\n");
  77:     exit(0);
  78: }

Defined functions

main defined in line 28; never used
showgroups defined in line 51; used 1 times
  • in line 37

Defined variables

copyright defined in line 8; never used
groups defined in line 26; used 3 times
sccsid defined in line 14; never used
Last modified: 1985-05-31
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1119
Valid CSS Valid XHTML 1.0 Strict