Commit Graph

1652 Commits

Author SHA1 Message Date
Todd C. Miller
8d2b9a4343 Make iobufs private to exec_iolog.c. 2023-03-24 15:26:37 -06:00
Todd C. Miller
ee3f99c88c Remove ttymode and its associated values. 2023-03-24 15:25:05 -06:00
Todd C. Miller
f9b1beced2 Move ptyname to struct exec_closure 2023-03-24 14:56:45 -06:00
Todd C. Miller
22776b0be6 Move pty_make_controlling() to exec_monitor.c where it is called.
We can use details->tty to access the pty follower path.
2023-03-24 14:56:13 -06:00
Todd C. Miller
7ac9ce001c Eliminate utmp_user global, just use the value in struct command details. 2023-03-24 14:44:56 -06:00
Todd C. Miller
778688d4fc Replace tty_mode global with term_raw flag in struct exec_closure.
The pty_cleanup hook needs access to the closure so add
pty_cleanup_init() to store a pointer to the closure for use
by pty_cleanup_hook().
2023-03-24 14:44:17 -06:00
Todd C. Miller
b81c5e8dac Register pty cleanup function in exec_pty(), not exec_cmnd_pty().
We want it to execute in the main sudo process, not the monitor.
2023-03-24 11:01:58 -06:00
Todd C. Miller
11739e3def Make ttyblock private to exec_iolog.c 2023-03-24 10:58:49 -06:00
Todd C. Miller
3303dd98c0 exec_pty.c: move foreground flag to struct exec_closure.
Also make pipeline flag private to exec_pty() and remove the unneeded
check_foreground() prototype.
2023-03-23 19:35:57 -06:00
Todd C. Miller
51cdb194b8 On resume, always sync the pty terminal settings with /dev/tty.
Changes made to the terminal settings while the command is suspended
are now reflected in the pty when the command is resumed.  This is
more consistent with the non-pty behavior and allows for the removal
of the "tty_initialized" global.  One downside to this change is
that if a terminal-based program using the pty is stopped with
SIGSTOP it may have the wrong terminal settings on resume.
However, this is no different from the non-pty case.
2023-03-23 10:39:28 -06:00
Todd C. Miller
a17491972b Quiet compiler warnings on systems where pid_t is not an int.
Historically, pid_t was a long on some 32-bit systems like Solaris.
2023-03-22 14:48:49 -06:00
Todd C. Miller
9d55ae892f exec_pty: always copy the terminal settings from /dev/tty the pty.
Previously, we only did this when running in the foreground but
this can cause problems when running a program that reads the
terminal settings or window size in the background.  If sudo is
running in the background, the terminal settings will be updated
if it transitions to the foreground process.
Based on a suggestion from From Duncan Overbruck.
2023-03-22 12:44:41 -06:00
Todd C. Miller
98ec786b44 check_foreground: use SFD_LEADER not SFD_FOLLOWER (which was closed).
Also use SFD_LEADER for sudo_term_copy() in exec_pty() for consistency.
From Duncan Overbruck.
2023-03-22 11:21:15 -06:00
Todd C. Miller
acbe617fb4 suspend_sudo_pty: fix cut & pasto in last commit to catch SIGCONT.
Also set sa.sa_handler to SIG_DFL instead of SIG_IGN.  There is no
difference for SIGCONT but it means we can re-use sa as-is later.
2023-03-22 08:26:36 -06:00
Todd C. Miller
0fcbcaede0 Catch SIGCONT and restore terminal settings on resume from SIGSTOP.
While we cannot catch SIGSTOP, we _can_ catch SIGCONT and set
/dev/tty to raw mode when running in the foreground.  Ignore SIGCONT
in suspend_sudo_pty() so we don't call resume_terminal() twice.
2023-03-21 19:11:31 -06:00
Todd C. Miller
1772fc7b66 Only convert a signal number to a name if we are going to use it.
It is mostly used for debug logging.
2023-03-21 15:50:39 -06:00
Todd C. Miller
adb84293ab Move updating of the window size back to the main sudo process.
We can use the leader file descriptor with TIOCGWINSZ to set the
window size of the pty.  Thanks to Duncan Overbruck for the hint.
2023-03-21 15:30:54 -06:00
Todd C. Miller
f2f233336e Use LIBPROTOBUF_C and LIBUTIL variables and use them. 2023-03-16 13:48:29 -06:00
Todd C. Miller
d5a7844423 Sync non-intercept version of intercept_cleanup() declaration. 2023-03-10 14:01:07 -07:00
Todd C. Miller
c61306e583 Plug a memory leak with ptrace-based intercept. 2023-03-10 13:32:56 -07:00
Todd C. Miller
31dad6b179 Plug memory leak when log_subcmds is enabled. 2023-03-10 13:18:02 -07:00
Todd C. Miller
19a660612f write_callback: only enable /dev/tty reader if the command is running
This fixes a hang when there is /dev/tty data in a buffer to be
flushed by the final call to del_io_events().  We do not want to
re-enable the reader when flushing the buffers as part of pty_finish().
See PR #247 for analysis of the problem and how to reproduce it.
2023-03-01 13:25:17 -07:00
Todd C. Miller
91814990aa Fix --enable-static-sudoers, broken in sudo 1.9.13.
sudo_qualify_plugin() should not try to fully-qualify the path to
a statically-compiled plugin.  GitHub issue #245
2023-02-23 06:57:37 -07:00
Todd C. Miller
0339337103 Run the editor in its own process group.
This fixes suspending the editor on GNU Hurd which doesn't seem to
have proper process group signal handling.
2023-02-21 16:14:14 -07:00
Todd C. Miller
8d95992c1a ptrace_intercept_execve: preserve old argv[0] after policy check.
We have to replace argv[0] with the pathname for the policy check
but want to restore it afterwards if the policy has not changed the
command's path name to avoid a mismatch later on.
2023-02-21 10:25:14 -07:00
Todd C. Miller
2845ceafb0 Handle "locale -a" returning both C.UTF-8 and C.utf8.
It is possible to have mutiple matches from the output of "locale
-a".  Just take the first one.  Fixes GitHub issue #241.
2023-02-15 13:49:04 -07:00
Todd C. Miller
4f50692acc Add some missing files to the clean and distclean targets. 2023-02-15 10:22:42 -07:00
Todd C. Miller
f160e5e6c6 Display error in error message if we can't restore the terminal. 2023-02-03 07:19:19 -07:00
Todd C. Miller
15b4cde692 Display an error message if unable to restore terminal settings. 2023-02-02 20:10:03 -07:00
Todd C. Miller
678d6664a9 pty_finish: only restore the terminal if sudo is the foreground process 2023-02-02 14:02:51 -07:00
Todd C. Miller
7cb23c85a1 Better background job detection when running a command in a pty.
If sudo is not the process group leader and stdin is not a tty, we
may be running as a background job via a shell script.  Start the
command in the background to avoid changing the terminal mode from
a background process.  GitHub issue #237
2023-02-02 13:55:18 -07:00
Todd C. Miller
4fb9855634 suspend_sudo_pty: stop the process group even if sudo is not the leader.
When sudo is not the process group leader, we still need to stop
sudo's process group and not just the sudo process itself.  If we
only send the signal to sudo itself, the shell will not notice if
it is not in monitor mode.  This can happen when sudo is run from
a shell script, for example.  In this case we need to signal the
shell itself.  If the process group leader is no longer present,
we must kill the command since there will be no one to resume us.
2023-02-02 13:31:16 -07:00
Todd C. Miller
7c5f0d3052 Initialize the integer result parameter passed to SIOCGIFANUM.
It appears that passing in a non-zero value causes the ioctl() to
fail.  From Tim Rice.
2023-01-31 12:35:49 -07:00
Todd C. Miller
fe001b6ffe get_execve_info: defer setting pathname until argbuf is finalized
If we reallocate the buffer (via growbuf()) in ptrace_read_vec(),
the address of argbuf may change.  If so, the value stored in
pathname will no longer be valid.  GitHub issue #194.
2023-01-25 11:55:29 -07:00
Todd C. Miller
a32a54dced Correct error message when command doesn't exist in intercept mode.
Previously, we would always use EACCES, even when ENOENT was
appropriate.  This also affected log_subcmds.
2023-01-25 10:31:49 -07:00
Todd C. Miller
d3afffec75 Include elf.h, not linux/elf.h but define NT_ARM_SYSTEM_CALL if missing.
Older kernel headers are missing the definition of EM_ARM in linux/elf.h.
GitHub issue #232
2023-01-23 13:55:23 -07:00
Todd C. Miller
9ddae66818 Add support for the struct kinfo_proc on Dragonfly BSD. 2023-01-19 13:22:32 -07:00
Todd C. Miller
0865e61d9e Pass back the number of files to edit when using sudoedit.
The sudo front-end can use this to determine where the list of files
to edit begins.
2023-01-18 13:38:15 -07:00
Todd C. Miller
8eabbf8fdd parse_args: an environment variable may not start with '='.
Also check VAR=val format in validate_env_vars() and add an error
message if insert_env_vars() fails.
2022-12-28 14:07:43 -07:00
Todd C. Miller
73abff2d05 Remove the owner and mode checks when loading a sudo plugin.
The sudo.conf file is considered a trusted source of information
and these checks suffer from TOCTOU issues anyway.  The checks
complicate loading of shared objects since we need to perform
fallback processing twice.
2022-12-26 07:43:55 -07:00
Todd C. Miller
97fb4eae72 sudo_dso_load: add AIX fallback path from shlib.so to shlib.a(shlib.so).
If the .so file is missing but the .a file exists, try to dlopen()
the AIX .a file using the .so name as the member.  We need to avoid
breaking existing configurations if the type of AIX shared library
changes when sudo is upgraded.
2022-12-26 07:43:55 -07:00
Todd C. Miller
206700c3f0 Use AIX-style shared libraries on AIX by default instead of SVR4-style.
This removes the need to use the -brtl linker flag which can cause
problems when there are both a .so and .a version of the same library
but with different versions.  This was particularly problematic
when using the AIX freeware version of OpenSSL.  The --with-aix-soname=svr4
option can be used to build SVR4-style shared libs instead.
2022-12-26 07:43:55 -07:00
Todd C. Miller
49f2d67070 Fix support for AIX-style path(module) syntax in sudo.conf Plugin lines. 2022-12-22 16:45:13 -07:00
wanglujun
5c495b5fef debug_return_int use error 2022-12-23 10:52:01 +08:00
Todd C. Miller
eada918bbb Add [arg ...] after command in SYNOPSIS and usage output.
Use Ar markup when referring to the command and args.
2022-12-20 09:09:25 -07:00
Todd C. Miller
9d5ed2f9ef fmtstr: call va_arg() for %c when computing length.
Even though we don't need to read the actual char to know its length,
we do need to consume it to get the correct value for the next format.
2022-12-17 18:55:16 -07:00
Todd C. Miller
3df7b64d80 Fix failure in check targets when there is no UTF-8 C locale. 2022-12-06 16:26:34 -07:00
Todd C. Miller
e707ffe58b Place C23 attributes before keywords in function declarations.
In practice this means we must use "sudo_noreturn static foo(void)"
instead of "static sudo_noreturn foo(void)".
2022-12-01 12:54:53 -07:00
Todd C. Miller
f066ff9e01 Eliminate a few harmless dead stores.
Quiets warnings from Infer.
2022-11-22 11:18:24 -07:00
modric
b1af59aa56 intercept_read: Print and then return. 2022-11-21 09:57:14 +08:00