summaryrefslogtreecommitdiff
path: root/libnm-core/nm-keyfile.c
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-10-02 19:53:54 +0200
committerThomas Haller <thaller@redhat.com>2018-10-04 11:03:23 +0200
commit837d44ffa4bfb3ef1a1cd786336dcd2415e9259b (patch)
tree4c12eb78ac82500476b2c31673465065bfbe620e /libnm-core/nm-keyfile.c
parent02c8844178380c5f4cc1c6aa971f90cfea2be0dc (diff)
downloadNetworkManager-837d44ffa4bfb3ef1a1cd786336dcd2415e9259b.tar.gz
keyfile: split automatically setting ID/UUID for keyfile
keyfile already supports omitting the "connection.id" and "connection.uuid". In that case, the ID would be taken from the keyfile's name, and the UUID was generated by md5 hashing the full filename. No longer do this during nm_keyfile_read(), instead let all callers call nm_keyfile_read_ensure_*() to their liking. This is done for two reasons: - a minor reason is, that one day we want to expose keyfile API as public API. That means, we also want to read keyfiles from stdin, where there is no filename available. The implementation which parses stdio needs to define their own way of auto-generating ID and UUID. Note how nm_keyfile_read()'s API no longer takes a filename as argument, which would be awkward for the stdin case. - Currently, we only support one keyfile directory, which (configurably) is "/etc/NetworkManager/system-connections". In the future, we want to support multiple keyfile dirctories, like "/var/run/NetworkManager/profiles" or "/usr/lib/NetworkManager/profiles". Here we want that a file "foo" (which does not specify a UUID) gets the same UUID regardless of the directory it is in. That seems better, because then the UUID won't change as you move the file between directories. Yes, that means, that the same UUID will be provided by multiple files, but NetworkManager must already cope with that situation anyway. Unfortunately, the UUID generation scheme hashes the full path. That means, we must hash the path name of the file "foo" inside the original "system-connections" directory. Refactor the code so that it accounds for a difference between the filename of the keyfile, and the profile_dir used for generating the UUID.
Diffstat (limited to 'libnm-core/nm-keyfile.c')
-rw-r--r--libnm-core/nm-keyfile.c38
1 files changed, 4 insertions, 34 deletions
diff --git a/libnm-core/nm-keyfile.c b/libnm-core/nm-keyfile.c
index 4de0ca415f..77c1534d53 100644
--- a/libnm-core/nm-keyfile.c
+++ b/libnm-core/nm-keyfile.c
@@ -2855,17 +2855,9 @@ nm_keyfile_read_ensure_uuid (NMConnection *connection,
/**
* 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
@@ -2877,7 +2869,6 @@ nm_keyfile_read_ensure_uuid (NMConnection *connection,
*/
NMConnection *
nm_keyfile_read (GKeyFile *keyfile,
- const char *keyfile_name,
const char *base_dir,
NMKeyfileReadHandler handler,
void *user_data,
@@ -2888,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 ();
@@ -2942,15 +2921,6 @@ nm_keyfile_read (GKeyFile *keyfile,
nm_connection_add_setting (connection, NM_SETTING (s_con));
}
- if (keyfile_name) {
- gs_free char *basename = g_path_get_basename (keyfile_name);
-
- nm_keyfile_read_ensure_id (connection, basename);
- }
-
- if (keyfile_name)
- nm_keyfile_read_ensure_uuid (connection, keyfile_name);
-
/* Make sure that we have 'interface-name' even if it was specified in the
* "wrong" (ie, deprecated) group.
*/