plugins/python: add support for callback errstr arguments

Plugins can raise a sudo.PluginError exception to add context message
for the failure.

The callback's errstr gets filled up with the specified message.
But, as sudo expects a string constant (will not free the string),
we store it in the plugin context at least until next callback
invocation.
This commit is contained in:
Robert Manner
2020-02-05 17:17:16 +01:00
committed by Todd C. Miller
parent 45d2638571
commit 3dd5f37af7
7 changed files with 120 additions and 25 deletions

View File

@@ -27,11 +27,16 @@ struct PluginContext {
PyObject *py_class;
PyObject *py_instance;
int call_close;
unsigned int sudo_api_version;
// We use this to let the error string live until sudo and the audit plugins
// are using it. Only set for sudo API >= 1.15, otherwise NULL
char *callback_error;
};
int python_plugin_register_logging(sudo_conv_t conversation, sudo_printf_t sudo_printf, char * const settings[]);
int python_plugin_init(struct PluginContext *plugin_ctx, char * const plugin_options[]);
int python_plugin_init(struct PluginContext *plugin_ctx, char * const plugin_options[], unsigned int version);
int python_plugin_construct_custom(struct PluginContext *plugin_ctx, PyObject *py_kwargs);