Commit 1ea0dd41 authored by Dan Winship's avatar Dan Winship

Merge branch 'master' into dhcp-merge

Conflicts:
	src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp-client.c
	src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp-lease.c
	src/dhcp-manager/systemd-dhcp/src/shared/fileio.c
	src/dhcp-manager/systemd-dhcp/src/shared/util.c
	src/dhcp-manager/systemd-dhcp/src/systemd/sd-dhcp-client.h
	src/dhcp-manager/systemd-dhcp/src/systemd/sd-dhcp-lease.h
parents e2e4637c af525e8a
......@@ -152,9 +152,6 @@ valgrind-*.log
/libnm-glib/tests/test-nm-client
/libnm-glib/tests/test-remote-settings-client
/libnm-util/nm-ifcfg-rh-docs.xml
/libnm-util/nm-keyfile-docs.xml
/libnm-util/nm-setting-docs.xml
/libnm-util/nm-version.h
/libnm-util/test-crypto
/libnm-util/tests/test-crypto
......@@ -166,6 +163,11 @@ valgrind-*.log
/libnm-util/tests/test-setting-8021x
/libnm-util/tests/test-setting-dcb
/libnm/nm-ifcfg-rh-docs.xml
/libnm/nm-keyfile-docs.xml
/libnm/nm-property-docs.xml
/libnm/nm-setting-docs.xml
/libnm/nm-setting-docs-overrides.xml
/libnm/tests/test-nm-client
/libnm/tests/test-remote-settings-client
/libnm/tests/test-secret-agent
......@@ -230,7 +232,9 @@ valgrind-*.log
/src/dhcp-manager/nm-dhcp-helper
/src/dhcp-manager/tests/test-dhcp-dhclient
/src/dhcp-manager/tests/test-dhcp-options
/src/dhcp-manager/tests/test-dhcp-utils
/src/dnsmasq-manager/tests/test-dnsmasq-utils
/src/nm-iface-helper
/src/settings/plugins/ibft/tests/test-ibft
/src/settings/plugins/ifcfg-rh/tests/network-scripts/*-Test_Write_*
/src/settings/plugins/ifcfg-rh/tests/network-scripts/Test_Write_*
......
......@@ -18,6 +18,8 @@
* Copyright 2008, 2014 Red Hat, Inc.
*/
#include "config.h"
#include <stdlib.h>
#include <string.h>
......
......@@ -18,7 +18,8 @@
* Copyright (C) 2008 - 2011 Red Hat, Inc.
*/
#include <config.h>
#include "config.h"
#include <string.h>
#include <glib-object.h>
......@@ -92,11 +93,9 @@ static GSList *
construct_ip4_items (GSList *items, GVariant *ip4_config, const char *prefix)
{
GPtrArray *addresses, *routes;
char **dns, **wins;
char **dns, **wins, *gateway;
GString *tmp;
GVariant *val;
char str_addr[INET_ADDRSTRLEN];
char str_gw[INET_ADDRSTRLEN];
int i;
if (ip4_config == NULL)
......@@ -108,22 +107,28 @@ construct_ip4_items (GSList *items, GVariant *ip4_config, const char *prefix)
/* IP addresses */
val = g_variant_lookup_value (ip4_config, "addresses", G_VARIANT_TYPE ("aau"));
if (val) {
addresses = nm_utils_ip4_addresses_from_variant (val);
addresses = nm_utils_ip4_addresses_from_variant (val, &gateway);
if (!gateway)
gateway = g_strdup ("0.0.0.0");
for (i = 0; i < addresses->len; i++) {
NMIP4Address *addr = addresses->pdata[i];
guint32 ip_prefix = nm_ip4_address_get_prefix (addr);
NMIPAddress *addr = addresses->pdata[i];
char *addrtmp;
nm_utils_inet4_ntop (nm_ip4_address_get_address (addr), str_addr);
nm_utils_inet4_ntop (nm_ip4_address_get_gateway (addr), str_gw);
addrtmp = g_strdup_printf ("%sIP4_ADDRESS_%d=%s/%d %s", prefix, i, str_addr, ip_prefix, str_gw);
addrtmp = g_strdup_printf ("%sIP4_ADDRESS_%d=%s/%d %s", prefix, i,
nm_ip_address_get_address (addr),
nm_ip_address_get_prefix (addr),
gateway);
items = g_slist_prepend (items, addrtmp);
}
if (addresses->len)
items = g_slist_prepend (items, g_strdup_printf ("%sIP4_NUM_ADDRESSES=%d", prefix, addresses->len));
/* Write gateway to a separate variable, too. */
items = g_slist_prepend (items, g_strdup_printf ("%sIP4_GATEWAY=%s", prefix, gateway));
g_ptr_array_unref (addresses);
g_free (gateway);
g_variant_unref (val);
}
......@@ -177,15 +182,19 @@ construct_ip4_items (GSList *items, GVariant *ip4_config, const char *prefix)
routes = nm_utils_ip4_routes_from_variant (val);
for (i = 0; i < routes->len; i++) {
NMIP4Route *route = routes->pdata[i];
guint32 ip_prefix = nm_ip4_route_get_prefix (route);
guint32 metric = nm_ip4_route_get_metric (route);
NMIPRoute *route = routes->pdata[i];
const char *next_hop;
char *routetmp;
nm_utils_inet4_ntop (nm_ip4_route_get_dest (route), str_addr);
nm_utils_inet4_ntop (nm_ip4_route_get_next_hop (route), str_gw);
next_hop = nm_ip_route_get_next_hop (route);
if (!next_hop)
next_hop = "0.0.0.0";
routetmp = g_strdup_printf ("%sIP4_ROUTE_%d=%s/%d %s %d", prefix, i, str_addr, ip_prefix, str_gw, metric);
routetmp = g_strdup_printf ("%sIP4_ROUTE_%d=%s/%d %s %u", prefix, i,
nm_ip_route_get_dest (route),
nm_ip_route_get_prefix (route),
next_hop,
(guint32) MAX (0, nm_ip_route_get_metric (route)));
items = g_slist_prepend (items, routetmp);
}
items = g_slist_prepend (items, g_strdup_printf ("%sIP4_NUM_ROUTES=%d", prefix, routes->len));
......@@ -222,11 +231,9 @@ static GSList *
construct_ip6_items (GSList *items, GVariant *ip6_config, const char *prefix)
{
GPtrArray *addresses, *routes;
char **dns;
char **dns, *gateway = NULL;
GString *tmp;
GVariant *val;
char str_addr[INET6_ADDRSTRLEN];
char str_gw[INET6_ADDRSTRLEN];
int i;
if (ip6_config == NULL)
......@@ -238,22 +245,28 @@ construct_ip6_items (GSList *items, GVariant *ip6_config, const char *prefix)
/* IP addresses */
val = g_variant_lookup_value (ip6_config, "addresses", G_VARIANT_TYPE ("a(ayuay)"));
if (val) {
addresses = nm_utils_ip6_addresses_from_variant (val);
addresses = nm_utils_ip6_addresses_from_variant (val, &gateway);
if (!gateway)
gateway = g_strdup ("::");
for (i = 0; i < addresses->len; i++) {
NMIP6Address *addr = addresses->pdata[i];
guint32 ip_prefix = nm_ip6_address_get_prefix (addr);
NMIPAddress *addr = addresses->pdata[i];
char *addrtmp;
nm_utils_inet6_ntop (nm_ip6_address_get_address (addr), str_addr);
nm_utils_inet6_ntop (nm_ip6_address_get_gateway (addr), str_gw);
addrtmp = g_strdup_printf ("%sIP6_ADDRESS_%d=%s/%d %s", prefix, i, str_addr, ip_prefix, str_gw);
addrtmp = g_strdup_printf ("%sIP6_ADDRESS_%d=%s/%d %s", prefix, i,
nm_ip_address_get_address (addr),
nm_ip_address_get_prefix (addr),
gateway);
items = g_slist_prepend (items, addrtmp);
}
if (addresses->len)
items = g_slist_prepend (items, g_strdup_printf ("%sIP6_NUM_ADDRESSES=%d", prefix, addresses->len));
/* Write gateway to a separate variable, too. */
items = g_slist_prepend (items, g_strdup_printf ("%sIP6_GATEWAY=%s", prefix, gateway));
g_ptr_array_unref (addresses);
g_free (gateway);
g_variant_unref (val);
}
......@@ -287,15 +300,19 @@ construct_ip6_items (GSList *items, GVariant *ip6_config, const char *prefix)
routes = nm_utils_ip6_routes_from_variant (val);
for (i = 0; i < routes->len; i++) {
NMIP6Route *route = routes->pdata[i];
guint32 ip_prefix = nm_ip6_route_get_prefix (route);
guint32 metric = nm_ip6_route_get_metric (route);
NMIPRoute *route = routes->pdata[i];
const char *next_hop;
char *routetmp;
nm_utils_inet6_ntop (nm_ip6_route_get_dest (route), str_addr);
nm_utils_inet6_ntop (nm_ip6_route_get_next_hop (route), str_gw);
next_hop = nm_ip_route_get_next_hop (route);
if (!next_hop)
next_hop = "::";
routetmp = g_strdup_printf ("%sIP6_ROUTE_%d=%s/%d %s %d", prefix, i, str_addr, ip_prefix, str_gw, metric);
routetmp = g_strdup_printf ("%sIP6_ROUTE_%d=%s/%d %s %u", prefix, i,
nm_ip_route_get_dest (route),
nm_ip_route_get_prefix (route),
next_hop,
(guint32) MAX (0, nm_ip_route_get_metric (route)));
items = g_slist_prepend (items, routetmp);
}
if (routes->len)
......
......@@ -18,6 +18,8 @@
* Copyright (C) 2008 - 2012 Red Hat, Inc.
*/
#include "config.h"
#include <syslog.h>
#include <stdio.h>
#include <unistd.h>
......
......@@ -18,7 +18,8 @@
*
*/
#include <config.h>
#include "config.h"
#include <arpa/inet.h>
#include <stdlib.h>
#include <string.h>
......@@ -183,6 +184,7 @@ parse_ip4 (GKeyFile *kf, GVariant **out_props, const char *section, GError **err
char *tmp;
char **split, **iter;
GPtrArray *addresses, *routes;
const char *gateway = NULL;
g_variant_builder_init (&props, G_VARIANT_TYPE ("a{sv}"));
......@@ -218,37 +220,36 @@ parse_ip4 (GKeyFile *kf, GVariant **out_props, const char *section, GError **err
g_free (tmp);
if (g_strv_length (split) > 0) {
addresses = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip4_address_unref);
addresses = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_address_unref);
for (iter = split; iter && *iter; iter++) {
NMIP4Address *addr;
guint32 a;
char *p;
NMIPAddress *addr;
char *ip, *prefix;
if (strlen (g_strstrip (*iter)) == 0)
continue;
addr = nm_ip4_address_new ();
p = strchr (*iter, '/');
g_assert (p);
*p++ = '\0';
ip = *iter;
g_assert_cmpint (inet_pton (AF_INET, *iter, &a), ==, 1);
nm_ip4_address_set_address (addr, a);
nm_ip4_address_set_prefix (addr, (guint) atoi (p));
prefix = strchr (ip, '/');
g_assert (prefix);
*prefix++ = '\0';
p = strchr (p, ' ');
g_assert (p);
p++;
g_assert_cmpint (inet_pton (AF_INET, p, &a), ==, 1);
nm_ip4_address_set_gateway (addr, a);
if (addresses->len == 0) {
gateway = strchr (prefix, ' ');
g_assert (gateway);
gateway++;
}
addr = nm_ip_address_new (AF_INET, ip, (guint) atoi (prefix), error);
if (!addr) {
g_ptr_array_unref (addresses);
return FALSE;
}
g_ptr_array_add (addresses, addr);
}
g_variant_builder_add (&props, "{sv}", "addresses",
nm_utils_ip4_addresses_to_variant (addresses));
nm_utils_ip4_addresses_to_variant (addresses, gateway));
g_ptr_array_unref (addresses);
}
g_strfreev (split);
......@@ -261,37 +262,36 @@ parse_ip4 (GKeyFile *kf, GVariant **out_props, const char *section, GError **err
g_free (tmp);
if (g_strv_length (split) > 0) {
routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip4_route_unref);
routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_route_unref);
for (iter = split; iter && *iter; iter++) {
NMIP4Route *route;
guint32 a;
char *p;
NMIPRoute *route;
char *dest, *prefix, *next_hop, *metric;
if (strlen (g_strstrip (*iter)) == 0)
continue;
route = nm_ip4_route_new ();
p = strchr (*iter, '/');
g_assert (p);
*p++ = '\0';
g_assert_cmpint (inet_pton (AF_INET, *iter, &a), ==, 1);
nm_ip4_route_set_dest (route, a);
nm_ip4_route_set_prefix (route, (guint) atoi (p));
dest = *iter;
p = strchr (p, ' ');
g_assert (p);
p++;
prefix = strchr (dest, '/');
g_assert (prefix);
*prefix++ = '\0';
g_assert_cmpint (inet_pton (AF_INET, p, &a), ==, 1);
nm_ip4_route_set_next_hop (route, a);
next_hop = strchr (prefix, ' ');
g_assert (next_hop);
next_hop++;
p = strchr (p, ' ');
g_assert (p);
p++;
nm_ip4_route_set_metric (route, (guint) atoi (p));
metric = strchr (next_hop, ' ');
g_assert (metric);
metric++;
route = nm_ip_route_new (AF_INET,
dest, (guint) atoi (prefix),
next_hop, (guint) atoi (metric),
error);
if (!route) {
g_ptr_array_unref (routes);
return FALSE;
}
g_ptr_array_add (routes, route);
}
......
......@@ -9,12 +9,15 @@ AM_CPPFLAGS = \
-I${top_builddir}/libnm-core \
-I${top_srcdir}/libnm \
-I${top_builddir}/libnm \
-I${top_srcdir}/clients/common \
$(GLIB_CFLAGS) \
-DG_LOG_DOMAIN=\""nmcli"\" \
-DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \
-DNMCLI_LOCALEDIR=\"$(datadir)/locale\"
nmcli_SOURCES = \
agent.c \
agent.h \
common.c \
common.h \
connections.c \
......@@ -28,22 +31,33 @@ nmcli_SOURCES = \
nmcli.c \
nmcli.h \
utils.c \
utils.h
utils.h \
polkit-agent.c \
polkit-agent.h \
\
$(srcdir)/../common/nm-secret-agent-simple.c \
$(srcdir)/../common/nm-secret-agent-simple.h \
$(NULL)
nmcli_LDADD = \
$(GLIB_LIBS) \
$(READLINE_LIBS) \
$(top_builddir)/libnm/libnm.la
if WITH_POLKIT_AGENT
AM_CPPFLAGS += $(POLKIT_CFLAGS)
nmcli_SOURCES += $(srcdir)/../common/nm-polkit-listener.c $(srcdir)/../common/nm-polkit-listener.h
nmcli_LDADD += $(POLKIT_LIBS)
endif
if BUILD_SETTING_DOCS
settings-docs.c: settings-docs.xsl $(top_builddir)/libnm-util/nm-setting-docs.xml
settings-docs.c: settings-docs.xsl $(top_builddir)/libnm/nm-property-docs.xml
$(AM_V_GEN) xsltproc --output $@ $^
BUILT_SOURCES = settings-docs.c
CLEANFILES = settings-docs.c
endif
DISTCLEANFILES = settings-docs.c
EXTRA_DIST = settings-docs.c settings-docs.xsl
completiondir = $(datadir)/bash-completion/completions
......
/*
* nmcli - command-line tool for controlling NetworkManager
* Functions for running NM secret agent.
*
* 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 2014 Red Hat, Inc.
*/
#include "config.h"
#include <glib.h>
#include <glib/gi18n.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <readline/readline.h>
#include <readline/history.h>
#include "common.h"
#include "utils.h"
#include "nm-secret-agent-simple.h"
#include "polkit-agent.h"
#include "agent.h"
static void
usage (void)