Commit Graph

27 Commits

Author SHA1 Message Date
Todd C. Miller
e343e07543 Use #include <foo.h> instead of #include "foo.h" in most cases.
We rely on the include path to find many of these headers.  It
especially doesn't make sense to use #include "foo.h" for headers
in the top-level include directory.
2023-09-25 10:13:28 -06:00
Todd C. Miller
5768d374cc libsudo_util: silence most -Wconversion warnings. 2023-07-07 15:07:04 -06:00
Todd C. Miller
f1a697a8ff Use close_range(2) in closefrom() emulation if available.
On Linux, prefer our own closefrom() emulation since the glibc
version may fail if /proc is not present and close_range() is not
supported.  On FreeBSD, closefrom(3) will either call the closefrom
or close_range system call, depending on which is available.
2022-03-01 09:54:23 -07:00
Todd C. Miller
476f00b82f Emulate closefrom() on macOS using proc_pidinfo().
This avoids relying on /dev/fd which may not exist in a chroot jail.
Adapted from a change in OpenSSH by likan_999.student AT sina.com
2021-09-27 13:44:41 -06:00
Todd C. Miller
88dcdcd11d Fix -Wshadow warnings. 2020-09-25 15:09:45 -06:00
Todd C. Miller
dd88460800 We no longer need to include headers we don't use for sudo*.h files.
Previously we needed to include headers required by the various
sudo*h files.  Now those files are more self-sufficient and we
should only include headers needed by code in the various .c files.
2020-05-18 06:47:04 -06:00
Todd C. Miller
09f1c26490 Fix typo in closefrom emulation. 2019-11-06 13:41:52 -07:00
Todd C. Miller
ac36cf2d4b In closefrom_fallback() use the interval [OPEN_MAX, INT_MAX].
We want to try closing at least OPEN_MAX fds but no more than INT_MAX.
On 64-bit systems it is possible for sysconf(_SC_OPEN_MAX) to return
a value larger than INT_MAX when the number of open files is unlimited.
2019-11-02 10:56:02 -06:00
Todd C. Miller
2512f6efbf Use sudo_strtonum() explicitly instead of via a macro. 2019-10-14 10:09:30 -06:00
Todd C. Miller
1e1ef61902 Add SPDX-License-Identifier to files. 2019-04-29 07:21:51 -06:00
Todd C. Miller
30a56af6ef FreeBSD's /dev/fd only contains fds 0-2 unless fdescfs is mounted.
In practice this doesn't matter since FreeBSD >= 8 has a native closefrom
2019-04-26 15:21:29 -06:00
Todd C. Miller
17ca31c381 Ignore EOVERFLOW from pstat_getproc(), it is not a fatal error.
It just means that one of the fields in pstat lacks the precision to
store a value.  That's not an issue for pst_highestfd.
2019-03-06 20:13:40 -07:00
Todd C. Miller
7c5469264d If fcntl fails, fall back to the /proc implementation. 2018-11-14 13:37:45 -07:00
Todd C. Miller
537a2f9773 Only use closefrom_fallback() if no better method exists.
The previous logic was too fragile.
2018-11-08 15:17:39 -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
48fba3c2cc update my email to Todd.Miller@sudo.ws 2017-12-03 17:53:40 -07:00
Todd C. Miller
5a6b8a78f1 Include pathnames.h for /dev/fd on FreeBSD and Mac OS X. 2017-07-27 20:51:21 -06:00
Todd C. Miller
6d4d4594b7 Use _PATH_DEV consistently 2017-06-29 18:10:53 -06:00
Todd C. Miller
d77941c2be We require POSIX so no need to conditionally include dirent.h.
Add a check for d_namlen and use the result in the NAMLEN macro.
2015-07-02 09:24:48 -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
dc883f2454 We require ANSI C so stop using the obsolete STDC_HEADERS. 2015-06-19 14:29:27 -06:00
Todd C. Miller
96eddddc12 Almost no systems actually define OPEN_MAX since it is dynamic on
modern OSes.  If sysconf(_SC_OPEN_MAX) ever fails, fall back on
_POSIX_OPEN_MAX instead.  We can assume modern systems have sysconf().
Also remove checks for strrchr() and strtoll() for which the HAVE_*
defines are no longer used.
2015-02-19 09:59:25 -07:00
Todd C. Miller
19a8a69a92 Don't appear to need sys/param.h for pstat_getproc() on HP-UX even
though the man page lists it.
2015-01-14 10:58:32 -07:00
Todd C. Miller
47835ff289 Rename missing.h -> sudo_compat.h 2014-07-22 14:25:16 -06:00
Todd C. Miller
87c2fe5a31 Prefix all libc replacements with sudo_ and #define the real name
to the sudo_ version.  That way we don't pollute the libc namespace.
2014-06-26 15:51:08 -06:00
Todd C. Miller
4d37a4a162 Top level directory reorg
Move src/po -> po
Combine common and compat -> lib/util
Move zlib -> lib/zlib
2014-06-26 15:51:02 -06:00