Directories shown as files, when sharing a mounted cifs drive

I have an issue where a directory is shown as a file when accessing a samba share ( on Ubuntu 12.10 ) from a Windows machine.

The output from ls -ll in the folder on the linuxbox is as follows:

chubby@chubby:/media/blackhole/_Arkiv$ ls -ll
total 0
drwxrwxrwx 0 jv users 0 Jun 18  2012 _20
drwxrwxrwx 0 jv users 0 Apr 17  2012 _2006
drwxrwxrwx 0 jv users 0 Apr 17  2012 _2007
drwxrwxrwx 0 jv users 0 May 12  2011 _2008
drwxrwxrwx 0 jv users 0 Feb 19 09:53 _2009
drwxrwxrwx 0 jv users 0 Dec 20  2011 _2010
drwxrwxrwx 0 jv users 0 May  8  2012 _2011
drwxrwxrwx 0 jv users 0 Mar  5 11:37 _2012
drwxrwxrwx 0 jv users 0 Feb 28 10:09 _2013
drwxrwxrwx 0 jv users 0 Feb 28 11:18 _Mailarkiv
drwxrwxrwx 0 jv users 0 Jan  3  2011 _Praktikanter

The entry in /etc/fstab is:

# Mounting blackhole
//192.168.0.50/kunder/ /media/blackhole cifs uid=jv,gid=users,credentials=/home/chubby/.smbcredentials,iocharset=utf8,file_mode=0777,dir_mode=0777 0 0

When I access the share directly from the NAS on my Windows box, there are no issues.

The version of Samba is 3.6.6, but I couldn't find anything in the changelogs that seem relevant.

I've tried mounting it in different locations with different permissions, users and groups but I have not made any progress

Due to my low reputation on serverfault ( mostly stackoverflow user ) I'm unable to post a screenshot that shows that the directories are shown as files.

If I type the full path in explorer, the directory listing works excellently, except for any subdirectories that are then shown as files.

Any attack vector for this issue would be greatly appreciated.

Please let me know if I have provided insufficient details.

Edit: The same share when accessed from a OS X, works perfectly listing the directories as directories. Best Regards!


Solution 1:

I have finally solved the problem.

I'll try to write this answer out more when I have the time.

The issue is connected to resharing a cifs filesystem, and then accessing this from a Windows7 computer.

The samba bug is here: https://bugzilla.samba.org/show_bug.cgi?id=9346

This apparently stems from the way information is set on the inode in cifs.

See bug here: https://bugzilla.kernel.org/show_bug.cgi?id=52791

So the way Samba tells determines ( for its Windows clients ) is by counting the number of hardlinks, rather than testing for the attribute. As cifs ( for some obscure reason ) always sets this to zero, where a directory always will have at least two, the directory will appear as a file for Windows clients.

So to "fix" this I installed my current kernel-headers and the linux source code:

sudo apt-get install linux-headers-$(uname -r) linux-source

I then went to /usr/src/linux-source-3.5.0 and extracted the archive there.

Finding the folder /usr/src/linux-source-3.5.0/linux-source-3.5.0/fs/cifs I change the following in the file inode.c (line 135):

set_nlink(inode, fattr->cf_nlink);

to:

if(fattr->cf_cifsattrs & ATTR_DIRECTORY)
          set_nlink(inode, 2);
        else
          set_nlink(inode, fattr->cf_nlink);

I then created a makefile to ease compilation ( and avoid annoying insmod errors ): Makefile2:

obm-m := cifs.o
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
        $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules

This allows us to do ( in the same folder ): sudo make -f Makefile2

This gives us a file called cifs.ko.

So now we can stop Samba, unmount any shares we have, remove the current cifs, and install our recompiled one.

sudo service smbd stop
sudo umount /path/to/share
sudo rmmod cifs
sudo insmod cifs.ko
sudo mount -a
sudo service smbd start

For me this did the trick, if you restart the box though, this change will not persist. I'll add to this post when I've figured out a good way to do this.

Please throw any questions or clarifications you require my way, I'll probably learn from it :)

Also thanks to kukks in #samba on freenode, I learned a lot of stuff there, though I ended up moving in another direction.