Commit Graph

3603 Commits

Author SHA1 Message Date
Todd C. Miller
e7d4c05ace check_user_runcwd: allow -D option if it matches the cwd in sudoers
Previously, check_user_runcwd() would return true if the runcwd
matched the user's cwd, even if sudoers specified a different one.
The user-specified runcwd was ignored but it is better to error out
in this case.  It is now also possible to use "sudo -D" with the
directory specified in sudoers.
2023-06-28 09:59:33 -06:00
Todd C. Miller
f2a274b061 Rename parse.c -> lookup.c now that it only contains sudoers_lookup. 2023-06-29 10:52:44 -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
Rose
e54ba33ea0 Avoid compiler casting warnings by assigning to the same type where possible
This saves instructions that are related to casting as well as compiler warnings.
2023-06-28 17:25:26 -04:00
Rose
0bb41ed82a Set command_info to NULL once it is freed
The lack of setting to NULL is a holdover from when command_info was a local variable and not a global one. However, we given how other global variables are set to NULL, it is best that we do the same here to avoid potential issues should sudoers_policy_store_result be called again after the first time failed, otherwise we could get a double-free.
2023-06-26 15:08:51 -04:00
binlingyu
f8a45e8a54 Modify the is_script function for match_command.c 2023-06-25 11:15:17 +08:00
Todd C. Miller
3bdd2214ad Merge pull request #266 from AtariDreams/c99
Do variable length arrays the C99 way
2023-06-20 13:29:30 -06:00
Todd C. Miller
69b486d462 Merge pull request #269 from trackers-lover/main
correct the return value type of function alias_find_used
2023-06-19 10:39:59 -06:00
Todd C. Miller
4da1f373de Add commented out example for disabling use_pty. 2023-06-18 08:03:46 -06:00
Rose
7fd680c983 Do variable length arrays the C99 way
Variable length arrays are supported by C99, but having it denoted as "1" confused the compiler and is not defined.

Note that because we don't get the inferred NULL terminator, we have to increase the malloc size by one.
2023-06-15 15:25:17 -04:00
Todd C. Miller
c5c589da04 Updated translations from translationproject.org 2023-06-14 11:08:57 -06:00
Todd C. Miller
baf482763c Add tests to exercise recent runas user and group bug fixes. 2023-06-14 10:29:07 -06:00
Todd C. Miller
0d17325039 Add test to exercise the bug that prevented the group specified via
"sudo -g" from matching when a Runas_Alias was used in the user or
group portion of a Runas_Spec.
2023-06-14 10:15:38 -06:00
Todd C. Miller
78e65e14ea runaslist_matches: split out user_list and group_list matching.
This makes it possible to call the appropriate runas user or group
list match function when resolving aliases instead of calling
runaslist_matches() itself.  Fixes a bug that prevented the group
specified via "sudo -g" from matching when a Runas_Alias was used
in the user or group portion of a Runas_Spec.
2023-06-13 20:13:24 -06:00
Todd C. Miller
4710283516 runaslist_matches: fix bug when no runas list is specified in sudoers.
If a sudoers rule has no runas list, a user-specified runas group
should only be allowed if it matches a group that the default runas
user belongs to.  Instead, a missing group check allowed the user
run commands as the default runas user with an arbitrary group.

This means that a rule like "somebody host = ALL", which should be
equivalent to "somebody host = (root) ALL", had the same effect as
"somebody host = (root:ALL) ALL".
2023-06-13 10:29:00 -06:00
Todd C. Miller
8c1559e0e3 runaslist_matches: remove special case to handle "sudo -g group"
Now that we are guaranteed to have a runas user list for all sudoers
rules that contain a runas list, we can remove support for the
special case where user_matched is set in the runas group matching
conditional.  This fixes a bug where "sudo -u myuser -g mygroup"
was permitted by a rule like "myuser ALL = (root) ALL".
2023-06-13 16:03:25 -06:00
Todd C. Miller
64ab8cd236 Populate runasusers even when only a grouplist is specified.
When a sudoers rule permits the user to run commands as a group,
not a user, we should set the runasusers to single member with the
special MYSELF token.  This guarantees that the only time runasusers
will be NULL is when no runaslist is present.
2023-06-13 15:46:46 -06:00
Todd C. Miller
a28d2d4128 Python may be built with 32-bit time_t support on 32-bit platforms.
We need to undef the SIZEOF_TIME_T from pyconfig.h so it does not
conflict with our own.
2023-06-11 14:05:02 -06:00
bianguangze
b4dcac650f correct the return value type of function alias_find_used 2023-06-09 09:46:05 +08:00
Todd C. Miller
5baf817dbc Updated translations from translationproject.org 2023-06-07 13:29:23 -06:00
Todd C. Miller
2c58d80751 Update .pot files for 1.9.14 2023-06-07 13:27:47 -06:00
Todd C. Miller
3786654dbd Add NETGROUP_QUERY option for servers that can't match nisNetgroupTriple.
This can be used to support netgroup queries on systems that lack
the innetgr() function and where the LDAP server cannot query the
nisNetgroup by nisNetgroupTriple.
2023-06-07 10:10:52 -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
2392ee9d7d run_command: back out changes to run editor in its own process group.
It unnecessarily complicates things to work around bugs in an OS
almost no one runs.
2023-06-04 19:11:48 -06:00
Todd C. Miller
95cd409079 Make suspend_parent.c out of lib/util and into src.
Nothing else uses it now.
2023-06-04 19:08:52 -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
d633d82f22 Fix typos and update excluded/ignored codespell lists. 2023-05-25 12:53:27 -06:00
Todd C. Miller
0986a8846e run_command: check that ttyfd is not -1 before using it 2023-05-19 13:38:48 -06:00
Todd C. Miller
4d417b46d9 Work around a macOS a kernel bug where tcsetpgrp() does not restart.
I reported this bug to Apple over 12 years ago.
2023-05-11 18:22:06 -06:00
Todd C. Miller
be20e1592f run_command: run editor in foreground if visudo is the foreground process
The command is now always run in its own process group.  If visudo
is run in the foreground, the command is run in the foreground too.
Otherwise, run the command in the background.  There is a race
between the tcsetpgrp() call in the parent and the execve() in the
child.  If we lose the race and the command needs the controlling
terminal, it will be stopped with SIGTTOU or SIGTTIN, which the
waitpid() loop will handle.
2023-05-11 18:20:50 -06:00
Todd C. Miller
7e28e60b56 Accept carriage return for EOL in addition to newline.
Since visudo doesn't alter the terminal settings it is possible for
the terminal to have the ONLCR bit set in the output control flags.
In that case, we will get a CR, not a NL when the user presses
enter/return.  One way this can happen is if visudo is run in the
background from a shell that supports line editing and the editor
restores the (cbreak-style) terminal mode when it finishes.
2023-05-11 18:12:54 -06:00
Todd C. Miller
91f100f5bc check_fill: sudoers_strict() is now a function, not a global variable 2023-05-09 14:16:17 -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
01ff7c476d parse.h is already included by sudoers.h. 2023-05-09 13:44:16 -06:00
Todd C. Miller
bde363e060 Rename parser_conf -> sudoers_conf in all but the parser itself. 2023-05-09 07:29:06 -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
fb9d0d79a7 push_include_int: Avoid passing close(2) a negative value on error.
Coverity CID 314108
2023-05-08 14:18:56 -06:00
Todd C. Miller
f722272b7c Eliminate dead store. Coverity CID 315032. 2023-05-08 14:15:48 -06:00
Todd C. Miller
c0fa3a4d24 Rename force_umask to override_umask and make it private to sudoers.c.
Add getter for policy.c.
2023-05-04 13:46:20 -06:00
Todd C. Miller
72489d7a83 Make timestamp_uid and timestamp_gid private to timestamp.c.
Add getter (for set_perms.c) and setter (for sudoers.c).
2023-05-04 13:08:23 -06:00
Todd C. Miller
d5de5890f5 Make login_style private to bsdauth.c
Add a setter for policy.c to handle auth_type from the front-end.
2023-05-04 13:06:09 -06:00
Rose
459a49b1fe Prefer size_t over int, as casting can take extra instructions 2023-05-03 15:18:05 -04: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
80768ed3a8 Make path_ldap_conf and path_ldap_secret private to policy.c.
Add getters for both so the ldap code can access them.
2023-05-02 10:47:53 -06:00
Todd C. Miller
f553ddc430 Make sudoers_file private to policy.c and visudo.c.
We just need a way for the policy (and visudo) to override the
default sudoers path.  This adds a getter to be used in file.c when
sudoers is first opened.
2023-05-02 10:47:47 -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
7a6ac5d26e Track the destination sudoers path for each parsed file.
When adminconfdir is enabled, the destination pathh may be different
from the path we opened.  We always store an edited file in the
adminconfdir (if enabled).  This makes it possible to use visudo
when /etc/sudoers is located on a read-only file system.
2023-05-02 10:45:56 -06:00
Todd C. Miller
d4c6ef1222 Add adminconfdir and --enable-adminconf to set it.
Configuration paths in sudo are now a colon-separated list of files
with the adminconfdir instance first (if enabled), followed by a
sysconfdir instance.
2023-05-02 10:37:39 -06:00