[svn-upgrade] Integrating new upstream version, shadow (4.0.1)
This commit is contained in:
404
src/groupadd.c
404
src/groupadd.c
@ -17,7 +17,7 @@
|
||||
* 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
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL JULIE HAUGH OR CONTRIBUTORS BE LIABLE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL JULIE HAUGH OR CONTRIBUTORS BE LIABLE
|
||||
* 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)
|
||||
@ -30,31 +30,24 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID(PKG_VER "$Id: groupadd.c,v 1.18 2000/10/09 19:02:20 kloczek Exp $")
|
||||
|
||||
RCSID (PKG_VER "$Id: groupadd.c,v 1.22 2002/01/06 14:09:07 kloczek Exp $")
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <grp.h>
|
||||
#include <ctype.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "defines.h"
|
||||
#include "prototypes.h"
|
||||
#include "chkname.h"
|
||||
|
||||
#include "getdef.h"
|
||||
|
||||
#include "groupio.h"
|
||||
|
||||
#ifdef SHADOWGRP
|
||||
#include "sgroupio.h"
|
||||
|
||||
#ifdef USE_PAM
|
||||
#include <security/pam_appl.h>
|
||||
#include <security/pam_misc.h>
|
||||
#include <pwd.h>
|
||||
#endif /* USE_PAM */
|
||||
|
||||
#endif /* USE_PAM */
|
||||
static int is_shadow_grp;
|
||||
#endif
|
||||
|
||||
@ -69,62 +62,58 @@ static int is_shadow_grp;
|
||||
#define E_NAME_IN_USE 9 /* group name nut unique */
|
||||
#define E_GRP_UPDATE 10 /* can't update group file */
|
||||
|
||||
static char *group_name;
|
||||
static gid_t group_id;
|
||||
static char *group_name;
|
||||
static gid_t group_id;
|
||||
static char *empty_list = NULL;
|
||||
|
||||
static char *Prog;
|
||||
static char *Prog;
|
||||
|
||||
static int oflg = 0; /* permit non-unique group ID to be specified with -g */
|
||||
static int gflg = 0; /* ID value for the new group */
|
||||
static int fflg = 0; /* if group already exists, do nothing and exit(0) */
|
||||
static int oflg = 0; /* permit non-unique group ID to be specified with -g */
|
||||
static int gflg = 0; /* ID value for the new group */
|
||||
static int fflg = 0; /* if group already exists, do nothing and exit(0) */
|
||||
|
||||
#ifdef NDBM
|
||||
extern int gr_dbm_mode;
|
||||
extern int sg_dbm_mode;
|
||||
extern int gr_dbm_mode;
|
||||
extern int sg_dbm_mode;
|
||||
#endif
|
||||
|
||||
extern int optind;
|
||||
extern char *optarg;
|
||||
|
||||
/* local function prototypes */
|
||||
static void usage(void);
|
||||
static void new_grent(struct group *);
|
||||
static void usage (void);
|
||||
static void new_grent (struct group *);
|
||||
|
||||
#ifdef SHADOWGRP
|
||||
static void new_sgent(struct sgrp *);
|
||||
static void new_sgent (struct sgrp *);
|
||||
#endif
|
||||
static void grp_update(void);
|
||||
static void find_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);
|
||||
static void fail_exit(int);
|
||||
static void grp_update (void);
|
||||
static void find_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);
|
||||
static void fail_exit (int);
|
||||
|
||||
/*
|
||||
* usage - display usage message and exit
|
||||
*/
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
static void usage (void)
|
||||
{
|
||||
fprintf(stderr, _("usage: groupadd [-g gid [-o]] group\n"));
|
||||
exit(E_USAGE);
|
||||
fprintf (stderr, _("usage: groupadd [-g gid [-o]] group\n"));
|
||||
exit (E_USAGE);
|
||||
}
|
||||
|
||||
/*
|
||||
* new_grent - initialize the values in a group file entry
|
||||
*
|
||||
* new_grent() takes all of the values that have been entered and
|
||||
* fills in a (struct group) with them.
|
||||
* new_grent() takes all of the values that have been entered and fills
|
||||
* in a (struct group) with them.
|
||||
*/
|
||||
|
||||
static void
|
||||
new_grent(struct group *grent)
|
||||
static void new_grent (struct group *grent)
|
||||
{
|
||||
memzero(grent, sizeof *grent);
|
||||
memzero (grent, sizeof *grent);
|
||||
grent->gr_name = group_name;
|
||||
grent->gr_passwd = SHADOW_PASSWD_STRING; /* XXX warning: const */
|
||||
grent->gr_passwd = SHADOW_PASSWD_STRING; /* XXX warning: const */
|
||||
grent->gr_gid = group_id;
|
||||
grent->gr_mem = &empty_list;
|
||||
}
|
||||
@ -133,20 +122,19 @@ new_grent(struct group *grent)
|
||||
/*
|
||||
* new_sgent - initialize the values in a shadow group file entry
|
||||
*
|
||||
* new_sgent() takes all of the values that have been entered and
|
||||
* fills in a (struct sgrp) with them.
|
||||
* new_sgent() takes all of the values that have been entered and fills
|
||||
* in a (struct sgrp) with them.
|
||||
*/
|
||||
|
||||
static void
|
||||
new_sgent(struct sgrp *sgent)
|
||||
static void new_sgent (struct sgrp *sgent)
|
||||
{
|
||||
memzero(sgent, sizeof *sgent);
|
||||
memzero (sgent, sizeof *sgent);
|
||||
sgent->sg_name = group_name;
|
||||
sgent->sg_passwd = "!"; /* XXX warning: const */
|
||||
sgent->sg_passwd = "!"; /* XXX warning: const */
|
||||
sgent->sg_adm = &empty_list;
|
||||
sgent->sg_mem = &empty_list;
|
||||
}
|
||||
#endif /* SHADOWGRP */
|
||||
#endif /* SHADOWGRP */
|
||||
|
||||
/*
|
||||
* grp_update - add new group file entries
|
||||
@ -154,13 +142,13 @@ new_sgent(struct sgrp *sgent)
|
||||
* grp_update() writes the new records to the group files.
|
||||
*/
|
||||
|
||||
static void
|
||||
grp_update(void)
|
||||
static void grp_update (void)
|
||||
{
|
||||
struct group grp;
|
||||
struct group grp;
|
||||
|
||||
#ifdef SHADOWGRP
|
||||
struct sgrp sgrp;
|
||||
#endif /* SHADOWGRP */
|
||||
struct sgrp sgrp;
|
||||
#endif /* SHADOWGRP */
|
||||
|
||||
/*
|
||||
* Create the initial entries for this new group.
|
||||
@ -169,15 +157,16 @@ grp_update(void)
|
||||
new_grent (&grp);
|
||||
#ifdef SHADOWGRP
|
||||
new_sgent (&sgrp);
|
||||
#endif /* SHADOWGRP */
|
||||
#endif /* SHADOWGRP */
|
||||
|
||||
/*
|
||||
* Write out the new group file entry.
|
||||
*/
|
||||
|
||||
if (! gr_update (&grp)) {
|
||||
fprintf(stderr, _("%s: error adding new group entry\n"), Prog);
|
||||
fail_exit(E_GRP_UPDATE);
|
||||
if (!gr_update (&grp)) {
|
||||
fprintf (stderr, _("%s: error adding new group entry\n"),
|
||||
Prog);
|
||||
fail_exit (E_GRP_UPDATE);
|
||||
}
|
||||
#ifdef NDBM
|
||||
|
||||
@ -185,12 +174,13 @@ grp_update(void)
|
||||
* Update the DBM group file with the new entry as well.
|
||||
*/
|
||||
|
||||
if (gr_dbm_present() && ! gr_dbm_update (&grp)) {
|
||||
fprintf(stderr, _("%s: cannot add new dbm group entry\n"), Prog);
|
||||
fail_exit(E_GRP_UPDATE);
|
||||
if (gr_dbm_present () && !gr_dbm_update (&grp)) {
|
||||
fprintf (stderr, _("%s: cannot add new dbm group entry\n"),
|
||||
Prog);
|
||||
fail_exit (E_GRP_UPDATE);
|
||||
}
|
||||
endgrent ();
|
||||
#endif /* NDBM */
|
||||
#endif /* NDBM */
|
||||
|
||||
#ifdef SHADOWGRP
|
||||
|
||||
@ -198,9 +188,10 @@ grp_update(void)
|
||||
* Write out the new shadow group entries as well.
|
||||
*/
|
||||
|
||||
if (is_shadow_grp && ! sgr_update (&sgrp)) {
|
||||
fprintf(stderr, _("%s: error adding new group entry\n"), Prog);
|
||||
fail_exit(E_GRP_UPDATE);
|
||||
if (is_shadow_grp && !sgr_update (&sgrp)) {
|
||||
fprintf (stderr, _("%s: error adding new group entry\n"),
|
||||
Prog);
|
||||
fail_exit (E_GRP_UPDATE);
|
||||
}
|
||||
#ifdef NDBM
|
||||
|
||||
@ -208,15 +199,16 @@ grp_update(void)
|
||||
* Update the DBM group file with the new entry as well.
|
||||
*/
|
||||
|
||||
if (is_shadow_grp && sg_dbm_present() && ! sg_dbm_update (&sgrp)) {
|
||||
fprintf(stderr, _("%s: cannot add new dbm group entry\n"), Prog);
|
||||
fail_exit(E_GRP_UPDATE);
|
||||
if (is_shadow_grp && sg_dbm_present () && !sg_dbm_update (&sgrp)) {
|
||||
fprintf (stderr, _("%s: cannot add new dbm group entry\n"),
|
||||
Prog);
|
||||
fail_exit (E_GRP_UPDATE);
|
||||
}
|
||||
endsgent ();
|
||||
#endif /* NDBM */
|
||||
#endif /* SHADOWGRP */
|
||||
SYSLOG((LOG_INFO, "new group: name=%s, gid=%d\n",
|
||||
group_name, group_id));
|
||||
#endif /* NDBM */
|
||||
#endif /* SHADOWGRP */
|
||||
SYSLOG ((LOG_INFO, "new group: name=%s, gid=%u",
|
||||
group_name, (unsigned int)group_id));
|
||||
}
|
||||
|
||||
/*
|
||||
@ -227,60 +219,59 @@ grp_update(void)
|
||||
* uniqueness.
|
||||
*/
|
||||
|
||||
static void
|
||||
find_new_gid(void)
|
||||
static void find_new_gid (void)
|
||||
{
|
||||
const struct group *grp;
|
||||
gid_t gid_min, gid_max;
|
||||
|
||||
gid_min = getdef_num("GID_MIN", 100);
|
||||
gid_max = getdef_num("GID_MAX", 60000);
|
||||
gid_min = getdef_unum ("GID_MIN", 100);
|
||||
gid_max = getdef_unum ("GID_MAX", 60000);
|
||||
|
||||
/*
|
||||
* Start with some GID value if the user didn't provide us with
|
||||
* one already.
|
||||
*/
|
||||
|
||||
if (! gflg)
|
||||
if (!gflg)
|
||||
group_id = gid_min;
|
||||
|
||||
/*
|
||||
* Search the entire group file, either looking for this
|
||||
* GID (if the user specified one with -g) or looking for the
|
||||
* largest unused value.
|
||||
* Search the entire group file, either looking for this GID (if the
|
||||
* user specified one with -g) or looking for the largest unused
|
||||
* value.
|
||||
*/
|
||||
|
||||
#ifdef NO_GETGRENT
|
||||
gr_rewind();
|
||||
while ((grp = gr_next())) {
|
||||
gr_rewind ();
|
||||
while ((grp = gr_next ())) {
|
||||
#else
|
||||
setgrent();
|
||||
while ((grp = getgrent())) {
|
||||
setgrent ();
|
||||
while ((grp = getgrent ())) {
|
||||
#endif
|
||||
if (strcmp(group_name, grp->gr_name) == 0) {
|
||||
if (strcmp (group_name, grp->gr_name) == 0) {
|
||||
if (fflg) {
|
||||
fail_exit(E_SUCCESS);
|
||||
fail_exit (E_SUCCESS);
|
||||
}
|
||||
fprintf(stderr, _("%s: name %s is not unique\n"),
|
||||
Prog, group_name);
|
||||
fail_exit(E_NAME_IN_USE);
|
||||
fprintf (stderr, _("%s: name %s is not unique\n"),
|
||||
Prog, group_name);
|
||||
fail_exit (E_NAME_IN_USE);
|
||||
}
|
||||
if (gflg && group_id == grp->gr_gid) {
|
||||
if (fflg) {
|
||||
/* turn off -g and search again */
|
||||
gflg = 0;
|
||||
#ifdef NO_GETGRENT
|
||||
gr_rewind();
|
||||
gr_rewind ();
|
||||
#else
|
||||
setgrent();
|
||||
setgrent ();
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
fprintf(stderr, _("%s: gid %ld is not unique\n"),
|
||||
Prog, (long) group_id);
|
||||
fail_exit(E_GID_IN_USE);
|
||||
fprintf (stderr, _("%s: gid %u is not unique\n"),
|
||||
Prog, (unsigned int) group_id);
|
||||
fail_exit (E_GID_IN_USE);
|
||||
}
|
||||
if (! gflg && grp->gr_gid >= group_id) {
|
||||
if (!gflg && grp->gr_gid >= group_id) {
|
||||
if (grp->gr_gid > gid_max)
|
||||
continue;
|
||||
group_id = grp->gr_gid + 1;
|
||||
@ -289,20 +280,20 @@ find_new_gid(void)
|
||||
if (!gflg && group_id == gid_max + 1) {
|
||||
for (group_id = gid_min; group_id < gid_max; group_id++) {
|
||||
#ifdef NO_GETGRENT
|
||||
gr_rewind();
|
||||
while ((grp = gr_next()) && grp->gr_gid != group_id)
|
||||
;
|
||||
gr_rewind ();
|
||||
while ((grp = gr_next ())
|
||||
&& grp->gr_gid != group_id);
|
||||
if (!grp)
|
||||
break;
|
||||
#else
|
||||
if (!getgrgid(group_id))
|
||||
if (!getgrgid (group_id))
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
if (group_id == gid_max) {
|
||||
fprintf(stderr, _("%s: can't get unique gid\n"),
|
||||
Prog);
|
||||
fail_exit(E_GID_IN_USE);
|
||||
fprintf (stderr, _("%s: can't get unique gid\n"),
|
||||
Prog);
|
||||
fail_exit (E_GID_IN_USE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -310,52 +301,51 @@ find_new_gid(void)
|
||||
/*
|
||||
* check_new_name - check the new name for validity
|
||||
*
|
||||
* check_new_name() insures that the new name doesn't contain
|
||||
* any illegal characters.
|
||||
* check_new_name() insures that the new name doesn't contain any
|
||||
* illegal characters.
|
||||
*/
|
||||
|
||||
static void
|
||||
check_new_name(void)
|
||||
static void check_new_name (void)
|
||||
{
|
||||
if (check_group_name(group_name))
|
||||
if (check_group_name (group_name))
|
||||
return;
|
||||
|
||||
/*
|
||||
* All invalid group names land here.
|
||||
*/
|
||||
|
||||
fprintf(stderr, _("%s: %s is a not a valid group name\n"),
|
||||
Prog, group_name);
|
||||
fprintf (stderr, _("%s: %s is a not a valid group name\n"),
|
||||
Prog, group_name);
|
||||
|
||||
exit(E_BAD_ARG);
|
||||
exit (E_BAD_ARG);
|
||||
}
|
||||
|
||||
/*
|
||||
* process_flags - perform command line argument setting
|
||||
*
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
static void
|
||||
process_flags(int argc, char **argv)
|
||||
static void process_flags (int argc, char **argv)
|
||||
{
|
||||
char *cp;
|
||||
int arg;
|
||||
|
||||
while ((arg = getopt(argc, argv, "og:O:f")) != EOF) {
|
||||
while ((arg = getopt (argc, argv, "og:O:f")) != EOF) {
|
||||
switch (arg) {
|
||||
case 'g':
|
||||
gflg++;
|
||||
if (! isdigit (optarg[0]))
|
||||
if (!isdigit (optarg[0]))
|
||||
usage ();
|
||||
|
||||
group_id = strtol(optarg, &cp, 10);
|
||||
group_id = strtoul (optarg, &cp, 10);
|
||||
if (*cp != '\0') {
|
||||
fprintf(stderr, _("%s: invalid group %s\n"),
|
||||
Prog, optarg);
|
||||
fail_exit(E_BAD_ARG);
|
||||
fprintf (stderr,
|
||||
_("%s: invalid group %s\n"), Prog,
|
||||
optarg);
|
||||
fail_exit (E_BAD_ARG);
|
||||
}
|
||||
break;
|
||||
case 'o':
|
||||
@ -367,67 +357,68 @@ process_flags(int argc, char **argv)
|
||||
* example: -O GID_MIN=100 -O GID_MAX=499
|
||||
* note: -O GID_MIN=10,GID_MAX=499 doesn't work yet
|
||||
*/
|
||||
cp = strchr(optarg, '=');
|
||||
cp = strchr (optarg, '=');
|
||||
if (!cp) {
|
||||
fprintf(stderr,
|
||||
_("%s: -O requires NAME=VALUE\n"),
|
||||
Prog);
|
||||
exit(E_BAD_ARG);
|
||||
fprintf (stderr,
|
||||
_("%s: -O requires NAME=VALUE\n"),
|
||||
Prog);
|
||||
exit (E_BAD_ARG);
|
||||
}
|
||||
/* terminate name, point to value */
|
||||
*cp++ = '\0';
|
||||
if (putdef_str(optarg, cp) < 0)
|
||||
exit(E_BAD_ARG);
|
||||
if (putdef_str (optarg, cp) < 0)
|
||||
exit (E_BAD_ARG);
|
||||
break;
|
||||
case 'f':
|
||||
/*
|
||||
* "force" - do nothing, just exit(0), if the
|
||||
* specified group already exists. With -g, if
|
||||
* specified group already exists. With -g, if
|
||||
* specified gid already exists, choose another
|
||||
* (unique) gid (turn off -g). Based on the
|
||||
* RedHat's patch from shadow-utils-970616-9.
|
||||
* (unique) gid (turn off -g). Based on the RedHat's
|
||||
* patch from shadow-utils-970616-9.
|
||||
*/
|
||||
fflg++;
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
usage ();
|
||||
}
|
||||
}
|
||||
|
||||
if (oflg && !gflg)
|
||||
usage();
|
||||
usage ();
|
||||
|
||||
if (optind != argc - 1)
|
||||
usage();
|
||||
usage ();
|
||||
|
||||
group_name = argv[argc - 1];
|
||||
check_new_name();
|
||||
check_new_name ();
|
||||
}
|
||||
|
||||
/*
|
||||
* close_files - close all of the files that were opened
|
||||
*
|
||||
* close_files() closes all of the files that were opened for this
|
||||
* new group. This causes any modified entries to be written out.
|
||||
* close_files() closes all of the files that were opened for this new
|
||||
* group. This causes any modified entries to be written out.
|
||||
*/
|
||||
|
||||
static void
|
||||
close_files(void)
|
||||
static void close_files (void)
|
||||
{
|
||||
if (!gr_close()) {
|
||||
fprintf(stderr, _("%s: cannot rewrite group file\n"), Prog);
|
||||
fail_exit(E_GRP_UPDATE);
|
||||
if (!gr_close ()) {
|
||||
fprintf (stderr, _("%s: cannot rewrite group file\n"),
|
||||
Prog);
|
||||
fail_exit (E_GRP_UPDATE);
|
||||
}
|
||||
gr_unlock();
|
||||
gr_unlock ();
|
||||
#ifdef SHADOWGRP
|
||||
if (is_shadow_grp && !sgr_close()) {
|
||||
fprintf(stderr, _("%s: cannot rewrite shadow group file\n"),
|
||||
Prog);
|
||||
fail_exit(E_GRP_UPDATE);
|
||||
if (is_shadow_grp && !sgr_close ()) {
|
||||
fprintf (stderr,
|
||||
_("%s: cannot rewrite shadow group file\n"),
|
||||
Prog);
|
||||
fail_exit (E_GRP_UPDATE);
|
||||
}
|
||||
if (is_shadow_grp)
|
||||
sgr_unlock ();
|
||||
#endif /* SHADOWGRP */
|
||||
#endif /* SHADOWGRP */
|
||||
}
|
||||
|
||||
/*
|
||||
@ -436,37 +427,39 @@ close_files(void)
|
||||
* open_files() opens the two group files.
|
||||
*/
|
||||
|
||||
static void
|
||||
open_files(void)
|
||||
static void open_files (void)
|
||||
{
|
||||
if (! gr_lock ()) {
|
||||
fprintf(stderr, _("%s: unable to lock group file\n"), Prog);
|
||||
exit(E_GRP_UPDATE);
|
||||
if (!gr_lock ()) {
|
||||
fprintf (stderr, _("%s: unable to lock group file\n"),
|
||||
Prog);
|
||||
exit (E_GRP_UPDATE);
|
||||
}
|
||||
if (! gr_open (O_RDWR)) {
|
||||
fprintf(stderr, _("%s: unable to open group file\n"), Prog);
|
||||
fail_exit(E_GRP_UPDATE);
|
||||
if (!gr_open (O_RDWR)) {
|
||||
fprintf (stderr, _("%s: unable to open group file\n"),
|
||||
Prog);
|
||||
fail_exit (E_GRP_UPDATE);
|
||||
}
|
||||
#ifdef SHADOWGRP
|
||||
if (is_shadow_grp && ! sgr_lock ()) {
|
||||
fprintf(stderr, _("%s: unable to lock shadow group file\n"),
|
||||
Prog);
|
||||
fail_exit(E_GRP_UPDATE);
|
||||
if (is_shadow_grp && !sgr_lock ()) {
|
||||
fprintf (stderr,
|
||||
_("%s: unable to lock shadow group file\n"),
|
||||
Prog);
|
||||
fail_exit (E_GRP_UPDATE);
|
||||
}
|
||||
if (is_shadow_grp && ! sgr_open (O_RDWR)) {
|
||||
fprintf(stderr, _("%s: unable to open shadow group file\n"),
|
||||
Prog);
|
||||
fail_exit(E_GRP_UPDATE);
|
||||
if (is_shadow_grp && !sgr_open (O_RDWR)) {
|
||||
fprintf (stderr,
|
||||
_("%s: unable to open shadow group file\n"),
|
||||
Prog);
|
||||
fail_exit (E_GRP_UPDATE);
|
||||
}
|
||||
#endif /* SHADOWGRP */
|
||||
#endif /* SHADOWGRP */
|
||||
}
|
||||
|
||||
/*
|
||||
* fail_exit - exit with an error code after unlocking files
|
||||
*/
|
||||
|
||||
static void
|
||||
fail_exit(int code)
|
||||
static void fail_exit (int code)
|
||||
{
|
||||
(void) gr_unlock ();
|
||||
#ifdef SHADOWGRP
|
||||
@ -478,17 +471,16 @@ fail_exit(int code)
|
||||
|
||||
#ifdef USE_PAM
|
||||
static struct pam_conv conv = {
|
||||
misc_conv,
|
||||
NULL
|
||||
misc_conv,
|
||||
NULL
|
||||
};
|
||||
#endif /* USE_PAM */
|
||||
#endif /* USE_PAM */
|
||||
|
||||
/*
|
||||
* main - groupadd command
|
||||
*/
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
#ifdef USE_PAM
|
||||
pam_handle_t *pamh = NULL;
|
||||
@ -500,73 +492,76 @@ main(int argc, char **argv)
|
||||
* Get my name so that I can use it to report errors.
|
||||
*/
|
||||
|
||||
Prog = Basename(argv[0]);
|
||||
Prog = Basename (argv[0]);
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
bindtextdomain(PACKAGE, LOCALEDIR);
|
||||
textdomain(PACKAGE);
|
||||
setlocale (LC_ALL, "");
|
||||
bindtextdomain (PACKAGE, LOCALEDIR);
|
||||
textdomain (PACKAGE);
|
||||
|
||||
#ifdef USE_PAM
|
||||
retval = PAM_SUCCESS;
|
||||
|
||||
pampw = getpwuid(getuid());
|
||||
pampw = getpwuid (getuid ());
|
||||
if (pampw == NULL) {
|
||||
retval = PAM_USER_UNKNOWN;
|
||||
}
|
||||
|
||||
if (retval == PAM_SUCCESS) {
|
||||
retval = pam_start("shadow", pampw->pw_name, &conv, &pamh);
|
||||
retval =
|
||||
pam_start ("shadow", pampw->pw_name, &conv, &pamh);
|
||||
}
|
||||
|
||||
if (retval == PAM_SUCCESS) {
|
||||
retval = pam_authenticate(pamh, 0);
|
||||
retval = pam_authenticate (pamh, 0);
|
||||
if (retval != PAM_SUCCESS) {
|
||||
pam_end(pamh, retval);
|
||||
pam_end (pamh, retval);
|
||||
}
|
||||
}
|
||||
|
||||
if (retval == PAM_SUCCESS) {
|
||||
retval = pam_acct_mgmt(pamh, 0);
|
||||
retval = pam_acct_mgmt (pamh, 0);
|
||||
if (retval != PAM_SUCCESS) {
|
||||
pam_end(pamh, retval);
|
||||
pam_end (pamh, retval);
|
||||
}
|
||||
}
|
||||
|
||||
if (retval != PAM_SUCCESS) {
|
||||
fprintf (stderr, _("%s: PAM authentication failed\n"), Prog);
|
||||
fprintf (stderr, _("%s: PAM authentication failed\n"),
|
||||
Prog);
|
||||
exit (1);
|
||||
}
|
||||
#endif /* USE_PAM */
|
||||
#endif /* USE_PAM */
|
||||
|
||||
OPENLOG(Prog);
|
||||
OPENLOG (Prog);
|
||||
|
||||
#ifdef SHADOWGRP
|
||||
is_shadow_grp = sgr_file_present();
|
||||
is_shadow_grp = sgr_file_present ();
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The open routines for the DBM files don't use read-write
|
||||
* as the mode, so we have to clue them in.
|
||||
* The open routines for the DBM files don't use read-write as the
|
||||
* mode, so we have to clue them in.
|
||||
*/
|
||||
|
||||
#ifdef NDBM
|
||||
gr_dbm_mode = O_RDWR;
|
||||
#ifdef SHADOWGRP
|
||||
sg_dbm_mode = O_RDWR;
|
||||
#endif /* SHADOWGRP */
|
||||
#endif /* NDBM */
|
||||
process_flags(argc, argv);
|
||||
#endif /* SHADOWGRP */
|
||||
#endif /* NDBM */
|
||||
process_flags (argc, argv);
|
||||
|
||||
/*
|
||||
* Start with a quick check to see if the group exists.
|
||||
*/
|
||||
|
||||
if (getgrnam(group_name)) {
|
||||
if (getgrnam (group_name)) {
|
||||
if (fflg) {
|
||||
exit(E_SUCCESS);
|
||||
exit (E_SUCCESS);
|
||||
}
|
||||
fprintf(stderr, _("%s: group %s exists\n"), Prog, group_name);
|
||||
exit(E_NAME_IN_USE);
|
||||
fprintf (stderr, _("%s: group %s exists\n"), Prog,
|
||||
group_name);
|
||||
exit (E_NAME_IN_USE);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -574,20 +569,20 @@ main(int argc, char **argv)
|
||||
* then close and update the files.
|
||||
*/
|
||||
|
||||
open_files();
|
||||
open_files ();
|
||||
|
||||
if (!gflg || !oflg)
|
||||
find_new_gid();
|
||||
find_new_gid ();
|
||||
|
||||
grp_update();
|
||||
grp_update ();
|
||||
|
||||
close_files();
|
||||
close_files ();
|
||||
|
||||
#ifdef USE_PAM
|
||||
if (retval == PAM_SUCCESS) {
|
||||
retval = pam_chauthtok(pamh, 0);
|
||||
retval = pam_chauthtok (pamh, 0);
|
||||
if (retval != PAM_SUCCESS) {
|
||||
pam_end(pamh, retval);
|
||||
pam_end (pamh, retval);
|
||||
}
|
||||
}
|
||||
|
||||
@ -597,8 +592,7 @@ main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (retval == PAM_SUCCESS)
|
||||
pam_end(pamh, PAM_SUCCESS);
|
||||
#endif /* USE_PAM */
|
||||
exit(E_SUCCESS);
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
pam_end (pamh, PAM_SUCCESS);
|
||||
#endif /* USE_PAM */
|
||||
exit (E_SUCCESS);
|
||||
/*NOTREACHED*/}
|
||||
|
Reference in New Issue
Block a user