Commit Graph

1652 Commits

Author SHA1 Message Date
Todd C. Miller
c6987aa26e Cast int to size_t before adding instead of casting the result.
Quiets PVS-Studio warning V1028.
2023-08-21 12:50:31 -06:00
Todd C. Miller
e933fc7ba3 Use a global static struct exec_closure for the cleanup hook.
This is safer than storing a pointer to a stack variable in the
cleanup function since we don't need to worry about it ever going
out of scope.  Quiets a clang 15 analyzer warning.
2023-08-21 10:47:34 -06:00
Todd C. Miller
d148e7d8f9 fd_matches_tty: only zero out fd_sb if fstat(2) fails.
We need to preserve the contents of the struct stat if the fd is
some other type so the check for piped output works correctly.
Bug #1057
2023-08-12 10:39:33 -06:00
Todd C. Miller
d6d467b92e Add implementation of SSL_read_ex/SSL_write_ex for those without. 2023-08-05 10:38:02 -06:00
Todd C. Miller
980e0216ac Add basic support for 32-bit and 64-bit LD_PRELOAD equivalents.
The noexec and intercept DSO settings may now include both a 32-bit
DSO and a 64-bit DSO specified by a colon.  For example:
/usr/libexec/sudo/sudo_intercept.so:/usr/libexec/sudo/sudo_intercept_64.so.
2023-07-31 13:46:57 -06:00
Todd C. Miller
7cb1f7f3a9 Cast TIOCSWINSZ to int to avoid overflow warning on 64-bit AIX. 2023-07-31 09:58:13 -06:00
Todd C. Miller
961f23af94 Read path section of sudo.conf for sudo_conf_intercept_path(). 2023-07-28 19:31:19 -06:00
Todd C. Miller
857653f9f5 Remove unused variable introduced in last commit. 2023-07-26 19:49:25 -06:00
Todd C. Miller
760c9c1107 Don't assume that if std{in,out,err} is a tty, it is the user's tty.
Previously, sudo only checked that the fd was a terminal, not that
it matched sudo's idea of the user's terminal.  This matters when
input or output is redirected to a different terminal.  In that
case we want to interpose the fd with a pipe even if it refers to
a terminal.  Bug #1056.
2023-07-26 19:43:49 -06:00
Todd C. Miller
78b712101e Pass SUDO_TERM_OFLAG to sudo_term_raw() when sudo output is piped.
This fixes a problem with "stair-stepped" output when the sudo-run
command's output is piped to another program and the command reads
input from the terminal.
2023-07-14 14:12:18 -06:00
Todd C. Miller
db4bdb7327 Simplify the exec_monitor() foreground flag.
Add cmnd_foreground flag that is only true if sudo is the foreground
process and the CD_EXEC_BG flag is not set and pass it to exec_monitor().
This means exec_monitor() no longer needs to check for CD_EXEC_BG.
2023-07-14 14:08:59 -06:00
Todd C. Miller
ff6ddff39b Fix a crash in intercept mode running a command with NULL argv[0].
Newer Linux kernels replace a NULL argv[0] with the empty string,
we should as well.
2023-07-12 09:29:00 -06:00
Todd C. Miller
b47f1799c5 sudo_conversation_printf: simplify \n -> \r\n handling 2023-07-12 08:39:18 -06:00
Todd C. Miller
a014b0f2aa sudo_conversation: zero out reply even if no password is requested.
This avoids a potential invalid free in the err label and provides
more predictable behavior when mixing message types in a conversation.
2023-07-12 08:16:35 -06:00
Todd C. Miller
dbb95ad214 sudo frontend: make more bit flags unsigned. 2023-07-10 11:06:34 -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
92860c717d struct exec_closure: make rows and cols int, not short
There's no real space saved by using short and using int avoids a
few casts.
2023-07-07 15:42:53 -06:00
Todd C. Miller
32f4b98f6b sudo frontend: silence most -Wconversion warnings. 2023-07-07 15:07:04 -06:00
Rose
cbed9daa46 Fixed even more signedness and conversion issues
This should be the last of them.
2023-07-03 22:07:35 -04:00
Todd C. Miller
04c7e910ef Fix up indentation. 2023-07-01 16:03:33 -06:00
Rose
45fdfa18f1 Mark functions not returning as sudo_noreturn
We also put NOTREACHED where it applies.
2023-07-01 17:40:16 -04:00
Todd C. Miller
97e574091a Avoid passing debug_return_size_t() a negative number. 2023-07-01 10:39:25 -06:00
Rose
22079c3072 Avoid compiler casting warnings Part 2
This saves instructions that are related to casting as well as compiler warnings.
2023-06-29 13:10:27 -04: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
Todd C. Miller
a0b074cc9c Fix undefined symbol on macOS for intercept mode and log_subcmds.
macOS does not support direct access to the environ pointer from a
shared object.  We need to redirect through _NSGetEnviron() instead.
Fixes GitHub issue #276.
2023-06-28 10:59:26 -06:00
Todd C. Miller
245c56bac1 Only call ptrace_verify_post_exec() for intercept, not log_subcmds. 2023-06-05 16:03:03 -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
27ea64bacd Use a "%s" format instead of using a translated string as the format. 2023-05-03 13:26:54 -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
Todd C. Miller
4363d03ef7 Convert config file paths to colon-separated path list.
This means that _PATH_SUDO_CONF, _PATH_SUDOERS, _PATH_SUDO_LOGSRVD_CONF,
and _PATH_CVTSUDOERS_CONF can now specify multiple files.  The first
file that exists is used.
2023-05-02 10:37:38 -06:00
Todd C. Miller
b1deffbe5b disable_coredump: only change the soft limit, leave the hard limit as-is
This should avoid problems on Linux in cases where sudo does not
have CAP_SYS_RESOURCE which may be the case in an unprivileged container.
GitHub issue #42
2023-04-24 10:32:40 -06:00
Todd C. Miller
6c3c8acbac More accurate description of what happens for "sudo -b". 2023-04-19 15:09:23 -06:00
Todd C. Miller
ab0f8dda31 Avoid calling isatty()/ttyname() on std{in,out,err} if not a char dev.
The user controls these fds so we should avoid calling ioctl(2) on
them unless they correspond to actual character device files.
2023-04-18 13:52:26 -06:00
Todd C. Miller
fe80c27dec Better support for "sudo -b" when running the command in a pty.
When a command is run via "sudo -b" it has no access to terminal
input.  In non-pty mode, the command runs in an orphaned process
group and reads from the controlling terminal fail with EIO.  We
cannot do the same while running in a pty but if we set stdin to a
half-closed pipe, reads from it will get EOF.  That is close enough.
2023-04-19 14:34:57 -06:00
Todd C. Miller
b24af7b3e6 Hard-code usage() and help() for an 80-column terminal.
Trying to tailor the help and usage output to the terminal width
is simply not worth it and could be abused to mark a socket as
"trusted" on Linux if there are additional kernel bugs like
CVE-2023-2002.
2023-04-18 07:33:12 -06:00
Todd C. Miller
65c0b5a089 Move CONFIGURE_ARGS from sudo_usage.h.in to config.h.in. 2023-04-18 07:29:37 -06:00
Todd C. Miller
80b85bdd50 get_user_info: call sudo_get_ttysize() even if no /dev/tty
We still want to initialize rows and cols based on the environment
if possible.
2023-04-17 07:27:05 -06:00
Todd C. Miller
4ac9941794 Get the tty size using stdout, not stderr, when printing help output.
While usage() prints to stderr, help() prints to stdout.
2023-04-16 16:06:59 -06:00
Todd C. Miller
d1912957ae get_user_info: pass sudo_get_ttysize() the fd of /dev/tty, not stderr.
Both the plugin API and the main event loop expect lines/cols to
refer to the user's terminal, so using /dev/tty is better here.
2023-04-16 16:05:15 -06:00
Todd C. Miller
cc22cca34f Add an fd argument to sudo_get_ttysize() instead of always using stderr.
For sudoreplay we open /dev/tty, so use that instead of stderr when
determining the terminal size.
2023-04-16 15:45:19 -06:00
Todd C. Miller
f0030cf30f Make struct {command,user}_details pointers const where possible. 2023-03-27 16:29:46 -06:00
Todd C. Miller
554397eaea Make user_details private to main. 2023-03-27 16:19:11 -06:00
Todd C. Miller
5108c279af Make user_details private to sudo.c. 2023-03-27 16:19:08 -06:00
Todd C. Miller
e435b158b8 Use sudo_get_ttysize() in help() and usage().
This eliminates a dependency on the user_details global.
2023-03-25 16:27:44 -06:00
Todd C. Miller
86002226b6 Store submitcwd (from user_details) in struct command_details.
This eliminates use of the user_details global from exec_setup().
2023-03-25 08:27:41 -06:00
Todd C. Miller
51453c4f2e utmp_fill: user is now always non-NULL, no need for user_details. 2023-03-24 19:16:44 -06:00
Todd C. Miller
fa5a28f345 Remove list_user global. 2023-03-24 19:10:46 -06:00
Todd C. Miller
a5b11a58b7 No need to declare tgetpass_flags, it is already in sudo.h. 2023-03-24 19:10:19 -06:00
Todd C. Miller
9fd787343d No need for sudo_mode to be global anymore. 2023-03-24 17:07:20 -06:00
Todd C. Miller
11277bb921 Make command_details private to main(). 2023-03-24 15:56:00 -06:00