8

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!

1 Answer 1

7

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.

2
  • 3
    Wow, that's the kind of bug that makes me wonder "what the heck were they thinking when they wrote that?" If you want to detect an attribute, query the attribute, don't look at a loose correlate. It's like writing a method: bool isPirate() {return pegLegs == 1;}. You'll be right most of the time, but there are some significant times when you won't. Jan 27, 2014 at 22:19
  • 1
    Thanks, the patch worked for me running Ubuntu 12.04 kernel 3.11 and samba 3.6.3. Just a couple of problems I found: 1) I had to run apt-get source linux-image-$(uname -r) to get the proper sources. 2) To be able to run make succesfully I copied the fs/cifs sources folder under de headers folder with the same subpath and compiled from the root of headers with make M=fs/cifs, as explained here: http://www.debian-administration.org/article/640/Rebuilding_a_single_kernel_module
    – drodsou
    Apr 23, 2014 at 17:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .