Commit Graph

27 Commits

Author SHA1 Message Date
Todd C. Miller
84e6e6ccf9 Update copyright year on some files where it was out of date. 2020-08-31 14:09:36 -06:00
Todd C. Miller
cd74b83c21 Make most python tests pass with Python 3.4
Dictionary order is not stable in Python < 3.6 so we need to sort
by key to have consistent results.
The LogHandler output is also different on older Python versions.
Also, don't stop running python tests after the first error.
2020-04-07 14:03:58 -06:00
Todd C. Miller
8a2c0d784f Sort the list of possible plugins before printing it.
This gives more reproducible error messages for the tests.
2020-04-07 14:03:58 -06:00
Todd C. Miller
93f5e1be36 Fall back to using Py_Finalize() for Python version < 3.6 2020-04-06 07:05:20 -06:00
Robert Manner
c039a99c10 plugins/python/sudo_module: add sudo.LogHandler
so python log system can be used with sudo logsystem.
Loggers use it by default (the handler is set on the root logger).
If that is not the intent, it can be overridden explicitly.
2020-02-28 05:46:54 -07:00
Robert Manner
34b4bb72d6 plugins/python: autodetect ClassName field
If "ClassName" is not specified, load the one and only sudo.Plugin from
the module (if so), otherwise display which plugins are available from
which the system admin can choose.
2020-02-28 05:46:54 -07:00
Robert Manner
5c96b4407d plugins/python/plugin_common: add a default search path for python plugins
If the ModulePath is relative, assume it is under
"/usr/local/libexec/sudo/python" or wherever the sudo plugins are in a
"python" subdirectory.
2020-02-28 05:46:54 -07:00
Robert Manner
f387cdf53f plugins/python: make show_version display the plugin in verbose mode
Before it only displayed the plugin version, now it also displays
which python plugin is loaded to be more useful.
2020-02-26 13:15:52 -07:00
Robert Manner
38fc37b214 plugins/python/approval: fix show_version crash when it is not implemented
For approval plugins show_version is not optional.
2020-02-26 13:15:52 -07:00
Robert Manner
3be61db35c plugins/python: restore the original python inittab after interpreter deinit 2020-02-19 11:48:16 -07:00
Robert Manner
27de7dd24d plugins/python: only deinit interpreters when sudo unlinks the plugin
This only happens when sudo unloads the last python plugin.
The reason doing so is because there are some python modules which
does not support importing them again after destroying the interpreter
which has imported them previously.

Another solution would be to just leak the interpreters (let the kernel
free up), but then there might be some python resources like open files
would not get cleaned up correctly if the plugin is badly written.

Tests are meant to test the scenario sudo does, so I have modified them
to generally do not unlink but only a few times (~per plugin type) so it
does not use 48 interpreters (one gets started on every plugin->open) and
it is visible at least which type of plugin fails deinit if there is an
error.
2020-02-19 11:48:16 -07:00
Robert Manner
8a9218d161 plugins/python/debug: adapt debug refcount solution of sudoers plugin 2020-02-19 11:48:16 -07:00
Robert Manner
a71828b385 plugins/python/python_plugin_common.c: release py_args in close
even if the arguments are not used (eg. when there is no "close" call
in the plugin).

It was not really a memleak, because interpreter is deinitialized anyway,
which frees the object.
2020-02-14 09:25:37 -07:00
Robert Manner
23af39b005 plugins/python: add python approval plugin wrapper 2020-02-12 11:16:00 -07:00
Robert Manner
b1d2ccecd0 plugins/python: make storing errstr more explicit
The error is always stored in plugin_ctx, but it is only set into errstr
if the API version is enough. (Previously it worked the opposite:
we only stored the error if API level was enough.)
2020-02-12 11:16:00 -07:00
Robert Manner
b165242035 plugins/python/sudo_module: let a reject also supply error message
Same as sudo.PluginError exception, have a sudo.PluginReject exception
as well. Added common base exception as well.
2020-02-12 11:16:00 -07:00
Robert Manner
3dd5f37af7 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.
2020-02-10 05:24:16 -07:00
Robert Manner
36694fce86 plugins/python/python_plugin_common: close can get custom arguments
For the audit plugin.
Ensure we do not fail if plugin_ctx->py_instance is NULL (because
plugin init has failed).
2020-02-10 05:24:16 -07:00
Robert Manner
21c02e1732 plugins/python/sudo_python_module.c: use IntEnums instead of constants
It is a bit more code, but it is more "pythonic" and easier to debug
as the enum values also know their names.

It is also an API break, eg. sudo.RC_OK becomes sudo.RC.OK as sudo.RC will
be the "type" of the enum, but I guess that is acceptable before the
initial release.
2020-02-10 05:24:16 -07:00
Robert Manner
22c64f58c0 plugins/python: use separate python interpreter for each plugin
On each plugin initialization we create a separate python interpreter
which gets stored in the plugin_ctx. The main interpreter is
stored in py_ctx and is used for creating more interpreters (if more plugins
get loaded) and final python deinitialization.

The "traceback" module import and the ImportBlocker initialization was
moved, because it has to happen inside the plugin specific interpreters.
2020-01-24 12:25:15 -07:00
Robert Manner
d67c64bb37 plugins/python/pyhelpers: have a default sudo_printf function
Adapted the default sudo_printf from sudoers plugin to be able to print
errors before plugin open() gets called. (This is used by the multiple io
plugin loading to display error for too much plugin load.)

Since this makes us always have a sudo_log, I have removed the logic about
whether it is available or not.
2020-01-23 12:46:14 -07:00
Robert Manner
185471f263 plugins/python/python_plugin_policy: fix validate() call
When calling validate() python function, TypeError exception was thrown
("argument list must be a tuple"), because the call does not have
arguments, and python does not accept empty tuple for execution. NULL
must be used instead, which was handled as argument construction failure
previously.
2020-01-20 06:30:20 -07:00
Robert Manner
2ee1dd3ec3 plugins/python: fix confusing version display
IO/Group/Policy Python API version is displayed instead of sudo version,
because that is not very meaningful in this context.

They are only displayed in verbose mode.

Example plugins express it more concrete that they are displaying their
version, not the API version.
2020-01-20 06:30:20 -07:00
Robert Manner
5be81eb25b plugins/python/python_plugin_common: raise debug level for module import 2020-01-20 06:30:20 -07:00
Todd C. Miller
486ee2b71f debug_decl and debug_decl_vars now require a semicolon at the end. 2019-12-22 08:48:16 -07:00
Robert Manner
d888d44594 plugins/python: make group plugin able to debug
It does not get the debug settings, so it looks them up through
sudo_conf.
2019-12-14 12:55:42 -07:00
Robert Manner
babdcbd031 plugins/python: a plugin which can load policy/io plugin written in python 2019-12-14 12:55:42 -07:00