[network-manager-applet] core: applet/editor bits for MAC address spoofing/cloning (rh #447827) (bgo #553771)



commit 68b4007877ab7efb2a298d6e8d0b8d49de8ec538
Author: JiÅ?í KlimeÅ¡ <jklimes redhat com>
Date:   Tue Jun 22 14:50:40 2010 +0200

    core: applet/editor bits for MAC address spoofing/cloning (rh #447827) (bgo #553771)
    
    'Wired' and 'Wireless' tabs have new field "Cloned MAC address" for MAC cloning. The
    previous "MAC address" field gets renamed to "Device MAC address".

 src/connection-editor/ce-page-wired.glade    |   46 +++++++++++++++++++++----
 src/connection-editor/ce-page-wireless.glade |   47 +++++++++++++++++++++-----
 src/connection-editor/page-wired.c           |   44 +++++++++++++++++------
 src/connection-editor/page-wireless.c        |   43 +++++++++++++++++------
 src/utils/utils.c                            |    4 +-
 5 files changed, 142 insertions(+), 42 deletions(-)
---
diff --git a/src/connection-editor/ce-page-wired.glade b/src/connection-editor/ce-page-wired.glade
index a3c75c7..47dc568 100644
--- a/src/connection-editor/ce-page-wired.glade
+++ b/src/connection-editor/ce-page-wired.glade
@@ -110,8 +110,9 @@ Media Independent Interface (MII)</property>
           <widget class="GtkLabel" id="label26">
             <property name="visible">True</property>
             <property name="xalign">0</property>
-            <property name="label" translatable="yes">_MAC address:</property>
+            <property name="label" translatable="yes">_Device MAC address:</property>
             <property name="use_underline">True</property>
+            <property name="mnemonic_widget">wired_device_mac</property>
           </widget>
           <packing>
             <property name="top_attach">4</property>
@@ -121,10 +122,10 @@ Media Independent Interface (MII)</property>
           </packing>
         </child>
         <child>
-          <widget class="GtkEntry" id="wired_mac">
+          <widget class="GtkEntry" id="wired_device_mac">
             <property name="visible">True</property>
             <property name="can_focus">True</property>
-            <property name="tooltip">This option locks this connection to the network device specified by the MAC address entered here.  Example: 00:11:22:33:44:55</property>
+            <property name="tooltip" translatable="yes">This option locks this connection to the network device specified by its permanent MAC address entered here.  Example: 00:11:22:33:44:55</property>
           </widget>
           <packing>
             <property name="left_attach">1</property>
@@ -138,13 +139,42 @@ Media Independent Interface (MII)</property>
           <widget class="GtkLabel" id="label27">
             <property name="visible">True</property>
             <property name="xalign">0</property>
-            <property name="label" translatable="yes">MT_U:</property>
+            <property name="label" translatable="yes">_Cloned MAC address:</property>
             <property name="use_underline">True</property>
-            <property name="mnemonic_widget">wired_mtu</property>
+            <property name="mnemonic_widget">wired_cloned_mac</property>
+          </widget>
+          <packing>
+            <property name="top_attach">5</property>
+            <property name="bottom_attach">6</property>
+            <property name="x_options">GTK_FILL</property>
+            <property name="y_options"></property>
+          </packing>
+        </child>
+        <child>
+          <widget class="GtkEntry" id="wired_cloned_mac">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="tooltip" translatable="yes">The MAC address entered here will be used as hardware address for the network device this connection is activated on.  This feature is known as MAC cloning or spoofing.  Example: 00:11:22:33:44:55</property>
           </widget>
           <packing>
+            <property name="left_attach">1</property>
+            <property name="right_attach">2</property>
             <property name="top_attach">5</property>
             <property name="bottom_attach">6</property>
+            <property name="y_options"></property>
+          </packing>
+        </child>
+        <child>
+          <widget class="GtkLabel" id="label28">
+            <property name="visible">True</property>
+            <property name="xalign">0</property>
+            <property name="label" translatable="yes">MT_U:</property>
+            <property name="use_underline">True</property>
+            <property name="mnemonic_widget">wired_mtu</property>
+          </widget>
+          <packing>
+            <property name="top_attach">6</property>
+            <property name="bottom_attach">7</property>
             <property name="x_options">GTK_FILL</property>
             <property name="y_options"></property>
           </packing>
@@ -165,7 +195,7 @@ Media Independent Interface (MII)</property>
               </packing>
             </child>
             <child>
-              <widget class="GtkLabel" id="label28">
+              <widget class="GtkLabel" id="label29">
                 <property name="visible">True</property>
                 <property name="label" translatable="yes">bytes</property>
               </widget>
@@ -179,8 +209,8 @@ Media Independent Interface (MII)</property>
           <packing>
             <property name="left_attach">1</property>
             <property name="right_attach">2</property>
-            <property name="top_attach">5</property>
-            <property name="bottom_attach">6</property>
+            <property name="top_attach">6</property>
+            <property name="bottom_attach">7</property>
             <property name="x_options">GTK_FILL</property>
             <property name="y_options">GTK_FILL</property>
           </packing>
diff --git a/src/connection-editor/ce-page-wireless.glade b/src/connection-editor/ce-page-wireless.glade
index 14cf313..cda9787 100644
--- a/src/connection-editor/ce-page-wireless.glade
+++ b/src/connection-editor/ce-page-wireless.glade
@@ -43,8 +43,8 @@
           <packing>
             <property name="left_attach">1</property>
             <property name="right_attach">2</property>
-            <property name="top_attach">8</property>
-            <property name="bottom_attach">9</property>
+            <property name="top_attach">9</property>
+            <property name="bottom_attach">10</property>
             <property name="x_options">GTK_FILL</property>
             <property name="y_options">GTK_FILL</property>
           </packing>
@@ -58,17 +58,17 @@
             <property name="mnemonic_widget">wireless_mtu</property>
           </widget>
           <packing>
-            <property name="top_attach">8</property>
-            <property name="bottom_attach">9</property>
+            <property name="top_attach">9</property>
+            <property name="bottom_attach">10</property>
             <property name="x_options">GTK_FILL</property>
             <property name="y_options"></property>
           </packing>
         </child>
         <child>
-          <widget class="GtkEntry" id="wireless_mac">
+          <widget class="GtkEntry" id="wireless_device_mac">
             <property name="visible">True</property>
             <property name="can_focus">True</property>
-            <property name="tooltip" translatable="yes">This option locks this connection to the network device specified by the MAC address entered here.  Example: 00:11:22:33:44:55</property>
+            <property name="tooltip" translatable="yes">This option locks this connection to the network device specified by its permanent MAC address entered here.  Example: 00:11:22:33:44:55</property>
           </widget>
           <packing>
             <property name="left_attach">1</property>
@@ -79,12 +79,12 @@
           </packing>
         </child>
         <child>
-          <widget class="GtkLabel" id="wireless_mac_label">
+          <widget class="GtkLabel" id="wireless_device_mac_label">
             <property name="visible">True</property>
             <property name="xalign">0</property>
-            <property name="label" translatable="yes">_MAC address:</property>
+            <property name="label" translatable="yes">_Device MAC address:</property>
             <property name="use_underline">True</property>
-            <property name="mnemonic_widget">wireless_mac</property>
+            <property name="mnemonic_widget">wireless_device_mac</property>
           </widget>
           <packing>
             <property name="top_attach">7</property>
@@ -94,6 +94,35 @@
           </packing>
         </child>
         <child>
+          <widget class="GtkEntry" id="wireless_cloned_mac">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="tooltip" translatable="yes">The MAC address entered here will be used as hardware address for the network device this connection is activated on.  This feature is known as MAC cloning or spoofing.  Example: 00:11:22:33:44:55</property>
+          </widget>
+          <packing>
+            <property name="left_attach">1</property>
+            <property name="right_attach">2</property>
+            <property name="top_attach">8</property>
+            <property name="bottom_attach">9</property>
+            <property name="y_options"></property>
+          </packing>
+        </child>
+        <child>
+          <widget class="GtkLabel" id="wireless_cloned_mac_label">
+            <property name="visible">True</property>
+            <property name="xalign">0</property>
+            <property name="label" translatable="yes">_Cloned MAC address:</property>
+            <property name="use_underline">True</property>
+            <property name="mnemonic_widget">wireless_cloned_mac</property>
+          </widget>
+          <packing>
+            <property name="top_attach">8</property>
+            <property name="bottom_attach">9</property>
+            <property name="x_options">GTK_FILL</property>
+            <property name="y_options"></property>
+          </packing>
+        </child>
+        <child>
           <widget class="GtkHBox" id="wireless_tx_power_hbox">
             <property name="visible">True</property>
             <property name="spacing">6</property>
diff --git a/src/connection-editor/page-wired.c b/src/connection-editor/page-wired.c
index 88474df..91f38a3 100644
--- a/src/connection-editor/page-wired.c
+++ b/src/connection-editor/page-wired.c
@@ -17,7 +17,7 @@
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * (C) Copyright 2008 Red Hat, Inc.
+ * (C) Copyright 2008 - 2010 Red Hat, Inc.
  */
 
 #include <string.h>
@@ -38,7 +38,8 @@ G_DEFINE_TYPE (CEPageWired, ce_page_wired, CE_TYPE_PAGE)
 typedef struct {
 	NMSettingWired *setting;
 
-	GtkEntry *mac;
+	GtkEntry *device_mac;  /* Permanent MAC of the device */
+	GtkEntry *cloned_mac;  /* Cloned MAC - used for MAC spoofing */
 	GtkComboBox *port;
 	GtkComboBox *speed;
 	GtkToggleButton *duplex;
@@ -68,7 +69,8 @@ wired_private_init (CEPageWired *self)
 
 	xml = CE_PAGE (self)->xml;
 
-	priv->mac = GTK_ENTRY (glade_xml_get_widget (xml, "wired_mac"));
+	priv->device_mac = GTK_ENTRY (glade_xml_get_widget (xml, "wired_device_mac"));
+	priv->cloned_mac = GTK_ENTRY (glade_xml_get_widget (xml, "wired_cloned_mac"));
 	priv->port = GTK_COMBO_BOX (glade_xml_get_widget (xml, "wired_port"));
 	priv->speed = GTK_COMBO_BOX (glade_xml_get_widget (xml, "wired_speed"));
 	priv->duplex = GTK_TOGGLE_BUTTON (glade_xml_get_widget (xml, "wired_duplex"));
@@ -138,9 +140,13 @@ populate_ui (CEPageWired *self)
 	gtk_toggle_button_set_active (priv->autonegotiate, 
 	                              nm_setting_wired_get_auto_negotiate (setting));
 
-	/* MAC address */
-	ce_page_mac_to_entry (nm_setting_wired_get_mac_address (setting), priv->mac);
-	g_signal_connect (priv->mac, "changed", G_CALLBACK (stuff_changed), self);
+	/* Device MAC address */
+	ce_page_mac_to_entry (nm_setting_wired_get_mac_address (setting), priv->device_mac);
+	g_signal_connect (priv->device_mac, "changed", G_CALLBACK (stuff_changed), self);
+
+	/* Cloned MAC address */
+	ce_page_mac_to_entry (nm_setting_wired_get_cloned_mac_address (setting), priv->cloned_mac);
+	g_signal_connect (priv->cloned_mac, "changed", G_CALLBACK (stuff_changed), self);
 
 	/* MTU */
 	mtu_def = ce_get_property_default (NM_SETTING (setting), NM_SETTING_WIRED_MTU);
@@ -239,7 +245,8 @@ ui_to_setting (CEPageWired *self)
 	CEPageWiredPrivate *priv = CE_PAGE_WIRED_GET_PRIVATE (self);
 	const char *port;
 	guint32 speed;
-	GByteArray *mac = NULL;
+	GByteArray *device_mac = NULL;
+	GByteArray *cloned_mac = NULL;
 
 	/* Port */
 	switch (gtk_combo_box_get_active (priv->port)) {
@@ -279,10 +286,12 @@ ui_to_setting (CEPageWired *self)
 		break;
 	}
 
-	mac = ce_page_entry_to_mac (priv->mac, NULL);
+	device_mac = ce_page_entry_to_mac (priv->device_mac, NULL);
+	cloned_mac = ce_page_entry_to_mac (priv->cloned_mac, NULL);
 
 	g_object_set (priv->setting,
-				  NM_SETTING_WIRED_MAC_ADDRESS, mac,
+				  NM_SETTING_WIRED_MAC_ADDRESS, device_mac,
+				  NM_SETTING_WIRED_CLONED_MAC_ADDRESS, cloned_mac,
 				  NM_SETTING_WIRED_PORT, port,
 				  NM_SETTING_WIRED_SPEED, speed,
 				  NM_SETTING_WIRED_DUPLEX, gtk_toggle_button_get_active (priv->duplex) ? "full" : "half",
@@ -290,8 +299,11 @@ ui_to_setting (CEPageWired *self)
 				  NM_SETTING_WIRED_MTU, (guint32) gtk_spin_button_get_value_as_int (priv->mtu),
 				  NULL);
 
-	if (mac)
-		g_byte_array_free (mac, TRUE);
+	if (device_mac)
+		g_byte_array_free (device_mac, TRUE);
+	if (cloned_mac)
+		g_byte_array_free (cloned_mac, TRUE);
+
 }
 
 static gboolean
@@ -302,9 +314,17 @@ validate (CEPage *page, NMConnection *connection, GError **error)
 	gboolean invalid = FALSE;
 	GByteArray *ignore;
 
-	ignore = ce_page_entry_to_mac (priv->mac, &invalid);
+	ignore = ce_page_entry_to_mac (priv->device_mac, &invalid);
+	if (invalid)
+		return FALSE;
+	if (ignore)
+		g_byte_array_free (ignore, TRUE);
+
+	ignore = ce_page_entry_to_mac (priv->cloned_mac, &invalid);
 	if (invalid)
 		return FALSE;
+	if (ignore)
+		g_byte_array_free (ignore, TRUE);
 
 	ui_to_setting (self);
 	return nm_setting_verify (NM_SETTING (priv->setting), NULL, error);
diff --git a/src/connection-editor/page-wireless.c b/src/connection-editor/page-wireless.c
index 4a9d7f3..c2c395c 100644
--- a/src/connection-editor/page-wireless.c
+++ b/src/connection-editor/page-wireless.c
@@ -42,7 +42,8 @@ typedef struct {
 
 	GtkEntry *ssid;
 	GtkEntry *bssid;
-	GtkEntry *mac;
+	GtkEntry *device_mac;    /* Permanent MAC of the device */
+	GtkEntry *cloned_mac;    /* Cloned MAC - used for MAC spoofing */
 	GtkComboBox *mode;
 	GtkComboBox *band;
 	GtkSpinButton *channel;
@@ -69,7 +70,8 @@ wireless_private_init (CEPageWireless *self)
 
 	priv->ssid     = GTK_ENTRY (glade_xml_get_widget (xml, "wireless_ssid"));
 	priv->bssid    = GTK_ENTRY (glade_xml_get_widget (xml, "wireless_bssid"));
-	priv->mac      = GTK_ENTRY (glade_xml_get_widget (xml, "wireless_mac"));
+	priv->device_mac = GTK_ENTRY (glade_xml_get_widget (xml, "wireless_device_mac"));
+	priv->cloned_mac = GTK_ENTRY (glade_xml_get_widget (xml, "wireless_cloned_mac"));
 	priv->mode     = GTK_COMBO_BOX (glade_xml_get_widget (xml, "wireless_mode"));
 	priv->band     = GTK_COMBO_BOX (glade_xml_get_widget (xml, "wireless_band"));
 	priv->channel  = GTK_SPIN_BUTTON (glade_xml_get_widget (xml, "wireless_channel"));
@@ -339,9 +341,13 @@ populate_ui (CEPageWireless *self)
 	ce_page_mac_to_entry (nm_setting_wireless_get_bssid (setting), priv->bssid);
 	g_signal_connect_swapped (priv->bssid, "changed", G_CALLBACK (ce_page_changed), self);
 
-	/* MAC address */
-	ce_page_mac_to_entry (nm_setting_wireless_get_mac_address (setting), priv->mac);
-	g_signal_connect_swapped (priv->mac, "changed", G_CALLBACK (ce_page_changed), self);
+	/* Device MAC address */
+	ce_page_mac_to_entry (nm_setting_wireless_get_mac_address (setting), priv->device_mac);
+	g_signal_connect_swapped (priv->device_mac, "changed", G_CALLBACK (ce_page_changed), self);
+
+	/* Cloned MAC address */
+	ce_page_mac_to_entry (nm_setting_wireless_get_cloned_mac_address (setting), priv->cloned_mac);
+	g_signal_connect_swapped (priv->cloned_mac, "changed", G_CALLBACK (ce_page_changed), self);
 
 	gtk_spin_button_set_value (priv->rate, (gdouble) nm_setting_wireless_get_rate (setting));
 	gtk_spin_button_set_value (priv->tx_power, (gdouble) nm_setting_wireless_get_tx_power (setting));
@@ -445,7 +451,8 @@ ui_to_setting (CEPageWireless *self)
 	CEPageWirelessPrivate *priv = CE_PAGE_WIRELESS_GET_PRIVATE (self);
 	GByteArray *ssid;
 	GByteArray *bssid = NULL;
-	GByteArray *mac = NULL;
+	GByteArray *device_mac = NULL;
+	GByteArray *cloned_mac = NULL;
 	const char *mode;
 	const char *band;
 
@@ -470,12 +477,14 @@ ui_to_setting (CEPageWireless *self)
 	}
 
 	bssid = ce_page_entry_to_mac (priv->bssid, NULL);
-	mac = ce_page_entry_to_mac (priv->mac, NULL);
+	device_mac = ce_page_entry_to_mac (priv->device_mac, NULL);
+	cloned_mac = ce_page_entry_to_mac (priv->cloned_mac, NULL);
 
 	g_object_set (priv->setting,
 				  NM_SETTING_WIRELESS_SSID, ssid,
 				  NM_SETTING_WIRELESS_BSSID, bssid,
-				  NM_SETTING_WIRELESS_MAC_ADDRESS, mac,
+				  NM_SETTING_WIRELESS_MAC_ADDRESS, device_mac,
+				  NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS, cloned_mac,
 				  NM_SETTING_WIRELESS_MODE, mode,
 				  NM_SETTING_WIRELESS_BAND, band,
 				  NM_SETTING_WIRELESS_CHANNEL, gtk_spin_button_get_value_as_int (priv->channel),
@@ -486,8 +495,10 @@ ui_to_setting (CEPageWireless *self)
 
 	if (ssid)
 		g_byte_array_free (ssid, TRUE);
-	if (mac)
-		g_byte_array_free (mac, TRUE);
+	if (device_mac)
+		g_byte_array_free (device_mac, TRUE);
+	if (cloned_mac)
+		g_byte_array_free (cloned_mac, TRUE);
 	if (bssid)
 		g_byte_array_free (bssid, TRUE);
 }
@@ -505,10 +516,20 @@ validate (CEPage *page, NMConnection *connection, GError **error)
 	ignore = ce_page_entry_to_mac (priv->bssid, &invalid);
 	if (invalid)
 		return FALSE;
+	if (ignore)
+		g_byte_array_free (ignore, TRUE);
+
+	ignore = ce_page_entry_to_mac (priv->device_mac, &invalid);
+	if (invalid)
+		return FALSE;
+	if (ignore)
+		g_byte_array_free (ignore, TRUE);
 
-	ignore = ce_page_entry_to_mac (priv->mac, &invalid);
+	ignore = ce_page_entry_to_mac (priv->cloned_mac, &invalid);
 	if (invalid)
 		return FALSE;
+	if (ignore)
+		g_byte_array_free (ignore, TRUE);
 
 	ui_to_setting (self);
 
diff --git a/src/utils/utils.c b/src/utils/utils.c
index ff994ba..fc51583 100644
--- a/src/utils/utils.c
+++ b/src/utils/utils.c
@@ -338,7 +338,7 @@ connection_valid_for_wired (NMConnection *connection,
 		if (!setting_mac)
 			return TRUE;
 
-		str_mac = nm_device_ethernet_get_hw_address (ethdev);
+		str_mac = nm_device_ethernet_get_permanent_hw_address (ethdev);
 		g_return_val_if_fail (str_mac != NULL, FALSE);
 
 		bin_mac = ether_aton (str_mac);
@@ -377,7 +377,7 @@ connection_valid_for_wireless (NMConnection *connection,
 		const char *str_mac;
 		struct ether_addr *bin_mac;
 
-		str_mac = nm_device_wifi_get_hw_address (wdev);
+		str_mac = nm_device_wifi_get_permanent_hw_address (wdev);
 		g_return_val_if_fail (str_mac != NULL, FALSE);
 
 		bin_mac = ether_aton (str_mac);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]