summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2021-09-13 08:43:18 +0200
committerThomas Haller <thaller@redhat.com>2021-09-13 09:32:57 +0200
commitd4a367b482079044f4b983412e1f874f227b7171 (patch)
tree90e09162e4c31500300346decf898372c36e518a
parent60000c72c37bf57ed15fbd4ba257e29cbf980632 (diff)
downloadNetworkManager-d4a367b482079044f4b983412e1f874f227b7171.tar.gz
nmcli: make relatives path for `nmcli connection load` absolute
NetworkManager (the daemon) has no defined working directory, so it can only handle absolute path names. This is in general and also for the LoadConnections() D-Bus call. That means, nmcli should make relative paths absolute. We don't use g_canonicalize_filename() because that also cleans up double slash and "/./". I don't think we should do that in this case, we should only prepend $PWD to make the path absolute. https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/794
-rw-r--r--src/nmcli/connections.c28
1 files changed, 23 insertions, 5 deletions
diff --git a/src/nmcli/connections.c b/src/nmcli/connections.c
index e8e607ec5e..5edd33f084 100644
--- a/src/nmcli/connections.c
+++ b/src/nmcli/connections.c
@@ -9261,10 +9261,11 @@ do_connection_reload(const NMCCommand *cmd, NmCli *nmc, int argc, const char *co
static void
do_connection_load(const NMCCommand *cmd, NmCli *nmc, int argc, const char *const *argv)
{
- GError * error = NULL;
- gs_free const char **filenames = NULL;
- gs_strfreev char ** failures = NULL;
- int i;
+ GError * error = NULL;
+ gs_strfreev char **filenames = NULL;
+ gs_strfreev char **failures = NULL;
+ gs_free char * current_dir = NULL;
+ int i;
next_arg(nmc, &argc, &argv, NULL);
if (argc == 0) {
@@ -9278,7 +9279,24 @@ do_connection_load(const NMCCommand *cmd, NmCli *nmc, int argc, const char *cons
return;
}
- filenames = (const char **) nm_strv_dup(argv, argc, FALSE);
+ filenames = nm_strv_dup(argv, argc, TRUE);
+
+ current_dir = g_get_current_dir();
+ if (filenames && current_dir && current_dir[0] == '/' && current_dir[1] != '/') {
+ for (i = 0; filenames[i]; i++) {
+ char *f = filenames[i];
+
+ if (f[0] == '\0' || f[0] == '/')
+ continue;
+
+ /* Don't use g_canonicalize_filename(), because we want to keep
+ * the argv argument closely to what the user provided. We will get
+ * that path back as "failures" below, so don't perform additional
+ * normalization except prepending the $PWD. */
+ filenames[i] = g_build_filename(current_dir, f, NULL);
+ g_free(f);
+ }
+ }
nm_client_load_connections(nmc->client, (char **) filenames, &failures, NULL, &error);
if (error) {