aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoão Valverde <joao.valverde@tecnico.ulisboa.pt>2021-03-05 04:09:47 +0000
committerWireshark GitLab Utility <gerald+gitlab-utility@wireshark.org>2021-03-06 12:56:11 +0000
commit41a172cc953382e4c830481dea14d895c622754e (patch)
treec5356ca4a2d622f621aefd5124e9ad3bd4cd6871
parentb5530e7021fa68c1d8e7e454b758cfea64acd6ba (diff)
if_capabilities: Use a structured error msg from dumpcap
Have dumpcap in child mode return an error message with a primary and secondary string, instead of using stderr. When writing to the console log we ignore the second message to prevent flooding the log with tutorial-like info on permissions.
-rw-r--r--capchild/capture_ifinfo.c36
-rw-r--r--caputils/capture_ifinfo.h3
-rw-r--r--dumpcap.c17
-rw-r--r--tshark.c8
-rw-r--r--ui/iface_lists.c2
-rw-r--r--ui/qt/capture_options_dialog.cpp2
-rw-r--r--ui/qt/main.cpp9
-rw-r--r--ui/qt/manage_interfaces_dialog.cpp2
8 files changed, 48 insertions, 31 deletions
diff --git a/capchild/capture_ifinfo.c b/capchild/capture_ifinfo.c
index e8f049818a..a7dc7b7649 100644
--- a/capchild/capture_ifinfo.c
+++ b/capchild/capture_ifinfo.c
@@ -196,7 +196,8 @@ capture_interface_list(int *err, char **err_str, void (*update_cb)(void))
if_capabilities_t *
capture_get_if_capabilities(const gchar *ifname, gboolean monitor_mode,
const gchar *auth_string,
- char **err_str, void (*update_cb)(void))
+ char **err_primary_msg, char **err_secondary_msg,
+ void (*update_cb)(void))
{
if_capabilities_t *caps;
GList *linktype_list = NULL, *timestamp_list = NULL;
@@ -207,27 +208,28 @@ capture_get_if_capabilities(const gchar *ifname, gboolean monitor_mode,
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture Interface Capabilities ...");
/* see if the interface is from extcap */
- caps = extcap_get_if_dlts(ifname, err_str);
+ caps = extcap_get_if_dlts(ifname, err_primary_msg);
if (caps != NULL)
return caps;
/* return if the extcap interface generated an error */
- if (err_str != NULL && *err_str != NULL)
+ if (err_primary_msg != NULL && *err_primary_msg != NULL)
return NULL;
/* Try to get our interface list */
err = sync_if_capabilities_open(ifname, monitor_mode, auth_string, &data,
&primary_msg, &secondary_msg, update_cb);
if (err != 0) {
- g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture Interface Capabilities failed. Error %d, %s (%s)",
- err, primary_msg ? primary_msg : "no message",
- secondary_msg ? secondary_msg : "no secondary message");
- if (err_str) {
- *err_str = primary_msg;
- } else {
+ g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture Interface Capabilities failed. Error %d, %s",
+ err, primary_msg ? primary_msg : "no message");
+ if (err_primary_msg)
+ *err_primary_msg = primary_msg;
+ else
g_free(primary_msg);
- }
- g_free(secondary_msg);
+ if (err_secondary_msg)
+ *err_secondary_msg = secondary_msg;
+ else
+ g_free(secondary_msg);
return NULL;
}
@@ -244,8 +246,8 @@ capture_get_if_capabilities(const gchar *ifname, gboolean monitor_mode,
*/
if (raw_list[0] == NULL || *raw_list[0] == '\0') {
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture Interface Capabilities returned no information.");
- if (err_str) {
- *err_str = g_strdup("Dumpcap returned no interface capability information");
+ if (err_primary_msg) {
+ *err_primary_msg = g_strdup("Dumpcap returned no interface capability information");
}
g_strfreev(raw_list);
return NULL;
@@ -267,8 +269,8 @@ capture_get_if_capabilities(const gchar *ifname, gboolean monitor_mode,
default:
g_log(LOG_DOMAIN_CAPTURE, G_LOG_LEVEL_MESSAGE, "Capture Interface Capabilities returned bad information.");
- if (err_str) {
- *err_str = g_strdup_printf("Dumpcap returned \"%s\" for monitor-mode capability",
+ if (err_primary_msg) {
+ *err_primary_msg = g_strdup_printf("Dumpcap returned \"%s\" for monitor-mode capability",
raw_list[0]);
}
g_free(caps);
@@ -323,8 +325,8 @@ capture_get_if_capabilities(const gchar *ifname, gboolean monitor_mode,
/* Check to see if we built a list */
if (linktype_list == NULL) {
/* No. */
- if (err_str)
- *err_str = g_strdup("Dumpcap returned no link-layer types");
+ if (err_primary_msg)
+ *err_primary_msg = g_strdup("Dumpcap returned no link-layer types");
g_free(caps);
return NULL;
}
diff --git a/caputils/capture_ifinfo.h b/caputils/capture_ifinfo.h
index 9965703538..5034ddb720 100644
--- a/caputils/capture_ifinfo.h
+++ b/caputils/capture_ifinfo.h
@@ -124,7 +124,8 @@ typedef struct {
extern if_capabilities_t *
capture_get_if_capabilities(const gchar *devname, gboolean monitor_mode,
const gchar *auth_string,
- char **err_str, void (*update_cb)(void));
+ char **err_primary_msg, char **err_secondary_msg,
+ void (*update_cb)(void));
void free_if_capabilities(if_capabilities_t *caps);
diff --git a/dumpcap.c b/dumpcap.c
index 8a64a20510..19cf9f3818 100644
--- a/dumpcap.c
+++ b/dumpcap.c
@@ -5447,9 +5447,20 @@ main(int argc, char *argv[])
caps = get_if_capabilities(interface_opts, &err, &err_str);
if (caps == NULL) {
- cmdarg_err("The capabilities of the capture device \"%s\" could not be obtained (%s).\n"
- "%s", interface_opts->name, err_str,
- get_pcap_failure_secondary_error_message(err, err_str));
+ if (capture_child) {
+ char *error_msg = g_strdup_printf("The capabilities of the capture device"
+ " \"%s\" could not be obtained (%s)",
+ interface_opts->name, err_str);
+ sync_pipe_errmsg_to_parent(2, error_msg,
+ get_pcap_failure_secondary_error_message(err, err_str));
+ g_free(error_msg);
+ }
+ else {
+ cmdarg_err("The capabilities of the capture device"
+ "\"%s\" could not be obtained (%s).\n%s",
+ interface_opts->name, err_str,
+ get_pcap_failure_secondary_error_message(err, err_str));
+ }
g_free(err_str);
exit_main(2);
}
diff --git a/tshark.c b/tshark.c
index 15f30c21bf..a2e4360f31 100644
--- a/tshark.c
+++ b/tshark.c
@@ -727,7 +727,7 @@ main(int argc, char *argv[])
int caps_queries = 0;
gboolean start_capture = FALSE;
GList *if_list;
- gchar *err_str;
+ gchar *err_str, *err_str_secondary;
struct bpf_program fcode;
#else
gboolean capture_option_specified = FALSE;
@@ -2200,11 +2200,13 @@ main(int argc, char *argv[])
auth_str = g_strdup_printf("%s:%s", interface_opts->auth_username, interface_opts->auth_password);
}
#endif
- caps = capture_get_if_capabilities(interface_opts->name, interface_opts->monitor_mode, auth_str, &err_str, NULL);
+ caps = capture_get_if_capabilities(interface_opts->name, interface_opts->monitor_mode,
+ auth_str, &err_str, &err_str_secondary, NULL);
g_free(auth_str);
if (caps == NULL) {
- cmdarg_err("%s", err_str);
+ cmdarg_err("%s%s%s", err_str, err_str_secondary ? "\n" : "", err_str_secondary ? err_str_secondary : "");
g_free(err_str);
+ g_free(err_str_secondary);
exit_status = INVALID_CAPABILITY;
goto clean_exit;
}
diff --git a/ui/iface_lists.c b/ui/iface_lists.c
index 9ba39b9c5e..3294e53334 100644
--- a/ui/iface_lists.c
+++ b/ui/iface_lists.c
@@ -225,7 +225,7 @@ scan_local_interfaces(void (*update_cb)(void))
}
device.type = if_info->type;
monitor_mode = prefs_capture_device_monitor_mode(if_info->name);
- caps = capture_get_if_capabilities(if_info->name, monitor_mode, NULL, NULL, update_cb);
+ caps = capture_get_if_capabilities(if_info->name, monitor_mode, NULL, NULL, NULL, update_cb);
for (; (curr_addr = g_slist_nth(if_info->addrs, ips)) != NULL; ips++) {
temp_addr = g_new0(if_addr_t, 1);
if (ips != 0) {
diff --git a/ui/qt/capture_options_dialog.cpp b/ui/qt/capture_options_dialog.cpp
index e4bd48fa94..f015888223 100644
--- a/ui/qt/capture_options_dialog.cpp
+++ b/ui/qt/capture_options_dialog.cpp
@@ -414,7 +414,7 @@ void CaptureOptionsDialog::interfaceItemChanged(QTreeWidgetItem *item, int colum
device->remote_opts.remote_host_opts.auth_password);
}
#endif
- caps = capture_get_if_capabilities(device->name, monitor_mode, auth_str, NULL, main_window_update);
+ caps = capture_get_if_capabilities(device->name, monitor_mode, auth_str, NULL, NULL, main_window_update);
g_free(auth_str);
if (caps != Q_NULLPTR) {
diff --git a/ui/qt/main.cpp b/ui/qt/main.cpp
index ddde2cbd4b..2e37116792 100644
--- a/ui/qt/main.cpp
+++ b/ui/qt/main.cpp
@@ -449,7 +449,7 @@ int main(int argc, char *qt_argv[])
char *rf_path;
int rf_open_errno;
#ifdef HAVE_LIBPCAP
- gchar *err_str;
+ gchar *err_str, *err_str_secondary;;
#else
#ifdef _WIN32
#ifdef HAVE_AIRPCAP
@@ -854,13 +854,14 @@ int main(int argc, char *qt_argv[])
device = &g_array_index(global_capture_opts.all_ifaces, interface_t, i);
if (device->selected) {
#if defined(HAVE_PCAP_CREATE)
- caps = capture_get_if_capabilities(device->name, device->monitor_mode_supported, NULL, &err_str, main_window_update);
+ caps = capture_get_if_capabilities(device->name, device->monitor_mode_supported, NULL, &err_str, &err_str_secondary, main_window_update);
#else
- caps = capture_get_if_capabilities(device->name, FALSE, NULL, &err_str,main_window_update);
+ caps = capture_get_if_capabilities(device->name, FALSE, NULL, &err_str, &err_str_secondary, main_window_update);
#endif
if (caps == NULL) {
- cmdarg_err("%s", err_str);
+ cmdarg_err("%s%s%s", err_str, err_str_secondary ? "\n" : "", err_str_secondary ? err_str_secondary : "");
g_free(err_str);
+ g_free(err_str_secondary);
ret_val = INVALID_CAPABILITY;
goto clean_exit;
}
diff --git a/ui/qt/manage_interfaces_dialog.cpp b/ui/qt/manage_interfaces_dialog.cpp
index 99b541ca64..48ec905e4d 100644
--- a/ui/qt/manage_interfaces_dialog.cpp
+++ b/ui/qt/manage_interfaces_dialog.cpp
@@ -403,7 +403,7 @@ void ManageInterfacesDialog::updateRemoteInterfaceList(GList* rlist, remote_opti
auth_str = g_strdup_printf("%s:%s", roptions->remote_host_opts.auth_username,
roptions->remote_host_opts.auth_password);
}
- caps = capture_get_if_capabilities(if_string, monitor_mode, auth_str, NULL, main_window_update);
+ caps = capture_get_if_capabilities(if_string, monitor_mode, auth_str, NULL, NULL, main_window_update);
g_free(auth_str);
for (; (curr_addr = g_slist_nth(if_info->addrs, ips)) != NULL; ips++) {
address addr_str;