2007-10-07 17:14:02 +05:30
|
|
|
/*
|
2008-04-27 06:10:09 +05:30
|
|
|
* Copyright (c) 1991 - 1994, Julianne Frances Haugh
|
|
|
|
* Copyright (c) 1996 - 2000, Marek Michałkiewicz
|
|
|
|
* Copyright (c) 2002 - 2006, Tomasz Kłoczko
|
|
|
|
* Copyright (c) 2007 - 2008, Nicolas François
|
2007-10-07 17:14:02 +05:30
|
|
|
* 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.
|
2008-04-27 06:10:09 +05:30
|
|
|
* 3. The name of the copyright holders or contributors may not be used to
|
|
|
|
* endorse or promote products derived from this software without
|
|
|
|
* specific prior written permission.
|
2007-10-07 17:14:02 +05:30
|
|
|
*
|
2008-04-27 06:10:09 +05:30
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 THE COPYRIGHT
|
|
|
|
* HOLDERS 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.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
#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>
|
2008-09-13 23:33:50 +05:30
|
|
|
#include <errno.h>
|
2019-09-20 13:57:31 +05:30
|
|
|
#ifdef USE_ECONF
|
|
|
|
#include <libeconf.h>
|
|
|
|
#endif
|
2007-10-07 17:14:02 +05:30
|
|
|
#include "getdef.h"
|
|
|
|
/*
|
|
|
|
* A configuration item definition.
|
|
|
|
*/
|
|
|
|
struct itemdef {
|
2009-04-23 17:16:46 +05:30
|
|
|
/*@null@*/const char *name; /* name of the item */
|
|
|
|
/*@null@*/char *value; /* value given, or NULL if no value */
|
2007-10-07 17:14:02 +05:30
|
|
|
};
|
|
|
|
|
2015-02-27 18:09:44 +05:30
|
|
|
#define PAMDEFS \
|
|
|
|
{"CHFN_AUTH", NULL}, \
|
|
|
|
{"CHSH_AUTH", NULL}, \
|
|
|
|
{"CRACKLIB_DICTPATH", NULL}, \
|
|
|
|
{"ENV_HZ", NULL}, \
|
|
|
|
{"ENVIRON_FILE", NULL}, \
|
|
|
|
{"ENV_TZ", NULL}, \
|
|
|
|
{"FAILLOG_ENAB", NULL}, \
|
|
|
|
{"FTMP_FILE", NULL}, \
|
|
|
|
{"ISSUE_FILE", NULL}, \
|
|
|
|
{"LASTLOG_ENAB", NULL}, \
|
|
|
|
{"LOGIN_STRING", NULL}, \
|
|
|
|
{"MAIL_CHECK_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}, \
|
|
|
|
{"QUOTAS_ENAB", NULL}, \
|
|
|
|
{"SU_WHEEL_ONLY", NULL}, \
|
|
|
|
{"ULIMIT", NULL},
|
|
|
|
|
2020-10-08 15:47:30 +05:30
|
|
|
/*
|
|
|
|
* Items used in other tools (util-linux, etc.)
|
|
|
|
*/
|
|
|
|
#define FOREIGNDEFS \
|
|
|
|
{"ALWAYS_SET_PATH", NULL}, \
|
|
|
|
{"ENV_ROOTPATH", NULL}, \
|
|
|
|
{"LOGIN_KEEP_USERNAME", NULL}, \
|
|
|
|
{"LOGIN_PLAIN_PROMPT", NULL}, \
|
|
|
|
{"MOTD_FIRSTONLY", NULL}, \
|
|
|
|
|
2015-02-27 18:09:44 +05:30
|
|
|
|
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-11-20 15:03:52 +05:30
|
|
|
{"ENCRYPT_METHOD", 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},
|
2020-01-12 02:49:37 +05:30
|
|
|
{"HOME_MODE", NULL},
|
2007-10-07 17:16:52 +05:30
|
|
|
{"HUSHLOGIN_FILE", NULL},
|
|
|
|
{"KILLCHAR", NULL},
|
2018-11-28 19:27:16 +05:30
|
|
|
{"LASTLOG_UID_MAX", NULL},
|
2007-10-07 17:16:52 +05:30
|
|
|
{"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-11-23 05:37:59 +05:30
|
|
|
{"MAX_MEMBERS_PER_GROUP", NULL},
|
2007-11-20 15:03:52 +05:30
|
|
|
{"MD5_CRYPT_ENAB", NULL},
|
2020-05-08 20:12:52 +05:30
|
|
|
{"NONEXISTENT", NULL},
|
2007-10-07 17:16:07 +05:30
|
|
|
{"PASS_MAX_DAYS", NULL},
|
|
|
|
{"PASS_MIN_DAYS", NULL},
|
|
|
|
{"PASS_WARN_AGE", NULL},
|
2008-05-20 02:28:59 +05:30
|
|
|
#ifdef USE_SHA_CRYPT
|
2007-11-20 15:03:52 +05:30
|
|
|
{"SHA_CRYPT_MAX_ROUNDS", NULL},
|
|
|
|
{"SHA_CRYPT_MIN_ROUNDS", NULL},
|
2019-09-17 00:24:56 +05:30
|
|
|
#endif
|
|
|
|
#ifdef USE_BCRYPT
|
|
|
|
{"BCRYPT_MAX_ROUNDS", NULL},
|
|
|
|
{"BCRYPT_MIN_ROUNDS", NULL},
|
2020-12-28 01:39:25 +05:30
|
|
|
#endif
|
|
|
|
#ifdef USE_YESCRYPT
|
|
|
|
{"YESCRYPT_COST_FACTOR", NULL},
|
2008-05-20 02:28:59 +05:30
|
|
|
#endif
|
2013-01-22 14:44:35 +05:30
|
|
|
{"SUB_GID_COUNT", NULL},
|
|
|
|
{"SUB_GID_MAX", NULL},
|
|
|
|
{"SUB_GID_MIN", NULL},
|
|
|
|
{"SUB_UID_COUNT", NULL},
|
|
|
|
{"SUB_UID_MAX", NULL},
|
|
|
|
{"SUB_UID_MIN", NULL},
|
2007-10-07 17:16:52 +05:30
|
|
|
{"SULOG_FILE", NULL},
|
|
|
|
{"SU_NAME", NULL},
|
2008-02-26 02:36:30 +05:30
|
|
|
{"SYS_GID_MAX", NULL},
|
|
|
|
{"SYS_GID_MIN", NULL},
|
|
|
|
{"SYS_UID_MAX", NULL},
|
|
|
|
{"SYS_UID_MIN", NULL},
|
2007-10-07 17:16:52 +05:30
|
|
|
{"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
|
2015-02-27 18:09:44 +05:30
|
|
|
PAMDEFS
|
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},
|
2010-01-30 Paweł Hajdan, Jr. <phajdan.jr@gentoo.org>
* NEWS: Add support for TCB.
* lib/tcbfuncs.h, lib/tcbfuncs.c, lib/Makefile.am: New library to
support TCB.
* lib/prototypes, libmisc/copydir.c (remove_tree): Add boolean
parameter remove_root.
* configure.in: Add conditional WITH_TCB.
* src/userdel.c, src/usermod.c: Add support for TCB. Update call to
remove_tree().
* src/pwconv.c, src/pwunconv.c: Should not be used with TCB enabled.
* src/vipw.c: Add support for TCB. Update call to remove_tree().
* src/useradd.c: Add support for TCB. Open the shadow file outside
of open_files().
* src/chage.c: Add support for TCB.
* src/Makefile.am: Install passwd sgid shadow when TCB is enabled.
* lib/getdefs.c, man/vipw.8.xml, man/login.defs.5.xml,
man/login.defs/TCB_AUTH_GROUP.xml, man/login.defs/USE_TCB.xml,
man/login.defs/TCB_SYMLINKS.xml, man/generate_mans.mak,
man/generate_mans.deps, man/Makefile.am: New configuration
parameters: TCB_AUTH_GROUP, TCB_SYMLINKS, USE_TCB.
* lib/shadowio.c, lib/commonio.c: Add support for TCB.
2010-03-04 23:41:13 +05:30
|
|
|
#endif
|
|
|
|
#ifdef WITH_TCB
|
|
|
|
{"TCB_AUTH_GROUP", NULL},
|
|
|
|
{"TCB_SYMLINKS", NULL},
|
|
|
|
{"USE_TCB", NULL},
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
2015-02-27 19:48:56 +05:30
|
|
|
{"FORCE_SHADOW", NULL},
|
2021-01-07 16:45:25 +05:30
|
|
|
{"GRANT_AUX_GROUP_SUBIDS", NULL},
|
2021-03-29 08:46:03 +05:30
|
|
|
{"PREVENT_NO_AUTH", NULL},
|
2007-10-07 17:16:16 +05:30
|
|
|
{NULL, NULL}
|
2007-10-07 17:14:02 +05:30
|
|
|
};
|
|
|
|
|
2015-02-27 18:09:44 +05:30
|
|
|
#define NUMKNOWNDEFS (sizeof(knowndef_table)/sizeof(knowndef_table[0]))
|
|
|
|
static struct itemdef knowndef_table[] = {
|
|
|
|
#ifdef USE_PAM
|
|
|
|
PAMDEFS
|
|
|
|
#endif
|
2020-10-08 15:47:30 +05:30
|
|
|
FOREIGNDEFS
|
2017-01-26 21:18:48 +05:30
|
|
|
{NULL, NULL}
|
2015-02-27 18:09:44 +05:30
|
|
|
};
|
|
|
|
|
2019-09-20 13:57:31 +05:30
|
|
|
#ifdef USE_ECONF
|
|
|
|
#ifdef VENDORDIR
|
|
|
|
static const char* vendordir = VENDORDIR;
|
|
|
|
#else
|
|
|
|
static const char* vendordir = NULL;
|
|
|
|
#endif
|
|
|
|
static const char* sysconfdir = "/etc";
|
|
|
|
#else
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifndef LOGINDEFS
|
|
|
|
#define LOGINDEFS "/etc/login.defs"
|
|
|
|
#endif
|
|
|
|
|
2016-05-15 19:19:39 +05:30
|
|
|
static const char* def_fname = LOGINDEFS; /* login config defs file */
|
2019-09-20 13:57:31 +05:30
|
|
|
#endif
|
2008-05-26 03:13:05 +05:30
|
|
|
static bool def_loaded = false; /* are defs already loaded? */
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/* local function prototypes */
|
2009-04-23 17:16:46 +05:30
|
|
|
static /*@observer@*/ /*@null@*/struct itemdef *def_find (const char *);
|
2007-10-07 17:16:07 +05:30
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2009-04-23 17:16:46 +05:30
|
|
|
/*@observer@*/ /*@null@*/const char *getdef_str (const char *item)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
struct itemdef *d;
|
|
|
|
|
2008-05-26 03:13:05 +05:30
|
|
|
if (!def_loaded) {
|
2007-10-07 17:16:07 +05:30
|
|
|
def_load ();
|
2008-05-26 03:13:05 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-05-26 03:13:05 +05:30
|
|
|
d = def_find (item);
|
2009-04-23 17:16:46 +05:30
|
|
|
return ((NULL == d)? (const 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.
|
|
|
|
*/
|
|
|
|
|
2008-05-26 03:13:05 +05:30
|
|
|
bool getdef_bool (const char *item)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
struct itemdef *d;
|
|
|
|
|
2008-05-26 03:13:05 +05:30
|
|
|
if (!def_loaded) {
|
2007-10-07 17:16:07 +05:30
|
|
|
def_load ();
|
2008-05-26 03:13:05 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-05-26 03:13:05 +05:30
|
|
|
d = def_find (item);
|
|
|
|
if ((NULL == d) || (NULL == d->value)) {
|
|
|
|
return false;
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
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;
|
2009-04-11 04:05:26 +05:30
|
|
|
long val;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-05-26 03:13:05 +05:30
|
|
|
if (!def_loaded) {
|
2007-10-07 17:16:07 +05:30
|
|
|
def_load ();
|
2008-05-26 03:13:05 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-05-26 03:13:05 +05:30
|
|
|
d = def_find (item);
|
|
|
|
if ((NULL == d) || (NULL == d->value)) {
|
2007-10-07 17:14:02 +05:30
|
|
|
return dflt;
|
2008-05-26 03:13:05 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2009-04-11 04:05:26 +05:30
|
|
|
if ( (getlong (d->value, &val) == 0)
|
|
|
|
|| (val > INT_MAX)
|
|
|
|
|| (val < INT_MIN)) {
|
|
|
|
fprintf (stderr,
|
|
|
|
_("configuration error - cannot parse %s value: '%s'"),
|
|
|
|
item, d->value);
|
|
|
|
return dflt;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (int) val;
|
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;
|
2009-04-11 04:05:26 +05:30
|
|
|
long val;
|
2007-10-07 17:14:59 +05:30
|
|
|
|
2008-05-26 03:13:05 +05:30
|
|
|
if (!def_loaded) {
|
2007-10-07 17:16:07 +05:30
|
|
|
def_load ();
|
2008-05-26 03:13:05 +05:30
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
|
2008-05-26 03:13:05 +05:30
|
|
|
d = def_find (item);
|
|
|
|
if ((NULL == d) || (NULL == d->value)) {
|
2007-10-07 17:14:59 +05:30
|
|
|
return dflt;
|
2008-05-26 03:13:05 +05:30
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
|
2009-04-11 04:05:26 +05:30
|
|
|
if ( (getlong (d->value, &val) == 0)
|
|
|
|
|| (val < 0)
|
|
|
|
|| (val > INT_MAX)) {
|
|
|
|
fprintf (stderr,
|
|
|
|
_("configuration error - cannot parse %s value: '%s'"),
|
|
|
|
item, d->value);
|
|
|
|
return dflt;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (unsigned int) val;
|
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;
|
2009-04-11 04:05:26 +05:30
|
|
|
long val;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-05-26 03:13:05 +05:30
|
|
|
if (!def_loaded) {
|
2007-10-07 17:16:07 +05:30
|
|
|
def_load ();
|
2008-05-26 03:13:05 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-05-26 03:13:05 +05:30
|
|
|
d = def_find (item);
|
|
|
|
if ((NULL == d) || (NULL == d->value)) {
|
2007-10-07 17:14:02 +05:30
|
|
|
return dflt;
|
2008-05-26 03:13:05 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2009-04-11 04:05:26 +05:30
|
|
|
if (getlong (d->value, &val) == 0) {
|
|
|
|
fprintf (stderr,
|
|
|
|
_("configuration error - cannot parse %s value: '%s'"),
|
|
|
|
item, d->value);
|
|
|
|
return dflt;
|
|
|
|
}
|
|
|
|
|
|
|
|
return val;
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2008-06-14 03:05:22 +05:30
|
|
|
/*
|
|
|
|
* getdef_ulong - get unsigned long 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.
|
|
|
|
*/
|
|
|
|
|
2008-06-15 02:39:33 +05:30
|
|
|
unsigned long getdef_ulong (const char *item, unsigned long dflt)
|
2008-06-14 03:05:22 +05:30
|
|
|
{
|
|
|
|
struct itemdef *d;
|
2009-04-23 17:16:46 +05:30
|
|
|
unsigned long val;
|
2008-06-14 03:05:22 +05:30
|
|
|
|
|
|
|
if (!def_loaded) {
|
|
|
|
def_load ();
|
|
|
|
}
|
|
|
|
|
|
|
|
d = def_find (item);
|
|
|
|
if ((NULL == d) || (NULL == d->value)) {
|
|
|
|
return dflt;
|
|
|
|
}
|
|
|
|
|
2009-04-23 17:16:46 +05:30
|
|
|
if (getulong (d->value, &val) == 0) {
|
2009-04-11 04:05:26 +05:30
|
|
|
/* FIXME: we should have a getulong */
|
|
|
|
fprintf (stderr,
|
|
|
|
_("configuration error - cannot parse %s value: '%s'"),
|
|
|
|
item, d->value);
|
|
|
|
return dflt;
|
|
|
|
}
|
|
|
|
|
|
|
|
return val;
|
2008-06-14 03:05:22 +05:30
|
|
|
}
|
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;
|
|
|
|
|
2008-05-26 03:13:05 +05:30
|
|
|
if (!def_loaded) {
|
2007-10-07 17:16:07 +05:30
|
|
|
def_load ();
|
2008-05-26 03:13:05 +05:30
|
|
|
}
|
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.
|
|
|
|
*/
|
2008-05-26 03:13:05 +05:30
|
|
|
d = def_find (name);
|
|
|
|
if (NULL == d) {
|
2007-10-07 17:14:02 +05:30
|
|
|
return -1;
|
2008-05-26 03:13:05 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Save off the value.
|
|
|
|
*/
|
2008-05-26 03:13:05 +05:30
|
|
|
cp = strdup (value);
|
|
|
|
if (NULL == cp) {
|
2009-04-23 17:16:46 +05:30
|
|
|
(void) fputs (_("Could not allocate space for config info.\n"),
|
|
|
|
stderr);
|
2007-10-07 17:16:07 +05:30
|
|
|
SYSLOG ((LOG_ERR, "could not allocate space for config info"));
|
2007-10-07 17:14:02 +05:30
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-05-26 03:13:05 +05:30
|
|
|
if (NULL != d->value) {
|
2007-10-07 17:16:07 +05:30
|
|
|
free (d->value);
|
2008-05-26 03:13:05 +05:30
|
|
|
}
|
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.
|
|
|
|
*/
|
|
|
|
|
2009-04-23 17:16:46 +05:30
|
|
|
static /*@observer@*/ /*@null@*/struct itemdef *def_find (const char *name)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:16 +05:30
|
|
|
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
|
|
|
*/
|
|
|
|
|
2008-05-26 03:13:05 +05:30
|
|
|
for (ptr = def_table; NULL != ptr->name; ptr++) {
|
|
|
|
if (strcmp (ptr->name, name) == 0) {
|
2007-10-07 17:16:16 +05:30
|
|
|
return ptr;
|
2008-05-26 03:13:05 +05:30
|
|
|
}
|
2007-10-07 17:16:25 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Item was never found.
|
|
|
|
*/
|
|
|
|
|
2015-02-27 18:09:44 +05:30
|
|
|
for (ptr = knowndef_table; NULL != ptr->name; ptr++) {
|
|
|
|
if (strcmp (ptr->name, name) == 0) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
2007-10-07 17:16:07 +05:30
|
|
|
fprintf (stderr,
|
2009-04-11 04:05:26 +05:30
|
|
|
_("configuration error - unknown item '%s' (notify administrator)\n"),
|
|
|
|
name);
|
2007-10-07 17:16:07 +05:30
|
|
|
SYSLOG ((LOG_CRIT, "unknown configuration item `%s'", name));
|
2015-02-27 18:09:44 +05:30
|
|
|
|
|
|
|
out:
|
2007-10-07 17:14:02 +05:30
|
|
|
return (struct itemdef *) NULL;
|
|
|
|
}
|
|
|
|
|
2016-05-15 19:19:39 +05:30
|
|
|
/*
|
|
|
|
* setdef_config_file - set the default configuration file path
|
|
|
|
*
|
|
|
|
* must be called prior to any def* calls.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void setdef_config_file (const char* file)
|
|
|
|
{
|
2019-09-20 13:57:31 +05:30
|
|
|
#ifdef USE_ECONF
|
|
|
|
size_t len;
|
|
|
|
char* cp;
|
|
|
|
|
|
|
|
len = strlen(file) + strlen(sysconfdir) + 2;
|
|
|
|
cp = malloc(len);
|
|
|
|
if (cp == NULL)
|
|
|
|
exit (13);
|
|
|
|
snprintf(cp, len, "%s/%s", file, sysconfdir);
|
|
|
|
sysconfdir = cp;
|
|
|
|
#ifdef VENDORDIR
|
|
|
|
len = strlen(file) + strlen(vendordir) + 2;
|
|
|
|
cp = malloc(len);
|
|
|
|
if (cp == NULL)
|
|
|
|
exit (13);
|
|
|
|
snprintf(cp, len, "%s/%s", file, vendordir);
|
|
|
|
vendordir = cp;
|
|
|
|
#endif
|
|
|
|
#else
|
2016-05-15 19:19:39 +05:30
|
|
|
def_fname = file;
|
2019-09-20 13:57:31 +05:30
|
|
|
#endif
|
2016-05-15 19:19:39 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
|
|
|
* 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
|
|
|
{
|
2019-09-20 13:57:31 +05:30
|
|
|
#ifdef USE_ECONF
|
|
|
|
econf_file *defs_file = NULL;
|
|
|
|
econf_err error;
|
|
|
|
char **keys;
|
|
|
|
size_t key_number;
|
|
|
|
#else
|
2007-10-07 17:14:02 +05:30
|
|
|
int i;
|
|
|
|
FILE *fp;
|
|
|
|
char buf[1024], *name, *value, *s;
|
2019-09-20 13:57:31 +05:30
|
|
|
#endif
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2015-02-27 16:53:58 +05:30
|
|
|
/*
|
|
|
|
* Set the initialized flag.
|
|
|
|
* (do it early to prevent recursion in putdef_str())
|
|
|
|
*/
|
|
|
|
def_loaded = true;
|
|
|
|
|
2019-09-20 13:57:31 +05:30
|
|
|
#ifdef USE_ECONF
|
|
|
|
|
|
|
|
error = econf_readDirs (&defs_file, vendordir, sysconfdir, "login", "defs", " \t", "#");
|
|
|
|
if (error) {
|
|
|
|
if (error == ECONF_NOFILE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
SYSLOG ((LOG_CRIT, "cannot open login definitions [%s]",
|
|
|
|
econf_errString(error)));
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((error = econf_getKeys(defs_file, NULL, &key_number, &keys))) {
|
|
|
|
SYSLOG ((LOG_CRIT, "cannot read login definitions [%s]",
|
|
|
|
econf_errString(error)));
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 0; i < key_number; i++) {
|
|
|
|
char *value;
|
|
|
|
|
|
|
|
econf_getStringValue(defs_file, NULL, keys[i], &value);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Store the value in def_table.
|
|
|
|
*
|
|
|
|
* Ignore failures to load the login.defs file.
|
|
|
|
* The error was already reported to the user and to
|
|
|
|
* syslog. The tools will just use their default values.
|
|
|
|
*/
|
|
|
|
(void)putdef_str (keys[i], value);
|
|
|
|
}
|
|
|
|
|
|
|
|
econf_free (keys);
|
|
|
|
econf_free (defs_file);
|
|
|
|
#else
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
|
|
|
* Open the configuration definitions file.
|
|
|
|
*/
|
2008-05-26 03:13:05 +05:30
|
|
|
fp = fopen (def_fname, "r");
|
|
|
|
if (NULL == fp) {
|
2015-02-27 16:53:58 +05:30
|
|
|
if (errno == ENOENT)
|
|
|
|
return;
|
|
|
|
|
2008-09-13 23:33:50 +05:30
|
|
|
int err = errno;
|
|
|
|
SYSLOG ((LOG_CRIT, "cannot open login definitions %s [%s]",
|
|
|
|
def_fname, strerror (err)));
|
2009-04-23 17:16:46 +05:30
|
|
|
exit (EXIT_FAILURE);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Go through all of the lines in the file.
|
|
|
|
*/
|
2008-06-14 03:05:22 +05:30
|
|
|
while (fgets (buf, (int) sizeof (buf), fp) != NULL) {
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Trim trailing whitespace.
|
|
|
|
*/
|
2008-06-14 03:05:22 +05:30
|
|
|
for (i = (int) strlen (buf) - 1; i >= 0; --i) {
|
2008-05-26 03:13:05 +05:30
|
|
|
if (!isspace (buf[i])) {
|
2007-10-07 17:14:02 +05:30
|
|
|
break;
|
2008-05-26 03:13:05 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2008-06-14 03:05:22 +05:30
|
|
|
i++;
|
|
|
|
buf[i] = '\0';
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
2009-04-23 17:16:46 +05:30
|
|
|
*
|
|
|
|
* Ignore failures to load the login.defs file.
|
|
|
|
* The error was already reported to the user and to
|
|
|
|
* syslog. The tools will just use their default values.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2009-04-23 17:16:46 +05:30
|
|
|
(void)putdef_str (name, value);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:15:40 +05:30
|
|
|
|
2008-05-26 03:13:05 +05:30
|
|
|
if (ferror (fp) != 0) {
|
2008-09-13 23:33:50 +05:30
|
|
|
int err = errno;
|
|
|
|
SYSLOG ((LOG_CRIT, "cannot read login definitions %s [%s]",
|
|
|
|
def_fname, strerror (err)));
|
2009-04-23 17:16:46 +05:30
|
|
|
exit (EXIT_FAILURE);
|
2007-10-07 17:15:40 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
(void) fclose (fp);
|
2019-09-20 13:57:31 +05:30
|
|
|
#endif
|
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) {
|
2008-05-26 03:13:05 +05:30
|
|
|
d = def_find (def_table[i].name);
|
|
|
|
if (NULL == d) {
|
2007-10-07 17:16:07 +05:30
|
|
|
printf ("error - lookup '%s' failed\n",
|
2008-05-26 03:13:05 +05:30
|
|
|
def_table[i].name);
|
|
|
|
} else {
|
2007-10-07 17:16:07 +05:30
|
|
|
printf ("%4d %-24s %s\n", i + 1, d->name, d->value);
|
2008-05-26 03:13:05 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:16:07 +05:30
|
|
|
for (i = 1; i < argc; i++) {
|
2008-05-26 03:13:05 +05:30
|
|
|
cp = getdef_str (argv[1]);
|
|
|
|
if (NULL != cp) {
|
2007-10-07 17:14:02 +05:30
|
|
|
printf ("%s `%s'\n", argv[1], cp);
|
2008-05-26 03:13:05 +05:30
|
|
|
} else {
|
2007-10-07 17:15:23 +05:30
|
|
|
printf ("%s not found\n", argv[1]);
|
2008-05-26 03:13:05 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2009-04-23 17:16:46 +05:30
|
|
|
exit (EXIT_SUCCESS);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
#endif
|