]> granicus.if.org Git - sudo/commitdiff
Use SUDO_CONV_DEBUG_MSG in the plugin instead of writing
authorTodd C. Miller <Todd.Miller@courtesan.com>
Sun, 13 Nov 2011 18:55:19 +0000 (13:55 -0500)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Sun, 13 Nov 2011 18:55:19 +0000 (13:55 -0500)
directly to the debug file.

common/sudo_debug.c
plugins/sudoers/sudoreplay.c
plugins/sudoers/testsudoers.c
plugins/sudoers/visudo.c
src/conversation.c

index 5d7537b19585609788218e66422c4c7547888b27..a51851fbcfaf977d6add796c66c8b741bf059858 100644 (file)
@@ -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);
index 2344666ce8a204b57221f3bdd468b24f4d2ea815..0e011391cc924c1c41c212e65c2cada0382b5b85 100644 (file)
@@ -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;
index a2021a58aad330c181c803906523b50b736465ef..ad01bbc168204ab60d922d541a9af9342f30c2d6 100644 (file)
@@ -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;
index 2bfc2da0d9063309fc57336522b32e2c6c2758aa..8a06fbc0910648e4d605640c5a4d91a663580127 100644 (file)
@@ -95,6 +95,8 @@ struct sudoersfile {
 };
 TQ_DECLARE(sudoersfile)
 
+sudo_conv_t sudo_conv; /* NULL in non-plugin */
+
 /*
  * Function prototypes
  */
index 767b544505554ae127c4eb3adab01f2d0b5bfe0c..c21a836a6c2f41750791dbbd977777bc1739a3f7 100644 (file)
 
 #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.
  */