callouts/: 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 | 60 +++++++++++++++++++++++++++++++++++ 8 files changed, 152 insertions(+)
diff --git a/callouts/nm-dispatcher-utils.c b/callouts/nm-dispatcher-utils.c index 015bb07..b88e778 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,11 +371,13 @@ 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 *vpn_ip_iface, + GVariant *vpn_proxy_props, GVariant *vpn_ip4_props, GVariant *vpn_ip6_props, char **out_iface, @@ -440,6 +490,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); @@ -448,6 +499,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 40a0d41..024e9f1 100644 --- a/callouts/nm-dispatcher-utils.h +++ b/callouts/nm-dispatcher-utils.h @@ -28,11 +28,13 @@ 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 *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 7ddffb0..eb9cdf9 100644 --- a/callouts/nm-dispatcher.c +++ b/callouts/nm-dispatcher.c @@ -76,11 +76,13 @@ 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 *vpn_ip_iface, + GVariant *vpn_proxy_props, GVariant *vpn_ip4_props, GVariant *vpn_ip6_props, gboolean request_debug, @@ -664,11 +666,13 @@ 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 *vpn_ip_iface, + GVariant *vpn_proxy_props, GVariant *vpn_ip4_props, GVariant *vpn_ip6_props, gboolean request_debug, @@ -695,11 +699,13 @@ 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, 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 83e84d7..cfdd986 100644 --- a/callouts/tests/test-dispatcher-envp.c +++ b/callouts/tests/test-dispatcher-envp.c @@ -192,6 +192,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; @@ -355,11 +396,13 @@ 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_vpn_ip_iface, + GVariant **out_vpn_proxy_props, GVariant **out_vpn_ip4_props, GVariant **out_vpn_ip6_props, char **out_expected_iface, @@ -375,11 +418,13 @@ 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_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); @@ -403,6 +448,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; @@ -447,11 +497,13 @@ test_generic (const char *file, const char *override_vpn_ip_iface) GVariant *con_dict = NULL; GVariant *con_props = NULL; GVariant *device_props = NULL; + GVariant *device_proxy_props = NULL; GVariant *device_ip4_props = NULL; GVariant *device_ip6_props = NULL; GVariant *device_dhcp4_props = NULL; GVariant *device_dhcp6_props = NULL; char *vpn_ip_iface = NULL; + GVariant *vpn_proxy_props = NULL; GVariant *vpn_ip4_props = NULL; GVariant *vpn_ip6_props = NULL; char *expected_iface = NULL; @@ -470,11 +522,13 @@ 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, &vpn_ip_iface, + &vpn_proxy_props, &vpn_ip4_props, &vpn_ip6_props, &expected_iface, @@ -490,11 +544,13 @@ 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, override_vpn_ip_iface ? override_vpn_ip_iface : vpn_ip_iface, + vpn_proxy_props, vpn_ip4_props, vpn_ip6_props, &out_iface, @@ -554,6 +610,8 @@ test_generic (const char *file, const char *override_vpn_ip_iface) g_variant_unref (con_dict); g_variant_unref (con_props); g_variant_unref (device_props); + if (device_proxy_props) + g_variant_unref (device_proxy_props); if (device_ip4_props) g_variant_unref (device_ip4_props); if (device_ip6_props) @@ -562,6 +620,8 @@ test_generic (const char *file, const char *override_vpn_ip_iface) g_variant_unref (device_dhcp4_props); if (device_dhcp6_props) g_variant_unref (device_dhcp6_props); + if (vpn_proxy_props) + g_variant_unref (vpn_proxy_props); if (vpn_ip4_props) g_variant_unref (vpn_ip4_props); if (vpn_ip6_props) -- 2.5.5 _______________________________________________ networkmanager-list mailing list networkmanager-list@gnome.org https://mail.gnome.org/mailman/listinfo/networkmanager-list