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

This commit is contained in:
nekral-guest
2007-10-07 11:46:07 +00:00
parent 0ee095abd8
commit 8e167d28af
414 changed files with 21641 additions and 27358 deletions

View File

@@ -30,22 +30,19 @@
#include <config.h>
#include "rcsid.h"
RCSID("$Id: getdef.c,v 1.20 2005/01/20 12:43:05 kloczek Exp $")
RCSID ("$Id: getdef.c,v 1.28 2005/04/01 22:52:03 kloczek Exp $")
#include "prototypes.h"
#include "defines.h"
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "getdef.h"
/*
* A configuration item definition.
*/
struct itemdef {
const char *name; /* name of the item */
char *value; /* value given, or NULL if no value */
const char *name; /* name of the item */
char *value; /* value given, or NULL if no value */
};
/*
@@ -54,85 +51,86 @@ struct itemdef {
#define NUMDEFS (sizeof(def_table)/sizeof(def_table[0]))
static struct itemdef def_table[] = {
{ "CHFN_AUTH", NULL },
{ "CHFN_RESTRICT", NULL },
{"CHFN_RESTRICT", NULL},
{"DEFAULT_HOME", NULL},
{"FAIL_DELAY", NULL},
{"PASS_MAX_DAYS", NULL},
{"PASS_MIN_DAYS", NULL},
{"PASS_WARN_AGE", NULL},
{"USERDEL_CMD", NULL},
#ifdef USE_PAM
{ "CLOSE_SESSIONS", NULL },
{"CLOSE_SESSIONS", NULL},
#else
{"CHFN_AUTH", NULL},
{"CHSH_AUTH", NULL},
{"CRACKLIB_DICTPATH", NULL},
{"ENV_HZ", NULL},
{"ENV_PATH", NULL},
{"ENV_ROOTPATH", NULL}, /* SuSE compatibility? */
{"ENV_SUPATH", NULL},
{"ENV_TZ", NULL},
{"ENVIRON_FILE", NULL},
{"FAILLOG_ENAB", NULL},
{"FTMP_FILE", NULL},
{"ISSUE_FILE", NULL},
{"LASTLOG_ENAB", NULL},
{"LOGIN_STRING", NULL},
{"MAIL_CHECK_ENAB", NULL},
{"MAIL_DIR", NULL},
{"MAIL_FILE", NULL},
{"MD5_CRYPT_ENAB", NULL},
{"MOTD_FILE", NULL},
{"NOLOGINS_FILE", NULL},
{"OBSCURE_CHECKS_ENAB", NULL},
{"PASS_ALWAYS_WARN", NULL},
{"PASS_CHANGE_TRIES", NULL},
{"PASS_MAX_LEN", NULL},
{"PASS_MIN_LEN", NULL},
{"PORTTIME_CHECKS_ENAB", NULL},
{"SU_WHEEL_ONLY", NULL},
{"QMAIL_DIR", NULL},
{"QUOTAS_ENAB", NULL},
{"ULIMIT", NULL},
#endif
{ "CONSOLE", NULL },
{ "CONSOLE_GROUPS", NULL },
{ "CRACKLIB_DICTPATH", NULL },
{ "CREATE_HOME", NULL },
{ "DEFAULT_HOME", NULL },
{ "ENVIRON_FILE", NULL },
{ "ENV_HZ", NULL },
{ "ENV_PATH", NULL },
{ "ENV_ROOTPATH", NULL }, /* SuSE compatibility? */
{ "ENV_SUPATH", NULL },
{ "ENV_TZ", NULL },
{ "ERASECHAR", NULL },
{ "FAILLOG_ENAB", NULL },
{ "FAIL_DELAY", NULL },
{ "FAKE_SHELL", NULL },
{ "FTMP_FILE", NULL },
{ "GETPASS_ASTERISKS", NULL },
{ "GID_MAX", NULL },
{ "GID_MIN", NULL },
{ "HUSHLOGIN_FILE", NULL },
{ "ISSUE_FILE", NULL },
{ "KILLCHAR", NULL },
{ "LASTLOG_ENAB", NULL },
{ "LOGIN_RETRIES", NULL },
{ "LOGIN_STRING", NULL },
{ "LOGIN_TIMEOUT", NULL },
{ "LOG_OK_LOGINS", NULL },
{ "LOG_UNKFAIL_ENAB", NULL },
{ "MAIL_CHECK_ENAB", NULL },
{ "MAIL_DIR", NULL },
{ "MAIL_FILE", NULL },
{ "MD5_CRYPT_ENAB", NULL },
{ "MOTD_FILE", NULL },
{ "NOLOGINS_FILE", NULL },
{ "NOLOGIN_STR", NULL },
{ "OBSCURE_CHECKS_ENAB", NULL },
{ "PASS_ALWAYS_WARN", NULL },
{ "PASS_CHANGE_TRIES", NULL },
{ "PASS_MAX_DAYS", NULL },
{ "PASS_MAX_LEN", NULL },
{ "PASS_MIN_DAYS", NULL },
{ "PASS_MIN_LEN", NULL },
{ "PASS_WARN_AGE", NULL },
{ "PORTTIME_CHECKS_ENAB", NULL },
{ "QMAIL_DIR", NULL },
{ "QUOTAS_ENAB", NULL },
{ "SULOG_FILE", NULL },
{ "SU_NAME", NULL },
{ "SU_WHEEL_ONLY", NULL },
{"CONSOLE", NULL},
{"CONSOLE_GROUPS", NULL},
{"CREATE_HOME", NULL},
{"ERASECHAR", NULL},
{"FAKE_SHELL", NULL},
{"GETPASS_ASTERISKS", NULL},
{"GID_MAX", NULL},
{"GID_MIN", NULL},
{"HUSHLOGIN_FILE", NULL},
{"KILLCHAR", NULL},
{"LOGIN_RETRIES", NULL},
{"LOGIN_TIMEOUT", NULL},
{"LOG_OK_LOGINS", NULL},
{"LOG_UNKFAIL_ENAB", NULL},
{"SULOG_FILE", NULL},
{"SU_NAME", NULL},
#ifdef USE_SYSLOG
{ "SYSLOG_SG_ENAB", NULL },
{ "SYSLOG_SU_ENAB", NULL },
{"SYSLOG_SG_ENAB", NULL},
{"SYSLOG_SU_ENAB", NULL},
#endif
{ "TTYGROUP", NULL },
{ "TTYPERM", NULL },
{ "TTYTYPE_FILE", NULL },
{ "UID_MAX", NULL },
{ "UID_MIN", NULL },
{ "ULIMIT", NULL },
{ "UMASK", NULL },
{ "USERDEL_CMD", NULL },
{ "USERGROUPS_ENAB", NULL }
{"TTYGROUP", NULL},
{"TTYPERM", NULL},
{"TTYTYPE_FILE", NULL},
{"UID_MAX", NULL},
{"UID_MIN", NULL},
{"UMASK", NULL},
{"USERGROUPS_ENAB", NULL}
};
#ifndef LOGINDEFS
#define LOGINDEFS "/etc/login.defs"
#endif
static char def_fname[] = LOGINDEFS; /* login config defs file */
static int def_loaded = 0; /* are defs already loaded? */
static char def_fname[] = LOGINDEFS; /* login config defs file */
static int def_loaded = 0; /* are defs already loaded? */
/* local function prototypes */
static struct itemdef *def_find(const char *);
static void def_load(void);
static struct itemdef *def_find (const char *);
static void def_load (void);
/*
@@ -142,15 +140,14 @@ static void def_load(void);
* defined. First time invoked, will load definitions from the file.
*/
char *
getdef_str(const char *item)
char *getdef_str (const char *item)
{
struct itemdef *d;
if (!def_loaded)
def_load();
def_load ();
return ((d = def_find(item)) == NULL ? (char *)NULL : d->value);
return ((d = def_find (item)) == NULL ? (char *) NULL : d->value);
}
@@ -160,18 +157,17 @@ getdef_str(const char *item)
* Return TRUE if specified item is defined as "yes", else FALSE.
*/
int
getdef_bool(const char *item)
int getdef_bool (const char *item)
{
struct itemdef *d;
if (!def_loaded)
def_load();
def_load ();
if ((d = def_find(item)) == NULL || d->value == NULL)
if ((d = def_find (item)) == NULL || d->value == NULL)
return 0;
return (strcasecmp(d->value, "yes") == 0);
return (strcasecmp (d->value, "yes") == 0);
}
@@ -183,18 +179,17 @@ getdef_bool(const char *item)
* values are handled.
*/
int
getdef_num(const char *item, int dflt)
int getdef_num (const char *item, int dflt)
{
struct itemdef *d;
if (!def_loaded)
def_load();
def_load ();
if ((d = def_find(item)) == NULL || d->value == NULL)
if ((d = def_find (item)) == NULL || d->value == NULL)
return dflt;
return (int) strtol(d->value, (char **)NULL, 0);
return (int) strtol (d->value, (char **) NULL, 0);
}
@@ -206,18 +201,17 @@ getdef_num(const char *item, int dflt)
* values are handled.
*/
unsigned int
getdef_unum(const char *item, unsigned int dflt)
unsigned int getdef_unum (const char *item, unsigned int dflt)
{
struct itemdef *d;
if (!def_loaded)
def_load();
def_load ();
if ((d = def_find(item)) == NULL || d->value == NULL)
if ((d = def_find (item)) == NULL || d->value == NULL)
return dflt;
return (unsigned int) strtoul(d->value, (char **)NULL, 0);
return (unsigned int) strtoul (d->value, (char **) NULL, 0);
}
@@ -229,18 +223,17 @@ getdef_unum(const char *item, unsigned int dflt)
* values are handled.
*/
long
getdef_long(const char *item, long dflt)
long getdef_long (const char *item, long dflt)
{
struct itemdef *d;
if (!def_loaded)
def_load();
def_load ();
if ((d = def_find(item)) == NULL || d->value == NULL)
if ((d = def_find (item)) == NULL || d->value == NULL)
return dflt;
return strtol(d->value, (char **)NULL, 0);
return strtol (d->value, (char **) NULL, 0);
}
@@ -249,35 +242,33 @@ getdef_long(const char *item, long dflt)
* (also used when loading the initial defaults)
*/
int
putdef_str(const char *name, const char *value)
int putdef_str (const char *name, const char *value)
{
struct itemdef *d;
char *cp;
if (!def_loaded)
def_load();
def_load ();
/*
* Locate the slot to save the value. If this parameter
* is unknown then "def_find" will print an err message.
*/
if ((d = def_find(name)) == NULL)
if ((d = def_find (name)) == NULL)
return -1;
/*
* Save off the value.
*/
if ((cp = strdup(value)) == NULL) {
fprintf(stderr,
_("Could not allocate space for config info.\n"));
SYSLOG((LOG_ERR,
"could not allocate space for config info"));
if ((cp = strdup (value)) == NULL) {
fprintf (stderr,
_("Could not allocate space for config info.\n"));
SYSLOG ((LOG_ERR, "could not allocate space for config info"));
return -1;
}
if (d->value)
free(d->value);
free (d->value);
d->value = cp;
return 0;
@@ -291,8 +282,7 @@ putdef_str(const char *name, const char *value)
* specified configuration option.
*/
static struct itemdef *
def_find(const char *name)
static struct itemdef *def_find (const char *name)
{
int min, max, curr, n;
@@ -301,7 +291,7 @@ def_find(const char *name)
*/
min = 0;
max = NUMDEFS-1;
max = NUMDEFS - 1;
/*
* Binary search into the table. Relies on the items being
@@ -309,23 +299,26 @@ def_find(const char *name)
*/
while (min <= max) {
curr = (min+max)/2;
curr = (min + max) / 2;
if (! (n = strcmp(def_table[curr].name, name)))
if (!(n = strcmp (def_table[curr].name, name)))
return &def_table[curr];
if (n < 0)
min = curr+1;
min = curr + 1;
else
max = curr-1;
max = curr - 1;
}
/*
* Item was never found.
*/
fprintf(stderr, _("configuration error - unknown item '%s' (notify administrator)\n"), name);
SYSLOG((LOG_CRIT, "unknown configuration item `%s'", name));
fprintf (stderr,
_
("configuration error - unknown item '%s' (notify administrator)\n"),
name);
SYSLOG ((LOG_CRIT, "unknown configuration item `%s'", name));
return (struct itemdef *) NULL;
}
@@ -335,8 +328,7 @@ def_find(const char *name)
* Loads the user-configured options from the default configuration file
*/
static void
def_load(void)
static void def_load (void)
{
int i;
FILE *fp;
@@ -345,10 +337,10 @@ def_load(void)
/*
* Open the configuration definitions file.
*/
if ((fp = fopen(def_fname, "r")) == NULL) {
SYSLOG((LOG_CRIT, "cannot open login definitions %s [%m]",
def_fname));
exit(1);
if ((fp = fopen (def_fname, "r")) == NULL) {
SYSLOG ((LOG_CRIT, "cannot open login definitions %s [%m]",
def_fname));
exit (1);
}
/*
@@ -360,13 +352,13 @@ def_load(void)
/*
* Go through all of the lines in the file.
*/
while (fgets(buf, sizeof(buf), fp) != NULL) {
while (fgets (buf, sizeof (buf), fp) != NULL) {
/*
* Trim trailing whitespace.
*/
for (i = strlen(buf)-1 ; i >= 0 ; --i) {
if (!isspace(buf[i]))
for (i = strlen (buf) - 1; i >= 0; --i) {
if (!isspace (buf[i]))
break;
}
buf[++i] = '\0';
@@ -374,37 +366,36 @@ def_load(void)
/*
* Break the line into two fields.
*/
name = buf + strspn(buf, " \t"); /* first nonwhite */
name = buf + strspn (buf, " \t"); /* first nonwhite */
if (*name == '\0' || *name == '#')
continue; /* comment or empty */
continue; /* comment or empty */
s = name + strcspn(name, " \t"); /* end of field */
s = name + strcspn (name, " \t"); /* end of field */
if (*s == '\0')
continue; /* only 1 field?? */
continue; /* only 1 field?? */
*s++ = '\0';
value = s + strspn(s, " \"\t"); /* next nonwhite */
*(value + strcspn(value, "\"")) = '\0';
value = s + strspn (s, " \"\t"); /* next nonwhite */
*(value + strcspn (value, "\"")) = '\0';
/*
* Store the value in def_table.
*/
putdef_str(name, value);
putdef_str (name, value);
}
if (ferror(fp)) {
SYSLOG((LOG_CRIT, "cannot read login definitions %s [%m]",
def_fname));
exit(1);
if (ferror (fp)) {
SYSLOG ((LOG_CRIT, "cannot read login definitions %s [%m]",
def_fname));
exit (1);
}
(void) fclose(fp);
(void) fclose (fp);
}
#ifdef CKDEFS
int
main(int argc, char **argv)
int main (int argc, char **argv)
{
int i;
char *cp;
@@ -412,18 +403,19 @@ main(int argc, char **argv)
def_load ();
for (i = 0 ; i < NUMDEFS ; ++i) {
if ((d = def_find(def_table[i].name)) == NULL)
printf("error - lookup '%s' failed\n", def_table[i].name);
for (i = 0; i < NUMDEFS; ++i) {
if ((d = def_find (def_table[i].name)) == NULL)
printf ("error - lookup '%s' failed\n",
def_table[i].name);
else
printf("%4d %-24s %s\n", i+1, d->name, d->value);
printf ("%4d %-24s %s\n", i + 1, d->name, d->value);
}
for (i = 1;i < argc;i++) {
for (i = 1; i < argc; i++) {
if ((cp = getdef_str (argv[1])) != NULL)
printf ("%s `%s'\n", argv[1], cp);
else
printf ("%s not found\n", argv[1]);
}
exit(0);
exit (0);
}
#endif