Skip to content

Commit e0d13e7

Browse files
authored
Merge pull request #32830 from yuwata/home-skel
home: fix ownership of files copied from skelton directory
2 parents f0888bb + 82260fc commit e0d13e7

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/home/homework.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,12 +1059,13 @@ static int home_deactivate(UserRecord *h, bool force) {
10591059
return 0;
10601060
}
10611061

1062-
static int copy_skel(int root_fd, const char *skel) {
1062+
static int copy_skel(UserRecord *h, int root_fd, const char *skel) {
10631063
int r;
10641064

1065+
assert(h);
10651066
assert(root_fd >= 0);
10661067

1067-
r = copy_tree_at(AT_FDCWD, skel, root_fd, ".", UID_INVALID, GID_INVALID, COPY_MERGE|COPY_REPLACE, NULL, NULL);
1068+
r = copy_tree_at(AT_FDCWD, skel, root_fd, ".", h->uid, h->gid, COPY_MERGE|COPY_REPLACE, NULL, NULL);
10681069
if (r == -ENOENT) {
10691070
log_info("Skeleton directory %s missing, ignoring.", skel);
10701071
return 0;
@@ -1092,7 +1093,7 @@ int home_populate(UserRecord *h, int dir_fd) {
10921093
assert(h);
10931094
assert(dir_fd >= 0);
10941095

1095-
r = copy_skel(dir_fd, user_record_skeleton_directory(h));
1096+
r = copy_skel(h, dir_fd, user_record_skeleton_directory(h));
10961097
if (r < 0)
10971098
return r;
10981099

test/units/TEST-46-HOMED.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ systemctl service-log-level systemd-homed debug
4444
mkdir -p /home
4545
mount -t tmpfs tmpfs /home -o size=290M
4646

47+
TMP_SKEL=$(mktemp -d)
48+
echo hogehoge >"$TMP_SKEL"/hoge
49+
4750
# we enable --luks-discard= since we run our tests in a tight VM, hence don't
4851
# needlessly pressure for storage. We also set the cheapest KDF, since we don't
4952
# want to waste CI CPU cycles on it. We also effectively disable rate-limiting on
@@ -55,7 +58,8 @@ NEWPASSWORD=xEhErW0ndafV4s homectl create test-user \
5558
--luks-pbkdf-type=pbkdf2 \
5659
--luks-pbkdf-time-cost=1ms \
5760
--rate-limit-interval=1s \
58-
--rate-limit-burst=1000
61+
--rate-limit-burst=1000 \
62+
--skel="$TMP_SKEL"
5963
inspect test-user
6064

6165
PASSWORD=xEhErW0ndafV4s homectl authenticate test-user
@@ -211,6 +215,8 @@ PASSWORD=xEhErW0ndafV4s homectl with test-user -- test -f /home/test-user/xyz
211215
PASSWORD=xEhErW0ndafV4s homectl with test-user -- rm /home/test-user/xyz
212216
PASSWORD=xEhErW0ndafV4s homectl with test-user -- test ! -f /home/test-user/xyz
213217
(! PASSWORD=xEhErW0ndafV4s homectl with test-user -- test -f /home/test-user/xyz)
218+
[[ $(PASSWORD=xEhErW0ndafV4s homectl with test-user -- stat -c %U /home/test-user/hoge) == "test-user" ]]
219+
[[ $(PASSWORD=xEhErW0ndafV4s homectl with test-user -- cat /home/test-user/hoge) == "$(cat "$TMP_SKEL"/hoge)" ]]
214220

215221
# Regression tests
216222
wait_for_state test-user inactive

0 commit comments

Comments
 (0)