143 Commits

Author SHA1 Message Date
THE-Spellchecker
5eba4b48cf Typographical and Grammatical fixes 2023-11-28 15:00:04 -07:00
Todd C. Miller
a2998a6701 alias_apply: change return type to bool
We can use the rbapply() return value to detect failure.
2023-11-09 15:31:26 -07:00
Todd C. Miller
886f1414eb Move the check for running setid commands in intercept mode to later.
Checking for setid commands in intercept mode after command matching
allows us to log a proper error message.  Previously, we simply
ignored setid commands when matching and the only indication of why
was in the debug logs.
2023-11-02 13:44:17 -06:00
Todd C. Miller
2d437c793d Fix spelling: resistent -> resistant 2023-10-12 10:20:34 -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
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
51d6b0f425 Promote verbose flag to int for display_privs and display_cmnd.
A negative verbosity will prevent non-error output from being
displayed.
2023-09-15 10:01:35 -06:00
Todd C. Miller
2ef90231a1 Make all match functions return ALLOW/DENY not true/false. 2023-09-09 14:07:06 -06:00
Todd C. Miller
7873f8334c Try to make sudo less vulnerable to ROWHAMMER attacks.
We now use ROWHAMMER-resistent values for ALLOW, DENY, AUTH_SUCCESS,
AUTH_FAILURE, AUTH_ERROR and AUTH_NONINTERACTIVE.  In addition, we
explicitly test for expected values instead of using a negated test
against an error value.  In the parser match functions this means
explicitly checking for ALLOW or DENY instead of accepting anything
that is not set to UNSPEC.

Thanks to Andrew J. Adiletta, M. Caner Tol, Yarkin Doroz, and Berk
Sunar, all affiliated with the Vernam Applied Cryptography and
Cybersecurity Lab at Worcester Polytechnic Institute, for the report.
Paper preprint: https://arxiv.org/abs/2309.02545
2023-09-09 14:07:04 -06:00
Todd C. Miller
87571dab0a Add struct sudoers_conf to struct sudoers_plugin_context.
There's now no need to pass this directly to init_parser() since we
already pass in a pointer to a sudoers_context struct.
2023-08-21 09:21:54 -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
0f2e5dae90 Use const pointers where possible in the display code. 2023-08-09 11:19:17 -06:00
Todd C. Miller
60eef27e6d Add verbose version of "sudo -l command" by using an extra -l.
The output of "sudo -ll command" consists of the matching sudoers
rule (in long form) with the addition of a "Matched" entry that
shows the fully-qualfied path along with any arguments.
2023-08-09 10:16:10 -06:00
Todd C. Miller
f6a9bb2e23 Use a single callback for sudoers_lookup() and add a closure pointer.
The single callback now receives all the match info (or UNSPEC if
no match was attempted).  This makes it possible to use the callback
for more than just printing testsudoers output.
2023-08-07 15:06:19 -06:00
Todd C. Miller
cbcb1d2506 sudoers plugin: make more bit flags unsigned. 2023-07-10 11:06:23 -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
e025cca440 Add callbacks to sudoers_lookup() so we can use it in testsudoers.
Also pass in the time to be used for NOTBEFORE/NOTAFTER checks.
2023-06-29 17:30:39 -06:00
Todd C. Miller
8b640329d3 Split display_privs() and display_cmnd() out of parse.c into display.c 2023-06-29 10:31:09 -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
1278e36ff3 Initialize digest_type to SUDO_DIGEST_INVALID, not -1 and make it unsigned.
This makes the digest type consistently unsigned instead of a mix
of signed (for the -1 value in the tokenizer) and unsigned.
2023-06-03 08:59:14 -06:00
Todd C. Miller
f352ef5d67 Move parser prototypes / externs from sudoers.h to parse.h or toke.h. 2023-05-09 14:01:41 -06:00
Todd C. Miller
8cbd5462a6 Move sudoers search path to struct sudoers_parser_config.
That way we can avoid passing it to init_parser() directly.
We still need sudoers_search_path to be shared between the lexer
and the parser.
2023-05-08 17:04:38 -06:00
Todd C. Miller
9d7c30c5a8 Add struct sudoers_parser_config and pass it to init_parser().
This struct contains parser configuration such as the sudoers file
uid/gid/mode and parse flags such as verbose, strict and recovery.
2023-05-08 17:03:31 -06:00
Todd C. Miller
bbbaea5b2f Rename init_parser_ext() to init_parser() and remove old wrapper.
There was only one consumer of the init_parser() wrapper now that
reset_parser() has been introduced.
2023-05-02 13:29:49 -06:00
Todd C. Miller
f258a15df5 Add reset_parser() and use in place of init_parser(NULL). 2023-05-02 13:27:17 -06:00
Todd C. Miller
5446b009e3 Support adminconfdir for relative include paths in sudoers. 2023-05-02 10:47:11 -06:00
Todd C. Miller
8049e4e32f Replace sudoers_warnings with sudoers_verbose.
This is now an int, with values > 1 reserved for visudo.
2023-03-20 18:27:27 -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
0aad96bba1 Add per-source innetgr function pointer and use it in netgr_matches().
This will be used to implement LDAP-specific netgroup lookups when
netgroup_base is set in ldap.conf.
2023-03-08 13:44:22 -07:00
Todd C. Miller
689022978c A user with "list" privs for root may not list all users.
A user with "sudo ALL" for root _is_ allowed to list any user.
2023-03-03 13:57:27 -07:00
Todd C. Miller
78ff514358 match_command: apply runchroot if set when matching the command
Previously we would prepend runchroot to the path we were checking
but that does not properly handle symbolic links.
2023-02-21 13:24:33 -07:00
Todd C. Miller
e5d98da014 Move hexchar() from the sudoers plugin to lib/util. 2023-01-03 15:50:42 -07:00
Todd C. Miller
a2b0a8330c Fix a few whitespace issues. 2022-07-09 11:21:17 -06:00
kernelmethod
c20859d55b Add an APPARMOR_PROFILE user spec option to sudoers
sudoers now supports an APPARMOR_PROFILE option, which can be specified
as e.g.

    alice       ALL=(ALL:ALL)   APPARMOR_PROFILE=foo    ALL

The line above says "user alice can run any command as any user/group,
under confinement by the AppArmor profile 'foo'." Profiles can be
specified in any way that complies with the rules of
aa_change_profile(2). For instance, the sudoers configuration

    alice       ALL=(ALL:ALL)   APPARMOR_PROFILE=unconfined     ALL

allows alice to run any command unconfined (i.e., without an AppArmor
profile), while

    alice       ALL=(ALL:ALL)   APPARMOR_PROFILE=foo//&bar      ALL

tells sudoers that alice can run any command under the stacked AppArmor
profiles 'foo' and 'bar'.

The intention of this option is to give sysadmins on Linux distros
supporting AppArmor better options for fine-grained access control.
Among other things, this option can enforce mandatory access control
(MAC) over the operations that a privileged user is able to perform to
ensure that they cannot privesc past the boundaries of a specified
profile. It can also be used to limit which users are able to get
unconfined system access, by enforcing a default AppArmor profile on all
users and then specifying 'APPARMOR_PROFILE=unconfined' for a privileged
subset of users.
2022-05-23 13:41:56 -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
86d2173937 Add support for matching command and args using regular expressions.
Either the command, its arguments or both may be (separate)
regular expressions.
2022-02-10 18:26:24 -07:00
Todd C. Miller
10ad934b77 Don't escape double quotes (") in a command when printing it.
Previously, cvtsudoers and "sudo -l" would escape double quotes in
a command or command line argument, which is not valid sudoers syntax.
2022-02-08 15:44:18 -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
730ebabdba init_parse_tree() now takes ownership of lhost and shost, if any.
This means that lhost and shost in struct sudoers_parse_tree
are no longer const and that free_parse_tree() will free lhost/shost.
The only consumer that passed in lho.st/shost was the SSSD back-end
which has been updated to avoid a double-free.
2021-11-19 12:29:21 -07:00
Todd C. Miller
ab9e44a6ca cvtsudoers: merge aliases when multiple sudoers files are specified
Duplicate aliases are remove.  If there are conflicting alias names,
the conflicts are renamed by appending a numerical suffix.
For example, if there are two SERVERS Host_Aliases, the second one
will be renamed to SERVERS_1.
2021-11-19 12:29:21 -07:00
Todd C. Miller
b1309f76db Add sudoers_parse_tree_list, a tail queue of struct sudoers_parse_tree.
This will be used to store multiple parse trees and merge them
into a single sudoers_parse_tree.
2021-11-11 15:40:51 -07:00
Todd C. Miller
4eebd53bce parse_gentime: use timegm() to generate time since the epoch
The timegm() function is non-standard but widely available.
Provide an implementation for those systems that lack it.
Bug #1006
2021-10-31 09:27:34 -06:00
Todd C. Miller
1831176a1a Add the ability to filter/match by command via the -m option.
For example "cvtsudoers -m cmd=/bin/ls" would only display entries
that would allow /bin/ls to be allowed or denied.
2021-09-24 10:44:13 -06:00
Todd C. Miller
f9d3f46fa7 Add intercept_allow_setid sudoers option, disabled by default.
With this change, a shell in intercept mode cannot run a setuid or
setgid binary by default.  On most systems, the dynamic loader will
ignore LD_PRELOAD for setuid/setgid binaries such as sudo which
would effectively disable intercept mode.
2021-08-18 15:43:26 -06:00
Todd C. Miller
786e5865cb Add "intercept" Defaults setting to allow interception of sub-commands.
This causes "intercept" to be set to true in command_info[] which
the sudo front-end will use to determine whether or not to intercept
attempts to run further commands, such as from a shell.  Also add
"log_children" which will use the same mechanism but only log (audit)
further commands.
2021-08-09 15:50:25 -06:00
Todd C. Miller
5a85543c16 Move alias checking code out of visudo.c and into check_aliases.c. 2021-02-23 18:42:37 -07:00
Todd C. Miller
921097cb67 Add back SUDOERS_NAME_MATCH and enable it when fuzzing.
This avoids the test environment from influencing sudoers matching.
2021-02-21 13:39:56 -07:00
Todd C. Miller
568931035d Move new_member_all to ldap_util.c, it is only used by ldap/sssd. 2021-01-31 05:44:40 -07:00
Todd C. Miller
9ed14870c6 Add garbage collection to the sudoers parser to clean up on error.
This makes it possible to avoid memory leaks when there is a parse error.
2021-02-01 15:06:20 -07:00