2011-05-03 03:38:51 +00:00
|
|
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
|
|
|
/* NetworkManager -- Network link manager
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 - 2011 Red Hat, Inc.
|
|
|
|
*/
|
|
|
|
|
2016-02-19 13:57:48 +00:00
|
|
|
#include "nm-default.h"
|
2014-11-13 15:07:02 +00:00
|
|
|
|
2011-05-03 03:38:51 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2016-02-19 13:57:48 +00:00
|
|
|
#include "nm-dbus-interface.h"
|
|
|
|
#include "nm-connection.h"
|
|
|
|
#include "nm-setting-ip4-config.h"
|
|
|
|
#include "nm-setting-ip6-config.h"
|
|
|
|
#include "nm-setting-connection.h"
|
2011-05-03 03:38:51 +00:00
|
|
|
|
2014-05-14 19:51:43 +00:00
|
|
|
#include "nm-dispatcher-api.h"
|
2011-05-03 03:38:51 +00:00
|
|
|
#include "nm-utils.h"
|
|
|
|
|
|
|
|
#include "nm-dispatcher-utils.h"
|
|
|
|
|
|
|
|
static GSList *
|
|
|
|
construct_basic_items (GSList *list,
|
|
|
|
const char *uuid,
|
|
|
|
const char *id,
|
|
|
|
const char *iface,
|
|
|
|
const char *ip_iface)
|
|
|
|
{
|
|
|
|
if (uuid)
|
|
|
|
list = g_slist_prepend (list, g_strdup_printf ("CONNECTION_UUID=%s", uuid));
|
|
|
|
if (id)
|
|
|
|
list = g_slist_prepend (list, g_strdup_printf ("CONNECTION_ID=%s", id));
|
|
|
|
if (iface)
|
|
|
|
list = g_slist_prepend (list, g_strdup_printf ("DEVICE_IFACE=%s", iface));
|
|
|
|
if (ip_iface)
|
|
|
|
list = g_slist_prepend (list, g_strdup_printf ("DEVICE_IP_IFACE=%s", ip_iface));
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2014-12-05 12:45:19 +00:00
|
|
|
static GSList *_list_append_val_strv (GSList *items, char **values, const char *format, ...) G_GNUC_PRINTF(3, 4);
|
|
|
|
|
|
|
|
static GSList *
|
|
|
|
_list_append_val_strv (GSList *items, char **values, const char *format, ...)
|
|
|
|
{
|
|
|
|
if (!values)
|
|
|
|
g_return_val_if_reached (items);
|
|
|
|
|
|
|
|
/* Only add an item if the list of @values is not empty */
|
|
|
|
if (values[0]) {
|
|
|
|
va_list args;
|
|
|
|
guint i;
|
|
|
|
GString *str = g_string_new (NULL);
|
|
|
|
|
|
|
|
va_start (args, format);
|
|
|
|
g_string_append_vprintf (str, format, args);
|
|
|
|
va_end (args);
|
|
|
|
|
|
|
|
g_string_append (str, values[0]);
|
|
|
|
for (i = 1; values[i]; i++) {
|
|
|
|
g_string_append_c (str, ' ');
|
|
|
|
g_string_append (str, values[i]);
|
|
|
|
}
|
|
|
|
items = g_slist_prepend (items, g_string_free (str, FALSE));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we take ownership of the values array and free it. */
|
|
|
|
g_strfreev (values);
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
|
2011-05-03 03:38:51 +00:00
|
|
|
static GSList *
|
|
|
|
add_domains (GSList *items,
|
2014-09-03 16:27:33 +00:00
|
|
|
GVariant *dict,
|
2011-05-03 03:38:51 +00:00
|
|
|
const char *prefix,
|
|
|
|
const char four_or_six)
|
|
|
|
{
|
2014-09-03 16:27:33 +00:00
|
|
|
GVariant *val;
|
2011-05-03 03:38:51 +00:00
|
|
|
|
|
|
|
/* Search domains */
|
2014-09-03 16:27:33 +00:00
|
|
|
val = g_variant_lookup_value (dict, "domains", G_VARIANT_TYPE_STRING_ARRAY);
|
2014-12-05 12:45:19 +00:00
|
|
|
if (val) {
|
|
|
|
items = _list_append_val_strv (items, g_variant_dup_strv (val, NULL),
|
|
|
|
"%sIP%c_DOMAINS=", prefix, four_or_six);
|
|
|
|
g_variant_unref (val);
|
2011-05-03 03:38:51 +00:00
|
|
|
}
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
|
2016-08-16 00:25:59 +00:00
|
|
|
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 = "";
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
|
2011-05-03 03:38:51 +00:00
|
|
|
static GSList *
|
2014-09-03 16:27:33 +00:00
|
|
|
construct_ip4_items (GSList *items, GVariant *ip4_config, const char *prefix)
|
2011-05-03 03:38:51 +00:00
|
|
|
{
|
2014-09-03 16:27:33 +00:00
|
|
|
GPtrArray *addresses, *routes;
|
2014-12-05 12:45:19 +00:00
|
|
|
char *gateway;
|
2014-09-03 16:27:33 +00:00
|
|
|
GVariant *val;
|
|
|
|
int i;
|
2011-05-03 03:38:51 +00:00
|
|
|
|
|
|
|
if (ip4_config == NULL)
|
|
|
|
return items;
|
|
|
|
|
|
|
|
if (prefix == NULL)
|
|
|
|
prefix = "";
|
|
|
|
|
|
|
|
/* IP addresses */
|
2014-09-03 16:27:33 +00:00
|
|
|
val = g_variant_lookup_value (ip4_config, "addresses", G_VARIANT_TYPE ("aau"));
|
2014-09-03 16:23:45 +00:00
|
|
|
if (val) {
|
2014-10-21 01:30:56 +00:00
|
|
|
addresses = nm_utils_ip4_addresses_from_variant (val, &gateway);
|
|
|
|
if (!gateway)
|
|
|
|
gateway = g_strdup ("0.0.0.0");
|
2011-05-03 03:38:51 +00:00
|
|
|
|
2014-09-03 16:27:33 +00:00
|
|
|
for (i = 0; i < addresses->len; i++) {
|
2014-09-16 20:42:46 +00:00
|
|
|
NMIPAddress *addr = addresses->pdata[i];
|
2014-09-03 16:23:45 +00:00
|
|
|
char *addrtmp;
|
2011-05-03 03:38:51 +00:00
|
|
|
|
2014-09-16 20:42:46 +00:00
|
|
|
addrtmp = g_strdup_printf ("%sIP4_ADDRESS_%d=%s/%d %s", prefix, i,
|
|
|
|
nm_ip_address_get_address (addr),
|
|
|
|
nm_ip_address_get_prefix (addr),
|
2014-10-21 01:30:56 +00:00
|
|
|
gateway);
|
2014-09-03 16:23:45 +00:00
|
|
|
items = g_slist_prepend (items, addrtmp);
|
|
|
|
}
|
2014-09-03 16:27:33 +00:00
|
|
|
if (addresses->len)
|
|
|
|
items = g_slist_prepend (items, g_strdup_printf ("%sIP4_NUM_ADDRESSES=%d", prefix, addresses->len));
|
2014-11-19 12:03:38 +00:00
|
|
|
|
|
|
|
/* Write gateway to a separate variable, too. */
|
|
|
|
items = g_slist_prepend (items, g_strdup_printf ("%sIP4_GATEWAY=%s", prefix, gateway));
|
|
|
|
|
2014-09-03 16:27:33 +00:00
|
|
|
g_ptr_array_unref (addresses);
|
2014-10-21 01:30:56 +00:00
|
|
|
g_free (gateway);
|
2014-09-03 16:27:33 +00:00
|
|
|
g_variant_unref (val);
|
2014-09-03 16:23:45 +00:00
|
|
|
}
|
2011-05-03 03:38:51 +00:00
|
|
|
|
|
|
|
/* DNS servers */
|
2014-09-03 16:27:33 +00:00
|
|
|
val = g_variant_lookup_value (ip4_config, "nameservers", G_VARIANT_TYPE ("au"));
|
|
|
|
if (val) {
|
2014-12-05 12:45:19 +00:00
|
|
|
items = _list_append_val_strv (items, nm_utils_ip4_dns_from_variant (val),
|
|
|
|
"%sIP4_NAMESERVERS=", prefix);
|
2014-09-03 16:27:33 +00:00
|
|
|
g_variant_unref (val);
|
2011-05-03 03:38:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Search domains */
|
|
|
|
items = add_domains (items, ip4_config, prefix, '4');
|
|
|
|
|
|
|
|
/* WINS servers */
|
2014-09-03 16:27:33 +00:00
|
|
|
val = g_variant_lookup_value (ip4_config, "wins-servers", G_VARIANT_TYPE ("au"));
|
|
|
|
if (val) {
|
2014-12-05 12:45:19 +00:00
|
|
|
items = _list_append_val_strv (items, nm_utils_ip4_dns_from_variant (val),
|
|
|
|
"%sIP4_WINS_SERVERS=", prefix);
|
2014-09-03 16:27:33 +00:00
|
|
|
g_variant_unref (val);
|
2011-05-03 03:38:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Static routes */
|
2014-09-03 16:27:33 +00:00
|
|
|
val = g_variant_lookup_value (ip4_config, "routes", G_VARIANT_TYPE ("aau"));
|
2014-09-03 16:23:45 +00:00
|
|
|
if (val) {
|
2014-09-03 16:27:33 +00:00
|
|
|
routes = nm_utils_ip4_routes_from_variant (val);
|
2011-05-03 03:38:51 +00:00
|
|
|
|
2014-09-03 16:27:33 +00:00
|
|
|
for (i = 0; i < routes->len; i++) {
|
2014-09-16 20:42:46 +00:00
|
|
|
NMIPRoute *route = routes->pdata[i];
|
|
|
|
const char *next_hop;
|
2014-09-03 16:23:45 +00:00
|
|
|
char *routetmp;
|
2011-05-03 03:38:51 +00:00
|
|
|
|
2014-09-16 20:42:46 +00:00
|
|
|
next_hop = nm_ip_route_get_next_hop (route);
|
|
|
|
if (!next_hop)
|
|
|
|
next_hop = "0.0.0.0";
|
2011-05-03 03:38:51 +00:00
|
|
|
|
2014-11-04 20:48:48 +00:00
|
|
|
routetmp = g_strdup_printf ("%sIP4_ROUTE_%d=%s/%d %s %u", prefix, i,
|
2014-09-16 20:42:46 +00:00
|
|
|
nm_ip_route_get_dest (route),
|
|
|
|
nm_ip_route_get_prefix (route),
|
|
|
|
next_hop,
|
2014-11-04 20:48:48 +00:00
|
|
|
(guint32) MAX (0, nm_ip_route_get_metric (route)));
|
2014-09-03 16:23:45 +00:00
|
|
|
items = g_slist_prepend (items, routetmp);
|
|
|
|
}
|
2014-09-03 16:27:33 +00:00
|
|
|
items = g_slist_prepend (items, g_strdup_printf ("%sIP4_NUM_ROUTES=%d", prefix, routes->len));
|
|
|
|
g_ptr_array_unref (routes);
|
|
|
|
g_variant_unref (val);
|
2014-09-03 16:23:45 +00:00
|
|
|
} else
|
|
|
|
items = g_slist_prepend (items, g_strdup_printf ("%sIP4_NUM_ROUTES=0", prefix));
|
2011-05-03 03:38:51 +00:00
|
|
|
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GSList *
|
2014-09-03 16:27:33 +00:00
|
|
|
construct_device_dhcp4_items (GSList *items, GVariant *dhcp4_config)
|
2011-05-03 03:38:51 +00:00
|
|
|
{
|
2014-09-03 16:27:33 +00:00
|
|
|
GVariantIter iter;
|
2011-05-11 20:24:40 +00:00
|
|
|
const char *key, *tmp;
|
2014-09-03 16:27:33 +00:00
|
|
|
GVariant *val;
|
2011-05-11 20:24:40 +00:00
|
|
|
char *ucased;
|
2011-05-03 03:38:51 +00:00
|
|
|
|
|
|
|
if (dhcp4_config == NULL)
|
|
|
|
return items;
|
|
|
|
|
2014-09-03 16:27:33 +00:00
|
|
|
g_variant_iter_init (&iter, dhcp4_config);
|
|
|
|
while (g_variant_iter_next (&iter, "{&sv}", &key, &val)) {
|
2011-05-11 20:24:40 +00:00
|
|
|
ucased = g_ascii_strup (key, -1);
|
2014-09-03 16:27:33 +00:00
|
|
|
tmp = g_variant_get_string (val, NULL);
|
2011-05-11 20:24:40 +00:00
|
|
|
items = g_slist_prepend (items, g_strdup_printf ("DHCP4_%s=%s", ucased, tmp));
|
|
|
|
g_free (ucased);
|
2015-03-12 18:24:32 +00:00
|
|
|
g_variant_unref (val);
|
2011-05-03 03:38:51 +00:00
|
|
|
}
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GSList *
|
2014-09-03 16:27:33 +00:00
|
|
|
construct_ip6_items (GSList *items, GVariant *ip6_config, const char *prefix)
|
2011-05-03 03:38:51 +00:00
|
|
|
{
|
2014-09-03 16:27:33 +00:00
|
|
|
GPtrArray *addresses, *routes;
|
2014-12-05 12:45:19 +00:00
|
|
|
char *gateway = NULL;
|
2014-09-03 16:27:33 +00:00
|
|
|
GVariant *val;
|
|
|
|
int i;
|
2011-05-03 03:38:51 +00:00
|
|
|
|
|
|
|
if (ip6_config == NULL)
|
|
|
|
return items;
|
|
|
|
|
|
|
|
if (prefix == NULL)
|
|
|
|
prefix = "";
|
|
|
|
|
|
|
|
/* IP addresses */
|
2014-09-03 16:27:33 +00:00
|
|
|
val = g_variant_lookup_value (ip6_config, "addresses", G_VARIANT_TYPE ("a(ayuay)"));
|
2014-09-03 16:23:45 +00:00
|
|
|
if (val) {
|
2014-10-21 01:30:56 +00:00
|
|
|
addresses = nm_utils_ip6_addresses_from_variant (val, &gateway);
|
|
|
|
if (!gateway)
|
|
|
|
gateway = g_strdup ("::");
|
2011-05-03 03:38:51 +00:00
|
|
|
|
2014-09-03 16:27:33 +00:00
|
|
|
for (i = 0; i < addresses->len; i++) {
|
2014-09-16 20:42:46 +00:00
|
|
|
NMIPAddress *addr = addresses->pdata[i];
|
2014-09-03 16:23:45 +00:00
|
|
|
char *addrtmp;
|
2011-05-03 03:38:51 +00:00
|
|
|
|
2014-09-16 20:42:46 +00:00
|
|
|
addrtmp = g_strdup_printf ("%sIP6_ADDRESS_%d=%s/%d %s", prefix, i,
|
|
|
|
nm_ip_address_get_address (addr),
|
|
|
|
nm_ip_address_get_prefix (addr),
|
2014-10-21 01:30:56 +00:00
|
|
|
gateway);
|
2014-09-03 16:23:45 +00:00
|
|
|
items = g_slist_prepend (items, addrtmp);
|
|
|
|
}
|
2014-09-03 16:27:33 +00:00
|
|
|
if (addresses->len)
|
|
|
|
items = g_slist_prepend (items, g_strdup_printf ("%sIP6_NUM_ADDRESSES=%d", prefix, addresses->len));
|
2014-11-19 12:03:38 +00:00
|
|
|
|
|
|
|
/* Write gateway to a separate variable, too. */
|
|
|
|
items = g_slist_prepend (items, g_strdup_printf ("%sIP6_GATEWAY=%s", prefix, gateway));
|
|
|
|
|
2014-09-03 16:27:33 +00:00
|
|
|
g_ptr_array_unref (addresses);
|
2014-10-21 01:30:56 +00:00
|
|
|
g_free (gateway);
|
2014-09-03 16:27:33 +00:00
|
|
|
g_variant_unref (val);
|
2014-09-03 16:23:45 +00:00
|
|
|
}
|
2011-05-03 03:38:51 +00:00
|
|
|
|
|
|
|
/* DNS servers */
|
2014-09-03 16:27:33 +00:00
|
|
|
val = g_variant_lookup_value (ip6_config, "nameservers", G_VARIANT_TYPE ("aay"));
|
2014-09-03 16:23:45 +00:00
|
|
|
if (val) {
|
2014-12-05 12:45:19 +00:00
|
|
|
items = _list_append_val_strv (items, nm_utils_ip6_dns_from_variant (val),
|
|
|
|
"%sIP6_NAMESERVERS=", prefix);
|
2014-09-03 16:27:33 +00:00
|
|
|
g_variant_unref (val);
|
2011-05-03 03:38:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Search domains */
|
|
|
|
items = add_domains (items, ip6_config, prefix, '6');
|
|
|
|
|
|
|
|
/* Static routes */
|
2014-09-03 16:27:33 +00:00
|
|
|
val = g_variant_lookup_value (ip6_config, "routes", G_VARIANT_TYPE ("a(ayuayu)"));
|
2014-09-03 16:23:45 +00:00
|
|
|
if (val) {
|
2014-09-03 16:27:33 +00:00
|
|
|
routes = nm_utils_ip6_routes_from_variant (val);
|
2011-05-03 03:38:51 +00:00
|
|
|
|
2014-09-03 16:27:33 +00:00
|
|
|
for (i = 0; i < routes->len; i++) {
|
2014-09-16 20:42:46 +00:00
|
|
|
NMIPRoute *route = routes->pdata[i];
|
|
|
|
const char *next_hop;
|
2014-09-03 16:23:45 +00:00
|
|
|
char *routetmp;
|
2011-05-03 03:38:51 +00:00
|
|
|
|
2014-09-16 20:42:46 +00:00
|
|
|
next_hop = nm_ip_route_get_next_hop (route);
|
|
|
|
if (!next_hop)
|
|
|
|
next_hop = "::";
|
2011-05-03 03:38:51 +00:00
|
|
|
|
2014-11-04 20:48:48 +00:00
|
|
|
routetmp = g_strdup_printf ("%sIP6_ROUTE_%d=%s/%d %s %u", prefix, i,
|
2014-09-16 20:42:46 +00:00
|
|
|
nm_ip_route_get_dest (route),
|
|
|
|
nm_ip_route_get_prefix (route),
|
|
|
|
next_hop,
|
2014-11-04 20:48:48 +00:00
|
|
|
(guint32) MAX (0, nm_ip_route_get_metric (route)));
|
2014-09-03 16:23:45 +00:00
|
|
|
items = g_slist_prepend (items, routetmp);
|
|
|
|
}
|
2014-09-03 16:27:33 +00:00
|
|
|
if (routes->len)
|
|
|
|
items = g_slist_prepend (items, g_strdup_printf ("%sIP6_NUM_ROUTES=%d", prefix, routes->len));
|
|
|
|
g_ptr_array_unref (routes);
|
|
|
|
g_variant_unref (val);
|
2014-09-03 16:23:45 +00:00
|
|
|
}
|
2011-05-03 03:38:51 +00:00
|
|
|
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GSList *
|
2014-09-03 16:27:33 +00:00
|
|
|
construct_device_dhcp6_items (GSList *items, GVariant *dhcp6_config)
|
2011-05-03 03:38:51 +00:00
|
|
|
{
|
2014-09-03 16:27:33 +00:00
|
|
|
GVariantIter iter;
|
2011-05-11 20:24:40 +00:00
|
|
|
const char *key, *tmp;
|
2014-09-03 16:27:33 +00:00
|
|
|
GVariant *val;
|
2011-05-11 20:24:40 +00:00
|
|
|
char *ucased;
|
2011-05-03 03:38:51 +00:00
|
|
|
|
|
|
|
if (dhcp6_config == NULL)
|
|
|
|
return items;
|
|
|
|
|
2014-09-03 16:27:33 +00:00
|
|
|
g_variant_iter_init (&iter, dhcp6_config);
|
|
|
|
while (g_variant_iter_next (&iter, "{&sv}", &key, &val)) {
|
2011-05-11 20:24:40 +00:00
|
|
|
ucased = g_ascii_strup (key, -1);
|
2014-09-03 16:27:33 +00:00
|
|
|
tmp = g_variant_get_string (val, NULL);
|
2011-05-11 20:24:40 +00:00
|
|
|
items = g_slist_prepend (items, g_strdup_printf ("DHCP6_%s=%s", ucased, tmp));
|
|
|
|
g_free (ucased);
|
2016-03-08 15:45:25 +00:00
|
|
|
g_variant_unref (val);
|
2011-05-03 03:38:51 +00:00
|
|
|
}
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
|
|
|
|
char **
|
|
|
|
nm_dispatcher_utils_construct_envp (const char *action,
|
2014-09-03 16:27:33 +00:00
|
|
|
GVariant *connection_dict,
|
|
|
|
GVariant *connection_props,
|
|
|
|
GVariant *device_props,
|
2016-08-16 00:25:59 +00:00
|
|
|
GVariant *device_proxy_props,
|
2014-09-03 16:27:33 +00:00
|
|
|
GVariant *device_ip4_props,
|
|
|
|
GVariant *device_ip6_props,
|
|
|
|
GVariant *device_dhcp4_props,
|
|
|
|
GVariant *device_dhcp6_props,
|
2016-07-20 15:24:41 +00:00
|
|
|
const char *connectivity_state,
|
2011-05-03 03:38:51 +00:00
|
|
|
const char *vpn_ip_iface,
|
2016-08-16 00:25:59 +00:00
|
|
|
GVariant *vpn_proxy_props,
|
2014-09-03 16:27:33 +00:00
|
|
|
GVariant *vpn_ip4_props,
|
|
|
|
GVariant *vpn_ip6_props,
|
2015-08-04 08:51:32 +00:00
|
|
|
char **out_iface,
|
|
|
|
const char **out_error_message)
|
2011-05-03 03:38:51 +00:00
|
|
|
{
|
|
|
|
const char *iface = NULL, *ip_iface = NULL;
|
2014-12-18 14:06:56 +00:00
|
|
|
const char *uuid = NULL, *id = NULL, *path = NULL;
|
2014-12-16 19:08:38 +00:00
|
|
|
const char *filename = NULL;
|
2014-12-18 14:13:57 +00:00
|
|
|
gboolean external;
|
2011-05-03 03:38:51 +00:00
|
|
|
NMDeviceState dev_state = NM_DEVICE_STATE_UNKNOWN;
|
2014-09-03 16:27:33 +00:00
|
|
|
GVariant *value;
|
2014-03-31 17:15:19 +00:00
|
|
|
char **envp = NULL, *path_item;
|
2011-05-03 03:38:51 +00:00
|
|
|
GSList *items = NULL, *iter;
|
|
|
|
guint i;
|
2014-09-03 16:27:33 +00:00
|
|
|
GVariant *con_setting;
|
2015-08-04 08:51:32 +00:00
|
|
|
const char *error_message_backup;
|
|
|
|
|
|
|
|
if (!out_error_message)
|
|
|
|
out_error_message = &error_message_backup;
|
2011-05-03 03:38:51 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (action != NULL, NULL);
|
|
|
|
g_return_val_if_fail (out_iface != NULL, NULL);
|
|
|
|
g_return_val_if_fail (*out_iface == NULL, NULL);
|
|
|
|
|
2016-07-19 15:05:35 +00:00
|
|
|
/* Hostname and connectivity changes don't require a device nor contain a connection */
|
|
|
|
if ( !strcmp (action, NMD_ACTION_HOSTNAME)
|
|
|
|
|| !strcmp (action, NMD_ACTION_CONNECTIVITY_CHANGE)) {
|
2014-03-31 17:15:19 +00:00
|
|
|
goto done;
|
2016-07-19 15:05:35 +00:00
|
|
|
}
|
2011-05-03 03:38:51 +00:00
|
|
|
|
2014-12-18 14:06:56 +00:00
|
|
|
/* Connection properties */
|
|
|
|
if (!g_variant_lookup (connection_props, NMD_CONNECTION_PROPS_PATH, "&o", &path)) {
|
2015-08-04 08:51:32 +00:00
|
|
|
*out_error_message = "Missing or invalid required value " NMD_CONNECTION_PROPS_PATH "!";
|
2014-12-18 14:06:56 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
items = g_slist_prepend (items, g_strdup_printf ("CONNECTION_DBUS_PATH=%s", path));
|
|
|
|
|
2014-12-18 14:13:57 +00:00
|
|
|
if (g_variant_lookup (connection_props, NMD_CONNECTION_PROPS_EXTERNAL, "b", &external) && external)
|
|
|
|
items = g_slist_prepend (items, g_strdup ("CONNECTION_EXTERNAL=1"));
|
|
|
|
|
2014-12-16 19:08:38 +00:00
|
|
|
if (g_variant_lookup (connection_props, NMD_CONNECTION_PROPS_FILENAME, "&s", &filename))
|
|
|
|
items = g_slist_prepend (items, g_strdup_printf ("CONNECTION_FILENAME=%s", filename));
|
|
|
|
|
2014-12-18 14:06:56 +00:00
|
|
|
|
2011-05-10 16:33:43 +00:00
|
|
|
/* Canonicalize the VPN interface name; "" is used when passing it through
|
|
|
|
* D-Bus so make sure that's fixed up here.
|
|
|
|
*/
|
|
|
|
if (vpn_ip_iface && !strlen (vpn_ip_iface))
|
|
|
|
vpn_ip_iface = NULL;
|
|
|
|
|
2011-05-03 03:38:51 +00:00
|
|
|
/* interface name */
|
2014-09-03 16:27:33 +00:00
|
|
|
if (!g_variant_lookup (device_props, NMD_DEVICE_PROPS_INTERFACE, "&s", &iface)) {
|
2015-08-04 08:51:32 +00:00
|
|
|
*out_error_message = "Missing or invalid required value " NMD_DEVICE_PROPS_INTERFACE "!";
|
2011-05-03 03:38:51 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2014-09-03 16:27:33 +00:00
|
|
|
if (!*iface)
|
2011-05-10 16:33:43 +00:00
|
|
|
iface = NULL;
|
2011-05-03 03:38:51 +00:00
|
|
|
|
|
|
|
/* IP interface name */
|
2014-09-03 16:27:33 +00:00
|
|
|
value = g_variant_lookup_value (device_props, NMD_DEVICE_PROPS_IP_INTERFACE, NULL);
|
2011-05-03 03:38:51 +00:00
|
|
|
if (value) {
|
2014-09-03 16:27:33 +00:00
|
|
|
if (!g_variant_is_of_type (value, G_VARIANT_TYPE_STRING)) {
|
2015-08-04 08:51:32 +00:00
|
|
|
*out_error_message = "Invalid value " NMD_DEVICE_PROPS_IP_INTERFACE "!";
|
2011-05-03 03:38:51 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2014-09-03 16:27:33 +00:00
|
|
|
g_variant_unref (value);
|
2015-07-14 10:57:26 +00:00
|
|
|
(void) g_variant_lookup (device_props, NMD_DEVICE_PROPS_IP_INTERFACE, "&s", &ip_iface);
|
2013-10-15 18:02:58 +00:00
|
|
|
}
|
2011-05-03 03:38:51 +00:00
|
|
|
|
|
|
|
/* Device type */
|
2014-09-03 16:27:33 +00:00
|
|
|
if (!g_variant_lookup (device_props, NMD_DEVICE_PROPS_TYPE, "u", NULL)) {
|
2015-08-04 08:51:32 +00:00
|
|
|
*out_error_message = "Missing or invalid required value " NMD_DEVICE_PROPS_TYPE "!";
|
2011-05-03 03:38:51 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Device state */
|
2014-09-03 16:27:33 +00:00
|
|
|
value = g_variant_lookup_value (device_props, NMD_DEVICE_PROPS_STATE, G_VARIANT_TYPE_UINT32);
|
|
|
|
if (!value) {
|
2015-08-04 08:51:32 +00:00
|
|
|
*out_error_message = "Missing or invalid required value " NMD_DEVICE_PROPS_STATE "!";
|
2011-05-03 03:38:51 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2014-09-03 16:27:33 +00:00
|
|
|
dev_state = g_variant_get_uint32 (value);
|
|
|
|
g_variant_unref (value);
|
2011-05-03 03:38:51 +00:00
|
|
|
|
|
|
|
/* device itself */
|
2014-09-03 16:27:33 +00:00
|
|
|
if (!g_variant_lookup (device_props, NMD_DEVICE_PROPS_PATH, "o", NULL)) {
|
2015-08-04 08:51:32 +00:00
|
|
|
*out_error_message = "Missing or invalid required value " NMD_DEVICE_PROPS_PATH "!";
|
2011-05-03 03:38:51 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-09-03 16:27:33 +00:00
|
|
|
/* UUID and ID */
|
2014-08-16 14:09:48 +00:00
|
|
|
con_setting = g_variant_lookup_value (connection_dict, NM_SETTING_CONNECTION_SETTING_NAME, NM_VARIANT_TYPE_SETTING);
|
2014-09-03 16:27:33 +00:00
|
|
|
if (!con_setting) {
|
2015-08-04 08:51:32 +00:00
|
|
|
*out_error_message = "Failed to read connection setting";
|
2014-09-03 16:27:33 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!g_variant_lookup (con_setting, NM_SETTING_CONNECTION_UUID, "&s", &uuid)) {
|
2015-08-04 08:51:32 +00:00
|
|
|
*out_error_message = "Connection hash did not contain the UUID";
|
2014-09-03 16:27:33 +00:00
|
|
|
g_variant_unref (con_setting);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!g_variant_lookup (con_setting, NM_SETTING_CONNECTION_ID, "&s", &id)) {
|
2015-08-04 08:51:32 +00:00
|
|
|
*out_error_message = "Connection hash did not contain the ID";
|
2014-09-03 16:27:33 +00:00
|
|
|
g_variant_unref (con_setting);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-05-03 03:38:51 +00:00
|
|
|
items = construct_basic_items (items, uuid, id, iface, ip_iface);
|
2014-09-03 16:27:33 +00:00
|
|
|
g_variant_unref (con_setting);
|
2011-05-03 03:38:51 +00:00
|
|
|
|
|
|
|
/* Device it's aren't valid if the device isn't activated */
|
|
|
|
if (iface && (dev_state == NM_DEVICE_STATE_ACTIVATED)) {
|
2016-08-16 00:25:59 +00:00
|
|
|
items = construct_proxy_items (items, device_proxy_props, NULL);
|
2011-05-03 03:38:51 +00:00
|
|
|
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);
|
|
|
|
items = construct_device_dhcp6_items (items, device_dhcp6_props);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vpn_ip_iface) {
|
|
|
|
items = g_slist_prepend (items, g_strdup_printf ("VPN_IP_IFACE=%s", vpn_ip_iface));
|
2016-08-16 00:25:59 +00:00
|
|
|
items = construct_proxy_items (items, vpn_proxy_props, "VPN_");
|
2011-05-03 03:38:51 +00:00
|
|
|
items = construct_ip4_items (items, vpn_ip4_props, "VPN_");
|
|
|
|
items = construct_ip6_items (items, vpn_ip6_props, "VPN_");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Backwards compat: 'iface' is set in this order:
|
|
|
|
* 1) VPN interface name
|
|
|
|
* 2) Device IP interface name
|
|
|
|
* 3) Device interface anme
|
|
|
|
*/
|
|
|
|
if (vpn_ip_iface)
|
|
|
|
*out_iface = g_strdup (vpn_ip_iface);
|
|
|
|
else if (ip_iface)
|
|
|
|
*out_iface = g_strdup (ip_iface);
|
|
|
|
else
|
|
|
|
*out_iface = g_strdup (iface);
|
|
|
|
|
2014-03-31 17:15:19 +00:00
|
|
|
done:
|
2016-07-20 15:24:41 +00:00
|
|
|
/* The connectivity_state value will only be meaningful for 'connectivity-change' events
|
|
|
|
* (otherwise it will be "UNKNOWN"), so we only set the environment variable in those cases.
|
|
|
|
*/
|
|
|
|
if (connectivity_state && strcmp(connectivity_state, "UNKNOWN"))
|
|
|
|
items = g_slist_prepend (items, g_strdup_printf ("CONNECTIVITY_STATE=%s", connectivity_state));
|
|
|
|
|
2014-03-31 17:15:19 +00:00
|
|
|
path = g_getenv ("PATH");
|
|
|
|
if (path) {
|
|
|
|
path_item = g_strdup_printf ("PATH=%s", path);
|
|
|
|
items = g_slist_prepend (items, path_item);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert the list to an environment pointer */
|
|
|
|
envp = g_new0 (char *, g_slist_length (items) + 1);
|
|
|
|
for (iter = items, i = 0; iter; iter = g_slist_next (iter), i++)
|
|
|
|
envp[i] = (char *) iter->data;
|
|
|
|
g_slist_free (items);
|
|
|
|
|
2015-08-04 08:51:32 +00:00
|
|
|
*out_error_message = NULL;
|
2011-05-03 03:38:51 +00:00
|
|
|
return envp;
|
|
|
|
}
|
|
|
|
|