UnitDependency dependency,
char ***strv) {
+ _cleanup_free_ char *path = NULL;
int r;
- char *path;
assert(u);
assert(unit_path);
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;
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;
+}