2
0
mirror of https://github.com/sudo-project/sudo.git synced 2025-09-03 15:55:40 +00:00

Move update_defaults into defaults.c and call it properly from

visudo and testsudoers.
This commit is contained in:
Todd C. Miller
2008-11-02 19:06:37 +00:00
parent 3cb9d538f9
commit f201db90f3
4 changed files with 47 additions and 66 deletions

View File

@@ -486,6 +486,52 @@ init_defaults()
firsttime = 0; firsttime = 0;
} }
/*
* Update the defaults based on what was set by sudoers.
* Pass in a an OR'd list of which default types to update.
*/
int
update_defaults(what)
int what;
{
struct defaults *def;
tq_foreach_fwd(&defaults, def) {
switch (def->type) {
case DEFAULTS:
if (ISSET(what, SETDEF_GENERIC) &&
!set_default(def->var, def->val, def->op))
return(FALSE);
break;
case DEFAULTS_USER:
if (ISSET(what, SETDEF_USER) &&
userlist_matches(sudo_user.pw, &def->binding) == ALLOW &&
!set_default(def->var, def->val, def->op))
return(FALSE);
break;
case DEFAULTS_RUNAS:
if (ISSET(what, SETDEF_RUNAS) &&
runaslist_matches(&def->binding, NULL) == ALLOW &&
!set_default(def->var, def->val, def->op))
return(FALSE);
break;
case DEFAULTS_HOST:
if (ISSET(what, SETDEF_HOST) &&
hostlist_matches(&def->binding) == ALLOW &&
!set_default(def->var, def->val, def->op))
return(FALSE);
break;
case DEFAULTS_CMND:
if (ISSET(what, SETDEF_CMND) &&
cmndlist_matches(&def->binding) == ALLOW &&
!set_default(def->var, def->val, def->op))
return(FALSE);
break;
}
}
return(TRUE);
}
static int static int
store_int(val, def, op) store_int(val, def, op)
char *val; char *val;

48
parse.c
View File

@@ -127,54 +127,6 @@ sudo_file_parse(nss)
return(0); return(0);
} }
/*
* Update the defaults based on what was set by sudoers.
* If skip_cmnd is 1, skip DEFAULTS_CMND, if it is 0, skip all others.
* Returns TRUE on success and FALSE on failure.
* XXX - move to defaults.c or match.c
*/
int
update_defaults(what)
int what;
{
struct defaults *def;
tq_foreach_fwd(&defaults, def) {
switch (def->type) {
case DEFAULTS:
if (ISSET(what, SETDEF_GENERIC) &&
!set_default(def->var, def->val, def->op))
return(FALSE);
break;
case DEFAULTS_USER:
if (ISSET(what, SETDEF_USER) &&
userlist_matches(sudo_user.pw, &def->binding) == ALLOW &&
!set_default(def->var, def->val, def->op))
return(FALSE);
break;
case DEFAULTS_RUNAS:
if (ISSET(what, SETDEF_RUNAS) &&
runaslist_matches(&def->binding, NULL) == ALLOW &&
!set_default(def->var, def->val, def->op))
return(FALSE);
break;
case DEFAULTS_HOST:
if (ISSET(what, SETDEF_HOST) &&
hostlist_matches(&def->binding) == ALLOW &&
!set_default(def->var, def->val, def->op))
return(FALSE);
break;
case DEFAULTS_CMND:
if (ISSET(what, SETDEF_CMND) &&
cmndlist_matches(&def->binding) == ALLOW &&
!set_default(def->var, def->val, def->op))
return(FALSE);
break;
}
}
return(TRUE);
}
/* /*
* Wrapper around update_defaults() for nsswitch code. * Wrapper around update_defaults() for nsswitch code.
*/ */

View File

@@ -336,14 +336,6 @@ set_runasgr(group)
} }
} }
/* XXX - sanity check defaults settings */
int
update_defaults(what)
int what;
{
return(TRUE);
}
void void
sudo_setspent() sudo_setspent()
{ {

View File

@@ -208,7 +208,7 @@ main(argc, argv)
error(1, "%s", sudoers_path); error(1, "%s", sudoers_path);
init_parser(sudoers_path, 0); init_parser(sudoers_path, 0);
yyparse(); yyparse();
(void) update_defaults(SETDEF_ALL & ~SETDEF_CMND); (void) update_defaults(SETDEF_GENERIC|SETDEF_HOST|SETDEF_USER);
editor = get_editor(&args); editor = get_editor(&args);
@@ -564,15 +564,6 @@ user_is_exempt()
return(FALSE); return(FALSE);
} }
/* STUB */
/* XXX - parse defaults to get editor and env_editor values */
int
update_defaults(what)
int what;
{
return(TRUE);
}
/* STUB */ /* STUB */
void void
sudo_setspent() sudo_setspent()