From 1e94425015464ee52dc50030dc7d87d1c8375f05 Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Wed, 18 Aug 2004 15:48:25 +0000 Subject: [PATCH] DEBUG_TRACE now only triggers with -v on the cmdline --HG-- extra : convert_revision : 91ef4ca657cd116dba148a50a90c8bcc5d206d4b --- cli-runopts.c | 8 ++++++++ dbutil.c | 8 ++++++++ dbutil.h | 1 + debug.h | 8 +++++--- dropbearconvert.c | 5 +++++ dropbearkey.c | 12 ++++++++++-- svr-runopts.c | 8 ++++++++ 7 files changed, 45 insertions(+), 5 deletions(-) diff --git a/cli-runopts.c b/cli-runopts.c index e66f860..05f637f 100644 --- a/cli-runopts.c +++ b/cli-runopts.c @@ -59,6 +59,9 @@ static void printhelp() { "-R Remote port forwarding\n" #endif "-l \n" +#ifdef DEBUG_TRACE + "-v verbose\n" +#endif ,DROPBEAR_VERSION, cli_opts.progname); } @@ -178,6 +181,11 @@ void cli_getopts(int argc, char ** argv) { printhelp(); exit(EXIT_SUCCESS); break; +#ifdef DEBUG_TRACE + case 'v': + debug_trace = 1; + break; +#endif case 'F': case 'e': case 'c': diff --git a/dbutil.c b/dbutil.c index d8ecad5..f49c78f 100644 --- a/dbutil.c +++ b/dbutil.c @@ -66,6 +66,10 @@ void (*_dropbear_exit)(int exitcode, const char* format, va_list param) void (*_dropbear_log)(int priority, const char* format, va_list param) = generic_dropbear_log; +#ifdef DEBUG_TRACE +int debug_trace = 0; +#endif + int usingsyslog = 0; /* set by runopts, but required externally to sessions */ #ifndef DISABLE_SYSLOG void startsyslog() { @@ -134,6 +138,10 @@ void dropbear_trace(const char* format, ...) { va_list param; + if (!debug_trace) { + return; + } + va_start(param, format); fprintf(stderr, "TRACE: "); vfprintf(stderr, format, param); diff --git a/dbutil.h b/dbutil.h index ce0f311..0409e36 100644 --- a/dbutil.h +++ b/dbutil.h @@ -42,6 +42,7 @@ void dropbear_log(int priority, const char* format, ...); #ifdef DEBUG_TRACE void dropbear_trace(const char* format, ...); void printhex(unsigned char* buf, int len); +extern int debug_trace; #endif char * stripcontrol(const char * text); unsigned char * getaddrstring(struct sockaddr_storage* addr, int withport); diff --git a/debug.h b/debug.h index 3ae7ca5..9bb840b 100644 --- a/debug.h +++ b/debug.h @@ -33,9 +33,11 @@ * etc. Don't use this normally, it might cause problems */ /* #define DEBUG_VALGRIND */ -/* Define this to print trace statements - very verbose */ -/* Caution: Don't use this in an unfriendly environment (ie unfirewalled), - * since the printing does not sanitise strings etc */ +/* Define this to compile in trace debugging printf()s. You'll need to + * run programs with "-v" to turn this on. + * Caution: Don't use this in an unfriendly environment (ie unfirewalled), + * since the printing may not sanitise strings etc. This will add a reasonable + * amount to your executable size. */ /* #define DEBUG_TRACE */ /* All functions writing to the cleartext payload buffer call diff --git a/dropbearconvert.c b/dropbearconvert.c index 482a820..9e16fe7 100644 --- a/dropbearconvert.c +++ b/dropbearconvert.c @@ -62,6 +62,11 @@ int main(int argc, char ** argv) { const char* infile; const char* outfile; +#ifdef DEBUG_TRACE + /* It's hard for it to get in the way _too_ much */ + debug_trace = 1; +#endif + /* get the commandline options */ if (argc != 5) { fprintf(stderr, "All arguments must be specified\n"); diff --git a/dropbearkey.c b/dropbearkey.c index 6a10eab..364b765 100644 --- a/dropbearkey.c +++ b/dropbearkey.c @@ -75,8 +75,11 @@ static void printhelp(char * progname) { #endif "-f filename Use filename for the secret key\n" "-s bits Key size in bits, should be a multiple of 8 (optional)\n" - "-y Just print the publickey and fingerprint for the\n private key in .\n", - progname); + "-y Just print the publickey and fingerprint for the\n private key in .\n" +#ifdef DEBUG_TRACE + "-v verbose\n" +#endif + ,progname); } #if defined(DBMULTI_dropbearkey) || !defined(DROPBEAR_MULTI) @@ -127,6 +130,11 @@ int main(int argc, char ** argv) { printhelp(argv[0]); exit(EXIT_SUCCESS); break; +#ifdef DEBUG_TRACE + case 'v': + debug_trace = 1; + break; +#endif default: fprintf(stderr, "Unknown argument %s\n", argv[i]); printhelp(argv[0]); diff --git a/svr-runopts.c b/svr-runopts.c index 82b6a30..3c4c660 100644 --- a/svr-runopts.c +++ b/svr-runopts.c @@ -75,6 +75,9 @@ static void printhelp(const char * progname) { " (default %d if none specified)\n" #ifdef INETD_MODE "-i Start for inetd\n" +#endif +#ifdef DEBUG_TRACE + "-v verbose\n" #endif ,DROPBEAR_VERSION, progname, #ifdef DROPBEAR_DSS @@ -193,6 +196,11 @@ void svr_getopts(int argc, char ** argv) { printhelp(argv[0]); exit(EXIT_FAILURE); break; +#ifdef DEBUG_TRACE + case 'v': + debug_trace = 1; + break; +#endif /* case '4': svr_opts.ipv4 = 0;