about summary refs log tree commit diff
path: root/libnm-core/nm-keyfile.c
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2018-10-20 01:31:18 +0200
committerMichael Biebl <biebl@debian.org>2018-10-20 01:31:18 +0200
commitb4885f208ba690090952c0ae0452dd5bc2ba0601 (patch)
tree5c8af02da4543f7132b9bad45711a3a65e620d0d /libnm-core/nm-keyfile.c
parent142485af41b7cf7b0060cc682a56d3ff38cabbb6 (diff)
parent6518e361171f64bcaaa4bf868139362ed95cc2e0 (diff)
Update upstream source from tag 'upstream/1.14.2'
Update to upstream version '1.14.2'
with Debian dir c118292f450ace1133a5dba2777cbeb54977dbe8
Diffstat (limited to 'libnm-core/nm-keyfile.c')
-rw-r--r--libnm-core/nm-keyfile.c87
1 files changed, 44 insertions, 43 deletions
diff --git a/libnm-core/nm-keyfile.c b/libnm-core/nm-keyfile.c
index c7d87869..e4ed1899 100644
--- a/libnm-core/nm-keyfile.c
+++ b/libnm-core/nm-keyfile.c
@@ -2812,20 +2812,52 @@ read_vpn_secrets (KeyfileReaderInfo *info, NMSettingVpn *s_vpn)
 	}
 }
 
+gboolean
+nm_keyfile_read_ensure_id (NMConnection *connection,
+                           const char *fallback_id)
+{
+	NMSettingConnection *s_con;
+
+	g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);
+	g_return_val_if_fail (fallback_id, FALSE);
+
+	s_con = nm_connection_get_setting_connection (connection);
+	g_return_val_if_fail (NM_IS_SETTING_CONNECTION (s_con), FALSE);
+
+	if (nm_setting_connection_get_id (s_con))
+		return FALSE;
+
+	g_object_set (s_con, NM_SETTING_CONNECTION_ID, fallback_id, NULL);
+	return TRUE;
+}
+
+gboolean
+nm_keyfile_read_ensure_uuid (NMConnection *connection,
+                             const char *fallback_uuid_seed)
+{
+	NMSettingConnection *s_con;
+	gs_free char *hashed_uuid = NULL;
+
+	g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);
+	g_return_val_if_fail (fallback_uuid_seed, FALSE);
+
+	s_con = nm_connection_get_setting_connection (connection);
+	g_return_val_if_fail (NM_IS_SETTING_CONNECTION (s_con), FALSE);
+
+	if (nm_setting_connection_get_uuid (s_con))
+		return FALSE;
+
+	hashed_uuid = _nm_utils_uuid_generate_from_strings ("keyfile", fallback_uuid_seed, NULL);
+	g_object_set (s_con, NM_SETTING_CONNECTION_UUID, hashed_uuid, NULL);
+	return TRUE;
+}
+
 /**
  * nm_keyfile_read:
  * @keyfile: the keyfile from which to create the connection
- * @keyfile_name: keyfile allows missing connection id and uuid
- *   and NetworkManager will create those when reading a connection
- *   from file. By providing a filename you can reproduce that behavior,
- *   but of course, it can only recreate the same UUID if you provide the
- *   same filename as NetworkManager core daemon would.
- *   @keyfile_name has only a relevance for setting the id or uuid if it
- *   is missing and as fallback for @base_dir.
  * @base_dir: when reading certificates from files with relative name,
- *   the relative path is made absolute using @base_dir.
- *   If @base_dir is missing, first try to get the pathname from @keyfile_name
- *   (if it is given as absolute path). As last, fallback to the current path.
+ *   the relative path is made absolute using @base_dir. This must
+ *   be an absolute path.
  * @handler: read handler
  * @user_data: user data for read handler
  * @error: error
@@ -2837,7 +2869,6 @@ read_vpn_secrets (KeyfileReaderInfo *info, NMSettingVpn *s_vpn)
  */
 NMConnection *
 nm_keyfile_read (GKeyFile *keyfile,
-                 const char *keyfile_name,
                  const char *base_dir,
                  NMKeyfileReadHandler handler,
                  void *user_data,
@@ -2848,25 +2879,13 @@ nm_keyfile_read (GKeyFile *keyfile,
 	NMSetting *setting;
 	char **groups;
 	gsize length;
-	int i;
+	gsize i;
 	gboolean vpn_secrets = FALSE;
 	KeyfileReaderInfo info = { 0 };
-	gs_free char *base_dir_free = NULL;
 
 	g_return_val_if_fail (keyfile, NULL);
 	g_return_val_if_fail (!error || !*error, NULL);
-
-	if (!base_dir) {
-		/* basedir is not given. Prefer it from the keyfile_name */
-		if (keyfile_name && keyfile_name[0] == '/') {
-			base_dir = base_dir_free = g_path_get_dirname (keyfile_name);
-		} else {
-			/* if keyfile is not given or not an absolute path, fallback
-			 * to current working directory. */
-			base_dir = base_dir_free = g_get_current_dir ();
-		}
-	} else
-		g_return_val_if_fail (base_dir[0] == '/', NULL);
+	g_return_val_if_fail (base_dir && base_dir[0] == '/', NULL);
 
 	connection = nm_simple_connection_new ();
 
@@ -2902,24 +2921,6 @@ nm_keyfile_read (GKeyFile *keyfile,
 		nm_connection_add_setting (connection, NM_SETTING (s_con));
 	}
 
-	/* Make sure that we have 'id' even if not explictly specified in the keyfile */
-	if (   keyfile_name
-	    && !nm_setting_connection_get_id (s_con)) {
-		gs_free char *base_name = NULL;
-
-		base_name = g_path_get_basename (keyfile_name);
-		g_object_set (s_con, NM_SETTING_CONNECTION_ID, base_name, NULL);
-	}
-
-	/* Make sure that we have 'uuid' even if not explictly specified in the keyfile */
-	if (   keyfile_name
-	    && !nm_setting_connection_get_uuid (s_con)) {
-		gs_free char *hashed_uuid = NULL;
-
-		hashed_uuid = _nm_utils_uuid_generate_from_strings ("keyfile", keyfile_name, NULL);
-		g_object_set (s_con, NM_SETTING_CONNECTION_UUID, hashed_uuid, NULL);
-	}
-
 	/* Make sure that we have 'interface-name' even if it was specified in the
 	 * "wrong" (ie, deprecated) group.
 	 */