78 Commits

Author SHA1 Message Date
Todd C. Miller
b9275b7eab Rename submit_time -> event_time in struct eventlog. 2023-11-23 09:08:04 -05:00
Todd C. Miller
0e53d5fddf We can use evlog.submit_time in the call to eventlog_alert().
This is set to the current wallclock time by sudoers_to_eventlog().
2023-11-23 09:08:04 -05:00
Todd C. Miller
432b085558 log_server_open: always pass in awake time, not wallclock time.
The timespec passed to log_server_open() should be from
sudo_gettime_awake() since it is used to build the command run time.
2023-11-23 09:08:04 -05:00
Todd C. Miller
13dec64f3d log_server_alert: struct timespec argument was not actually used
The struct timespec argument is used to initialize the command
start time, which is not used for an alert message.
2023-11-23 09:08:04 -05:00
Todd C. Miller
2b87749f8f Only log the run environment for commands that are allowed.
It may not be available otherwise and unless the command is being
run it has no real meaning.
2023-10-21 19:15:44 -06:00
Todd C. Miller
e343e07543 Use #include <foo.h> instead of #include "foo.h" in most cases.
We rely on the include path to find many of these headers.  It
especially doesn't make sense to use #include "foo.h" for headers
in the top-level include directory.
2023-09-25 10:13:28 -06:00
Todd C. Miller
a9801cc99d Parse euid and egid from sudo front-end.
These are needed by bsm_audit.c.
2023-09-13 12:43:39 -06:00
Todd C. Miller
b42cab112f Call log_allowed() even when "log_allowed" is disabled.
Otherwise, sudo will not send mail if "mail_always" or "mail_all_cmnds"
is set.
2023-08-25 11:19:42 -06:00
Todd C. Miller
c7157ce0b1 Move a few fields from sudoers_user_contect to sudoers_context.
They are not really specific to the user or user-specified.
2023-08-21 15:30:12 -06:00
Todd C. Miller
9f05bfd298 Fix log_server_accept() definition for --disable-log-client builds. 2023-08-21 11:35:23 -06:00
Todd C. Miller
3473bf9360 Move sudo_mode into struct sudoers_context. 2023-08-21 10:47:23 -06:00
Todd C. Miller
837da1bef0 Move NewArgv, NewArgc and saved_argv into struct sudoers_context. 2023-08-21 09:22:24 -06:00
Todd C. Miller
2440174954 Make struct sudoers_context private to sudoers.c.
We now pass a pointer to the context where necessary.  There are a
few cases where we need to request the context from sudoers via
sudoers_get_context() for the plugin API functions.  If the plugin
API was able to pass around a closure pointer this would not be
necessary.
2023-08-21 09:21:49 -06:00
Todd C. Miller
2d2529a15e Add a sudoers_context struct that embeds the user and runas structs. 2023-08-20 16:27:08 -06:00
Todd C. Miller
bd8cccb5dd Rename struct sudo_user -> struct sudo_user_context.
Also rename the sudo_user global to user_ctx.
2023-08-12 10:39:47 -06:00
Rose
5d758264ab Give every printf-like function restrict qualifiers
The format value has to be a string literal, every time.

Otherwise, you are not using these functions correctly. To reinforce this fact, I putrestrict over every non-contrib example of this I could find.
2023-07-07 20:23:20 -04:00
Todd C. Miller
0a4c8872a8 The I/O log file name is not just the basename of the full iolog_path.
The audit plugin already has the correct value for iolog_file, don't
overwrite it with basename(iolog_path).  In the future we may wish
to pass in iolog_file and iolog_dir in addition to iolog_path.
Fixes Bug #1046.
2023-03-31 15:51:14 -06:00
Todd C. Miller
ce387a6849 Split log_{input,output} into log_{stdin,ttyin} and log_{ttyout,stdout,stderr}
If log_input is set, log_{stdin,ttyin} will be set as well.
If log_output is set, log_{stdout,stderr,ttyout} will be set as well.
This provides more fine-grained control over I/O logging and makes it
possible to disable logging piped or redirected intput or output.
2022-09-20 14:35:12 -06:00
Todd C. Miller
02e92c2afd Set MODE_POLICY_INTERCEPTED for log_subcmds too.
This fixes a problem where sub-commands were not being logged to
the remote log server, if configured.  Since we don't go through
sudoers_policy_main() again for log_subcmds, we set the flag in
sudoers_audit_accept() instead.  The reason this is complicated is
that when I/O logging is enabled the initial accept message gets
sent as part of the remote logging handshake.  GitHub issue #174
2022-09-03 09:43:41 -06:00
Todd C. Miller
885abf48d7 Save the initial command run via sudo and use it when logging exit status.
Otherwise, if we are in intercept mode or logging sub-commands the
exit status will be logged with the wrong command.
2022-06-30 11:10:43 -06:00
Todd C. Miller
f5ac1317c4 Make sudo pass -Wmissing-prototypes 2022-06-27 12:48:03 -06:00
Todd C. Miller
d04810c4f2 Save a pointer to the event_alloc parameter in the plugin open function.
That way we don't need to pass event_alloc around to the log client
functions.
2022-06-09 13:05:21 -06:00
Todd C. Miller
d7ddff2a31 Add a hook for sudoers parse errors (including defaults and aliases).
The hook can be used to log parser errors (sudoers module) or keep
track of which files have an error (visudo).
Previously, we only kept track of a single parse error.
2022-03-10 13:30:56 -07:00
Todd C. Miller
72989bf83f Quiet two PVS-studio warnings. 2022-01-05 11:04:18 -07:00
Todd C. Miller
00f0c233b2 Only include log_client.h if SUDOERS_LOG_CLIENT is defined. 2021-10-21 19:46:35 -06:00
Todd C. Miller
ec751c63eb log_allowed: pass struct eventlog * instead of argv[] and envp[].
This lets us log based on the command_info[] list passed in from
the front-end.  Previously, much of the struct eventlog was constructed
from internal sudoers state instead.
2021-08-25 17:29:15 -06:00
Todd C. Miller
e2abcd6cb6 log_server_accept: fix memory leak of evlog when logging a sub-command.
Coverity CID 238643
2021-08-14 09:11:02 -06:00
Todd C. Miller
dae370fb70 Use a separate uuid for intercepted commands.
We use the uuid to match the command with its exit status.
2021-08-09 15:50:26 -06:00
Todd C. Miller
2e99450d40 Fix logging intercepted commands to a log server in sudoers.
Only available when the server supports the subcommands capability.
2021-08-09 15:50:26 -06:00
Todd C. Miller
1ae9954c63 Use run_argv and run_envp passed into the audit plugin for event logging.
Previously we used NewArgv[] and env_get() but now that logging is
performed via an audit plugin we should use the values passed in.
2021-08-09 15:50:25 -06:00
Todd C. Miller
8fa897d3ae Move log_server_accept() out from under the #ifdef SUDOERS_LOG_CLIENT
Fixes a link error when sudo is configured with --disable-log-client.
2021-04-01 15:10:32 -06:00
Todd C. Miller
0663ffbc3f Use sudo_basename() instead of doing the equivalent manually. 2021-02-10 15:14:08 -07:00
Todd C. Miller
5c66e9532e Set sudoers_audit.close to NULL if not using a log server. 2020-12-11 08:46:39 -07:00
Todd C. Miller
27615b5582 For the audit plugin, command_info may be NULL.
Fixes a NULL dereference in sudoers_audit when an I/O logging
plugin rejects input/output or returns an error.
2020-11-17 13:04:57 -07:00
Todd C. Miller
2b71b61044 Update struct eventlog based on command_info[] from front-end.
The I/O log path is not known until the I/O log plugins have
run and other plugins may alter the execution environment.
2020-11-14 11:42:27 -07:00
Todd C. Miller
56fb16d3e8 Use sudoers_to_eventlog() and init_log_details() in sudoers_audit_accept().
log_deserialize_info() can be private to iolog.c again.
2020-11-09 17:15:11 -07:00
Todd C. Miller
62525dcc94 Log reject and alert messages to the log server if one is defined. 2020-11-09 17:15:02 -07:00
Todd C. Miller
e56c3b342b Rename iolog_plugin.h to log_client.h.
It is no longer I/O log specific and is used by sudoers_audit too.
2020-11-09 17:13:04 -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
2112d9beb1 Log accept messages in sudoers_audit if not I/O logging. 2020-11-04 05:39:16 -07:00
Todd C. Miller
4416bd5977 Use libeventlog in sudoers instead of doing our own logging. 2020-10-26 16:10:40 -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
985af422d2 Rename __dso_public -> sudo_dso_public and move to config.h. 2020-08-12 09:57:42 -06:00
Todd C. Miller
ac00a07018 Initialize sudo_conv and sudo_printf in sudoers_audit_open().
We will need them if there is an error parsing sudoers and leaving
them unset can result in NULL deref.  Also set the text domain to
"sudoers" like we do for the policy and I/O logging open functions.
Bug #934.
2020-07-12 10:13:53 -06:00
Todd C. Miller
f047377a07 Add basic support for reject and error audit events to sudoers.
This is only used when logging events from plugins other than sudoers,
such as an approval plugin.  With this change, if an approval
plugin rejects the command the denial will be logged in the
sudoers log file using the message from the approval plugin.
2020-06-04 14:41:35 -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
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
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
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
cf6c60c102 Add log_allowed and log_denied sudoers flags, defaulting to true. 2019-10-17 13:43:04 -06:00