]> granicus.if.org Git - sudo/commitdiff
Use generic bitmap macros instead of select-style fd_set.
authorTodd C. Miller <Todd.Miller@courtesan.com>
Thu, 23 Oct 2014 20:37:27 +0000 (14:37 -0600)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Thu, 23 Oct 2014 20:37:27 +0000 (14:37 -0600)
12 files changed:
Makefile.in
include/sudo_debug.h
lib/util/Makefile.in
lib/util/sudo_debug.c
plugins/group_file/Makefile.in
plugins/sample/Makefile.in
plugins/sudoers/Makefile.in
plugins/sudoers/sudoers_debug.c
plugins/sudoers/sudoers_debug.h
plugins/system_group/Makefile.in
src/Makefile.in
src/exec.c

index 2290d2d0e806d22ce17ee9cf6e0756cd64849ec4..e809ab715b7f97afd2532d98f97f2ebcc6a3f1ba 100644 (file)
@@ -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 \
index 44193cd3f5c39808729ca411c57206d649c1d364..4e5e8cfcc9e0bb4fb66ef3baa5510e833e014ede 100644 (file)
 #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);
index c30172ac30172bc72449236664cd2b1ff365b897..5fc2b887031bd4fadaba77b47a797c1822132dec 100644 (file)
@@ -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@
index 264745a29982dca948d2531f2032b0ca78621d3d..6b5ecb44b5587d48732f75b8c99f196581701042 100644 (file)
 
 #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;
 }
index 38c41bc85c86885818a3a52690e5c8d4a89c15bd..4fb4ed6ab1e1363fa5890dc61466ea21c5cfc9df 100644 (file)
@@ -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@
index cff2910eb105ea0d9a48a786b7215e7cce1cdfb4..80a2656b978fcee3ec9ea9c6b7e241785ba96acd 100644 (file)
@@ -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@
index af026a1989d1ccf33e72eab0abfcbd5bf0ca4c5a..8d6ba530b8fc20c9fc5fe9016ca88ca38f6316ad 100644 (file)
@@ -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@
index eecc1ae13cae251495096df88b2abc76b34d051d..6ad3f611aa73651f5afbb5852181ca4bb7fdc01d 100644 (file)
@@ -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
index c7e4fd779c7ecc24d4811b60c80241fbc243b02a..4c3ac5bc77ed19df6bd84b2cb95e1d31131a4992 100644 (file)
@@ -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 */
index 18023e2b6f9c1f3e34e5a5f939c4cf92e8a784e6..be5721ac4299ba95f6c799d9db45bcaeafb8e314 100644 (file)
@@ -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@
index f01a0a2cbcdf7e14910a3f3a5ba70aae352b26c6..ba93ca9275754c6ab6eb0f6e8af57bdb18782f6e 100644 (file)
@@ -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@
index 128c7f88f58fc26a9bd2bd3ca43e3712375530d3..2b53f3d069110f6b0e5b5e34d4bb225567b76754 100644 (file)
@@ -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)