2
0
mirror of https://github.com/sudo-project/sudo.git synced 2025-08-31 14:25:15 +00:00

Add parser_warnx() and parser_vwarnx() that displays file:line:col

Used by defaults.c and check_aliases.c.
This commit is contained in:
Todd C. Miller
2023-09-18 12:42:51 -06:00
parent 3a77314373
commit e28dc0f275
6 changed files with 131 additions and 84 deletions

View File

@@ -73,7 +73,6 @@ static bool store_timespec(const char *str, struct sudo_defs_types *def);
static bool store_rlimit(const char *str, struct sudo_defs_types *def);
static bool list_op(const char *str, size_t, struct list_members *list, enum list_ops op);
static bool valid_path(const struct sudoers_context *ctx, struct sudo_defs_types *def, const char *val, const char *file, int line, int column, bool quiet);
static bool defaults_warnx(const struct sudoers_context *ctx, const char *file, int line, int column, bool quiet, const char * restrict fmt, ...) sudo_printflike(6, 7);
/*
* Table describing compile-time and run-time options.
@@ -172,6 +171,21 @@ dump_defaults(void)
debug_return;
}
static bool
defaults_warnx(const struct sudoers_context *ctx, const char *file, int line,
int column, bool quiet, const char * restrict fmt, ...)
{
va_list ap;
bool ret;
debug_decl(defaults_warnx, SUDOERS_DEBUG_DEFAULTS);
va_start(ap, fmt);
ret = parser_vwarnx(ctx, file, line, column, true, quiet, fmt, ap);
va_end(ap);
debug_return_bool(ret);
}
/*
* Find the index of the specified Defaults name in sudo_defs_table[]
* On success, returns the matching index or -1 on failure.
@@ -1262,41 +1276,3 @@ cb_passprompt_regex(struct sudoers_context *ctx, const char *file,
debug_return_bool(true);
}
static bool
defaults_warnx(const struct sudoers_context *ctx, const char *file, int line,
int column, bool quiet, const char * restrict fmt, ...)
{
bool ret = true;
va_list ap;
debug_decl(defaults_warnx, SUDOERS_DEBUG_DEFAULTS);
if (sudoers_error_hook != NULL) {
va_start(ap, fmt);
ret = sudoers_error_hook(ctx, file, line, column, fmt, ap);
va_end(ap);
}
if (!quiet) {
int oldlocale;
char *errstr;
sudoers_setlocale(SUDOERS_LOCALE_USER, &oldlocale);
va_start(ap, fmt);
if (vasprintf(&errstr, _(fmt), ap) == -1) {
errstr = NULL;
ret = false;
} else if (line > 0) {
sudo_printf(SUDO_CONV_ERROR_MSG, _("%s:%d:%d: %s\n"), file,
line, column, errstr);
} else {
sudo_printf(SUDO_CONV_ERROR_MSG, _("%s: %s\n"), file, errstr);
}
va_end(ap);
sudoers_setlocale(oldlocale, NULL);
free(errstr);
}
debug_return_bool(ret);
}