2007-10-07 17:14:02 +05:30
|
|
|
/*
|
|
|
|
* Copyright 1991 - 1994, Julianne Frances Haugh and Chip Rosenthal
|
|
|
|
* 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>
|
|
|
|
|
2007-11-11 05:16:11 +05:30
|
|
|
#ident "$Id$"
|
2007-10-07 17:17:01 +05:30
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
#include "prototypes.h"
|
|
|
|
#include "defines.h"
|
|
|
|
#include <stdio.h>
|
2007-10-07 17:15:40 +05:30
|
|
|
#include <stdlib.h>
|
2007-10-07 17:14:02 +05:30
|
|
|
#include <ctype.h>
|
|
|
|
#include "getdef.h"
|
|
|
|
/*
|
|
|
|
* A configuration item definition.
|
|
|
|
*/
|
|
|
|
struct itemdef {
|
2007-10-07 17:16:07 +05:30
|
|
|
const char *name; /* name of the item */
|
|
|
|
char *value; /* value given, or NULL if no value */
|
2007-10-07 17:14:02 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
#define NUMDEFS (sizeof(def_table)/sizeof(def_table[0]))
|
|
|
|
static struct itemdef def_table[] = {
|
2007-10-07 17:16:07 +05:30
|
|
|
{"CHFN_RESTRICT", NULL},
|
2007-10-07 17:16:52 +05:30
|
|
|
{"CONSOLE_GROUPS", NULL},
|
|
|
|
{"CONSOLE", NULL},
|
|
|
|
{"CREATE_HOME", NULL},
|
2007-10-07 17:16:07 +05:30
|
|
|
{"DEFAULT_HOME", NULL},
|
2007-10-07 17:16:52 +05:30
|
|
|
{"ENV_PATH", NULL},
|
|
|
|
{"ENV_SUPATH", NULL},
|
|
|
|
{"ERASECHAR", NULL},
|
2007-10-07 17:16:07 +05:30
|
|
|
{"FAIL_DELAY", NULL},
|
2007-10-07 17:16:52 +05:30
|
|
|
{"FAKE_SHELL", 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},
|
|
|
|
{"MAIL_DIR", NULL},
|
2007-10-07 17:17:11 +05:30
|
|
|
{"MAIL_FILE", NULL},
|
2007-10-07 17:16:07 +05:30
|
|
|
{"PASS_MAX_DAYS", NULL},
|
|
|
|
{"PASS_MIN_DAYS", NULL},
|
|
|
|
{"PASS_WARN_AGE", NULL},
|
2007-10-07 17:16:52 +05:30
|
|
|
{"SULOG_FILE", NULL},
|
|
|
|
{"SU_NAME", NULL},
|
|
|
|
{"TTYGROUP", NULL},
|
|
|
|
{"TTYPERM", NULL},
|
|
|
|
{"TTYTYPE_FILE", NULL},
|
|
|
|
{"UID_MAX", NULL},
|
|
|
|
{"UID_MIN", NULL},
|
|
|
|
{"UMASK", NULL},
|
2007-10-07 17:16:07 +05:30
|
|
|
{"USERDEL_CMD", NULL},
|
2007-10-07 17:16:52 +05:30
|
|
|
{"USERGROUPS_ENAB", NULL},
|
|
|
|
#ifndef USE_PAM
|
2007-10-07 17:16:07 +05:30
|
|
|
{"CHFN_AUTH", NULL},
|
|
|
|
{"CHSH_AUTH", NULL},
|
|
|
|
{"CRACKLIB_DICTPATH", NULL},
|
|
|
|
{"ENV_HZ", NULL},
|
|
|
|
{"ENVIRON_FILE", NULL},
|
2007-10-07 17:17:33 +05:30
|
|
|
{"ENV_TZ", NULL},
|
2007-10-07 17:16:07 +05:30
|
|
|
{"FAILLOG_ENAB", NULL},
|
|
|
|
{"FTMP_FILE", NULL},
|
|
|
|
{"ISSUE_FILE", NULL},
|
|
|
|
{"LASTLOG_ENAB", NULL},
|
|
|
|
{"LOGIN_STRING", NULL},
|
|
|
|
{"MAIL_CHECK_ENAB", NULL},
|
2007-10-07 17:17:33 +05:30
|
|
|
{"MD5_CRYPT_ENAB", NULL},
|
2007-10-07 17:16:07 +05:30
|
|
|
{"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},
|
|
|
|
{"QUOTAS_ENAB", NULL},
|
2007-10-07 17:17:33 +05:30
|
|
|
{"SU_WHEEL_ONLY", NULL},
|
2007-10-07 17:16:07 +05:30
|
|
|
{"ULIMIT", NULL},
|
2007-10-07 17:14:14 +05:30
|
|
|
#endif
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef USE_SYSLOG
|
2007-10-07 17:16:07 +05:30
|
|
|
{"SYSLOG_SG_ENAB", NULL},
|
|
|
|
{"SYSLOG_SU_ENAB", NULL},
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
2007-10-07 17:16:16 +05:30
|
|
|
{NULL, NULL}
|
2007-10-07 17:14:02 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
#ifndef LOGINDEFS
|
|
|
|
#define LOGINDEFS "/etc/login.defs"
|
|
|
|
#endif
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
static char def_fname[] = LOGINDEFS; /* login config defs file */
|
|
|
|
static int def_loaded = 0; /* are defs already loaded? */
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/* local function prototypes */
|
2007-10-07 17:16:07 +05:30
|
|
|
static struct itemdef *def_find (const char *);
|
|
|
|
static void def_load (void);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* getdef_str - get string value from table of definitions.
|
|
|
|
*
|
|
|
|
* Return point to static data for specified item, or NULL if item is not
|
|
|
|
* defined. First time invoked, will load definitions from the file.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
char *getdef_str (const char *item)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
struct itemdef *d;
|
|
|
|
|
|
|
|
if (!def_loaded)
|
2007-10-07 17:16:07 +05:30
|
|
|
def_load ();
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
return ((d = def_find (item)) == NULL ? (char *) NULL : d->value);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* getdef_bool - get boolean value from table of definitions.
|
|
|
|
*
|
|
|
|
* Return TRUE if specified item is defined as "yes", else FALSE.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
int getdef_bool (const char *item)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
struct itemdef *d;
|
|
|
|
|
|
|
|
if (!def_loaded)
|
2007-10-07 17:16:07 +05:30
|
|
|
def_load ();
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
if ((d = def_find (item)) == NULL || d->value == NULL)
|
2007-10-07 17:14:02 +05:30
|
|
|
return 0;
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
return (strcasecmp (d->value, "yes") == 0);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* getdef_num - get numerical value from table of definitions
|
|
|
|
*
|
|
|
|
* Returns numeric value of specified item, else the "dflt" value if
|
|
|
|
* the item is not defined. Octal (leading "0") and hex (leading "0x")
|
|
|
|
* values are handled.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
int getdef_num (const char *item, int dflt)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
struct itemdef *d;
|
|
|
|
|
|
|
|
if (!def_loaded)
|
2007-10-07 17:16:07 +05:30
|
|
|
def_load ();
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
if ((d = def_find (item)) == NULL || d->value == NULL)
|
2007-10-07 17:14:02 +05:30
|
|
|
return dflt;
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
return (int) strtol (d->value, (char **) NULL, 0);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
/*
|
|
|
|
* getdef_unum - get unsigned numerical value from table of definitions
|
|
|
|
*
|
|
|
|
* Returns numeric value of specified item, else the "dflt" value if
|
|
|
|
* the item is not defined. Octal (leading "0") and hex (leading "0x")
|
|
|
|
* values are handled.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
unsigned int getdef_unum (const char *item, unsigned int dflt)
|
2007-10-07 17:14:59 +05:30
|
|
|
{
|
|
|
|
struct itemdef *d;
|
|
|
|
|
|
|
|
if (!def_loaded)
|
2007-10-07 17:16:07 +05:30
|
|
|
def_load ();
|
2007-10-07 17:14:59 +05:30
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
if ((d = def_find (item)) == NULL || d->value == NULL)
|
2007-10-07 17:14:59 +05:30
|
|
|
return dflt;
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
return (unsigned int) strtoul (d->value, (char **) NULL, 0);
|
2007-10-07 17:14:59 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
|
|
|
* getdef_long - get long integer value from table of definitions
|
|
|
|
*
|
|
|
|
* Returns numeric value of specified item, else the "dflt" value if
|
|
|
|
* the item is not defined. Octal (leading "0") and hex (leading "0x")
|
|
|
|
* values are handled.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
long getdef_long (const char *item, long dflt)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
struct itemdef *d;
|
|
|
|
|
|
|
|
if (!def_loaded)
|
2007-10-07 17:16:07 +05:30
|
|
|
def_load ();
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
if ((d = def_find (item)) == NULL || d->value == NULL)
|
2007-10-07 17:14:02 +05:30
|
|
|
return dflt;
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
return strtol (d->value, (char **) NULL, 0);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* putdef_str - override the value read from /etc/login.defs
|
|
|
|
* (also used when loading the initial defaults)
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
int putdef_str (const char *name, const char *value)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
struct itemdef *d;
|
|
|
|
char *cp;
|
|
|
|
|
|
|
|
if (!def_loaded)
|
2007-10-07 17:16:07 +05:30
|
|
|
def_load ();
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Locate the slot to save the value. If this parameter
|
|
|
|
* is unknown then "def_find" will print an err message.
|
|
|
|
*/
|
2007-10-07 17:16:07 +05:30
|
|
|
if ((d = def_find (name)) == NULL)
|
2007-10-07 17:14:02 +05:30
|
|
|
return -1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Save off the value.
|
|
|
|
*/
|
2007-10-07 17:16:07 +05:30
|
|
|
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"));
|
2007-10-07 17:14:02 +05:30
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d->value)
|
2007-10-07 17:16:07 +05:30
|
|
|
free (d->value);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
d->value = cp;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* def_find - locate named item in table
|
|
|
|
*
|
2007-10-07 17:16:16 +05:30
|
|
|
* Search through a table of configurable items to locate the
|
2007-10-07 17:14:02 +05:30
|
|
|
* specified configuration option.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
static struct itemdef *def_find (const char *name)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:16 +05:30
|
|
|
int n;
|
|
|
|
struct itemdef *ptr;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:16:16 +05:30
|
|
|
* Search into the table.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
|
2007-10-07 17:16:16 +05:30
|
|
|
for (ptr = def_table; ptr->name; ptr++) {
|
|
|
|
if (!(n = strcmp (ptr->name, name)))
|
|
|
|
return ptr;
|
2007-10-07 17:16:25 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Item was never found.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
fprintf (stderr,
|
|
|
|
_
|
|
|
|
("configuration error - unknown item '%s' (notify administrator)\n"),
|
|
|
|
name);
|
|
|
|
SYSLOG ((LOG_CRIT, "unknown configuration item `%s'", name));
|
2007-10-07 17:14:02 +05:30
|
|
|
return (struct itemdef *) NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* def_load - load configuration table
|
|
|
|
*
|
|
|
|
* Loads the user-configured options from the default configuration file
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
static void def_load (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
int i;
|
|
|
|
FILE *fp;
|
|
|
|
char buf[1024], *name, *value, *s;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Open the configuration definitions file.
|
|
|
|
*/
|
2007-10-07 17:16:07 +05:30
|
|
|
if ((fp = fopen (def_fname, "r")) == NULL) {
|
|
|
|
SYSLOG ((LOG_CRIT, "cannot open login definitions %s [%m]",
|
|
|
|
def_fname));
|
|
|
|
exit (1);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the initialized flag.
|
|
|
|
* (do it early to prevent recursion in putdef_str())
|
|
|
|
*/
|
|
|
|
++def_loaded;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Go through all of the lines in the file.
|
|
|
|
*/
|
2007-10-07 17:16:07 +05:30
|
|
|
while (fgets (buf, sizeof (buf), fp) != NULL) {
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Trim trailing whitespace.
|
|
|
|
*/
|
2007-10-07 17:16:07 +05:30
|
|
|
for (i = strlen (buf) - 1; i >= 0; --i) {
|
|
|
|
if (!isspace (buf[i]))
|
2007-10-07 17:14:02 +05:30
|
|
|
break;
|
|
|
|
}
|
|
|
|
buf[++i] = '\0';
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Break the line into two fields.
|
|
|
|
*/
|
2007-10-07 17:16:07 +05:30
|
|
|
name = buf + strspn (buf, " \t"); /* first nonwhite */
|
2007-10-07 17:14:02 +05:30
|
|
|
if (*name == '\0' || *name == '#')
|
2007-10-07 17:16:07 +05:30
|
|
|
continue; /* comment or empty */
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
s = name + strcspn (name, " \t"); /* end of field */
|
2007-10-07 17:14:02 +05:30
|
|
|
if (*s == '\0')
|
2007-10-07 17:16:07 +05:30
|
|
|
continue; /* only 1 field?? */
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
*s++ = '\0';
|
2007-10-07 17:16:07 +05:30
|
|
|
value = s + strspn (s, " \"\t"); /* next nonwhite */
|
|
|
|
*(value + strcspn (value, "\"")) = '\0';
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Store the value in def_table.
|
|
|
|
*/
|
2007-10-07 17:16:07 +05:30
|
|
|
putdef_str (name, value);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:15:40 +05:30
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
if (ferror (fp)) {
|
|
|
|
SYSLOG ((LOG_CRIT, "cannot read login definitions %s [%m]",
|
|
|
|
def_fname));
|
|
|
|
exit (1);
|
2007-10-07 17:15:40 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
(void) fclose (fp);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef CKDEFS
|
2007-10-07 17:16:07 +05:30
|
|
|
int main (int argc, char **argv)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char *cp;
|
|
|
|
struct itemdef *d;
|
|
|
|
|
|
|
|
def_load ();
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
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);
|
2007-10-07 17:14:02 +05:30
|
|
|
else
|
2007-10-07 17:16:07 +05:30
|
|
|
printf ("%4d %-24s %s\n", i + 1, d->name, d->value);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:16:07 +05:30
|
|
|
for (i = 1; i < argc; i++) {
|
2007-10-07 17:14:02 +05:30
|
|
|
if ((cp = getdef_str (argv[1])) != NULL)
|
|
|
|
printf ("%s `%s'\n", argv[1], cp);
|
|
|
|
else
|
2007-10-07 17:15:23 +05:30
|
|
|
printf ("%s not found\n", argv[1]);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:16:07 +05:30
|
|
|
exit (0);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
#endif
|