SMB shares and NFS exports may now point to any existing directory (USB disks under /mnt or /media, /srv, home folders...) instead of only ZFS dataset mountpoints. System trees (/etc, /usr, /var, /boot, /proc, /root, ...) are refused, also after resolving symlinks. The path suggestions list mounted data filesystems from /proc/self/mounts in addition to ZFS mountpoints. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -70,12 +70,13 @@ func TestValidation(t *testing.T) {
|
||||
t.Errorf("%q accepted", n)
|
||||
}
|
||||
}
|
||||
for _, p := range []string{"/nas/x", "/tmp_pool"} {
|
||||
for _, p := range []string{"/nas/x", "/tmp_pool", "/mnt/usb", "/srv/media", "/home/alice/docs", "/media/disk", "/variable", "/etcetera"} {
|
||||
if err := ValidatePath(p); err != nil {
|
||||
t.Errorf("%q rejected: %v", p, err)
|
||||
}
|
||||
}
|
||||
for _, p := range []string{"", "/", "nas/x", "/nas/../etc", "/nas/", "/nas/x\"y", "/nas/x\n"} {
|
||||
for _, p := range []string{"", "/", "nas/x", "/nas/../etc", "/nas/", "/nas/x\"y", "/nas/x\n",
|
||||
"/etc", "/etc/samba", "/var/lib/docker", "/usr", "/proc/1", "/root", "/boot/efi", "/run/user/1000"} {
|
||||
if ValidatePath(p) == nil {
|
||||
t.Errorf("%q accepted", p)
|
||||
}
|
||||
@@ -336,3 +337,27 @@ func TestUsers(t *testing.T) {
|
||||
t.Errorf("owner account deleted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseMounts(t *testing.T) {
|
||||
in := `proc /proc proc rw,nosuid 0 0
|
||||
tmpfs /run tmpfs rw 0 0
|
||||
/dev/sda2 / ext4 rw 0 0
|
||||
/dev/sda1 /boot/efi vfat rw 0 0
|
||||
tank /tank zfs rw,xattr 0 0
|
||||
tank /tank zfs rw,xattr 0 0
|
||||
/dev/sdc1 /mnt/usb\040disk ext4 rw 0 0
|
||||
overlay /srv/docker/merged overlay rw 0 0
|
||||
`
|
||||
got := strings.Join(ParseMounts(in), "|")
|
||||
if got != "/mnt/usb disk|/tank" {
|
||||
t.Errorf("ParseMounts = %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigRefusesSystemPath(t *testing.T) {
|
||||
c := Defaults()
|
||||
c.SMB.Shares = []SMBShare{{Name: "etc", Path: "/etc", Guest: true}}
|
||||
if c.Validate() == nil {
|
||||
t.Errorf("share on /etc accepted")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user