Wrap calls to plugin event callbacks to use the plugin's debug instance.
Otherwise, the debug output in a plugin's event callback will go to the sudo debug file, not sudoers.
This commit is contained in:
27
src/sudo.c
27
src/sudo.c
@@ -1357,6 +1357,21 @@ iolog_unlink(struct plugin_container *plugin)
|
|||||||
debug_return;
|
debug_return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
plugin_event_callback(int fd, int what, void *v)
|
||||||
|
{
|
||||||
|
struct sudo_plugin_event_int *ev_int = v;
|
||||||
|
int old_instance;
|
||||||
|
debug_decl(plugin_event_callback, SUDO_DEBUG_PCOMM);
|
||||||
|
|
||||||
|
/* Run the real callback using the plugin's debug instance. */
|
||||||
|
old_instance = sudo_debug_set_active_instance(ev_int->debug_instance);
|
||||||
|
ev_int->callback(fd, what, ev_int->closure);
|
||||||
|
sudo_debug_set_active_instance(old_instance);
|
||||||
|
|
||||||
|
debug_return;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Fill in a previously allocated struct sudo_plugin_event.
|
* Fill in a previously allocated struct sudo_plugin_event.
|
||||||
*/
|
*/
|
||||||
@@ -1368,9 +1383,16 @@ plugin_event_set(struct sudo_plugin_event *pev, int fd, int events,
|
|||||||
debug_decl(plugin_event_set, SUDO_DEBUG_PCOMM);
|
debug_decl(plugin_event_set, SUDO_DEBUG_PCOMM);
|
||||||
|
|
||||||
ev_int = __containerof(pev, struct sudo_plugin_event_int, public);
|
ev_int = __containerof(pev, struct sudo_plugin_event_int, public);
|
||||||
if (sudo_ev_set(&ev_int->private, fd, events, callback, closure) == -1)
|
if (sudo_ev_set(&ev_int->private, fd, events, plugin_event_callback, ev_int) == -1)
|
||||||
debug_return_int(-1);
|
debug_return_int(-1);
|
||||||
|
|
||||||
|
/* Stash active instance so we can restore it when callback runs. */
|
||||||
|
ev_int->debug_instance = sudo_debug_get_active_instance();
|
||||||
|
|
||||||
|
/* Actual user-specified callback and closure. */
|
||||||
|
ev_int->callback = callback;
|
||||||
|
ev_int->closure = closure;
|
||||||
|
|
||||||
/* Plugin can only operate on the main event loop. */
|
/* Plugin can only operate on the main event loop. */
|
||||||
ev_int->private.base = sudo_event_base;
|
ev_int->private.base = sudo_event_base;
|
||||||
|
|
||||||
@@ -1503,6 +1525,9 @@ sudo_plugin_event_alloc(void)
|
|||||||
ev_int->public.loopbreak = plugin_event_loopbreak;
|
ev_int->public.loopbreak = plugin_event_loopbreak;
|
||||||
ev_int->public.free = plugin_event_free;
|
ev_int->public.free = plugin_event_free;
|
||||||
|
|
||||||
|
/* Debug instance to use with the callback. */
|
||||||
|
ev_int->debug_instance = SUDO_DEBUG_INSTANCE_INITIALIZER;
|
||||||
|
|
||||||
/* Clear private portion in case caller tries to use us uninitialized. */
|
/* Clear private portion in case caller tries to use us uninitialized. */
|
||||||
memset(&ev_int->private, 0, sizeof(ev_int->private));
|
memset(&ev_int->private, 0, sizeof(ev_int->private));
|
||||||
|
|
||||||
|
@@ -109,7 +109,10 @@ TAILQ_HEAD(plugin_container_list, plugin_container);
|
|||||||
*/
|
*/
|
||||||
struct sudo_plugin_event_int {
|
struct sudo_plugin_event_int {
|
||||||
struct sudo_event private; /* must be first */
|
struct sudo_event private; /* must be first */
|
||||||
struct sudo_plugin_event public;
|
int debug_instance; /* plugin's debug instance */
|
||||||
|
void *closure; /* actual user closure */
|
||||||
|
sudo_ev_callback_t callback; /* actual user callback */
|
||||||
|
struct sudo_plugin_event public; /* user-visible portion */
|
||||||
};
|
};
|
||||||
|
|
||||||
extern struct plugin_container policy_plugin;
|
extern struct plugin_container policy_plugin;
|
||||||
|
Reference in New Issue
Block a user