summary refs log tree commit diff
path: root/cli/src/connections.c
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2010-11-29 19:00:22 +0100
committerMichael Biebl <biebl@debian.org>2010-11-29 19:00:22 +0100
commita6b89d35fabd9f5934b84d7cde22e9268f92c3d3 (patch)
tree9e44755880d5933fcc90c6008d4585a76298a1bd /cli/src/connections.c
parent9fae01fa351805b2903e535736e06971bc0b925e (diff)
Imported Upstream version 0.8.2 upstream/0.8.2
Diffstat (limited to 'cli/src/connections.c')
-rw-r--r--cli/src/connections.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/cli/src/connections.c b/cli/src/connections.c
index e9aa597d..e0b94ceb 100644
--- a/cli/src/connections.c
+++ b/cli/src/connections.c
@@ -24,6 +24,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
+#include <unistd.h>
 #include <errno.h>
 #include <signal.h>
 #include <netinet/ether.h>
@@ -64,9 +65,10 @@ static NmcOutputField nmc_fields_con_status[] = {
 	{"DBUS-SERVICE",  N_("DBUS-SERVICE"), 45, NULL, 0},  /* 5 */
 	{"SPEC-OBJECT",   N_("SPEC-OBJECT"),  10, NULL, 0},  /* 6 */
 	{"VPN",           N_("VPN"),           5, NULL, 0},  /* 7 */
+	{"DBUS-PATH",     N_("DBUS-PATH"),    51, NULL, 0},  /* 8 */
 	{NULL,            NULL,                0, NULL, 0}
 };
-#define NMC_FIELDS_CON_STATUS_ALL     "NAME,UUID,DEVICES,SCOPE,DEFAULT,VPN,DBUS-SERVICE,SPEC-OBJECT"
+#define NMC_FIELDS_CON_STATUS_ALL     "NAME,UUID,DEVICES,SCOPE,DEFAULT,VPN,DBUS-SERVICE,DBUS-PATH,SPEC-OBJECT"
 #define NMC_FIELDS_CON_STATUS_COMMON  "NAME,UUID,DEVICES,SCOPE,DEFAULT,VPN"
 
 /* Available fields for 'con list' */
@@ -79,9 +81,10 @@ static NmcOutputField nmc_fields_con_list[] = {
 	{"TIMESTAMP-REAL",  N_("TIMESTAMP-REAL"), 34, NULL, 0},  /* 5 */
 	{"AUTOCONNECT",     N_("AUTOCONNECT"),    13, NULL, 0},  /* 6 */
 	{"READONLY",        N_("READONLY"),       10, NULL, 0},  /* 7 */
+	{"DBUS-PATH",       N_("DBUS-PATH"),      42, NULL, 0},  /* 8 */
 	{NULL,              NULL,                  0, NULL, 0}
 };
-#define NMC_FIELDS_CON_LIST_ALL     "NAME,UUID,TYPE,SCOPE,TIMESTAMP,TIMESTAMP-REAL,AUTOCONNECT,READONLY"
+#define NMC_FIELDS_CON_LIST_ALL     "NAME,UUID,TYPE,SCOPE,TIMESTAMP,TIMESTAMP-REAL,AUTOCONNECT,READONLY,DBUS-PATH"
 #define NMC_FIELDS_CON_LIST_COMMON  "NAME,UUID,TYPE,SCOPE,TIMESTAMP-REAL"
 
 
@@ -375,6 +378,7 @@ show_connection (NMConnection *data, gpointer user_data)
 		timestamp = nm_setting_connection_get_timestamp (s_con);
 		timestamp_str = g_strdup_printf ("%" G_GUINT64_FORMAT, timestamp);
 		strftime (timestamp_real_str, sizeof (timestamp_real_str), "%c", localtime ((time_t *) &timestamp));
+
 		nmc->allowed_fields[0].value = nm_setting_connection_get_id (s_con);
 		nmc->allowed_fields[1].value = nm_setting_connection_get_uuid (s_con);
 		nmc->allowed_fields[2].value = nm_setting_connection_get_connection_type (s_con);
@@ -383,6 +387,7 @@ show_connection (NMConnection *data, gpointer user_data)
 		nmc->allowed_fields[5].value = timestamp ? timestamp_real_str : _("never");
 		nmc->allowed_fields[6].value = nm_setting_connection_get_autoconnect (s_con) ? _("yes") : _("no");
 		nmc->allowed_fields[7].value = nm_setting_connection_get_read_only (s_con) ? _("yes") : _("no");
+		nmc->allowed_fields[8].value = nm_connection_get_path (connection);
 
 		nmc->print_fields.flags &= ~NMC_PF_FLAG_MAIN_HEADER_ADD & ~NMC_PF_FLAG_MAIN_HEADER_ONLY & ~NMC_PF_FLAG_FIELD_NAMES; /* Clear header flags */
 		print_fields (nmc->print_fields, nmc->allowed_fields);
@@ -603,6 +608,7 @@ show_active_connection (gpointer data, gpointer user_data)
 			info->nmc->allowed_fields[5].value = nm_active_connection_get_service_name (active);
 			info->nmc->allowed_fields[6].value = nm_active_connection_get_specific_object (active);
 			info->nmc->allowed_fields[7].value = NM_IS_VPN_CONNECTION (active) ? _("yes") : _("no");
+			info->nmc->allowed_fields[8].value = nm_object_get_path (NM_OBJECT (active));
 
 			info->nmc->print_fields.flags &= ~NMC_PF_FLAG_MAIN_HEADER_ADD & ~NMC_PF_FLAG_MAIN_HEADER_ONLY & ~NMC_PF_FLAG_FIELD_NAMES; /* Clear header flags */
 			print_fields (info->nmc->print_fields, info->nmc->allowed_fields);
@@ -711,10 +717,11 @@ check_ethernet_compatible (NMDeviceEthernet *device, NMConnection *connection, G
 	if (s_wired) {
 		const GByteArray *mac;
 		const char *device_mac_str;
-		struct ether_addr *device_mac;
+		struct ether_addr *device_mac = NULL;
 
-		device_mac_str = nm_device_ethernet_get_hw_address (device);
-		device_mac = ether_aton (device_mac_str);
+		device_mac_str = nm_device_ethernet_get_permanent_hw_address (device);
+		if (device_mac_str)
+			device_mac = ether_aton (device_mac_str);
 		if (!device_mac) {
 			g_set_error (error, 0, 0, "Invalid device MAC address.");
 			return FALSE;
@@ -760,10 +767,11 @@ check_wifi_compatible (NMDeviceWifi *device, NMConnection *connection, GError **
 	if (s_wireless) {
 		const GByteArray *mac;
 		const char *device_mac_str;
-		struct ether_addr *device_mac;
+		struct ether_addr *device_mac = NULL;
 
-		device_mac_str = nm_device_wifi_get_hw_address (device);
-		device_mac = ether_aton (device_mac_str);
+		device_mac_str = nm_device_wifi_get_permanent_hw_address (device);
+		if (device_mac_str)
+			device_mac = ether_aton (device_mac_str);
 		if (!device_mac) {
 			g_set_error (error, 0, 0, "Invalid device MAC address.");
 			return FALSE;
@@ -1288,7 +1296,7 @@ activate_connection_cb (gpointer user_data, const char *path, GError *error)
 		printf (_("Active connection state: %s\n"), active_connection_state_to_string (state));
 		printf (_("Active connection path: %s\n"), orig_path);
 
-		if (!orig_nmc->should_wait || state == NM_ACTIVE_CONNECTION_STATE_ACTIVATED) {
+		if (orig_nmc->nowait_flag || state == NM_ACTIVE_CONNECTION_STATE_ACTIVATED) {
 			/* don't want to wait or already activated */
 			quit ();
 		} else {
@@ -1415,7 +1423,10 @@ do_connection_up (NmCli *nmc, int argc, char **argv)
 		goto error;
 	}
 
-	nmc->should_wait = wait;
+	/* Use nowait_flag instead of should_wait because exitting has to be postponed till active_connection_state_cb()
+	 * is called, giving NM time to check our permissions */
+	nmc->nowait_flag = !wait;
+	nmc->should_wait = TRUE;
 	nm_client_activate_connection (nmc->client,
 	                               is_system ? NM_DBUS_SERVICE_SYSTEM_SETTINGS : NM_DBUS_SERVICE_USER_SETTINGS,
 	                               con_path,
@@ -1504,6 +1515,7 @@ do_connection_down (NmCli *nmc, int argc, char **argv)
 	else {
 		fprintf (stderr, _("Warning: Connection not active\n"));
 	}
+	sleep (1);  /* Don't quit immediatelly and give NM time to check our permissions */
 
 error:
 	nmc->should_wait = FALSE;