Commit Graph

1666 Commits

Author SHA1 Message Date
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
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