Commit Graph

250 Commits

Author SHA1 Message Date
Todd C. Miller
ed18d0d5f8 Make the behavior when we cannot write to a log or audit file
configurable.  File log failures are ignored by default for consistency
with syslog.  Audit errors are ignored by default to allow the admin
to fix the issue.  I/O log file errors are still fatal by default
since if I/O logging is activated it is usually to have an audit trail.
Bug #751
2016-08-17 07:22:51 -06:00
Todd C. Miller
4352bb9ca9 Add function name in "command resumed" debug message 2016-07-28 06:23:39 -06:00
Todd C. Miller
383debee9f If waitpid() returns 0 or -1, display a warning, this should never happen.
Add a check for unhandled wait status (also should never happen).
2016-07-28 06:16:43 -06:00
Todd C. Miller
4f47a2ad7d Explicitly check for a continued process with waitpid(2). Otherwise,
waitpid() will return 0 when the command is resumed after being
suspended, which we were treating the same as -1.  Fixes suspend
and resume on Linux and probably others.
2016-07-27 16:17:41 -06:00
Todd C. Miller
66ab525f1e Don't skip debug printfs in handle_sigchld() just because execve()
returned an error.
2016-06-23 11:27:59 -06:00
Todd C. Miller
8a86233c16 In handle_sigchld() fix the return value when we've already received
an exec error.  We don't want to overwrite the error status but we
do need to indicate that the command is no longer running.
Fixes as hang on execve(2) error when running in a pty.
2016-06-09 10:50:58 -06:00
Todd C. Miller
356e74e1db Don't read from stdin when flushing final buffers in blocking mode.
Reading from the pipe can block too if the other end is not closed.
2016-05-24 11:16:44 -06:00
Todd C. Miller
8f694cc228 In del_io_events(), avoid reading from the pty master in blocking
mode.  We now do two passes, one with SUDO_EVLOOP_NONBLOCK and
another that could block if stdin is a pipe.  This ensures we consume
the pipe until EOF.
2016-05-20 10:17:23 -06:00
Todd C. Miller
994f86b40f In pty_close(), call del_io_events with the SUDO_EVLOOP_ONCE flag
so the event loop will exit after a single run through.  Otherwise,
we may hang at exit on non-BSD systems.
2016-05-20 08:12:46 -06:00
Todd C. Miller
38f4ba2249 Bump I/O buffer size to 64K. We don't use PIPE_BUF or _PC_PIPE_BUF
for this because that corresponds to the value for atomic pipe
writes.  The actual pipe buffer is much larger on modern systems
and 64K is what BSD and Linux support for large pipe buffers.
2016-05-17 08:31:23 -06:00
Todd C. Miller
3b6cb9d65b Don't use SUDO_EVLOOP_NONBLOCK when flushing buffers at pty close
time, only when the user suspends sudo.  Fixes a problem where all
buffers might not get flushed at exit when logging I/O.  Reproducible
via "sudo tar cf - foo | (cd /tmp && sudo tar xf -)" on OpenBSD.
2016-05-17 08:16:43 -06:00
Todd C. Miller
a2e541aef8 O_NOCTTY has no effect when opening /dev/tty as the open can only
succeed if there is already a controlling tty.
2016-05-16 11:17:20 -06:00
Todd C. Miller
b04c49dbd3 Break up io_callback() into read_callback() and write_callback()
to make it clear that we can't get an event with both read and write
set.
2016-05-09 10:53:20 -06:00
Todd C. Miller
094854adfe In io_callback() make sure we clear SUDO_EV_READ if we close the
fd.  It should not be possible for SUDO_EV_READ to be set when
revent is non-NULL but this makes static analyzers happier.
Coverity CID 104124.
2016-05-07 14:51:37 -06:00
Todd C. Miller
6473d55aa7 Cast the return value of fcntl() to void when setting FD_CLOEXEC.
Coverity CID 104063, 104064, 104069, 104070, 104071, 104072, 104073, 104074
2016-05-05 16:16:24 -06:00
Todd C. Miller
829917f008 pid_t is defined by POSIX as a signed integer type so we don't need
a cast when comparing to -1.
2016-05-04 14:14:38 -06:00
Todd C. Miller
4ce39df38f In io_callback() if we write the complete buffer and find that there
is no associated reader just return as there is nothing else to be
done.  In practice is it not possible for SUDO_EV_READ to be set
if revent is NULL but an early return is harmless and possibly
easier to understand.  Coverity CID 104124.
2016-05-04 12:53:20 -06:00
Todd C. Miller
a7e5ae1e5b When freeing the iobs after pty tear-down, also free the associated
event structures.  Quiets a memory leak warnings from address
sanitizer and valgrind.
2016-01-29 10:31:54 -07:00
Todd C. Miller
70914b3328 sudo_term_* already restart themselve for all but SIGTTOU so we
don't need to use our own restart loops.
2015-09-07 06:06:08 -06:00
Todd C. Miller
13869d349c Linux sets si_pid in struct siginfo to 0 when the process that sent
the signal is in a different container since the PID namespaces in
different conatiners are separate.  Avoid looking up the process
group by id when si_pid is 0 since getpgid(0) returns the process
group of the current process.  Since sudo ignores signals sent
by processes in its own process group, this had the effect of
ignoring signals sent from other containers.  From Maarten de Vries
2015-08-10 15:13:37 -06:00
Todd C. Miller
61182c87ea In io_callback() service writes before reads. That way, if both
SUDO_EV_READ and SUDO_EV_WRITE are set and read() returns 0 (EOF)
we don't close the fd before the write() is performed.

If the write() returns EPIPE, ENXIO, EIO or EBADF, clear SUDO_EV_READ
before we close the fd to avoid calling read() on a closed fd.
2015-07-08 10:12:15 -06:00
Todd C. Miller
0b241088b3 There's no need to conditionalize the #include <unistd.h>, we require
a POSIX system.
2015-07-02 09:08:28 -06:00
Todd C. Miller
4a07b472f0 Only include stddef.h where it is needed. 2015-06-20 05:34:35 -06:00
Todd C. Miller
c36415417f Add function name to "unable to allocate memory" warnings. 2015-06-19 14:51:17 -06:00
Todd C. Miller
dc883f2454 We require ANSI C so stop using the obsolete STDC_HEADERS. 2015-06-19 14:29:27 -06:00
Todd C. Miller
4f9cabd005 Remove obsolete memory.h include. 2015-06-18 21:02:57 -06:00
Todd C. Miller
cb63ca701c Avoid using exiting allocators in the front end. 2015-06-17 17:00:54 -06:00
Todd C. Miller
59ab26dbcc Go back to a 2 args debug_decl and just use the "default" instance,
now renamed "active".
2015-02-01 08:24:49 -07:00
Todd C. Miller
29039859b7 Defer registration of the SIGCHLD handler until just before we exec
the command.  Fixes a problem where pam_gnome_keyring installs its
own SIGCHLD handler and may not restore the original one.  As a
result, we now have to explicitly wait for the askpass helper to
finish.  Bug #657
2014-11-18 14:05:51 -07:00
Todd C. Miller
21166d4da9 Make sure that SIGCHLD is not treated as a user-generated signal
in which case it could be ignored.  Bug #676
2014-11-04 09:24:41 -07:00
Todd C. Miller
4bf641df69 In the plugin registers with the debug framework at open time, the
sudo front-end will now set the default debug instance appropriately
before calling into the plugin.  This means the plugin no longer needs
to do the sudo_debug_set_default_instance() dance.
2014-10-24 11:17:48 -06:00
Todd C. Miller
866cfc4fc3 Add support for multiple Debug lines per program. Callers may
register arbitrary debug facilities or use built-in defaults.  We
now use separate Debug statements for plugins and programs.
2014-10-22 13:23:05 -06:00
Todd C. Miller
328c563791 Check return value of sigaction(), even though it should never fail. 2014-09-04 10:13:26 -06:00
Todd C. Miller
26e61adc50 Treat EOF on signal pipe (which should never happen) as ECONNRESET. 2014-08-29 11:20:17 -06:00
Todd C. Miller
2b849b2687 Don't allow sudo_ev_loopcont() to override sudo_ev_loopexit() 2014-08-29 09:47:08 -06:00
Todd C. Miller
acdb6d3690 Change behavior when plugin I/O logging function returns 0 or -1.
For -1 (error) return, we now kill the command and disable
the I/O logging function that returned the error.
For a 0 (reject) return, we no longer display the rejected
output to the user's terminal.  The plugin API revision is now 1.6.
2014-08-26 12:07:57 -06:00
Todd C. Miller
ae0014d6f4 Attempt to handle systems with SA_SIGINFO but that lack SI_USER. 2014-07-28 20:25:46 -06:00
Todd C. Miller
36a5767e3e efree -> sudo_efree for consistency 2014-07-10 15:35:04 -06:00
Todd C. Miller
2d61d38c23 Add sudo_ prefix to alloc.c functions and rename alloc.h -> sudo_alloc.h 2014-06-27 10:48:31 -06:00
Todd C. Miller
aecef4aa1d Rename warning/fatal -> sudo_warn/sudo_fatal to avoid namespace
pollution in libsudo_util.so.
2014-06-27 09:30:52 -06:00
Todd C. Miller
d36846a699 Reduce name space pollution in libsudo_util.so 2014-06-26 16:21:19 -06:00
Todd C. Miller
826e190f31 Ignore signals sent by the command's process group, not just the
command itself.  If we cannot determine the process group ID of the
sender (as it may no longer exist), just check the process ID.
2014-05-28 09:50:14 -06:00
Todd C. Miller
d628e17ead Handle EINTR from write(2) when writing to pipes and socket pairs. 2014-05-27 10:16:49 -06:00
Todd C. Miller
7f0b9eca03 Add debugging info for when we delete I/O events that still have
buffered data in them.
2014-05-02 14:58:01 -06:00
Todd C. Miller
135c85e152 In term_restore(), only restores the terminal if we are in the
foregroup process group.  Instead of calling tcgetpgrp(), which is
racy, we set a temporary handler for SIGTTOU and check whether it
was received after a failed call to tcsetattr().
2014-02-05 12:03:58 -07:00
Todd C. Miller
b1de1bce33 term_restore() now restarts itself so we don't need to do it ourselves. 2014-02-03 20:36:48 -07:00
Todd C. Miller
1adeda54ef Add support for preventing fds from getting clobbered by closefrom(). 2013-12-20 11:14:32 -07:00
Todd C. Miller
96eb2c4f8f Add warning_gettext() wrapper function that changes to the user locale,
then calls gettext().
Add U_ macro that calls warning_gettext() instead of gettext().
Rename warning2()/error2() back to warning_nodebug()/error_nodebug().
2013-11-18 08:59:57 -07:00
Todd C. Miller
99b7351de0 Fix some #if vs. #ifdef and remove an extraneous semicolon.
Bug #624; from Daniel Richard G.
2013-11-17 16:15:36 -07:00
Todd C. Miller
fd88ed42c8 Use MSG_WAITALL when receiving struct command_status over the Unix
domain socket since we no longer use datagrams.  This should avoid
the need to handle incomplete reads, though in theory it is still
possible.
2013-10-29 15:26:32 -06:00