dhcp: merge branch 'master' into th/systemd-dhcp-integration

Only basic merging. The result does not yet compile.

https://bugzilla.gnome.org/show_bug.cgi?id=742719

Conflicts:
	src/dhcp-manager/systemd-dhcp/src/libsystemd-network/dhcp-packet.c
	src/dhcp-manager/systemd-dhcp/src/libsystemd-network/network-internal.c
	src/dhcp-manager/systemd-dhcp/src/libsystemd-network/network-internal.h
	src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp-lease.c
	src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp6-client.c
	src/dhcp-manager/systemd-dhcp/src/shared/macro.h
	src/dhcp-manager/systemd-dhcp/src/shared/strv.c
	src/dhcp-manager/systemd-dhcp/src/shared/util.c
	src/dhcp-manager/systemd-dhcp/src/shared/util.h
	src/dhcp-manager/systemd-dhcp/src/systemd/sd-dhcp6-client.h
This commit is contained in:
Thomas Haller 2015-02-01 15:25:19 +01:00
commit 7afb63ca34
692 changed files with 62737 additions and 37759 deletions

14
.gitignore vendored
View file

@ -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,10 +232,10 @@ 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_*
/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh
/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh-utils
/src/settings/plugins/ifnet/tests/check_ifnet
@ -247,6 +249,8 @@ valgrind-*.log
/src/tests/test-ip4-config
/src/tests/test-ip6-config
/src/tests/test-resolvconf-capture
/src/tests/test-route-manager-fake
/src/tests/test-route-manager-linux
/src/tests/test-wired-defname
/vapi/*.vapi

51
NEWS
View file

@ -1,3 +1,52 @@
===============================================
NetworkManager-1.0
Overview of changes since NetworkManager-0.9.10
===============================================
This is a new stable release of NetworkManager. Notable changes include:
* A new 'libnm' GObject-based client library to replace libnm-util/libnm-glib
- IP address, IP route, hardware address, and other properties are now
represented as strings
- Based on GIO's GDBus bindings instead of dbus-glib
- Uses modern GObject APIs including GAsyncResult and GVariant
- For more information see https://wiki.gnome.org/Projects/NetworkManager/libnm
* Devices and VPN connections now have individual default routes. Priorities
are handled through configurable route metrics.
* nmcli now supports password requests and PolicyKit authorizations
* A faster, lighter-weight (though less capable) internal DHCP client has been
added and may be selected with the "dhcp=internal" option. It supports
fewer DHCP options and does not yet support DHCPv6.
* A new 'configure-and-quit=yes' option has been added for environments with
less dynamic network configuration
* When running on 3.17 and later kernels, NetworkManager handles IPv6LL address
assignment to ensure that IPv6 connectivity is not enabled until
intentionally configured by the user
* NetworkManager no longer causes the nl80211 kernel module to be loaded on
systems with no Wi-Fi devices
* Bluetooth DUN support now works with Bluez 5.x
* VPN connections can now persist across link changes and suspend/resume if
their VPN plugin supports this feature
* A new 'ibft' settings plugin has been added to support firmware-based
iBFT/iSCSI configurations. This functionality has been moved to 'ibft'
from the 'ifcfg-rh' plugin.
* IPv6 router advertisement MTUs are now respected
* NetworkManager no longer requires polkit libraries at runtime when Polkit
support is enabled, and Polkit can be disabled at build time too
* Automatically created connections are now deleted when their device goes away
* 'nmcli dev connect' now attemts to create a connection if none exists
* Manually configured static IPv6 configuration is kept even if SLAAC fails
* Manpages for the 'keyfile' and 'ifcfg-rh' plugins now describe their
configuration syntax and available options
* WWAN connections now support IPv6 if the modem and provider support IPv6
* Software devices (bridge, bond, team, etc) can now be deleted from the D-Bus
API or with nmcli
* The manpages, documentation, and API annotations have received many cleanups
* Externally created virtual interfaces are no longer managed by NetworkManager
until they are set "up" or activated via nmcli
* Team device support is now an optional plugin
==============================================
NetworkManager-0.9.10
Overview of changes since NetworkManager-0.9.8
@ -41,7 +90,7 @@ This is a new stable release of NetworkManager. Notable changes include:
* The dispatcher timeout has increased to 10 minutes, and new "pre-up" and
"pre-down" events have been added which block activation until complete
* NetworkManager no longer prevents Wake-on-LAN functionality from working
* PPPoE now requires userland "rp-pppoe" to work around kernel bugs with
* PPPoE now requires userland "rp-pppoe" to work around kernel bugs
that prevent detecting server-side termination of the PPP link
* An ARP announcement is now sent after IPv4 addresses are configured
* Added a DNS plugin for dnssec-trigger for better DNSSEC operation

View file

@ -18,6 +18,8 @@
* Copyright 2008, 2014 Red Hat, Inc.
*/
#include "config.h"
#include <stdlib.h>
#include <string.h>

View file

@ -31,6 +31,8 @@
#define NM_DISPATCHER_DBUS_PATH "/org/freedesktop/nm_dispatcher"
#define NMD_CONNECTION_PROPS_PATH "path"
#define NMD_CONNECTION_PROPS_FILENAME "filename"
#define NMD_CONNECTION_PROPS_EXTERNAL "external"
#define NMD_DEVICE_PROPS_INTERFACE "interface"
#define NMD_DEVICE_PROPS_IP_INTERFACE "ip-interface"

View file

@ -18,7 +18,8 @@
* Copyright (C) 2008 - 2011 Red Hat, Inc.
*/
#include <config.h>
#include "config.h"
#include <string.h>
#include <glib-object.h>
@ -52,6 +53,37 @@ construct_basic_items (GSList *list,
return list;
}
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;
}
static GSList *
add_domains (GSList *items,
GVariant *dict,
@ -59,32 +91,14 @@ add_domains (GSList *items,
const char four_or_six)
{
GVariant *val;
char **domains = NULL;
GString *tmp;
guint i;
/* Search domains */
val = g_variant_lookup_value (dict, "domains", G_VARIANT_TYPE_STRING_ARRAY);
if (!val)
return items;
domains = g_variant_dup_strv (val, NULL);
g_variant_unref (val);
if (!domains[0]) {
g_strfreev (domains);
return items;
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);
}
tmp = g_string_new (NULL);
g_string_append_printf (tmp, "%sIP%c_DOMAINS=", prefix, four_or_six);
for (i = 0; domains[i]; i++) {
if (i > 0)
g_string_append_c (tmp, ' ');
g_string_append (tmp, domains[i]);
}
items = g_slist_prepend (items, g_string_free (tmp, FALSE));
g_strfreev (domains);
return items;
}
@ -92,11 +106,8 @@ static GSList *
construct_ip4_items (GSList *items, GVariant *ip4_config, const char *prefix)
{
GPtrArray *addresses, *routes;
char **dns, **wins;
GString *tmp;
char *gateway;
GVariant *val;
char str_addr[INET_ADDRSTRLEN];
char str_gw[INET_ADDRSTRLEN];
int i;
if (ip4_config == NULL)
@ -108,42 +119,36 @@ 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);
}
/* DNS servers */
val = g_variant_lookup_value (ip4_config, "nameservers", G_VARIANT_TYPE ("au"));
if (val) {
dns = nm_utils_ip4_dns_from_variant (val);
if (dns[0]) {
tmp = g_string_new (NULL);
g_string_append_printf (tmp, "%sIP4_NAMESERVERS=", prefix);
for (i = 0; dns[i]; i++) {
if (i != 0)
g_string_append_c (tmp, ' ');
g_string_append (tmp, dns[i]);
}
items = g_slist_prepend (items, g_string_free (tmp, FALSE));
}
g_strfreev (dns);
items = _list_append_val_strv (items, nm_utils_ip4_dns_from_variant (val),
"%sIP4_NAMESERVERS=", prefix);
g_variant_unref (val);
}
@ -153,21 +158,8 @@ construct_ip4_items (GSList *items, GVariant *ip4_config, const char *prefix)
/* WINS servers */
val = g_variant_lookup_value (ip4_config, "wins-servers", G_VARIANT_TYPE ("au"));
if (val) {
wins = nm_utils_ip4_dns_from_variant (val);
if (wins[0]) {
tmp = g_string_new (NULL);
g_string_append_printf (tmp, "%sIP4_WINS_SERVERS=", prefix);
for (i = 0; wins[i]; i++) {
if (i != 0)
g_string_append_c (tmp, ' ');
g_string_append (tmp, wins[i]);
}
items = g_slist_prepend (items, g_string_free (tmp, FALSE));
}
g_strfreev (wins);
items = _list_append_val_strv (items, nm_utils_ip4_dns_from_variant (val),
"%sIP4_WINS_SERVERS=", prefix);
g_variant_unref (val);
}
@ -177,15 +169,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 +218,8 @@ static GSList *
construct_ip6_items (GSList *items, GVariant *ip6_config, const char *prefix)
{
GPtrArray *addresses, *routes;
char **dns;
GString *tmp;
char *gateway = NULL;
GVariant *val;
char str_addr[INET6_ADDRSTRLEN];
char str_gw[INET6_ADDRSTRLEN];
int i;
if (ip6_config == NULL)
@ -238,43 +231,36 @@ 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);
}
/* DNS servers */
val = g_variant_lookup_value (ip6_config, "nameservers", G_VARIANT_TYPE ("aay"));
if (val) {
dns = nm_utils_ip6_dns_from_variant (val);
if (dns[0]) {
tmp = g_string_new (NULL);
g_string_append_printf (tmp, "%sIP6_NAMESERVERS=", prefix);
for (i = 0; dns[i]; i++) {
if (i != 0)
g_string_append_c (tmp, ' ');
g_string_append (tmp, dns[i]);
}
items = g_slist_prepend (items, g_string_free (tmp, FALSE));
}
g_strfreev (dns);
items = _list_append_val_strv (items, nm_utils_ip6_dns_from_variant (val),
"%sIP6_NAMESERVERS=", prefix);
g_variant_unref (val);
}
@ -287,15 +273,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)
@ -343,7 +333,9 @@ nm_dispatcher_utils_construct_envp (const char *action,
char **out_iface)
{
const char *iface = NULL, *ip_iface = NULL;
const char *uuid = NULL, *id = NULL, *path;
const char *uuid = NULL, *id = NULL, *path = NULL;
const char *filename = NULL;
gboolean external;
NMDeviceState dev_state = NM_DEVICE_STATE_UNKNOWN;
GVariant *value;
char **envp = NULL, *path_item;
@ -359,6 +351,20 @@ nm_dispatcher_utils_construct_envp (const char *action,
if (!strcmp (action, "hostname"))
goto done;
/* Connection properties */
if (!g_variant_lookup (connection_props, NMD_CONNECTION_PROPS_PATH, "&o", &path)) {
g_warning ("Missing or invalid required value " NMD_CONNECTION_PROPS_PATH "!");
return NULL;
}
items = g_slist_prepend (items, g_strdup_printf ("CONNECTION_DBUS_PATH=%s", path));
if (g_variant_lookup (connection_props, NMD_CONNECTION_PROPS_EXTERNAL, "b", &external) && external)
items = g_slist_prepend (items, g_strdup ("CONNECTION_EXTERNAL=1"));
if (g_variant_lookup (connection_props, NMD_CONNECTION_PROPS_FILENAME, "&s", &filename))
items = g_slist_prepend (items, g_strdup_printf ("CONNECTION_FILENAME=%s", filename));
/* Canonicalize the VPN interface name; "" is used when passing it through
* D-Bus so make sure that's fixed up here.
*/

View file

@ -18,6 +18,8 @@
* Copyright (C) 2008 - 2012 Red Hat, Inc.
*/
#include "config.h"
#include <syslog.h>
#include <stdio.h>
#include <unistd.h>
@ -294,7 +296,7 @@ script_timeout_cb (gpointer user_data)
if (kill (script->pid, 0) == 0)
kill (script->pid, SIGKILL);
waitpid (script->pid, NULL, 0);
(void) waitpid (script->pid, NULL, 0);
script->error = g_strdup_printf ("Script '%s' timed out.", script->script);
script->result = DISPATCH_RESULT_TIMEOUT;
@ -359,15 +361,6 @@ check_filename (const char *file_name)
return TRUE;
}
static void
child_setup (gpointer user_data G_GNUC_UNUSED)
{
/* We are in the child process at this point */
/* Give child a different process group to ensure signal separation. */
pid_t pid = getpid ();
setpgid (pid, pid);
}
#define SCRIPT_TIMEOUT 600 /* 10 minutes */
static void
@ -385,7 +378,7 @@ dispatch_one_script (Request *request)
if (request->debug)
g_message ("Running script '%s'", script->script);
if (g_spawn_async ("/", argv, request->envp, G_SPAWN_DO_NOT_REAP_CHILD, child_setup, request, &script->pid, &error)) {
if (g_spawn_async ("/", argv, request->envp, G_SPAWN_DO_NOT_REAP_CHILD, NULL, request, &script->pid, &error)) {
request->script_watch_id = g_child_watch_add (script->pid, (GChildWatchFunc) script_watch_cb, script);
request->script_timeout_id = g_timeout_add_seconds (SCRIPT_TIMEOUT, script_timeout_cb, script);
} else {

View file

@ -28,12 +28,14 @@ test_dispatcher_envp_LDADD = \
###########################################
@VALGRIND_RULES@
TESTS = test-dispatcher-envp
endif
EXTRA_DIST= \
dispatcher-old-down \
dispatcher-old-up \
dispatcher-old-vpn-down \
dispatcher-old-vpn-up
dispatcher-down \
dispatcher-external \
dispatcher-up \
dispatcher-vpn-down \
dispatcher-vpn-up

View file

@ -14,7 +14,9 @@ path=/org/freedesktop/NetworkManager/Devices/0
[env]
PATH=
CONNECTION_UUID=3fd2a33a-d81b-423f-ae99-e6baba742311
CONNECTION_DBUS_PATH=/org/freedesktop/NetworkManager/Connections/5
CONNECTION_ID=Random Connection
CONNECTION_FILENAME=/callouts/tests/dispatcher-down
DEVICE_IFACE=wlan0
DEVICE_IP_IFACE=wlan0

View file

@ -0,0 +1,33 @@
[main]
action=up
expected-iface=virbr0
uuid=92bbc2fb-7304-46be-8ebb-6093dbe19a6a
id=virbr0
external=1
[device]
state=100
ip-interface=virbr0
type=13
interface=virbr0
path=/org/freedesktop/NetworkManager/Devices/0
[ip4]
addresses=192.168.122.1/24 0.0.0.0
domains=
gateway=0.0.0.0
[env]
PATH=
CONNECTION_UUID=92bbc2fb-7304-46be-8ebb-6093dbe19a6a
CONNECTION_DBUS_PATH=/org/freedesktop/NetworkManager/Connections/5
CONNECTION_FILENAME=/callouts/tests/dispatcher-external
CONNECTION_ID=virbr0
CONNECTION_EXTERNAL=1
DEVICE_IFACE=virbr0
DEVICE_IP_IFACE=virbr0
IP4_NUM_ADDRESSES=1
IP4_ADDRESS_0=192.168.122.1/24 0.0.0.0
IP4_GATEWAY=0.0.0.0
IP4_NUM_ROUTES=0

View file

@ -33,12 +33,15 @@ domains=hsd1.mn.comcast.net.
[env]
PATH=
CONNECTION_UUID=3fd2a33a-d81b-423f-ae99-e6baba742311
CONNECTION_DBUS_PATH=/org/freedesktop/NetworkManager/Connections/5
CONNECTION_ID=Random Connection
CONNECTION_FILENAME=/callouts/tests/dispatcher-up
DEVICE_IFACE=wlan0
DEVICE_IP_IFACE=wlan0
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
IP4_GATEWAY=192.168.1.1
IP4_DOMAINS=hsd1.mn.comcast.net.
IP4_NUM_ROUTES=0
DHCP4_NETBIOS_NAME_SERVERS=0.0.0.0

View file

@ -33,12 +33,15 @@ domains=hsd1.mn.comcast.net.
[env]
PATH=
CONNECTION_UUID=355653c0-34d3-4777-ad25-f9a498b7ef8e
CONNECTION_DBUS_PATH=/org/freedesktop/NetworkManager/Connections/5
CONNECTION_ID=Random Connection
CONNECTION_FILENAME=/callouts/tests/dispatcher-vpn-down
DEVICE_IFACE=wlan0
DEVICE_IP_IFACE=tun0
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
IP4_GATEWAY=192.168.1.1
IP4_DOMAINS=hsd1.mn.comcast.net.
IP4_NUM_ROUTES=0
DHCP4_NETBIOS_NAME_SERVERS=0.0.0.0

View file

@ -33,12 +33,15 @@ domains=hsd1.mn.comcast.net.
[env]
PATH=
CONNECTION_UUID=355653c0-34d3-4777-ad25-f9a498b7ef8e
CONNECTION_DBUS_PATH=/org/freedesktop/NetworkManager/Connections/5
CONNECTION_ID=Random Connection
CONNECTION_FILENAME=/callouts/tests/dispatcher-vpn-up
DEVICE_IFACE=wlan0
DEVICE_IP_IFACE=tun0
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
IP4_GATEWAY=192.168.1.1
IP4_DOMAINS=hsd1.mn.comcast.net.
IP4_NUM_ROUTES=0
DHCP4_NETBIOS_NAME_SERVERS=0.0.0.0

View file

@ -18,7 +18,8 @@
*
*/
#include <config.h>
#include "config.h"
#include <arpa/inet.h>
#include <stdlib.h>
#include <string.h>
@ -33,6 +34,7 @@
static gboolean
parse_main (GKeyFile *kf,
const char *filename,
GVariant **out_con_dict,
GVariant **out_con_props,
char **out_expected_iface,
@ -79,8 +81,21 @@ parse_main (GKeyFile *kf,
g_variant_builder_init (&props, G_VARIANT_TYPE ("a{sv}"));
g_variant_builder_add (&props, "{sv}",
"connection-path",
NMD_CONNECTION_PROPS_PATH,
g_variant_new_object_path ("/org/freedesktop/NetworkManager/Connections/5"));
/* Strip out the non-fixed portion of the filename */
filename = strstr (filename, "/callouts");
g_variant_builder_add (&props, "{sv}",
"filename",
g_variant_new_string (filename));
if (g_key_file_get_boolean (kf, "main", "external", NULL)) {
g_variant_builder_add (&props, "{sv}",
"external",
g_variant_new_boolean (TRUE));
}
*out_con_props = g_variant_builder_end (&props);
return TRUE;
@ -183,6 +198,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}"));
@ -196,12 +212,12 @@ parse_ip4 (GKeyFile *kf, GVariant **out_props, const char *section, GError **err
split = g_strsplit_set (tmp, " ", -1);
g_free (tmp);
if (g_strv_length (split) > 0) {
if (split && g_strv_length (split) > 0) {
for (iter = split; iter && *iter; iter++)
g_strstrip (*iter);
g_variant_builder_add (&props, "{sv}", "domains", g_variant_new_strv ((gpointer) split, -1));
g_strfreev (split);
}
g_strfreev (split);
/* nameservers */
if (!add_uint_array (kf, &props, "ip4", "nameservers", error))
@ -217,38 +233,37 @@ parse_ip4 (GKeyFile *kf, GVariant **out_props, const char *section, GError **err
split = g_strsplit_set (tmp, ",", -1);
g_free (tmp);
if (g_strv_length (split) > 0) {
addresses = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip4_address_unref);
if (split && g_strv_length (split) > 0) {
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 ();
ip = *iter;
p = strchr (*iter, '/');
g_assert (p);
*p++ = '\0';
prefix = strchr (ip, '/');
g_assert (prefix);
*prefix++ = '\0';
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));
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);
@ -260,38 +275,37 @@ parse_ip4 (GKeyFile *kf, GVariant **out_props, const char *section, GError **err
split = g_strsplit_set (tmp, ",", -1);
g_free (tmp);
if (g_strv_length (split) > 0) {
routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip4_route_unref);
if (split && g_strv_length (split) > 0) {
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 ();
dest = *iter;
p = strchr (*iter, '/');
g_assert (p);
*p++ = '\0';
prefix = strchr (dest, '/');
g_assert (prefix);
*prefix++ = '\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));
next_hop = strchr (prefix, ' ');
g_assert (next_hop);
next_hop++;
p = strchr (p, ' ');
g_assert (p);
p++;
g_assert_cmpint (inet_pton (AF_INET, p, &a), ==, 1);
nm_ip4_route_set_next_hop (route, a);
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);
}
@ -322,11 +336,15 @@ parse_dhcp (GKeyFile *kf,
g_variant_builder_init (&props, G_VARIANT_TYPE ("a{sv}"));
for (iter = keys; iter && *iter; iter++) {
val = g_key_file_get_string (kf, group_name, *iter, error);
if (!val)
if (!val) {
g_strfreev (keys);
g_variant_builder_clear (&props);
return FALSE;
}
g_variant_builder_add (&props, "{sv}", *iter, g_variant_new_string (val));
g_free (val);
}
g_strfreev (keys);
*out_props = g_variant_builder_end (&props);
return TRUE;
@ -353,11 +371,27 @@ get_dispatcher_file (const char *file,
gboolean success = FALSE;
char **keys, **iter, *val;
g_assert (!error || !*error);
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_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_ip4_props && !*out_vpn_ip4_props);
g_assert (out_vpn_ip6_props && !*out_vpn_ip6_props);
g_assert (out_expected_iface && !*out_expected_iface);
g_assert (out_action && !*out_action);
g_assert (out_env && !*out_env);
kf = g_key_file_new ();
if (!g_key_file_load_from_file (kf, file, G_KEY_FILE_NONE, error))
return FALSE;
if (!parse_main (kf,
file,
out_con_dict,
out_con_props,
out_expected_iface,
@ -380,7 +414,7 @@ get_dispatcher_file (const char *file,
}
if (g_key_file_has_group (kf, "dhcp6")) {
if (!parse_dhcp (kf, "dhcp6", out_device_dhcp4_props, error))
if (!parse_dhcp (kf, "dhcp6", out_device_dhcp6_props, error))
goto out;
}
@ -505,6 +539,7 @@ test_generic (const char *file, const char *override_vpn_ip_iface)
g_assert_cmpstr (expected_iface, ==, out_iface);
g_strfreev (denv);
g_free (out_iface);
g_free (vpn_ip_iface);
g_free (expected_iface);
@ -530,27 +565,33 @@ test_generic (const char *file, const char *override_vpn_ip_iface)
/*******************************************/
static void
test_old_up (void)
test_up (void)
{
test_generic ("dispatcher-old-up", NULL);
test_generic ("dispatcher-up", NULL);
}
static void
test_old_down (void)
test_down (void)
{
test_generic ("dispatcher-old-down", NULL);
test_generic ("dispatcher-down", NULL);
}
static void
test_old_vpn_up (void)
test_vpn_up (void)
{
test_generic ("dispatcher-old-vpn-up", NULL);
test_generic ("dispatcher-vpn-up", NULL);
}
static void
test_old_vpn_down (void)
test_vpn_down (void)
{
test_generic ("dispatcher-old-vpn-down", NULL);
test_generic ("dispatcher-vpn-down", NULL);
}
static void
test_external (void)
{
test_generic ("dispatcher-external", NULL);
}
static void
@ -559,7 +600,7 @@ test_up_empty_vpn_iface (void)
/* Test that an empty VPN iface variable, like is passed through D-Bus
* from NM, is ignored by the dispatcher environment construction code.
*/
test_generic ("dispatcher-old-up", "");
test_generic ("dispatcher-up", "");
}
/*******************************************/
@ -573,10 +614,11 @@ main (int argc, char **argv)
g_type_init ();
#endif
g_test_add_func ("/dispatcher/old_up", test_old_up);
g_test_add_func ("/dispatcher/old_down", test_old_down);
g_test_add_func ("/dispatcher/old_vpn_up", test_old_vpn_up);
g_test_add_func ("/dispatcher/old_vpn_down", test_old_vpn_down);
g_test_add_func ("/dispatcher/up", test_up);
g_test_add_func ("/dispatcher/down", test_down);
g_test_add_func ("/dispatcher/vpn_up", test_vpn_up);
g_test_add_func ("/dispatcher/vpn_down", test_vpn_down);
g_test_add_func ("/dispatcher/external", test_external);
g_test_add_func ("/dispatcher/up_empty_vpn_iface", test_up_empty_vpn_iface);

View file

@ -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

252
clients/cli/agent.c Normal file
View file

@ -0,0 +1,252 @@
/*
* 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)
{
g_printerr (_("Usage: nmcli agent { COMMAND | help }\n\n"
"COMMAND := { secret | polkit | all }\n\n"
));
}
static void
usage_agent_secret (void)
{
g_printerr (_("Usage: nmcli agent secret { help }\n"
"\n"
"Runs nmcli as NetworkManager secret agent. When NetworkManager requires\n"
"a password it asks registered agents for it. This command keeps nmcli running\n"
"and if a password is required asks the user for it.\n\n"));
}
static void
usage_agent_polkit (void)
{
g_printerr (_("Usage: nmcli agent polkit { help }\n"
"\n"
"Registers nmcli as a polkit action for the user session.\n"
"When a polkit daemon requires an authorization, nmcli asks the user and gives\n"
"the response back to polkit.\n\n"));
}
static void
usage_agent_all (void)
{
g_printerr (_("Usage: nmcli agent all { help }\n"
"\n"
"Runs nmcli as both NetworkManager secret and a polkit agent.\n\n"));
}
/* for pre-filling a string to readline prompt */
static char *pre_input_deftext;
static int
set_deftext (void)
{
if (pre_input_deftext && rl_startup_hook) {
rl_insert_text (pre_input_deftext);
g_free (pre_input_deftext);
pre_input_deftext = NULL;
rl_startup_hook = NULL;
}
return 0;
}
static gboolean
get_secrets_from_user (const char *request_id,
const char *title,
const char *msg,
GPtrArray *secrets)
{
int i;
for (i = 0; i < secrets->len; i++) {
NMSecretAgentSimpleSecret *secret = secrets->pdata[i];
char *pwd = NULL;
/* Ask user for the password */
g_print ("%s\n", msg);
if (secret->value) {
/* Prefill the password if we have it. */
rl_startup_hook = set_deftext;
pre_input_deftext = g_strdup (secret->value);
}
pwd = nmc_readline ("%s (%s): ", secret->name, secret->prop_name);
/* No password provided, cancel the secrets. */
if (!pwd)
return FALSE;
g_free (secret->value);
secret->value = pwd;
}
return TRUE;
}
static void
secrets_requested (NMSecretAgentSimple *agent,
const char *request_id,
const char *title,
const char *msg,
GPtrArray *secrets,
gpointer user_data)
{
NmCli *nmc = (NmCli *) user_data;
gboolean success = FALSE;
if (nmc->print_output == NMC_PRINT_PRETTY)
nmc_terminal_erase_line ();
success = get_secrets_from_user (request_id, title, msg, secrets);
if (success)
nm_secret_agent_simple_response (agent, request_id, secrets);
else
nm_secret_agent_simple_response (agent, request_id, NULL);
}
static NMCResultCode
do_agent_secret (NmCli *nmc, int argc, char **argv)
{
/* Create secret agent */
nmc->secret_agent = nm_secret_agent_simple_new ("nmcli-agent");
if (nmc->secret_agent) {
/* We keep running */
nmc->should_wait = TRUE;
nm_secret_agent_simple_enable (NM_SECRET_AGENT_SIMPLE (nmc->secret_agent), NULL);
g_signal_connect (nmc->secret_agent, "request-secrets", G_CALLBACK (secrets_requested), nmc);
g_print (_("nmcli successfully registered as a NetworkManager's secret agent.\n"));
} else {
g_string_printf (nmc->return_text, _("Error: secret agent initialization failed"));
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
}
return nmc->return_value;
}
static NMCResultCode
do_agent_polkit (NmCli *nmc, int argc, char **argv)
{
GError *error = NULL;
/* Initialize polkit agent */
if (!nmc_polkit_agent_init (nmc, TRUE, &error)) {
g_dbus_error_strip_remote_error (error);
g_string_printf (nmc->return_text, _("Error: polkit agent initialization failed: %s"),
error->message);
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
g_error_free (error);
} else {
/* We keep running */
nmc->should_wait = TRUE;
g_print (_("nmcli successfully registered as a polkit agent.\n"));
}
return nmc->return_value;
}
static NMCResultCode
do_agent_all (NmCli *nmc, int argc, char **argv)
{
NMCResultCode secret_res;
/* Run both secret and polkit agent */
secret_res = do_agent_secret (nmc, argc, argv);
if (secret_res != NMC_RESULT_SUCCESS)
g_printerr ("%s\n", nmc->return_text->str);
nmc->return_value = do_agent_polkit (nmc, argc, argv);
if (nmc->return_value == NMC_RESULT_SUCCESS && secret_res != NMC_RESULT_SUCCESS)
nmc->return_value = secret_res;
return nmc->return_value;
}
NMCResultCode
do_agent (NmCli *nmc, int argc, char **argv)
{
/* Get NMClient object */
nmc->get_client (nmc);
/* Check whether NetworkManager is running */
if (!nm_client_get_nm_running (nmc->client)) {
g_string_printf (nmc->return_text, _("Error: NetworkManager is not running."));
nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING;
return nmc->return_value;
}
/* Compare NM and nmcli versions */
if (!nmc_versions_match (nmc))
return nmc->return_value;
if (argc == 0) {
nmc->return_value = do_agent_all (nmc, 0, NULL);
}
if (argc > 0) {
if (nmc_arg_is_help (*argv)) {
usage ();
goto usage_exit;
} else if (matches (*argv, "secret") == 0) {
if (nmc_arg_is_help (*(argv+1))) {
usage_agent_secret ();
goto usage_exit;
}
nmc->return_value = do_agent_secret (nmc, argc-1, argv+1);
} else if (matches (*argv, "polkit") == 0) {
if (nmc_arg_is_help (*(argv+1))) {
usage_agent_polkit ();
goto usage_exit;
}
nmc->return_value = do_agent_polkit (nmc, argc-1, argv+1);
} else if (matches (*argv, "all") == 0) {
if (nmc_arg_is_help (*(argv+1))) {
usage_agent_all ();
goto usage_exit;
}
nmc->return_value = do_agent_all (nmc, argc-1, argv+1);
} else {
usage ();
g_string_printf (nmc->return_text, _("Error: 'agent' command '%s' is not valid."), *argv);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
}
}
usage_exit:
return nmc->return_value;
}

View file

@ -1,5 +1,6 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager -- Network link manager
/*
* 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
@ -15,22 +16,14 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright (C) 2012 Red Hat, Inc.
* Copyright 2014 Red Hat, Inc.
*/
#ifndef __NETWORKMANAGER_POSIX_SIGNALS_H__
#define __NETWORKMANAGER_POSIX_SIGNALS_H__
#ifndef __NMC_AGENT_H__
#define __NMC_AGENT_H__
#include <glib.h>
#include <signal.h>
#include "nmcli.h"
/*
* This function can be used in g_spawn_* as GSpawnChildSetupFunc()
* callback.
*/
void nm_unblock_posix_signals (gpointer user_data);
NMCResultCode do_agent (NmCli *nmc, int argc, char **argv);
void nm_save_original_signal_mask (sigset_t sig_mask);
const sigset_t *nm_get_original_signal_mask (void);
#endif /* __NETWORKMANAGER_POSIX_SIGNALS_H__ */
#endif /* __NMC_AGENT_H__ */

View file

@ -30,6 +30,8 @@
#include <readline/readline.h>
#include <readline/history.h>
#include "nm-glib-compat.h"
#include "common.h"
#include "utils.h"
@ -37,13 +39,14 @@
NmcOutputField nmc_fields_ip4_config[] = {
{"GROUP", N_("GROUP"), 15}, /* 0 */
{"ADDRESS", N_("ADDRESS"), 68}, /* 1 */
{"ROUTE", N_("ROUTE"), 68}, /* 2 */
{"DNS", N_("DNS"), 35}, /* 3 */
{"DOMAIN", N_("DOMAIN"), 35}, /* 4 */
{"WINS", N_("WINS"), 20}, /* 5 */
{"GATEWAY", N_("GATEWAY"), 0}, /* 2 */
{"ROUTE", N_("ROUTE"), 68}, /* 3 */
{"DNS", N_("DNS"), 35}, /* 4 */
{"DOMAIN", N_("DOMAIN"), 35}, /* 5 */
{"WINS", N_("WINS"), 20}, /* 6 */
{NULL, NULL, 0}
};
#define NMC_FIELDS_IP4_CONFIG_ALL "GROUP,ADDRESS,ROUTE,DNS,DOMAIN,WINS"
#define NMC_FIELDS_IP4_CONFIG_ALL "GROUP,ADDRESS,GATEWAY,ROUTE,DNS,DOMAIN,WINS"
/* Available fields for DHCPv4 group */
NmcOutputField nmc_fields_dhcp4_config[] = {
@ -57,12 +60,13 @@ NmcOutputField nmc_fields_dhcp4_config[] = {
NmcOutputField nmc_fields_ip6_config[] = {
{"GROUP", N_("GROUP"), 15}, /* 0 */
{"ADDRESS", N_("ADDRESS"), 95}, /* 1 */
{"ROUTE", N_("ROUTE"), 95}, /* 2 */
{"DNS", N_("DNS"), 60}, /* 3 */
{"DOMAIN", N_("DOMAIN"), 35}, /* 4 */
{"GATEWAY", N_("GATEWAY"), 0}, /* 2 */
{"ROUTE", N_("ROUTE"), 95}, /* 3 */
{"DNS", N_("DNS"), 60}, /* 4 */
{"DOMAIN", N_("DOMAIN"), 35}, /* 5 */
{NULL, NULL, 0}
};
#define NMC_FIELDS_IP6_CONFIG_ALL "GROUP,ADDRESS,ROUTE,DNS,DOMAIN"
#define NMC_FIELDS_IP6_CONFIG_ALL "GROUP,ADDRESS,GATEWAY,ROUTE,DNS,DOMAIN"
/* Available fields for DHCPv6 group */
NmcOutputField nmc_fields_dhcp6_config[] = {
@ -74,7 +78,7 @@ NmcOutputField nmc_fields_dhcp6_config[] = {
gboolean
print_ip4_config (NMIP4Config *cfg4,
print_ip4_config (NMIPConfig *cfg4,
NmCli *nmc,
const char *group_prefix,
const char *one_field)
@ -100,62 +104,58 @@ print_ip4_config (NMIP4Config *cfg4,
g_ptr_array_add (nmc->output_data, arr);
/* addresses */
ptr_array = nm_ip4_config_get_addresses (cfg4);
ptr_array = nm_ip_config_get_addresses (cfg4);
if (ptr_array) {
addr_arr = g_new (char *, ptr_array->len + 1);
for (i = 0; i < ptr_array->len; i++) {
NMIP4Address *addr = (NMIP4Address *) g_ptr_array_index (ptr_array, i);
guint32 prefix;
char *ip_str, *gw_str;
NMIPAddress *addr = (NMIPAddress *) g_ptr_array_index (ptr_array, i);
ip_str = nmc_ip4_address_as_string (nm_ip4_address_get_address (addr), NULL);
prefix = nm_ip4_address_get_prefix (addr);
gw_str = nmc_ip4_address_as_string (nm_ip4_address_get_gateway (addr), NULL);
addr_arr[i] = g_strdup_printf ("ip = %s/%u, gw = %s", ip_str, prefix, gw_str);
g_free (ip_str);
g_free (gw_str);
addr_arr[i] = g_strdup_printf ("%s/%u",
nm_ip_address_get_address (addr),
nm_ip_address_get_prefix (addr));
}
addr_arr[i] = NULL;
}
/* routes */
ptr_array = nm_ip4_config_get_routes (cfg4);
ptr_array = nm_ip_config_get_routes (cfg4);
if (ptr_array) {
route_arr = g_new (char *, ptr_array->len + 1);
for (i = 0; i < ptr_array->len; i++) {
NMIP4Route *route = (NMIP4Route *) g_ptr_array_index (ptr_array, i);
guint32 prefix, metric;
char *dest_str, *nexthop_str;
NMIPRoute *route = (NMIPRoute *) g_ptr_array_index (ptr_array, i);
const char *next_hop;
dest_str = nmc_ip4_address_as_string (nm_ip4_route_get_dest (route), NULL);
nexthop_str = nmc_ip4_address_as_string (nm_ip4_route_get_next_hop (route), NULL);
prefix = nm_ip4_route_get_prefix (route);
metric = nm_ip4_route_get_metric (route);
next_hop = nm_ip_route_get_next_hop (route);
if (!next_hop)
next_hop = "0.0.0.0";
route_arr[i] = g_strdup_printf ("dst = %s/%u, nh = %s, mt = %u", dest_str, prefix, nexthop_str, metric);
g_free (dest_str);
g_free (nexthop_str);
route_arr[i] = g_strdup_printf ("dst = %s/%u, nh = %s%c mt = %u",
nm_ip_route_get_dest (route),
nm_ip_route_get_prefix (route),
next_hop,
nm_ip_route_get_metric (route) == -1 ? '\0' : ',',
(guint32) nm_ip_route_get_metric (route));
}
route_arr[i] = NULL;
}
/* DNS */
dns_arr = g_strdupv ((char **) nm_ip4_config_get_nameservers (cfg4));
dns_arr = g_strdupv ((char **) nm_ip_config_get_nameservers (cfg4));
/* domains */
domain_arr = g_strdupv ((char **) nm_ip4_config_get_domains (cfg4));
domain_arr = g_strdupv ((char **) nm_ip_config_get_domains (cfg4));
/* WINS */
wins_arr = g_strdupv ((char **) nm_ip4_config_get_wins_servers (cfg4));
wins_arr = g_strdupv ((char **) nm_ip_config_get_wins_servers (cfg4));
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX);
set_val_strc (arr, 0, group_prefix);
set_val_arr (arr, 1, addr_arr);
set_val_arr (arr, 2, route_arr);
set_val_arr (arr, 3, dns_arr);
set_val_arr (arr, 4, domain_arr);
set_val_arr (arr, 5, wins_arr);
set_val_strc (arr, 2, nm_ip_config_get_gateway (cfg4));
set_val_arr (arr, 3, route_arr);
set_val_arr (arr, 4, dns_arr);
set_val_arr (arr, 5, domain_arr);
set_val_arr (arr, 6, wins_arr);
g_ptr_array_add (nmc->output_data, arr);
print_data (nmc); /* Print all data */
@ -167,7 +167,7 @@ print_ip4_config (NMIP4Config *cfg4,
}
gboolean
print_ip6_config (NMIP6Config *cfg6,
print_ip6_config (NMIPConfig *cfg6,
NmCli *nmc,
const char *group_prefix,
const char *one_field)
@ -192,58 +192,54 @@ print_ip6_config (NMIP6Config *cfg6,
g_ptr_array_add (nmc->output_data, arr);
/* addresses */
ptr_array = nm_ip6_config_get_addresses (cfg6);
ptr_array = nm_ip_config_get_addresses (cfg6);
if (ptr_array) {
addr_arr = g_new (char *, ptr_array->len + 1);
for (i = 0; i < ptr_array->len; i++) {
NMIP6Address *addr = (NMIP6Address *) g_ptr_array_index (ptr_array, i);
guint32 prefix;
char *ip_str, *gw_str;
NMIPAddress *addr = (NMIPAddress *) g_ptr_array_index (ptr_array, i);
ip_str = nmc_ip6_address_as_string (nm_ip6_address_get_address (addr), NULL);
prefix = nm_ip6_address_get_prefix (addr);
gw_str = nmc_ip6_address_as_string (nm_ip6_address_get_gateway (addr), NULL);
addr_arr[i] = g_strdup_printf ("ip = %s/%u, gw = %s", ip_str, prefix, gw_str);
g_free (ip_str);
g_free (gw_str);
addr_arr[i] = g_strdup_printf ("%s/%u",
nm_ip_address_get_address (addr),
nm_ip_address_get_prefix (addr));
}
addr_arr[i] = NULL;
}
/* routes */
ptr_array = nm_ip6_config_get_routes (cfg6);
ptr_array = nm_ip_config_get_routes (cfg6);
if (ptr_array) {
route_arr = g_new (char *, ptr_array->len + 1);
for (i = 0; i < ptr_array->len; i++) {
NMIP6Route *route = (NMIP6Route *) g_ptr_array_index (ptr_array, i);
guint32 prefix, metric;
char *dest_str, *nexthop_str;
NMIPRoute *route = (NMIPRoute *) g_ptr_array_index (ptr_array, i);
const char *next_hop;
dest_str = nmc_ip6_address_as_string (nm_ip6_route_get_dest (route), NULL);
nexthop_str = nmc_ip6_address_as_string (nm_ip6_route_get_next_hop (route), NULL);
prefix = nm_ip6_route_get_prefix (route);
metric = nm_ip6_route_get_metric (route);
next_hop = nm_ip_route_get_next_hop (route);
if (!next_hop)
next_hop = "::";
route_arr[i] = g_strdup_printf ("dst = %s/%u, nh = %s, mt = %u", dest_str, prefix, nexthop_str, metric);
g_free (dest_str);
g_free (nexthop_str);
route_arr[i] = g_strdup_printf ("dst = %s/%u, nh = %s%c mt = %u",
nm_ip_route_get_dest (route),
nm_ip_route_get_prefix (route),
next_hop,
nm_ip_route_get_metric (route) == -1 ? '\0' : ',',
(guint32) nm_ip_route_get_metric (route));
}
route_arr[i] = NULL;
}
/* DNS */
dns_arr = g_strdupv ((char **) nm_ip6_config_get_nameservers (cfg6));
dns_arr = g_strdupv ((char **) nm_ip_config_get_nameservers (cfg6));
/* domains */
domain_arr = g_strdupv ((char **) nm_ip6_config_get_domains (cfg6));
domain_arr = g_strdupv ((char **) nm_ip_config_get_domains (cfg6));
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX);
set_val_strc (arr, 0, group_prefix);
set_val_arr (arr, 1, addr_arr);
set_val_arr (arr, 2, route_arr);
set_val_arr (arr, 3, dns_arr);
set_val_arr (arr, 4, domain_arr);
set_val_strc (arr, 2, nm_ip_config_get_gateway (cfg6));
set_val_arr (arr, 3, route_arr);
set_val_arr (arr, 4, dns_arr);
set_val_arr (arr, 5, domain_arr);
g_ptr_array_add (nmc->output_data, arr);
print_data (nmc); /* Print all data */
@ -255,7 +251,7 @@ print_ip6_config (NMIP6Config *cfg6,
}
gboolean
print_dhcp4_config (NMDhcp4Config *dhcp4,
print_dhcp4_config (NMDhcpConfig *dhcp4,
NmCli *nmc,
const char *group_prefix,
const char *one_field)
@ -267,7 +263,7 @@ print_dhcp4_config (NMDhcp4Config *dhcp4,
if (dhcp4 == NULL)
return FALSE;
table = nm_dhcp4_config_get_options (dhcp4);
table = nm_dhcp_config_get_options (dhcp4);
if (table) {
GHashTableIter table_iter;
gpointer key, value;
@ -303,7 +299,7 @@ print_dhcp4_config (NMDhcp4Config *dhcp4,
}
gboolean
print_dhcp6_config (NMDhcp6Config *dhcp6,
print_dhcp6_config (NMDhcpConfig *dhcp6,
NmCli *nmc,
const char *group_prefix,
const char *one_field)
@ -315,7 +311,7 @@ print_dhcp6_config (NMDhcp6Config *dhcp6,
if (dhcp6 == NULL)
return FALSE;
table = nm_dhcp6_config_get_options (dhcp6);
table = nm_dhcp_config_get_options (dhcp6);
if (table) {
GHashTableIter table_iter;
gpointer key, value;
@ -351,18 +347,19 @@ print_dhcp6_config (NMDhcp6Config *dhcp6,
}
/*
* Parse IPv4 address from string to NMIP4Address stucture.
* ip_str is the IPv4 address in the form address/prefix
* gw_str is the gateway address (it is optional)
* Parse IP address from string to NMIPAddress stucture.
* ip_str is the IP address in the form address/prefix
*/
NMIP4Address *
nmc_parse_and_build_ip4_address (const char *ip_str, const char *gw_str, GError **error)
NMIPAddress *
nmc_parse_and_build_address (int family, const char *ip_str, GError **error)
{
NMIP4Address *addr = NULL;
guint32 ip4_addr, gw_addr;
int max_prefix = (family == AF_INET) ? 32 : 128;
NMIPAddress *addr = NULL;
const char *ip;
char *tmp;
char *plen;
long int prefix;
GError *local = NULL;
g_return_val_if_fail (ip_str != NULL, NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
@ -372,158 +369,71 @@ nmc_parse_and_build_ip4_address (const char *ip_str, const char *gw_str, GError
if (plen)
*plen++ = '\0';
if (inet_pton (AF_INET, tmp, &ip4_addr) < 1) {
g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
_("invalid IPv4 address '%s'"), tmp);
goto finish;
}
ip = tmp;
prefix = 32;
prefix = max_prefix;
if (plen) {
if (!nmc_string_to_int (plen, TRUE, 1, 32, &prefix)) {
if (!nmc_string_to_int (plen, TRUE, 1, max_prefix, &prefix)) {
g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
_("invalid prefix '%s'; <1-32> allowed"), plen);
_("invalid prefix '%s'; <1-%d> allowed"), plen, max_prefix);
goto finish;
}
}
if (inet_pton (AF_INET, gw_str ? gw_str : "0.0.0.0", &gw_addr) < 1) {
addr = nm_ip_address_new (family, ip, (guint32) prefix, &local);
if (!addr) {
g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
_("invalid gateway '%s'"), gw_str);
goto finish;
_("invalid IP address: %s"), local->message);
g_clear_error (&local);
}
addr = nm_ip4_address_new ();
nm_ip4_address_set_address (addr, ip4_addr);
nm_ip4_address_set_prefix (addr, (guint32) prefix);
nm_ip4_address_set_gateway (addr, gw_addr);
finish:
g_free (tmp);
return addr;
}
/*
* Parse IPv6 address from string to NMIP6Address stucture.
* ip_str is the IPv6 address in the form address/prefix
* gw_str is the gateway address (it is optional)
*/
NMIP6Address *
nmc_parse_and_build_ip6_address (const char *ip_str, const char *gw_str, GError **error)
{
NMIP6Address *addr = NULL;
struct in6_addr ip_addr, gw_addr;
char *tmp;
char *plen;
long int prefix;
g_return_val_if_fail (ip_str != NULL, NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
tmp = g_strdup (ip_str);
plen = strchr (tmp, '/'); /* prefix delimiter */
if (plen)
*plen++ = '\0';
if (inet_pton (AF_INET6, tmp, &ip_addr) < 1) {
g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
_("invalid IPv6 address '%s'"), tmp);
goto finish;
}
prefix = 128;
if (plen) {
if (!nmc_string_to_int (plen, TRUE, 1, 128, &prefix)) {
g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
_("invalid prefix '%s'; <1-128> allowed"), plen);
goto finish;
}
}
if (inet_pton (AF_INET6, gw_str ? gw_str : "::", &gw_addr) < 1) {
g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
_("invalid gateway '%s'"), gw_str);
goto finish;
}
addr = nm_ip6_address_new ();
nm_ip6_address_set_address (addr, &ip_addr);
nm_ip6_address_set_prefix (addr, (guint32) prefix);
nm_ip6_address_set_gateway (addr, &gw_addr);
finish:
g_free (tmp);
return addr;
}
typedef struct {
long int prefix;
long int metric;
union _IpDest {
guint32 ip4_dst;
struct in6_addr ip6_dst;
} dst;
union _IpNextHop {
guint32 ip4_nh;
struct in6_addr ip6_nh;
} nh;
} ParsedRoute;
/*
* _parse_and_build_route:
* nmc_parse_and_build_route:
* @family: AF_INET or AF_INET6
* @first: the route destination in the form of "address/prefix"
(/prefix is optional)
* @second: (allow-none): next hop address, if third is not NULL. Otherwise it could be
either next hop address or metric. (It can be NULL when @third is NULL).
* @third: (allow-none): route metric
* @out: (out): route struct to fill
* @error: location to store GError
*
* Parse route from strings and fill @out parameter.
* Parse route from strings and return an #NMIPRoute
*
* Returns: %TRUE on success, %FALSE on failure
*/
static gboolean
_parse_and_build_route (int family,
const char *first,
const char *second,
const char *third,
ParsedRoute *out,
GError **error)
NMIPRoute *
nmc_parse_and_build_route (int family,
const char *first,
const char *second,
const char *third,
GError **error)
{
int max_prefix;
char *tmp, *plen;
int max_prefix = (family == AF_INET) ? 32 : 128;
char *dest = NULL, *plen = NULL;
const char *next_hop = NULL;
const char *canon_dest;
long int prefix = max_prefix, metric = -1;
NMIPRoute *route = NULL;
gboolean success = FALSE;
GError *local = NULL;
g_return_val_if_fail (family == AF_INET || family == AF_INET6, FALSE);
g_return_val_if_fail (first != NULL, FALSE);
g_return_val_if_fail (second || !third, FALSE);
g_return_val_if_fail (out, FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
max_prefix = (family == AF_INET) ? 32 : 128;
/* initialize default values */
out->prefix = max_prefix;
out->metric = 0;
if (family == AF_INET)
out->nh.ip4_nh = 0;
else
out->nh.ip6_nh = in6addr_any;
tmp = g_strdup (first);
plen = strchr (tmp, '/'); /* prefix delimiter */
dest = g_strdup (first);
plen = strchr (dest, '/'); /* prefix delimiter */
if (plen)
*plen++ = '\0';
if (inet_pton (family, tmp, family == AF_INET ? (void *) &out->dst.ip4_dst : (void *) &out->dst.ip6_dst) < 1) {
g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
_("invalid route destination address '%s'"), tmp);
goto finish;
}
if (plen) {
if (!nmc_string_to_int (plen, TRUE, 1, max_prefix, &out->prefix)) {
if (!nmc_string_to_int (plen, TRUE, 1, max_prefix, &prefix)) {
g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
_("invalid prefix '%s'; <1-%d> allowed"),
plen, max_prefix);
@ -532,113 +442,49 @@ _parse_and_build_route (int family,
}
if (second) {
if (inet_pton (family, second, family == AF_INET ? (void *) &out->nh.ip4_nh : (void *) &out->nh.ip6_nh) < 1) {
if (third) {
g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
_("invalid next hop address '%s'"), second);
if (third || nm_utils_ipaddr_valid (family, second))
next_hop = second;
else {
/* 'second' can be a metric */
if (!nmc_string_to_int (second, TRUE, 0, G_MAXUINT32, &metric)) {
g_set_error (error, 1, 0, _("the second component of route ('%s') is neither "
"a next hop address nor a metric"), second);
goto finish;
} else {
/* 'second' can be a metric */
if (!nmc_string_to_int (second, TRUE, 0, G_MAXUINT32, &out->metric)) {
g_set_error (error, 1, 0, _("the second component of route ('%s') is neither "
"a next hop address nor a metric"), second);
goto finish;
}
}
}
}
if (third) {
if (!nmc_string_to_int (third, TRUE, 0, G_MAXUINT32, &out->metric)) {
if (!nmc_string_to_int (third, TRUE, 0, G_MAXUINT32, &metric)) {
g_set_error (error, 1, 0, _("invalid metric '%s'"), third);
goto finish;
}
}
/* We don't accept default routes as NetworkManager handles it itself */
if ( (family == AF_INET && out->dst.ip4_dst == 0)
|| (family == AF_INET6 && IN6_IS_ADDR_UNSPECIFIED (&out->dst.ip6_dst))) {
route = nm_ip_route_new (family, dest, prefix, next_hop, metric, &local);
if (!route) {
g_set_error (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
_("invalid route: %s"), local->message);
g_clear_error (&local);
goto finish;
}
/* We don't accept default routes as NetworkManager handles it
* itself. But we have to check this after @route has normalized the
* dest string.
*/
canon_dest = nm_ip_route_get_dest (route);
if (!strcmp (canon_dest, "0.0.0.0") || !strcmp (canon_dest, "::")) {
g_set_error_literal (error, NMCLI_ERROR, NMC_RESULT_ERROR_USER_INPUT,
_("default route cannot be added (NetworkManager handles it by itself)"));
g_clear_pointer (&route, nm_ip_route_unref);
goto finish;
}
success = TRUE;
finish:
g_free (tmp);
return success;
}
/*
* nmc_parse_and_build_ip4_route:
* @first: the IPv4 route destination in the form of "address/prefix"
(/prefix is optional)
* @second: (allow-none): next hop address, if third is not NULL. Otherwise it could be
either next hop address or metric. (It can be NULL when @third is NULL).
* @third: (allow-none): route metric
* @error: location to store GError
*
* Parse IPv4 route from strings to NMIP4Route stucture.
*
* Returns: route as a NMIP4Route object, or %NULL on failure
*/
NMIP4Route *
nmc_parse_and_build_ip4_route (const char *first,
const char *second,
const char *third,
GError **error)
{
ParsedRoute tmp_route;
NMIP4Route *route = NULL;
g_return_val_if_fail (first != NULL, NULL);
g_return_val_if_fail (second || !third, NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
if (_parse_and_build_route (AF_INET, first, second, third, &tmp_route, error)) {
route = nm_ip4_route_new ();
nm_ip4_route_set_dest (route, tmp_route.dst.ip4_dst);
nm_ip4_route_set_prefix (route, (guint32) tmp_route.prefix);
nm_ip4_route_set_next_hop (route, tmp_route.nh.ip4_nh);
nm_ip4_route_set_metric (route, (guint32) tmp_route.metric);
}
return route;
}
/*
* nmc_parse_and_build_ip6_route:
* @first: the IPv6 route destination in the form of "address/prefix"
(/prefix is optional)
* @second: (allow-none): next hop address, if third is not NULL. Otherwise it could be
either next hop address or metric. (It can be NULL when @third is NULL).
* @third: (allow-none): route metric
* @error: location to store GError
*
* Parse IPv6 route from strings to NMIP6Route stucture.
*
* Returns: route as a NMIP6Route object, or %NULL on failure
*/
NMIP6Route *
nmc_parse_and_build_ip6_route (const char *first,
const char *second,
const char *third,
GError **error)
{
ParsedRoute tmp_route;
NMIP6Route *route = NULL;
g_return_val_if_fail (first != NULL, NULL);
g_return_val_if_fail (second || !third, NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
if (_parse_and_build_route (AF_INET6, first, second, third, &tmp_route, error)) {
route = nm_ip6_route_new ();
nm_ip6_route_set_dest (route, &tmp_route.dst.ip6_dst);
nm_ip6_route_set_prefix (route, (guint32) tmp_route.prefix);
nm_ip6_route_set_next_hop (route, &tmp_route.nh.ip6_nh);
nm_ip6_route_set_metric (route, (guint32) tmp_route.metric);
}
g_free (dest);
return route;
}
@ -1054,6 +900,93 @@ nmc_find_connection (const GPtrArray *connections,
return found;
}
static gboolean
get_secrets_from_user (const char *request_id,
const char *title,
const char *msg,
gboolean ask,
GHashTable *pwds_hash,
GPtrArray *secrets)
{
int i;
for (i = 0; i < secrets->len; i++) {
NMSecretAgentSimpleSecret *secret = secrets->pdata[i];
char *pwd = NULL;
/* First try to find the password in provided passwords file,
* then ask user. */
if (pwds_hash && (pwd = g_hash_table_lookup (pwds_hash, secret->prop_name))) {
pwd = g_strdup (pwd);
} else {
g_print ("%s\n", msg);
if (ask) {
if (secret->value) {
/* Prefill the password if we have it. */
rl_startup_hook = nmc_rl_set_deftext;
nmc_rl_pre_input_deftext = g_strdup (secret->value);
}
pwd = nmc_readline ("%s (%s): ", secret->name, secret->prop_name);
if (!pwd)
pwd = g_strdup ("");
} else {
g_printerr (_("Warning: password for '%s' not given in 'passwd-file' "
"and nmcli cannot ask without '--ask' option.\n"),
secret->prop_name);
}
}
/* No password provided, cancel the secrets. */
if (!pwd)
return FALSE;
g_free (secret->value);
secret->value = pwd;
}
return TRUE;
}
/**
* nmc_secrets_requested:
* @agent: the #NMSecretAgentSimple
* @request_id: request ID, to eventually pass to
* nm_secret_agent_simple_response()
* @title: a title for the password request
* @msg: a prompt message for the password request
* @secrets: (element-type #NMSecretAgentSimpleSecret): array of secrets
* being requested.
* @user_data: user data passed to the function
*
* This function is used as a callback for "request-secrets" signal of
* NMSecretAgentSimpleSecret.
*/
void
nmc_secrets_requested (NMSecretAgentSimple *agent,
const char *request_id,
const char *title,
const char *msg,
GPtrArray *secrets,
gpointer user_data)
{
NmCli *nmc = (NmCli *) user_data;
gboolean success = FALSE;
if (nmc->print_output == NMC_PRINT_PRETTY)
nmc_terminal_erase_line ();
success = get_secrets_from_user (request_id, title, msg, nmc->in_editor || nmc->ask,
nmc->pwds_hash, secrets);
if (success)
nm_secret_agent_simple_response (agent, request_id, secrets);
else {
/* Unregister our secret agent on failure, so that another agent
* may be tried */
if (nmc->secret_agent) {
nm_secret_agent_old_unregister (nmc->secret_agent, NULL, NULL);
g_clear_object (&nmc->secret_agent);
}
}
}
/**
* nmc_cleanup_readline:
*
@ -1196,3 +1129,18 @@ nmc_rl_gen_func_basic (const char *text, int state, const char **words)
return NULL;
}
/* for pre-filling a string to readline prompt */
char *nmc_rl_pre_input_deftext;
int
nmc_rl_set_deftext (void)
{
if (nmc_rl_pre_input_deftext && rl_startup_hook) {
rl_insert_text (nmc_rl_pre_input_deftext);
g_free (nmc_rl_pre_input_deftext);
nmc_rl_pre_input_deftext = NULL;
rl_startup_hook = NULL;
}
return 0;
}

View file

@ -16,24 +16,22 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* (C) Copyright 2012 - 2014 Red Hat, Inc.
* Copyright 2012 - 2014 Red Hat, Inc.
*/
#ifndef NMC_COMMON_H
#define NMC_COMMON_H
#include "nmcli.h"
#include "nm-secret-agent-simple.h"
gboolean print_ip4_config (NMIP4Config *cfg4, NmCli *nmc, const char *group_prefix, const char *one_field);
gboolean print_ip6_config (NMIP6Config *cfg6, NmCli *nmc, const char *group_prefix, const char *one_field);
gboolean print_dhcp4_config (NMDhcp4Config *dhcp4, NmCli *nmc, const char *group_prefix, const char *one_field);
gboolean print_dhcp6_config (NMDhcp6Config *dhcp6, NmCli *nmc, const char *group_prefix, const char *one_field);
gboolean print_ip4_config (NMIPConfig *cfg4, NmCli *nmc, const char *group_prefix, const char *one_field);
gboolean print_ip6_config (NMIPConfig *cfg6, NmCli *nmc, const char *group_prefix, const char *one_field);
gboolean print_dhcp4_config (NMDhcpConfig *dhcp4, NmCli *nmc, const char *group_prefix, const char *one_field);
gboolean print_dhcp6_config (NMDhcpConfig *dhcp6, NmCli *nmc, const char *group_prefix, const char *one_field);
NMIP4Address *nmc_parse_and_build_ip4_address (const char *ip_str, const char *gw_str, GError **error);
NMIP6Address *nmc_parse_and_build_ip6_address (const char *ip_str, const char *gw_str, GError **error);
NMIP4Route *nmc_parse_and_build_ip4_route (const char *first, const char *second, const char *third, GError **error);
NMIP6Route *nmc_parse_and_build_ip6_route (const char *first, const char *second, const char *third, GError **error);
NMIPAddress *nmc_parse_and_build_address (int family, const char *ip_str, GError **error);
NMIPRoute *nmc_parse_and_build_route (int family, const char *first, const char *second, const char *third, GError **error);
const char * nmc_device_state_to_string (NMDeviceState state);
const char * nmc_device_reason_to_string (NMDeviceStateReason reason);
@ -51,10 +49,21 @@ NMConnection *nmc_find_connection (const GPtrArray *connections,
const char *filter_val,
int *start);
void nmc_secrets_requested (NMSecretAgentSimple *agent,
const char *request_id,
const char *title,
const char *msg,
GPtrArray *secrets,
gpointer user_data);
void nmc_cleanup_readline (void);
char *nmc_readline (const char *prompt_fmt, ...) G_GNUC_PRINTF (1, 2);
char *nmc_rl_gen_func_basic (const char *text, int state, const char **words);
gboolean nmc_get_in_readline (void);
void nmc_set_in_readline (gboolean in_readline);
/* for pre-filling a string to readline prompt */
extern char *nmc_rl_pre_input_deftext;
int nmc_rl_set_deftext (void);
#endif /* NMC_COMMON_H */

File diff suppressed because it is too large Load diff

View file

@ -28,6 +28,8 @@
#include <glib.h>
#include <glib/gi18n.h>
#include "nm-secret-agent-simple.h"
#include "polkit-agent.h"
#include "utils.h"
#include "common.h"
#include "devices.h"
@ -190,11 +192,12 @@ static NmcOutputField nmc_fields_dev_show_master_prop[] = {
/* Available fields for 'device show' - VLAN part */
static NmcOutputField nmc_fields_dev_show_vlan_prop[] = {
{"NAME", N_("NAME"), 18}, /* 0 */
{"ID", N_("ID"), 5}, /* 1 */
{"PARENT", N_("PARENT"), 10}, /* 1 */
{"ID", N_("ID"), 5}, /* 2 */
{NULL, NULL, 0}
};
#define NMC_FIELDS_DEV_SHOW_VLAN_PROP_ALL "NAME,ID"
#define NMC_FIELDS_DEV_SHOW_VLAN_PROP_COMMON "NAME,ID"
#define NMC_FIELDS_DEV_SHOW_VLAN_PROP_ALL "NAME,PARENT,ID"
#define NMC_FIELDS_DEV_SHOW_VLAN_PROP_COMMON "NAME,PARENT,ID"
/* Available fields for 'device show' - BLUETOOTH part */
static NmcOutputField nmc_fields_dev_show_bluetooth[] = {
@ -433,6 +436,60 @@ get_devices_sorted (NMClient *client)
return sorted;
}
static int
compare_aps (gconstpointer a, gconstpointer b, gpointer user_data)
{
NMAccessPoint *apa = *(NMAccessPoint **)a;
NMAccessPoint *apb = *(NMAccessPoint **)b;
int cmp;
cmp = nm_access_point_get_strength (apb) - nm_access_point_get_strength (apa);
if (cmp != 0)
return cmp;
cmp = nm_access_point_get_frequency (apa) - nm_access_point_get_frequency (apb);
if (cmp != 0)
return cmp;
return nm_access_point_get_max_bitrate (apb) - nm_access_point_get_max_bitrate (apa);
}
static GPtrArray *
sort_access_points (const GPtrArray *aps)
{
GPtrArray *sorted;
int i;
sorted = g_ptr_array_sized_new (aps->len);
for (i = 0; aps && i < aps->len; i++)
g_ptr_array_add (sorted, aps->pdata[i]);
g_ptr_array_sort_with_data (sorted, compare_aps, NULL);
return sorted;
}
typedef struct {
NmcTermColor color;
NmcTermFormat color_fmt;
} ColorInfo;
static ColorInfo
wifi_signal_to_color (guint8 strength)
{
ColorInfo color_info = { NMC_TERM_COLOR_NORMAL, NMC_TERM_FORMAT_NORMAL };
if (strength > 80)
color_info.color = NMC_TERM_COLOR_GREEN;
else if (strength > 55)
color_info.color = NMC_TERM_COLOR_YELLOW;
else if (strength > 30)
color_info.color = NMC_TERM_COLOR_MAGENTA;
else if (strength > 5)
color_info.color = NMC_TERM_COLOR_CYAN;
else
color_info.color_fmt = NMC_TERM_FORMAT_DIM;
return color_info;
}
static char *
ap_wpa_rsn_flags_to_string (NM80211ApSecurityFlags flags)
{
@ -502,6 +559,7 @@ fill_output_access_point (gpointer data, gpointer user_data)
GString *security_str;
char *ap_name;
const char *sig_bars;
ColorInfo color_info;
if (info->active_bssid) {
const char *current_bssid = nm_access_point_get_bssid (ap);
@ -587,6 +645,13 @@ fill_output_access_point (gpointer data, gpointer user_data)
set_val_strc (arr, 15, active ? "*" : " ");
set_val_strc (arr, 16, nm_object_get_path (NM_OBJECT (ap)));
/* Set colors */
color_info = wifi_signal_to_color (strength);
set_val_color_all (arr, color_info.color);
set_val_color_fmt_all (arr, color_info.color_fmt);
if (active)
arr[15].color = NMC_TERM_COLOR_GREEN;
g_ptr_array_add (info->nmc->output_data, arr);
g_string_free (security_str, FALSE);
@ -766,10 +831,8 @@ show_device_info (NMDevice *device, NmCli *nmc)
NmcOutputField *tmpl, *arr;
size_t tmpl_len;
gboolean was_output = FALSE;
NMIP4Config *cfg4;
NMIP6Config *cfg6;
NMDhcp4Config *dhcp4;
NMDhcp6Config *dhcp6;
NMIPConfig *cfg4, *cfg6;
NMDhcpConfig *dhcp4, *dhcp6;
const char *base_hdr = _("Device details");
GPtrArray *fields_in_section = NULL;
@ -892,7 +955,7 @@ show_device_info (NMDevice *device, NmCli *nmc)
NMDeviceWifiCapabilities wcaps;
NMAccessPoint *active_ap = NULL;
const char *active_bssid = NULL;
const GPtrArray *aps;
GPtrArray *aps;
/* section WIFI-PROPERTIES */
if (!strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[2].name)) {
@ -941,8 +1004,9 @@ show_device_info (NMDevice *device, NmCli *nmc)
info->output_flags = NMC_OF_FLAG_SECTION_PREFIX;
info->active_bssid = active_bssid;
info->device = nm_device_get_iface (device);
aps = nm_device_wifi_get_access_points (NM_DEVICE_WIFI (device));
aps = sort_access_points (nm_device_wifi_get_access_points (NM_DEVICE_WIFI (device)));
g_ptr_array_foreach ((GPtrArray *) aps, fill_output_access_point, (gpointer) info);
g_ptr_array_free (aps, FALSE);
g_free (info);
print_data (nmc); /* Print all data */
was_output = TRUE;
@ -1084,6 +1148,7 @@ show_device_info (NMDevice *device, NmCli *nmc)
if ((NM_IS_DEVICE_VLAN (device))) {
if (!strcasecmp (nmc_fields_dev_show_sections[section_idx].name, nmc_fields_dev_show_sections[14].name)) {
char * vlan_id_str = g_strdup_printf ("%u", nm_device_vlan_get_vlan_id (NM_DEVICE_VLAN (device)));
NMDevice *parent = nm_device_vlan_get_parent (NM_DEVICE_VLAN (device));
tmpl = nmc_fields_dev_show_vlan_prop;
tmpl_len = sizeof (nmc_fields_dev_show_vlan_prop);
@ -1094,7 +1159,8 @@ show_device_info (NMDevice *device, NmCli *nmc)
arr = nmc_dup_fields_array (tmpl, tmpl_len, NMC_OF_FLAG_SECTION_PREFIX);
set_val_strc (arr, 0, nmc_fields_dev_show_sections[14].name); /* "VLAN" */
set_val_str (arr, 1, vlan_id_str);
set_val_strc (arr, 1, parent ? nm_device_get_iface (parent) : NULL);
set_val_str (arr, 2, vlan_id_str);
g_ptr_array_add (nmc->output_data, arr);
print_data (nmc); /* Print all data */
@ -1185,15 +1251,27 @@ static void
fill_output_device_status (NMDevice *device, NmCli *nmc)
{
NMActiveConnection *ac;
NMDeviceState state;
NmcOutputField *arr = nmc_dup_fields_array (nmc_fields_dev_status,
sizeof (nmc_fields_dev_status),
0);
state = nm_device_get_state (device);
ac = nm_device_get_active_connection (device);
/* Show devices in color */
if (state <= NM_DEVICE_STATE_UNAVAILABLE)
set_val_color_fmt_all (arr, NMC_TERM_FORMAT_DIM);
else if (state == NM_DEVICE_STATE_DISCONNECTED)
set_val_color_all (arr, NMC_TERM_COLOR_RED);
else if (state >= NM_DEVICE_STATE_PREPARE && state <= NM_DEVICE_STATE_SECONDARIES)
set_val_color_all (arr, NMC_TERM_COLOR_YELLOW);
else if (state == NM_DEVICE_STATE_ACTIVATED)
set_val_color_all (arr, NMC_TERM_COLOR_GREEN);
set_val_strc (arr, 0, nm_device_get_iface (device));
set_val_strc (arr, 1, nm_device_get_type_description (device));
set_val_strc (arr, 2, nmc_device_state_to_string (nm_device_get_state (device)));
set_val_strc (arr, 2, nmc_device_state_to_string (state));
set_val_strc (arr, 3, nm_object_get_path (NM_OBJECT (device)));
set_val_strc (arr, 4, get_active_connection_id (device));
set_val_strc (arr, 5, ac ? nm_active_connection_get_uuid (ac) : NULL);
@ -1332,48 +1410,57 @@ progress_cb (gpointer user_data)
return TRUE;
}
static void connected_state_cb (NMDevice *device, NMActiveConnection *active);
static void
connected_state_cb (NMDevice *device, GParamSpec *pspec, gpointer user_data)
device_state_cb (NMDevice *device, GParamSpec *pspec, gpointer user_data)
{
NMActiveConnection *active = (NMActiveConnection *) user_data;
connected_state_cb (device, active);
}
static void
active_state_cb (NMActiveConnection *active, GParamSpec *pspec, gpointer user_data)
{
NMDevice *device = (NMDevice *) user_data;
connected_state_cb (device, active);
}
static void
connected_state_cb (NMDevice *device, NMActiveConnection *active)
{
NMDeviceState state;
NMDeviceStateReason reason;
NMActiveConnectionState ac_state;
state = nm_device_get_state (device);
ac_state = nm_active_connection_get_state (active);
if (ac_state == NM_ACTIVE_CONNECTION_STATE_ACTIVATING)
return;
if (state == NM_DEVICE_STATE_ACTIVATED) {
nmc_terminal_erase_line ();
g_print (_("Device '%s' successfully activated with '%s'.\n"),
nm_device_get_iface (device),
nm_active_connection_get_uuid (active));
g_object_unref (active);
quit ();
}
}
static void
monitor_device_state_cb (NMDevice *device, GParamSpec *pspec, gpointer user_data)
{
NmCli *nmc = (NmCli *) user_data;
NMDeviceState state;
NMDeviceStateReason reason;
state = nm_device_get_state (device);
if (state == NM_DEVICE_STATE_ACTIVATED) {
NMActiveConnection *active = nm_device_get_active_connection (device);
if (nmc->print_output == NMC_PRINT_PRETTY)
nmc_terminal_erase_line ();
g_print (_("Connection with UUID '%s' created and activated on device '%s'\n"),
nm_active_connection_get_uuid (active), nm_device_get_iface (device));
quit ();
} else if (state == NM_DEVICE_STATE_FAILED) {
} else if ( state <= NM_DEVICE_STATE_DISCONNECTED
|| state >= NM_DEVICE_STATE_DEACTIVATING) {
reason = nm_device_get_state_reason (device);
g_string_printf (nmc->return_text, _("Error: Connection activation failed: (%d) %s."),
reason, nmc_device_reason_to_string (reason));
nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION;
quit ();
}
g_print (_("Error: Connection activation failed: (%d) %s.\n"),
reason, nmc_device_reason_to_string (reason));
} else
return;
g_signal_handlers_disconnect_by_func (active, G_CALLBACK (active_state_cb), device);
g_signal_handlers_disconnect_by_func (device, G_CALLBACK (device_state_cb), active);
g_object_unref (active);
g_object_unref (device);
quit ();
}
typedef struct {
@ -1407,6 +1494,7 @@ add_and_activate_cb (GObject *client,
if (state == NM_ACTIVE_CONNECTION_STATE_UNKNOWN) {
g_string_printf (nmc->return_text, _("Error: Failed to add/activate new connection: Unknown error"));
nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION;
g_object_unref (active);
quit ();
}
@ -1421,12 +1509,14 @@ add_and_activate_cb (GObject *client,
g_object_unref (active);
quit ();
} else {
g_signal_connect (device, "notify::state", G_CALLBACK (monitor_device_state_cb), nmc);
g_object_ref (device);
g_signal_connect (device, "notify::state", G_CALLBACK (device_state_cb), active);
g_signal_connect (active, "notify::state", G_CALLBACK (active_state_cb), device);
g_timeout_add_seconds (nmc->timeout, timeout_cb, nmc); /* Exit if timeout expires */
if (nmc->print_output == NMC_PRINT_PRETTY)
progress_id = g_timeout_add (120, progress_cb, device);
g_object_unref (active);
}
}
@ -1488,6 +1578,7 @@ connect_device_cb (GObject *client, GAsyncResult *result, gpointer user_data)
if (devices->len == 0) {
g_string_printf (nmc->return_text, _("Error: Device activation failed: device was disconnected"));
nmc->return_value = NMC_RESULT_ERROR_CON_ACTIVATION;
g_object_unref (active);
quit ();
g_free (info);
return;
@ -1502,9 +1593,19 @@ connect_device_cb (GObject *client, GAsyncResult *result, gpointer user_data)
nmc_terminal_erase_line ();
g_print (_("Device '%s' has been connected.\n"), nm_device_get_iface (device));
}
g_object_unref (active);
quit ();
} else {
g_signal_connect (device, "notify::state", G_CALLBACK (connected_state_cb), active);
if (nmc->secret_agent) {
NMRemoteConnection *connection = nm_active_connection_get_connection (active);
nm_secret_agent_simple_enable (NM_SECRET_AGENT_SIMPLE (nmc->secret_agent),
nm_connection_get_path (NM_CONNECTION (connection)));
}
g_object_ref (device);
g_signal_connect (device, "notify::state", G_CALLBACK (device_state_cb), active);
g_signal_connect (active, "notify::state", G_CALLBACK (active_state_cb), device);
/* Start timer not to loop forever if "notify::state" signal is not issued */
g_timeout_add_seconds (nmc->timeout, timeout_cb, nmc);
}
@ -1574,6 +1675,11 @@ do_device_connect (NmCli *nmc, int argc, char **argv)
nmc->nowait_flag = (nmc->timeout == 0);
nmc->should_wait = TRUE;
/* Create secret agent */
nmc->secret_agent = nm_secret_agent_simple_new ("nmcli-connect");
if (nmc->secret_agent)
g_signal_connect (nmc->secret_agent, "request-secrets", G_CALLBACK (nmc_secrets_requested), nmc);
info = g_malloc0 (sizeof (AddAndActivateInfo));
info->nmc = nmc;
info->device = device;
@ -1599,17 +1705,28 @@ error:
static void
disconnect_state_cb (NMDevice *device, GParamSpec *pspec, gpointer user_data)
{
NmCli *nmc = (NmCli *) user_data;
NMDeviceState state;
state = nm_device_get_state (device);
if (state == NM_DEVICE_STATE_DISCONNECTED) {
g_string_printf (nmc->return_text, _("Success: Device '%s' successfully disconnected."), nm_device_get_iface (device));
g_signal_handlers_disconnect_by_data (device, user_data);
g_print (_("Device '%s' successfully disconnected.\n"),
nm_device_get_iface (device));
quit ();
}
}
static void
device_removed_cb (NMClient *client, NMDevice *device, gpointer user_data)
{
/* Success: device has been removed. It happens when disconnecting a software device. */
g_signal_handlers_disconnect_by_data (client, user_data);
g_print (_("Device '%s' successfully disconnected.\n"),
nm_device_get_iface (device));
quit ();
}
static void
disconnect_device_cb (GObject *object, GAsyncResult *result, gpointer user_data)
{
@ -1639,6 +1756,7 @@ disconnect_device_cb (GObject *object, GAsyncResult *result, gpointer user_data)
quit ();
} else {
g_signal_connect (device, "notify::state", G_CALLBACK (disconnect_state_cb), nmc);
g_signal_connect (nmc->client, NM_CLIENT_DEVICE_REMOVED, G_CALLBACK (device_removed_cb), nmc);
/* Start timer not to loop forever if "notify::state" signal is not issued */
g_timeout_add_seconds (nmc->timeout, timeout_cb, nmc);
}
@ -1814,7 +1932,7 @@ show_access_point_info (NMDevice *device, NmCli *nmc)
{
NMAccessPoint *active_ap = NULL;
const char *active_bssid = NULL;
const GPtrArray *aps;
GPtrArray *aps;
APInfo *info;
NmcOutputField *arr;
@ -1833,8 +1951,9 @@ show_access_point_info (NMDevice *device, NmCli *nmc)
info->output_flags = 0;
info->active_bssid = active_bssid;
info->device = nm_device_get_iface (device);
aps = nm_device_wifi_get_access_points (NM_DEVICE_WIFI (device));
aps = sort_access_points (nm_device_wifi_get_access_points (NM_DEVICE_WIFI (device)));
g_ptr_array_foreach ((GPtrArray *) aps, fill_output_access_point, (gpointer) info);
g_ptr_array_free (aps, FALSE);
print_data (nmc); /* Print all data */
nmc_empty_output_fields (nmc);
@ -2776,6 +2895,9 @@ do_devices (NmCli *nmc, int argc, char **argv)
{
GError *error = NULL;
/* Register polkit agent */
nmc_start_polkit_agent_start_try (nmc);
rl_attempted_completion_function = (rl_completion_func_t *) nmcli_device_tab_completion;
/* Get NMClient object early */

View file

@ -14,7 +14,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright 2010 - 2014 Red Hat, Inc.
* Copyright 2010 - 2015 Red Hat, Inc.
*/
#include "config.h"
@ -25,6 +25,7 @@
#include <glib.h>
#include <glib/gi18n.h>
#include "polkit-agent.h"
#include "utils.h"
#include "general.h"
@ -263,6 +264,26 @@ nm_state_to_string (NMState state)
}
}
static NmcTermColor
state_to_color (NMState state)
{
switch (state) {
case NM_STATE_CONNECTING:
return NMC_TERM_COLOR_YELLOW;
case NM_STATE_CONNECTED_LOCAL:
case NM_STATE_CONNECTED_SITE:
case NM_STATE_CONNECTED_GLOBAL:
return NMC_TERM_COLOR_GREEN;
case NM_STATE_DISCONNECTING:
return NMC_TERM_COLOR_YELLOW;
case NM_STATE_ASLEEP:
case NM_STATE_DISCONNECTED:
return NMC_TERM_COLOR_RED;
default:
return NMC_TERM_COLOR_NORMAL;
}
}
static const char *
nm_connectivity_to_string (NMConnectivityState connectivity)
{
@ -281,17 +302,33 @@ nm_connectivity_to_string (NMConnectivityState connectivity)
}
}
static NmcTermColor
connectivity_to_color (NMConnectivityState connectivity)
{
switch (connectivity) {
case NM_CONNECTIVITY_NONE:
return NMC_TERM_COLOR_RED;
case NM_CONNECTIVITY_PORTAL:
case NM_CONNECTIVITY_LIMITED:
return NMC_TERM_COLOR_YELLOW;
case NM_CONNECTIVITY_FULL:
return NMC_TERM_COLOR_GREEN;
default:
return NMC_TERM_COLOR_NORMAL;
}
}
static gboolean
show_nm_status (NmCli *nmc, const char *pretty_header_name, const char *print_flds)
{
gboolean startup = FALSE;
NMState state = NM_STATE_UNKNOWN;
NMConnectivityState connectivity = NM_CONNECTIVITY_UNKNOWN;
const char *net_enabled_str;
const char *wireless_hw_enabled_str, *wireless_enabled_str;
const char *wwan_hw_enabled_str, *wwan_enabled_str;
gboolean net_enabled;
gboolean wireless_hw_enabled, wireless_enabled;
gboolean wwan_hw_enabled, wwan_enabled;
#if WITH_WIMAX
const char *wimax_hw_enabled_str, *wimax_enabled_str;
gboolean wimax_hw_enabled, wimax_enabled;
#endif
GError *error = NULL;
const char *fields_str;
@ -332,14 +369,14 @@ show_nm_status (NmCli *nmc, const char *pretty_header_name, const char *print_fl
state = nm_client_get_state (nmc->client);
startup = nm_client_get_startup (nmc->client);
connectivity = nm_client_get_connectivity (nmc->client);
net_enabled_str = nm_client_networking_get_enabled (nmc->client) ? _("enabled") : _("disabled");
wireless_hw_enabled_str = nm_client_wireless_hardware_get_enabled (nmc->client) ? _("enabled") : _("disabled");
wireless_enabled_str = nm_client_wireless_get_enabled (nmc->client) ? _("enabled") : _("disabled");
wwan_hw_enabled_str = nm_client_wwan_hardware_get_enabled (nmc->client) ? _("enabled") : _("disabled");
wwan_enabled_str = nm_client_wwan_get_enabled (nmc->client) ? _("enabled") : _("disabled");
net_enabled = nm_client_networking_get_enabled (nmc->client);
wireless_hw_enabled = nm_client_wireless_hardware_get_enabled (nmc->client);
wireless_enabled = nm_client_wireless_get_enabled (nmc->client);
wwan_hw_enabled = nm_client_wwan_hardware_get_enabled (nmc->client);
wwan_enabled = nm_client_wwan_get_enabled (nmc->client);
#if WITH_WIMAX
wimax_hw_enabled_str = nm_client_wimax_hardware_get_enabled (nmc->client) ? _("enabled") : _("disabled");
wimax_enabled_str = nm_client_wimax_get_enabled (nmc->client) ? _("enabled") : _("disabled");
wimax_hw_enabled = nm_client_wimax_hardware_get_enabled (nmc->client);
wimax_enabled = nm_client_wimax_get_enabled (nmc->client);
#endif
nmc->print_fields.header_name = pretty_header_name ? (char *) pretty_header_name : _("NetworkManager status");
@ -352,15 +389,30 @@ show_nm_status (NmCli *nmc, const char *pretty_header_name, const char *print_fl
set_val_strc (arr, 2, nm_state_to_string (state));
set_val_strc (arr, 3, startup ? _("starting") : _("started"));
set_val_strc (arr, 4, nm_connectivity_to_string (connectivity));
set_val_strc (arr, 5, net_enabled_str);
set_val_strc (arr, 6, wireless_hw_enabled_str);
set_val_strc (arr, 7, wireless_enabled_str);
set_val_strc (arr, 8, wwan_hw_enabled_str);
set_val_strc (arr, 9, wwan_enabled_str);
set_val_strc (arr, 5, net_enabled ? _("enabled") : _("disabled"));
set_val_strc (arr, 6, wireless_hw_enabled ? _("enabled") : _("disabled"));
set_val_strc (arr, 7, wireless_enabled ? _("enabled") : _("disabled"));
set_val_strc (arr, 8, wwan_hw_enabled ? _("enabled") : _("disabled"));
set_val_strc (arr, 9, wwan_enabled ? _("enabled") : _("disabled"));
#if WITH_WIMAX
set_val_strc (arr, 10, wimax_hw_enabled_str);
set_val_strc (arr, 11, wimax_enabled_str);
set_val_strc (arr, 10, wimax_hw_enabled ? _("enabled") : _("disabled"));
set_val_strc (arr, 11, wimax_enabled ? _("enabled") : _("disabled"));
#endif
/* Set colors */
arr[2].color = state_to_color (state);
arr[3].color = startup ? NMC_TERM_COLOR_YELLOW : NMC_TERM_COLOR_GREEN;
arr[4].color = connectivity_to_color (connectivity);
arr[5].color = net_enabled ? NMC_TERM_COLOR_GREEN : NMC_TERM_COLOR_RED;
arr[6].color = wireless_hw_enabled ? NMC_TERM_COLOR_GREEN : NMC_TERM_COLOR_RED;
arr[7].color = wireless_enabled ? NMC_TERM_COLOR_GREEN : NMC_TERM_COLOR_RED;
arr[8].color = wwan_hw_enabled ? NMC_TERM_COLOR_GREEN : NMC_TERM_COLOR_RED;
arr[9].color = wwan_enabled ? NMC_TERM_COLOR_GREEN : NMC_TERM_COLOR_RED;
#if WITH_WIMAX
arr[10].color = wimax_hw_enabled ? NMC_TERM_COLOR_GREEN : NMC_TERM_COLOR_RED;
arr[11].color = wimax_enabled ? NMC_TERM_COLOR_GREEN : NMC_TERM_COLOR_RED;
#endif
g_ptr_array_add (nmc->output_data, arr);
print_data (nmc); /* Print all data */
@ -558,6 +610,9 @@ do_general (NmCli *nmc, int argc, char **argv)
{
GError *error = NULL;
/* Register polkit agent */
nmc_start_polkit_agent_start_try (nmc);
if (argc == 0) {
if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error)) {
g_string_printf (nmc->return_text, _("Error: %s."), error->message);
@ -726,6 +781,9 @@ do_networking (NmCli *nmc, int argc, char **argv)
{
gboolean enable_flag;
/* Register polkit agent */
nmc_start_polkit_agent_start_try (nmc);
if (argc == 0)
nmc_switch_show (nmc, NMC_FIELDS_NM_NETWORKING, _("Networking"));
else if (argc > 0) {
@ -787,6 +845,9 @@ do_radio (NmCli *nmc, int argc, char **argv)
GError *error = NULL;
gboolean enable_flag;
/* Register polkit agent */
nmc_start_polkit_agent_start_try (nmc);
if (argc == 0) {
if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error)) {
g_string_printf (nmc->return_text, _("Error: %s."), error->message);

View file

@ -170,6 +170,33 @@ _nmcli_compl_OPTIONS()
ask)
_nmcli_array_delete_at words 0
;;
order)
if [[ "${#words[@]}" -eq 2 ]]; then
local ord="${words[1]}"
local ord_sta=""
local i
local c=()
# FIXME: currently the completion considers colon as separator
# for words. Hence the following doesn't work as $ord will
# not contain any colons at this point.
# See https://bugzilla.gnome.org/show_bug.cgi?id=745157
if [[ $ord = *":"* ]]; then
ord_sta="${ord%:*}:"
ord="${ord##*:}"
fi
if [[ $ord = [-+]* ]]; then
ord_sta="$ord_sta${ord:0:1}"
fi
for i in active name type path; do
c=("${c[@]}" "$ord_sta$i")
done
_nmcli_list "${c[*]}"
return 0
fi
_nmcli_array_delete_at words 0 1
;;
show-secrets)
_nmcli_array_delete_at words 0
;;
@ -197,6 +224,13 @@ _nmcli_compl_OPTIONS()
fi
_nmcli_array_delete_at words 0 1
;;
colors)
if [[ "${#words[@]}" -eq 2 ]]; then
_nmcli_list "yes no auto"
return 0
fi
_nmcli_array_delete_at words 0 1
;;
fields)
if [[ "${#words[@]}" -eq 2 ]]; then
_nmcli_list "all common
@ -502,7 +536,8 @@ _nmcli_compl_ARGS()
user| \
username| \
service| \
password)
password| \
passwd-file)
if [[ "${#words[@]}" -eq 2 ]]; then
return 0
fi
@ -682,7 +717,7 @@ _nmcli()
local COMMAND_CONNECTION_ACTIVE=""
HELP_ONLY_AS_FIRST=
local LONG_OPTIONS=(terse pretty mode fields escape nocheck ask wait version help)
local LONG_OPTIONS=(terse pretty mode fields colors escape nocheck ask wait version help)
_nmcli_compl_OPTIONS
i=$?
@ -700,7 +735,7 @@ _nmcli()
# (if the current word starts with a dash) or the OBJECT list
# otherwise.
if [[ "${words[0]:0:1}" != '-' ]]; then
OPTIONS=(help general networking radio connection device)
OPTIONS=(help general networking radio connection device agent)
elif [[ "${words[0]:1:1}" == '-' || "${words[0]}" == "-" ]]; then
OPTIONS=("${LONG_OPTIONS[@]/#/--}")
else
@ -777,11 +812,11 @@ _nmcli()
case "$command" in
s|sh|sho|show)
if [[ ${#words[@]} -eq 3 ]]; then
_nmcli_compl_COMMAND_nl "${words[2]}" "$(printf "id\nuuid\npath\napath\n%s" "$(_nmcli_con_show NAME)")" active show-secrets
_nmcli_compl_COMMAND_nl "${words[2]}" "$(printf "id\nuuid\npath\napath\n%s" "$(_nmcli_con_show NAME)")" active show-secrets order
elif [[ ${#words[@]} -gt 3 ]]; then
_nmcli_array_delete_at words 0 1
LONG_OPTIONS=(help active show-secrets)
LONG_OPTIONS=(help active show-secrets order)
HELP_ONLY_AS_FIRST=1
_nmcli_compl_OPTIONS
i=$?
@ -845,9 +880,9 @@ _nmcli()
_nmcli_compl_ARGS_CONNECTION && return 0
if [[ "$COMMAND_CONNECTION_TYPE" = "ifname" ]]; then
OPTIONS=(ap nsp)
OPTIONS=(ap nsp passwd-file)
else
OPTIONS=(ifname ap nsp)
OPTIONS=(ifname ap nsp passwd-file)
fi
_nmcli_compl_ARGS
fi
@ -1149,18 +1184,23 @@ _nmcli()
;;
esac
OPTIONS=(id uuid path apath)
OPTIONS=(id uuid path)
_nmcli_compl_ARGS_CONNECTION && return 0
while [[ "${#words[@]}" -gt 0 ]]; do
if [[ ${#words[@]} -le 1 ]]; then
_nmcli_list_nl "$(nmcli --fields profile connection show "${COMMAND_CONNECTION_TYPE:-id}" "$COMMAND_CONNECTION_ID" 2>/dev/null | sed -n 's/^\([^:]\+\):.*/\1/p')"
local PREFIX=""
if [[ "${words[0]:0:1}" == [+-] ]]; then
PREFIX="${words[0]:0:1}"
fi
_nmcli_list_nl "$(nmcli --fields profile connection show ${COMMAND_CONNECTION_TYPE} "$COMMAND_CONNECTION_ID" 2>/dev/null | sed -n 's/^\([^:]\+\):.*/'$PREFIX'\1/p')"
return 0
elif [[ ${#words[@]} -le 2 ]]; then
return 0
fi
_nmcli_array_delete_at words 0 1
done
_nmcli_list_nl "$(nmcli --fields profile connection show "${COMMAND_CONNECTION_TYPE:-id}" "$COMMAND_CONNECTION_ID" 2>/dev/null | sed -n 's/^\([^:]\+\):.*/\1/p')"
_nmcli_list_nl "$(nmcli --fields profile connection show ${COMMAND_CONNECTION_TYPE} "$COMMAND_CONNECTION_ID" 2>/dev/null | sed -n 's/^\([^:]\+\):.*/\1/p')"
return 0
fi
;;
@ -1267,6 +1307,11 @@ _nmcli()
esac
fi
;;
a|ag|age|agen|agent)
if [[ ${#words[@]} -eq 2 ]]; then
_nmcli_compl_COMMAND "$command" secret polkit all
fi
;;
esac
return 0

View file

@ -16,7 +16,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright 2010 - 2014 Red Hat, Inc.
* Copyright 2010 - 2015 Red Hat, Inc.
*/
/* Generated configuration file */
@ -27,6 +27,8 @@
#include <stdlib.h>
#include <signal.h>
#include <pthread.h>
#include <termios.h>
#include <unistd.h>
#include <locale.h>
#include <readline/readline.h>
#include <readline/history.h>
@ -34,12 +36,14 @@
#include <glib.h>
#include <glib/gi18n.h>
#include "polkit-agent.h"
#include "nmcli.h"
#include "utils.h"
#include "common.h"
#include "connections.h"
#include "devices.h"
#include "general.h"
#include "agent.h"
#if defined(NM_DIST_VERSION)
# define NMCLI_VERSION NM_DIST_VERSION
@ -61,6 +65,7 @@ typedef struct {
/* --- Global variables --- */
GMainLoop *loop = NULL;
static sigset_t signal_set;
struct termios termios_orig;
/* Get an error quark for use with GError */
@ -84,6 +89,7 @@ usage (const char *prog_name)
" -t[erse] terse output\n"
" -p[retty] pretty output\n"
" -m[ode] tabular|multiline output mode\n"
" -c[olors] auto|yes|no whether to use colors in output\n"
" -f[ields] <field1,field2,...>|all|common specify fields to output\n"
" -e[scape] yes|no escape columns separators in values\n"
" -n[ocheck] don't check nmcli and NetworkManager versions\n"
@ -98,6 +104,7 @@ usage (const char *prog_name)
" r[adio] NetworkManager radio switches\n"
" c[onnection] NetworkManager's connections\n"
" d[evice] devices managed by NetworkManager\n"
" a[gent] NetworkManager secret agent or polkit agent\n"
"\n"),
prog_name);
}
@ -118,6 +125,7 @@ static const struct cmd {
{ "radio", do_radio },
{ "connection", do_connections },
{ "device", do_devices },
{ "agent", do_agent },
{ "help", do_help },
{ 0 }
};
@ -203,6 +211,24 @@ parse_command_line (NmCli *nmc, int argc, char **argv)
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
return nmc->return_value;
}
} else if (matches (opt, "-colors") == 0) {
next_arg (&argc, &argv);
if (argc <= 1) {
g_string_printf (nmc->return_text, _("Error: missing argument for '%s' option."), opt);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
return nmc->return_value;
}
if (matches (argv[1], "auto") == 0)
nmc->use_colors = NMC_USE_COLOR_AUTO;
else if (matches (argv[1], "yes") == 0)
nmc->use_colors = NMC_USE_COLOR_YES;
else if (matches (argv[1], "no") == 0)
nmc->use_colors = NMC_USE_COLOR_NO;
else {
g_string_printf (nmc->return_text, _("Error: '%s' is not valid argument for '%s' option."), argv[1], opt);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
return nmc->return_value;
}
} else if (matches (opt, "-escape") == 0) {
next_arg (&argc, &argv);
if (argc <= 1) {
@ -261,8 +287,10 @@ parse_command_line (NmCli *nmc, int argc, char **argv)
argv++;
}
if (argc > 1)
if (argc > 1) {
/* Now run the requested command */
return do_cmd (nmc, argv[1], argc-1, argv+1);
}
usage (base);
return nmc->return_value;
@ -332,6 +360,7 @@ signal_handling_thread (void *arg) {
pthread_mutex_unlock (&sigint_mutex);
} else {
/* We can quit nmcli */
tcsetattr (STDIN_FILENO, TCSADRAIN, &termios_orig);
nmc_cleanup_readline ();
g_print (_("\nError: nmcli terminated by signal %s (%d)\n"),
strsignal (signo), signo);
@ -340,6 +369,7 @@ signal_handling_thread (void *arg) {
break;
case SIGQUIT:
case SIGTERM:
tcsetattr (STDIN_FILENO, TCSADRAIN, &termios_orig);
nmc_cleanup_readline ();
if (!nmcli_sigquit_internal)
g_print (_("\nError: nmcli terminated by signal %s (%d)\n"),
@ -500,6 +530,10 @@ nmc_init (NmCli *nmc)
nmc->connections = NULL;
nmc->secret_agent = NULL;
nmc->pwds_hash = NULL;
nmc->pk_listener = NULL;
nmc->should_wait = FALSE;
nmc->nowait_flag = TRUE;
nmc->print_output = NMC_PRINT_NORMAL;
@ -511,6 +545,7 @@ nmc_init (NmCli *nmc)
memset (&nmc->print_fields, '\0', sizeof (NmcPrintFields));
nmc->nocheck_ver = FALSE;
nmc->ask = FALSE;
nmc->use_colors = NMC_USE_COLOR_AUTO;
nmc->in_editor = FALSE;
nmc->editor_status_line = FALSE;
nmc->editor_save_confirmation = TRUE;
@ -525,9 +560,19 @@ nmc_cleanup (NmCli *nmc)
g_string_free (nmc->return_text, TRUE);
if (nmc->secret_agent) {
/* Destroy secret agent if we have one. */
nm_secret_agent_old_unregister (nmc->secret_agent, NULL, NULL);
g_object_unref (nmc->secret_agent);
}
if (nmc->pwds_hash)
g_hash_table_destroy (nmc->pwds_hash);
g_free (nmc->required_fields);
nmc_empty_output_fields (nmc);
g_ptr_array_unref (nmc->output_data);
nmc_polkit_agent_fini (nmc);
}
static gboolean
@ -565,6 +610,9 @@ main (int argc, char *argv[])
#if !GLIB_CHECK_VERSION (2, 35, 0)
g_type_init ();
#endif
/* Save terminal settings */
tcgetattr (STDIN_FILENO, &termios_orig);
/* readline init */
rl_event_hook = event_hook_for_readline;

View file

@ -14,13 +14,23 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright 2010 - 2014 Red Hat, Inc.
* Copyright 2010 - 2015 Red Hat, Inc.
*/
#ifndef NMC_NMCLI_H
#define NMC_NMCLI_H
#include "config.h"
#include <NetworkManager.h>
#include <nm-secret-agent-old.h>
#if WITH_POLKIT_AGENT
#include "nm-polkit-listener.h"
#else
/* polkit agent is not available; define fake NMPolkitListener */
typedef gpointer NMPolkitListener;
#endif
/* nmcli exit codes */
typedef enum {
@ -58,6 +68,28 @@ typedef enum {
NMC_RESULT_ERROR_NOT_FOUND = 10
} NMCResultCode;
typedef enum {
NMC_TERM_COLOR_NORMAL = 0,
NMC_TERM_COLOR_BLACK = 1,
NMC_TERM_COLOR_RED = 2,
NMC_TERM_COLOR_GREEN = 3,
NMC_TERM_COLOR_YELLOW = 4,
NMC_TERM_COLOR_BLUE = 5,
NMC_TERM_COLOR_MAGENTA = 6,
NMC_TERM_COLOR_CYAN = 7,
NMC_TERM_COLOR_WHITE = 8
} NmcTermColor;
typedef enum {
NMC_TERM_FORMAT_NORMAL,
NMC_TERM_FORMAT_BOLD,
NMC_TERM_FORMAT_DIM,
NMC_TERM_FORMAT_UNDERLINE,
NMC_TERM_FORMAT_BLINK,
NMC_TERM_FORMAT_REVERSE,
NMC_TERM_FORMAT_HIDDEN,
} NmcTermFormat;
typedef enum {
NMC_PRINT_TERSE = 0,
NMC_PRINT_NORMAL = 1,
@ -80,6 +112,8 @@ typedef struct _NmcOutputField {
gboolean value_is_array; /* Whether value is char** instead of char* */
gboolean free_value; /* Whether to free the value */
guint32 flags; /* Flags - whether and how to print values/field names/headers */
NmcTermColor color; /* Use this color to print value */
NmcTermFormat color_fmt; /* Use this terminal format to print value */
} NmcOutputField;
typedef struct {
@ -89,16 +123,10 @@ typedef struct {
} NmcPrintFields;
typedef enum {
NMC_TERM_COLOR_NORMAL = 0,
NMC_TERM_COLOR_BLACK = 1,
NMC_TERM_COLOR_RED = 2,
NMC_TERM_COLOR_GREEN = 3,
NMC_TERM_COLOR_YELLOW = 4,
NMC_TERM_COLOR_BLUE = 5,
NMC_TERM_COLOR_MAGENTA = 6,
NMC_TERM_COLOR_CYAN = 7,
NMC_TERM_COLOR_WHITE = 8
} NmcTermColor;
NMC_USE_COLOR_AUTO,
NMC_USE_COLOR_YES,
NMC_USE_COLOR_NO,
} NmcColorOption;
/* NmCli - main structure */
typedef struct _NmCli {
@ -112,11 +140,16 @@ typedef struct _NmCli {
const GPtrArray *connections; /* List of connections */
NMSecretAgentOld *secret_agent; /* Secret agent */
GHashTable *pwds_hash; /* Hash table with passwords in passwd-file */
NMPolkitListener *pk_listener ; /* polkit agent listener */
gboolean should_wait; /* Indication that nmcli should not end yet */
gboolean nowait_flag; /* '--nowait' option; used for passing to callbacks */
NMCPrintOutput print_output; /* Output mode */
gboolean multiline_output; /* Multiline output instead of default tabular */
gboolean mode_specified; /* Whether tabular/multiline mode was specified via '--mode' option */
NmcColorOption use_colors; /* Whether to use colors for output: option '--color' */
gboolean escape_values; /* Whether to escape ':' and '\' in terse tabular mode */
char *required_fields; /* Required fields in output: '--fields' option */
GPtrArray *output_data; /* GPtrArray of arrays of NmcOutputField structs - accumulates data for output */

166
clients/cli/polkit-agent.c Normal file
View file

@ -0,0 +1,166 @@
/* nmcli - command-line tool to control NetworkManager
*
* 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"
#if WITH_POLKIT_AGENT
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <termios.h>
#include <glib.h>
#include <glib/gi18n-lib.h>
#include "polkit-agent.h"
#include "nm-polkit-listener.h"
#include "common.h"
static char *
polkit_request (const char *request,
const char *action_id,
const char *message,
const char *icon_name,
const char *user,
gboolean echo_on,
gpointer user_data)
{
char *response, *tmp, *p;
struct termios termios_orig, termios_new;
g_print ("%s\n", message);
g_print ("(action_id: %s)\n", action_id);
if (!echo_on) {
tcgetattr (STDIN_FILENO, &termios_orig);
termios_new = termios_orig;
termios_new.c_lflag &= ~(ECHO);
tcsetattr (STDIN_FILENO, TCSADRAIN, &termios_new);
}
/* Ask user for polkit authorization password */
if (user) {
/* chop of ": " if present */
tmp = g_strdup (request);
p = strrchr (tmp, ':');
if (p && !strcmp (p, ": "))
*p = '\0';
response = nmc_readline ("%s (%s): ", tmp, user);
g_free (tmp);
} else
response = nmc_readline ("%s", request);
g_print ("\n");
/* Restore original terminal settings */
if (!echo_on)
tcsetattr (STDIN_FILENO, TCSADRAIN, &termios_orig);
return response;
}
static void
polkit_show_info (const char *text)
{
g_print (_("Authentication message: %s\n"), text);
}
static void
polkit_show_error (const char *text)
{
g_print (_("Authentication error: %s\n"), text);
}
static void
polkit_completed (gboolean gained_authorization)
{
/* We don't print anything here. The outcome will be evident from
* the operation result anyway. */
}
gboolean
nmc_polkit_agent_init (NmCli* nmc, gboolean for_session, GError **error)
{
PolkitAgentListener *listener;
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
listener = nm_polkit_listener_new (for_session, error);
if (!listener)
return FALSE;
nm_polkit_listener_set_request_callback (NM_POLKIT_LISTENER (listener), polkit_request, nmc);
nm_polkit_listener_set_show_info_callback (NM_POLKIT_LISTENER (listener), polkit_show_info);
nm_polkit_listener_set_show_error_callback (NM_POLKIT_LISTENER (listener), polkit_show_error);
nm_polkit_listener_set_completed_callback (NM_POLKIT_LISTENER (listener), polkit_completed);
nmc->pk_listener = NM_POLKIT_LISTENER (listener);
return TRUE;
}
void
nmc_polkit_agent_fini (NmCli* nmc)
{
g_clear_object (&nmc->pk_listener);
}
gboolean
nmc_start_polkit_agent_start_try (NmCli *nmc)
{
GError *error = NULL;
/* We don't register polkit agent at all when running non-interactively */
if (!nmc->ask)
return TRUE;
if (!nmc_polkit_agent_init (nmc, FALSE, &error)) {
g_printerr (_("Warning: polkit agent initialization failed: %s\n"),
error->message);
g_error_free (error);
return FALSE;
}
return TRUE;
}
#else
/* polkit agent is not avalable; implement stub functions. */
#include <glib.h>
#include "nmcli.h"
#include "polkit-agent.h"
gboolean
nmc_polkit_agent_init (NmCli* nmc, gboolean for_session, GError **error)
{
return TRUE;
}
void
nmc_polkit_agent_fini (NmCli* nmc)
{
}
gboolean
nmc_start_polkit_agent_start_try (NmCli *nmc)
{
return TRUE;
}
#endif /* #if WITH_POLKIT_AGENT */

View file

@ -1,5 +1,6 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* This program is free software; you can redistribute it and/or modify
/* nmcli - command-line tool to control NetworkManager
*
* 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.
@ -13,18 +14,17 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright (C) 2012 Red Hat, Inc.
* Author: Dan Williams <dcbw@redhat.com>
* Copyright 2014 Red Hat, Inc.
*/
#ifndef __NETWORKMANAGER_SESSION_UTILS_H__
#define __NETWORKMANAGER_SESSION_UTILS_H__
#ifndef __NMC_POLKIT_AGENT_H__
#define __NMC_POLKIT_AGENT_H__
#include <glib.h>
#include <glib-object.h>
#include "nmcli.h"
gboolean nm_session_uid_to_user (uid_t uid, const char **out_user, GError **error);
gboolean nmc_polkit_agent_init (NmCli *nmc, gboolean for_session, GError **error);
void nmc_polkit_agent_fini (NmCli* nmc);
gboolean nm_session_user_to_uid (const char *user, uid_t *out_uid, GError **error);
gboolean nmc_start_polkit_agent_start_try (NmCli *nmc);
#endif /* NM_SESSION_UTILS_H */
#endif /* __NMC_POLKIT_AGENT_H__ */

File diff suppressed because it is too large Load diff

View file

@ -30,8 +30,8 @@ void nmc_properties_cleanup (void);
NMSetting *nmc_setting_new_for_name (const char *name);
void nmc_setting_custom_init (NMSetting *setting);
void nmc_setting_ip4_connect_handlers (NMSettingIP4Config *setting);
void nmc_setting_ip6_connect_handlers (NMSettingIP6Config *setting);
void nmc_setting_ip4_connect_handlers (NMSettingIPConfig *setting);
void nmc_setting_ip6_connect_handlers (NMSettingIPConfig *setting);
void nmc_setting_wireless_connect_handlers (NMSettingWireless *setting);
void nmc_setting_connection_connect_handlers (NMSettingConnection *setting, NMConnection *connection);

View file

@ -14,7 +14,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* (C) Copyright 2010 - 2014 Red Hat, Inc.
* Copyright 2010 - 2015 Red Hat, Inc.
*/
/* Generated configuration file */
@ -307,28 +307,121 @@ nmc_term_color_sequence (NmcTermColor color)
}
}
const char *
nmc_term_format_sequence (NmcTermFormat format)
{
switch (format) {
case NMC_TERM_FORMAT_BOLD:
return "\33[1m";
break;
case NMC_TERM_FORMAT_DIM:
return "\33[2m";
break;
case NMC_TERM_FORMAT_UNDERLINE:
return "\33[4m";
break;
case NMC_TERM_FORMAT_BLINK:
return "\33[5m";
break;
case NMC_TERM_FORMAT_REVERSE:
return "\33[7m";
break;
case NMC_TERM_FORMAT_HIDDEN:
return "\33[8m";
break;
default:
return "";
break;
}
}
char *
nmc_colorize (NmcTermColor color, const char *fmt, ...)
nmc_colorize (NmcTermColor color, NmcTermFormat format, const char *fmt, ...)
{
va_list args;
char *str, *colored;
const char *ansi_color, *color_end;
const char *ansi_color, *color_end, *ansi_fmt, *format_end;
static const char *end_seq = "\33[0m";
va_start (args, fmt);
str = g_strdup_vprintf (fmt, args);
va_end (args);
ansi_color = nmc_term_color_sequence (color);
if (*ansi_color)
color_end = "\33[0m";
else
color_end = "";
ansi_fmt = nmc_term_format_sequence (format);
color_end = *ansi_color ? end_seq : "";
format_end = *ansi_fmt ? end_seq : "";
colored = g_strdup_printf ("%s%s%s", ansi_color, str, color_end);
colored = g_strdup_printf ("%s%s%s%s%s", ansi_fmt, ansi_color, str, color_end, format_end);
g_free (str);
return colored;
}
/*
* Count characters belonging to terminal color escape sequences.
* @start points to beginning of the string, @end points to the end,
* or NULL if the string is nul-terminated.
*/
static int
nmc_count_color_escape_chars (const char *start, const char *end)
{
int num = 0;
gboolean inside = FALSE;
if (end == NULL)
end = start + strlen (start);
while (start < end) {
if (*start == '\33' && *(start+1) == '[')
inside = TRUE;
if (inside)
num++;
if (*start == 'm')
inside = FALSE;
start++;
}
return num;
}
/* Filter out possible ANSI color escape sequences */
/* It directly modifies the passed string @str. */
void
nmc_filter_out_colors_inplace (char *str)
{
const char *p1;
char *p2;
gboolean copy_char = TRUE;
if (!str)
return;
p1 = p2 = str;
while (*p1) {
if (*p1 == '\33' && *(p1+1) == '[')
copy_char = FALSE;
if (copy_char)
*p2++ = *p1;
if (!copy_char && *p1 == 'm')
copy_char = TRUE;
p1++;
}
*p2 = '\0';
}
/* Filter out possible ANSI color escape sequences */
char *
nmc_filter_out_colors (const char *str)
{
char *filtered;
if (!str)
return NULL;
filtered = g_strdup (str);
nmc_filter_out_colors_inplace (filtered);
return filtered;
}
/*
* Convert string to signed integer.
* If required, the resulting number is checked to be in the <min,max> range.
@ -510,13 +603,10 @@ nmc_string_is_valid (const char *input, const char **allowed, GError **error)
finish:
if (ret == NULL) {
char *valid_vals = g_strjoinv (", ", (char **) allowed);
if (!input || !*input) {
g_set_error (error, 1, 0, _("missing name, try one of [%s]"),
valid_vals);
} else {
g_set_error (error, 1, 0, _("'%s' not among [%s]"),
input ? input : "", valid_vals);
}
if (!input || !*input)
g_set_error (error, 1, 0, _("missing name, try one of [%s]"), valid_vals);
else
g_set_error (error, 1, 0, _("'%s' not among [%s]"), input, valid_vals);
g_free (valid_vals);
}
@ -591,21 +681,24 @@ nmc_strsplit_set (const char *str, const char *delimiter, int max_tokens)
}
/*
* Find out how many columns an UTF-8 string occupies on the screen
* Find out how many columns an UTF-8 string occupies on the screen.
*/
int
nmc_string_screen_width (const char *start, const char *end)
{
int width = 0;
const char *p = start;
if (end == NULL)
end = start + strlen (start);
while (start < end) {
width += g_unichar_iswide (g_utf8_get_char (start)) ? 2 : g_unichar_iszerowidth (g_utf8_get_char (start)) ? 0 : 1;
start = g_utf8_next_char (start);
while (p < end) {
width += g_unichar_iswide (g_utf8_get_char (p)) ? 2 : g_unichar_iszerowidth (g_utf8_get_char (p)) ? 0 : 1;
p = g_utf8_next_char (p);
}
return width;
/* Subtract color escape sequences as they don't occupy space. */
return width - nmc_count_color_escape_chars (start, NULL);
}
void
@ -640,6 +733,26 @@ set_val_arrc (NmcOutputField fields_array[], guint32 idx, const char **value)
fields_array[idx].free_value = FALSE;
}
void
set_val_color_all (NmcOutputField fields_array[], NmcTermColor color)
{
int i;
for (i = 0; fields_array[i].name; i++) {
fields_array[i].color = color;
}
}
void
set_val_color_fmt_all (NmcOutputField fields_array[], NmcTermFormat format)
{
int i;
for (i = 0; fields_array[i].name; i++) {
fields_array[i].color_fmt = format;
}
}
/*
* Free 'value' members in array of NmcOutputField
*/
@ -858,23 +971,55 @@ nmc_empty_output_fields (NmCli *nmc)
}
static char *
get_value_to_print (NmcOutputField *fields,
colorize_string (gboolean colorize,
NmcTermColor color,
NmcTermFormat color_fmt,
const char *str,
gboolean *dealloc)
{
char *out;
if ( colorize
&& (color != NMC_TERM_COLOR_NORMAL || color_fmt != NMC_TERM_FORMAT_NORMAL)) {
out = nmc_colorize (color, color_fmt, str);
*dealloc = TRUE;
} else {
out = (char *) str;
*dealloc = FALSE;
}
return out;
}
static char *
get_value_to_print (NmcOutputField *field,
gboolean field_name,
const char *not_set_str,
gboolean *dealloc)
gboolean *dealloc,
gboolean colorize)
{
gboolean is_array = fields->value_is_array;
char *value;
gboolean is_array = field->value_is_array;
char *value, *out;
gboolean free_value, free_out;
if (field_name)
value = _(fields->name_l10n);
value = _(field->name_l10n);
else
value = fields->value ?
(is_array ? g_strjoinv (" | ", (char **) fields->value) :
(char *) fields->value) :
value = field->value ?
(is_array ? g_strjoinv (" | ", (char **) field->value) :
(char *) field->value) :
(char *) not_set_str;
*dealloc = fields->value && is_array && !field_name;
return value;
free_value = field->value && is_array && !field_name;
/* colorize the value */
out = colorize_string (colorize, field->color, field->color_fmt, value, &free_out);
if (free_out) {
if (free_value)
g_free (value);
*dealloc = TRUE;
} else
*dealloc = free_value;
return out;
}
/*
@ -904,6 +1049,7 @@ print_required_fields (NmCli *nmc, const NmcOutputField field_values[])
gboolean field_names = field_values[0].flags & NMC_OF_FLAG_FIELD_NAMES;
gboolean section_prefix = field_values[0].flags & NMC_OF_FLAG_SECTION_PREFIX;
gboolean main_header = main_header_add || main_header_only;
gboolean colorize;
/* No headers are printed in terse mode:
* - neither main header nor field (column) names
@ -911,6 +1057,11 @@ print_required_fields (NmCli *nmc, const NmcOutputField field_values[])
if ((main_header_only || field_names) && terse)
return;
/* Only show colors if the output is a terminal */
colorize = nmc->use_colors == NMC_USE_COLOR_YES ? TRUE :
nmc->use_colors == NMC_USE_COLOR_NO ? FALSE :
isatty (fileno (stdout));
if (multiline) {
/* --- Multiline mode --- */
enum { ML_HEADER_WIDTH = 79 };
@ -933,6 +1084,7 @@ print_required_fields (NmCli *nmc, const NmcOutputField field_values[])
if (!main_header_only && !field_names) {
for (i = 0; i < fields.indices->len; i++) {
char *tmp;
gboolean free_print_val;
int idx = g_array_index (fields.indices, int, i);
gboolean is_array = field_values[idx].value_is_array;
@ -944,10 +1096,14 @@ print_required_fields (NmCli *nmc, const NmcOutputField field_values[])
if (is_array) {
/* value is a null-terminated string array */
const char **p;
const char **p, *val;
char *print_val;
int j;
for (p = (const char **) field_values[idx].value, j = 1; p && *p; p++, j++) {
val = *p ? *p : not_set_str;
print_val = colorize_string (colorize, field_values[idx].color, field_values[idx].color_fmt,
val, &free_print_val);
tmp = g_strdup_printf ("%s%s%s[%d]:",
section_prefix ? (const char*) field_values[0].value : "",
section_prefix ? "." : "",
@ -955,24 +1111,30 @@ print_required_fields (NmCli *nmc, const NmcOutputField field_values[])
j);
width1 = strlen (tmp);
width2 = nmc_string_screen_width (tmp, NULL);
g_print ("%-*s%s\n", terse ? 0 : ML_VALUE_INDENT+width1-width2, tmp,
*p ? *p : not_set_str);
g_print ("%-*s%s\n", terse ? 0 : ML_VALUE_INDENT+width1-width2, tmp, print_val);
g_free (tmp);
if (free_print_val)
g_free (print_val);
}
} else {
/* value is a string */
const char *hdr_name = (const char*) field_values[0].value;
const char *val = (const char*) field_values[idx].value;
char *print_val;
val = val ? val : not_set_str;
print_val = colorize_string (colorize, field_values[idx].color, field_values[idx].color_fmt,
val, &free_print_val);
tmp = g_strdup_printf ("%s%s%s:",
section_prefix ? hdr_name : "",
section_prefix ? "." : "",
_(field_values[idx].name_l10n));
width1 = strlen (tmp);
width2 = nmc_string_screen_width (tmp, NULL);
g_print ("%-*s%s\n", terse ? 0 : ML_VALUE_INDENT+width1-width2, tmp,
val ? val : not_set_str);
g_print ("%-*s%s\n", terse ? 0 : ML_VALUE_INDENT+width1-width2, tmp, print_val);
g_free (tmp);
if (free_print_val)
g_free (print_val);
}
}
if (pretty) {
@ -990,7 +1152,8 @@ print_required_fields (NmCli *nmc, const NmcOutputField field_values[])
for (i = 0; i < fields.indices->len; i++) {
int idx = g_array_index (fields.indices, int, i);
gboolean dealloc;
char *value = get_value_to_print ((NmcOutputField *) field_values+idx, field_names, not_set_str, &dealloc);
char *value = get_value_to_print ((NmcOutputField *) field_values+idx, field_names,
not_set_str, &dealloc, colorize);
if (terse) {
if (escape) {
@ -1088,7 +1251,7 @@ print_data (NmCli *nmc)
char *value;
row = g_ptr_array_index (nmc->output_data, j);
field_names = row[0].flags & NMC_OF_FLAG_FIELD_NAMES;
value = get_value_to_print (row+i, field_names, "--", &dealloc);
value = get_value_to_print (row+i, field_names, "--", &dealloc, FALSE);
len = nmc_string_screen_width (value, NULL);
max_width = len > max_width ? len : max_width;
if (dealloc)

View file

@ -14,7 +14,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright 2010 - 2014 Red Hat, Inc.
* Copyright 2010 - 2015 Red Hat, Inc.
*/
#ifndef NMC_UTILS_H
@ -67,7 +67,10 @@ char *nmc_ip6_address_as_string (const struct in6_addr *ip, GError **error);
void nmc_terminal_erase_line (void);
void nmc_terminal_show_progress (const char *str);
const char *nmc_term_color_sequence (NmcTermColor color);
char *nmc_colorize (NmcTermColor color, const char * fmt, ...);
const char *nmc_term_format_sequence (NmcTermFormat format);
char *nmc_colorize (NmcTermColor color, NmcTermFormat format, const char * fmt, ...);
void nmc_filter_out_colors_inplace (char *str);
char *nmc_filter_out_colors (const char *str);
char *nmc_get_user_input (const char *ask_str);
int nmc_string_to_arg_array (const char *line, const char *delim, char ***argv, int *argc);
const char *nmc_string_is_valid (const char *input, const char **allowed, GError **error);
@ -79,6 +82,8 @@ void set_val_str (NmcOutputField fields_array[], guint32 index, char *value);
void set_val_strc (NmcOutputField fields_array[], guint32 index, const char *value);
void set_val_arr (NmcOutputField fields_array[], guint32 index, char **value);
void set_val_arrc (NmcOutputField fields_array[], guint32 index, const char **value);
void set_val_color_all (NmcOutputField fields_array[], NmcTermColor color);
void set_val_color_fmt_all (NmcOutputField fields_array[], NmcTermFormat format);
void nmc_free_output_field_values (NmcOutputField fields_array[]);
GArray *parse_output_fields (const char *fields_str,
const NmcOutputField fields_array[],

View file

@ -0,0 +1,415 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* 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, see <http://www.gnu.org/licenses/>.
*
* Copyright 2014 Red Hat, Inc.
*/
/**
* SECTION:nm-polkit-listener
* @short_description: A polkit agent listener
*
* #NMPolkitListener is the polkit agent listener used by nmcli and nmtui.
* http://www.freedesktop.org/software/polkit/docs/latest/index.html
*
* For an example polkit agent you can look at polkit source tree:
* http://cgit.freedesktop.org/polkit/tree/src/polkitagent/polkitagenttextlistener.c
* http://cgit.freedesktop.org/polkit/tree/src/programs/pkttyagent.c
* or LXDE polkit agent:
* http://git.lxde.org/gitweb/?p=debian/lxpolkit.git;a=blob;f=src/lxpolkit-listener.c
* https://github.com/lxde/lxqt-policykit/tree/master/src
*/
#include "config.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <glib.h>
#include <glib/gi18n-lib.h>
#include "nm-glib-compat.h"
#include "nm-polkit-listener.h"
G_DEFINE_TYPE (NMPolkitListener, nm_polkit_listener, POLKIT_AGENT_TYPE_LISTENER)
#define NM_POLKIT_LISTENER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_POLKIT_LISTENER, NMPolkitListenerPrivate))
typedef struct {
gpointer reg_handle; /* handle of polkit agent registration */
GSimpleAsyncResult *simple;
PolkitAgentSession *active_session;
gulong cancel_id;
GCancellable *cancellable;
char *action_id;
char *message;
char *icon_name;
char *identity;
/* callbacks */
NMPolkitListenerOnRequestFunc on_request_callback;
NMPolkitListenerOnShowInfoFunc on_show_info_callback;
NMPolkitListenerOnShowErrorFunc on_show_error_callback;
NMPolkitListenerOnCompletedFunc on_completed_callback;
gpointer request_callback_data;
} NMPolkitListenerPrivate;
static void
on_request (PolkitAgentSession *session,
const char *request,
gboolean echo_on,
gpointer user_data)
{
NMPolkitListenerPrivate *priv = NM_POLKIT_LISTENER_GET_PRIVATE (user_data);
char *response = NULL;
if (priv->on_request_callback) {
response = priv->on_request_callback (request, priv->action_id,
priv->message, priv->icon_name,
priv->identity, echo_on,
priv->request_callback_data);
}
if (response) {
polkit_agent_session_response (session, response);
g_free (response);
} else {
//FIXME: polkit_agent_session_cancel() should emit "completed", but it doesn't work for me ???
//polkit_agent_session_cancel (session);
polkit_agent_session_response (session, "");
}
}
static void
on_show_info (PolkitAgentSession *session,
const char *text,
gpointer user_data)
{
NMPolkitListenerPrivate *priv = NM_POLKIT_LISTENER_GET_PRIVATE (user_data);
if (priv->on_show_info_callback)
priv->on_show_info_callback (text);
}
static void
on_show_error (PolkitAgentSession *session,
const char *text,
gpointer user_data)
{
NMPolkitListenerPrivate *priv = NM_POLKIT_LISTENER_GET_PRIVATE (user_data);
if (priv->on_show_error_callback)
priv->on_show_error_callback (text);
}
static void
on_completed (PolkitAgentSession *session,
gboolean gained_authorization,
gpointer user_data)
{
NMPolkitListenerPrivate *priv = NM_POLKIT_LISTENER_GET_PRIVATE (user_data);
if (priv->on_completed_callback)
priv->on_completed_callback (gained_authorization);
g_simple_async_result_complete_in_idle (priv->simple);
g_object_unref (priv->simple);
g_object_unref (priv->active_session);
if (priv->cancellable) {
g_cancellable_disconnect (priv->cancellable, priv->cancel_id);
g_object_unref (priv->cancellable);
}
priv->simple = NULL;
priv->active_session = NULL;
priv->cancel_id = 0;
g_clear_pointer (&priv->action_id, g_free);
g_clear_pointer (&priv->message, g_free);
g_clear_pointer (&priv->icon_name, g_free);
g_clear_pointer (&priv->identity, g_free);
}
static void
on_cancelled (GCancellable *cancellable, gpointer user_data)
{
NMPolkitListenerPrivate *priv = NM_POLKIT_LISTENER_GET_PRIVATE (user_data);
polkit_agent_session_cancel (priv->active_session);
}
static gint
compare_users (gconstpointer a, gconstpointer b)
{
char *user;
int ret;
if (POLKIT_IS_UNIX_USER (a))
user = g_strdup (polkit_unix_user_get_name (POLKIT_UNIX_USER (a)));
else
user = polkit_identity_to_string (POLKIT_IDENTITY (a));
ret = g_strcmp0 ((const char *) user, (const char *) b);
g_free (user);
return ret;
}
static PolkitIdentity *
choose_identity (GList *identities)
{
const char *user;
GList *elem;
/* Choose identity. First try current user, then root, and else
* take the firts one */
user = getenv("USER");
elem = g_list_find_custom (identities, user, (GCompareFunc) compare_users);
if (!elem) {
elem = g_list_find_custom (identities, "root", (GCompareFunc) compare_users);
if (!elem)
elem = identities;
}
return elem->data;
}
static void
initiate_authentication (PolkitAgentListener *listener,
const char *action_id,
const char *message,
const char *icon_name,
PolkitDetails *details,
const char *cookie,
GList *identities,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
NMPolkitListenerPrivate *priv = NM_POLKIT_LISTENER_GET_PRIVATE (listener);
GSimpleAsyncResult *simple;
PolkitIdentity *identity;
simple = g_simple_async_result_new (G_OBJECT (listener),
callback,
user_data,
initiate_authentication);
if (priv->active_session != NULL) {
g_simple_async_result_set_error (simple,
POLKIT_ERROR,
POLKIT_ERROR_FAILED,
_("An authentication session is already underway."));
g_simple_async_result_complete_in_idle (simple);
g_object_unref (simple);
return;
}
/* Choose identity */
identity = choose_identity (identities);
priv->active_session = polkit_agent_session_new (identity, cookie);
g_signal_connect (priv->active_session,
"completed",
G_CALLBACK (on_completed),
listener);
g_signal_connect (priv->active_session,
"request",
G_CALLBACK (on_request),
listener);
g_signal_connect (priv->active_session,
"show-info",
G_CALLBACK (on_show_info),
listener);
g_signal_connect (priv->active_session,
"show-error",
G_CALLBACK (on_show_error),
listener);
priv->action_id = g_strdup (action_id);
priv->message = g_strdup (message);
priv->icon_name = g_strdup (icon_name);
if (POLKIT_IS_UNIX_USER (identity))
priv->identity = g_strdup (polkit_unix_user_get_name (POLKIT_UNIX_USER (identity)));
else
priv->identity = polkit_identity_to_string (identity);
priv->simple = simple;
priv->cancellable = g_object_ref (cancellable);
priv->cancel_id = g_cancellable_connect (cancellable,
G_CALLBACK (on_cancelled),
listener,
NULL);
polkit_agent_session_initiate (priv->active_session);
}
static gboolean
initiate_authentication_finish (PolkitAgentListener *listener,
GAsyncResult *result,
GError **error)
{
return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error);
}
static void
nm_polkit_listener_init (NMPolkitListener *agent)
{
}
static void
nm_polkit_listener_finalize (GObject *object)
{
NMPolkitListenerPrivate *priv = NM_POLKIT_LISTENER_GET_PRIVATE (object);
if (priv->reg_handle)
polkit_agent_listener_unregister (priv->reg_handle);
g_free (priv->action_id);
g_free (priv->message);
g_free (priv->icon_name);
g_free (priv->identity);
G_OBJECT_CLASS (nm_polkit_listener_parent_class)->finalize (object);
}
static void
nm_polkit_listener_class_init (NMPolkitListenerClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
PolkitAgentListenerClass *pkal_class = POLKIT_AGENT_LISTENER_CLASS (klass);
g_type_class_add_private (klass, sizeof (NMPolkitListenerPrivate));
gobject_class->finalize = nm_polkit_listener_finalize;
pkal_class->initiate_authentication = initiate_authentication;
pkal_class->initiate_authentication_finish = initiate_authentication_finish;
}
/**
* nm_polkit_listener_new:
* @for_session: %TRUE for registering the polkit agent for the user session,
* %FALSE for registering it for the running process
* @error: location to store error, or %NULL
*
* Creates a new #NMPolkitListener and registers it as a polkit agent.
*
* Returns: a new #NMPolkitListener
*/
PolkitAgentListener *
nm_polkit_listener_new (gboolean for_session, GError **error)
{
PolkitAgentListener *listener;
PolkitSubject* session;
NMPolkitListenerPrivate *priv;
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
listener = g_object_new (NM_TYPE_POLKIT_LISTENER, NULL);
priv = NM_POLKIT_LISTENER_GET_PRIVATE (listener);
if (for_session)
session = polkit_unix_session_new_for_process_sync (getpid (), NULL, NULL);
else
session = polkit_unix_process_new_for_owner (getpid (), 0, getuid ());
priv->reg_handle = polkit_agent_listener_register (listener, POLKIT_AGENT_REGISTER_FLAGS_NONE,
session, NULL, NULL, error);
if (!priv->reg_handle) {
g_object_unref (listener);
g_object_unref (session);
return NULL;
}
return listener;
}
/**
* nm_polkit_listener_set_request_callback:
* @self: a #NMPolkitListener object
* @request_callback: callback to install for polkit requests
* @request_callback_data: usaer data passed to request_callback when it is called
*
* Set a callback for "request" signal. The callback will be invoked when polkit
* requests an authorization.
*/
void
nm_polkit_listener_set_request_callback (NMPolkitListener *self,
NMPolkitListenerOnRequestFunc request_callback,
gpointer request_callback_data)
{
NMPolkitListenerPrivate *priv;
g_return_if_fail (NM_IS_POLKIT_LISTENER (self));
priv = NM_POLKIT_LISTENER_GET_PRIVATE (self);
priv->on_request_callback = request_callback;
priv->request_callback_data = request_callback_data;
}
/**
* nm_polkit_listener_set_show_info_callback:
* @self: a #NMPolkitListener object
* @show_info_callback: callback to install for polkit show info trigger
*
* Set a callback for "show-info" signal. The callback will be invoked when polkit
* has an info text to display.
*/
void
nm_polkit_listener_set_show_info_callback (NMPolkitListener *self,
NMPolkitListenerOnShowInfoFunc show_info_callback)
{
g_return_if_fail (NM_IS_POLKIT_LISTENER (self));
NM_POLKIT_LISTENER_GET_PRIVATE (self)->on_show_info_callback = show_info_callback;
}
/**
* nm_polkit_listener_set_show_error_callback:
* @self: a #NMPolkitListener object
* @show_error_callback: callback to install for polkit show error trigger
*
* Set a callback for "show-error" signal. The callback will be invoked when polkit
* has an error text to display.
*/
void
nm_polkit_listener_set_show_error_callback (NMPolkitListener *self,
NMPolkitListenerOnShowErrorFunc show_error_callback)
{
g_return_if_fail (NM_IS_POLKIT_LISTENER (self));
NM_POLKIT_LISTENER_GET_PRIVATE (self)->on_show_error_callback = show_error_callback;
}
/**
* nm_polkit_listener_set_completed_callback:
* @self: a #NMPolkitListener object
* @completed_callback: callback to install for polkit completing authorization
*
* Set a callback for "completed" signal. The callback will be invoked when polkit
* completed the request.
*/
void
nm_polkit_listener_set_completed_callback (NMPolkitListener *self,
NMPolkitListenerOnCompletedFunc completed_callback)
{
g_return_if_fail (NM_IS_POLKIT_LISTENER (self));
NM_POLKIT_LISTENER_GET_PRIVATE (self)->on_completed_callback = completed_callback;
}

View file

@ -0,0 +1,104 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* 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, see <http://www.gnu.org/licenses/>.
*
* Copyright 2014 Red Hat, Inc.
*/
#ifndef __NM_POLKIT_LISTENER_H__
#define __NM_POLKIT_LISTENER_H__
#include <glib.h>
#define POLKIT_AGENT_I_KNOW_API_IS_SUBJECT_TO_CHANGE
#include <polkitagent/polkitagent.h>
G_BEGIN_DECLS
#define NM_TYPE_POLKIT_LISTENER (nm_polkit_listener_get_type ())
#define NM_POLKIT_LISTENER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_POLKIT_LISTENER, NMPolkitListener))
#define NM_POLKIT_LISTENER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_POLKIT_LISTENER, NMPolkitListenerClass))
#define NM_IS_POLKIT_LISTENER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_POLKIT_LISTENER))
#define NM_IS_POLKIT_LISTENER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_POLKIT_LISTENER))
#define NM_POLKIT_LISTENER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_POLKIT_LISTENER, NMPolkitListenerClass))
/**
* NMPolkitListenerOnRequestFunc:
* @request: the request asked by polkit agent
* @action_id: the action_id of the polkit request
* @message: the message of the polkit request
* @icon_name: the icon name of the polkit request
* @user: user name
* @echo_on: whether the response to the request should be echoed to the screen
* @user_data: user data for the callback
*
* Called as a result of a request by polkit. The function should obtain response
* to the request from user, i.e. get the password required.
*/
typedef char * (*NMPolkitListenerOnRequestFunc) (const char *request,
const char *action_id,
const char *message,
const char *icon_name,
const char *user,
gboolean echo_on,
gpointer user_data);
/**
* NMPolkitListenerOnShowInfoFunc:
* @text: the info text from polkit
*
* Called as a result of show-info signal by polkit.
*/
typedef void (*NMPolkitListenerOnShowInfoFunc) (const char *text);
/**
* NMPolkitListenerOnShowErrorFunc:
* @text: the error text from polkit
*
* Called as a result of show-error signal by polkit.
*/
typedef void (*NMPolkitListenerOnShowErrorFunc) (const char *text);
/**
* NMPolkitListenerCompletedFunc:
* @gained_authorization: whether the autorization was successful
*
* Called as a result of completed signal by polkit.
*/
typedef void (*NMPolkitListenerOnCompletedFunc) (gboolean gained_authorization);
typedef struct {
PolkitAgentListener parent;
} NMPolkitListener;
typedef struct {
PolkitAgentListenerClass parent;
} NMPolkitListenerClass;
GType nm_polkit_listener_get_type (void);
PolkitAgentListener* nm_polkit_listener_new (gboolean for_session, GError **error);
void nm_polkit_listener_set_request_callback (NMPolkitListener *self,
NMPolkitListenerOnRequestFunc request_callback,
gpointer request_callback_data);
void nm_polkit_listener_set_show_info_callback (NMPolkitListener *self,
NMPolkitListenerOnShowInfoFunc show_info_callback);
void nm_polkit_listener_set_show_error_callback (NMPolkitListener *self,
NMPolkitListenerOnShowErrorFunc show_error_callback);
void nm_polkit_listener_set_completed_callback (NMPolkitListener *self,
NMPolkitListenerOnCompletedFunc completed_callback);
G_END_DECLS
#endif /* __NM_POLKIT_LISTENER_H__ */

View file

@ -18,10 +18,10 @@
*/
/**
* SECTION:nmt-secret-agent
* @short_description: A secret agent
* SECTION:nm-secret-agent-simple
* @short_description: A simple secret agent for NetworkManager
*
* #NmtSecretAgent is the secret agent used by nmtui-connect.
* #NMSecretAgentSimple is the secret agent used by nmtui-connect and nmcli.
*
* This is a stripped-down version of gnome-shell's ShellNetworkAgent,
* with bits of the corresponding JavaScript code squished down into
@ -34,12 +34,11 @@
#include <string.h>
#include <glib/gi18n-lib.h>
#include "nmt-secret-agent.h"
#include "nmt-newt.h"
#include "nm-secret-agent-simple.h"
G_DEFINE_TYPE (NmtSecretAgent, nmt_secret_agent, NM_TYPE_SECRET_AGENT)
G_DEFINE_TYPE (NMSecretAgentSimple, nm_secret_agent_simple, NM_TYPE_SECRET_AGENT_OLD)
#define NMT_SECRET_AGENT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_SECRET_AGENT, NmtSecretAgentPrivate))
#define NM_SECRET_AGENT_SIMPLE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SECRET_AGENT_SIMPLE, NMSecretAgentSimplePrivate))
enum {
REQUEST_SECRETS,
@ -50,45 +49,48 @@ enum {
static guint signals[LAST_SIGNAL] = { 0 };
typedef struct {
NmtSecretAgent *self;
NMSecretAgentSimple *self;
gchar *request_id;
NMConnection *connection;
gchar **hints;
NMSecretAgentGetSecretsFunc callback;
NMSecretAgentOldGetSecretsFunc callback;
gpointer callback_data;
} NmtSecretAgentRequest;
} NMSecretAgentSimpleRequest;
typedef struct {
/* <char *request_id, NmtSecretAgentRequest *request> */
/* <char *request_id, NMSecretAgentSimpleRequest *request> */
GHashTable *requests;
} NmtSecretAgentPrivate;
char *path;
gboolean enabled;
} NMSecretAgentSimplePrivate;
static void
nmt_secret_agent_request_free (gpointer data)
nm_secret_agent_simple_request_free (gpointer data)
{
NmtSecretAgentRequest *request = data;
NMSecretAgentSimpleRequest *request = data;
g_object_unref (request->self);
g_object_unref (request->connection);
g_strfreev (request->hints);
g_slice_free (NmtSecretAgentRequest, request);
g_slice_free (NMSecretAgentSimpleRequest, request);
}
static void
nmt_secret_agent_init (NmtSecretAgent *agent)
nm_secret_agent_simple_init (NMSecretAgentSimple *agent)
{
NmtSecretAgentPrivate *priv = NMT_SECRET_AGENT_GET_PRIVATE (agent);
NMSecretAgentSimplePrivate *priv = NM_SECRET_AGENT_SIMPLE_GET_PRIVATE (agent);
priv->requests = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, nmt_secret_agent_request_free);
g_free, nm_secret_agent_simple_request_free);
}
static void
nmt_secret_agent_finalize (GObject *object)
nm_secret_agent_simple_finalize (GObject *object)
{
NmtSecretAgentPrivate *priv = NMT_SECRET_AGENT_GET_PRIVATE (object);
NMSecretAgentSimplePrivate *priv = NM_SECRET_AGENT_SIMPLE_GET_PRIVATE (object);
GError *error;
GHashTableIter iter;
gpointer key;
@ -100,9 +102,9 @@ nmt_secret_agent_finalize (GObject *object)
g_hash_table_iter_init (&iter, priv->requests);
while (g_hash_table_iter_next (&iter, &key, &value)) {
NmtSecretAgentRequest *request = value;
NMSecretAgentSimpleRequest *request = value;
request->callback (NM_SECRET_AGENT (object),
request->callback (NM_SECRET_AGENT_OLD (object),
request->connection,
NULL, error,
request->callback_data);
@ -111,7 +113,9 @@ nmt_secret_agent_finalize (GObject *object)
g_hash_table_destroy (priv->requests);
g_error_free (error);
G_OBJECT_CLASS (nmt_secret_agent_parent_class)->finalize (object);
g_free (priv->path);
G_OBJECT_CLASS (nm_secret_agent_simple_parent_class)->finalize (object);
}
static gboolean
@ -129,7 +133,7 @@ strv_has (gchar **haystack,
}
/**
* NmtSecretAgentSecret:
* NMSecretAgentSimpleSecret:
* @name: the user-visible name of the secret. Eg, "WEP Passphrase".
* @value: the value of the secret
* @password: %TRUE if this secret represents a password, %FALSE
@ -139,38 +143,37 @@ strv_has (gchar **haystack,
*/
typedef struct {
NmtSecretAgentSecret base;
NMSecretAgentSimpleSecret base;
NMSetting *setting;
char *property;
NmtNewtEntryValidator validator;
gpointer validator_data;
} NmtSecretAgentSecretReal;
} NMSecretAgentSimpleSecretReal;
static void
nmt_secret_agent_secret_free (NmtSecretAgentSecret *secret)
nm_secret_agent_simple_secret_free (NMSecretAgentSimpleSecret *secret)
{
NmtSecretAgentSecretReal *real = (NmtSecretAgentSecretReal *)secret;
NMSecretAgentSimpleSecretReal *real = (NMSecretAgentSimpleSecretReal *)secret;
g_free (secret->name);
g_free (secret->prop_name);
g_free (secret->value);
g_free (real->property);
g_clear_object (&real->setting);
g_slice_free (NmtSecretAgentSecretReal, real);
g_slice_free (NMSecretAgentSimpleSecretReal, real);
}
static NmtSecretAgentSecret *
nmt_secret_agent_secret_new (const char *name,
NMSetting *setting,
const char *property,
gboolean password)
static NMSecretAgentSimpleSecret *
nm_secret_agent_simple_secret_new (const char *name,
NMSetting *setting,
const char *property,
gboolean password)
{
NmtSecretAgentSecretReal *real;
NMSecretAgentSimpleSecretReal *real;
real = g_slice_new0 (NmtSecretAgentSecretReal);
real = g_slice_new0 (NMSecretAgentSimpleSecretReal);
real->base.name = g_strdup (name);
real->base.prop_name = g_strdup_printf ("%s.%s", nm_setting_get_name (setting), property);
real->base.password = password;
if (setting) {
@ -184,12 +187,12 @@ nmt_secret_agent_secret_new (const char *name,
}
static gboolean
add_8021x_secrets (NmtSecretAgentRequest *request,
GPtrArray *secrets)
add_8021x_secrets (NMSecretAgentSimpleRequest *request,
GPtrArray *secrets)
{
NMSetting8021x *s_8021x = nm_connection_get_setting_802_1x (request->connection);
const char *eap_method;
NmtSecretAgentSecret *secret;
NMSecretAgentSimpleSecret *secret;
eap_method = nm_setting_802_1x_get_eap_method (s_8021x, 0);
if (!eap_method)
@ -203,29 +206,29 @@ add_8021x_secrets (NmtSecretAgentRequest *request,
* is not visible here since we only care about phase2 authentication
* (and don't even care of which one)
*/
secret = nmt_secret_agent_secret_new (_("Username"),
NM_SETTING (s_8021x),
NM_SETTING_802_1X_IDENTITY,
FALSE);
secret = nm_secret_agent_simple_secret_new (_("Username"),
NM_SETTING (s_8021x),
NM_SETTING_802_1X_IDENTITY,
FALSE);
g_ptr_array_add (secrets, secret);
secret = nmt_secret_agent_secret_new (_("Password"),
NM_SETTING (s_8021x),
NM_SETTING_802_1X_PASSWORD,
TRUE);
secret = nm_secret_agent_simple_secret_new (_("Password"),
NM_SETTING (s_8021x),
NM_SETTING_802_1X_PASSWORD,
TRUE);
g_ptr_array_add (secrets, secret);
return TRUE;
}
if (!strcmp (eap_method, "tls")) {
secret = nmt_secret_agent_secret_new (_("Identity"),
NM_SETTING (s_8021x),
NM_SETTING_802_1X_IDENTITY,
FALSE);
secret = nm_secret_agent_simple_secret_new (_("Identity"),
NM_SETTING (s_8021x),
NM_SETTING_802_1X_IDENTITY,
FALSE);
g_ptr_array_add (secrets, secret);
secret = nmt_secret_agent_secret_new (_("Private key password"),
NM_SETTING (s_8021x),
NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD,
TRUE);
secret = nm_secret_agent_simple_secret_new (_("Private key password"),
NM_SETTING (s_8021x),
NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD,
TRUE);
g_ptr_array_add (secrets, secret);
return TRUE;
}
@ -234,21 +237,21 @@ add_8021x_secrets (NmtSecretAgentRequest *request,
}
static gboolean
add_wireless_secrets (NmtSecretAgentRequest *request,
GPtrArray *secrets)
add_wireless_secrets (NMSecretAgentSimpleRequest *request,
GPtrArray *secrets)
{
NMSettingWirelessSecurity *s_wsec = nm_connection_get_setting_wireless_security (request->connection);
const char *key_mgmt = nm_setting_wireless_security_get_key_mgmt (s_wsec);
NmtSecretAgentSecret *secret;
NMSecretAgentSimpleSecret *secret;
if (!key_mgmt)
return FALSE;
if (!strcmp (key_mgmt, "wpa-none") || !strcmp (key_mgmt, "wpa-psk")) {
secret = nmt_secret_agent_secret_new (_("Password"),
NM_SETTING (s_wsec),
NM_SETTING_WIRELESS_SECURITY_PSK,
TRUE);
secret = nm_secret_agent_simple_secret_new (_("Password"),
NM_SETTING (s_wsec),
NM_SETTING_WIRELESS_SECURITY_PSK,
TRUE);
g_ptr_array_add (secrets, secret);
return TRUE;
}
@ -259,26 +262,22 @@ add_wireless_secrets (NmtSecretAgentRequest *request,
index = nm_setting_wireless_security_get_wep_tx_keyidx (s_wsec);
key = g_strdup_printf ("wep-key%d", index);
secret = nmt_secret_agent_secret_new (_("Key"),
NM_SETTING (s_wsec),
key,
TRUE);
secret = nm_secret_agent_simple_secret_new (_("Key"),
NM_SETTING (s_wsec),
key,
TRUE);
g_free (key);
#if 0
nmt_secret_agent_secret_set_validator (secret, static_wep_key_validate,
nm_setting_wireless_security_get_wep_key_type (s_wsec));
#endif
g_ptr_array_add (secrets, secret);
return TRUE;
}
if (!strcmp (key_mgmt, "iee8021x")) {
if (!g_strcmp0 (nm_setting_wireless_security_get_auth_alg (s_wsec), "leap")) {
secret = nmt_secret_agent_secret_new (_("Password"),
NM_SETTING (s_wsec),
NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD,
TRUE);
secret = nm_secret_agent_simple_secret_new (_("Password"),
NM_SETTING (s_wsec),
NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD,
TRUE);
g_ptr_array_add (secrets, secret);
return TRUE;
} else
@ -292,40 +291,40 @@ add_wireless_secrets (NmtSecretAgentRequest *request,
}
static gboolean
add_pppoe_secrets (NmtSecretAgentRequest *request,
GPtrArray *secrets)
add_pppoe_secrets (NMSecretAgentSimpleRequest *request,
GPtrArray *secrets)
{
NMSettingPppoe *s_pppoe = nm_connection_get_setting_pppoe (request->connection);
NmtSecretAgentSecret *secret;
NMSecretAgentSimpleSecret *secret;
secret = nmt_secret_agent_secret_new (_("Username"),
NM_SETTING (s_pppoe),
NM_SETTING_PPPOE_USERNAME,
FALSE);
secret = nm_secret_agent_simple_secret_new (_("Username"),
NM_SETTING (s_pppoe),
NM_SETTING_PPPOE_USERNAME,
FALSE);
g_ptr_array_add (secrets, secret);
secret = nmt_secret_agent_secret_new (_("Service"),
NM_SETTING (s_pppoe),
NM_SETTING_PPPOE_SERVICE,
FALSE);
secret = nm_secret_agent_simple_secret_new (_("Service"),
NM_SETTING (s_pppoe),
NM_SETTING_PPPOE_SERVICE,
FALSE);
g_ptr_array_add (secrets, secret);
secret = nmt_secret_agent_secret_new (_("Password"),
NM_SETTING (s_pppoe),
NM_SETTING_PPPOE_PASSWORD,
TRUE);
secret = nm_secret_agent_simple_secret_new (_("Password"),
NM_SETTING (s_pppoe),
NM_SETTING_PPPOE_PASSWORD,
TRUE);
g_ptr_array_add (secrets, secret);
return TRUE;
}
static void
request_secrets_from_ui (NmtSecretAgentRequest *request)
request_secrets_from_ui (NMSecretAgentSimpleRequest *request)
{
GPtrArray *secrets;
NmtSecretAgentSecret *secret;
NMSecretAgentSimpleSecret *secret;
const char *title;
char *msg;
gboolean ok = TRUE;
secrets = g_ptr_array_new_with_free_func ((GDestroyNotify) nmt_secret_agent_secret_free);
secrets = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_secret_agent_simple_secret_free);
if (nm_connection_is_type (request->connection, NM_SETTING_WIRELESS_SETTING_NAME)) {
NMSettingWireless *s_wireless;
@ -349,10 +348,10 @@ request_secrets_from_ui (NmtSecretAgentRequest *request)
title = _("Wired 802.1X authentication");
msg = NULL;
secret = nmt_secret_agent_secret_new (_("Network name"),
NM_SETTING (s_con),
NM_SETTING_CONNECTION_ID,
FALSE);
secret = nm_secret_agent_simple_secret_new (_("Network name"),
NM_SETTING (s_con),
NM_SETTING_CONNECTION_ID,
FALSE);
g_ptr_array_add (secrets, secret);
ok = add_8021x_secrets (request, secrets);
} else if (nm_connection_is_type (request->connection, NM_SETTING_PPPOE_SETTING_NAME)) {
@ -367,20 +366,20 @@ request_secrets_from_ui (NmtSecretAgentRequest *request)
title = _("PIN code required");
msg = g_strdup (_("PIN code is needed for the mobile broadband device"));
secret = nmt_secret_agent_secret_new (_("PIN"),
NM_SETTING (s_gsm),
NM_SETTING_GSM_PIN,
FALSE);
secret = nm_secret_agent_simple_secret_new (_("PIN"),
NM_SETTING (s_gsm),
NM_SETTING_GSM_PIN,
FALSE);
g_ptr_array_add (secrets, secret);
} else {
title = _("Mobile broadband network password");
msg = g_strdup_printf (_("A password is required to connect to '%s'."),
nm_connection_get_id (request->connection));
secret = nmt_secret_agent_secret_new (_("Password"),
NM_SETTING (s_gsm),
NM_SETTING_GSM_PASSWORD,
TRUE);
secret = nm_secret_agent_simple_secret_new (_("Password"),
NM_SETTING (s_gsm),
NM_SETTING_GSM_PASSWORD,
TRUE);
g_ptr_array_add (secrets, secret);
}
} else if (nm_connection_is_type (request->connection, NM_SETTING_CDMA_SETTING_NAME)) {
@ -390,10 +389,10 @@ request_secrets_from_ui (NmtSecretAgentRequest *request)
msg = g_strdup_printf (_("A password is required to connect to '%s'."),
nm_connection_get_id (request->connection));
secret = nmt_secret_agent_secret_new (_("Password"),
NM_SETTING (s_cdma),
NM_SETTING_CDMA_PASSWORD,
TRUE);
secret = nm_secret_agent_simple_secret_new (_("Password"),
NM_SETTING (s_cdma),
NM_SETTING_CDMA_PASSWORD,
TRUE);
g_ptr_array_add (secrets, secret);
} else if (nm_connection_is_type (request->connection, NM_SETTING_BLUETOOTH_SETTING_NAME)) {
NMSetting *setting;
@ -406,10 +405,10 @@ request_secrets_from_ui (NmtSecretAgentRequest *request)
msg = g_strdup_printf (_("A password is required to connect to '%s'."),
nm_connection_get_id (request->connection));
secret = nmt_secret_agent_secret_new (_("Password"),
setting,
"password",
TRUE);
secret = nm_secret_agent_simple_secret_new (_("Password"),
setting,
"password",
TRUE);
g_ptr_array_add (secrets, secret);
} else
ok = FALSE;
@ -424,18 +423,18 @@ request_secrets_from_ui (NmtSecretAgentRequest *request)
}
static void
nmt_secret_agent_get_secrets (NMSecretAgent *agent,
NMConnection *connection,
const gchar *connection_path,
const gchar *setting_name,
const gchar **hints,
NMSecretAgentGetSecretsFlags flags,
NMSecretAgentGetSecretsFunc callback,
gpointer callback_data)
nm_secret_agent_simple_get_secrets (NMSecretAgentOld *agent,
NMConnection *connection,
const gchar *connection_path,
const gchar *setting_name,
const gchar **hints,
NMSecretAgentGetSecretsFlags flags,
NMSecretAgentOldGetSecretsFunc callback,
gpointer callback_data)
{
NmtSecretAgent *self = NMT_SECRET_AGENT (agent);
NmtSecretAgentPrivate *priv = NMT_SECRET_AGENT_GET_PRIVATE (self);
NmtSecretAgentRequest *request;
NMSecretAgentSimple *self = NM_SECRET_AGENT_SIMPLE (agent);
NMSecretAgentSimplePrivate *priv = NM_SECRET_AGENT_SIMPLE_GET_PRIVATE (self);
NMSecretAgentSimpleRequest *request;
NMSettingConnection *s_con;
const char *connection_type;
char *request_id;
@ -470,7 +469,7 @@ nmt_secret_agent_get_secrets (NMSecretAgent *agent,
goto nope;
}
request = g_slice_new (NmtSecretAgentRequest);
request = g_slice_new (NMSecretAgentSimpleRequest);
request->self = g_object_ref (self);
request->connection = g_object_ref (connection);
request->hints = g_strdupv ((gchar **)hints);
@ -479,37 +478,38 @@ nmt_secret_agent_get_secrets (NMSecretAgent *agent,
request->request_id = request_id;
g_hash_table_replace (priv->requests, request->request_id, request);
request_secrets_from_ui (request);
if (priv->enabled)
request_secrets_from_ui (request);
}
/**
* nmt_secret_agent_response:
* @self: the #NmtSecretAgent
* nm_secret_agent_simple_response:
* @self: the #NMSecretAgentSimple
* @request_id: the request ID being responded to
* @secrets: (allow-none): the array of secrets, or %NULL
*
* Response to a #NmtSecretAgent::get-secrets signal.
* Response to a #NMSecretAgentSimple::get-secrets signal.
*
* If the user provided secrets, the caller should set the
* corresponding <literal>value</literal> fields in the
* #NmtSecretAgentSecrets (freeing any initial values they had), and
* pass the array to nmt_secret_agent_response(). If the user
* #NMSecretAgentSimpleSecrets (freeing any initial values they had), and
* pass the array to nm_secret_agent_simple_response(). If the user
* cancelled the request, @secrets should be NULL.
*/
void
nmt_secret_agent_response (NmtSecretAgent *self,
const char *request_id,
GPtrArray *secrets)
nm_secret_agent_simple_response (NMSecretAgentSimple *self,
const char *request_id,
GPtrArray *secrets)
{
NmtSecretAgentPrivate *priv;
NmtSecretAgentRequest *request;
NMSecretAgentSimplePrivate *priv;
NMSecretAgentSimpleRequest *request;
GVariant *dict = NULL;
GError *error = NULL;
int i;
g_return_if_fail (NMT_IS_SECRET_AGENT (self));
g_return_if_fail (NM_IS_SECRET_AGENT_SIMPLE (self));
priv = NMT_SECRET_AGENT_GET_PRIVATE (self);
priv = NM_SECRET_AGENT_SIMPLE_GET_PRIVATE (self);
request = g_hash_table_lookup (priv->requests, request_id);
g_return_if_fail (request != NULL);
@ -521,7 +521,7 @@ nmt_secret_agent_response (NmtSecretAgent *self,
settings = g_hash_table_new (g_str_hash, g_str_equal);
for (i = 0; i < secrets->len; i++) {
NmtSecretAgentSecretReal *secret = secrets->pdata[i];
NMSecretAgentSimpleSecretReal *secret = secrets->pdata[i];
setting_builder = g_hash_table_lookup (settings, nm_setting_get_name (secret->setting));
if (!setting_builder) {
@ -546,76 +546,124 @@ nmt_secret_agent_response (NmtSecretAgent *self,
"User cancelled");
}
request->callback (NM_SECRET_AGENT (self), request->connection, dict, error, request->callback_data);
request->callback (NM_SECRET_AGENT_OLD (self), request->connection, dict, error, request->callback_data);
g_clear_error (&error);
g_hash_table_remove (priv->requests, request_id);
}
static void
nmt_secret_agent_cancel_get_secrets (NMSecretAgent *agent,
const gchar *connection_path,
const gchar *setting_name)
nm_secret_agent_simple_cancel_get_secrets (NMSecretAgentOld *agent,
const gchar *connection_path,
const gchar *setting_name)
{
/* We don't support cancellation. Sorry! */
}
static void
nmt_secret_agent_save_secrets (NMSecretAgent *agent,
NMConnection *connection,
const gchar *connection_path,
NMSecretAgentSaveSecretsFunc callback,
gpointer callback_data)
nm_secret_agent_simple_save_secrets (NMSecretAgentOld *agent,
NMConnection *connection,
const gchar *connection_path,
NMSecretAgentOldSaveSecretsFunc callback,
gpointer callback_data)
{
/* We don't support secret storage */
callback (agent, connection, NULL, callback_data);}
callback (agent, connection, NULL, callback_data);
}
static void
nmt_secret_agent_delete_secrets (NMSecretAgent *agent,
NMConnection *connection,
const gchar *connection_path,
NMSecretAgentDeleteSecretsFunc callback,
gpointer callback_data)
nm_secret_agent_simple_delete_secrets (NMSecretAgentOld *agent,
NMConnection *connection,
const gchar *connection_path,
NMSecretAgentOldDeleteSecretsFunc callback,
gpointer callback_data)
{
/* We don't support secret storage, so there's nothing to delete. */
callback (agent, connection, NULL, callback_data);
}
/**
* nm_secret_agent_simple_enable:
* @self: the #NMSecretAgentSimple
* @path: (allow-none): the path of the connection (if any) to handle secrets
* for. If %NULL, secrets for any connection will be handled.
*
* Enables servicing the requests including the already queued ones. If @path
* is given, the agent will only handle requests for connections that match
* @path.
*/
void
nmt_secret_agent_class_init (NmtSecretAgentClass *klass)
nm_secret_agent_simple_enable (NMSecretAgentSimple *self, const char *path)
{
NMSecretAgentSimplePrivate *priv = NM_SECRET_AGENT_SIMPLE_GET_PRIVATE (self);
GList *requests, *iter;
GError *error;
if (g_strcmp0 (path, priv->path) != 0) {
g_free (priv->path);
priv->path = g_strdup (path);
}
if (priv->enabled)
return;
priv->enabled = TRUE;
/* Service pending secret requests. */
requests = g_hash_table_get_values (priv->requests);
for (iter = requests; iter; iter = g_list_next (iter)) {
NMSecretAgentSimpleRequest *request = iter->data;
if (g_str_has_prefix (request->request_id, priv->path)) {
request_secrets_from_ui (request);
} else {
/* We only handle requests for connection with @path if set. */
error = g_error_new (NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR_FAILED,
"Request for %s secrets doesn't match path %s",
request->request_id, priv->path);
request->callback (NM_SECRET_AGENT_OLD (self), request->connection, NULL, error, request->callback_data);
g_hash_table_remove (priv->requests, request->request_id);
g_error_free (error);
}
}
g_list_free (requests);
}
void
nm_secret_agent_simple_class_init (NMSecretAgentSimpleClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
NMSecretAgentClass *agent_class = NM_SECRET_AGENT_CLASS (klass);
NMSecretAgentOldClass *agent_class = NM_SECRET_AGENT_OLD_CLASS (klass);
g_type_class_add_private (klass, sizeof (NmtSecretAgentPrivate));
g_type_class_add_private (klass, sizeof (NMSecretAgentSimplePrivate));
gobject_class->finalize = nmt_secret_agent_finalize;
gobject_class->finalize = nm_secret_agent_simple_finalize;
agent_class->get_secrets = nmt_secret_agent_get_secrets;
agent_class->cancel_get_secrets = nmt_secret_agent_cancel_get_secrets;
agent_class->save_secrets = nmt_secret_agent_save_secrets;
agent_class->delete_secrets = nmt_secret_agent_delete_secrets;
agent_class->get_secrets = nm_secret_agent_simple_get_secrets;
agent_class->cancel_get_secrets = nm_secret_agent_simple_cancel_get_secrets;
agent_class->save_secrets = nm_secret_agent_simple_save_secrets;
agent_class->delete_secrets = nm_secret_agent_simple_delete_secrets;
/**
* NmtSecretAgent::request-secrets:
* @agent: the #NmtSecretAgent
* NMSecretAgentSimple::request-secrets:
* @agent: the #NMSecretAgentSimple
* @request_id: request ID, to eventually pass to
* nmt_secret_agent_response().
* nm_secret_agent_simple_response().
* @title: a title for the password dialog
* @prompt: a prompt message for the password dialog
* @secrets: (element-type #NmtSecretAgentSecret): array of secrets
* @secrets: (element-type #NMSecretAgentSimpleSecret): array of secrets
* being requested.
*
* Emitted when the agent requires secrets from the user.
*
* The application should create a password dialog (eg,
* #NmtPasswordDialog) with the given title and prompt, and an
* entry for each element of @secrets. If any of the secrets
* already have a <literal>value</literal> filled in, the
* corresponding entry should be initialized to that value.
* The application should ask user for the secrets. For example,
* nmtui should create a password dialog (#NmtPasswordDialog)
* with the given title and prompt, and an entry for each
* element of @secrets. If any of the secrets already have a
* <literal>value</literal> filled in, the corresponding entry
* should be initialized to that value.
*
* When the dialog is complete, the app must call
* nmt_secret_agent_response() with the results.
* nm_secret_agent_simple_response() with the results.
*/
signals[REQUEST_SECRETS] = g_signal_new ("request-secrets",
G_TYPE_FROM_CLASS (klass),
@ -629,16 +677,19 @@ nmt_secret_agent_class_init (NmtSecretAgentClass *klass)
}
/**
* nmt_secret_agent_new:
* nm_secret_agent_simple_new:
* @name: the identifier of secret agent
*
* Creates a new #NmtSecretAgent.
* Creates a new #NMSecretAgentSimple. It does not serve any requests until
* nm_secret_agent_simple_enable() is called.
*
* Returns: a new #NmtSecretAgent
* Returns: a new #NMSecretAgentSimple if the agent creation is successful
* or %NULL in case of a failure.
*/
NMSecretAgent *
nmt_secret_agent_new (void)
NMSecretAgentOld *
nm_secret_agent_simple_new (const char *name)
{
return g_initable_new (NMT_TYPE_SECRET_AGENT, NULL, NULL,
NM_SECRET_AGENT_IDENTIFIER, "nmtui",
return g_initable_new (NM_TYPE_SECRET_AGENT_SIMPLE, NULL, NULL,
NM_SECRET_AGENT_OLD_IDENTIFIER, name,
NULL);
}

View file

@ -0,0 +1,62 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* 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, see <http://www.gnu.org/licenses/>.
*
* Copyright 2013 - 2014 Red Hat, Inc.
*/
#ifndef __NM_SECRET_AGENT_SIMPLE_H__
#define __NM_SECRET_AGENT_SIMPLE_H__
#include <NetworkManager.h>
#include <nm-secret-agent-old.h>
G_BEGIN_DECLS
#define NM_TYPE_SECRET_AGENT_SIMPLE (nm_secret_agent_simple_get_type ())
#define NM_SECRET_AGENT_SIMPLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SECRET_AGENT_SIMPLE, NMSecretAgentSimple))
#define NM_SECRET_AGENT_SIMPLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SECRET_AGENT_SIMPLE, NMSecretAgentSimpleClass))
#define NM_IS_SECRET_AGENT_SIMPLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SECRET_AGENT_SIMPLE))
#define NM_IS_SECRET_AGENT_SIMPLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SECRET_AGENT_SIMPLE))
#define NM_SECRET_AGENT_SIMPLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SECRET_AGENT_SIMPLE, NMSecretAgentSimpleClass))
typedef struct {
NMSecretAgentOld parent;
} NMSecretAgentSimple;
typedef struct {
NMSecretAgentOldClass parent;
} NMSecretAgentSimpleClass;
typedef struct {
char *name, *prop_name, *value;
gboolean password;
} NMSecretAgentSimpleSecret;
GType nm_secret_agent_simple_get_type (void);
NMSecretAgentOld *nm_secret_agent_simple_new (const char *name);
void nm_secret_agent_simple_response (NMSecretAgentSimple *self,
const char *request_id,
GPtrArray *secrets);
void nm_secret_agent_simple_enable (NMSecretAgentSimple *self,
const char *path);
G_END_DECLS
#endif /* __NM_SECRET_AGENT_SIMPLE_H__ */

View file

@ -31,7 +31,7 @@
* Robert Love <rml@novell.com>
*/
#include <config.h>
#include "config.h"
#include <stdio.h>
#include <stdlib.h>

View file

@ -10,6 +10,7 @@ AM_CPPFLAGS= \
-I$(top_srcdir)/libnm \
-I$(top_builddir)/libnm \
-I$(srcdir)/newt \
-I$(top_srcdir)/clients/common \
$(GLIB_CFLAGS) \
$(NEWT_CFLAGS) \
$(GUDEV_CFLAGS) \
@ -54,8 +55,14 @@ nmtui_SOURCES = \
nmt-device-entry.h \
nmt-edit-connection-list.c \
nmt-edit-connection-list.h \
nmt-editor-grid.c \
nmt-editor-grid.h \
nmt-editor-page.c \
nmt-editor-page.h \
nmt-editor-page-device.c \
nmt-editor-page-device.h \
nmt-editor-section.c \
nmt-editor-section.h \
nmt-editor.c \
nmt-editor.h \
nmt-ip-entry.c \
@ -70,22 +77,16 @@ nmtui_SOURCES = \
nmt-page-bridge.h \
nmt-page-bridge-port.c \
nmt-page-bridge-port.h \
nmt-page-device.c \
nmt-page-device.h \
nmt-page-dsl.c \
nmt-page-dsl.h \
nmt-page-ethernet.c \
nmt-page-ethernet.h \
nmt-page-grid.c \
nmt-page-grid.h \
nmt-page-infiniband.c \
nmt-page-infiniband.h \
nmt-page-ip4.c \
nmt-page-ip4.h \
nmt-page-ip6.c \
nmt-page-ip6.h \
nmt-page-main.c \
nmt-page-main.h \
nmt-page-ppp.c \
nmt-page-ppp.h \
nmt-page-team.c \
@ -106,14 +107,14 @@ nmtui_SOURCES = \
nmt-route-entry.h \
nmt-route-table.c \
nmt-route-table.h \
nmt-secret-agent.c \
nmt-secret-agent.h \
nmt-slave-list.c \
nmt-slave-list.h \
nmt-utils.c \
nmt-utils.h \
nmt-widget-list.c \
nmt-widget-list.h \
$(srcdir)/../common/nm-secret-agent-simple.c \
$(srcdir)/../common/nm-secret-agent-simple.h \
$(NULL)
nmtui_LDADD = \

View file

@ -147,12 +147,27 @@ nmt_newt_popup_activated (NmtNewtWidget *widget)
for (i = 0; i < priv->entries->len; i++)
nmt_newt_listbox_append (NMT_NEWT_LISTBOX (listbox), entries[i].label, NULL);
nmt_newt_listbox_set_active (NMT_NEWT_LISTBOX (listbox), priv->active);
nmt_newt_widget_set_padding (listbox, 1, 0, 1, 0);
nmt_newt_widget_size_request (listbox, &list_w, &list_h);
g_object_get (nmt_newt_widget_get_form (widget),
"x", &window_x,
"y", &window_y,
NULL);
newtComponentGetPosition (nmt_newt_component_get_component (NMT_NEWT_COMPONENT (widget)),
&button_x, &button_y);
window_x = button_x + 4;
window_y = button_y + 2 - priv->active;
/* (window_x + button_x) is the screen X coordinate of the newtComponent. A
* newtButton labelled "Foo" is rendered as " <Foo>" (with a preceding
* space), so the "F" is at (window_x + button_x + 2). We've added 1 column
* of padding to the left of the listbox, so we need to position the popup
* at (window_x + button_x + 1) in order for its text to be aligned with the
* button's text. (The x and y coordinates given to NmtNewtForm are the
* coordinates of the top left of the window content, ignoring the border
* graphics.)
*/
window_x += button_x + 1;
window_y += button_y - priv->active;
form = g_object_new (NMT_TYPE_NEWT_FORM,
"x", window_x,

View file

@ -260,12 +260,12 @@ nmt_newt_section_size_request (NmtNewtWidget *widget,
int *height)
{
NmtNewtSectionPrivate *priv = NMT_NEWT_SECTION_GET_PRIVATE (widget);
int border_width, border_height;
int w_ignore, h_ignore;
g_return_if_fail (priv->header != NULL && priv->body != NULL);
if (priv->show_border)
nmt_newt_widget_size_request (priv->border_grid, &border_width, &border_height);
nmt_newt_widget_size_request (priv->border_grid, &w_ignore, &h_ignore);
nmt_newt_widget_size_request (priv->header, &priv->hwidth_req, &priv->hheight_req);
nmt_newt_widget_size_request (priv->body, &priv->bwidth_req, &priv->bheight_req);
@ -322,10 +322,10 @@ nmt_newt_section_size_allocate (NmtNewtWidget *widget,
NmtNewtSectionPrivate *priv = NMT_NEWT_SECTION_GET_PRIVATE (widget);
if (priv->show_border) {
int border_height, border_width;
int w_ignore, h_ignore;
adjust_border_for_allocation (priv, height);
nmt_newt_widget_size_request (priv->border_grid, &border_height, &border_width);
nmt_newt_widget_size_request (priv->border_grid, &w_ignore, &h_ignore);
nmt_newt_widget_size_allocate (priv->border_grid, x, y, 1, height);
nmt_newt_widget_size_allocate (priv->header, x + 2, y, width, priv->hheight_req);
} else

File diff suppressed because it is too large Load diff

View file

@ -25,49 +25,28 @@ G_BEGIN_DECLS
void nm_editor_bindings_init (void);
void nm_editor_bind_ip4_addresses_with_prefix_to_strv (gpointer source,
void nm_editor_bind_ip_addresses_with_prefix_to_strv (int family,
gpointer source,
const gchar *source_property,
gpointer target,
const gchar *target_property,
GBindingFlags flags);
void nm_editor_bind_ip4_addresses_to_strv (gpointer source,
const gchar *source_property,
gpointer target,
const gchar *target_property,
GBindingFlags flags);
void nm_editor_bind_ip4_gateway_to_string (gpointer source,
void nm_editor_bind_ip_addresses_to_strv (int family,
gpointer source,
const gchar *source_property,
gpointer target,
const gchar *target_property,
GBindingFlags flags);
void nm_editor_bind_ip4_route_to_strings (gpointer source,
const gchar *source_property,
gpointer dest_target,
const gchar *dest_target_property,
gpointer next_hop_target,
const gchar *next_hop_target_property,
gpointer metric_target,
const gchar *metric_target_property,
void nm_editor_bind_ip_gateway_to_string (int family,
NMSettingIPConfig *source,
gpointer target,
const gchar *target_property,
const gchar *target_sensitive_property,
GBindingFlags flags);
void nm_editor_bind_ip6_addresses_with_prefix_to_strv (gpointer source,
const gchar *source_property,
gpointer target,
const gchar *target_property,
GBindingFlags flags);
void nm_editor_bind_ip6_addresses_to_strv (gpointer source,
const gchar *source_property,
gpointer target,
const gchar *target_property,
GBindingFlags flags);
void nm_editor_bind_ip6_gateway_to_string (gpointer source,
const gchar *source_property,
gpointer target,
const gchar *target_property,
GBindingFlags flags);
void nm_editor_bind_ip6_route_to_strings (gpointer source,
void nm_editor_bind_ip_route_to_strings (int family,
gpointer source,
const gchar *source_property,
gpointer dest_target,
const gchar *dest_target_property,

View file

@ -272,7 +272,7 @@ get_available_connection_name (const char *format,
}
/* Find the next available unique connection name */
while (!cname && (i++ < 10000)) {
for (i = 1; !cname && i < 10000; i++) {
char *temp;
gboolean found = FALSE;

View file

@ -503,9 +503,11 @@ nmt_connect_connection_list_rebuild (NmtConnectConnectionList *list)
for (diter = nmt_devices; diter; diter = diter->next) {
nmtdev = diter->data;
if (diter != nmt_devices)
nmt_newt_listbox_append (listbox, "", NULL);
nmt_newt_listbox_append (listbox, nmtdev->name, NULL);
if (nmtdev->conns) {
if (diter != nmt_devices)
nmt_newt_listbox_append (listbox, "", NULL);
nmt_newt_listbox_append (listbox, nmtdev->name, NULL);
}
for (citer = nmtdev->conns; citer; citer = citer->next) {
nmtconn = citer->data;
@ -544,17 +546,9 @@ nmt_connect_connection_list_rebuild (NmtConnectConnectionList *list)
}
static void
rebuild_on_acs_changed (GObject *object,
GParamSpec *spec,
gpointer list)
{
nmt_connect_connection_list_rebuild (list);
}
static void
rebuild_on_devices_changed (NMClient *client,
NMDevice *device,
gpointer list)
rebuild_on_property_changed (GObject *object,
GParamSpec *spec,
gpointer list)
{
nmt_connect_connection_list_rebuild (list);
}
@ -565,11 +559,11 @@ nmt_connect_connection_list_constructed (GObject *object)
NmtConnectConnectionList *list = NMT_CONNECT_CONNECTION_LIST (object);
g_signal_connect (nm_client, "notify::" NM_CLIENT_ACTIVE_CONNECTIONS,
G_CALLBACK (rebuild_on_acs_changed), list);
g_signal_connect (nm_client, "device-added",
G_CALLBACK (rebuild_on_devices_changed), list);
g_signal_connect (nm_client, "device-removed",
G_CALLBACK (rebuild_on_devices_changed), list);
G_CALLBACK (rebuild_on_property_changed), list);
g_signal_connect (nm_client, "notify::" NM_CLIENT_CONNECTIONS,
G_CALLBACK (rebuild_on_property_changed), list);
g_signal_connect (nm_client, "notify::" NM_CLIENT_DEVICES,
G_CALLBACK (rebuild_on_property_changed), list);
nmt_connect_connection_list_rebuild (list);
@ -583,8 +577,7 @@ nmt_connect_connection_list_finalize (GObject *object)
g_slist_free_full (priv->nmt_devices, (GDestroyNotify) nmt_connect_device_free);
g_signal_handlers_disconnect_by_func (nm_client, G_CALLBACK (rebuild_on_acs_changed), object);
g_signal_handlers_disconnect_by_func (nm_client, G_CALLBACK (rebuild_on_devices_changed), object);
g_signal_handlers_disconnect_by_func (nm_client, G_CALLBACK (rebuild_on_property_changed), object);
G_OBJECT_CLASS (nmt_connect_connection_list_parent_class)->finalize (object);
}

View file

@ -28,7 +28,7 @@
* matching a known #NMDevice, then it will also display the other
* property in parentheses.
*
* FIXME: #NmtDeviceEntry is currently an #NmtPageGrid object, so that
* FIXME: #NmtDeviceEntry is currently an #NmtEditorGrid object, so that
* we can possibly eventually add a button to its "extra" field, that
* would pop up a form for selecting a device. But if we're not going
* to implement that then we should make it just an #NmtNewtEntry.
@ -46,7 +46,7 @@
#include "nmtui.h"
#include "nmt-device-entry.h"
G_DEFINE_TYPE (NmtDeviceEntry, nmt_device_entry, NMT_TYPE_PAGE_GRID)
G_DEFINE_TYPE (NmtDeviceEntry, nmt_device_entry, NMT_TYPE_EDITOR_GRID)
#define NMT_DEVICE_ENTRY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_DEVICE_ENTRY, NmtDeviceEntryPrivate))
@ -379,7 +379,7 @@ nmt_device_entry_constructed (GObject *object)
{
NmtDeviceEntryPrivate *priv = NMT_DEVICE_ENTRY_GET_PRIVATE (object);
nmt_page_grid_append (NMT_PAGE_GRID (object), priv->label, NMT_NEWT_WIDGET (priv->entry), NULL);
nmt_editor_grid_append (NMT_EDITOR_GRID (object), priv->label, NMT_NEWT_WIDGET (priv->entry), NULL);
G_OBJECT_CLASS (nmt_device_entry_parent_class)->constructed (object);
}

View file

@ -19,7 +19,7 @@
#ifndef NMT_DEVICE_ENTRY_H
#define NMT_DEVICE_ENTRY_H
#include "nmt-page-grid.h"
#include "nmt-editor-grid.h"
#include <NetworkManager.h>
@ -33,12 +33,12 @@ G_BEGIN_DECLS
#define NMT_DEVICE_ENTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_DEVICE_ENTRY, NmtDeviceEntryClass))
typedef struct {
NmtPageGrid parent;
NmtEditorGrid parent;
} NmtDeviceEntry;
typedef struct {
NmtPageGridClass parent;
NmtEditorGridClass parent;
} NmtDeviceEntryClass;

View file

@ -17,10 +17,10 @@
*/
/**
* SECTION:nmt-page-grid
* SECTION:nmt-editor-grid
* @short_description: Grid widget for #NmtEditorPages
*
* #NmtPageGrid is the layout grid used by #NmtEditorPages. It
* #NmtEditorGrid is the layout grid used by #NmtEditorPages. It
* consists of a number of rows, each containing either a single
* widget that spans the entire width of the row, or else containing a
* label, a widget, and an optional extra widget.
@ -29,10 +29,10 @@
* its main widget is multiple rows high. The label and extra widgets
* will be top-aligned if the row is taller than they are.
*
* The #NmtPageGrids in a form behave as though they are all in a
* The #NmtEditorGrids in a form behave as though they are all in a
* "size group" together; they will all use the same column widths,
* which will be wide enough for the widest labels/widgets in any of
* the grids. #NmtPageGrid is also specially aware of #NmtNewtSection,
* the grids. #NmtEditorGrid is also specially aware of #NmtNewtSection,
* and grids inside sections will automatically take the size of the
* section border into account as well.
*/
@ -41,96 +41,100 @@
#include <string.h>
#include "nmt-page-grid.h"
#include "nmt-editor-grid.h"
G_DEFINE_TYPE (NmtPageGrid, nmt_page_grid, NMT_TYPE_NEWT_CONTAINER)
G_DEFINE_TYPE (NmtEditorGrid, nmt_editor_grid, NMT_TYPE_NEWT_CONTAINER)
#define NMT_PAGE_GRID_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_PAGE_GRID, NmtPageGridPrivate))
#define NMT_EDITOR_GRID_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_EDITOR_GRID, NmtEditorGridPrivate))
typedef struct {
GArray *rows;
int *row_heights;
int indent;
} NmtPageGridPrivate;
} NmtEditorGridPrivate;
typedef struct {
NmtNewtWidget *label;
NmtNewtWidget *widget;
NmtNewtWidget *extra;
NmtPageGridRowFlags flags;
} NmtPageGridRow;
NmtEditorGridRowFlags flags;
} NmtEditorGridRow;
typedef struct {
int col_widths[3];
} NmtPageGridFormState;
} NmtEditorGridFormState;
/**
* nmt_page_grid_new:
* nmt_editor_grid_new:
*
* Creates a new #NmtPageGrid
* Creates a new #NmtEditorGrid
*
* Returns: a new #NmtPageGrid
* Returns: a new #NmtEditorGrid
*/
NmtNewtWidget *
nmt_page_grid_new (void)
nmt_editor_grid_new (void)
{
return g_object_new (NMT_TYPE_PAGE_GRID,
return g_object_new (NMT_TYPE_EDITOR_GRID,
NULL);
}
static void
nmt_page_grid_init (NmtPageGrid *grid)
nmt_editor_grid_init (NmtEditorGrid *grid)
{
NmtPageGridPrivate *priv = NMT_PAGE_GRID_GET_PRIVATE (grid);
NmtEditorGridPrivate *priv = NMT_EDITOR_GRID_GET_PRIVATE (grid);
priv->rows = g_array_new (FALSE, TRUE, sizeof (NmtPageGridRow));
priv->rows = g_array_new (FALSE, TRUE, sizeof (NmtEditorGridRow));
}
static void
nmt_page_grid_finalize (GObject *object)
nmt_editor_grid_finalize (GObject *object)
{
NmtPageGridPrivate *priv = NMT_PAGE_GRID_GET_PRIVATE (object);
NmtEditorGridPrivate *priv = NMT_EDITOR_GRID_GET_PRIVATE (object);
g_array_unref (priv->rows);
g_clear_pointer (&priv->row_heights, g_free);
G_OBJECT_CLASS (nmt_page_grid_parent_class)->finalize (object);
G_OBJECT_CLASS (nmt_editor_grid_parent_class)->finalize (object);
}
/**
* nmt_page_grid_append:
* @grid: the #NmtPageGrid
* nmt_editor_grid_append:
* @grid: the #NmtEditorGrid
* @label: (allow-none): the label text for @widget, or %NULL
* @widget: the (main) widget
* @widget: (allow-none): the (main) widget
* @extra: (allow-none): optional extra widget
*
* Adds a row to @grid.
*
* If @label is non-%NULL, this will add a three-column row,
* containing a right-aligned #NmtNewtLabel in the first column,
* @widget in the second column, and @extra (if non-%NULL) in
* the third column.
* If @label and @widget are both non-%NULL, this will add a three-column row,
* containing a right-aligned #NmtNewtLabel in the first column, @widget in the
* second column, and @extra (if non-%NULL) in the third column.
*
* If @label is %NULL, then this will add a row with a single
* grid-spanning column, containing @widget.
* If either @label or @widget is %NULL, then the other column will expand into
* it.
*
* FIXME: That's sort of weird.
*
* See also nmt_page_grid_set_row_flags().
* See also nmt_editor_grid_set_row_flags().
*/
void
nmt_page_grid_append (NmtPageGrid *grid,
nmt_editor_grid_append (NmtEditorGrid *grid,
const char *label,
NmtNewtWidget *widget,
NmtNewtWidget *extra)
{
NmtPageGridPrivate *priv = NMT_PAGE_GRID_GET_PRIVATE (grid);
NmtNewtContainerClass *parent_class = NMT_NEWT_CONTAINER_CLASS (nmt_page_grid_parent_class);
NmtEditorGridPrivate *priv = NMT_EDITOR_GRID_GET_PRIVATE (grid);
NmtNewtContainerClass *parent_class = NMT_NEWT_CONTAINER_CLASS (nmt_editor_grid_parent_class);
NmtNewtContainer *container = NMT_NEWT_CONTAINER (grid);
NmtPageGridRow row;
NmtEditorGridRow row;
g_return_if_fail (label != NULL || widget != NULL);
memset (&row, 0, sizeof (row));
if (label && !widget) {
widget = nmt_newt_label_new (label);
label = NULL;
}
if (label) {
row.label = nmt_newt_label_new (label);
parent_class->add (container, row.label);
@ -153,11 +157,11 @@ nmt_page_grid_append (NmtPageGrid *grid,
}
static int
nmt_page_grid_find_widget (NmtPageGrid *grid,
nmt_editor_grid_find_widget (NmtEditorGrid *grid,
NmtNewtWidget *widget)
{
NmtPageGridPrivate *priv = NMT_PAGE_GRID_GET_PRIVATE (grid);
NmtPageGridRow *rows = (NmtPageGridRow *) priv->rows->data;
NmtEditorGridPrivate *priv = NMT_EDITOR_GRID_GET_PRIVATE (grid);
NmtEditorGridRow *rows = (NmtEditorGridRow *) priv->rows->data;
int i;
for (i = 0; i < priv->rows->len; i++) {
@ -169,48 +173,48 @@ nmt_page_grid_find_widget (NmtPageGrid *grid,
}
/**
* NmtPageGridRowFlags:
* @NMT_PAGE_GRID_ROW_LABEL_ALIGN_LEFT: the row's label should be
* NmtEditorGridRowFlags:
* @NMT_EDITOR_GRID_ROW_LABEL_ALIGN_LEFT: the row's label should be
* aligned left instead of right.
* @NMT_PAGE_GRID_ROW_EXTRA_ALIGN_RIGHT: the row's extra widget
* @NMT_EDITOR_GRID_ROW_EXTRA_ALIGN_RIGHT: the row's extra widget
* should be aligned right instead of left.
*
* Flags to alter an #NmtPageGrid row's layout.
* Flags to alter an #NmtEditorGrid row's layout.
*/
/**
* nmt_page_grid_set_row_flags:
* @grid: an #NmtPageGrid
* nmt_editor_grid_set_row_flags:
* @grid: an #NmtEditorGrid
* @widget: the widget whose row you want to adjust
* @flags: the flags to set
*
* Sets flags to adjust the layout of @widget's row in @grid.
*/
void
nmt_page_grid_set_row_flags (NmtPageGrid *grid,
nmt_editor_grid_set_row_flags (NmtEditorGrid *grid,
NmtNewtWidget *widget,
NmtPageGridRowFlags flags)
NmtEditorGridRowFlags flags)
{
NmtPageGridPrivate *priv = NMT_PAGE_GRID_GET_PRIVATE (grid);
NmtPageGridRow *rows = (NmtPageGridRow *) priv->rows->data;
NmtEditorGridPrivate *priv = NMT_EDITOR_GRID_GET_PRIVATE (grid);
NmtEditorGridRow *rows = (NmtEditorGridRow *) priv->rows->data;
int i;
i = nmt_page_grid_find_widget (grid, widget);
i = nmt_editor_grid_find_widget (grid, widget);
if (i != -1)
rows[i].flags = flags;
}
static void
nmt_page_grid_remove (NmtNewtContainer *container,
nmt_editor_grid_remove (NmtNewtContainer *container,
NmtNewtWidget *widget)
{
NmtPageGrid *grid = NMT_PAGE_GRID (container);
NmtPageGridPrivate *priv = NMT_PAGE_GRID_GET_PRIVATE (grid);
NmtNewtContainerClass *parent_class = NMT_NEWT_CONTAINER_CLASS (nmt_page_grid_parent_class);
NmtPageGridRow *rows = (NmtPageGridRow *) priv->rows->data;
NmtEditorGrid *grid = NMT_EDITOR_GRID (container);
NmtEditorGridPrivate *priv = NMT_EDITOR_GRID_GET_PRIVATE (grid);
NmtNewtContainerClass *parent_class = NMT_NEWT_CONTAINER_CLASS (nmt_editor_grid_parent_class);
NmtEditorGridRow *rows = (NmtEditorGridRow *) priv->rows->data;
int i;
i = nmt_page_grid_find_widget (grid, widget);
i = nmt_editor_grid_find_widget (grid, widget);
if (i != -1) {
if (rows[i].label)
parent_class->remove (container, rows[i].label);
@ -227,10 +231,10 @@ nmt_page_grid_remove (NmtNewtContainer *container,
}
static newtComponent *
nmt_page_grid_get_components (NmtNewtWidget *widget)
nmt_editor_grid_get_components (NmtNewtWidget *widget)
{
NmtPageGridPrivate *priv = NMT_PAGE_GRID_GET_PRIVATE (widget);
NmtPageGridRow *rows = (NmtPageGridRow *) priv->rows->data;
NmtEditorGridPrivate *priv = NMT_EDITOR_GRID_GET_PRIVATE (widget);
NmtEditorGridRow *rows = (NmtEditorGridRow *) priv->rows->data;
newtComponent *child_cos;
GPtrArray *cos;
int i, c;
@ -265,31 +269,31 @@ nmt_page_grid_get_components (NmtNewtWidget *widget)
return (newtComponent *) g_ptr_array_free (cos, FALSE);
}
static NmtPageGridFormState *
static NmtEditorGridFormState *
get_form_state (NmtNewtWidget *widget)
{
NmtNewtForm *form = nmt_newt_widget_get_form (widget);
NmtPageGridFormState *state;
NmtEditorGridFormState *state;
if (!form)
return NULL;
state = g_object_get_data (G_OBJECT (form), "NmtPageGridFormState");
state = g_object_get_data (G_OBJECT (form), "NmtEditorGridFormState");
if (state)
return state;
state = g_new0 (NmtPageGridFormState, 1);
g_object_set_data_full (G_OBJECT (form), "NmtPageGridFormState", state, g_free);
state = g_new0 (NmtEditorGridFormState, 1);
g_object_set_data_full (G_OBJECT (form), "NmtEditorGridFormState", state, g_free);
return state;
}
static void
nmt_page_grid_realize (NmtNewtWidget *widget)
nmt_editor_grid_realize (NmtNewtWidget *widget)
{
NmtPageGridPrivate *priv = NMT_PAGE_GRID_GET_PRIVATE (widget);
NmtEditorGridPrivate *priv = NMT_EDITOR_GRID_GET_PRIVATE (widget);
NmtNewtWidget *parent;
NMT_NEWT_WIDGET_CLASS (nmt_page_grid_parent_class)->realize (widget);
NMT_NEWT_WIDGET_CLASS (nmt_editor_grid_parent_class)->realize (widget);
/* This is a hack, but it's the simplest way to make it work... */
priv->indent = 0;
@ -305,24 +309,24 @@ nmt_page_grid_realize (NmtNewtWidget *widget)
}
static void
nmt_page_grid_unrealize (NmtNewtWidget *widget)
nmt_editor_grid_unrealize (NmtNewtWidget *widget)
{
NmtPageGridFormState *state = get_form_state (widget);
NmtEditorGridFormState *state = get_form_state (widget);
if (state)
memset (state->col_widths, 0, sizeof (state->col_widths));
NMT_NEWT_WIDGET_CLASS (nmt_page_grid_parent_class)->unrealize (widget);
NMT_NEWT_WIDGET_CLASS (nmt_editor_grid_parent_class)->unrealize (widget);
}
static void
nmt_page_grid_size_request (NmtNewtWidget *widget,
nmt_editor_grid_size_request (NmtNewtWidget *widget,
int *width,
int *height)
{
NmtPageGridPrivate *priv = NMT_PAGE_GRID_GET_PRIVATE (widget);
NmtPageGridRow *rows = (NmtPageGridRow *) priv->rows->data;
NmtPageGridFormState *state = get_form_state (widget);
NmtEditorGridPrivate *priv = NMT_EDITOR_GRID_GET_PRIVATE (widget);
NmtEditorGridRow *rows = (NmtEditorGridRow *) priv->rows->data;
NmtEditorGridFormState *state = get_form_state (widget);
gboolean add_padding = FALSE;
int i;
@ -367,15 +371,15 @@ nmt_page_grid_size_request (NmtNewtWidget *widget,
static void
nmt_page_grid_size_allocate (NmtNewtWidget *widget,
nmt_editor_grid_size_allocate (NmtNewtWidget *widget,
int x,
int y,
int width,
int height)
{
NmtPageGridPrivate *priv = NMT_PAGE_GRID_GET_PRIVATE (widget);
NmtPageGridRow *rows = (NmtPageGridRow *) priv->rows->data;
NmtPageGridFormState *state = get_form_state (widget);
NmtEditorGridPrivate *priv = NMT_EDITOR_GRID_GET_PRIVATE (widget);
NmtEditorGridRow *rows = (NmtEditorGridRow *) priv->rows->data;
NmtEditorGridFormState *state = get_form_state (widget);
int col0_width, col1_width, col2_width;
int i, row;
@ -390,7 +394,7 @@ nmt_page_grid_size_allocate (NmtNewtWidget *widget,
if (rows[i].label) {
int lwidth, lheight, lx;
if (rows[i].flags & NMT_PAGE_GRID_ROW_LABEL_ALIGN_LEFT)
if (rows[i].flags & NMT_EDITOR_GRID_ROW_LABEL_ALIGN_LEFT)
lx = x;
else {
nmt_newt_widget_size_request (rows[i].label, &lwidth, &lheight);
@ -408,27 +412,28 @@ nmt_page_grid_size_allocate (NmtNewtWidget *widget,
y + row,
col1_width,
priv->row_heights[i]);
if (rows[i].extra) {
int wwidth, wheight, ex;
if (rows[i].flags & NMT_PAGE_GRID_ROW_EXTRA_ALIGN_RIGHT)
ex = x + col0_width + col1_width + 2;
else {
nmt_newt_widget_size_request (rows[i].widget, &wwidth, &wheight);
ex = x + col0_width + wwidth + 2;
}
nmt_newt_widget_size_allocate (rows[i].extra,
ex,
y + row,
col2_width,
priv->row_heights[i]);
}
} else {
nmt_newt_widget_size_allocate (rows[i].widget,
x,
y + row,
col0_width + col1_width + col2_width + 2,
col0_width + col1_width + 1,
priv->row_heights[i]);
}
if (rows[i].extra) {
int wwidth, wheight, ex;
if (rows[i].flags & NMT_EDITOR_GRID_ROW_EXTRA_ALIGN_RIGHT)
ex = x + col0_width + col1_width + 2;
else {
nmt_newt_widget_size_request (rows[i].widget, &wwidth, &wheight);
ex = x + col0_width + wwidth + 2;
}
nmt_newt_widget_size_allocate (rows[i].extra,
ex,
y + row,
col2_width,
priv->row_heights[i]);
}
@ -437,22 +442,22 @@ nmt_page_grid_size_allocate (NmtNewtWidget *widget,
}
static void
nmt_page_grid_class_init (NmtPageGridClass *grid_class)
nmt_editor_grid_class_init (NmtEditorGridClass *grid_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (grid_class);
NmtNewtWidgetClass *widget_class = NMT_NEWT_WIDGET_CLASS (grid_class);
NmtNewtContainerClass *container_class = NMT_NEWT_CONTAINER_CLASS (grid_class);
g_type_class_add_private (grid_class, sizeof (NmtPageGridPrivate));
g_type_class_add_private (grid_class, sizeof (NmtEditorGridPrivate));
/* virtual methods */
object_class->finalize = nmt_page_grid_finalize;
object_class->finalize = nmt_editor_grid_finalize;
widget_class->realize = nmt_page_grid_realize;
widget_class->unrealize = nmt_page_grid_unrealize;
widget_class->get_components = nmt_page_grid_get_components;
widget_class->size_request = nmt_page_grid_size_request;
widget_class->size_allocate = nmt_page_grid_size_allocate;
widget_class->realize = nmt_editor_grid_realize;
widget_class->unrealize = nmt_editor_grid_unrealize;
widget_class->get_components = nmt_editor_grid_get_components;
widget_class->size_request = nmt_editor_grid_size_request;
widget_class->size_allocate = nmt_editor_grid_size_allocate;
container_class->remove = nmt_page_grid_remove;
container_class->remove = nmt_editor_grid_remove;
}

View file

@ -16,47 +16,47 @@
* Copyright 2013 Red Hat, Inc.
*/
#ifndef NMT_PAGE_GRID_H
#define NMT_PAGE_GRID_H
#ifndef NMT_EDITOR_GRID_H
#define NMT_EDITOR_GRID_H
#include "nmt-newt.h"
G_BEGIN_DECLS
#define NMT_TYPE_PAGE_GRID (nmt_page_grid_get_type ())
#define NMT_PAGE_GRID(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMT_TYPE_PAGE_GRID, NmtPageGrid))
#define NMT_PAGE_GRID_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMT_TYPE_PAGE_GRID, NmtPageGridClass))
#define NMT_IS_PAGE_GRID(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMT_TYPE_PAGE_GRID))
#define NMT_IS_PAGE_GRID_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMT_TYPE_PAGE_GRID))
#define NMT_PAGE_GRID_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_PAGE_GRID, NmtPageGridClass))
#define NMT_TYPE_EDITOR_GRID (nmt_editor_grid_get_type ())
#define NMT_EDITOR_GRID(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMT_TYPE_EDITOR_GRID, NmtEditorGrid))
#define NMT_EDITOR_GRID_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMT_TYPE_EDITOR_GRID, NmtEditorGridClass))
#define NMT_IS_EDITOR_GRID(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMT_TYPE_EDITOR_GRID))
#define NMT_IS_EDITOR_GRID_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMT_TYPE_EDITOR_GRID))
#define NMT_EDITOR_GRID_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_EDITOR_GRID, NmtEditorGridClass))
typedef struct {
NmtNewtContainer parent;
} NmtPageGrid;
} NmtEditorGrid;
typedef struct {
NmtNewtContainerClass parent;
} NmtPageGridClass;
} NmtEditorGridClass;
GType nmt_page_grid_get_type (void);
GType nmt_editor_grid_get_type (void);
typedef enum {
NMT_PAGE_GRID_ROW_LABEL_ALIGN_LEFT = (1 << 0),
NMT_PAGE_GRID_ROW_EXTRA_ALIGN_RIGHT = (1 << 1)
} NmtPageGridRowFlags;
NMT_EDITOR_GRID_ROW_LABEL_ALIGN_LEFT = (1 << 0),
NMT_EDITOR_GRID_ROW_EXTRA_ALIGN_RIGHT = (1 << 1)
} NmtEditorGridRowFlags;
NmtNewtWidget *nmt_page_grid_new (void);
NmtNewtWidget *nmt_editor_grid_new (void);
void nmt_page_grid_append (NmtPageGrid *grid,
void nmt_editor_grid_append (NmtEditorGrid *grid,
const char *label,
NmtNewtWidget *widget,
NmtNewtWidget *extra);
void nmt_page_grid_set_row_flags (NmtPageGrid *grid,
void nmt_editor_grid_set_row_flags (NmtEditorGrid *grid,
NmtNewtWidget *widget,
NmtPageGridRowFlags flags);
NmtEditorGridRowFlags flags);
G_END_DECLS
#endif /* NMT_PAGE_GRID_H */
#endif /* NMT_EDITOR_GRID_H */

View file

@ -17,10 +17,10 @@
*/
/**
* SECTION:nmt-page-device
* SECTION:nmt-editor-page-device
* @short_description: Abstract base class for "device" editor pages
*
* #NmtPageDevice is the base class for #NmtEditorPage subclasses
* #NmtEditorPageDevice is the base class for #NmtEditorPage subclasses
* representing device-type-specific data. (Eg, #NmtPageEthernet,
* #NmtPageVlan, etc).
*
@ -30,72 +30,60 @@
#include "config.h"
#include "nmt-page-device.h"
#include "nmt-editor-page-device.h"
G_DEFINE_TYPE (NmtPageDevice, nmt_page_device, NMT_TYPE_EDITOR_PAGE)
G_DEFINE_TYPE (NmtEditorPageDevice, nmt_editor_page_device, NMT_TYPE_EDITOR_PAGE)
#define NMT_PAGE_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_PAGE_DEVICE, NmtPageDevicePrivate))
#define NMT_EDITOR_PAGE_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_EDITOR_PAGE_DEVICE, NmtEditorPageDevicePrivate))
typedef struct {
NmtDeviceEntry *device_entry;
gboolean show_by_default;
} NmtPageDevicePrivate;
} NmtEditorPageDevicePrivate;
enum {
PROP_0,
PROP_DEVICE_ENTRY,
PROP_SHOW_BY_DEFAULT,
LAST_PROP
};
static void
nmt_page_device_init (NmtPageDevice *device)
nmt_editor_page_device_init (NmtEditorPageDevice *device)
{
}
static void
nmt_page_device_finalize (GObject *object)
nmt_editor_page_device_finalize (GObject *object)
{
NmtPageDevicePrivate *priv = NMT_PAGE_DEVICE_GET_PRIVATE (object);
NmtEditorPageDevicePrivate *priv = NMT_EDITOR_PAGE_DEVICE_GET_PRIVATE (object);
g_clear_object (&priv->device_entry);
G_OBJECT_CLASS (nmt_page_device_parent_class)->finalize (object);
G_OBJECT_CLASS (nmt_editor_page_device_parent_class)->finalize (object);
}
NmtDeviceEntry *
nmt_page_device_get_device_entry (NmtPageDevice *page)
nmt_editor_page_device_get_device_entry (NmtEditorPageDevice *page)
{
NmtPageDevicePrivate *priv = NMT_PAGE_DEVICE_GET_PRIVATE (page);
NmtEditorPageDevicePrivate *priv = NMT_EDITOR_PAGE_DEVICE_GET_PRIVATE (page);
return priv->device_entry;
}
static gboolean
nmt_page_device_show_by_default (NmtEditorPage *page)
{
NmtPageDevicePrivate *priv = NMT_PAGE_DEVICE_GET_PRIVATE (page);
return priv->show_by_default;
}
static void
nmt_page_device_set_property (GObject *object,
nmt_editor_page_device_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
NmtPageDevicePrivate *priv = NMT_PAGE_DEVICE_GET_PRIVATE (object);
NmtEditorPageDevicePrivate *priv = NMT_EDITOR_PAGE_DEVICE_GET_PRIVATE (object);
switch (prop_id) {
case PROP_DEVICE_ENTRY:
priv->device_entry = g_value_dup_object (value);
break;
case PROP_SHOW_BY_DEFAULT:
priv->show_by_default = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -103,20 +91,17 @@ nmt_page_device_set_property (GObject *object,
}
static void
nmt_page_device_get_property (GObject *object,
nmt_editor_page_device_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
NmtPageDevicePrivate *priv = NMT_PAGE_DEVICE_GET_PRIVATE (object);
NmtEditorPageDevicePrivate *priv = NMT_EDITOR_PAGE_DEVICE_GET_PRIVATE (object);
switch (prop_id) {
case PROP_DEVICE_ENTRY:
g_value_set_object (value, priv->device_entry);
break;
case PROP_SHOW_BY_DEFAULT:
g_value_set_boolean (value, priv->show_by_default);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -124,19 +109,16 @@ nmt_page_device_get_property (GObject *object,
}
static void
nmt_page_device_class_init (NmtPageDeviceClass *page_device_class)
nmt_editor_page_device_class_init (NmtEditorPageDeviceClass *page_device_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (page_device_class);
NmtEditorPageClass *page_class = NMT_EDITOR_PAGE_CLASS (page_device_class);
g_type_class_add_private (page_device_class, sizeof (NmtPageDevicePrivate));
g_type_class_add_private (page_device_class, sizeof (NmtEditorPageDevicePrivate));
/* virtual methods */
object_class->set_property = nmt_page_device_set_property;
object_class->get_property = nmt_page_device_get_property;
object_class->finalize = nmt_page_device_finalize;
page_class->show_by_default = nmt_page_device_show_by_default;
object_class->set_property = nmt_editor_page_device_set_property;
object_class->get_property = nmt_editor_page_device_get_property;
object_class->finalize = nmt_editor_page_device_finalize;
/* properties */
g_object_class_install_property
@ -146,11 +128,4 @@ nmt_page_device_class_init (NmtPageDeviceClass *page_device_class)
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property
(object_class, PROP_SHOW_BY_DEFAULT,
g_param_spec_boolean ("show-by-default", "", "",
TRUE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
}

View file

@ -0,0 +1,50 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* 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, see <http://www.gnu.org/licenses/>.
*
* Copyright 2013 Red Hat, Inc.
*/
#ifndef NMT_EDITOR_PAGE_DEVICE_H
#define NMT_EDITOR_PAGE_DEVICE_H
#include "nmt-editor-page.h"
#include "nmt-device-entry.h"
G_BEGIN_DECLS
#define NMT_TYPE_EDITOR_PAGE_DEVICE (nmt_editor_page_device_get_type ())
#define NMT_EDITOR_PAGE_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMT_TYPE_EDITOR_PAGE_DEVICE, NmtEditorPageDevice))
#define NMT_EDITOR_PAGE_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMT_TYPE_EDITOR_PAGE_DEVICE, NmtEditorPageDeviceClass))
#define NMT_IS_EDITOR_PAGE_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMT_TYPE_EDITOR_PAGE_DEVICE))
#define NMT_IS_EDITOR_PAGE_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMT_TYPE_EDITOR_PAGE_DEVICE))
#define NMT_EDITOR_PAGE_DEVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_EDITOR_PAGE_DEVICE, NmtEditorPageDeviceClass))
typedef struct {
NmtEditorPage parent;
} NmtEditorPageDevice;
typedef struct {
NmtEditorPageClass parent;
} NmtEditorPageDeviceClass;
GType nmt_editor_page_device_get_type (void);
NmtDeviceEntry *nmt_editor_page_device_get_device_entry (NmtEditorPageDevice *page);
G_END_DECLS
#endif /* NMT_EDITOR_PAGE_DEVICE_H */

View file

@ -21,9 +21,7 @@
* @short_description: An #NmtEditor "page"
*
* #NmtEditorPage is the abstract base class for #NmtEditor "pages".
* Note that despite the name, currently all "page" types except
* #NmtPageMain are actually displayed as collapsible sections, not
* separate tabs/forms.
* A "page" is a set of related #NmtEditorSections.
*/
#include "config.h"
@ -32,14 +30,13 @@
#include "nmt-editor-page.h"
G_DEFINE_ABSTRACT_TYPE (NmtEditorPage, nmt_editor_page, NMT_TYPE_PAGE_GRID)
G_DEFINE_ABSTRACT_TYPE (NmtEditorPage, nmt_editor_page, G_TYPE_OBJECT)
#define NMT_EDITOR_PAGE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_EDITOR_PAGE, NmtEditorPagePrivate))
typedef struct {
char *title;
NmtNewtWidget *header_widget;
NMConnection *connection;
GSList *sections;
} NmtEditorPagePrivate;
@ -47,7 +44,6 @@ enum {
PROP_0,
PROP_CONNECTION,
PROP_TITLE,
LAST_PROP
};
@ -55,9 +51,6 @@ enum {
static void
nmt_editor_page_init (NmtEditorPage *page)
{
NmtEditorPagePrivate *priv = NMT_EDITOR_PAGE_GET_PRIVATE (page);
priv->header_widget = g_object_ref_sink (nmt_newt_separator_new ());
}
static void
@ -65,9 +58,8 @@ nmt_editor_page_finalize (GObject *object)
{
NmtEditorPagePrivate *priv = NMT_EDITOR_PAGE_GET_PRIVATE (object);
g_free (priv->title);
g_clear_object (&priv->header_widget);
g_clear_object (&priv->connection);
g_slist_free_full (priv->sections, g_object_unref);
G_OBJECT_CLASS (nmt_editor_page_parent_class)->finalize (object);
}
@ -89,81 +81,37 @@ nmt_editor_page_get_connection (NmtEditorPage *page)
}
/**
* nmt_editor_page_set_header_widget:
* nmt_editor_page_get_sections:
* @page: the #NmtEditorPage
* @widget: an #NmtNewtWidget
*
* Sets the page's header widget. When displayed as a subpage of
* #NmtPageMain, this widget will be put into the corresponding
* #NmtNewtSection's header.
* Gets the page's list of sections to display.
*
* FIXME: for consistency, this should be a property as well.
* Returns: (transfer none): the list of sections; this is the internal list
* used by the page and must not be modified or freed.
*/
GSList *
nmt_editor_page_get_sections (NmtEditorPage *page)
{
NmtEditorPagePrivate *priv = NMT_EDITOR_PAGE_GET_PRIVATE (page);
return priv->sections;
}
/**
* nmt_editor_page_add_section:
* @page: the #NmtEditorPage
* @section: the #NmtEditorSection
*
* Adds a section to the page. This should only be called by #NmtEditorPage
* subclasses.
*/
void
nmt_editor_page_set_header_widget (NmtEditorPage *page,
NmtNewtWidget *widget)
nmt_editor_page_add_section (NmtEditorPage *page,
NmtEditorSection *section)
{
NmtEditorPagePrivate *priv = NMT_EDITOR_PAGE_GET_PRIVATE (page);
g_clear_object (&priv->header_widget);
if (!widget)
widget = nmt_newt_separator_new ();
priv->header_widget = g_object_ref_sink (widget);
}
/**
* nmt_editor_page_get_header_widget:
* @page: the #NmtEditorPage
*
* Gets the page's header widget. When displayed as a subpage of
* #NmtPageMain, this widget will be put into the corresponding
* #NmtNewtSection's header.
*
* Returns: (transfer none): the page's header widget.
*/
NmtNewtWidget *
nmt_editor_page_get_header_widget (NmtEditorPage *page)
{
NmtEditorPagePrivate *priv = NMT_EDITOR_PAGE_GET_PRIVATE (page);
return priv->header_widget;
}
/**
* nmt_editor_page_get_title:
* @page: the #NmtEditorPage
*
* Gets the page's title.
*
* Returns: the page's title
*/
const char *
nmt_editor_page_get_title (NmtEditorPage *page)
{
NmtEditorPagePrivate *priv = NMT_EDITOR_PAGE_GET_PRIVATE (page);
return priv->title;
}
static gboolean
nmt_editor_page_real_show_by_default (NmtEditorPage *page)
{
return TRUE;
}
/**
* nmt_editor_page_show_by_default:
* @page: the #NmtEditorPage
*
* Checks if @page should be shown expanded by default
*
* Returns: %TRUE or %FALSE
*/
gboolean
nmt_editor_page_show_by_default (NmtEditorPage *page)
{
return NMT_EDITOR_PAGE_GET_CLASS (page)->show_by_default (page);
priv->sections = g_slist_append (priv->sections, g_object_ref_sink (section));
}
static void
@ -178,9 +126,6 @@ nmt_editor_page_set_property (GObject *object,
case PROP_CONNECTION:
priv->connection = g_value_dup_object (value);
break;
case PROP_TITLE:
priv->title = g_value_dup_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -199,9 +144,6 @@ nmt_editor_page_get_property (GObject *object,
case PROP_CONNECTION:
g_value_set_object (value, priv->connection);
break;
case PROP_TITLE:
g_value_set_string (value, priv->title);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -220,8 +162,6 @@ nmt_editor_page_class_init (NmtEditorPageClass *page_class)
object_class->get_property = nmt_editor_page_get_property;
object_class->finalize = nmt_editor_page_finalize;
page_class->show_by_default = nmt_editor_page_real_show_by_default;
/* properties */
/**
@ -236,16 +176,4 @@ nmt_editor_page_class_init (NmtEditorPageClass *page_class)
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
/**
* NmtEditorPage:title:
*
* The page's title.
*/
g_object_class_install_property
(object_class, PROP_TITLE,
g_param_spec_string ("title", "", "",
NULL,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
}

View file

@ -13,7 +13,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2013 Red Hat, Inc.
* Copyright 2013-2014 Red Hat, Inc.
*/
#ifndef NMT_EDITOR_PAGE_H
@ -21,7 +21,8 @@
#include <NetworkManager.h>
#include "nmt-page-grid.h"
#include "nmt-editor-grid.h"
#include "nmt-editor-section.h"
G_BEGIN_DECLS
@ -33,27 +34,24 @@ G_BEGIN_DECLS
#define NMT_EDITOR_PAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_EDITOR_PAGE, NmtEditorPageClass))
typedef struct {
NmtPageGrid parent;
GObject parent;
} NmtEditorPage;
typedef struct {
NmtPageGridClass parent;
GObjectClass parent;
gboolean (*show_by_default) (NmtEditorPage *);
} NmtEditorPageClass;
GType nmt_editor_page_get_type (void);
NMConnection *nmt_editor_page_get_connection (NmtEditorPage *page);
void nmt_editor_page_set_header_widget (NmtEditorPage *page,
NmtNewtWidget *widget);
NmtNewtWidget *nmt_editor_page_get_header_widget (NmtEditorPage *page);
GSList *nmt_editor_page_get_sections (NmtEditorPage *page);
const char *nmt_editor_page_get_title (NmtEditorPage *page);
gboolean nmt_editor_page_show_by_default (NmtEditorPage *page);
/*< protected >*/
void nmt_editor_page_add_section (NmtEditorPage *page,
NmtEditorSection *section);
G_END_DECLS

View file

@ -0,0 +1,282 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* 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, see <http://www.gnu.org/licenses/>.
*
* Copyright 2013 Red Hat, Inc.
*/
/**
* SECTION:nmt-editor-section:
* @short_description: A section of the #NmtEditor
*
* #NmtEditorSection is the abstract base class for #NmtEditor sections.
*/
#include "config.h"
#include <glib/gi18n-lib.h>
#include "nmt-editor-section.h"
#include "nmt-newt-toggle-button.h"
G_DEFINE_TYPE (NmtEditorSection, nmt_editor_section, NMT_TYPE_NEWT_SECTION)
#define NMT_EDITOR_SECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_EDITOR_SECTION, NmtEditorSectionPrivate))
typedef struct {
NmtEditorGrid *header, *body;
char *title;
NmtNewtWidget *header_widget;
NmtNewtWidget *toggle;
gboolean show_by_default;
} NmtEditorSectionPrivate;
enum {
PROP_0,
PROP_TITLE,
PROP_SHOW_BY_DEFAULT,
PROP_HEADER_WIDGET,
LAST_PROP
};
/**
* nmt_editor_section_new:
* @title: the section title
* @header_widget: (allow-none): the widget to show next to the title
* @show_by_default: whether the section should be open by default
*
* Creates a new #NmtEditorSection.
*
* Returns: a new #NmtEditorSection
*/
NmtEditorSection *
nmt_editor_section_new (const char *title,
NmtNewtWidget *header_widget,
gboolean show_by_default)
{
return g_object_new (NMT_TYPE_EDITOR_SECTION,
"title", title,
"header-widget", header_widget,
"show-by-default", show_by_default,
NULL);
}
static void
rebuild_header (NmtEditorSection *section)
{
NmtEditorSectionPrivate *priv = NMT_EDITOR_SECTION_GET_PRIVATE (section);
/* Removing any widget in an NmtEditorGrid removes its whole row, so we can
* remove the existing title/widget/toggle by asking to remove toggle.
*/
nmt_newt_container_remove (NMT_NEWT_CONTAINER (priv->header), priv->toggle);
nmt_editor_grid_append (priv->header,
priv->title,
priv->header_widget,
priv->toggle);
nmt_editor_grid_set_row_flags (priv->header,
priv->toggle,
NMT_EDITOR_GRID_ROW_LABEL_ALIGN_LEFT |
NMT_EDITOR_GRID_ROW_EXTRA_ALIGN_RIGHT);
}
static void
nmt_editor_section_init (NmtEditorSection *section)
{
NmtEditorSectionPrivate *priv = NMT_EDITOR_SECTION_GET_PRIVATE (section);
priv->header = NMT_EDITOR_GRID (nmt_editor_grid_new ());
priv->body = NMT_EDITOR_GRID (nmt_editor_grid_new ());
priv->toggle = nmt_newt_toggle_button_new (_("Hide"), _("Show"));
g_object_ref_sink (priv->toggle);
nmt_newt_section_set_header (NMT_NEWT_SECTION (section), NMT_NEWT_WIDGET (priv->header));
nmt_newt_section_set_body (NMT_NEWT_SECTION (section), NMT_NEWT_WIDGET (priv->body));
g_object_bind_property (priv->toggle, "active",
section, "open",
G_BINDING_SYNC_CREATE);
}
static void
nmt_editor_section_finalize (GObject *object)
{
NmtEditorSectionPrivate *priv = NMT_EDITOR_SECTION_GET_PRIVATE (object);
g_free (priv->title);
g_clear_object (&priv->header_widget);
g_clear_object (&priv->toggle);
G_OBJECT_CLASS (nmt_editor_section_parent_class)->finalize (object);
}
/**
* nmt_editor_section_get_header_widget:
* @section: the #NmtEditorSection
*
* Gets the section's header widget.
*
* Returns: the section's header widget.
*/
NmtNewtWidget *
nmt_editor_section_get_header_widget (NmtEditorSection *section)
{
NmtEditorSectionPrivate *priv = NMT_EDITOR_SECTION_GET_PRIVATE (section);
return priv->header_widget;
}
/**
* nmt_editor_section_get_body:
* @section: the #NmtEditorSection
*
* Gets the section's body grid, so that you can add things to it.
*
* Returns: the #NmtEditorGrid used for the section body
*/
NmtEditorGrid *
nmt_editor_section_get_body (NmtEditorSection *section)
{
NmtEditorSectionPrivate *priv = NMT_EDITOR_SECTION_GET_PRIVATE (section);
return priv->body;
}
/**
* nmt_editor_section_get_title:
* @section: the #NmtEditorSection
*
* Gets the section's title.
*
* Returns: the section's title
*/
const char *
nmt_editor_section_get_title (NmtEditorSection *section)
{
NmtEditorSectionPrivate *priv = NMT_EDITOR_SECTION_GET_PRIVATE (section);
return priv->title;
}
static void
nmt_editor_section_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
NmtEditorSection *section = NMT_EDITOR_SECTION (object);
NmtEditorSectionPrivate *priv = NMT_EDITOR_SECTION_GET_PRIVATE (section);
switch (prop_id) {
case PROP_TITLE:
priv->title = g_value_dup_string (value);
rebuild_header (section);
break;
case PROP_SHOW_BY_DEFAULT:
priv->show_by_default = g_value_get_boolean (value);
nmt_newt_toggle_button_set_active (NMT_NEWT_TOGGLE_BUTTON (priv->toggle),
priv->show_by_default);
break;
case PROP_HEADER_WIDGET:
priv->header_widget = g_value_get_object (value);
if (priv->header_widget)
g_object_ref_sink (priv->header_widget);
rebuild_header (section);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
nmt_editor_section_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
NmtEditorSectionPrivate *priv = NMT_EDITOR_SECTION_GET_PRIVATE (object);
switch (prop_id) {
case PROP_TITLE:
g_value_set_string (value, priv->title);
break;
case PROP_SHOW_BY_DEFAULT:
g_value_set_boolean (value, priv->show_by_default);
break;
case PROP_HEADER_WIDGET:
g_value_set_object (value, priv->header_widget);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
nmt_editor_section_class_init (NmtEditorSectionClass *section_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (section_class);
g_type_class_add_private (section_class, sizeof (NmtEditorSectionPrivate));
/* virtual methods */
object_class->set_property = nmt_editor_section_set_property;
object_class->get_property = nmt_editor_section_get_property;
object_class->finalize = nmt_editor_section_finalize;
/* properties */
/**
* NmtEditorSection:title:
*
* The section's title.
*/
g_object_class_install_property
(object_class, PROP_TITLE,
g_param_spec_string ("title", "", "",
NULL,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
/**
* NmtEditorSection:show-by-default:
*
* Whether the section should be expanded by default.
*/
g_object_class_install_property
(object_class, PROP_SHOW_BY_DEFAULT,
g_param_spec_boolean ("show-by-default", "", "",
TRUE,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
/**
* NmtEditorSection:header-widget:
*
* The widget (if any) that appears between the section title and its toggle
* button.
*/
g_object_class_install_property
(object_class, PROP_HEADER_WIDGET,
g_param_spec_object ("header-widget", "", "",
NMT_TYPE_NEWT_WIDGET,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
}

View file

@ -0,0 +1,56 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* 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, see <http://www.gnu.org/licenses/>.
*
* Copyright 2013 Red Hat, Inc.
*/
#ifndef NMT_EDITOR_SECTION_H
#define NMT_EDITOR_SECTION_H
#include "nmt-newt-section.h"
#include "nmt-editor-grid.h"
G_BEGIN_DECLS
#define NMT_TYPE_EDITOR_SECTION (nmt_editor_section_get_type ())
#define NMT_EDITOR_SECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMT_TYPE_EDITOR_SECTION, NmtEditorSection))
#define NMT_EDITOR_SECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMT_TYPE_EDITOR_SECTION, NmtEditorSectionClass))
#define NMT_IS_EDITOR_SECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMT_TYPE_EDITOR_SECTION))
#define NMT_IS_EDITOR_SECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMT_TYPE_EDITOR_SECTION))
#define NMT_EDITOR_SECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_EDITOR_SECTION, NmtEditorSectionClass))
typedef struct {
NmtNewtSection parent;
} NmtEditorSection;
typedef struct {
NmtNewtSectionClass parent;
} NmtEditorSectionClass;
GType nmt_editor_section_get_type (void);
NmtEditorSection *nmt_editor_section_new (const char *title,
NmtNewtWidget *header_widget,
gboolean show_by_default);
const char *nmt_editor_section_get_title (NmtEditorSection *section);
NmtNewtWidget *nmt_editor_section_get_header_widget (NmtEditorSection *section);
NmtEditorGrid *nmt_editor_section_get_body (NmtEditorSection *section);
G_END_DECLS
#endif /* NMT_EDITOR_SECTION_H */

View file

@ -34,9 +34,26 @@
#include "nmtui.h"
#include "nm-editor-utils.h"
#include "nmt-page-main.h"
#include "nmt-utils.h"
#include "nmt-device-entry.h"
#include "nmt-mac-entry.h"
#include "nmt-mtu-entry.h"
#include "nmt-page-bond.h"
#include "nmt-page-bridge.h"
#include "nmt-page-bridge-port.h"
#include "nmt-page-dsl.h"
#include "nmt-page-ethernet.h"
#include "nmt-page-infiniband.h"
#include "nmt-page-ip4.h"
#include "nmt-page-ip6.h"
#include "nmt-page-ppp.h"
#include "nmt-page-team.h"
#include "nmt-page-team-port.h"
#include "nmt-page-vlan.h"
#include "nmt-page-wifi.h"
G_DEFINE_TYPE (NmtEditor, nmt_editor, NMT_TYPE_NEWT_FORM)
#define NMT_EDITOR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_EDITOR, NmtEditorPrivate))
@ -47,6 +64,7 @@ typedef struct {
NMEditorConnectionTypeData *type_data;
GSList *pages;
NmtNewtWidget *ok, *cancel;
gboolean running;
} NmtEditorPrivate;
@ -217,12 +235,71 @@ build_edit_connection (NMConnection *orig_connection)
return edit_connection;
}
static gboolean
permissions_transform_to_allusers (GBinding *binding,
const GValue *source_value,
GValue *target_value,
gpointer user_data)
{
char **perms = g_value_get_boxed (source_value);
g_value_set_boolean (target_value, g_strv_length (perms) == 0);
return TRUE;
}
static gboolean
permissions_transform_from_allusers (GBinding *binding,
const GValue *source_value,
GValue *target_value,
gpointer user_data)
{
gboolean allusers = g_value_get_boolean (source_value);
char **perms = NULL;
if (!allusers) {
perms = g_new (char *, 2);
perms[0] = g_strdup_printf ("user:%s:", g_get_user_name ());
perms[1] = NULL;
}
g_value_take_boxed (target_value, perms);
return TRUE;
}
static NmtNewtWidget *
add_sections_for_page (NmtEditor *editor, NmtEditorGrid *grid, NmtEditorPage *page)
{
NmtEditorPrivate *priv = NMT_EDITOR_GET_PRIVATE (editor);
NmtNewtWidget *first_section = NULL;
const GSList *sections, *iter;
g_return_val_if_fail (NMT_IS_EDITOR_PAGE (page), NULL);
priv->pages = g_slist_prepend (priv->pages, page);
sections = nmt_editor_page_get_sections (page);
for (iter = sections; iter; iter = iter->next) {
if (!first_section)
first_section = iter->data;
nmt_editor_grid_append (grid, NULL, iter->data, NULL);
}
return first_section;
}
static void
nmt_editor_constructed (GObject *object)
{
NmtEditor *editor = NMT_EDITOR (object);
NmtEditorPrivate *priv = NMT_EDITOR_GET_PRIVATE (editor);
NmtNewtWidget *vbox, *buttons, *page;
NMSettingConnection *s_con;
NmtNewtWidget *vbox, *widget, *buttons;
NmtEditorGrid *grid;
const char *deventry_label;
NmtDeviceEntry *deventry;
GType hardware_type;
const char *slave_type;
NmtEditorPage *page;
if (G_OBJECT_CLASS (nmt_editor_parent_class)->constructed)
G_OBJECT_CLASS (nmt_editor_parent_class)->constructed (object);
@ -231,8 +308,104 @@ nmt_editor_constructed (GObject *object)
vbox = nmt_newt_grid_new ();
page = nmt_page_main_new (priv->edit_connection, priv->type_data);
nmt_newt_grid_add (NMT_NEWT_GRID (vbox), page, 0, 0);
s_con = nm_connection_get_setting_connection (priv->edit_connection);
grid = NMT_EDITOR_GRID (nmt_editor_grid_new ());
nmt_newt_grid_add (NMT_NEWT_GRID (vbox), NMT_NEWT_WIDGET (grid), 0, 0);
/* Add the top widgets */
widget = nmt_newt_entry_new (40, NMT_NEWT_ENTRY_NONEMPTY);
g_object_bind_property (s_con, NM_SETTING_CONNECTION_ID,
widget, "text",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_editor_grid_append (grid, _("Profile name"), widget, NULL);
if (priv->type_data->virtual)
hardware_type = G_TYPE_NONE;
else
hardware_type = priv->type_data->device_type;
/* For connections involving multiple network devices, clarify which one
* NMSettingConnection:interface-name refers to.
*/
if (nm_connection_is_type (priv->edit_connection, NM_SETTING_PPPOE_SETTING_NAME))
deventry_label = _("Ethernet device");
else
deventry_label = _("Device");
widget = nmt_device_entry_new (deventry_label, 40, hardware_type);
nmt_editor_grid_append (grid, NULL, widget, NULL);
deventry = NMT_DEVICE_ENTRY (widget);
g_object_bind_property (s_con, NM_SETTING_CONNECTION_INTERFACE_NAME,
deventry, "interface-name",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_editor_grid_append (grid, NULL, nmt_newt_separator_new (), NULL);
/* Now add the various pages... */
if (nm_connection_is_type (priv->edit_connection, NM_SETTING_BOND_SETTING_NAME))
page = nmt_page_bond_new (priv->edit_connection, deventry);
else if (nm_connection_is_type (priv->edit_connection, NM_SETTING_BRIDGE_SETTING_NAME))
page = nmt_page_bridge_new (priv->edit_connection, deventry);
else if (nm_connection_is_type (priv->edit_connection, NM_SETTING_INFINIBAND_SETTING_NAME))
page = nmt_page_infiniband_new (priv->edit_connection, deventry);
else if (nm_connection_is_type (priv->edit_connection, NM_SETTING_PPPOE_SETTING_NAME))
page = nmt_page_dsl_new (priv->edit_connection, deventry);
else if (nm_connection_is_type (priv->edit_connection, NM_SETTING_TEAM_SETTING_NAME))
page = nmt_page_team_new (priv->edit_connection, deventry);
else if (nm_connection_is_type (priv->edit_connection, NM_SETTING_VLAN_SETTING_NAME))
page = nmt_page_vlan_new (priv->edit_connection, deventry);
else if (nm_connection_is_type (priv->edit_connection, NM_SETTING_WIRED_SETTING_NAME))
page = nmt_page_ethernet_new (priv->edit_connection, deventry);
else if (nm_connection_is_type (priv->edit_connection, NM_SETTING_WIRELESS_SETTING_NAME))
page = nmt_page_wifi_new (priv->edit_connection, deventry);
else
g_assert_not_reached ();
add_sections_for_page (editor, grid, page);
nmt_editor_grid_append (grid, NULL, nmt_newt_separator_new (), NULL);
slave_type = nm_setting_connection_get_slave_type (s_con);
if (slave_type) {
if (!strcmp (slave_type, NM_SETTING_BRIDGE_SETTING_NAME))
add_sections_for_page (editor, grid, nmt_page_bridge_port_new (priv->edit_connection));
else if (!strcmp (slave_type, NM_SETTING_TEAM_SETTING_NAME))
add_sections_for_page (editor, grid, nmt_page_team_port_new (priv->edit_connection));
} else {
NmtNewtWidget *section;
section = add_sections_for_page (editor, grid, nmt_page_ip4_new (priv->edit_connection));
/* Add a separator between ip4 and ip6 that's only visible if ip4 is open */
widget = nmt_newt_separator_new ();
g_object_bind_property (section, "open", widget, "visible", G_BINDING_SYNC_CREATE);
nmt_editor_grid_append (grid, NULL, widget, NULL);
add_sections_for_page (editor, grid, nmt_page_ip6_new (priv->edit_connection));
nmt_editor_grid_append (grid, NULL, nmt_newt_separator_new (), NULL);
}
/* And finally the bottom widgets */
widget = nmt_newt_checkbox_new (_("Automatically connect"));
g_object_bind_property (s_con, NM_SETTING_CONNECTION_AUTOCONNECT,
widget, "active",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_editor_grid_append (grid, NULL, widget, NULL);
widget = nmt_newt_checkbox_new (_("Available to all users"));
g_object_bind_property_full (s_con, NM_SETTING_CONNECTION_PERMISSIONS,
widget, "active",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE,
permissions_transform_to_allusers,
permissions_transform_from_allusers,
NULL, NULL);
nmt_editor_grid_append (grid, NULL, widget, NULL);
/* And the button box */
buttons = nmt_newt_button_box_new (NMT_NEWT_BUTTON_BOX_HORIZONTAL);
nmt_newt_grid_add (NMT_NEWT_GRID (vbox), buttons, 0, 1);
@ -243,7 +416,7 @@ nmt_editor_constructed (GObject *object)
priv->ok = nmt_newt_button_box_add_end (NMT_NEWT_BUTTON_BOX (buttons), _("OK"));
g_signal_connect (priv->ok, "clicked", G_CALLBACK (save_connection_and_exit), editor);
g_object_bind_property (page, "valid",
g_object_bind_property (NMT_NEWT_WIDGET (grid), "valid",
priv->ok, "sensitive",
G_BINDING_SYNC_CREATE);
@ -258,6 +431,8 @@ nmt_editor_finalize (GObject *object)
g_clear_object (&priv->orig_connection);
g_clear_object (&priv->edit_connection);
g_slist_free_full (priv->pages, g_object_unref);
g_clear_object (&priv->ok);
g_clear_object (&priv->cancel);

View file

@ -35,7 +35,7 @@
#include "nmt-address-list.h"
#include "nmt-slave-list.h"
G_DEFINE_TYPE (NmtPageBond, nmt_page_bond, NMT_TYPE_PAGE_DEVICE)
G_DEFINE_TYPE (NmtPageBond, nmt_page_bond, NMT_TYPE_EDITOR_PAGE_DEVICE)
#define NMT_PAGE_BOND_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_PAGE_BOND, NmtPageBondPrivate))
@ -64,13 +64,12 @@ typedef struct {
gboolean updating;
} NmtPageBondPrivate;
NmtNewtWidget *
NmtEditorPage *
nmt_page_bond_new (NMConnection *conn,
NmtDeviceEntry *deventry)
{
return g_object_new (NMT_TYPE_PAGE_BOND,
"connection", conn,
"title", _("BOND"),
"device-entry", deventry,
NULL);
}
@ -338,7 +337,8 @@ nmt_page_bond_constructed (GObject *object)
{
NmtPageBond *bond = NMT_PAGE_BOND (object);
NmtPageBondPrivate *priv = NMT_PAGE_BOND_GET_PRIVATE (bond);
NmtPageGrid *grid;
NmtEditorSection *section;
NmtEditorGrid *grid;
NMSettingBond *s_bond;
NmtNewtWidget *widget, *label;
NMConnection *conn;
@ -351,68 +351,69 @@ nmt_page_bond_constructed (GObject *object)
}
priv->s_bond = s_bond;
grid = NMT_PAGE_GRID (bond);
section = nmt_editor_section_new (_("BOND"), NULL, TRUE);
grid = nmt_editor_section_get_body (section);
widget = nmt_newt_separator_new ();
nmt_page_grid_append (grid, _("Slaves"), widget, NULL);
nmt_page_grid_set_row_flags (grid, widget, NMT_PAGE_GRID_ROW_LABEL_ALIGN_LEFT);
nmt_editor_grid_append (grid, _("Slaves"), widget, NULL);
nmt_editor_grid_set_row_flags (grid, widget, NMT_EDITOR_GRID_ROW_LABEL_ALIGN_LEFT);
widget = nmt_slave_list_new (conn, bond_connection_type_filter, bond);
g_signal_connect (widget, "notify::connections",
G_CALLBACK (slaves_changed), bond);
nmt_page_grid_append (grid, NULL, widget, NULL);
nmt_editor_grid_append (grid, NULL, widget, NULL);
priv->slaves = NMT_SLAVE_LIST (widget);
widget = nmt_newt_popup_new (bond_mode);
g_signal_connect (widget, "notify::active-id",
G_CALLBACK (mode_widget_changed), bond);
nmt_page_grid_append (grid, _("Mode"), widget, NULL);
nmt_editor_grid_append (grid, _("Mode"), widget, NULL);
priv->mode = NMT_NEWT_POPUP (widget);
widget = nmt_newt_entry_new (40, 0);
g_signal_connect (widget, "notify::text",
G_CALLBACK (primary_widget_changed), bond);
nmt_page_grid_append (grid, _("Primary"), widget, NULL);
nmt_editor_grid_append (grid, _("Primary"), widget, NULL);
priv->primary = NMT_NEWT_ENTRY (widget);
widget = nmt_newt_popup_new (bond_monitoring);
g_signal_connect (widget, "notify::active",
G_CALLBACK (monitoring_widget_changed), bond);
nmt_page_grid_append (grid, _("Link monitoring"), widget, NULL);
nmt_editor_grid_append (grid, _("Link monitoring"), widget, NULL);
priv->monitoring = NMT_NEWT_POPUP (widget);
widget = nmt_newt_entry_numeric_new (10, 0, G_MAXINT);
g_signal_connect (widget, "notify::text",
G_CALLBACK (miimon_widget_changed), bond);
label = nmt_newt_label_new (C_("milliseconds", "ms"));
nmt_page_grid_append (grid, _("Monitoring frequency"), widget, label);
nmt_editor_grid_append (grid, _("Monitoring frequency"), widget, label);
priv->miimon = NMT_NEWT_ENTRY (widget);
widget = nmt_newt_entry_numeric_new (10, 0, G_MAXINT);
g_signal_connect (widget, "notify::text",
G_CALLBACK (updelay_widget_changed), bond);
label = nmt_newt_label_new (C_("milliseconds", "ms"));
nmt_page_grid_append (grid, _("Link up delay"), widget, label);
nmt_editor_grid_append (grid, _("Link up delay"), widget, label);
priv->updelay = NMT_NEWT_ENTRY (widget);
widget = nmt_newt_entry_numeric_new (10, 0, G_MAXINT);
g_signal_connect (widget, "notify::text",
G_CALLBACK (downdelay_widget_changed), bond);
label = nmt_newt_label_new (C_("milliseconds", "ms"));
nmt_page_grid_append (grid, _("Link down delay"), widget, label);
nmt_editor_grid_append (grid, _("Link down delay"), widget, label);
priv->downdelay = NMT_NEWT_ENTRY (widget);
widget = nmt_newt_entry_numeric_new (10, 0, G_MAXINT);
g_signal_connect (widget, "notify::text",
G_CALLBACK (arp_interval_widget_changed), bond);
label = nmt_newt_label_new (C_("milliseconds", "ms"));
nmt_page_grid_append (grid, _("Monitoring frequency"), widget, label);
nmt_editor_grid_append (grid, _("Monitoring frequency"), widget, label);
priv->arp_interval = NMT_NEWT_ENTRY (widget);
widget = nmt_address_list_new (NMT_ADDRESS_LIST_IP4);
g_signal_connect (widget, "notify::strings",
G_CALLBACK (arp_ip_target_widget_changed), bond);
nmt_page_grid_append (grid, _("ARP targets"), widget, NULL);
nmt_editor_grid_append (grid, _("ARP targets"), widget, NULL);
priv->arp_ip_target = NMT_ADDRESS_LIST (widget);
g_signal_connect (s_bond, "notify::" NM_SETTING_BOND_OPTIONS,
@ -420,6 +421,8 @@ nmt_page_bond_constructed (GObject *object)
bond_options_changed (G_OBJECT (s_bond), NULL, bond);
slaves_changed (G_OBJECT (priv->slaves), NULL, bond);
nmt_editor_page_add_section (NMT_EDITOR_PAGE (bond), section);
G_OBJECT_CLASS (nmt_page_bond_parent_class)->constructed (object);
}

View file

@ -19,7 +19,7 @@
#ifndef NMT_PAGE_BOND_H
#define NMT_PAGE_BOND_H
#include "nmt-page-device.h"
#include "nmt-editor-page-device.h"
G_BEGIN_DECLS
@ -31,18 +31,18 @@ G_BEGIN_DECLS
#define NMT_PAGE_BOND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_PAGE_BOND, NmtPageBondClass))
typedef struct {
NmtPageDevice parent;
NmtEditorPageDevice parent;
} NmtPageBond;
typedef struct {
NmtPageDeviceClass parent;
NmtEditorPageDeviceClass parent;
} NmtPageBondClass;
GType nmt_page_bond_get_type (void);
NmtNewtWidget *nmt_page_bond_new (NMConnection *conn,
NmtEditorPage *nmt_page_bond_new (NMConnection *conn,
NmtDeviceEntry *deventry);
G_END_DECLS

View file

@ -30,12 +30,11 @@
G_DEFINE_TYPE (NmtPageBridgePort, nmt_page_bridge_port, NMT_TYPE_EDITOR_PAGE)
NmtNewtWidget *
NmtEditorPage *
nmt_page_bridge_port_new (NMConnection *conn)
{
return g_object_new (NMT_TYPE_PAGE_BRIDGE_PORT,
"connection", conn,
"title", _("BRIDGE PORT"),
NULL);
}
@ -48,7 +47,8 @@ static void
nmt_page_bridge_port_constructed (GObject *object)
{
NmtPageBridgePort *bridge = NMT_PAGE_BRIDGE_PORT (object);
NmtPageGrid *grid;
NmtEditorSection *section;
NmtEditorGrid *grid;
NMSettingBridgePort *s_port;
NmtNewtWidget *widget;
NMConnection *conn;
@ -60,25 +60,28 @@ nmt_page_bridge_port_constructed (GObject *object)
s_port = nm_connection_get_setting_bridge_port (conn);
}
grid = NMT_PAGE_GRID (bridge);
section = nmt_editor_section_new (_("BRIDGE PORT"), NULL, TRUE);
grid = nmt_editor_section_get_body (section);
widget = nmt_newt_entry_numeric_new (10, 0, 63);
g_object_bind_property (s_port, NM_SETTING_BRIDGE_PORT_PRIORITY,
widget, "text",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_page_grid_append (grid, _("Priority"), widget, NULL);
nmt_editor_grid_append (grid, _("Priority"), widget, NULL);
widget = nmt_newt_entry_numeric_new (10, 1, 65535);
g_object_bind_property (s_port, NM_SETTING_BRIDGE_PORT_PATH_COST,
widget, "text",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_page_grid_append (grid, _("Path cost"), widget, NULL);
nmt_editor_grid_append (grid, _("Path cost"), widget, NULL);
widget = nmt_newt_checkbox_new (_("Hairpin mode"));
g_object_bind_property (s_port, NM_SETTING_BRIDGE_PORT_HAIRPIN_MODE,
widget, "active",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_page_grid_append (grid, NULL, widget, NULL);
nmt_editor_grid_append (grid, NULL, widget, NULL);
nmt_editor_page_add_section (NMT_EDITOR_PAGE (bridge), section);
G_OBJECT_CLASS (nmt_page_bridge_port_parent_class)->constructed (object);
}

View file

@ -42,7 +42,7 @@ typedef struct {
GType nmt_page_bridge_port_get_type (void);
NmtNewtWidget *nmt_page_bridge_port_new (NMConnection *conn);
NmtEditorPage *nmt_page_bridge_port_new (NMConnection *conn);
G_END_DECLS

View file

@ -31,15 +31,14 @@
#include "nmt-address-list.h"
#include "nmt-slave-list.h"
G_DEFINE_TYPE (NmtPageBridge, nmt_page_bridge, NMT_TYPE_PAGE_DEVICE)
G_DEFINE_TYPE (NmtPageBridge, nmt_page_bridge, NMT_TYPE_EDITOR_PAGE_DEVICE)
NmtNewtWidget *
NmtEditorPage *
nmt_page_bridge_new (NMConnection *conn,
NmtDeviceEntry *deventry)
{
return g_object_new (NMT_TYPE_PAGE_BRIDGE,
"connection", conn,
"title", _("BRIDGE"),
"device-entry", deventry,
NULL);
}
@ -62,7 +61,8 @@ static void
nmt_page_bridge_constructed (GObject *object)
{
NmtPageBridge *bridge = NMT_PAGE_BRIDGE (object);
NmtPageGrid *grid;
NmtEditorSection *section;
NmtEditorGrid *grid;
NMSettingBridge *s_bridge;
NmtNewtWidget *widget, *label, *stp;
NMConnection *conn;
@ -74,27 +74,34 @@ nmt_page_bridge_constructed (GObject *object)
s_bridge = nm_connection_get_setting_bridge (conn);
}
grid = NMT_PAGE_GRID (bridge);
section = nmt_editor_section_new (_("BRIDGE"), NULL, TRUE);
grid = nmt_editor_section_get_body (section);
widget = nmt_newt_separator_new ();
nmt_page_grid_append (grid, _("Slaves"), widget, NULL);
nmt_page_grid_set_row_flags (grid, widget, NMT_PAGE_GRID_ROW_LABEL_ALIGN_LEFT);
nmt_editor_grid_append (grid, _("Slaves"), widget, NULL);
nmt_editor_grid_set_row_flags (grid, widget, NMT_EDITOR_GRID_ROW_LABEL_ALIGN_LEFT);
widget = nmt_slave_list_new (conn, bridge_connection_type_filter, bridge);
nmt_page_grid_append (grid, NULL, widget, NULL);
nmt_editor_grid_append (grid, NULL, widget, NULL);
widget = nmt_newt_entry_numeric_new (10, 0, 1000000);
g_object_bind_property (s_bridge, NM_SETTING_BRIDGE_AGEING_TIME,
widget, "text",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
label = nmt_newt_label_new (_("seconds"));
nmt_page_grid_append (grid, _("Aging time"), widget, label);
nmt_editor_grid_append (grid, _("Aging time"), widget, label);
widget = nmt_newt_checkbox_new (_("Enable IGMP snooping"));
g_object_bind_property (s_bridge, NM_SETTING_BRIDGE_MULTICAST_SNOOPING,
widget, "active",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_editor_grid_append (grid, NULL, widget, NULL);
widget = stp = nmt_newt_checkbox_new (_("Enable STP (Spanning Tree Protocol)"));
g_object_bind_property (s_bridge, NM_SETTING_BRIDGE_STP,
widget, "active",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_page_grid_append (grid, NULL, widget, NULL);
nmt_editor_grid_append (grid, NULL, widget, NULL);
widget = nmt_newt_entry_numeric_new (10, 0, G_MAXINT);
g_object_bind_property (s_bridge, NM_SETTING_BRIDGE_PRIORITY,
@ -103,7 +110,7 @@ nmt_page_bridge_constructed (GObject *object)
g_object_bind_property (s_bridge, NM_SETTING_BRIDGE_STP,
widget, "sensitive",
G_BINDING_SYNC_CREATE);
nmt_page_grid_append (grid, _("Priority"), widget, NULL);
nmt_editor_grid_append (grid, _("Priority"), widget, NULL);
widget = nmt_newt_entry_numeric_new (10, 2, 30);
g_object_bind_property (s_bridge, NM_SETTING_BRIDGE_FORWARD_DELAY,
@ -113,7 +120,7 @@ nmt_page_bridge_constructed (GObject *object)
widget, "sensitive",
G_BINDING_SYNC_CREATE);
label = nmt_newt_label_new (_("seconds"));
nmt_page_grid_append (grid, _("Forward delay"), widget, label);
nmt_editor_grid_append (grid, _("Forward delay"), widget, label);
widget = nmt_newt_entry_numeric_new (10, 1, 10);
g_object_bind_property (s_bridge, NM_SETTING_BRIDGE_HELLO_TIME,
@ -123,7 +130,7 @@ nmt_page_bridge_constructed (GObject *object)
widget, "sensitive",
G_BINDING_SYNC_CREATE);
label = nmt_newt_label_new (_("seconds"));
nmt_page_grid_append (grid, _("Hello time"), widget, label);
nmt_editor_grid_append (grid, _("Hello time"), widget, label);
widget = nmt_newt_entry_numeric_new (10, 6, 40);
g_object_bind_property (s_bridge, NM_SETTING_BRIDGE_MAX_AGE,
@ -133,7 +140,9 @@ nmt_page_bridge_constructed (GObject *object)
widget, "sensitive",
G_BINDING_SYNC_CREATE);
label = nmt_newt_label_new (_("seconds"));
nmt_page_grid_append (grid, _("Max age"), widget, label);
nmt_editor_grid_append (grid, _("Max age"), widget, label);
nmt_editor_page_add_section (NMT_EDITOR_PAGE (bridge), section);
G_OBJECT_CLASS (nmt_page_bridge_parent_class)->constructed (object);
}

View file

@ -19,7 +19,7 @@
#ifndef NMT_PAGE_BRIDGE_H
#define NMT_PAGE_BRIDGE_H
#include "nmt-page-device.h"
#include "nmt-editor-page-device.h"
G_BEGIN_DECLS
@ -31,18 +31,18 @@ G_BEGIN_DECLS
#define NMT_PAGE_BRIDGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_PAGE_BRIDGE, NmtPageBridgeClass))
typedef struct {
NmtPageDevice parent;
NmtEditorPageDevice parent;
} NmtPageBridge;
typedef struct {
NmtPageDeviceClass parent;
NmtEditorPageDeviceClass parent;
} NmtPageBridgeClass;
GType nmt_page_bridge_get_type (void);
NmtNewtWidget *nmt_page_bridge_new (NMConnection *conn,
NmtEditorPage *nmt_page_bridge_new (NMConnection *conn,
NmtDeviceEntry *deventry);
G_END_DECLS

View file

@ -1,50 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* 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, see <http://www.gnu.org/licenses/>.
*
* Copyright 2013 Red Hat, Inc.
*/
#ifndef NMT_PAGE_DEVICE_H
#define NMT_PAGE_DEVICE_H
#include "nmt-editor-page.h"
#include "nmt-device-entry.h"
G_BEGIN_DECLS
#define NMT_TYPE_PAGE_DEVICE (nmt_page_device_get_type ())
#define NMT_PAGE_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMT_TYPE_PAGE_DEVICE, NmtPageDevice))
#define NMT_PAGE_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMT_TYPE_PAGE_DEVICE, NmtPageDeviceClass))
#define NMT_IS_PAGE_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMT_TYPE_PAGE_DEVICE))
#define NMT_IS_PAGE_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMT_TYPE_PAGE_DEVICE))
#define NMT_PAGE_DEVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_PAGE_DEVICE, NmtPageDeviceClass))
typedef struct {
NmtEditorPage parent;
} NmtPageDevice;
typedef struct {
NmtEditorPageClass parent;
} NmtPageDeviceClass;
GType nmt_page_device_get_type (void);
NmtDeviceEntry *nmt_page_device_get_device_entry (NmtPageDevice *page);
G_END_DECLS
#endif /* NMT_PAGE_DEVICE_H */

View file

@ -27,16 +27,26 @@
#include <glib/gi18n-lib.h>
#include "nmt-page-dsl.h"
#include "nmt-page-ethernet.h"
#include "nmt-page-ppp.h"
#include "nmt-password-fields.h"
G_DEFINE_TYPE (NmtPageDsl, nmt_page_dsl, NMT_TYPE_EDITOR_PAGE)
G_DEFINE_TYPE (NmtPageDsl, nmt_page_dsl, NMT_TYPE_EDITOR_PAGE_DEVICE)
NmtNewtWidget *
nmt_page_dsl_new (NMConnection *conn)
#define NMT_PAGE_DSL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_PAGE_DSL, NmtPageDslPrivate))
typedef struct {
NmtEditorPage *ethernet_page, *ppp_page;
} NmtPageDslPrivate;
NmtEditorPage *
nmt_page_dsl_new (NMConnection *conn,
NmtDeviceEntry *deventry)
{
return g_object_new (NMT_TYPE_PAGE_DSL,
"connection", conn,
"title", _("DSL"),
"device-entry", deventry,
NULL);
}
@ -45,26 +55,18 @@ nmt_page_dsl_init (NmtPageDsl *dsl)
{
}
static void
nmt_page_dsl_constructed (GObject *object)
static NmtEditorSection *
build_dsl_section (NmtPageDsl *dsl, NMSettingPppoe *s_pppoe)
{
NmtPageDsl *dsl = NMT_PAGE_DSL (object);
NmtPageGrid *grid;
NMSettingPppoe *s_pppoe;
NmtEditorSection *section;
NmtEditorGrid *grid;
NmtNewtWidget *widget;
NMConnection *conn;
conn = nmt_editor_page_get_connection (NMT_EDITOR_PAGE (dsl));
s_pppoe = nm_connection_get_setting_pppoe (conn);
if (!s_pppoe) {
nm_connection_add_setting (conn, nm_setting_pppoe_new ());
s_pppoe = nm_connection_get_setting_pppoe (conn);
}
grid = NMT_PAGE_GRID (dsl);
section = nmt_editor_section_new (_("DSL"), NULL, TRUE);
grid = nmt_editor_section_get_body (section);
widget = nmt_newt_entry_new (40, 0);
nmt_page_grid_append (grid, _("Username"), widget, NULL);
nmt_editor_grid_append (grid, _("Username"), widget, NULL);
g_object_bind_property (s_pppoe, NM_SETTING_PPPOE_USERNAME,
widget, "text",
G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
@ -73,21 +75,69 @@ nmt_page_dsl_constructed (GObject *object)
g_object_bind_property (s_pppoe, NM_SETTING_PPPOE_PASSWORD,
widget, "password",
G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
nmt_page_grid_append (grid, _("Password"), widget, NULL);
nmt_editor_grid_append (grid, _("Password"), widget, NULL);
widget = nmt_newt_entry_new (40, 0);
nmt_page_grid_append (grid, _("Service"), widget, NULL);
nmt_editor_grid_append (grid, _("Service"), widget, NULL);
g_object_bind_property (s_pppoe, NM_SETTING_PPPOE_SERVICE,
widget, "text",
G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
return section;
}
static void
nmt_page_dsl_constructed (GObject *object)
{
NmtPageDsl *dsl = NMT_PAGE_DSL (object);
NmtPageDslPrivate *priv = NMT_PAGE_DSL_GET_PRIVATE (dsl);
NMConnection *conn;
NMSettingPppoe *s_pppoe;
NmtEditorSection *section;
const GSList *sections, *iter;
conn = nmt_editor_page_get_connection (NMT_EDITOR_PAGE (dsl));
s_pppoe = nm_connection_get_setting_pppoe (conn);
if (!s_pppoe) {
nm_connection_add_setting (conn, nm_setting_pppoe_new ());
s_pppoe = nm_connection_get_setting_pppoe (conn);
}
section = build_dsl_section (dsl, s_pppoe);
nmt_editor_page_add_section (NMT_EDITOR_PAGE (dsl), section);
priv->ethernet_page = nmt_page_ethernet_new (conn, nmt_editor_page_device_get_device_entry (NMT_EDITOR_PAGE_DEVICE (dsl)));
sections = nmt_editor_page_get_sections (priv->ethernet_page);
for (iter = sections; iter; iter = iter->next)
nmt_editor_page_add_section (NMT_EDITOR_PAGE (dsl), iter->data);
priv->ppp_page = nmt_page_ppp_new (conn);
sections = nmt_editor_page_get_sections (priv->ppp_page);
for (iter = sections; iter; iter = iter->next)
nmt_editor_page_add_section (NMT_EDITOR_PAGE (dsl), iter->data);
G_OBJECT_CLASS (nmt_page_dsl_parent_class)->constructed (object);
}
static void
nmt_page_dsl_finalize (GObject *object)
{
NmtPageDsl *dsl = NMT_PAGE_DSL (object);
NmtPageDslPrivate *priv = NMT_PAGE_DSL_GET_PRIVATE (dsl);
g_clear_object (&priv->ethernet_page);
g_clear_object (&priv->ppp_page);
G_OBJECT_CLASS (nmt_page_dsl_parent_class)->finalize (object);
}
static void
nmt_page_dsl_class_init (NmtPageDslClass *dsl_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (dsl_class);
g_type_class_add_private (object_class, sizeof (NmtPageDslPrivate));
object_class->constructed = nmt_page_dsl_constructed;
object_class->finalize = nmt_page_dsl_finalize;
}

View file

@ -19,7 +19,7 @@
#ifndef NMT_PAGE_DSL_H
#define NMT_PAGE_DSL_H
#include "nmt-editor-page.h"
#include "nmt-editor-page-device.h"
G_BEGIN_DECLS
@ -31,18 +31,19 @@ G_BEGIN_DECLS
#define NMT_PAGE_DSL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_PAGE_DSL, NmtPageDslClass))
typedef struct {
NmtEditorPage parent;
NmtEditorPageDevice parent;
} NmtPageDsl;
typedef struct {
NmtEditorPageClass parent;
NmtEditorPageDeviceClass parent;
} NmtPageDslClass;
GType nmt_page_dsl_get_type (void);
NmtNewtWidget *nmt_page_dsl_new (NMConnection *conn);
NmtEditorPage *nmt_page_dsl_new (NMConnection *conn,
NmtDeviceEntry *deventry);
G_END_DECLS

View file

@ -30,17 +30,15 @@
#include "nmt-mac-entry.h"
#include "nmt-mtu-entry.h"
G_DEFINE_TYPE (NmtPageEthernet, nmt_page_ethernet, NMT_TYPE_PAGE_DEVICE)
G_DEFINE_TYPE (NmtPageEthernet, nmt_page_ethernet, NMT_TYPE_EDITOR_PAGE_DEVICE)
NmtNewtWidget *
NmtEditorPage *
nmt_page_ethernet_new (NMConnection *conn,
NmtDeviceEntry *deventry)
{
return g_object_new (NMT_TYPE_PAGE_ETHERNET,
"connection", conn,
"title", _("ETHERNET"),
"device-entry", deventry,
"show-by-default", FALSE,
NULL);
}
@ -54,7 +52,8 @@ nmt_page_ethernet_constructed (GObject *object)
{
NmtPageEthernet *ethernet = NMT_PAGE_ETHERNET (object);
NmtDeviceEntry *deventry;
NmtPageGrid *grid;
NmtEditorSection *section;
NmtEditorGrid *grid;
NMSettingWired *s_wired;
NmtNewtWidget *widget;
NMConnection *conn;
@ -66,24 +65,27 @@ nmt_page_ethernet_constructed (GObject *object)
s_wired = nm_connection_get_setting_wired (conn);
}
deventry = nmt_page_device_get_device_entry (NMT_PAGE_DEVICE (object));
deventry = nmt_editor_page_device_get_device_entry (NMT_EDITOR_PAGE_DEVICE (object));
g_object_bind_property (s_wired, NM_SETTING_WIRED_MAC_ADDRESS,
deventry, "mac-address",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
grid = NMT_PAGE_GRID (ethernet);
section = nmt_editor_section_new (_("ETHERNET"), NULL, FALSE);
grid = nmt_editor_section_get_body (section);
widget = nmt_mac_entry_new (40, ETH_ALEN);
g_object_bind_property (s_wired, NM_SETTING_WIRED_CLONED_MAC_ADDRESS,
widget, "mac-address",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_page_grid_append (grid, _("Cloned MAC address"), widget, NULL);
nmt_editor_grid_append (grid, _("Cloned MAC address"), widget, NULL);
widget = nmt_mtu_entry_new ();
g_object_bind_property (s_wired, NM_SETTING_WIRED_MTU,
widget, "mtu",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_page_grid_append (grid, _("MTU"), widget, NULL);
nmt_editor_grid_append (grid, _("MTU"), widget, NULL);
nmt_editor_page_add_section (NMT_EDITOR_PAGE (ethernet), section);
G_OBJECT_CLASS (nmt_page_ethernet_parent_class)->constructed (object);
}

View file

@ -19,7 +19,7 @@
#ifndef NMT_PAGE_ETHERNET_H
#define NMT_PAGE_ETHERNET_H
#include "nmt-page-device.h"
#include "nmt-editor-page-device.h"
G_BEGIN_DECLS
@ -31,18 +31,18 @@ G_BEGIN_DECLS
#define NMT_PAGE_ETHERNET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_PAGE_ETHERNET, NmtPageEthernetClass))
typedef struct {
NmtPageDevice parent;
NmtEditorPageDevice parent;
} NmtPageEthernet;
typedef struct {
NmtPageDeviceClass parent;
NmtEditorPageDeviceClass parent;
} NmtPageEthernetClass;
GType nmt_page_ethernet_get_type (void);
NmtNewtWidget *nmt_page_ethernet_new (NMConnection *conn,
NmtEditorPage *nmt_page_ethernet_new (NMConnection *conn,
NmtDeviceEntry *deventry);
G_END_DECLS

View file

@ -29,15 +29,14 @@
#include "nmt-page-infiniband.h"
#include "nmt-mtu-entry.h"
G_DEFINE_TYPE (NmtPageInfiniband, nmt_page_infiniband, NMT_TYPE_PAGE_DEVICE)
G_DEFINE_TYPE (NmtPageInfiniband, nmt_page_infiniband, NMT_TYPE_EDITOR_PAGE_DEVICE)
NmtNewtWidget *
NmtEditorPage *
nmt_page_infiniband_new (NMConnection *conn,
NmtDeviceEntry *deventry)
{
return g_object_new (NMT_TYPE_PAGE_INFINIBAND,
"connection", conn,
"title", _("INFINIBAND"),
"device-entry", deventry,
NULL);
}
@ -58,7 +57,8 @@ nmt_page_infiniband_constructed (GObject *object)
{
NmtPageInfiniband *infiniband = NMT_PAGE_INFINIBAND (object);
NmtDeviceEntry *deventry;
NmtPageGrid *grid;
NmtEditorSection *section;
NmtEditorGrid *grid;
NMSettingInfiniband *s_ib;
NmtNewtWidget *widget;
NMConnection *conn;
@ -76,24 +76,27 @@ nmt_page_infiniband_constructed (GObject *object)
NULL);
}
deventry = nmt_page_device_get_device_entry (NMT_PAGE_DEVICE (object));
deventry = nmt_editor_page_device_get_device_entry (NMT_EDITOR_PAGE_DEVICE (object));
g_object_bind_property (s_ib, NM_SETTING_INFINIBAND_MAC_ADDRESS,
deventry, "mac-address",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
grid = NMT_PAGE_GRID (infiniband);
section = nmt_editor_section_new (_("INFINIBAND"), NULL, TRUE);
grid = nmt_editor_section_get_body (section);
widget = nmt_newt_popup_new (transport_mode);
g_object_bind_property (s_ib, NM_SETTING_INFINIBAND_TRANSPORT_MODE,
widget, "active-id",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_page_grid_append (grid, _("Transport mode"), widget, NULL);
nmt_editor_grid_append (grid, _("Transport mode"), widget, NULL);
widget = nmt_mtu_entry_new ();
g_object_bind_property (s_ib, NM_SETTING_INFINIBAND_MTU,
widget, "mtu",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_page_grid_append (grid, _("MTU"), widget, NULL);
nmt_editor_grid_append (grid, _("MTU"), widget, NULL);
nmt_editor_page_add_section (NMT_EDITOR_PAGE (infiniband), section);
G_OBJECT_CLASS (nmt_page_infiniband_parent_class)->constructed (object);
}

View file

@ -19,7 +19,7 @@
#ifndef NMT_PAGE_INFINIBAND_H
#define NMT_PAGE_INFINIBAND_H
#include "nmt-page-device.h"
#include "nmt-editor-page-device.h"
G_BEGIN_DECLS
@ -31,18 +31,18 @@ G_BEGIN_DECLS
#define NMT_PAGE_INFINIBAND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_PAGE_INFINIBAND, NmtPageInfinibandClass))
typedef struct {
NmtPageDevice parent;
NmtEditorPageDevice parent;
} NmtPageInfiniband;
typedef struct {
NmtPageDeviceClass parent;
NmtEditorPageDeviceClass parent;
} NmtPageInfinibandClass;
GType nmt_page_infiniband_get_type (void);
NmtNewtWidget *nmt_page_infiniband_new (NMConnection *conn,
NmtEditorPage *nmt_page_infiniband_new (NMConnection *conn,
NmtDeviceEntry *deventry);
G_END_DECLS

View file

@ -46,29 +46,14 @@ static NmtNewtPopupEntry ip4methods[] = {
{ NULL, NULL }
};
NmtNewtWidget *
NmtEditorPage *
nmt_page_ip4_new (NMConnection *conn)
{
return g_object_new (NMT_TYPE_PAGE_IP4,
"connection", conn,
"title", _("IPv4 CONFIGURATION"),
NULL);
}
static gboolean
nmt_page_ip4_show_by_default (NmtEditorPage *page)
{
NMConnection *conn;
NMSettingIP4Config *s_ip4;
conn = nmt_editor_page_get_connection (page);
s_ip4 = nm_connection_get_setting_ip4_config (conn);
if ( !g_strcmp0 (nm_setting_ip4_config_get_method (s_ip4), NM_SETTING_IP4_CONFIG_METHOD_MANUAL)
|| nm_setting_ip4_config_get_num_addresses (s_ip4))
return TRUE;
return FALSE;
}
static void
nmt_page_ip4_init (NmtPageIP4 *ip4)
{
@ -114,82 +99,96 @@ static void
nmt_page_ip4_constructed (GObject *object)
{
NmtPageIP4 *ip4 = NMT_PAGE_IP4 (object);
NmtPageGrid *grid;
NMSettingIP4Config *s_ip4;
gboolean show_by_default;
NmtEditorSection *section;
NmtEditorGrid *grid;
NMSettingIPConfig *s_ip4;
NmtNewtWidget *widget, *button;
NMConnection *conn;
conn = nmt_editor_page_get_connection (NMT_EDITOR_PAGE (ip4));
s_ip4 = nm_connection_get_setting_ip4_config (conn);
if (!s_ip4) {
s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
g_object_set (G_OBJECT (s_ip4),
NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
NULL);
nm_connection_add_setting (conn, (NMSetting *) s_ip4);
}
widget = nmt_newt_popup_new (ip4methods);
g_object_bind_property (s_ip4, NM_SETTING_IP4_CONFIG_METHOD,
g_object_bind_property (s_ip4, NM_SETTING_IP_CONFIG_METHOD,
widget, "active-id",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_editor_page_set_header_widget (NMT_EDITOR_PAGE (ip4), widget);
grid = NMT_PAGE_GRID (ip4);
if (!g_strcmp0 (nm_setting_ip_config_get_method (s_ip4), NM_SETTING_IP4_CONFIG_METHOD_MANUAL))
show_by_default = TRUE;
else if (nm_setting_ip_config_get_num_addresses (s_ip4))
show_by_default = TRUE;
else
show_by_default = FALSE;
section = nmt_editor_section_new (_("IPv4 CONFIGURATION"), widget, show_by_default);
grid = nmt_editor_section_get_body (section);
widget = nmt_address_list_new (NMT_ADDRESS_LIST_IP4_WITH_PREFIX);
nm_editor_bind_ip4_addresses_with_prefix_to_strv (s_ip4, NM_SETTING_IP4_CONFIG_ADDRESSES,
widget, "strings",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_page_grid_append (grid, _("Addresses"), widget, NULL);
nm_editor_bind_ip_addresses_with_prefix_to_strv (AF_INET,
s_ip4, NM_SETTING_IP_CONFIG_ADDRESSES,
widget, "strings",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_editor_grid_append (grid, _("Addresses"), widget, NULL);
widget = nmt_ip_entry_new (25, AF_INET, FALSE, TRUE);
nm_editor_bind_ip4_gateway_to_string (s_ip4, NM_SETTING_IP4_CONFIG_ADDRESSES,
widget, "text",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_page_grid_append (grid, _("Gateway"), widget, NULL);
nm_editor_bind_ip_gateway_to_string (AF_INET,
s_ip4,
widget, "text", "sensitive",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_editor_grid_append (grid, _("Gateway"), widget, NULL);
widget = nmt_address_list_new (NMT_ADDRESS_LIST_IP4);
nm_editor_bind_ip4_addresses_to_strv (s_ip4, NM_SETTING_IP4_CONFIG_DNS,
widget, "strings",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_page_grid_append (grid, _("DNS servers"), widget, NULL);
nm_editor_bind_ip_addresses_to_strv (AF_INET,
s_ip4, NM_SETTING_IP_CONFIG_DNS,
widget, "strings",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_editor_grid_append (grid, _("DNS servers"), widget, NULL);
widget = nmt_address_list_new (NMT_ADDRESS_LIST_HOSTNAME);
g_object_bind_property (s_ip4, NM_SETTING_IP4_CONFIG_DNS_SEARCH,
g_object_bind_property (s_ip4, NM_SETTING_IP_CONFIG_DNS_SEARCH,
widget, "strings",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_page_grid_append (grid, _("Search domains"), widget, NULL);
nmt_editor_grid_append (grid, _("Search domains"), widget, NULL);
nmt_page_grid_append (grid, NULL, nmt_newt_separator_new (), NULL);
nmt_editor_grid_append (grid, NULL, nmt_newt_separator_new (), NULL);
widget = g_object_new (NMT_TYPE_NEWT_LABEL,
"text", "",
"style", NMT_NEWT_LABEL_PLAIN,
NULL);
g_object_bind_property_full (s_ip4, NM_SETTING_IP4_CONFIG_ROUTES,
g_object_bind_property_full (s_ip4, NM_SETTING_IP_CONFIG_ROUTES,
widget, "text",
G_BINDING_SYNC_CREATE,
ip4_routes_transform_to_description,
NULL, NULL, NULL);
button = nmt_newt_button_new (_("Edit..."));
g_signal_connect (button, "clicked", G_CALLBACK (edit_routes), s_ip4);
nmt_page_grid_append (grid, _("Routing"), widget, button);
nmt_editor_grid_append (grid, _("Routing"), widget, button);
widget = nmt_newt_checkbox_new (_("Never use this network for default route"));
g_object_bind_property (s_ip4, NM_SETTING_IP4_CONFIG_NEVER_DEFAULT,
g_object_bind_property (s_ip4, NM_SETTING_IP_CONFIG_NEVER_DEFAULT,
widget, "active",
G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
nmt_page_grid_append (grid, NULL, widget, NULL);
nmt_editor_grid_append (grid, NULL, widget, NULL);
nmt_page_grid_append (grid, NULL, nmt_newt_separator_new (), NULL);
nmt_editor_grid_append (grid, NULL, nmt_newt_separator_new (), NULL);
widget = nmt_newt_checkbox_new (_("Require IPv4 addressing for this connection"));
g_object_bind_property (s_ip4, NM_SETTING_IP4_CONFIG_MAY_FAIL,
g_object_bind_property (s_ip4, NM_SETTING_IP_CONFIG_MAY_FAIL,
widget, "active",
G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL |
G_BINDING_INVERT_BOOLEAN);
nmt_page_grid_append (grid, NULL, widget, NULL);
nmt_editor_grid_append (grid, NULL, widget, NULL);
nmt_editor_page_add_section (NMT_EDITOR_PAGE (ip4), section);
G_OBJECT_CLASS (nmt_page_ip4_parent_class)->constructed (object);
}
@ -198,9 +197,6 @@ static void
nmt_page_ip4_class_init (NmtPageIP4Class *ip4_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (ip4_class);
NmtEditorPageClass *page_class = NMT_EDITOR_PAGE_CLASS (ip4_class);
object_class->constructed = nmt_page_ip4_constructed;
page_class->show_by_default = nmt_page_ip4_show_by_default;
}

View file

@ -42,7 +42,7 @@ typedef struct {
GType nmt_page_ip4_get_type (void);
NmtNewtWidget *nmt_page_ip4_new (NMConnection *conn);
NmtEditorPage *nmt_page_ip4_new (NMConnection *conn);
G_END_DECLS

View file

@ -46,29 +46,14 @@ static NmtNewtPopupEntry ip6methods[] = {
{ NULL, NULL }
};
NmtNewtWidget *
NmtEditorPage *
nmt_page_ip6_new (NMConnection *conn)
{
return g_object_new (NMT_TYPE_PAGE_IP6,
"connection", conn,
"title", _("IPv6 CONFIGURATION"),
NULL);
}
static gboolean
nmt_page_ip6_show_by_default (NmtEditorPage *page)
{
NMConnection *conn;
NMSettingIP6Config *s_ip6;
conn = nmt_editor_page_get_connection (page);
s_ip6 = nm_connection_get_setting_ip6_config (conn);
if ( !g_strcmp0 (nm_setting_ip6_config_get_method (s_ip6), NM_SETTING_IP6_CONFIG_METHOD_MANUAL)
|| nm_setting_ip6_config_get_num_addresses (s_ip6))
return TRUE;
return FALSE;
}
static void
nmt_page_ip6_init (NmtPageIP6 *ip6)
{
@ -114,80 +99,94 @@ static void
nmt_page_ip6_constructed (GObject *object)
{
NmtPageIP6 *ip6 = NMT_PAGE_IP6 (object);
NmtPageGrid *grid;
NMSettingIP6Config *s_ip6;
gboolean show_by_default;
NmtEditorSection *section;
NmtEditorGrid *grid;
NMSettingIPConfig *s_ip6;
NmtNewtWidget *widget, *button;
NMConnection *conn;
conn = nmt_editor_page_get_connection (NMT_EDITOR_PAGE (ip6));
s_ip6 = nm_connection_get_setting_ip6_config (conn);
if (!s_ip6) {
s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
g_object_set (G_OBJECT (s_ip6),
NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO,
NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO,
NULL);
nm_connection_add_setting (conn, (NMSetting *) s_ip6);
}
widget = nmt_newt_popup_new (ip6methods);
g_object_bind_property (s_ip6, NM_SETTING_IP6_CONFIG_METHOD,
g_object_bind_property (s_ip6, NM_SETTING_IP_CONFIG_METHOD,
widget, "active-id",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_editor_page_set_header_widget (NMT_EDITOR_PAGE (ip6), widget);
grid = NMT_PAGE_GRID (ip6);
if (!g_strcmp0 (nm_setting_ip_config_get_method (s_ip6), NM_SETTING_IP6_CONFIG_METHOD_MANUAL))
show_by_default = TRUE;
else if (nm_setting_ip_config_get_num_addresses (s_ip6))
show_by_default = TRUE;
else
show_by_default = FALSE;
section = nmt_editor_section_new (_("IPv6 CONFIGURATION"), widget, show_by_default);
grid = nmt_editor_section_get_body (section);
widget = nmt_address_list_new (NMT_ADDRESS_LIST_IP6_WITH_PREFIX);
nm_editor_bind_ip6_addresses_with_prefix_to_strv (s_ip6, NM_SETTING_IP6_CONFIG_ADDRESSES,
widget, "strings",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_page_grid_append (grid, _("Addresses"), widget, NULL);
nm_editor_bind_ip_addresses_with_prefix_to_strv (AF_INET6,
s_ip6, NM_SETTING_IP_CONFIG_ADDRESSES,
widget, "strings",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_editor_grid_append (grid, _("Addresses"), widget, NULL);
widget = nmt_ip_entry_new (25, AF_INET6, FALSE, TRUE);
nm_editor_bind_ip6_gateway_to_string (s_ip6, NM_SETTING_IP6_CONFIG_ADDRESSES,
widget, "text",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_page_grid_append (grid, _("Gateway"), widget, NULL);
nm_editor_bind_ip_gateway_to_string (AF_INET6,
s_ip6,
widget, "text", "sensitive",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_editor_grid_append (grid, _("Gateway"), widget, NULL);
widget = nmt_address_list_new (NMT_ADDRESS_LIST_IP6);
nm_editor_bind_ip6_addresses_to_strv (s_ip6, NM_SETTING_IP6_CONFIG_DNS,
widget, "strings",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_page_grid_append (grid, _("DNS servers"), widget, NULL);
nm_editor_bind_ip_addresses_to_strv (AF_INET6,
s_ip6, NM_SETTING_IP_CONFIG_DNS,
widget, "strings",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_editor_grid_append (grid, _("DNS servers"), widget, NULL);
widget = nmt_address_list_new (NMT_ADDRESS_LIST_HOSTNAME);
g_object_bind_property (s_ip6, NM_SETTING_IP6_CONFIG_DNS_SEARCH,
g_object_bind_property (s_ip6, NM_SETTING_IP_CONFIG_DNS_SEARCH,
widget, "strings",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_page_grid_append (grid, _("Search domains"), widget, NULL);
nmt_editor_grid_append (grid, _("Search domains"), widget, NULL);
widget = g_object_new (NMT_TYPE_NEWT_LABEL,
"text", "",
"style", NMT_NEWT_LABEL_PLAIN,
NULL);
g_object_bind_property_full (s_ip6, NM_SETTING_IP6_CONFIG_ROUTES,
g_object_bind_property_full (s_ip6, NM_SETTING_IP_CONFIG_ROUTES,
widget, "text",
G_BINDING_SYNC_CREATE,
ip6_routes_transform_to_description,
NULL, NULL, NULL);
button = nmt_newt_button_new (_("Edit..."));
g_signal_connect (button, "clicked", G_CALLBACK (edit_routes), s_ip6);
nmt_page_grid_append (grid, _("Routing"), widget, button);
nmt_editor_grid_append (grid, _("Routing"), widget, button);
widget = nmt_newt_checkbox_new (_("Never use this network for default route"));
g_object_bind_property (s_ip6, NM_SETTING_IP6_CONFIG_NEVER_DEFAULT,
g_object_bind_property (s_ip6, NM_SETTING_IP_CONFIG_NEVER_DEFAULT,
widget, "active",
G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
nmt_page_grid_append (grid, NULL, widget, NULL);
nmt_editor_grid_append (grid, NULL, widget, NULL);
nmt_page_grid_append (grid, NULL, nmt_newt_separator_new (), NULL);
nmt_editor_grid_append (grid, NULL, nmt_newt_separator_new (), NULL);
widget = nmt_newt_checkbox_new (_("Require IPv6 addressing for this connection"));
g_object_bind_property (s_ip6, NM_SETTING_IP6_CONFIG_MAY_FAIL,
g_object_bind_property (s_ip6, NM_SETTING_IP_CONFIG_MAY_FAIL,
widget, "active",
G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL |
G_BINDING_INVERT_BOOLEAN);
nmt_page_grid_append (grid, NULL, widget, NULL);
nmt_editor_grid_append (grid, NULL, widget, NULL);
nmt_editor_page_add_section (NMT_EDITOR_PAGE (ip6), section);
G_OBJECT_CLASS (nmt_page_ip6_parent_class)->constructed (object);
}
@ -196,9 +195,6 @@ static void
nmt_page_ip6_class_init (NmtPageIP6Class *ip6_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (ip6_class);
NmtEditorPageClass *page_class = NMT_EDITOR_PAGE_CLASS (ip6_class);
object_class->constructed = nmt_page_ip6_constructed;
page_class->show_by_default = nmt_page_ip6_show_by_default;
}

View file

@ -42,7 +42,7 @@ typedef struct {
GType nmt_page_ip6_get_type (void);
NmtNewtWidget *nmt_page_ip6_new (NMConnection *conn);
NmtEditorPage *nmt_page_ip6_new (NMConnection *conn);
G_END_DECLS

View file

@ -1,328 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* 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, see <http://www.gnu.org/licenses/>.
*
* Copyright 2013 Red Hat, Inc.
*/
/**
* SECTION:nmt-page-main
* @short_description: The top-level #NmtEditorPage for a connection
*
* #NmtPageMain is the top-level #NmtEditorPage for a connection. It
* handles #NMSettingConnection properties, and embeds the other pages
* within itself.
*/
#include "config.h"
#include <glib.h>
#include <glib/gi18n-lib.h>
#include <NetworkManager.h>
#include "nmt-page-main.h"
#include "nmt-device-entry.h"
#include "nmt-mac-entry.h"
#include "nmt-mtu-entry.h"
#include "nmtui.h"
#include "nmt-page-bond.h"
#include "nmt-page-bridge.h"
#include "nmt-page-bridge-port.h"
#include "nmt-page-dsl.h"
#include "nmt-page-ethernet.h"
#include "nmt-page-infiniband.h"
#include "nmt-page-ip4.h"
#include "nmt-page-ip6.h"
#include "nmt-page-ppp.h"
#include "nmt-page-team.h"
#include "nmt-page-team-port.h"
#include "nmt-page-vlan.h"
#include "nmt-page-wifi.h"
G_DEFINE_TYPE (NmtPageMain, nmt_page_main, NMT_TYPE_EDITOR_PAGE)
#define NMT_PAGE_MAIN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_PAGE_MAIN, NmtPageMainPrivate))
typedef struct {
NMEditorConnectionTypeData *type_data;
} NmtPageMainPrivate;
enum {
PROP_0,
PROP_TYPE_DATA,
LAST_PROP
};
/**
* nmt_page_main_new:
* @conn: the #NMConnection to display
* @type_data: @conn's #NMEditorConnectionTypeData
*
* Creates a new #NmtPageMain
*
* Returns: a new #NmtPageMain
*/
NmtNewtWidget *
nmt_page_main_new (NMConnection *conn,
NMEditorConnectionTypeData *type_data)
{
return g_object_new (NMT_TYPE_PAGE_MAIN,
"connection", conn,
"type-data", type_data,
NULL);
}
static void
nmt_page_main_init (NmtPageMain *page)
{
}
static gboolean
permissions_transform_to_allusers (GBinding *binding,
const GValue *source_value,
GValue *target_value,
gpointer user_data)
{
char **perms = g_value_get_boxed (source_value);
g_value_set_boolean (target_value, g_strv_length (perms) == 0);
return TRUE;
}
static gboolean
permissions_transform_from_allusers (GBinding *binding,
const GValue *source_value,
GValue *target_value,
gpointer user_data)
{
gboolean allusers = g_value_get_boolean (source_value);
char **perms = NULL;
if (allusers) {
perms = g_new (char *, 2);
perms[0] = g_strdup_printf ("user:%s:", g_get_user_name ());
perms[1] = NULL;
}
g_value_take_boxed (target_value, perms);
return TRUE;
}
static NmtNewtWidget *
add_section_for_page (NmtPageGrid *grid, NmtNewtWidget *widget)
{
NmtEditorPage *page;
NmtNewtWidget *section, *header, *toggle;
g_return_val_if_fail (NMT_IS_EDITOR_PAGE (widget), NULL);
g_return_val_if_fail (nmt_newt_widget_get_parent (widget) == NULL, NULL);
page = NMT_EDITOR_PAGE (widget);
section = nmt_newt_section_new (TRUE);
toggle = nmt_newt_toggle_button_new (_("Hide"), _("Show"));
header = nmt_page_grid_new ();
nmt_page_grid_append (NMT_PAGE_GRID (header),
nmt_editor_page_get_title (page),
nmt_editor_page_get_header_widget (page),
toggle);
nmt_page_grid_set_row_flags (NMT_PAGE_GRID (header),
nmt_editor_page_get_header_widget (page),
NMT_PAGE_GRID_ROW_LABEL_ALIGN_LEFT |
NMT_PAGE_GRID_ROW_EXTRA_ALIGN_RIGHT);
nmt_newt_section_set_header (NMT_NEWT_SECTION (section), header);
nmt_newt_section_set_body (NMT_NEWT_SECTION (section), widget);
g_object_bind_property (toggle, "active",
section, "open",
G_BINDING_SYNC_CREATE);
if (nmt_editor_page_show_by_default (page) || !nmt_newt_widget_get_valid (section))
nmt_newt_toggle_button_set_active (NMT_NEWT_TOGGLE_BUTTON (toggle), TRUE);
nmt_page_grid_append (grid, NULL, section, NULL);
return section;
}
static void
nmt_page_main_constructed (GObject *object)
{
NmtPageMain *page_main = NMT_PAGE_MAIN (object);
NmtPageMainPrivate *priv = NMT_PAGE_MAIN_GET_PRIVATE (page_main);
NmtPageGrid *grid;
NMConnection *conn;
NMSettingConnection *s_con;
NmtNewtWidget *widget, *section, *separator;
const char *deventry_label;
NmtDeviceEntry *deventry;
GType hardware_type;
const char *slave_type;
conn = nmt_editor_page_get_connection (NMT_EDITOR_PAGE (page_main));
s_con = nm_connection_get_setting_connection (conn);
grid = NMT_PAGE_GRID (page_main);
widget = nmt_newt_entry_new (40, NMT_NEWT_ENTRY_NONEMPTY);
g_object_bind_property (s_con, NM_SETTING_CONNECTION_ID,
widget, "text",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_page_grid_append (grid, _("Profile name"), widget, NULL);
if (priv->type_data->virtual)
hardware_type = G_TYPE_NONE;
else
hardware_type = priv->type_data->device_type;
/* For connections involving multiple network devices, clarify which one
* NMSettingConnection:interface-name refers to.
*/
if (nm_connection_is_type (conn, NM_SETTING_PPPOE_SETTING_NAME))
deventry_label = _("Ethernet device");
else
deventry_label = _("Device");
widget = nmt_device_entry_new (deventry_label, 40, hardware_type);
nmt_page_grid_append (grid, NULL, widget, NULL);
deventry = NMT_DEVICE_ENTRY (widget);
g_object_bind_property (s_con, NM_SETTING_CONNECTION_INTERFACE_NAME,
deventry, "interface-name",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_page_grid_append (grid, NULL, nmt_newt_separator_new (), NULL);
if (nm_connection_is_type (conn, NM_SETTING_BOND_SETTING_NAME))
add_section_for_page (grid, nmt_page_bond_new (conn, deventry));
else if (nm_connection_is_type (conn, NM_SETTING_BRIDGE_SETTING_NAME))
add_section_for_page (grid, nmt_page_bridge_new (conn, deventry));
else if (nm_connection_is_type (conn, NM_SETTING_INFINIBAND_SETTING_NAME))
add_section_for_page (grid, nmt_page_infiniband_new (conn, deventry));
else if (nm_connection_is_type (conn, NM_SETTING_PPPOE_SETTING_NAME)) {
add_section_for_page (grid, nmt_page_dsl_new (conn));
add_section_for_page (grid, nmt_page_ethernet_new (conn, deventry));
add_section_for_page (grid, nmt_page_ppp_new (conn));
} else if (nm_connection_is_type (conn, NM_SETTING_TEAM_SETTING_NAME))
add_section_for_page (grid, nmt_page_team_new (conn, deventry));
else if (nm_connection_is_type (conn, NM_SETTING_VLAN_SETTING_NAME))
add_section_for_page (grid, nmt_page_vlan_new (conn, deventry));
else if (nm_connection_is_type (conn, NM_SETTING_WIRED_SETTING_NAME))
add_section_for_page (grid, nmt_page_ethernet_new (conn, deventry));
else if (nm_connection_is_type (conn, NM_SETTING_WIRELESS_SETTING_NAME))
add_section_for_page (grid, nmt_page_wifi_new (conn, deventry));
nmt_page_grid_append (grid, NULL, nmt_newt_separator_new (), NULL);
slave_type = nm_setting_connection_get_slave_type (s_con);
if (slave_type) {
if (!strcmp (slave_type, NM_SETTING_BRIDGE_SETTING_NAME))
add_section_for_page (grid, nmt_page_bridge_port_new (conn));
else if (!strcmp (slave_type, NM_SETTING_TEAM_SETTING_NAME))
add_section_for_page (grid, nmt_page_team_port_new (conn));
} else {
section = add_section_for_page (grid, nmt_page_ip4_new (conn));
/* Add a separator between ip4 and ip6 that's only visible if ip4 is open */
separator = nmt_newt_separator_new ();
g_object_bind_property (section, "open", separator, "visible", G_BINDING_SYNC_CREATE);
nmt_page_grid_append (grid, NULL, separator, NULL);
add_section_for_page (grid, nmt_page_ip6_new (conn));
nmt_page_grid_append (grid, NULL, nmt_newt_separator_new (), NULL);
}
widget = nmt_newt_checkbox_new (_("Automatically connect"));
g_object_bind_property (s_con, NM_SETTING_CONNECTION_AUTOCONNECT,
widget, "active",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_page_grid_append (grid, NULL, widget, NULL);
widget = nmt_newt_checkbox_new (_("Available to all users"));
g_object_bind_property_full (s_con, NM_SETTING_CONNECTION_PERMISSIONS,
widget, "active",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE,
permissions_transform_to_allusers,
permissions_transform_from_allusers,
NULL, NULL);
nmt_page_grid_append (grid, NULL, widget, NULL);
G_OBJECT_CLASS (nmt_page_main_parent_class)->constructed (object);
}
static void
nmt_page_main_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
NmtPageMainPrivate *priv = NMT_PAGE_MAIN_GET_PRIVATE (object);
switch (prop_id) {
case PROP_TYPE_DATA:
priv->type_data = g_value_get_pointer (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
nmt_page_main_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
NmtPageMainPrivate *priv = NMT_PAGE_MAIN_GET_PRIVATE (object);
switch (prop_id) {
case PROP_TYPE_DATA:
g_value_set_pointer (value, priv->type_data);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
nmt_page_main_class_init (NmtPageMainClass *main_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (main_class);
g_type_class_add_private (main_class, sizeof (NmtPageMainPrivate));
object_class->constructed = nmt_page_main_constructed;
object_class->set_property = nmt_page_main_set_property;
object_class->get_property = nmt_page_main_get_property;
/**
* NmtPageMain:type-data:
*
* The page's connection's #NMEditorConnectionTypeData
*/
g_object_class_install_property
(object_class, PROP_TYPE_DATA,
g_param_spec_pointer ("type-data", "", "",
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
}

View file

@ -1,51 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* 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, see <http://www.gnu.org/licenses/>.
*
* Copyright 2013 Red Hat, Inc.
*/
#ifndef NMT_PAGE_MAIN_H
#define NMT_PAGE_MAIN_H
#include "nmt-editor-page.h"
#include "nm-editor-utils.h"
G_BEGIN_DECLS
#define NMT_TYPE_PAGE_MAIN (nmt_page_main_get_type ())
#define NMT_PAGE_MAIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMT_TYPE_PAGE_MAIN, NmtPageMain))
#define NMT_PAGE_MAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMT_TYPE_PAGE_MAIN, NmtPageMainClass))
#define NMT_IS_PAGE_MAIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMT_TYPE_PAGE_MAIN))
#define NMT_IS_PAGE_MAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMT_TYPE_PAGE_MAIN))
#define NMT_PAGE_MAIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_PAGE_MAIN, NmtPageMainClass))
typedef struct {
NmtEditorPage parent;
} NmtPageMain;
typedef struct {
NmtEditorPageClass parent;
} NmtPageMainClass;
GType nmt_page_main_get_type (void);
NmtNewtWidget *nmt_page_main_new (NMConnection *conn,
NMEditorConnectionTypeData *type_data);
G_END_DECLS
#endif /* NMT_PAGE_MAIN_H */

View file

@ -41,12 +41,11 @@ typedef struct {
#define NMT_PAGE_PPP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_PAGE_PPP, NmtPagePppPrivate))
NmtNewtWidget *
NmtEditorPage *
nmt_page_ppp_new (NMConnection *conn)
{
return g_object_new (NMT_TYPE_PAGE_PPP,
"connection", conn,
"title", _("PPP CONFIGURATION"),
NULL);
}
@ -111,11 +110,12 @@ nmt_page_ppp_constructed (GObject *object)
{
NmtPagePpp *ppp = NMT_PAGE_PPP (object);
NmtPagePppPrivate *priv = NMT_PAGE_PPP_GET_PRIVATE (ppp);
NmtPageGrid *grid;
NmtEditorSection *section;
NmtEditorGrid *grid;
NMSettingPpp *s_ppp;
NmtNewtWidget *widget, *use_mppe;
NmtNewtGrid *auth_grid, *mppe_grid;
NmtNewtSection *section;
NmtNewtSection *auth_section, *mppe_section;
NMConnection *conn;
conn = nmt_editor_page_get_connection (NMT_EDITOR_PAGE (ppp));
@ -131,20 +131,21 @@ nmt_page_ppp_constructed (GObject *object)
priv->lcp_echo_failure = 5;
}
grid = NMT_PAGE_GRID (ppp);
section = nmt_editor_section_new (_("PPP CONFIGURATION"), NULL, TRUE);
grid = nmt_editor_section_get_body (section);
/* Auth methods */
widget = nmt_newt_section_new (FALSE);
section = NMT_NEWT_SECTION (widget);
g_object_set (section, "open", TRUE, NULL);
nmt_page_grid_append (grid, NULL, widget, NULL);
auth_section = NMT_NEWT_SECTION (widget);
g_object_set (auth_section, "open", TRUE, NULL);
nmt_editor_grid_append (grid, NULL, widget, NULL);
widget = nmt_newt_label_new (_("Allowed authentication methods:"));
nmt_newt_section_set_header (section, widget);
nmt_newt_section_set_header (auth_section, widget);
widget = nmt_newt_grid_new ();
auth_grid = NMT_NEWT_GRID (widget);
nmt_newt_section_set_body (section, widget);
nmt_newt_section_set_body (auth_section, widget);
widget = nmt_newt_checkbox_new (_("EAP"));
g_object_bind_property (s_ppp, NM_SETTING_PPP_REFUSE_EAP,
@ -186,13 +187,13 @@ nmt_page_ppp_constructed (GObject *object)
G_BINDING_SYNC_CREATE);
nmt_newt_grid_add (auth_grid, widget, 0, 4);
nmt_page_grid_append (grid, NULL, nmt_newt_separator_new (), NULL);
nmt_editor_grid_append (grid, NULL, nmt_newt_separator_new (), NULL);
/* MPPE */
widget = nmt_newt_section_new (FALSE);
section = NMT_NEWT_SECTION (widget);
g_object_set (section, "open", TRUE, NULL);
nmt_page_grid_append (grid, NULL, widget, NULL);
mppe_section = NMT_NEWT_SECTION (widget);
g_object_set (mppe_section, "open", TRUE, NULL);
nmt_editor_grid_append (grid, NULL, widget, NULL);
widget = nmt_newt_checkbox_new (_("Use point-to-point encryption (MPPE)"));
g_object_bind_property (s_ppp, NM_SETTING_PPP_REQUIRE_MPPE,
@ -200,11 +201,11 @@ nmt_page_ppp_constructed (GObject *object)
G_BINDING_BIDIRECTIONAL |
G_BINDING_SYNC_CREATE);
use_mppe = widget;
nmt_newt_section_set_header (section, widget);
nmt_newt_section_set_header (mppe_section, widget);
widget = nmt_newt_grid_new ();
mppe_grid = NMT_NEWT_GRID (widget);
nmt_newt_section_set_body (section, widget);
nmt_newt_section_set_body (mppe_section, widget);
widget = nmt_newt_checkbox_new (_("Require 128-bit encryption"));
g_object_bind_property (use_mppe, "active",
@ -226,7 +227,7 @@ nmt_page_ppp_constructed (GObject *object)
G_BINDING_SYNC_CREATE);
nmt_newt_grid_add (mppe_grid, widget, 0, 1);
nmt_page_grid_append (grid, NULL, nmt_newt_separator_new (), NULL);
nmt_editor_grid_append (grid, NULL, nmt_newt_separator_new (), NULL);
widget = nmt_newt_checkbox_new (_("Allow BSD data compression"));
g_object_bind_property (s_ppp, NM_SETTING_PPP_NOBSDCOMP,
@ -234,7 +235,7 @@ nmt_page_ppp_constructed (GObject *object)
G_BINDING_BIDIRECTIONAL |
G_BINDING_INVERT_BOOLEAN |
G_BINDING_SYNC_CREATE);
nmt_page_grid_append (grid, NULL, widget, NULL);
nmt_editor_grid_append (grid, NULL, widget, NULL);
widget = nmt_newt_checkbox_new (_("Allow Deflate data compression"));
g_object_bind_property (s_ppp, NM_SETTING_PPP_NODEFLATE,
@ -242,7 +243,7 @@ nmt_page_ppp_constructed (GObject *object)
G_BINDING_BIDIRECTIONAL |
G_BINDING_INVERT_BOOLEAN |
G_BINDING_SYNC_CREATE);
nmt_page_grid_append (grid, NULL, widget, NULL);
nmt_editor_grid_append (grid, NULL, widget, NULL);
widget = nmt_newt_checkbox_new (_("Use TCP header compression"));
g_object_bind_property (s_ppp, NM_SETTING_PPP_NO_VJ_COMP,
@ -250,9 +251,9 @@ nmt_page_ppp_constructed (GObject *object)
G_BINDING_BIDIRECTIONAL |
G_BINDING_INVERT_BOOLEAN |
G_BINDING_SYNC_CREATE);
nmt_page_grid_append (grid, NULL, widget, NULL);
nmt_editor_grid_append (grid, NULL, widget, NULL);
nmt_page_grid_append (grid, NULL, nmt_newt_separator_new (), NULL);
nmt_editor_grid_append (grid, NULL, nmt_newt_separator_new (), NULL);
widget = nmt_newt_checkbox_new (_("Send PPP echo packets"));
g_object_bind_property_full (s_ppp, NM_SETTING_PPP_LCP_ECHO_INTERVAL,
@ -269,7 +270,9 @@ nmt_page_ppp_constructed (GObject *object)
transform_lcp_echo_properties_to_checkbox,
transform_checkbox_to_lcp_echo_failure,
ppp, NULL);
nmt_page_grid_append (grid, NULL, widget, NULL);
nmt_editor_grid_append (grid, NULL, widget, NULL);
nmt_editor_page_add_section (NMT_EDITOR_PAGE (ppp), section);
G_OBJECT_CLASS (nmt_page_ppp_parent_class)->constructed (object);
}

View file

@ -42,7 +42,7 @@ typedef struct {
GType nmt_page_ppp_get_type (void);
NmtNewtWidget *nmt_page_ppp_new (NMConnection *conn);
NmtEditorPage *nmt_page_ppp_new (NMConnection *conn);
G_END_DECLS

View file

@ -37,12 +37,11 @@ typedef struct {
} NmtPageTeamPortPrivate;
NmtNewtWidget *
NmtEditorPage *
nmt_page_team_port_new (NMConnection *conn)
{
return g_object_new (NMT_TYPE_PAGE_TEAM_PORT,
"connection", conn,
"title", _("TEAM PORT"),
NULL);
}
@ -79,6 +78,7 @@ nmt_page_team_port_constructed (GObject *object)
{
NmtPageTeamPort *team = NMT_PAGE_TEAM_PORT (object);
NmtPageTeamPortPrivate *priv = NMT_PAGE_TEAM_PORT_GET_PRIVATE (team);
NmtEditorSection *section;
NmtNewtGrid *grid;
NMSettingTeamPort *s_port;
NmtNewtWidget *widget;
@ -92,8 +92,10 @@ nmt_page_team_port_constructed (GObject *object)
}
priv->s_port = s_port;
section = nmt_editor_section_new (_("TEAM PORT"), NULL, TRUE);
widget = nmt_newt_grid_new ();
nmt_page_grid_append (NMT_PAGE_GRID (team), NULL, widget, NULL);
nmt_editor_grid_append (nmt_editor_section_get_body (section), NULL, widget, NULL);
grid = NMT_NEWT_GRID (widget);
@ -111,6 +113,8 @@ nmt_page_team_port_constructed (GObject *object)
g_signal_connect (widget, "clicked", G_CALLBACK (edit_clicked), team);
nmt_newt_grid_add (grid, widget, 0, 4);
nmt_editor_page_add_section (NMT_EDITOR_PAGE (team), section);
G_OBJECT_CLASS (nmt_page_team_port_parent_class)->constructed (object);
}

View file

@ -19,7 +19,7 @@
#ifndef NMT_PAGE_TEAM_PORT_H
#define NMT_PAGE_TEAM_PORT_H
#include "nmt-page-device.h"
#include "nmt-editor-page-device.h"
G_BEGIN_DECLS
@ -42,7 +42,7 @@ typedef struct {
GType nmt_page_team_port_get_type (void);
NmtNewtWidget *nmt_page_team_port_new (NMConnection *conn);
NmtEditorPage *nmt_page_team_port_new (NMConnection *conn);
G_END_DECLS

View file

@ -30,7 +30,7 @@
#include "nmt-slave-list.h"
G_DEFINE_TYPE (NmtPageTeam, nmt_page_team, NMT_TYPE_PAGE_DEVICE)
G_DEFINE_TYPE (NmtPageTeam, nmt_page_team, NMT_TYPE_EDITOR_PAGE_DEVICE)
#define NMT_PAGE_TEAM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_PAGE_TEAM, NmtPageTeamPrivate))
@ -42,13 +42,12 @@ typedef struct {
} NmtPageTeamPrivate;
NmtNewtWidget *
NmtEditorPage *
nmt_page_team_new (NMConnection *conn,
NmtDeviceEntry *deventry)
{
return g_object_new (NMT_TYPE_PAGE_TEAM,
"connection", conn,
"title", _("TEAM"),
"device-entry", deventry,
NULL);
}
@ -132,6 +131,7 @@ nmt_page_team_constructed (GObject *object)
{
NmtPageTeam *team = NMT_PAGE_TEAM (object);
NmtPageTeamPrivate *priv = NMT_PAGE_TEAM_GET_PRIVATE (team);
NmtEditorSection *section;
NmtNewtGrid *grid;
NMSettingTeam *s_team;
NmtNewtWidget *widget;
@ -145,8 +145,10 @@ nmt_page_team_constructed (GObject *object)
}
priv->s_team = s_team;
section = nmt_editor_section_new (_("TEAM"), NULL, TRUE);
widget = nmt_newt_grid_new ();
nmt_page_grid_append (NMT_PAGE_GRID (team), NULL, widget, NULL);
nmt_editor_grid_append (nmt_editor_section_get_body (section), NULL, widget, NULL);
grid = NMT_NEWT_GRID (widget);
@ -175,6 +177,8 @@ nmt_page_team_constructed (GObject *object)
g_signal_connect (widget, "clicked", G_CALLBACK (edit_clicked), team);
nmt_newt_grid_add (grid, widget, 0, 4);
nmt_editor_page_add_section (NMT_EDITOR_PAGE (team), section);
G_OBJECT_CLASS (nmt_page_team_parent_class)->constructed (object);
}

View file

@ -19,7 +19,7 @@
#ifndef NMT_PAGE_TEAM_H
#define NMT_PAGE_TEAM_H
#include "nmt-page-device.h"
#include "nmt-editor-page-device.h"
G_BEGIN_DECLS
@ -31,18 +31,18 @@ G_BEGIN_DECLS
#define NMT_PAGE_TEAM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_PAGE_TEAM, NmtPageTeamClass))
typedef struct {
NmtPageDevice parent;
NmtEditorPageDevice parent;
} NmtPageTeam;
typedef struct {
NmtPageDeviceClass parent;
NmtEditorPageDeviceClass parent;
} NmtPageTeamClass;
GType nmt_page_team_get_type (void);
NmtNewtWidget *nmt_page_team_new (NMConnection *conn,
NmtEditorPage *nmt_page_team_new (NMConnection *conn,
NmtDeviceEntry *deventry);
G_END_DECLS

View file

@ -33,7 +33,7 @@
#include "nmt-mac-entry.h"
#include "nmt-mtu-entry.h"
G_DEFINE_TYPE (NmtPageVlan, nmt_page_vlan, NMT_TYPE_PAGE_DEVICE)
G_DEFINE_TYPE (NmtPageVlan, nmt_page_vlan, NMT_TYPE_EDITOR_PAGE_DEVICE)
#define NMT_PAGE_VLAN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_PAGE_VLAN, NmtPageVlanPrivate))
@ -42,13 +42,12 @@ typedef struct {
} NmtPageVlanPrivate;
NmtNewtWidget *
NmtEditorPage *
nmt_page_vlan_new (NMConnection *conn,
NmtDeviceEntry *deventry)
{
return g_object_new (NMT_TYPE_PAGE_VLAN,
"connection", conn,
"title", _("VLAN"),
"device-entry", deventry,
NULL);
}
@ -72,7 +71,8 @@ nmt_page_vlan_constructed (GObject *object)
{
NmtPageVlan *vlan = NMT_PAGE_VLAN (object);
NmtPageVlanPrivate *priv = NMT_PAGE_VLAN_GET_PRIVATE (vlan);
NmtPageGrid *grid;
NmtEditorSection *section;
NmtEditorGrid *grid;
NMSettingWired *s_wired;
NMSettingVlan *s_vlan;
NmtNewtWidget *widget, *parent, *id_entry;
@ -94,7 +94,8 @@ nmt_page_vlan_constructed (GObject *object)
}
priv->s_wired = g_object_ref_sink (s_wired);
grid = NMT_PAGE_GRID (vlan);
section = nmt_editor_section_new (_("VLAN"), NULL, TRUE);
grid = nmt_editor_section_get_body (section);
nm_editor_bind_vlan_name (s_vlan, nm_connection_get_setting_connection (conn));
@ -107,27 +108,29 @@ nmt_page_vlan_constructed (GObject *object)
g_object_bind_property (s_wired, NM_SETTING_WIRED_MAC_ADDRESS,
widget, "mac-address",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_page_grid_append (grid, NULL, widget, NULL);
nmt_editor_grid_append (grid, NULL, widget, NULL);
widget = id_entry = nmt_newt_entry_numeric_new (8, 0, 4095);
g_object_bind_property (s_vlan, NM_SETTING_VLAN_ID,
widget, "text",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_page_grid_append (grid, _("VLAN id"), widget, NULL);
nmt_editor_grid_append (grid, _("VLAN id"), widget, NULL);
nmt_page_grid_append (grid, NULL, nmt_newt_separator_new (), NULL);
nmt_editor_grid_append (grid, NULL, nmt_newt_separator_new (), NULL);
widget = nmt_mac_entry_new (40, ETH_ALEN);
g_object_bind_property (s_wired, NM_SETTING_WIRED_CLONED_MAC_ADDRESS,
widget, "mac-address",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_page_grid_append (grid, _("Cloned MAC address"), widget, NULL);
nmt_editor_grid_append (grid, _("Cloned MAC address"), widget, NULL);
widget = nmt_mtu_entry_new ();
g_object_bind_property (s_wired, NM_SETTING_WIRED_MTU,
widget, "mtu",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_page_grid_append (grid, _("MTU"), widget, NULL);
nmt_editor_grid_append (grid, _("MTU"), widget, NULL);
nmt_editor_page_add_section (NMT_EDITOR_PAGE (vlan), section);
G_OBJECT_CLASS (nmt_page_vlan_parent_class)->constructed (object);
}

View file

@ -19,7 +19,7 @@
#ifndef NMT_PAGE_VLAN_H
#define NMT_PAGE_VLAN_H
#include "nmt-page-device.h"
#include "nmt-editor-page-device.h"
G_BEGIN_DECLS
@ -31,18 +31,18 @@ G_BEGIN_DECLS
#define NMT_PAGE_VLAN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_PAGE_VLAN, NmtPageVlanClass))
typedef struct {
NmtPageDevice parent;
NmtEditorPageDevice parent;
} NmtPageVlan;
typedef struct {
NmtPageDeviceClass parent;
NmtEditorPageDeviceClass parent;
} NmtPageVlanClass;
GType nmt_page_vlan_get_type (void);
NmtNewtWidget *nmt_page_vlan_new (NMConnection *conn,
NmtEditorPage *nmt_page_vlan_new (NMConnection *conn,
NmtDeviceEntry *deventry);
G_END_DECLS

View file

@ -39,7 +39,7 @@
#include "nm-editor-bindings.h"
G_DEFINE_TYPE (NmtPageWifi, nmt_page_wifi, NMT_TYPE_PAGE_DEVICE)
G_DEFINE_TYPE (NmtPageWifi, nmt_page_wifi, NMT_TYPE_EDITOR_PAGE_DEVICE)
#define NMT_PAGE_WIFI_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMT_TYPE_PAGE_WIFI, NmtPageWifiPrivate))
@ -48,13 +48,12 @@ typedef struct {
} NmtPageWifiPrivate;
NmtNewtWidget *
NmtEditorPage *
nmt_page_wifi_new (NMConnection *conn,
NmtDeviceEntry *deventry)
{
return g_object_new (NMT_TYPE_PAGE_WIFI,
"connection", conn,
"title", _("WI-FI"),
"device-entry", deventry,
NULL);
}
@ -184,7 +183,8 @@ nmt_page_wifi_constructed (GObject *object)
NmtPageWifiPrivate *priv = NMT_PAGE_WIFI_GET_PRIVATE (object);
NmtPageWifi *wifi = NMT_PAGE_WIFI (object);
NmtDeviceEntry *deventry;
NmtPageGrid *grid;
NmtEditorSection *section;
NmtEditorGrid *grid;
NMSettingWireless *s_wireless;
NMSettingWirelessSecurity *s_wsec;
NmtNewtWidget *widget, *hbox, *subgrid;
@ -209,12 +209,13 @@ nmt_page_wifi_constructed (GObject *object)
}
priv->s_wsec = g_object_ref_sink (s_wsec);
deventry = nmt_page_device_get_device_entry (NMT_PAGE_DEVICE (object));
deventry = nmt_editor_page_device_get_device_entry (NMT_EDITOR_PAGE_DEVICE (object));
g_object_bind_property (s_wireless, NM_SETTING_WIRELESS_MAC_ADDRESS,
deventry, "mac-address",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
grid = NMT_PAGE_GRID (wifi);
section = nmt_editor_section_new (_("WI-FI"), NULL, TRUE);
grid = nmt_editor_section_get_body (section);
widget = nmt_newt_entry_new (40, NMT_NEWT_ENTRY_NONEMPTY);
g_object_bind_property_full (s_wireless, NM_SETTING_WIRELESS_SSID,
@ -223,13 +224,13 @@ nmt_page_wifi_constructed (GObject *object)
ssid_transform_to_entry,
ssid_transform_from_entry,
s_wireless, NULL);
nmt_page_grid_append (grid, _("SSID"), widget, NULL);
nmt_editor_grid_append (grid, _("SSID"), widget, NULL);
widget = nmt_newt_popup_new (wifi_mode);
g_object_bind_property (s_wireless, NM_SETTING_WIRELESS_MODE,
widget, "active-id",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_page_grid_append (grid, _("Mode"), widget, NULL);
nmt_editor_grid_append (grid, _("Mode"), widget, NULL);
mode = widget;
hbox = nmt_newt_grid_new ();
@ -255,28 +256,28 @@ nmt_page_wifi_constructed (GObject *object)
G_BINDING_SYNC_CREATE,
mode_transform_to_band_visibility,
NULL, NULL, NULL);
nmt_page_grid_append (grid, _("Channel"), hbox, NULL);
nmt_editor_grid_append (grid, _("Channel"), hbox, NULL);
nmt_page_grid_append (grid, NULL, nmt_newt_separator_new (), NULL);
nmt_editor_grid_append (grid, NULL, nmt_newt_separator_new (), NULL);
widget = nmt_newt_popup_new (wifi_security);
nmt_page_grid_append (grid, _("Security"), widget, NULL);
nmt_editor_grid_append (grid, _("Security"), widget, NULL);
security = widget;
widget = nmt_newt_stack_new ();
stack = NMT_NEWT_STACK (widget);
/* none */
subgrid = nmt_page_grid_new ();
subgrid = nmt_editor_grid_new ();
nmt_newt_stack_add (stack, "none", subgrid);
/* wpa-personal */
subgrid = nmt_page_grid_new ();
subgrid = nmt_editor_grid_new ();
widget = nmt_password_fields_new (40, NMT_PASSWORD_FIELDS_SHOW_PASSWORD);
g_object_bind_property (s_wsec, NM_SETTING_WIRELESS_SECURITY_PSK,
widget, "password",
G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
nmt_page_grid_append (NMT_PAGE_GRID (subgrid), _("Password"), widget, NULL);
nmt_editor_grid_append (NMT_EDITOR_GRID (subgrid), _("Password"), widget, NULL);
nmt_newt_stack_add (stack, "wpa-personal", subgrid);
/* "wpa-enterprise" */
@ -285,13 +286,13 @@ nmt_page_wifi_constructed (GObject *object)
nmt_newt_stack_add (stack, "wpa-enterprise", widget);
/* wep-key */
subgrid = nmt_page_grid_new ();
subgrid = nmt_editor_grid_new ();
widget = entry = nmt_password_fields_new (40, NMT_PASSWORD_FIELDS_SHOW_PASSWORD);
nmt_page_grid_append (NMT_PAGE_GRID (subgrid), _("Key"), widget, NULL);
nmt_editor_grid_append (NMT_EDITOR_GRID (subgrid), _("Key"), widget, NULL);
widget = nmt_newt_popup_new (wep_index);
nmt_page_grid_append (NMT_PAGE_GRID (subgrid), _("WEP index"), widget, NULL);
nmt_editor_grid_append (NMT_EDITOR_GRID (subgrid), _("WEP index"), widget, NULL);
nm_editor_bind_wireless_security_wep_key (s_wsec,
entry, "password",
@ -299,18 +300,18 @@ nmt_page_wifi_constructed (GObject *object)
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
widget = nmt_newt_popup_new (wep_auth);
nmt_page_grid_append (NMT_PAGE_GRID (subgrid), _("Authentication"), widget, NULL);
nmt_editor_grid_append (NMT_EDITOR_GRID (subgrid), _("Authentication"), widget, NULL);
nmt_newt_stack_add (stack, "wep-key", subgrid);
/* wep-passphrase */
subgrid = nmt_page_grid_new ();
subgrid = nmt_editor_grid_new ();
widget = entry = nmt_password_fields_new (40, NMT_PASSWORD_FIELDS_SHOW_PASSWORD);
nmt_page_grid_append (NMT_PAGE_GRID (subgrid), _("Password"), widget, NULL);
nmt_editor_grid_append (NMT_EDITOR_GRID (subgrid), _("Password"), widget, NULL);
widget = nmt_newt_popup_new (wep_index);
nmt_page_grid_append (NMT_PAGE_GRID (subgrid), _("WEP index"), widget, NULL);
nmt_editor_grid_append (NMT_EDITOR_GRID (subgrid), _("WEP index"), widget, NULL);
nm_editor_bind_wireless_security_wep_key (s_wsec,
entry, "password",
@ -318,7 +319,7 @@ nmt_page_wifi_constructed (GObject *object)
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
widget = nmt_newt_popup_new (wep_auth);
nmt_page_grid_append (NMT_PAGE_GRID (subgrid), _("Authentication"), widget, NULL);
nmt_editor_grid_append (NMT_EDITOR_GRID (subgrid), _("Authentication"), widget, NULL);
nmt_newt_stack_add (stack, "wep-passphrase", subgrid);
@ -328,10 +329,10 @@ nmt_page_wifi_constructed (GObject *object)
nmt_newt_stack_add (stack, "dynamic-wep", widget);
/* leap */
subgrid = nmt_page_grid_new ();
subgrid = nmt_editor_grid_new ();
widget = nmt_newt_entry_new (40, NMT_NEWT_ENTRY_NONEMPTY);
nmt_page_grid_append (NMT_PAGE_GRID (subgrid), _("Username"), widget, NULL);
nmt_editor_grid_append (NMT_EDITOR_GRID (subgrid), _("Username"), widget, NULL);
g_object_bind_property (s_wsec, NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME,
widget, "text",
G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
@ -340,36 +341,38 @@ nmt_page_wifi_constructed (GObject *object)
g_object_bind_property (s_wsec, NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD,
widget, "password",
G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
nmt_page_grid_append (NMT_PAGE_GRID (subgrid), _("Password"), widget, NULL);
nmt_editor_grid_append (NMT_EDITOR_GRID (subgrid), _("Password"), widget, NULL);
nmt_newt_stack_add (stack, "leap", subgrid);
nmt_page_grid_append (grid, NULL, NMT_NEWT_WIDGET (stack), NULL);
nmt_editor_grid_append (grid, NULL, NMT_NEWT_WIDGET (stack), NULL);
g_object_bind_property (security, "active-id",
stack, "active-id",
G_BINDING_SYNC_CREATE);
nm_editor_bind_wireless_security_method (conn, s_wsec, security, "active-id",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_page_grid_append (grid, NULL, nmt_newt_separator_new (), NULL);
nmt_editor_grid_append (grid, NULL, nmt_newt_separator_new (), NULL);
widget = nmt_mac_entry_new (40, ETH_ALEN);
g_object_bind_property (s_wireless, NM_SETTING_WIRELESS_BSSID,
widget, "mac-address",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_page_grid_append (grid, _("BSSID"), widget, NULL);
nmt_editor_grid_append (grid, _("BSSID"), widget, NULL);
widget = nmt_mac_entry_new (40, ETH_ALEN);
g_object_bind_property (s_wireless, NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS,
widget, "mac-address",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_page_grid_append (grid, _("Cloned MAC address"), widget, NULL);
nmt_editor_grid_append (grid, _("Cloned MAC address"), widget, NULL);
widget = nmt_mtu_entry_new ();
g_object_bind_property (s_wireless, NM_SETTING_WIRELESS_MTU,
widget, "mtu",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
nmt_page_grid_append (grid, _("MTU"), widget, NULL);
nmt_editor_grid_append (grid, _("MTU"), widget, NULL);
nmt_editor_page_add_section (NMT_EDITOR_PAGE (wifi), section);
G_OBJECT_CLASS (nmt_page_wifi_parent_class)->constructed (object);
}

View file

@ -19,7 +19,7 @@
#ifndef NMT_PAGE_WIFI_H
#define NMT_PAGE_WIFI_H
#include "nmt-page-device.h"
#include "nmt-editor-page-device.h"
G_BEGIN_DECLS
@ -31,18 +31,18 @@ G_BEGIN_DECLS
#define NMT_PAGE_WIFI_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_PAGE_WIFI, NmtPageWifiClass))
typedef struct {
NmtPageDevice parent;
NmtEditorPageDevice parent;
} NmtPageWifi;
typedef struct {
NmtPageDeviceClass parent;
NmtEditorPageDeviceClass parent;
} NmtPageWifiClass;
GType nmt_page_wifi_get_type (void);
NmtNewtWidget *nmt_page_wifi_new (NMConnection *conn,
NmtEditorPage *nmt_page_wifi_new (NMConnection *conn,
NmtDeviceEntry *deventry);
G_END_DECLS

View file

@ -29,7 +29,7 @@
#include <glib/gi18n-lib.h>
#include "nmt-password-dialog.h"
#include "nmt-secret-agent.h"
#include "nm-secret-agent-simple.h"
#include "nmtui.h"
G_DEFINE_TYPE (NmtPasswordDialog, nmt_password_dialog, NMT_TYPE_NEWT_FORM)
@ -60,10 +60,10 @@ enum {
/**
* nmt_password_dialog_new:
* @request_id: the request ID from the #NmtSecretAgent
* @request_id: the request ID from the #NMSecretAgentSimple
* @title: the dialog title
* @prompt: the prompt text to display
* @secrets: (element-type #NmtSecretAgentSecret): the secrets requested
* @secrets: (element-type #NMSecretAgentSimpleSecret): the secrets requested
*
* Creates a new #NmtPasswordDialog to request passwords from
* the user.
@ -109,7 +109,7 @@ maybe_save_input_and_exit (NmtNewtWidget *widget,
priv->succeeded = TRUE;
for (i = 0; i < priv->secrets->len; i++) {
NmtSecretAgentSecret *secret = priv->secrets->pdata[i];
NMSecretAgentSimpleSecret *secret = priv->secrets->pdata[i];
g_free (secret->value);
g_object_get (priv->entries->pdata[i], "text", &secret->value, NULL);
@ -143,7 +143,7 @@ nmt_password_dialog_constructed (GObject *object)
secret_grid = NMT_NEWT_GRID (widget);
for (i = 0; i < priv->secrets->len; i++) {
NmtSecretAgentSecret *secret = priv->secrets->pdata[i];
NMSecretAgentSimpleSecret *secret = priv->secrets->pdata[i];
NmtNewtEntryFlags flags;
widget = nmt_newt_label_new (secret->name);
@ -258,7 +258,7 @@ nmt_password_dialog_class_init (NmtPasswordDialogClass *dialog_class)
/**
* NmtPasswordDialog:request-id:
*
* The request ID from the #NmtSecretAgent
* The request ID from the #NMSecretAgentSimple
*/
g_object_class_install_property
(object_class, PROP_REQUEST_ID,
@ -284,7 +284,7 @@ nmt_password_dialog_class_init (NmtPasswordDialogClass *dialog_class)
*
* The array of request secrets
*
* Element-Type: #NmtSecretAgentSecret.
* Element-Type: #NMSecretAgentSimpleSecret.
*/
g_object_class_install_property
(object_class, PROP_SECRETS,

View file

@ -77,21 +77,15 @@ save_routes_and_exit (NmtNewtButton *button,
{
NmtRouteEditor *editor = user_data;
NmtRouteEditorPrivate *priv = NMT_ROUTE_EDITOR_GET_PRIVATE (editor);
const char *property;
GBinding *binding;
GPtrArray *routes;
if (NM_IS_SETTING_IP4_CONFIG (priv->edit_setting))
property = NM_SETTING_IP4_CONFIG_ROUTES;
else
property = NM_SETTING_IP6_CONFIG_ROUTES;
/* Because of the complicated dbus-glib GTypes, it's easier to cheat
* and use GBinding to do this than it is to copy the value by hand.
*/
binding = g_object_bind_property (priv->edit_setting, property,
priv->orig_setting, property,
G_BINDING_SYNC_CREATE);
g_object_unref (binding);
g_object_get (priv->edit_setting,
NM_SETTING_IP_CONFIG_ROUTES, &routes,
NULL);
g_object_set (priv->orig_setting,
NM_SETTING_IP_CONFIG_ROUTES, routes,
NULL);
g_ptr_array_unref (routes);
nmt_newt_form_quit (NMT_NEWT_FORM (editor));
}
@ -106,17 +100,13 @@ nmt_route_editor_constructed (GObject *object)
if (G_OBJECT_CLASS (nmt_route_editor_parent_class)->constructed)
G_OBJECT_CLASS (nmt_route_editor_parent_class)->constructed (object);
if (NM_IS_SETTING_IP4_CONFIG (priv->edit_setting)) {
if (NM_IS_SETTING_IP4_CONFIG (priv->edit_setting))
routes = nmt_route_table_new (AF_INET);
g_object_bind_property (priv->edit_setting, NM_SETTING_IP4_CONFIG_ROUTES,
routes, "ip4-routes",
G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
} else {
else
routes = nmt_route_table_new (AF_INET6);
g_object_bind_property (priv->edit_setting, NM_SETTING_IP6_CONFIG_ROUTES,
routes, "ip6-routes",
G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
}
g_object_bind_property (priv->edit_setting, NM_SETTING_IP_CONFIG_ROUTES,
routes, "routes",
G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
vbox = nmt_newt_grid_new ();
nmt_newt_grid_add (NMT_NEWT_GRID (vbox), routes, 0, 0);

View file

@ -49,8 +49,7 @@ typedef struct {
int family;
int ip_entry_width, metric_entry_width;
NMIP4Route *ip4_route;
NMIP6Route *ip6_route;
NMIPRoute *route;
} NmtRouteEntryPrivate;
enum {
@ -58,8 +57,7 @@ enum {
PROP_FAMILY,
PROP_IP_ENTRY_WIDTH,
PROP_METRIC_ENTRY_WIDTH,
PROP_IP4_ROUTE,
PROP_IP6_ROUTE,
PROP_ROUTE,
LAST_PROP
};
@ -143,20 +141,12 @@ nmt_route_entry_constructed (GObject *object)
nmt_newt_grid_add (grid, priv->metric, 4, 0);
nmt_newt_widget_set_padding (priv->metric, 1, 0, 0, 0);
if (priv->family == AF_INET) {
nm_editor_bind_ip4_route_to_strings (object, "ip4-route",
priv->dest, "text",
priv->next_hop, "text",
priv->metric, "text",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
} else if (priv->family == AF_INET6) {
nm_editor_bind_ip6_route_to_strings (object, "ip6-route",
priv->dest, "text",
priv->next_hop, "text",
priv->metric, "text",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
} else
g_assert_not_reached ();
nm_editor_bind_ip_route_to_strings (priv->family,
object, "route",
priv->dest, "text",
priv->next_hop, "text",
priv->metric, "text",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
G_OBJECT_CLASS (nmt_route_entry_parent_class)->constructed (object);
}
@ -174,8 +164,7 @@ nmt_route_entry_finalize (GObject *object)
{
NmtRouteEntryPrivate *priv = NMT_ROUTE_ENTRY_GET_PRIVATE (object);
g_clear_pointer (&priv->ip4_route, nm_ip4_route_unref);
g_clear_pointer (&priv->ip6_route, nm_ip6_route_unref);
g_clear_pointer (&priv->route, nm_ip_route_unref);
G_OBJECT_CLASS (nmt_route_entry_parent_class)->finalize (object);
}
@ -198,17 +187,10 @@ nmt_route_entry_set_property (GObject *object,
case PROP_METRIC_ENTRY_WIDTH:
priv->metric_entry_width = g_value_get_int (value);
break;
case PROP_IP4_ROUTE:
g_return_if_fail (priv->family == AF_INET);
if (priv->ip4_route)
nm_ip4_route_unref (priv->ip4_route);
priv->ip4_route = g_value_dup_boxed (value);
break;
case PROP_IP6_ROUTE:
g_return_if_fail (priv->family == AF_INET6);
if (priv->ip6_route)
nm_ip6_route_unref (priv->ip6_route);
priv->ip6_route = g_value_dup_boxed (value);
case PROP_ROUTE:
if (priv->route)
nm_ip_route_unref (priv->route);
priv->route = g_value_dup_boxed (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -234,13 +216,8 @@ nmt_route_entry_get_property (GObject *object,
case PROP_METRIC_ENTRY_WIDTH:
g_value_set_int (value, priv->metric_entry_width);
break;
case PROP_IP4_ROUTE:
g_return_if_fail (priv->family == AF_INET);
g_value_set_boxed (value, priv->ip4_route);
break;
case PROP_IP6_ROUTE:
g_return_if_fail (priv->family == AF_INET6);
g_value_set_boxed (value, priv->ip6_route);
case PROP_ROUTE:
g_value_set_boxed (value, priv->route);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -301,27 +278,14 @@ nmt_route_entry_class_init (NmtRouteEntryClass *entry_class)
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
/**
* NmtRouteEntry:ip4-route:
* NmtRouteEntry:route:
*
* The contents of the entries, as an #NMIP4Route. Only valid
* if #NmtRouteEntry:family is %AF_INET.
* The contents of the entries, as an #NMIPRoute.
*/
g_object_class_install_property
(object_class, PROP_IP4_ROUTE,
g_param_spec_boxed ("ip4-route", "", "",
nm_ip4_route_get_type (),
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
/**
* NmtRouteEntry:ip6-route:
*
* The contents of the entries, as an #NMIP6Route. Only valid
* if #NmtRouteEntry:family is %AF_INET6.
*/
g_object_class_install_property
(object_class, PROP_IP6_ROUTE,
g_param_spec_boxed ("ip6-route", "", "",
nm_ip6_route_get_type (),
(object_class, PROP_ROUTE,
g_param_spec_boxed ("route", "", "",
nm_ip_route_get_type (),
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
}

View file

@ -54,8 +54,7 @@ typedef struct {
enum {
PROP_0,
PROP_FAMILY,
PROP_IP4_ROUTES,
PROP_IP6_ROUTES,
PROP_ROUTES,
LAST_PROP
};
@ -85,7 +84,7 @@ route_list_transform_to_route (GBinding *binding,
NmtRouteTable *table = NMT_ROUTE_TABLE (g_binding_get_source (binding));
NmtRouteTablePrivate *priv = NMT_ROUTE_TABLE_GET_PRIVATE (table);
int n = GPOINTER_TO_INT (user_data);
gpointer route;
NMIPRoute *route;
if (n >= priv->routes->len)
return FALSE;
@ -105,24 +104,17 @@ route_list_transform_from_route (GBinding *binding,
NmtRouteTablePrivate *priv = NMT_ROUTE_TABLE_GET_PRIVATE (table);
int n = GPOINTER_TO_INT (user_data);
GPtrArray *routes;
gpointer route;
NMIPRoute *route;
if (n >= priv->routes->len)
return FALSE;
route = priv->routes->pdata[n];
routes = priv->routes;
if (priv->family == AF_INET)
priv->routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip4_route_unref);
else
priv->routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip6_route_unref);
priv->routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_route_unref);
if (route) {
if (priv->family == AF_INET)
nm_ip4_route_unref (route);
else if (priv->family == AF_INET6)
nm_ip6_route_unref (route);
}
if (route)
nm_ip_route_unref (route);
routes->pdata[n] = g_value_dup_boxed (source_value);
g_value_take_boxed (target_value, routes);
@ -141,21 +133,12 @@ create_route_entry (NmtWidgetList *list,
priv->ip_entry_width,
priv->metric_entry_width);
if (priv->family == AF_INET) {
g_object_bind_property_full (table, "ip4-routes",
entry, "ip4-route",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE,
route_list_transform_to_route,
route_list_transform_from_route,
GINT_TO_POINTER (num), NULL);
} else {
g_object_bind_property_full (table, "ip6-routes",
entry, "ip6-route",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE,
route_list_transform_to_route,
route_list_transform_from_route,
GINT_TO_POINTER (num), NULL);
}
g_object_bind_property_full (table, "routes",
entry, "route",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE,
route_list_transform_to_route,
route_list_transform_from_route,
GINT_TO_POINTER (num), NULL);
return entry;
}
@ -164,24 +147,15 @@ add_route (NmtWidgetList *list,
gpointer table)
{
NmtRouteTablePrivate *priv = NMT_ROUTE_TABLE_GET_PRIVATE (table);
NMIPRoute *route;
if (priv->family == AF_INET) {
NMIP4Route *route;
route = nm_ip4_route_new ();
nm_ip4_route_set_prefix (route, 32);
g_ptr_array_add (priv->routes, route);
nmt_widget_list_set_length (list, priv->routes->len);
g_object_notify (table, "ip4-routes");
} else {
NMIP6Route *route;
route = nm_ip6_route_new ();
nm_ip6_route_set_prefix (route, 128);
g_ptr_array_add (priv->routes, route);
nmt_widget_list_set_length (list, priv->routes->len);
g_object_notify (table, "ip6-routes");
}
if (priv->family == AF_INET)
route = nm_ip_route_new (AF_INET, "0.0.0.0", 32, NULL, 0, NULL);
else
route = nm_ip_route_new (AF_INET6, "::", 128, NULL, 0, NULL);
g_ptr_array_add (priv->routes, route);
nmt_widget_list_set_length (list, priv->routes->len);
g_object_notify (table, "routes");
}
static void
@ -190,7 +164,7 @@ remove_route (NmtWidgetList *list,
gpointer table)
{
NmtRouteTablePrivate *priv = NMT_ROUTE_TABLE_GET_PRIVATE (table);
gpointer route;
NMIPRoute *route;
if (num >= priv->routes->len)
return;
@ -199,10 +173,7 @@ remove_route (NmtWidgetList *list,
g_ptr_array_remove_index (priv->routes, num);
nmt_widget_list_set_length (list, priv->routes->len);
if (priv->family == AF_INET)
g_object_notify (table, "ip4-routes");
else
g_object_notify (table, "ip6-routes");
g_object_notify (table, "routes");
}
static void
@ -214,6 +185,8 @@ nmt_route_table_init (NmtRouteTable *table)
int dest_prefix_width, next_hop_width, metric_width;
char *text;
priv->routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip_route_unref);
header = nmt_newt_grid_new ();
text = g_strdup_printf ("%s/%s", _("Destination"), _("Prefix"));
@ -283,27 +256,12 @@ nmt_route_table_set_property (GObject *object,
switch (prop_id) {
case PROP_FAMILY:
priv->family = g_value_get_int (value);
if (priv->family == AF_INET)
priv->routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip4_route_unref);
else
priv->routes = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_ip6_route_unref);
break;
case PROP_IP4_ROUTES:
g_return_if_fail (priv->family == AF_INET);
case PROP_ROUTES:
array = g_value_get_boxed (value);
g_ptr_array_set_size (priv->routes, 0);
for (i = 0; i < array->len; i++) {
nm_ip4_route_ref (array->pdata[i]);
g_ptr_array_add (priv->routes, array->pdata[i]);
}
nmt_widget_list_set_length (NMT_WIDGET_LIST (priv->list), priv->routes->len);
break;
case PROP_IP6_ROUTES:
g_return_if_fail (priv->family == AF_INET6);
array = g_value_get_boxed (value);
g_ptr_array_set_size (priv->routes, 0);
for (i = 0; i < array->len; i++) {
nm_ip6_route_ref (array->pdata[i]);
nm_ip_route_ref (array->pdata[i]);
g_ptr_array_add (priv->routes, array->pdata[i]);
}
nmt_widget_list_set_length (NMT_WIDGET_LIST (priv->list), priv->routes->len);
@ -326,12 +284,7 @@ nmt_route_table_get_property (GObject *object,
case PROP_FAMILY:
g_value_set_int (value, priv->family);
break;
case PROP_IP4_ROUTES:
g_return_if_fail (priv->family == AF_INET);
g_value_set_boxed (value, priv->routes);
break;
case PROP_IP6_ROUTES:
g_return_if_fail (priv->family == AF_INET6);
case PROP_ROUTES:
g_value_set_boxed (value, priv->routes);
break;
default:
@ -365,34 +318,16 @@ nmt_route_table_class_init (NmtRouteTableClass *table_class)
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
/**
* NmtRouteTable:ip4-routes:
* NmtRouteTable:routes:
*
* The array of routes, suitable for binding to
* #NMSettingIP4Config:routes.
* The array of routes, suitable for binding to #NMSettingIP4Config:routes
* or #NMSettingIP6Config:routes.
*
* Only valid if #NmtRouteTable:family is %AF_INET
*
* Element-type: NMIP4Route
* Element-type: NMIPRoute
*/
g_object_class_install_property
(object_class, PROP_IP4_ROUTES,
g_param_spec_boxed ("ip4-routes", "", "",
G_TYPE_PTR_ARRAY,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
/**
* NmtRouteTable:ip6-routes:
*
* The array of routes, suitable for binding to
* #NMSettingIP6Config:routes.
*
* Only valid if #NmtRouteTable:family is %AF_INET6
*
* Element-type: NMIP6Route
*/
g_object_class_install_property
(object_class, PROP_IP6_ROUTES,
g_param_spec_boxed ("ip6-routes", "", "",
(object_class, PROP_ROUTES,
g_param_spec_boxed ("routes", "", "",
G_TYPE_PTR_ARRAY,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));

View file

@ -1,57 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
* 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, see <http://www.gnu.org/licenses/>.
*
* Copyright 2013 Red Hat, Inc.
*/
#ifndef NMT_SECRET_AGENT_H
#define NMT_SECRET_AGENT_H
#include <NetworkManager.h>
G_BEGIN_DECLS
#define NMT_TYPE_SECRET_AGENT (nmt_secret_agent_get_type ())
#define NMT_SECRET_AGENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMT_TYPE_SECRET_AGENT, NmtSecretAgent))
#define NMT_SECRET_AGENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMT_TYPE_SECRET_AGENT, NmtSecretAgentClass))
#define NMT_IS_SECRET_AGENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMT_TYPE_SECRET_AGENT))
#define NMT_IS_SECRET_AGENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMT_TYPE_SECRET_AGENT))
#define NMT_SECRET_AGENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMT_TYPE_SECRET_AGENT, NmtSecretAgentClass))
typedef struct {
NMSecretAgent parent;
} NmtSecretAgent;
typedef struct {
NMSecretAgentClass parent;
} NmtSecretAgentClass;
typedef struct {
char *name, *value;
gboolean password;
} NmtSecretAgentSecret;
GType nmt_secret_agent_get_type (void);
NMSecretAgent *nmt_secret_agent_new (void);
void nmt_secret_agent_response (NmtSecretAgent *self,
const char *request_id,
GPtrArray *secrets);
G_END_DECLS
#endif /* NMT_SECRET_AGENT_H */

View file

@ -36,16 +36,16 @@
#include "nmtui-connect.h"
#include "nmt-connect-connection-list.h"
#include "nmt-password-dialog.h"
#include "nmt-secret-agent.h"
#include "nm-secret-agent-simple.h"
#include "nmt-utils.h"
static void
secrets_requested (NmtSecretAgent *agent,
const char *request_id,
const char *title,
const char *msg,
GPtrArray *secrets,
gpointer user_data)
secrets_requested (NMSecretAgentSimple *agent,
const char *request_id,
const char *title,
const char *msg,
GPtrArray *secrets,
gpointer user_data)
{
NmtNewtForm *form;
@ -53,9 +53,9 @@ secrets_requested (NmtSecretAgent *agent,
nmt_newt_form_run_sync (form);
if (nmt_password_dialog_succeeded (NMT_PASSWORD_DIALOG (form)))
nmt_secret_agent_response (agent, request_id, secrets);
nm_secret_agent_simple_response (agent, request_id, secrets);
else
nmt_secret_agent_response (agent, request_id, NULL);
nm_secret_agent_simple_response (agent, request_id, NULL);
g_object_unref (form);
}
@ -132,7 +132,7 @@ activate_connection (NMConnection *connection,
NMObject *specific_object)
{
NmtNewtForm *form;
NMSecretAgent *agent;
NMSecretAgentOld *agent;
NmtNewtWidget *label;
NmtSyncOp op;
const char *specific_object_path;
@ -145,8 +145,14 @@ activate_connection (NMConnection *connection,
label = nmt_newt_label_new (_("Connecting..."));
nmt_newt_form_set_content (form, label);
agent = nmt_secret_agent_new ();
g_signal_connect (agent, "request-secrets", G_CALLBACK (secrets_requested), NULL);
agent = nm_secret_agent_simple_new ("nmtui");
if (agent) {
if (connection) {
nm_secret_agent_simple_enable (NM_SECRET_AGENT_SIMPLE (agent),
nm_object_get_path (NM_OBJECT (connection)));
}
g_signal_connect (agent, "request-secrets", G_CALLBACK (secrets_requested), NULL);
}
specific_object_path = specific_object ? nm_object_get_path (specific_object) : NULL;
@ -182,6 +188,14 @@ activate_connection (NMConnection *connection,
goto done;
}
if (!connection) {
connection = NM_CONNECTION (nm_active_connection_get_connection (ac));
if (connection) {
nm_secret_agent_simple_enable (NM_SECRET_AGENT_SIMPLE (agent),
nm_object_get_path (NM_OBJECT (connection)));
}
}
/* Now wait for the connection to actually reach the ACTIVATED state,
* allowing the user to cancel if it takes too long.
*/
@ -206,7 +220,7 @@ activate_connection (NMConnection *connection,
nmt_newt_form_quit (form);
g_object_unref (form);
nm_secret_agent_unregister (agent, NULL, NULL);
nm_secret_agent_old_unregister (agent, NULL, NULL);
g_object_unref (agent);
}

View file

@ -463,7 +463,7 @@ connection_deleted_callback (GObject *connection,
ConnectionDeleteData *data = user_data;
GError *error = NULL;
if (!nm_remote_connection_delete_finish (data->connection, result, NULL)) {
if (!nm_remote_connection_delete_finish (data->connection, result, &error)) {
nmt_newt_message_dialog (_("Unable to delete connection: %s"),
error->message);
} else
@ -515,7 +515,8 @@ remove_one_connection (NMRemoteConnection *connection)
void
nmt_remove_connection (NMRemoteConnection *connection)
{
const GPtrArray *conns;
const GPtrArray *all_conns;
GSList *slaves, *iter;
int i;
NMRemoteConnection *slave;
NMSettingConnection *s_con;
@ -535,16 +536,22 @@ nmt_remove_connection (NMRemoteConnection *connection)
uuid = nm_connection_get_uuid (NM_CONNECTION (connection));
iface = nm_connection_get_interface_name (NM_CONNECTION (connection));
conns = nm_client_get_connections (nm_client);
for (i = 0; i < conns->len; i++) {
slave = conns->pdata[i];
all_conns = nm_client_get_connections (nm_client);
slaves = NULL;
for (i = 0; i < all_conns->len; i++) {
slave = all_conns->pdata[i];
s_con = nm_connection_get_setting_connection (NM_CONNECTION (slave));
master = nm_setting_connection_get_master (s_con);
if (master) {
if (!g_strcmp0 (master, uuid) || !g_strcmp0 (master, iface))
remove_one_connection (slave);
slaves = g_slist_prepend (slaves, g_object_ref (slave));
}
}
for (iter = slaves; iter; iter = iter->next)
remove_one_connection (iter->data);
g_slist_free_full (slaves, g_object_unref);
g_object_unref (connection);
}

View file

@ -28,6 +28,8 @@
* FIXME.
*/
#include "config.h"
#include <string.h>
#include <glib.h>
#include <gmodule.h>

View file

@ -1,12 +1,11 @@
AC_PREREQ([2.63])
dnl The NM version number
m4_define([nm_major_version], [0])
m4_define([nm_minor_version], [9])
m4_define([nm_micro_version], [11])
m4_define([nm_nano_version], [0])
m4_define([nm_major_version], [1])
m4_define([nm_minor_version], [1])
m4_define([nm_micro_version], [0])
m4_define([nm_version],
[nm_major_version.nm_minor_version.nm_micro_version.nm_nano_version])
[nm_major_version.nm_minor_version.nm_micro_version])
m4_define([nm_git_sha], [m4_esyscmd([ ( [ -d ./.git/ ] && [ "$(readlink -f ./.git/)" = "$(readlink -f "$(git rev-parse --git-dir 2>/dev/null)" 2>/dev/null)" ] && git rev-parse --verify -q HEAD 2>/dev/null ) || true ])])
AC_INIT([NetworkManager], [nm_version],
@ -60,6 +59,7 @@ AC_SUBST(NM_MAJOR_VERSION)
AC_SUBST(NM_MINOR_VERSION)
AC_SUBST(NM_MICRO_VERSION)
AC_SUBST(NM_VERSION)
AC_DEFINE_UNQUOTED(NM_GIT_SHA,"$NM_GIT_SHA",[git commit id of the original source code version])
dnl
dnl Checks for typedefs, structures, and compiler characteristics.
@ -145,11 +145,26 @@ if ! test x"$ac_distver" = x""; then
AC_DEFINE_UNQUOTED(NM_DIST_VERSION, "$ac_distver", [Define the distribution version string])
fi
AC_ARG_ENABLE(wifi, AS_HELP_STRING([--enable-wifi], [enable Wi-Fi support]))
if test "${enable_wifi}" != "no"; then
enable_wifi='yes'
AC_DEFINE(WITH_WIFI, 1, [Define if you have Wi-Fi support])
else
AC_DEFINE(WITH_WIFI, 0, [Define if you have Wi-Fi support])
fi
AM_CONDITIONAL(WITH_WIFI, test "${enable_wifi}" = "yes")
dnl
dnl Default to using WEXT but allow it to be disabled
dnl
AC_ARG_WITH(wext, AS_HELP_STRING([--with-wext=yes], [Enable or disable Linux Wireless Extensions]), ac_with_wext=$withval, ac_with_wext="yes")
AC_ARG_WITH(wext, AS_HELP_STRING([--with-wext=yes], [Enable or disable Linux Wireless Extensions]), ac_with_wext=$withval, ac_with_wext="$enable_wifi")
if test "$ac_with_wext" != 'no'; then
ac_with_wext='yes'
fi
if test x"$ac_with_wext" = x"yes"; then
if test "$enable_wifi" != "yes"; then
AC_MSG_ERROR(Enabling WEXT support and disabling Wi-Fi makes no sense)
fi
AC_MSG_CHECKING([Linux kernel WEXT headers])
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
@ -193,20 +208,24 @@ if test "$ac_have_nl80211" = no; then
AC_MSG_ERROR(Linux kernel development header linux/nl80211.h not installed or not functional)
fi
AC_MSG_CHECKING([Linux kernel nl80211 Critical Protocol Start/Stop])
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[[#ifndef __user
#define __user
#endif
#include <sys/types.h>
#include <linux/types.h>
#include <sys/socket.h>
#include <linux/nl80211.h>]],
[[unsigned int a = NL80211_CMD_CRIT_PROTOCOL_START; a++;]])],
[ac_have_nl80211_critproto=yes],
[ac_have_nl80211_critproto=no])
AC_MSG_RESULT($ac_have_nl80211_critproto)
if test "$with_wifi" = "yes"; then
AC_MSG_CHECKING([Linux kernel nl80211 Critical Protocol Start/Stop])
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[[#ifndef __user
#define __user
#endif
#include <sys/types.h>
#include <linux/types.h>
#include <sys/socket.h>
#include <linux/nl80211.h>]],
[[unsigned int a = NL80211_CMD_CRIT_PROTOCOL_START; a++;]])],
[ac_have_nl80211_critproto=yes],
[ac_have_nl80211_critproto=no])
AC_MSG_RESULT($ac_have_nl80211_critproto)
else
ac_have_nl80211_critproto='no'
fi
if test "$ac_have_nl80211_critproto" = yes; then
AC_DEFINE(HAVE_NL80211_CRITICAL_PROTOCOL_CMDS, 1, [Define if nl80211 has critical protocol support])
else
@ -302,7 +321,7 @@ AM_CONDITIONAL(WITH_QT, test "${enable_qt}" = "yes")
AC_ARG_WITH(udev-dir, AS_HELP_STRING([--with-udev-dir=DIR], [Absolute path of the udev base directory. Set to 'no' not to install the udev rules]), [], [with_udev_dir="yes"])
if (test "$with_udev_dir" != 'no'); then
if (test "$with_udev_dir" != 'yes' && echo -n "$with_udev_dir" | grep -v -q '^/'); then
if (test "$with_udev_dir" != 'yes' && printf '%s' "$with_udev_dir" | grep -v -q '^/'); then
AC_MSG_ERROR([--with-udev-dir must be an absolute path or 'yes' or 'no'. Instead it is '$with_udev_dir'])
fi
if (test "$with_udev_dir" = 'yes'); then
@ -332,30 +351,40 @@ fi
PKG_CHECK_MODULES(SYSTEMD_200, [systemd >= 200], [have_systemd_200=yes],[have_systemd_200=no])
AM_CONDITIONAL(HAVE_SYSTEMD_200, test "${have_systemd_200}" = "yes")
# session tracking support
AC_MSG_CHECKING([Session tracking support])
# Session tracking support
AC_ARG_WITH(systemd-logind, AS_HELP_STRING([--with-systemd-logind=yes|no],
[Support systemd session tracking]))
AC_ARG_WITH(consolekit, AS_HELP_STRING([--with-consolekit=yes|no],
[Support consolekit session tracking]))
AC_ARG_WITH(session-tracking, AS_HELP_STRING([--with-session-tracking=systemd|consolekit|no],
[Select session tracking support (default: consolekit)]))
# default to consolekit
AS_IF([test -z "$with_session_tracking"], with_session_tracking=consolekit)
AS_IF([test "$with_session_tracking" = "ck"], with_session_tracking=consolekit)
AS_IF([test "$with_session_tracking" = "none"], with_session_tracking=no)
# check value
AS_IF([! (echo "$with_session_tracking" | grep -q -E "^(systemd|consolekit|no)$")],
AC_MSG_ERROR([--with-session-tracking must be systemd/consolekit/no, not $with_session_tracking]))
# add conditionals and subtitutions
AM_CONDITIONAL(SESSION_TRACKING_CK, test "$with_session_tracking" = "consolekit")
AM_CONDITIONAL(SESSION_TRACKING_SYSTEMD, test "$with_session_tracking" = "systemd")
if test "$with_session_tracking" = "systemd"; then
PKG_CHECK_MODULES(SYSTEMD_LOGIN, [libsystemd],,
[PKG_CHECK_MODULES(SYSTEMD_LOGIN, [libsystemd-login])])
[Compatibility option to choose one session tracking module]))
# backwards compatibility
AS_IF([test "$with_session_tracking" = "ck"], [use_consolekit="yes" use_systemd_logind="no"])
AS_IF([test "$with_session_tracking" = "consolekit"], [use_consolekit="yes" use_systemd_logind="no"])
AS_IF([test "$with_session_tracking" = "systemd"], [use_consolekit="no" use_systemd_logind="yes"])
AS_IF([test "$with_session_tracking" = "no"], [use_consolekit="no" use_systemd_logind="no"])
AS_IF([test "$with_session_tracking" = "none"], [use_consolekit="no" use_systemd_logind="no"])
# current options
AS_IF([test -n "$with_systemd_logind" ], [use_systemd_logind="$with_systemd_logind"])
AS_IF([test -n "$with_consolekit" ], [use_consolekit="$with_consolekit"])
# defaults
AS_IF([test -z "$use_systemd_logind"], [use_systemd_logind="yes"])
AS_IF([test -z "$use_consolekit"], [use_consolekit="yes"])
# output
session_tracking=
if test "$use_systemd_logind" = "yes"; then
PKG_CHECK_MODULES(SYSTEMD_LOGIN, [libsystemd-login])
AC_SUBST(SYSTEMD_LOGIN_CFLAGS)
AC_SUBST(SYSTEMD_LOGIN_LIBS)
AC_DEFINE([SESSION_TRACKING_SYSTEMD], 1, [Define to 1 if libsystemd-login is available])
session_tracking="$session_tracking, systemd-logind"
fi
if test "$with_session_tracking" = "consolekit"; then
AC_SUBST(CKDB_PATH, /var/run/ConsoleKit/database)
if test "$use_consolekit" = "yes"; then
AC_DEFINE([SESSION_TRACKING_CONSOLEKIT], 1, [Define to 1 if ConsoleKit is available])
AC_DEFINE([CKDB_PATH], "/var/run/ConsoleKit/database", [Path to ConsoleKit database])
session_tracking="$session_tracking, consolekit"
fi
AC_MSG_RESULT($with_session_tracking)
session_tracking="$(printf '%s' "${session_tracking}" | sed 's/^, //')"
AC_ARG_WITH(suspend-resume, AS_HELP_STRING([--with-suspend-resume=upower|systemd], [Build NetworkManager with specific suspend/resume support]))
if test "z$with_suspend_resume" = "z"; then
@ -419,10 +448,21 @@ AC_COMPILE_IFELSE(
#endif
#include <linux/if_link.h>]],
[[int a = IN6_ADDR_GEN_MODE_EUI64; a++;]])],
[ac_have_kernel_gen_mode="1"],
[ac_have_kernel_gen_mode="0"])
AC_DEFINE_UNQUOTED(HAVE_KERNEL_INET6_ADDR_GEN_MODE,
$ac_have_kernel_gen_mode, [Define if the kernel has IN6_ADDR_GEN_MODE_*])
[ac_have_kernel_gen_mode=yes],
[ac_have_kernel_gen_mode=no])
AC_MSG_RESULT($ac_have_kernel_gen_mode)
if test "$ac_have_kernel_gen_mode" = yes; then
AC_DEFINE(HAVE_KERNEL_INET6_ADDR_GEN_MODE, 1, [Define if the kernel has IN6_ADDR_GEN_MODE_*])
else
AC_DEFINE(HAVE_KERNEL_INET6_ADDR_GEN_MODE, 0, [Define if the kernel has IN6_ADDR_GEN_MODE_*])
fi
# IPv6 tokenized identifiers support in libnl
AC_CHECK_LIB([nl-route-3], [rtnl_link_inet6_get_token],
ac_have_ipv6_token="1",
ac_have_ipv6_token="0")
AC_DEFINE_UNQUOTED(HAVE_LIBNL_INET6_TOKEN,
$ac_have_ipv6_token, [Define if libnl has rtnl_link_inet6_get_token()])
# uuid library
PKG_CHECK_MODULES(UUID, uuid)
@ -498,6 +538,22 @@ else
fi
AC_SUBST(NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT)
PKG_CHECK_MODULES(POLKIT, [polkit-agent-1 >= 0.97], [have_pk_agent=yes],[have_pk_agent=no])
AC_ARG_ENABLE(polkit-agent, AS_HELP_STRING([--enable-polkit-agent], [enable polkit agent for clients]),
[enable_polkit_agent=${enableval}], [enable_polkit_agent=${have_pk_agent}])
if (test "${enable_polkit_agent}" = "yes"); then
if test x"$have_pk_agent" = x"no"; then
AC_MSG_ERROR(Polkit agent is required)
fi
AC_SUBST(POLKIT_CFLAGS)
AC_SUBST(POLKIT_LIBS)
AC_DEFINE(WITH_POLKIT_AGENT, 1, [Define if you have polkit agent])
else
AC_DEFINE(WITH_POLKIT_AGENT, 0, [Define if you have polkit agent])
fi
AM_CONDITIONAL(WITH_POLKIT_AGENT, test "${enable_polkit_agent}" = "yes")
AC_ARG_ENABLE(modify-system,
AS_HELP_STRING([--enable-modify-system], [Allow users to modify system connections]))
if test "${enable_modify_system}" = "yes"; then
@ -642,7 +698,7 @@ if (test "${enable_bluez5_dun}" = "yes"); then
fi
AC_DEFINE(WITH_BLUEZ5_DUN, 1, [Define if you have Bluez 5 libraries])
else
AC_DEFINE(HAVE_BLUEZ5_DUN, 0, [Define if you have Bluez 5 libraries])
AC_DEFINE(WITH_BLUEZ5_DUN, 0, [Define if you have Bluez 5 libraries])
fi
AM_CONDITIONAL(WITH_BLUEZ5_DUN, test "${enable_bluez5_dun}" = "yes")
@ -665,10 +721,10 @@ fi
if test "$with_dhcpcd" = "yes"; then
AC_PATH_PROGS(with_dhcpcd, dhcpcd, no, /sbin:/usr/sbin:/usr/local/sbin)
if test "$with_dhcpcd" != "no"; then
if ! $with_dhcpcd --version 2>&1 | grep -q "^dhcpcd [[456789]]\."; then
if ! $with_dhcpcd --version 2>&1 | grep -q "^dhcpcd [456789]\."; then
AC_MSG_WARN([Cannot use dhcpcd, version 4.x or higher is required])
with_dhcpcd=no
elif $with_dhcpcd --version 2>&1 | grep -q "^dhcpcd [[6789]]\."; then
elif $with_dhcpcd --version 2>&1 | grep -q "^dhcpcd [6789]\."; then
AC_DEFINE(DHCPCD_SUPPORTS_IPV6, 1, [Define if dhcpcd supports IPv6 (6.x+)])
fi
fi
@ -801,6 +857,14 @@ AM_CONDITIONAL(BUILD_NMTUI, test "$build_nmtui" = yes)
NM_COMPILER_WARNINGS
AC_ARG_ENABLE(lto, AS_HELP_STRING([--enable-lto], [Enable Link Time Optimization for smaller size (default: no)]))
if (test "${enable_lto}" = "yes"); then
CFLAGS="-flto $CFLAGS"
else
enable_lto='no'
fi
dnl -------------------------
dnl Vala bindings
dnl -------------------------
@ -809,13 +873,13 @@ VAPIGEN_CHECK(0.17.1.24)
# Tests, utilities and documentation
AC_ARG_ENABLE(tests, AS_HELP_STRING([--enable-tests=root|yes|no], [Build NetworkManager tests (default: yes)]))
AC_ARG_WITH(valgrind, AS_HELP_STRING([--with-valgrind=yes|no|path], [Use valgrind to memory-check the tests (default: yes)]))
AC_ARG_WITH(valgrind, AS_HELP_STRING([--with-valgrind=yes|no|path], [Use valgrind to memory-check the tests (default: no)]))
# Fallback to --with-tests
AC_ARG_WITH(tests, AS_HELP_STRING([--with-tests], [Build NetworkManager tests (deprecated)]))
AS_IF([test -n "$with_tests"], enable_tests="$with_tests")
# Default to --enable-tests --with-valgrind
# Default to --enable-tests --with-valgrind=no
AS_IF([test -z "$enable_tests"], enable_tests="yes")
AS_IF([test -z "$with_valgrind"], with_valgrind="yes")
AS_IF([test -z "$with_valgrind"], with_valgrind="no")
# Normalize values
AS_IF([test "$enable_tests" != "yes" -a "$enable_tests" != "root"], enable_tests="no")
# Search for tools
@ -827,6 +891,7 @@ AM_CONDITIONAL(REQUIRE_ROOT_TESTS, test "$enable_tests" == "root")
AS_IF([test "$with_valgrind" != "no"],
AC_SUBST(VALGRIND_RULES, 'TESTS_ENVIRONMENT = "$(top_srcdir)/tools/run-test-valgrind.sh" "$(LIBTOOL)" "$(with_valgrind)" "$(top_srcdir)/valgrind.suppressions"'),
AC_SUBST(VALGRIND_RULES, []))
AM_CONDITIONAL(WITH_VALGRIND, test "${with_valgrind}" != "no")
GTK_DOC_CHECK(1.0)
@ -877,7 +942,7 @@ if test "$build_setting_docs" != "yes" \
-a -f man/nm-settings-keyfile.xml \
-a -f man/nm-settings-ifcfg-rh.xml \
-a -f docs/api/settings-spec.xml \
-a -f cli/src/settings-docs.c; then
-a -f clients/cli/settings-docs.c; then
AC_DEFINE(HAVE_SETTING_DOCS, [1], [Define if you have pre-built settings docs])
have_setting_docs=yes
fi
@ -933,7 +998,6 @@ libnm-util/libnm-util.pc
libnm-util/nm-version.h
libnm-util/Makefile
libnm-util/tests/Makefile
libnm-util/tests/certs/Makefile
libnm-glib/libnm-glib.pc
libnm-glib/libnm-glib-vpn.pc
libnm-glib/Makefile
@ -959,6 +1023,7 @@ man/NetworkManager.conf.xml
man/nm-system-settings.conf.5
man/nm-online.1
man/nmcli.1
man/nmtui.1
po/Makefile.in
policy/Makefile
policy/org.freedesktop.NetworkManager.policy.in
@ -979,6 +1044,8 @@ examples/python/Makefile
examples/python/dbus/Makefile
examples/python/gi/Makefile
examples/ruby/Makefile
examples/lua/Makefile
examples/lua/lgi/Makefile
examples/C/Makefile
examples/C/glib/Makefile
examples/C/qt/Makefile
@ -1002,7 +1069,7 @@ echo " nmrundir: $nmrundir"
echo
echo "Platform:"
echo " session tracking: $with_session_tracking"
echo " session tracking: $session_tracking"
echo " suspend/resume: $with_suspend_resume"
if test "${enable_polkit}" = "yes"; then
if test "${enable_modify_system}" = "yes"; then
@ -1013,11 +1080,13 @@ if test "${enable_polkit}" = "yes"; then
else
echo " policykit: no"
fi
echo " polkit agent: ${enable_polkit_agent}"
echo " selinux: $have_selinux"
echo
echo "Features:"
echo " wext: $ac_with_wext"
echo " wifi: $enable_wifi"
echo " wimax: $enable_wimax"
echo " ppp: $enable_ppp"
echo " modemmanager-1: $with_modem_manager_1"
@ -1049,4 +1118,5 @@ echo " documentation: $enable_gtk_doc"
echo " tests: $enable_tests"
echo " valgrind: $with_valgrind"
echo " code coverage: $enable_code_coverage"
echo " LTO: $enable_lto"
echo

View file

@ -0,0 +1,45 @@
# A list of packages useful/needed to build and develop
# NetworkManager on Fedora and RHEL.
#
# Not all of these packages are available, depending
# on your distribution/release. But yum will happily
# skip them.
#
# Not all of these packages are strictly speaking necessary.
# This is a generous list of related packages.
yum install \
git \
bzip2 \
intltool \
bash-completion \
cscope \
gtk-doc \
libnl3-devel \
libndp-devel \
libtool \
autopoint \
gettext-devel \
dbus-devel \
dbus-glib-devel \
libgudev1-devel \
libuuid-devel \
nss-devel \
ppp-devel \
valgrind \
systemd-devel \
ModemManager-devel \
ModemManager-glib-devel \
newt-devel \
vala-devel \
vala-tools \
dbus-x11 \
wireless-tools-devel \
polkit-devel \
wimax-devel \
libsoup-devel \
readline-devel \
teamd-devel \
rpm-build \
perl-YAML-LibYAM \

View file

@ -0,0 +1,11 @@
# This file enables the standalone 'iBFT' settings plugin to read
# iBFT information with iscsiadm and create connections from that
# data.
#
# Do not edit this file; it will be overwritten on upgrades. If you
# want to override the values here, or set additional values, you can
# do so by adding another file (eg, "99-local.conf") to this directory
# and setting keys there.
[main]
plugins+=ibft

View file

@ -58,19 +58,14 @@
%global with_wwan 1
%endif
%ifarch s390 s390x
# No hardware-based plugins on s390
%global with_adsl 0
%global with_bluetooth 0
%global with_wifi 0
%global with_wimax 0
%global with_wwan 0
%endif
%if (0%{?fedora} && 0%{?fedora} <= 19)
%global with_team 0
%endif
%define with_modem_manager_1 0
%if 0%{?with_bluetooth} || (0%{?with_wwan} && (0%{?rhel} || (0%{?fedora} && 0%{?fedora} > 19)))
%define with_modem_manager_1 1
%endif
%global _hardened_build 1
@ -88,7 +83,8 @@ URL: http://www.gnome.org/projects/NetworkManager/
Source: __SOURCE1__
Source1: NetworkManager.conf
Source2: 00-server.conf
Source3: 20-connectivity-fedora.conf
Source3: 10-ibft-plugin.conf
Source4: 20-connectivity-fedora.conf
#Patch1: 0001-some.patch
@ -160,7 +156,7 @@ BuildRequires: wimax-devel
BuildRequires: systemd >= 200-3 systemd-devel
BuildRequires: libsoup-devel
BuildRequires: libndp-devel >= 1.0
%if 0%{?with_bluetooth} || (0%{?with_wwan} && (0%{?rhel} || (0%{?fedora} && 0%{?fedora} > 19)))
%if 0%{?with_modem_manager_1}
BuildRequires: ModemManager-glib-devel >= 1.0
%endif
%if 0%{?with_nmtui}
@ -169,6 +165,8 @@ BuildRequires: newt-devel
BuildRequires: /usr/bin/dbus-launch
BuildRequires: pygobject3-base
BuildRequires: dbus-python
BuildRequires: libselinux-devel
BuildRequires: polkit-devel
%description
@ -218,6 +216,8 @@ Group: System Environment/Base
BuildRequires: teamd-devel
Requires: %{name}%{?_isa} = %{epoch}:%{version}-%{release}
Obsoletes: NetworkManager < %{obsoletes_nmver}
# Team was split from main NM binary between 0.9.10 and 1.0
Obsoletes: NetworkManager < 1.0.0
%description team
This package contains NetworkManager support for team devices.
@ -306,8 +306,6 @@ NetworkManager API. See also NetworkManager-libnm-devel.
%package libnm
Summary: Libraries for adding NetworkManager support to applications (new API).
Group: Development/Libraries
Requires: dbus >= %{dbus_version}
Requires: dbus-glib >= %{dbus_glib_version}
%description libnm
This package contains the libraries that make it easier to use some NetworkManager
@ -322,7 +320,6 @@ Requires: %{name}-devel%{?_isa} = %{epoch}:%{version}-%{release}
Requires: %{name}-libnm%{?_isa} = %{epoch}:%{version}-%{release}
Requires: glib2-devel
Requires: pkgconfig
Requires: dbus-glib-devel >= %{dbus_glib_version}
%description libnm-devel
This package contains the header and pkg-config files for development applications using
@ -387,11 +384,16 @@ by nm-connection-editor and nm-applet in a non-graphical environment.
--with-crypto=nss \
--enable-more-warnings=error \
--enable-ppp=yes \
%if 0%{?rhel} || (0%{?fedora} > 19)
%if 0%{?with_modem_manager_1}
--with-modem-manager-1=yes \
%else
--with-modem-manager-1=no \
%endif
%if 0%{?with_wifi}
--enable-wifi=yes \
%else
--enable-wifi=no \
%endif
%if 0%{?with_wimax}
--enable-wimax=yes \
%else
@ -413,7 +415,9 @@ by nm-connection-editor and nm-applet in a non-graphical environment.
%else
--enable-teamdctl=no \
%endif
--with-selinux=yes \
--enable-polkit=yes \
--enable-polkit-agent \
--enable-modify-system=yes \
--enable-concheck \
--with-session-tracking=systemd \
@ -442,6 +446,7 @@ make install DESTDIR=$RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/%{name}/conf.d
%{__cp} %{SOURCE2} $RPM_BUILD_ROOT%{_sysconfdir}/%{name}/conf.d
%{__cp} %{SOURCE3} $RPM_BUILD_ROOT%{_sysconfdir}/%{name}/conf.d
%{__cp} %{SOURCE4} $RPM_BUILD_ROOT%{_sysconfdir}/%{name}/conf.d
# create a VPN directory
%{__mkdir_p} $RPM_BUILD_ROOT%{_sysconfdir}/NetworkManager/VPN
@ -452,6 +457,13 @@ mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/%{name}/conf.d
# create a dnsmasq.d directory
%{__mkdir_p} $RPM_BUILD_ROOT%{_sysconfdir}/NetworkManager/dnsmasq.d
# create dispatcher directories
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/%{name}/dispatcher.d
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/%{name}/dispatcher.d/pre-up.d
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/%{name}/dispatcher.d/pre-down.d
%{__cp} examples/dispatcher/10-ifcfg-rh-routes.sh $RPM_BUILD_ROOT%{_sysconfdir}/%{name}/dispatcher.d/
%{__ln_s} ../10-ifcfg-rh-routes.sh $RPM_BUILD_ROOT%{_sysconfdir}/%{name}/dispatcher.d/pre-up.d/
%{__mkdir_p} $RPM_BUILD_ROOT%{_datadir}/gnome-vpn-properties
%{__mkdir_p} $RPM_BUILD_ROOT%{_localstatedir}/lib/NetworkManager
@ -509,8 +521,10 @@ fi
%{_datadir}/bash-completion/completions/nmcli
%dir %{_sysconfdir}/%{name}/
%dir %{_sysconfdir}/%{name}/dispatcher.d
%{_sysconfdir}/%{name}/dispatcher.d/10-ifcfg-rh-routes.sh
%dir %{_sysconfdir}/%{name}/dispatcher.d/pre-down.d
%dir %{_sysconfdir}/%{name}/dispatcher.d/pre-up.d
%{_sysconfdir}/%{name}/dispatcher.d/pre-up.d/10-ifcfg-rh-routes.sh
%dir %{_sysconfdir}/%{name}/dnsmasq.d
%dir %{_sysconfdir}/%{name}/VPN
%config(noreplace) %{_sysconfdir}/%{name}/NetworkManager.conf
@ -518,8 +532,13 @@ fi
%{_libexecdir}/nm-dhcp-helper
%{_libexecdir}/nm-avahi-autoipd.action
%{_libexecdir}/nm-dispatcher
%{_libexecdir}/nm-iface-helper
%dir %{_libdir}/NetworkManager
%{_libdir}/NetworkManager/libnm-settings-plugin*.so
%if 0%{?with_nmtui}
%exclude %{_mandir}/man1/nmtui*
%endif
%config %{_sysconfdir}/%{name}/conf.d/10-ibft-plugin.conf
%{_mandir}/man1/*
%{_mandir}/man5/*
%{_mandir}/man8/*
@ -542,6 +561,8 @@ fi
%files adsl
%defattr(-,root,root,0755)
%{_libdir}/%{name}/libnm-device-plugin-adsl.so
%else
%exclude %{_libdir}/%{name}/libnm-device-plugin-adsl.so
%endif
%if 0%{?with_bluetooth}
@ -650,6 +671,7 @@ fi
%{_bindir}/nmtui-edit
%{_bindir}/nmtui-connect
%{_bindir}/nmtui-hostname
%{_mandir}/man1/nmtui*
%endif
%changelog

View file

@ -24,14 +24,14 @@ abs_path() {
}
get_version() {
local major minor micro nano
local major minor micro
local F="${1:-"$GITDIR/configure.ac"}"
vars="$(sed -n 's/^m4_define(\[nm_\(major\|minor\|micro\|nano\)_version\], *\[\([0-9]\+\)\]) *$/local \1='\''\2'\''/p' "$F" 2>/dev/null)"
vars="$(sed -n 's/^m4_define(\[nm_\(major\|minor\|micro\)_version\], *\[\([0-9]\+\)\]) *$/local \1='\''\2'\''/p' "$F" 2>/dev/null)"
eval "$vars"
[[ -n "$major" && -n "$minor" && "$micro" && "$nano" ]] || return 1
echo "$major.$minor.$micro.$nano"
[[ -n "$major" && -n "$minor" && "$micro" ]] || return 1
echo "$major.$minor.$micro"
}
write_changelog() {
@ -73,6 +73,7 @@ SOURCE="$(abs_path "$SOURCE" "$(ls -1 "$GITDIR/NetworkManager-$VERSION"*.tar* 2>
[[ -f "$SOURCE" ]] || die "could not find source ${_SOURCE:-$GITDIR/NetworkManager-$VERSION*.tar*} . Did you execute \`make dist\`? Otherwise set \$SOURCE variable"
SOURCE_NETWORKMANAGER_CONF="$(abs_path "$SOURCE_NETWORKMANAGER_CONF" "$SCRIPTDIR/NetworkManager.conf")"
SOURCE_CONFIG_SERVER="$(abs_path "$SOURCE_CONFIG_SERVER" "$SCRIPTDIR/00-server.conf")"
SOURCE_CONFIG_IBFT_PLUGIN="$(abs_path "$SOURCE_CONFIG_IBFT_PLUGIN" "$SCRIPTDIR/10-ibft-plugin.conf")"
SOURCE_CONFIG_CONNECTIVITY_FEDORA="$(abs_path "$SOURCE_CONFIG_CONNECTIVITY_FEDORA" "$SCRIPTDIR/20-connectivity-fedora.conf")"
TEMP="$(mktemp -d "$SCRIPTDIR/NetworkManager.$DATE.XXXXXX")"
@ -87,6 +88,7 @@ LOG "SPECFILE=$SPECFILE"
LOG "SOURCE=$SOURCE"
LOG "SOURCE_NETWORKMANAGER_CONF=$SOURCE_NETWORKMANAGER_CONF"
LOG "SOURCE_CONFIG_SERVER=$SOURCE_CONFIG_SERVER"
LOG "SOURCE_CONFIG_IBFT_PLUGIN=$SOURCE_CONFIG_IBFT_PLUGIN"
LOG "SOURCE_CONFIG_CONNECTIVITY_FEDORA=$SOURCE_CONFIG_CONNECTIVITY_FEDORA"
LOG "BASEDIR=$TEMP"
@ -100,6 +102,7 @@ mkdir -p "$TEMP/SOURCES/" "$TEMP/SPECS/" || die "error creating SPECS directoy"
cp "$SOURCE" "$TEMP/SOURCES/" || die "Could not copy source $SOURCE to $TEMP/SOURCES"
cp "$SOURCE_NETWORKMANAGER_CONF" "$TEMP/SOURCES/NetworkManager.conf" || die "Could not copy source $SOURCE_NETWORKMANAGER_CONF to $TEMP/SOURCES"
cp "$SOURCE_CONFIG_SERVER" "$TEMP/SOURCES/00-server.conf" || die "Could not copy source $SOURCE_CONFIG_SERVER to $TEMP/SOURCES"
cp "$SOURCE_CONFIG_IBFT_PLUGIN" "$TEMP/SOURCES/10-ibft-plugin.conf" || die "Could not copy source $SOURCE_CONFIG_IBFT_PLUGIN to $TEMP/SOURCES"
cp "$SOURCE_CONFIG_CONNECTIVITY_FEDORA" "$TEMP/SOURCES/20-connectivity-fedora.conf" || die "Could not copy source $SOURCE_CONFIG_CONNECTIVITY_FEDORA to $TEMP/SOURCES"
write_changelog
@ -116,7 +119,16 @@ sed -e "/^__CHANGELOG__$/ \
d
}" > "$TEMPSPEC" || die "Error reading spec file"
rpmbuild --define "_topdir $TEMP" -ba "$TEMPSPEC" || die "ERROR: rpmbuild FAILED"
case "$BUILDTYPE" in
"SRPM")
RPM_BUILD_OPTION=-bs
;;
*)
RPM_BUILD_OPTION=-ba
;;
esac
rpmbuild --define "_topdir $TEMP" $RPM_BUILD_OPTION "$TEMPSPEC" || die "ERROR: rpmbuild FAILED"
ln -snf "$TEMPBASE" ./latest
TEMP_LATEST="$(readlink -f .)"/latest
@ -128,6 +140,6 @@ LOG
LOG "See \"$TEMP_LATEST/\" which symlinks to \"$TEMPBASE\""
LOG
LOG "Result:"
ls -dla "$TEMP_LATEST" "$(dirname "$TEMP_LATEST")/$TEMPBASE/" "$TEMP_LATEST"/RPMS/*/ "$TEMP_LATEST"/RPMS/*/*.rpm "$TEMP_LATEST"/SRPMS/ "$TEMP_LATEST"/SRPMS/*.rpm | sed 's/^/ /'
ls -dla "$TEMP_LATEST" "$(dirname "$TEMP_LATEST")/$TEMPBASE/" "$TEMP_LATEST"/RPMS/*/ "$TEMP_LATEST"/RPMS/*/*.rpm "$TEMP_LATEST"/SRPMS/ "$TEMP_LATEST"/SRPMS/*.rpm 2>/dev/null | sed 's/^/ /'

View file

@ -15,6 +15,7 @@ usage() {
echo " --force: force build, even if working directory is not clean and has local modifications"
echo " --clean: run \`git-clean -fdx :/\` before build"
echo " --quick: only run \`make dist\` instead of \`make distcheck\`"
echo " --srpm: only build the SRPM"
}
@ -46,6 +47,9 @@ for A; do
-Q|--quick)
QUICK=1
;;
-S|--srpm)
BUILDTYPE=SRPM
;;
*)
usage
die "Unexpected argument \"$A\""
@ -61,7 +65,7 @@ if [[ $IGNORE_DIRTY != 1 ]]; then
# check for a clean working directory.
# We ignore the /contrib directory, because this is where the automation
# scripts and the build results will be.
if [[ "x$(LANG=C git clean -ndx | grep '^Would remove contrib/.*$' -v)" != x ]]; then
if [[ "x$(LANG=C git clean -ndx | grep '^Would \(remove contrib/\|skip repository libgsystem/\).*$' -v)" != x ]]; then
die "The working directory is not clean. Refuse to run. Try \`$0 --force\`, \`$0 --clean\`, or \`git clean -e :/contrib -dx -n\`"
fi
if [[ "x$(git status --porcelain)" != x ]]; then
@ -84,5 +88,7 @@ else
make distcheck || die "Error make distcheck"
fi
export BUILDTYPE
"$SCRIPTDIR"/build.sh

View file

@ -7,6 +7,7 @@ Before=network.target @DISTRO_NETWORK_SERVICE@
Type=dbus
BusName=org.freedesktop.NetworkManager
ExecStart=@sbindir@/NetworkManager --no-daemon
Restart=on-failure
# NM doesn't want systemd to kill its children for it
KillMode=process

View file

@ -15,7 +15,7 @@ GENERATED_FILES = spec.html
if SETTING_DOCS_AVAILABLE
settings-spec.xml: settings-spec.xsl $(top_builddir)/libnm-util/nm-setting-docs.xml
settings-spec.xml: settings-spec.xsl $(top_builddir)/libnm/nm-setting-docs.xml
$(AM_V_GEN) xsltproc --output $@ $^
# Top-level SGML file includes (depends on) settings-spec.xml
@ -59,6 +59,7 @@ MKHTML_OPTIONS=--path="$(abs_srcdir)"
content_files = \
version.xml \
migrating-to-09.xml \
../../COPYING \
$(NULL)
include $(top_srcdir)/gtk-doc.make
@ -70,5 +71,10 @@ CLEANFILES += html/* tmpl/* xml/* \
NetworkManager-sections.txt \
NetworkManager-overrides.txt
DISTCLEANFILES = $(GENERATED_FILES)
if BUILD_SETTING_DOCS
CLEANFILES += settings-spec.xml
endif
if ENABLE_GTK_DOC
CLEANFILES += spec.html
endif

View file

@ -42,7 +42,7 @@
<entry><screen><xsl:value-of select="@name"/></screen></entry>
<entry><screen><xsl:value-of select="@type"/></screen></entry>
<entry><screen><xsl:value-of select="@default"/></screen></entry>
<entry><xsl:value-of select="@description"/><xsl:if test="contains(@name,'-flags') and $setting_name != 'dcb'"> (see <xref linkend="secrets-flags"/> for flag values)</xsl:if></entry>
<entry><xsl:value-of select="@description"/><xsl:if test="@type = 'NMSettingSecretFlags'"> (see <xref linkend="secrets-flags"/> for flag values)</xsl:if></entry>
</row>
</xsl:template>

View file

@ -30,6 +30,7 @@ CFILE_GLOB=$(top_srcdir)/libnm-glib/*.c
# Header files to ignore when scanning.
IGNORE_HFILES= \
common.h \
nm-dbus-helpers-private.h \
nm-device-private.h \
nm-object-cache.h \

Some files were not shown because too many files have changed in this diff Show more