Todd C. Miller [Mon, 16 May 2016 17:12:54 +0000 (11:12 -0600)]
Do not need to open /dev/tty with O_NONBLOCK, it doesn't block on
first open like a physical terminal. By definition, if you have a
controlling tty, the first open (which might block) has already
occurred.
Todd C. Miller [Thu, 12 May 2016 16:07:59 +0000 (10:07 -0600)]
Use EOVERFLOW, not ENOMEM for overflow conditions.
For snprintf() and vsnprintf(), POSIX says we should return -1 and
set errno to EOVERFLOW if the size param is > INT_MAX; also zero
out the string in this case (not mandated by POSIX) for safety.
Todd C. Miller [Wed, 11 May 2016 15:40:31 +0000 (09:40 -0600)]
Remove sudo_mkpwcache() and sudo_mkgrcache(). We now create the
caches as needed on demand. Also remove calls to sudo_freepwcache()
and sudo_freegrcache() that are immediately followed by execve(),
they are not needed.
Todd C. Miller [Wed, 11 May 2016 13:06:45 +0000 (07:06 -0600)]
Eliminate use of setpwent()/endpwent() and setgrent()/endgrent().
Sudo never iterates over the passwd or group file.
Rename sudo_set{pw,gr}ent() -> sudo_mk{pw,gr}cache() and
use sudo_free{pw,gr}cache() instead of sudo_end{pw,gr}ent().
Todd C. Miller [Tue, 10 May 2016 12:32:55 +0000 (06:32 -0600)]
Remove unnecessary NULL checks in the RUNAS_CHANGED macro. The
only place where the pointers could be NULL is in visudo_json.c but
we already check for "next" being NULL there. Quiets a cppcheck
warning.
Todd C. Miller [Mon, 9 May 2016 20:27:33 +0000 (14:27 -0600)]
Add io_log_read() and io_log_gets() to hide differences between
gzread/fread and gzgets/fgets. Check for premature EOF and error
from io_log_read(). Also sanity check the index in the timing file.
Coverity CID 104630.
Todd C. Miller [Sat, 7 May 2016 20:51:37 +0000 (14:51 -0600)]
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.
Todd C. Miller [Fri, 6 May 2016 20:30:46 +0000 (14:30 -0600)]
Newer versions of Ubuntu have switched from using the "admin" group
to the "sudo" group to align with Debian. create_admin_success_flag()
now accepts either one.
https://bugs.launchpad.net/ubuntu/+source/sudo/+bug/1387347
Todd C. Miller [Fri, 6 May 2016 20:12:08 +0000 (14:12 -0600)]
Instead of using stat(2) to see if the admin flag file exists and
creating it if not, just try to create the file and treat EEXIST
as a non-error. Coverity CID 104121.
Todd C. Miller [Thu, 5 May 2016 22:30:11 +0000 (16:30 -0600)]
Ignore ts_write() return value when disabling an entry with a bogus
timestamp. We ignore the timestamp entry even it doesn't succeed.
Coverity CID 104062.
Todd C. Miller [Thu, 5 May 2016 21:12:37 +0000 (15:12 -0600)]
In fill_args(), check for "arg_size == 0" instead of
"sudoerslval.command.args == NULL" since the latter leads Coverity
to imply that sudoerslval.command.args could be NULL later on.
Coverity CID 104093.
Todd C. Miller [Wed, 4 May 2016 22:48:02 +0000 (16:48 -0600)]
In parse_expr(), move the "bad" label after the "default" case in
the switch(), not before it. This seemed to confuse Covertity,
resulting in a false positive, CID 104095.
Todd C. Miller [Wed, 4 May 2016 20:13:44 +0000 (14:13 -0600)]
In dispatch_signal() for stopped processes check for tcgetpgrp()
returning -1. Also change checks from "saved_pgrp != -1" to
"fd != -1". Coverity CID 104098.
Todd C. Miller [Wed, 4 May 2016 19:48:44 +0000 (13:48 -0600)]
In relabel_tty() always jump to bad: on error, regardless of the
value of se_state.enforcing. On error, return -1 if enforcing,
else 0. Coverity CID 104099.
Todd C. Miller [Wed, 4 May 2016 18:53:20 +0000 (12:53 -0600)]
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.
Todd C. Miller [Wed, 4 May 2016 14:55:21 +0000 (08:55 -0600)]
Sync the "cache hit" debug messages with the "cached" debug messages.
This fixes a bug where we could dereference a NULL pointer when we
look up a negative cached entry which is stored as a NULL passwd
or group struct pointer. Bug #743.
Todd C. Miller [Thu, 28 Apr 2016 21:27:53 +0000 (15:27 -0600)]
Remove the check for __sprintf_chk when checking for _FORTIFY_SOURCE,
Some implementations are purely header-file based. As long as we
can link a test program using sprintf() when _FORTIFY_SOURCE=2 it
should be safe to use.
Todd C. Miller [Thu, 28 Apr 2016 21:09:46 +0000 (15:09 -0600)]
Remove configure checks for dev_t, id_t, ino_t, ptrdiff_t, size_t
and ssize_t. These have been specified by either ANSI C or POSIX
for long enough that if the system doesn't support them, it is
unlikely to be able to compile sudo anyway.
Todd C. Miller [Thu, 28 Apr 2016 17:01:58 +0000 (11:01 -0600)]
Do group setup in policy_init_session() before calling out to the
plugin. This makes it possible for the pam_group module to change
the group in pam_setcred(). It's a bit bogus since pam_setcred()
is documented as not changing the group or user ID, but pam_group
is shipped with stock Linux-PAM so we need to support it.
Todd C. Miller [Fri, 22 Apr 2016 22:36:36 +0000 (16:36 -0600)]
Ignore SIGPIPE for the duration of sudo and not just in a few select
places. We have no control over what nss, PAM modules or sudo
plugins might do so ignoring SIGPIPE is safest.
Todd C. Miller [Tue, 19 Apr 2016 16:08:51 +0000 (10:08 -0600)]
When determining whether or not "sudo -l" or "sudo -b" should prompt
for a password, take all sudoers sources into account. In other
words, if both file and ldap sudoers sources are in use, "sudo -v"
will now require that all entries in both sources be have NOPASSWD
(file) or !authenticate (ldap) in the entries.
Todd C. Miller [Tue, 22 Mar 2016 22:31:28 +0000 (16:31 -0600)]
If the auth_type setting in /etc/security/login.cfg is set to
PAM_AUTH but pam_start() fails, fall back to use AIX authentication.
Skip the auth_type check if sudo is not compiled with PAM support.
Todd C. Miller [Wed, 9 Mar 2016 16:39:46 +0000 (09:39 -0700)]
Work around an ambiguity in the PAM spec with respect to the conversation
function. It is not clear whether the "struct pam_message **msg" is an
array of pointers or a pointer to an array. Linux-PAM and OpenPAM use
an array of pointers while Solaris/HP-UX/AIX uses a pointer to an array.
Bug #726.
Todd C. Miller [Fri, 26 Feb 2016 16:32:08 +0000 (09:32 -0700)]
Fix the check for whether a user is allowed to lists another user's
privileges. The "matched" variable is not boolean, it can also
have the value UNSPEC so we need to check explicitly for true.
Bug #738
Todd C. Miller [Wed, 24 Feb 2016 23:00:08 +0000 (16:00 -0700)]
Don't check for posix_spawn() or posix_spawnp() if we were unable
to find spawn.h. This should only be a problem on systems with
broken headers. Bug #730