mirror of
https://github.com/sudo-project/sudo.git
synced 2025-09-01 06:45:10 +00:00
Add support for multiple Debug lines per program. Callers may
register arbitrary debug facilities or use built-in defaults. We now use separate Debug statements for plugins and programs.
This commit is contained in:
@@ -119,7 +119,7 @@ static void check_foreground(void);
|
||||
static void
|
||||
pty_cleanup(void)
|
||||
{
|
||||
debug_decl(cleanup, SUDO_DEBUG_EXEC);
|
||||
debug_decl(cleanup, SUDO_DEBUG_EXEC, sudo_debug_instance);
|
||||
|
||||
if (!TAILQ_EMPTY(&io_plugins) && io_fds[SFD_USERTTY] != -1)
|
||||
sudo_term_restore(io_fds[SFD_USERTTY], 0);
|
||||
@@ -191,7 +191,7 @@ mon_handler(int s)
|
||||
void
|
||||
pty_setup(uid_t uid, const char *tty, const char *utmp_user)
|
||||
{
|
||||
debug_decl(pty_setup, SUDO_DEBUG_EXEC);
|
||||
debug_decl(pty_setup, SUDO_DEBUG_EXEC, sudo_debug_instance);
|
||||
|
||||
io_fds[SFD_USERTTY] = open(_PATH_TTY, O_RDWR|O_NOCTTY, 0);
|
||||
if (io_fds[SFD_USERTTY] != -1) {
|
||||
@@ -213,7 +213,7 @@ log_ttyin(const char *buf, unsigned int n, struct io_buffer *iob)
|
||||
struct plugin_container *plugin;
|
||||
sigset_t omask;
|
||||
bool rval = true;
|
||||
debug_decl(log_ttyin, SUDO_DEBUG_EXEC);
|
||||
debug_decl(log_ttyin, SUDO_DEBUG_EXEC, sudo_debug_instance);
|
||||
|
||||
sigprocmask(SIG_BLOCK, &ttyblock, &omask);
|
||||
TAILQ_FOREACH(plugin, &io_plugins, entries) {
|
||||
@@ -241,7 +241,7 @@ log_stdin(const char *buf, unsigned int n, struct io_buffer *iob)
|
||||
struct plugin_container *plugin;
|
||||
sigset_t omask;
|
||||
bool rval = true;
|
||||
debug_decl(log_stdin, SUDO_DEBUG_EXEC);
|
||||
debug_decl(log_stdin, SUDO_DEBUG_EXEC, sudo_debug_instance);
|
||||
|
||||
sigprocmask(SIG_BLOCK, &ttyblock, &omask);
|
||||
TAILQ_FOREACH(plugin, &io_plugins, entries) {
|
||||
@@ -269,7 +269,7 @@ log_ttyout(const char *buf, unsigned int n, struct io_buffer *iob)
|
||||
struct plugin_container *plugin;
|
||||
sigset_t omask;
|
||||
bool rval = true;
|
||||
debug_decl(log_ttyout, SUDO_DEBUG_EXEC);
|
||||
debug_decl(log_ttyout, SUDO_DEBUG_EXEC, sudo_debug_instance);
|
||||
|
||||
sigprocmask(SIG_BLOCK, &ttyblock, &omask);
|
||||
TAILQ_FOREACH(plugin, &io_plugins, entries) {
|
||||
@@ -309,7 +309,7 @@ log_stdout(const char *buf, unsigned int n, struct io_buffer *iob)
|
||||
struct plugin_container *plugin;
|
||||
sigset_t omask;
|
||||
bool rval = true;
|
||||
debug_decl(log_stdout, SUDO_DEBUG_EXEC);
|
||||
debug_decl(log_stdout, SUDO_DEBUG_EXEC, sudo_debug_instance);
|
||||
|
||||
sigprocmask(SIG_BLOCK, &ttyblock, &omask);
|
||||
TAILQ_FOREACH(plugin, &io_plugins, entries) {
|
||||
@@ -349,7 +349,7 @@ log_stderr(const char *buf, unsigned int n, struct io_buffer *iob)
|
||||
struct plugin_container *plugin;
|
||||
sigset_t omask;
|
||||
bool rval = true;
|
||||
debug_decl(log_stderr, SUDO_DEBUG_EXEC);
|
||||
debug_decl(log_stderr, SUDO_DEBUG_EXEC, sudo_debug_instance);
|
||||
|
||||
sigprocmask(SIG_BLOCK, &ttyblock, &omask);
|
||||
TAILQ_FOREACH(plugin, &io_plugins, entries) {
|
||||
@@ -390,7 +390,7 @@ log_stderr(const char *buf, unsigned int n, struct io_buffer *iob)
|
||||
static void
|
||||
check_foreground(void)
|
||||
{
|
||||
debug_decl(check_foreground, SUDO_DEBUG_EXEC);
|
||||
debug_decl(check_foreground, SUDO_DEBUG_EXEC, sudo_debug_instance);
|
||||
|
||||
if (io_fds[SFD_USERTTY] != -1) {
|
||||
foreground = tcgetpgrp(io_fds[SFD_USERTTY]) == ppgrp;
|
||||
@@ -416,7 +416,7 @@ suspend_parent(int signo)
|
||||
char signame[SIG2STR_MAX];
|
||||
sigaction_t sa, osa;
|
||||
int n, rval = 0;
|
||||
debug_decl(suspend_parent, SUDO_DEBUG_EXEC);
|
||||
debug_decl(suspend_parent, SUDO_DEBUG_EXEC, sudo_debug_instance);
|
||||
|
||||
switch (signo) {
|
||||
case SIGTTOU:
|
||||
@@ -506,7 +506,7 @@ suspend_parent(int signo)
|
||||
void
|
||||
terminate_command(pid_t pid, bool use_pgrp)
|
||||
{
|
||||
debug_decl(terminate_command, SUDO_DEBUG_EXEC);
|
||||
debug_decl(terminate_command, SUDO_DEBUG_EXEC, sudo_debug_instance);
|
||||
|
||||
/*
|
||||
* Note that SIGCHLD will interrupt the sleep()
|
||||
@@ -541,7 +541,7 @@ io_callback(int fd, int what, void *v)
|
||||
struct io_buffer *iob = v;
|
||||
struct sudo_event_base *evbase;
|
||||
int n;
|
||||
debug_decl(io_callback, SUDO_DEBUG_EXEC);
|
||||
debug_decl(io_callback, SUDO_DEBUG_EXEC, sudo_debug_instance);
|
||||
|
||||
if (ISSET(what, SUDO_EV_READ)) {
|
||||
evbase = sudo_ev_get_base(iob->revent);
|
||||
@@ -664,7 +664,7 @@ io_buf_new(int rfd, int wfd, bool (*action)(const char *, unsigned int, struct i
|
||||
{
|
||||
int n;
|
||||
struct io_buffer *iob;
|
||||
debug_decl(io_buf_new, SUDO_DEBUG_EXEC);
|
||||
debug_decl(io_buf_new, SUDO_DEBUG_EXEC, sudo_debug_instance);
|
||||
|
||||
/* Set non-blocking mode. */
|
||||
n = fcntl(rfd, F_GETFL, 0);
|
||||
@@ -702,7 +702,7 @@ fork_pty(struct command_details *details, int sv[], sigset_t *omask)
|
||||
sigaction_t sa;
|
||||
sigset_t mask;
|
||||
pid_t child;
|
||||
debug_decl(fork_pty, SUDO_DEBUG_EXEC);
|
||||
debug_decl(fork_pty, SUDO_DEBUG_EXEC, sudo_debug_instance);
|
||||
|
||||
ppgrp = getpgrp(); /* parent's pgrp, so child can signal us */
|
||||
|
||||
@@ -877,7 +877,7 @@ pty_close(struct command_status *cstat)
|
||||
{
|
||||
struct io_buffer *iob;
|
||||
int n;
|
||||
debug_decl(pty_close, SUDO_DEBUG_EXEC);
|
||||
debug_decl(pty_close, SUDO_DEBUG_EXEC, sudo_debug_instance);
|
||||
|
||||
/* Flush any remaining output (the plugin already got it) */
|
||||
if (io_fds[SFD_USERTTY] != -1) {
|
||||
@@ -926,7 +926,7 @@ void
|
||||
add_io_events(struct sudo_event_base *evbase)
|
||||
{
|
||||
struct io_buffer *iob;
|
||||
debug_decl(add_io_events, SUDO_DEBUG_EXEC);
|
||||
debug_decl(add_io_events, SUDO_DEBUG_EXEC, sudo_debug_instance);
|
||||
|
||||
/*
|
||||
* Schedule all readers as long as the buffer is not full.
|
||||
@@ -968,7 +968,7 @@ del_io_events(void)
|
||||
{
|
||||
struct io_buffer *iob;
|
||||
struct sudo_event_base *evbase;
|
||||
debug_decl(del_io_events, SUDO_DEBUG_EXEC);
|
||||
debug_decl(del_io_events, SUDO_DEBUG_EXEC, sudo_debug_instance);
|
||||
|
||||
/* Remove iobufs from existing event base. */
|
||||
SLIST_FOREACH(iob, &iobufs, entries) {
|
||||
@@ -1032,7 +1032,7 @@ deliver_signal(pid_t pid, int signo, bool from_parent)
|
||||
{
|
||||
char signame[SIG2STR_MAX];
|
||||
int status;
|
||||
debug_decl(deliver_signal, SUDO_DEBUG_EXEC);
|
||||
debug_decl(deliver_signal, SUDO_DEBUG_EXEC, sudo_debug_instance);
|
||||
|
||||
if (signo == SIGCONT_FG)
|
||||
strlcpy(signame, "CONT_FG", sizeof(signame));
|
||||
@@ -1081,7 +1081,7 @@ static int
|
||||
send_status(int fd, struct command_status *cstat)
|
||||
{
|
||||
int n = -1;
|
||||
debug_decl(send_status, SUDO_DEBUG_EXEC);
|
||||
debug_decl(send_status, SUDO_DEBUG_EXEC, sudo_debug_instance);
|
||||
|
||||
if (cstat->type != CMD_INVALID) {
|
||||
sudo_debug_printf(SUDO_DEBUG_INFO,
|
||||
@@ -1111,7 +1111,7 @@ handle_sigchld(int backchannel, struct command_status *cstat)
|
||||
bool alive = true;
|
||||
int status;
|
||||
pid_t pid;
|
||||
debug_decl(handle_sigchld, SUDO_DEBUG_EXEC);
|
||||
debug_decl(handle_sigchld, SUDO_DEBUG_EXEC, sudo_debug_instance);
|
||||
|
||||
/* read command status */
|
||||
do {
|
||||
@@ -1168,7 +1168,7 @@ mon_signal_pipe_cb(int fd, int what, void *v)
|
||||
struct monitor_closure *mc = v;
|
||||
unsigned char signo;
|
||||
ssize_t nread;
|
||||
debug_decl(mon_signal_pipe_cb, SUDO_DEBUG_EXEC);
|
||||
debug_decl(mon_signal_pipe_cb, SUDO_DEBUG_EXEC, sudo_debug_instance);
|
||||
|
||||
nread = read(fd, &signo, sizeof(signo));
|
||||
if (nread <= 0) {
|
||||
@@ -1203,7 +1203,7 @@ mon_errpipe_cb(int fd, int what, void *v)
|
||||
{
|
||||
struct monitor_closure *mc = v;
|
||||
ssize_t n;
|
||||
debug_decl(mon_errpipe_cb, SUDO_DEBUG_EXEC);
|
||||
debug_decl(mon_errpipe_cb, SUDO_DEBUG_EXEC, sudo_debug_instance);
|
||||
|
||||
/* read errno or EOF from command pipe */
|
||||
n = read(fd, mc->cstat, sizeof(struct command_status));
|
||||
@@ -1226,7 +1226,7 @@ mon_backchannel_cb(int fd, int what, void *v)
|
||||
struct monitor_closure *mc = v;
|
||||
struct command_status cstmp;
|
||||
ssize_t n;
|
||||
debug_decl(mon_backchannel_cb, SUDO_DEBUG_EXEC);
|
||||
debug_decl(mon_backchannel_cb, SUDO_DEBUG_EXEC, sudo_debug_instance);
|
||||
|
||||
/* read command from backchannel, should be a signal */
|
||||
n = recv(fd, &cstmp, sizeof(cstmp), MSG_WAITALL);
|
||||
@@ -1264,7 +1264,7 @@ exec_monitor(struct command_details *details, int backchannel)
|
||||
struct monitor_closure mc;
|
||||
sigaction_t sa;
|
||||
int errpipe[2], n;
|
||||
debug_decl(exec_monitor, SUDO_DEBUG_EXEC);
|
||||
debug_decl(exec_monitor, SUDO_DEBUG_EXEC, sudo_debug_instance);
|
||||
|
||||
/* Close unused fds. */
|
||||
if (io_fds[SFD_MASTER] != -1)
|
||||
@@ -1481,7 +1481,7 @@ exec_pty(struct command_details *details,
|
||||
struct command_status *cstat, int errfd)
|
||||
{
|
||||
pid_t self = getpid();
|
||||
debug_decl(exec_pty, SUDO_DEBUG_EXEC);
|
||||
debug_decl(exec_pty, SUDO_DEBUG_EXEC, sudo_debug_instance);
|
||||
|
||||
/* Register cleanup function */
|
||||
sudo_fatal_callback_register(pty_cleanup);
|
||||
@@ -1526,7 +1526,7 @@ sync_ttysize(int src, int dst)
|
||||
#ifdef TIOCGWINSZ
|
||||
struct winsize wsize;
|
||||
pid_t pgrp;
|
||||
debug_decl(sync_ttysize, SUDO_DEBUG_EXEC);
|
||||
debug_decl(sync_ttysize, SUDO_DEBUG_EXEC, sudo_debug_instance);
|
||||
|
||||
if (ioctl(src, TIOCGWINSZ, &wsize) == 0) {
|
||||
ioctl(dst, TIOCSWINSZ, &wsize);
|
||||
@@ -1558,7 +1558,7 @@ static void
|
||||
ev_free_by_fd(struct sudo_event_base *evbase, int fd)
|
||||
{
|
||||
struct io_buffer *iob;
|
||||
debug_decl(ev_free_by_fd, SUDO_DEBUG_EXEC);
|
||||
debug_decl(ev_free_by_fd, SUDO_DEBUG_EXEC, sudo_debug_instance);
|
||||
|
||||
/* Deschedule any users of the fd and free up the events. */
|
||||
SLIST_FOREACH(iob, &iobufs, entries) {
|
||||
@@ -1593,7 +1593,7 @@ ev_free_by_fd(struct sudo_event_base *evbase, int fd)
|
||||
static int
|
||||
safe_close(int fd)
|
||||
{
|
||||
debug_decl(safe_close, SUDO_DEBUG_EXEC);
|
||||
debug_decl(safe_close, SUDO_DEBUG_EXEC, sudo_debug_instance);
|
||||
|
||||
/* Avoid closing /dev/tty or std{in,out,err}. */
|
||||
if (fd < 3 || fd == io_fds[SFD_USERTTY]) {
|
||||
|
Reference in New Issue
Block a user