Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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!

share|improve this question
add comment

2 Answers

up vote 7 down vote accepted

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.

share|improve this answer
1  
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. –  Kennet Belenky Jan 27 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_mod‌​ule –  drodsou Apr 23 at 17:04
add comment

I am also seeing this error, but my setup is like this: Window->Linux->Windows. basically I have a share on Windows that I am sharing out to the Linux box and I am accessing the Linux box from another Windows machine just browsing. Folders native to Linux show up just fine but the mounted folder that is pointing to the other Windows share have folders show up as a 0byte files.

I'm starting to think it's the way Windows interpret the info being sent from the SMB server?

share|improve this answer
    
This may be better as a comment –  Dave M Apr 15 '13 at 20:40
    
That is the exact issue and setup I was having, so you might be able to follow the same "solution" that I presented, but it is kind of a technical solution. –  Johan Sigfred Abildskov Oct 14 '13 at 15:05
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.