Commit Graph

2592 Commits

Author SHA1 Message Date
Todd C. Miller
ac61b5655d Use EXIT_SUCCESS and EXIT_FAILURE more consistently. 2020-02-08 12:43:00 -07:00
Todd C. Miller
c92f39ed3d Use json functions from libsudo_util in cvtsudoers. 2020-02-08 09:11:02 -07:00
Todd C. Miller
d25ce46c56 Check localtime() return value; coverity CID 208156 2020-02-07 13:58:31 -07:00
Todd C. Miller
a75992897c Check fseeko() return value; coverity CID 207993 2020-02-07 13:24:11 -07:00
Todd C. Miller
2fe127d108 Move some scripts from the top level src dir to a scripts dir. 2020-02-06 14:30:26 -07:00
Todd C. Miller
aa1ca9c9ba Add sample approval plugin that simply tests for "business hours" 2020-02-06 13:53:09 -07:00
Todd C. Miller
ce21233fbe Tech audit_json about approval plugin accept/reject 2020-02-06 12:49:13 -07:00
Todd C. Miller
404b28c4d0 Exported symbol is audit_json 2020-02-05 21:12:49 -07:00
Todd C. Miller
c2faa9e6ef Add runas_user and runas_group (if set) to command_info for audit plugin.
Otherwise, the audit plugin has to look up the runas name and group
by user or group ID.
2020-02-05 10:53:50 -07:00
Todd C. Miller
658702b6d4 For plugin events, set the sudo event base for setbase(NULL).
This makes it possible for a plugin to change the event base
to a local one and then reset it back to its original value.
2020-02-02 12:37:11 -07:00
Todd C. Miller
49e7e4ecd5 Don't display "error in event loop" on loop break reading ServerHello.
We should already have displayed a more useful error message.
Otherwise, we can get two "error in event loop" warnings if
the TLS handshake fails (in addition to other error messages).
2020-02-01 08:32:27 -07:00
Todd C. Miller
b9bea25592 Read ServerHello message synchronously before the command is executed.
Otherwise, the command could be run before the TLS handshake completes.
2020-01-31 19:48:27 -07:00
Todd C. Miller
1b7dc82fee Change audit close arguments to a type and value.
That way we can distinguish between different error types.
2020-01-30 17:05:27 -07:00
Todd C. Miller
bf85ea2bf7 Example audit plugin that writes JSON output to a log file. 2020-01-30 13:25:52 -07:00
Todd C. Miller
a88a05c1eb Adapt python plugin to new plugin API changes 2020-01-30 13:25:38 -07:00
Todd C. Miller
45e589d443 Pass back a failure or error string to the front end.
The audit_failure() function now stores the failure string.
This will allow an audit plugin to log the reason if the user's
request is a rejected.
2020-01-30 13:25:36 -07:00
Todd C. Miller
604945f93e Fix warning about unresolved host name with "sudo -l -h hostname".
The resolve_host() function returns 0 on success, not bool.
2020-01-28 13:00:54 -07:00
Todd C. Miller
4e87e1a97b Fix typo in a test: python_policy->close not python_io->close 2020-01-28 13:00:33 -07:00
Robert Manner
f268e851d7 plugins/sudo_python_module: Fix double free in sudo.options_as_dict function
PyArg_ParseTuple sets the py_config_tuple pointer, but it does not
increment the reference count, so by decrementing, we end up freeing
the argument passed in.
2020-01-28 07:20:44 -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
99f8394182 plugins/python/regress: add a failing textcase about python plugins affect each other
Since python plugins are run inside the same interpreter, they affect
each other's state, which would be better to avoid.
2020-01-24 12:25:15 -07:00
Todd C. Miller
5472b17516 Fix crash in sudo 1.8.30 when suspending sudo at the password prompt.
The closure pointer in sudo_conv_callback was being filled in with
a struct getpass_closure ** instead of a struct getpass_closure *.
The bug was introduced in the fix for Bug #910; previously the
closure variable was a struct getpass_closure, not a pointer.
Fix from Michael Norton; Bug #914.
2020-01-24 11:13:55 -07:00
Robert Manner
d3d3a59e08 plugins/python/Makefile.in: update autogenerated header dependencies 2020-01-23 12:46:14 -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
2eeda38f95 plugins/python/regress: add a testcase for multiple io plugin loading
to verify 2 python plugins can work next to each other.
2020-01-23 12:46:14 -07:00
Robert Manner
3128cc97ca plugins/python: fix return value typo for the error case 2020-01-23 12:46:14 -07:00
Robert Manner
304a7fdc1f plugins/python/plugin_io: enable loading of multiple io plugins
Separate sudo io plugin symbols are created which stores wrapper
functions adding the context of which python plugin the callback is
about.

These sudo io plugin "slots" get generated with macros by the preprocessor.

This makes sudo support loading multiple python IO plugins like this:
(note the differences in the symbol names)

Plugin python_io python_plugin.so ModulePath=... ClassName=SudoIOPlugin1
Plugin python_io1 python_plugin.so ModulePath=... ClassName=SudoIOPlugin2
Plugin python_io2 python_plugin.so ModulePath=... ClassName=SudoIOPlugin3
2020-01-23 12:46:14 -07:00
Robert Manner
edd7356f2a plugins/python/Makefile.in: remove path prefix from examples to make install target work 2020-01-23 12:46:14 -07:00
Laszlo Orban
24c9438486 logserver option to disable certificate verification on server side and server authentication on client side 2020-01-23 10:12:12 -07:00
Laszlo Orban
9935a7e2ff Rename tls_checkpeer to tls_reqcert in ServerHello message 2020-01-23 10:12:12 -07:00
Laszlo Orban
6f3f45aa24 sudoers: disable SO_KEEPALIVE socket option based on log_server_disable_keepalive flag in sudoers 2020-01-22 10:52:18 -07:00
Todd C. Miller
dde86e585f Add support for building on OpenSSL 1.0.2.
This adds compatibility defines for some OpenSSL 1.1.x functions.
2020-01-21 13:27:40 -07:00
Todd C. Miller
c3bd025052 Store the server host name and IP in client_closure_fill().
Also check for getpeername() and inet_ntop() failure.
2020-01-20 14:03:41 -07:00
Todd C. Miller
2d91555e85 Fix handling of SSL_ERROR_WANT_{READ,WRITE} during normal I/O.
If we get SSL_ERROR_WANT_WRITE during SSL_read(), we need to resume
the SSL_read(), not call SSL_write() as we were doing.  Likewise
for SSL_ERROR_WANT_READ received from SSL_write().
This introduces a flag so we call the proper callback even when
the I/O direction doesn't match the read/write calls.
2020-01-20 12:42:39 -07:00
Todd C. Miller
5913c63642 Add abs_top_srcdir and abs_top_builddir and use them.
Configure provides absolution versions of srcdir, builddir, top_srcdir
and top_builddir.  We can use these instead of calling pwd.
2020-01-20 06:37:42 -07:00
Robert Manner
8cacaabe9b plugins/python/regress: add missing license texts 2020-01-20 06:30:20 -07:00
Robert Manner
b66ecf6e13 plugins/python: various portability improvements 2020-01-20 06:30:20 -07:00
Robert Manner
f3b7f3c0d4 plugins/python/example_{io,conversation}: avoid printing signal number
They are platform dependant, so their test would fail on some platforms.
While we could create separate plugin for the tests, I like the idea that
the examples are ensured to be working.

I believe this is a good compromise for being able to auto update the
test cases.
2020-01-20 06:30:20 -07:00
Robert Manner
40f2189586 plugins/python/regress: load the python plugin dynamically
instead of linking with it.
2020-01-20 06:30:20 -07:00
Robert Manner
383ca80333 plugins/python/regress/testdata: generated data for the pyplugin tests 2020-01-20 06:30:20 -07:00
Robert Manner
5da7bd562c plugins/python/regress: adds tests for python plugin feature and examples 2020-01-20 06:30:20 -07:00
Robert Manner
0b2d0334b7 plugins/python/example_policy_plugin.py: extend user env changing example
Make the demonstration extend the environment with a new variable.
Easier to read, and makes the testing able to check for that it is working.
2020-01-20 06:30:20 -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
35c85596d7 plugins/python/example_policy_plugin.py: make allowed_commands ordered
Storing them as "tuple" instead of "set", so they have a fix order.
This makes the output of the list() example stable. ("set" is printed out
in random order)
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
87d76f4bbc plugins/python/example_conversation.py: make log path configurable
Similarly to IO plugin example. (It is easier to test it this way.)
2020-01-20 06:30:20 -07:00
Robert Manner
591d57ad28 plugins/python/example_io_plugin.py: fix backtrace during destructor
If the plugin fails to open the file for writing, constructor will raise
an exception and exit before creating the "_log" member variable.
So the destructor will also raise a backtrace. (Which python ignores, but
dumps out to stderr.)
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
Robert Manner
8eab169098 plugins/python/example_debugging: fix typo in comment 2020-01-20 06:30:20 -07:00
Todd C. Miller
47d9504716 Add debugging statements to certificate checks. 2020-01-18 12:57:24 -07:00