[network-manager-openvpn/NM_0_8] core/ui: add SOCKS proxy support (bgo #440031)



commit 84062eab6e5445fc4e31dad0a868ae8b0805918d
Author: Dan Williams <dcbw redhat com>
Date:   Thu Aug 19 00:13:30 2010 -0500

    core/ui: add SOCKS proxy support (bgo #440031)

 properties/auth-helpers.c          |  118 +++++++++++++++++++++++------------
 properties/import-export.c         |   32 +++++++---
 properties/nm-openvpn-dialog.glade |    2 +-
 src/nm-openvpn-service.c           |   46 ++++++++++----
 src/nm-openvpn-service.h           |    7 +-
 5 files changed, 136 insertions(+), 69 deletions(-)
---
diff --git a/properties/auth-helpers.c b/properties/auth-helpers.c
index c660ebe..631be2b 100644
--- a/properties/auth-helpers.c
+++ b/properties/auth-helpers.c
@@ -845,9 +845,10 @@ static const char *advanced_keys[] = {
 	NM_OPENVPN_KEY_FRAGMENT_SIZE,
 	NM_OPENVPN_KEY_TAP_DEV,
 	NM_OPENVPN_KEY_PROTO_TCP,
-	NM_OPENVPN_KEY_HTTP_PROXY,
-	NM_OPENVPN_KEY_HTTP_PROXY_PORT,
-	NM_OPENVPN_KEY_HTTP_PROXY_RETRY,
+	NM_OPENVPN_KEY_PROXY_TYPE,
+	NM_OPENVPN_KEY_PROXY_SERVER,
+	NM_OPENVPN_KEY_PROXY_PORT,
+	NM_OPENVPN_KEY_PROXY_RETRY,
 	NM_OPENVPN_KEY_HTTP_PROXY_USERNAME,
 	NM_OPENVPN_KEY_CIPHER,
 	NM_OPENVPN_KEY_AUTH,
@@ -1130,8 +1131,9 @@ tls_auth_toggled_cb (GtkWidget *widget, gpointer user_data)
 	gtk_widget_set_sensitive (widget, use_auth);
 }
 
-#define PROXY_TYPE_NONE 0
-#define PROXY_TYPE_HTTP 1
+#define PROXY_TYPE_NONE  0
+#define PROXY_TYPE_HTTP  1
+#define PROXY_TYPE_SOCKS 2
 
 static void
 proxy_type_changed (GtkComboBox *combo, gpointer user_data)
@@ -1140,20 +1142,36 @@ proxy_type_changed (GtkComboBox *combo, gpointer user_data)
 	gboolean sensitive;
 	GtkWidget *widget;
 	guint32 i = 0;
+	int active;
 	const char *widgets[] = {
 		"proxy_desc_label", "proxy_server_label", "proxy_server_entry",
 		"proxy_port_label", "proxy_port_spinbutton", "proxy_retry_checkbutton",
 		"proxy_username_label", "proxy_password_label", "proxy_username_entry",
 		"proxy_password_entry", NULL
 	};
+	const char *user_pass_widgets[] = {
+		"proxy_username_label", "proxy_password_label", "proxy_username_entry",
+		"proxy_password_entry", NULL
+	};
+
+	active = gtk_combo_box_get_active (combo);
+	sensitive = (active > PROXY_TYPE_NONE);
 
-	sensitive = (gtk_combo_box_get_active (combo) == PROXY_TYPE_HTTP);
 	while (widgets[i]) {
 		widget = glade_xml_get_widget (xml, widgets[i++]);
 		gtk_widget_set_sensitive (widget, sensitive);
 	}
 
-	/* HTTP Proxy option requires TCP; but don't reset the TCP checkbutton
+	/* Additionally user/pass widgets need to be disabled for SOCKS */
+	if (active == PROXY_TYPE_SOCKS) {
+		i = 0;
+		while (user_pass_widgets[i]) {
+			widget = glade_xml_get_widget (xml, user_pass_widgets[i++]);
+			gtk_widget_set_sensitive (widget, FALSE);
+		}
+	}
+
+	/* Proxy options require TCP; but don't reset the TCP checkbutton
 	 * to false when the user disables HTTP proxy; leave it checked.
 	 */
 	widget = glade_xml_get_widget (xml, "tcp_checkbutton");
@@ -1175,7 +1193,7 @@ advanced_dialog_new (GHashTable *hash, const char *contype)
 	const char *value, *value2;
 	GtkListStore *store;
 	GtkTreeIter iter;
-	guint32 active = 0;
+	guint32 active = PROXY_TYPE_NONE;
 
 	g_return_val_if_fail (hash != NULL, NULL);
 
@@ -1226,27 +1244,27 @@ advanced_dialog_new (GHashTable *hash, const char *contype)
 	gtk_list_store_append (store, &iter);
 	gtk_list_store_set (store, &iter, 0, _("Not required"), -1);
 	gtk_list_store_append (store, &iter);
-	gtk_list_store_set (store, &iter, 0, _("HTTP Proxy"), -1);
+	gtk_list_store_set (store, &iter, 0, _("HTTP"), -1);
+	gtk_list_store_append (store, &iter);
+	gtk_list_store_set (store, &iter, 0, _("SOCKS"), -1);
 
-	value = g_hash_table_lookup (hash, NM_OPENVPN_KEY_HTTP_PROXY);
-	value2 = g_hash_table_lookup (hash, NM_OPENVPN_KEY_HTTP_PROXY_PORT);
+	value = g_hash_table_lookup (hash, NM_OPENVPN_KEY_PROXY_SERVER);
+	value2 = g_hash_table_lookup (hash, NM_OPENVPN_KEY_PROXY_PORT);
 	if (value && strlen (value) && value2 && strlen (value2)) {
-		long int tmp = 8080;
-
-		active = 1;
+		long int tmp = 0;
 
 		widget = glade_xml_get_widget (xml, "proxy_server_entry");
 		gtk_entry_set_text (GTK_ENTRY (widget), value);
 
 		errno = 0;
 		tmp = strtol (value2, NULL, 10);
-		if (errno != 0 || tmp < 1 || tmp > 65535)
-			tmp = 8080;
+		if (errno != 0 || tmp < 0 || tmp > 65535)
+			tmp = 0;
 		widget = glade_xml_get_widget (xml, "proxy_port_spinbutton");
 		gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), (gdouble) tmp);
 
 		widget = glade_xml_get_widget (xml, "proxy_retry_checkbutton");
-		value = g_hash_table_lookup (hash, NM_OPENVPN_KEY_HTTP_PROXY_RETRY);
+		value = g_hash_table_lookup (hash, NM_OPENVPN_KEY_PROXY_RETRY);
 		if (value && !strcmp (value, "yes"))
 			gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
 
@@ -1263,6 +1281,16 @@ advanced_dialog_new (GHashTable *hash, const char *contype)
 		}
 	}
 
+	value = g_hash_table_lookup (hash, NM_OPENVPN_KEY_PROXY_TYPE);
+	if (value) {
+		if (!strcmp (value, "http"))
+			active = PROXY_TYPE_HTTP;
+		else if (!strcmp (value, "socks"))
+			active = PROXY_TYPE_SOCKS;
+		else
+			active = PROXY_TYPE_NONE;
+	}
+
 	gtk_combo_box_set_model (GTK_COMBO_BOX (combo), GTK_TREE_MODEL (store));
 	g_object_unref (store);
 	gtk_combo_box_set_active (GTK_COMBO_BOX (combo), active);
@@ -1451,6 +1479,7 @@ advanced_dialog_new_hash_from_dialog (GtkWidget *dialog, GError **error)
 	GladeXML *xml;
 	const char *contype = NULL;
 	const char *value;
+	int proxy_type = PROXY_TYPE_NONE;
 
 	g_return_val_if_fail (dialog != NULL, NULL);
 	if (error)
@@ -1497,42 +1526,49 @@ advanced_dialog_new_hash_from_dialog (GtkWidget *dialog, GError **error)
 		g_hash_table_insert (hash, g_strdup (NM_OPENVPN_KEY_PORT), g_strdup_printf ("%d", port));
 	}
 
-	/* HTTP proxy support */
+	/* Proxy support */
 	widget = glade_xml_get_widget (xml, "proxy_type_combo");
-	if (gtk_combo_box_get_active (GTK_COMBO_BOX (widget)) == PROXY_TYPE_HTTP) {
+	proxy_type = gtk_combo_box_get_active (GTK_COMBO_BOX (widget));
+	if (proxy_type != PROXY_TYPE_NONE) {
 		widget = glade_xml_get_widget (xml, "proxy_server_entry");
 		value = (char *) gtk_entry_get_text (GTK_ENTRY (widget));
-
 		if (value && strlen (value)) {
 			int proxy_port;
 
-			g_hash_table_insert (hash, g_strdup (NM_OPENVPN_KEY_HTTP_PROXY), g_strdup (value));
+			if (proxy_type == PROXY_TYPE_HTTP)
+				g_hash_table_insert (hash, g_strdup (NM_OPENVPN_KEY_PROXY_TYPE), g_strdup ("http"));
+			else if (proxy_type == PROXY_TYPE_SOCKS)
+				g_hash_table_insert (hash, g_strdup (NM_OPENVPN_KEY_PROXY_TYPE), g_strdup ("socks"));
+
+			g_hash_table_insert (hash, g_strdup (NM_OPENVPN_KEY_PROXY_SERVER), g_strdup (value));
 
 			widget = glade_xml_get_widget (xml, "proxy_port_spinbutton");
 			proxy_port = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget));
-			if (!proxy_port)
-				proxy_port = 8080;
-			g_hash_table_insert (hash, g_strdup (NM_OPENVPN_KEY_HTTP_PROXY_PORT),
-			                     g_strdup_printf ("%d", proxy_port));
+			if (proxy_port > 0) {
+				g_hash_table_insert (hash, g_strdup (NM_OPENVPN_KEY_PROXY_PORT),
+				                     g_strdup_printf ("%d", proxy_port));
+			}
 
 			widget = glade_xml_get_widget (xml, "proxy_retry_checkbutton");
 			if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
-				g_hash_table_insert (hash, g_strdup (NM_OPENVPN_KEY_HTTP_PROXY_RETRY), g_strdup ("yes"));
-
-			widget = glade_xml_get_widget (xml, "proxy_username_entry");
-			value = (char *) gtk_entry_get_text (GTK_ENTRY (widget));
-			if (value && strlen (value)) {
-				g_hash_table_insert (hash,
-				                     g_strdup (NM_OPENVPN_KEY_HTTP_PROXY_USERNAME),
-				                     g_strdup (value));
-			}
+				g_hash_table_insert (hash, g_strdup (NM_OPENVPN_KEY_PROXY_RETRY), g_strdup ("yes"));
+
+			if (proxy_type == PROXY_TYPE_HTTP) {
+				widget = glade_xml_get_widget (xml, "proxy_username_entry");
+				value = (char *) gtk_entry_get_text (GTK_ENTRY (widget));
+				if (value && strlen (value)) {
+					g_hash_table_insert (hash,
+					                     g_strdup (NM_OPENVPN_KEY_HTTP_PROXY_USERNAME),
+					                     g_strdup (value));
+				}
 
-			widget = glade_xml_get_widget (xml, "proxy_password_entry");
-			value = (char *) gtk_entry_get_text (GTK_ENTRY (widget));
-			if (value && strlen (value)) {
-				g_hash_table_insert (hash,
-				                     g_strdup (NM_OPENVPN_KEY_HTTP_PROXY_PASSWORD),
-				                     g_strdup (value));
+				widget = glade_xml_get_widget (xml, "proxy_password_entry");
+				value = (char *) gtk_entry_get_text (GTK_ENTRY (widget));
+				if (value && strlen (value)) {
+					g_hash_table_insert (hash,
+					                     g_strdup (NM_OPENVPN_KEY_HTTP_PROXY_PASSWORD),
+					                     g_strdup (value));
+				}
 			}
 		}
 	}
diff --git a/properties/import-export.c b/properties/import-export.c
index 31186bd..0424995 100644
--- a/properties/import-export.c
+++ b/properties/import-export.c
@@ -58,8 +58,10 @@
 #define PKCS12_TAG "pkcs12 "
 #define PORT_TAG "port "
 #define PROTO_TAG "proto "
-#define PROXY_TAG "http-proxy "
-#define PROXY_RETRY_TAG "http-proxy-retry"
+#define HTTP_PROXY_TAG "http-proxy "
+#define HTTP_PROXY_RETRY_TAG "http-proxy-retry"
+#define SOCKS_PROXY_TAG "socks-proxy "
+#define SOCKS_PROXY_RETRY_TAG "socks-proxy-retry"
 #define REMOTE_TAG "remote "
 #define RENEG_SEC_TAG "reneg-sec "
 #define RPORT_TAG "rport "
@@ -252,6 +254,7 @@ do_import (const char *path, char **lines, GError **error)
 	const char *ctype = NULL;
 	char *basename;
 	char *default_path, *tmp, *tmp2;
+	gboolean http_proxy = FALSE, socks_proxy = FALSE, proxy_set = FALSE;
 
 	connection = nm_connection_new ();
 	s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ());
@@ -281,7 +284,7 @@ do_import (const char *path, char **lines, GError **error)
 	g_free (basename);
 
 	for (line = lines; *line; line++) {
-		char *comment, **items, *leftover = NULL;
+		char *comment, **items = NULL, *leftover = NULL;
 
 		if ((comment = strchr (*line, '#')))
 			*comment = '\0';
@@ -389,17 +392,23 @@ do_import (const char *path, char **lines, GError **error)
 			continue;
 		}
 
-		if (!strncmp (*line, PROXY_RETRY_TAG, strlen (PROXY_RETRY_TAG))) {
+		if (   !strncmp (*line, HTTP_PROXY_RETRY_TAG, strlen (HTTP_PROXY_RETRY_TAG))
+		    || !strncmp (*line, SOCKS_PROXY_RETRY_TAG, strlen (SOCKS_PROXY_RETRY_TAG))) {
 			nm_setting_vpn_add_data_item (s_vpn,
-			                              g_strdup (NM_OPENVPN_KEY_HTTP_PROXY_RETRY),
+			                              g_strdup (NM_OPENVPN_KEY_PROXY_RETRY),
 			                              g_strdup ("yes"));
 			continue;
 		}
 
-		if (!strncmp (*line, PROXY_TAG, strlen (PROXY_TAG))) {
+		http_proxy = g_str_has_prefix (*line, HTTP_PROXY_TAG);
+		socks_proxy = g_str_has_prefix (*line, SOCKS_PROXY_TAG);
+		if ((http_proxy || socks_proxy) && !proxy_set) {
 			gboolean success = FALSE;
 
-			items = get_args (*line + strlen (PROXY_TAG));
+			if (http_proxy)
+				items = get_args (*line + strlen (HTTP_PROXY_TAG));
+			else if (socks_proxy)
+				items = get_args (*line + strlen (SOCKS_PROXY_TAG));
 			if (!items)
 				continue;
 
@@ -408,8 +417,10 @@ do_import (const char *path, char **lines, GError **error)
 				char *s_port = NULL;
 				char *user = NULL, *pass = NULL;
 
-				if (g_strv_length (items) >= 3)
+				if (http_proxy && g_strv_length (items) >= 3)
 					success = parse_http_proxy_auth (items[2], &user, &pass);
+				else if (socks_proxy)
+					success = TRUE;
 
 				if (success) {
 					success = FALSE;
@@ -422,12 +433,13 @@ do_import (const char *path, char **lines, GError **error)
 				}
 
 				if (success) {
-					nm_setting_vpn_add_data_item (s_vpn, NM_OPENVPN_KEY_HTTP_PROXY, items[0]);
-					nm_setting_vpn_add_data_item (s_vpn, NM_OPENVPN_KEY_HTTP_PROXY_PORT, s_port);
+					nm_setting_vpn_add_data_item (s_vpn, NM_OPENVPN_KEY_PROXY_SERVER, items[0]);
+					nm_setting_vpn_add_data_item (s_vpn, NM_OPENVPN_KEY_PROXY_PORT, s_port);
 					if (user)
 						nm_setting_vpn_add_data_item (s_vpn, NM_OPENVPN_KEY_HTTP_PROXY_USERNAME, user);
 					if (pass)
 						nm_setting_vpn_add_secret (s_vpn, NM_OPENVPN_KEY_HTTP_PROXY_PASSWORD, pass);
+					proxy_set = TRUE;
 				}
 				g_free (s_port);
 				g_free (user);
diff --git a/properties/nm-openvpn-dialog.glade b/properties/nm-openvpn-dialog.glade
index af4c9dc..78cc383 100644
--- a/properties/nm-openvpn-dialog.glade
+++ b/properties/nm-openvpn-dialog.glade
@@ -1497,7 +1497,7 @@ Example: /CN=myvpn.company.com&lt;/i&gt;</property>
                                 <property name="can_focus">True</property>
                                 <property name="invisible_char">&#x25CF;</property>
                                 <property name="width_chars">5</property>
-                                <property name="adjustment">8080 1 65535 1 10 0</property>
+                                <property name="adjustment">0 0 65535 1 10 0</property>
                                 <property name="climb_rate">1</property>
                                 <property name="numeric">True</property>
                               </widget>
diff --git a/src/nm-openvpn-service.c b/src/nm-openvpn-service.c
index 2e27a82..73e5062 100644
--- a/src/nm-openvpn-service.c
+++ b/src/nm-openvpn-service.c
@@ -104,9 +104,10 @@ static ValidProperty valid_properties[] = {
 	{ NM_OPENVPN_KEY_MSSFIX,               G_TYPE_BOOLEAN, 0, 0, FALSE },
 	{ NM_OPENVPN_KEY_PROTO_TCP,            G_TYPE_BOOLEAN, 0, 0, FALSE },
 	{ NM_OPENVPN_KEY_PORT,                 G_TYPE_INT, 1, 65535, FALSE },
-	{ NM_OPENVPN_KEY_HTTP_PROXY,           G_TYPE_STRING, 0, 0, FALSE },
-	{ NM_OPENVPN_KEY_HTTP_PROXY_PORT,      G_TYPE_INT, 1, 65535, FALSE },
-	{ NM_OPENVPN_KEY_HTTP_PROXY_RETRY,     G_TYPE_BOOLEAN, 0, 0, FALSE },
+	{ NM_OPENVPN_KEY_PROXY_TYPE,           G_TYPE_STRING, 0, 0, FALSE },
+	{ NM_OPENVPN_KEY_PROXY_SERVER,         G_TYPE_STRING, 0, 0, FALSE },
+	{ NM_OPENVPN_KEY_PROXY_PORT,           G_TYPE_INT, 1, 65535, FALSE },
+	{ NM_OPENVPN_KEY_PROXY_RETRY,          G_TYPE_BOOLEAN, 0, 0, FALSE },
 	{ NM_OPENVPN_KEY_HTTP_PROXY_USERNAME,  G_TYPE_STRING, 0, 0, FALSE },
 	{ NM_OPENVPN_KEY_REMOTE,               G_TYPE_STRING, 0, 0, FALSE },
 	{ NM_OPENVPN_KEY_REMOTE_IP,            G_TYPE_STRING, 0, 0, TRUE },
@@ -720,7 +721,7 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
                                  GError **error)
 {
 	NMOpenvpnPluginPrivate *priv = NM_OPENVPN_PLUGIN_GET_PRIVATE (plugin);
-	const char *openvpn_binary, *auth, *connection_type, *tmp, *tmp2;
+	const char *openvpn_binary, *auth, *connection_type, *tmp, *tmp2, *tmp3, *tmp4;
 	GPtrArray *args;
 	GSource *openvpn_watch;
 	GPid pid;
@@ -768,19 +769,36 @@ nm_openvpn_start_openvpn_binary (NMOpenvpnPlugin *plugin,
 		add_openvpn_arg (args, tmp);
 	}
 
-	tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_HTTP_PROXY);
-	tmp2 = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_HTTP_PROXY_PORT);
+	tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_PROXY_TYPE);
+	tmp2 = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_PROXY_SERVER);
+	tmp3 = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_PROXY_PORT);
+	tmp4 = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_PROXY_RETRY);
 	if (tmp && strlen (tmp) && tmp2 && strlen (tmp2)) {
-		add_openvpn_arg (args, "--http-proxy");
-		add_openvpn_arg (args, tmp);
-		add_openvpn_arg (args, tmp2);
-		add_openvpn_arg (args, "'auto'");  /* Automatic proxy auth method detection */
+		if (!strcmp (tmp, "http")) {
+			add_openvpn_arg (args, "--http-proxy");
+			add_openvpn_arg (args, tmp2);
+			if (tmp3 && strlen (tmp3))
+				add_openvpn_arg (args, tmp3);
+			add_openvpn_arg (args, "'auto'");  /* Automatic proxy auth method detection */
+			if (tmp4)
+				add_openvpn_arg (args, "--http-proxy-retry");
+		} else if (!strcmp (tmp, "socks")) {
+			add_openvpn_arg (args, "--socks-proxy");
+			add_openvpn_arg (args, tmp2);
+			if (tmp3 && strlen (tmp3))
+				add_openvpn_arg (args, tmp3);
+			if (tmp4)
+				add_openvpn_arg (args, "--socks-proxy-retry");
+		} else {
+			g_set_error (error,
+				         NM_VPN_PLUGIN_ERROR,
+				         NM_VPN_PLUGIN_ERROR_BAD_ARGUMENTS,
+				         "Invalid proxy type '%s'.",
+				         tmp);
+			return FALSE;
+		}
 	}
 
-	tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_HTTP_PROXY_RETRY);
-	if (tmp && strlen (tmp))
-		add_openvpn_arg (args, "--http-proxy-retry");
-
 	tmp = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_COMP_LZO);
 	if (tmp && !strcmp (tmp, "yes"))
 		add_openvpn_arg (args, "--comp-lzo");
diff --git a/src/nm-openvpn-service.h b/src/nm-openvpn-service.h
index c8a7619..d503f4e 100644
--- a/src/nm-openvpn-service.h
+++ b/src/nm-openvpn-service.h
@@ -50,9 +50,10 @@
 #define NM_OPENVPN_KEY_MSSFIX "mssfix"
 #define NM_OPENVPN_KEY_PORT "port"
 #define NM_OPENVPN_KEY_PROTO_TCP "proto-tcp"
-#define NM_OPENVPN_KEY_HTTP_PROXY "http-proxy"
-#define NM_OPENVPN_KEY_HTTP_PROXY_PORT "http-proxy-port"
-#define NM_OPENVPN_KEY_HTTP_PROXY_RETRY "http-proxy-retry"
+#define NM_OPENVPN_KEY_PROXY_TYPE "proxy-type"
+#define NM_OPENVPN_KEY_PROXY_SERVER "proxy-server"
+#define NM_OPENVPN_KEY_PROXY_PORT "proxy-port"
+#define NM_OPENVPN_KEY_PROXY_RETRY "proxy-retry"
 #define NM_OPENVPN_KEY_HTTP_PROXY_USERNAME "http-proxy-username"
 #define NM_OPENVPN_KEY_REMOTE "remote"
 #define NM_OPENVPN_KEY_REMOTE_IP "remote-ip"



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