2007-10-07 17:14:02 +05:30
|
|
|
/*
|
|
|
|
* Copyright 1991 - 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>
|
|
|
|
|
|
|
|
#include "rcsid.h"
|
2007-10-07 17:15:23 +05:30
|
|
|
RCSID (PKG_VER "$Id: groupmod.c,v 1.22 2003/06/19 18:11:01 kloczek Exp $")
|
2007-10-07 17:14:02 +05:30
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <grp.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <fcntl.h>
|
2007-10-07 17:14:38 +05:30
|
|
|
#ifdef USE_PAM
|
|
|
|
#include <security/pam_appl.h>
|
|
|
|
#include <security/pam_misc.h>
|
|
|
|
#include <pwd.h>
|
2007-10-07 17:14:59 +05:30
|
|
|
#endif /* USE_PAM */
|
2007-10-07 17:14:02 +05:30
|
|
|
#include "prototypes.h"
|
|
|
|
#include "chkname.h"
|
|
|
|
#include "defines.h"
|
|
|
|
#include "groupio.h"
|
2007-10-07 17:15:23 +05:30
|
|
|
#include "nscd.h"
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef SHADOWGRP
|
|
|
|
#include "sgroupio.h"
|
|
|
|
static int is_shadow_grp;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* exit status values
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define E_SUCCESS 0 /* success */
|
|
|
|
#define E_USAGE 2 /* invalid command syntax */
|
|
|
|
#define E_BAD_ARG 3 /* invalid argument to option */
|
|
|
|
#define E_GID_IN_USE 4 /* gid already in use (and no -o) */
|
|
|
|
#define E_NOTFOUND 6 /* specified group doesn't exist */
|
|
|
|
#define E_NAME_IN_USE 9 /* group name already in use */
|
|
|
|
#define E_GRP_UPDATE 10 /* can't update group file */
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
static char *group_name;
|
|
|
|
static char *group_newname;
|
|
|
|
static gid_t group_id;
|
|
|
|
static gid_t group_newid;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
static char *Prog;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
static int
|
2007-10-07 17:14:59 +05:30
|
|
|
oflg = 0, /* permit non-unique group ID to be specified with -g */
|
|
|
|
gflg = 0, /* new ID value for the group */
|
|
|
|
nflg = 0; /* a new name has been specified for the group */
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
#ifdef NDBM
|
2007-10-07 17:14:59 +05:30
|
|
|
extern int gr_dbm_mode;
|
|
|
|
extern int sg_dbm_mode;
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
|
|
|
|
|
|
|
/* local function prototypes */
|
2007-10-07 17:14:59 +05:30
|
|
|
static void usage (void);
|
|
|
|
static void new_grent (struct group *);
|
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef SHADOWGRP
|
2007-10-07 17:14:59 +05:30
|
|
|
static void new_sgent (struct sgrp *);
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
2007-10-07 17:14:59 +05:30
|
|
|
static void grp_update (void);
|
|
|
|
static void check_new_gid (void);
|
|
|
|
static void check_new_name (void);
|
|
|
|
static void process_flags (int, char **);
|
|
|
|
static void close_files (void);
|
|
|
|
static void open_files (void);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* usage - display usage message and exit
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
static void usage (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr,
|
2007-10-07 17:15:23 +05:30
|
|
|
_("Usage: groupmod [-g gid [-o]] [-n name] group\n"));
|
2007-10-07 17:14:59 +05:30
|
|
|
exit (E_USAGE);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* new_grent - updates the values in a group file entry
|
|
|
|
*
|
2007-10-07 17:14:59 +05:30
|
|
|
* new_grent() takes all of the values that have been entered and fills
|
|
|
|
* in a (struct group) with them.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
static void new_grent (struct group *grent)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
if (nflg)
|
|
|
|
grent->gr_name = xstrdup (group_newname);
|
|
|
|
|
|
|
|
if (gflg)
|
|
|
|
grent->gr_gid = group_newid;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SHADOWGRP
|
|
|
|
/*
|
|
|
|
* new_sgent - updates the values in a shadow group file entry
|
|
|
|
*
|
2007-10-07 17:14:59 +05:30
|
|
|
* new_sgent() takes all of the values that have been entered and fills
|
|
|
|
* in a (struct sgrp) with them.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
static void new_sgent (struct sgrp *sgent)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
if (nflg)
|
|
|
|
sgent->sg_name = xstrdup (group_newname);
|
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
#endif /* SHADOWGRP */
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* grp_update - update group file entries
|
|
|
|
*
|
|
|
|
* grp_update() writes the new records to the group files.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
static void grp_update (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
struct group grp;
|
|
|
|
const struct group *ogrp;
|
2007-10-07 17:14:59 +05:30
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef SHADOWGRP
|
|
|
|
struct sgrp sgrp;
|
|
|
|
const struct sgrp *osgrp = NULL;
|
2007-10-07 17:14:59 +05:30
|
|
|
#endif /* SHADOWGRP */
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the current settings for this group.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
ogrp = gr_locate (group_name);
|
2007-10-07 17:14:02 +05:30
|
|
|
if (!ogrp) {
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: %s not found in /etc/group\n"),
|
|
|
|
Prog, group_name);
|
|
|
|
exit (E_GRP_UPDATE);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
grp = *ogrp;
|
|
|
|
new_grent (&grp);
|
|
|
|
#ifdef SHADOWGRP
|
2007-10-07 17:14:59 +05:30
|
|
|
if (is_shadow_grp && (osgrp = sgr_locate (group_name))) {
|
2007-10-07 17:14:02 +05:30
|
|
|
sgrp = *osgrp;
|
|
|
|
new_sgent (&sgrp);
|
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
#endif /* SHADOWGRP */
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Write out the new group file entry.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!gr_update (&grp)) {
|
|
|
|
fprintf (stderr, _("%s: error adding new group entry\n"),
|
|
|
|
Prog);
|
|
|
|
exit (E_GRP_UPDATE);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
if (nflg && !gr_remove (group_name)) {
|
|
|
|
fprintf (stderr, _("%s: error removing group entry\n"),
|
|
|
|
Prog);
|
|
|
|
exit (E_GRP_UPDATE);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
#ifdef NDBM
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update the DBM group file with the new entry as well.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (gr_dbm_present ()) {
|
|
|
|
if (!gr_dbm_update (&grp)) {
|
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: cannot add new dbm group entry\n"),
|
|
|
|
Prog);
|
|
|
|
exit (E_GRP_UPDATE);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
if (nflg && (ogrp = getgrnam (group_name)) &&
|
|
|
|
!gr_dbm_remove (ogrp)) {
|
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: error removing group dbm entry\n"),
|
|
|
|
Prog);
|
|
|
|
exit (E_GRP_UPDATE);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
endgrent ();
|
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
#endif /* NDBM */
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
#ifdef SHADOWGRP
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Make sure there was a shadow entry to begin with. Skip down to
|
|
|
|
* "out" if there wasn't. Can't just return because there might be
|
|
|
|
* some syslogging to do.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!osgrp)
|
2007-10-07 17:14:02 +05:30
|
|
|
goto out;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write out the new shadow group entries as well.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!sgr_update (&sgrp)) {
|
|
|
|
fprintf (stderr, _("%s: error adding new group entry\n"),
|
|
|
|
Prog);
|
|
|
|
exit (E_GRP_UPDATE);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
if (nflg && !sgr_remove (group_name)) {
|
|
|
|
fprintf (stderr, _("%s: error removing group entry\n"),
|
|
|
|
Prog);
|
|
|
|
exit (E_GRP_UPDATE);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
#ifdef NDBM
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update the DBM shadow group file with the new entry as well.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (sg_dbm_present ()) {
|
|
|
|
if (!sg_dbm_update (&sgrp)) {
|
|
|
|
fprintf (stderr,
|
|
|
|
_
|
|
|
|
("%s: cannot add new dbm shadow group entry\n"),
|
|
|
|
Prog);
|
|
|
|
exit (E_GRP_UPDATE);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
if (nflg && !sg_dbm_remove (group_name)) {
|
2007-10-07 17:14:02 +05:30
|
|
|
fprintf (stderr,
|
2007-10-07 17:14:59 +05:30
|
|
|
_
|
|
|
|
("%s: error removing shadow group dbm entry\n"),
|
|
|
|
Prog);
|
|
|
|
exit (E_GRP_UPDATE);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
endsgent ();
|
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
#endif /* NDBM */
|
|
|
|
out:
|
|
|
|
#endif /* SHADOWGRP */
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
if (nflg)
|
2007-10-07 17:14:59 +05:30
|
|
|
SYSLOG ((LOG_INFO, "change group `%s' to `%s'",
|
|
|
|
group_name, group_newname));
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
if (gflg)
|
2007-10-07 17:14:59 +05:30
|
|
|
SYSLOG ((LOG_INFO, "change gid for `%s' to %u",
|
|
|
|
nflg ? group_newname : group_name, group_newid));
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* check_new_gid - check the new GID value for uniqueness
|
|
|
|
*
|
|
|
|
* check_new_gid() insures that the new GID value is unique.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
static void check_new_gid (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* First, the easy stuff. If the ID can be duplicated, or if the ID
|
|
|
|
* didn't really change, just return. If the ID didn't change, turn
|
|
|
|
* off those flags. No sense doing needless work.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
if (group_id == group_newid) {
|
|
|
|
gflg = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (oflg || !getgrgid (group_newid))
|
2007-10-07 17:14:02 +05:30
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Tell the user what they did wrong.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: %u is not a unique gid\n"), Prog, group_newid);
|
|
|
|
exit (E_GID_IN_USE);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* check_new_name - check the new name for uniqueness
|
|
|
|
*
|
2007-10-07 17:14:59 +05:30
|
|
|
* check_new_name() insures that the new name does not exist already.
|
|
|
|
* You can't have the same name twice, period.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
static void check_new_name (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Make sure they are actually changing the name.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (strcmp (group_name, group_newname) == 0) {
|
2007-10-07 17:14:02 +05:30
|
|
|
nflg = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (check_group_name (group_newname)) {
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* If the entry is found, too bad.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (getgrnam (group_newname)) {
|
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: %s is not a unique name\n"), Prog,
|
|
|
|
group_newname);
|
|
|
|
exit (E_NAME_IN_USE);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* All invalid group names land here.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr, _("%s: %s is a not a valid group name\n"),
|
|
|
|
Prog, group_newname);
|
|
|
|
exit (E_BAD_ARG);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* process_flags - perform command line argument setting
|
|
|
|
*
|
2007-10-07 17:14:59 +05:30
|
|
|
* process_flags() interprets the command line arguments and sets the
|
|
|
|
* values that the user will be created with accordingly. The values
|
|
|
|
* are checked for sanity.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
static void process_flags (int argc, char **argv)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:14:59 +05:30
|
|
|
char *end;
|
|
|
|
int arg;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
while ((arg = getopt (argc, argv, "og:n:")) != EOF) {
|
|
|
|
switch (arg) {
|
2007-10-07 17:14:59 +05:30
|
|
|
case 'g':
|
|
|
|
gflg++;
|
|
|
|
group_newid = strtoul (optarg, &end, 10);
|
|
|
|
if (*end != '\0') {
|
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: invalid group %s\n"),
|
|
|
|
Prog, optarg);
|
|
|
|
exit (E_BAD_ARG);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
nflg++;
|
|
|
|
group_newname = optarg;
|
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
oflg++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage ();
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
if (oflg && !gflg)
|
2007-10-07 17:14:59 +05:30
|
|
|
usage ();
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
if (optind != argc - 1)
|
2007-10-07 17:14:59 +05:30
|
|
|
usage ();
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
group_name = argv[argc - 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* close_files - close all of the files that were opened
|
|
|
|
*
|
2007-10-07 17:14:59 +05:30
|
|
|
* close_files() closes all of the files that were opened for this new
|
|
|
|
* group. This causes any modified entries to be written out.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
static void close_files (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!gr_close ()) {
|
|
|
|
fprintf (stderr, _("%s: cannot rewrite group file\n"),
|
|
|
|
Prog);
|
|
|
|
exit (E_GRP_UPDATE);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
gr_unlock ();
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef SHADOWGRP
|
2007-10-07 17:14:59 +05:30
|
|
|
if (is_shadow_grp && !sgr_close ()) {
|
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: cannot rewrite shadow group file\n"),
|
|
|
|
Prog);
|
|
|
|
exit (E_GRP_UPDATE);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
if (is_shadow_grp)
|
|
|
|
sgr_unlock ();
|
2007-10-07 17:14:59 +05:30
|
|
|
#endif /* SHADOWGRP */
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* open_files - lock and open the group files
|
|
|
|
*
|
|
|
|
* open_files() opens the two group files.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
static void open_files (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!gr_lock ()) {
|
|
|
|
fprintf (stderr, _("%s: unable to lock group file\n"),
|
|
|
|
Prog);
|
|
|
|
exit (E_GRP_UPDATE);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!gr_open (O_RDWR)) {
|
|
|
|
fprintf (stderr, _("%s: unable to open group file\n"),
|
|
|
|
Prog);
|
|
|
|
exit (E_GRP_UPDATE);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
#ifdef SHADOWGRP
|
2007-10-07 17:14:59 +05:30
|
|
|
if (is_shadow_grp && !sgr_lock ()) {
|
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: unable to lock shadow group file\n"),
|
|
|
|
Prog);
|
|
|
|
exit (E_GRP_UPDATE);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
if (is_shadow_grp && !sgr_open (O_RDWR)) {
|
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: unable to open shadow group file\n"),
|
|
|
|
Prog);
|
|
|
|
exit (E_GRP_UPDATE);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
#endif /* SHADOWGRP */
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:14:38 +05:30
|
|
|
#ifdef USE_PAM
|
|
|
|
static struct pam_conv conv = {
|
2007-10-07 17:14:59 +05:30
|
|
|
misc_conv,
|
|
|
|
NULL
|
2007-10-07 17:14:38 +05:30
|
|
|
};
|
2007-10-07 17:14:59 +05:30
|
|
|
#endif /* USE_PAM */
|
2007-10-07 17:14:38 +05:30
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
|
|
|
* main - groupmod command
|
|
|
|
*
|
|
|
|
* The syntax of the groupmod command is
|
|
|
|
*
|
|
|
|
* groupmod [ -g gid [ -o ]] [ -n name ] group
|
|
|
|
*
|
|
|
|
* The flags are
|
|
|
|
* -g - specify a new group ID value
|
|
|
|
* -o - permit the group ID value to be non-unique
|
|
|
|
* -n - specify a new group name
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
struct group *grp;
|
|
|
|
|
2007-10-07 17:14:38 +05:30
|
|
|
#ifdef USE_PAM
|
|
|
|
pam_handle_t *pamh = NULL;
|
|
|
|
struct passwd *pampw;
|
|
|
|
int retval;
|
|
|
|
#endif
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Get my name so that I can use it to report errors.
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
setlocale (LC_ALL, "");
|
|
|
|
bindtextdomain (PACKAGE, LOCALEDIR);
|
|
|
|
textdomain (PACKAGE);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:38 +05:30
|
|
|
#ifdef USE_PAM
|
|
|
|
retval = PAM_SUCCESS;
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
pampw = getpwuid (getuid ());
|
2007-10-07 17:14:38 +05:30
|
|
|
if (pampw == NULL) {
|
|
|
|
retval = PAM_USER_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (retval == PAM_SUCCESS) {
|
2007-10-07 17:14:59 +05:30
|
|
|
retval =
|
|
|
|
pam_start ("shadow", pampw->pw_name, &conv, &pamh);
|
2007-10-07 17:14:38 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
if (retval == PAM_SUCCESS) {
|
2007-10-07 17:14:59 +05:30
|
|
|
retval = pam_authenticate (pamh, 0);
|
2007-10-07 17:14:38 +05:30
|
|
|
if (retval != PAM_SUCCESS) {
|
2007-10-07 17:14:59 +05:30
|
|
|
pam_end (pamh, retval);
|
2007-10-07 17:14:38 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (retval == PAM_SUCCESS) {
|
2007-10-07 17:14:59 +05:30
|
|
|
retval = pam_acct_mgmt (pamh, 0);
|
2007-10-07 17:14:38 +05:30
|
|
|
if (retval != PAM_SUCCESS) {
|
2007-10-07 17:14:59 +05:30
|
|
|
pam_end (pamh, retval);
|
2007-10-07 17:14:38 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (retval != PAM_SUCCESS) {
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr, _("%s: PAM authentication failed\n"),
|
|
|
|
Prog);
|
2007-10-07 17:14:38 +05:30
|
|
|
exit (1);
|
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
#endif /* USE_PAM */
|
2007-10-07 17:14:38 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
OPENLOG (Prog);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
#ifdef SHADOWGRP
|
2007-10-07 17:14:59 +05:30
|
|
|
is_shadow_grp = sgr_file_present ();
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* The open routines for the DBM files don't use read-write as the
|
|
|
|
* mode, so we have to clue them in.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef NDBM
|
|
|
|
gr_dbm_mode = O_RDWR;
|
|
|
|
#ifdef SHADOWGRP
|
|
|
|
sg_dbm_mode = O_RDWR;
|
2007-10-07 17:14:59 +05:30
|
|
|
#endif /* SHADOWGRP */
|
|
|
|
#endif /* NDBM */
|
2007-10-07 17:14:02 +05:30
|
|
|
process_flags (argc, argv);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start with a quick check to see if the group exists.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!(grp = getgrnam (group_name))) {
|
|
|
|
fprintf (stderr, _("%s: group %s does not exist\n"),
|
|
|
|
Prog, group_name);
|
|
|
|
exit (E_NOTFOUND);
|
2007-10-07 17:14:02 +05:30
|
|
|
} else
|
|
|
|
group_id = grp->gr_gid;
|
|
|
|
|
|
|
|
#ifdef USE_NIS
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now make sure it isn't an NIS group.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (__isgrNIS ()) {
|
2007-10-07 17:14:59 +05:30
|
|
|
char *nis_domain;
|
|
|
|
char *nis_master;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr, _("%s: group %s is a NIS group\n"),
|
|
|
|
Prog, group_name);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!yp_get_default_domain (&nis_domain) &&
|
|
|
|
!yp_master (nis_domain, "group.byname", &nis_master)) {
|
|
|
|
fprintf (stderr, _("%s: %s is the NIS master\n"),
|
|
|
|
Prog, nis_master);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
exit (E_NOTFOUND);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (gflg)
|
|
|
|
check_new_gid ();
|
|
|
|
|
|
|
|
if (nflg)
|
|
|
|
check_new_name ();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do the hard stuff - open the files, create the group entries,
|
|
|
|
* then close and update the files.
|
|
|
|
*/
|
|
|
|
|
|
|
|
open_files ();
|
|
|
|
|
|
|
|
grp_update ();
|
2007-10-07 17:15:23 +05:30
|
|
|
nscd_flush_cache ("group");
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
close_files ();
|
2007-10-07 17:14:38 +05:30
|
|
|
|
|
|
|
#ifdef USE_PAM
|
|
|
|
if (retval == PAM_SUCCESS) {
|
2007-10-07 17:14:59 +05:30
|
|
|
retval = pam_chauthtok (pamh, 0);
|
2007-10-07 17:14:38 +05:30
|
|
|
if (retval != PAM_SUCCESS) {
|
2007-10-07 17:14:59 +05:30
|
|
|
pam_end (pamh, retval);
|
2007-10-07 17:14:38 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (retval != PAM_SUCCESS) {
|
|
|
|
fprintf (stderr, _("%s: PAM chauthtok failed\n"), Prog);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (retval == PAM_SUCCESS)
|
2007-10-07 17:14:59 +05:30
|
|
|
pam_end (pamh, PAM_SUCCESS);
|
|
|
|
#endif /* USE_PAM */
|
|
|
|
exit (E_SUCCESS);
|
2007-10-07 17:15:23 +05:30
|
|
|
/* NOT REACHED */
|
|
|
|
}
|