Use SUDO_CONV_DEBUG_MSG in the plugin instead of writing
directly to the debug file.
This commit is contained in:
@@ -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. */
|
||||
/* 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);
|
||||
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);
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
@@ -95,6 +95,8 @@ struct sudoersfile {
|
||||
};
|
||||
TQ_DECLARE(sudoersfile)
|
||||
|
||||
sudo_conv_t sudo_conv; /* NULL in non-plugin */
|
||||
|
||||
/*
|
||||
* Function prototypes
|
||||
*/
|
||||
|
@@ -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.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user