Make sure we don't try to fall back to using the conversation
function for debugging in the main sudo process if we are unable to open the debug file.
This commit is contained in:
@@ -107,8 +107,14 @@ const char *const sudo_debug_subsystems[] = {
|
|||||||
|
|
||||||
#define NUM_SUBSYSTEMS (sizeof(sudo_debug_subsystems) / sizeof(sudo_debug_subsystems[0]) - 1)
|
#define NUM_SUBSYSTEMS (sizeof(sudo_debug_subsystems) / sizeof(sudo_debug_subsystems[0]) - 1)
|
||||||
|
|
||||||
|
/* Values for sudo_debug_mode */
|
||||||
|
#define SUDO_DEBUG_MODE_DISABLED 0
|
||||||
|
#define SUDO_DEBUG_MODE_FILE 1
|
||||||
|
#define SUDO_DEBUG_MODE_CONV 2
|
||||||
|
|
||||||
static int sudo_debug_settings[NUM_SUBSYSTEMS];
|
static int sudo_debug_settings[NUM_SUBSYSTEMS];
|
||||||
static int sudo_debug_fd = -1;
|
static int sudo_debug_fd = -1;
|
||||||
|
static int sudo_debug_mode;
|
||||||
|
|
||||||
extern sudo_conv_t sudo_conv;
|
extern sudo_conv_t sudo_conv;
|
||||||
|
|
||||||
@@ -135,6 +141,10 @@ int sudo_debug_init(const char *debugfile, const char *settings)
|
|||||||
if (sudo_debug_fd == -1)
|
if (sudo_debug_fd == -1)
|
||||||
return 0;
|
return 0;
|
||||||
(void)fcntl(sudo_debug_fd, F_SETFD, FD_CLOEXEC);
|
(void)fcntl(sudo_debug_fd, F_SETFD, FD_CLOEXEC);
|
||||||
|
sudo_debug_mode = SUDO_DEBUG_MODE_FILE;
|
||||||
|
} else {
|
||||||
|
/* Called from the plugin, no debug file. */
|
||||||
|
sudo_debug_mode = SUDO_DEBUG_MODE_CONV;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Parse settings string. */
|
/* Parse settings string. */
|
||||||
@@ -253,23 +263,21 @@ sudo_debug_write(const char *str, int len)
|
|||||||
if (len <= 0)
|
if (len <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (sudo_debug_fd == -1) {
|
switch (sudo_debug_mode) {
|
||||||
/* Use conversation function if no debug fd. */
|
case SUDO_DEBUG_MODE_CONV:
|
||||||
if (sudo_conv == NULL)
|
/* Call conversation function */
|
||||||
return;
|
if (sudo_conv != NULL) {
|
||||||
|
|
||||||
struct sudo_conv_message msg;
|
struct sudo_conv_message msg;
|
||||||
struct sudo_conv_reply repl;
|
struct sudo_conv_reply repl;
|
||||||
|
|
||||||
/* Call conversation function */
|
|
||||||
memset(&msg, 0, sizeof(msg));
|
memset(&msg, 0, sizeof(msg));
|
||||||
memset(&repl, 0, sizeof(repl));
|
memset(&repl, 0, sizeof(repl));
|
||||||
msg.msg_type = SUDO_CONV_DEBUG_MSG;
|
msg.msg_type = SUDO_CONV_DEBUG_MSG;
|
||||||
msg.msg = str;
|
msg.msg = str;
|
||||||
sudo_conv(1, &msg, &repl);
|
sudo_conv(1, &msg, &repl);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
case SUDO_DEBUG_MODE_FILE:
|
||||||
/* Prepend program name with trailing space. */
|
/* Prepend program name with trailing space. */
|
||||||
iov[1].iov_base = (char *)getprogname();
|
iov[1].iov_base = (char *)getprogname();
|
||||||
iov[1].iov_len = strlen(iov[1].iov_base);
|
iov[1].iov_len = strlen(iov[1].iov_base);
|
||||||
@@ -296,6 +304,8 @@ sudo_debug_write(const char *str, int len)
|
|||||||
|
|
||||||
/* Write message in a single syscall */
|
/* Write message in a single syscall */
|
||||||
(void) writev(sudo_debug_fd, iov, iovcnt);
|
(void) writev(sudo_debug_fd, iov, iovcnt);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -305,7 +315,7 @@ sudo_debug_printf2(int level, const char *fmt, ...)
|
|||||||
va_list ap;
|
va_list ap;
|
||||||
char *buf;
|
char *buf;
|
||||||
|
|
||||||
if (sudo_debug_fd == -1 && sudo_conv == NULL)
|
if (!sudo_debug_mode)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Extract pri and subsystem from level. */
|
/* Extract pri and subsystem from level. */
|
||||||
@@ -333,7 +343,7 @@ sudo_debug_execve2(int level, const char *path, char *const argv[], char *const
|
|||||||
int buflen, pri, subsys, log_envp = 0;
|
int buflen, pri, subsys, log_envp = 0;
|
||||||
size_t plen;
|
size_t plen;
|
||||||
|
|
||||||
if (sudo_debug_fd == -1 && sudo_conv == NULL)
|
if (!sudo_debug_mode)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Extract pri and subsystem from level. */
|
/* Extract pri and subsystem from level. */
|
||||||
|
Reference in New Issue
Block a user