Merge pull request #152 from HansH111/tracelevel2

This commit is contained in:
Matt Johnston 2022-03-23 21:55:33 +08:00 committed by GitHub
commit 515db2d706
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 128 additions and 68 deletions

View File

@ -85,7 +85,6 @@ void recv_msg_userauth_banner() {
banner = buf_getstring(ses.payload, &bannerlen); banner = buf_getstring(ses.payload, &bannerlen);
buf_eatstring(ses.payload); /* The language string */ buf_eatstring(ses.payload); /* The language string */
if (cli_opts.quiet == 0) {
if (bannerlen > MAX_BANNER_SIZE) { if (bannerlen > MAX_BANNER_SIZE) {
TRACE(("recv_msg_userauth_banner: bannerlen too long: %d", bannerlen)) TRACE(("recv_msg_userauth_banner: bannerlen too long: %d", bannerlen))
truncated = 1; truncated = 1;
@ -110,7 +109,7 @@ void recv_msg_userauth_banner() {
if (truncated) { if (truncated) {
fprintf(stderr, "[Banner from the server is too long]\n"); fprintf(stderr, "[Banner from the server is too long]\n");
} }
}
m_free(banner); m_free(banner);
TRACE(("leave recv_msg_userauth_banner")) TRACE(("leave recv_msg_userauth_banner"))
} }
@ -261,7 +260,7 @@ void recv_msg_userauth_success() {
/* This function can validly get called multiple times /* This function can validly get called multiple times
if DROPBEAR_CLI_IMMEDIATE_AUTH is set */ if DROPBEAR_CLI_IMMEDIATE_AUTH is set */
TRACE(("received msg_userauth_success")) DEBUG1(("received msg_userauth_success"))
if (cli_opts.disable_trivial_auth && cli_ses.is_trivial_auth) { if (cli_opts.disable_trivial_auth && cli_ses.is_trivial_auth) {
dropbear_exit("trivial authentication not allowed"); dropbear_exit("trivial authentication not allowed");
} }

View File

@ -120,7 +120,7 @@ void cli_auth_password() {
char* password = NULL; char* password = NULL;
char prompt[80]; char prompt[80];
TRACE(("enter cli_auth_password")) DEBUG1(("enter cli_auth_password"))
CHECKCLEARTOWRITE(); CHECKCLEARTOWRITE();
snprintf(prompt, sizeof(prompt), "%s@%s's password: ", snprintf(prompt, sizeof(prompt), "%s@%s's password: ",

View File

@ -147,7 +147,7 @@ static void send_msg_userauth_pubkey(sign_key *key, enum signature_type sigtype,
buffer* sigbuf = NULL; buffer* sigbuf = NULL;
enum signkey_type keytype = signkey_type_from_signature(sigtype); enum signkey_type keytype = signkey_type_from_signature(sigtype);
TRACE(("enter send_msg_userauth_pubkey sigtype %d", sigtype)) DEBUG1(("enter send_msg_userauth_pubkey %s", signature_name_from_type(sigtype, NULL)))
CHECKCLEARTOWRITE(); CHECKCLEARTOWRITE();
buf_putbyte(ses.writepayload, SSH_MSG_USERAUTH_REQUEST); buf_putbyte(ses.writepayload, SSH_MSG_USERAUTH_REQUEST);

View File

@ -65,8 +65,12 @@ int main(int argc, char ** argv) {
} }
#endif #endif
TRACE(("user='%s' host='%s' port='%s' bind_address='%s' bind_port='%s'", cli_opts.username, if (cli_opts.bind_address) {
DEBUG1(("connect to: user=%s host=%s/%s bind_address=%s:%s", cli_opts.username,
cli_opts.remotehost, cli_opts.remoteport, cli_opts.bind_address, cli_opts.bind_port)) cli_opts.remotehost, cli_opts.remoteport, cli_opts.bind_address, cli_opts.bind_port))
} else {
DEBUG1(("connect to: user=%s host=%s/%s",cli_opts.username,cli_opts.remotehost,cli_opts.remoteport))
}
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) { if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) {
dropbear_exit("signal() error"); dropbear_exit("signal() error");
@ -135,6 +139,7 @@ static void cli_proxy_cmd(int *sock_in, int *sock_out, pid_t *pid_out) {
ret = spawn_command(exec_proxy_cmd, ex_cmd, ret = spawn_command(exec_proxy_cmd, ex_cmd,
sock_out, sock_in, NULL, pid_out); sock_out, sock_in, NULL, pid_out);
DEBUG1(("cmd: %s pid=%d", ex_cmd,*pid_out))
m_free(ex_cmd); m_free(ex_cmd);
if (ret == DROPBEAR_FAILURE) { if (ret == DROPBEAR_FAILURE) {
dropbear_exit("Failed running proxy command"); dropbear_exit("Failed running proxy command");

View File

@ -96,7 +96,7 @@ static void printhelp() {
"-b [bind_address][:bind_port]\n" "-b [bind_address][:bind_port]\n"
"-V Version\n" "-V Version\n"
#if DEBUG_TRACE #if DEBUG_TRACE
"-v verbose (compiled with DEBUG_TRACE)\n" "-v verbose (repeat for more verbose)\n"
#endif #endif
,DROPBEAR_VERSION, cli_opts.progname, ,DROPBEAR_VERSION, cli_opts.progname,
#if DROPBEAR_CLI_PUBKEY_AUTH #if DROPBEAR_CLI_PUBKEY_AUTH
@ -302,7 +302,7 @@ void cli_getopts(int argc, char ** argv) {
#endif #endif
#if DEBUG_TRACE #if DEBUG_TRACE
case 'v': case 'v':
debug_trace = 1; debug_trace++;
break; break;
#endif #endif
case 'F': case 'F':

View File

@ -102,7 +102,7 @@ void cli_connected(int result, int sock, void* userdata, const char *errstring)
dropbear_exit("Connect failed: %s", errstring); dropbear_exit("Connect failed: %s", errstring);
} }
myses->sock_in = myses->sock_out = sock; myses->sock_in = myses->sock_out = sock;
TRACE(("cli_connected")) DEBUG1(("cli_connected"))
ses.socket_prio = DROPBEAR_PRIO_NORMAL; ses.socket_prio = DROPBEAR_PRIO_NORMAL;
/* switches to lowdelay */ /* switches to lowdelay */
update_channel_prio(); update_channel_prio();

View File

@ -463,7 +463,7 @@ algo_type * buf_match_algo(buffer* buf, algo_type localalgos[],
/* get the comma-separated list from the buffer ie "algo1,algo2,algo3" */ /* get the comma-separated list from the buffer ie "algo1,algo2,algo3" */
algolist = buf_getstring(buf, &len); algolist = buf_getstring(buf, &len);
TRACE(("buf_match_algo: %s", algolist)) DEBUG3(("buf_match_algo: %s", algolist))
remotecount = MAX_PROPOSED_ALGO; remotecount = MAX_PROPOSED_ALGO;
get_algolist(algolist, len, remotenames, &remotecount); get_algolist(algolist, len, remotenames, &remotecount);

View File

@ -869,7 +869,7 @@ static void read_kex_algos() {
goto error; goto error;
} }
TRACE(("kexguess2 %d", kexguess2)) TRACE(("kexguess2 %d", kexguess2))
TRACE(("kex algo %s", algo->name)) DEBUG3(("kex algo %s", algo->name))
ses.newkeys->algo_kex = algo->data; ses.newkeys->algo_kex = algo->data;
/* server_host_key_algorithms */ /* server_host_key_algorithms */
@ -879,7 +879,7 @@ static void read_kex_algos() {
erralgo = "hostkey"; erralgo = "hostkey";
goto error; goto error;
} }
TRACE(("signature algo %s", algo->name)) DEBUG2(("hostkey algo %s", algo->name))
ses.newkeys->algo_signature = algo->val; ses.newkeys->algo_signature = algo->val;
ses.newkeys->algo_hostkey = signkey_type_from_signature(ses.newkeys->algo_signature); ses.newkeys->algo_hostkey = signkey_type_from_signature(ses.newkeys->algo_signature);
@ -889,7 +889,7 @@ static void read_kex_algos() {
erralgo = "enc c->s"; erralgo = "enc c->s";
goto error; goto error;
} }
TRACE(("enc c2s is %s", c2s_cipher_algo->name)) DEBUG2(("enc c2s is %s", c2s_cipher_algo->name))
/* encryption_algorithms_server_to_client */ /* encryption_algorithms_server_to_client */
s2c_cipher_algo = buf_match_algo(ses.payload, sshciphers, 0, NULL); s2c_cipher_algo = buf_match_algo(ses.payload, sshciphers, 0, NULL);
@ -897,7 +897,7 @@ static void read_kex_algos() {
erralgo = "enc s->c"; erralgo = "enc s->c";
goto error; goto error;
} }
TRACE(("enc s2c is %s", s2c_cipher_algo->name)) DEBUG2(("enc s2c is %s", s2c_cipher_algo->name))
/* mac_algorithms_client_to_server */ /* mac_algorithms_client_to_server */
c2s_hash_algo = buf_match_algo(ses.payload, sshhashes, 0, NULL); c2s_hash_algo = buf_match_algo(ses.payload, sshhashes, 0, NULL);
@ -910,7 +910,7 @@ static void read_kex_algos() {
erralgo = "mac c->s"; erralgo = "mac c->s";
goto error; goto error;
} }
TRACE(("hash c2s is %s", c2s_hash_algo ? c2s_hash_algo->name : "<implicit>")) DEBUG2(("hmac c2s is %s", c2s_hash_algo ? c2s_hash_algo->name : "<implicit>"))
/* mac_algorithms_server_to_client */ /* mac_algorithms_server_to_client */
s2c_hash_algo = buf_match_algo(ses.payload, sshhashes, 0, NULL); s2c_hash_algo = buf_match_algo(ses.payload, sshhashes, 0, NULL);
@ -923,7 +923,7 @@ static void read_kex_algos() {
erralgo = "mac s->c"; erralgo = "mac s->c";
goto error; goto error;
} }
TRACE(("hash s2c is %s", s2c_hash_algo ? s2c_hash_algo->name : "<implicit>")) DEBUG2(("hmac s2c is %s", s2c_hash_algo ? s2c_hash_algo->name : "<implicit>"))
/* compression_algorithms_client_to_server */ /* compression_algorithms_client_to_server */
c2s_comp_algo = buf_match_algo(ses.payload, ses.compress_algos, 0, NULL); c2s_comp_algo = buf_match_algo(ses.payload, ses.compress_algos, 0, NULL);
@ -931,7 +931,7 @@ static void read_kex_algos() {
erralgo = "comp c->s"; erralgo = "comp c->s";
goto error; goto error;
} }
TRACE(("hash c2s is %s", c2s_comp_algo->name)) DEBUG2(("comp c2s is %s", c2s_comp_algo->name))
/* compression_algorithms_server_to_client */ /* compression_algorithms_server_to_client */
s2c_comp_algo = buf_match_algo(ses.payload, ses.compress_algos, 0, NULL); s2c_comp_algo = buf_match_algo(ses.payload, ses.compress_algos, 0, NULL);
@ -939,7 +939,7 @@ static void read_kex_algos() {
erralgo = "comp s->c"; erralgo = "comp s->c";
goto error; goto error;
} }
TRACE(("hash s2c is %s", s2c_comp_algo->name)) DEBUG2(("comp s2c is %s", s2c_comp_algo->name))
/* languages_client_to_server */ /* languages_client_to_server */
buf_eatstring(ses.payload); buf_eatstring(ses.payload);

View File

@ -404,7 +404,7 @@ static void read_session_identification() {
dropbear_exit("Incompatible remote version '%s'", ses.remoteident); dropbear_exit("Incompatible remote version '%s'", ses.remoteident);
} }
TRACE(("remoteident: %s", ses.remoteident)) DEBUG1(("remoteident: %s", ses.remoteident))
} }

View File

@ -185,39 +185,63 @@ static double time_since_start()
return nowf - debug_start_time; return nowf - debug_start_time;
} }
void dropbear_trace(const char* format, ...) { static void dropbear_tracelevel(int level, const char *format, va_list param)
va_list param; {
if (debug_trace == 0 || debug_trace < level) {
if (!debug_trace) {
return; return;
} }
va_start(param, format); fprintf(stderr, "TRACE%d (%d) %f: ", level, getpid(), time_since_start());
fprintf(stderr, "TRACE (%d) %f: ", getpid(), time_since_start());
vfprintf(stderr, format, param); vfprintf(stderr, format, param);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
}
#if (DEBUG_TRACE>=1)
void dropbear_trace1(const char* format, ...) {
va_list param;
va_start(param, format);
dropbear_tracelevel(1, format, param);
va_end(param); va_end(param);
} }
#endif
#if (DEBUG_TRACE>=2)
void dropbear_trace2(const char* format, ...) { void dropbear_trace2(const char* format, ...) {
static int trace_env = -1;
va_list param; va_list param;
if (trace_env == -1) {
trace_env = getenv("DROPBEAR_TRACE2") ? 1 : 0;
}
if (!(debug_trace && trace_env)) {
return;
}
va_start(param, format); va_start(param, format);
fprintf(stderr, "TRACE2 (%d) %f: ", getpid(), time_since_start()); dropbear_tracelevel(2, format, param);
vfprintf(stderr, format, param);
fprintf(stderr, "\n");
va_end(param); va_end(param);
} }
#endif /* DEBUG_TRACE */ #endif
#if (DEBUG_TRACE>=3)
void dropbear_trace3(const char* format, ...) {
va_list param;
va_start(param, format);
dropbear_tracelevel(3, format, param);
va_end(param);
}
#endif
#if (DEBUG_TRACE>=4)
void dropbear_trace4(const char* format, ...) {
va_list param;
va_start(param, format);
dropbear_tracelevel(4, format, param);
va_end(param);
}
#endif
#if (DEBUG_TRACE>=5)
void dropbear_trace5(const char* format, ...) {
va_list param;
va_start(param, format);
dropbear_tracelevel(5, format, param);
va_end(param);
}
#endif
#endif
/* Connect to a given unix socket. The socket is blocking */ /* Connect to a given unix socket. The socket is blocking */
#if ENABLE_CONNECT_UNIX #if ENABLE_CONNECT_UNIX

View File

@ -47,8 +47,11 @@ void dropbear_log(int priority, const char* format, ...) ATTRIB_PRINTF(2,3) ;
void fail_assert(const char* expr, const char* file, int line) ATTRIB_NORETURN; void fail_assert(const char* expr, const char* file, int line) ATTRIB_NORETURN;
#if DEBUG_TRACE #if DEBUG_TRACE
void dropbear_trace(const char* format, ...) ATTRIB_PRINTF(1,2); void dropbear_trace1(const char* format, ...) ATTRIB_PRINTF(1,2);
void dropbear_trace2(const char* format, ...) ATTRIB_PRINTF(1,2); void dropbear_trace2(const char* format, ...) ATTRIB_PRINTF(1,2);
void dropbear_trace3(const char* format, ...) ATTRIB_PRINTF(1,2);
void dropbear_trace4(const char* format, ...) ATTRIB_PRINTF(1,2);
void dropbear_trace5(const char* format, ...) ATTRIB_PRINTF(1,2);
void printhex(const char * label, const unsigned char * buf, int len); void printhex(const char * label, const unsigned char * buf, int len);
void printmpint(const char *label, mp_int *mp); void printmpint(const char *label, mp_int *mp);
void debug_start_net(void); void debug_start_net(void);

36
debug.h
View File

@ -48,15 +48,41 @@
/*#define DEBUG_KEXHASH*/ /*#define DEBUG_KEXHASH*/
/*#define DEBUG_RSA*/ /*#define DEBUG_RSA*/
/* you don't need to touch this block */
#if DEBUG_TRACE #if DEBUG_TRACE
extern int debug_trace; extern int debug_trace;
#define TRACE(X) dropbear_trace X; #endif
#define TRACE2(X) dropbear_trace2 X;
#else /*DEBUG_TRACE*/ /* Enable debug trace levels.
We can't use __VA_ARGS_ here because Dropbear supports
old ~C89 compilers */
/* Default is to discard output ... */
#define DEBUG1(X)
#define DEBUG2(X)
#define DEBUG3(X)
#define TRACE(X) #define TRACE(X)
#define TRACE2(X) #define TRACE2(X)
#endif /*DEBUG_TRACE*/ /* ... unless DEBUG_TRACE is high enough */
#if (DEBUG_TRACE>=1)
#undef DEBUG1
#define DEBUG1(X) dropbear_trace1 X;
#endif
#if (DEBUG_TRACE>=2)
#undef DEBUG2
#define DEBUG2(X) dropbear_trace2 X;
#endif
#if (DEBUG_TRACE>=3)
#undef DEBUG3
#define DEBUG3(X) dropbear_trace3 X;
#endif
#if (DEBUG_TRACE>=4)
#undef TRACE
#define TRACE(X) dropbear_trace4 X;
#endif
#if (DEBUG_TRACE>=5)
#undef TRACE2
#define TRACE2(X) dropbear_trace5 X;
#endif
/* To debug with GDB it is easier to run with no forking of child processes. /* To debug with GDB it is easier to run with no forking of child processes.
You will need to pass "-F" as well. */ You will need to pass "-F" as well. */

View File

@ -44,8 +44,11 @@ IMPORTANT: Some options will require "make clean" after changes */
This option is ignored on non-Linux platforms at present */ This option is ignored on non-Linux platforms at present */
#define DROPBEAR_REEXEC 1 #define DROPBEAR_REEXEC 1
/* Include verbose debug output, enabled with -v at runtime. /* Include verbose debug output, enabled with -v at runtime (repeat to increase).
* This will add a reasonable amount to your executable size. */ * define which level of debug output you compile in
* TRACE1 - TRACE3 = approx 4 Kb (connection, remote identity, algos, auth type info)
* TRACE4 = approx 17 Kb (detailed before connection)
* TRACE5 = approx 8 Kb (detailed after connection) */
#define DEBUG_TRACE 0 #define DEBUG_TRACE 0
/* Set this if you want to use the DROPBEAR_SMALL_CODE option. This can save /* Set this if you want to use the DROPBEAR_SMALL_CODE option. This can save