Commit Graph

191 Commits

Author SHA1 Message Date
Todd C. Miller
923edabe6c Convert sudo to use BSD TAILQ macros instead of home ground tail
queue functions.  This includes a private queue.h header derived
from FreeBSD.  It is simpler to just use our own header rather than
try to deal with macros that may or may not be present in various
queue.h incarnations.
2013-10-22 09:00:37 -06:00
Todd C. Miller
83d2d25c4c Convert the main sudo event loop to use the event subsystem.
Read events for I/O buffers are added before the loop starts.
Write events are added on demand as the buffers are filled.
2013-10-12 05:53:52 -06:00
Todd C. Miller
ff18c65862 Use SOCK_STREAM for socketpair, not SOCK_DGRAM so we get consistent
semantics when the other end closes.  This should make the conversion
to poll() less problematic.
2013-10-12 05:39:02 -06:00
Todd C. Miller
299a881fe2 If not using a pty and the child process gets SIGTTOU or SIGTTIN
and sudo is the foreground process, make the child the foreground
process and continue it.
2013-08-14 16:36:41 -06:00
Todd C. Miller
d6282d154a Update copyright years. 2013-04-24 09:35:02 -04:00
Todd C. Miller
39acd2fcba Rename error/errorx -> fatal/fatalx and remove the exit value as
it was always 1.
2013-04-18 14:07:59 -04:00
Todd C. Miller
eb2259bc12 Move exec_cmnd to exec.c to fix a compilation issue with sesh.c 2013-03-14 19:59:07 -04:00
Todd C. Miller
5cb928c512 If the policy plugin does not provide a close function, there is
no command timeout and no pty is required, skip the event loop and
just exec the command directly.
2013-02-23 14:19:07 -05:00
Todd C. Miller
e764604485 Remove extra flag to sudo_sigaction(). We want to trap the signal
regardless of whether or not it is ignored by the underlying command
since there's no way to know what signal handlers the command will
install.  Now we just use sudo_sigaction() to set a flag in
saved_signals[] to indicate whether a signal needs to be restored
before exec.
2013-01-19 15:10:01 -05:00
Todd C. Miller
855a11af2b Move signal code into its own source file and add sudo_sigaction()
wrapper that has an extra flag to check the saved_signals list to
only install the handler if the signal is not already ignored.
Bump plugin API version for the new front-end signal behavior.
2013-01-17 13:29:46 -05:00
Todd C. Miller
99704cc101 Catch SIGINT, SIGQUIT and SIGTSTP in the front end before we execute
the command.  If we get SIGINT or SIGQUIT, call the plugin close()
functions as if the command was interrupted.  If we get SIGTSTP,
uninstall the handler and deliver SIGTSTP to ourselves.
2013-01-17 09:20:45 -05:00
Todd C. Miller
541315212e Rename handle_signals() to dispatch_signals().
Block other signals in handler() so we don't have to worry about
the write() being interrupted.
2013-01-17 09:17:54 -05:00
Todd C. Miller
d129290ec3 Print SIGCONT_FG and SIGCONT_BG properly in debug output. 2012-12-28 11:01:36 -05:00
Todd C. Miller
1d7072fe09 Don't include <sys/param.h>. We only needed it for MAXPATHLEN,
MAXHOSTNAMELEN and the MIN/MAX macros.  We now use PATH_MAX and
HOST_NAME_MAX throughout without falling back on MAXPATHLEN or
MAXHOSTNAMELEN and define our own MIN/MAX macros as needed.
2012-12-04 10:40:47 -05:00
Todd C. Miller
7b3d268687 Call gettext() on parameters for warning()/warningx() instead of
having warning() do it for us.
2012-11-25 09:34:04 -05:00
Todd C. Miller
acf8af9aac #unifdef HAVE_SETLOCALE, it is C89 so no need to check for it. 2012-11-12 08:51:58 -05:00
Todd C. Miller
c1db4b1546 Always include locale.h from gettext.h so we no longer need to
include locale.h from the .c files.
2012-11-11 20:23:53 -05:00
Todd C. Miller
595d3b2651 Display warning/error messages in the user's locale. 2012-11-08 15:37:44 -05:00
Todd C. Miller
885b6e7cda When setting the signal handler for SIGTSTP to the default value
in non-I/O log mode, store the old handler value for when we restore
it after resume.
2012-09-16 18:40:39 -04:00
Todd C. Miller
ae21fb299d Silence compiler warnings. 2012-08-29 14:40:25 -04:00
Todd C. Miller
ab7dda035a Replace strsigname() with sig2str(), emulating it as needed. 2012-08-29 14:25:09 -04:00
Todd C. Miller
37269d662a Pass on SIGTSTP to the command if it was sent by a user process
(not the kernel or the terminal) when we are not I/O logging and
set the default SIGTSTP handler when we re-send the signal to
ourself, restoring our handler after we resume.
2012-08-27 11:22:33 -04:00
Todd C. Miller
29907e357c Shells typically change their process group when they start up so
that they can implement job control.  Most well-behaved shells
change the pgrp back to its original value before suspending so we
must not try to restore in that case, lest we race with the child
upon resume, potentially stopping sudo with SIGTTOU while the command
continues to run.  Some shells, such as pdksh, just suspend the
shell by sending SIGSTOP to themselves without restoring the pgrp.
In this case we need to change the pgrp back for them.
Should fix bug #568
2012-08-27 10:29:59 -04:00
Todd C. Miller
537dc94b9e Use strsigname() to print signal names in the debug output.
If the system has no strsigname(), use our own.
2012-08-26 20:12:51 -04:00
Todd C. Miller
dc08cf3c99 If we receive a signal from the command we executed, do not forward
it back to the command.  This fixes a problem with BSD-derived
versions of the reboot command which send SIGTERM to all other
processes, including the sudo process.  Sudo would then deliver
SIGTERM to reboot which would die before calling the reboot() system
call, effectively leaving the system in single user mode.
2012-08-06 14:38:35 -04:00
Todd C. Miller
5e502bd6d6 When checking whether a signal is user-generated, compare si_code
against SI_USER instead of <= 0 since on HP-UX, terminal-related
signals get a code of 0.
2012-07-31 13:36:48 -04:00
Todd C. Miller
466a126c69 The pointer to the siginfo_t struct in a signal handler may be NULL. 2012-05-11 07:57:01 -04:00
Todd C. Miller
23b7a1fa5c Call the policy's init_session() function before we fork the child.
That way, the session is created and destroyed in the same process,
which is needed by some modules, such as  pam_mount.
2012-04-23 16:38:16 -04:00
Todd C. Miller
df04ccb207 Linux select() may return ENOMEM if there is a kernel resource
shortage.  Older Solaris select() may return EIO instead of EBADF
when the tty goes away.  If we get an unhandled select() failure,
kill the child and exit cleanly.
2012-04-10 10:18:39 -04:00
Todd C. Miller
c8ce3a0a85 Log the process id in the debug file output. Since we don't want
to keep calling getpid(), stash the value at init time and when we
fork().
2012-04-06 15:20:16 -04:00
Todd C. Miller
6f4afc6652 If select() return EBADF in the main event loop, one of the ttys
must have gone away so perform any I/O we can and close the bad
fds.
2012-04-05 12:39:46 -04:00
Todd C. Miller
aecb5206e2 Fix compiler warnings on some platforms and provide a better method
of defeating gcc's warn_unused_result attribute.
2012-03-29 10:33:40 -04:00
Todd C. Miller
55d1a1a79d Use ecalloc() when allocating structs. 2012-03-19 11:24:24 -04:00
Todd C. Miller
1877c455d1 The change in 818e82ecbbfc that caused to exit when the monitor
dies created a race condition between the monitor exiting and the
status being read.  All we really want to do is make sure that
select() notifies us that there is a status change when the monitor
dies unexpectedly so shutdown the socketpair connected to the monitor
for writing when it dies.  That way we can still read the status
that is pending on the socket and select() on Linux will tell us
that the fd is ready.
2012-01-25 16:29:08 -05:00
Todd C. Miller
d11e7febbc Refactor disable_execute() and my_execve() into exec_common.c for
use by sesh.c.  This fixes NOEXEC when SELinux is used.  Instead
of disabling exec in exec_setup(), disable it immediately before
executing the command.  Adapted from a diff by Arno Schuring.
2012-01-25 14:58:02 -05:00
Todd C. Miller
2fd77381a1 When not logging I/O, use a signal handler that only forwards SIGINT,
SIGQUIT and SIGHUP when they are user-generated signals.  Fixes a
race in the non-I/O logging path where the command may receive two
keyboard-generated signals; one from the kernel and one from the
sudo process.
2012-01-17 10:27:33 -05:00
Todd C. Miller
97cecaf6eb Back out change that put the command in its own pgrp when not logging
I/O.  It causes problems with pipelines.
2012-01-17 10:25:44 -05:00
Todd C. Miller
0771c981de Update copyright year. 2012-01-06 14:23:55 -05:00
Todd C. Miller
5bc0756406 When not logging I/O, put command in its own pgrp and make that the
controlling pgrp if the command is in the foreground.  Fixes a race
in the non-I/O logging path where the command may receive two
keyboard-generated signals; one from the kernel and one from the
sudo process.
2012-01-03 10:06:07 -05:00
Todd C. Miller
1f97735fbb Fix typo in visiblepw description; from Joel Pickett 2011-12-18 14:20:56 -05:00
Todd C. Miller
98c77b5b96 Handle different Unix domain socket (actually socketpair) semantics
in BSD vs. Linux.  In BSD if one end of the socketpair goes away
select() returns the fd as readable and the read will fail with
ECONNRESET.  This doesn't appear to happen on Linux so if we notice
that the monitor process has died when I/O logging is enabled,
behave like the command has exited.  This means we log the wait
status of the monitor, not the command, but there is nothing else
we can do at that point.  This should only be an issue if SIGKILL
is sent to the monitor process.
2011-12-08 11:18:38 -05:00
Todd C. Miller
0e26e43b99 Remove duplicate return statements. 2011-12-02 15:23:42 -05:00
Todd C. Miller
21a2f95821 Use stdbool.h instead of rolling our own TRUE/FALSE macros. 2011-12-02 11:27:33 -05:00
Todd C. Miller
a64f1eaea8 Do not close error pipe or debug fd via closefrom() as we need them
to report an exec error should one occur.
2011-11-29 19:51:24 -05:00
Todd C. Miller
3ee9cef0da Fold SUDO_DEBUG_PROGERR and SUDO_DEBUG_SYSERR into SUDO_DEBUG_ERROR 2011-11-07 16:33:49 -05:00
Todd C. Miller
ab75dd2e30 Get rid of done: label. If the child exits we still need to close
the pty, update utmp and restore the SELinux tty context.
2011-10-24 11:14:20 -04:00
Todd C. Miller
839919566e Add debug_decl/debug_return (almost) everywhere.
Remove old sudo_debug() and convert users to sudo_debug_printf().
2011-10-22 14:40:21 -04:00
Todd C. Miller
d81c14005f Silence compiler warnings on Solaris with gcc 3.4.3 2011-08-23 16:42:18 -04:00
Todd C. Miller
3c9e5f28fc Fix compressed io log corruption in background mode by using _exit()
instead of exit() to avoid flushing buffers twice.

Improved background mode support.  When not allocating a pty, the
command is run in its own process group.  This prevents write access
to the tty.  When running in a pty, stdin is not hooked up and we
never read from /dev/tty, which results in similar behavior.
2011-05-31 12:49:22 -04:00
Todd C. Miller
1b67009ca1 Always allocate a pty when running a command in the background but
call setsid() after forking to make sure we don't end up with a
controlling tty.
2011-05-27 15:20:20 -04:00