home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / misc / volume05 / whosin < prev    next >
Encoding:
Internet Message Format  |  1991-08-27  |  5.3 KB

  1. From decwrl!labrea!rutgers!mailrus!cwjcc!hal!ncoast!allbery Sun Oct 30 15:05:55 PST 1988
  2. Article 685 of comp.sources.misc:
  3. Path: granite!decwrl!labrea!rutgers!mailrus!cwjcc!hal!ncoast!allbery
  4. From: randy@uokmax.UUCP (Longshot)
  5. Newsgroups: comp.sources.misc
  6. Subject: v05i008: whosin - show groups members
  7. Message-ID: <12856@ncoast.UUCP>
  8. Date: 28 Oct 88 02:28:22 GMT
  9. Sender: allbery@ncoast.UUCP
  10. Reply-To: randy@uokmax.UUCP (Longshot)
  11. Organization: University of Oklahoma, Norman
  12. Lines: 158
  13. Approved: allbery@ncoast.UUCP
  14.  
  15. Posting-number: Volume 5, Issue 8
  16. Submitted-by: "Longshot" <randy@uokmax.UUCP>
  17. Archive-name: whosin
  18.  
  19. [Methinks this is a job for perl or awk, not C....  ++bsa]
  20.  
  21. A little program I wrote to display the members of specified groups. Should
  22. work on any UNIX with grp.h and group data in /etc/group.
  23.  
  24. Randy J. Ray
  25. ---- Cut Here and unpack ----
  26. #!/bin/sh
  27. # shar:    Shell Archiver  (v1.22)
  28. #    Packed Sun Oct 23 21:00:34 CDT 1988 by uokmax!randy
  29. #    from directory /uokmax/staff/randy/src/C
  30. #
  31. #    Run the following text with /bin/sh to create:
  32. #      README
  33. #      whosin.L
  34. #      whosin.c
  35. #
  36. if test -f README; then echo "File README exists"; else
  37. echo "x - extracting README (Text)"
  38. sed 's/^X//' << 'SHAR_EOF' > README &&
  39. XThis is a little program I tossed together because I occassionally wanted
  40. Xto know who all were included in a specific group. This is handy if you need
  41. Xto get in touch with someone who has specific access. It accepts as arguments
  42. Xgroup names or numbers as listed in the file /etc/group. It prints the name,
  43. Xnumber, and number of listed users for the group, followed by an alphabetized
  44. Xlist of usernames, printed 8 to a line. To create it, just type:
  45. X
  46. X    cc -O -o whosin whosin.c    # No need for a makefile
  47. X
  48. XAs /etc/group is world readable, and no writing is done, no special permissions
  49. Xare needed. Be warned, however. On our system, many student account groups are
  50. Xnot entered with complete listings, as they change from semester to semester.
  51. XRather, the group entry is made, and the user accounts bestowed with the
  52. Xnumber. In these cases, the group appears legal, but is reported with
  53. X"Users: 0" and no names following. This is not really a bug, since all the
  54. Xprogram does is read the file. But it is handy for smaller groups (like finding
  55. Xthe nearest person with root access, by typing "whosin wheel").
  56. X
  57. XRandy J. Ray
  58. X--
  59. XRandy J. Ray                   University of Oklahoma, Norman, Oklahoma
  60. Xrandy@uokmax.uucp            "...and he who made kittens put snakes
  61. XRJRAY@aardvark.ucs.uoknor.edu          in the grass..."  -Jethro Tull
  62. X-=*-=*-=*-=*-=*-=*-=*-=*-=*-=*-=*-=*-=*-=*-=*-=*-=*-=*-=*-=*-=*-=*-=*-=*-=*-=*-
  63. SHAR_EOF
  64. chmod 0644 README || echo "restore of README fails"
  65. set `wc -c README`;Sum=$1
  66. if test "$Sum" != "1384"
  67. then echo original size 1384, current size $Sum;fi
  68. fi
  69. if test -f whosin.L; then echo "File whosin.L exists"; else
  70. echo "x - extracting whosin.L (Text)"
  71. sed 's/^X//' << 'SHAR_EOF' > whosin.L &&
  72. X.TH WHOSIN L LOCAL
  73. X.SH NAME
  74. Xwhosin \- diplays users in specified groups
  75. X.SH SYNOPSIS
  76. Xwhosin [
  77. X.B name
  78. X|
  79. X.B number
  80. X] . . .
  81. X.SH DESCRIPTION
  82. X.B Whosin
  83. Xtakes a list of arguments being either names of active groups
  84. Xor groups numbers, and displays the users listed with that
  85. Xgroup in the file
  86. X.I /etc/group .
  87. X.SH FILES
  88. X/etc/group
  89. X.SH "SEE ALSO"
  90. Xgroups(1), gid(L), uid(L), id(L)
  91. X.SH BUGS
  92. XIf the group's entry in /etc/group is quite long (as is the case for
  93. Xgroups such as eecsugrad, the undergraduate accounts in EECS), all
  94. Xindividual names are not listed with the regular entry. In these cases,
  95. Xno names are listed, and number of users is reported as 0.
  96. X.SH AUTHOR
  97. XRandy J. Ray
  98. SHAR_EOF
  99. chmod 0644 whosin.L || echo "restore of whosin.L fails"
  100. set `wc -c whosin.L`;Sum=$1
  101. if test "$Sum" != "672"
  102. then echo original size 672, current size $Sum;fi
  103. fi
  104. if test -f whosin.c; then echo "File whosin.c exists"; else
  105. echo "x - extracting whosin.c (Text)"
  106. sed 's/^X//' << 'SHAR_EOF' > whosin.c &&
  107. X/*
  108. X    whosin - show the members of a specified group
  109. X*/
  110. X
  111. X/*
  112. X    $Header: whosin.c,v 1.2 88/10/19 19:50:14 randy Exp $
  113. X
  114. X    $Log:    whosin.c,v $
  115. X * Revision 1.2  88/10/19  19:50:14  randy
  116. X * Changed string.h header file to strings.h to increase portability.
  117. X * 
  118. X * Revision 1.1  88/10/17  14:35:51  randy
  119. X * Initial revision
  120. X * 
  121. X*/
  122. X
  123. X#include <stdio.h>
  124. X#include <grp.h>
  125. X#include <strings.h>
  126. X
  127. Xmain(argc,argv)
  128. Xint argc;
  129. Xchar **argv;
  130. X{
  131. X    int strkmp(),grnum,nnum;
  132. X    char **names,**argx,*grp;
  133. X    struct group *gr;
  134. X
  135. X    if (--argc == 0) {
  136. X        fprintf(stderr,"Usage: whosin [group name | group num] . . .\n");
  137. X        exit(1);
  138. X    }
  139. X    while (argc--) {
  140. X        grnum=atoi(*++argv);
  141. X        if ((grnum == 0) && (strcmp(*argv,"0"))) gr=getgrnam(*argv);
  142. X            else gr=getgrgid(grnum);
  143. X        if ((names=gr->gr_mem) == NULL) {
  144. X            fprintf(stderr,"Unknown group: %s\n",*argv);
  145. X            exit(1);
  146. X        }
  147. X        argx=names;
  148. X        nnum=0;
  149. X        while (*argx++) nnum++;
  150. X        qsort(names,nnum,(sizeof(char *)),strkmp);
  151. X        printf("\nGroup: %s\t\tId: %d\t\tUsers: %d\n",gr->gr_name,gr->gr_gid,nnum);
  152. X        grnum=0;
  153. X        while (grnum++ != nnum) {
  154. X            printf("%-9s",*names++);
  155. X            if ((grnum % 8) == 0) putchar('\n');
  156. X        }
  157. X        if ((nnum % 8) != 0) putchar('\n');
  158. X    }
  159. X}
  160. X
  161. Xint strkmp(s1,s2)
  162. Xchar **s1,**s2;
  163. X{
  164. X    return(strcmp(*s1,*s2));
  165. X}
  166. SHAR_EOF
  167. chmod 0444 whosin.c || echo "restore of whosin.c fails"
  168. set `wc -c whosin.c`;Sum=$1
  169. if test "$Sum" != "1220"
  170. then echo original size 1220, current size $Sum;fi
  171. fi
  172. exit 0
  173.  
  174.  
  175.