]> granicus.if.org Git - shadow/blob - src/gpasswd.c
Added the subversion svn:keywords property (Id) for proper identification.
[shadow] / src / gpasswd.c
1 /*
2  * Copyright 1990 - 1994, Julianne Frances Haugh
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of Julianne F. Haugh nor the names of its contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY JULIE HAUGH AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL JULIE HAUGH OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29
30 #include <config.h>
31
32 #ident "$Id$"
33
34 #include <errno.h>
35 #include <fcntl.h>
36 #include <grp.h>
37 #include <pwd.h>
38 #include <signal.h>
39 #include <stdio.h>
40 #include <sys/types.h>
41 #include "defines.h"
42 #include "exitcodes.h"
43 #include "groupio.h"
44 #include "nscd.h"
45 #include "prototypes.h"
46 #ifdef  SHADOWGRP
47 #include "sgroupio.h"
48 #endif
49 /*
50  * Global variables
51  */
52 static char *Prog;
53
54 #ifdef SHADOWGRP
55 static int is_shadowgrp;
56 #endif
57
58 static int
59  aflg = 0, Aflg = 0, dflg = 0, Mflg = 0, rflg = 0, Rflg = 0;
60
61 unsigned int bywho = -1;
62
63 #ifndef RETRIES
64 #define RETRIES 3
65 #endif
66
67 /* local function prototypes */
68 static void usage (void);
69 static RETSIGTYPE catch_signals (int);
70 static int check_list (const char *);
71
72 /*
73  * usage - display usage message
74  */
75 static void usage (void)
76 {
77         fprintf (stderr, _("Usage: %s [-r|-R] group\n"), Prog);
78         fprintf (stderr, _("       %s [-a user] group\n"), Prog);
79         fprintf (stderr, _("       %s [-d user] group\n"), Prog);
80 #ifdef  SHADOWGRP
81         fprintf (stderr,
82                  _("       %s [-A user,...] [-M user,...] group\n"), Prog);
83 #else
84         fprintf (stderr, _("       %s [-M user,...] group\n"), Prog);
85 #endif
86         exit (E_USAGE);
87 }
88
89 /*
90  * catch_signals - set or reset termio modes.
91  *
92  *      catch_signals() is called before processing begins. signal() is then
93  *      called with catch_signals() as the signal handler. If signal later
94  *      calls catch_signals() with a signal number, the terminal modes are
95  *      then reset.
96  */
97 static RETSIGTYPE catch_signals (int killed)
98 {
99         static TERMIO sgtty;
100
101         if (killed)
102                 STTY (0, &sgtty);
103         else
104                 GTTY (0, &sgtty);
105
106         if (killed) {
107                 putchar ('\n');
108                 fflush (stdout);
109                 exit (killed);
110         }
111 }
112
113 /*
114  * check_list - check a comma-separated list of user names for validity
115  *
116  *      check_list scans a comma-separated list of user names and checks
117  *      that each listed name exists.
118  */
119 static int check_list (const char *users)
120 {
121         const char *start, *end;
122         char username[32];
123         int errors = 0;
124         int len;
125
126         for (start = users; start && *start; start = end) {
127                 if ((end = strchr (start, ','))) {
128                         len = end - start;
129                         end++;
130                 } else {
131                         len = strlen (start);
132                 }
133
134                 if (len > sizeof (username) - 1)
135                         len = sizeof (username) - 1;
136                 strncpy (username, start, len);
137                 username[len] = '\0';
138
139                 /*
140                  * This user must exist.
141                  */
142
143                 if (!getpwnam (username)) {
144                         fprintf (stderr, _("%s: unknown user %s\n"),
145                                  Prog, username);
146                         errors++;
147                 }
148         }
149         return errors;
150 }
151
152 static void failure (void)
153 {
154         fprintf (stderr, _("%s: Permission denied.\n"), Prog);
155         exit (1);
156 }
157
158 /*
159  * gpasswd - administer the /etc/group file
160  *
161  *      -a user         add user to the named group
162  *      -d user         remove user from the named group
163  *      -r              remove password from the named group
164  *      -R              restrict access to the named group
165  *      -A user,...     make list of users the administrative users
166  *      -M user,...     make list of users the group members
167  */
168 int main (int argc, char **argv)
169 {
170         int flag;
171         char *cp;
172         int amroot;
173         int retries;
174         struct group *gr = NULL;
175         struct group grent;
176         static char pass[BUFSIZ];
177
178 #ifdef  SHADOWGRP
179         struct sgrp *sg = NULL;
180         struct sgrp sgent;
181         char *admins = NULL;
182 #endif
183         struct passwd *pw = NULL;
184         char *myname;
185         char *user = NULL;
186         char *group = NULL;
187         char *members = NULL;
188
189 #ifdef WITH_AUDIT
190         audit_help_open ();
191 #endif
192
193         sanitize_env ();
194         setlocale (LC_ALL, "");
195         bindtextdomain (PACKAGE, LOCALEDIR);
196         textdomain (PACKAGE);
197
198         /*
199          * Make a note of whether or not this command was invoked by root.
200          * This will be used to bypass certain checks later on. Also, set
201          * the real user ID to match the effective user ID. This will
202          * prevent the invoker from issuing signals which would interfer
203          * with this command.
204          */
205         amroot = getuid () == 0;
206         bywho = getuid ();
207         Prog = Basename (argv[0]);
208
209         OPENLOG ("gpasswd");
210         setbuf (stdout, NULL);
211         setbuf (stderr, NULL);
212
213 #ifdef SHADOWGRP
214         is_shadowgrp = sgr_file_present ();
215 #endif
216         while ((flag = getopt (argc, argv, "a:A:d:gM:rR")) != EOF) {
217                 switch (flag) {
218                 case 'a':       /* add a user */
219                         user = optarg;
220                         if (!getpwnam (user)) {
221                                 fprintf (stderr,
222                                          _("%s: unknown user %s\n"), Prog,
223                                          user);
224 #ifdef WITH_AUDIT
225                                 audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
226                                               "adding to group", user, -1, 0);
227 #endif
228                                 exit (1);
229                         }
230                         aflg++;
231                         break;
232 #ifdef SHADOWGRP
233                 case 'A':
234                         if (!amroot) {
235 #ifdef WITH_AUDIT
236                                 audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
237                                               "Listing administrators", NULL,
238                                               bywho, 0);
239 #endif
240                                 failure ();
241                         }
242                         if (!is_shadowgrp) {
243                                 fprintf (stderr,
244                                          _
245                                          ("%s: shadow group passwords required for -A\n"),
246                                          Prog);
247                                 exit (2);
248                         }
249                         admins = optarg;
250                         if (check_list (admins))
251                                 exit (1);
252                         Aflg++;
253                         break;
254 #endif
255                 case 'd':       /* delete a user */
256                         dflg++;
257                         user = optarg;
258                         break;
259                 case 'g':       /* no-op from normal password */
260                         break;
261                 case 'M':
262                         if (!amroot) {
263 #ifdef WITH_AUDIT
264                                 audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
265                                               "listing members", NULL, bywho,
266                                               0);
267 #endif
268                                 failure ();
269                         }
270                         members = optarg;
271                         if (check_list (members))
272                                 exit (1);
273                         Mflg++;
274                         break;
275                 case 'r':       /* remove group password */
276                         rflg++;
277                         break;
278                 case 'R':       /* restrict group password */
279                         Rflg++;
280                         break;
281                 default:
282                         usage ();
283                 }
284         }
285
286         /*
287          * Make sure exclusive flags are exclusive
288          */
289
290         if (aflg + dflg + rflg + Rflg + (Aflg || Mflg) > 1)
291                 usage ();
292
293         /*
294          * Determine the name of the user that invoked this command. This
295          * is really hit or miss because there are so many ways that command
296          * can be executed and so many ways to trip up the routines that
297          * report the user name.
298          */
299
300         pw = get_my_pwent ();
301         if (!pw) {
302                 fprintf (stderr, _("Who are you?\n"));
303 #ifdef WITH_AUDIT
304                 audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "user lookup", NULL,
305                               bywho, 0);
306 #endif
307                 failure ();
308         }
309         myname = xstrdup (pw->pw_name);
310
311         /*
312          * Get the name of the group that is being affected. The group entry
313          * will be completely replicated so it may be modified later on.
314          */
315
316         /*
317          * XXX - should get the entry using gr_locate() and modify that,
318          * getgrnam() could give us a NIS group.  --marekm
319          */
320         if (!(group = argv[optind]))
321                 usage ();
322
323         if (!(gr = getgrnam (group))) {
324                 fprintf (stderr, _("unknown group: %s\n"), group);
325 #ifdef WITH_AUDIT
326                 audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "group lookup", group,
327                               -1, 0);
328 #endif
329                 failure ();
330         }
331         grent = *gr;
332         grent.gr_name = xstrdup (gr->gr_name);
333         grent.gr_passwd = xstrdup (gr->gr_passwd);
334
335         grent.gr_mem = dup_list (gr->gr_mem);
336 #ifdef  SHADOWGRP
337         if ((sg = getsgnam (group))) {
338                 sgent = *sg;
339                 sgent.sg_name = xstrdup (sg->sg_name);
340                 sgent.sg_passwd = xstrdup (sg->sg_passwd);
341
342                 sgent.sg_mem = dup_list (sg->sg_mem);
343                 sgent.sg_adm = dup_list (sg->sg_adm);
344         } else {
345                 sgent.sg_name = xstrdup (group);
346                 sgent.sg_passwd = grent.gr_passwd;
347                 grent.gr_passwd = "!";  /* XXX warning: const */
348
349                 sgent.sg_mem = dup_list (grent.gr_mem);
350
351                 sgent.sg_adm = (char **) xmalloc (sizeof (char *) * 2);
352 #ifdef FIRST_MEMBER_IS_ADMIN
353                 if (sgent.sg_mem[0]) {
354                         sgent.sg_adm[0] = xstrdup (sgent.sg_mem[0]);
355                         sgent.sg_adm[1] = 0;
356                 } else
357 #endif
358                         sgent.sg_adm[0] = 0;
359
360                 sg = &sgent;
361         }
362
363         /*
364          * The policy here for changing a group is that 1) you must be root
365          * or 2). you must be listed as an administrative member. 
366          * Administrative members can do anything to a group that the root
367          * user can.
368          */
369         if (!amroot && !is_on_list (sgent.sg_adm, myname)) {
370 #ifdef WITH_AUDIT
371                 audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "modify group", group,
372                               -1, 0);
373 #endif
374                 failure ();
375         }
376 #else                           /* ! SHADOWGRP */
377
378 #ifdef FIRST_MEMBER_IS_ADMIN
379         /*
380          * The policy here for changing a group is that 1) you must bes root
381          * or 2) you must be the first listed member of the group. The
382          * first listed member of a group can do anything to that group that
383          * the root user can. The rationale for this hack is that the FIRST
384          * user is probably the most important user in this entire group.
385          */
386         if (!amroot) {
387                 if (grent.gr_mem[0] == (char *) 0) {
388 #ifdef WITH_AUDIT
389                         audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
390                                       "modifying group", group, -1, 0);
391 #endif
392                         failure ();
393                 }
394
395                 if (strcmp (grent.gr_mem[0], myname) != 0) {
396 #ifdef WITH_AUDIT
397                         audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
398                                       "modifying group", myname, -1, 0);
399 #endif
400                         failure ();
401                 }
402         }
403 #else
404         /*
405          * This feature enabled by default could be a security problem when
406          * installed on existing systems where the first group member might
407          * be just a normal user.  --marekm
408          */
409         if (!amroot) {
410 #ifdef WITH_AUDIT
411                 audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "modifying group",
412                               group, -1, 0);
413 #endif
414                 failure ();
415         }
416 #endif
417
418 #endif                          /* SHADOWGRP */
419
420         /*
421          * Removing a password is straight forward. Just set the password
422          * field to a "".
423          */
424         if (rflg) {
425                 grent.gr_passwd = "";   /* XXX warning: const */
426 #ifdef  SHADOWGRP
427                 sgent.sg_passwd = "";   /* XXX warning: const */
428 #endif
429 #ifdef WITH_AUDIT
430                 audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
431                               "deleting group password", group, -1, 1);
432 #endif
433                 SYSLOG ((LOG_INFO, "remove password from group %s by %s",
434                          group, myname));
435                 goto output;
436         } else if (Rflg) {
437                 /*
438                  * Same thing for restricting the group. Set the password
439                  * field to "!".
440                  */
441                 grent.gr_passwd = "!";  /* XXX warning: const */
442 #ifdef  SHADOWGRP
443                 sgent.sg_passwd = "!";  /* XXX warning: const */
444 #endif
445 #ifdef WITH_AUDIT
446                 audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
447                               "restrict access to group", group, -1, 1);
448 #endif
449                 SYSLOG ((LOG_INFO, "restrict access to group %s by %s",
450                          group, myname));
451                 goto output;
452         }
453
454         /*
455          * Adding a member to a member list is pretty straightforward as
456          * well. Call the appropriate routine and split.
457          */
458         if (aflg) {
459                 printf (_("Adding user %s to group %s\n"), user, group);
460                 grent.gr_mem = add_list (grent.gr_mem, user);
461 #ifdef  SHADOWGRP
462                 sgent.sg_mem = add_list (sgent.sg_mem, user);
463 #endif
464 #ifdef WITH_AUDIT
465                 audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "adding group member",
466                               user, -1, 1);
467 #endif
468                 SYSLOG ((LOG_INFO, "add member %s to group %s by %s", user,
469                          group, myname));
470                 goto output;
471         }
472
473         /*
474          * Removing a member from the member list is the same deal as adding
475          * one, except the routine is different.
476          */
477         if (dflg) {
478                 int removed = 0;
479
480                 printf (_("Removing user %s from group %s\n"), user, group);
481
482                 if (is_on_list (grent.gr_mem, user)) {
483                         removed = 1;
484                         grent.gr_mem = del_list (grent.gr_mem, user);
485                 }
486 #ifdef  SHADOWGRP
487                 if (is_on_list (sgent.sg_mem, user)) {
488                         removed = 1;
489                         sgent.sg_mem = del_list (sgent.sg_mem, user);
490                 }
491 #endif
492                 if (!removed) {
493                         fprintf (stderr, _("%s: unknown member %s\n"),
494                                  Prog, user);
495 #ifdef WITH_AUDIT
496                         audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
497                                       "deleting member", user, -1, 0);
498 #endif
499                         exit (1);
500                 }
501 #ifdef WITH_AUDIT
502                 audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "deleting member",
503                               user, -1, 1);
504 #endif
505                 SYSLOG ((LOG_INFO, "remove member %s from group %s by %s",
506                          user, group, myname));
507                 goto output;
508         }
509 #ifdef  SHADOWGRP
510         /*
511          * Replacing the entire list of administators is simple. Check the
512          * list to make sure everyone is a real user. Then slap the new list
513          * in place.
514          */
515         if (Aflg) {
516 #ifdef WITH_AUDIT
517                 audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "setting group admin",
518                               group, -1, 1);
519 #endif
520                 SYSLOG ((LOG_INFO, "set administrators of %s to %s",
521                          group, admins));
522                 sgent.sg_adm = comma_to_list (admins);
523                 if (!Mflg)
524                         goto output;
525         }
526 #endif
527
528         /*
529          * Replacing the entire list of members is simple. Check the list to
530          * make sure everyone is a real user. Then slap the new list in
531          * place.
532          */
533         if (Mflg) {
534 #ifdef WITH_AUDIT
535                 audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
536                               "setting group members", group, -1, 1);
537 #endif
538                 SYSLOG ((LOG_INFO, "set members of %s to %s", group, members));
539 #ifdef SHADOWGRP
540                 sgent.sg_mem = comma_to_list (members);
541 #endif
542                 grent.gr_mem = comma_to_list (members);
543                 goto output;
544         }
545
546         /*
547          * If the password is being changed, the input and output must both
548          * be a tty. The typical keyboard signals are caught so the termio
549          * modes can be restored.
550          */
551         if (!isatty (0) || !isatty (1)) {
552                 fprintf (stderr, _("%s: Not a tty\n"), Prog);
553 #ifdef WITH_AUDIT
554                 audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "changing password",
555                               group, -1, 0);
556 #endif
557                 exit (1);
558         }
559
560         catch_signals (0);      /* save tty modes */
561
562         signal (SIGHUP, catch_signals);
563         signal (SIGINT, catch_signals);
564         signal (SIGQUIT, catch_signals);
565         signal (SIGTERM, catch_signals);
566 #ifdef  SIGTSTP
567         signal (SIGTSTP, catch_signals);
568 #endif
569
570         /*
571          * A new password is to be entered and it must be encrypted, etc.
572          * The password will be prompted for twice, and both entries must be
573          * identical. There is no need to validate the old password since
574          * the invoker is either the group owner, or root.
575          */
576         printf (_("Changing the password for group %s\n"), group);
577
578         for (retries = 0; retries < RETRIES; retries++) {
579                 if (!(cp = getpass (_("New Password: "))))
580                         exit (1);
581
582                 STRFCPY (pass, cp);
583                 strzero (cp);
584                 if (!(cp = getpass (_("Re-enter new password: "))))
585                         exit (1);
586
587                 if (strcmp (pass, cp) == 0) {
588                         strzero (cp);
589                         break;
590                 }
591
592                 strzero (cp);
593                 memzero (pass, sizeof pass);
594
595                 if (retries + 1 < RETRIES) {
596                         puts (_("They don't match; try again"));
597 #ifdef WITH_AUDIT
598                         audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
599                                       "changing password", group, -1, 0);
600 #endif
601                 }
602         }
603
604         if (retries == RETRIES) {
605                 fprintf (stderr, _("%s: Try again later\n"), Prog);
606                 exit (1);
607         }
608
609         cp = pw_encrypt (pass, crypt_make_salt ());
610         memzero (pass, sizeof pass);
611 #ifdef SHADOWGRP
612         if (is_shadowgrp)
613                 sgent.sg_passwd = cp;
614         else
615 #endif
616                 grent.gr_passwd = cp;
617 #ifdef WITH_AUDIT
618         audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "changing password", group,
619                       -1, 1);
620 #endif
621         SYSLOG ((LOG_INFO, "change the password for group %s by %s", group,
622                  myname));
623
624         /*
625          * This is the common arrival point to output the new group file.
626          * The freshly crafted entry is in allocated space. The group file
627          * will be locked and opened for writing. The new entry will be
628          * output, etc.
629          */
630       output:
631         if (setuid (0)) {
632                 fprintf (stderr, _("Cannot change ID to root.\n"));
633                 SYSLOG ((LOG_ERR, "can't setuid(0)"));
634 #ifdef WITH_AUDIT
635                 audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "changing id to root",
636                               group, -1, 0);
637 #endif
638                 closelog ();
639                 exit (1);
640         }
641         pwd_init ();
642
643         if (!gr_lock ()) {
644                 fprintf (stderr, _("%s: can't get lock\n"), Prog);
645                 SYSLOG ((LOG_WARN, "failed to get lock for /etc/group"));
646 #ifdef WITH_AUDIT
647                 audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "locking /etc/group",
648                               group, -1, 0);
649 #endif
650                 exit (1);
651         }
652 #ifdef  SHADOWGRP
653         if (is_shadowgrp && !sgr_lock ()) {
654                 fprintf (stderr, _("%s: can't get shadow lock\n"), Prog);
655                 SYSLOG ((LOG_WARN, "failed to get lock for /etc/gshadow"));
656 #ifdef WITH_AUDIT
657                 audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
658                               "locking /etc/gshadow", group, -1, 0);
659 #endif
660                 exit (1);
661         }
662 #endif
663         if (!gr_open (O_RDWR)) {
664                 fprintf (stderr, _("%s: can't open file\n"), Prog);
665                 SYSLOG ((LOG_WARN, "cannot open /etc/group"));
666 #ifdef WITH_AUDIT
667                 audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "opening /etc/group",
668                               group, -1, 0);
669 #endif
670                 exit (1);
671         }
672 #ifdef  SHADOWGRP
673         if (is_shadowgrp && !sgr_open (O_RDWR)) {
674                 fprintf (stderr, _("%s: can't open shadow file\n"), Prog);
675                 SYSLOG ((LOG_WARN, "cannot open /etc/gshadow"));
676 #ifdef WITH_AUDIT
677                 audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
678                               "opening /etc/gshadow", group, -1, 0);
679 #endif
680                 exit (1);
681         }
682 #endif
683         if (!gr_update (&grent)) {
684                 fprintf (stderr, _("%s: can't update entry\n"), Prog);
685                 SYSLOG ((LOG_WARN, "cannot update /etc/group"));
686 #ifdef WITH_AUDIT
687                 audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "updating /etc/group",
688                               group, -1, 0);
689 #endif
690                 exit (1);
691         }
692 #ifdef  SHADOWGRP
693         if (is_shadowgrp && !sgr_update (&sgent)) {
694                 fprintf (stderr, _("%s: can't update shadow entry\n"), Prog);
695                 SYSLOG ((LOG_WARN, "cannot update /etc/gshadow"));
696 #ifdef WITH_AUDIT
697                 audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
698                               "updating /etc/gshadow", group, -1, 0);
699 #endif
700                 exit (1);
701         }
702 #endif
703         if (!gr_close ()) {
704                 fprintf (stderr, _("%s: can't re-write file\n"), Prog);
705                 SYSLOG ((LOG_WARN, "cannot re-write /etc/group"));
706 #ifdef WITH_AUDIT
707                 audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
708                               "rewriting /etc/group", group, -1, 0);
709 #endif
710                 exit (1);
711         }
712 #ifdef  SHADOWGRP
713         if (is_shadowgrp && !sgr_close ()) {
714                 fprintf (stderr, _("%s: can't re-write shadow file\n"), Prog);
715                 SYSLOG ((LOG_WARN, "cannot re-write /etc/gshadow"));
716 #ifdef WITH_AUDIT
717                 audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
718                               "rewriting /etc/gshadow", group, -1, 0);
719 #endif
720                 exit (1);
721         }
722         if (is_shadowgrp)
723                 sgr_unlock ();
724 #endif
725         if (!gr_unlock ()) {
726                 fprintf (stderr, _("%s: can't unlock file\n"), Prog);
727 #ifdef WITH_AUDIT
728                 audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
729                               "unlocking group file", group, -1, 0);
730 #endif
731                 exit (1);
732         }
733
734         nscd_flush_cache ("group");
735
736         exit (E_SUCCESS);
737 }