Fix retrieval of data link type supported by remote interfaces with authentication
authorPascal Quantin <pascal.quantin@gmail.com>
Fri, 17 Jul 2015 15:01:27 +0000 (17:01 +0200)
committerAnders Broman <a.broman58@gmail.com>
Wed, 22 Jul 2015 07:10:10 +0000 (07:10 +0000)
Make use of -A parameter when querying data link types supported by a given interface with dumpcap.
Ensure to pass the authentication parameters configured for a remote interface when calling capture_get_if_capabilities()

Bug: 11366
Change-Id: I4efea615084a82108e4a12a64e8c46817f30a5c6
Reviewed-on: https://code.wireshark.org/review/9690
Petri-Dish: Pascal Quantin <pascal.quantin@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Pascal Quantin <pascal.quantin@gmail.com>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
13 files changed:
capchild/capture_ifinfo.c
capchild/capture_sync.c
capchild/capture_sync.h
caputils/capture_ifinfo.h
dumpcap.c
echld/dispatcher.c
tshark.c
ui/gtk/capture_dlg.c
ui/gtk/main.c
ui/gtk/prefs_capture.c
ui/iface_lists.c
ui/qt/manage_interfaces_dialog.cpp
wireshark-qt.cpp

index eb86215c89aa9f1f0df7101367b1dcc0136fc495..510f52954983391aa78fdf60c79131881170555b 100644 (file)
@@ -223,6 +223,7 @@ capture_interface_list(int *err, char **err_str, void (*update_cb)(void))
  * we use "real" data serialization instead, e.g. via XML? */
 if_capabilities_t *
 capture_get_if_capabilities(const gchar *ifname, gboolean monitor_mode,
+                            const gchar *auth_string,
                             char **err_str, void (*update_cb)(void))
 {
     if_capabilities_t *caps;
@@ -246,7 +247,7 @@ capture_get_if_capabilities(const gchar *ifname, gboolean monitor_mode,
 #endif /* HAVE_EXTCAP */
 
     /* Try to get our interface list */
-    err = sync_if_capabilities_open(ifname, monitor_mode, &data,
+    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)!",
index 29274d6647a77f88cb196268674a08dee1607038..0b92c5702804cfe5b4bd5cc8d4740af6f413fad9 100644 (file)
@@ -1324,7 +1324,7 @@ sync_interface_list_open(gchar **data, gchar **primary_msg,
  * must be freed with g_free().
  */
 int
-sync_if_capabilities_open(const gchar *ifname, gboolean monitor_mode,
+sync_if_capabilities_open(const gchar *ifname, gboolean monitor_mode, const gchar* auth,
                           gchar **data, gchar **primary_msg,
                           gchar **secondary_msg, void (*update_cb)(void))
 {
@@ -1348,6 +1348,10 @@ sync_if_capabilities_open(const gchar *ifname, gboolean monitor_mode,
     argv = sync_pipe_add_arg(argv, &argc, "-L");
     if (monitor_mode)
         argv = sync_pipe_add_arg(argv, &argc, "-I");
+    if (auth) {
+        argv = sync_pipe_add_arg(argv, &argc, "-A");
+        argv = sync_pipe_add_arg(argv, &argc, auth);
+    }
 
 #ifndef DEBUG_CHILD
     /* Run dumpcap in capture child mode */
index 7449d96939c76f77a8815545734056a34cdaa266..3cdac27956b7172711b57a34bab47c9fd983681f 100644 (file)
@@ -73,7 +73,7 @@ sync_interface_list_open(gchar **data, gchar **primary_msg,
 
 /** Get interface capabilities using dumpcap */
 extern int
-sync_if_capabilities_open(const gchar *ifname, gboolean monitor_mode,
+sync_if_capabilities_open(const gchar *ifname, gboolean monitor_mode, const gchar* auth,
                           gchar **data, gchar **primary_msg,
                           gchar **secondary_msg, void (*update_cb)(void));
 
index 4293b816b1dde4e0589e6572dc586d340212ceef..16ae28fd5107c5ce5067fb8b7389ea3b2135a8dc 100644 (file)
@@ -114,7 +114,8 @@ typedef struct {
  * Fetch the linktype list for the specified interface from a child process.
  */
 extern if_capabilities_t *
-capture_get_if_capabilities(const char *devname, gboolean monitor_mode,
+capture_get_if_capabilities(const gchar *devname, gboolean monitor_mode,
+                            const gchar *auth_string,
                             char **err_str, void (*update_cb)(void));
 
 void free_if_capabilities(if_capabilities_t *caps);
index f41f9ea6fab4502cc78ec54881903837ff4253a7..de683346e6201aac1ebf8f74e6056a0bedf04d0a 100644 (file)
--- a/dumpcap.c
+++ b/dumpcap.c
@@ -1214,11 +1214,7 @@ is_linux_bonding_device(const char *ifname _U_)
  * Get the capabilities of a network device.
  */
 static if_capabilities_t *
-get_if_capabilities(const char *devicename, gboolean monitor_mode
-#ifndef HAVE_PCAP_CREATE
-        _U_
-#endif
-, char **err_str)
+get_if_capabilities(interface_options *interface_opts, char **err_str)
 {
     if_capabilities_t *caps;
     char errbuf[PCAP_ERRBUF_SIZE];
@@ -1254,7 +1250,19 @@ get_if_capabilities(const char *devicename, gboolean monitor_mode
      */
     errbuf[0] = '\0';
 #ifdef HAVE_PCAP_OPEN
-    pch = pcap_open(devicename, MIN_PACKET_SIZE, 0, 0, NULL, errbuf);
+#ifdef HAVE_PCAP_REMOTE
+    if (strncmp (interface_opts->name, "rpcap://", 8) == 0) {
+        struct pcap_rmtauth auth;
+
+        auth.type = interface_opts->auth_type == CAPTURE_AUTH_PWD ?
+            RPCAP_RMTAUTH_PWD : RPCAP_RMTAUTH_NULL;
+        auth.username = interface_opts->auth_username;
+        auth.password = interface_opts->auth_password;
+
+        pch = pcap_open(interface_opts->name, MIN_PACKET_SIZE, 0, 0, &auth, errbuf);
+    } else
+#endif
+        pch = pcap_open(interface_opts->name, MIN_PACKET_SIZE, 0, 0, NULL, errbuf);
     caps->can_set_rfmon = FALSE;
     if (pch == NULL) {
         if (err_str != NULL)
@@ -1263,14 +1271,14 @@ get_if_capabilities(const char *devicename, gboolean monitor_mode
         return NULL;
     }
 #elif defined(HAVE_PCAP_CREATE)
-    pch = pcap_create(devicename, errbuf);
+    pch = pcap_create(interface_opts->name, errbuf);
     if (pch == NULL) {
         if (err_str != NULL)
             *err_str = g_strdup(errbuf);
         g_free(caps);
         return NULL;
     }
-    if (is_linux_bonding_device(devicename)) {
+    if (is_linux_bonding_device(interface_opts->name)) {
         /*
          * Linux bonding device; not Wi-Fi, so no monitor mode, and
          * calling pcap_can_set_rfmon() might get a "no such device"
@@ -1298,7 +1306,7 @@ get_if_capabilities(const char *devicename, gboolean monitor_mode
         caps->can_set_rfmon = FALSE;
     else if (status == 1) {
         caps->can_set_rfmon = TRUE;
-        if (monitor_mode)
+        if (interface_opts->monitor_mode)
             pcap_set_rfmon(pch, 1);
     } else {
         if (err_str != NULL) {
@@ -1325,7 +1333,7 @@ get_if_capabilities(const char *devicename, gboolean monitor_mode
         return NULL;
     }
 #else
-    pch = pcap_open_live(devicename, MIN_PACKET_SIZE, 0, 0, errbuf);
+    pch = pcap_open_live(interface_opts->name, MIN_PACKET_SIZE, 0, 0, errbuf);
     caps->can_set_rfmon = FALSE;
     if (pch == NULL) {
         if (err_str != NULL)
@@ -1334,7 +1342,7 @@ get_if_capabilities(const char *devicename, gboolean monitor_mode
         return NULL;
     }
 #endif
-    deflt = get_pcap_linktype(pch, devicename);
+    deflt = get_pcap_linktype(pch, interface_opts->name);
 #ifdef HAVE_PCAP_LIST_DATALINKS
     nlt = pcap_list_datalinks(pch, &linktypes);
     if (nlt == 0 || linktypes == NULL) {
@@ -4962,8 +4970,7 @@ DIAG_ON(cast-qual)
 
             interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, ii);
 
-            caps = get_if_capabilities(interface_opts.name,
-                                       interface_opts.monitor_mode, &err_str);
+            caps = get_if_capabilities(&interface_opts, &err_str);
             if (caps == NULL) {
                 cmdarg_err("The capabilities of the capture device \"%s\" could not be obtained (%s).\n"
                            "Please check to make sure you have sufficient permissions, and that\n"
index 9de70ae75bae5532ffcfa76c2ca6775d58caaf4b..53907d182d5ba70271b17b4d24dc3b0f3380ea58 100644 (file)
@@ -264,7 +264,7 @@ static char* intflist2json(GList* if_list, char** if_cap_err) {
 
 
 
-               caps = capture_get_if_capabilities(if_info->name, 0, if_cap_err, NULL);
+               caps = capture_get_if_capabilities(if_info->name, 0, NULL, if_cap_err, NULL);
 
                if (caps != NULL) {
                        if (caps->data_link_types != NULL) {
@@ -287,7 +287,7 @@ static char* intflist2json(GList* if_list, char** if_cap_err) {
 
                        if (caps->can_set_rfmon) {
                                free_if_capabilities(caps);
-                               caps = capture_get_if_capabilities(if_info->name, 1, if_cap_err, NULL);
+                               caps = capture_get_if_capabilities(if_info->name, 1, NULL, if_cap_err, NULL);
 
                                if (caps->data_link_types != NULL) {
                                        GList* lt_entry = caps->data_link_types;
index 42ac5daca091ad9c425bbde19970798e3119c59d..1ad7e0899a2405ded69cc3a7126d26ef2d839041 100644 (file)
--- a/tshark.c
+++ b/tshark.c
@@ -2218,9 +2218,16 @@ DIAG_ON(cast-qual)
         for (i = 0; i < global_capture_opts.ifaces->len; i++) {
           interface_options  interface_opts;
           if_capabilities_t *caps;
+          char *auth_str = NULL;
 
           interface_opts = g_array_index(global_capture_opts.ifaces, interface_options, i);
-          caps = capture_get_if_capabilities(interface_opts.name, interface_opts.monitor_mode, &err_str, NULL);
+#ifdef HAVE_PCAP_REMOTE
+          if (interface_opts.auth_type == CAPTURE_AUTH_PWD) {
+              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);
+          g_free(auth_str);
           if (caps == NULL) {
             cmdarg_err("%s", err_str);
             g_free(err_str);
index 80c848ef4f0eb39f885e77fd833d5cef2fb7b60b..747097677f5400ddf78566ffce0c7172f369d50e 100644 (file)
@@ -1225,6 +1225,7 @@ insert_new_rows(GList *list)
   model = gtk_tree_view_get_model(if_cb);
   /* Scan through the list and build a list of strings to display. */
   for (if_entry = g_list_first(list); if_entry != NULL; if_entry = g_list_next(if_entry)) {
+    gchar *auth_str = NULL;
     if_info = (if_info_t *)if_entry->data;
 #ifdef HAVE_PCAP_REMOTE
     add_interface_to_remote_list(if_info);
@@ -1282,7 +1283,14 @@ insert_new_rows(GList *list)
     }
     device.cfilter = g_strdup(global_capture_opts.default_options.cfilter);
     monitor_mode = prefs_capture_device_monitor_mode(if_string);
-    caps = capture_get_if_capabilities(if_string, monitor_mode, NULL, main_window_update);
+#ifdef HAVE_PCAP_REMOTE
+    if (global_remote_opts.remote_host_opts.auth_type == CAPTURE_AUTH_PWD) {
+      auth_str = g_strdup_printf("%s:%s", global_remote_opts.remote_host_opts.auth_username,
+                                 global_remote_opts.remote_host_opts.auth_password);
+    }
+#endif
+    caps = capture_get_if_capabilities(if_string, monitor_mode, auth_str, NULL, main_window_update);
+    g_free(auth_str);
     gtk_list_store_append (GTK_LIST_STORE(model), &iter);
     for (; (curr_addr = g_slist_nth(if_info->addrs, ips)) != NULL; ips++) {
       if (ips != 0) {
@@ -5875,6 +5883,7 @@ capture_prep_monitor_changed_cb(GtkWidget *monitor, gpointer argp _U_)
   link_row          *linkr;
   GtkWidget         *linktype_combo_box = (GtkWidget *) g_object_get_data(G_OBJECT(opt_edit_w), E_CAP_LT_CBX_KEY);
   GtkWidget         *linktype_lb        = (GtkWidget *)g_object_get_data(G_OBJECT(linktype_combo_box), E_CAP_LT_CBX_LABEL_KEY);
+  gchar             *auth_str = NULL;
 
   device = g_array_index(global_capture_opts.all_ifaces, interface_t, marked_interface);
   global_capture_opts.all_ifaces = g_array_remove_index(global_capture_opts.all_ifaces, marked_interface);
@@ -5882,7 +5891,14 @@ capture_prep_monitor_changed_cb(GtkWidget *monitor, gpointer argp _U_)
 
   if_string = g_strdup(device.name);
   monitor_mode = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(monitor));
-  caps = capture_get_if_capabilities(if_string, monitor_mode, NULL, main_window_update);
+#ifdef HAVE_PCAP_REMOTE
+  if (device.remote_opts.remote_host_opts.auth_type == CAPTURE_AUTH_PWD) {
+    auth_str = g_strdup_printf("%s:%s", device.remote_opts.remote_host_opts.auth_username,
+                               device.remote_opts.remote_host_opts.auth_password);
+  }
+#endif
+  caps = capture_get_if_capabilities(if_string, monitor_mode, auth_str, NULL, main_window_update);
+  g_free(auth_str);
 
   if (caps != NULL) {
     g_signal_handlers_disconnect_by_func(linktype_combo_box, G_CALLBACK(select_link_type_cb), NULL );
index c69ba84ebab604fd35f34af6004cf307901b5a4e..b5cd7922bc66e7382e776497ccad0d8899ede928 100644 (file)
@@ -2955,11 +2955,19 @@ DIAG_ON(cast-qual)
 
             device = g_array_index(global_capture_opts.all_ifaces, interface_t, i);
             if (device.selected) {
+                gchar* auth_str = NULL;
+#ifdef HAVE_PCAP_REMOTE
+                if (device.remote_opts.remote_host_opts.auth_type == CAPTURE_AUTH_PWD) {
+                    auth_str = g_strdup_printf("%s:%s", device.remote_opts.remote_host_opts.auth_username,
+                                               device.remote_opts.remote_host_opts.auth_password);
+                }
+#endif
 #if defined(HAVE_PCAP_CREATE)
-                caps = capture_get_if_capabilities(device.name, device.monitor_mode_supported, &err_str, main_window_update);
+                caps = capture_get_if_capabilities(device.name, device.monitor_mode_supported, auth_str, &err_str, main_window_update);
 #else
-                caps = capture_get_if_capabilities(device.name, FALSE, &err_str,main_window_update);
+                caps = capture_get_if_capabilities(device.name, FALSE, auth_str, &err_str,main_window_update);
 #endif
+                g_free(auth_str);
                 if (caps == NULL) {
                     cmdarg_err("%s", err_str);
                     g_free(err_str);
index be9654ecb2a0f386b36b1bc7722efc8c4cff8b85..b95e05c4bfbee732b9226342bb0a6cd470b47993 100644 (file)
@@ -1075,7 +1075,7 @@ ifopts_description_to_val (const char *if_name, gboolean monitor_mode, const cha
        if_capabilities_t *caps;
        int dlt = -1;
 
-       caps = capture_get_if_capabilities(if_name, monitor_mode, NULL, main_window_update);
+       caps = capture_get_if_capabilities(if_name, monitor_mode, NULL, NULL, main_window_update);
        if (caps != NULL) {
                if (caps->data_link_types != NULL) {
                        GList  *lt_entry;
@@ -1186,9 +1186,9 @@ ifopts_edit_ifsel_cb(GtkTreeSelection     *selection _U_,
         * to the interface capabilities of the selected interface
         */
 #ifdef HAVE_PCAP_CREATE
-       caps = capture_get_if_capabilities(if_name, monitor_mode, NULL, main_window_update);
+       caps = capture_get_if_capabilities(if_name, monitor_mode, NULL, NULL, main_window_update);
 #else
-       caps = capture_get_if_capabilities(if_name, FALSE, NULL, main_window_update);
+       caps = capture_get_if_capabilities(if_name, FALSE, NULL, NULL, main_window_update);
 #endif
        if (caps != NULL) {
 #ifdef HAVE_PCAP_CREATE
@@ -1304,10 +1304,10 @@ ifopts_edit_monitor_changed_cb(GtkToggleButton *tbt, gpointer udata)
        gtk_list_store_set  (list_store, &list_iter,
                             DEF_MONITOR_MODE_COLUMN, monitor_mode,
                             -1);
-       caps = capture_get_if_capabilities(if_name, monitor_mode, NULL, main_window_update);
+       caps = capture_get_if_capabilities(if_name, monitor_mode, NULL, NULL, main_window_update);
 #else
        /* no monitor-mode support */
-       caps = capture_get_if_capabilities(if_name, FALSE, NULL);
+       caps = capture_get_if_capabilities(if_name, FALSE, NULL, NULL);
 #endif
 
        /*
@@ -1620,10 +1620,10 @@ ifopts_options_add(GtkListStore *list_store, if_info_t *if_info)
 #ifdef HAVE_PCAP_CREATE
        /* get default monitor mode setting */
        monitor_mode = prefs_capture_device_monitor_mode(if_info->name);
-       caps = capture_get_if_capabilities(if_info->name, monitor_mode, NULL, main_window_update);
+       caps = capture_get_if_capabilities(if_info->name, monitor_mode, NULL, NULL, main_window_update);
 #else
        /* no monitor-mode support */
-       caps = capture_get_if_capabilities(if_info->name, FALSE, NULL, main_window_update);
+       caps = capture_get_if_capabilities(if_info->name, FALSE, NULL, NULL, main_window_update);
 #endif
 
        /* set default link-layer header type */
index 2756805a9358bf42470eab6c92b9cf889cecb830..8c29dd357e45fd3d34ab264e04cc408e6d49a361 100644 (file)
@@ -183,7 +183,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, update_cb);
+        caps = capture_get_if_capabilities(if_info->name, monitor_mode, NULL, NULL, update_cb);
         for (; (curr_addr = g_slist_nth(if_info->addrs, ips)) != NULL; ips++) {
             temp_addr = (if_addr_t *)g_malloc0(sizeof(if_addr_t));
             if (ips != 0) {
index c0746f8409b1f43afda67a5572b469214b0ead42..cc80b4dc3eb97f8bbb7a60c9c3589445b7d180fd 100644 (file)
@@ -475,7 +475,7 @@ void ManageInterfacesDialog::addRemoteInterfaces(GList* rlist, remote_options *r
     GList *if_entry, *lt_entry;
     if_info_t *if_info;
     char *if_string = NULL;
-    gchar *descr, *str = NULL, *link_type_name = NULL;;
+    gchar *descr, *str = NULL, *link_type_name = NULL, *auth_str;
     if_capabilities_t *caps;
     gint linktype_count;
     bool monitor_mode, found = false;
@@ -490,6 +490,7 @@ void ManageInterfacesDialog::addRemoteInterfaces(GList* rlist, remote_options *r
 
     guint num_interfaces = global_capture_opts.all_ifaces->len;
     for (if_entry = g_list_first(rlist); if_entry != NULL; if_entry = g_list_next(if_entry)) {
+        auth_str = NULL;
         if_info = (if_info_t *)if_entry->data;
         for (i = 0; i < num_interfaces; i++) {
             device = g_array_index(global_capture_opts.all_ifaces, interface_t, i);
@@ -546,7 +547,14 @@ void ManageInterfacesDialog::addRemoteInterfaces(GList* rlist, remote_options *r
         }
         device.cfilter = g_strdup(global_capture_opts.default_options.cfilter);
         monitor_mode = prefs_capture_device_monitor_mode(if_string);
-        caps = capture_get_if_capabilities(if_string, monitor_mode, NULL, main_window_update);
+#ifdef HAVE_PCAP_REMOTE
+        if (roptions->remote_host_opts.auth_type == CAPTURE_AUTH_PWD) {
+            auth_str = g_strdup_printf("%s:%s", roptions->remote_host_opts.auth_username,
+                                       roptions->remote_host_opts.auth_password);
+        }
+#endif
+        caps = capture_get_if_capabilities(if_string, monitor_mode, auth_str, NULL, main_window_update);
+        g_free(auth_str);
         for (; (curr_addr = g_slist_nth(if_info->addrs, ips)) != NULL; ips++) {
             address addr_str;
             char* temp_addr_str = NULL;
index 28ce67fd2a427d868667d30528934f79d0cea782..6ac94b451ca24720aa38dd2fe0d5f36dd8f99af7 100644 (file)
@@ -1248,9 +1248,9 @@ DIAG_ON(cast-qual)
             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, &err_str, main_window_update);
+                caps = capture_get_if_capabilities(device.name, device.monitor_mode_supported, NULL, &err_str, main_window_update);
 #else
-                caps = capture_get_if_capabilities(device.name, FALSE, &err_str,main_window_update);
+                caps = capture_get_if_capabilities(device.name, FALSE, NULL, &err_str,main_window_update);
 #endif
                 if (caps == NULL) {
                     cmdarg_err("%s", err_str);