return 1;
}
-static int make_uid_symlinks(uid_t uid, const char *name, bool b) {
- char path1[STRLEN("/run/systemd/dynamic-uid/direct:") + DECIMAL_STR_MAX(uid_t) + 1];
- const char *path2;
- int r = 0, k;
-
- /* Add direct additional symlinks for direct lookups of dynamic UIDs and their names by userspace code. The
- * only reason we have this is because dbus-daemon cannot use D-Bus for resolving users and groups (since it
- * would be its own client then). We hence keep these world-readable symlinks in place, so that the
- * unprivileged dbus user can read the mappings when it needs them via these symlinks instead of having to go
- * via the bus. Ideally, we'd use the lock files we keep for this anyway, but we can't since we use BSD locks
- * on them and as those may be taken by any user with read access we can't make them world-readable. */
-
- xsprintf(path1, "/run/systemd/dynamic-uid/direct:" UID_FMT, uid);
- if (unlink(path1) < 0 && errno != ENOENT)
- r = -errno;
-
- if (b && symlink(name, path1) < 0) {
- k = log_warning_errno(errno, "Failed to symlink \"%s\": %m", path1);
- if (r == 0)
- r = k;
- }
-
- path2 = strjoina("/run/systemd/dynamic-uid/direct:", name);
- if (unlink(path2) < 0 && errno != ENOENT) {
- k = -errno;
- if (r == 0)
- r = k;
- }
-
- if (b && symlink(path1 + STRLEN("/run/systemd/dynamic-uid/direct:"), path2) < 0) {
- k = log_warning_errno(errno, "Failed to symlink \"%s\": %m", path2);
- if (r == 0)
- r = k;
- }
-
- return r;
-}
-
static int pick_uid(char **suggested_paths, const char *name, uid_t *ret_uid) {
/* Find a suitable free UID. We use the following strategy to find a suitable UID:
}
(void) ftruncate(lock_fd, l);
- (void) make_uid_symlinks(candidate, name, true); /* also add direct lookup symlinks */
*ret_uid = candidate;
return TAKE_FD(lock_fd);
return send_one_fd_iov(d->storage_socket[1], lock_fd, &iov, 1, MSG_DONTWAIT);
}
-static void unlink_uid_lock(int lock_fd, uid_t uid, const char *name) {
+static void unlink_uid_lock(int lock_fd, uid_t uid) {
char lock_path[STRLEN("/run/systemd/dynamic-uid/") + DECIMAL_STR_MAX(uid_t) + 1];
if (lock_fd < 0)
xsprintf(lock_path, "/run/systemd/dynamic-uid/" UID_FMT, uid);
(void) unlink(lock_path);
-
- (void) make_uid_symlinks(uid, name, false); /* remove direct lookup symlinks */
}
static int dynamic_user_realize(
/* So, we found a working UID/lock combination. Let's see if we actually still need it. */
r = posix_lock(d->storage_socket[0], LOCK_EX);
if (r < 0) {
- unlink_uid_lock(uid_lock_fd, num, d->name);
+ unlink_uid_lock(uid_lock_fd, num);
return r;
}
if (r < 0) {
if (r != -EAGAIN) {
/* OK, something bad happened, let's get rid of the bits we acquired. */
- unlink_uid_lock(uid_lock_fd, num, d->name);
+ unlink_uid_lock(uid_lock_fd, num);
return r;
}
} else {
/* Hmm, so as it appears there's now something stored in the storage socket.
* Throw away what we acquired, and use what's stored now. */
- unlink_uid_lock(uid_lock_fd, num, d->name);
+ unlink_uid_lock(uid_lock_fd, num);
safe_close(uid_lock_fd);
num = new_uid;
return r;
/* This dynamic user was realized and dynamically allocated. In this case, let's remove the lock file. */
- unlink_uid_lock(lock_fd, uid, d->name);
+ unlink_uid_lock(lock_fd, uid);
return 1;
}