Skip to content

Commit 87a7b4f

Browse files
authored
Fix bug with sftp jail and username containing - (hestiacp#3941)
* Bug with / not mounting due error with systemd files when username contain - * Use double qoutes * Add test regarding sftp jail * Fix folder not created * Use mkdir -p * Improve chown
1 parent 44d9c46 commit 87a7b4f

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

bin/v-add-web-domain-ftp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,11 @@ else
8080
log_event "$E_INVALID" "$ARGUMENTS"
8181
exit "$E_INVALID"
8282
fi
83+
8384
# Creating ftp user home directory
8485
if [ ! -e "$ftp_path_a" ]; then
85-
$BIN/v-add-fs-directory "$user" "$ftp_path_a"
86-
chown $user:$user "$ftp_path_a"
86+
mkdir -p "$ftp_path_a"
87+
chown --no-dereference $user:$user "$ftp_path_a"
8788
chmod 751 "$ftp_path_a"
8889
fi
8990
fi

bin/v-change-web-domain-ftp-path

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ check_hestia_demo_mode
6565

6666
# MKDIR if path doesn't exist
6767
if [ ! -e "$ftp_path_a" ]; then
68-
$BIN/v-add-fs-directory "$user" "$ftp_path_a"
69-
chown $user:$user "$ftp_path_a"
68+
mkdir -p "$ftp_path_a"
69+
chown --no-dereference $user:$user "$ftp_path_a"
7070
chmod 751 "$ftp_path_a"
7171
fi
7272

func/main.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,7 +1726,8 @@ add_chroot_jail() {
17261726
chmod 755 /srv/jail/$user/home
17271727
fi
17281728

1729-
cat > /etc/systemd/system/srv-jail-$user-home.mount << EOF
1729+
systemd=$(systemd-escape -p --suffix=mount "/srv/jail/$user/home")
1730+
cat > "/etc/systemd/system/$systemd" << EOF
17301731
[Unit]
17311732
Description=Mount $user's home directory to the jail chroot
17321733
Before=local-fs.target
@@ -1743,16 +1744,17 @@ RequiredBy=local-fs.target
17431744
EOF
17441745

17451746
systemctl daemon-reload > /dev/null 2>&1
1746-
systemctl enable srv-jail-$user-home.mount > /dev/null 2>&1
1747-
systemctl start srv-jail-$user-home.mount > /dev/null 2>&1
1747+
systemctl enable "$systemd" > /dev/null 2>&1
1748+
systemctl start "$systemd" > /dev/null 2>&1
17481749
}
17491750

17501751
delete_chroot_jail() {
17511752
local user=$1
17521753

1753-
systemctl stop srv-jail-$user-home.mount > /dev/null 2>&1
1754-
systemctl disable srv-jail-$user-home.mount > /dev/null 2>&1
1755-
rm -f /etc/systemd/system/srv-jail-$user-home.mount
1754+
systemd=$(systemd-escape -p --suffix=mount "/srv/jail/$user/home")
1755+
systemctl stop "$systemd" > /dev/null 2>&1
1756+
systemctl disable "$systemd" > /dev/null 2>&1
1757+
rm -f "/etc/systemd/system/$systemd"
17561758
systemctl daemon-reload > /dev/null 2>&1
17571759
rmdir /srv/jail/$user/home > /dev/null 2>&1
17581760
rmdir /srv/jail/$user > /dev/null 2>&1

test/test.bats

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,8 @@ function check_ip_not_banned(){
415415

416416
run stat -c '%U' /home/$user
417417
assert_output --partial "$user"
418+
mount_file=$(systemd-escape -p --suffix=mount "/srv/jail/$user/home")
419+
assert_file_not_exist /etc/systemd/system/$mount_file
418420
}
419421

420422
@test "User: Change user invalid shell" {
@@ -430,6 +432,8 @@ function check_ip_not_banned(){
430432

431433
run stat -c '%U' /home/$user
432434
assert_output --partial 'root'
435+
mount_file=$(systemd-escape -p --suffix=mount "/srv/jail/$user/home")
436+
assert_file_exist /etc/systemd/system/$mount_file
433437
}
434438

435439

0 commit comments

Comments
 (0)