In the plugin registers with the debug framework at open time, the
sudo front-end will now set the default debug instance appropriately before calling into the plugin. This means the plugin no longer needs to do the sudo_debug_set_default_instance() dance.
This commit is contained in:
@@ -338,7 +338,6 @@ set_debugging(const char *conf_file)
|
||||
struct plugin_info *plugin_info;
|
||||
const char *progname;
|
||||
size_t prognamelen;
|
||||
int instance;
|
||||
debug_decl(main, SUDO_DEBUG_UTIL, SUDO_DEBUG_INSTANCE_DEFAULT)
|
||||
|
||||
progname = getprogname();
|
||||
@@ -352,10 +351,7 @@ set_debugging(const char *conf_file)
|
||||
* Register debug instance for the main program, making it
|
||||
* the default instance if one is not already set.
|
||||
*/
|
||||
instance = sudo_debug_register(progname, NULL, NULL,
|
||||
&debug_spec->debug_files);
|
||||
if (sudo_debug_get_default_instance() == SUDO_DEBUG_INSTANCE_INITIALIZER)
|
||||
sudo_debug_set_default_instance(instance);
|
||||
sudo_debug_register(progname, NULL, NULL, &debug_spec->debug_files);
|
||||
sudo_debug_enter(__func__, __FILE__, __LINE__, sudo_debug_subsys);
|
||||
continue;
|
||||
}
|
||||
|
@@ -310,6 +310,10 @@ sudo_debug_register(const char *program, const char *const subsystems[],
|
||||
SLIST_INSERT_HEAD(&instance->outputs, output, entries);
|
||||
}
|
||||
|
||||
/* Set default instance if not already set. */
|
||||
if (sudo_debug_default_instance == -1)
|
||||
sudo_debug_default_instance = idx;
|
||||
|
||||
/* Stash the pid string so we only have to format it once. */
|
||||
if (sudo_debug_pidlen == 0) {
|
||||
(void)snprintf(sudo_debug_pidstr, sizeof(sudo_debug_pidstr), "[%d] ",
|
||||
|
@@ -573,7 +573,7 @@ sudoers_io_open(unsigned int version, sudo_conv_t conversation,
|
||||
char * const *cur;
|
||||
const char *plugin_path = NULL;
|
||||
size_t len;
|
||||
int i, prev_instance, rval = -1;
|
||||
int i, rval = -1;
|
||||
debug_decl(sudoers_io_open, SUDOERS_DEBUG_PLUGIN, sudoers_debug_instance)
|
||||
|
||||
sudo_conv = conversation;
|
||||
@@ -583,8 +583,6 @@ sudoers_io_open(unsigned int version, sudo_conv_t conversation,
|
||||
if (argc == 0)
|
||||
debug_return_bool(true);
|
||||
|
||||
prev_instance = sudo_debug_set_default_instance(sudoers_debug_instance);
|
||||
|
||||
memset(&details, 0, sizeof(details));
|
||||
|
||||
bindtextdomain("sudoers", LOCALEDIR);
|
||||
@@ -674,19 +672,15 @@ done:
|
||||
sudo_gr_delref(details.runas_gr);
|
||||
sudo_endgrent();
|
||||
|
||||
sudo_debug_set_default_instance(prev_instance);
|
||||
|
||||
debug_return_bool(rval);
|
||||
}
|
||||
|
||||
static void
|
||||
sudoers_io_close(int exit_status, int error)
|
||||
{
|
||||
int i, prev_instance;
|
||||
int i;
|
||||
debug_decl(sudoers_io_close, SUDOERS_DEBUG_PLUGIN, sudoers_debug_instance)
|
||||
|
||||
prev_instance = sudo_debug_set_default_instance(sudoers_debug_instance);
|
||||
|
||||
for (i = 0; i < IOFD_MAX; i++) {
|
||||
if (io_log_files[i].fd.v == NULL)
|
||||
continue;
|
||||
@@ -697,7 +691,6 @@ sudoers_io_close(int exit_status, int error)
|
||||
#endif
|
||||
fclose(io_log_files[i].fd.f);
|
||||
}
|
||||
sudo_debug_set_default_instance(prev_instance);
|
||||
|
||||
sudo_debug_exit(__func__, __FILE__, __LINE__, sudo_debug_subsys);
|
||||
if (sudoers_debug_instance != SUDO_DEBUG_INSTANCE_INITIALIZER) {
|
||||
@@ -711,16 +704,11 @@ sudoers_io_close(int exit_status, int error)
|
||||
static int
|
||||
sudoers_io_version(int verbose)
|
||||
{
|
||||
int prev_instance;
|
||||
debug_decl(sudoers_io_version, SUDOERS_DEBUG_PLUGIN, sudoers_debug_instance)
|
||||
|
||||
prev_instance = sudo_debug_set_default_instance(sudoers_debug_instance);
|
||||
|
||||
sudo_printf(SUDO_CONV_INFO_MSG, "Sudoers I/O plugin version %s\n",
|
||||
PACKAGE_VERSION);
|
||||
|
||||
sudo_debug_set_default_instance(prev_instance);
|
||||
|
||||
debug_return_bool(true);
|
||||
}
|
||||
|
||||
@@ -731,11 +719,9 @@ static int
|
||||
sudoers_io_log(const char *buf, unsigned int len, int idx)
|
||||
{
|
||||
struct timeval now, delay;
|
||||
int prev_instance, rval = true;
|
||||
int rval = true;
|
||||
debug_decl(sudoers_io_version, SUDOERS_DEBUG_PLUGIN, sudoers_debug_instance)
|
||||
|
||||
prev_instance = sudo_debug_set_default_instance(sudoers_debug_instance);
|
||||
|
||||
gettimeofday(&now, NULL);
|
||||
|
||||
#ifdef HAVE_ZLIB_H
|
||||
@@ -764,8 +750,6 @@ sudoers_io_log(const char *buf, unsigned int len, int idx)
|
||||
last_time.tv_sec = now.tv_sec;
|
||||
last_time.tv_usec = now.tv_usec;
|
||||
|
||||
sudo_debug_set_default_instance(prev_instance);
|
||||
|
||||
debug_return_bool(rval);
|
||||
}
|
||||
|
||||
|
@@ -374,7 +374,7 @@ sudoers_policy_deserialize_info(void *v, char **runas_user, char **runas_group)
|
||||
user_umask = umask(SUDO_UMASK);
|
||||
umask(user_umask);
|
||||
|
||||
/* Setup debugging if indicated. */
|
||||
/* Setup debugging if indicated. (XXX - do earlier) */
|
||||
sudoers_debug_register(&debug_files, plugin_path);
|
||||
|
||||
/* Dump settings and user info (XXX - plugin args) */
|
||||
@@ -538,7 +538,6 @@ sudoers_policy_open(unsigned int version, sudo_conv_t conversation,
|
||||
char * const user_info[], char * const envp[], char * const args[])
|
||||
{
|
||||
struct sudoers_policy_open_info info;
|
||||
int prev_instance, rval;
|
||||
debug_decl(sudoers_policy_open, SUDOERS_DEBUG_PLUGIN, sudoers_debug_instance)
|
||||
|
||||
sudo_version = version;
|
||||
@@ -549,26 +548,18 @@ sudoers_policy_open(unsigned int version, sudo_conv_t conversation,
|
||||
if (sudo_version < SUDO_API_MKVERSION(1, 2))
|
||||
args = NULL;
|
||||
|
||||
prev_instance = sudo_debug_set_default_instance(sudoers_debug_instance);
|
||||
|
||||
/* Call the sudoers init function. */
|
||||
info.settings = settings;
|
||||
info.user_info = user_info;
|
||||
info.plugin_args = args;
|
||||
rval = sudoers_policy_init(&info, envp);
|
||||
|
||||
sudo_debug_set_default_instance(prev_instance);
|
||||
debug_return_bool(rval);
|
||||
debug_return_bool(sudoers_policy_init(&info, envp));
|
||||
}
|
||||
|
||||
static void
|
||||
sudoers_policy_close(int exit_status, int error_code)
|
||||
{
|
||||
int prev_instance;
|
||||
debug_decl(sudoers_policy_close, SUDOERS_DEBUG_PLUGIN, sudoers_debug_instance)
|
||||
|
||||
prev_instance = sudo_debug_set_default_instance(sudoers_debug_instance);
|
||||
|
||||
/* We do not currently log the exit status. */
|
||||
if (error_code) {
|
||||
errno = error_code;
|
||||
@@ -598,7 +589,6 @@ sudoers_policy_close(int exit_status, int error_code)
|
||||
}
|
||||
sudo_efree(user_gids);
|
||||
user_gids = NULL;
|
||||
sudo_debug_set_default_instance(prev_instance);
|
||||
|
||||
sudo_debug_exit(__func__, __FILE__, __LINE__, sudo_debug_subsys);
|
||||
if (sudoers_debug_instance != SUDO_DEBUG_INSTANCE_INITIALIZER) {
|
||||
@@ -617,18 +607,13 @@ sudoers_policy_close(int exit_status, int error_code)
|
||||
static int
|
||||
sudoers_policy_init_session(struct passwd *pwd, char **user_env[])
|
||||
{
|
||||
int prev_instance, rval;
|
||||
debug_decl(sudoers_policy_init_session, SUDOERS_DEBUG_PLUGIN, sudoers_debug_instance)
|
||||
|
||||
prev_instance = sudo_debug_set_default_instance(sudoers_debug_instance);
|
||||
|
||||
/* user_env is only specified for API version 1.2 and higher. */
|
||||
if (sudo_version < SUDO_API_MKVERSION(1, 2))
|
||||
user_env = NULL;
|
||||
|
||||
rval = sudo_auth_begin_session(pwd, user_env);
|
||||
sudo_debug_set_default_instance(prev_instance);
|
||||
debug_return_bool(rval);
|
||||
debug_return_bool(sudo_auth_begin_session(pwd, user_env));
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -636,10 +621,9 @@ sudoers_policy_check(int argc, char * const argv[], char *env_add[],
|
||||
char **command_infop[], char **argv_out[], char **user_env_out[])
|
||||
{
|
||||
struct sudoers_exec_args exec_args;
|
||||
int prev_instance, rval;
|
||||
int rval;
|
||||
debug_decl(sudoers_policy_check, SUDOERS_DEBUG_PLUGIN, sudoers_debug_instance)
|
||||
|
||||
prev_instance = sudo_debug_set_default_instance(sudoers_debug_instance);
|
||||
if (!ISSET(sudo_mode, MODE_EDIT))
|
||||
SET(sudo_mode, MODE_RUN);
|
||||
|
||||
@@ -654,37 +638,28 @@ sudoers_policy_check(int argc, char * const argv[], char *env_add[],
|
||||
!sudo_auth_needs_end_session())
|
||||
sudoers_policy.close = NULL;
|
||||
}
|
||||
sudo_debug_set_default_instance(prev_instance);
|
||||
debug_return_bool(rval);
|
||||
}
|
||||
|
||||
static int
|
||||
sudoers_policy_validate(void)
|
||||
{
|
||||
int prev_instance, rval;
|
||||
debug_decl(sudoers_policy_validate, SUDOERS_DEBUG_PLUGIN, sudoers_debug_instance)
|
||||
|
||||
prev_instance = sudo_debug_set_default_instance(sudoers_debug_instance);
|
||||
user_cmnd = "validate";
|
||||
SET(sudo_mode, MODE_VALIDATE);
|
||||
|
||||
rval = sudoers_policy_main(0, NULL, I_VERIFYPW, NULL, NULL);
|
||||
sudo_debug_set_default_instance(prev_instance);
|
||||
debug_return_bool(rval);
|
||||
debug_return_bool(sudoers_policy_main(0, NULL, I_VERIFYPW, NULL, NULL));
|
||||
}
|
||||
|
||||
static void
|
||||
sudoers_policy_invalidate(int remove)
|
||||
{
|
||||
int prev_instance;
|
||||
debug_decl(sudoers_policy_invalidate, SUDOERS_DEBUG_PLUGIN, sudoers_debug_instance)
|
||||
|
||||
prev_instance = sudo_debug_set_default_instance(sudoers_debug_instance);
|
||||
|
||||
user_cmnd = "kill";
|
||||
remove_timestamp(remove);
|
||||
sudoers_cleanup();
|
||||
sudo_debug_set_default_instance(prev_instance);
|
||||
|
||||
debug_return;
|
||||
}
|
||||
@@ -693,11 +668,9 @@ static int
|
||||
sudoers_policy_list(int argc, char * const argv[], int verbose,
|
||||
const char *list_user)
|
||||
{
|
||||
int prev_instance, rval = -1;
|
||||
int rval;
|
||||
debug_decl(sudoers_policy_list, SUDOERS_DEBUG_PLUGIN, sudoers_debug_instance)
|
||||
|
||||
prev_instance = sudo_debug_set_default_instance(sudoers_debug_instance);
|
||||
|
||||
user_cmnd = "list";
|
||||
if (argc)
|
||||
SET(sudo_mode, MODE_CHECK);
|
||||
@@ -709,7 +682,7 @@ sudoers_policy_list(int argc, char * const argv[], int verbose,
|
||||
list_pw = sudo_getpwnam(list_user);
|
||||
if (list_pw == NULL) {
|
||||
sudo_warnx(U_("unknown user: %s"), list_user);
|
||||
goto done;
|
||||
debug_return_bool(-1);
|
||||
}
|
||||
}
|
||||
rval = sudoers_policy_main(argc, argv, I_LISTPW, NULL, NULL);
|
||||
@@ -718,19 +691,14 @@ sudoers_policy_list(int argc, char * const argv[], int verbose,
|
||||
list_pw = NULL;
|
||||
}
|
||||
|
||||
done:
|
||||
sudo_debug_set_default_instance(prev_instance);
|
||||
debug_return_bool(rval);
|
||||
}
|
||||
|
||||
static int
|
||||
sudoers_policy_version(int verbose)
|
||||
{
|
||||
int prev_instance;
|
||||
debug_decl(sudoers_policy_version, SUDOERS_DEBUG_PLUGIN, sudoers_debug_instance)
|
||||
|
||||
prev_instance = sudo_debug_set_default_instance(sudoers_debug_instance);
|
||||
|
||||
sudo_printf(SUDO_CONV_INFO_MSG, _("Sudoers policy plugin version %s\n"),
|
||||
PACKAGE_VERSION);
|
||||
sudo_printf(SUDO_CONV_INFO_MSG, _("Sudoers file grammar version %d\n"),
|
||||
@@ -753,18 +721,17 @@ sudoers_policy_version(int verbose)
|
||||
sudo_printf(SUDO_CONV_INFO_MSG, "\n");
|
||||
}
|
||||
}
|
||||
sudo_debug_set_default_instance(prev_instance);
|
||||
debug_return_bool(true);
|
||||
}
|
||||
|
||||
/*
|
||||
* Register environment function hooks.
|
||||
* Note that we have not registered sudoers with the debug subsystem yet.
|
||||
*/
|
||||
static void
|
||||
sudoers_policy_register_hooks(int version, int (*register_hook)(struct sudo_hook *hook))
|
||||
{
|
||||
struct sudo_hook hook;
|
||||
int prev_instance;
|
||||
debug_decl(sudoers_policy_register_hooks, SUDOERS_DEBUG_PLUGIN, sudoers_debug_instance)
|
||||
|
||||
prev_instance = sudo_debug_set_default_instance(sudoers_debug_instance);
|
||||
|
||||
memset(&hook, 0, sizeof(hook));
|
||||
hook.hook_version = SUDO_HOOK_VERSION;
|
||||
@@ -784,8 +751,6 @@ sudoers_policy_register_hooks(int version, int (*register_hook)(struct sudo_hook
|
||||
hook.hook_type = SUDO_HOOK_PUTENV;
|
||||
hook.hook_fn = sudoers_hook_putenv;
|
||||
register_hook(&hook);
|
||||
|
||||
sudo_debug_set_default_instance(prev_instance);
|
||||
}
|
||||
|
||||
__dso_public struct policy_plugin sudoers_policy = {
|
||||
|
@@ -218,7 +218,10 @@ log_ttyin(const char *buf, unsigned int n, struct io_buffer *iob)
|
||||
sigprocmask(SIG_BLOCK, &ttyblock, &omask);
|
||||
TAILQ_FOREACH(plugin, &io_plugins, entries) {
|
||||
if (plugin->u.io->log_ttyin) {
|
||||
int rc = plugin->u.io->log_ttyin(buf, n);
|
||||
int rc;
|
||||
|
||||
sudo_debug_set_default_instance(plugin->debug_instance);
|
||||
rc = plugin->u.io->log_ttyin(buf, n);
|
||||
if (rc <= 0) {
|
||||
if (rc < 0) {
|
||||
/* Error: disable plugin's I/O function. */
|
||||
@@ -229,6 +232,7 @@ log_ttyin(const char *buf, unsigned int n, struct io_buffer *iob)
|
||||
}
|
||||
}
|
||||
}
|
||||
sudo_debug_set_default_instance(sudo_debug_instance);
|
||||
sigprocmask(SIG_SETMASK, &omask, NULL);
|
||||
|
||||
debug_return_bool(rval);
|
||||
@@ -246,7 +250,10 @@ log_stdin(const char *buf, unsigned int n, struct io_buffer *iob)
|
||||
sigprocmask(SIG_BLOCK, &ttyblock, &omask);
|
||||
TAILQ_FOREACH(plugin, &io_plugins, entries) {
|
||||
if (plugin->u.io->log_stdin) {
|
||||
int rc = plugin->u.io->log_stdin(buf, n);
|
||||
int rc;
|
||||
|
||||
sudo_debug_set_default_instance(plugin->debug_instance);
|
||||
rc = plugin->u.io->log_stdin(buf, n);
|
||||
if (rc <= 0) {
|
||||
if (rc < 0) {
|
||||
/* Error: disable plugin's I/O function. */
|
||||
@@ -257,6 +264,7 @@ log_stdin(const char *buf, unsigned int n, struct io_buffer *iob)
|
||||
}
|
||||
}
|
||||
}
|
||||
sudo_debug_set_default_instance(sudo_debug_instance);
|
||||
sigprocmask(SIG_SETMASK, &omask, NULL);
|
||||
|
||||
debug_return_bool(rval);
|
||||
@@ -274,7 +282,10 @@ log_ttyout(const char *buf, unsigned int n, struct io_buffer *iob)
|
||||
sigprocmask(SIG_BLOCK, &ttyblock, &omask);
|
||||
TAILQ_FOREACH(plugin, &io_plugins, entries) {
|
||||
if (plugin->u.io->log_ttyout) {
|
||||
int rc = plugin->u.io->log_ttyout(buf, n);
|
||||
int rc;
|
||||
|
||||
sudo_debug_set_default_instance(plugin->debug_instance);
|
||||
rc = plugin->u.io->log_ttyout(buf, n);
|
||||
if (rc <= 0) {
|
||||
if (rc < 0) {
|
||||
/* Error: disable plugin's I/O function. */
|
||||
@@ -285,6 +296,7 @@ log_ttyout(const char *buf, unsigned int n, struct io_buffer *iob)
|
||||
}
|
||||
}
|
||||
}
|
||||
sudo_debug_set_default_instance(sudo_debug_instance);
|
||||
if (!rval) {
|
||||
/*
|
||||
* I/O plugin rejected the output, delete the write event
|
||||
@@ -314,7 +326,10 @@ log_stdout(const char *buf, unsigned int n, struct io_buffer *iob)
|
||||
sigprocmask(SIG_BLOCK, &ttyblock, &omask);
|
||||
TAILQ_FOREACH(plugin, &io_plugins, entries) {
|
||||
if (plugin->u.io->log_stdout) {
|
||||
int rc = plugin->u.io->log_stdout(buf, n);
|
||||
int rc;
|
||||
|
||||
sudo_debug_set_default_instance(plugin->debug_instance);
|
||||
rc = plugin->u.io->log_stdout(buf, n);
|
||||
if (rc <= 0) {
|
||||
if (rc < 0) {
|
||||
/* Error: disable plugin's I/O function. */
|
||||
@@ -325,6 +340,7 @@ log_stdout(const char *buf, unsigned int n, struct io_buffer *iob)
|
||||
}
|
||||
}
|
||||
}
|
||||
sudo_debug_set_default_instance(sudo_debug_instance);
|
||||
if (!rval) {
|
||||
/*
|
||||
* I/O plugin rejected the output, delete the write event
|
||||
@@ -354,7 +370,10 @@ log_stderr(const char *buf, unsigned int n, struct io_buffer *iob)
|
||||
sigprocmask(SIG_BLOCK, &ttyblock, &omask);
|
||||
TAILQ_FOREACH(plugin, &io_plugins, entries) {
|
||||
if (plugin->u.io->log_stderr) {
|
||||
int rc = plugin->u.io->log_stderr(buf, n);
|
||||
int rc;
|
||||
|
||||
sudo_debug_set_default_instance(plugin->debug_instance);
|
||||
rc = plugin->u.io->log_stderr(buf, n);
|
||||
if (rc <= 0) {
|
||||
if (rc < 0) {
|
||||
/* Error: disable plugin's I/O function. */
|
||||
@@ -365,6 +384,7 @@ log_stderr(const char *buf, unsigned int n, struct io_buffer *iob)
|
||||
}
|
||||
}
|
||||
}
|
||||
sudo_debug_set_default_instance(sudo_debug_instance);
|
||||
if (!rval) {
|
||||
/*
|
||||
* I/O plugin rejected the output, delete the write event
|
||||
|
@@ -238,6 +238,7 @@ sudo_load_plugin(struct plugin_container *policy_plugin,
|
||||
policy_plugin->path = sudo_estrdup(path);
|
||||
policy_plugin->name = info->symbol_name;
|
||||
policy_plugin->options = info->options;
|
||||
policy_plugin->debug_instance = SUDO_DEBUG_INSTANCE_INITIALIZER;
|
||||
policy_plugin->u.generic = plugin;
|
||||
TAILQ_INIT(&policy_plugin->debug_files);
|
||||
TAILQ_SWAP(&policy_plugin->debug_files, &info->debug_files,
|
||||
@@ -260,6 +261,7 @@ sudo_load_plugin(struct plugin_container *policy_plugin,
|
||||
container->path = sudo_estrdup(path);
|
||||
container->name = info->symbol_name;
|
||||
container->options = info->options;
|
||||
container->debug_instance = SUDO_DEBUG_INSTANCE_INITIALIZER;
|
||||
container->u.generic = plugin;
|
||||
TAILQ_INIT(&container->debug_files);
|
||||
TAILQ_SWAP(&container->debug_files, &info->debug_files,
|
||||
@@ -329,6 +331,7 @@ sudo_load_plugins(struct plugin_container *policy_plugin,
|
||||
}
|
||||
|
||||
/* Install hooks (XXX - later). */
|
||||
sudo_debug_set_default_instance(SUDO_DEBUG_INSTANCE_INITIALIZER);
|
||||
if (policy_plugin->u.policy->version >= SUDO_API_MKVERSION(1, 2)) {
|
||||
if (policy_plugin->u.policy->register_hooks != NULL)
|
||||
policy_plugin->u.policy->register_hooks(SUDO_HOOK_VERSION, register_hook);
|
||||
@@ -339,6 +342,7 @@ sudo_load_plugins(struct plugin_container *policy_plugin,
|
||||
container->u.io->register_hooks(SUDO_HOOK_VERSION, register_hook);
|
||||
}
|
||||
}
|
||||
sudo_debug_set_default_instance(sudo_debug_instance);
|
||||
|
||||
done:
|
||||
debug_return_bool(rval);
|
||||
|
62
src/sudo.c
62
src/sudo.c
@@ -1145,6 +1145,7 @@ policy_open(struct plugin_container *plugin, struct sudo_settings *settings,
|
||||
/*
|
||||
* Backwards compatibility for older API versions
|
||||
*/
|
||||
sudo_debug_set_default_instance(SUDO_DEBUG_INSTANCE_INITIALIZER);
|
||||
switch (plugin->u.generic->version) {
|
||||
case SUDO_API_MKVERSION(1, 0):
|
||||
case SUDO_API_MKVERSION(1, 1):
|
||||
@@ -1158,6 +1159,10 @@ policy_open(struct plugin_container *plugin, struct sudo_settings *settings,
|
||||
plugin->options);
|
||||
}
|
||||
|
||||
/* Stash plugin debug instance ID if set in open() function. */
|
||||
plugin->debug_instance = sudo_debug_get_default_instance();
|
||||
sudo_debug_set_default_instance(sudo_debug_instance);
|
||||
|
||||
debug_return_bool(rval);
|
||||
}
|
||||
|
||||
@@ -1166,7 +1171,9 @@ policy_close(struct plugin_container *plugin, int exit_status, int error_code)
|
||||
{
|
||||
debug_decl(policy_close, SUDO_DEBUG_PCOMM, sudo_debug_instance)
|
||||
if (plugin->u.policy->close != NULL) {
|
||||
sudo_debug_set_default_instance(plugin->debug_instance);
|
||||
plugin->u.policy->close(exit_status, error_code);
|
||||
sudo_debug_set_default_instance(sudo_debug_instance);
|
||||
} else if (error_code) {
|
||||
errno = error_code;
|
||||
sudo_warn(U_("unable to execute %s"), command_details.command);
|
||||
@@ -1177,10 +1184,15 @@ policy_close(struct plugin_container *plugin, int exit_status, int error_code)
|
||||
static int
|
||||
policy_show_version(struct plugin_container *plugin, int verbose)
|
||||
{
|
||||
int rval;
|
||||
debug_decl(policy_show_version, SUDO_DEBUG_PCOMM, sudo_debug_instance)
|
||||
|
||||
if (plugin->u.policy->show_version == NULL)
|
||||
debug_return_bool(true);
|
||||
debug_return_bool(plugin->u.policy->show_version(verbose));
|
||||
sudo_debug_set_default_instance(plugin->debug_instance);
|
||||
rval = plugin->u.policy->show_version(verbose);
|
||||
sudo_debug_set_default_instance(sudo_debug_instance);
|
||||
debug_return_bool(rval);
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -1188,38 +1200,53 @@ policy_check(struct plugin_container *plugin, int argc, char * const argv[],
|
||||
char *env_add[], char **command_info[], char **argv_out[],
|
||||
char **user_env_out[])
|
||||
{
|
||||
int rval;
|
||||
debug_decl(policy_check, SUDO_DEBUG_PCOMM, sudo_debug_instance)
|
||||
|
||||
if (plugin->u.policy->check_policy == NULL) {
|
||||
sudo_fatalx(U_("policy plugin %s is missing the `check_policy' method"),
|
||||
plugin->name);
|
||||
}
|
||||
debug_return_bool(plugin->u.policy->check_policy(argc, argv, env_add,
|
||||
command_info, argv_out, user_env_out));
|
||||
sudo_debug_set_default_instance(plugin->debug_instance);
|
||||
rval = plugin->u.policy->check_policy(argc, argv, env_add, command_info,
|
||||
argv_out, user_env_out);
|
||||
sudo_debug_set_default_instance(sudo_debug_instance);
|
||||
debug_return_bool(rval);
|
||||
}
|
||||
|
||||
static int
|
||||
policy_list(struct plugin_container *plugin, int argc, char * const argv[],
|
||||
int verbose, const char *list_user)
|
||||
{
|
||||
int rval;
|
||||
debug_decl(policy_list, SUDO_DEBUG_PCOMM, sudo_debug_instance)
|
||||
|
||||
if (plugin->u.policy->list == NULL) {
|
||||
sudo_warnx(U_("policy plugin %s does not support listing privileges"),
|
||||
plugin->name);
|
||||
debug_return_bool(false);
|
||||
}
|
||||
debug_return_bool(plugin->u.policy->list(argc, argv, verbose, list_user));
|
||||
sudo_debug_set_default_instance(plugin->debug_instance);
|
||||
rval = plugin->u.policy->list(argc, argv, verbose, list_user);
|
||||
sudo_debug_set_default_instance(sudo_debug_instance);
|
||||
debug_return_bool(rval);
|
||||
}
|
||||
|
||||
static int
|
||||
policy_validate(struct plugin_container *plugin)
|
||||
{
|
||||
int rval;
|
||||
debug_decl(policy_validate, SUDO_DEBUG_PCOMM, sudo_debug_instance)
|
||||
|
||||
if (plugin->u.policy->validate == NULL) {
|
||||
sudo_warnx(U_("policy plugin %s does not support the -v option"),
|
||||
plugin->name);
|
||||
debug_return_bool(false);
|
||||
}
|
||||
debug_return_bool(plugin->u.policy->validate());
|
||||
sudo_debug_set_default_instance(plugin->debug_instance);
|
||||
rval = plugin->u.policy->validate();
|
||||
sudo_debug_set_default_instance(sudo_debug_instance);
|
||||
debug_return_bool(rval);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -1230,7 +1257,9 @@ policy_invalidate(struct plugin_container *plugin, int remove)
|
||||
sudo_fatalx(U_("policy plugin %s does not support the -k/-K options"),
|
||||
plugin->name);
|
||||
}
|
||||
sudo_debug_set_default_instance(plugin->debug_instance);
|
||||
plugin->u.policy->invalidate(remove);
|
||||
sudo_debug_set_default_instance(sudo_debug_instance);
|
||||
debug_return;
|
||||
}
|
||||
|
||||
@@ -1244,6 +1273,7 @@ policy_init_session(struct command_details *details)
|
||||
/*
|
||||
* Backwards compatibility for older API versions
|
||||
*/
|
||||
sudo_debug_set_default_instance(policy_plugin.debug_instance);
|
||||
switch (policy_plugin.u.generic->version) {
|
||||
case SUDO_API_MKVERSION(1, 0):
|
||||
case SUDO_API_MKVERSION(1, 1):
|
||||
@@ -1253,6 +1283,7 @@ policy_init_session(struct command_details *details)
|
||||
rval = policy_plugin.u.policy->init_session(details->pw,
|
||||
&details->envp);
|
||||
}
|
||||
sudo_debug_set_default_instance(sudo_debug_instance);
|
||||
}
|
||||
debug_return_bool(rval);
|
||||
}
|
||||
@@ -1274,6 +1305,7 @@ iolog_open(struct plugin_container *plugin, struct sudo_settings *settings,
|
||||
/*
|
||||
* Backwards compatibility for older API versions
|
||||
*/
|
||||
sudo_debug_set_default_instance(plugin->debug_instance);
|
||||
switch (plugin->u.generic->version) {
|
||||
case SUDO_API_MKVERSION(1, 0):
|
||||
rval = plugin->u.io_1_0->open(plugin->u.io_1_0->version,
|
||||
@@ -1290,6 +1322,7 @@ iolog_open(struct plugin_container *plugin, struct sudo_settings *settings,
|
||||
sudo_conversation_printf, plugin_settings, user_info, command_info,
|
||||
argc, argv, user_env, plugin->options);
|
||||
}
|
||||
sudo_debug_set_default_instance(sudo_debug_instance);
|
||||
debug_return_bool(rval);
|
||||
}
|
||||
|
||||
@@ -1297,18 +1330,28 @@ static void
|
||||
iolog_close(struct plugin_container *plugin, int exit_status, int error_code)
|
||||
{
|
||||
debug_decl(iolog_close, SUDO_DEBUG_PCOMM, sudo_debug_instance)
|
||||
if (plugin->u.io->close != NULL)
|
||||
|
||||
if (plugin->u.io->close != NULL) {
|
||||
sudo_debug_set_default_instance(plugin->debug_instance);
|
||||
plugin->u.io->close(exit_status, error_code);
|
||||
sudo_debug_set_default_instance(sudo_debug_instance);
|
||||
}
|
||||
debug_return;
|
||||
}
|
||||
|
||||
static int
|
||||
iolog_show_version(struct plugin_container *plugin, int verbose)
|
||||
{
|
||||
int rval;
|
||||
debug_decl(iolog_show_version, SUDO_DEBUG_PCOMM, sudo_debug_instance)
|
||||
|
||||
if (plugin->u.io->show_version == NULL)
|
||||
debug_return_bool(true);
|
||||
debug_return_bool(plugin->u.io->show_version(verbose));
|
||||
|
||||
sudo_debug_set_default_instance(plugin->debug_instance);
|
||||
rval = plugin->u.io->show_version(verbose);
|
||||
sudo_debug_set_default_instance(sudo_debug_instance);
|
||||
debug_return_bool(rval);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1322,9 +1365,12 @@ iolog_unlink(struct plugin_container *plugin)
|
||||
|
||||
/* Deregister hooks, if any. */
|
||||
if (plugin->u.io->version >= SUDO_API_MKVERSION(1, 2)) {
|
||||
if (plugin->u.io->deregister_hooks != NULL)
|
||||
if (plugin->u.io->deregister_hooks != NULL) {
|
||||
sudo_debug_set_default_instance(plugin->debug_instance);
|
||||
plugin->u.io->deregister_hooks(SUDO_HOOK_VERSION,
|
||||
deregister_hook);
|
||||
sudo_debug_set_default_instance(sudo_debug_instance);
|
||||
}
|
||||
}
|
||||
/* Remove from io_plugins list and free. */
|
||||
TAILQ_REMOVE(&io_plugins, plugin, entries);
|
||||
|
@@ -87,6 +87,7 @@ struct plugin_container {
|
||||
const char *path;
|
||||
char * const *options;
|
||||
void *handle;
|
||||
int debug_instance;
|
||||
union {
|
||||
struct generic_plugin *generic;
|
||||
struct policy_plugin *policy;
|
||||
|
Reference in New Issue
Block a user