core icon indicating copy to clipboard operation
core copied to clipboard

Scanning directory via SMB does not properly resolve symlinks, thus allowing loops.

Open mickg10 opened this issue 12 years ago • 12 comments

In reality: sources/xfsprogs-2.10.2/include/disk is a symlink to '.'.

Including that results in: [13:37:51.069] now scanning /mickg/files/Disk_Q/sources/xfsprogs-2.10.2/include/disk/disk/disk/disk/disk/xfs/xfs/disk/disk/disk/disk/disk/xfs/xfs/disk/disk/disk/xfs/disk

/mickg/files/Disk_Q is a smb-share.

Mike

mickg10 avatar Jun 10 '14 17:06 mickg10

Is that SMB share on a linux machine or did you use NTFS symlinks ?

PVince81 avatar Jun 11 '14 08:06 PVince81

As far as I know there is no protection against symlink recursion as ownCloud does not support symlinks in general. It means that the file scanner needs to be improved to be aware of possible loops.

CC @icewind1991

PVince81 avatar Jun 11 '14 08:06 PVince81

I don't think there is a general solution to detect symlinks loops, on linux with local filesystem we could probably use the inode number exposed by stat() but that wont work for external storages that include symlinks

icewind1991 avatar Jun 11 '14 13:06 icewind1991

Add a release note about the use of Symlinks not being supported, and the danger of infinite loops.

MTRichards avatar Sep 04 '14 21:09 MTRichards

Wouldn't a rather simple workaround to the looping issue be to just not follow any symlinks to directories? More fine-grained handling could be added later...

h-2 avatar Dec 28 '14 11:12 h-2

Add a release note about the use of Symlinks not being supported, and the danger of infinite loops.

should be added to the documentation @carlaschroder

DeepDiver1975 avatar Jan 07 '15 11:01 DeepDiver1975

Wouldn't a rather simple workaround to the looping issue be to just not follow any symlinks to directories?

In case we can easily detect symlinks - this might work out - anyway moving this to OC8.1

DeepDiver1975 avatar Jan 07 '15 11:01 DeepDiver1975

In case we can easily detect symlinks - this might work out

http://php.net/manual/en/function.is-link.php

DeepDiver1975 avatar Jan 07 '15 11:01 DeepDiver1975

added to 8.0 release notes

carlaschroder avatar Jan 28 '15 22:01 carlaschroder

@jvillafanez is there an easy way to prevent following symlinks ?

PVince81 avatar Sep 20 '16 10:09 PVince81

From the SMB point of view, and taking into account that we're moving to use the native library, the link detection in SMB is unreliable right now.

php > print_r(smbclient_stat($a, 'smb://10.0.2.6/tmp/simlink'));
Array
(
    [0] => -1734054622
    [1] => 1070907291
    [2] => 16877
    [3] => 2
    [4] => 1001
    [5] => 1001
    [6] => 0
    [7] => 0
    [8] => 1474372606
    [9] => 1474372606
    [10] => 1474372606
    [11] => 512
    [12] => 0
    [dev] => -1734054622
    [ino] => 1070907291
    [mode] => 16877
    [nlink] => 2
    [uid] => 1001
    [gid] => 1001
    [rdev] => 0
    [size] => 0
    [atime] => 1474372606
    [mtime] => 1474372606
    [ctime] => 1474372606
    [blksize] => 512
    [blocks] => 0
)
php > echo decoct(16877 & octdec('0170000')) . "\n";
40000

According to http://man7.org/linux/man-pages/man2/stat.2.html that would mean "simlink" is a directory, but it's in fact a link to a directory.

On the other hand, the CLI can detect this using a "stat" call, but parsing and extracting that information will be messy, and probably not a good idea if something important is going to rely on this.

I might be using an outdated library version, but I haven't seen changes in the library regarding this.

jvillafanez avatar Sep 20 '16 12:09 jvillafanez

Moving this to enhancement as it's a design challenge which doesn't have a proper easy solution. And symlinks are calling for this behaviour ...

hodyroff avatar Dec 12 '16 09:12 hodyroff