chiark / gitweb /
conf-parser: warn when we open configuration files with weird access bits
authorLennart Poettering <lennart@poettering.net>
Mon, 3 Feb 2014 11:52:16 +0000 (12:52 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 3 Feb 2014 18:59:18 +0000 (19:59 +0100)
src/core/load-dropin.c
src/shared/conf-parser.c
src/shared/util.c
src/shared/util.h

index 35040090ac3bbe186d2d295b7b4630e76d3dc040..546e560b852c82c4bb27ff59aba793ba6ea3098d 100644 (file)
@@ -100,8 +100,8 @@ static int process_dir(
                 UnitDependency dependency,
                 char ***strv) {
 
+        _cleanup_free_ char *path = NULL;
         int r;
-        char *path;
 
         assert(u);
         assert(unit_path);
@@ -112,39 +112,29 @@ static int process_dir(
         if (!path)
                 return log_oom();
 
-        if (u->manager->unit_path_cache &&
-            !set_get(u->manager->unit_path_cache, path))
-                r = 0;
-        else
+        if (!u->manager->unit_path_cache || set_get(u->manager->unit_path_cache, path)) {
                 r = iterate_dir(u, path, dependency, strv);
-        free(path);
-
-        if (r < 0)
-                return r;
+                if (r < 0)
+                        return r;
+        }
 
         if (u->instance) {
-                char *template;
+                _cleanup_free_ char *template = NULL, *p = NULL;
                 /* Also try the template dir */
 
                 template = unit_name_template(name);
                 if (!template)
                         return log_oom();
 
-                path = strjoin(unit_path, "/", template, suffix, NULL);
-                free(template);
-
-                if (!path)
+                p = strjoin(unit_path, "/", template, suffix, NULL);
+                if (!p)
                         return log_oom();
 
-                if (u->manager->unit_path_cache &&
-                    !set_get(u->manager->unit_path_cache, path))
-                        r = 0;
-                else
-                        r = iterate_dir(u, path, dependency, strv);
-                free(path);
-
-                if (r < 0)
-                        return r;
+                if (!u->manager->unit_path_cache || set_get(u->manager->unit_path_cache, p)) {
+                        r = iterate_dir(u, p, dependency, strv);
+                        if (r < 0)
+                                return r;
+                }
         }
 
         return 0;
index df4e961ea03925c474dd86e7e1dddc2297f59385..d5a639e874a3138bfe040977f1e7fa46a1da905c 100644 (file)
@@ -332,6 +332,8 @@ int config_parse(const char *unit,
                 }
         }
 
+        fd_warn_permissions(filename, fileno(f));
+
         while (!feof(f)) {
                 char l[LINE_MAX], *p, *c = NULL, *e;
                 bool escaped = false;
index aae587243eb1d8eae70cd3591fab455133318992..f76ed6f563cf32eb2ef524e30a694e7d12e3a4dd 100644 (file)
@@ -6132,3 +6132,21 @@ int open_tmpfile(const char *path, int flags) {
         unlink(p);
         return fd;
 }
+
+int fd_warn_permissions(const char *path, int fd) {
+        struct stat st;
+
+        if (fstat(fd, &st) < 0)
+                return -errno;
+
+        if (st.st_mode & 0111)
+                log_warning("Configuration file %s is marked executable. Please remove executable permission bits. Proceeding anyway.", path);
+
+        if (st.st_mode & 0002)
+                log_warning("Configuration file %s is marked world-writable. Please remove world writability permission bits. Proceeding anyway.", path);
+
+        if (getpid() == 1 && (st.st_mode & 0044) != 0044)
+                log_warning("Configuration file %s is marked world-inaccessible. This has no effect as configuration data is accessible via APIs without restrictions. Proceeding anyway.", path);
+
+        return 0;
+}
index e4de4728bdf3b66e69464c52a83ee3913a690e01..219e4897b38bc78cc384f3a6aec1fea26e352041 100644 (file)
@@ -867,3 +867,5 @@ int writev_safe(int fd, const struct iovec *w, int j);
 
 int mkostemp_safe(char *pattern, int flags);
 int open_tmpfile(const char *path, int flags);
+
+int fd_warn_permissions(const char *path, int fd);