Todd C. Miller [Tue, 19 Nov 2013 23:06:08 +0000 (16:06 -0700)]
Rename snprintf replacement rpl_snprintf since we may now replace
the libc version and #define rpl_snprintf snprintf in missing.h so
we get our version when needed. This is consistent with how we
replace glob and fnmatch.
Todd C. Miller [Tue, 19 Nov 2013 16:48:01 +0000 (09:48 -0700)]
Include unistd.h in sig2str.c for Tru64 as it defines SIGRTMIN and
SIGRTMAX in terms of sysconf(), which is prototyped in unistd.h.
Bug #621; from Daniel Richard G.
Todd C. Miller [Mon, 18 Nov 2013 16:10:09 +0000 (09:10 -0700)]
Allow sudo to compile without variadic macro support in cpp.
Debugging support will be limited (no file info from warnings.)
From Daniel Richard G.; Bug #621
Todd C. Miller [Mon, 18 Nov 2013 15:59:57 +0000 (08:59 -0700)]
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().
Todd C. Miller [Sun, 17 Nov 2013 23:11:39 +0000 (16:11 -0700)]
Add debug_return_const_str and debug_return_const_ptr for returning
a const string or pointer. Using const for the normal versions
produces warnings with the Tru64 compiler.
Todd C. Miller [Sat, 16 Nov 2013 16:21:43 +0000 (09:21 -0700)]
log_{fatal,warning} now logs to the debug file itself.
log_{fatal,warning} now calls warningx2() after setting the
locale itself instead of using the wrapper macros.
This removes the only use of warningx(ngettext(...)).
Todd C. Miller [Wed, 13 Nov 2013 21:45:47 +0000 (14:45 -0700)]
From Daniel Richard G. (bug #622)
Add an autogen.sh script that rebuilds the autoconf world.
Move old aclocal.m4 contents to m4/sudo.m4.
New (generayed) aclocal.m4 contains the m4_include directives.
Some tests had #include directives where the '#' was not in column 1.
Updated obsolete macro usage via autoupdate.
Todd C. Miller [Mon, 11 Nov 2013 23:00:07 +0000 (16:00 -0700)]
In v{warning,fatal}x?() make a new copy of ap for the debug functions.
It is not legal to use ap twice without reinitializing it.
Noticed by Daniel Richard G.
Todd C. Miller [Mon, 11 Nov 2013 20:53:06 +0000 (13:53 -0700)]
Uniquify header dependencies so we don't end up with duplicates
when a header file includes other headers. The header dependencies
are sorted so the generated order is stable.
Todd C. Miller [Mon, 4 Nov 2013 13:06:01 +0000 (06:06 -0700)]
When deleting an event, check ev->events to determine whether to
remove from readfds or writefds instead of blinding removing from
both. Also fix highfd adjustment.
Todd C. Miller [Fri, 1 Nov 2013 22:54:49 +0000 (16:54 -0600)]
Don't call sudo_ev_{add,del}_impl() for timeout-only events. This
makes it possible to pass sudo_ev_alloc() an fd of -1 for events
only use SUDO_EV_TIMEOUT.
Todd C. Miller [Tue, 29 Oct 2013 21:26:32 +0000 (15:26 -0600)]
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.
Todd C. Miller [Mon, 28 Oct 2013 22:40:04 +0000 (16:40 -0600)]
Fix sudo_ev_scan_impl() return value in event_poll.c.
Make sure we clear active flag from unprocessed events if
sudo_ev_loopbreak() or sudo_ev_loopcontinue() are used.
Remove bogus optimization when the timeout is zero or negative; it
could prevent an I/O event from being triggered.
Todd C. Miller [Mon, 28 Oct 2013 17:13:45 +0000 (11:13 -0600)]
Get rid of cur and pending pointers in struct sudo_event_base. We
now pop the first event off the active queue instead of using a
foreach loop with deferred removal of the event.
Add SUDO_EVQ_INSERTED and SUDO_EVQ_TIMEOUTS flags to indicate that
the event on the event queue and timeouts queue respectively.
No longer need to compare the timeout to {0,0} or compare the
event's base pointer to NULL to determine queue membership.
Todd C. Miller [Mon, 28 Oct 2013 16:00:09 +0000 (10:00 -0600)]
Add support for libevent-style timed events. Adding a timed event
is currently O(n). The only consumer of timed events is sudoreplay
which only used a singled one so O(n) == O(1) for now. This also
allows us to remove the nanosleep compat function as we now use a
timeout event instead.
Todd C. Miller [Sat, 26 Oct 2013 12:55:23 +0000 (06:55 -0600)]
Add a list of active events in the base that the back end sets when
it calls poll or select. This allows the front end to iterate over
the events instead of having that code in both back ends. It will
also simplify support for timeout events. Also make sure we can't
touch freed memory if a callback frees its own event.
Todd C. Miller [Thu, 24 Oct 2013 16:40:51 +0000 (10:40 -0600)]
Add missing else when the connection from the monitor to the parent
sudo process is broken (due to the parent dying). Prevents a
spurious "unexpected reply type on backchannel" warning.
Todd C. Miller [Thu, 24 Oct 2013 16:19:36 +0000 (10:19 -0600)]
When flushing output we don't care whether we are the foreground
process or not, we still need to flush to /dev/tty. If we are in
the background, it is OK to get SIGTTOU.
Todd C. Miller [Wed, 23 Oct 2013 17:15:24 +0000 (11:15 -0600)]
Ignore SIGPIPE when connecting to the LDAP server so we can get a
proper error message with the IBM LDAP libs. Also return LDAP_SUCCESS
instead of 0 from most sudo_ldap_* functions that return an int.
Todd C. Miller [Tue, 22 Oct 2013 22:52:23 +0000 (16:52 -0600)]
sudo_ldap_parse_uri() should join multiple URIs in the string list
together but it was clearing the host entry each time through the
loop. Fixes a bug with multiple URI entries in ldap.conf where
only the last one was being honored.
Todd C. Miller [Tue, 22 Oct 2013 21:54:41 +0000 (15:54 -0600)]
Avoid a double free introduced when plugging a memory leak in
safe_close(). A new ev_free_by_fd() function is used to remove and
free any events sharing the specified fd. This can be used after
safe_close() to make sure we don't try to select() on a closed fd.
Todd C. Miller [Tue, 22 Oct 2013 20:58:00 +0000 (14:58 -0600)]
Quiet some llvm check false positives. The common idiom of using
TAILQ_FIRST, TAILQ_REMOVE and free in a loop to free each entry in
a TAILQ confuses llvm. Use TAILQ_FOREACH_SAFE instead (which is
probably faster anyway).
Todd C. Miller [Tue, 22 Oct 2013 15:08:38 +0000 (09:08 -0600)]
Add "headless" tail queues and use them in place of the semi-circular
lists in sudoers. Once the headless tail queue is built up it is
converted to a normal TAILQ. This removes the last consumer of
list.c and list.h so those can now be removed.
Todd C. Miller [Tue, 22 Oct 2013 15:00:37 +0000 (09:00 -0600)]
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.
Todd C. Miller [Sat, 12 Oct 2013 11:53:52 +0000 (05:53 -0600)]
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.
Todd C. Miller [Sat, 12 Oct 2013 11:53:43 +0000 (05:53 -0600)]
Simple event subsystem that uses poll() or select(). Basically a
simplied subset of libevent2. Currently only fd events are supported
(since that's all we need). The poll() backend is used by default,
except on Mac OS X where poll() is broken for devices (including
/dev/tty and ptys).
Todd C. Miller [Sat, 12 Oct 2013 11:39:02 +0000 (05:39 -0600)]
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.