Use generic bitmap macros instead of select-style fd_set.
This commit is contained in:
@@ -83,7 +83,7 @@ XGETTEXT_OPTS = -F -k_ -kN_ -kU_ --copyright-holder="Todd C. Miller" \
|
||||
--flag sudo_lbuf_append_quoted:3:c-format --foreign-user
|
||||
|
||||
# Default cppcheck options when run from the top-level Makefile
|
||||
CPPCHECK_OPTS = -q --force --enable=warning,performance,portability --suppress=constStatement --error-exitcode=1 --inline-suppr -U__cplusplus -UQUAD_MAX -UQUAD_MIN -UUQUAD_MAX -U_POSIX_HOST_NAME_MAX -U_POSIX_PATH_MAX -DNSIG=64
|
||||
CPPCHECK_OPTS = -q --force --enable=warning,performance,portability --suppress=constStatement --error-exitcode=1 --inline-suppr -U__cplusplus -UQUAD_MAX -UQUAD_MIN -UUQUAD_MAX -U_POSIX_HOST_NAME_MAX -U_POSIX_PATH_MAX -U__NBBY -U__NBBY -DNSIG=64
|
||||
|
||||
all: config.status
|
||||
for d in $(SUBDIRS); do \
|
||||
|
@@ -20,6 +20,21 @@
|
||||
#include <stdarg.h>
|
||||
#include "sudo_queue.h"
|
||||
|
||||
/* Number of bits in a byte. */
|
||||
#ifndef NBBY
|
||||
# ifdef __NBBY
|
||||
# define NBBY __NBBY
|
||||
# else
|
||||
# define NBBY 8
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Bit map macros. */
|
||||
#define sudo_setbit(_a, _i) ((_a)[(_i) / NBBY] |= 1 << ((_i) % NBBY))
|
||||
#define sudo_clrbit(_a, _i) ((_a)[(_i) / NBBY] &= ~(1<<((_i) % NBBY)))
|
||||
#define sudo_isset(_a, _i) ((_a)[(_i) / NBBY] & (1<<((_i) % NBBY)))
|
||||
#define sudo_isclr(_a, _i) (((_a)[(_i) / NBBY] & (1<<((_i) % NBBY))) == 0)
|
||||
|
||||
/*
|
||||
* List of debug files and flags for use in registration.
|
||||
*/
|
||||
@@ -227,11 +242,11 @@ __dso_public void sudo_debug_exit_str(const char *func, const char *file, int li
|
||||
__dso_public void sudo_debug_exit_str_masked(const char *func, const char *file, int line, int subsys, const char *rval);
|
||||
__dso_public pid_t sudo_debug_fork(void);
|
||||
__dso_public int sudo_debug_get_default_instance(void);
|
||||
__dso_public int sudo_debug_get_fds(fd_set **fdsetp);
|
||||
__dso_public int sudo_debug_get_fds(unsigned char **fds);
|
||||
__dso_public int sudo_debug_get_instance(const char *program);
|
||||
__dso_public void sudo_debug_printf2(const char *func, const char *file, int line, int level, const char *fmt, ...) __printf0like(5, 6);
|
||||
__dso_public void sudo_debug_printf_nvm(int pri, const char *fmt, ...) __printf0like(2, 3);
|
||||
__dso_public int sudo_debug_register(const char *program, const char *const subsystems[], int ids[], struct sudo_conf_debug_file_list *debug_files);
|
||||
__dso_public int sudo_debug_register(const char *program, const char *const subsystems[], unsigned int ids[], struct sudo_conf_debug_file_list *debug_files);
|
||||
__dso_public int sudo_debug_set_default_instance(int inst);
|
||||
__dso_public void sudo_debug_update_fd(int ofd, int nfd);
|
||||
__dso_public void sudo_debug_vprintf2(const char *func, const char *file, int line, int level, const char *fmt, va_list ap) __printf0like(5, 0);
|
||||
|
@@ -74,7 +74,7 @@ SSP_LDFLAGS = @SSP_LDFLAGS@
|
||||
SHLIB_VERSION = 0:0:0
|
||||
|
||||
# cppcheck options, usually set in the top-level Makefile
|
||||
CPPCHECK_OPTS = -q --force --enable=warning,performance,portability --suppress=constStatement --error-exitcode=1 --inline-suppr -U__cplusplus -UQUAD_MAX -UQUAD_MIN -UUQUAD_MAX -U_POSIX_HOST_NAME_MAX -U_POSIX_PATH_MAX -DNSIG=64
|
||||
CPPCHECK_OPTS = -q --force --enable=warning,performance,portability --suppress=constStatement --error-exitcode=1 --inline-suppr -U__cplusplus -UQUAD_MAX -UQUAD_MIN -UUQUAD_MAX -U_POSIX_HOST_NAME_MAX -U_POSIX_PATH_MAX -U__NBBY -DNSIG=64
|
||||
|
||||
# Regression tests
|
||||
TEST_PROGS = atofoo_test conf_test hltq_test parseln_test progname_test @COMPAT_TEST_PROGS@
|
||||
|
@@ -16,13 +16,6 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <sys/param.h> /* for howmany() on Linux */
|
||||
#ifdef HAVE_SYS_SYSMACROS_H
|
||||
# include <sys/sysmacros.h> /* for howmany() on Solaris */
|
||||
#endif
|
||||
#ifdef HAVE_SYS_SELECT_H
|
||||
# include <sys/select.h>
|
||||
#endif /* HAVE_SYS_SELECT_H */
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/uio.h>
|
||||
@@ -119,7 +112,7 @@ SLIST_HEAD(sudo_debug_output_list, sudo_debug_output);
|
||||
struct sudo_debug_instance {
|
||||
char *program;
|
||||
const char *const *subsystems;
|
||||
const int *subsystem_ids;
|
||||
const unsigned int *subsystem_ids;
|
||||
unsigned int max_subsystem;
|
||||
struct sudo_debug_output_list outputs;
|
||||
};
|
||||
@@ -132,7 +125,8 @@ static int sudo_debug_last_instance = -1;
|
||||
static char sudo_debug_pidstr[(((sizeof(int) * 8) + 2) / 3) + 3];
|
||||
static size_t sudo_debug_pidlen;
|
||||
|
||||
static fd_set sudo_debug_fdset; /* XXX - make dynamic */
|
||||
static const int sudo_debug_fdset_size = 1024 * NBBY; /* XXX - make dynamic */
|
||||
static unsigned char sudo_debug_fds[1024]; /* XXX - make dynamic */
|
||||
static int sudo_debug_max_fd = -1;
|
||||
|
||||
/* Default instance index to use for common utility functions. */
|
||||
@@ -173,9 +167,9 @@ sudo_debug_new_output(struct sudo_debug_instance *instance,
|
||||
ignore_result(fchown(output->fd, (uid_t)-1, 0));
|
||||
}
|
||||
(void)fcntl(output->fd, F_SETFD, FD_CLOEXEC);
|
||||
/* XXX - realloc sudo_debug_fdset as needed (or use other bitmap). */
|
||||
if (output->fd < FD_SETSIZE) {
|
||||
FD_SET(output->fd, &sudo_debug_fdset);
|
||||
/* XXX - realloc sudo_debug_fds as needed. */
|
||||
if (output->fd < sudo_debug_fdset_size) {
|
||||
sudo_setbit(sudo_debug_fds, output->fd);
|
||||
if (output->fd > sudo_debug_max_fd)
|
||||
sudo_debug_max_fd = output->fd;
|
||||
}
|
||||
@@ -197,13 +191,13 @@ sudo_debug_new_output(struct sudo_debug_instance *instance,
|
||||
if (strcasecmp(pri, sudo_debug_priorities[i]) == 0) {
|
||||
for (j = 0; instance->subsystems[j] != NULL; j++) {
|
||||
if (strcasecmp(subsys, "all") == 0) {
|
||||
const int idx = instance->subsystem_ids ?
|
||||
const unsigned int idx = instance->subsystem_ids ?
|
||||
SUDO_DEBUG_SUBSYS(instance->subsystem_ids[j]) : j;
|
||||
output->settings[idx] = i;
|
||||
continue;
|
||||
}
|
||||
if (strcasecmp(subsys, instance->subsystems[j]) == 0) {
|
||||
const int idx = instance->subsystem_ids ?
|
||||
const unsigned int idx = instance->subsystem_ids ?
|
||||
SUDO_DEBUG_SUBSYS(instance->subsystem_ids[j]) : j;
|
||||
output->settings[idx] = i;
|
||||
break;
|
||||
@@ -227,7 +221,7 @@ sudo_debug_new_output(struct sudo_debug_instance *instance,
|
||||
*/
|
||||
int
|
||||
sudo_debug_register(const char *program, const char *const subsystems[],
|
||||
int ids[], struct sudo_conf_debug_file_list *debug_files)
|
||||
unsigned int ids[], struct sudo_conf_debug_file_list *debug_files)
|
||||
{
|
||||
struct sudo_debug_instance *instance = NULL;
|
||||
struct sudo_debug_output *output;
|
||||
@@ -809,17 +803,17 @@ sudo_debug_set_default_instance(int inst)
|
||||
|
||||
/*
|
||||
* Replace the ofd with nfd in all outputs if present.
|
||||
* Also updates sudo_debug_fdset.
|
||||
* Also updates sudo_debug_fds.
|
||||
*/
|
||||
void
|
||||
sudo_debug_update_fd(int ofd, int nfd)
|
||||
{
|
||||
int idx;
|
||||
|
||||
if (ofd <= sudo_debug_max_fd && FD_ISSET(ofd, &sudo_debug_fdset)) {
|
||||
/* Update sudo_debug_fdset. */
|
||||
FD_CLR(ofd, &sudo_debug_fdset);
|
||||
FD_SET(nfd, &sudo_debug_fdset);
|
||||
if (ofd <= sudo_debug_max_fd && sudo_isset(sudo_debug_fds, ofd)) {
|
||||
/* Update sudo_debug_fds. */
|
||||
sudo_clrbit(sudo_debug_fds, ofd);
|
||||
sudo_setbit(sudo_debug_fds, nfd);
|
||||
|
||||
/* Update the outputs. */
|
||||
for (idx = 0; idx <= sudo_debug_last_instance; idx++) {
|
||||
@@ -839,11 +833,11 @@ sudo_debug_update_fd(int ofd, int nfd)
|
||||
|
||||
/*
|
||||
* Returns the highest debug output fd or -1 if no debug files open.
|
||||
* Fills in fdsetp with the value of sudo_debug_fdset.
|
||||
* Fills in fdsetp with the value of sudo_debug_fds.
|
||||
*/
|
||||
int
|
||||
sudo_debug_get_fds(fd_set **fdsetp)
|
||||
sudo_debug_get_fds(unsigned char **fds)
|
||||
{
|
||||
*fdsetp = &sudo_debug_fdset;
|
||||
*fds = sudo_debug_fds;
|
||||
return sudo_debug_max_fd;
|
||||
}
|
||||
|
@@ -58,7 +58,7 @@ SSP_CFLAGS = @SSP_CFLAGS@
|
||||
SSP_LDFLAGS = @SSP_LDFLAGS@
|
||||
|
||||
# cppcheck options, usually set in the top-level Makefile
|
||||
CPPCHECK_OPTS = -q --force --enable=warning,performance,portability --suppress=constStatement --error-exitcode=1 --inline-suppr -U__cplusplus -UQUAD_MAX -UQUAD_MIN -UUQUAD_MAX -U_POSIX_HOST_NAME_MAX -U_POSIX_PATH_MAX -DNSIG=64
|
||||
CPPCHECK_OPTS = -q --force --enable=warning,performance,portability --suppress=constStatement --error-exitcode=1 --inline-suppr -U__cplusplus -UQUAD_MAX -UQUAD_MIN -UUQUAD_MAX -U_POSIX_HOST_NAME_MAX -U_POSIX_PATH_MAX -U__NBBY -DNSIG=64
|
||||
|
||||
# Where to install things...
|
||||
prefix = @prefix@
|
||||
|
@@ -57,7 +57,7 @@ SSP_CFLAGS = @SSP_CFLAGS@
|
||||
SSP_LDFLAGS = @SSP_LDFLAGS@
|
||||
|
||||
# cppcheck options, usually set in the top-level Makefile
|
||||
CPPCHECK_OPTS = -q --force --enable=warning,performance,portability --suppress=constStatement --error-exitcode=1 --inline-suppr -U__cplusplus -UQUAD_MAX -UQUAD_MIN -UUQUAD_MAX -U_POSIX_HOST_NAME_MAX -U_POSIX_PATH_MAX -DNSIG=64
|
||||
CPPCHECK_OPTS = -q --force --enable=warning,performance,portability --suppress=constStatement --error-exitcode=1 --inline-suppr -U__cplusplus -UQUAD_MAX -UQUAD_MIN -UUQUAD_MAX -U_POSIX_HOST_NAME_MAX -U_POSIX_PATH_MAX -U__NBBY -DNSIG=64
|
||||
|
||||
# Where to install things...
|
||||
prefix = @prefix@
|
||||
|
@@ -76,7 +76,7 @@ SSP_CFLAGS = @SSP_CFLAGS@
|
||||
SSP_LDFLAGS = @SSP_LDFLAGS@
|
||||
|
||||
# cppcheck options, usually set in the top-level Makefile
|
||||
CPPCHECK_OPTS = -q --force --enable=warning,performance,portability --suppress=constStatement --error-exitcode=1 --inline-suppr -U__cplusplus -UQUAD_MAX -UQUAD_MIN -UUQUAD_MAX -U_POSIX_HOST_NAME_MAX -U_POSIX_PATH_MAX -DNSIG=64
|
||||
CPPCHECK_OPTS = -q --force --enable=warning,performance,portability --suppress=constStatement --error-exitcode=1 --inline-suppr -U__cplusplus -UQUAD_MAX -UQUAD_MIN -UUQUAD_MAX -U_POSIX_HOST_NAME_MAX -U_POSIX_PATH_MAX -U__NBBY -DNSIG=64
|
||||
|
||||
# Where to install things...
|
||||
prefix = @prefix@
|
||||
|
@@ -71,7 +71,7 @@ static const char *const sudoers_subsystem_names[] = {
|
||||
#define NUM_SUBSYSTEMS (sizeof(sudoers_subsystem_names) / sizeof(sudoers_subsystem_names[0]) - 1)
|
||||
|
||||
/* Subsystem IDs assigned at registration time. */
|
||||
int sudoers_subsystem_ids[NUM_SUBSYSTEMS];
|
||||
unsigned int sudoers_subsystem_ids[NUM_SUBSYSTEMS];
|
||||
|
||||
/*
|
||||
* Parse the "filename flags,..." debug_flags entry and insert a new
|
||||
|
@@ -23,7 +23,7 @@
|
||||
* Sudoers debug subsystems.
|
||||
* Note that sudoers_subsystem_ids[] is filled in at debug registration time.
|
||||
*/
|
||||
extern int sudoers_subsystem_ids[];
|
||||
extern unsigned int sudoers_subsystem_ids[];
|
||||
#define SUDOERS_DEBUG_ALIAS (sudoers_subsystem_ids[ 0]) /* sudoers alias functions */
|
||||
#define SUDOERS_DEBUG_AUDIT (sudoers_subsystem_ids[ 1]) /* audit */
|
||||
#define SUDOERS_DEBUG_AUTH (sudoers_subsystem_ids[ 2]) /* authentication functions */
|
||||
|
@@ -58,7 +58,7 @@ SSP_CFLAGS = @SSP_CFLAGS@
|
||||
SSP_LDFLAGS = @SSP_LDFLAGS@
|
||||
|
||||
# cppcheck options, usually set in the top-level Makefile
|
||||
CPPCHECK_OPTS = -q --force --enable=warning,performance,portability --suppress=constStatement --error-exitcode=1 --inline-suppr -U__cplusplus -UQUAD_MAX -UQUAD_MIN -UUQUAD_MAX -U_POSIX_HOST_NAME_MAX -U_POSIX_PATH_MAX -DNSIG=64
|
||||
CPPCHECK_OPTS = -q --force --enable=warning,performance,portability --suppress=constStatement --error-exitcode=1 --inline-suppr -U__cplusplus -UQUAD_MAX -UQUAD_MIN -UUQUAD_MAX -U_POSIX_HOST_NAME_MAX -U_POSIX_PATH_MAX -U__NBBY -DNSIG=64
|
||||
|
||||
# Where to install things...
|
||||
prefix = @prefix@
|
||||
|
@@ -58,7 +58,7 @@ SSP_CFLAGS = @SSP_CFLAGS@
|
||||
SSP_LDFLAGS = @SSP_LDFLAGS@
|
||||
|
||||
# cppcheck options, usually set in the top-level Makefile
|
||||
CPPCHECK_OPTS = -q --force --enable=warning,performance,portability --suppress=constStatement --error-exitcode=1 --inline-suppr -U__cplusplus -UQUAD_MAX -UQUAD_MIN -UUQUAD_MAX -U_POSIX_HOST_NAME_MAX -U_POSIX_PATH_MAX -DNSIG=64
|
||||
CPPCHECK_OPTS = -q --force --enable=warning,performance,portability --suppress=constStatement --error-exitcode=1 --inline-suppr -U__cplusplus -UQUAD_MAX -UQUAD_MIN -UUQUAD_MAX -U_POSIX_HOST_NAME_MAX -U_POSIX_PATH_MAX -U__NBBY -DNSIG=64
|
||||
|
||||
# Where to install things...
|
||||
prefix = @prefix@
|
||||
|
@@ -174,12 +174,12 @@ exec_cmnd(struct command_details *details, struct command_status *cstat,
|
||||
details->argv, details->envp);
|
||||
if (details->closefrom >= 0) {
|
||||
int fd, maxfd;
|
||||
fd_set *debug_fds;
|
||||
unsigned char *debug_fds;
|
||||
|
||||
/* Preserve debug fds and error pipe as needed. */
|
||||
maxfd = sudo_debug_get_fds(&debug_fds);
|
||||
for (fd = 0; fd <= maxfd; fd++) {
|
||||
if (FD_ISSET(fd, debug_fds))
|
||||
if (sudo_isset(debug_fds, fd))
|
||||
add_preserved_fd(&details->preserved_fds, fd);
|
||||
}
|
||||
if (errfd != -1)
|
||||
|
Reference in New Issue
Block a user