[PATCH v4 5/7] callouts: Fixes in Dispatcher to release Proxy env variables



Dispatcher Fixed to release env variables for proxy stuff. For VPNs
proxy variables have prefix "VPN_" as usual.
---
 callouts/nm-dispatcher-utils.c        | 52 ++++++++++++++++++++++++++++++++
 callouts/nm-dispatcher-utils.h        |  2 ++
 callouts/nm-dispatcher.c              |  6 ++++
 callouts/tests/dispatcher-external    |  8 +++++
 callouts/tests/dispatcher-up          |  8 +++++
 callouts/tests/dispatcher-vpn-down    |  8 +++++
 callouts/tests/dispatcher-vpn-up      |  8 +++++
 callouts/tests/test-dispatcher-envp.c | 56 +++++++++++++++++++++++++++++++++++
 8 files changed, 148 insertions(+)

diff --git a/callouts/nm-dispatcher-utils.c b/callouts/nm-dispatcher-utils.c
index 78ef8dd..3fdf800 100644
--- a/callouts/nm-dispatcher-utils.c
+++ b/callouts/nm-dispatcher-utils.c
@@ -101,6 +101,54 @@ add_domains (GSList *items,
 }
 
 static GSList *
+construct_proxy_items (GSList *items, GVariant *proxy_config, const char *prefix)
+{
+       GVariant *val;
+
+       if (proxy_config == NULL)
+               return items;
+
+       if (prefix == NULL)
+               prefix = "";
+
+       /* Proxies */
+       val = g_variant_lookup_value (proxy_config, "proxies", G_VARIANT_TYPE_STRING_ARRAY);
+       if (val) {
+               items = _list_append_val_strv (items, g_variant_dup_strv (val, NULL),
+                                              "%sPROXIES=", prefix);
+               g_variant_unref (val);
+       }
+
+       /* PAC Url */
+       val = g_variant_lookup_value (proxy_config, "pac-url", G_VARIANT_TYPE_STRING);
+       if (val) {
+               char *str;
+
+               str = g_strdup_printf ("%sPROXY_PAC_URL=%s",
+                                      prefix,
+                                      g_variant_get_string (val, NULL));
+
+               items = g_slist_prepend (items, str);
+               g_variant_unref (val);
+       }
+
+       /* PAC Script */
+       val = g_variant_lookup_value (proxy_config, "pac-script", G_VARIANT_TYPE_STRING);
+       if (val) {
+               char *str;
+
+               str = g_strdup_printf ("%sPROXY_PAC_SCRIPT=%s",
+                                      prefix,
+                                      g_variant_get_string (val, NULL));
+
+               items = g_slist_prepend (items, str);
+               g_variant_unref (val);
+       }
+
+       return items;
+}
+
+static GSList *
 construct_ip4_items (GSList *items, GVariant *ip4_config, const char *prefix)
 {
        GPtrArray *addresses, *routes;
@@ -323,12 +371,14 @@ nm_dispatcher_utils_construct_envp (const char *action,
                                     GVariant *connection_dict,
                                     GVariant *connection_props,
                                     GVariant *device_props,
+                                    GVariant *device_proxy_props,
                                     GVariant *device_ip4_props,
                                     GVariant *device_ip6_props,
                                     GVariant *device_dhcp4_props,
                                     GVariant *device_dhcp6_props,
                                     const char *connectivity_state,
                                     const char *vpn_ip_iface,
+                                    GVariant *vpn_proxy_props,
                                     GVariant *vpn_ip4_props,
                                     GVariant *vpn_ip6_props,
                                     char **out_iface,
@@ -443,6 +493,7 @@ nm_dispatcher_utils_construct_envp (const char *action,
 
        /* Device it's aren't valid if the device isn't activated */
        if (iface && (dev_state == NM_DEVICE_STATE_ACTIVATED)) {
+               items = construct_proxy_items (items, device_proxy_props, NULL);
                items = construct_ip4_items (items, device_ip4_props, NULL);
                items = construct_ip6_items (items, device_ip6_props, NULL);
                items = construct_device_dhcp4_items (items, device_dhcp4_props);
@@ -451,6 +502,7 @@ nm_dispatcher_utils_construct_envp (const char *action,
 
        if (vpn_ip_iface) {
                items = g_slist_prepend (items, g_strdup_printf ("VPN_IP_IFACE=%s", vpn_ip_iface));
+               items = construct_proxy_items (items, vpn_proxy_props, "VPN_");
                items = construct_ip4_items (items, vpn_ip4_props, "VPN_");
                items = construct_ip6_items (items, vpn_ip6_props, "VPN_");
        }
diff --git a/callouts/nm-dispatcher-utils.h b/callouts/nm-dispatcher-utils.h
index 034898e..3c0afe6 100644
--- a/callouts/nm-dispatcher-utils.h
+++ b/callouts/nm-dispatcher-utils.h
@@ -28,12 +28,14 @@ nm_dispatcher_utils_construct_envp (const char *action,
                                     GVariant *connection_dict,
                                     GVariant *connection_props,
                                     GVariant *device_props,
+                                    GVariant *device_proxy_props,
                                     GVariant *device_ip4_props,
                                     GVariant *device_ip6_props,
                                     GVariant *device_dhcp4_props,
                                     GVariant *device_dhcp6_props,
                                     const char *connectivity_state,
                                     const char *vpn_ip_iface,
+                                    GVariant *vpn_proxy_props,
                                     GVariant *vpn_ip4_props,
                                     GVariant *vpn_ip6_props,
                                     char **out_iface,
diff --git a/callouts/nm-dispatcher.c b/callouts/nm-dispatcher.c
index 94bd132..6bb5221 100644
--- a/callouts/nm-dispatcher.c
+++ b/callouts/nm-dispatcher.c
@@ -76,12 +76,14 @@ handle_action (NMDBusDispatcher *dbus_dispatcher,
                GVariant *connection_dict,
                GVariant *connection_props,
                GVariant *device_props,
+               GVariant *device_proxy_props,
                GVariant *device_ip4_props,
                GVariant *device_ip6_props,
                GVariant *device_dhcp4_props,
                GVariant *device_dhcp6_props,
                const char *connectivity_state,
                const char *vpn_ip_iface,
+               GVariant *vpn_proxy_props,
                GVariant *vpn_ip4_props,
                GVariant *vpn_ip6_props,
                gboolean request_debug,
@@ -665,12 +667,14 @@ handle_action (NMDBusDispatcher *dbus_dispatcher,
                GVariant *connection_dict,
                GVariant *connection_props,
                GVariant *device_props,
+               GVariant *device_proxy_props,
                GVariant *device_ip4_props,
                GVariant *device_ip6_props,
                GVariant *device_dhcp4_props,
                GVariant *device_dhcp6_props,
                const char *connectivity_state,
                const char *vpn_ip_iface,
+               GVariant *vpn_proxy_props,
                GVariant *vpn_ip4_props,
                GVariant *vpn_ip6_props,
                gboolean request_debug,
@@ -697,12 +701,14 @@ handle_action (NMDBusDispatcher *dbus_dispatcher,
                                                            connection_dict,
                                                            connection_props,
                                                            device_props,
+                                                           device_proxy_props,
                                                            device_ip4_props,
                                                            device_ip6_props,
                                                            device_dhcp4_props,
                                                            device_dhcp6_props,
                                                            connectivity_state,
                                                            vpn_ip_iface,
+                                                           vpn_proxy_props,
                                                            vpn_ip4_props,
                                                            vpn_ip6_props,
                                                            &request->iface,
diff --git a/callouts/tests/dispatcher-external b/callouts/tests/dispatcher-external
index 5430bec..2ff0c63 100644
--- a/callouts/tests/dispatcher-external
+++ b/callouts/tests/dispatcher-external
@@ -12,6 +12,11 @@ type=13
 interface=virbr0
 path=/org/freedesktop/NetworkManager/Devices/0
 
+[proxy]
+proxies=http://test.proxy.com https://sec.proxy.com
+pac-url=http://networkmanager.com/proxy.pac
+pac-script=path/to/script
+
 [ip4]
 addresses=192.168.122.1/24 0.0.0.0
 domains=
@@ -26,6 +31,9 @@ CONNECTION_ID=virbr0
 CONNECTION_EXTERNAL=1
 DEVICE_IFACE=virbr0
 DEVICE_IP_IFACE=virbr0
+PROXIES=http://test.proxy.com https://sec.proxy.com
+PROXY_PAC_URL=http://networkmanager.com/proxy.pac
+PROXY_PAC_SCRIPT=path/to/script
 IP4_NUM_ADDRESSES=1
 IP4_ADDRESS_0=192.168.122.1/24 0.0.0.0
 IP4_GATEWAY=0.0.0.0
diff --git a/callouts/tests/dispatcher-up b/callouts/tests/dispatcher-up
index 463409e..d3f9c29 100644
--- a/callouts/tests/dispatcher-up
+++ b/callouts/tests/dispatcher-up
@@ -25,6 +25,11 @@ broadcast_address=192.168.1.255
 subnet_mask=255.255.255.0
 expiry=1304300446
 
+[proxy]
+proxies=http://test.proxy.com https://sec.proxy.com
+pac-url=http://networkmanager.com/proxy.pac
+pac-script=path/to/script
+
 [ip4]
 addresses=192.168.1.119/24 192.168.1.1
 nameservers=68.87.77.134 68.87.72.134 192.168.1.1
@@ -38,6 +43,9 @@ CONNECTION_ID=Random Connection
 CONNECTION_FILENAME=/callouts/tests/dispatcher-up
 DEVICE_IFACE=wlan0
 DEVICE_IP_IFACE=wlan0
+PROXIES=http://test.proxy.com https://sec.proxy.com
+PROXY_PAC_URL=http://networkmanager.com/proxy.pac
+PROXY_PAC_SCRIPT=path/to/script
 IP4_ADDRESS_0=192.168.1.119/24 192.168.1.1
 IP4_NUM_ADDRESSES=1
 IP4_NAMESERVERS=68.87.77.134 68.87.72.134 192.168.1.1
diff --git a/callouts/tests/dispatcher-vpn-down b/callouts/tests/dispatcher-vpn-down
index 18267f8..5f5823b 100644
--- a/callouts/tests/dispatcher-vpn-down
+++ b/callouts/tests/dispatcher-vpn-down
@@ -25,6 +25,11 @@ broadcast_address=192.168.1.255
 subnet_mask=255.255.255.0
 expiry=1304349405
 
+[proxy]
+proxies=http://test.proxy.com https://sec.proxy.com
+pac-url=http://networkmanager.com/proxy.pac
+pac-script=path/to/script
+
 [ip4]
 addresses=192.168.1.119/24 192.168.1.1
 nameservers=68.87.77.134 68.87.72.134 192.168.1.1
@@ -38,6 +43,9 @@ CONNECTION_ID=Random Connection
 CONNECTION_FILENAME=/callouts/tests/dispatcher-vpn-down
 DEVICE_IFACE=wlan0
 DEVICE_IP_IFACE=tun0
+PROXIES=http://test.proxy.com https://sec.proxy.com
+PROXY_PAC_URL=http://networkmanager.com/proxy.pac
+PROXY_PAC_SCRIPT=path/to/script
 IP4_ADDRESS_0=192.168.1.119/24 192.168.1.1
 IP4_NUM_ADDRESSES=1
 IP4_NAMESERVERS=68.87.77.134 68.87.72.134 192.168.1.1
diff --git a/callouts/tests/dispatcher-vpn-up b/callouts/tests/dispatcher-vpn-up
index 181ecb5..fc2518c 100644
--- a/callouts/tests/dispatcher-vpn-up
+++ b/callouts/tests/dispatcher-vpn-up
@@ -25,6 +25,11 @@ broadcast_address=192.168.1.255
 subnet_mask=255.255.255.0
 expiry=1304349405
 
+[proxy]
+proxies=http://test.proxy.com https://sec.proxy.com
+pac-url=http://networkmanager.com/proxy.pac
+pac-script=path/to/script
+
 [ip4]
 addresses=192.168.1.119/24 192.168.1.1
 nameservers=68.87.77.134 68.87.72.134 192.168.1.1
@@ -38,6 +43,9 @@ CONNECTION_ID=Random Connection
 CONNECTION_FILENAME=/callouts/tests/dispatcher-vpn-up
 DEVICE_IFACE=wlan0
 DEVICE_IP_IFACE=tun0
+PROXIES=http://test.proxy.com https://sec.proxy.com
+PROXY_PAC_URL=http://networkmanager.com/proxy.pac
+PROXY_PAC_SCRIPT=path/to/script
 IP4_ADDRESS_0=192.168.1.119/24 192.168.1.1
 IP4_NUM_ADDRESSES=1
 IP4_NAMESERVERS=68.87.77.134 68.87.72.134 192.168.1.1
diff --git a/callouts/tests/test-dispatcher-envp.c b/callouts/tests/test-dispatcher-envp.c
index 8636f09..6c565ff 100644
--- a/callouts/tests/test-dispatcher-envp.c
+++ b/callouts/tests/test-dispatcher-envp.c
@@ -194,6 +194,47 @@ add_uint_array (GKeyFile *kf,
 }
 
 static gboolean
+parse_proxy (GKeyFile *kf, GVariant **out_props, const char *section, GError **error)
+{
+       GVariantBuilder props;
+       char *tmp;
+       char **split, **iter;
+
+       g_variant_builder_init (&props, G_VARIANT_TYPE ("a{sv}"));
+
+       tmp = g_key_file_get_string (kf, section, "proxies", error);
+       if (tmp == NULL)
+               return FALSE;
+       split = g_strsplit_set (tmp, " ", -1);
+       g_free (tmp);
+
+       if (split && g_strv_length (split) > 0) {
+               for (iter = split; iter && *iter; iter++)
+                       g_strstrip (*iter);
+               g_variant_builder_add (&props, "{sv}", "proxies", g_variant_new_strv ((gpointer) split, -1));
+       }
+       g_strfreev (split);
+
+       tmp = g_key_file_get_string (kf, section, "pac-url", error);
+       if (tmp == NULL)
+               return FALSE;
+       g_variant_builder_add (&props, "{sv}",
+                              "pac-url",
+                              g_variant_new_string (tmp));
+       g_free (tmp);
+
+       tmp = g_key_file_get_string (kf, section, "pac-script", error);
+       if (tmp == NULL)
+               return FALSE;
+       g_variant_builder_add (&props, "{sv}",
+                              "pac-script",
+                              g_variant_new_string (tmp));
+       g_free (tmp);
+       *out_props = g_variant_builder_end (&props);
+       return TRUE;
+}
+
+static gboolean
 parse_ip4 (GKeyFile *kf, GVariant **out_props, const char *section, GError **error)
 {
        GVariantBuilder props;
@@ -357,12 +398,14 @@ get_dispatcher_file (const char *file,
                      GVariant **out_con_dict,
                      GVariant **out_con_props,
                      GVariant **out_device_props,
+                     GVariant **out_device_proxy_props,
                      GVariant **out_device_ip4_props,
                      GVariant **out_device_ip6_props,
                      GVariant **out_device_dhcp4_props,
                      GVariant **out_device_dhcp6_props,
                      char **out_connectivity_state,
                      char **out_vpn_ip_iface,
+                     GVariant **out_vpn_proxy_props,
                      GVariant **out_vpn_ip4_props,
                      GVariant **out_vpn_ip6_props,
                      char **out_expected_iface,
@@ -378,12 +421,14 @@ get_dispatcher_file (const char *file,
        g_assert (out_con_dict && !*out_con_dict);
        g_assert (out_con_props && !*out_con_props);
        g_assert (out_device_props && !*out_device_props);
+       g_assert (out_device_proxy_props && !*out_device_proxy_props);
        g_assert (out_device_ip4_props && !*out_device_ip4_props);
        g_assert (out_device_ip6_props && !*out_device_ip6_props);
        g_assert (out_device_dhcp4_props && !*out_device_dhcp4_props);
        g_assert (out_device_dhcp6_props && !*out_device_dhcp6_props);
        g_assert (out_connectivity_state && !*out_connectivity_state);
        g_assert (out_vpn_ip_iface && !*out_vpn_ip_iface);
+       g_assert (out_vpn_proxy_props && !*out_vpn_proxy_props);
        g_assert (out_vpn_ip4_props && !*out_vpn_ip4_props);
        g_assert (out_vpn_ip6_props && !*out_vpn_ip6_props);
        g_assert (out_expected_iface && !*out_expected_iface);
@@ -408,6 +453,11 @@ get_dispatcher_file (const char *file,
        if (!parse_device (kf, out_device_props, error))
                goto out;
 
+       if (g_key_file_has_group (kf, "proxy")) {
+               if (!parse_proxy (kf, out_device_proxy_props, "proxy", error))
+                       goto out;
+       }
+
        if (g_key_file_has_group (kf, "ip4")) {
                if (!parse_ip4 (kf, out_device_ip4_props, "ip4", error))
                        goto out;
@@ -452,12 +502,14 @@ test_generic (const char *file, const char *override_vpn_ip_iface)
        gs_unref_variant GVariant *con_dict = NULL;
        gs_unref_variant GVariant *con_props = NULL;
        gs_unref_variant GVariant *device_props = NULL;
+       gs_unref_variant GVariant *device_proxy_props = NULL;
        gs_unref_variant GVariant *device_ip4_props = NULL;
        gs_unref_variant GVariant *device_ip6_props = NULL;
        gs_unref_variant GVariant *device_dhcp4_props = NULL;
        gs_unref_variant GVariant *device_dhcp6_props = NULL;
        gs_free char *connectivity_change = NULL;
        gs_free char *vpn_ip_iface = NULL;
+       gs_unref_variant GVariant *vpn_proxy_props = NULL;
        gs_unref_variant GVariant *vpn_ip4_props = NULL;
        gs_unref_variant GVariant *vpn_ip6_props = NULL;
        gs_free char *expected_iface = NULL;
@@ -477,12 +529,14 @@ test_generic (const char *file, const char *override_vpn_ip_iface)
                                       &con_dict,
                                       &con_props,
                                       &device_props,
+                                      &device_proxy_props,
                                       &device_ip4_props,
                                       &device_ip6_props,
                                       &device_dhcp4_props,
                                       &device_dhcp6_props,
                                       &connectivity_change,
                                       &vpn_ip_iface,
+                                      &vpn_proxy_props,
                                       &vpn_ip4_props,
                                       &vpn_ip6_props,
                                       &expected_iface,
@@ -498,12 +552,14 @@ test_generic (const char *file, const char *override_vpn_ip_iface)
                                                   con_dict,
                                                   con_props,
                                                   device_props,
+                                                  device_proxy_props,
                                                   device_ip4_props,
                                                   device_ip6_props,
                                                   device_dhcp4_props,
                                                   device_dhcp6_props,
                                                   connectivity_change,
                                                   override_vpn_ip_iface ? override_vpn_ip_iface : 
vpn_ip_iface,
+                                                  vpn_proxy_props,
                                                   vpn_ip4_props,
                                                   vpn_ip6_props,
                                                   &out_iface,
-- 
2.5.5



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