mirror of
https://github.com/sudo-project/sudo.git
synced 2025-08-31 06:15:37 +00:00
o Change defaults stuff to put the value right in the struct.
o Implement mailer_flags o Store syslog stuff both in int and string form. Setting the string form magically updates the int version. o Add boolean attribute to strings where it makes sense to say !foo
This commit is contained in:
519
defaults.c
519
defaults.c
@@ -97,139 +97,138 @@ static struct strmap priorities[] = {
|
||||
/*
|
||||
* Local prototypes.
|
||||
*/
|
||||
static int store_int __P((char *, int, int));
|
||||
static int store_str __P((char *, int, int));
|
||||
static int store_syslogfac __P((char *, int, int));
|
||||
static int store_syslogpri __P((char *, int, int));
|
||||
static int store_umask __P((char *, int, int));
|
||||
static char *num_to_name __P((int, struct strmap *));
|
||||
static int store_int __P((char *, struct sudo_defs_types *, int));
|
||||
static int store_str __P((char *, struct sudo_defs_types *, int));
|
||||
static int store_syslogfac __P((char *, struct sudo_defs_types *, int));
|
||||
static int store_syslogpri __P((char *, struct sudo_defs_types *, int));
|
||||
static int store_mode __P((char *, struct sudo_defs_types *, int));
|
||||
|
||||
/*
|
||||
* Structure describing compile-time and run-time options.
|
||||
* Index for T_INT starts at one since index 0 is for flags.
|
||||
* XXX - syslog things should be strings (and !facility should turn off)
|
||||
* XXX - some of these names are pretty lame.
|
||||
* Table describing compile-time and run-time options.
|
||||
*/
|
||||
struct sudo_defs_types {
|
||||
char *name;
|
||||
unsigned int type;
|
||||
unsigned int index;
|
||||
int (*store) __P((char *, int, int));
|
||||
char *desc;
|
||||
} sudo_defs_table[] = {
|
||||
struct sudo_defs_types sudo_defs_table[] = {
|
||||
{
|
||||
"long_otp_prompt", T_FLAG, FL_LONG_OTP_PROMPT, NULL,
|
||||
"syslog_ifac", T_INT, { 0 },
|
||||
NULL
|
||||
}, {
|
||||
"syslog_igoodpri", T_INT, { 0 },
|
||||
NULL
|
||||
}, {
|
||||
"syslog_ibadpri", T_INT, { 0 },
|
||||
NULL
|
||||
}, {
|
||||
"syslog", T_LOGFAC|T_BOOL, { 0 },
|
||||
"Syslog facility if syslog is being used for logging: %s"
|
||||
}, {
|
||||
"syslog_goodpri", T_LOGPRI, { 0 },
|
||||
"Syslog priority to use when user authenticates successfully: %s"
|
||||
}, {
|
||||
"syslog_badpri", T_LOGPRI, { 0 },
|
||||
"Syslog priority to use when user authenticates unsuccessfully: %s"
|
||||
}, {
|
||||
"long_otp_prompt", T_FLAG, { 0 },
|
||||
"Put OTP prompt on its own line"
|
||||
}, {
|
||||
"ignore_dot", T_FLAG, FL_IGNORE_DOT, NULL,
|
||||
"ignore_dot", T_FLAG, { 0 },
|
||||
"Ignore '.' in $PATH"
|
||||
}, {
|
||||
"mail_if_no_user", T_FLAG, FL_MAIL_IF_NOUSER, NULL,
|
||||
"mail_always", T_FLAG, { 0 },
|
||||
"Always send mail when sudo is run"
|
||||
}, {
|
||||
"mail_if_no_user", T_FLAG, { 0 },
|
||||
"Send mail if the user is not in sudoers"
|
||||
}, {
|
||||
"mail_if_no_host", T_FLAG, FL_MAIL_IF_NOHOST, NULL,
|
||||
"mail_if_no_host", T_FLAG, { 0 },
|
||||
"Send mail if the user is not in sudoers for this host"
|
||||
}, {
|
||||
"mail_if_no_perms", T_FLAG, FL_MAIL_IF_NOPERMS, NULL,
|
||||
"mail_if_no_perms", T_FLAG, { 0 },
|
||||
"Send mail if the user is not allowed to run a command"
|
||||
}, {
|
||||
"tty_tickets", T_FLAG, FL_TTY_TICKETS, NULL,
|
||||
"Use a separate timestamp for each user/tty combo"
|
||||
}, {
|
||||
"lecture", T_FLAG, FL_LECTURE, NULL,
|
||||
"Lecture user the first time they run sudo"
|
||||
}, {
|
||||
"authenticate", T_FLAG, FL_AUTHENTICATE, NULL,
|
||||
"Require users to authenticate by default"
|
||||
}, {
|
||||
"root_sudo", T_FLAG, FL_ROOT_SUDO, NULL,
|
||||
"Root may run sudo"
|
||||
}, {
|
||||
"log_host", T_FLAG, FL_LOG_HOST, NULL,
|
||||
"Log the hostname in the (non-syslog) log file"
|
||||
}, {
|
||||
"log_year", T_FLAG, FL_LOG_YEAR, NULL,
|
||||
"Log the year in the (non-syslog) log file"
|
||||
}, {
|
||||
"shell_noargs", T_FLAG, FL_SHELL_NOARGS, NULL,
|
||||
"If sudo is invoked with no arguments, start a shell"
|
||||
}, {
|
||||
"set_home", T_FLAG, FL_SET_HOME, NULL,
|
||||
"Set $HOME to the target user when starting a shell with -s"
|
||||
}, {
|
||||
"path_info", T_FLAG, FL_PATH_INFO, NULL,
|
||||
"Allow some information gathering to give useful error messages"
|
||||
}, {
|
||||
"fqdn", T_FLAG, FL_FQDN, NULL,
|
||||
"Require fully-qualified hsotnames in the sudoers file"
|
||||
}, {
|
||||
"insults", T_FLAG, FL_INSULTS, NULL,
|
||||
"Insult the user when they enter an incorrect password"
|
||||
}, {
|
||||
"syslog", T_INT|T_BOOL, I_LOGFAC, store_syslogfac,
|
||||
"Syslog facility: %s"
|
||||
}, {
|
||||
"syslog_goodpri", T_INT, I_GOODPRI, store_syslogpri,
|
||||
"Syslog priority to use when user authenticates successfully: %s"
|
||||
}, {
|
||||
"syslog_badpri", T_INT, I_BADPRI, store_syslogpri,
|
||||
"Syslog priority to use when user authenticates unsuccessfully: %s"
|
||||
}, {
|
||||
"loglinelen", T_INT, I_LOGLEN, store_int,
|
||||
"Number of length at which to wrap log file lines (0 for no wrap): %d"
|
||||
}, {
|
||||
"timestamp_timeout", T_INT, I_TS_TIMEOUT, store_int,
|
||||
"Authentication timestamp timeout: %d minutes"
|
||||
}, {
|
||||
"passwd_timeout", T_INT, I_PW_TIMEOUT, store_int,
|
||||
"Password prompt timeout: %d minutes"
|
||||
}, {
|
||||
"passwd_tries", T_INT, I_PW_TRIES, store_int,
|
||||
"Number of tries to enter a password: %d"
|
||||
}, {
|
||||
"umask", T_INT|T_BOOL, I_UMASK, store_umask,
|
||||
"Umask to use or 0777 to use user's: 0%o"
|
||||
}, {
|
||||
"logfile", T_STR, I_LOGFILE, store_str,
|
||||
"Path to log file: %s"
|
||||
}, {
|
||||
"mailerpath", T_STR, I_MAILERPATH, store_str,
|
||||
"Path to mail program: %s"
|
||||
}, {
|
||||
"mailerflags", T_STR, I_MAILERARGS, store_str,
|
||||
"Flags for mail program: %s"
|
||||
}, {
|
||||
"alertmail", T_STR, I_ALERTMAIL, store_str,
|
||||
"Address to send mail to: %s"
|
||||
}, {
|
||||
"mailsub", T_STR, I_MAILSUB, store_str,
|
||||
"Subject line for mail messages: %s"
|
||||
}, {
|
||||
"badpass_message", T_STR, I_BADPASS_MSG, store_str,
|
||||
"Incorrect password message: %s"
|
||||
}, {
|
||||
"timestampdir", T_STR, I_TIMESTAMPDIR, store_str,
|
||||
"Path to authentication timestamp dir: %s"
|
||||
}, {
|
||||
"exempt_group", T_STR, I_EXEMPT_GRP, store_str,
|
||||
"Users in this group are exempt from password and PATH requirements: %s"
|
||||
}, {
|
||||
"passprompt", T_STR, I_PASSPROMPT, store_str,
|
||||
"Default password prompt: %s"
|
||||
}, {
|
||||
"runas_default", T_STR, I_RUNAS_DEF, store_str,
|
||||
"Default user to run commands as: %s"
|
||||
}, {
|
||||
"secure_path", T_STR, I_SECURE_PATH, store_str,
|
||||
"Override user's $PATH with: %s"
|
||||
}, {
|
||||
NULL, 0, 0, NULL, NULL
|
||||
"tty_tickets", T_FLAG, { 0 },
|
||||
"Use a separate timestamp for each user/tty combo"
|
||||
}, {
|
||||
"lecture", T_FLAG, { 0 },
|
||||
"Lecture user the first time they run sudo"
|
||||
}, {
|
||||
"authenticate", T_FLAG, { 0 },
|
||||
"Require users to authenticate by default"
|
||||
}, {
|
||||
"root_sudo", T_FLAG, { 0 },
|
||||
"Root may run sudo"
|
||||
}, {
|
||||
"log_host", T_FLAG, { 0 },
|
||||
"Log the hostname in the (non-syslog) log file"
|
||||
}, {
|
||||
"log_year", T_FLAG, { 0 },
|
||||
"Log the year in the (non-syslog) log file"
|
||||
}, {
|
||||
"shell_noargs", T_FLAG, { 0 },
|
||||
"If sudo is invoked with no arguments, start a shell"
|
||||
}, {
|
||||
"set_home", T_FLAG, { 0 },
|
||||
"Set $HOME to the target user when starting a shell with -s"
|
||||
}, {
|
||||
"path_info", T_FLAG, { 0 },
|
||||
"Allow some information gathering to give useful error messages"
|
||||
}, {
|
||||
"fqdn", T_FLAG, { 0 },
|
||||
"Require fully-qualified hsotnames in the sudoers file"
|
||||
}, {
|
||||
"insults", T_FLAG, { 0 },
|
||||
"Insult the user when they enter an incorrect password"
|
||||
}, {
|
||||
"loglinelen", T_INT, { 0 },
|
||||
"Length at which to wrap log file lines (0 for no wrap): %d"
|
||||
}, {
|
||||
"timestamp_timeout", T_INT|T_BOOL, { 0 },
|
||||
"Authentication timestamp timeout: %d minutes"
|
||||
}, {
|
||||
"passwd_timeout", T_INT|T_BOOL, { 0 },
|
||||
"Password prompt timeout: %d minutes"
|
||||
}, {
|
||||
"passwd_tries", T_INT, { 0 },
|
||||
"Number of tries to enter a password: %d"
|
||||
}, {
|
||||
"umask", T_MODE|T_BOOL, { 0 },
|
||||
"Umask to use or 0777 to use user's: 0%o"
|
||||
}, {
|
||||
"logfile", T_STR|T_BOOL, { 0 },
|
||||
"Path to log file: %s"
|
||||
}, {
|
||||
"mailerpath", T_STR|T_BOOL, { 0 },
|
||||
"Path to mail program: %s"
|
||||
}, {
|
||||
"mailerflags", T_STR|T_BOOL, { 0 },
|
||||
"Flags for mail program: %s"
|
||||
}, {
|
||||
"mailto", T_STR|T_BOOL, { 0 },
|
||||
"Address to send mail to: %s"
|
||||
}, {
|
||||
"mailsub", T_STR, { 0 },
|
||||
"Subject line for mail messages: %s"
|
||||
}, {
|
||||
"badpass_message", T_STR, { 0 },
|
||||
"Incorrect password message: %s"
|
||||
}, {
|
||||
"timestampdir", T_STR, { 0 },
|
||||
"Path to authentication timestamp dir: %s"
|
||||
}, {
|
||||
"exempt_group", T_STR|T_BOOL, { 0 },
|
||||
"Users in this group are exempt from password and PATH requirements: %s"
|
||||
}, {
|
||||
"passprompt", T_STR, { 0 },
|
||||
"Default password prompt: %s"
|
||||
}, {
|
||||
"runas_default", T_STR, { 0 },
|
||||
"Default user to run commands as: %s"
|
||||
}, {
|
||||
"secure_path", T_STR|T_BOOL, { 0 },
|
||||
"Value to override user's $PATH with: %s"
|
||||
}, {
|
||||
NULL, 0, { 0 }, NULL
|
||||
}
|
||||
};
|
||||
|
||||
unsigned int sudo_inttable[SUDO_INTTABLE_LAST];
|
||||
char *sudo_strtable[SUDO_STRTABLE_LAST];
|
||||
|
||||
/*
|
||||
* Print version and configure info.
|
||||
*/
|
||||
@@ -239,28 +238,26 @@ dump_defaults()
|
||||
struct sudo_defs_types *cur;
|
||||
|
||||
for (cur = sudo_defs_table; cur->name; cur++) {
|
||||
switch (cur->type & T_MASK) {
|
||||
case T_FLAG:
|
||||
if ((sudo_inttable[I_FLAGS]) & (cur->index))
|
||||
puts(cur->desc);
|
||||
break;
|
||||
case T_STR:
|
||||
if (sudo_strtable[cur->index]) {
|
||||
(void) printf(cur->desc, sudo_strtable[cur->index]);
|
||||
if (cur->desc) {
|
||||
switch (cur->type & T_MASK) {
|
||||
case T_FLAG:
|
||||
if (cur->sd_un.flag)
|
||||
puts(cur->desc);
|
||||
break;
|
||||
case T_STR:
|
||||
case T_LOGFAC:
|
||||
case T_LOGPRI:
|
||||
if (cur->sd_un.str) {
|
||||
(void) printf(cur->desc, cur->sd_un.str);
|
||||
putchar('\n');
|
||||
}
|
||||
break;
|
||||
case T_INT:
|
||||
case T_MODE:
|
||||
(void) printf(cur->desc, cur->sd_un.ival);
|
||||
putchar('\n');
|
||||
}
|
||||
break;
|
||||
case T_INT:
|
||||
if (cur->index == I_LOGFAC)
|
||||
(void) printf(cur->desc,
|
||||
num_to_name(sudo_inttable[cur->index], facilities));
|
||||
else if (cur->index == I_GOODPRI || cur->index == I_BADPRI)
|
||||
(void) printf(cur->desc,
|
||||
num_to_name(sudo_inttable[cur->index], priorities));
|
||||
else
|
||||
(void) printf(cur->desc, sudo_inttable[cur->index]);
|
||||
putchar('\n');
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -282,40 +279,24 @@ list_options()
|
||||
|
||||
(void) puts("Available options in a sudoers ``Defaults'' line:\n");
|
||||
for (cur = sudo_defs_table; cur->name; cur++) {
|
||||
switch (cur->type & T_MASK) {
|
||||
case T_FLAG:
|
||||
(void) printf("%s: %s\n", cur->name, cur->desc);
|
||||
break;
|
||||
case T_STR:
|
||||
case T_INT:
|
||||
p = strrchr(cur->desc, ':');
|
||||
if (p)
|
||||
(void) printf("%s: %.*s\n", cur->name, p - cur->desc,
|
||||
cur->desc);
|
||||
else
|
||||
if (cur->name && cur->desc) {
|
||||
switch (cur->type & T_MASK) {
|
||||
case T_FLAG:
|
||||
(void) printf("%s: %s\n", cur->name, cur->desc);
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
p = strrchr(cur->desc, ':');
|
||||
if (p)
|
||||
(void) printf("%s: %.*s\n", cur->name, p - cur->desc,
|
||||
cur->desc);
|
||||
else
|
||||
(void) printf("%s: %s\n", cur->name, cur->desc);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert a syslog number to a name.
|
||||
*/
|
||||
static char *
|
||||
num_to_name(num, table)
|
||||
int num;
|
||||
struct strmap *table;
|
||||
{
|
||||
struct strmap *t;
|
||||
|
||||
for (t = table; t->name; t++)
|
||||
if (t->num == num)
|
||||
return(t->name);
|
||||
|
||||
return("disabled");
|
||||
}
|
||||
|
||||
/*
|
||||
* Sets/clears an entry in the defaults structure
|
||||
* If a variable that takes a value is used in a boolean
|
||||
@@ -344,6 +325,22 @@ set_default(var, val, op)
|
||||
}
|
||||
|
||||
switch (cur->type & T_MASK) {
|
||||
case T_LOGFAC:
|
||||
if (!store_syslogfac(val, cur, op)) {
|
||||
(void) fprintf(stderr,
|
||||
"%s: value '%s' is invalid for option '%s'\n", Argv[0],
|
||||
val, var);
|
||||
return(FALSE);
|
||||
}
|
||||
break;
|
||||
case T_LOGPRI:
|
||||
if (!store_syslogpri(val, cur, op)) {
|
||||
(void) fprintf(stderr,
|
||||
"%s: value '%s' is invalid for option '%s'\n", Argv[0],
|
||||
val, var);
|
||||
return(FALSE);
|
||||
}
|
||||
break;
|
||||
case T_STR:
|
||||
if (!val) {
|
||||
/* Check for bogus boolean usage or lack of a value. */
|
||||
@@ -354,7 +351,7 @@ set_default(var, val, op)
|
||||
return(FALSE);
|
||||
}
|
||||
}
|
||||
if (!cur->store(val, cur->index, op)) {
|
||||
if (!store_str(val, cur, op)) {
|
||||
(void) fprintf(stderr,
|
||||
"%s: value '%s' is invalid for option '%s'\n", Argv[0],
|
||||
val, var);
|
||||
@@ -371,7 +368,24 @@ set_default(var, val, op)
|
||||
return(FALSE);
|
||||
}
|
||||
}
|
||||
if (!cur->store(val, cur->index, op)) {
|
||||
if (!store_int(val, cur, op)) {
|
||||
(void) fprintf(stderr,
|
||||
"%s: value '%s' is invalid for option '%s'\n", Argv[0],
|
||||
val, var);
|
||||
return(FALSE);
|
||||
}
|
||||
break;
|
||||
case T_MODE:
|
||||
if (!val) {
|
||||
/* Check for bogus boolean usage or lack of a value. */
|
||||
if (!(cur->type & T_BOOL) || op != FALSE) {
|
||||
(void) fprintf(stderr,
|
||||
"%s: no value specified for `%s' on line %d\n", Argv[0],
|
||||
var, sudolineno);
|
||||
return(FALSE);
|
||||
}
|
||||
}
|
||||
if (!store_mode(val, cur, op)) {
|
||||
(void) fprintf(stderr,
|
||||
"%s: value '%s' is invalid for option '%s'\n", Argv[0],
|
||||
val, var);
|
||||
@@ -385,10 +399,7 @@ set_default(var, val, op)
|
||||
Argv[0], var, sudolineno);
|
||||
return(FALSE);
|
||||
}
|
||||
if (op == TRUE)
|
||||
sudo_inttable[0] |= cur->index;
|
||||
else
|
||||
sudo_inttable[0] &= ~(cur->index);
|
||||
cur->sd_un.flag = op;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -403,108 +414,108 @@ void
|
||||
init_defaults()
|
||||
{
|
||||
static int firsttime = 1;
|
||||
int i;
|
||||
struct sudo_defs_types *def;
|
||||
|
||||
/* Free any strings that were set. */
|
||||
if (!firsttime) {
|
||||
for (i = 0; i < SUDO_STRTABLE_LAST; i++)
|
||||
if (sudo_strtable[i])
|
||||
free(sudo_strtable[i]);
|
||||
for (def = sudo_defs_table; def->name; def++)
|
||||
switch (def->type & T_MASK) {
|
||||
case T_STR:
|
||||
case T_LOGFAC:
|
||||
case T_LOGPRI:
|
||||
if (def->sd_un.str)
|
||||
free(def->sd_un.str);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
memset(sudo_strtable, 0, sizeof(sudo_strtable));
|
||||
memset(sudo_inttable, 0, sizeof(sudo_inttable));
|
||||
|
||||
/* First initialize the flags. */
|
||||
#ifdef LONG_OTP_PROMPT
|
||||
sudo_inttable[I_FLAGS] |= FL_LONG_OTP_PROMPT;
|
||||
def_flag(I_LONG_OTP_PROMPT) = TRUE;
|
||||
#endif
|
||||
#ifdef IGNORE_DOT_PATH
|
||||
sudo_inttable[I_FLAGS] |= FL_IGNORE_DOT;
|
||||
def_flag(I_IGNORE_DOT) = TRUE;
|
||||
#endif
|
||||
#ifdef ALWAYS_SEND_MAIL
|
||||
sudo_inttable[I_FLAGS] |= FL_MAIL_ALWAYS;
|
||||
def_flag(I_MAIL_ALWAYS) = TRUE;
|
||||
#endif
|
||||
#ifdef SEND_MAIL_WHEN_NO_USER
|
||||
sudo_inttable[I_FLAGS] |= FL_MAIL_IF_NOUSER;
|
||||
def_flag(I_MAIL_IF_NOUSER) = TRUE;
|
||||
#endif
|
||||
#ifdef SEND_MAIL_WHEN_NO_HOST
|
||||
sudo_inttable[I_FLAGS] |= FL_MAIL_IF_NOHOST;
|
||||
def_flag(I_MAIL_IF_NOHOST) = TRUE;
|
||||
#endif
|
||||
#ifdef SEND_MAIL_WHEN_NOT_OK
|
||||
sudo_inttable[I_FLAGS] |= FL_MAIL_IF_NOPERMS;
|
||||
def_flag(I_MAIL_IF_NOPERMS) = TRUE;
|
||||
#endif
|
||||
#ifdef USE_TTY_TICKETS
|
||||
sudo_inttable[I_FLAGS] |= FL_TTY_TICKETS;
|
||||
def_flag(I_TTY_TICKETS) = TRUE;
|
||||
#endif
|
||||
#ifndef NO_LECTURE
|
||||
sudo_inttable[I_FLAGS] |= FL_LECTURE;
|
||||
def_flag(I_LECTURE) = TRUE;
|
||||
#endif
|
||||
#ifndef NO_AUTHENTICATION
|
||||
sudo_inttable[I_FLAGS] |= FL_AUTHENTICATE;
|
||||
def_flag(I_AUTHENTICATE) = TRUE;
|
||||
#endif
|
||||
#ifndef NO_ROOT_SUDO
|
||||
sudo_inttable[I_FLAGS] |= FL_ROOT_SUDO;
|
||||
def_flag(I_ROOT_SUDO) = TRUE;
|
||||
#endif
|
||||
#ifdef HOST_IN_LOG
|
||||
sudo_inttable[I_FLAGS] |= FL_LOG_HOST;
|
||||
def_flag(I_LOG_HOST) = TRUE;
|
||||
#endif
|
||||
#ifdef SHELL_IF_NO_ARGS
|
||||
sudo_inttable[I_FLAGS] |= FL_SHELL_NOARGS;
|
||||
def_flag(I_SHELL_NOARGS) = TRUE;
|
||||
#endif
|
||||
#ifdef SHELL_SETS_HOME
|
||||
sudo_inttable[I_FLAGS] |= FL_SET_HOME;
|
||||
def_flag(I_SET_HOME) = TRUE;
|
||||
#endif
|
||||
#ifndef DONT_LEAK_PATH_INFO
|
||||
sudo_inttable[I_FLAGS] |= FL_PATH_INFO;
|
||||
def_flag(I_PATH_INFO) = TRUE;
|
||||
#endif
|
||||
#ifdef FQDN
|
||||
sudo_inttable[I_FLAGS] |= FL_FQDN;
|
||||
def_flag(I_FQDN) = TRUE;
|
||||
#endif
|
||||
#ifdef USE_INSULTS
|
||||
sudo_inttable[I_FLAGS] |= FL_INSULTS;
|
||||
def_flag(I_INSULTS) = TRUE;
|
||||
#endif
|
||||
|
||||
/* Then initialize the ints. */
|
||||
/* Syslog options need special care since they both strings and ints */
|
||||
#if (LOGGING & SLOG_SYSLOG)
|
||||
sudo_inttable[I_LOGFAC] = LOGFAC;
|
||||
sudo_inttable[I_GOODPRI] = PRI_SUCCESS;
|
||||
sudo_inttable[I_BADPRI] = PRI_FAILURE;
|
||||
#else
|
||||
sudo_inttable[I_LOGFAC] = (unsigned int)-1;
|
||||
(void) store_syslogfac(LOGFAC, &sudo_defs_table[I_LOGFACSTR], TRUE);
|
||||
(void) store_syslogpri(PRI_SUCCESS, &sudo_defs_table[I_GOODPRISTR], TRUE);
|
||||
(void) store_syslogpri(PRI_FAILURE, &sudo_defs_table[I_BADPRISTR], TRUE);
|
||||
#endif
|
||||
|
||||
/* Then initialize the int-like things. */
|
||||
#ifdef SUDO_UMASK
|
||||
sudo_inttable[I_UMASK] = SUDO_UMASK;
|
||||
def_mode(I_UMASK) = SUDO_UMASK;
|
||||
#else
|
||||
sudo_inttable[I_UMASK] = 0777;
|
||||
def_mode(I_UMASK) = 0777;
|
||||
#endif
|
||||
sudo_inttable[I_LOGLEN] = MAXLOGFILELEN;
|
||||
sudo_inttable[I_TS_TIMEOUT] = TIMEOUT;
|
||||
sudo_inttable[I_PW_TIMEOUT] = PASSWORD_TIMEOUT;
|
||||
sudo_inttable[I_PW_TRIES] = TRIES_FOR_PASSWORD;
|
||||
def_ival(I_LOGLEN) = MAXLOGFILELEN;
|
||||
def_ival(I_TS_TIMEOUT) = TIMEOUT;
|
||||
def_ival(I_PW_TIMEOUT) = PASSWORD_TIMEOUT;
|
||||
def_ival(I_PW_TRIES) = TRIES_FOR_PASSWORD;
|
||||
|
||||
/* Finally do the strings */
|
||||
sudo_strtable[I_ALERTMAIL] = estrdup(ALERTMAIL);
|
||||
sudo_strtable[I_MAILSUB] = estrdup(MAILSUBJECT);
|
||||
sudo_strtable[I_BADPASS_MSG] = estrdup(INCORRECT_PASSWORD);
|
||||
sudo_strtable[I_TIMESTAMPDIR] = estrdup(_PATH_SUDO_TIMEDIR);
|
||||
sudo_strtable[I_PASSPROMPT] = estrdup(PASSPROMPT);
|
||||
sudo_strtable[I_RUNAS_DEF] = estrdup(RUNAS_DEFAULT);
|
||||
def_str(I_MAILTO) = estrdup(MAILTO);
|
||||
def_str(I_MAILSUB) = estrdup(MAILSUBJECT);
|
||||
def_str(I_BADPASS_MSG) = estrdup(INCORRECT_PASSWORD);
|
||||
def_str(I_TIMESTAMPDIR) = estrdup(_PATH_SUDO_TIMEDIR);
|
||||
def_str(I_PASSPROMPT) = estrdup(PASSPROMPT);
|
||||
def_str(I_RUNAS_DEF) = estrdup(RUNAS_DEFAULT);
|
||||
#ifdef _PATH_SENDMAIL
|
||||
sudo_strtable[I_MAILERPATH] = estrdup(_PATH_SENDMAIL);
|
||||
def_str(I_MAILERPATH) = estrdup(_PATH_SENDMAIL);
|
||||
def_str(I_MAILERFLAGS) = estrdup("-t");
|
||||
#endif
|
||||
#if (LOGGING & SLOG_FILE)
|
||||
sudo_strtable[I_LOGFILE] = estrdup(_PATH_SUDO_LOGFILE);
|
||||
def_str(I_LOGFILE) = estrdup(_PATH_SUDO_LOGFILE);
|
||||
#endif
|
||||
#ifdef EXEMPTGROUP
|
||||
sudo_strtable[I_EXEMPT_GRP] = estrdup(EXEMPTGROUP);
|
||||
def_str(I_EXEMPT_GRP) = estrdup(EXEMPTGROUP);
|
||||
#endif
|
||||
#ifdef SECURE_PATH
|
||||
sudo_strtable[I_SECURE_PATH] = estrdup(SECURE_PATH);
|
||||
#endif
|
||||
#if 0
|
||||
/* XXX - implement */
|
||||
sudo_strtable[I_MAILERARGS] = estrdup(XXX);
|
||||
def_str(I_SECURE_PATH) = estrdup(SECURE_PATH);
|
||||
#endif
|
||||
|
||||
/*
|
||||
@@ -513,104 +524,122 @@ init_defaults()
|
||||
* value changes we get the change.
|
||||
*/
|
||||
if (user_runas == NULL)
|
||||
user_runas = &sudo_strtable[I_RUNAS_DEF];
|
||||
user_runas = &def_str(I_RUNAS_DEF);
|
||||
|
||||
firsttime = 0;
|
||||
}
|
||||
|
||||
static int
|
||||
store_int(val, index, op)
|
||||
store_int(val, def, op)
|
||||
char *val;
|
||||
int index;
|
||||
struct sudo_defs_types *def;
|
||||
int op;
|
||||
{
|
||||
char *endp;
|
||||
unsigned long ul;
|
||||
|
||||
if (op == FALSE) {
|
||||
sudo_inttable[index] = 0;
|
||||
def->sd_un.ival = 0;
|
||||
} else {
|
||||
ul = strtoul(val, &endp, 10);
|
||||
if (*endp != '\0')
|
||||
return(FALSE);
|
||||
/* XXX - should check against UINT_MAX */
|
||||
sudo_inttable[index] = (unsigned int)ul;
|
||||
def->sd_un.ival = (unsigned int)ul;
|
||||
}
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
static int
|
||||
store_str(val, index, op)
|
||||
store_str(val, def, op)
|
||||
char *val;
|
||||
int index;
|
||||
struct sudo_defs_types *def;
|
||||
int op;
|
||||
{
|
||||
|
||||
if (sudo_strtable[index])
|
||||
free(sudo_strtable[index]);
|
||||
if (def->sd_un.str)
|
||||
free(def->sd_un.str);
|
||||
if (op == FALSE)
|
||||
sudo_strtable[index] = NULL;
|
||||
def->sd_un.str = NULL;
|
||||
else
|
||||
sudo_strtable[index] = estrdup(val);
|
||||
def->sd_un.str = estrdup(val);
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
static int
|
||||
store_syslogfac(val, index, op)
|
||||
store_syslogfac(val, def, op)
|
||||
char *val;
|
||||
int index;
|
||||
struct sudo_defs_types *def;
|
||||
int op;
|
||||
{
|
||||
struct strmap *fac;
|
||||
|
||||
if (op == FALSE) {
|
||||
sudo_inttable[index] = (unsigned int)-1;
|
||||
free(def->sd_un.str);
|
||||
def->sd_un.str = NULL;
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
for (fac = facilities; fac->name && strcmp(val, fac->name); fac++)
|
||||
;
|
||||
if (fac->name == NULL)
|
||||
return(FALSE);
|
||||
sudo_inttable[index] = fac->num;
|
||||
return(FALSE); /* not found */
|
||||
|
||||
/* Store both name and number. */
|
||||
if (def->sd_un.str)
|
||||
free(def->sd_un.str);
|
||||
def->sd_un.str = estrdup(fac->name);
|
||||
sudo_defs_table[I_LOGFAC].sd_un.ival = fac->num;
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
static int
|
||||
store_syslogpri(val, index, op)
|
||||
store_syslogpri(val, def, op)
|
||||
char *val;
|
||||
int index;
|
||||
struct sudo_defs_types *def;
|
||||
int op;
|
||||
{
|
||||
struct strmap *pri;
|
||||
struct sudo_defs_types *idef;
|
||||
|
||||
if (op == FALSE)
|
||||
return(FALSE);
|
||||
if (def == &sudo_defs_table[I_GOODPRISTR])
|
||||
idef = &sudo_defs_table[I_GOODPRI];
|
||||
else if (def == &sudo_defs_table[I_BADPRISTR])
|
||||
idef = &sudo_defs_table[I_BADPRI];
|
||||
else
|
||||
return(FALSE);
|
||||
|
||||
for (pri = priorities; pri->name && strcmp(val, pri->name); pri++)
|
||||
;
|
||||
if (pri->name == NULL)
|
||||
return(FALSE);
|
||||
sudo_inttable[index] = pri->num;
|
||||
return(FALSE); /* not found */
|
||||
|
||||
/* Store both name and number. */
|
||||
if (def->sd_un.str)
|
||||
free(def->sd_un.str);
|
||||
def->sd_un.str = estrdup(pri->name);
|
||||
idef->sd_un.ival = pri->num;
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
static int
|
||||
store_umask(val, index, op)
|
||||
store_mode(val, def, op)
|
||||
char *val;
|
||||
int index;
|
||||
struct sudo_defs_types *def;
|
||||
int op;
|
||||
{
|
||||
char *endp;
|
||||
unsigned long ul;
|
||||
|
||||
if (op == FALSE) {
|
||||
sudo_inttable[index] = 0777;
|
||||
def->sd_un.mode = 0777;
|
||||
} else {
|
||||
ul = strtoul(val, &endp, 8);
|
||||
if (*endp != '\0' || ul >= 0777)
|
||||
return(FALSE);
|
||||
sudo_inttable[index] = (mode_t)ul;
|
||||
def->sd_un.mode = (mode_t)ul;
|
||||
}
|
||||
return(TRUE);
|
||||
}
|
||||
|
Reference in New Issue
Block a user