2007-10-07 17:14:02 +05:30
|
|
|
/*
|
|
|
|
* Copyright 1990 - 1994, Julianne Frances Haugh
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of Julianne F. Haugh nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY JULIE HAUGH AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
2007-10-07 17:14:59 +05:30
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL JULIE HAUGH OR CONTRIBUTORS BE LIABLE
|
2007-10-07 17:14:02 +05:30
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-11-11 05:16:11 +05:30
|
|
|
#ident "$Id$"
|
2007-10-07 17:17:01 +05:30
|
|
|
|
2007-10-07 17:16:52 +05:30
|
|
|
#include <errno.h>
|
2007-10-07 17:14:02 +05:30
|
|
|
#include <fcntl.h>
|
2007-10-07 17:16:52 +05:30
|
|
|
#include <grp.h>
|
|
|
|
#include <pwd.h>
|
2007-10-07 17:14:02 +05:30
|
|
|
#include <signal.h>
|
2007-10-07 17:16:52 +05:30
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/types.h>
|
2007-10-07 17:14:02 +05:30
|
|
|
#include "defines.h"
|
2007-10-07 17:16:52 +05:30
|
|
|
#include "exitcodes.h"
|
2007-10-07 17:14:02 +05:30
|
|
|
#include "groupio.h"
|
2007-10-07 17:17:22 +05:30
|
|
|
#include "nscd.h"
|
2007-10-07 17:16:52 +05:30
|
|
|
#include "prototypes.h"
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef SHADOWGRP
|
|
|
|
#include "sgroupio.h"
|
|
|
|
#endif
|
2007-10-07 17:17:01 +05:30
|
|
|
/*
|
|
|
|
* Global variables
|
|
|
|
*/
|
2007-10-07 17:14:02 +05:30
|
|
|
static char *Prog;
|
2007-10-07 17:14:59 +05:30
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef SHADOWGRP
|
|
|
|
static int is_shadowgrp;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int
|
2007-10-07 17:14:59 +05:30
|
|
|
aflg = 0, Aflg = 0, dflg = 0, Mflg = 0, rflg = 0, Rflg = 0;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:17:01 +05:30
|
|
|
unsigned int bywho = -1;
|
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifndef RETRIES
|
|
|
|
#define RETRIES 3
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* local function prototypes */
|
2007-10-07 17:14:59 +05:30
|
|
|
static void usage (void);
|
2007-10-07 17:17:22 +05:30
|
|
|
static RETSIGTYPE catch_signals (int);
|
2007-10-07 17:14:59 +05:30
|
|
|
static int check_list (const char *);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* usage - display usage message
|
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
static void usage (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:15:23 +05:30
|
|
|
fprintf (stderr, _("Usage: %s [-r|-R] group\n"), Prog);
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr, _(" %s [-a user] group\n"), Prog);
|
|
|
|
fprintf (stderr, _(" %s [-d user] group\n"), Prog);
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef SHADOWGRP
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr,
|
|
|
|
_(" %s [-A user,...] [-M user,...] group\n"), Prog);
|
2007-10-07 17:14:02 +05:30
|
|
|
#else
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr, _(" %s [-M user,...] group\n"), Prog);
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
2007-10-07 17:16:52 +05:30
|
|
|
exit (E_USAGE);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:17:22 +05:30
|
|
|
* catch_signals - set or reset termio modes.
|
2007-10-07 17:14:02 +05:30
|
|
|
*
|
2007-10-07 17:17:22 +05:30
|
|
|
* catch_signals() is called before processing begins. signal() is then
|
|
|
|
* called with catch_signals() as the signal handler. If signal later
|
|
|
|
* calls catch_signals() with a signal number, the terminal modes are
|
|
|
|
* then reset.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-10-07 17:17:22 +05:30
|
|
|
static RETSIGTYPE catch_signals (int killed)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
static TERMIO sgtty;
|
|
|
|
|
|
|
|
if (killed)
|
2007-10-07 17:14:59 +05:30
|
|
|
STTY (0, &sgtty);
|
2007-10-07 17:14:02 +05:30
|
|
|
else
|
2007-10-07 17:14:59 +05:30
|
|
|
GTTY (0, &sgtty);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
if (killed) {
|
|
|
|
putchar ('\n');
|
|
|
|
fflush (stdout);
|
|
|
|
exit (killed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* check_list - check a comma-separated list of user names for validity
|
|
|
|
*
|
|
|
|
* check_list scans a comma-separated list of user names and checks
|
|
|
|
* that each listed name exists.
|
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
static int check_list (const char *users)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
const char *start, *end;
|
|
|
|
char username[32];
|
2007-10-07 17:14:59 +05:30
|
|
|
int errors = 0;
|
|
|
|
int len;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
for (start = users; start && *start; start = end) {
|
|
|
|
if ((end = strchr (start, ','))) {
|
|
|
|
len = end - start;
|
|
|
|
end++;
|
|
|
|
} else {
|
2007-10-07 17:14:59 +05:30
|
|
|
len = strlen (start);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (len > sizeof (username) - 1)
|
|
|
|
len = sizeof (username) - 1;
|
|
|
|
strncpy (username, start, len);
|
2007-10-07 17:14:02 +05:30
|
|
|
username[len] = '\0';
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This user must exist.
|
|
|
|
*/
|
|
|
|
|
* lib/prototypes.h, configure.in, libmisc/Makefile.am,
libmisc/xgetXXbyYY.c, libmisc/xgetpwnam.c, libmisc/xgetpwuid.c,
libmisc/xgetgrnam.c, libmisc/xgetgrgid.c, libmisc/xgetspnam.c:
Added functions xgetpwnam(), xgetpwuid(), xgetgrnam(),
xgetgrgid(), and xgetspnam(). They allocate memory for the
returned structure and are more robust to successive calls. They
are implemented with the libc's getxxyyy_r() functions if
available.
* libmisc/limits.c, libmisc/entry.c, libmisc/chowntty.c,
libmisc/addgrps.c, libmisc/myname.c, libmisc/rlogin.c,
libmisc/pwdcheck.c, src/newgrp.c, src/login_nopam.c,
src/userdel.c, src/lastlog.c, src/grpck.c, src/gpasswd.c,
src/newusers.c, src/chpasswd.c, src/chfn.c, src/groupmems.c,
src/usermod.c, src/expiry.c, src/groupdel.c, src/chgpasswd.c,
src/su.c, src/useradd.c, src/groupmod.c, src/passwd.c, src/pwck.c,
src/groupadd.c, src/chage.c, src/login.c, src/suauth.c,
src/faillog.c, src/groups.c, src/chsh.c, src/id.c: Review all the
usage of one of the getpwnam(), getpwuid(), getgrnam(),
getgrgid(), and getspnam() functions. It was noticed on
http://bugs.debian.org/341230 that chfn and chsh use a passwd
structure after calling a pam function, which result in using
information from the passwd structure requested by pam, not the
original one. It is much easier to use the new xget... functions
to avoid these issues. I've checked which call to the original
get... functions could be left (reducing the scope of the
structure if possible), and I've left comments to ease future
reviews (e.g. /* local, no need for xgetpwnam */).
Note: the getpwent/getgrent calls should probably be checked also.
* src/groupdel.c, src/expiry.c: Fix typos in comments.
* src/groupmod.c: Re-indent.
* libmisc/Makefile.am, lib/groupmem.c, lib/groupio.c, lib/pwmem.c,
lib/pwio.c, lib/shadowmem.c, lib/shadowio.c: Move the __<xx>_dup
functions (used by the xget... functions) from the <xx>io.c files
to the new <xx>mem.c files. This avoid linking some utils against
the SELinux library.
2007-11-19 04:45:26 +05:30
|
|
|
if (!getpwnam (username)) { /* local, no need for xgetpwnam */
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr, _("%s: unknown user %s\n"),
|
|
|
|
Prog, username);
|
2007-10-07 17:14:02 +05:30
|
|
|
errors++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return errors;
|
|
|
|
}
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
static void failure (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:25 +05:30
|
|
|
fprintf (stderr, _("%s: Permission denied.\n"), Prog);
|
2007-10-07 17:14:59 +05:30
|
|
|
exit (1);
|
2007-10-07 17:17:01 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* gpasswd - administer the /etc/group file
|
|
|
|
*
|
|
|
|
* -a user add user to the named group
|
|
|
|
* -d user remove user from the named group
|
|
|
|
* -r remove password from the named group
|
|
|
|
* -R restrict access to the named group
|
|
|
|
* -A user,... make list of users the administrative users
|
|
|
|
* -M user,... make list of users the group members
|
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
int main (int argc, char **argv)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:14:59 +05:30
|
|
|
int flag;
|
|
|
|
char *cp;
|
|
|
|
int amroot;
|
|
|
|
int retries;
|
2007-10-07 17:14:02 +05:30
|
|
|
struct group *gr = NULL;
|
2007-10-07 17:14:59 +05:30
|
|
|
struct group grent;
|
2007-10-07 17:14:02 +05:30
|
|
|
static char pass[BUFSIZ];
|
2007-10-07 17:14:59 +05:30
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef SHADOWGRP
|
|
|
|
struct sgrp *sg = NULL;
|
2007-10-07 17:14:59 +05:30
|
|
|
struct sgrp sgent;
|
2007-10-07 17:14:02 +05:30
|
|
|
char *admins = NULL;
|
|
|
|
#endif
|
|
|
|
struct passwd *pw = NULL;
|
|
|
|
char *myname;
|
|
|
|
char *user = NULL;
|
|
|
|
char *group = NULL;
|
|
|
|
char *members = NULL;
|
|
|
|
|
2007-10-07 17:17:01 +05:30
|
|
|
#ifdef WITH_AUDIT
|
|
|
|
audit_help_open ();
|
|
|
|
#endif
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
sanitize_env ();
|
|
|
|
setlocale (LC_ALL, "");
|
|
|
|
bindtextdomain (PACKAGE, LOCALEDIR);
|
|
|
|
textdomain (PACKAGE);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Make a note of whether or not this command was invoked by root.
|
|
|
|
* This will be used to bypass certain checks later on. Also, set
|
|
|
|
* the real user ID to match the effective user ID. This will
|
|
|
|
* prevent the invoker from issuing signals which would interfer
|
|
|
|
* with this command.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
amroot = getuid () == 0;
|
2007-10-07 17:17:01 +05:30
|
|
|
bywho = getuid ();
|
2007-10-07 17:14:59 +05:30
|
|
|
Prog = Basename (argv[0]);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
OPENLOG ("gpasswd");
|
|
|
|
setbuf (stdout, NULL);
|
|
|
|
setbuf (stderr, NULL);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
#ifdef SHADOWGRP
|
2007-10-07 17:14:59 +05:30
|
|
|
is_shadowgrp = sgr_file_present ();
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
2007-10-07 17:16:34 +05:30
|
|
|
while ((flag = getopt (argc, argv, "a:A:d:gM:rR")) != EOF) {
|
2007-10-07 17:14:02 +05:30
|
|
|
switch (flag) {
|
|
|
|
case 'a': /* add a user */
|
|
|
|
user = optarg;
|
* lib/prototypes.h, configure.in, libmisc/Makefile.am,
libmisc/xgetXXbyYY.c, libmisc/xgetpwnam.c, libmisc/xgetpwuid.c,
libmisc/xgetgrnam.c, libmisc/xgetgrgid.c, libmisc/xgetspnam.c:
Added functions xgetpwnam(), xgetpwuid(), xgetgrnam(),
xgetgrgid(), and xgetspnam(). They allocate memory for the
returned structure and are more robust to successive calls. They
are implemented with the libc's getxxyyy_r() functions if
available.
* libmisc/limits.c, libmisc/entry.c, libmisc/chowntty.c,
libmisc/addgrps.c, libmisc/myname.c, libmisc/rlogin.c,
libmisc/pwdcheck.c, src/newgrp.c, src/login_nopam.c,
src/userdel.c, src/lastlog.c, src/grpck.c, src/gpasswd.c,
src/newusers.c, src/chpasswd.c, src/chfn.c, src/groupmems.c,
src/usermod.c, src/expiry.c, src/groupdel.c, src/chgpasswd.c,
src/su.c, src/useradd.c, src/groupmod.c, src/passwd.c, src/pwck.c,
src/groupadd.c, src/chage.c, src/login.c, src/suauth.c,
src/faillog.c, src/groups.c, src/chsh.c, src/id.c: Review all the
usage of one of the getpwnam(), getpwuid(), getgrnam(),
getgrgid(), and getspnam() functions. It was noticed on
http://bugs.debian.org/341230 that chfn and chsh use a passwd
structure after calling a pam function, which result in using
information from the passwd structure requested by pam, not the
original one. It is much easier to use the new xget... functions
to avoid these issues. I've checked which call to the original
get... functions could be left (reducing the scope of the
structure if possible), and I've left comments to ease future
reviews (e.g. /* local, no need for xgetpwnam */).
Note: the getpwent/getgrent calls should probably be checked also.
* src/groupdel.c, src/expiry.c: Fix typos in comments.
* src/groupmod.c: Re-indent.
* libmisc/Makefile.am, lib/groupmem.c, lib/groupio.c, lib/pwmem.c,
lib/pwio.c, lib/shadowmem.c, lib/shadowio.c: Move the __<xx>_dup
functions (used by the xget... functions) from the <xx>io.c files
to the new <xx>mem.c files. This avoid linking some utils against
the SELinux library.
2007-11-19 04:45:26 +05:30
|
|
|
/* local, no need for xgetpwnam */
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!getpwnam (user)) {
|
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: unknown user %s\n"), Prog,
|
|
|
|
user);
|
2007-10-07 17:17:01 +05:30
|
|
|
#ifdef WITH_AUDIT
|
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
|
|
|
"adding to group", user, -1, 0);
|
|
|
|
#endif
|
2007-10-07 17:14:59 +05:30
|
|
|
exit (1);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
aflg++;
|
|
|
|
break;
|
|
|
|
#ifdef SHADOWGRP
|
|
|
|
case 'A':
|
2007-10-07 17:17:01 +05:30
|
|
|
if (!amroot) {
|
|
|
|
#ifdef WITH_AUDIT
|
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
|
|
|
"Listing administrators", NULL,
|
|
|
|
bywho, 0);
|
|
|
|
#endif
|
2007-10-07 17:14:59 +05:30
|
|
|
failure ();
|
2007-10-07 17:17:01 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
if (!is_shadowgrp) {
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr,
|
|
|
|
_
|
|
|
|
("%s: shadow group passwords required for -A\n"),
|
|
|
|
Prog);
|
|
|
|
exit (2);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
admins = optarg;
|
2007-10-07 17:14:59 +05:30
|
|
|
if (check_list (admins))
|
|
|
|
exit (1);
|
2007-10-07 17:14:02 +05:30
|
|
|
Aflg++;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case 'd': /* delete a user */
|
|
|
|
dflg++;
|
|
|
|
user = optarg;
|
|
|
|
break;
|
|
|
|
case 'g': /* no-op from normal password */
|
|
|
|
break;
|
|
|
|
case 'M':
|
2007-10-07 17:17:01 +05:30
|
|
|
if (!amroot) {
|
|
|
|
#ifdef WITH_AUDIT
|
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
|
|
|
"listing members", NULL, bywho,
|
|
|
|
0);
|
|
|
|
#endif
|
2007-10-07 17:14:59 +05:30
|
|
|
failure ();
|
2007-10-07 17:17:01 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
members = optarg;
|
2007-10-07 17:14:59 +05:30
|
|
|
if (check_list (members))
|
|
|
|
exit (1);
|
2007-10-07 17:14:02 +05:30
|
|
|
Mflg++;
|
|
|
|
break;
|
|
|
|
case 'r': /* remove group password */
|
|
|
|
rflg++;
|
|
|
|
break;
|
|
|
|
case 'R': /* restrict group password */
|
|
|
|
Rflg++;
|
|
|
|
break;
|
|
|
|
default:
|
2007-10-07 17:14:59 +05:30
|
|
|
usage ();
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure exclusive flags are exclusive
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (aflg + dflg + rflg + Rflg + (Aflg || Mflg) > 1)
|
|
|
|
usage ();
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Determine the name of the user that invoked this command. This
|
|
|
|
* is really hit or miss because there are so many ways that command
|
|
|
|
* can be executed and so many ways to trip up the routines that
|
|
|
|
* report the user name.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
pw = get_my_pwent ();
|
2007-10-07 17:14:02 +05:30
|
|
|
if (!pw) {
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr, _("Who are you?\n"));
|
2007-10-07 17:17:01 +05:30
|
|
|
#ifdef WITH_AUDIT
|
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "user lookup", NULL,
|
|
|
|
bywho, 0);
|
|
|
|
#endif
|
|
|
|
failure ();
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
myname = xstrdup (pw->pw_name);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Get the name of the group that is being affected. The group entry
|
|
|
|
* will be completely replicated so it may be modified later on.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* XXX - should get the entry using gr_locate() and modify that,
|
|
|
|
* getgrnam() could give us a NIS group. --marekm
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!(group = argv[optind]))
|
2007-10-07 17:14:02 +05:30
|
|
|
usage ();
|
|
|
|
|
* lib/prototypes.h, configure.in, libmisc/Makefile.am,
libmisc/xgetXXbyYY.c, libmisc/xgetpwnam.c, libmisc/xgetpwuid.c,
libmisc/xgetgrnam.c, libmisc/xgetgrgid.c, libmisc/xgetspnam.c:
Added functions xgetpwnam(), xgetpwuid(), xgetgrnam(),
xgetgrgid(), and xgetspnam(). They allocate memory for the
returned structure and are more robust to successive calls. They
are implemented with the libc's getxxyyy_r() functions if
available.
* libmisc/limits.c, libmisc/entry.c, libmisc/chowntty.c,
libmisc/addgrps.c, libmisc/myname.c, libmisc/rlogin.c,
libmisc/pwdcheck.c, src/newgrp.c, src/login_nopam.c,
src/userdel.c, src/lastlog.c, src/grpck.c, src/gpasswd.c,
src/newusers.c, src/chpasswd.c, src/chfn.c, src/groupmems.c,
src/usermod.c, src/expiry.c, src/groupdel.c, src/chgpasswd.c,
src/su.c, src/useradd.c, src/groupmod.c, src/passwd.c, src/pwck.c,
src/groupadd.c, src/chage.c, src/login.c, src/suauth.c,
src/faillog.c, src/groups.c, src/chsh.c, src/id.c: Review all the
usage of one of the getpwnam(), getpwuid(), getgrnam(),
getgrgid(), and getspnam() functions. It was noticed on
http://bugs.debian.org/341230 that chfn and chsh use a passwd
structure after calling a pam function, which result in using
information from the passwd structure requested by pam, not the
original one. It is much easier to use the new xget... functions
to avoid these issues. I've checked which call to the original
get... functions could be left (reducing the scope of the
structure if possible), and I've left comments to ease future
reviews (e.g. /* local, no need for xgetpwnam */).
Note: the getpwent/getgrent calls should probably be checked also.
* src/groupdel.c, src/expiry.c: Fix typos in comments.
* src/groupmod.c: Re-indent.
* libmisc/Makefile.am, lib/groupmem.c, lib/groupio.c, lib/pwmem.c,
lib/pwio.c, lib/shadowmem.c, lib/shadowio.c: Move the __<xx>_dup
functions (used by the xget... functions) from the <xx>io.c files
to the new <xx>mem.c files. This avoid linking some utils against
the SELinux library.
2007-11-19 04:45:26 +05:30
|
|
|
if (!(gr = getgrnam (group))) { /* dup, no need for xgetgrnam */
|
2007-10-07 17:14:02 +05:30
|
|
|
fprintf (stderr, _("unknown group: %s\n"), group);
|
2007-10-07 17:17:01 +05:30
|
|
|
#ifdef WITH_AUDIT
|
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "group lookup", group,
|
|
|
|
-1, 0);
|
|
|
|
#endif
|
|
|
|
failure ();
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
grent = *gr;
|
2007-10-07 17:14:59 +05:30
|
|
|
grent.gr_name = xstrdup (gr->gr_name);
|
|
|
|
grent.gr_passwd = xstrdup (gr->gr_passwd);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
grent.gr_mem = dup_list (gr->gr_mem);
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef SHADOWGRP
|
|
|
|
if ((sg = getsgnam (group))) {
|
|
|
|
sgent = *sg;
|
2007-10-07 17:14:59 +05:30
|
|
|
sgent.sg_name = xstrdup (sg->sg_name);
|
|
|
|
sgent.sg_passwd = xstrdup (sg->sg_passwd);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
sgent.sg_mem = dup_list (sg->sg_mem);
|
|
|
|
sgent.sg_adm = dup_list (sg->sg_adm);
|
2007-10-07 17:14:02 +05:30
|
|
|
} else {
|
2007-10-07 17:14:59 +05:30
|
|
|
sgent.sg_name = xstrdup (group);
|
2007-10-07 17:14:02 +05:30
|
|
|
sgent.sg_passwd = grent.gr_passwd;
|
2007-10-07 17:14:59 +05:30
|
|
|
grent.gr_passwd = "!"; /* XXX warning: const */
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
sgent.sg_mem = dup_list (grent.gr_mem);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
sgent.sg_adm = (char **) xmalloc (sizeof (char *) * 2);
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef FIRST_MEMBER_IS_ADMIN
|
|
|
|
if (sgent.sg_mem[0]) {
|
2007-10-07 17:14:59 +05:30
|
|
|
sgent.sg_adm[0] = xstrdup (sgent.sg_mem[0]);
|
2007-10-07 17:14:02 +05:30
|
|
|
sgent.sg_adm[1] = 0;
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
sgent.sg_adm[0] = 0;
|
|
|
|
|
|
|
|
sg = &sgent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* The policy here for changing a group is that 1) you must be root
|
|
|
|
* or 2). you must be listed as an administrative member.
|
|
|
|
* Administrative members can do anything to a group that the root
|
|
|
|
* user can.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-10-07 17:17:01 +05:30
|
|
|
if (!amroot && !is_on_list (sgent.sg_adm, myname)) {
|
|
|
|
#ifdef WITH_AUDIT
|
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "modify group", group,
|
|
|
|
-1, 0);
|
|
|
|
#endif
|
2007-10-07 17:14:59 +05:30
|
|
|
failure ();
|
2007-10-07 17:17:01 +05:30
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
#else /* ! SHADOWGRP */
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
#ifdef FIRST_MEMBER_IS_ADMIN
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* The policy here for changing a group is that 1) you must bes root
|
|
|
|
* or 2) you must be the first listed member of the group. The
|
|
|
|
* first listed member of a group can do anything to that group that
|
|
|
|
* the root user can. The rationale for this hack is that the FIRST
|
|
|
|
* user is probably the most important user in this entire group.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!amroot) {
|
2007-10-07 17:17:01 +05:30
|
|
|
if (grent.gr_mem[0] == (char *) 0) {
|
|
|
|
#ifdef WITH_AUDIT
|
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
|
|
|
"modifying group", group, -1, 0);
|
|
|
|
#endif
|
2007-10-07 17:14:59 +05:30
|
|
|
failure ();
|
2007-10-07 17:17:01 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:17:01 +05:30
|
|
|
if (strcmp (grent.gr_mem[0], myname) != 0) {
|
|
|
|
#ifdef WITH_AUDIT
|
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
|
|
|
"modifying group", myname, -1, 0);
|
|
|
|
#endif
|
2007-10-07 17:14:59 +05:30
|
|
|
failure ();
|
2007-10-07 17:17:01 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
#else
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* This feature enabled by default could be a security problem when
|
|
|
|
* installed on existing systems where the first group member might
|
|
|
|
* be just a normal user. --marekm
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-10-07 17:17:01 +05:30
|
|
|
if (!amroot) {
|
|
|
|
#ifdef WITH_AUDIT
|
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "modifying group",
|
|
|
|
group, -1, 0);
|
|
|
|
#endif
|
2007-10-07 17:14:59 +05:30
|
|
|
failure ();
|
2007-10-07 17:17:01 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
#endif /* SHADOWGRP */
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Removing a password is straight forward. Just set the password
|
|
|
|
* field to a "".
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
if (rflg) {
|
2007-10-07 17:14:59 +05:30
|
|
|
grent.gr_passwd = ""; /* XXX warning: const */
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef SHADOWGRP
|
2007-10-07 17:14:59 +05:30
|
|
|
sgent.sg_passwd = ""; /* XXX warning: const */
|
2007-10-07 17:17:01 +05:30
|
|
|
#endif
|
|
|
|
#ifdef WITH_AUDIT
|
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
|
|
|
"deleting group password", group, -1, 1);
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
2007-10-07 17:14:59 +05:30
|
|
|
SYSLOG ((LOG_INFO, "remove password from group %s by %s",
|
|
|
|
group, myname));
|
2007-10-07 17:14:02 +05:30
|
|
|
goto output;
|
|
|
|
} else if (Rflg) {
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Same thing for restricting the group. Set the password
|
2007-10-07 17:14:02 +05:30
|
|
|
* field to "!".
|
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
grent.gr_passwd = "!"; /* XXX warning: const */
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef SHADOWGRP
|
2007-10-07 17:14:59 +05:30
|
|
|
sgent.sg_passwd = "!"; /* XXX warning: const */
|
2007-10-07 17:17:01 +05:30
|
|
|
#endif
|
|
|
|
#ifdef WITH_AUDIT
|
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
|
|
|
"restrict access to group", group, -1, 1);
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
2007-10-07 17:14:59 +05:30
|
|
|
SYSLOG ((LOG_INFO, "restrict access to group %s by %s",
|
|
|
|
group, myname));
|
2007-10-07 17:14:02 +05:30
|
|
|
goto output;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Adding a member to a member list is pretty straightforward as
|
|
|
|
* well. Call the appropriate routine and split.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
if (aflg) {
|
2007-10-07 17:14:59 +05:30
|
|
|
printf (_("Adding user %s to group %s\n"), user, group);
|
2007-10-07 17:14:02 +05:30
|
|
|
grent.gr_mem = add_list (grent.gr_mem, user);
|
|
|
|
#ifdef SHADOWGRP
|
|
|
|
sgent.sg_mem = add_list (sgent.sg_mem, user);
|
2007-10-07 17:17:01 +05:30
|
|
|
#endif
|
|
|
|
#ifdef WITH_AUDIT
|
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "adding group member",
|
|
|
|
user, -1, 1);
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
2007-10-07 17:14:59 +05:30
|
|
|
SYSLOG ((LOG_INFO, "add member %s to group %s by %s", user,
|
|
|
|
group, myname));
|
2007-10-07 17:14:02 +05:30
|
|
|
goto output;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Removing a member from the member list is the same deal as adding
|
|
|
|
* one, except the routine is different.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
if (dflg) {
|
2007-10-07 17:14:59 +05:30
|
|
|
int removed = 0;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
printf (_("Removing user %s from group %s\n"), user, group);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (is_on_list (grent.gr_mem, user)) {
|
2007-10-07 17:14:02 +05:30
|
|
|
removed = 1;
|
|
|
|
grent.gr_mem = del_list (grent.gr_mem, user);
|
|
|
|
}
|
|
|
|
#ifdef SHADOWGRP
|
2007-10-07 17:14:59 +05:30
|
|
|
if (is_on_list (sgent.sg_mem, user)) {
|
2007-10-07 17:14:02 +05:30
|
|
|
removed = 1;
|
|
|
|
sgent.sg_mem = del_list (sgent.sg_mem, user);
|
|
|
|
}
|
|
|
|
#endif
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!removed) {
|
|
|
|
fprintf (stderr, _("%s: unknown member %s\n"),
|
|
|
|
Prog, user);
|
2007-10-07 17:17:01 +05:30
|
|
|
#ifdef WITH_AUDIT
|
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
|
|
|
"deleting member", user, -1, 0);
|
|
|
|
#endif
|
2007-10-07 17:14:02 +05:30
|
|
|
exit (1);
|
|
|
|
}
|
2007-10-07 17:17:01 +05:30
|
|
|
#ifdef WITH_AUDIT
|
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "deleting member",
|
|
|
|
user, -1, 1);
|
|
|
|
#endif
|
2007-10-07 17:14:59 +05:30
|
|
|
SYSLOG ((LOG_INFO, "remove member %s from group %s by %s",
|
|
|
|
user, group, myname));
|
2007-10-07 17:14:02 +05:30
|
|
|
goto output;
|
|
|
|
}
|
|
|
|
#ifdef SHADOWGRP
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Replacing the entire list of administators is simple. Check the
|
|
|
|
* list to make sure everyone is a real user. Then slap the new list
|
|
|
|
* in place.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
if (Aflg) {
|
2007-10-07 17:17:01 +05:30
|
|
|
#ifdef WITH_AUDIT
|
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "setting group admin",
|
|
|
|
group, -1, 1);
|
|
|
|
#endif
|
2007-10-07 17:14:59 +05:30
|
|
|
SYSLOG ((LOG_INFO, "set administrators of %s to %s",
|
|
|
|
group, admins));
|
|
|
|
sgent.sg_adm = comma_to_list (admins);
|
2007-10-07 17:14:02 +05:30
|
|
|
if (!Mflg)
|
|
|
|
goto output;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Replacing the entire list of members is simple. Check the list to
|
|
|
|
* make sure everyone is a real user. Then slap the new list in
|
|
|
|
* place.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
if (Mflg) {
|
2007-10-07 17:17:01 +05:30
|
|
|
#ifdef WITH_AUDIT
|
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
|
|
|
"setting group members", group, -1, 1);
|
|
|
|
#endif
|
2007-10-07 17:16:07 +05:30
|
|
|
SYSLOG ((LOG_INFO, "set members of %s to %s", group, members));
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef SHADOWGRP
|
2007-10-07 17:14:59 +05:30
|
|
|
sgent.sg_mem = comma_to_list (members);
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
2007-10-07 17:14:59 +05:30
|
|
|
grent.gr_mem = comma_to_list (members);
|
2007-10-07 17:14:02 +05:30
|
|
|
goto output;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* If the password is being changed, the input and output must both
|
|
|
|
* be a tty. The typical keyboard signals are caught so the termio
|
|
|
|
* modes can be restored.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!isatty (0) || !isatty (1)) {
|
|
|
|
fprintf (stderr, _("%s: Not a tty\n"), Prog);
|
2007-10-07 17:17:01 +05:30
|
|
|
#ifdef WITH_AUDIT
|
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "changing password",
|
|
|
|
group, -1, 0);
|
|
|
|
#endif
|
2007-10-07 17:14:02 +05:30
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
2007-10-07 17:17:22 +05:30
|
|
|
catch_signals (0); /* save tty modes */
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:17:22 +05:30
|
|
|
signal (SIGHUP, catch_signals);
|
|
|
|
signal (SIGINT, catch_signals);
|
|
|
|
signal (SIGQUIT, catch_signals);
|
|
|
|
signal (SIGTERM, catch_signals);
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef SIGTSTP
|
2007-10-07 17:17:22 +05:30
|
|
|
signal (SIGTSTP, catch_signals);
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* A new password is to be entered and it must be encrypted, etc.
|
|
|
|
* The password will be prompted for twice, and both entries must be
|
|
|
|
* identical. There is no need to validate the old password since
|
|
|
|
* the invoker is either the group owner, or root.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
printf (_("Changing the password for group %s\n"), group);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
for (retries = 0; retries < RETRIES; retries++) {
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!(cp = getpass (_("New Password: "))))
|
2007-10-07 17:14:02 +05:30
|
|
|
exit (1);
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
STRFCPY (pass, cp);
|
|
|
|
strzero (cp);
|
|
|
|
if (!(cp = getpass (_("Re-enter new password: "))))
|
2007-10-07 17:14:02 +05:30
|
|
|
exit (1);
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (strcmp (pass, cp) == 0) {
|
|
|
|
strzero (cp);
|
2007-10-07 17:14:02 +05:30
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
strzero (cp);
|
|
|
|
memzero (pass, sizeof pass);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:17:01 +05:30
|
|
|
if (retries + 1 < RETRIES) {
|
2007-10-07 17:14:59 +05:30
|
|
|
puts (_("They don't match; try again"));
|
2007-10-07 17:17:01 +05:30
|
|
|
#ifdef WITH_AUDIT
|
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
|
|
|
"changing password", group, -1, 0);
|
|
|
|
#endif
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
if (retries == RETRIES) {
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr, _("%s: Try again later\n"), Prog);
|
|
|
|
exit (1);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
cp = pw_encrypt (pass, crypt_make_salt ());
|
|
|
|
memzero (pass, sizeof pass);
|
2007-10-07 17:14:14 +05:30
|
|
|
#ifdef SHADOWGRP
|
|
|
|
if (is_shadowgrp)
|
|
|
|
sgent.sg_passwd = cp;
|
|
|
|
else
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
2007-10-07 17:14:59 +05:30
|
|
|
grent.gr_passwd = cp;
|
2007-10-07 17:17:01 +05:30
|
|
|
#ifdef WITH_AUDIT
|
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "changing password", group,
|
|
|
|
-1, 1);
|
|
|
|
#endif
|
2007-10-07 17:14:59 +05:30
|
|
|
SYSLOG ((LOG_INFO, "change the password for group %s by %s", group,
|
|
|
|
myname));
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* This is the common arrival point to output the new group file.
|
|
|
|
* The freshly crafted entry is in allocated space. The group file
|
|
|
|
* will be locked and opened for writing. The new entry will be
|
|
|
|
* output, etc.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
output:
|
|
|
|
if (setuid (0)) {
|
|
|
|
fprintf (stderr, _("Cannot change ID to root.\n"));
|
|
|
|
SYSLOG ((LOG_ERR, "can't setuid(0)"));
|
2007-10-07 17:17:01 +05:30
|
|
|
#ifdef WITH_AUDIT
|
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "changing id to root",
|
|
|
|
group, -1, 0);
|
|
|
|
#endif
|
2007-10-07 17:14:59 +05:30
|
|
|
closelog ();
|
|
|
|
exit (1);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
pwd_init ();
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!gr_lock ()) {
|
|
|
|
fprintf (stderr, _("%s: can't get lock\n"), Prog);
|
|
|
|
SYSLOG ((LOG_WARN, "failed to get lock for /etc/group"));
|
2007-10-07 17:17:01 +05:30
|
|
|
#ifdef WITH_AUDIT
|
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "locking /etc/group",
|
|
|
|
group, -1, 0);
|
|
|
|
#endif
|
2007-10-07 17:14:02 +05:30
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
#ifdef SHADOWGRP
|
2007-10-07 17:14:59 +05:30
|
|
|
if (is_shadowgrp && !sgr_lock ()) {
|
|
|
|
fprintf (stderr, _("%s: can't get shadow lock\n"), Prog);
|
|
|
|
SYSLOG ((LOG_WARN, "failed to get lock for /etc/gshadow"));
|
2007-10-07 17:17:01 +05:30
|
|
|
#ifdef WITH_AUDIT
|
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
|
|
|
"locking /etc/gshadow", group, -1, 0);
|
|
|
|
#endif
|
2007-10-07 17:14:02 +05:30
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
#endif
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!gr_open (O_RDWR)) {
|
|
|
|
fprintf (stderr, _("%s: can't open file\n"), Prog);
|
|
|
|
SYSLOG ((LOG_WARN, "cannot open /etc/group"));
|
2007-10-07 17:17:01 +05:30
|
|
|
#ifdef WITH_AUDIT
|
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "opening /etc/group",
|
|
|
|
group, -1, 0);
|
|
|
|
#endif
|
2007-10-07 17:14:02 +05:30
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
#ifdef SHADOWGRP
|
2007-10-07 17:14:59 +05:30
|
|
|
if (is_shadowgrp && !sgr_open (O_RDWR)) {
|
|
|
|
fprintf (stderr, _("%s: can't open shadow file\n"), Prog);
|
|
|
|
SYSLOG ((LOG_WARN, "cannot open /etc/gshadow"));
|
2007-10-07 17:17:01 +05:30
|
|
|
#ifdef WITH_AUDIT
|
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
|
|
|
"opening /etc/gshadow", group, -1, 0);
|
|
|
|
#endif
|
2007-10-07 17:14:02 +05:30
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
#endif
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!gr_update (&grent)) {
|
|
|
|
fprintf (stderr, _("%s: can't update entry\n"), Prog);
|
|
|
|
SYSLOG ((LOG_WARN, "cannot update /etc/group"));
|
2007-10-07 17:17:01 +05:30
|
|
|
#ifdef WITH_AUDIT
|
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "updating /etc/group",
|
|
|
|
group, -1, 0);
|
|
|
|
#endif
|
2007-10-07 17:14:02 +05:30
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
#ifdef SHADOWGRP
|
2007-10-07 17:14:59 +05:30
|
|
|
if (is_shadowgrp && !sgr_update (&sgent)) {
|
2007-10-07 17:16:07 +05:30
|
|
|
fprintf (stderr, _("%s: can't update shadow entry\n"), Prog);
|
2007-10-07 17:14:59 +05:30
|
|
|
SYSLOG ((LOG_WARN, "cannot update /etc/gshadow"));
|
2007-10-07 17:17:01 +05:30
|
|
|
#ifdef WITH_AUDIT
|
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
|
|
|
"updating /etc/gshadow", group, -1, 0);
|
|
|
|
#endif
|
2007-10-07 17:14:02 +05:30
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
#endif
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!gr_close ()) {
|
|
|
|
fprintf (stderr, _("%s: can't re-write file\n"), Prog);
|
|
|
|
SYSLOG ((LOG_WARN, "cannot re-write /etc/group"));
|
2007-10-07 17:17:01 +05:30
|
|
|
#ifdef WITH_AUDIT
|
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
|
|
|
"rewriting /etc/group", group, -1, 0);
|
|
|
|
#endif
|
2007-10-07 17:14:02 +05:30
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
#ifdef SHADOWGRP
|
2007-10-07 17:14:59 +05:30
|
|
|
if (is_shadowgrp && !sgr_close ()) {
|
2007-10-07 17:16:07 +05:30
|
|
|
fprintf (stderr, _("%s: can't re-write shadow file\n"), Prog);
|
2007-10-07 17:14:59 +05:30
|
|
|
SYSLOG ((LOG_WARN, "cannot re-write /etc/gshadow"));
|
2007-10-07 17:17:01 +05:30
|
|
|
#ifdef WITH_AUDIT
|
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
|
|
|
"rewriting /etc/gshadow", group, -1, 0);
|
|
|
|
#endif
|
2007-10-07 17:14:02 +05:30
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
if (is_shadowgrp)
|
|
|
|
sgr_unlock ();
|
|
|
|
#endif
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!gr_unlock ()) {
|
|
|
|
fprintf (stderr, _("%s: can't unlock file\n"), Prog);
|
2007-10-07 17:17:01 +05:30
|
|
|
#ifdef WITH_AUDIT
|
|
|
|
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
|
|
|
|
"unlocking group file", group, -1, 0);
|
|
|
|
#endif
|
2007-10-07 17:14:02 +05:30
|
|
|
exit (1);
|
|
|
|
}
|
2007-10-07 17:16:52 +05:30
|
|
|
|
|
|
|
nscd_flush_cache ("group");
|
|
|
|
|
|
|
|
exit (E_SUCCESS);
|
2007-10-07 17:15:23 +05:30
|
|
|
}
|