2
0
mirror of https://github.com/sudo-project/sudo.git synced 2025-09-03 07:45:47 +00:00

Add new check_defaults() function to check (but not update) the

Defaults entries.  Visudo can now use this instead of update_defaults
to check all the defaults regardless instead of just the global
Defaults entries.
This commit is contained in:
Todd C. Miller
2012-08-14 10:45:55 -04:00
parent d764db707a
commit 7aeadbd5b3
3 changed files with 64 additions and 11 deletions

View File

@@ -485,7 +485,7 @@ init_defaults(void)
* Update the defaults based on what was set by sudoers. * Update the defaults based on what was set by sudoers.
* Pass in an OR'd list of which default types to update. * Pass in an OR'd list of which default types to update.
*/ */
int bool
update_defaults(int what) update_defaults(int what)
{ {
struct defaults *def; struct defaults *def;
@@ -528,6 +528,54 @@ update_defaults(int what)
debug_return_bool(rc); debug_return_bool(rc);
} }
/*
* Check the defaults entries without actually setting them.
* Pass in an OR'd list of which default types to check.
*/
bool
check_defaults(int what, bool quiet)
{
struct sudo_defs_types *cur;
struct defaults *def;
bool rc = true;
debug_decl(check_defaults, SUDO_DEBUG_DEFAULTS)
tq_foreach_fwd(&defaults, def) {
switch (def->type) {
case DEFAULTS:
if (!ISSET(what, SETDEF_GENERIC))
continue;
break;
case DEFAULTS_USER:
if (!ISSET(what, SETDEF_USER))
continue;
break;
case DEFAULTS_RUNAS:
if (!ISSET(what, SETDEF_RUNAS))
continue;
break;
case DEFAULTS_HOST:
if (!ISSET(what, SETDEF_HOST))
continue;
break;
case DEFAULTS_CMND:
if (!ISSET(what, SETDEF_CMND))
continue;
break;
}
for (cur = sudo_defs_table; cur->name != NULL; cur++) {
if (strcmp(def->var, cur->name) == 0)
break;
}
if (cur->name == NULL) {
if (!quiet)
warningx(_("unknown defaults entry `%s'"), def->var);
rc = false;
}
}
debug_return_bool(rc);
}
static bool static bool
store_int(char *val, struct sudo_defs_types *def, int op) store_int(char *val, struct sudo_defs_types *def, int op)
{ {

View File

@@ -93,7 +93,7 @@ struct sudo_defs_types {
#define T_PATH 0x200 #define T_PATH 0x200
/* /*
* Argument to update_defaults() * Argument to update_defaults() and check_defaults()
*/ */
#define SETDEF_GENERIC 0x01 #define SETDEF_GENERIC 0x01
#define SETDEF_HOST 0x02 #define SETDEF_HOST 0x02
@@ -107,8 +107,9 @@ struct sudo_defs_types {
*/ */
void dump_default(void); void dump_default(void);
void init_defaults(void); void init_defaults(void);
bool set_default(char *, char *, int); bool set_default(char *var, char *val, int op);
int update_defaults(int); bool update_defaults(int what);
bool check_defaults(int what, bool quiet);
extern struct sudo_defs_types sudo_defs_table[]; extern struct sudo_defs_types sudo_defs_table[];

View File

@@ -500,10 +500,10 @@ reparse_sudoers(char *editor, char *args, bool strict, bool quiet)
} }
fclose(yyin); fclose(yyin);
if (!parse_error) { if (!parse_error) {
if (!update_defaults(SETDEF_GENERIC|SETDEF_HOST|SETDEF_USER) || if (!check_defaults(SETDEF_ALL, quiet) ||
check_aliases(strict, quiet) != 0) { check_aliases(strict, quiet) != 0) {
parse_error = true; parse_error = true;
errorfile = sp->path; errorfile = NULL;
} }
} }
@@ -527,10 +527,11 @@ reparse_sudoers(char *editor, char *args, bool strict, bool quiet)
tq_foreach_fwd(&sudoerslist, sp) { tq_foreach_fwd(&sudoerslist, sp) {
if (errorfile == NULL || strcmp(sp->path, errorfile) == 0) { if (errorfile == NULL || strcmp(sp->path, errorfile) == 0) {
edit_sudoers(sp, editor, args, errorlineno); edit_sudoers(sp, editor, args, errorlineno);
break; if (errorfile != NULL)
break;
} }
} }
if (sp == NULL) { if (errorfile != NULL && sp == NULL) {
errorx(1, _("internal error, unable to find %s in list!"), errorx(1, _("internal error, unable to find %s in list!"),
sudoers); sudoers);
} }
@@ -825,9 +826,12 @@ check_syntax(char *sudoers_path, bool quiet, bool strict, bool oldperms)
parse_error = true; parse_error = true;
errorfile = sudoers_path; errorfile = sudoers_path;
} }
if (!parse_error && check_aliases(strict, quiet) != 0) { if (!parse_error) {
parse_error = true; if (!check_defaults(SETDEF_ALL, quiet) ||
errorfile = sudoers_path; check_aliases(strict, quiet) != 0) {
parse_error = true;
errorfile = NULL;
}
} }
ok = !parse_error; ok = !parse_error;