/*
* Local prototypes.
*/
-static bool store_int(const char *var, union sudo_defs_val *sd_un);
-static bool store_list(const char *var, union sudo_defs_val *sd_un, int op);
-static bool store_mode(const char *var, union sudo_defs_val *sd_un);
-static int store_str(const char *var, union sudo_defs_val *sd_un);
-static bool store_syslogfac(const char *var, union sudo_defs_val *sd_un);
-static bool store_syslogpri(const char *var, union sudo_defs_val *sd_un);
-static bool store_tuple(const char *val, union sudo_defs_val *sd_un, struct def_values *tuple_vals);
-static bool store_uint(const char *var, union sudo_defs_val *sd_un);
-static bool store_float(const char *var, union sudo_defs_val *sd_un);
-static bool list_op(const char *var, size_t, union sudo_defs_val *sd_un, enum list_ops op);
+static bool store_int(const char *str, union sudo_defs_val *sd_un);
+static bool store_list(const char *str, union sudo_defs_val *sd_un, int op);
+static bool store_mode(const char *str, union sudo_defs_val *sd_un);
+static int store_str(const char *str, union sudo_defs_val *sd_un);
+static bool store_syslogfac(const char *str, union sudo_defs_val *sd_un);
+static bool store_syslogpri(const char *str, union sudo_defs_val *sd_un);
+static bool store_tuple(const char *str, union sudo_defs_val *sd_un, struct def_values *tuple_vals);
+static bool store_uint(const char *str, union sudo_defs_val *sd_un);
+static bool store_float(const char *str, union sudo_defs_val *sd_un);
+static bool list_op(const char *str, size_t, union sudo_defs_val *sd_un, enum list_ops op);
static const char *logfac2str(int);
static const char *logpri2str(int);
* Returns true if it matches, else false.
*/
static bool
-default_type_matches(struct defaults *def, int what)
+default_type_matches(struct defaults *d, int what)
{
debug_decl(default_type_matches, SUDOERS_DEBUG_DEFAULTS)
- switch (def->type) {
+ switch (d->type) {
case DEFAULTS:
if (ISSET(what, SETDEF_GENERIC))
debug_return_bool(true);
* Returns true if it matches, else false.
*/
static bool
-default_binding_matches(struct defaults *def, int what)
+default_binding_matches(struct defaults *d, int what)
{
debug_decl(default_binding_matches, SUDOERS_DEBUG_DEFAULTS)
- switch (def->type) {
+ switch (d->type) {
case DEFAULTS:
debug_return_bool(true);
break;
case DEFAULTS_USER:
- if (userlist_matches(sudo_user.pw, def->binding) == ALLOW)
+ if (userlist_matches(sudo_user.pw, d->binding) == ALLOW)
debug_return_bool(true);
break;
case DEFAULTS_RUNAS:
- if (runaslist_matches(def->binding, NULL, NULL, NULL) == ALLOW)
+ if (runaslist_matches(d->binding, NULL, NULL, NULL) == ALLOW)
debug_return_bool(true);
break;
case DEFAULTS_HOST:
- if (hostlist_matches(sudo_user.pw, def->binding) == ALLOW)
+ if (hostlist_matches(sudo_user.pw, d->binding) == ALLOW)
debug_return_bool(true);
break;
case DEFAULTS_CMND:
- if (cmndlist_matches(def->binding) == ALLOW)
+ if (cmndlist_matches(d->binding) == ALLOW)
debug_return_bool(true);
break;
}
bool
update_defaults(int what, bool quiet)
{
- struct defaults *def;
+ struct defaults *d;
bool ret = true;
debug_decl(update_defaults, SUDOERS_DEBUG_DEFAULTS)
/*
* First apply Defaults values marked as early.
*/
- TAILQ_FOREACH(def, &defaults, entries) {
- struct early_default *early = is_early_default(def->var);
+ TAILQ_FOREACH(d, &defaults, entries) {
+ struct early_default *early = is_early_default(d->var);
if (early == NULL)
continue;
- if (!default_type_matches(def, what) ||
- !default_binding_matches(def, what))
+ if (!default_type_matches(d, what) ||
+ !default_binding_matches(d, what))
continue;
- if (!set_early_default(def->var, def->val, def->op, "sudoers", 0, quiet, early))
+ if (!set_early_default(d->var, d->val, d->op, "sudoers", 0, quiet, early))
ret = false;
}
if (!run_early_defaults())
/*
* Then set the rest of the defaults.
*/
- TAILQ_FOREACH(def, &defaults, entries) {
+ TAILQ_FOREACH(d, &defaults, entries) {
/* Skip Defaults marked as early, we already did them. */
- if (is_early_default(def->var))
+ if (is_early_default(d->var))
continue;
- if (!default_type_matches(def, what) ||
- !default_binding_matches(def, what))
+ if (!default_type_matches(d, what) ||
+ !default_binding_matches(d, what))
continue;
- if (!set_default(def->var, def->val, def->op, "sudoers", 0, quiet))
+ if (!set_default(d->var, d->val, d->op, "sudoers", 0, quiet))
ret = false;
}
debug_return_bool(ret);
}
static bool
-store_int(const char *val, union sudo_defs_val *sd_un)
+store_int(const char *str, union sudo_defs_val *sd_un)
{
const char *errstr;
int i;
debug_decl(store_int, SUDOERS_DEBUG_DEFAULTS)
- if (val == NULL) {
+ if (str == NULL) {
sd_un->ival = 0;
} else {
- i = strtonum(val, INT_MIN, INT_MAX, &errstr);
+ i = strtonum(str, INT_MIN, INT_MAX, &errstr);
if (errstr != NULL) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
- "%s: %s", val, errstr);
+ "%s: %s", str, errstr);
debug_return_bool(false);
}
sd_un->ival = i;
}
static bool
-store_uint(const char *val, union sudo_defs_val *sd_un)
+store_uint(const char *str, union sudo_defs_val *sd_un)
{
const char *errstr;
unsigned int u;
debug_decl(store_uint, SUDOERS_DEBUG_DEFAULTS)
- if (val == NULL) {
+ if (str == NULL) {
sd_un->uival = 0;
} else {
- u = strtonum(val, 0, UINT_MAX, &errstr);
+ u = strtonum(str, 0, UINT_MAX, &errstr);
if (errstr != NULL) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
- "%s: %s", val, errstr);
+ "%s: %s", str, errstr);
debug_return_bool(false);
}
sd_un->uival = u;
}
static bool
-store_float(const char *val, union sudo_defs_val *sd_un)
+store_float(const char *str, union sudo_defs_val *sd_un)
{
char *endp;
double d;
debug_decl(store_float, SUDOERS_DEBUG_DEFAULTS)
- if (val == NULL) {
+ if (str == NULL) {
sd_un->fval = 0.0;
} else {
- d = strtod(val, &endp);
+ d = strtod(str, &endp);
if (*endp != '\0')
debug_return_bool(false);
/* XXX - should check against HUGE_VAL */
}
static bool
-store_tuple(const char *val, union sudo_defs_val *sd_un,
+store_tuple(const char *str, union sudo_defs_val *sd_un,
struct def_values *tuple_vals)
{
struct def_values *v;
* For negation to work the first element of enum def_tuple
* must be equivalent to boolean false.
*/
- if (val == NULL) {
+ if (str == NULL) {
sd_un->ival = 0;
} else {
for (v = tuple_vals; v->sval != NULL; v++) {
- if (strcmp(v->sval, val) == 0) {
+ if (strcmp(v->sval, str) == 0) {
sd_un->tuple = v->nval;
break;
}
}
static int
-store_str(const char *val, union sudo_defs_val *sd_un)
+store_str(const char *str, union sudo_defs_val *sd_un)
{
debug_decl(store_str, SUDOERS_DEBUG_DEFAULTS)
free(sd_un->str);
- if (val == NULL) {
+ if (str == NULL) {
sd_un->str = NULL;
} else {
- if ((sd_un->str = strdup(val)) == NULL) {
+ if ((sd_un->str = strdup(str)) == NULL) {
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
debug_return_int(-1);
}
}
static bool
-store_syslogfac(const char *val, union sudo_defs_val *sd_un)
+store_syslogfac(const char *str, union sudo_defs_val *sd_un)
{
struct strmap *fac;
debug_decl(store_syslogfac, SUDOERS_DEBUG_DEFAULTS)
- if (val == NULL) {
+ if (str == NULL) {
sd_un->ival = false;
debug_return_bool(true);
}
for (fac = facilities; fac->name != NULL; fac++) {
- if (strcmp(val, fac->name) != 0) {
+ if (strcmp(str, fac->name) != 0) {
sd_un->ival = fac->num;
debug_return_bool(true);
}
}
static bool
-store_syslogpri(const char *val, union sudo_defs_val *sd_un)
+store_syslogpri(const char *str, union sudo_defs_val *sd_un)
{
struct strmap *pri;
debug_decl(store_syslogpri, SUDOERS_DEBUG_DEFAULTS)
- if (val == NULL)
+ if (str == NULL)
debug_return_bool(false);
for (pri = priorities; pri->name != NULL; pri++) {
- if (strcmp(val, pri->name) != 0) {
+ if (strcmp(str, pri->name) != 0) {
sd_un->ival = pri->num;
debug_return_bool(true);
}
}
static bool
-store_mode(const char *val, union sudo_defs_val *sd_un)
+store_mode(const char *str, union sudo_defs_val *sd_un)
{
mode_t mode;
const char *errstr;
debug_decl(store_mode, SUDOERS_DEBUG_DEFAULTS)
- if (val == NULL) {
+ if (str == NULL) {
sd_un->mode = 0777;
} else {
- mode = sudo_strtomode(val, &errstr);
+ mode = sudo_strtomode(str, &errstr);
if (errstr != NULL) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
- "%s is %s", val, errstr);
+ "%s is %s", str, errstr);
debug_return_bool(false);
}
sd_un->mode = mode;
}
static bool
-list_op(const char *val, size_t len, union sudo_defs_val *sd_un,
+list_op(const char *str, size_t len, union sudo_defs_val *sd_un,
enum list_ops op)
{
struct list_member *cur, *prev = NULL;
}
SLIST_FOREACH(cur, &sd_un->list, entries) {
- if ((strncmp(cur->value, val, len) == 0 && cur->value[len] == '\0')) {
+ if ((strncmp(cur->value, str, len) == 0 && cur->value[len] == '\0')) {
if (op == add)
debug_return_bool(true); /* already exists */
/* Add new node to the head of the list. */
if (op == add) {
cur = calloc(1, sizeof(struct list_member));
- if (cur == NULL || (cur->value = strndup(val, len)) == NULL) {
+ if (cur == NULL || (cur->value = strndup(str, len)) == NULL) {
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
free(cur);
debug_return_bool(false);