Commit Graph

136 Commits

Author SHA1 Message Date
Todd C. Miller
356287557f Use dup3() instead of dup2().
This is less error prone since dup3() returns an error if old == new.
Sudo guarantees that fds 0-2 are already open.
2019-11-02 10:55:50 -06:00
Todd C. Miller
352212c7bf Open all pipes using pipe2() with O_CLOEXEC.
We no longer depend on calling closefrom() before exec.
2019-11-02 10:52:34 -06:00
Todd C. Miller
cf6c60c102 Add log_allowed and log_denied sudoers flags, defaulting to true. 2019-10-17 13:43:04 -06:00
Todd C. Miller
9d8f374397 Add ssizeof macro that returns ssize_t.
We can use this instead of casting the result of size_t to int.
Also change checks for snprintf() returning <=0 to <0.
2019-06-25 09:45:10 -06:00
Todd C. Miller
1e1ef61902 Add SPDX-License-Identifier to files. 2019-04-29 07:21:51 -06:00
Todd C. Miller
aa0146d68d Keep debug fds open in send_mail() to aid in debugging.
Adds closefrom_nodebug() which acts like closefrom(3) but doesn't
close debug fds for use by send_mail().
Also moves the code to exec the mailer to its own function.
2019-04-20 17:28:45 -06:00
Todd C. Miller
985600e7f0 Minor snprintf() usage tweaks:
1) don't assume snprintf() returns -1 on error, check for <0
2) when comparing return value of sizeof(foo), cast the sizeof, not the len
3) cast return value to void in cases where snprintf cannot fail
2019-01-20 07:49:48 -07:00
Todd C. Miller
cdd5bb32eb Add sudo_gai_fatal, sudo_gai_vfatal, sudo_gai_vwarn, sudo_gai_warn
and gai_log_warning that use gai_strerror() instead of strerror().
2018-11-05 09:08:05 -07:00
Todd C. Miller
6c3d20cb41 Convert PVS-Studio comment to ANSI C. 2018-10-26 08:39:09 -06:00
Todd C. Miller
64e5d34c57 Add comments in .c files so PVS-Studio will check them. 2018-10-21 08:46:05 -06:00
Todd C. Miller
5f61f2c0f4 Remove special handling of the USERNAME environment variable. It
used to be set on old versions of Fedora but that hasn't been the
case for some time.  It's worth noting that ssh doesn't set USERNAME
either.
2018-09-24 05:30:03 -06:00
Todd C. Miller
f2fdda1aa7 Silence a clang analyzer false positive. 2017-12-22 13:27:08 -07:00
Todd C. Miller
1350a30737 Add authfail_message sudoers option to allow the user to override
the default message of %d incorrect password attempt(s).
2017-12-11 12:43:58 -07:00
Todd C. Miller
b16912da1d Don't include syslog.h from logging.h, just include it in the two
.c files it is actually needed.
2017-12-08 15:00:41 -07:00
Todd C. Miller
48fba3c2cc update my email to Todd.Miller@sudo.ws 2017-12-03 17:53:40 -07:00
Todd C. Miller
d129f306ea Add syslog_pid sudoers option to log sudo's process ID when logging
via syslog.  This is disabled by default to match historic behavior.
2017-07-20 16:33:12 -06:00
Todd C. Miller
414b28dc45 move va_start() in mysyslog() 2017-01-13 16:30:08 -07:00
Todd C. Miller
00b6be9dfa Allow syslog priority to be negated or set to "none" to disable
logging successes or failures.
2016-11-30 16:26:10 -07:00
Todd C. Miller
8133cdfdf6 Use sys/stat.h defines instead of bare octal values. 2016-11-07 13:36:05 -07:00
Todd C. Miller
7c56179c7d Use "double quotes" in messages instead of a combination of the
accent (grave) mark and apostrophe.
2016-11-02 17:10:17 -06:00
Todd C. Miller
fc1b4155d7 Replace bare ";" in the body of for() loops with "continue;" for
improved readability.
2016-10-26 10:42:28 -06:00
Todd C. Miller
19c96da44d add vsyslog() for systems without it. 2016-10-19 11:32:36 -06:00
Todd C. Miller
c18ff022e0 Use vsyslog() if available. 2016-10-18 17:00:53 -06:00
Todd C. Miller
44c2679f83 Add syslog_maxlen to control the max size of syslog messages. 2016-10-18 15:51:47 -06:00
Todd C. Miller
3f022419ae Be consistent with the naming of the variable used to store the
function return value.  Previously, some code used "rval", some
used "ret".  This standardizes on "ret" and uses "rc" for temporary
return codes.
2016-09-08 16:38:08 -06:00
Todd C. Miller
d8a65715d6 Avoid duplicate warnings when we cannot write to the log file.
Also send the warning in mail if possible.
2016-08-17 14:51:20 -06:00
Todd C. Miller
9ccd260842 Make sure we print an error message to stderr (and not just send
mail) if do_logfile() fails.  Bug #751
2016-08-15 07:25:18 -06:00
Todd C. Miller
23d288563e 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().
2016-05-11 07:06:45 -06:00
Todd C. Miller
7b302e09ae Check return value of restore_perms() in vlog_warning().
Coverity CID 104079.
2016-05-06 09:26:45 -06:00
Todd C. Miller
0690793c25 Fix fd leak in do_logfile() if we fail to lock the log file.
Coverity CID 104115.
2016-05-06 09:12:39 -06:00
Todd C. Miller
57b1dc5e1d Add missing newline when logging to a file (not syslog) and
loglinelen is set to a non-positive number.  Bug #742
2016-04-26 14:39:42 -06:00
Todd C. Miller
b4309d4aea 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.
2016-04-22 16:36:36 -06:00
Todd C. Miller
5ad68edd65 It is possible for WIFSTOPPED to be true even if waitpid() is not
given WUNTRACED if the child is ptraced.  Don't exit the waitpid()
loop if WIFSTOPPED is true, just in case.
2015-10-02 11:24:01 -06:00
Todd C. Miller
701534c63c Fix typo in error message. 2015-07-03 07:06:29 -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
81f94499bf Check restore_perms() return value in all cases, pushing the
return value back up the call stack.
2015-06-25 11:12:36 -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
e2328479dd Use strtok_r() instead of strtok() 2015-06-19 12:35:51 -06:00
Todd C. Miller
138aa2ccd1 Remove BROKEN_SYSLOG define which was for obsolete versions of HP-UX.
Remove last remnants of 4.2BSD syslog support.
2015-06-18 17:53:49 -06:00
Todd C. Miller
ec7e467c58 Remove asprintf() return value warnings. 2015-06-17 17:00:25 -06:00
Todd C. Miller
8eff57f070 Bring back VALIDATE_ERROR which will be used in the case of memory
allocation errors.
2015-06-04 20:42:42 -06:00
Todd C. Miller
9d1c408b73 Non-exiting allocators for log functions. If log_allowed() fails
the user may not run the command.  We don't try to return early for
log_failure(), log_auth_failure() or log_denial() as we would not
run the command in that case.
2015-05-27 10:55:27 -06:00
Todd C. Miller
eea4e1afd9 Convert two debug_return_int to debug_return_bool. 2015-05-07 10:40:46 -06:00
Todd C. Miller
3b30984406 Use saved errno in vlog_warning() before calling sudo_vwarn_nodebug().
Fixes the error message printed if set_perms() fails.
2015-03-21 15:41:59 -06:00
Todd C. Miller
53ac30b63a Add mail_all_cmnds to always mail when a user runs a command (or
tries to) including sudoedit.  The mail_always flag goes back to
its old semantic of always mailing when sudo is run.
2015-02-15 20:30:11 -07:00
Todd C. Miller
ed4ffa6265 Don't send mail about pseudo-command failure unless it is an
authentication failure.
2015-02-02 15:01:06 -07: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
57553fffdd Rename VALIDATE_OK -> VALIDATE_SUCCESS
Rename VALIDATE_NOT_OK -> VALIDATE_FAILURE
2015-01-21 11:03:48 -07:00