home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3561 < prev    next >
Encoding:
Internet Message Format  |  1991-06-29  |  52.9 KB

  1. From: jfh@rpp386.cactus.org (John F Haugh II)
  2. Newsgroups: alt.sources
  3. Subject: Shadow login suite, patch 6
  4. Message-ID: <19411@rpp386.cactus.org>
  5. Date: 27 Jun 91 13:00:47 GMT
  6.  
  7. This is getting close to the end of the current beta test cycle, so you
  8. won't be seeing many more of these large patches.
  9.  
  10. There are three features to this patch.  The first is the continued
  11. introduction of the SVR4 user administration commands.  Earlier I posted
  12. the useradd, userdel and usermod clones.  This patch gives you the
  13. groupadd, groupdel and groupmod clones.  The second round of changes
  14. involves support code added to the libraries to perform deletions from
  15. the DBM files.  Finally there are a number of bug fixes of the more
  16. common "buggy code" variety.
  17.  
  18. There are two current patches in the pipeline.  The first ports the
  19. code to SunOS.  It was performed by Dr. Michael Newberry "down under",
  20. and I would like to welcome him to the group of people currently
  21. working on this project.  The second provides for run-time configuration
  22. of the programs [ as opposed to the current compile-time configuration ]
  23. and was performed by Chip Rosenthal, who has been involved with this
  24. project for several years now.  I don't know what the order will be
  25. for posting them.
  26. --
  27. Prereq: "3.0.5"
  28. Index: patchlevel.h
  29. *** rel3/patchlevel.h    Tue Jun 25 09:38:24 1991
  30. --- patchlevel.h    Wed Jun 26 09:43:23 1991
  31. ***************
  32. *** 10,14 ****
  33.    */
  34.   
  35.   #define    RELEASE        3
  36. ! #define    PATCHLEVEL    5
  37. ! #define    VERSION        "3.0.5"
  38. --- 10,14 ----
  39.    */
  40.   
  41.   #define    RELEASE        3
  42. ! #define    PATCHLEVEL    6
  43. ! #define    VERSION        "3.0.6"
  44. Index: Makefile
  45. *** rel3/Makefile    Tue Jun 25 09:38:24 1991
  46. --- Makefile    Wed Jun 26 09:43:26 1991
  47. ***************
  48. *** 8,16 ****
  49.   # and conspicuously displayed on all copies of object code or
  50.   # distribution media.
  51.   #
  52. ! #    @(#)Makefile    3.15    20:52:45  - Shadow password system
  53.   #
  54. ! #    @(#)Makefile    3.15    20:52:45    6/13/91
  55.   #
  56.   SHELL = /bin/sh
  57.   
  58. --- 8,16 ----
  59.   # and conspicuously displayed on all copies of object code or
  60.   # distribution media.
  61.   #
  62. ! #    @(#)Makefile    3.17    09:41:38  - Shadow password system
  63.   #
  64. ! #    @(#)Makefile    3.17    09:41:38    6/25/91
  65.   #
  66.   SHELL = /bin/sh
  67.   
  68. ***************
  69. *** 18,24 ****
  70.   # Set this flag to decide what level of code "get" returns.
  71.   # The base USENET release was release 1.  It is no longer supported.
  72.   # The version with the utilities added was release 2.
  73. ! # The unreleased version with database-like file access is release 3.
  74.   RELEASE = 3
  75.   GFLAGS = -t -r$(RELEASE)
  76.   
  77. --- 18,24 ----
  78.   # Set this flag to decide what level of code "get" returns.
  79.   # The base USENET release was release 1.  It is no longer supported.
  80.   # The version with the utilities added was release 2.
  81. ! # The version with database-like file access is release 3.
  82.   RELEASE = 3
  83.   GFLAGS = -t -r$(RELEASE)
  84.   
  85. ***************
  86. *** 141,150 ****
  87.       chfn.c chsh.c chage.c rad64.c encrypt.c chpasswd.c shadowio.c pwio.c \
  88.       newusers.c groupio.c fields.c pwdbm.c grpack.c grdbm.c sppack.c \
  89.       spdbm.c dpmain.c gshadow.c gsdbm.c gspack.c sgroupio.c useradd.c \
  90. !     userdel.c patchlevel.h usermod.c copydir.c mkrmdir.c
  91.   
  92. ! FILES1 = README newgrp.c Makefile config.h pwunconv.c obscure.c age.c id.c \
  93. !     patchlevel.h
  94.   
  95.   FILES2 = passwd.c port.c lmain.c mkpasswd.c sulogin.c pwpack.c dialup.c \
  96.       sulog.c getpass.c
  97. --- 141,151 ----
  98.       chfn.c chsh.c chage.c rad64.c encrypt.c chpasswd.c shadowio.c pwio.c \
  99.       newusers.c groupio.c fields.c pwdbm.c grpack.c grdbm.c sppack.c \
  100.       spdbm.c dpmain.c gshadow.c gsdbm.c gspack.c sgroupio.c useradd.c \
  101. !     userdel.c patchlevel.h usermod.c copydir.c mkrmdir.c groupadd.c \
  102. !     groupdel.c groupmod.c
  103.   
  104. ! FILES1 = README patchlevel.h newgrp.c Makefile config.h pwunconv.c obscure.c \
  105. !     age.c id.c
  106.   
  107.   FILES2 = passwd.c port.c lmain.c mkpasswd.c sulogin.c pwpack.c dialup.c \
  108.       sulog.c getpass.c
  109. ***************
  110. *** 164,169 ****
  111. --- 165,172 ----
  112.   
  113.   FILES8 = useradd.c userdel.c usermod.c copydir.c mkrmdir.c
  114.   
  115. + FILES9 = groupadd.c groupdel.c groupmod.c
  116.   MAN_1 = chage.1 chfn.1 chsh.1 login.1 passwd.1 su.1
  117.   MAN_3 = shadow.3
  118.   MAN_4 = faillog.4 passwd.4 porttime.4 shadow.4
  119. ***************
  120. *** 173,179 ****
  121.   
  122.   BINS = su login pwconv pwunconv passwd sulogin faillog newgrp gpasswd \
  123.       mkpasswd chfn chsh chage chpasswd newusers dpasswd id useradd \
  124. !     userdel usermod
  125.   
  126.   all:    $(BINS) $(DOCS)
  127.   
  128. --- 176,182 ----
  129.   
  130.   BINS = su login pwconv pwunconv passwd sulogin faillog newgrp gpasswd \
  131.       mkpasswd chfn chsh chage chpasswd newusers dpasswd id useradd \
  132. !     userdel usermod groupadd groupdel groupmod
  133.   
  134.   all:    $(BINS) $(DOCS)
  135.   
  136. ***************
  137. *** 209,229 ****
  138.   install: all
  139.       strip $(BINS)
  140.       cp login $(LOGINDIR)/login
  141. !     cp mkpasswd pwconv pwunconv sulogin chpasswd newusers /etc
  142. !     cp su passwd gpasswd dpasswd faillog newgrp chfn chsh id /bin
  143.       cp dialup.h shadow.h pwd.h /usr/include
  144.       chown $(RUID) $(LOGINDIR)/login /etc/pwconv /etc/pwunconv /etc/sulogin \
  145.           /bin/su /bin/passwd /bin/gpasswd /bin/newgrp /etc/mkpasswd \
  146. !         /bin/dpasswd /bin/chsh /bin/chfn /bin/chage
  147.       chgrp $(RGID) $(LOGINDIR)/login /etc/pwconv /etc/pwunconv /etc/sulogin \
  148.           /bin/su /bin/passwd /bin/gpasswd /bin/newgrp /etc/mkpasswd \
  149. !         /bin/dpasswd /bin/chsh /bin/chfn /bin/chage
  150.       chown $(BUID) /bin/faillog /bin/id /usr/include/shadow.h \
  151.           /usr/include/dialup.h /usr/include/pwd.h
  152.       chgrp $(BGID) /bin/faillog /bin/id /usr/include/shadow.h \
  153.           /usr/include/dialup.h /usr/include/pwd.h
  154.       chmod 700 /etc/pwconv /etc/pwunconv /etc/sulogin /etc/mkpasswd \
  155. !         /etc/chpasswd /etc/newusers /bin/dpasswd /bin/chage
  156.       chmod 4711 $(LOGINDIR)/login /bin/su /bin/passwd /bin/gpasswd \
  157.           /bin/newgrp /bin/chfn /bin/chsh
  158.       chmod 711 /bin/faillog /bin/id
  159. --- 212,239 ----
  160.   install: all
  161.       strip $(BINS)
  162.       cp login $(LOGINDIR)/login
  163. !     cp mkpasswd pwconv pwunconv sulogin chpasswd newusers \
  164. !         useradd userdel usermod groupadd groupdel groupmod /etc
  165. !     cp su passwd gpasswd dpasswd faillog newgrp chfn chsh chage id /bin
  166.       cp dialup.h shadow.h pwd.h /usr/include
  167.       chown $(RUID) $(LOGINDIR)/login /etc/pwconv /etc/pwunconv /etc/sulogin \
  168.           /bin/su /bin/passwd /bin/gpasswd /bin/newgrp /etc/mkpasswd \
  169. !         /bin/dpasswd /bin/chsh /bin/chfn /bin/chage /etc/useradd \
  170. !         /etc/userdel /etc/usermod /etc/groupadd /etc/groupdel \
  171. !         /etc/groupmod
  172.       chgrp $(RGID) $(LOGINDIR)/login /etc/pwconv /etc/pwunconv /etc/sulogin \
  173.           /bin/su /bin/passwd /bin/gpasswd /bin/newgrp /etc/mkpasswd \
  174. !         /bin/dpasswd /bin/chsh /bin/chfn /bin/chage /etc/useradd \
  175. !         /etc/userdel /etc/usermod /etc/groupadd /etc/groupdel \
  176. !         /etc/groupmod
  177.       chown $(BUID) /bin/faillog /bin/id /usr/include/shadow.h \
  178.           /usr/include/dialup.h /usr/include/pwd.h
  179.       chgrp $(BGID) /bin/faillog /bin/id /usr/include/shadow.h \
  180.           /usr/include/dialup.h /usr/include/pwd.h
  181.       chmod 700 /etc/pwconv /etc/pwunconv /etc/sulogin /etc/mkpasswd \
  182. !         /etc/chpasswd /etc/newusers /bin/dpasswd /bin/chage \
  183. !         /etc/useradd /etc/userdel /etc/usermod /etc/groupadd \
  184. !         /etc/groupdel /etc/groupmod
  185.       chmod 4711 $(LOGINDIR)/login /bin/su /bin/passwd /bin/gpasswd \
  186.           /bin/newgrp /bin/chfn /bin/chsh
  187.       chmod 711 /bin/faillog /bin/id
  188. ***************
  189. *** 233,248 ****
  190.   lint:    su.lint login.lint pwconv.lint pwunconv.lint passwd.lint sulogin.lint \
  191.       faillog.lint newgrp.lint gpasswd.lint mkpasswd.lint chfn.lint \
  192.       chsh.lint chage.lint dpasswd.lint id.lint useradd.lint userdel.lint \
  193. !     usermod.lint $(ALLSRCS:.c=.L)
  194.   
  195.   tags:    $(ALLSRCS)
  196.       $(TAGS) $(ALLSRCS)
  197.   
  198. ! README:    s.README
  199. !     get -t -r$(RELEASE) s.README
  200.       
  201.   $(DOCS):
  202. !     get -t -r$(RELEASE) s.$@
  203.   
  204.   login:    $(LOBJS) libshadow.a
  205.       $(CC) -o login $(LDFLAGS) $(LOBJS) libshadow.a $(LIBS)
  206. --- 243,258 ----
  207.   lint:    su.lint login.lint pwconv.lint pwunconv.lint passwd.lint sulogin.lint \
  208.       faillog.lint newgrp.lint gpasswd.lint mkpasswd.lint chfn.lint \
  209.       chsh.lint chage.lint dpasswd.lint id.lint useradd.lint userdel.lint \
  210. !     usermod.lint groupadd.lint groupdel.lint groupmod.lint $(ALLSRCS:.c=.L)
  211.   
  212.   tags:    $(ALLSRCS)
  213.       $(TAGS) $(ALLSRCS)
  214.   
  215. ! README:
  216. !     [ -f s.README ] && get -t -r$(RELEASE) s.README
  217.       
  218.   $(DOCS):
  219. !     [ -f s.$@ ] && get -t -r$(RELEASE) s.$@
  220.   
  221.   login:    $(LOBJS) libshadow.a
  222.       $(CC) -o login $(LDFLAGS) $(LOBJS) libshadow.a $(LIBS)
  223. ***************
  224. *** 367,372 ****
  225. --- 377,400 ----
  226.   usermod.lint: usermod.c copydir.c mkrmdir.c
  227.       $(LINT) $(LINTFLAGS) usermod.c copydir.c mkrmdir.c > usermod.lint
  228.   
  229. + groupadd: groupadd.o libshadow.a
  230. +     $(CC) -o groupadd $(LDFLAGS) groupadd.o libshadow.a $(LIBS)
  231. + groupadd.lint: groupadd.c
  232. +     $(LINT) $(LINTFLAGS) groupadd.c > groupadd.lint
  233. + groupdel: groupdel.o libshadow.a
  234. +     $(CC) -o groupdel $(LDFLAGS) groupdel.o libshadow.a $(LIBS)
  235. + groupdel.lint: groupdel.c
  236. +     $(LINT) $(LINTFLAGS) groupdel.c > groupdel.lint
  237. + groupmod: groupmod.o libshadow.a
  238. +     $(CC) -o groupmod $(LDFLAGS) groupmod.o libshadow.a $(LIBS)
  239. + groupmod.lint: groupmod.c
  240. +     $(LINT) $(LINTFLAGS) groupmod.c > groupmod.lint
  241.   sulog.o: config.h
  242.   
  243.   susetup.c: setup.c
  244. ***************
  245. *** 437,442 ****
  246. --- 465,474 ----
  247.   dpmain.o: dialup.h
  248.   useradd.o: config.h shadow.h pwd.h
  249.   userdel.o: config.h shadow.h pwd.h
  250. + usermod.o: config.h shadow.h pwd.h
  251. + groupadd.o: config.h shadow.h
  252. + groupdel.o: config.h shadow.h
  253. + groupmod.o: config.h shadow.h
  254.   
  255.   clean:
  256.       -rm -f *.o a.out core npasswd nshadow *.pag *.dir
  257. ***************
  258. *** 451,483 ****
  259.           fi ;\
  260.       done
  261.   
  262. ! shar:    login.sh.1 login.sh.2 login.sh.3 login.sh.4 login.sh.5 login.sh.6 \
  263. !     login.sh.7 login.sh.8 login.sh.9
  264. ! login.sh.1: $(FILES1) Makefile
  265. !     shar -a $(FILES1) > login.sh.1
  266. ! login.sh.2: $(FILES2) Makefile
  267. !     shar -a $(FILES2) > login.sh.2
  268. ! login.sh.3: $(FILES3) Makefile
  269. !     shar -a $(FILES3) > login.sh.3
  270. ! login.sh.4: $(FILES4) Makefile
  271. !     shar -a $(FILES4) > login.sh.4
  272. ! login.sh.5: $(FILES5) Makefile
  273. !     shar -a $(FILES5) > login.sh.5
  274. ! login.sh.6: $(FILES6) Makefile
  275. !     shar -a $(FILES6) > login.sh.6
  276. ! login.sh.7: $(FILES7) Makefile
  277. !     shar -a $(FILES7) > login.sh.7
  278. ! login.sh.8: $(FILES8) Makefile
  279. !     shar -a $(FILES8) > login.sh.8
  280.   
  281. ! login.sh.9: $(DOCS) Makefile
  282. !     shar -a $(DOCS) > login.sh.9
  283.   
  284. --- 483,517 ----
  285.           fi ;\
  286.       done
  287.   
  288. ! shar:    login.sh.01 login.sh.02 login.sh.03 login.sh.04 login.sh.05 \
  289. !     login.sh.06 login.sh.07 login.sh.08 login.sh.09 login.sh.10
  290.   
  291. ! login.sh.01: $(FILES1) Makefile
  292. !     shar -a $(FILES1) > login.sh.01
  293. ! login.sh.02: $(FILES2) Makefile
  294. !     shar -a $(FILES2) > login.sh.02
  295. ! login.sh.03: $(FILES3) Makefile
  296. !     shar -a $(FILES3) > login.sh.03
  297. ! login.sh.04: $(FILES4) Makefile
  298. !     shar -a $(FILES4) > login.sh.04
  299. ! login.sh.05: $(FILES5) Makefile
  300. !     shar -a $(FILES5) > login.sh.05
  301. ! login.sh.06: $(FILES6) Makefile
  302. !     shar -a $(FILES6) > login.sh.06
  303. ! login.sh.07: $(FILES7) Makefile
  304. !     shar -a $(FILES7) > login.sh.07
  305. ! login.sh.08: $(FILES8) Makefile
  306. !     shar -a $(FILES8) > login.sh.08
  307. ! login.sh.09: $(FILES9) Makefile
  308. !     shar -a $(FILES9) > login.sh.09
  309.   
  310. + login.sh.10: $(DOCS) Makefile
  311. +     shar -a $(DOCS) > login.sh.10
  312. Index: grdbm.c
  313. *** rel3/grdbm.c    Tue Jun 25 09:35:40 1991
  314. --- grdbm.c    Wed Jun 26 09:43:28 1991
  315. ***************
  316. *** 7,13 ****
  317.    */
  318.   
  319.   #ifndef    lint
  320. ! static    char    sccsid[] = "@(#)grdbm.c    3.1    08:11:52    11/21/90";
  321.   #endif
  322.   
  323.   #include <string.h>
  324. --- 7,13 ----
  325.    */
  326.   
  327.   #ifndef    lint
  328. ! static    char    sccsid[] = "@(#)grdbm.c    3.2    22:53:58    6/13/91";
  329.   #endif
  330.   
  331.   #include <string.h>
  332. ***************
  333. *** 104,108 ****
  334. --- 104,187 ----
  335.           }
  336.       }
  337.       return 1;
  338. + }
  339. + /*
  340. +  * gr_dbm_remove
  341. +  *
  342. +  * Deletes the DBM group file entries, if they exist.
  343. +  */
  344. + int
  345. + gr_dbm_remove (gr)
  346. + struct    group    *gr;
  347. + {
  348. +     datum    key;
  349. +     datum    content;
  350. +     char    data[BUFSIZ*8];
  351. +     char    grpkey[60];
  352. +     char    *cp;
  353. +     int    len;
  354. +     int    i;
  355. +     int    cnt;
  356. +     int    errors = 0;
  357. +     static    int    once;
  358. +     if (! once) {
  359. +         if (! gr_dbm)
  360. +             setgrent ();
  361. +         once++;
  362. +     }
  363. +     if (! gr_dbm)
  364. +         return 0;
  365. +     key.dsize = strlen (gr->gr_name);
  366. +     key.dptr = gr->gr_name;
  367. +     content = dbm_fetch (gr_dbm, key);
  368. +     if (content.dptr == 0)
  369. +         ++errors;
  370. +     else {
  371. +         if (content.dsize == sizeof (int)) {
  372. +             memcpy (&cnt, content.dptr, sizeof cnt);
  373. +             for (i = 0;i < cnt;i++) {
  374. +                 key.dsize = sizeof i + strlen (gr->gr_name);
  375. +                 key.dptr = grpkey;
  376. +                 memcpy (grpkey, &i, sizeof i);
  377. +                 strcpy (grpkey + sizeof i, gr->gr_name);
  378. +                 if (dbm_delete (gr_dbm, key))
  379. +                     ++errors;
  380. +             }
  381. +         } else {
  382. +             if (dbm_delete (gr_dbm, key))
  383. +                 ++errors;
  384. +         }
  385. +     }
  386. +     key.dsize = sizeof gr->gr_gid;
  387. +     key.dptr = &gr->gr_gid;
  388. +     content = dbm_fetch (gr_dbm, key);
  389. +     if (content.dptr == 0)
  390. +         ++errors;
  391. +     else {
  392. +         if (content.dsize == sizeof (int)) {
  393. +             memcpy (&cnt, content.dptr, sizeof cnt);
  394. +             for (i = 0;i < cnt;i++) {
  395. +                 key.dsize = sizeof i + sizeof gr->gr_gid;
  396. +                 key.dptr = grpkey;
  397. +                 memcpy (grpkey, &i, sizeof i);
  398. +                 memcpy (grpkey + sizeof i,
  399. +                     &gr->gr_gid, sizeof gr->gr_gid);
  400. +                 if (dbm_delete (gr_dbm, key))
  401. +                     ++errors;
  402. +             }
  403. +         } else {
  404. +             if (dbm_delete (gr_dbm, key))
  405. +                 ++errors;
  406. +         }
  407. +     }
  408. +     return errors ? 0:1;
  409.   }
  410.   #endif
  411. Index: gsdbm.c
  412. *** rel3/gsdbm.c    Tue Jun 25 09:35:52 1991
  413. --- gsdbm.c    Wed Jun 26 09:43:29 1991
  414. ***************
  415. *** 10,16 ****
  416.    */
  417.   
  418.   #ifndef    lint
  419. ! static    char    sccsid[] = "@(#)gsdbm.c    3.3    11:25:29    12/19/90";
  420.   #endif
  421.   
  422.   #include <string.h>
  423. --- 10,16 ----
  424.    */
  425.   
  426.   #ifndef    lint
  427. ! static    char    sccsid[] = "@(#)gsdbm.c    3.4    22:55:17    6/13/91";
  428.   #endif
  429.   
  430.   #include <string.h>
  431. ***************
  432. *** 88,92 ****
  433. --- 88,145 ----
  434.           }
  435.       }
  436.       return 1;
  437. + }
  438. + /*
  439. +  * sgr_dbm_remove
  440. +  *
  441. +  * Deletes the DBM shadow group file entries, if they exist.
  442. +  */
  443. + int
  444. + sgr_dbm_remove (name)
  445. + char    *name;
  446. + {
  447. +     datum    key;
  448. +     datum    content;
  449. +     char    grpkey[60];
  450. +     char    *cp;
  451. +     int    i;
  452. +     int    cnt;
  453. +     int    errors = 0;
  454. +     static    int    once;
  455. +     if (! once) {
  456. +         if (! sgr_dbm)
  457. +             setsgent ();
  458. +         once++;
  459. +     }
  460. +     if (! sgr_dbm)
  461. +         return 0;
  462. +     key.dsize = strlen (name);
  463. +     key.dptr = name;
  464. +     content = dbm_fetch (sgr_dbm, key);
  465. +     if (content.dptr == 0)
  466. +         ++errors;
  467. +     else {
  468. +         if (content.dsize == sizeof (int)) {
  469. +             memcpy (&cnt, content.dptr, sizeof cnt);
  470. +             for (i = 0;i < cnt;i++) {
  471. +                 key.dsize = sizeof i + strlen (name);
  472. +                 key.dptr = grpkey;
  473. +                 memcpy (grpkey, &i, sizeof i);
  474. +                 strcpy (grpkey + sizeof i, name);
  475. +                 if (dbm_delete (sgr_dbm, key))
  476. +                     ++errors;
  477. +             }
  478. +         } else {
  479. +             if (dbm_delete (sgr_dbm, key))
  480. +                 ++errors;
  481. +         }
  482. +     }
  483. +     return errors ? 0:1;
  484.   }
  485.   #endif
  486. Index: gshadow.c
  487. *** rel3/gshadow.c    Tue Jun 25 09:38:10 1991
  488. --- gshadow.c    Wed Jun 26 09:43:30 1991
  489. ***************
  490. *** 32,38 ****
  491.   
  492.   
  493.   #ifndef    lint
  494. ! static    char    sccsid[] = "@(#)gshadow.c    3.4    07:31:22    6/6/91";
  495.   #endif
  496.   
  497.   #define    MAXMEM    1024
  498. --- 32,38 ----
  499.   
  500.   
  501.   #ifndef    lint
  502. ! static    char    sccsid[] = "@(#)gshadow.c    3.5    22:56:08    6/13/91";
  503.   #endif
  504.   
  505.   #define    MAXMEM    1024
  506. ***************
  507. *** 136,147 ****
  508.       if (cp = strrchr (sgrbuf, '\n'))
  509.           *cp = '\0';
  510.   
  511. !     for (cp = sgrbuf, i = 0;*cp && i < FIELDS;i++) {
  512.           fields[i] = cp;
  513. !         while (*cp && *cp != ':')
  514. !             cp++;
  515. !         if (*cp)
  516.               *cp++ = '\0';
  517.       }
  518.       if (*cp || i != FIELDS)
  519. --- 136,144 ----
  520.       if (cp = strrchr (sgrbuf, '\n'))
  521.           *cp = '\0';
  522.   
  523. !     for (cp = sgrbuf, i = 0;i < FIELDS && cp;i++) {
  524.           fields[i] = cp;
  525. !         if (cp = strchr (cp, ':'))
  526.               *cp++ = '\0';
  527.       }
  528.       if (*cp || i != FIELDS)
  529. *** /dev/null    Wed Jun 26 09:26:31 1991
  530. --- groupadd.c    Wed Jun 26 09:43:32 1991
  531. ***************
  532. *** 0 ****
  533. --- 1,390 ----
  534. + /*
  535. +  * Copyright 1991, John F. Haugh II
  536. +  * All rights reserved.
  537. +  *
  538. +  * Permission is granted to copy and create derivative works for any
  539. +  * non-commercial purpose, provided this copyright notice is preserved
  540. +  * in all copies of source code, or included in human readable form
  541. +  * and conspicuously displayed on all copies of object code or
  542. +  * distribution media.
  543. +  */
  544. + #ifndef lint
  545. + static    char    sccsid[] = "@(#)groupadd.c    3.1    22:59:04    6/13/91";
  546. + #endif
  547. + #include <sys/types.h>
  548. + #include <stdio.h>
  549. + #include <grp.h>
  550. + #include <ctype.h>
  551. + #include <fcntl.h>
  552. + #ifdef    BSD
  553. + #include <strings.h>
  554. + #else
  555. + #include <string.h>
  556. + #endif
  557. + #include "config.h"
  558. + #include "shadow.h"
  559. + #ifdef    USE_SYSLOG
  560. + #include <syslog.h>
  561. + #endif
  562. + char    group_name[BUFSIZ];
  563. + int    group_id;
  564. + char    *Prog;
  565. + int    oflg;    /* permit non-unique group ID to be specified with -g         */
  566. + int    gflg;    /* ID value for the new group                                 */
  567. + #ifdef    NDBM
  568. + extern    int    gr_dbm_mode;
  569. + extern    int    sg_dbm_mode;
  570. + #endif
  571. + extern    char    *malloc();
  572. + extern    struct    group    *getgrnam();
  573. + extern    struct    group    *gr_next();
  574. + extern    int    gr_lock();
  575. + extern    int    gr_unlock();
  576. + extern    int    gr_rewind();
  577. + extern    int    gr_open();
  578. + #ifdef    SHADOWGRP
  579. + extern    int    sgr_lock();
  580. + extern    int    sgr_unlock();
  581. + extern    int    sgr_open();
  582. + #endif
  583. + /*
  584. +  * usage - display usage message and exit
  585. +  */
  586. + usage ()
  587. + {
  588. +     fprintf (stderr, "usage: groupadd [-g gid [-o]] group\n");
  589. +     exit (2);
  590. + }
  591. + /*
  592. +  * new_grent - initialize the values in a group file entry
  593. +  *
  594. +  *    new_grent() takes all of the values that have been entered and
  595. +  *    fills in a (struct group) with them.
  596. +  */
  597. + void
  598. + new_grent (grent)
  599. + struct    group    *grent;
  600. + {
  601. +     static    char    *empty_list = 0;
  602. +     memset (grent, 0, sizeof *grent);
  603. +     grent->gr_name = group_name;
  604. +     grent->gr_passwd = "*";
  605. +     grent->gr_gid = group_id;
  606. +     grent->gr_mem = &empty_list;
  607. + }
  608. + #ifdef    SHADOWGRP
  609. + /*
  610. +  * new_sgent - initialize the values in a shadow group file entry
  611. +  *
  612. +  *    new_sgent() takes all of the values that have been entered and
  613. +  *    fills in a (struct sgrp) with them.
  614. +  */
  615. + void
  616. + new_sgent (sgent)
  617. + struct    sgrp    *sgent;
  618. + {
  619. +     static    char    *empty_list = 0;
  620. +     memset (sgent, 0, sizeof *sgent);
  621. +     sgent->sg_name = group_name;
  622. +     sgent->sg_passwd = "!";
  623. +     sgent->sg_adm = &empty_list;
  624. +     sgent->sg_mem = &empty_list;
  625. + }
  626. + #endif    /* SHADOWGRP */
  627. + /*
  628. +  * grp_update - add new group file entries
  629. +  *
  630. +  *    grp_update() writes the new records to the group files.
  631. +  */
  632. + void
  633. + grp_update ()
  634. + {
  635. +     int    i;
  636. +     struct    group    grp;
  637. + #ifdef    SHADOWGRP
  638. +     struct    sgrp    sgrp;
  639. + #endif    /* SHADOWGRP */
  640. +     /*
  641. +      * Create the initial entries for this new group.
  642. +      */
  643. +     new_grent (&grp);
  644. + #ifdef    SHADOWGRP
  645. +     new_sgent (&sgrp);
  646. + #endif    /* SHADOWGRP */
  647. +     /*
  648. +      * Write out the new group file entry.
  649. +      */
  650. +     if (! gr_update (&grp)) {
  651. +         fprintf (stderr, "%s: error adding new group entry\n", Prog);
  652. +         exit (1);
  653. +     }
  654. + #ifdef    NDBM
  655. +     /*
  656. +      * Update the DBM group file with the new entry as well.
  657. +      */
  658. +     if (! gr_dbm_update (&grp)) {
  659. +         fprintf (stderr, "%s: cannot add new dbm group entry\n", Prog);
  660. +         exit (1);
  661. +     }
  662. + #endif    /* NDBM */
  663. + #ifdef    SHADOWGRP
  664. +     /*
  665. +      * Write out the new shadow group entries as well.
  666. +      */
  667. +     if (! sgr_update (&sgrp)) {
  668. +         fprintf (stderr, "%s: error adding new group entry\n", Prog);
  669. +         exit (1);
  670. +     }
  671. + #ifdef    NDBM
  672. +     /*
  673. +      * Update the DBM group file with the new entry as well.
  674. +      */
  675. +     if (! sgr_dbm_update (&sgrp)) {
  676. +         fprintf (stderr, "%s: cannot add new dbm group entry\n", Prog);
  677. +         exit (1);
  678. +     }
  679. + #endif    /* NDBM */
  680. + #endif    /* SHADOWGRP */
  681. + #ifdef    USE_SYSLOG
  682. +     syslog (LOG_INFO, "new group: name=%s, gid=%d\n",
  683. +         group_name, group_id);
  684. + #endif    /* USE_SYSLOG */
  685. + }
  686. + /*
  687. +  * find_new_gid - find the next available GID
  688. +  *
  689. +  *    find_new_gid() locates the next highest unused GID in the group
  690. +  *    file, or checks the given group ID against the existing ones for
  691. +  *    uniqueness.
  692. +  */
  693. + int
  694. + find_new_gid ()
  695. + {
  696. +     struct    group    *grp;
  697. +     /*
  698. +      * Start with some GID value if the user didn't provide us with
  699. +      * one already.
  700. +      */
  701. +     if (! gflg)
  702. +         group_id = 100;
  703. +     /*
  704. +      * Search the entire group file, either looking for this
  705. +      * GID (if the user specified one with -g) or looking for the
  706. +      * largest unused value.
  707. +      */
  708. +     for (gr_rewind (), grp = gr_next ();grp;grp = gr_next ()) {
  709. +         if (strcmp (group_name, grp->gr_name) == 0) {
  710. +             fprintf (stderr, "%s: name %s is not unique\n",
  711. +                 Prog, group_name);
  712. +             exit (1);
  713. +         }
  714. +         if (gflg && group_id == grp->gr_gid) {
  715. +             fprintf (stderr, "%s: gid %d is not unique\n",
  716. +                 Prog, group_id);
  717. +             exit (1);
  718. +         }
  719. +         if (! gflg && grp->gr_gid >= group_id)
  720. +             group_id = grp->gr_gid + 1;
  721. +     }
  722. + }
  723. + /*
  724. +  * process_flags - perform command line argument setting
  725. +  *
  726. +  *    process_flags() interprets the command line arguments and sets
  727. +  *    the values that the user will be created with accordingly.  The
  728. +  *    values are checked for sanity.
  729. +  */
  730. + void
  731. + process_flags (argc, argv)
  732. + int    argc;
  733. + char    **argv;
  734. + {
  735. +     extern    int    optind;
  736. +     extern    char    *optarg;
  737. +     struct    group    *grp;
  738. +     char    *end;
  739. +     int    anyflag = 0;
  740. +     int    arg;
  741. +     while ((arg = getopt (argc, argv, "og:")) != EOF) {
  742. +         switch (arg) {
  743. +             case 'g':
  744. +                 gflg++;
  745. +                 if (! isdigit (optarg[0]))
  746. +                     usage ();
  747. +                 group_id = strtol (optarg, &end, 10);
  748. +                 if (*end != '\0') {
  749. +                     fprintf (stderr, "%s: invalid group %s\n",
  750. +                         Prog, optarg);
  751. +                     exit (3);
  752. +                 }
  753. +                 break;
  754. +             case 'o':
  755. +                 if (! gflg)
  756. +                     usage ();
  757. +                 oflg++;
  758. +                 break;
  759. +             default:
  760. +                 usage ();
  761. +         }
  762. +         anyflag++;
  763. +     }
  764. +     if (optind == argc - 1)
  765. +         strcpy (group_name, argv[argc - 1]);
  766. +     else
  767. +         usage ();
  768. + }
  769. + /*
  770. +  * close_files - close all of the files that were opened
  771. +  *
  772. +  *    close_files() closes all of the files that were opened for this
  773. +  *    new group.  This causes any modified entries to be written out.
  774. +  */
  775. + close_files ()
  776. + {
  777. +     if (! gr_close ()) {
  778. +         fprintf (stderr, "%s: cannot rewrite group file\n", Prog);
  779. +         exit (1);
  780. +     }
  781. +     (void) gr_unlock ();
  782. + #ifdef    SHADOWGRP
  783. +     if (! sgr_close ()) {
  784. +         fprintf (stderr, "%s: cannot rewrite shadow group file\n",
  785. +             Prog);
  786. +         exit (1);
  787. +     }
  788. +     (void) sgr_unlock ();
  789. + #endif    /* SHADOWGRP */
  790. + }
  791. + /*
  792. +  * open_files - lock and open the group files
  793. +  *
  794. +  *    open_files() opens the two group files.
  795. +  */
  796. + open_files ()
  797. + {
  798. +     if (! gr_lock ()) {
  799. +         fprintf (stderr, "%s: unable to lock group file\n", Prog);
  800. +         exit (1);
  801. +     }
  802. +     if (! gr_open (O_RDWR)) {
  803. +         fprintf (stderr, "%s: unable to open group file\n", Prog);
  804. +         exit (1);
  805. +     }
  806. + #ifdef    SHADOWGRP
  807. +     if (! sgr_lock ()) {
  808. +         fprintf (stderr, "%s: unable to lock shadow group file\n",
  809. +             Prog);
  810. +         exit (1);
  811. +     }
  812. +     if (! sgr_open (O_RDWR)) {
  813. +         fprintf (stderr, "%s: unable to open shadow group file\n",
  814. +             Prog);
  815. +         exit (1);
  816. +     }
  817. + #endif    /* SHADOWGRP */
  818. + }
  819. + /*
  820. +  * main - useradd command
  821. +  */
  822. + main (argc, argv)
  823. + int    argc;
  824. + char    **argv;
  825. + {
  826. +     /*
  827. +      * Get my name so that I can use it to report errors.
  828. +      */
  829. +     if (Prog = strrchr (argv[0], '/'))
  830. +         Prog++;
  831. +     else
  832. +         Prog = argv[0];
  833. + #ifdef    USE_SYSLOG
  834. +     openlog (Prog, LOG_PID|LOG_CONS|LOG_NOWAIT, LOG_AUTH);
  835. + #endif    /* USE_SYSLOG */
  836. +     /*
  837. +      * The open routines for the DBM files don't use read-write
  838. +      * as the mode, so we have to clue them in.
  839. +      */
  840. + #ifdef    NDBM
  841. +     gr_dbm_mode = O_RDWR;
  842. + #ifdef    SHADOWGRP
  843. +     sg_dbm_mode = O_RDWR;
  844. + #endif    /* SHADOWGRP */
  845. + #endif    /* NDBM */
  846. +     process_flags (argc, argv);
  847. +     /*
  848. +      * Start with a quick check to see if the group exists.
  849. +      */
  850. +     if (getgrnam (group_name)) {
  851. +         fprintf (stderr, "%s: group %s exists\n", Prog, group_name);
  852. +         exit (9);
  853. +     }
  854. +     /*
  855. +      * Do the hard stuff - open the files, create the group entries,
  856. +      * then close and update the files.
  857. +      */
  858. +     open_files ();
  859. +     grp_update ();
  860. +     close_files ();
  861. +     exit (0);
  862. +     /*NOTREACHED*/
  863. + }
  864. *** /dev/null    Wed Jun 26 09:26:31 1991
  865. --- groupdel.c    Wed Jun 26 09:43:33 1991
  866. ***************
  867. *** 0 ****
  868. --- 1,254 ----
  869. + /*
  870. +  * Copyright 1991, John F. Haugh II
  871. +  * All rights reserved.
  872. +  *
  873. +  * Permission is granted to copy and create derivative works for any
  874. +  * non-commercial purpose, provided this copyright notice is preserved
  875. +  * in all copies of source code, or included in human readable form
  876. +  * and conspicuously displayed on all copies of object code or
  877. +  * distribution media.
  878. +  */
  879. + #ifndef lint
  880. + static    char    sccsid[] = "@(#)groupdel.c    3.1    22:59:09    6/13/91";
  881. + #endif
  882. + #include <sys/types.h>
  883. + #include <stdio.h>
  884. + #include <grp.h>
  885. + #include <ctype.h>
  886. + #include <fcntl.h>
  887. + #ifdef    BSD
  888. + #include <strings.h>
  889. + #else
  890. + #include <string.h>
  891. + #endif
  892. + #include "config.h"
  893. + #include "shadow.h"
  894. + #ifdef    USE_SYSLOG
  895. + #include <syslog.h>
  896. + #endif
  897. + char    group_name[BUFSIZ];
  898. + char    *Prog;
  899. + #ifdef    NDBM
  900. + extern    int    gr_dbm_mode;
  901. + extern    int    sg_dbm_mode;
  902. + #endif
  903. + extern    char    *malloc();
  904. + extern    struct    group    *getgrnam();
  905. + extern    struct    group    *gr_next();
  906. + extern    struct    group    *gr_locate();
  907. + extern    int    gr_lock();
  908. + extern    int    gr_unlock();
  909. + extern    int    gr_rewind();
  910. + extern    int    gr_open();
  911. + #ifdef    SHADOWGRP
  912. + extern    struct    sgrp    *sgr_locate();
  913. + extern    int    sgr_lock();
  914. + extern    int    sgr_unlock();
  915. + extern    int    sgr_open();
  916. + #endif
  917. + /*
  918. +  * usage - display usage message and exit
  919. +  */
  920. + usage ()
  921. + {
  922. +     fprintf (stderr, "usage: groupmod group\n");
  923. +     exit (2);
  924. + }
  925. + /*
  926. +  * grp_update - update group file entries
  927. +  *
  928. +  *    grp_update() writes the new records to the group files.
  929. +  */
  930. + void
  931. + grp_update ()
  932. + {
  933. +     int    i;
  934. +     struct    group    *ogrp;
  935. +     if (! gr_remove (group_name)) {
  936. +         fprintf (stderr, "%s: error removing group entry\n", Prog);
  937. +         exit (1);
  938. +     }
  939. + #ifdef    NDBM
  940. +     /*
  941. +      * Update the DBM group file
  942. +      */
  943. +     if (access ("/etc/group.pag", 0) == 0) {
  944. +         if ((ogrp = getgrnam (group_name)) &&
  945. +                 ! gr_dbm_remove (ogrp)) {
  946. +             fprintf (stderr, "%s: error removing group dbm entry\n",
  947. +                 Prog);
  948. +             exit (1);
  949. +         }
  950. +     }
  951. + #endif    /* NDBM */
  952. + #ifdef    SHADOWGRP
  953. +     /*
  954. +      * Delete the shadow group entries as well.
  955. +      */
  956. +     if (! sgr_remove (group_name)) {
  957. +         fprintf (stderr, "%s: error removing shadow group entry\n",
  958. +             Prog);
  959. +         exit (1);
  960. +     }
  961. + #ifdef    NDBM
  962. +     /*
  963. +      * Update the DBM shadow group file
  964. +      */
  965. +     if (access ("/etc/gshadow.pag", 0) == 0) {
  966. +         if (! sgr_dbm_remove (group_name)) {
  967. +             fprintf (stderr,
  968. +                 "%s: error removing shadow group dbm entry\n",
  969. +                 Prog);
  970. +             exit (1);
  971. +         }
  972. +     }
  973. + #endif    /* NDBM */
  974. + #endif    /* SHADOWGRP */
  975. + #ifdef    USE_SYSLOG
  976. +     syslog (LOG_INFO, "remove group `%s'\n", group_name);
  977. + #endif    /* USE_SYSLOG */
  978. + }
  979. + /*
  980. +  * close_files - close all of the files that were opened
  981. +  *
  982. +  *    close_files() closes all of the files that were opened for this
  983. +  *    new group.  This causes any modified entries to be written out.
  984. +  */
  985. + close_files ()
  986. + {
  987. +     if (! gr_close ()) {
  988. +         fprintf (stderr, "%s: cannot rewrite group file\n", Prog);
  989. +         exit (1);
  990. +     }
  991. +     (void) gr_unlock ();
  992. + #ifdef    SHADOWGRP
  993. +     if (! sgr_close ()) {
  994. +         fprintf (stderr, "%s: cannot rewrite shadow group file\n",
  995. +             Prog);
  996. +         exit (1);
  997. +     }
  998. +     (void) sgr_unlock ();
  999. + #endif    /* SHADOWGRP */
  1000. + }
  1001. + /*
  1002. +  * open_files - lock and open the group files
  1003. +  *
  1004. +  *    open_files() opens the two group files.
  1005. +  */
  1006. + open_files ()
  1007. + {
  1008. +     if (! gr_lock ()) {
  1009. +         fprintf (stderr, "%s: unable to lock group file\n", Prog);
  1010. +         exit (1);
  1011. +     }
  1012. +     if (! gr_open (O_RDWR)) {
  1013. +         fprintf (stderr, "%s: unable to open group file\n", Prog);
  1014. +         exit (1);
  1015. +     }
  1016. + #ifdef    SHADOWGRP
  1017. +     if (! sgr_lock ()) {
  1018. +         fprintf (stderr, "%s: unable to lock shadow group file\n",
  1019. +             Prog);
  1020. +         exit (1);
  1021. +     }
  1022. +     if (! sgr_open (O_RDWR)) {
  1023. +         fprintf (stderr, "%s: unable to open shadow group file\n",
  1024. +             Prog);
  1025. +         exit (1);
  1026. +     }
  1027. + #endif    /* SHADOWGRP */
  1028. + }
  1029. + /*
  1030. +  * main - groupdel command
  1031. +  *
  1032. +  *    The syntax of the groupdel command is
  1033. +  *    
  1034. +  *    groupdel group
  1035. +  *
  1036. +  *    The named group will be deleted.
  1037. +  */
  1038. + main (argc, argv)
  1039. + int    argc;
  1040. + char    **argv;
  1041. + {
  1042. +     /*
  1043. +      * Get my name so that I can use it to report errors.
  1044. +      */
  1045. +     if (Prog = strrchr (argv[0], '/'))
  1046. +         Prog++;
  1047. +     else
  1048. +         Prog = argv[0];
  1049. +     if (argc != 2)
  1050. +         usage ();
  1051. +     strncpy (group_name, argv[1], BUFSIZ);
  1052. + #ifdef    USE_SYSLOG
  1053. +     openlog (Prog, LOG_PID|LOG_CONS|LOG_NOWAIT, LOG_AUTH);
  1054. + #endif    /* USE_SYSLOG */
  1055. +     /*
  1056. +      * The open routines for the DBM files don't use read-write
  1057. +      * as the mode, so we have to clue them in.
  1058. +      */
  1059. + #ifdef    NDBM
  1060. +     gr_dbm_mode = O_RDWR;
  1061. + #ifdef    SHADOWGRP
  1062. +     sg_dbm_mode = O_RDWR;
  1063. + #endif    /* SHADOWGRP */
  1064. + #endif    /* NDBM */
  1065. +     /*
  1066. +      * Start with a quick check to see if the group exists.
  1067. +      */
  1068. +     if (! getgrnam (group_name)) {
  1069. +         fprintf (stderr, "%s: group %s does not exist\n",
  1070. +             Prog, group_name);
  1071. +         exit (9);
  1072. +     }
  1073. +     /*
  1074. +      * Do the hard stuff - open the files, delete the group entries,
  1075. +      * then close and update the files.
  1076. +      */
  1077. +     open_files ();
  1078. +     grp_update ();
  1079. +     close_files ();
  1080. +     exit (0);
  1081. +     /*NOTREACHED*/
  1082. + }
  1083. *** /dev/null    Wed Jun 26 09:26:31 1991
  1084. --- groupmod.c    Wed Jun 26 09:43:34 1991
  1085. ***************
  1086. *** 0 ****
  1087. --- 1,421 ----
  1088. + /*
  1089. +  * Copyright 1991, John F. Haugh II
  1090. +  * All rights reserved.
  1091. +  *
  1092. +  * Permission is granted to copy and create derivative works for any
  1093. +  * non-commercial purpose, provided this copyright notice is preserved
  1094. +  * in all copies of source code, or included in human readable form
  1095. +  * and conspicuously displayed on all copies of object code or
  1096. +  * distribution media.
  1097. +  */
  1098. + #ifndef lint
  1099. + static    char    sccsid[] = "@(#)groupmod.c    3.1    22:59:07    6/13/91";
  1100. + #endif
  1101. + #include <sys/types.h>
  1102. + #include <stdio.h>
  1103. + #include <grp.h>
  1104. + #include <ctype.h>
  1105. + #include <fcntl.h>
  1106. + #ifdef    BSD
  1107. + #include <strings.h>
  1108. + #else
  1109. + #include <string.h>
  1110. + #endif
  1111. + #include "config.h"
  1112. + #include "shadow.h"
  1113. + #ifdef    USE_SYSLOG
  1114. + #include <syslog.h>
  1115. + #endif
  1116. + char    group_name[BUFSIZ];
  1117. + char    group_newname[BUFSIZ];
  1118. + int    group_id;
  1119. + int    group_newid;
  1120. + char    *Prog;
  1121. + int    oflg;    /* permit non-unique group ID to be specified with -g         */
  1122. + int    gflg;    /* new ID value for the group                                 */
  1123. + int    nflg;    /* a new name has been specified for the group                */
  1124. + #ifdef    NDBM
  1125. + extern    int    gr_dbm_mode;
  1126. + extern    int    sg_dbm_mode;
  1127. + #endif
  1128. + extern    char    *malloc();
  1129. + extern    struct    group    *getgrnam();
  1130. + extern    struct    group    *gr_next();
  1131. + extern    struct    group    *gr_locate();
  1132. + extern    int    gr_lock();
  1133. + extern    int    gr_unlock();
  1134. + extern    int    gr_rewind();
  1135. + extern    int    gr_open();
  1136. + #ifdef    SHADOWGRP
  1137. + extern    struct    sgrp    *sgr_locate();
  1138. + extern    int    sgr_lock();
  1139. + extern    int    sgr_unlock();
  1140. + extern    int    sgr_open();
  1141. + #endif
  1142. + /*
  1143. +  * usage - display usage message and exit
  1144. +  */
  1145. + usage ()
  1146. + {
  1147. +     fprintf (stderr, "usage: groupmod [-g gid [-o]] [-n name] group\n");
  1148. +     exit (2);
  1149. + }
  1150. + /*
  1151. +  * new_grent - updates the values in a group file entry
  1152. +  *
  1153. +  *    new_grent() takes all of the values that have been entered and
  1154. +  *    fills in a (struct group) with them.
  1155. +  */
  1156. + void
  1157. + new_grent (grent)
  1158. + struct    group    *grent;
  1159. + {
  1160. +     if (nflg)
  1161. +         grent->gr_name = strdup (group_newname);
  1162. +     if (gflg)
  1163. +         grent->gr_gid = group_newid;
  1164. + }
  1165. + #ifdef    SHADOWGRP
  1166. + /*
  1167. +  * new_sgent - updates the values in a shadow group file entry
  1168. +  *
  1169. +  *    new_sgent() takes all of the values that have been entered and
  1170. +  *    fills in a (struct sgrp) with them.
  1171. +  */
  1172. + void
  1173. + new_sgent (sgent)
  1174. + struct    sgrp    *sgent;
  1175. + {
  1176. +     if (nflg)
  1177. +         sgent->sg_name = strdup (group_newname);
  1178. + }
  1179. + #endif    /* SHADOWGRP */
  1180. + /*
  1181. +  * grp_update - update group file entries
  1182. +  *
  1183. +  *    grp_update() writes the new records to the group files.
  1184. +  */
  1185. + void
  1186. + grp_update ()
  1187. + {
  1188. +     int    i;
  1189. +     struct    group    grp;
  1190. +     struct    group    *ogrp;
  1191. + #ifdef    SHADOWGRP
  1192. +     struct    sgrp    sgrp;
  1193. + #endif    /* SHADOWGRP */
  1194. +     /*
  1195. +      * Create the initial entries for this new group.
  1196. +      */
  1197. +     grp = *(gr_locate (group_name));
  1198. +     new_grent (&grp);
  1199. + #ifdef    SHADOWGRP
  1200. +     sgrp = *(sgr_locate (group_name));
  1201. +     new_sgent (&sgrp);
  1202. + #endif    /* SHADOWGRP */
  1203. +     /*
  1204. +      * Write out the new group file entry.
  1205. +      */
  1206. +     if (! gr_update (&grp)) {
  1207. +         fprintf (stderr, "%s: error adding new group entry\n", Prog);
  1208. +         exit (1);
  1209. +     }
  1210. +     if (nflg && ! gr_remove (group_name)) {
  1211. +         fprintf (stderr, "%s: error removing group entry\n", Prog);
  1212. +         exit (1);
  1213. +     }
  1214. + #ifdef    NDBM
  1215. +     /*
  1216. +      * Update the DBM group file with the new entry as well.
  1217. +      */
  1218. +     if (access ("/etc/group.pag", 0) == 0) {
  1219. +         if (! gr_dbm_update (&grp)) {
  1220. +             fprintf (stderr, "%s: cannot add new dbm group entry\n",
  1221. +                 Prog);
  1222. +             exit (1);
  1223. +         }
  1224. +         if (nflg && (ogrp = getgrnam (group_name)) &&
  1225. +                 ! gr_dbm_remove (ogrp)) {
  1226. +             fprintf (stderr, "%s: error removing group dbm entry\n",
  1227. +                 Prog);
  1228. +             exit (1);
  1229. +         }
  1230. +     }
  1231. + #endif    /* NDBM */
  1232. + #ifdef    SHADOWGRP
  1233. +     /*
  1234. +      * Write out the new shadow group entries as well.
  1235. +      */
  1236. +     if (! sgr_update (&sgrp)) {
  1237. +         fprintf (stderr, "%s: error adding new group entry\n", Prog);
  1238. +         exit (1);
  1239. +     }
  1240. +     if (nflg && ! sgr_remove (group_name)) {
  1241. +         fprintf (stderr, "%s: error removing group entry\n", Prog);
  1242. +         exit (1);
  1243. +     }
  1244. + #ifdef    NDBM
  1245. +     /*
  1246. +      * Update the DBM shadow group file with the new entry as well.
  1247. +      */
  1248. +     if (access ("/etc/gshadow.pag", 0) == 0) {
  1249. +         if (! sgr_dbm_update (&sgrp)) {
  1250. +             fprintf (stderr,
  1251. +                 "%s: cannot add new dbm shadow group entry\n",
  1252. +                 Prog);
  1253. +             exit (1);
  1254. +         }
  1255. +         if (nflg && ! sgr_dbm_remove (group_name)) {
  1256. +             fprintf (stderr,
  1257. +                 "%s: error removing shadow group dbm entry\n",
  1258. +                 Prog);
  1259. +             exit (1);
  1260. +         }
  1261. +     }
  1262. + #endif    /* NDBM */
  1263. + #endif    /* SHADOWGRP */
  1264. + #ifdef    USE_SYSLOG
  1265. +     if (nflg)
  1266. +         syslog (LOG_INFO, "change group `%s' to `%s'\n",
  1267. +             group_name, group_newname);
  1268. +     if (gflg)
  1269. +         syslog (LOG_INFO, "change gid for `%s' to %d\n",
  1270. +             nflg ? group_name:group_newname, group_newid);
  1271. + #endif    /* USE_SYSLOG */
  1272. + }
  1273. + /*
  1274. +  * check_new_gid - check the new GID value for uniqueness
  1275. +  *
  1276. +  *    check_new_gid() insures that the new GID value is unique.
  1277. +  */
  1278. + int
  1279. + check_new_gid ()
  1280. + {
  1281. +     /*
  1282. +      * First, the easy stuff.  If the ID can be duplicated, or if
  1283. +      * the ID didn't really change, just return.  If the ID didn't
  1284. +      * change, turn off those flags.  No sense doing needless work.
  1285. +      */
  1286. +     if (oflg)
  1287. +         return 0;
  1288. +     if (group_id == group_newid) {
  1289. +         gflg = 0;
  1290. +         return 0;
  1291. +     }
  1292. +     if (getgrgid (group_newid))
  1293. +         return -1;
  1294. +     return 0;
  1295. + }
  1296. + /*
  1297. +  * process_flags - perform command line argument setting
  1298. +  *
  1299. +  *    process_flags() interprets the command line arguments and sets
  1300. +  *    the values that the user will be created with accordingly.  The
  1301. +  *    values are checked for sanity.
  1302. +  */
  1303. + void
  1304. + process_flags (argc, argv)
  1305. + int    argc;
  1306. + char    **argv;
  1307. + {
  1308. +     extern    int    optind;
  1309. +     extern    char    *optarg;
  1310. +     struct    group    *grp;
  1311. +     char    *end;
  1312. +     int    anyflag = 0;
  1313. +     int    arg;
  1314. +     while ((arg = getopt (argc, argv, "og:n:")) != EOF) {
  1315. +         switch (arg) {
  1316. +             case 'g':
  1317. +                 gflg++;
  1318. +                 group_newid = strtol (optarg, &end, 10);
  1319. +                 if (*end != '\0') {
  1320. +                     fprintf (stderr, "%s: invalid group %s\n",
  1321. +                         Prog, optarg);
  1322. +                     exit (3);
  1323. +                 }
  1324. +                 break;
  1325. +             case 'n':
  1326. +                 if (strcmp (group_name, optarg)) {
  1327. +                     nflg++;
  1328. +                     strncpy (group_newname, optarg, BUFSIZ);
  1329. +                 }
  1330. +                 break;
  1331. +             case 'o':
  1332. +                 if (! gflg)
  1333. +                     usage ();
  1334. +                 oflg++;
  1335. +                 break;
  1336. +             default:
  1337. +                 usage ();
  1338. +         }
  1339. +         anyflag++;
  1340. +     }
  1341. +     if (optind == argc - 1)
  1342. +         strcpy (group_name, argv[argc - 1]);
  1343. +     else
  1344. +         usage ();
  1345. + }
  1346. + /*
  1347. +  * close_files - close all of the files that were opened
  1348. +  *
  1349. +  *    close_files() closes all of the files that were opened for this
  1350. +  *    new group.  This causes any modified entries to be written out.
  1351. +  */
  1352. + close_files ()
  1353. + {
  1354. +     if (! gr_close ()) {
  1355. +         fprintf (stderr, "%s: cannot rewrite group file\n", Prog);
  1356. +         exit (1);
  1357. +     }
  1358. +     (void) gr_unlock ();
  1359. + #ifdef    SHADOWGRP
  1360. +     if (! sgr_close ()) {
  1361. +         fprintf (stderr, "%s: cannot rewrite shadow group file\n",
  1362. +             Prog);
  1363. +         exit (1);
  1364. +     }
  1365. +     (void) sgr_unlock ();
  1366. + #endif    /* SHADOWGRP */
  1367. + }
  1368. + /*
  1369. +  * open_files - lock and open the group files
  1370. +  *
  1371. +  *    open_files() opens the two group files.
  1372. +  */
  1373. + open_files ()
  1374. + {
  1375. +     if (! gr_lock ()) {
  1376. +         fprintf (stderr, "%s: unable to lock group file\n", Prog);
  1377. +         exit (1);
  1378. +     }
  1379. +     if (! gr_open (O_RDWR)) {
  1380. +         fprintf (stderr, "%s: unable to open group file\n", Prog);
  1381. +         exit (1);
  1382. +     }
  1383. + #ifdef    SHADOWGRP
  1384. +     if (! sgr_lock ()) {
  1385. +         fprintf (stderr, "%s: unable to lock shadow group file\n",
  1386. +             Prog);
  1387. +         exit (1);
  1388. +     }
  1389. +     if (! sgr_open (O_RDWR)) {
  1390. +         fprintf (stderr, "%s: unable to open shadow group file\n",
  1391. +             Prog);
  1392. +         exit (1);
  1393. +     }
  1394. + #endif    /* SHADOWGRP */
  1395. + }
  1396. + /*
  1397. +  * main - groupmod command
  1398. +  *
  1399. +  *    The syntax of the groupmod command is
  1400. +  *    
  1401. +  *    groupmod [ -g gid [ -o ]] [ -n name ] group
  1402. +  *
  1403. +  *    The flags are
  1404. +  *        -g - specify a new group ID value
  1405. +  *        -o - permit the group ID value to be non-unique
  1406. +  *        -n - specify a new group name
  1407. +  */
  1408. + main (argc, argv)
  1409. + int    argc;
  1410. + char    **argv;
  1411. + {
  1412. +     /*
  1413. +      * Get my name so that I can use it to report errors.
  1414. +      */
  1415. +     if (Prog = strrchr (argv[0], '/'))
  1416. +         Prog++;
  1417. +     else
  1418. +         Prog = argv[0];
  1419. + #ifdef    USE_SYSLOG
  1420. +     openlog (Prog, LOG_PID|LOG_CONS|LOG_NOWAIT, LOG_AUTH);
  1421. + #endif    /* USE_SYSLOG */
  1422. +     /*
  1423. +      * The open routines for the DBM files don't use read-write
  1424. +      * as the mode, so we have to clue them in.
  1425. +      */
  1426. + #ifdef    NDBM
  1427. +     gr_dbm_mode = O_RDWR;
  1428. + #ifdef    SHADOWGRP
  1429. +     sg_dbm_mode = O_RDWR;
  1430. + #endif    /* SHADOWGRP */
  1431. + #endif    /* NDBM */
  1432. +     process_flags (argc, argv);
  1433. +     /*
  1434. +      * Start with a quick check to see if the group exists.
  1435. +      */
  1436. +     if (! getgrnam (group_name)) {
  1437. +         fprintf (stderr, "%s: group %s does not exist\n",
  1438. +             Prog, group_name);
  1439. +         exit (9);
  1440. +     }
  1441. +     /*
  1442. +      * Do the hard stuff - open the files, create the group entries,
  1443. +      * then close and update the files.
  1444. +      */
  1445. +     open_files ();
  1446. +     grp_update ();
  1447. +     close_files ();
  1448. +     exit (0);
  1449. +     /*NOTREACHED*/
  1450. + }
  1451. Index: useradd.c
  1452. *** rel3/useradd.c    Tue Jun 25 09:38:28 1991
  1453. --- useradd.c    Wed Jun 26 09:43:37 1991
  1454. ***************
  1455. *** 10,16 ****
  1456.    */
  1457.   
  1458.   #ifndef lint
  1459. ! static    char    sccsid[] = "@(#)useradd.c    3.2    20:15:10    6/11/91";
  1460.   #endif
  1461.   
  1462.   #include <sys/types.h>
  1463. --- 10,16 ----
  1464.    */
  1465.   
  1466.   #ifndef lint
  1467. ! static    char    sccsid[] = "@(#)useradd.c    3.4    09:39:58    6/26/91";
  1468.   #endif
  1469.   
  1470.   #include <sys/types.h>
  1471. ***************
  1472. *** 80,93 ****
  1473.   int    eflg;    /* days after password changed before it becomes expired      */
  1474.   int    Dflg;    /* set/show new user default values                           */
  1475.   
  1476. ! #if defined(DBM) || defined(NDBM)
  1477.   extern    int    pw_dbm_mode;
  1478. - #endif
  1479. - #ifdef    NDBM
  1480.   extern    int    sp_dbm_mode;
  1481.   extern    int    gr_dbm_mode;
  1482.   extern    int    sg_dbm_mode;
  1483.   #endif
  1484.   extern    FILE    *fopen();
  1485.   extern    int    fclose();
  1486.   extern    char    *malloc();
  1487. --- 80,93 ----
  1488.   int    eflg;    /* days after password changed before it becomes expired      */
  1489.   int    Dflg;    /* set/show new user default values                           */
  1490.   
  1491. ! #ifdef NDBM
  1492.   extern    int    pw_dbm_mode;
  1493.   extern    int    sp_dbm_mode;
  1494.   extern    int    gr_dbm_mode;
  1495. + #ifdef    SHADOWGRP
  1496.   extern    int    sg_dbm_mode;
  1497.   #endif
  1498. + #endif
  1499.   extern    FILE    *fopen();
  1500.   extern    int    fclose();
  1501.   extern    char    *malloc();
  1502. ***************
  1503. *** 372,378 ****
  1504.               else if (grp = getgrnam (cp))
  1505.                   def_group = grp->gr_gid;
  1506.               else
  1507. !                 fprintf (stderr, "%s: unknown group %s\n", cp);
  1508.           }
  1509.           
  1510.           /*
  1511. --- 372,379 ----
  1512.               else if (grp = getgrnam (cp))
  1513.                   def_group = grp->gr_gid;
  1514.               else
  1515. !                 fprintf (stderr, "%s: unknown group %s\n",
  1516. !                     Prog, cp);
  1517.           }
  1518.           
  1519.           /*
  1520. ***************
  1521. *** 638,644 ****
  1522.   usage ()
  1523.   {
  1524.       fprintf (stderr,
  1525. !         "usage:\tuseradd [-u uid [-o]] [-g group] [-G group,...] \n");
  1526.       fprintf (stderr,
  1527.           "\t\t[-d home] [-s shell] [-c comment] [-m [-k template]]\n");
  1528.       fprintf (stderr,
  1529. --- 639,645 ----
  1530.   usage ()
  1531.   {
  1532.       fprintf (stderr,
  1533. !         "usage:\t%s [-u uid [-o]] [-g group] [-G group,...] \n", Prog);
  1534.       fprintf (stderr,
  1535.           "\t\t[-d home] [-s shell] [-c comment] [-m [-k template]]\n");
  1536.       fprintf (stderr,
  1537. ***************
  1538. *** 645,651 ****
  1539.           "\t\t[-f inactive] [-e expire] name\n");
  1540.   
  1541.       fprintf (stderr,
  1542. !         "\tuseradd -D [-g group] [-b base] [-f inactive] [-e expire]\n");
  1543.   
  1544.       exit (1);
  1545.   }
  1546. --- 646,653 ----
  1547.           "\t\t[-f inactive] [-e expire] name\n");
  1548.   
  1549.       fprintf (stderr,
  1550. !         "\t%s -D [-g group] [-b base] [-f inactive] [-e expire]\n",
  1551. !             Prog);
  1552.   
  1553.       exit (1);
  1554.   }
  1555. ***************
  1556. *** 962,971 ****
  1557.                   if (! grp) {
  1558.                       fprintf (stderr,
  1559.                           "%s: unknown group %s\n",
  1560. !                         optarg);
  1561.                       exit (1);
  1562.                   }
  1563. !                 def_group = grp->gr_gid;
  1564.                   break;
  1565.               case 'G':
  1566.                   Gflg++;
  1567. --- 964,973 ----
  1568.                   if (! grp) {
  1569.                       fprintf (stderr,
  1570.                           "%s: unknown group %s\n",
  1571. !                         Prog, optarg);
  1572.                       exit (1);
  1573.                   }
  1574. !                 user_gid = grp->gr_gid;
  1575.                   break;
  1576.               case 'G':
  1577.                   Gflg++;
  1578. ***************
  1579. *** 1061,1068 ****
  1580. --- 1063,1072 ----
  1581.                   Prog);
  1582.               exit (1);
  1583.           }
  1584. +         (void) sgr_unlock ();
  1585.   #endif
  1586.       }
  1587. +     (void) spw_unlock ();
  1588.       (void) pw_unlock ();
  1589.   }
  1590.   
  1591. Index: userdel.c
  1592. *** rel3/userdel.c    Tue Jun 25 09:38:29 1991
  1593. --- userdel.c    Wed Jun 26 09:43:39 1991
  1594. ***************
  1595. *** 10,16 ****
  1596.    */
  1597.   
  1598.   #ifndef lint
  1599. ! static    char    sccsid[] = "@(#)userdel.c    3.5    20:53:04    6/13/91";
  1600.   #endif
  1601.   
  1602.   #include <sys/types.h>
  1603. --- 10,16 ----
  1604.    */
  1605.   
  1606.   #ifndef lint
  1607. ! static    char    sccsid[] = "@(#)userdel.c    3.7    09:40:05    6/26/91";
  1608.   #endif
  1609.   
  1610.   #include <sys/types.h>
  1611. ***************
  1612. *** 64,73 ****
  1613.   char    *Prog;
  1614.   int    rflg;
  1615.   
  1616. - #if defined(DBM) || defined(NDBM)
  1617. - extern    int    pw_dbm_mode;
  1618. - #endif
  1619.   #ifdef    NDBM
  1620.   extern    int    sp_dbm_mode;
  1621.   extern    int    gr_dbm_mode;
  1622.   #ifdef    SHADOWGRP
  1623. --- 64,71 ----
  1624.   char    *Prog;
  1625.   int    rflg;
  1626.   
  1627.   #ifdef    NDBM
  1628. + extern    int    pw_dbm_mode;
  1629.   extern    int    sp_dbm_mode;
  1630.   extern    int    gr_dbm_mode;
  1631.   #ifdef    SHADOWGRP
  1632. ***************
  1633. *** 147,153 ****
  1634.   
  1635.   usage ()
  1636.   {
  1637. !     fprintf (stderr, "usage: userdel [-r] name\n");
  1638.       exit (2);
  1639.   }
  1640.   
  1641. --- 145,151 ----
  1642.   
  1643.   usage ()
  1644.   {
  1645. !     fprintf (stderr, "usage: %s [-r] name\n", Prog);
  1646.       exit (2);
  1647.   }
  1648.   
  1649. ***************
  1650. *** 266,272 ****
  1651.   #endif
  1652.   #ifdef    USE_SYSLOG
  1653.           syslog (LOG_INFO, "delete `%s' from shadow group `%s'\n",
  1654. !             user_name, grp->gr_name);
  1655.   #endif
  1656.       }
  1657.   #endif
  1658. --- 264,270 ----
  1659.   #endif
  1660.   #ifdef    USE_SYSLOG
  1661.           syslog (LOG_INFO, "delete `%s' from shadow group `%s'\n",
  1662. !             user_name, sgrp->sg_name);
  1663.   #endif
  1664.       }
  1665.   #endif
  1666. ***************
  1667. *** 304,309 ****
  1668. --- 302,308 ----
  1669.       }
  1670.       (void) sgr_unlock ();
  1671.   #endif
  1672. +     (void) spw_unlock ();
  1673.       (void) pw_unlock ();
  1674.   }
  1675.   
  1676. Index: usermod.c
  1677. *** rel3/usermod.c    Tue Jun 25 09:38:29 1991
  1678. --- usermod.c    Wed Jun 26 09:43:42 1991
  1679. ***************
  1680. *** 10,16 ****
  1681.    */
  1682.   
  1683.   #ifndef lint
  1684. ! static    char    sccsid[] = "@(#)usermod.c    3.2    20:26:57    6/11/91";
  1685.   #endif
  1686.   
  1687.   #include <sys/types.h>
  1688. --- 10,16 ----
  1689.    */
  1690.   
  1691.   #ifndef lint
  1692. ! static    char    sccsid[] = "@(#)usermod.c    3.3    09:29:57    6/26/91";
  1693.   #endif
  1694.   
  1695.   #include <sys/types.h>
  1696. ***************
  1697. *** 57,63 ****
  1698.   char    user_shell[BUFSIZ];
  1699.   long    user_expire;
  1700.   long    user_inactive;
  1701. ! int    user_ngroups;
  1702.   gid_t    user_groups[NGROUPS_MAX];
  1703.   struct    passwd    user_pwd;
  1704.   struct    spwd    user_spwd;
  1705. --- 57,63 ----
  1706.   char    user_shell[BUFSIZ];
  1707.   long    user_expire;
  1708.   long    user_inactive;
  1709. ! int    user_ngroups = -1;
  1710.   gid_t    user_groups[NGROUPS_MAX];
  1711.   struct    passwd    user_pwd;
  1712.   struct    spwd    user_spwd;
  1713. ***************
  1714. *** 76,89 ****
  1715.   int    eflg;    /* days after password changed before it becomes expired      */
  1716.   int    lflg;    /* new user name for user                                     */
  1717.   
  1718. - #if defined(DBM) || defined(NDBM)
  1719. - extern    int    pw_dbm_mode;
  1720. - #endif
  1721.   #ifdef    NDBM
  1722.   extern    int    sp_dbm_mode;
  1723.   extern    int    gr_dbm_mode;
  1724.   extern    int    sg_dbm_mode;
  1725.   #endif
  1726.   extern    FILE    *fopen();
  1727.   extern    int    fclose();
  1728.   extern    char    *malloc();
  1729. --- 76,89 ----
  1730.   int    eflg;    /* days after password changed before it becomes expired      */
  1731.   int    lflg;    /* new user name for user                                     */
  1732.   
  1733.   #ifdef    NDBM
  1734. + extern    int    pw_dbm_mode;
  1735.   extern    int    sp_dbm_mode;
  1736.   extern    int    gr_dbm_mode;
  1737. + #ifdef    SHADOWGRP
  1738.   extern    int    sg_dbm_mode;
  1739.   #endif
  1740. + #endif
  1741.   extern    FILE    *fopen();
  1742.   extern    int    fclose();
  1743.   extern    char    *malloc();
  1744. ***************
  1745. *** 848,854 ****
  1746.                   if (! grp) {
  1747.                       fprintf (stderr,
  1748.                           "%s: unknown group %s\n",
  1749. !                         optarg);
  1750.                       exit (1);
  1751.                   }
  1752.                   if (grp->gr_gid != user_gid) {
  1753. --- 848,854 ----
  1754.                   if (! grp) {
  1755.                       fprintf (stderr,
  1756.                           "%s: unknown group %s\n",
  1757. !                         Prog, optarg);
  1758.                       exit (1);
  1759.                   }
  1760.                   if (grp->gr_gid != user_gid) {
  1761. ***************
  1762. *** 907,912 ****
  1763. --- 907,916 ----
  1764.           }
  1765.           anyflag++;
  1766.       }
  1767. +     if (anyflag == 0) {
  1768. +         fprintf (stderr, "%s: no flags given\n", Prog);
  1769. +         exit (1);
  1770. +     }
  1771.       if (optind != argc - 1)
  1772.           usage ();
  1773.   
  1774. ***************
  1775. *** 917,923 ****
  1776.           uflg = oflg = 0;
  1777.   
  1778.       if (lflg && getpwnam (user_newname)) {
  1779. !         fprintf (stderr, "%s: user %s exists\n", user_newname);
  1780.           exit (9);
  1781.       }
  1782.   }
  1783. --- 921,927 ----
  1784.           uflg = oflg = 0;
  1785.   
  1786.       if (lflg && getpwnam (user_newname)) {
  1787. !         fprintf (stderr, "%s: user %s exists\n", Prog, user_newname);
  1788.           exit (9);
  1789.       }
  1790.   }
  1791. ***************
  1792. *** 940,946 ****
  1793.               Prog);
  1794.           exit (1);
  1795.       }
  1796. !     if (user_ngroups > 0) {
  1797.           if (! gr_close ()) {
  1798.               fprintf (stderr, "%s: cannot rewrite group file\n",
  1799.                   Prog);
  1800. --- 944,950 ----
  1801.               Prog);
  1802.           exit (1);
  1803.       }
  1804. !     if (user_ngroups >= 0) {
  1805.           if (! gr_close ()) {
  1806.               fprintf (stderr, "%s: cannot rewrite group file\n",
  1807.                   Prog);
  1808. ***************
  1809. *** 953,960 ****
  1810. --- 957,966 ----
  1811.                   Prog);
  1812.               exit (1);
  1813.           }
  1814. +         (void) sgr_unlock ();
  1815.   #endif
  1816.       }
  1817. +     (void) spw_unlock ();
  1818.       (void) pw_unlock ();
  1819.   }
  1820.   
  1821. ***************
  1822. *** 1009,1019 ****
  1823.   
  1824.       if (lflg || uflg || gflg || cflg || dflg || sflg) {
  1825.           if (! pw_update (&pwent)) {
  1826. !             fprintf (stderr, "%s: error changing password entry\n");
  1827.               exit (1);
  1828.           }
  1829.           if (lflg && ! pw_remove (user_name)) {
  1830. !             fprintf (stderr, "%s: error removing password entry\n");
  1831.               exit (1);
  1832.           }
  1833.   #if defined(DBM) || defined(NDBM)
  1834. --- 1015,1027 ----
  1835.   
  1836.       if (lflg || uflg || gflg || cflg || dflg || sflg) {
  1837.           if (! pw_update (&pwent)) {
  1838. !             fprintf (stderr, "%s: error changing password entry\n",
  1839. !                 Prog);
  1840.               exit (1);
  1841.           }
  1842.           if (lflg && ! pw_remove (user_name)) {
  1843. !             fprintf (stderr, "%s: error removing password entry\n",
  1844. !                 Prog);
  1845.               exit (1);
  1846.           }
  1847.   #if defined(DBM) || defined(NDBM)
  1848. Index: shadowio.c
  1849. *** rel3/shadowio.c    Tue Jun 25 09:37:59 1991
  1850. --- shadowio.c    Wed Jun 26 09:43:44 1991
  1851. ***************
  1852. *** 24,30 ****
  1853.    */
  1854.   
  1855.   #ifndef    lint
  1856. ! static    char    sccsid[] = "@(#)shadowio.c    3.5    09:08:15    5/28/91";
  1857.   #endif
  1858.   
  1859.   #include <sys/types.h>
  1860. --- 24,30 ----
  1861.    */
  1862.   
  1863.   #ifndef    lint
  1864. ! static    char    sccsid[] = "@(#)shadowio.c    3.6    09:17:38    6/26/91";
  1865.   #endif
  1866.   
  1867.   #include <sys/types.h>
  1868. ***************
  1869. *** 338,351 ****
  1870.   spw_close ()
  1871.   {
  1872.       char    backup[BUFSIZ];
  1873. -     int    fd;
  1874.       int    mask;
  1875.       int    c;
  1876. -     int    i;
  1877.       int    errors = 0;
  1878.       FILE    *bkfp;
  1879.       struct    spw_file_entry *spwf;
  1880. !     struct    spw_file_entry *ospwf;
  1881.   
  1882.       if (! isopen) {
  1883.           errno = EINVAL;
  1884. --- 338,349 ----
  1885.   spw_close ()
  1886.   {
  1887.       char    backup[BUFSIZ];
  1888.       int    mask;
  1889.       int    c;
  1890.       int    errors = 0;
  1891.       FILE    *bkfp;
  1892.       struct    spw_file_entry *spwf;
  1893. !     struct    stat    sb;
  1894.   
  1895.       if (! isopen) {
  1896.           errno = EINVAL;
  1897. ***************
  1898. *** 361,372 ****
  1899.       strcat (backup, "-");
  1900.   
  1901.       if (open_modes == O_RDWR && sp_changed) {
  1902. !         mask = umask (077);
  1903.           if ((bkfp = fopen (backup, "w")) == 0) {
  1904.               umask (mask);
  1905.               return 0;
  1906.           }
  1907.           umask (mask);
  1908.   
  1909.           rewind (spwfp);
  1910.           while ((c = getc (spwfp)) != EOF) {
  1911. --- 359,372 ----
  1912.       strcat (backup, "-");
  1913.   
  1914.       if (open_modes == O_RDWR && sp_changed) {
  1915. !         mask = umask (0377);
  1916.           if ((bkfp = fopen (backup, "w")) == 0) {
  1917.               umask (mask);
  1918.               return 0;
  1919.           }
  1920.           umask (mask);
  1921. +         fstat (fileno (spwfp), &sb);
  1922. +         chown (backup, sb.st_uid, sb.st_gid);
  1923.   
  1924.           rewind (spwfp);
  1925.           while ((c = getc (spwfp)) != EOF) {
  1926. ***************
  1927. *** 381,387 ****
  1928.           isopen = 0;
  1929.           (void) fclose (spwfp);
  1930.   
  1931. !         mask = umask (077);
  1932.           if (! (spwfp = fopen (spw_filename, "w"))) {
  1933.               umask (mask);
  1934.               return 0;
  1935. --- 381,387 ----
  1936.           isopen = 0;
  1937.           (void) fclose (spwfp);
  1938.   
  1939. !         mask = umask (0377);
  1940.           if (! (spwfp = fopen (spw_filename, "w"))) {
  1941.               umask (mask);
  1942.               return 0;
  1943. ***************
  1944. *** 429,434 ****
  1945. --- 429,435 ----
  1946.           free (spwf);
  1947.       }
  1948.       spwf_tail = 0;
  1949. +     isopen = 0;
  1950.       return 1;
  1951.   }
  1952.   
  1953. Index: groupio.c
  1954. *** rel3/groupio.c    Tue Jun 25 09:37:51 1991
  1955. --- groupio.c    Wed Jun 26 09:43:47 1991
  1956. ***************
  1957. *** 36,42 ****
  1958.   #endif
  1959.   
  1960.   #ifndef    lint
  1961. ! static    char    sccsid[] = "@(#)groupio.c    3.7 09:07:28 5/28/91";
  1962.   #endif
  1963.   
  1964.   static    int    islocked;
  1965. --- 36,42 ----
  1966.   #endif
  1967.   
  1968.   #ifndef    lint
  1969. ! static    char    sccsid[] = "@(#)groupio.c    3.8 09:03:34 6/26/91";
  1970.   #endif
  1971.   
  1972.   static    int    islocked;
  1973. ***************
  1974. *** 365,370 ****
  1975. --- 365,371 ----
  1976.       FILE    *bkfp;
  1977.       struct    gr_file_entry *grf;
  1978.       struct    gr_file_entry *ogrf;
  1979. +     struct    stat    sb;
  1980.   
  1981.       if (! isopen) {
  1982.           errno = EINVAL;
  1983. ***************
  1984. *** 386,391 ****
  1985. --- 387,394 ----
  1986.               return 0;
  1987.           }
  1988.           umask (mask);
  1989. +         fstat (fileno (grfp), &sb);
  1990. +         chown (backup, sb.st_uid, sb.st_gid);
  1991.   
  1992.           rewind (grfp);
  1993.           while ((c = getc (grfp)) != EOF) {
  1994. ***************
  1995. *** 448,453 ****
  1996. --- 451,457 ----
  1997.           free (grf);
  1998.       }
  1999.       grf_tail = 0;
  2000. +     isopen = 0;
  2001.       return 1;
  2002.   }
  2003.   
  2004. Index: sgroupio.c
  2005. *** rel3/sgroupio.c    Tue Jun 25 09:38:10 1991
  2006. --- sgroupio.c    Wed Jun 26 09:43:49 1991
  2007. ***************
  2008. *** 38,44 ****
  2009.   #include "shadow.h"
  2010.   
  2011.   #ifndef    lint
  2012. ! static    char    sccsid[] = "@(#)sgroupio.c    3.3    07:06:36    6/6/91";
  2013.   #endif
  2014.   
  2015.   static    int    islocked;
  2016. --- 38,44 ----
  2017.   #include "shadow.h"
  2018.   
  2019.   #ifndef    lint
  2020. ! static    char    sccsid[] = "@(#)sgroupio.c    3.4    09:11:25    6/26/91";
  2021.   #endif
  2022.   
  2023.   static    int    islocked;
  2024. ***************
  2025. *** 369,382 ****
  2026.   sgr_close ()
  2027.   {
  2028.       char    backup[BUFSIZ];
  2029. -     int    fd;
  2030.       int    mask;
  2031.       int    c;
  2032. -     int    i;
  2033.       int    errors = 0;
  2034.       FILE    *bkfp;
  2035.       struct    sg_file_entry *sgrf;
  2036. !     struct    sg_file_entry *osgrf;
  2037.   
  2038.       if (! isopen) {
  2039.           errno = EINVAL;
  2040. --- 369,380 ----
  2041.   sgr_close ()
  2042.   {
  2043.       char    backup[BUFSIZ];
  2044.       int    mask;
  2045.       int    c;
  2046.       int    errors = 0;
  2047.       FILE    *bkfp;
  2048.       struct    sg_file_entry *sgrf;
  2049. !     struct    stat    sb;
  2050.   
  2051.       if (! isopen) {
  2052.           errno = EINVAL;
  2053. ***************
  2054. *** 398,403 ****
  2055. --- 396,403 ----
  2056.               return 0;
  2057.           }
  2058.           umask (mask);
  2059. +         fstat (fileno (sgrfp), &sb);
  2060. +         chown (backup, sb.st_uid, sb.st_gid);
  2061.   
  2062.           rewind (sgrfp);
  2063.           while ((c = getc (sgrfp)) != EOF) {
  2064. ***************
  2065. *** 460,465 ****
  2066. --- 460,466 ----
  2067.           free (sgrf);
  2068.       }
  2069.       sgr_tail = 0;
  2070. +     isopen = 0;
  2071.       return 1;
  2072.   }
  2073.   
  2074. Index: pwio.c
  2075. *** rel3/pwio.c    Tue Jun 25 09:37:56 1991
  2076. --- pwio.c    Wed Jun 26 09:43:52 1991
  2077. ***************
  2078. *** 37,43 ****
  2079.   #endif
  2080.   
  2081.   #ifndef lint
  2082. ! static    char    sccsid[] = "@(#)pwio.c    3.7    09:08:02    5/28/91";
  2083.   #endif
  2084.   
  2085.   static    int    islocked;
  2086. --- 37,43 ----
  2087.   #endif
  2088.   
  2089.   #ifndef lint
  2090. ! static    char    sccsid[] = "@(#)pwio.c    3.8    09:04:48    6/26/91";
  2091.   #endif
  2092.   
  2093.   static    int    islocked;
  2094. ***************
  2095. *** 361,366 ****
  2096. --- 361,367 ----
  2097.       FILE    *bkfp;
  2098.       struct    pw_file_entry *pwf;
  2099.       struct    pw_file_entry *opwf;
  2100. +     struct    stat    sb;
  2101.   
  2102.       if (! isopen) {
  2103.           errno = EINVAL;
  2104. ***************
  2105. *** 376,387 ****
  2106.       strcat (backup, "-");
  2107.   
  2108.       if (open_modes == O_RDWR && pw_changed) {
  2109. !         mask = umask (022);
  2110.           if ((bkfp = fopen (backup, "w")) == 0) {
  2111.               umask (mask);
  2112.               return 0;
  2113.           }
  2114.           umask (mask);
  2115.   
  2116.           rewind (pwfp);
  2117.           while ((c = getc (pwfp)) != EOF) {
  2118. --- 377,390 ----
  2119.       strcat (backup, "-");
  2120.   
  2121.       if (open_modes == O_RDWR && pw_changed) {
  2122. !         mask = umask (0222);
  2123.           if ((bkfp = fopen (backup, "w")) == 0) {
  2124.               umask (mask);
  2125.               return 0;
  2126.           }
  2127.           umask (mask);
  2128. +         fstat (fileno (pwfp), &sb);
  2129. +         chown (backup, sb.st_uid, sb.st_gid);
  2130.   
  2131.           rewind (pwfp);
  2132.           while ((c = getc (pwfp)) != EOF) {
  2133. ***************
  2134. *** 396,402 ****
  2135.           isopen = 0;
  2136.           (void) fclose (pwfp);
  2137.   
  2138. !         mask = umask (022);
  2139.           if (! (pwfp = fopen (pw_filename, "w"))) {
  2140.               umask (mask);
  2141.               return 0;
  2142. --- 399,405 ----
  2143.           isopen = 0;
  2144.           (void) fclose (pwfp);
  2145.   
  2146. !         mask = umask (0222);
  2147.           if (! (pwfp = fopen (pw_filename, "w"))) {
  2148.               umask (mask);
  2149.               return 0;
  2150. ***************
  2151. *** 443,448 ****
  2152. --- 446,452 ----
  2153.           free (pwf);
  2154.       }
  2155.       pwf_tail = 0;
  2156. +     isopen = 0;
  2157.       return 1;
  2158.   }
  2159.   
  2160. Index: chage.c
  2161. *** rel3/chage.c    Tue Jun 25 09:38:02 1991
  2162. --- chage.c    Wed Jun 26 09:43:59 1991
  2163. ***************
  2164. *** 17,23 ****
  2165.   #include <time.h>
  2166.   
  2167.   #ifndef    lint
  2168. ! static    char    sccsid[] = "@(#)chage.c    3.7    06:35:00    5/29/91";
  2169.   #endif
  2170.   
  2171.   /*
  2172. --- 17,23 ----
  2173.   #include <time.h>
  2174.   
  2175.   #ifndef    lint
  2176. ! static    char    sccsid[] = "@(#)chage.c    3.8    09:01:54    6/26/91";
  2177.   #endif
  2178.   
  2179.   /*
  2180. ***************
  2181. *** 406,418 ****
  2182.   char    **argv;
  2183.   {
  2184.       int    flag;
  2185. !     int    lflg;
  2186. !     int    mflg;
  2187. !     int    Mflg;
  2188. !     int    dflg;
  2189. !     int    Wflg;
  2190. !     int    Iflg;
  2191. !     int    Eflg;
  2192.       int    ruid = getuid ();
  2193.       struct    passwd    *pw;
  2194.       struct    passwd    pwent;
  2195. --- 406,418 ----
  2196.   char    **argv;
  2197.   {
  2198.       int    flag;
  2199. !     int    lflg = 0;
  2200. !     int    mflg = 0;
  2201. !     int    Mflg = 0;
  2202. !     int    dflg = 0;
  2203. !     int    Wflg = 0;
  2204. !     int    Iflg = 0;
  2205. !     int    Eflg = 0;
  2206.       int    ruid = getuid ();
  2207.       struct    passwd    *pw;
  2208.       struct    passwd    pwent;
  2209. Index: obscure.c
  2210. *** rel3/obscure.c    Tue Jun 25 09:37:55 1991
  2211. --- obscure.c    Wed Jun 26 09:44:01 1991
  2212. ***************
  2213. *** 21,27 ****
  2214.   #include "config.h"
  2215.   
  2216.   #ifndef    lint
  2217. ! static    char    sccsid[] = "@(#)obscure.c    3.2    09:07:51    5/28/91";
  2218.   #endif
  2219.   
  2220.   #ifdef    NO_STRSTR
  2221. --- 21,27 ----
  2222.   #include "config.h"
  2223.   
  2224.   #ifndef    lint
  2225. ! static    char    sccsid[] = "@(#)obscure.c    3.3    09:05:34    6/26/91";
  2226.   #endif
  2227.   
  2228.   #ifdef    NO_STRSTR
  2229. ***************
  2230. *** 95,101 ****
  2231.       if (similiar (newmono, oldmono))    /* jumbled version */
  2232.           return (0);
  2233.   
  2234. !     if (simple (new, old))            /* keyspace size */
  2235.           return (0);
  2236.   
  2237.       strcpy (wrapped, oldmono);
  2238. --- 95,101 ----
  2239.       if (similiar (newmono, oldmono))    /* jumbled version */
  2240.           return (0);
  2241.   
  2242. !     if (simple (old, new))            /* keyspace size */
  2243.           return (0);
  2244.   
  2245.       strcpy (wrapped, oldmono);
  2246. -- 
  2247. John F. Haugh II        | Distribution to  | UUCP: ...!cs.utexas.edu!rpp386!jfh
  2248. Ma Bell: (512) 255-8251 | GEnie PROHIBITED :-) |  Domain: jfh@rpp386.cactus.org
  2249. "UNIX signals are not interrupts.  Worse, SIGCHLD/SIGCLD is not even a UNIX
  2250.  signal, it's an abomination."  -- Doug Gwyn
  2251.