[svn-upgrade] Integrating new upstream version, shadow (4.0.7)
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
# Makefile.in generated by automake 1.9.3 from Makefile.am.
|
||||
# Makefile.in generated by automake 1.9.4 from Makefile.am.
|
||||
# @configure_input@
|
||||
|
||||
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
|
||||
|
12
src/chage.c
12
src/chage.c
@ -30,7 +30,7 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID (PKG_VER "$Id: chage.c,v 1.34 2004/10/11 13:42:49 kloczek Exp $")
|
||||
RCSID (PKG_VER "$Id: chage.c,v 1.35 2005/01/17 23:12:04 kloczek Exp $")
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
@ -148,8 +148,8 @@ static int new_fields (void)
|
||||
char buf[200];
|
||||
char *cp;
|
||||
|
||||
printf (_
|
||||
("Enter the new value, or press ENTER for the default\n\n"));
|
||||
printf (_("Enter the new value, or press ENTER for the default\n"));
|
||||
printf("\n");
|
||||
|
||||
snprintf (buf, sizeof buf, "%ld", mindays);
|
||||
change_field (buf, sizeof buf, _("Minimum Password Age"));
|
||||
@ -454,7 +454,7 @@ int main (int argc, char **argv)
|
||||
*/
|
||||
|
||||
if (!amroot && !lflg) {
|
||||
fprintf (stderr, _("%s: permission denied\n"), Prog);
|
||||
fprintf (stderr, _("%s: permission denied.\n"), Prog);
|
||||
closelog ();
|
||||
exit (1);
|
||||
}
|
||||
@ -514,7 +514,7 @@ int main (int argc, char **argv)
|
||||
exit (1);
|
||||
}
|
||||
if (!(pw = pw_locate (argv[optind]))) {
|
||||
fprintf (stderr, _("%s: unknown user: %s\n"), Prog,
|
||||
fprintf (stderr, _("%s: unknown user %s\n"), Prog,
|
||||
argv[optind]);
|
||||
cleanup (1);
|
||||
closelog ();
|
||||
@ -584,7 +584,7 @@ int main (int argc, char **argv)
|
||||
|
||||
if (lflg) {
|
||||
if (!amroot && (ruid != pwent.pw_uid)) {
|
||||
fprintf (stderr, _("%s: permission denied\n"),
|
||||
fprintf (stderr, _("%s: permission denied.\n"),
|
||||
Prog);
|
||||
closelog ();
|
||||
exit (1);
|
||||
|
22
src/chfn.c
22
src/chfn.c
@ -30,7 +30,7 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID (PKG_VER "$Id: chfn.c,v 1.22 2003/06/19 18:11:01 kloczek Exp $")
|
||||
RCSID (PKG_VER "$Id: chfn.c,v 1.23 2005/01/17 23:12:04 kloczek Exp $")
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
@ -147,17 +147,17 @@ static void new_fields (void)
|
||||
if (may_change_field ('r'))
|
||||
change_field (roomno, sizeof roomno, _("Room Number"));
|
||||
else
|
||||
printf (_("\tRoom Number: %s\n"), roomno);
|
||||
printf ("\t%s: %s\n", _("Room Number"), roomno);
|
||||
|
||||
if (may_change_field ('w'))
|
||||
change_field (workph, sizeof workph, _("Work Phone"));
|
||||
else
|
||||
printf (_("\tWork Phone: %s\n"), workph);
|
||||
printf ("\t%s: %s\n", _("Work Phone"), workph);
|
||||
|
||||
if (may_change_field ('h'))
|
||||
change_field (homeph, sizeof homeph, _("Home Phone"));
|
||||
else
|
||||
printf (_("\tHome Phone: %s\n"), homeph);
|
||||
printf ("\t%s: %s\n", _("Home Phone"), homeph);
|
||||
|
||||
if (amroot)
|
||||
change_field (slop, sizeof slop, _("Other"));
|
||||
@ -269,7 +269,7 @@ int main (int argc, char **argv)
|
||||
case 'f':
|
||||
if (!may_change_field ('f')) {
|
||||
fprintf (stderr,
|
||||
_("%s: Permission denied.\n"),
|
||||
_("%s: permission denied.\n"),
|
||||
Prog);
|
||||
exit (1);
|
||||
}
|
||||
@ -279,7 +279,7 @@ int main (int argc, char **argv)
|
||||
case 'r':
|
||||
if (!may_change_field ('r')) {
|
||||
fprintf (stderr,
|
||||
_("%s: Permission denied.\n"),
|
||||
_("%s: permission denied.\n"),
|
||||
Prog);
|
||||
exit (1);
|
||||
}
|
||||
@ -289,7 +289,7 @@ int main (int argc, char **argv)
|
||||
case 'w':
|
||||
if (!may_change_field ('w')) {
|
||||
fprintf (stderr,
|
||||
_("%s: Permission denied.\n"),
|
||||
_("%s: permission denied.\n"),
|
||||
Prog);
|
||||
exit (1);
|
||||
}
|
||||
@ -299,7 +299,7 @@ int main (int argc, char **argv)
|
||||
case 'h':
|
||||
if (!may_change_field ('h')) {
|
||||
fprintf (stderr,
|
||||
_("%s: Permission denied.\n"),
|
||||
_("%s: permission denied.\n"),
|
||||
Prog);
|
||||
exit (1);
|
||||
}
|
||||
@ -309,7 +309,7 @@ int main (int argc, char **argv)
|
||||
case 'o':
|
||||
if (!amroot) {
|
||||
fprintf (stderr,
|
||||
_("%s: Permission denied.\n"),
|
||||
_("%s: permission denied.\n"),
|
||||
Prog);
|
||||
exit (1);
|
||||
}
|
||||
@ -330,7 +330,7 @@ int main (int argc, char **argv)
|
||||
user = argv[optind];
|
||||
pw = getpwnam (user);
|
||||
if (!pw) {
|
||||
fprintf (stderr, _("%s: Unknown user %s\n"), Prog,
|
||||
fprintf (stderr, _("%s: unknown user %s\n"), Prog,
|
||||
user);
|
||||
exit (1);
|
||||
}
|
||||
@ -377,7 +377,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,12 +30,13 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID (PKG_VER "$Id: chpasswd.c,v 1.19 2004/10/11 06:26:40 kloczek Exp $")
|
||||
RCSID (PKG_VER "$Id: chpasswd.c,v 1.22 2004/12/10 00:27:55 kloczek Exp $")
|
||||
#include <stdio.h>
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
#include <pwd.h>
|
||||
#include <fcntl.h>
|
||||
#include <getopt.h>
|
||||
#include "pwio.h"
|
||||
#ifdef SHADOWPWD
|
||||
#include "shadowio.h"
|
||||
@ -48,6 +49,7 @@ RCSID (PKG_VER "$Id: chpasswd.c,v 1.19 2004/10/11 06:26:40 kloczek Exp $")
|
||||
#endif /* USE_PAM */
|
||||
static char *Prog;
|
||||
static int eflg = 0;
|
||||
static int md5flg = 0;
|
||||
|
||||
#ifdef SHADOWPWD
|
||||
static int is_shadow_pwd;
|
||||
@ -64,7 +66,13 @@ static void usage (void);
|
||||
|
||||
static void usage (void)
|
||||
{
|
||||
fprintf (stderr, _("Usage: %s [-e]\n"), Prog);
|
||||
fprintf (stderr, _("Usage: chpasswd [options]\n"
|
||||
"\n"
|
||||
"Options:\n"
|
||||
" -e, --encrypted supplied passwords are encrypted\n"
|
||||
" -h, --help display this help message and exit\n"
|
||||
" -m, --md5 use MD5 encryption instead DES when the supplied\n"
|
||||
" passwords are not encrypted\n"));
|
||||
exit (1);
|
||||
}
|
||||
|
||||
@ -105,11 +113,38 @@ int main (int argc, char **argv)
|
||||
bindtextdomain (PACKAGE, LOCALEDIR);
|
||||
textdomain (PACKAGE);
|
||||
|
||||
/* XXX - use getopt() */
|
||||
if (!(argc == 1 || (argc == 2 && !strcmp(argv[1], "-e"))))
|
||||
usage();
|
||||
if (argc == 2)
|
||||
eflg = 1;
|
||||
{
|
||||
int option_index = 0;
|
||||
int c;
|
||||
static struct option long_options[] = {
|
||||
{"encrypted", no_argument, NULL, 'e'},
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{"md5", no_argument, NULL, 'm'},
|
||||
{NULL, 0, NULL, '\0'}
|
||||
};
|
||||
|
||||
while ((c =
|
||||
getopt_long (argc, argv, "ehm", long_options,
|
||||
&option_index)) != -1) {
|
||||
switch (c) {
|
||||
case 'e':
|
||||
eflg = 1;
|
||||
break;
|
||||
case 'h':
|
||||
usage ();
|
||||
break;
|
||||
case 'm':
|
||||
md5flg = 1;
|
||||
break;
|
||||
case 0:
|
||||
/* long option */
|
||||
break;
|
||||
default:
|
||||
usage ();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_PAM
|
||||
retval = PAM_SUCCESS;
|
||||
@ -220,8 +255,16 @@ int main (int argc, char **argv)
|
||||
continue;
|
||||
}
|
||||
newpwd = cp;
|
||||
if (!eflg)
|
||||
cp = pw_encrypt (newpwd, crypt_make_salt ());
|
||||
if (!eflg) {
|
||||
if (md5flg) {
|
||||
char salt[12] = "$1$";
|
||||
|
||||
strcat (salt, crypt_make_salt ());
|
||||
cp = pw_encrypt (newpwd, salt);
|
||||
} else
|
||||
cp = pw_encrypt (newpwd,
|
||||
crypt_make_salt ());
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the password file entry for this user. The user must
|
||||
|
@ -30,7 +30,7 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID (PKG_VER "$Id: chsh.c,v 1.23 2003/06/19 18:11:01 kloczek Exp $")
|
||||
RCSID (PKG_VER "$Id: chsh.c,v 1.24 2005/01/17 23:12:04 kloczek Exp $")
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
@ -87,7 +87,7 @@ static void usage (void)
|
||||
static void new_fields (void)
|
||||
{
|
||||
printf (_
|
||||
("Enter the new value, or press return for the default\n"));
|
||||
("Enter the new value, or press ENTER for the default\n"));
|
||||
change_field (loginsh, sizeof loginsh, _("Login Shell"));
|
||||
}
|
||||
|
||||
@ -182,7 +182,7 @@ int main (int argc, char **argv)
|
||||
pw = getpwnam (user);
|
||||
if (!pw) {
|
||||
fprintf (stderr,
|
||||
_("%s: Unknown user %s\n"), Prog, user);
|
||||
_("%s: unknown user %s\n"), Prog, user);
|
||||
exit (1);
|
||||
}
|
||||
} else {
|
||||
|
355
src/faillog.c
355
src/faillog.c
@ -30,16 +30,16 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID (PKG_VER "$Id: faillog.c,v 1.12 2003/04/25 22:32:36 kloczek Exp $")
|
||||
RCSID (PKG_VER "$Id: faillog.c,v 1.17 2005/01/02 06:36:48 kloczek Exp $")
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <pwd.h>
|
||||
#include <time.h>
|
||||
#include <getopt.h>
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
#include "faillog.h"
|
||||
static char *Prog; /* program name */
|
||||
static FILE *fail; /* failure file stream */
|
||||
static uid_t user; /* one single user, specified on command line */
|
||||
static int days; /* number of days to consider for print command */
|
||||
@ -47,155 +47,29 @@ static time_t seconds; /* that number of days in seconds */
|
||||
|
||||
static int
|
||||
aflg = 0, /* set if all users are to be printed always */
|
||||
uflg = 0, /* set if user is a valid user id */
|
||||
tflg = 0; /* print is restricted to most recent days */
|
||||
uflg = 0, /* set if user is a valid user id */
|
||||
tflg = 0; /* print is restricted to most recent days */
|
||||
|
||||
static struct stat statbuf; /* fstat buffer for file size */
|
||||
|
||||
#if !defined(UNISTD_H) && !defined(STDLIB_H)
|
||||
extern char *optarg;
|
||||
#endif
|
||||
|
||||
#define NOW (time((time_t *) 0))
|
||||
|
||||
/* local function prototypes */
|
||||
static void usage (void);
|
||||
static void print (void);
|
||||
static void print_one (const struct faillog *, uid_t);
|
||||
static void reset (void);
|
||||
static int reset_one (uid_t);
|
||||
static void setmax (int);
|
||||
static void setmax_one (uid_t, int);
|
||||
static void set_locktime (long);
|
||||
static void set_locktime_one (uid_t, long);
|
||||
|
||||
|
||||
static void usage (void)
|
||||
{
|
||||
fprintf (stderr,
|
||||
_
|
||||
("Usage: %s [-a|-u user] [-m max] [-r] [-t days] [-l locksecs]\n"),
|
||||
Prog);
|
||||
fprintf (stderr, _("Usage: faillog [options]\n"
|
||||
"\n"
|
||||
"Options:\n"
|
||||
" -a, --all display faillog records for all users\n"
|
||||
" -h, --help display this help message and exit\n"
|
||||
" -l, --lock-time SEC after failed login lock accout to SEC seconds\n"
|
||||
" -m, --maximum MAX set maiximum failed login counters to MAX\n"
|
||||
" -r, --reset reset the counters of login failures\n"
|
||||
" -u, --user LOGIN display faillog record or maintains failure counters\n"
|
||||
" and limits (if used with -r, -m or -l options) only\n"
|
||||
" for user with LOGIN\n"));
|
||||
exit (1);
|
||||
}
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
int c, anyflag = 0;
|
||||
struct passwd *pwent;
|
||||
|
||||
Prog = Basename (argv[0]);
|
||||
|
||||
setlocale (LC_ALL, "");
|
||||
bindtextdomain (PACKAGE, LOCALEDIR);
|
||||
textdomain (PACKAGE);
|
||||
|
||||
/* try to open for read/write, if that fails - read only */
|
||||
|
||||
fail = fopen (FAILLOG_FILE, "r+");
|
||||
if (!fail)
|
||||
fail = fopen (FAILLOG_FILE, "r");
|
||||
if (!fail) {
|
||||
perror (FAILLOG_FILE);
|
||||
exit (1);
|
||||
}
|
||||
while ((c = getopt (argc, argv, "al:m:pru:t:")) != EOF) {
|
||||
switch (c) {
|
||||
case 'a':
|
||||
aflg++;
|
||||
if (uflg)
|
||||
usage ();
|
||||
break;
|
||||
case 'l':
|
||||
set_locktime ((long) atoi (optarg));
|
||||
anyflag++;
|
||||
break;
|
||||
case 'm':
|
||||
setmax (atoi (optarg));
|
||||
anyflag++;
|
||||
break;
|
||||
case 'p':
|
||||
print ();
|
||||
anyflag++;
|
||||
break;
|
||||
case 'r':
|
||||
reset ();
|
||||
anyflag++;
|
||||
break;
|
||||
case 'u':
|
||||
if (aflg)
|
||||
usage ();
|
||||
|
||||
pwent = getpwnam (optarg);
|
||||
if (!pwent) {
|
||||
fprintf (stderr, _("Unknown User: %s\n"),
|
||||
optarg);
|
||||
exit (1);
|
||||
}
|
||||
uflg++;
|
||||
user = pwent->pw_uid;
|
||||
break;
|
||||
case 't':
|
||||
days = atoi (optarg);
|
||||
seconds = days * DAY;
|
||||
tflg++;
|
||||
break;
|
||||
default:
|
||||
usage ();
|
||||
}
|
||||
}
|
||||
/* no flags implies -a -p (= print information for all users) */
|
||||
if (!(anyflag || aflg || tflg || uflg))
|
||||
aflg++;
|
||||
/* (-a or -t days or -u user) and no other flags implies -p
|
||||
(= print information for selected users) */
|
||||
if (!anyflag && (aflg || tflg || uflg))
|
||||
print ();
|
||||
fclose (fail);
|
||||
return 0;
|
||||
/*NOTREACHED*/}
|
||||
|
||||
static void print (void)
|
||||
{
|
||||
uid_t uid;
|
||||
off_t offset;
|
||||
struct faillog faillog;
|
||||
|
||||
if (uflg) {
|
||||
offset = user * sizeof faillog;
|
||||
if (fstat (fileno (fail), &statbuf)) {
|
||||
perror (FAILLOG_FILE);
|
||||
return;
|
||||
}
|
||||
if (offset >= statbuf.st_size)
|
||||
return;
|
||||
|
||||
fseek (fail, (off_t) user * sizeof faillog, SEEK_SET);
|
||||
if (fread ((char *) &faillog, sizeof faillog, 1, fail) ==
|
||||
1)
|
||||
print_one (&faillog, user);
|
||||
else
|
||||
perror (FAILLOG_FILE);
|
||||
} else {
|
||||
for (uid = 0;
|
||||
fread ((char *) &faillog, sizeof faillog, 1,
|
||||
fail) == 1; uid++) {
|
||||
|
||||
if (aflg == 0 && faillog.fail_cnt == 0)
|
||||
continue;
|
||||
|
||||
if (aflg == 0 && tflg &&
|
||||
NOW - faillog.fail_time > seconds)
|
||||
continue;
|
||||
|
||||
if (aflg && faillog.fail_time == 0)
|
||||
continue;
|
||||
|
||||
print_one (&faillog, uid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void print_one (const struct faillog *fl, uid_t uid)
|
||||
{
|
||||
static int once;
|
||||
@ -242,16 +116,6 @@ static void print_one (const struct faillog *fl, uid_t uid)
|
||||
}
|
||||
}
|
||||
|
||||
static void reset (void)
|
||||
{
|
||||
uid_t uid;
|
||||
|
||||
if (uflg)
|
||||
reset_one (user);
|
||||
else
|
||||
for (uid = 0; reset_one (uid); uid++);
|
||||
}
|
||||
|
||||
static int reset_one (uid_t uid)
|
||||
{
|
||||
off_t offset;
|
||||
@ -265,7 +129,7 @@ static int reset_one (uid_t uid)
|
||||
if (offset >= statbuf.st_size)
|
||||
return 0;
|
||||
|
||||
if (fseek (fail, offset, SEEK_SET) != 0) {
|
||||
if (fseeko (fail, offset, SEEK_SET) != 0) {
|
||||
perror (FAILLOG_FILE);
|
||||
return 0;
|
||||
}
|
||||
@ -280,7 +144,7 @@ static int reset_one (uid_t uid)
|
||||
|
||||
faillog.fail_cnt = 0;
|
||||
|
||||
if (fseek (fail, offset, SEEK_SET) == 0
|
||||
if (fseeko (fail, offset, SEEK_SET) == 0
|
||||
&& fwrite ((char *) &faillog, sizeof faillog, 1, fail) == 1) {
|
||||
fflush (fail);
|
||||
return 1;
|
||||
@ -290,6 +154,82 @@ static int reset_one (uid_t uid)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void reset (void)
|
||||
{
|
||||
uid_t uid;
|
||||
|
||||
if (uflg)
|
||||
reset_one (user);
|
||||
else
|
||||
for (uid = 0; reset_one (uid); uid++);
|
||||
}
|
||||
|
||||
static void print (void)
|
||||
{
|
||||
uid_t uid;
|
||||
off_t offset;
|
||||
struct faillog faillog;
|
||||
|
||||
if (uflg) {
|
||||
offset = user * sizeof faillog;
|
||||
if (fstat (fileno (fail), &statbuf)) {
|
||||
perror (FAILLOG_FILE);
|
||||
return;
|
||||
}
|
||||
if (offset >= statbuf.st_size)
|
||||
return;
|
||||
|
||||
fseeko (fail, (off_t) user * sizeof faillog, SEEK_SET);
|
||||
if (fread ((char *) &faillog, sizeof faillog, 1, fail) ==
|
||||
1)
|
||||
print_one (&faillog, user);
|
||||
else
|
||||
perror (FAILLOG_FILE);
|
||||
} else {
|
||||
for (uid = 0;
|
||||
fread ((char *) &faillog, sizeof faillog, 1,
|
||||
fail) == 1; uid++) {
|
||||
|
||||
if (aflg == 0 && faillog.fail_cnt == 0)
|
||||
continue;
|
||||
|
||||
if (aflg == 0 && tflg &&
|
||||
NOW - faillog.fail_time > seconds)
|
||||
continue;
|
||||
|
||||
if (aflg && faillog.fail_time == 0)
|
||||
continue;
|
||||
|
||||
print_one (&faillog, uid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void setmax_one (uid_t uid, int max)
|
||||
{
|
||||
off_t offset;
|
||||
struct faillog faillog;
|
||||
|
||||
offset = uid * sizeof faillog;
|
||||
|
||||
if (fseeko (fail, offset, SEEK_SET) != 0) {
|
||||
perror (FAILLOG_FILE);
|
||||
return;
|
||||
}
|
||||
if (fread ((char *) &faillog, sizeof faillog, 1, fail) != 1) {
|
||||
if (!feof (fail))
|
||||
perror (FAILLOG_FILE);
|
||||
memzero (&faillog, sizeof faillog);
|
||||
}
|
||||
faillog.fail_max = max;
|
||||
|
||||
if (fseeko (fail, offset, SEEK_SET) == 0
|
||||
&& fwrite ((char *) &faillog, sizeof faillog, 1, fail) == 1)
|
||||
fflush (fail);
|
||||
else
|
||||
perror (FAILLOG_FILE);
|
||||
}
|
||||
|
||||
static void setmax (int max)
|
||||
{
|
||||
struct passwd *pwent;
|
||||
@ -303,14 +243,14 @@ static void setmax (int max)
|
||||
}
|
||||
}
|
||||
|
||||
static void setmax_one (uid_t uid, int max)
|
||||
static void set_locktime_one (uid_t uid, long locktime)
|
||||
{
|
||||
off_t offset;
|
||||
struct faillog faillog;
|
||||
|
||||
offset = uid * sizeof faillog;
|
||||
|
||||
if (fseek (fail, offset, SEEK_SET) != 0) {
|
||||
if (fseeko (fail, offset, SEEK_SET) != 0) {
|
||||
perror (FAILLOG_FILE);
|
||||
return;
|
||||
}
|
||||
@ -319,9 +259,9 @@ static void setmax_one (uid_t uid, int max)
|
||||
perror (FAILLOG_FILE);
|
||||
memzero (&faillog, sizeof faillog);
|
||||
}
|
||||
faillog.fail_max = max;
|
||||
faillog.fail_locktime = locktime;
|
||||
|
||||
if (fseek (fail, offset, SEEK_SET) == 0
|
||||
if (fseeko (fail, offset, SEEK_SET) == 0
|
||||
&& fwrite ((char *) &faillog, sizeof faillog, 1, fail) == 1)
|
||||
fflush (fail);
|
||||
else
|
||||
@ -345,27 +285,94 @@ static void set_locktime (long locktime)
|
||||
}
|
||||
}
|
||||
|
||||
static void set_locktime_one (uid_t uid, long locktime)
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
off_t offset;
|
||||
struct faillog faillog;
|
||||
int anyflag = 0;
|
||||
struct passwd *pwent;
|
||||
|
||||
offset = uid * sizeof faillog;
|
||||
setlocale (LC_ALL, "");
|
||||
bindtextdomain (PACKAGE, LOCALEDIR);
|
||||
textdomain (PACKAGE);
|
||||
|
||||
if (fseek (fail, offset, SEEK_SET) != 0) {
|
||||
/* try to open for read/write, if that fails - read only */
|
||||
|
||||
fail = fopen (FAILLOG_FILE, "r+");
|
||||
if (!fail)
|
||||
fail = fopen (FAILLOG_FILE, "r");
|
||||
if (!fail) {
|
||||
perror (FAILLOG_FILE);
|
||||
return;
|
||||
exit (1);
|
||||
}
|
||||
if (fread ((char *) &faillog, sizeof faillog, 1, fail) != 1) {
|
||||
if (!feof (fail))
|
||||
perror (FAILLOG_FILE);
|
||||
memzero (&faillog, sizeof faillog);
|
||||
}
|
||||
faillog.fail_locktime = locktime;
|
||||
|
||||
if (fseek (fail, offset, SEEK_SET) == 0
|
||||
&& fwrite ((char *) &faillog, sizeof faillog, 1, fail) == 1)
|
||||
fflush (fail);
|
||||
else
|
||||
perror (FAILLOG_FILE);
|
||||
{
|
||||
int option_index = 0;
|
||||
int c;
|
||||
static struct option long_options[] = {
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{"lock-secs", no_argument, NULL, 'l'},
|
||||
{"maximum", no_argument, NULL, 'm'},
|
||||
{"reset", no_argument, NULL, 'r'},
|
||||
{"user", no_argument, NULL, 'u'},
|
||||
{"", no_argument, NULL, 't'},
|
||||
{NULL, 0, NULL, '\0'}
|
||||
};
|
||||
|
||||
while ((c =
|
||||
getopt_long (argc, argv, "ahl:m:rt:u:",
|
||||
long_options, &option_index)) != -1) {
|
||||
switch (c) {
|
||||
case 'a':
|
||||
aflg++;
|
||||
if (uflg)
|
||||
usage ();
|
||||
break;
|
||||
case 'l':
|
||||
set_locktime ((long) atoi (optarg));
|
||||
anyflag++;
|
||||
break;
|
||||
case 'm':
|
||||
setmax (atoi (optarg));
|
||||
anyflag++;
|
||||
break;
|
||||
case 'p':
|
||||
print ();
|
||||
anyflag++;
|
||||
break;
|
||||
case 'r':
|
||||
reset ();
|
||||
anyflag++;
|
||||
break;
|
||||
case 'u':
|
||||
if (aflg)
|
||||
usage ();
|
||||
|
||||
pwent = getpwnam (optarg);
|
||||
if (!pwent) {
|
||||
fprintf (stderr, _("Unknown User: %s\n"),
|
||||
optarg);
|
||||
exit (1);
|
||||
}
|
||||
uflg++;
|
||||
user = pwent->pw_uid;
|
||||
break;
|
||||
case 't':
|
||||
days = atoi (optarg);
|
||||
seconds = days * DAY;
|
||||
tflg++;
|
||||
break;
|
||||
default:
|
||||
usage ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* no flags implies -a -p (= print information for all users) */
|
||||
if (!(anyflag || aflg || tflg || uflg))
|
||||
aflg++;
|
||||
/* (-a or -t days or -u user) and no other flags implies -p
|
||||
(= print information for selected users) */
|
||||
if (!anyflag && (aflg || tflg || uflg))
|
||||
print ();
|
||||
fclose (fail);
|
||||
return 0;
|
||||
}
|
||||
|
@ -30,7 +30,7 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID (PKG_VER "$Id: gpasswd.c,v 1.21 2003/06/19 18:11:01 kloczek Exp $")
|
||||
RCSID (PKG_VER "$Id: gpasswd.c,v 1.22 2005/01/17 23:12:04 kloczek Exp $")
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <pwd.h>
|
||||
@ -154,7 +154,7 @@ static int check_list (const char *users)
|
||||
|
||||
static void failure (void)
|
||||
{
|
||||
fprintf (stderr, _("Permission denied.\n"));
|
||||
fprintf (stderr, _("%s: permission denied.\n"), Prog);
|
||||
exit (1);
|
||||
/*NOTREACHED*/}
|
||||
|
||||
|
16
src/groups.c
16
src/groups.c
@ -30,12 +30,18 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID (PKG_VER "$Id: groups.c,v 1.8 2002/01/05 15:41:43 kloczek Exp $")
|
||||
RCSID (PKG_VER "$Id: groups.c,v 1.9 2005/01/17 23:12:04 kloczek Exp $")
|
||||
#include <stdio.h>
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
|
||||
/*
|
||||
* Global variables
|
||||
*/
|
||||
static char *Prog;
|
||||
|
||||
/* local function prototypes */
|
||||
static void print_groups (const char *);
|
||||
|
||||
@ -56,7 +62,7 @@ static void print_groups (const char *member)
|
||||
setgrent ();
|
||||
|
||||
if ((pwd = getpwnam (member)) == 0) {
|
||||
fprintf (stderr, _("unknown user %s\n"), member);
|
||||
fprintf (stderr, _("%s: unknown user %s\n"), Prog, member);
|
||||
exit (1);
|
||||
}
|
||||
while ((grp = getgrent ())) {
|
||||
@ -106,6 +112,12 @@ int main (int argc, char **argv)
|
||||
bindtextdomain (PACKAGE, LOCALEDIR);
|
||||
textdomain (PACKAGE);
|
||||
|
||||
/*
|
||||
* Get the program name so that error messages can use it.
|
||||
*/
|
||||
|
||||
Prog = Basename (argv[0]);
|
||||
|
||||
if (argc == 1) {
|
||||
|
||||
/*
|
||||
|
203
src/lastlog.c
203
src/lastlog.c
@ -30,7 +30,7 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID (PKG_VER "$Id: lastlog.c,v 1.13 2003/12/17 12:52:25 kloczek Exp $")
|
||||
RCSID (PKG_VER "$Id: lastlog.c,v 1.15 2004/12/20 02:10:56 kloczek Exp $")
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
@ -43,6 +43,7 @@ RCSID (PKG_VER "$Id: lastlog.c,v 1.13 2003/12/17 12:52:25 kloczek Exp $")
|
||||
#else
|
||||
#include "lastlog_.h"
|
||||
#endif
|
||||
#include <getopt.h>
|
||||
/*
|
||||
* Needed for MkLinux DR1/2/2.1 - J.
|
||||
*/
|
||||
@ -60,106 +61,17 @@ static struct lastlog lastlog; /* scratch structure to play with ... */
|
||||
static struct stat statbuf; /* fstat buffer for file size */
|
||||
static struct passwd *pwent;
|
||||
|
||||
#include <getopt.h>
|
||||
static struct option const longopts[] = {
|
||||
{"user", required_argument, 0, 'u'},
|
||||
{"time", required_argument, 0, 't'},
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
#define NOW (time ((time_t *) 0))
|
||||
|
||||
/* local function prototypes */
|
||||
static void print (void);
|
||||
static void print_one (const struct passwd *);
|
||||
|
||||
int main (int argc, char **argv)
|
||||
static void usage (void)
|
||||
{
|
||||
int c;
|
||||
|
||||
setlocale (LC_ALL, "");
|
||||
bindtextdomain (PACKAGE, LOCALEDIR);
|
||||
textdomain (PACKAGE);
|
||||
|
||||
if ((lastlogfile = fopen (LASTLOG_FILE, "r")) == (FILE *) 0) {
|
||||
perror (LASTLOG_FILE);
|
||||
exit (1);
|
||||
}
|
||||
while ((c =
|
||||
getopt_long (argc, argv, "u:t:h", longopts, NULL)) != -1) {
|
||||
switch (c) {
|
||||
case 'u':
|
||||
pwent = getpwnam (optarg);
|
||||
if (!pwent) {
|
||||
fprintf (stderr,
|
||||
_("Unknown User: %s\n"), optarg);
|
||||
exit (1);
|
||||
}
|
||||
uflg++;
|
||||
user = pwent->pw_uid;
|
||||
break;
|
||||
case 't':
|
||||
days = atoi (optarg);
|
||||
seconds = days * DAY;
|
||||
tflg++;
|
||||
break;
|
||||
case 'h':
|
||||
fprintf (stdout,
|
||||
_
|
||||
("Usage: %s [{-u|--login} login] [{-t|--time} days] [{-h|--help}]\n"),
|
||||
argv[0]);
|
||||
exit (0);
|
||||
default:
|
||||
fprintf (stdout,
|
||||
_
|
||||
("Usage: %s [{-u|--login} login] [{-t|--time} days] [{-h|--help}]\n"),
|
||||
argv[0]);
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
print ();
|
||||
fclose (lastlogfile);
|
||||
exit (0);
|
||||
/*NOTREACHED*/}
|
||||
|
||||
static void print (void)
|
||||
{
|
||||
off_t offset;
|
||||
|
||||
if (uflg) {
|
||||
offset = (unsigned long) user *sizeof lastlog;
|
||||
|
||||
if (fstat (fileno (lastlogfile), &statbuf)) {
|
||||
perror (LASTLOG_FILE);
|
||||
return;
|
||||
}
|
||||
if (offset >= statbuf.st_size)
|
||||
return;
|
||||
|
||||
fseek (lastlogfile, offset, SEEK_SET);
|
||||
if (fread ((char *) &lastlog, sizeof lastlog, 1,
|
||||
lastlogfile) == 1)
|
||||
print_one (pwent);
|
||||
else
|
||||
perror (LASTLOG_FILE);
|
||||
} else {
|
||||
setpwent ();
|
||||
while ((pwent = getpwent ())) {
|
||||
user = pwent->pw_uid;
|
||||
offset = (unsigned long) user *sizeof lastlog;
|
||||
|
||||
fseek (lastlogfile, offset, SEEK_SET);
|
||||
if (fread ((char *) &lastlog, sizeof lastlog, 1,
|
||||
lastlogfile) != 1)
|
||||
continue;
|
||||
|
||||
if (tflg && NOW - lastlog.ll_time > seconds)
|
||||
continue;
|
||||
|
||||
print_one (pwent);
|
||||
}
|
||||
}
|
||||
fprintf (stdout, _("Usage: lastlog [options]\n"
|
||||
"\n"
|
||||
"Options:\n"
|
||||
" -u, --login LOGIN print lastlog record for user with specyfied LOGIN\n"
|
||||
" -h, --help display this help message and exit\n"
|
||||
" -t, --time DAYS print only lastlog records more recent than DAYS\n"));
|
||||
exit (1);
|
||||
}
|
||||
|
||||
static void print_one (const struct passwd *pw)
|
||||
@ -168,6 +80,7 @@ static void print_one (const struct passwd *pw)
|
||||
char *cp;
|
||||
struct tm *tm;
|
||||
time_t ll_time;
|
||||
|
||||
#ifdef HAVE_STRFTIME
|
||||
char ptime[80];
|
||||
#endif
|
||||
@ -204,3 +117,97 @@ static void print_one (const struct passwd *pw)
|
||||
printf ("%-16s\t%-8.8s %s\n", pw->pw_name, lastlog.ll_line, cp);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void print (void)
|
||||
{
|
||||
off_t offset;
|
||||
|
||||
if (uflg) {
|
||||
offset = user * sizeof lastlog;
|
||||
|
||||
if (fstat (fileno (lastlogfile), &statbuf)) {
|
||||
perror (LASTLOG_FILE);
|
||||
return;
|
||||
}
|
||||
if (offset >= statbuf.st_size)
|
||||
return;
|
||||
|
||||
fseeko (lastlogfile, offset, SEEK_SET);
|
||||
if (fread ((char *) &lastlog, sizeof lastlog, 1,
|
||||
lastlogfile) == 1)
|
||||
print_one (pwent);
|
||||
else
|
||||
perror (LASTLOG_FILE);
|
||||
} else {
|
||||
setpwent ();
|
||||
while ((pwent = getpwent ())) {
|
||||
user = pwent->pw_uid;
|
||||
offset = user * sizeof lastlog;
|
||||
|
||||
fseeko (lastlogfile, offset, SEEK_SET);
|
||||
if (fread ((char *) &lastlog, sizeof lastlog, 1,
|
||||
lastlogfile) != 1)
|
||||
continue;
|
||||
|
||||
if (tflg && NOW - lastlog.ll_time > seconds)
|
||||
continue;
|
||||
|
||||
print_one (pwent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
setlocale (LC_ALL, "");
|
||||
bindtextdomain (PACKAGE, LOCALEDIR);
|
||||
textdomain (PACKAGE);
|
||||
|
||||
{
|
||||
int c;
|
||||
static struct option const longopts[] = {
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{"time", required_argument, NULL, 't'},
|
||||
{"user", required_argument, NULL, 'u'},
|
||||
{NULL, 0, NULL, '\0'}
|
||||
};
|
||||
|
||||
while ((c =
|
||||
getopt_long (argc, argv, "ht:u:", longopts,
|
||||
NULL)) != -1) {
|
||||
switch (c) {
|
||||
case 'h':
|
||||
usage ();
|
||||
break;
|
||||
case 't':
|
||||
days = atoi (optarg);
|
||||
seconds = days * DAY;
|
||||
tflg++;
|
||||
break;
|
||||
case 'u':
|
||||
pwent = getpwnam (optarg);
|
||||
if (!pwent) {
|
||||
fprintf (stderr,
|
||||
_("Unknown User: %s\n"),
|
||||
optarg);
|
||||
exit (1);
|
||||
}
|
||||
uflg++;
|
||||
user = pwent->pw_uid;
|
||||
break;
|
||||
default:
|
||||
usage ();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((lastlogfile = fopen (LASTLOG_FILE, "r")) == (FILE *) 0) {
|
||||
perror (LASTLOG_FILE);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
print ();
|
||||
fclose (lastlogfile);
|
||||
exit (0);
|
||||
}
|
||||
|
@ -30,7 +30,7 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID (PKG_VER "$Id: login.c,v 1.37 2004/08/04 10:33:43 kloczek Exp $")
|
||||
RCSID (PKG_VER "$Id: login.c,v 1.38 2005/01/17 23:12:04 kloczek Exp $")
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
#include <sys/stat.h>
|
||||
@ -500,7 +500,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);
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID (PKG_VER "$Id: mkpasswd.c,v 1.10 2004/08/18 09:52:32 kloczek Exp $")
|
||||
RCSID (PKG_VER "$Id: mkpasswd.c,v 1.11 2005/01/17 23:12:05 kloczek Exp $")
|
||||
#include <sys/stat.h>
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
@ -283,9 +283,8 @@ int main (int argc, char **argv)
|
||||
buf[sizeof buf - 1] = '\0';
|
||||
if (!(cp = strchr (buf, '\n'))) {
|
||||
fprintf (stderr,
|
||||
_("%s: the beginning with " %
|
||||
.16 s..." is too long\n"), Progname,
|
||||
buf);
|
||||
_("%s: the line beginning with %.16s... is too long\n"),
|
||||
Progname, buf);
|
||||
exit (1);
|
||||
}
|
||||
*cp = '\0';
|
||||
@ -319,45 +318,45 @@ int main (int argc, char **argv)
|
||||
if (vflg) {
|
||||
if (!sflg && pflg)
|
||||
printf (_
|
||||
("adding record for name " %
|
||||
s "\n"), passwd->pw_name);
|
||||
("adding record for name %s\n"),
|
||||
passwd->pw_name);
|
||||
#ifdef SHADOWPWD
|
||||
if (sflg && pflg)
|
||||
printf (_
|
||||
("adding record for name " %
|
||||
s "\n"), shadow->sp_namp);
|
||||
("adding record for name %s\n"),
|
||||
shadow->sp_namp);
|
||||
#endif
|
||||
if (!sflg && gflg)
|
||||
printf (_
|
||||
("adding record for name " %
|
||||
s "\n"), group->gr_name);
|
||||
("adding record for name %s\n"),
|
||||
group->gr_name);
|
||||
#ifdef SHADOWGRP
|
||||
if (sflg && gflg)
|
||||
printf (_
|
||||
("adding record for name " %
|
||||
s "\n"), gshadow->sg_name);
|
||||
("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);
|
||||
_("%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);
|
||||
_("%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);
|
||||
_("%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);
|
||||
_("%s: error adding record for %s\n"),
|
||||
Progname, gshadow->sg_name);
|
||||
#endif /* SHADOWGRP */
|
||||
|
||||
/*
|
||||
|
@ -30,7 +30,7 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID (PKG_VER "$Id: passwd.c,v 1.30 2003/12/17 09:43:30 kloczek Exp $")
|
||||
RCSID (PKG_VER "$Id: passwd.c,v 1.31 2005/01/17 23:12:05 kloczek Exp $")
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
#include <sys/types.h>
|
||||
@ -850,7 +850,7 @@ int main (int argc, char **argv)
|
||||
if (anyflag || !Sflg || (optind < argc))
|
||||
usage (E_USAGE);
|
||||
if (!amroot) {
|
||||
fprintf (stderr, _("%s: Permission denied.\n"),
|
||||
fprintf (stderr, _("%s: permission denied.\n"),
|
||||
Prog);
|
||||
exit (E_NOPERM);
|
||||
}
|
||||
@ -887,7 +887,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);
|
||||
}
|
||||
#ifdef NDBM
|
||||
@ -900,7 +900,7 @@ int main (int argc, char **argv)
|
||||
|
||||
pw = getpwnam (name);
|
||||
if (!pw) {
|
||||
fprintf (stderr, _("%s: Unknown user %s\n"), Prog, name);
|
||||
fprintf (stderr, _("%s: unknown user %s\n"), Prog, name);
|
||||
exit (E_NOPERM);
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID (PKG_VER "$Id: userdel.c,v 1.31 2004/10/11 06:26:40 kloczek Exp $")
|
||||
RCSID (PKG_VER "$Id: userdel.c,v 1.32 2005/01/17 23:12:05 kloczek Exp $")
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
@ -591,7 +591,7 @@ static void remove_mailbox (void)
|
||||
if (i == 0) {
|
||||
fprintf (stderr,
|
||||
_
|
||||
("%s: warning: %s not owned by %s, not removing\n"),
|
||||
("%s: %s not owned by %s, not removing\n"),
|
||||
Prog, mailfile, user_name);
|
||||
return;
|
||||
} else if (i == -1)
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "rcsid.h"
|
||||
RCSID (PKG_VER "$Id: vipw.c,v 1.7 2004/06/03 00:27:19 kloczek Exp $")
|
||||
RCSID (PKG_VER "$Id: vipw.c,v 1.8 2004/12/20 02:19:30 kloczek Exp $")
|
||||
#include "defines.h"
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
@ -63,7 +63,7 @@ create_backup_file (FILE * fp, const char *backup, struct stat *sb)
|
||||
return -1;
|
||||
|
||||
c = 0;
|
||||
if (fseek(fp, 0, SEEK_SET) == 0)
|
||||
if (fseeko(fp, 0, SEEK_SET) == 0)
|
||||
while ((c = getc(fp)) != EOF) {
|
||||
if (putc(c, bkfp) == EOF)
|
||||
break;
|
||||
|
Reference in New Issue
Block a user