diff options
author | Michael Marineau <michael.marineau@coreos.com> | 2014-01-31 15:35:04 -0800 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2014-02-14 00:58:00 +0100 |
commit | 112cfb181453e38d3ef4a74fba23abbb53392002 (patch) | |
tree | 29bed2d262a751a8297712f71123a5fb7e75c1b4 /src/shared/conf-files.c | |
parent | b58b227a53ee2b9feba8433a1558b51132ffb18b (diff) |
shared: include root when canonicalizing conf paths
The conf_files_list family accepts an alternate root path to prefix all
directories in the list but path_strv_canonicalize_uniq doesn't use it.
This results in the suspicious behavior of resolving directory symlinks
based on the contents of / instead of the alternate root.
This adds a prefix argument to path_strv_canonicalize which will now
prepend the prefix, if given, to every path in the list. To avoid
answering what a relative path means when called with a root prefix
path_strv_canonicalize is now path_strv_canonicalize_absolute and only
considers absolute paths. Fortunately all users of already call
path_strv_canonicalize with a list of absolute paths.
Diffstat (limited to 'src/shared/conf-files.c')
-rw-r--r-- | src/shared/conf-files.c | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/src/shared/conf-files.c b/src/shared/conf-files.c index c86bb03074..5201782183 100644 --- a/src/shared/conf-files.c +++ b/src/shared/conf-files.c @@ -37,12 +37,8 @@ #include "hashmap.h" #include "conf-files.h" -static int files_add(Hashmap *h, const char *root, const char *path, const char *suffix) { +static int files_add(Hashmap *h, const char *dirpath, const char *suffix) { _cleanup_closedir_ DIR *dir = NULL; - _cleanup_free_ char *dirpath = NULL; - - if (asprintf(&dirpath, "%s%s", root ? root : "", path) < 0) - return -ENOMEM; dir = opendir(dirpath); if (!dir) { @@ -104,7 +100,7 @@ static int conf_files_list_strv_internal(char ***strv, const char *suffix, const assert(suffix); /* This alters the dirs string array */ - if (!path_strv_canonicalize_uniq(dirs)) + if (!path_strv_canonicalize_absolute_uniq(dirs, root)) return -ENOMEM; fh = hashmap_new(string_hash_func, string_compare_func); @@ -112,7 +108,7 @@ static int conf_files_list_strv_internal(char ***strv, const char *suffix, const return -ENOMEM; STRV_FOREACH(p, dirs) { - r = files_add(fh, root, *p, suffix); + r = files_add(fh, *p, suffix); if (r == -ENOMEM) { hashmap_free_free(fh); return r; |