--- embedaddon/sudo/common/sudo_debug.c 2013/10/14 07:56:33 1.1.1.4 +++ embedaddon/sudo/common/sudo_debug.c 2014/06/15 16:12:54 1.1.1.5 @@ -47,15 +47,16 @@ #include #include +#define DEFAULT_TEXT_DOMAIN "sudo" +#include "gettext.h" /* must be included before missing.h */ + #include "missing.h" #include "alloc.h" #include "fatal.h" #include "sudo_plugin.h" #include "sudo_debug.h" +#include "sudo_util.h" -#define DEFAULT_TEXT_DOMAIN "sudo" -#include "gettext.h" - /* * The debug priorities and subsystems are currently hard-coded. * In the future we might consider allowing plugins to register their @@ -103,6 +104,7 @@ const char *const sudo_debug_subsystems[] = { "plugin", "hooks", "sssd", + "event", NULL }; @@ -118,6 +120,7 @@ static int sudo_debug_fd = -1; static int sudo_debug_mode; static char sudo_debug_pidstr[(((sizeof(int) * 8) + 2) / 3) + 3]; static size_t sudo_debug_pidlen; +static const int num_subsystems = NUM_SUBSYSTEMS; /* * Parse settings string from sudo.conf and open debugfile. @@ -129,8 +132,12 @@ int sudo_debug_init(const char *debugfile, const char char *buf, *cp, *subsys, *pri; int i, j; + /* Make sure we are not already initialized. */ + if (sudo_debug_mode != SUDO_DEBUG_MODE_DISABLED) + return 1; + /* Init per-subsystems settings to -1 since 0 is a valid priority. */ - for (i = 0; i < NUM_SUBSYSTEMS; i++) + for (i = 0; i < num_subsystems; i++) sudo_debug_settings[i] = -1; /* Open debug file if specified. */ @@ -339,12 +346,12 @@ sudo_debug_write_file(const char *func, const char *fi iov[2].iov_base = sudo_debug_pidstr; iov[2].iov_len = sudo_debug_pidlen; - /* Add string along with newline if it doesn't have one. */ + /* Add string, trimming any trailing newlines. */ + while (len > 0 && str[len - 1] == '\n') + len--; if (len > 0) { iov[iovcnt].iov_base = (char *)str; iov[iovcnt].iov_len = len; - while (len > 0 && str[len - 1] == '\n') - iov[iovcnt].iov_len--; iovcnt++; } @@ -437,7 +444,7 @@ sudo_debug_vprintf2(const char *func, const char *file subsys = SUDO_DEBUG_SUBSYS(level); /* Make sure we want debug info at this level. */ - if (subsys < NUM_SUBSYSTEMS && sudo_debug_settings[subsys] >= pri) { + if (subsys < num_subsystems && sudo_debug_settings[subsys] >= pri) { buflen = fmt ? vasprintf(&buf, fmt, ap) : 0; if (buflen != -1) { int errcode = ISSET(level, SUDO_DEBUG_ERRNO) ? saved_errno : 0; @@ -452,7 +459,19 @@ sudo_debug_vprintf2(const char *func, const char *file errno = saved_errno; } +#ifdef NO_VARIADIC_MACROS void +sudo_debug_printf_nvm(int pri, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + sudo_debug_vprintf2(NULL, NULL, 0, pri, fmt, ap); + va_end(ap); +} +#endif /* NO_VARIADIC_MACROS */ + +void sudo_debug_printf2(const char *func, const char *file, int lineno, int level, const char *fmt, ...) { @@ -479,7 +498,7 @@ sudo_debug_execve2(int level, const char *path, char * subsys = SUDO_DEBUG_SUBSYS(level); /* Make sure we want debug info at this level. */ - if (subsys >= NUM_SUBSYSTEMS || sudo_debug_settings[subsys] < pri) + if (subsys >= num_subsystems || sudo_debug_settings[subsys] < pri) return; /* Log envp for debug level "debug". */ @@ -545,8 +564,16 @@ sudo_debug_execve2(int level, const char *path, char * } /* - * Dup sudo_debug_fd to the specified value so we don't - * close it when calling closefrom(). + * Getter for the debug descriptor. + */ +int +sudo_debug_fd_get(void) +{ + return sudo_debug_fd; +} + +/* + * Setter for the debug descriptor. */ int sudo_debug_fd_set(int fd)