Wire up debug_level

This commit is contained in:
Todd C. Miller
2010-02-20 13:25:10 -05:00
parent b4e0f503e1
commit abb431b363
3 changed files with 17 additions and 49 deletions

View File

@@ -189,6 +189,7 @@ parse_args(int argc, char **argv, int *nargc, char ***nargv, char ***settingsp,
#endif #endif
case 'D': case 'D':
sudo_settings.D.value = optarg; sudo_settings.D.value = optarg;
debug_level = atoi(optarg);
break; break;
case 'E': case 'E':
sudo_settings.c.value = "true"; sudo_settings.c.value = "true";

View File

@@ -84,6 +84,7 @@
*/ */
struct plugin_container policy_plugin; struct plugin_container policy_plugin;
struct plugin_container_list io_plugins; struct plugin_container_list io_plugins;
int debug_level;
/* /*
* Local functions * Local functions
@@ -179,8 +180,7 @@ main(int argc, char *argv[], char *envp[])
user_info, envp); user_info, envp);
} }
/* XXX - should not need to check for MODE_INVALIDATE ORed in */ sudo_debug(9, "sudo_mode %d", sudo_mode);
warningx("sudo_mode %d", sudo_mode); /* XXX */
switch (sudo_mode & MODE_MASK) { switch (sudo_mode & MODE_MASK) {
case MODE_VERSION: case MODE_VERSION:
policy_plugin.u.policy->show_version(!user_details.uid); policy_plugin.u.policy->show_version(!user_details.uid);
@@ -224,7 +224,7 @@ main(int argc, char *argv[], char *envp[])
case MODE_RUN: case MODE_RUN:
ok = policy_plugin.u.policy->check_policy(nargc, nargv, env_add, ok = policy_plugin.u.policy->check_policy(nargc, nargv, env_add,
&command_info, &argv_out, &user_env_out); &command_info, &argv_out, &user_env_out);
warningx("policy plugin returns %d", ok); /* XXX */ sudo_debug(8, "policy plugin returns %d", ok);
if (ok != TRUE) if (ok != TRUE)
exit(ok); /* plugin printed error message */ exit(ok); /* plugin printed error message */
command_info_to_details(command_info, &command_details); command_info_to_details(command_info, &command_details);
@@ -747,7 +747,7 @@ run_command(struct command_details *details, char *argv[], char *envp[])
/* If there are I/O plugins, allocate a pty and exec */ /* If there are I/O plugins, allocate a pty and exec */
if (!tq_empty(&io_plugins)) { if (!tq_empty(&io_plugins)) {
warningx("script mode"); /* XXX */ sudo_debug(8, "script mode");
script_setup(details->euid); script_setup(details->euid);
script_execve(details, argv, envp, &cstat); script_execve(details, argv, envp, &cstat);
} else { } else {
@@ -789,7 +789,7 @@ run_command(struct command_details *details, char *argv[], char *envp[])
_exit(1); _exit(1);
} }
close(sv[1]); close(sv[1]);
warningx("waiting for child"); /* XXX */ sudo_debug(9, "waiting for child");
/* wait for child to complete or for data on sv[0] */ /* wait for child to complete or for data on sv[0] */
fdsr = (fd_set *)emalloc2(howmany(sv[0] + 1, NFDBITS), sizeof(fd_mask)); fdsr = (fd_set *)emalloc2(howmany(sv[0] + 1, NFDBITS), sizeof(fd_mask));
@@ -855,39 +855,21 @@ run_command(struct command_details *details, char *argv[], char *envp[])
exit(exitcode); exit(exitcode);
} }
#if 0 /* XXX - convert warning/error to something log this */
/* /*
* Simple debugging/logging. * Simple debugging/logging.
* XXX - use askpass if configured?
*/ */
void void
sudo_log(int level, const char *fmt, ...) sudo_debug(int level, const char *fmt, ...)
{ {
va_list ap; va_list ap;
switch (level) { if (level > debug_level)
case SUDO_LOG_INFO: return;
va_start(ap, fmt);
vfprintf(stdout, fmt, ap); fputs(getprogname(), stderr);
va_end(ap); fputs(": ", stderr);
break; va_start(ap, fmt);
case SUDO_LOG_DEBUG1: vfprintf(stderr, fmt, ap);
case SUDO_LOG_DEBUG2: va_end(ap);
case SUDO_LOG_DEBUG3: putc('\n', stderr);
case SUDO_LOG_DEBUG4:
case SUDO_LOG_DEBUG5:
case SUDO_LOG_DEBUG6:
case SUDO_LOG_DEBUG7:
case SUDO_LOG_DEBUG8:
case SUDO_LOG_DEBUG9:
if (level > debug_level)
return;
/* FALLTHROUGH */
case SUDO_LOG_WARN:
case SUDO_LOG_ERROR:
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
}
} }
#endif

View File

@@ -209,26 +209,11 @@ extern struct plugin_container_list io_plugins;
extern int errno; extern int errno;
#endif #endif
#ifdef ntoyet
/* /*
* Sudo logging/debugging, printf-style. * Sudo logging/debugging, printf-style.
* XXX - not hooked up yet
* The debug level may be set on the command line via the -D flag. * The debug level may be set on the command line via the -D flag.
* A higher debug level yields more verbose debugging. * A higher debug level yields more verbose debugging.
*/ */
#define SUDO_LOG_DEBUG1 1 void sudo_debug(int level, const char *format, ...) __printflike(2, 3);
#define SUDO_LOG_DEBUG2 2
#define SUDO_LOG_DEBUG3 3
#define SUDO_LOG_DEBUG4 4
#define SUDO_LOG_DEBUG5 5
#define SUDO_LOG_DEBUG6 6
#define SUDO_LOG_DEBUG7 7
#define SUDO_LOG_DEBUG8 8
#define SUDO_LOG_DEBUG9 9
#define SUDO_LOG_INFO 10
#define SUDO_LOG_WARN 11
#define SUDO_LOG_ERROR 12
void sudo_log(int level, const char *format, ...) __printflike(2, 3);
#endif
#endif /* _SUDO_SUDO_H */ #endif /* _SUDO_SUDO_H */