[network-manager-openvpn] properties: export HTTP proxy authfile too
- From: Dan Williams <dcbw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-openvpn] properties: export HTTP proxy authfile too
- Date: Wed, 6 Apr 2011 04:00:56 +0000 (UTC)
commit 37734e85a4b145e716259e666f26492be08ddfea
Author: Dan Williams <dcbw redhat com>
Date: Tue Apr 5 22:59:43 2011 -0500
properties: export HTTP proxy authfile too
Fixes distcheck now that we have secret flags, since when imported
the connection will have secret flags set for the HTTP proxy
password, but previously since the authfile wasn't written out,
the re-imported connection wouldn't get the secrets flags and
the connection compare in the testcase would fail.
properties/import-export.c | 31 ++++++++++++++++++++++++++++++-
properties/tests/test-import-export.c | 19 ++++++-------------
2 files changed, 36 insertions(+), 14 deletions(-)
---
diff --git a/properties/import-export.c b/properties/import-export.c
index 8802877..8a451cf 100644
--- a/properties/import-export.c
+++ b/properties/import-export.c
@@ -738,6 +738,8 @@ do_export (const char *path, NMConnection *connection, GError **error)
const char *proxy_server = NULL;
const char *proxy_port = NULL;
const char *proxy_retry = NULL;
+ const char *proxy_username = NULL;
+ const char *proxy_password = NULL;
s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
g_assert (s_con);
@@ -922,12 +924,39 @@ do_export (const char *path, NMConnection *connection, GError **error)
proxy_server = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_PROXY_SERVER);
proxy_port = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_PROXY_PORT);
proxy_retry = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_PROXY_RETRY);
+ proxy_username = nm_setting_vpn_get_data_item (s_vpn, NM_OPENVPN_KEY_HTTP_PROXY_USERNAME);
+ proxy_password = nm_setting_vpn_get_secret (s_vpn, NM_OPENVPN_KEY_HTTP_PROXY_PASSWORD);
+
if (!strcmp (proxy_type, "http") && proxy_server && proxy_port) {
+ char *authfile, *authcontents, *base, *dirname;
+
if (!proxy_port)
proxy_port = "8080";
- fprintf (f, "http-proxy %s %s\n", proxy_server, proxy_port);
+
+ /* If there's a username, need to write an authfile */
+ base = g_path_get_basename (path);
+ dirname = g_path_get_dirname (path);
+ authfile = g_strdup_printf ("%s/%s-httpauthfile", dirname, base);
+ g_free (base);
+ g_free (dirname);
+
+ fprintf (f, "http-proxy %s %s%s%s\n",
+ proxy_server,
+ proxy_port,
+ proxy_username ? " " : "",
+ proxy_username ? authfile : "");
if (proxy_retry && !strcmp (proxy_retry, "yes"))
fprintf (f, "http-proxy-retry\n");
+
+ /* Write out the authfile */
+ if (proxy_username) {
+ authcontents = g_strdup_printf ("%s\n%s\n",
+ proxy_username,
+ proxy_password ? proxy_password : "");
+ g_file_set_contents (authfile, authcontents, -1, NULL);
+ g_free (authcontents);
+ }
+ g_free (authfile);
} else if (!strcmp (proxy_type, "socks") && proxy_server && proxy_port) {
if (!proxy_port)
proxy_port = "1080";
diff --git a/properties/tests/test-import-export.c b/properties/tests/test-import-export.c
index ae5b8ff..6188968 100644
--- a/properties/tests/test-import-export.c
+++ b/properties/tests/test-import-export.c
@@ -793,7 +793,6 @@ test_proxy_http_export (NMVpnPluginUiInterface *plugin, const char *dir, const c
char *path;
gboolean success;
GError *error = NULL;
- NMSettingVPN *s_vpn;
connection = get_basic_connection ("proxy-http-export", plugin, dir, "proxy-http.ovpn");
ASSERT (connection != NULL, "proxy-http-export", "failed to import connection");
@@ -810,25 +809,19 @@ test_proxy_http_export (NMVpnPluginUiInterface *plugin, const char *dir, const c
/* Now re-import it and compare the connections to ensure they are the same */
reimported = get_basic_connection ("proxy-http-export", plugin, tmpdir, PROXY_HTTP_EXPORTED_NAME);
(void) unlink (path);
+ g_free (path);
ASSERT (reimported != NULL, "proxy-http-export", "failed to re-import connection");
- /* Clear secrets first, since they don't get exported, and thus would
- * make the connection comparison below fail.
- */
- remove_secrets (connection);
-
- /* Also clear the HTTP Proxy username. We don't export that either since it
- * goes into a separate authfile.
- */
- s_vpn = NM_SETTING_VPN (nm_connection_get_setting (connection, NM_TYPE_SETTING_VPN));
- nm_setting_vpn_remove_data_item (s_vpn, NM_OPENVPN_KEY_HTTP_PROXY_USERNAME);
-
ASSERT (nm_connection_compare (connection, reimported, NM_SETTING_COMPARE_FLAG_EXACT) == TRUE,
"proxy-http-export", "original and reimported connection differ");
+ /* Unlink the proxy authfile */
+ path = g_strdup_printf ("%s/%s-httpauthfile", tmpdir, PROXY_HTTP_EXPORTED_NAME);
+ (void) unlink (path);
+ g_free (path);
+
g_object_unref (reimported);
g_object_unref (connection);
- g_free (path);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]