chiark / gitweb /
Add function to open temp files in selinux mode
[elogind.git] / src / shared / util.c
index bef87304e6ce20958297cc91391b1dc4ef65cf11..75dc58b63db2edeceab89b3c279a53924a2094de 100644 (file)
@@ -3795,7 +3795,7 @@ bool dirent_is_file_with_suffix(const struct dirent *de, const char *suffix) {
         return endswith(de->d_name, suffix);
 }
 
-void execute_directory(const char *directory, DIR *d, usec_t timeout, char *argv[], char *env[]) {
+void execute_directory(const char *directory, DIR *d, usec_t timeout, char *argv[]) {
         pid_t executor_pid;
         int r;
 
@@ -3826,14 +3826,6 @@ void execute_directory(const char *directory, DIR *d, usec_t timeout, char *argv
 
                 assert_se(prctl(PR_SET_PDEATHSIG, SIGTERM) == 0);
 
-                if (!strv_isempty(env)) {
-                        char **i;
-
-                        STRV_FOREACH(i, env)
-                                putenv(*i);
-                }
-
-
                 if (!d) {
                         d = _d = opendir(directory);
                         if (!d) {
@@ -5427,7 +5419,7 @@ bool string_has_cc(const char *p, const char *ok) {
 
         for (t = p; *t; t++) {
                 if (ok && strchr(ok, *t))
-                        return false;
+                        continue;
 
                 if (*t > 0 && *t < ' ')
                         return true;
@@ -6823,3 +6815,43 @@ bool is_localhost(const char *hostname) {
                endswith(hostname, ".localdomain") ||
                endswith(hostname, ".localdomain.");
 }
+
+int take_password_lock(const char *root) {
+
+        struct flock flock = {
+                .l_type = F_WRLCK,
+                .l_whence = SEEK_SET,
+                .l_start = 0,
+                .l_len = 0,
+        };
+
+        const char *path;
+        int fd, r;
+
+        /* This is roughly the same as lckpwdf(), but not as awful. We
+         * don't want to use alarm() and signals, hence we implement
+         * our own trivial version of this.
+         *
+         * Note that shadow-utils also takes per-database locks in
+         * addition to lckpwdf(). However, we don't given that they
+         * are redundant as they they invoke lckpwdf() first and keep
+         * it during everything they do. The per-database locks are
+         * awfully racy, and thus we just won't do them. */
+
+        if (root)
+                path = strappenda(root, "/etc/.pwd.lock");
+        else
+                path = "/etc/.pwd.lock";
+
+        fd = open(path, O_WRONLY|O_CREAT|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW, 0600);
+        if (fd < 0)
+                return -errno;
+
+        r = fcntl(fd, F_SETLKW, &flock);
+        if (r < 0) {
+                safe_close(fd);
+                return -errno;
+        }
+
+        return fd;
+}