[svn-upgrade] Integrating new upstream version, shadow (4.0.18)

This commit is contained in:
nekral-guest
2007-10-07 11:47:57 +00:00
parent 8a78a8d68c
commit 5e20c4359f
282 changed files with 25348 additions and 11794 deletions

View File

@@ -28,6 +28,7 @@ usbin_PROGRAMS = \
chpasswd \
groupadd \
groupdel \
groupmems \
groupmod \
grpck \
grpconv \
@@ -60,6 +61,7 @@ chpasswd_LDADD = $(LDADD) $(LIBPAM) $(LIBSELINUX)
gpasswd_LDADD = $(LDADD) $(LIBAUDIT) $(LIBSELINUX)
groupadd_LDADD = $(LDADD) $(LIBPAM) $(LIBAUDIT) $(LIBSELINUX)
groupdel_LDADD = $(LDADD) $(LIBPAM) $(LIBAUDIT) $(LIBSELINUX)
groupmems_LDADD = $(LDADD) $(LIBPAM) $(LIBSELINUX)
groupmod_LDADD = $(LDADD) $(LIBPAM) $(LIBAUDIT) $(LIBSELINUX)
grpck_LDADD = $(LDADD) $(LIBSELINUX)
grpconv_LDADD = $(LDADD) $(LIBSELINUX)

View File

@@ -42,11 +42,12 @@ ubin_PROGRAMS = faillog$(EXEEXT) lastlog$(EXEEXT) chage$(EXEEXT) \
chfn$(EXEEXT) chsh$(EXEEXT) expiry$(EXEEXT) gpasswd$(EXEEXT) \
newgrp$(EXEEXT) passwd$(EXEEXT)
usbin_PROGRAMS = chgpasswd$(EXEEXT) chpasswd$(EXEEXT) \
groupadd$(EXEEXT) groupdel$(EXEEXT) groupmod$(EXEEXT) \
grpck$(EXEEXT) grpconv$(EXEEXT) grpunconv$(EXEEXT) \
logoutd$(EXEEXT) newusers$(EXEEXT) pwck$(EXEEXT) \
pwconv$(EXEEXT) pwunconv$(EXEEXT) useradd$(EXEEXT) \
userdel$(EXEEXT) usermod$(EXEEXT) vipw$(EXEEXT)
groupadd$(EXEEXT) groupdel$(EXEEXT) groupmems$(EXEEXT) \
groupmod$(EXEEXT) grpck$(EXEEXT) grpconv$(EXEEXT) \
grpunconv$(EXEEXT) logoutd$(EXEEXT) newusers$(EXEEXT) \
pwck$(EXEEXT) pwconv$(EXEEXT) pwunconv$(EXEEXT) \
useradd$(EXEEXT) userdel$(EXEEXT) usermod$(EXEEXT) \
vipw$(EXEEXT)
noinst_PROGRAMS = id$(EXEEXT) sulogin$(EXEEXT)
subdir = src
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
@@ -111,6 +112,10 @@ groupdel_SOURCES = groupdel.c
groupdel_OBJECTS = groupdel.$(OBJEXT)
groupdel_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2) \
$(am__DEPENDENCIES_2) $(am__DEPENDENCIES_2)
groupmems_SOURCES = groupmems.c
groupmems_OBJECTS = groupmems.$(OBJEXT)
groupmems_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2) \
$(am__DEPENDENCIES_2)
groupmod_SOURCES = groupmod.c
groupmod_OBJECTS = groupmod.$(OBJEXT)
groupmod_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2) \
@@ -208,17 +213,17 @@ CCLD = $(CC)
LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(AM_LDFLAGS) $(LDFLAGS) -o $@
SOURCES = chage.c chfn.c chgpasswd.c chpasswd.c chsh.c expiry.c \
faillog.c gpasswd.c groupadd.c groupdel.c groupmod.c groups.c \
grpck.c grpconv.c grpunconv.c id.c lastlog.c $(login_SOURCES) \
logoutd.c newgrp.c newusers.c nologin.c passwd.c pwck.c \
pwconv.c pwunconv.c $(su_SOURCES) sulogin.c useradd.c \
userdel.c usermod.c vipw.c
faillog.c gpasswd.c groupadd.c groupdel.c groupmems.c \
groupmod.c groups.c grpck.c grpconv.c grpunconv.c id.c \
lastlog.c $(login_SOURCES) logoutd.c newgrp.c newusers.c \
nologin.c passwd.c pwck.c pwconv.c pwunconv.c $(su_SOURCES) \
sulogin.c useradd.c userdel.c usermod.c vipw.c
DIST_SOURCES = chage.c chfn.c chgpasswd.c chpasswd.c chsh.c expiry.c \
faillog.c gpasswd.c groupadd.c groupdel.c groupmod.c groups.c \
grpck.c grpconv.c grpunconv.c id.c lastlog.c $(login_SOURCES) \
logoutd.c newgrp.c newusers.c nologin.c passwd.c pwck.c \
pwconv.c pwunconv.c $(su_SOURCES) sulogin.c useradd.c \
userdel.c usermod.c vipw.c
faillog.c gpasswd.c groupadd.c groupdel.c groupmems.c \
groupmod.c groups.c grpck.c grpconv.c grpunconv.c id.c \
lastlog.c $(login_SOURCES) logoutd.c newgrp.c newusers.c \
nologin.c passwd.c pwck.c pwconv.c pwunconv.c $(su_SOURCES) \
sulogin.c useradd.c userdel.c usermod.c vipw.c
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
@@ -254,6 +259,7 @@ EXEEXT = @EXEEXT@
F77 = @F77@
FFLAGS = @FFLAGS@
GMSGFMT = @GMSGFMT@
GREP = @GREP@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
@@ -294,6 +300,7 @@ PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
POSUB = @POSUB@
RANLIB = @RANLIB@
SED = @SED@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
STRIP = @STRIP@
@@ -309,12 +316,10 @@ XMLCATALOG = @XMLCATALOG@
XML_CATALOG_FILE = @XML_CATALOG_FILE@
XSLTPROC = @XSLTPROC@
YACC = @YACC@
ac_ct_AR = @ac_ct_AR@
YFLAGS = @YFLAGS@
ac_ct_CC = @ac_ct_CC@
ac_ct_CXX = @ac_ct_CXX@
ac_ct_F77 = @ac_ct_F77@
ac_ct_RANLIB = @ac_ct_RANLIB@
ac_ct_STRIP = @ac_ct_STRIP@
am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@
@@ -331,23 +336,30 @@ build_cpu = @build_cpu@
build_os = @build_os@
build_vendor = @build_vendor@
datadir = @datadir@
datarootdir = @datarootdir@
docdir = @docdir@
dvidir = @dvidir@
exec_prefix = @exec_prefix@
host = @host@
host_alias = @host_alias@
host_cpu = @host_cpu@
host_os = @host_os@
host_vendor = @host_vendor@
htmldir = @htmldir@
includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
libdir = @libdir@
libexecdir = @libexecdir@
localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
sysconfdir = @sysconfdir@
@@ -375,6 +387,7 @@ chpasswd_LDADD = $(LDADD) $(LIBPAM) $(LIBSELINUX)
gpasswd_LDADD = $(LDADD) $(LIBAUDIT) $(LIBSELINUX)
groupadd_LDADD = $(LDADD) $(LIBPAM) $(LIBAUDIT) $(LIBSELINUX)
groupdel_LDADD = $(LDADD) $(LIBPAM) $(LIBAUDIT) $(LIBSELINUX)
groupmems_LDADD = $(LDADD) $(LIBPAM) $(LIBSELINUX)
groupmod_LDADD = $(LDADD) $(LIBPAM) $(LIBAUDIT) $(LIBSELINUX)
grpck_LDADD = $(LDADD) $(LIBSELINUX)
grpconv_LDADD = $(LDADD) $(LIBSELINUX)
@@ -413,9 +426,9 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__confi
exit 1;; \
esac; \
done; \
echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/Makefile'; \
echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/Makefile'; \
cd $(top_srcdir) && \
$(AUTOMAKE) --gnu src/Makefile
$(AUTOMAKE) --foreign src/Makefile
.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@case '$?' in \
@@ -582,6 +595,9 @@ groupadd$(EXEEXT): $(groupadd_OBJECTS) $(groupadd_DEPENDENCIES)
groupdel$(EXEEXT): $(groupdel_OBJECTS) $(groupdel_DEPENDENCIES)
@rm -f groupdel$(EXEEXT)
$(LINK) $(groupdel_LDFLAGS) $(groupdel_OBJECTS) $(groupdel_LDADD) $(LIBS)
groupmems$(EXEEXT): $(groupmems_OBJECTS) $(groupmems_DEPENDENCIES)
@rm -f groupmems$(EXEEXT)
$(LINK) $(groupmems_LDFLAGS) $(groupmems_OBJECTS) $(groupmems_LDADD) $(LIBS)
groupmod$(EXEEXT): $(groupmod_OBJECTS) $(groupmod_DEPENDENCIES)
@rm -f groupmod$(EXEEXT)
$(LINK) $(groupmod_LDFLAGS) $(groupmod_OBJECTS) $(groupmod_LDADD) $(LIBS)
@@ -665,6 +681,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gpasswd.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/groupadd.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/groupdel.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/groupmems.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/groupmod.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/groups.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/grpck.Po@am__quote@

View File

@@ -29,7 +29,7 @@
#include <config.h>
#ident "$Id: chage.c,v 1.72 2006/06/20 20:00:04 kloczek Exp $"
#ident "$Id: chage.c,v 1.73 2006/07/11 13:15:41 kloczek Exp $"
#include <ctype.h>
#include <fcntl.h>
@@ -103,7 +103,7 @@ int isnum (const char *s)
*/
static void usage (void)
{
fprintf (stderr, _("Usage: chage [options] user\n"
fprintf (stderr, _("Usage: chage [options] [LOGIN]\n"
"\n"
"Options:\n"
" -d, --lastday LAST_DAY set last password change to LAST_DAY\n"

View File

@@ -29,9 +29,10 @@
#include <config.h>
#ident "$Id: chsh.c,v 1.40 2006/05/07 17:44:39 kloczek Exp $"
#ident "$Id: chsh.c,v 1.42 2006/07/13 21:26:35 kloczek Exp $"
#include <fcntl.h>
#include <getopt.h>
#include <pwd.h>
#include <signal.h>
#include <stdio.h>
@@ -76,7 +77,12 @@ static int restricted_shell (const char *);
*/
static void usage (void)
{
fprintf (stderr, _("Usage: %s [-s shell] [name]\n"), Prog);
fprintf (stderr, _("Usage: chsh [options] [LOGIN]\n"
"\n"
"Options:\n"
" -h, --help display this help message and exit\n"
" -s, --shell SHELL new login shell for the user account\n"
"\n"));
exit (E_USAGE);
}
@@ -170,7 +176,6 @@ static int check_shell (const char *sh)
int main (int argc, char **argv)
{
char *user; /* User name */
int flag; /* Current command line flag */
int sflg = 0; /* -s - set shell from command line */
const struct passwd *pw; /* Password entry from /etc/passwd */
struct passwd pwent; /* New password entry */
@@ -204,15 +209,29 @@ int main (int argc, char **argv)
* There is only one option, but use getopt() anyway to
* keep things consistent.
*/
{
int option_index = 0;
int c;
static struct option long_options[] = {
{"help", no_argument, NULL, 'h'},
{"shell", required_argument, NULL, 's'},
{NULL, 0, NULL, '\0'}
};
while ((flag = getopt (argc, argv, "s:")) != EOF) {
switch (flag) {
case 's':
sflg++;
STRFCPY (loginsh, optarg);
break;
default:
usage ();
while ((c =
getopt_long (argc, argv, "hs:", long_options,
&option_index)) != -1) {
switch (c) {
case 'h':
usage ();
break;
case 's':
sflg++;
STRFCPY (loginsh, optarg);
break;
default:
usage ();
}
}
}

View File

@@ -29,7 +29,7 @@
#include <config.h>
#ident "$Id: groupadd.c,v 1.53 2006/06/24 05:52:00 kloczek Exp $"
#ident "$Id: groupadd.c,v 1.55 2006/07/28 17:38:52 kloczek Exp $"
#include <ctype.h>
#include <fcntl.h>
@@ -88,13 +88,14 @@ static void check_new_name (void);
static void close_files (void);
static void open_files (void);
static void fail_exit (int);
static gid_t get_gid (const char *gidstr);
/*
* usage - display usage message and exit
*/
static void usage (void)
{
fprintf (stderr, _("Usage: groupadd [options] group\n"
fprintf (stderr, _("Usage: groupadd [options] GROUP\n"
"\n"
"Options:\n"
" -f, --force force exit with success status if the specified\n"
@@ -369,6 +370,23 @@ static void fail_exit (int code)
exit (code);
}
/*
* get_id - validate and get group ID
*/
static gid_t get_gid (const char *gidstr)
{
long val;
char *errptr;
val = strtol (gidstr, &errptr, 10);
if (*errptr || errno == ERANGE || val < 0) {
fprintf (stderr, _("%s: invalid numeric argument '%s'\n"), Prog,
gidstr);
exit (E_BAD_ARG);
}
return val;
}
/*
* main - groupadd command
*/
@@ -427,16 +445,7 @@ int main (int argc, char **argv)
break;
case 'g':
gflg++;
if (!isdigit (optarg[0]))
usage ();
group_id = strtoul (optarg, &cp, 10);
if (*cp != '\0') {
fprintf (stderr,
_("%s: invalid group %s\n"),
Prog, optarg);
fail_exit (E_BAD_ARG);
}
group_id = get_gid (optarg);
break;
case 'h':
usage ();

309
src/groupmems.c Normal file
View File

@@ -0,0 +1,309 @@
/*
* Copyright 2000, International Business Machines
* George Kraft IV, gk4@us.ibm.com, 03/23/2000
* 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
* 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)
* 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 <fcntl.h>
#include <getopt.h>
#include <grp.h>
#include <stdio.h>
#include <sys/types.h>
#ifdef USE_PAM
#include "pam_defs.h"
#include <pwd.h>
#endif /* USE_PAM */
#include "defines.h"
#include "groupio.h"
/* Exit Status Values */
#define EXIT_SUCCESS 0 /* success */
#define EXIT_USAGE 1 /* invalid command syntax */
#define EXIT_GROUP_FILE 2 /* group file access problems */
#define EXIT_NOT_ROOT 3 /* not super user */
#define EXIT_NOT_EROOT 4 /* not effective super user */
#define EXIT_NOT_PRIMARY 5 /* not primary owner of group */
#define EXIT_NOT_MEMBER 6 /* member of group does not exist */
#define EXIT_MEMBER_EXISTS 7 /* member of group already exists */
#define TRUE 1
#define FALSE 0
/*
* Global variables
*/
extern int optind;
extern char *optarg;
static char *adduser = NULL;
static char *deluser = NULL;
static char *thisgroup = NULL;
static int purge = FALSE;
static int list = FALSE;
static int exclusive = 0;
static int isroot (void)
{
return getuid ()? FALSE : TRUE;
}
static int isgroup (void)
{
gid_t g = getgid ();
struct group *grp = getgrgid (g);
return TRUE;
}
static char *whoami (void)
{
struct group *grp = getgrgid (getgid ());
struct passwd *usr = getpwuid (getuid ());
if (0 == strcmp (usr->pw_name, grp->gr_name)) {
return (char *) strdup (usr->pw_name);
} else {
return NULL;
}
}
static void addtogroup (char *user, char **members)
{
int i;
for (i = 0; NULL != members[i]; i++) {
if (0 == strcmp (user, members[i])) {
fprintf (stderr, _("Member already exists\n"));
exit (EXIT_MEMBER_EXISTS);
}
}
members = (char **) realloc (members, sizeof (char *) * i);
members[i] = user;
members[i + 1] = NULL;
}
static void rmfromgroup (char *user, char **members)
{
int i;
int found = FALSE;
i = 0;
while (!found && NULL != members[i]) {
if (0 == strcmp (user, members[i])) {
found = TRUE;
} else {
i++;
}
}
while (found && NULL != members[i]) {
members[i] = members[++i];
}
if (!found) {
fprintf (stderr, _("Member to remove could not be found\n"));
exit (EXIT_NOT_MEMBER);
}
}
static void nomembers (char **members)
{
int i;
for (i = 0; NULL != members[i]; i++) {
members[i] = NULL;
}
}
static void members (char **members)
{
int i;
for (i = 0; NULL != members[i]; i++) {
printf ("%s ", members[i]);
if (NULL == members[i + 1]) {
printf ("\n");
} else {
printf (" ");
}
}
}
static void usage (void)
{
fprintf (stderr,
_
("Usage: groupmems -a username | -d username | -D | -l [-g groupname]\n"));
exit (EXIT_USAGE);
}
int main (int argc, char **argv)
{
int arg;
char *name;
struct group *grp;
#ifdef USE_PAM
pam_handle_t *pamh = NULL;
struct passwd *pampw;
int retval;
#endif
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
int option_index = 0;
static struct option long_options[] = {
{"add", required_argument, NULL, 'a'},
{"delete", required_argument, NULL, 'd'},
{"group", required_argument, NULL, 'g'},
{"list", no_argument, NULL, 'l'},
{"purge", no_argument, NULL, 'p'},
{NULL, 0, NULL, '\0'}
};
while ((arg =
getopt_long (argc, argv, "a:d:g:lp", long_options,
&option_index)) != EOF) {
switch (arg) {
case 'a':
adduser = strdup (optarg);
++exclusive;
break;
case 'd':
deluser = strdup (optarg);
++exclusive;
break;
case 'p':
purge = TRUE;
++exclusive;
break;
case 'g':
thisgroup = strdup (optarg);
break;
case 'l':
list = TRUE;
++exclusive;
break;
default:
usage ();
}
}
if (exclusive > 1 || optind < argc) {
usage ();
}
if (!isroot () && NULL != thisgroup) {
fprintf (stderr,
_("Only root can add members to different groups\n"));
exit (EXIT_NOT_ROOT);
} else if (isroot () && NULL != thisgroup) {
name = thisgroup;
} else if (!isgroup ()) {
fprintf (stderr, _("Group access is required\n"));
exit (EXIT_NOT_EROOT);
} else if (NULL == (name = whoami ())) {
fprintf (stderr, _("Not primary owner of current group\n"));
exit (EXIT_NOT_PRIMARY);
}
#ifdef USE_PAM
retval = PAM_SUCCESS;
pampw = getpwuid (getuid ());
if (pampw == NULL) {
retval = PAM_USER_UNKNOWN;
}
if (retval == PAM_SUCCESS) {
retval = pam_start ("groupmod", pampw->pw_name, &conv, &pamh);
}
if (retval == PAM_SUCCESS) {
retval = pam_authenticate (pamh, 0);
if (retval != PAM_SUCCESS) {
pam_end (pamh, retval);
}
}
if (retval == PAM_SUCCESS) {
retval = pam_acct_mgmt (pamh, 0);
if (retval != PAM_SUCCESS) {
pam_end (pamh, retval);
}
}
if (retval != PAM_SUCCESS) {
fprintf (stderr, _("PAM authentication failed for\n"));
exit (1);
}
#endif
if (!gr_lock ()) {
fprintf (stderr, _("Unable to lock group file\n"));
exit (EXIT_GROUP_FILE);
}
if (!gr_open (O_RDWR)) {
fprintf (stderr, _("Unable to open group file\n"));
exit (EXIT_GROUP_FILE);
}
grp = (struct group *) gr_locate (name);
if (NULL != adduser) {
addtogroup (adduser, grp->gr_mem);
gr_update (grp);
} else if (NULL != deluser) {
rmfromgroup (deluser, grp->gr_mem);
gr_update (grp);
} else if (purge) {
nomembers (grp->gr_mem);
gr_update (grp);
} else if (list) {
members (grp->gr_mem);
}
if (!gr_close ()) {
fprintf (stderr, _("Cannot close group file\n"));
exit (EXIT_GROUP_FILE);
}
gr_unlock ();
#ifdef USE_PAM
if (retval == PAM_SUCCESS) {
pam_end (pamh, PAM_SUCCESS);
}
#endif /* USE_PAM */
exit (EXIT_SUCCESS);
}

View File

@@ -29,10 +29,11 @@
#include <config.h>
#ident "$Id: groupmod.c,v 1.37 2005/10/19 15:21:07 kloczek Exp $"
#ident "$Id: groupmod.c,v 1.41 2006/07/28 17:38:52 kloczek Exp $"
#include <ctype.h>
#include <fcntl.h>
#include <getopt.h>
#include <grp.h>
#include <stdio.h>
#include <sys/types.h>
@@ -89,6 +90,7 @@ static void check_new_name (void);
static void process_flags (int, char **);
static void close_files (void);
static void open_files (void);
static gid_t get_gid (const char *gidstr);
/*
* usage - display usage message and exit
@@ -96,7 +98,14 @@ static void open_files (void);
static void usage (void)
{
fprintf (stderr, _("Usage: groupmod [-g gid [-o]] [-n name] group\n"));
fprintf (stderr, _("Usage: groupmod [options] GROUP\n"
"\n"
"Options:\n"
" -g, --gid GID force use new GID by GROUP\n"
" -h, --help display this help message and exit\n"
" -n, --new-name NEW_GROUP force use NEW_GROUP name by GROUP\n"
" -o, --non-unique allow using duplicate (non-unique) GID by GROUP\n"
"\n"));
exit (E_USAGE);
}
@@ -309,6 +318,23 @@ static void check_new_name (void)
exit (E_BAD_ARG);
}
/*
* get_id - validate and get group ID
*/
static gid_t get_gid (const char *gidstr)
{
long val;
char *errptr;
val = strtol (gidstr, &errptr, 10);
if (*errptr || errno == ERANGE || val < 0) {
fprintf (stderr, _("%s: invalid numeric argument '%s'\n"), Prog,
gidstr);
exit (E_BAD_ARG);
}
return val;
}
/*
* process_flags - perform command line argument setting
*
@@ -318,37 +344,43 @@ static void check_new_name (void)
*/
static void process_flags (int argc, char **argv)
{
char *end;
int arg;
while ((arg = getopt (argc, argv, "g:n:o")) != EOF) {
switch (arg) {
case 'g':
gflg++;
group_newid = strtoul (optarg, &end, 10);
if (*end != '\0') {
fprintf (stderr,
_("%s: invalid group %s\n"),
Prog, optarg);
{
int option_index = 0;
int c;
static struct option long_options[] = {
{"gid", required_argument, NULL, 'g'},
{"help", no_argument, NULL, 'h'},
{"new-name", required_argument, NULL, 'n'},
{"non-unique", no_argument, NULL, 'o'},
{NULL, 0, NULL, '\0'}
};
while ((c =
getopt_long (argc, argv, "g:hn:o",
long_options, &option_index)) != -1) {
switch (c) {
case 'g':
gflg++;
group_newid = get_gid (optarg);
#ifdef WITH_AUDIT
audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
"modifying group", NULL,
group_newid, 0);
audit_logger (AUDIT_USER_CHAUTHTOK,
Prog, "modifying group",
NULL, group_newid, 0);
#endif
exit (E_BAD_ARG);
break;
case 'n':
nflg++;
group_newname = optarg;
break;
case 'o':
oflg++;
break;
default:
usage ();
}
break;
case 'n':
nflg++;
group_newname = optarg;
break;
case 'o':
oflg++;
break;
default:
usage ();
}
}
if (oflg && !gflg)
usage ();

View File

@@ -29,7 +29,7 @@
#include <config.h>
#ident "$Id: passwd.c,v 1.59 2006/06/20 20:00:04 kloczek Exp $"
#ident "$Id: passwd.c,v 1.61 2006/07/28 17:40:15 kloczek Exp $"
#include <errno.h>
#include <fcntl.h>
@@ -130,7 +130,7 @@ static long getnumber (const char *);
*/
static void usage (int status)
{
fprintf (stderr, _("Usage: passwd [options] [login]\n"
fprintf (stderr, _("Usage: passwd [options] [LOGIN]\n"
"\n"
"Options:\n"
" -a, --all report password status on all accounts\n"
@@ -553,14 +553,17 @@ static void update_shadow (void)
spw_unlock ();
}
static long getnumber (const char *str)
static long getnumber (const char *numstr)
{
long val;
char *cp;
char *errptr;
val = strtol (str, &cp, 10);
if (*cp)
usage (E_BAD_ARG);
val = strtol (numstr, &errptr, 10);
if (*errptr || errno == ERANGE) {
fprintf (stderr, _("%s: invalid numeric argument '%s'\n"), Prog,
numstr);
exit (E_BAD_ARG);
}
return val;
}

View File

@@ -29,7 +29,7 @@
#include <config.h>
#ident "$Id: su.c,v 1.71 2006/06/20 20:00:04 kloczek Exp $"
#ident "$Id: su.c,v 1.74 2006/08/01 10:30:02 kloczek Exp $"
#include <getopt.h>
#include <grp.h>
@@ -252,7 +252,7 @@ static void run_shell (const char *shellstr, char *args[], int doshell,
*/
static void usage (void)
{
fprintf (stderr, _("Usage: su [options] [login]\n"
fprintf (stderr, _("Usage: su [options] [LOGIN]\n"
"\n"
"Options:\n"
" -c, --command COMMAND pass COMMAND to the invoked shell\n"
@@ -279,7 +279,6 @@ static void usage (void)
int main (int argc, char **argv)
{
char *cp;
char **envcp;
const char *tty = 0; /* Name of tty SU is run from */
int doshell = 0;
int fakelogin = 0;
@@ -290,6 +289,7 @@ int main (int argc, char **argv)
char *shellstr = 0, *command = 0;
#ifdef USE_PAM
char **envcp;
int ret;
#else /* !USE_PAM */
int err = 0;
@@ -710,11 +710,6 @@ int main (int argc, char **argv)
addenv ("PATH", cp);
}
#ifndef USE_PAM
/* setup the environment for PAM later on, else we run into auth problems */
environ = newenvp; /* make new environment active */
#endif
if (getenv ("IFS")) /* don't export user IFS ... */
addenv ("IFS= \t\n", NULL); /* ... instead, set a safe IFS */
@@ -794,6 +789,8 @@ int main (int argc, char **argv)
exit (1);
}
#else /* !USE_PAM */
environ = newenvp; /* make new environment active */
if (!amroot) /* no limits if su from root */
setup_limits (&pwent);

View File

@@ -29,7 +29,7 @@
#include <config.h>
#ident "$Id: useradd.c,v 1.99 2006/06/22 11:30:32 kloczek Exp $"
#ident "$Id: useradd.c,v 1.100 2006/07/28 17:42:48 kloczek Exp $"
#include <ctype.h>
#include <errno.h>
@@ -198,42 +198,47 @@ static void fail_exit (int code)
exit (code);
}
static struct group *getgr_nam_gid (const char *name)
static struct group *getgr_nam_gid (const char *grname)
{
gid_t gid;
char *ep;
long gid;
char *errptr;
gid = strtoul (name, &ep, 10);
if (*name != '\0' && *ep == '\0') /* valid numeric GID */
return getgrgid (gid);
return getgrnam (name);
gid = strtol (grname, &errptr, 10);
if (*errptr || errno == ERANGE || gid < 0) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"), Prog, grname);
exit (E_BAD_ARG);
}
return getgrnam (grname);
}
static long get_number (const char *cp)
static long get_number (const char *numstr)
{
long val;
char *ep;
char *errptr;
val = strtol (cp, &ep, 10);
if (*cp != '\0' && *ep == '\0') /* valid number */
return val;
fprintf (stderr, _("%s: invalid numeric argument '%s'\n"), Prog, cp);
exit (E_BAD_ARG);
val = strtol (numstr, &errptr, 10);
if (*errptr || errno == ERANGE) {
fprintf (stderr, _("%s: invalid numeric argument '%s'\n"), Prog,
numstr);
exit (E_BAD_ARG);
}
return val;
}
static uid_t get_uid (const char *cp)
static uid_t get_uid (const char *uidstr)
{
uid_t val;
char *ep;
long val;
char *errptr;
val = strtoul (cp, &ep, 10);
if (*cp != '\0' && *ep == '\0') /* valid number */
return val;
fprintf (stderr, _("%s: invalid numeric argument '%s'\n"), Prog, cp);
exit (E_BAD_ARG);
val = strtol (uidstr, &errptr, 10);
if (*errptr || errno == ERANGE || val < 0) {
fprintf (stderr,
_("%s: invalid numeric argument '%s'\n"), Prog,
uidstr);
exit (E_BAD_ARG);
}
return val;
}
#define MATCH(x,y) (strncmp((x),(y),strlen(y)) == 0)
@@ -316,7 +321,7 @@ static void get_defaults (void)
else if (MATCH (buf, INACT)) {
long val = strtol (cp, &ep, 10);
if (*cp != '\0' && *ep == '\0') /* valid number */
if (*cp || errno == ERANGE)
def_inactive = val;
else
def_inactive = -1;

View File

@@ -29,7 +29,7 @@
#include <config.h>
#ident "$Id: usermod.c,v 1.69 2006/06/25 13:10:29 kloczek Exp $"
#ident "$Id: usermod.c,v 1.71 2006/07/28 17:42:48 kloczek Exp $"
#include <ctype.h>
#include <errno.h>
@@ -68,12 +68,12 @@
#define E_USAGE 2 /* invalid command syntax */
#define E_BAD_ARG 3 /* invalid argument to option */
#define E_UID_IN_USE 4 /* UID already in use (and no -o) */
/* #define E_BAD_PWFILE 5 *//* passwd file contains errors */
/* #define E_BAD_PWFILE 5 passwd file contains errors */
#define E_NOTFOUND 6 /* specified user/group doesn't exist */
#define E_USER_BUSY 8 /* user to modify is logged in */
#define E_NAME_IN_USE 9 /* username already in use */
#define E_GRP_UPDATE 10 /* can't update group file */
/* #define E_NOSPACE 11 *//* insufficient space to move home dir */
/* #define E_NOSPACE 11 insufficient space to move home dir */
#define E_HOMEDIR 12 /* unable to complete home dir move */
#define VALID(s) (strcspn (s, ":\n") == strlen (s))
/*
@@ -160,16 +160,18 @@ static void move_mailbox (void);
* "56k-family"... ergh.
* --Pac.
*/
static struct group *getgr_nam_gid (const char *name)
static struct group *getgr_nam_gid (const char *grname)
{
gid_t gid;
char *ep;
long val;
char *errptr;
gid = strtoul (name, &ep, 10);
if (*name != '\0' && *ep == '\0') /* valid numeric GID */
return getgrgid (gid);
return getgrnam (name);
val = strtol (grname, &errptr, 10);
if (*errptr || errno == ERANGE || val < 0) {
fprintf (stderr, _("%s: invalid numeric argument '%s'\n"), Prog,
grname);
exit (E_BAD_ARG);
}
return getgrnam (grname);
}
/*
@@ -276,7 +278,8 @@ static void usage (void)
fprintf (stderr, _("Usage: usermod [options] LOGIN\n"
"\n"
"Options:\n"
" -a, --append GROUP append the user to the supplemental GROUP\n"
" -a, --append append the user to the supplemental GROUPS\n"
" (use only with -G)\n"
" -c, --comment COMMENT new value of the GECOS field\n"
" -d, --home HOME_DIR new home directory for the user account\n"
" -e, --expiredate EXPIRE_DATE set account expiration date to EXPIRE_DATE\n"
@@ -803,30 +806,32 @@ static int grp_update (void)
return ret;
}
static long get_number (const char *cp)
static long get_number (const char *numstr)
{
long val;
char *ep;
char *errptr;
val = strtol (cp, &ep, 10);
if (*cp != '\0' && *ep == '\0') /* valid number */
return val;
fprintf (stderr, _("%s: invalid numeric argument '%s'\n"), Prog, cp);
exit (E_BAD_ARG);
val = strtol (numstr, &errptr, 10);
if (*errptr || errno == ERANGE) {
fprintf (stderr, _("%s: invalid numeric argument '%s'\n"), Prog,
numstr);
exit (E_BAD_ARG);
}
return val;
}
static uid_t get_id (const char *cp)
static uid_t get_id (const char *uidstr)
{
uid_t val;
char *ep;
long val;
char *errptr;
val = strtoul (cp, &ep, 10);
if (*cp != '\0' && *ep == '\0') /* valid number */
return val;
fprintf (stderr, _("%s: invalid numeric argument '%s'\n"), Prog, cp);
exit (E_BAD_ARG);
val = strtol (uidstr, &errptr, 10);
if (*errptr || errno == ERANGE || val < 0) {
fprintf (stderr, _("%s: invalid numeric argument '%s'\n"), Prog,
uidstr);
exit (E_BAD_ARG);
}
return val;
}
/*
@@ -922,7 +927,7 @@ static void process_flags (int argc, char **argv)
{NULL, 0, NULL, '\0'}
};
while ((c =
getopt_long (argc, argv, "a:c:d:e:f:g:G:hl:Lmop:s:u:U",
getopt_long (argc, argv, "ac:d:e:f:g:G:hl:Lmop:s:u:U",
long_options, NULL)) != -1) {
switch (c) {
case 'a':