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:

committed by
Todd C. Miller

parent
45d2638571
commit
3dd5f37af7
@@ -31,6 +31,7 @@ PyAPI_FUNC(PyObject *) PyStructSequence_GetItem(PyObject *, Py_ssize_t);
|
||||
|
||||
// exceptions:
|
||||
PyObject *sudo_exc_SudoException;
|
||||
PyObject *sudo_exc_PluginError;
|
||||
static PyObject *sudo_exc_ConversationInterrupted;
|
||||
|
||||
// the methods exposed in the "sudo" python module
|
||||
@@ -562,6 +563,7 @@ sudo_module_init(void)
|
||||
} while(0);
|
||||
|
||||
MODULE_ADD_EXCEPTION(SudoException, NULL);
|
||||
MODULE_ADD_EXCEPTION(PluginError, NULL);
|
||||
MODULE_ADD_EXCEPTION(ConversationInterrupted, EXC_VAR(SudoException));
|
||||
|
||||
#define MODULE_REGISTER_ENUM(name, key_values) \
|
||||
@@ -611,6 +613,7 @@ cleanup:
|
||||
if (PyErr_Occurred()) {
|
||||
Py_CLEAR(py_module);
|
||||
Py_CLEAR(sudo_exc_SudoException);
|
||||
Py_CLEAR(sudo_exc_PluginError);
|
||||
Py_CLEAR(sudo_exc_ConversationInterrupted);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user