215 Commits

Author SHA1 Message Date
Todd C. Miller
ecdf0c80f3 Add pam_silent sudoers option.
Inspired by PR #368
GitHub issue #216
2024-04-17 19:30:11 -06:00
Todd C. Miller
7019148160 Fix printing of warning when a Defaults setting is missing a value.
This is a bug in parse_default_entry() introduced in sudo 1.8.19
when support for using the default syslog facility was added at the
wrong place in a switch().
2023-12-16 08:08:44 -07:00
Todd C. Miller
f67a7e623e Sprinkle some more const in defaults.c. 2023-12-15 15:05:02 -07:00
Todd C. Miller
2df637b262 Fix evaluation of a tuple used in "true" boolean context.
Previously, a tuple in boolean context was always treated as a
negated entry, which doesn't match the documentation.  We assume
that there are at least two tuple entries where the first maps to
boolean false and the second maps to boolean true.
2023-12-15 14:57:59 -07:00
Todd C. Miller
1a11be4d9f store_plugin: avoid potential NULL deref in boolean context
Coverity CID 330466
2023-11-02 14:26:44 -06:00
Todd C. Miller
1398289fab Add casts when storing values in a struct timespec.
Fixes -Wconversion warnings on some 32-bit systems where time_t is
still 32-bit.
2023-09-27 15:11:10 -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
1c13b8a628 Add support for "plugin" defaults type. 2023-09-24 16:28:36 -06:00
Todd C. Miller
e28dc0f275 Add parser_warnx() and parser_vwarnx() that displays file:line:col
Used by defaults.c and check_aliases.c.
2023-09-18 12:42:51 -06:00
Todd C. Miller
b8f2680cf0 Make flag in union sudo_defs_val bool to match how it is used.
Adjust find_path()'s ignore_dot function argument to match.
2023-09-13 14:59:29 -06:00
Todd C. Miller
68a9e91860 Move default value for "iolog_file" to sudo_iolog.h. 2023-08-29 11:46:58 -06:00
Todd C. Miller
07003d9020 Disable fast_glob and fdexec if SUDOERS_NAME_MATCH is defined.
We use SUDOERS_NAME_MATCH for fuzzing when we want to avoid searching
the file system for commands.
2023-08-28 13:18:37 -06:00
Todd C. Miller
4cdee2e312 Don't set defaults values for features that are not present.
This means that lecture_status_dir and timestampdir are only set
if _PATH_SUDO_LECTURE_DIR and _PATH_SUDO_TIMEDIR respectively are
set.  Also, the log server defaults are only set when SUDOERS_LOG_CLIENT
is defined.
2023-08-25 11:19:42 -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
a38b714667 sudoers plugin: silence most -Wconversion warnings. 2023-07-07 15:07:04 -06:00
Todd C. Miller
6fddb2875c sudo_ldap_check_non_unix_group: pass nss pointer to netgr_matches()
This allows us to use the LDAP-specific version of innetgr() when
possible.  Also enable "use_netgroups" by default even on systems
without innetgr() since we can now query netgroups directly via
LDAP.
2023-06-06 19:55:06 -06:00
Todd C. Miller
894daa88f6 Enable the use_pty option by default for sudo 1.9.14.
GitHub issue #258
2023-04-06 11:30:51 -06:00
Todd C. Miller
1f19a6b72b Pass around const struct sudoers_parse_tree pointers where possible. 2023-03-17 13:31:36 -06:00
Todd C. Miller
304726a215 Move gcc-style __attribute__ macros to config.h.in
Renamed __malloc -> sudo_malloclike, __printflike -> sudo_printflike,
__printf0like -> sudo_printf0like.
Add sudo_noreturn instead of __attribute__((__noreturn__)).
We do not use stdnoreturn.h since it has been deprecated in C23
in favor of the [[noreturn]] attribute.
2022-09-07 07:48:31 -06:00
Todd C. Miller
3ce19efca9 Add intercept_verify sudoers option to control execve(2) argument checking. 2022-07-29 15:22:27 -06:00
Todd C. Miller
13672f28df Make sudo pass -Wwrite-strings 2022-06-28 16:33:15 -06:00
Todd C. Miller
dc8311dae9 Fix potential signed integer overflow on 32-bit CPUs.
Converting fractional minutes to nanoseconds could overflow a 32-bit
integer, use long long instead.
2022-05-27 15:47:32 -06:00
Todd C. Miller
f053f174bc Add intercept_type sudoers option to set intercept/log_subcmds mechanism. 2022-05-24 13:39:28 -06:00
Todd C. Miller
4ab6a87b96 Initialize intercept_allow_setid to true if we use ptrace(2) and seccomp(2). 2022-05-04 13:32:28 -06:00
Todd C. Miller
65e5b89f1d Pass file, line and column to sudoers defaults callbacks. 2022-03-10 13:35:58 -07: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
7c17f84a35 Add helper function to compile a regex that supports (?i). 2022-02-11 12:01:31 -07:00
Todd C. Miller
85fef8b50f Add sudoers option to perform authentication even in non-interative mode.
If noninteractive_auth is set, authentication methods that do not
require input from the user's terminal may proceed.  It is off by
default, which restores the pre-1.9.9 behavior of "sudo -n".
2022-02-01 20:08:26 -07:00
Todd C. Miller
c58a080dd5 Add a flag to avoid splitting list entries on white space. 2022-01-28 08:52:41 -07:00
Todd C. Miller
0efe280037 Add a new sudoers settings log_passwords and passprompt_regex.
When logging terminal input, if log_passwords is disabled and any
of the regular expressions in the passprompt_regex list are found
in the terminal output, terminal input will be replaced with '*'
characters until a newline or carriage return is found in the input
or an output character is received.
2022-01-28 08:52:41 -07:00
Todd C. Miller
86f123cd9d Pass the operator to the Defaults callback too.
That way we can tell what to do in callbacks for lists.
2022-01-28 08:52:41 -07:00
Todd C. Miller
e1c2288fbc Don't set/run early Defaults if a custom defaults_list is specified.
Defaults settings passed in by the front end are already "early"
so there is no need to treat any of them as special.

Otherwise, we end up running the early defaults callbacks before
sudoers has been parsed.  This means that, for instance, it is not
possible to disable the fqdn flag before its callback is run if
sudo is build with the --with-fqdn option.  Bug #1016.
2022-01-18 15:38:57 -07:00
Todd C. Miller
28cfe868ec Mark is_early_default(), run_early_defaults(), set_early_default() static.
They are not used outside of defaults.c.
2022-01-18 13:40:59 -07:00
Todd C. Miller
83defd3a6f Fix CodeQL "Multiplication result converted to larger type" warnings. 2021-12-10 13:33:07 -07:00
Todd C. Miller
e64a089aea Add reference counting to Defaults bindings.
Previously, we checked that the previous entry's binding pointer
was not the same while freeing.  However, to be able to merge
Defaults records we cannot rely on Defaults entries with the same
binding being immediately adjacent.  This removes the prev_binding
checks in favor of a reference count which allows us to plug the
memory leak in cvtsudoers when merging Defaults.
2021-11-20 08:01:37 -07:00
Todd C. Miller
8e656b63c8 free_defs_val: free rlimits like strings (which they are). 2021-11-09 13:45:06 -07:00
Todd C. Miller
19065cb221 Use strtoul() on systems without strtoull().
We can assume that systems without strtoull() have 32-bit resource limits.
2021-11-08 18:21:15 -07:00
Todd C. Miller
f279df5e18 Add basic support for setting resource limits in sudoers.
The default for rlimit_core is "0,0"
Resource limits are passed back to the front-end in command_info[]
when set.
2021-11-08 17:46:19 -07:00
Todd C. Miller
0ea561ca6a Limit paths for command, cwd and chroot to PATH_MAX bytes.
This helps prevent the fuzzer from going off the rails.
2021-09-19 18:13:43 -06:00
Todd C. Miller
d7cdf1e47c append_defaults() should not be passed a value for boolean flags.
The operation should simply be set to true/false.
Also treat a NULL file as coming from the front-end.
Bug #993.
2021-09-14 08:02:37 -06:00
Todd C. Miller
132936f8f0 Make it possible to call the sudoers policy check function multiple times.
We need to reset the Defaults values to their original state.
2021-08-09 15:50:25 -06:00
Todd C. Miller
1032fca5b8 Trying to use "+=" or "-=" operators on a non-list is an error.
Previously, they were simply treated as "=" for non-lists.
2021-07-29 09:29:10 -06:00
Todd C. Miller
d1cc1c59e8 Correct the integer overflow check in store_timespec().
Fixes oss-fuzz issue #31463
2021-02-26 16:43:48 -07:00
Todd C. Miller
b3b80fe6df Implement sudoers_policy_deregister_hooks()
Register/deregister hooks in fuzz_policy and also call show_version().
2021-02-25 15:02:09 -07:00
Todd C. Miller
7bafd52fac Remove unnecessary break statement. 2021-02-25 13:19:55 -07:00
Todd C. Miller
cbd11c44d2 Update Defaults settings after parsing sudoers.
Also stub out dump_defaults when fuzzing as it is not used.
2021-02-24 12:29:34 -07:00
Todd C. Miller
a5504148a5 Add admin_flag sudoers option and make --enable-admin-flag take a path.
It is now possible to disable the Ubuntu admin flag in sudoers
or change its location.
GitHub issue #56
2021-02-16 13:20:02 -07:00