Commit Graph

1652 Commits

Author SHA1 Message Date
Todd C. Miller
253e041d3b Load the sudoers module as an audit plugin if loaded as a policy plugin.
Now that logging of successful commands is performed by sudoers as an
audit plugin we need to load sudoers_audit if sudoers_policy is also
loaded.  Otherwise, accpted commands will not be logged.
2020-06-02 14:54:04 -06:00
Todd C. Miller
f0dc48548c Add support for "accept" audit events sent by the sudo front-end.
With this change, the sudo front-end will send an "accept" audit
event to the audit plugins after all the I/O logging plugins have
been initialized.  This can be used by an audit plugin that does
not care about the result of the individual policy and approval
plugins and only wants to receive a single "accept" event if all
policy and approval plugins have succeeded.  The plugin_type argument
for events sent by the front-end is SUDO_FRONT_END (0).
2020-06-02 09:07:44 -06:00
Todd C. Miller
a380709215 If event loop fails due to ENXIO, remove /dev/tty events and recover.
This fixes an issue on Solaris 11.4 (and probably others) with "sudo
reboot" when I/O logging is enabled.  Previously, sudo would kill
the command if it was still running after the event loop terminated,
leaving the system in a half-dead state.
2020-06-02 08:59:38 -06:00
Todd C. Miller
592eb7ab49 Don't try to suspend sudo if the user's tty has gone away.
Fixes a problem on Solaris 11.4 (and possibly others) where sudo
continually tries to put itself in the background after the user's
terminal has been revoked.
2020-06-01 14:19:50 -06:00
Todd C. Miller
de31e6d53b Back out WIP code that was mistakenly committed. 2020-06-01 14:04:15 -06:00
Todd C. Miller
ad70fb4f1e On Solaris 11.4 the openpty(3) prototype lives in termios.h. 2020-06-01 12:59:29 -06:00
Todd C. Miller
2dd1e1907d Check audit plugins for a close function too before execing command directly.
We cannot exec the command directly if any of the policy or audit
plugins use a close function.
2020-05-26 11:36:17 -06:00
Todd C. Miller
446ae3f507 Include string.h unconditionally and only use strings.h for strn?casecmp()
In the pre-POSIX days BSD had strings.h, not string.h.
Now strings.h is only used for non-ANSI string functions.
2020-05-18 07:59:24 -06:00
Todd C. Miller
dd88460800 We no longer need to include headers we don't use for sudo*.h files.
Previously we needed to include headers required by the various
sudo*h files.  Now those files are more self-sufficient and we
should only include headers needed by code in the various .c files.
2020-05-18 06:47:04 -06:00
Todd C. Miller
92199e25c4 The --preserve-env=list option may be specified more than once. 2020-05-07 11:11:43 -06:00
Todd C. Miller
4266279c0c Don't allow duplicate values for command line options that take an argument.
Previously, if multiple instances of the same command line option were
specified, the last one would be used.  This meant that, for example,
"sudo -u someuser -u otheruser id" would run the command as "otheruser".
This has the potential to cause problems for programs that run sudo with
a user-specified command that do not use the "--" option to indicate
that no more options should be processed.  While this is a bug in
the calling program, there is little downside to erroring out when
multiple options of the same type are specified on the command line.
Bug #924
2020-05-06 19:33:24 -06:00
Todd C. Miller
4dba87262a Look up runas user by name, not euid, where possible.
Fixes a problem when there are multiple users with the same user-ID
where the PAM session modules could be called with the wrong user name.
Debian bug #734752
2020-05-06 16:38:08 -06:00
Todd C. Miller
ea99394fcf Fix ironic typo in spelling fixes. Bug #925 2020-05-06 11:04:47 -06:00
Todd C. Miller
0cf2e09e0c Apply spelling fixes.
Fixes from PR #30 (ka7) and Bug #925 (fossies.org codespell)
2020-05-06 09:27:43 -06:00
Todd C. Miller
76bf9a73bc Fix sudoedit when running with SELinux RBAC mode.
We can't use run_command() to run sesh, that will use the sudo event
loop (and might run it in a pty!).
There's no need to relabel the tty when copying files.
Get the path to sesh from sudo.conf.

Currently, for SELinux RBAC, the editor runs with the target user's
security context. This defeats the purpose of sudoedit.  Fixing
that requires passing file descriptors between the main sudo process
(running with the invoking user's security context) and sesh (runnning
with the target user's security context).
2020-04-21 14:29:23 -06:00
Todd C. Miller
009876bf36 Refactor the sudoedit code to copy files so it can be shared.
The SELinux sudoedit code now extends the destination file the
same way the non-SELinux version does.
2020-04-21 11:05:32 -06:00
Todd C. Miller
0bd39701b4 Do not remove sudoedit temporary files if we cannot overwrite the real file.
The warning message says the files were preserved but they actually
got removed.
2020-04-21 11:05:30 -06:00
Todd C. Miller
adb4360c40 Extend the original file before to the new size before updating it.
Instead of opening the original file for writing w/ tuncation, we
first extend the file with zeroes (by writing, not seeking), then
overwrite it.  This should allow sudo to fail early if the disk is
out of space before it overwrites the original file.
2020-04-17 19:08:56 -06:00
Todd C. Miller
2a60816f75 I/O log plugins should be closed *before* the policy plugin, not after. 2020-04-17 15:57:06 -06:00
Todd C. Miller
93aa9f9e90 Add cwd_optional to command details and enable it in the sudoers plugin.
If cwd_optional is set to true, a failure to set the cwd will be a
warning, not an error, and the command will still run.
Debian bug #598519
2020-03-31 19:43:48 -06:00
Todd C. Miller
3221c8b4d8 Don't kill the command just because the loop exited unexpectedly.
We currently have no good way to distinguish between an error
executing the command and an error while the command is running.

In the future, we should have additional status codes so we
can tell what type of condition caused the loop to exit.

For now, only kill the command if cstat is left uninitialized.
2020-03-31 08:49:30 -06:00
Todd C. Miller
712afe0319 Ignore a failure to restore the RLIMIT_CORE resource limit.
Linux containers don't allow RLIMIT_CORE to be set back to RLIM_INFINITY
if we set the limit to zero, even for root.  This is not a problem
outside the container.
2020-03-14 11:13:55 -06:00
Todd C. Miller
9c90f592c2 Sudo's -S option should override the SUDO_CONV_PREFER_TTY flag. 2020-02-27 14:11:16 -07:00
Todd C. Miller
92e42ff548 Add compatibility define for fseeko(3).
This is better than cluttering up the code with #ifdefs for obsolete
systems.
2020-02-15 10:22:15 -07:00
Todd C. Miller
01a53f2865 Add open and close functions to the approval plugin API.
We need a close function to be able to to free memory allocated for
errstr.  Unlike the other plugins, the close function is called
immediately after the plugin's check or show_version function.
The plugin does not remain open until the command completes.
2020-02-10 15:29:48 -07:00
Robert Manner
2781ec030b src/sudo.c: call audit plugin close when result is a wait status 2020-02-10 05:31:30 -07:00
Todd C. Miller
ac61b5655d Use EXIT_SUCCESS and EXIT_FAILURE more consistently. 2020-02-08 12:43:00 -07:00
Todd C. Miller
c5afbf00fc Mark main sudo usage() function __noreturn__.
This splits the usage printing out into display_usage().
2020-02-08 12:17:33 -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
0972dafb1f Refactor code to alloc and insert a new plugin_container.
The only outlier is the policy plugin which is not part of a list
since there can only be a single policy plugin.
2020-02-06 12:49:15 -07:00
Todd C. Miller
db17cadaf6 Add an approval plugin type that runs after the policy plugin.
The basic idea is that the approval plugin adds an additional
layer of policy.  There can be multiple approval plugins.
2020-02-06 12:49:11 -07:00
Todd C. Miller
d219c64635 Only enable pwfeedback when reading password from /dev/tty.
This effectively disables pwfeedback when the -S or -A options are used.
2020-02-05 10:53:49 -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
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
22105009d8 Define a new plugin type that receives accept and reject messages.
This can be used to implement logging-only plugins.
The plugin functions now take an errstr argument that can be used
to return an error string to be logged on failure or error.
2020-01-30 13:25:34 -07:00
Todd C. Miller
fa8ffeb175 Fix a buffer overflow when pwfeedback is enabled and input is a not a tty.
In getln() if the user enters ^U (erase line) and the write(2) fails,
the remaining buffer size is reset but the current pointer is not.
While here, fix an incorrect break for erase when write(2) fails.
Also disable pwfeedback when input is not a tty as it cannot work.
CVE-2019-18634
Credit: Joe Vennix from Apple Information Security.
2020-01-29 20:15:21 -07:00
Robert Manner
74f559155a src/load_plugins.c: plugins can supply a clone function
if they want to support getting loaded multiple times.
2020-01-23 12:46:14 -07:00
Todd C. Miller
fb5fc9876a Refactor code to allocate and fill struct plugin_container.
This will help avoid duplicate code in the audit and approval plugins.
2020-01-22 12:35:44 -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
0d2195c374 Iterate over io_plugins list in the iolog_* wrappers.
Moving the iteration into the wrapper functions simplifies the calling code.
2020-01-07 20:05:29 -07:00
Todd C. Miller
b0a84c4292 policy_plugin is global, no need to pass it to policy_* functions. 2020-01-07 18:40:36 -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
Todd C. Miller
d2b7148b6c Using "libtool --clean" to remove regular files is slow.
We only need to use libtool's clean mode to remove files created by libtool.
2020-01-18 05:53:55 -07:00
Todd C. Miller
9e12b71776 Treat EROFS (like EACCES) as a non-fatal error in dir_is_writable().
Fixes sudoedit on macOS 10.15 and above where the root file system
is mounted read-only.  See https://support.apple.com/en-us/HT210650.
From Dan Villiom Podlaski Christiansen.  Bug #913
2020-01-16 13:55:32 -07:00
Todd C. Miller
405d26f5b8 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.
2020-01-15 14:05:08 -07:00
Todd C. Miller
9c5c79194d Fix handling of duplicate policy and I/O plugins.
The warning message said the later I/O plugin was ignored but it
actually overwrote the existing one instead.
The first registered plugin of the same name now is used, as was intended.
Specifying more than one policy plugin is no longer a fatal error;
this allows the admin to fix the situation.
2020-01-14 13:53:52 -07:00
Todd C. Miller
c592470dbd For sudoedit_checkdir consider a user-owner directory to be writable.
The non-faccessat() code already did this so this just brings the
faccessat() path into alignment.  Bug #912
2020-01-11 15:32:48 -07:00
Todd C. Miller
1e25d03c98 Use 64-bit resource limits on AIX. 2019-12-25 16:39:11 -07:00
Todd C. Miller
dfabda3d49 When restoring old resource limits, try to recover if we receive
EINVAL.  On NetBSD, setrlimit(2) can return EINVAL if the new soft
limit is lower than the current resource usage.  This can be a
problem when restoring the old stack limit if sudo has raised it.
2019-12-25 13:48:04 -07:00
Todd C. Miller
dbc905fdf8 Sudo doesn't require such a large stack. 2019-12-25 13:13:20 -07:00