From: Todd C. Miller Date: Sun, 13 Nov 2011 18:55:19 +0000 (-0500) Subject: Use SUDO_CONV_DEBUG_MSG in the plugin instead of writing X-Git-Tag: SUDO_1_8_4~154^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=65b781a2efad18c410375b5c6dfb0890be6c2b66;p=sudo Use SUDO_CONV_DEBUG_MSG in the plugin instead of writing directly to the debug file. --- diff --git a/common/sudo_debug.c b/common/sudo_debug.c index 5d7537b19..a51851fbc 100644 --- a/common/sudo_debug.c +++ b/common/sudo_debug.c @@ -46,6 +46,7 @@ #include "alloc.h" #include "error.h" #include "gettext.h" +#include "sudo_plugin.h" #include "sudo_debug.h" /* @@ -103,6 +104,8 @@ const char *const sudo_debug_subsystems[] = { static int sudo_debug_settings[NUM_SUBSYSTEMS]; static int sudo_debug_fd = -1; +extern sudo_conv_t sudo_conv; + /* * Parse settings string from sudo.conf and open debugfile. * Returns 1 on success, 0 if cannot open debugfile. @@ -117,13 +120,16 @@ int sudo_debug_init(const char *debugfile, const char *settings) for (i = 0; i < NUM_SUBSYSTEMS; i++) sudo_debug_settings[i] = -1; - /* Open debug file descriptor. */ - if (sudo_debug_fd != -1) - close(sudo_debug_fd); - sudo_debug_fd = open(debugfile, O_WRONLY|O_APPEND|O_CREAT, S_IRUSR|S_IWUSR); - if (sudo_debug_fd == -1) - return 0; - (void)fcntl(sudo_debug_fd, F_SETFD, FD_CLOEXEC); + /* Open debug file if specified. */ + if (debugfile != NULL) { + if (sudo_debug_fd != -1) + close(sudo_debug_fd); + sudo_debug_fd = open(debugfile, O_WRONLY|O_APPEND|O_CREAT, + S_IRUSR|S_IWUSR); + if (sudo_debug_fd == -1) + return 0; + (void)fcntl(sudo_debug_fd, F_SETFD, FD_CLOEXEC); + } /* Parse settings string. */ buf = estrdup(settings); @@ -238,9 +244,23 @@ sudo_debug_write(const char *str, int len) struct iovec iov[5]; int iovcnt = 4; - if (sudo_debug_fd == -1 || len <= 0) + if (len <= 0) return; + if (sudo_debug_fd == -1) { + /* Use conversation function if no debug fd. */ + struct sudo_conv_message msg; + struct sudo_conv_reply repl; + + /* Call conversation function */ + memset(&msg, 0, sizeof(msg)); + memset(&repl, 0, sizeof(repl)); + msg.msg_type = SUDO_CONV_DEBUG_MSG; + msg.msg = str; + sudo_conv(1, &msg, &repl); + return; + } + /* Prepend program name with trailing space. */ iov[1].iov_base = (char *)getprogname(); iov[1].iov_len = strlen(iov[1].iov_base); diff --git a/plugins/sudoers/sudoreplay.c b/plugins/sudoers/sudoreplay.c index 2344666ce..0e011391c 100644 --- a/plugins/sudoers/sudoreplay.c +++ b/plugins/sudoers/sudoreplay.c @@ -94,6 +94,7 @@ #include "alloc.h" #include "error.h" #include "gettext.h" +#include "sudo_plugin.h" #ifndef LINE_MAX # define LINE_MAX 2048 @@ -172,6 +173,8 @@ struct search_node { } u; } *search_expr; +sudo_conv_t sudo_conv; /* NULL in non-plugin */ + #define STACK_NODE_SIZE 32 static struct search_node *node_stack[32]; static int stack_top; diff --git a/plugins/sudoers/testsudoers.c b/plugins/sudoers/testsudoers.c index a2021a58a..ad01bbc16 100644 --- a/plugins/sudoers/testsudoers.c +++ b/plugins/sudoers/testsudoers.c @@ -112,6 +112,7 @@ static char *runas_group, *runas_user; extern int errorlineno, parse_error; extern char *errorfile; sudo_printf_t sudo_printf = testsudoers_printf; +sudo_conv_t sudo_conv; /* NULL in non-plugin */ /* For getopt(3) */ extern char *optarg; diff --git a/plugins/sudoers/visudo.c b/plugins/sudoers/visudo.c index 2bfc2da0d..8a06fbc09 100644 --- a/plugins/sudoers/visudo.c +++ b/plugins/sudoers/visudo.c @@ -95,6 +95,8 @@ struct sudoersfile { }; TQ_DECLARE(sudoersfile) +sudo_conv_t sudo_conv; /* NULL in non-plugin */ + /* * Function prototypes */ diff --git a/src/conversation.c b/src/conversation.c index 767b54450..c21a836a6 100644 --- a/src/conversation.c +++ b/src/conversation.c @@ -47,9 +47,12 @@ #include "sudo.h" #include "sudo_plugin.h" +#include "sudo_plugin_int.h" extern int tgetpass_flags; /* XXX */ +sudo_conv_t sudo_conv; /* NULL in sudo front-end */ + /* * Sudo conversation function. */