extcap: Set matching libssh log level

Instead of always setting the libssh log level to SSH_LOG_INFO
when an extcap has a ws log level of LOG_LEVEL_DEBUG or lower,
set the libssh log level to a corresponding log level
(NOISY/TRACE, DEBUG/DEBUG, INFO/INFO, MESSAGE and above/WARN).

Format the libssh logging messages more similar to our normal
logging messages, with a libssh domain and using the libssh
priority.

Prior to 0.11.0 (that is, this commit:
657d9143d1
) libssh sends some merely informational messages at their WARN
level, so lower that down to INFO, which isn't printed by default
and doesn't get printed in the GUI.

Related to #17888
This commit is contained in:
John Thacker 2024-01-18 21:19:08 -05:00
parent 55214bdacd
commit 6d39c511fb
7 changed files with 62 additions and 15 deletions

View File

@ -2491,7 +2491,7 @@ int main(int argc, char *argv[])
ws_warning("ERROR: count of packets must be specified (--remote-count)");
goto end;
}
ssh_params->debug = extcap_conf->debug;
ssh_params_set_log_level(ssh_params, extcap_conf->debug);
ret = ssh_open_remote_connection(ssh_params, remote_interface,
remote_filter, count, extcap_conf->fifo);
} else {

View File

@ -184,9 +184,7 @@ uint8_t extcap_base_parse_options(extcap_parameters * extcap, int result, char *
/* Invalid log level string. */
ret = 0;
}
else if (level <= LOG_LEVEL_DEBUG) {
extcap->debug = true;
}
extcap->debug = level;
break;
case EXTCAP_OPT_LOG_FILE:
extcap_init_log_file(optargument);

View File

@ -81,7 +81,7 @@ typedef struct _extcap_parameters
char * help_header;
GList * help_options;
bool debug;
enum ws_log_level debug;
} extcap_parameters;
/* used to inform to extcap application that end of application is requested */

View File

@ -60,9 +60,41 @@
"hmac-sha1-etm@openssh.com,hmac-sha1"
#endif
static void extcap_log(int priority _U_, const char *function, const char *buffer, void *userdata _U_)
static void extcap_log(int priority, const char *function, const char *buffer, void *userdata _U_)
{
ws_debug("[%s] %s", function, buffer);
enum ws_log_level level = LOG_LEVEL_DEBUG;
switch (priority) {
case SSH_LOG_TRACE:
level = LOG_LEVEL_NOISY;
break;
case SSH_LOG_DEBUG:
level = LOG_LEVEL_DEBUG;
break;
case SSH_LOG_INFO:
level = LOG_LEVEL_INFO;
break;
case SSH_LOG_WARN:
default:
/* Prior to 0.11.0 libssh prints far too much at SSH_LOG_WARN,
* including merely informational messages.
* Lower them to LOG_LEVEL_INFO, which won't get shown in the GUI
* and aren't shown by default. (Anything INFO and below goes to
* stdout due to ws_log_console_writer_set_use_stdout in extcap-base.c)
* After the following commit libssh only uses LOG_LEVEL_WARN for
* serious issues:
* https://gitlab.com/libssh/libssh-mirror/-/commit/657d9143d121dfff74f5a63f734d0096c7f37194
*/
#if LIBSSH_VERSION_INT < SSH_VERSION_INT(0,11,0)
level = LOG_LEVEL_INFO;
#else
level = LOG_LEVEL_WARNING;
#endif
break;
}
/* We set the libssh log level to specifically ask for this, so don't
* both checking the log level a second time.
*/
ws_log_write_always_full("libssh", level, NULL, 0, function, "%s", buffer);
}
void add_libssh_info(extcap_parameters * extcap_conf)
@ -101,11 +133,8 @@ ssh_session create_ssh_connection(const ssh_params_t* ssh_params, char** err_inf
goto failure;
}
if (ssh_params->debug) {
int debug_level = SSH_LOG_INFO;
ssh_options_set(sshs, SSH_OPTIONS_LOG_VERBOSITY, &debug_level);
ssh_set_log_callback(extcap_log);
}
ssh_options_set(sshs, SSH_OPTIONS_LOG_VERBOSITY, &ssh_params->debug);
ssh_set_log_callback(extcap_log);
if (ssh_params->ssh_sha1) {
if (ssh_options_set(sshs, SSH_OPTIONS_HOSTKEYS, HOSTKEYS_SHA1)) {
@ -291,6 +320,23 @@ void ssh_params_free(ssh_params_t* ssh_params)
g_free(ssh_params);
}
void ssh_params_set_log_level(ssh_params_t* ssh_params, enum ws_log_level level)
{
switch (level) {
case LOG_LEVEL_NOISY:
ssh_params->debug = SSH_LOG_TRACE;
break;
case LOG_LEVEL_DEBUG:
ssh_params->debug = SSH_LOG_DEBUG;
break;
case LOG_LEVEL_INFO:
ssh_params->debug = SSH_LOG_INFO;
break;
default:
ssh_params->debug = SSH_LOG_WARN;
}
}
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*

View File

@ -50,7 +50,7 @@ typedef struct _ssh_params {
char* sshkey_passphrase;
char* proxycommand;
bool ssh_sha1;
bool debug;
int debug;
} ssh_params_t;
/* Add libssh version information to an extcap_parameters structure */
@ -71,6 +71,9 @@ ssh_params_t* ssh_params_new(void);
/* Clean the ssh params */
void ssh_params_free(ssh_params_t* ssh_params);
/* Sets the libssh log level to match the ws log level */
void ssh_params_set_log_level(ssh_params_t* ssh_params, enum ws_log_level level);
#endif
/*

View File

@ -665,7 +665,7 @@ int main(int argc, char *argv[])
if (remote_filter == NULL)
remote_filter = local_interfaces_to_filter(ssh_params->port);
filter = concat_filters(extcap_conf->capture_filter, remote_filter);
ssh_params->debug = extcap_conf->debug;
ssh_params_set_log_level(ssh_params, extcap_conf->debug);
ret = ssh_open_remote_connection(ssh_params, remote_interface,
filter, remote_capture_command_select, remote_capture_command,
privilege, noprom, count, extcap_conf->fifo);

View File

@ -724,7 +724,7 @@ int main(int argc, char *argv[])
}
remote_center_frequency = center_freq(remote_channel_frequency, remote_channel_width);
filter = concat_filters(extcap_conf->capture_filter, remote_filter);
ssh_params->debug = extcap_conf->debug;
ssh_params_set_log_level(ssh_params, extcap_conf->debug);
ret = ssh_open_remote_connection(ssh_params, remote_capture_functions,
remote_interface, remote_channel_frequency, remote_channel_width, remote_center_frequency,
filter, count, extcap_conf->fifo);