[svn-upgrade] Integrating new upstream version, shadow (4.0.1)
This commit is contained in:
451
src/groupmod.c
451
src/groupmod.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,29 +30,23 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID(PKG_VER "$Id: groupmod.c,v 1.16 2000/10/09 19:02:20 kloczek Exp $")
|
||||
|
||||
RCSID (PKG_VER "$Id: groupmod.c,v 1.19 2002/01/05 15:41:43 kloczek Exp $")
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <grp.h>
|
||||
#include <ctype.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#ifdef USE_PAM
|
||||
#include <security/pam_appl.h>
|
||||
#include <security/pam_misc.h>
|
||||
#include <pwd.h>
|
||||
#endif /* USE_PAM */
|
||||
|
||||
#endif /* USE_PAM */
|
||||
#include "prototypes.h"
|
||||
#include "chkname.h"
|
||||
#include "defines.h"
|
||||
|
||||
#include "groupio.h"
|
||||
|
||||
#ifdef SHADOWGRP
|
||||
#include "sgroupio.h"
|
||||
|
||||
static int is_shadow_grp;
|
||||
#endif
|
||||
|
||||
@@ -68,59 +62,56 @@ static int is_shadow_grp;
|
||||
#define E_NAME_IN_USE 9 /* group name already in use */
|
||||
#define E_GRP_UPDATE 10 /* can't update group file */
|
||||
|
||||
static char *group_name;
|
||||
static char *group_newname;
|
||||
static gid_t group_id;
|
||||
static gid_t group_newid;
|
||||
static char *group_name;
|
||||
static char *group_newname;
|
||||
static gid_t group_id;
|
||||
static gid_t group_newid;
|
||||
|
||||
static char *Prog;
|
||||
static char *Prog;
|
||||
|
||||
static int
|
||||
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 */
|
||||
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 */
|
||||
|
||||
#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 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);
|
||||
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);
|
||||
|
||||
/*
|
||||
* usage - display usage message and exit
|
||||
*/
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
static void usage (void)
|
||||
{
|
||||
fprintf(stderr, _("usage: groupmod [-g gid [-o]] [-n name] group\n"));
|
||||
exit(E_USAGE);
|
||||
fprintf (stderr,
|
||||
_("usage: groupmod [-g gid [-o]] [-n name] group\n"));
|
||||
exit (E_USAGE);
|
||||
}
|
||||
|
||||
/*
|
||||
* new_grent - updates 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)
|
||||
{
|
||||
if (nflg)
|
||||
grent->gr_name = xstrdup (group_newname);
|
||||
@@ -133,17 +124,16 @@ new_grent(struct group *grent)
|
||||
/*
|
||||
* new_sgent - updates 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)
|
||||
{
|
||||
if (nflg)
|
||||
sgent->sg_name = xstrdup (group_newname);
|
||||
}
|
||||
#endif /* SHADOWGRP */
|
||||
#endif /* SHADOWGRP */
|
||||
|
||||
/*
|
||||
* grp_update - update group file entries
|
||||
@@ -151,47 +141,49 @@ 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;
|
||||
const struct group *ogrp;
|
||||
|
||||
#ifdef SHADOWGRP
|
||||
struct sgrp sgrp;
|
||||
const struct sgrp *osgrp = NULL;
|
||||
#endif /* SHADOWGRP */
|
||||
#endif /* SHADOWGRP */
|
||||
|
||||
/*
|
||||
* Get the current settings for this group.
|
||||
*/
|
||||
|
||||
ogrp = gr_locate(group_name);
|
||||
ogrp = gr_locate (group_name);
|
||||
if (!ogrp) {
|
||||
fprintf(stderr,
|
||||
_("%s: %s not found in /etc/group\n"),
|
||||
Prog, group_name);
|
||||
exit(E_GRP_UPDATE);
|
||||
fprintf (stderr,
|
||||
_("%s: %s not found in /etc/group\n"),
|
||||
Prog, group_name);
|
||||
exit (E_GRP_UPDATE);
|
||||
}
|
||||
grp = *ogrp;
|
||||
new_grent (&grp);
|
||||
#ifdef SHADOWGRP
|
||||
if (is_shadow_grp && (osgrp = sgr_locate(group_name))) {
|
||||
if (is_shadow_grp && (osgrp = sgr_locate (group_name))) {
|
||||
sgrp = *osgrp;
|
||||
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);
|
||||
exit(E_GRP_UPDATE);
|
||||
if (!gr_update (&grp)) {
|
||||
fprintf (stderr, _("%s: error adding new group entry\n"),
|
||||
Prog);
|
||||
exit (E_GRP_UPDATE);
|
||||
}
|
||||
if (nflg && !gr_remove(group_name)) {
|
||||
fprintf(stderr, _("%s: error removing group entry\n"), Prog);
|
||||
exit(E_GRP_UPDATE);
|
||||
if (nflg && !gr_remove (group_name)) {
|
||||
fprintf (stderr, _("%s: error removing group entry\n"),
|
||||
Prog);
|
||||
exit (E_GRP_UPDATE);
|
||||
}
|
||||
#ifdef NDBM
|
||||
|
||||
@@ -199,46 +191,48 @@ grp_update(void)
|
||||
* Update the DBM group file with the new entry as well.
|
||||
*/
|
||||
|
||||
if (gr_dbm_present()) {
|
||||
if (!gr_dbm_update(&grp)) {
|
||||
fprintf(stderr,
|
||||
_("%s: cannot add new dbm group entry\n"),
|
||||
Prog);
|
||||
exit(E_GRP_UPDATE);
|
||||
if (gr_dbm_present ()) {
|
||||
if (!gr_dbm_update (&grp)) {
|
||||
fprintf (stderr,
|
||||
_("%s: cannot add new dbm group entry\n"),
|
||||
Prog);
|
||||
exit (E_GRP_UPDATE);
|
||||
}
|
||||
if (nflg && (ogrp = getgrnam(group_name)) &&
|
||||
!gr_dbm_remove(ogrp)) {
|
||||
fprintf(stderr,
|
||||
_("%s: error removing group dbm entry\n"),
|
||||
Prog);
|
||||
exit(E_GRP_UPDATE);
|
||||
if (nflg && (ogrp = getgrnam (group_name)) &&
|
||||
!gr_dbm_remove (ogrp)) {
|
||||
fprintf (stderr,
|
||||
_("%s: error removing group dbm entry\n"),
|
||||
Prog);
|
||||
exit (E_GRP_UPDATE);
|
||||
}
|
||||
endgrent ();
|
||||
}
|
||||
#endif /* NDBM */
|
||||
#endif /* NDBM */
|
||||
|
||||
#ifdef SHADOWGRP
|
||||
|
||||
/*
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
if (! osgrp)
|
||||
if (!osgrp)
|
||||
goto out;
|
||||
|
||||
/*
|
||||
* Write out the new shadow group entries as well.
|
||||
*/
|
||||
|
||||
if (!sgr_update(&sgrp)) {
|
||||
fprintf(stderr, _("%s: error adding new group entry\n"), Prog);
|
||||
exit(E_GRP_UPDATE);
|
||||
if (!sgr_update (&sgrp)) {
|
||||
fprintf (stderr, _("%s: error adding new group entry\n"),
|
||||
Prog);
|
||||
exit (E_GRP_UPDATE);
|
||||
}
|
||||
if (nflg && !sgr_remove(group_name)) {
|
||||
fprintf(stderr, _("%s: error removing group entry\n"), Prog);
|
||||
exit(E_GRP_UPDATE);
|
||||
if (nflg && !sgr_remove (group_name)) {
|
||||
fprintf (stderr, _("%s: error removing group entry\n"),
|
||||
Prog);
|
||||
exit (E_GRP_UPDATE);
|
||||
}
|
||||
#ifdef NDBM
|
||||
|
||||
@@ -246,32 +240,34 @@ grp_update(void)
|
||||
* Update the DBM shadow group file with the new entry as well.
|
||||
*/
|
||||
|
||||
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);
|
||||
}
|
||||
if (nflg && ! sg_dbm_remove (group_name)) {
|
||||
if (sg_dbm_present ()) {
|
||||
if (!sg_dbm_update (&sgrp)) {
|
||||
fprintf (stderr,
|
||||
_("%s: error removing shadow group dbm entry\n"),
|
||||
Prog);
|
||||
exit(E_GRP_UPDATE);
|
||||
_
|
||||
("%s: cannot add new dbm shadow group entry\n"),
|
||||
Prog);
|
||||
exit (E_GRP_UPDATE);
|
||||
}
|
||||
if (nflg && !sg_dbm_remove (group_name)) {
|
||||
fprintf (stderr,
|
||||
_
|
||||
("%s: error removing shadow group dbm entry\n"),
|
||||
Prog);
|
||||
exit (E_GRP_UPDATE);
|
||||
}
|
||||
endsgent ();
|
||||
}
|
||||
#endif /* NDBM */
|
||||
out:
|
||||
#endif /* SHADOWGRP */
|
||||
#endif /* NDBM */
|
||||
out:
|
||||
#endif /* SHADOWGRP */
|
||||
|
||||
if (nflg)
|
||||
SYSLOG((LOG_INFO, "change group `%s' to `%s'\n",
|
||||
group_name, group_newname));
|
||||
SYSLOG ((LOG_INFO, "change group `%s' to `%s'",
|
||||
group_name, group_newname));
|
||||
|
||||
if (gflg)
|
||||
SYSLOG((LOG_INFO, "change gid for `%s' to %d\n",
|
||||
nflg ? group_newname:group_name, group_newid));
|
||||
SYSLOG ((LOG_INFO, "change gid for `%s' to %u",
|
||||
nflg ? group_newname : group_name, group_newid));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -280,13 +276,12 @@ out:
|
||||
* check_new_gid() insures that the new GID value is unique.
|
||||
*/
|
||||
|
||||
static void
|
||||
check_new_gid(void)
|
||||
static void check_new_gid (void)
|
||||
{
|
||||
/*
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
if (group_id == group_newid) {
|
||||
@@ -294,48 +289,47 @@ check_new_gid(void)
|
||||
return;
|
||||
}
|
||||
|
||||
if (oflg || ! getgrgid (group_newid))
|
||||
if (oflg || !getgrgid (group_newid))
|
||||
return;
|
||||
|
||||
/*
|
||||
* Tell the user what they did wrong.
|
||||
*/
|
||||
|
||||
fprintf(stderr,
|
||||
_("%s: %ld is not a unique gid\n"),
|
||||
Prog, (long) group_newid);
|
||||
exit(E_GID_IN_USE);
|
||||
fprintf (stderr,
|
||||
_("%s: %u is not a unique gid\n"), Prog, group_newid);
|
||||
exit (E_GID_IN_USE);
|
||||
}
|
||||
|
||||
/*
|
||||
* check_new_name - check the new name for uniqueness
|
||||
*
|
||||
* check_new_name() insures that the new name does not exist
|
||||
* already. You can't have the same name twice, period.
|
||||
* check_new_name() insures that the new name does not exist already.
|
||||
* You can't have the same name twice, period.
|
||||
*/
|
||||
|
||||
static void
|
||||
check_new_name(void)
|
||||
static void check_new_name (void)
|
||||
{
|
||||
/*
|
||||
* Make sure they are actually changing the name.
|
||||
*/
|
||||
|
||||
if (strcmp(group_name, group_newname) == 0) {
|
||||
if (strcmp (group_name, group_newname) == 0) {
|
||||
nflg = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (check_group_name(group_newname)) {
|
||||
if (check_group_name (group_newname)) {
|
||||
|
||||
/*
|
||||
* If the entry is found, too bad.
|
||||
*/
|
||||
|
||||
if (getgrnam(group_newname)) {
|
||||
fprintf(stderr, _("%s: %s is not a unique name\n"),
|
||||
Prog, group_newname);
|
||||
exit(E_NAME_IN_USE);
|
||||
if (getgrnam (group_newname)) {
|
||||
fprintf (stderr,
|
||||
_("%s: %s is not a unique name\n"), Prog,
|
||||
group_newname);
|
||||
exit (E_NAME_IN_USE);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -344,53 +338,52 @@ check_new_name(void)
|
||||
* All invalid group names land here.
|
||||
*/
|
||||
|
||||
fprintf(stderr, _("%s: %s is a not a valid group name\n"),
|
||||
Prog, group_newname);
|
||||
exit(E_BAD_ARG);
|
||||
fprintf (stderr, _("%s: %s is a not a valid group name\n"),
|
||||
Prog, group_newname);
|
||||
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 *end;
|
||||
int arg;
|
||||
char *end;
|
||||
int arg;
|
||||
|
||||
while ((arg = getopt (argc, argv, "og:n:")) != EOF) {
|
||||
switch (arg) {
|
||||
case 'g':
|
||||
gflg++;
|
||||
group_newid = strtol(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 ();
|
||||
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 ();
|
||||
}
|
||||
}
|
||||
if (oflg && !gflg)
|
||||
usage();
|
||||
usage ();
|
||||
|
||||
if (optind != argc - 1)
|
||||
usage();
|
||||
usage ();
|
||||
|
||||
group_name = argv[argc - 1];
|
||||
}
|
||||
@@ -398,27 +391,28 @@ process_flags(int argc, char **argv)
|
||||
/*
|
||||
* 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);
|
||||
exit(E_GRP_UPDATE);
|
||||
if (!gr_close ()) {
|
||||
fprintf (stderr, _("%s: cannot rewrite group file\n"),
|
||||
Prog);
|
||||
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);
|
||||
exit(E_GRP_UPDATE);
|
||||
if (is_shadow_grp && !sgr_close ()) {
|
||||
fprintf (stderr,
|
||||
_("%s: cannot rewrite shadow group file\n"),
|
||||
Prog);
|
||||
exit (E_GRP_UPDATE);
|
||||
}
|
||||
if (is_shadow_grp)
|
||||
sgr_unlock ();
|
||||
#endif /* SHADOWGRP */
|
||||
#endif /* SHADOWGRP */
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -427,37 +421,40 @@ 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);
|
||||
exit(E_GRP_UPDATE);
|
||||
if (!gr_open (O_RDWR)) {
|
||||
fprintf (stderr, _("%s: unable to open group file\n"),
|
||||
Prog);
|
||||
exit (E_GRP_UPDATE);
|
||||
}
|
||||
#ifdef SHADOWGRP
|
||||
if (is_shadow_grp && !sgr_lock()) {
|
||||
fprintf(stderr, _("%s: unable to lock shadow group file\n"),
|
||||
Prog);
|
||||
exit(E_GRP_UPDATE);
|
||||
if (is_shadow_grp && !sgr_lock ()) {
|
||||
fprintf (stderr,
|
||||
_("%s: unable to lock shadow group file\n"),
|
||||
Prog);
|
||||
exit (E_GRP_UPDATE);
|
||||
}
|
||||
if (is_shadow_grp && !sgr_open(O_RDWR)) {
|
||||
fprintf(stderr, _("%s: unable to open shadow group file\n"),
|
||||
Prog);
|
||||
exit(E_GRP_UPDATE);
|
||||
if (is_shadow_grp && !sgr_open (O_RDWR)) {
|
||||
fprintf (stderr,
|
||||
_("%s: unable to open shadow group file\n"),
|
||||
Prog);
|
||||
exit (E_GRP_UPDATE);
|
||||
}
|
||||
#endif /* SHADOWGRP */
|
||||
#endif /* SHADOWGRP */
|
||||
}
|
||||
|
||||
#ifdef USE_PAM
|
||||
static struct pam_conv conv = {
|
||||
misc_conv,
|
||||
NULL
|
||||
misc_conv,
|
||||
NULL
|
||||
};
|
||||
#endif /* USE_PAM */
|
||||
#endif /* USE_PAM */
|
||||
|
||||
/*
|
||||
* main - groupmod command
|
||||
@@ -472,10 +469,10 @@ static struct pam_conv conv = {
|
||||
* -n - specify a new group name
|
||||
*/
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
struct group *grp;
|
||||
struct group *grp;
|
||||
|
||||
#ifdef USE_PAM
|
||||
pam_handle_t *pamh = NULL;
|
||||
struct passwd *pampw;
|
||||
@@ -486,71 +483,73 @@ 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 */
|
||||
#endif /* SHADOWGRP */
|
||||
#endif /* NDBM */
|
||||
process_flags (argc, argv);
|
||||
|
||||
/*
|
||||
* Start with a quick check to see if the group exists.
|
||||
*/
|
||||
|
||||
if (!(grp = getgrnam(group_name))) {
|
||||
fprintf(stderr, _("%s: group %s does not exist\n"),
|
||||
Prog, group_name);
|
||||
exit(E_NOTFOUND);
|
||||
if (!(grp = getgrnam (group_name))) {
|
||||
fprintf (stderr, _("%s: group %s does not exist\n"),
|
||||
Prog, group_name);
|
||||
exit (E_NOTFOUND);
|
||||
} else
|
||||
group_id = grp->gr_gid;
|
||||
|
||||
@@ -561,19 +560,18 @@ main(int argc, char **argv)
|
||||
*/
|
||||
|
||||
if (__isgrNIS ()) {
|
||||
char *nis_domain;
|
||||
char *nis_master;
|
||||
char *nis_domain;
|
||||
char *nis_master;
|
||||
|
||||
fprintf(stderr, _("%s: group %s is a NIS group\n"),
|
||||
Prog, group_name);
|
||||
fprintf (stderr, _("%s: group %s is a NIS group\n"),
|
||||
Prog, group_name);
|
||||
|
||||
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);
|
||||
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);
|
||||
}
|
||||
exit(E_NOTFOUND);
|
||||
exit (E_NOTFOUND);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -596,9 +594,9 @@ main(int argc, char **argv)
|
||||
|
||||
#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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -608,8 +606,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