[svn-upgrade] Integrating new upstream version, shadow (4.0.10)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
|
||||
EXTRA_DIST = .indent.pro
|
||||
EXTRA_DIST = \
|
||||
.indent.pro
|
||||
|
||||
ubindir = ${prefix}/bin
|
||||
usbindir = ${prefix}/sbin
|
||||
@@ -30,7 +31,6 @@ usbin_PROGRAMS = \
|
||||
grpconv \
|
||||
grpunconv \
|
||||
logoutd \
|
||||
mkpasswd \
|
||||
newusers \
|
||||
pwck \
|
||||
pwconv \
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
@SET_MAKE@
|
||||
|
||||
SOURCES = chage.c chfn.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 mkpasswd.c newgrp.c newusers.c passwd.c pwck.c pwconv.c pwunconv.c $(su_SOURCES) sulogin.c useradd.c userdel.c usermod.c vipw.c
|
||||
SOURCES = chage.c chfn.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 passwd.c pwck.c pwconv.c pwunconv.c $(su_SOURCES) sulogin.c useradd.c userdel.c usermod.c vipw.c
|
||||
|
||||
srcdir = @srcdir@
|
||||
top_srcdir = @top_srcdir@
|
||||
@@ -44,19 +44,15 @@ ubin_PROGRAMS = faillog$(EXEEXT) lastlog$(EXEEXT) chage$(EXEEXT) \
|
||||
newgrp$(EXEEXT) passwd$(EXEEXT)
|
||||
usbin_PROGRAMS = chpasswd$(EXEEXT) groupadd$(EXEEXT) groupdel$(EXEEXT) \
|
||||
groupmod$(EXEEXT) grpck$(EXEEXT) grpconv$(EXEEXT) \
|
||||
grpunconv$(EXEEXT) logoutd$(EXEEXT) mkpasswd$(EXEEXT) \
|
||||
newusers$(EXEEXT) pwck$(EXEEXT) pwconv$(EXEEXT) \
|
||||
pwunconv$(EXEEXT) useradd$(EXEEXT) userdel$(EXEEXT) \
|
||||
usermod$(EXEEXT) vipw$(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
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
am__aclocal_m4_deps = $(top_srcdir)/m4/gettext.m4 \
|
||||
$(top_srcdir)/m4/iconv.m4 $(top_srcdir)/m4/lib-ld.m4 \
|
||||
$(top_srcdir)/m4/lib-link.m4 $(top_srcdir)/m4/lib-prefix.m4 \
|
||||
$(top_srcdir)/m4/nls.m4 $(top_srcdir)/m4/po.m4 \
|
||||
$(top_srcdir)/m4/progtest.m4 $(top_srcdir)/configure.in
|
||||
am__aclocal_m4_deps = $(top_srcdir)/configure.in
|
||||
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
|
||||
$(ACLOCAL_M4)
|
||||
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
|
||||
@@ -146,11 +142,6 @@ logoutd_OBJECTS = logoutd.$(OBJEXT)
|
||||
logoutd_LDADD = $(LDADD)
|
||||
logoutd_DEPENDENCIES = $(top_builddir)/libmisc/libmisc.a \
|
||||
$(top_builddir)/lib/libshadow.la
|
||||
mkpasswd_SOURCES = mkpasswd.c
|
||||
mkpasswd_OBJECTS = mkpasswd.$(OBJEXT)
|
||||
mkpasswd_LDADD = $(LDADD)
|
||||
mkpasswd_DEPENDENCIES = $(top_builddir)/libmisc/libmisc.a \
|
||||
$(top_builddir)/lib/libshadow.la
|
||||
newgrp_SOURCES = newgrp.c
|
||||
newgrp_OBJECTS = newgrp.$(OBJEXT)
|
||||
newgrp_LDADD = $(LDADD)
|
||||
@@ -214,15 +205,15 @@ LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
|
||||
SOURCES = chage.c chfn.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 mkpasswd.c newgrp.c newusers.c passwd.c pwck.c \
|
||||
pwconv.c pwunconv.c $(su_SOURCES) sulogin.c useradd.c \
|
||||
userdel.c usermod.c vipw.c
|
||||
logoutd.c newgrp.c newusers.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 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 mkpasswd.c newgrp.c newusers.c passwd.c pwck.c \
|
||||
pwconv.c pwunconv.c $(su_SOURCES) sulogin.c useradd.c \
|
||||
userdel.c usermod.c vipw.c
|
||||
logoutd.c newgrp.c newusers.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)
|
||||
@@ -344,7 +335,9 @@ sbindir = @sbindir@
|
||||
sharedstatedir = @sharedstatedir@
|
||||
sysconfdir = @sysconfdir@
|
||||
target_alias = @target_alias@
|
||||
EXTRA_DIST = .indent.pro
|
||||
EXTRA_DIST = \
|
||||
.indent.pro
|
||||
|
||||
ubindir = ${prefix}/bin
|
||||
usbindir = ${prefix}/sbin
|
||||
INCLUDES = \
|
||||
@@ -391,9 +384,9 @@ $(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__confi
|
||||
exit 1;; \
|
||||
esac; \
|
||||
done; \
|
||||
echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/Makefile'; \
|
||||
echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/Makefile'; \
|
||||
cd $(top_srcdir) && \
|
||||
$(AUTOMAKE) --foreign src/Makefile
|
||||
$(AUTOMAKE) --gnu src/Makefile
|
||||
.PRECIOUS: Makefile
|
||||
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
|
||||
@case '$?' in \
|
||||
@@ -556,9 +549,6 @@ login$(EXEEXT): $(login_OBJECTS) $(login_DEPENDENCIES)
|
||||
logoutd$(EXEEXT): $(logoutd_OBJECTS) $(logoutd_DEPENDENCIES)
|
||||
@rm -f logoutd$(EXEEXT)
|
||||
$(LINK) $(logoutd_LDFLAGS) $(logoutd_OBJECTS) $(logoutd_LDADD) $(LIBS)
|
||||
mkpasswd$(EXEEXT): $(mkpasswd_OBJECTS) $(mkpasswd_DEPENDENCIES)
|
||||
@rm -f mkpasswd$(EXEEXT)
|
||||
$(LINK) $(mkpasswd_LDFLAGS) $(mkpasswd_OBJECTS) $(mkpasswd_LDADD) $(LIBS)
|
||||
newgrp$(EXEEXT): $(newgrp_OBJECTS) $(newgrp_DEPENDENCIES)
|
||||
@rm -f newgrp$(EXEEXT)
|
||||
$(LINK) $(newgrp_LDFLAGS) $(newgrp_OBJECTS) $(newgrp_LDADD) $(LIBS)
|
||||
@@ -621,7 +611,6 @@ distclean-compile:
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/login.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/login_nopam.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/logoutd.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mkpasswd.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/newgrp.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/newusers.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/passwd.Po@am__quote@
|
||||
|
||||
148
src/chage.c
148
src/chage.c
@@ -30,15 +30,15 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID (PKG_VER "$Id: chage.c,v 1.43 2005/04/17 00:07:00 kloczek Exp $")
|
||||
#include <sys/types.h>
|
||||
RCSID (PKG_VER "$Id: chage.c,v 1.47 2005/06/20 15:43:09 kloczek Exp $")
|
||||
#include <ctype.h>
|
||||
#include <fcntl.h>
|
||||
#include <getopt.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
#ifdef SHADOWPWD
|
||||
#ifdef USE_PAM
|
||||
#include <security/pam_appl.h>
|
||||
#include <security/pam_misc.h>
|
||||
@@ -107,10 +107,20 @@ int isnum (const char *s)
|
||||
|
||||
static void usage (void)
|
||||
{
|
||||
fprintf (stderr,
|
||||
_
|
||||
("Usage: chage [-l] [-m min_days] [-M max_days] [-W warn]\n"
|
||||
" [-I inactive] [-E expire] [-d last_day] user\n"));
|
||||
fprintf (stderr, _("Usage: chage [options] user\n"
|
||||
"\n"
|
||||
"Options:\n"
|
||||
" -d, --lastday LAST_DAY set last password change to LAST_DAY\n"
|
||||
" -E, --expiredate EXPIRE_DATE set account expiration date to EXPIRE_DATE\n"
|
||||
" -h, --help display this help message and exit\n"
|
||||
" -I, --inactive INACTIVE set password inactive after expiration\n"
|
||||
" to INACTIVE\n"
|
||||
" -l, --list show account aging information\n"
|
||||
" -m, --mindays MIN_DAYS set minimum number of days before password\n"
|
||||
" change to MIN_DAYS\n"
|
||||
" -M, --maxdays MAX_DAYS set maximim number of days before password\n"
|
||||
" change to MAX_DAYS\n"
|
||||
" -W, --warndays WARN_DAYS set expiration warning days to WARN_DAYS\n"));
|
||||
exit (1);
|
||||
}
|
||||
|
||||
@@ -327,13 +337,13 @@ static void cleanup (int state)
|
||||
*
|
||||
* The valid options are
|
||||
*
|
||||
* -m set minimum number of days before password change (*)
|
||||
* -M set maximim number of days before password change (*)
|
||||
* -d set last password change date (*)
|
||||
* -l show account aging information
|
||||
* -W set expiration warning days (*)
|
||||
* -I set password inactive after expiration (*)
|
||||
* -E set account expiration date (*)
|
||||
* -I set password inactive after expiration (*)
|
||||
* -l show account aging information
|
||||
* -M set maximim number of days before password change (*)
|
||||
* -m set minimum number of days before password change (*)
|
||||
* -W set expiration warning days (*)
|
||||
*
|
||||
* (*) requires root permission to execute.
|
||||
*
|
||||
@@ -375,46 +385,67 @@ int main (int argc, char **argv)
|
||||
*/
|
||||
Prog = Basename (argv[0]);
|
||||
|
||||
/*
|
||||
* Parse the command line options.
|
||||
*/
|
||||
while ((flag = getopt (argc, argv, "lm:M:W:I:E:d:")) != EOF) {
|
||||
switch (flag) {
|
||||
case 'l':
|
||||
lflg++;
|
||||
break;
|
||||
case 'm':
|
||||
mflg++;
|
||||
mindays = strtol (optarg, 0, 10);
|
||||
break;
|
||||
case 'M':
|
||||
Mflg++;
|
||||
maxdays = strtol (optarg, 0, 10);
|
||||
break;
|
||||
case 'd':
|
||||
dflg++;
|
||||
if (!isnum (optarg))
|
||||
lastday = strtoday (optarg);
|
||||
else
|
||||
lastday = strtol (optarg, 0, 10);
|
||||
break;
|
||||
case 'W':
|
||||
Wflg++;
|
||||
warndays = strtol (optarg, 0, 10);
|
||||
break;
|
||||
case 'I':
|
||||
Iflg++;
|
||||
inactdays = strtol (optarg, 0, 10);
|
||||
break;
|
||||
case 'E':
|
||||
Eflg++;
|
||||
if (!isnum (optarg))
|
||||
expdays = strtoday (optarg);
|
||||
else
|
||||
expdays = strtol (optarg, 0, 10);
|
||||
break;
|
||||
default:
|
||||
usage ();
|
||||
{
|
||||
/*
|
||||
* Parse the command line options.
|
||||
*/
|
||||
int option_index = 0;
|
||||
int c;
|
||||
static struct option long_options[] = {
|
||||
{"lastday", required_argument, NULL, 'd'},
|
||||
{"expiredate", required_argument, NULL, 'E'},
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{"inactive", required_argument, NULL, 'I'},
|
||||
{"list", no_argument, NULL, 'l'},
|
||||
{"mindays", required_argument, NULL, 'm'},
|
||||
{"maxdays", required_argument, NULL, 'M'},
|
||||
{"warndays", required_argument, NULL, 'W'},
|
||||
{NULL, 0, NULL, '\0'}
|
||||
};
|
||||
|
||||
while ((c =
|
||||
getopt_long (argc, argv, "d:E:hI:lm:M:W:", long_options,
|
||||
&option_index)) != -1) {
|
||||
switch (c) {
|
||||
case 'd':
|
||||
dflg++;
|
||||
if (!isnum (optarg))
|
||||
lastday = strtoday (optarg);
|
||||
else
|
||||
lastday = strtol (optarg, 0, 10);
|
||||
break;
|
||||
case 'E':
|
||||
Eflg++;
|
||||
if (!isnum (optarg))
|
||||
expdays = strtoday (optarg);
|
||||
else
|
||||
expdays = strtol (optarg, 0, 10);
|
||||
break;
|
||||
case 'h':
|
||||
usage ();
|
||||
break;
|
||||
case 'I':
|
||||
Iflg++;
|
||||
inactdays = strtol (optarg, 0, 10);
|
||||
break;
|
||||
case 'l':
|
||||
lflg++;
|
||||
break;
|
||||
case 'm':
|
||||
mflg++;
|
||||
mindays = strtol (optarg, 0, 10);
|
||||
break;
|
||||
case 'M':
|
||||
Mflg++;
|
||||
maxdays = strtol (optarg, 0, 10);
|
||||
break;
|
||||
case 'W':
|
||||
Wflg++;
|
||||
warndays = strtol (optarg, 0, 10);
|
||||
break;
|
||||
default:
|
||||
usage ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -440,7 +471,7 @@ int main (int argc, char **argv)
|
||||
*/
|
||||
|
||||
if (!amroot && !lflg) {
|
||||
fprintf (stderr, _("%s: permission denied.\n"), Prog);
|
||||
fprintf (stderr, _("%s: Permission denied.\n"), Prog);
|
||||
exit (E_NOPERM);
|
||||
}
|
||||
|
||||
@@ -568,7 +599,7 @@ int main (int argc, char **argv)
|
||||
|
||||
if (lflg) {
|
||||
if (!amroot && (ruid != pwent.pw_uid)) {
|
||||
fprintf (stderr, _("%s: permission denied.\n"), Prog);
|
||||
fprintf (stderr, _("%s: Permission denied.\n"), Prog);
|
||||
closelog ();
|
||||
exit (E_NOPERM);
|
||||
}
|
||||
@@ -723,12 +754,3 @@ int main (int argc, char **argv)
|
||||
exit (E_SUCCESS);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
#else /* !SHADOWPWD */
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
fprintf (stderr,
|
||||
"%s: not configured for shadow password support.\n", argv[0]);
|
||||
exit (E_NOPERM);
|
||||
}
|
||||
#endif /* !SHADOWPWD */
|
||||
|
||||
14
src/chfn.c
14
src/chfn.c
@@ -30,7 +30,7 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID (PKG_VER "$Id: chfn.c,v 1.27 2005/04/06 04:26:06 kloczek Exp $")
|
||||
RCSID (PKG_VER "$Id: chfn.c,v 1.28 2005/06/20 09:36:26 kloczek Exp $")
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
@@ -265,7 +265,7 @@ int main (int argc, char **argv)
|
||||
case 'f':
|
||||
if (!may_change_field ('f')) {
|
||||
fprintf (stderr,
|
||||
_("%s: permission denied.\n"), Prog);
|
||||
_("%s: Permission denied.\n"), Prog);
|
||||
exit (1);
|
||||
}
|
||||
fflg++;
|
||||
@@ -274,7 +274,7 @@ int main (int argc, char **argv)
|
||||
case 'r':
|
||||
if (!may_change_field ('r')) {
|
||||
fprintf (stderr,
|
||||
_("%s: permission denied.\n"), Prog);
|
||||
_("%s: Permission denied.\n"), Prog);
|
||||
exit (1);
|
||||
}
|
||||
rflg++;
|
||||
@@ -283,7 +283,7 @@ int main (int argc, char **argv)
|
||||
case 'w':
|
||||
if (!may_change_field ('w')) {
|
||||
fprintf (stderr,
|
||||
_("%s: permission denied.\n"), Prog);
|
||||
_("%s: Permission denied.\n"), Prog);
|
||||
exit (1);
|
||||
}
|
||||
wflg++;
|
||||
@@ -292,7 +292,7 @@ int main (int argc, char **argv)
|
||||
case 'h':
|
||||
if (!may_change_field ('h')) {
|
||||
fprintf (stderr,
|
||||
_("%s: permission denied.\n"), Prog);
|
||||
_("%s: Permission denied.\n"), Prog);
|
||||
exit (1);
|
||||
}
|
||||
hflg++;
|
||||
@@ -301,7 +301,7 @@ int main (int argc, char **argv)
|
||||
case 'o':
|
||||
if (!amroot) {
|
||||
fprintf (stderr,
|
||||
_("%s: permission denied.\n"), Prog);
|
||||
_("%s: Permission denied.\n"), Prog);
|
||||
exit (1);
|
||||
}
|
||||
oflg++;
|
||||
@@ -367,7 +367,7 @@ int main (int argc, char **argv)
|
||||
*/
|
||||
|
||||
if (!amroot && pw->pw_uid != getuid ()) {
|
||||
fprintf (stderr, _("%s: permission denied.\n"), Prog);
|
||||
fprintf (stderr, _("%s: Permission denied.\n"), Prog);
|
||||
closelog ();
|
||||
exit (1);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID (PKG_VER "$Id: chpasswd.c,v 1.24 2005/04/06 00:13:45 kloczek Exp $")
|
||||
RCSID (PKG_VER "$Id: chpasswd.c,v 1.26 2005/05/25 19:31:51 kloczek Exp $")
|
||||
#include <fcntl.h>
|
||||
#include <getopt.h>
|
||||
#include <pwd.h>
|
||||
@@ -45,9 +45,7 @@ RCSID (PKG_VER "$Id: chpasswd.c,v 1.24 2005/04/06 00:13:45 kloczek Exp $")
|
||||
#include "defines.h"
|
||||
#include "pwio.h"
|
||||
#include "nscd.h"
|
||||
#ifdef SHADOWPWD
|
||||
#include "shadowio.h"
|
||||
#endif
|
||||
/*
|
||||
* Global variables
|
||||
*/
|
||||
@@ -55,9 +53,7 @@ static char *Prog;
|
||||
static int eflg = 0;
|
||||
static int md5flg = 0;
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
static int is_shadow_pwd;
|
||||
#endif
|
||||
|
||||
/* local function prototypes */
|
||||
static void usage (void);
|
||||
@@ -92,10 +88,9 @@ int main (int argc, char **argv)
|
||||
char *newpwd;
|
||||
char *cp;
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
const struct spwd *sp;
|
||||
struct spwd newsp;
|
||||
#endif
|
||||
|
||||
const struct passwd *pw;
|
||||
struct passwd newpw;
|
||||
int errors = 0;
|
||||
@@ -194,7 +189,7 @@ int main (int argc, char **argv)
|
||||
pw_unlock ();
|
||||
exit (1);
|
||||
}
|
||||
#ifdef SHADOWPWD
|
||||
|
||||
is_shadow_pwd = spw_file_present ();
|
||||
if (is_shadow_pwd) {
|
||||
if (!spw_lock ()) {
|
||||
@@ -211,7 +206,6 @@ int main (int argc, char **argv)
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Read each line, separating the user name from the password. The
|
||||
@@ -276,12 +270,10 @@ int main (int argc, char **argv)
|
||||
errors++;
|
||||
continue;
|
||||
}
|
||||
#ifdef SHADOWPWD
|
||||
if (is_shadow_pwd)
|
||||
sp = spw_locate (name);
|
||||
else
|
||||
sp = NULL;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The freshly encrypted new password is merged into the
|
||||
@@ -289,14 +281,11 @@ int main (int argc, char **argv)
|
||||
* date is set to the current date.
|
||||
*/
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
if (sp) {
|
||||
newsp = *sp;
|
||||
newsp.sp_pwdp = cp;
|
||||
newsp.sp_lstchg = now;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
} else {
|
||||
newpw = *pw;
|
||||
newpw.pw_passwd = cp;
|
||||
}
|
||||
@@ -307,11 +296,9 @@ int main (int argc, char **argv)
|
||||
* other entries have been updated as well.
|
||||
*/
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
if (sp)
|
||||
ok = spw_update (&newsp);
|
||||
else
|
||||
#endif
|
||||
ok = pw_update (&newpw);
|
||||
|
||||
if (!ok) {
|
||||
@@ -335,14 +322,11 @@ int main (int argc, char **argv)
|
||||
if (errors) {
|
||||
fprintf (stderr,
|
||||
_("%s: error detected, changes ignored\n"), Prog);
|
||||
#ifdef SHADOWPWD
|
||||
if (is_shadow_pwd)
|
||||
spw_unlock ();
|
||||
#endif
|
||||
pw_unlock ();
|
||||
exit (1);
|
||||
}
|
||||
#ifdef SHADOWPWD
|
||||
if (is_shadow_pwd) {
|
||||
if (!spw_close ()) {
|
||||
fprintf (stderr,
|
||||
@@ -352,7 +336,6 @@ int main (int argc, char **argv)
|
||||
}
|
||||
spw_unlock ();
|
||||
}
|
||||
#endif
|
||||
if (!pw_close ()) {
|
||||
fprintf (stderr, _("%s: error updating password file\n"), Prog);
|
||||
exit (1);
|
||||
|
||||
18
src/expiry.c
18
src/expiry.c
@@ -30,7 +30,7 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID (PKG_VER "$Id: expiry.c,v 1.13 2005/03/31 05:14:54 kloczek Exp $")
|
||||
RCSID (PKG_VER "$Id: expiry.c,v 1.14 2005/05/25 18:20:25 kloczek Exp $")
|
||||
#include <sys/types.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
@@ -71,9 +71,7 @@ int main (int argc, char **argv)
|
||||
{
|
||||
struct passwd *pwd;
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
struct spwd *spwd;
|
||||
#endif
|
||||
char *Prog = argv[0];
|
||||
|
||||
sanitize_env ();
|
||||
@@ -122,9 +120,7 @@ int main (int argc, char **argv)
|
||||
fprintf (stderr, _("%s: unknown user\n"), Prog);
|
||||
exit (10);
|
||||
}
|
||||
#ifdef SHADOWPWD
|
||||
spwd = getspnam (pwd->pw_name);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* If checking accounts, use agecheck() function.
|
||||
@@ -136,21 +132,13 @@ int main (int argc, char **argv)
|
||||
* Print out number of days until expiration.
|
||||
*/
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
agecheck (pwd, spwd);
|
||||
#else
|
||||
agecheck (pwd);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Exit with status indicating state of account.
|
||||
*/
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
exit (isexpired (pwd, spwd));
|
||||
#else
|
||||
exit (isexpired (pwd));
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -165,11 +153,7 @@ int main (int argc, char **argv)
|
||||
* all unless the account is unexpired.
|
||||
*/
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
expire (pwd, spwd);
|
||||
#else
|
||||
expire (pwd);
|
||||
#endif
|
||||
exit (0);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID (PKG_VER "$Id: faillog.c,v 1.22 2005/04/25 10:25:50 kloczek Exp $")
|
||||
RCSID (PKG_VER "$Id: faillog.c,v 1.23 2005/05/25 19:31:51 kloczek Exp $")
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
@@ -84,7 +84,8 @@ static void print_one (const struct faillog *fl, uid_t uid)
|
||||
#endif
|
||||
|
||||
if (!once) {
|
||||
printf (_("Login Failures Maximum Latest On\n"));
|
||||
printf (_
|
||||
("Login Failures Maximum Latest On\n"));
|
||||
once++;
|
||||
}
|
||||
pwent = getpwuid (uid);
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID (PKG_VER "$Id: gpasswd.c,v 1.24 2005/04/06 04:26:06 kloczek Exp $")
|
||||
RCSID (PKG_VER "$Id: gpasswd.c,v 1.25 2005/06/20 09:36:27 kloczek Exp $")
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <pwd.h>
|
||||
@@ -147,7 +147,7 @@ static int check_list (const char *users)
|
||||
|
||||
static void failure (void)
|
||||
{
|
||||
fprintf (stderr, _("%s: permission denied.\n"), Prog);
|
||||
fprintf (stderr, _("%s: Permission denied.\n"), Prog);
|
||||
exit (1);
|
||||
/*NOTREACHED*/}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID (PKG_VER "$Id: groupadd.c,v 1.31 2005/04/06 04:26:06 kloczek Exp $")
|
||||
RCSID (PKG_VER "$Id: groupadd.c,v 1.33 2005/06/20 09:57:51 kloczek Exp $")
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <grp.h>
|
||||
@@ -161,7 +161,6 @@ static void grp_update (void)
|
||||
fprintf (stderr, _("%s: error adding new group entry\n"), Prog);
|
||||
fail_exit (E_GRP_UPDATE);
|
||||
}
|
||||
|
||||
#ifdef SHADOWGRP
|
||||
/*
|
||||
* Write out the new shadow group entries as well.
|
||||
@@ -171,7 +170,7 @@ static void grp_update (void)
|
||||
fail_exit (E_GRP_UPDATE);
|
||||
}
|
||||
#endif /* SHADOWGRP */
|
||||
SYSLOG ((LOG_INFO, "new group: name=%s, gid=%u",
|
||||
SYSLOG ((LOG_INFO, "new group: name=%s, GID=%u",
|
||||
group_name, (unsigned int) group_id));
|
||||
}
|
||||
|
||||
@@ -231,7 +230,7 @@ static void find_new_gid (void)
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
fprintf (stderr, _("%s: gid %u is not unique\n"),
|
||||
fprintf (stderr, _("%s: GID %u is not unique\n"),
|
||||
Prog, (unsigned int) group_id);
|
||||
fail_exit (E_GID_IN_USE);
|
||||
}
|
||||
@@ -255,7 +254,7 @@ static void find_new_gid (void)
|
||||
#endif
|
||||
}
|
||||
if (group_id == gid_max) {
|
||||
fprintf (stderr, _("%s: can't get unique gid\n"), Prog);
|
||||
fprintf (stderr, _("%s: can't get unique GID\n"), Prog);
|
||||
fail_exit (E_GID_IN_USE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID (PKG_VER "$Id: groupdel.c,v 1.20 2005/04/06 04:26:06 kloczek Exp $")
|
||||
RCSID (PKG_VER "$Id: groupdel.c,v 1.21 2005/05/25 19:31:51 kloczek Exp $")
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <grp.h>
|
||||
@@ -96,7 +96,6 @@ static void grp_update (void)
|
||||
fprintf (stderr, _("%s: error removing group entry\n"), Prog);
|
||||
errors++;
|
||||
}
|
||||
|
||||
#ifdef SHADOWGRP
|
||||
/*
|
||||
* Delete the shadow group entries as well.
|
||||
@@ -291,7 +290,6 @@ int main (int argc, char **argv)
|
||||
Prog, group_name);
|
||||
exit (E_NOTFOUND);
|
||||
}
|
||||
|
||||
#ifdef USE_NIS
|
||||
/*
|
||||
* Make sure this isn't a NIS group
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID (PKG_VER "$Id: groupmod.c,v 1.26 2005/04/06 04:26:06 kloczek Exp $")
|
||||
RCSID (PKG_VER "$Id: groupmod.c,v 1.28 2005/06/20 09:57:51 kloczek Exp $")
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <grp.h>
|
||||
@@ -178,7 +178,6 @@ static void grp_update (void)
|
||||
fprintf (stderr, _("%s: error removing group entry\n"), Prog);
|
||||
exit (E_GRP_UPDATE);
|
||||
}
|
||||
|
||||
#ifdef SHADOWGRP
|
||||
/*
|
||||
* Make sure there was a shadow entry to begin with. Skip down to
|
||||
@@ -209,7 +208,7 @@ static void grp_update (void)
|
||||
group_name, group_newname));
|
||||
|
||||
if (gflg)
|
||||
SYSLOG ((LOG_INFO, "change gid for `%s' to %u",
|
||||
SYSLOG ((LOG_INFO, "change GID for `%s' to %u",
|
||||
nflg ? group_newname : group_name, group_newid));
|
||||
}
|
||||
|
||||
@@ -239,7 +238,7 @@ static void check_new_gid (void)
|
||||
* Tell the user what they did wrong.
|
||||
*/
|
||||
|
||||
fprintf (stderr, _("%s: %u is not a unique gid\n"), Prog, group_newid);
|
||||
fprintf (stderr, _("%s: %u is not a unique GID\n"), Prog, group_newid);
|
||||
exit (E_GID_IN_USE);
|
||||
}
|
||||
|
||||
|
||||
18
src/id.c
18
src/id.c
@@ -38,7 +38,7 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID (PKG_VER "$Id: id.c,v 1.13 2003/06/19 18:11:01 kloczek Exp $")
|
||||
RCSID (PKG_VER "$Id: id.c,v 1.15 2005/06/20 10:17:08 kloczek Exp $")
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <grp.h>
|
||||
@@ -120,15 +120,15 @@ static void usage (void)
|
||||
|
||||
pw = getpwuid (ruid);
|
||||
if (pw)
|
||||
printf ("uid=%u(%s)", ruid, pw->pw_name);
|
||||
printf ("UID=%u(%s)", ruid, pw->pw_name);
|
||||
else
|
||||
printf ("uid=%u", ruid);
|
||||
printf ("UID=%u", ruid);
|
||||
|
||||
gr = getgrgid (rgid);
|
||||
if (gr)
|
||||
printf (" gid=%u(%s)", rgid, gr->gr_name);
|
||||
printf (" GID=%u(%s)", rgid, gr->gr_name);
|
||||
else
|
||||
printf (" gid=%u", rgid);
|
||||
printf (" GID=%u", rgid);
|
||||
|
||||
/*
|
||||
* Print out the effective user ID and group ID if they are
|
||||
@@ -138,16 +138,16 @@ static void usage (void)
|
||||
if (ruid != euid) {
|
||||
pw = getpwuid (euid);
|
||||
if (pw)
|
||||
printf (" euid=%u(%s)", euid, pw->pw_name);
|
||||
printf (" EUID=%u(%s)", euid, pw->pw_name);
|
||||
else
|
||||
printf (" euid=%u", euid);
|
||||
printf (" EUID=%u", euid);
|
||||
}
|
||||
if (rgid != egid) {
|
||||
gr = getgrgid (egid);
|
||||
if (gr)
|
||||
printf (" egid=%u(%s)", egid, gr->gr_name);
|
||||
printf (" EGID=%u(%s)", egid, gr->gr_name);
|
||||
else
|
||||
printf (" egid=%u", egid);
|
||||
printf (" EGID=%u", egid);
|
||||
}
|
||||
#ifdef HAVE_GETGROUPS
|
||||
/*
|
||||
|
||||
109
src/login.c
109
src/login.c
@@ -30,7 +30,7 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID (PKG_VER "$Id: login.c,v 1.52 2005/04/17 15:38:56 kloczek Exp $")
|
||||
RCSID (PKG_VER "$Id: login.c,v 1.59 2005/06/20 09:36:27 kloczek Exp $")
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
#include <sys/stat.h>
|
||||
@@ -348,7 +348,7 @@ int main (int argc, char **argv)
|
||||
pid_t child;
|
||||
char *pam_user;
|
||||
#endif /* USE_PAM */
|
||||
#if defined(SHADOWPWD) && !defined(USE_PAM)
|
||||
#ifndef USE_PAM
|
||||
struct spwd *spwd = NULL;
|
||||
#endif
|
||||
/*
|
||||
@@ -369,7 +369,7 @@ int main (int argc, char **argv)
|
||||
|
||||
check_flags (argc, argv);
|
||||
|
||||
while ((flag = getopt (argc, argv, "d:f:h:pr:")) != EOF) {
|
||||
while ((flag = getopt (argc, argv, "d:f::h:pr:")) != EOF) {
|
||||
switch (flag) {
|
||||
case 'p':
|
||||
pflg++;
|
||||
@@ -378,11 +378,16 @@ int main (int argc, char **argv)
|
||||
/*
|
||||
* username must be a separate token
|
||||
* (-f root, *not* -froot). --marekm
|
||||
*
|
||||
* if -f has an arg, use that, else use the
|
||||
* normal user name passed after all options
|
||||
* --benc
|
||||
*/
|
||||
if (optarg != argv[optind - 1])
|
||||
if (optarg != NULL && optarg != argv[optind - 1])
|
||||
usage ();
|
||||
fflg++;
|
||||
STRFCPY (username, optarg);
|
||||
if (optarg)
|
||||
STRFCPY (username, optarg);
|
||||
break;
|
||||
#ifdef RLOGIN
|
||||
case 'r':
|
||||
@@ -418,7 +423,7 @@ int main (int argc, char **argv)
|
||||
*/
|
||||
|
||||
if ((rflg || fflg || hflg) && !amroot) {
|
||||
fprintf (stderr, _("%s: permission denied.\n"), Prog);
|
||||
fprintf (stderr, _("%s: Permission denied.\n"), Prog);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
@@ -535,7 +540,7 @@ int main (int argc, char **argv)
|
||||
init_env ();
|
||||
|
||||
if (optind < argc) { /* get the user name */
|
||||
if (rflg || fflg)
|
||||
if (rflg || (fflg && username[0]))
|
||||
usage ();
|
||||
|
||||
STRFCPY (username, argv[optind]);
|
||||
@@ -703,11 +708,14 @@ int main (int argc, char **argv)
|
||||
|
||||
if (!pwd || setup_groups (pwd))
|
||||
exit (1);
|
||||
else
|
||||
pwent = *pwd;
|
||||
|
||||
retcode = pam_setcred (pamh, PAM_ESTABLISH_CRED);
|
||||
PAM_FAIL_CHECK;
|
||||
|
||||
retcode = pam_open_session (pamh, 0);
|
||||
retcode = pam_open_session (pamh,
|
||||
hushed (&pwent) ? PAM_SILENT : 0);
|
||||
PAM_FAIL_CHECK;
|
||||
|
||||
#else /* ! USE_PAM */
|
||||
@@ -742,7 +750,6 @@ int main (int argc, char **argv)
|
||||
pwent = *pwd;
|
||||
}
|
||||
#ifndef USE_PAM
|
||||
#ifdef SHADOWPWD
|
||||
spwd = NULL;
|
||||
if (pwd && strcmp (pwd->pw_passwd, SHADOW_PASSWD_STRING) == 0) {
|
||||
spwd = getspnam (username);
|
||||
@@ -753,7 +760,6 @@ int main (int argc, char **argv)
|
||||
"no shadow password for `%s'%s",
|
||||
username, fromhost));
|
||||
}
|
||||
#endif /* SHADOWPWD */
|
||||
|
||||
/*
|
||||
* If the encrypted password begins with a "!", the account
|
||||
@@ -918,9 +924,7 @@ int main (int argc, char **argv)
|
||||
subroot++; /* say i was here again */
|
||||
endpwent (); /* close all of the file which were */
|
||||
endgrent (); /* open in the original rooted file */
|
||||
#ifdef SHADOWPWD
|
||||
endspent (); /* system. they will be re-opened */
|
||||
#endif
|
||||
#ifdef SHADOWGRP
|
||||
endsgent (); /* in the new rooted file system */
|
||||
#endif
|
||||
@@ -938,7 +942,6 @@ int main (int argc, char **argv)
|
||||
* and changes to the user in the child before executing the passwd
|
||||
* program. --marekm
|
||||
*/
|
||||
#ifdef SHADOWPWD
|
||||
if (spwd) { /* check for age of password */
|
||||
if (expire (&pwent, spwd)) {
|
||||
pwd = getpwnam (username);
|
||||
@@ -947,11 +950,44 @@ int main (int argc, char **argv)
|
||||
pwent = *pwd;
|
||||
}
|
||||
}
|
||||
#endif /* SHADOWPWD */
|
||||
setup_limits (&pwent); /* nice, ulimit etc. */
|
||||
#endif /* ! USE_PAM */
|
||||
chown_tty (tty, &pwent);
|
||||
|
||||
#ifdef USE_PAM
|
||||
/*
|
||||
* We must fork before setuid() because we need to call
|
||||
* pam_close_session() as root.
|
||||
*
|
||||
* Note: not true in other (non-Linux) PAM implementations, where
|
||||
* the parent process of login (init, telnetd, ...) is responsible
|
||||
* for calling pam_close_session(). This avoids an extra process for
|
||||
* each login. Maybe we should do this on Linux too? We let the
|
||||
* admin configure whether they need to keep login around to close
|
||||
* sessions.
|
||||
*/
|
||||
if (getdef_bool ("CLOSE_SESSIONS")) {
|
||||
signal (SIGINT, SIG_IGN);
|
||||
child = fork ();
|
||||
if (child < 0) {
|
||||
/* error in fork() */
|
||||
fprintf (stderr,
|
||||
"login: failure forking: %s",
|
||||
strerror (errno));
|
||||
PAM_END;
|
||||
exit (0);
|
||||
} else if (child) {
|
||||
/*
|
||||
* parent - wait for child to finish, then cleanup
|
||||
* session
|
||||
*/
|
||||
wait (NULL);
|
||||
PAM_END;
|
||||
exit (0);
|
||||
}
|
||||
/* child */
|
||||
}
|
||||
#endif
|
||||
/* We call set_groups() above because this clobbers pam_groups.so */
|
||||
#ifndef USE_PAM
|
||||
if (setup_uid_gid (&pwent, is_console))
|
||||
@@ -1021,11 +1057,7 @@ int main (int argc, char **argv)
|
||||
#endif
|
||||
printf (".\n");
|
||||
}
|
||||
#ifdef SHADOWPWD
|
||||
agecheck (&pwent, spwd);
|
||||
#else
|
||||
agecheck (&pwent);
|
||||
#endif
|
||||
|
||||
mailcheck (); /* report on the status of mail */
|
||||
#endif /* !USE_PAM */
|
||||
@@ -1039,55 +1071,22 @@ int main (int argc, char **argv)
|
||||
signal (SIGTERM, SIG_DFL); /* default terminate signal */
|
||||
signal (SIGALRM, SIG_DFL); /* default alarm signal */
|
||||
signal (SIGHUP, SIG_DFL); /* added this. --marekm */
|
||||
|
||||
#ifdef USE_PAM
|
||||
/*
|
||||
* We must fork before setuid() because we need to call
|
||||
* pam_close_session() as root.
|
||||
*
|
||||
* Note: not true in other (non-Linux) PAM implementations, where
|
||||
* the parent process of login (init, telnetd, ...) is responsible
|
||||
* for calling pam_close_session(). This avoids an extra process for
|
||||
* each login. Maybe we should do this on Linux too? We let the
|
||||
* admin configure whether they need to keep login around to close
|
||||
* sessions.
|
||||
*/
|
||||
if (getdef_bool ("CLOSE_SESSIONS")) {
|
||||
signal (SIGINT, SIG_IGN);
|
||||
child = fork ();
|
||||
if (child < 0) {
|
||||
/* error in fork() */
|
||||
fprintf (stderr,
|
||||
"login: failure forking: %s",
|
||||
strerror (errno));
|
||||
PAM_END;
|
||||
exit (0);
|
||||
} else if (child) {
|
||||
/*
|
||||
* parent - wait for child to finish, then cleanup
|
||||
* session
|
||||
*/
|
||||
wait (NULL);
|
||||
PAM_END;
|
||||
exit (0);
|
||||
}
|
||||
/* child */
|
||||
}
|
||||
#endif
|
||||
signal (SIGINT, SIG_DFL); /* default interrupt signal */
|
||||
|
||||
endpwent (); /* stop access to password file */
|
||||
endgrent (); /* stop access to group file */
|
||||
#ifdef SHADOWPWD
|
||||
endspent (); /* stop access to shadow passwd file */
|
||||
#endif
|
||||
#ifdef SHADOWGRP
|
||||
endsgent (); /* stop access to shadow group file */
|
||||
#endif
|
||||
if (pwent.pw_uid == 0)
|
||||
SYSLOG ((LOG_NOTICE, "ROOT LOGIN %s", fromhost));
|
||||
else if (getdef_bool ("LOG_OK_LOGINS"))
|
||||
#ifdef USE_PAM
|
||||
SYSLOG ((LOG_INFO, "`%s' logged in %s", pam_user, fromhost));
|
||||
#else
|
||||
SYSLOG ((LOG_INFO, "`%s' logged in %s", username, fromhost));
|
||||
#endif
|
||||
closelog ();
|
||||
if ((tmp = getdef_str ("FAKE_SHELL")) != NULL) {
|
||||
shell (tmp, pwent.pw_shell); /* fake shell */
|
||||
|
||||
399
src/mkpasswd.c
399
src/mkpasswd.c
@@ -1,399 +0,0 @@
|
||||
/*
|
||||
* Copyright 1990 - 1994, Julianne Frances Haugh
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of Julianne F. Haugh nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY JULIE HAUGH AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* 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 "rcsid.h"
|
||||
RCSID (PKG_VER "$Id: mkpasswd.c,v 1.12 2005/03/31 05:14:54 kloczek Exp $")
|
||||
#include <sys/stat.h>
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
#include <stdio.h>
|
||||
#if !defined(NDBM) /*{ */
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
setlocale (LC_ALL, "");
|
||||
bindtextdomain (PACKAGE, LOCALEDIR);
|
||||
textdomain (PACKAGE);
|
||||
|
||||
fprintf (stderr,
|
||||
_
|
||||
("%s: no DBM database on system - no action performed\n"),
|
||||
argv[0]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else /*} defined(NDBM) { */
|
||||
#include <fcntl.h>
|
||||
#include <pwd.h>
|
||||
#include <ndbm.h>
|
||||
#include <grp.h>
|
||||
extern DBM *pw_dbm;
|
||||
extern DBM *gr_dbm;
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
extern DBM *sp_dbm;
|
||||
#endif
|
||||
#ifdef SHADOWGRP
|
||||
extern DBM *sg_dbm;
|
||||
#endif
|
||||
|
||||
char *Progname;
|
||||
int vflg = 0;
|
||||
int fflg = 0;
|
||||
int gflg = 0;
|
||||
int sflg = 0; /* -s flag -- leave in, makes code nicer */
|
||||
int pflg = 0;
|
||||
|
||||
extern struct passwd *sgetpwent ();
|
||||
extern int pw_dbm_update ();
|
||||
|
||||
extern struct group *sgetgrent ();
|
||||
extern int gr_dbm_update ();
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
extern struct spwd *sgetspent ();
|
||||
extern int sp_dbm_update ();
|
||||
#endif
|
||||
|
||||
#ifdef SHADOWGRP
|
||||
extern struct sgrp *sgetsgent ();
|
||||
extern int sg_dbm_update ();
|
||||
#endif
|
||||
|
||||
/* local function prototypes */
|
||||
static void usage (void);
|
||||
|
||||
/*
|
||||
* mkpasswd - create DBM files for /etc/passwd-like input file
|
||||
*
|
||||
* mkpasswd takes an an argument the name of a file in /etc/passwd format
|
||||
* and creates a DBM file keyed by user ID and name. The output files have
|
||||
* the same name as the input file, with .dir and .pag appended.
|
||||
*
|
||||
* this command will also create look-aside files for
|
||||
* /etc/group, /etc/shadow, and /etc/gshadow.
|
||||
*/
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
extern int optind;
|
||||
extern char *optarg;
|
||||
FILE *fp; /* File pointer for input file */
|
||||
char *file; /* Name of input file */
|
||||
char *dir; /* Name of .dir file */
|
||||
char *pag; /* Name of .pag file */
|
||||
char *cp; /* Temporary character pointer */
|
||||
int flag; /* Flag for command line option */
|
||||
int cnt = 0; /* Number of entries in database */
|
||||
int longest = 0; /* Longest entry in database */
|
||||
int len; /* Length of input line */
|
||||
int errors = 0; /* Count of errors processing file */
|
||||
char buf[BUFSIZ * 8]; /* Input line from file */
|
||||
struct passwd *passwd = NULL; /* Pointer to password file entry */
|
||||
|
||||
struct group *group = NULL; /* Pointer to group file entry */
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
struct spwd *shadow = NULL; /* Pointer to shadow passwd entry */
|
||||
#endif
|
||||
#ifdef SHADOWGRP
|
||||
struct sgrp *gshadow = NULL; /* Pointer to shadow group entry */
|
||||
#endif
|
||||
DBM *dbm; /* Pointer to new NDBM files */
|
||||
DBM *dbm_open (); /* Function to open NDBM files */
|
||||
|
||||
/*
|
||||
* Figure out what my name is. I will use this later ...
|
||||
*/
|
||||
|
||||
Progname = Basename (argv[0]);
|
||||
|
||||
/*
|
||||
* Figure out what the flags might be ...
|
||||
*/
|
||||
|
||||
while ((flag = getopt (argc, argv, "fvpgs")) != EOF) {
|
||||
switch (flag) {
|
||||
case 'v':
|
||||
vflg++;
|
||||
break;
|
||||
case 'f':
|
||||
fflg++;
|
||||
break;
|
||||
case 'g':
|
||||
gflg++;
|
||||
#ifndef SHADOWGRP
|
||||
if (sflg)
|
||||
usage ();
|
||||
#endif
|
||||
if (pflg)
|
||||
usage ();
|
||||
|
||||
break;
|
||||
#if defined(SHADOWPWD) || defined(SHADOWGRP)
|
||||
case 's':
|
||||
sflg++;
|
||||
#ifndef SHADOWGRP
|
||||
if (gflg)
|
||||
usage ();
|
||||
#endif
|
||||
break;
|
||||
#endif
|
||||
case 'p':
|
||||
pflg++;
|
||||
if (gflg)
|
||||
usage ();
|
||||
|
||||
break;
|
||||
default:
|
||||
usage ();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Backwards compatibility fix for -p flag ...
|
||||
*/
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
if (!sflg && !gflg)
|
||||
#else
|
||||
if (!gflg)
|
||||
#endif
|
||||
pflg++;
|
||||
|
||||
/*
|
||||
* The last and only remaining argument must be the file name
|
||||
*/
|
||||
|
||||
if (argc - 1 != optind)
|
||||
usage ();
|
||||
|
||||
file = argv[optind];
|
||||
|
||||
if (!(fp = fopen (file, "r"))) {
|
||||
fprintf (stderr, _("%s: cannot open file %s\n"), Progname,
|
||||
file);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Make the filenames for the two DBM files.
|
||||
*/
|
||||
|
||||
dir = xmalloc (strlen (file) + 5); /* space for .dir file */
|
||||
strcat (strcpy (dir, file), ".dir");
|
||||
|
||||
pag = xmalloc (strlen (file) + 5); /* space for .pag file */
|
||||
strcat (strcpy (pag, file), ".pag");
|
||||
|
||||
/*
|
||||
* Remove existing files if requested.
|
||||
*/
|
||||
|
||||
if (fflg) {
|
||||
(void) unlink (dir);
|
||||
(void) unlink (pag);
|
||||
}
|
||||
|
||||
/*
|
||||
* Create the two DBM files - it is an error for these files
|
||||
* to have existed already.
|
||||
*/
|
||||
|
||||
if (access (dir, F_OK) == 0) {
|
||||
fprintf (stderr, _("%s: cannot overwrite file %s\n"),
|
||||
Progname, dir);
|
||||
exit (1);
|
||||
}
|
||||
if (access (pag, F_OK) == 0) {
|
||||
fprintf (stderr, _("%s: cannot overwrite file %s\n"),
|
||||
Progname, pag);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
if (sflg)
|
||||
umask (077);
|
||||
else
|
||||
umask (022);
|
||||
|
||||
/*
|
||||
* Now the DBM database gets initialized
|
||||
*/
|
||||
|
||||
if (!(dbm = dbm_open (file, O_RDWR | O_CREAT, 0644))) {
|
||||
fprintf (stderr, _("%s: cannot open DBM files for %s\n"),
|
||||
Progname, file);
|
||||
exit (1);
|
||||
}
|
||||
if (gflg) {
|
||||
#ifdef SHADOWGRP
|
||||
if (sflg)
|
||||
sg_dbm = dbm;
|
||||
else
|
||||
#endif
|
||||
gr_dbm = dbm;
|
||||
} else {
|
||||
#ifdef SHADOWPWD
|
||||
if (sflg)
|
||||
sp_dbm = dbm;
|
||||
else
|
||||
#endif
|
||||
pw_dbm = dbm;
|
||||
}
|
||||
|
||||
/*
|
||||
* Read every line in the password file and convert it into a data
|
||||
* structure to be put in the DBM database files.
|
||||
*/
|
||||
|
||||
while (fgetsx (buf, BUFSIZ, fp) != NULL) {
|
||||
|
||||
/*
|
||||
* Get the next line and strip off the trailing newline
|
||||
* character.
|
||||
*/
|
||||
|
||||
buf[sizeof buf - 1] = '\0';
|
||||
if (!(cp = strchr (buf, '\n'))) {
|
||||
fprintf (stderr,
|
||||
_("%s: the line beginning with %.16s... is too long\n"),
|
||||
Progname, buf);
|
||||
exit (1);
|
||||
}
|
||||
*cp = '\0';
|
||||
len = strlen (buf);
|
||||
|
||||
#ifdef USE_NIS
|
||||
/*
|
||||
* Parse the password file line into a (struct passwd).
|
||||
* Erroneous lines cause error messages, but that's all. YP
|
||||
* lines are ignored completely.
|
||||
*/
|
||||
|
||||
if (buf[0] == '-' || buf[0] == '+')
|
||||
continue;
|
||||
#endif
|
||||
if (!(((!sflg && pflg) && (passwd = sgetpwent (buf)))
|
||||
#ifdef SHADOWPWD
|
||||
|| ((sflg && pflg) && (shadow = sgetspent (buf)))
|
||||
#endif
|
||||
|| ((!sflg && gflg) && (group = sgetgrent (buf)))
|
||||
#ifdef SHADOWGRP
|
||||
|| ((sflg && gflg) && (gshadow = sgetsgent (buf)))
|
||||
#endif
|
||||
)) {
|
||||
fprintf (stderr,
|
||||
_("%s: error parsing line \"%s\"\n"),
|
||||
Progname, buf);
|
||||
errors++;
|
||||
continue;
|
||||
}
|
||||
if (vflg) {
|
||||
if (!sflg && pflg)
|
||||
printf (_
|
||||
("adding record for name %s\n"),
|
||||
passwd->pw_name);
|
||||
#ifdef SHADOWPWD
|
||||
if (sflg && pflg)
|
||||
printf (_
|
||||
("adding record for name %s\n"),
|
||||
shadow->sp_namp);
|
||||
#endif
|
||||
if (!sflg && gflg)
|
||||
printf (_
|
||||
("adding record for name %s\n"),
|
||||
group->gr_name);
|
||||
#ifdef SHADOWGRP
|
||||
if (sflg && gflg)
|
||||
printf (_
|
||||
("adding record for name %s\n"),
|
||||
gshadow->sg_name);
|
||||
#endif
|
||||
}
|
||||
if (!sflg && pflg && !pw_dbm_update (passwd))
|
||||
fprintf (stderr,
|
||||
_("%s: error adding record for %s\n"),
|
||||
Progname, passwd->pw_name);
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
if (sflg && pflg && !sp_dbm_update (shadow))
|
||||
fprintf (stderr,
|
||||
_("%s: error adding record for %s\n"),
|
||||
Progname, shadow->sp_namp);
|
||||
#endif
|
||||
if (!sflg && gflg && !gr_dbm_update (group))
|
||||
fprintf (stderr,
|
||||
_("%s: error adding record for %s\n"),
|
||||
Progname, group->gr_name);
|
||||
#ifdef SHADOWGRP
|
||||
if (sflg && gflg && !sg_dbm_update (gshadow))
|
||||
fprintf (stderr,
|
||||
_("%s: error adding record for %s\n"),
|
||||
Progname, gshadow->sg_name);
|
||||
#endif /* SHADOWGRP */
|
||||
|
||||
/*
|
||||
* Update the longest record and record count
|
||||
*/
|
||||
|
||||
if (len > longest)
|
||||
longest = len;
|
||||
cnt++;
|
||||
}
|
||||
|
||||
/*
|
||||
* Tell the user how things went ...
|
||||
*/
|
||||
|
||||
if (vflg)
|
||||
printf (_("added %d entries, longest was %d\n"), cnt, longest);
|
||||
|
||||
exit (errors);
|
||||
/*NOTREACHED*/}
|
||||
|
||||
/*
|
||||
* usage - print error message and exit
|
||||
*/
|
||||
|
||||
static void usage (void)
|
||||
{
|
||||
#ifdef SHADOWPWD
|
||||
#ifdef SHADOWGRP
|
||||
fprintf (stderr, _("Usage: %s [-vf] [-p|g|sp|sg] file\n"), Progname);
|
||||
#else /* !SHADOWGRP */
|
||||
fprintf (stderr, _("Usage: %s [-vf] [-p|g|sp] file\n"), Progname);
|
||||
#endif /* SHADOWGRP */
|
||||
#else /* !SHADOWPWD */
|
||||
fprintf (stderr, _("Usage: %s [-vf] [-p|g] file\n"), Progname);
|
||||
#endif /* SHADOWPWD */
|
||||
|
||||
exit (1);
|
||||
/*NOTREACHED*/}
|
||||
#endif /*} defined(NDBM) */
|
||||
31
src/newgrp.c
31
src/newgrp.c
@@ -30,7 +30,7 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID (PKG_VER "$Id: newgrp.c,v 1.28 2005/05/19 11:28:27 kloczek Exp $")
|
||||
RCSID (PKG_VER "$Id: newgrp.c,v 1.32 2005/06/20 10:17:08 kloczek Exp $")
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <grp.h>
|
||||
@@ -82,9 +82,8 @@ int main (int argc, char **argv)
|
||||
struct passwd *pwd;
|
||||
struct group *grp;
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
struct spwd *spwd;
|
||||
#endif
|
||||
|
||||
#ifdef SHADOWGRP
|
||||
struct sgrp *sgrp;
|
||||
#endif
|
||||
@@ -128,8 +127,8 @@ int main (int argc, char **argv)
|
||||
|
||||
pwd = get_my_pwent ();
|
||||
if (!pwd) {
|
||||
fprintf (stderr, _("unknown uid: %u\n"), getuid ());
|
||||
SYSLOG ((LOG_WARN, "unknown uid %u", getuid ()));
|
||||
fprintf (stderr, _("unknown UID: %u\n"), getuid ());
|
||||
SYSLOG ((LOG_WARN, "unknown UID %u", getuid ()));
|
||||
closelog ();
|
||||
exit (1);
|
||||
}
|
||||
@@ -210,9 +209,9 @@ int main (int argc, char **argv)
|
||||
*/
|
||||
|
||||
if (!(grp = getgrgid (pwd->pw_gid))) {
|
||||
fprintf (stderr, _("unknown gid: %lu\n"),
|
||||
fprintf (stderr, _("unknown GID: %lu\n"),
|
||||
(unsigned long) pwd->pw_gid);
|
||||
SYSLOG ((LOG_CRIT, "unknown gid: %lu",
|
||||
SYSLOG ((LOG_CRIT, "unknown GID: %lu",
|
||||
(unsigned long) pwd->pw_gid));
|
||||
goto failure;
|
||||
} else
|
||||
@@ -252,14 +251,14 @@ int main (int argc, char **argv)
|
||||
* set to the value from her password file entry.
|
||||
*
|
||||
* If run as newgrp, or as sg with no command, this process exec's
|
||||
* an interactive subshell with the effective gid of the new group.
|
||||
* an interactive subshell with the effective GID of the new group.
|
||||
* If run as sg with a command, that command is exec'ed in this
|
||||
* subshell. When this process terminates, either because the user
|
||||
* exits, or the command completes, the parent of this process
|
||||
* resumes with the current gid.
|
||||
* resumes with the current GID.
|
||||
*
|
||||
* If a group is explicitly specified on the command line, the
|
||||
* interactive shell or command is run with that effective gid.
|
||||
* interactive shell or command is run with that effective GID.
|
||||
* Access will be denied if no entry for that group can be found in
|
||||
* /etc/group. If the current user name appears in the members list
|
||||
* for that group, access will be granted immediately; if not, the
|
||||
@@ -267,9 +266,9 @@ int main (int argc, char **argv)
|
||||
* password response is incorrect, if the specified group does not
|
||||
* have a password, or if that group has been locked by gpasswd -R,
|
||||
* access will be denied. This is true even if the group specified
|
||||
* has the user's login gid (as shown in /etc/passwd). If no group
|
||||
* has the user's login GID (as shown in /etc/passwd). If no group
|
||||
* is explicitly specified on the command line, the effect is
|
||||
* exactly the same as if a group name matching the user's login gid
|
||||
* exactly the same as if a group name matching the user's login GID
|
||||
* had been explicitly specified. Root, however, is never
|
||||
* challenged for passwords, and is always allowed access.
|
||||
*
|
||||
@@ -313,10 +312,8 @@ int main (int argc, char **argv)
|
||||
* group password.
|
||||
*/
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
if ((spwd = getspnam (name)))
|
||||
pwd->pw_passwd = spwd->sp_pwdp;
|
||||
#endif
|
||||
|
||||
if (pwd->pw_passwd[0] == '\0' && grp->gr_passwd[0])
|
||||
needspasswd = 1;
|
||||
@@ -480,8 +477,8 @@ int main (int argc, char **argv)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Set the effective gid to the new group id and the effective uid
|
||||
* to the real uid. For root, this also sets the real gid to the
|
||||
* Set the effective GID to the new group id and the effective UID
|
||||
* to the real UID. For root, this also sets the real GID to the
|
||||
* new group id.
|
||||
*/
|
||||
|
||||
@@ -542,9 +539,7 @@ int main (int argc, char **argv)
|
||||
|
||||
cp = Basename ((char *) prog);
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
endspent ();
|
||||
#endif
|
||||
#ifdef SHADOWGRP
|
||||
endsgent ();
|
||||
#endif
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID (PKG_VER "$Id: newusers.c,v 1.21 2005/03/31 05:14:54 kloczek Exp $")
|
||||
RCSID (PKG_VER "$Id: newusers.c,v 1.23 2005/05/25 19:31:51 kloczek Exp $")
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include "prototypes.h"
|
||||
@@ -56,11 +56,9 @@ static char *Prog;
|
||||
#include "pwio.h"
|
||||
#include "groupio.h"
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
#include "shadowio.h"
|
||||
|
||||
static int is_shadow;
|
||||
#endif
|
||||
|
||||
/* local function prototypes */
|
||||
static void usage (void);
|
||||
@@ -237,10 +235,8 @@ static void update_passwd (struct passwd *pwd, const char *passwd)
|
||||
|
||||
static int add_passwd (struct passwd *pwd, const char *passwd)
|
||||
{
|
||||
#ifdef SHADOWPWD
|
||||
const struct spwd *sp;
|
||||
struct spwd spent;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* In the case of regular password files, this is real easy - pwd
|
||||
@@ -252,7 +248,6 @@ static int add_passwd (struct passwd *pwd, const char *passwd)
|
||||
update_passwd (pwd, passwd);
|
||||
return 0;
|
||||
}
|
||||
#ifdef SHADOWPWD
|
||||
/*
|
||||
* Do the first and easiest shadow file case. The user already
|
||||
* exists in the shadow password file.
|
||||
@@ -293,7 +288,6 @@ static int add_passwd (struct passwd *pwd, const char *passwd)
|
||||
spent.sp_flag = -1;
|
||||
|
||||
return !spw_update (&spent);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef USE_PAM
|
||||
@@ -382,36 +376,22 @@ int main (int argc, char **argv)
|
||||
fprintf (stderr, _("%s: can't lock /etc/passwd.\n"), Prog);
|
||||
exit (1);
|
||||
}
|
||||
#ifdef SHADOWPWD
|
||||
is_shadow = spw_file_present ();
|
||||
|
||||
if ((is_shadow && !spw_lock ()) || !gr_lock ())
|
||||
#else
|
||||
if (!gr_lock ())
|
||||
#endif
|
||||
{
|
||||
if ((is_shadow && !spw_lock ()) || !gr_lock ()) {
|
||||
fprintf (stderr,
|
||||
_("%s: can't lock files, try again later\n"), Prog);
|
||||
(void) pw_unlock ();
|
||||
#ifdef SHADOWPWD
|
||||
if (is_shadow)
|
||||
spw_unlock ();
|
||||
#endif
|
||||
exit (1);
|
||||
}
|
||||
#ifdef SHADOWPWD
|
||||
if (!pw_open (O_RDWR) || (is_shadow && !spw_open (O_RDWR))
|
||||
|| !gr_open (O_RDWR))
|
||||
#else
|
||||
if (!pw_open (O_RDWR) || !gr_open (O_RDWR))
|
||||
#endif
|
||||
{
|
||||
|| !gr_open (O_RDWR)) {
|
||||
fprintf (stderr, _("%s: can't open files\n"), Prog);
|
||||
(void) pw_unlock ();
|
||||
#ifdef SHADOWPWD
|
||||
if (is_shadow)
|
||||
spw_unlock ();
|
||||
#endif
|
||||
(void) gr_unlock ();
|
||||
exit (1);
|
||||
}
|
||||
@@ -560,33 +540,22 @@ int main (int argc, char **argv)
|
||||
fprintf (stderr,
|
||||
_("%s: error detected, changes ignored\n"), Prog);
|
||||
(void) gr_unlock ();
|
||||
#ifdef SHADOWPWD
|
||||
if (is_shadow)
|
||||
spw_unlock ();
|
||||
#endif
|
||||
(void) pw_unlock ();
|
||||
exit (1);
|
||||
}
|
||||
#ifdef SHADOWPWD
|
||||
if (!pw_close () || (is_shadow && !spw_close ()) || !gr_close ())
|
||||
#else
|
||||
if (!pw_close () || !gr_close ())
|
||||
#endif
|
||||
{
|
||||
if (!pw_close () || (is_shadow && !spw_close ()) || !gr_close ()) {
|
||||
fprintf (stderr, _("%s: error updating files\n"), Prog);
|
||||
(void) gr_unlock ();
|
||||
#ifdef SHADOWPWD
|
||||
if (is_shadow)
|
||||
spw_unlock ();
|
||||
#endif
|
||||
(void) pw_unlock ();
|
||||
exit (1);
|
||||
}
|
||||
(void) gr_unlock ();
|
||||
#ifdef SHADOWPWD
|
||||
if (is_shadow)
|
||||
spw_unlock ();
|
||||
#endif
|
||||
(void) pw_unlock ();
|
||||
|
||||
#ifdef USE_PAM
|
||||
|
||||
78
src/passwd.c
78
src/passwd.c
@@ -30,7 +30,7 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID (PKG_VER "$Id: passwd.c,v 1.36 2005/04/15 21:23:49 kloczek Exp $")
|
||||
RCSID (PKG_VER "$Id: passwd.c,v 1.39 2005/06/20 09:36:27 kloczek Exp $")
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
#include <sys/types.h>
|
||||
@@ -50,9 +50,7 @@ RCSID (PKG_VER "$Id: passwd.c,v 1.36 2005/04/15 21:23:49 kloczek Exp $")
|
||||
#endif
|
||||
#include <pwd.h>
|
||||
#include "pwauth.h"
|
||||
#ifdef SHADOWPWD
|
||||
#include "shadowio.h"
|
||||
#endif
|
||||
#include "pwio.h"
|
||||
#include "nscd.h"
|
||||
#include "getdef.h"
|
||||
@@ -79,14 +77,12 @@ static char *Prog; /* Program name */
|
||||
static int amroot; /* The real UID was 0 */
|
||||
|
||||
static int
|
||||
#ifdef SHADOWPWD
|
||||
eflg = 0, /* -e - force password change */
|
||||
iflg = 0, /* -i - set inactive days */
|
||||
kflg = 0, /* -k - change only if expired */
|
||||
nflg = 0, /* -n - set minimum days */
|
||||
wflg = 0, /* -w - set warning days */
|
||||
xflg = 0, /* -x - set maximum days */
|
||||
#endif
|
||||
aflg = 0, /* -a - show status for all users */
|
||||
dflg = 0, /* -d - delete password */
|
||||
lflg = 0, /* -l - lock account */
|
||||
@@ -100,12 +96,10 @@ static int
|
||||
*/
|
||||
static int anyflag = 0;
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
static long age_min = 0; /* Minimum days before change */
|
||||
static long age_max = 0; /* Maximum days until change */
|
||||
static long warn = 0; /* Warning days before change */
|
||||
static long inact = 0; /* Days without change before locked */
|
||||
#endif
|
||||
|
||||
static int do_update_age = 0;
|
||||
|
||||
@@ -125,11 +119,7 @@ static void usage (int);
|
||||
static int reuse (const char *, const struct passwd *);
|
||||
static int new_password (const struct passwd *);
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
static void check_password (const struct passwd *, const struct spwd *);
|
||||
#else /* !SHADOWPWD */
|
||||
static void check_password (const struct passwd *);
|
||||
#endif /* !SHADOWPWD */
|
||||
static char *insert_crypt_passwd (const char *, const char *);
|
||||
#endif /* !USE_PAM */
|
||||
static char *date_to_str (time_t);
|
||||
@@ -140,9 +130,7 @@ static void oom (void);
|
||||
static char *update_crypt_pw (char *);
|
||||
static void update_noshadow (void);
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
static void update_shadow (void);
|
||||
#endif
|
||||
static long getnumber (const char *);
|
||||
|
||||
/*
|
||||
@@ -314,21 +302,12 @@ Please use a combination of upper and lower case letters and numbers.\n"), getde
|
||||
* password for the given user.
|
||||
*/
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
static void check_password (const struct passwd *pw, const struct spwd *sp)
|
||||
{
|
||||
#else
|
||||
static void check_password (const struct passwd *pw)
|
||||
{
|
||||
#endif
|
||||
time_t now, last, ok;
|
||||
int exp_status;
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
exp_status = isexpired (pw, sp);
|
||||
#else
|
||||
exp_status = isexpired (pw);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* If not expired and the "change only if expired" option (idea from
|
||||
@@ -346,7 +325,6 @@ static void check_password (const struct passwd *pw)
|
||||
|
||||
time (&now);
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
/*
|
||||
* Expired accounts cannot be changed ever. Passwords which are
|
||||
* locked may not be changed. Passwords where min > max may not be
|
||||
@@ -371,19 +349,6 @@ static void check_password (const struct passwd *pw)
|
||||
last = sp->sp_lstchg * SCALE;
|
||||
ok = last + (sp->sp_min > 0 ? sp->sp_min * SCALE : 0);
|
||||
|
||||
#else /* !SHADOWPWD */
|
||||
if (pw->pw_passwd[0] == '!' || exp_status > 1) {
|
||||
fprintf (stderr,
|
||||
_("The password for %s cannot be changed.\n"),
|
||||
pw->pw_name);
|
||||
SYSLOG ((LOG_WARN, "password locked for `%s'", pw->pw_name));
|
||||
closelog ();
|
||||
exit (E_NOPERM);
|
||||
}
|
||||
|
||||
last = 0;
|
||||
ok = 0;
|
||||
#endif /* !SHADOWPWD */
|
||||
if (now < ok) {
|
||||
fprintf (stderr,
|
||||
_
|
||||
@@ -435,11 +400,8 @@ static const char *pw_status (const char *pass)
|
||||
|
||||
static void print_status (const struct passwd *pw)
|
||||
{
|
||||
#ifdef SHADOWPWD
|
||||
struct spwd *sp;
|
||||
#endif
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
sp = getspnam (pw->pw_name);
|
||||
if (sp) {
|
||||
printf ("%s %s %s %ld %ld %ld %ld\n",
|
||||
@@ -450,9 +412,7 @@ static void print_status (const struct passwd *pw)
|
||||
(sp->sp_max * SCALE) / DAY,
|
||||
(sp->sp_warn * SCALE) / DAY,
|
||||
(sp->sp_inact * SCALE) / DAY);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
} else {
|
||||
printf ("%s %s\n", pw->pw_name, pw_status (pw->pw_passwd));
|
||||
}
|
||||
}
|
||||
@@ -461,9 +421,7 @@ static void print_status (const struct passwd *pw)
|
||||
static void fail_exit (int status)
|
||||
{
|
||||
pw_unlock ();
|
||||
#ifdef SHADOWPWD
|
||||
spw_unlock ();
|
||||
#endif
|
||||
exit (status);
|
||||
}
|
||||
|
||||
@@ -537,7 +495,6 @@ static void update_noshadow (void)
|
||||
pw_unlock ();
|
||||
}
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
static void update_shadow (void)
|
||||
{
|
||||
const struct spwd *sp;
|
||||
@@ -597,7 +554,6 @@ static void update_shadow (void)
|
||||
}
|
||||
spw_unlock ();
|
||||
}
|
||||
#endif /* SHADOWPWD */
|
||||
|
||||
static long getnumber (const char *str)
|
||||
{
|
||||
@@ -647,9 +603,7 @@ int main (int argc, char **argv)
|
||||
#ifndef USE_PAM
|
||||
char *cp; /* Miscellaneous character pointing */
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
const struct spwd *sp; /* Shadow file entry for user */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
setlocale (LC_ALL, "");
|
||||
@@ -715,16 +669,9 @@ int main (int argc, char **argv)
|
||||
* be checked for any commands which are restricted to root only.
|
||||
*/
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
#define FLAGS "adlqr:uSekn:x:i:w:"
|
||||
#else
|
||||
# define FLAGS "adlqr:uS"
|
||||
#endif
|
||||
|
||||
while ((flag = getopt (argc, argv, FLAGS)) != EOF) {
|
||||
#undef FLAGS
|
||||
while ((flag = getopt (argc, argv, "adlqr:uSekn:x:i:w:")) != EOF) {
|
||||
switch (flag) {
|
||||
#ifdef SHADOWPWD
|
||||
case 'x':
|
||||
age_max = getnumber (optarg);
|
||||
xflg++;
|
||||
@@ -755,7 +702,6 @@ int main (int argc, char **argv)
|
||||
/* change only if expired, like Linux-PAM passwd -k. */
|
||||
kflg++; /* ok for users */
|
||||
break;
|
||||
#endif /* SHADOWPWD */
|
||||
case 'a':
|
||||
aflg++;
|
||||
break;
|
||||
@@ -820,7 +766,7 @@ int main (int argc, char **argv)
|
||||
if (anyflag || !Sflg || (optind < argc))
|
||||
usage (E_USAGE);
|
||||
if (!amroot) {
|
||||
fprintf (stderr, _("%s: permission denied.\n"), Prog);
|
||||
fprintf (stderr, _("%s: Permission denied.\n"), Prog);
|
||||
exit (E_NOPERM);
|
||||
}
|
||||
setpwent ();
|
||||
@@ -856,7 +802,7 @@ int main (int argc, char **argv)
|
||||
usage (E_USAGE);
|
||||
|
||||
if (anyflag && !amroot) {
|
||||
fprintf (stderr, _("%s: permission denied.\n"), Prog);
|
||||
fprintf (stderr, _("%s: Permission denied.\n"), Prog);
|
||||
exit (E_NOPERM);
|
||||
}
|
||||
|
||||
@@ -895,7 +841,6 @@ int main (int argc, char **argv)
|
||||
exit (E_SUCCESS);
|
||||
}
|
||||
#ifndef USE_PAM
|
||||
#ifdef SHADOWPWD
|
||||
/*
|
||||
* The user name is valid, so let's get the shadow file entry.
|
||||
*/
|
||||
@@ -905,9 +850,6 @@ int main (int argc, char **argv)
|
||||
sp = pwd_to_spwd (pw);
|
||||
|
||||
cp = sp->sp_pwdp;
|
||||
#else
|
||||
cp = pw->pw_passwd;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* If there are no other flags, just change the password.
|
||||
@@ -921,11 +863,7 @@ int main (int argc, char **argv)
|
||||
* Otherwise, go ahead and set a new password.
|
||||
*/
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
check_password (pw, sp);
|
||||
#else
|
||||
check_password (pw);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Let the user know whose password is being changed.
|
||||
@@ -961,25 +899,21 @@ int main (int argc, char **argv)
|
||||
do_pam_passwd (name, qflg, kflg);
|
||||
exit (E_SUCCESS);
|
||||
}
|
||||
#endif /* SHADOWPWD */
|
||||
#endif /* USE_PAM */
|
||||
if (setuid (0)) {
|
||||
fprintf (stderr, _("Cannot change ID to root.\n"));
|
||||
SYSLOG ((LOG_ERR, "can't setuid(0)"));
|
||||
closelog ();
|
||||
exit (E_NOPERM);
|
||||
}
|
||||
#ifdef SHADOWPWD
|
||||
if (spw_file_present ())
|
||||
update_shadow ();
|
||||
else
|
||||
#endif
|
||||
update_noshadow ();
|
||||
|
||||
nscd_flush_cache ("passwd");
|
||||
nscd_flush_cache ("group");
|
||||
#ifdef SHADOWPWD
|
||||
nscd_flush_cache ("shadow");
|
||||
#endif
|
||||
|
||||
SYSLOG ((LOG_INFO, "password for `%s' changed by `%s'", name, myname));
|
||||
closelog ();
|
||||
|
||||
30
src/pwck.c
30
src/pwck.c
@@ -30,7 +30,7 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID (PKG_VER "$Id: pwck.c,v 1.26 2005/04/06 04:26:06 kloczek Exp $")
|
||||
RCSID (PKG_VER "$Id: pwck.c,v 1.27 2005/05/25 18:20:25 kloczek Exp $")
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <grp.h>
|
||||
@@ -43,11 +43,9 @@ RCSID (PKG_VER "$Id: pwck.c,v 1.26 2005/04/06 04:26:06 kloczek Exp $")
|
||||
extern void __pw_del_entry (const struct commonio_entry *);
|
||||
extern struct commonio_entry *__pw_get_head (void);
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
#include "shadowio.h"
|
||||
extern void __spw_del_entry (const struct commonio_entry *);
|
||||
extern struct commonio_entry *__spw_get_head (void);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Exit codes
|
||||
@@ -67,9 +65,7 @@ extern struct commonio_entry *__spw_get_head (void);
|
||||
static char *Prog;
|
||||
static const char *pwd_file = PASSWD_FILE;
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
static const char *spw_file = SHADOW_FILE;
|
||||
#endif
|
||||
static int read_only = 0;
|
||||
static int quiet = 0; /* don't report warnings, only errors */
|
||||
|
||||
@@ -83,12 +79,8 @@ static int yes_or_no (void);
|
||||
|
||||
static void usage (void)
|
||||
{
|
||||
#ifdef SHADOWPWD
|
||||
fprintf (stderr, _("Usage: %s [-q] [-r] [-s] [passwd [shadow]]\n"),
|
||||
Prog);
|
||||
#else
|
||||
fprintf (stderr, _("Usage: %s [-q] [-r] [-s] [passwd]\n"), Prog);
|
||||
#endif
|
||||
exit (E_USAGE);
|
||||
}
|
||||
|
||||
@@ -132,11 +124,9 @@ int main (int argc, char **argv)
|
||||
struct passwd *pwd;
|
||||
int sort_mode = 0;
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
struct commonio_entry *spe, *tspe;
|
||||
struct spwd *spw;
|
||||
int is_shadow = 0;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Get my name so that I can use it to report errors.
|
||||
@@ -180,11 +170,7 @@ int main (int argc, char **argv)
|
||||
* Make certain we have the right number of arguments
|
||||
*/
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
if (optind != argc && optind + 1 != argc && optind + 2 != argc)
|
||||
#else
|
||||
if (optind != argc && optind + 1 != argc)
|
||||
#endif
|
||||
usage ();
|
||||
|
||||
/*
|
||||
@@ -196,14 +182,12 @@ int main (int argc, char **argv)
|
||||
pwd_file = argv[optind];
|
||||
pw_name (pwd_file);
|
||||
}
|
||||
#ifdef SHADOWPWD
|
||||
if (optind + 2 == argc) {
|
||||
spw_file = argv[optind + 1];
|
||||
spw_name (spw_file);
|
||||
is_shadow = 1;
|
||||
} else if (optind == argc)
|
||||
is_shadow = spw_file_present ();
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Lock the files if we aren't in "read-only" mode
|
||||
@@ -218,7 +202,6 @@ int main (int argc, char **argv)
|
||||
closelog ();
|
||||
exit (E_CANTLOCK);
|
||||
}
|
||||
#ifdef SHADOWPWD
|
||||
if (is_shadow && !spw_lock ()) {
|
||||
fprintf (stderr, _("%s: cannot lock file %s\n"),
|
||||
Prog, spw_file);
|
||||
@@ -227,7 +210,6 @@ int main (int argc, char **argv)
|
||||
closelog ();
|
||||
exit (E_CANTLOCK);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -243,7 +225,6 @@ int main (int argc, char **argv)
|
||||
closelog ();
|
||||
exit (E_CANTOPEN);
|
||||
}
|
||||
#ifdef SHADOWPWD
|
||||
if (is_shadow && !spw_open (read_only ? O_RDONLY : O_RDWR)) {
|
||||
fprintf (stderr, _("%s: cannot open file %s\n"),
|
||||
Prog, spw_file);
|
||||
@@ -252,14 +233,11 @@ int main (int argc, char **argv)
|
||||
closelog ();
|
||||
exit (E_CANTOPEN);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (sort_mode) {
|
||||
pw_sort ();
|
||||
#ifdef SHADOWPWD
|
||||
if (is_shadow)
|
||||
spw_sort ();
|
||||
#endif
|
||||
goto write_and_bye;
|
||||
}
|
||||
|
||||
@@ -419,7 +397,6 @@ int main (int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
if (!is_shadow)
|
||||
goto shadow_done;
|
||||
|
||||
@@ -560,7 +537,6 @@ int main (int argc, char **argv)
|
||||
}
|
||||
|
||||
shadow_done:
|
||||
#endif
|
||||
|
||||
/*
|
||||
* All done. If there were no deletions we can just abandon any
|
||||
@@ -576,7 +552,6 @@ int main (int argc, char **argv)
|
||||
closelog ();
|
||||
exit (E_CANTUPDATE);
|
||||
}
|
||||
#ifdef SHADOWPWD
|
||||
if (is_shadow && !spw_close ()) {
|
||||
fprintf (stderr, _("%s: cannot update file %s\n"),
|
||||
Prog, spw_file);
|
||||
@@ -584,17 +559,14 @@ int main (int argc, char **argv)
|
||||
closelog ();
|
||||
exit (E_CANTUPDATE);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Don't be anti-social - unlock the files when you're done.
|
||||
*/
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
if (is_shadow)
|
||||
spw_unlock ();
|
||||
#endif
|
||||
(void) pw_unlock ();
|
||||
|
||||
/*
|
||||
|
||||
12
src/pwconv.c
12
src/pwconv.c
@@ -29,7 +29,7 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID (PKG_VER "$Id: pwconv.c,v 1.16 2005/03/31 05:14:54 kloczek Exp $")
|
||||
RCSID (PKG_VER "$Id: pwconv.c,v 1.17 2005/05/25 18:20:25 kloczek Exp $")
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -43,7 +43,6 @@ RCSID (PKG_VER "$Id: pwconv.c,v 1.16 2005/03/31 05:14:54 kloczek Exp $")
|
||||
#include "pwio.h"
|
||||
#include "shadowio.h"
|
||||
#include "getdef.h"
|
||||
#ifdef SHADOWPWD
|
||||
/*
|
||||
* exit status values
|
||||
*/
|
||||
@@ -179,12 +178,3 @@ int main (int argc, char **argv)
|
||||
pw_unlock ();
|
||||
exit (E_SUCCESS);
|
||||
}
|
||||
|
||||
#else /* !SHADOWPWD */
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
fprintf (stderr,
|
||||
"%s: not configured for shadow password support.\n", argv[0]);
|
||||
exit (1);
|
||||
}
|
||||
#endif /* !SHADOWPWD */
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID (PKG_VER "$Id: pwunconv.c,v 1.16 2005/03/31 05:14:54 kloczek Exp $")
|
||||
RCSID (PKG_VER "$Id: pwunconv.c,v 1.17 2005/05/25 18:20:25 kloczek Exp $")
|
||||
#include "defines.h"
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
@@ -41,7 +41,6 @@ RCSID (PKG_VER "$Id: pwunconv.c,v 1.16 2005/03/31 05:14:54 kloczek Exp $")
|
||||
#include "pwio.h"
|
||||
#include "shadowio.h"
|
||||
#include "nscd.h"
|
||||
#ifdef SHADOWPWD
|
||||
char *l64a ();
|
||||
|
||||
static int shadow_locked = 0, passwd_locked = 0;
|
||||
@@ -148,18 +147,7 @@ int main (int argc, char **argv)
|
||||
pw_unlock ();
|
||||
|
||||
nscd_flush_cache ("passwd");
|
||||
#ifdef SHADOWPWD
|
||||
nscd_flush_cache ("shadow");
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else /* !SHADOWPWD */
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
fprintf (stderr,
|
||||
"%s: not configured for shadow password support.\n", argv[0]);
|
||||
exit (1);
|
||||
}
|
||||
#endif /* !SHADOWPWD */
|
||||
|
||||
21
src/su.c
21
src/su.c
@@ -30,7 +30,7 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID (PKG_VER "$Id: su.c,v 1.30 2005/04/02 14:09:48 kloczek Exp $")
|
||||
RCSID (PKG_VER "$Id: su.c,v 1.34 2005/06/20 10:17:08 kloczek Exp $")
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#ifdef USE_PAM
|
||||
@@ -125,7 +125,7 @@ static void su_failure (const char *tty)
|
||||
#ifdef USE_SYSLOG
|
||||
if (getdef_bool ("SYSLOG_SU_ENAB"))
|
||||
SYSLOG ((pwent.pw_uid ? LOG_INFO : LOG_NOTICE,
|
||||
"- %s %s-%s", tty,
|
||||
"- %s %s:%s", tty,
|
||||
oldname[0] ? oldname : "???", name[0] ? name : "???"));
|
||||
closelog ();
|
||||
#endif
|
||||
@@ -270,9 +270,8 @@ int main (int argc, char **argv)
|
||||
RETSIGTYPE (*oldsig) ();
|
||||
int is_console = 0;
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
struct spwd *spwd = 0;
|
||||
#endif
|
||||
|
||||
#ifdef SU_ACCESS
|
||||
char *oldpass;
|
||||
#endif
|
||||
@@ -405,10 +404,8 @@ int main (int argc, char **argv)
|
||||
* Sort out the password of user calling su, in case needed later
|
||||
* -- chris
|
||||
*/
|
||||
#ifdef SHADOWPWD
|
||||
if ((spwd = getspnam (oldname)))
|
||||
pw->pw_passwd = spwd->sp_pwdp;
|
||||
#endif
|
||||
oldpass = xstrdup (pw->pw_passwd);
|
||||
#endif /* SU_ACCESS */
|
||||
|
||||
@@ -449,12 +446,10 @@ int main (int argc, char **argv)
|
||||
exit (1);
|
||||
}
|
||||
#ifndef USE_PAM
|
||||
#ifdef SHADOWPWD
|
||||
spwd = NULL;
|
||||
if (strcmp (pw->pw_passwd, SHADOW_PASSWD_STRING) == 0
|
||||
&& (spwd = getspnam (name)))
|
||||
pw->pw_passwd = spwd->sp_pwdp;
|
||||
#endif
|
||||
#endif /* !USE_PAM */
|
||||
pwent = *pw;
|
||||
|
||||
@@ -466,7 +461,7 @@ int main (int argc, char **argv)
|
||||
|
||||
/* The original Shadow 3.3.2 did this differently. Do it like BSD:
|
||||
*
|
||||
* - check for uid 0 instead of name "root" - there are systems with
|
||||
* - check for UID 0 instead of name "root" - there are systems with
|
||||
* several root accounts under different names,
|
||||
*
|
||||
* - check the contents of /etc/group instead of the current group
|
||||
@@ -563,7 +558,6 @@ int main (int argc, char **argv)
|
||||
*/
|
||||
|
||||
if (!amroot) {
|
||||
#ifdef SHADOWPWD
|
||||
if (!spwd)
|
||||
spwd = pwd_to_spwd (&pwent);
|
||||
|
||||
@@ -572,7 +566,6 @@ int main (int argc, char **argv)
|
||||
"Expired account %s", name));
|
||||
su_failure (tty);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -616,20 +609,16 @@ int main (int argc, char **argv)
|
||||
pwent.pw_shell++; /* skip the '*' */
|
||||
subsystem (&pwent); /* figure out what to execute */
|
||||
endpwent ();
|
||||
#ifdef SHADOWPWD
|
||||
endspent ();
|
||||
#endif
|
||||
goto top;
|
||||
}
|
||||
|
||||
sulog (tty, 1, oldname, name); /* save SU information */
|
||||
endpwent ();
|
||||
#ifdef SHADOWPWD
|
||||
endspent ();
|
||||
#endif
|
||||
#ifdef USE_SYSLOG
|
||||
if (getdef_bool ("SYSLOG_SU_ENAB"))
|
||||
SYSLOG ((LOG_INFO, "+ %s %s-%s", tty,
|
||||
SYSLOG ((LOG_INFO, "+ %s %s:%s", tty,
|
||||
oldname[0] ? oldname : "???", name[0] ? name : "???"));
|
||||
#endif
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID (PKG_VER "$Id: useradd.c,v 1.55 2005/04/17 00:15:55 kloczek Exp $")
|
||||
RCSID (PKG_VER "$Id: useradd.c,v 1.59 2005/06/20 10:17:09 kloczek Exp $")
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
#include "chkname.h"
|
||||
@@ -75,10 +75,8 @@ static const char *def_shell = "";
|
||||
static const char *def_template = SKEL_DIR;
|
||||
static const char *def_create_mail_spool = "no";
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
static long def_inactive = -1;
|
||||
static const char *def_expire = "";
|
||||
#endif
|
||||
|
||||
static char def_file[] = USER_DEFAULTS_FILE;
|
||||
|
||||
@@ -93,10 +91,9 @@ static const char *user_home = "";
|
||||
static const char *user_shell = "";
|
||||
static const char *create_mail_spool = "";
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
static long user_expire = -1;
|
||||
static int is_shadow_pwd;
|
||||
#endif
|
||||
|
||||
#ifdef SHADOWGRP
|
||||
static int is_shadow_grp;
|
||||
#endif
|
||||
@@ -134,11 +131,7 @@ static int home_added;
|
||||
#endif
|
||||
|
||||
#include "pwio.h"
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
#include "shadowio.h"
|
||||
#endif
|
||||
|
||||
#include "getdef.h"
|
||||
|
||||
/*
|
||||
@@ -148,7 +141,7 @@ static int home_added;
|
||||
#define E_PW_UPDATE 1 /* can't update password file */
|
||||
#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_UID_IN_USE 4 /* UID already in use (and no -o) */
|
||||
#define E_NOTFOUND 6 /* specified group doesn't exist */
|
||||
#define E_NAME_IN_USE 9 /* username already in use */
|
||||
#define E_GRP_UPDATE 10 /* can't update group file */
|
||||
@@ -175,10 +168,8 @@ static int get_groups (char *);
|
||||
static void usage (void);
|
||||
static void new_pwent (struct passwd *);
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
static long scale_age (long);
|
||||
static void new_spent (struct spwd *);
|
||||
#endif
|
||||
static void grp_update (void);
|
||||
static void find_new_uid (void);
|
||||
|
||||
@@ -211,7 +202,7 @@ static struct group *getgr_nam_gid (const char *name)
|
||||
char *ep;
|
||||
|
||||
gid = strtoul (name, &ep, 10);
|
||||
if (*name != '\0' && *ep == '\0') /* valid numeric gid */
|
||||
if (*name != '\0' && *ep == '\0') /* valid numeric GID */
|
||||
return getgrgid (gid);
|
||||
|
||||
return getgrnam (name);
|
||||
@@ -295,7 +286,7 @@ static void get_defaults (void)
|
||||
def_gname = xstrdup (grp->gr_name);
|
||||
} else {
|
||||
fprintf (stderr,
|
||||
_("%s: unknown gid %s\n"),
|
||||
_("%s: unknown GID %s\n"),
|
||||
Prog, cp);
|
||||
}
|
||||
} else if ((grp = getgrnam (cp))) {
|
||||
@@ -320,7 +311,6 @@ static void get_defaults (void)
|
||||
else if (MATCH (buf, SHELL)) {
|
||||
def_shell = xstrdup (cp);
|
||||
}
|
||||
#ifdef SHADOWPWD
|
||||
|
||||
/*
|
||||
* Default Password Inactive value
|
||||
@@ -340,7 +330,6 @@ static void get_defaults (void)
|
||||
else if (MATCH (buf, EXPIRE)) {
|
||||
def_expire = xstrdup (cp);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Default Skeleton information
|
||||
@@ -376,10 +365,8 @@ static void show_defaults (void)
|
||||
{
|
||||
printf ("GROUP=%u\n", (unsigned int) def_group);
|
||||
printf ("HOME=%s\n", def_home);
|
||||
#ifdef SHADOWPWD
|
||||
printf ("INACTIVE=%ld\n", def_inactive);
|
||||
printf ("EXPIRE=%s\n", def_expire);
|
||||
#endif
|
||||
printf ("SHELL=%s\n", def_shell);
|
||||
printf ("SKEL=%s\n", def_template);
|
||||
printf ("CREATE_MAIL_SPOOL=%s\n", def_create_mail_spool);
|
||||
@@ -446,14 +433,12 @@ static int set_defaults (void)
|
||||
} else if (!out_home && MATCH (buf, HOME)) {
|
||||
fprintf (ofp, HOME "%s\n", def_home);
|
||||
out_home++;
|
||||
#ifdef SHADOWPWD
|
||||
} else if (!out_inactive && MATCH (buf, INACT)) {
|
||||
fprintf (ofp, INACT "%ld\n", def_inactive);
|
||||
out_inactive++;
|
||||
} else if (!out_expire && MATCH (buf, EXPIRE)) {
|
||||
fprintf (ofp, EXPIRE "%s\n", def_expire);
|
||||
out_expire++;
|
||||
#endif
|
||||
} else if (!out_shell && MATCH (buf, SHELL)) {
|
||||
fprintf (ofp, SHELL "%s\n", def_shell);
|
||||
out_shell++;
|
||||
@@ -481,12 +466,10 @@ static int set_defaults (void)
|
||||
fprintf (ofp, DGROUP "%u\n", (unsigned int) def_group);
|
||||
if (!out_home)
|
||||
fprintf (ofp, HOME "%s\n", def_home);
|
||||
#ifdef SHADOWPWD
|
||||
if (!out_inactive)
|
||||
fprintf (ofp, INACT "%ld\n", def_inactive);
|
||||
if (!out_expire)
|
||||
fprintf (ofp, EXPIRE "%s\n", def_expire);
|
||||
#endif
|
||||
if (!out_shell)
|
||||
fprintf (ofp, SHELL "%s\n", def_shell);
|
||||
if (!out_skel)
|
||||
@@ -527,20 +510,12 @@ static int set_defaults (void)
|
||||
perror (buf);
|
||||
return -1;
|
||||
}
|
||||
#ifdef SHADOWPWD
|
||||
SYSLOG ((LOG_INFO,
|
||||
"useradd defaults: GROUP=%u, HOME=%s, SHELL=%s, INACTIVE=%ld, "
|
||||
"EXPIRE=%s, SKEL=%s, CREATE_MAIL_SPOOL=%s",
|
||||
(unsigned int) def_group, def_home, def_shell,
|
||||
def_inactive, def_expire, def_template,
|
||||
def_create_mail_spool));
|
||||
#else
|
||||
SYSLOG ((LOG_INFO,
|
||||
"useradd defaults: GROUP=%u, HOME=%s, SHELL=%s, "
|
||||
"SKEL=%s, CREATE_MAIL_SPOOL=%s",
|
||||
(unsigned int) def_group, def_home, def_shell,
|
||||
def_template, def_create_mail_spool));
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -661,16 +636,11 @@ static void usage (void)
|
||||
fprintf (stderr,
|
||||
_
|
||||
(" [-d home] [-s shell] [-c comment] [-m [-k template]]\n"));
|
||||
#ifdef SHADOWPWD
|
||||
fprintf (stderr, _(" [-f inactive] [-e expire]\n"));
|
||||
#endif
|
||||
fprintf (stderr, _(" [-p passwd] name\n"));
|
||||
fprintf (stderr,
|
||||
_(" useradd -D [-g group] [-b base] [-s shell]\n"));
|
||||
#ifdef SHADOWPWD
|
||||
fprintf (stderr, _(" [-f inactive] [-e expire]\n"));
|
||||
#endif
|
||||
|
||||
exit (E_USAGE);
|
||||
}
|
||||
|
||||
@@ -685,11 +655,9 @@ static void new_pwent (struct passwd *pwent)
|
||||
{
|
||||
memzero (pwent, sizeof *pwent);
|
||||
pwent->pw_name = (char *) user_name;
|
||||
#ifdef SHADOWPWD
|
||||
if (is_shadow_pwd)
|
||||
pwent->pw_passwd = (char *) SHADOW_PASSWD_STRING;
|
||||
else
|
||||
#endif
|
||||
pwent->pw_passwd = (char *) user_pass;
|
||||
|
||||
pwent->pw_uid = user_id;
|
||||
@@ -699,7 +667,6 @@ static void new_pwent (struct passwd *pwent)
|
||||
pwent->pw_shell = (char *) user_shell;
|
||||
}
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
static long scale_age (long x)
|
||||
{
|
||||
if (x <= 0)
|
||||
@@ -728,7 +695,6 @@ static void new_spent (struct spwd *spent)
|
||||
spent->sp_expire = scale_age (user_expire);
|
||||
spent->sp_flag = -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* grp_update - add user to secondary group set
|
||||
@@ -906,7 +872,7 @@ static void find_new_uid (void)
|
||||
exit (E_NAME_IN_USE);
|
||||
}
|
||||
if (uflg && user_id == pwd->pw_uid) {
|
||||
fprintf (stderr, _("%s: uid %u is not unique\n"),
|
||||
fprintf (stderr, _("%s: UID %u is not unique\n"),
|
||||
Prog, (unsigned int) user_id);
|
||||
exit (E_UID_IN_USE);
|
||||
}
|
||||
@@ -917,10 +883,10 @@ static void find_new_uid (void)
|
||||
}
|
||||
}
|
||||
/*
|
||||
* If a user with uid equal to UID_MAX exists, the above algorithm
|
||||
* If a user with UID equal to UID_MAX exists, the above algorithm
|
||||
* will give us UID_MAX+1 even if not unique. Search for the first
|
||||
* free uid starting with UID_MIN (it's O(n*n) but can be avoided
|
||||
* by not having users with uid equal to UID_MAX). --marekm
|
||||
* free UID starting with UID_MIN (it's O(n*n) but can be avoided
|
||||
* by not having users with UID equal to UID_MAX). --marekm
|
||||
*/
|
||||
if (!uflg && user_id == uid_max + 1) {
|
||||
for (user_id = uid_min; user_id < uid_max; user_id++) {
|
||||
@@ -936,7 +902,7 @@ static void find_new_uid (void)
|
||||
#endif
|
||||
}
|
||||
if (user_id == uid_max) {
|
||||
fprintf (stderr, _("%s: can't get unique uid\n"), Prog);
|
||||
fprintf (stderr, _("%s: can't get unique UID\n"), Prog);
|
||||
fail_exit (E_UID_IN_USE);
|
||||
}
|
||||
}
|
||||
@@ -957,13 +923,8 @@ static void process_flags (int argc, char **argv)
|
||||
int arg;
|
||||
char *cp;
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
#define FLAGS "A:Du:og:G:d:s:c:mk:p:f:e:b:O:M"
|
||||
#else
|
||||
#define FLAGS "A:Du:og:G:d:s:c:mk:p:b:O:M"
|
||||
#endif
|
||||
while ((arg = getopt (argc, argv, FLAGS)) != EOF) {
|
||||
#undef FLAGS
|
||||
while ((arg =
|
||||
getopt (argc, argv, "A:Du:og:G:d:s:c:mk:p:f:e:b:O:M")) != EOF) {
|
||||
switch (arg) {
|
||||
case 'b':
|
||||
if (!Dflg)
|
||||
@@ -1005,7 +966,6 @@ static void process_flags (int argc, char **argv)
|
||||
usage ();
|
||||
Dflg++;
|
||||
break;
|
||||
#ifdef SHADOWPWD
|
||||
case 'e':
|
||||
if (*optarg) {
|
||||
user_expire = strtoday (optarg);
|
||||
@@ -1047,7 +1007,6 @@ static void process_flags (int argc, char **argv)
|
||||
}
|
||||
fflg++;
|
||||
break;
|
||||
#endif
|
||||
case 'g':
|
||||
grp = getgr_nam_gid (optarg);
|
||||
if (!grp) {
|
||||
@@ -1174,10 +1133,8 @@ static void process_flags (int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
if (!eflg)
|
||||
user_expire = strtoday (def_expire);
|
||||
#endif
|
||||
|
||||
if (!gflg)
|
||||
user_gid = def_group;
|
||||
@@ -1199,13 +1156,11 @@ static void close_files (void)
|
||||
fprintf (stderr, _("%s: cannot rewrite password file\n"), Prog);
|
||||
fail_exit (E_PW_UPDATE);
|
||||
}
|
||||
#ifdef SHADOWPWD
|
||||
if (is_shadow_pwd && !spw_close ()) {
|
||||
fprintf (stderr,
|
||||
_("%s: cannot rewrite shadow password file\n"), Prog);
|
||||
fail_exit (E_PW_UPDATE);
|
||||
}
|
||||
#endif
|
||||
if (do_grp_update) {
|
||||
if (!gr_close ()) {
|
||||
fprintf (stderr,
|
||||
@@ -1225,10 +1180,8 @@ static void close_files (void)
|
||||
sgr_unlock ();
|
||||
#endif
|
||||
}
|
||||
#ifdef SHADOWPWD
|
||||
if (is_shadow_pwd)
|
||||
spw_unlock ();
|
||||
#endif
|
||||
pw_unlock ();
|
||||
}
|
||||
|
||||
@@ -1249,7 +1202,6 @@ static void open_files (void)
|
||||
pw_unlock ();
|
||||
exit (E_PW_UPDATE);
|
||||
}
|
||||
#ifdef SHADOWPWD
|
||||
if (is_shadow_pwd && !spw_lock ()) {
|
||||
fprintf (stderr,
|
||||
_("%s: cannot lock shadow password file\n"), Prog);
|
||||
@@ -1263,7 +1215,6 @@ static void open_files (void)
|
||||
pw_unlock ();
|
||||
exit (E_PW_UPDATE);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -1305,10 +1256,7 @@ static void lastlog_reset (uid_t uid)
|
||||
static void usr_update (void)
|
||||
{
|
||||
struct passwd pwent;
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
struct spwd spent;
|
||||
#endif
|
||||
|
||||
if (!oflg)
|
||||
find_new_uid ();
|
||||
@@ -1319,9 +1267,7 @@ static void usr_update (void)
|
||||
*/
|
||||
|
||||
new_pwent (&pwent);
|
||||
#ifdef SHADOWPWD
|
||||
new_spent (&spent);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Create a syslog entry. We need to do this now in case anything
|
||||
@@ -1329,7 +1275,7 @@ static void usr_update (void)
|
||||
*/
|
||||
|
||||
SYSLOG ((LOG_INFO,
|
||||
"new user: name=%s, uid=%u, gid=%u, home=%s, shell=%s",
|
||||
"new user: name=%s, UID=%u, GID=%u, home=%s, shell=%s",
|
||||
user_name, (unsigned int) user_id,
|
||||
(unsigned int) user_gid, user_home, user_shell));
|
||||
|
||||
@@ -1355,7 +1301,6 @@ static void usr_update (void)
|
||||
exit (E_PW_UPDATE);
|
||||
}
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
/*
|
||||
* Put the new (struct spwd) in the table.
|
||||
*/
|
||||
@@ -1366,7 +1311,6 @@ static void usr_update (void)
|
||||
Prog);
|
||||
exit (E_PW_UPDATE);
|
||||
}
|
||||
#endif /* SHADOWPWD */
|
||||
|
||||
/*
|
||||
* Do any group file updates for this user.
|
||||
@@ -1486,9 +1430,7 @@ int main (int argc, char **argv)
|
||||
sys_ngroups = sysconf (_SC_NGROUPS_MAX);
|
||||
user_groups = malloc ((1 + sys_ngroups) * sizeof (char *));
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
is_shadow_pwd = spw_file_present ();
|
||||
#endif
|
||||
#ifdef SHADOWGRP
|
||||
is_shadow_grp = sgr_file_present ();
|
||||
#endif
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID (PKG_VER "$Id: userdel.c,v 1.37 2005/04/06 04:26:06 kloczek Exp $")
|
||||
RCSID (PKG_VER "$Id: userdel.c,v 1.41 2005/06/20 10:17:09 kloczek Exp $")
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
@@ -67,18 +67,14 @@ static int fflg = 0, rflg = 0;
|
||||
|
||||
#include "groupio.h"
|
||||
#include "pwio.h"
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
#include "shadowio.h"
|
||||
#endif
|
||||
|
||||
#ifdef SHADOWGRP
|
||||
#include "sgroupio.h"
|
||||
#endif
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
static int is_shadow_pwd;
|
||||
#endif
|
||||
|
||||
#ifdef SHADOWGRP
|
||||
static int is_shadow_grp;
|
||||
#endif
|
||||
@@ -126,6 +122,7 @@ static void update_groups (void)
|
||||
struct group *ngrp;
|
||||
|
||||
#ifdef SHADOWGRP
|
||||
int deleted_user_group = 0;
|
||||
const struct sgrp *sgrp;
|
||||
struct sgrp *nsgrp;
|
||||
#endif /* SHADOWGRP */
|
||||
@@ -178,6 +175,10 @@ static void update_groups (void)
|
||||
|
||||
gr_remove (grp->gr_name);
|
||||
|
||||
#ifdef SHADOWGRP
|
||||
deleted_user_group = 1;
|
||||
#endif
|
||||
|
||||
SYSLOG ((LOG_INFO, "removed group `%s' owned by `%s'\n",
|
||||
grp->gr_name, user_name));
|
||||
}
|
||||
@@ -222,6 +223,9 @@ static void update_groups (void)
|
||||
SYSLOG ((LOG_INFO, "delete `%s' from shadow group `%s'\n",
|
||||
user_name, nsgrp->sg_name));
|
||||
}
|
||||
|
||||
if (deleted_user_group)
|
||||
sgr_remove (user_name);
|
||||
#endif /* SHADOWGRP */
|
||||
}
|
||||
|
||||
@@ -236,11 +240,9 @@ static void close_files (void)
|
||||
{
|
||||
if (!pw_close ())
|
||||
fprintf (stderr, _("%s: cannot rewrite password file\n"), Prog);
|
||||
#ifdef SHADOWPWD
|
||||
if (is_shadow_pwd && !spw_close ())
|
||||
fprintf (stderr,
|
||||
_("%s: cannot rewrite shadow password file\n"), Prog);
|
||||
#endif
|
||||
if (!gr_close ())
|
||||
fprintf (stderr, _("%s: cannot rewrite group file\n"), Prog);
|
||||
|
||||
@@ -253,10 +255,8 @@ static void close_files (void)
|
||||
if (is_shadow_grp)
|
||||
(void) sgr_unlock ();
|
||||
#endif
|
||||
#ifdef SHADOWPWD
|
||||
if (is_shadow_pwd)
|
||||
(void) spw_unlock ();
|
||||
#endif
|
||||
(void) pw_unlock ();
|
||||
}
|
||||
|
||||
@@ -268,10 +268,8 @@ static void fail_exit (int code)
|
||||
{
|
||||
(void) pw_unlock ();
|
||||
(void) gr_unlock ();
|
||||
#ifdef SHADOWPWD
|
||||
if (is_shadow_pwd)
|
||||
spw_unlock ();
|
||||
#endif
|
||||
#ifdef SHADOWGRP
|
||||
if (is_shadow_grp)
|
||||
sgr_unlock ();
|
||||
@@ -295,7 +293,6 @@ static void open_files (void)
|
||||
fprintf (stderr, _("%s: unable to open password file\n"), Prog);
|
||||
fail_exit (E_PW_UPDATE);
|
||||
}
|
||||
#ifdef SHADOWPWD
|
||||
if (is_shadow_pwd && !spw_lock ()) {
|
||||
fprintf (stderr,
|
||||
_("%s: cannot lock shadow password file\n"), Prog);
|
||||
@@ -306,7 +303,6 @@ static void open_files (void)
|
||||
_("%s: cannot open shadow password file\n"), Prog);
|
||||
fail_exit (E_PW_UPDATE);
|
||||
}
|
||||
#endif
|
||||
if (!gr_lock ()) {
|
||||
fprintf (stderr, _("%s: unable to lock group file\n"), Prog);
|
||||
fail_exit (E_GRP_UPDATE);
|
||||
@@ -341,11 +337,9 @@ static void update_user (void)
|
||||
if (!pw_remove (user_name))
|
||||
fprintf (stderr,
|
||||
_("%s: error deleting password entry\n"), Prog);
|
||||
#ifdef SHADOWPWD
|
||||
if (is_shadow_pwd && !spw_remove (user_name))
|
||||
fprintf (stderr,
|
||||
_("%s: error deleting shadow password entry\n"), Prog);
|
||||
#endif
|
||||
SYSLOG ((LOG_INFO, "delete user `%s'\n", user_name));
|
||||
}
|
||||
|
||||
@@ -354,7 +348,7 @@ static void update_user (void)
|
||||
*
|
||||
* XXX - should probably check if there are any processes owned
|
||||
* by this user. Also, I think this check should be in usermod
|
||||
* as well (at least when changing username or uid). --marekm
|
||||
* as well (at least when changing username or UID). --marekm
|
||||
*/
|
||||
|
||||
static void user_busy (const char *name, uid_t uid)
|
||||
@@ -577,9 +571,7 @@ int main (int argc, char **argv)
|
||||
|
||||
OPENLOG ("userdel");
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
is_shadow_pwd = spw_file_present ();
|
||||
#endif
|
||||
#ifdef SHADOWGRP
|
||||
is_shadow_grp = sgr_file_present ();
|
||||
#endif
|
||||
@@ -630,9 +622,7 @@ int main (int argc, char **argv)
|
||||
|
||||
nscd_flush_cache ("passwd");
|
||||
nscd_flush_cache ("group");
|
||||
#ifdef SHADOWPWD
|
||||
nscd_flush_cache ("shadow");
|
||||
#endif
|
||||
|
||||
if (rflg)
|
||||
remove_mailbox ();
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID (PKG_VER "$Id: usermod.c,v 1.37 2005/04/17 15:49:01 kloczek Exp $")
|
||||
RCSID (PKG_VER "$Id: usermod.c,v 1.42 2005/06/20 10:17:10 kloczek Exp $")
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
@@ -62,7 +62,7 @@ RCSID (PKG_VER "$Id: usermod.c,v 1.37 2005/04/17 15:49:01 kloczek Exp $")
|
||||
#define E_PW_UPDATE 1 /* can't update password file */
|
||||
#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_UID_IN_USE 4 /* UID already in use (and no -o) */
|
||||
/* #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 */
|
||||
@@ -83,10 +83,8 @@ static char *user_home;
|
||||
static char *user_newhome;
|
||||
static char *user_shell;
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
static long user_expire;
|
||||
static long user_inactive;
|
||||
#endif
|
||||
static long sys_ngroups;
|
||||
static char **user_groups; /* NULL-terminated list */
|
||||
|
||||
@@ -101,18 +99,15 @@ static int
|
||||
sflg = 0, /* new shell program */
|
||||
cflg = 0, /* new comment (GECOS) field */
|
||||
mflg = 0, /* create user's home directory if it doesn't exist */
|
||||
#ifdef SHADOWPWD
|
||||
fflg = 0, /* days until account with expired password is locked */
|
||||
eflg = 0, /* days since 1970-01-01 when account becomes expired */
|
||||
#endif
|
||||
Lflg = 0, /* lock the password */
|
||||
Uflg = 0, /* unlock the password */
|
||||
pflg = 0, /* new encrypted password */
|
||||
lflg = 0; /* new user name */
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
static int is_shadow_pwd;
|
||||
#endif
|
||||
|
||||
#ifdef SHADOWGRP
|
||||
static int is_shadow_grp;
|
||||
#endif
|
||||
@@ -124,19 +119,14 @@ static int is_shadow_grp;
|
||||
#endif
|
||||
|
||||
#include "pwio.h"
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
#include "shadowio.h"
|
||||
#endif
|
||||
|
||||
/* local function prototypes */
|
||||
static int get_groups (char *);
|
||||
static void usage (void);
|
||||
static void new_pwent (struct passwd *);
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
static void new_spent (struct spwd *);
|
||||
#endif
|
||||
static void fail_exit (int);
|
||||
static int update_group (void);
|
||||
|
||||
@@ -169,7 +159,7 @@ static struct group *getgr_nam_gid (const char *name)
|
||||
char *ep;
|
||||
|
||||
gid = strtoul (name, &ep, 10);
|
||||
if (*name != '\0' && *ep == '\0') /* valid numeric gid */
|
||||
if (*name != '\0' && *ep == '\0') /* valid numeric GID */
|
||||
return getgrgid (gid);
|
||||
|
||||
return getgrnam (name);
|
||||
@@ -292,9 +282,7 @@ static void usage (void)
|
||||
_
|
||||
("\t\t[-d home [-m]] [-s shell] [-c comment] [-l new_name]\n"));
|
||||
fprintf (stderr, "\t\t");
|
||||
#ifdef SHADOWPWD
|
||||
fprintf (stderr, _("[-f inactive] [-e expire] "));
|
||||
#endif
|
||||
fprintf (stderr, _("[-p passwd] [-L|-U] name\n"));
|
||||
exit (E_USAGE);
|
||||
}
|
||||
@@ -343,9 +331,7 @@ static void new_pwent (struct passwd *pwent)
|
||||
pwent->pw_name, user_newname));
|
||||
pwent->pw_name = xstrdup (user_newname);
|
||||
}
|
||||
#ifdef SHADOWPWD
|
||||
if (!is_shadow_pwd)
|
||||
#endif
|
||||
pwent->pw_passwd =
|
||||
new_pw_passwd (pwent->pw_passwd, pwent->pw_name);
|
||||
|
||||
@@ -378,7 +364,6 @@ static void new_pwent (struct passwd *pwent)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
/*
|
||||
* new_spent - initialize the values in a shadow password file entry
|
||||
*
|
||||
@@ -406,7 +391,6 @@ static void new_spent (struct spwd *spent)
|
||||
}
|
||||
spent->sp_pwdp = new_pw_passwd (spent->sp_pwdp, spent->sp_namp);
|
||||
}
|
||||
#endif /* SHADOWPWD */
|
||||
|
||||
/*
|
||||
* fail_exit - exit with an error code after unlocking files
|
||||
@@ -419,10 +403,8 @@ static void fail_exit (int code)
|
||||
if (is_shadow_grp)
|
||||
sgr_unlock ();
|
||||
#endif
|
||||
#ifdef SHADOWPWD
|
||||
if (is_shadow_pwd)
|
||||
spw_unlock ();
|
||||
#endif
|
||||
(void) pw_unlock ();
|
||||
exit (code);
|
||||
}
|
||||
@@ -709,9 +691,7 @@ static void process_flags (int argc, char **argv)
|
||||
const struct group *grp;
|
||||
const struct passwd *pwd;
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
const struct spwd *spwd = NULL;
|
||||
#endif
|
||||
int anyflag = 0;
|
||||
int arg;
|
||||
|
||||
@@ -752,19 +732,12 @@ static void process_flags (int argc, char **argv)
|
||||
user_home = xstrdup (pwd->pw_dir);
|
||||
user_shell = xstrdup (pwd->pw_shell);
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
if (is_shadow_pwd && (spwd = getspnam (user_name))) {
|
||||
user_expire = spwd->sp_expire;
|
||||
user_inactive = spwd->sp_inact;
|
||||
}
|
||||
#endif
|
||||
#ifdef SHADOWPWD
|
||||
#define FLAGS "A:u:og:G:d:s:c:mf:e:l:p:LU"
|
||||
#else
|
||||
#define FLAGS "A:u:og:G:d:s:c:ml:p:LU"
|
||||
#endif
|
||||
while ((arg = getopt (argc, argv, FLAGS)) != EOF) {
|
||||
#undef FLAGS
|
||||
|
||||
while ((arg = getopt (argc, argv, "A:u:og:G:d:s:c:mf:e:l:p:LU")) != EOF) {
|
||||
switch (arg) {
|
||||
case 'c':
|
||||
if (!VALID (optarg)) {
|
||||
@@ -786,7 +759,6 @@ static void process_flags (int argc, char **argv)
|
||||
dflg++;
|
||||
user_newhome = optarg;
|
||||
break;
|
||||
#ifdef SHADOWPWD
|
||||
case 'e':
|
||||
if (*optarg) {
|
||||
user_expire = strtoday (optarg);
|
||||
@@ -806,7 +778,6 @@ static void process_flags (int argc, char **argv)
|
||||
user_inactive = get_number (optarg);
|
||||
fflg++;
|
||||
break;
|
||||
#endif
|
||||
case 'g':
|
||||
grp = getgr_nam_gid (optarg);
|
||||
if (!grp) {
|
||||
@@ -896,7 +867,6 @@ static void process_flags (int argc, char **argv)
|
||||
fprintf (stderr, _("%s: no flags given\n"), Prog);
|
||||
exit (E_USAGE);
|
||||
}
|
||||
#ifdef SHADOWPWD
|
||||
if (!is_shadow_pwd && (eflg || fflg)) {
|
||||
fprintf (stderr,
|
||||
_
|
||||
@@ -904,7 +874,6 @@ static void process_flags (int argc, char **argv)
|
||||
Prog);
|
||||
exit (E_USAGE);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (optind != argc - 1)
|
||||
usage ();
|
||||
@@ -940,17 +909,13 @@ static void close_files (void)
|
||||
fprintf (stderr, _("%s: cannot rewrite password file\n"), Prog);
|
||||
fail_exit (E_PW_UPDATE);
|
||||
}
|
||||
#ifdef SHADOWPWD
|
||||
if (is_shadow_pwd && !spw_close ()) {
|
||||
fprintf (stderr,
|
||||
_("%s: cannot rewrite shadow password file\n"), Prog);
|
||||
fail_exit (E_PW_UPDATE);
|
||||
}
|
||||
#endif
|
||||
#ifdef SHADOWPWD
|
||||
if (is_shadow_pwd)
|
||||
spw_unlock ();
|
||||
#endif
|
||||
(void) pw_unlock ();
|
||||
|
||||
/*
|
||||
@@ -958,9 +923,7 @@ static void close_files (void)
|
||||
*/
|
||||
|
||||
endpwent ();
|
||||
#ifdef SHADOWPWD
|
||||
endspent ();
|
||||
#endif
|
||||
endgrent ();
|
||||
#ifdef SHADOWGRP
|
||||
endsgent ();
|
||||
@@ -983,7 +946,6 @@ static void open_files (void)
|
||||
fprintf (stderr, _("%s: unable to open password file\n"), Prog);
|
||||
fail_exit (E_PW_UPDATE);
|
||||
}
|
||||
#ifdef SHADOWPWD
|
||||
if (is_shadow_pwd && !spw_lock ()) {
|
||||
fprintf (stderr,
|
||||
_("%s: cannot lock shadow password file\n"), Prog);
|
||||
@@ -994,7 +956,6 @@ static void open_files (void)
|
||||
_("%s: cannot open shadow password file\n"), Prog);
|
||||
fail_exit (E_PW_UPDATE);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1009,10 +970,8 @@ static void usr_update (void)
|
||||
struct passwd pwent;
|
||||
const struct passwd *pwd;
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
struct spwd spent;
|
||||
const struct spwd *spwd = NULL;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Locate the entry in /etc/passwd, which MUST exist.
|
||||
@@ -1027,7 +986,6 @@ static void usr_update (void)
|
||||
pwent = *pwd;
|
||||
new_pwent (&pwent);
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
|
||||
/*
|
||||
* Locate the entry in /etc/shadow. It doesn't have to exist, and
|
||||
@@ -1038,7 +996,6 @@ static void usr_update (void)
|
||||
spent = *spwd;
|
||||
new_spent (&spent);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (lflg || uflg || gflg || cflg || dflg || sflg || pflg
|
||||
|| Lflg || Uflg) {
|
||||
@@ -1055,7 +1012,6 @@ static void usr_update (void)
|
||||
fail_exit (E_PW_UPDATE);
|
||||
}
|
||||
}
|
||||
#ifdef SHADOWPWD
|
||||
if (spwd && (lflg || eflg || fflg || pflg || Lflg || Uflg)) {
|
||||
if (!spw_update (&spent)) {
|
||||
fprintf (stderr,
|
||||
@@ -1072,7 +1028,6 @@ static void usr_update (void)
|
||||
fail_exit (E_PW_UPDATE);
|
||||
}
|
||||
}
|
||||
#endif /* SHADOWPWD */
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1115,10 +1070,15 @@ static void move_home (void)
|
||||
}
|
||||
if (copy_tree (user_home, user_newhome,
|
||||
uflg ? user_newid : -1,
|
||||
gflg ? user_newgid : -1) ==
|
||||
0 && remove_tree (user_home) == 0
|
||||
&& rmdir (user_home) == 0)
|
||||
gflg ? user_newgid : -1) == 0) {
|
||||
if (remove_tree (user_home) != 0 ||
|
||||
rmdir (user_home) != 0)
|
||||
fprintf (stderr,
|
||||
_
|
||||
("%s: warning: failed to completely remove old home directory %s"),
|
||||
Prog, user_home);
|
||||
return;
|
||||
}
|
||||
|
||||
(void) remove_tree (user_newhome);
|
||||
(void) rmdir (user_newhome);
|
||||
@@ -1275,9 +1235,7 @@ int main (int argc, char **argv)
|
||||
|
||||
OPENLOG ("usermod");
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
is_shadow_pwd = spw_file_present ();
|
||||
#endif
|
||||
#ifdef SHADOWGRP
|
||||
is_shadow_grp = sgr_file_present ();
|
||||
#endif
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID (PKG_VER "$Id: vipw.c,v 1.10 2005/04/13 22:59:18 kloczek Exp $")
|
||||
RCSID (PKG_VER "$Id: vipw.c,v 1.11 2005/05/25 18:20:25 kloczek Exp $")
|
||||
#include "defines.h"
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
@@ -240,11 +240,9 @@ int main (int argc, char **argv)
|
||||
}
|
||||
|
||||
if (do_vipw) {
|
||||
#ifdef SHADOWPWD
|
||||
if (editshadow)
|
||||
vipwedit (SHADOW_FILE, spw_lock, spw_unlock);
|
||||
else
|
||||
#endif
|
||||
vipwedit (PASSWD_FILE, pw_lock, pw_unlock);
|
||||
} else {
|
||||
#ifdef SHADOWGRP
|
||||
@@ -257,8 +255,6 @@ int main (int argc, char **argv)
|
||||
|
||||
nscd_flush_cache ("passwd");
|
||||
nscd_flush_cache ("group");
|
||||
#ifdef SHADOWPWD
|
||||
nscd_flush_cache ("shadow");
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user