Todd C. Miller
b3173fdedc
The runas user must be set before applying runas-based Defaults.
...
This effectively backs out changeset f738f5ac5350, which made
it possible to log the command when an invalid user was specified.
The policy plugin API doesn't supply the command until the check
function, at which point we've already denied the command due to
the invalid user. Bug #951 .
2020-12-20 08:43:34 -07:00
Todd C. Miller
63739dd326
Store the user-provided runas user and group name in struct sudo_user.
...
This makes it available for event logging in case the name doesn't resolve.
2020-12-05 09:05:42 -07:00
Todd C. Miller
008a0e8dc1
Store iolog_path in struct sudo_user for use in the event log.
2020-12-05 08:31:46 -07:00
Todd C. Miller
fd39e2d7d6
Defer lookup of runas user until sudoers_main() for better logging.
...
The log message now includes user info and the command attempted.
2020-12-04 13:49:37 -07:00
Todd C. Miller
7d0b19d2a0
Don't free the private copy of the environment until the close function.
...
We may need to use it when logging from the audit reject function.
2020-11-17 13:44:32 -07:00
Todd C. Miller
62547746d3
Rename iolog_client -> log_client.
...
The logsrvd client code is now used for more than just I/O logging.
2020-11-09 17:13:04 -07:00
Todd C. Miller
e0c2635fb3
Apply Google inclusive language guidelines.
...
Also replace backwards with backward.
2020-10-30 10:15:30 -06:00
Todd C. Miller
28d6771d24
Add log_format sudoers setting to select sudo or json format logs.
...
Defaults to sudo-format logs.
2020-10-27 15:26:02 -06:00
Todd C. Miller
fdae4bdbbb
Add support for file log line wrapping in libeventlog.
2020-10-26 16:16:46 -06:00
Todd C. Miller
d899fe5936
Use real setters for the eventlog config.
...
This makes it possible to have a base config that the callers can
modify instead of replacing the config wholesale.
2020-10-26 16:10:42 -06:00
Todd C. Miller
a5a5cc7f85
sudoers_policy_store() -> sudoers_policy_store_result()
2020-10-16 05:56:03 -06:00
Todd C. Miller
bf9d208662
Rename sudoers_policy_exec_setup() -> sudoers_policy_store().
...
It is called even when there is no command to execute.
Also pass in status of whether or not the command was accepted.
2020-10-14 06:33:35 -06:00
Todd C. Miller
88dcdcd11d
Fix -Wshadow warnings.
2020-09-25 15:09:45 -06:00
Todd C. Miller
f1d19f1d6e
Add SLOG_AUDIT flag for log_warningx() to also audit the message.
...
This lets us combine audit_failure() and log_warningx() calls with
the same message.
2020-09-23 08:18:55 -06:00
Todd C. Miller
6ee731caff
Log when user-specified command line options are rejected by sudoers.
...
We already audit those but in some cases they were not logged as well.
2020-09-23 08:02:43 -06:00
Todd C. Miller
6f8e1b9741
Fix potential NULL deref in debug code.
2020-09-23 08:59:18 -06:00
Todd C. Miller
c200e71637
Add callback for runchroot Defaults and require password -D/-R checks.
...
Using a command-based Default for runchroot will still only work for
paths that exist both in and outside the chroot.
2020-09-09 19:18:24 -06:00
Todd C. Miller
10d3d69aa1
Pass a struct to the match functions to track the resolved command.
...
This makes it possible to update user_cmnd and cmnd_status modified
by per-rule CHROOT settings.
2020-09-09 15:26:45 -06:00
Todd C. Miller
b6dbfe5094
Take the chroot into account when search for the command.
...
This could a a user-specific chroot via the -R option, a runchroot
Defaults value, or a per-command CHROOT spec in the sudoers rule.
2020-09-09 15:26:44 -06:00
Todd C. Miller
226307591c
Log the runcwd not submitcwd in the sudo-style log file.
...
The log entry should reflect the working directory the command
actually ran in.
2020-09-02 11:23:26 -06:00
Todd C. Miller
1676f0ceeb
Support "*" for CWD/CHROOT to allow user to specify cwd or chroot.
...
Adds two new command line options, -D (--chdir) and -R (--chroot)
that can only be used when sudoers sets runcwd or runchroot to "*".
2020-09-01 14:10:02 -06:00
Todd C. Miller
961a4afe67
Fix some warnings from pvs-studio
2020-08-12 13:45:09 -06:00
Todd C. Miller
cbad17a994
Move inclusion of compat headers up with the system headers.
...
Now that sudo_dso_public is defined in config.h we don't need sudo_compat.h
before including the compat headers.
2020-08-12 10:07:07 -06:00
Todd C. Miller
852d8c7953
Fix a typo in the audit string when "sudo -E" is not allowed.
2020-06-07 08:37:32 -06:00
Todd C. Miller
b519481912
Defer logging of the successful command until approval plugins have run.
...
This adds audit plugin support to the sudoers module, currently
only used for accept events. As a result, the sudoers file is now
initially parsed as an audit plugin.
2020-06-02 09:07:46 -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
5635c22f6b
Add --disable-log-server and --disable-log-client configure options.
...
These can be used to optionally disable building sudo_logsrvd and
support for remote I/O logging in the sudoers plugin respectively.
2020-02-26 13:17:40 -07:00
Todd C. Miller
f6a264e719
Avoid calling sudoers_policy_exec_setup() on error.
...
We only want to pass the execution environment back for commands
that are accepted or rejected.
Also avoid potentially freeing the wrong pointer when garbage
collection is enabled.
2020-02-24 19:59:44 -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
486ee2b71f
debug_decl and debug_decl_vars now require a semicolon at the end.
2019-12-22 08:48:16 -07:00
Todd C. Miller
4392b5726e
Output the name of the limit when warning about setrlimit or getrlimit.
...
From Kimmo Suominen.
2019-12-18 09:42:14 -07:00
Todd C. Miller
b14d633ec6
Add runas_check_shell flag to require a runas user to have a valid shell.
...
Not enabled by default.
2019-12-09 19:29:45 -07:00
Todd C. Miller
df8f06609c
Add a new flag "allow_unknown_runas_id" to control matching of unknown IDs.
...
Previous, sudo would always allow unknown user or group IDs if the
sudoers entry permitted it. This included the "ALL" alias.
With this change, the admin must explicitly enable support for unknown IDs.
2019-12-09 17:14:06 -07:00
Todd C. Miller
d10220162d
Don't touch the local iolog sequence file if we are logging remotely
2019-11-18 13:51:52 -07:00
Todd C. Miller
635445d471
Transparently handle the "sudo sudoedit" problem.
...
Some admin are confused about how to give users sudoedit permission
and many users try to run sudoedit via sudo instead of directly.
If the user runs "sudo sudoedit" sudo will now treat it as plain
"sudoedit" after issuing a warning. If the admin has specified a
fully-qualified path for sudoedit in sudoers, sudo will treat it
as just "sudoedit" and match accordingly. In visudo (but not sudo),
a fully-qualified path for sudoedit is now treated as an error.
2019-11-05 15:18:34 -07:00
Todd C. Miller
ee91b7360b
Simplify expand_iolog_path()
2019-10-24 20:04:33 -06:00
Todd C. Miller
7ba7c5835e
Enable sudo_logsrvd.conf settings.
2019-10-24 20:04:31 -06:00
Todd C. Miller
059b55ce72
Refactor code in sudoers that creates I/O log files to share with logsrvd.
2019-10-24 20:04:31 -06:00
Todd C. Miller
40bf4081be
Rename sudo_strtoid() to sudo_strtoidx() and add simplified sudo_strtoid()
2019-10-20 10:21:29 -06:00
Todd C. Miller
b02851dcf3
Change how the umask is handled with PAM and login.conf.
...
If the umask is explicitly set in sudoers, use that value regardless
of what is in PAM or login.conf. If using the default umask from
sudoers, allow PAM or login.conf to override it. Bug #900
2019-10-18 06:20:27 -06:00
Todd C. Miller
c49760e55d
Simpler change to retry sudo_secure_file() as root as needed.
2019-07-14 19:37:33 -06:00
Todd C. Miller
cecf69ff3c
If we are unable to stat() sudoers as non-root, try again as root.
...
By default, sudo relies soley on group permissions to read sudoers
to make it possible to store sudoers on NFS. However, if /etc/sudoers
is not accessible to non-root uids for some reason, sudo will fail.
Bug #880 .
2019-07-14 18:51:50 -06:00
Todd C. Miller
9d8f374397
Add ssizeof macro that returns ssize_t.
...
We can use this instead of casting the result of size_t to int.
Also change checks for snprintf() returning <=0 to <0.
2019-06-25 09:45:10 -06:00
Todd C. Miller
29223d7f64
In tty_present(), check for /dev/tty if sudo was unable to get the tty name.
...
For requiretty it is enough to check that /dev/tty is available.
If sudo can't get the tty from the kernel (missing /proc?) that is OK.
2019-06-19 20:32:22 -06:00
Todd C. Miller
1e1ef61902
Add SPDX-License-Identifier to files.
2019-04-29 07:21:51 -06:00
Todd C. Miller
f3344b5881
Fix pasto; the unrestricted env file was read when we want the restricted one.
2019-02-19 11:03:02 -07:00
Todd C. Miller
985600e7f0
Minor snprintf() usage tweaks:
...
1) don't assume snprintf() returns -1 on error, check for <0
2) when comparing return value of sizeof(foo), cast the sizeof, not the len
3) cast return value to void in cases where snprintf cannot fail
2019-01-20 07:49:48 -07:00
Todd C. Miller
efe35e5b1e
Use debug_return_int not debug_return_bool in resolve_host
2018-12-24 20:31:26 -07:00