OpenWrt Forum Archive

Topic: How to get USB-samba share writeable?

The content of this topic has been archived on 4 May 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hi!

I have followed the usb and samba howto.

USB-Devices are mounted automatically:

/dev/root on /rom type squashfs (ro)
none on /dev type devfs (rw)
/dev/mtdblock/4 on / type jffs2 (rw)
none on /proc type proc (rw)
none on /tmp type tmpfs (rw,nosuid,nodev)
none on /dev/pts type devpts (rw)
none on /proc/bus/usb type usbfs (rw)
/dev/scsi/host0/bus0/target0/lun0/part1 on /mnt/disc0_1 type vfat (rw)
/dev/scsi/host1/bus0/target0/lun0/part1 on /mnt/disc1_1 type vfat (rw)

With ssh I can write on disc0 and disc1!

* installed samba,
* added name of my router to localhosts
* renamed /etc/init.d/samba to /etc/init.d/S50samba
* edited my smb.conf:
[global]
syslog = 0
syslog only = yes
workgroup = WORKGROUP
server string = OpenWrt
security = share
encrypt passwords = no
guest account = nobody
local master = yes
name resolve order = lmhosts hosts bcast
guest ok = yes
guest only = no
read only = no

[tmp]
comment = /tmp
path = /tmp
browseable = yes
public = yes
writeable = yes
read only = no
guest ok = yes
guest only = no

[mnt]
comment = /mnt
path = /mnt
browseable = yes
public = yes
writeable = yes
read only = no
guest ok = yes
guest only = no

[disc0_1]
comment = /mnt/disc0_1
path = /mnt/disc0_1
browseable = yes
public = yes
writeable = yes
read only = no
guest ok = yes
guest only = no

(I know "writeable = yes" and "read only = no" should be the same.
And I know that mnt and disc0_1 are "redundant". Only some more tries.)

Samba is up and running, but maybe something is still wrong.

"ps | grep mbd" delivers:

  481 root        912 S   nmbd -D
  483 root        924 S   smbd -D
  505 root       1264 S   smbd -D

There are two smb-daemons!?

From my PC I can see:
* "tmp" and write to it!
* "mnt" and only read it!
* "disc0_1" and only read it!

But I want to write to disc0_1 and still can't!

There are differences in device, mount, fs and rights for /tmp and /mnt (as you can see above from "mount") and as follows:

drwxr-xr-x    1 root   root            0 Jan  1 00:19 mnt
drwxrwxrwt    5 root     root          160 Jan  1 00:00 tmp

Why doesn't it work? What did I wrong? Can anybody tell me?

Best regards

Thorsten

Had the same problems.

1) what filesystem is the disk? Make sure user "nobody" can read it: for vfat, "mount xxx xxx -o dmask=0,fmask=0". for ntfs, "-o umask=0". for ext2/3, i dunno.
2) Yea that should do it. If you *REALLY* can't get it to work, a terrible and horribly incorrect way would be to say "guest account=root". But don't do that. Fix it the *right* way by mounting it correctly.

- Flyashi

For vfat usb devices that I share with samba, I also mount with "uid=65534,gid=65534" options, so my command looks like this:

mount -o  auto,users,umask=000,dmask=000,fmask=000,uid=65534,gid=65534 ${part} ${path}

You can edit /etc/hotplug.d/usb/01-mount to do this for you automatically.  If you do, keep in mind that anytime you update your WRT with a new firmware these changes will be lost and you'll need to re-apply them.

G

Hi!

Thanks for your helpful answers!

I found some samba configuration options "force create mode" and "force directory mode" that usually should do the job, but they don't. Perhaps they are an advanced feature of a later version, that is not present in whiterussian rc5!?

guest account = root works! ;-)

So I tried it with your other tipps.

@bluesguy: changes will only be lost if you don't use squashfs!? At least the webif seems to allow to choose how to update squashfs firmware, but I wasn't successful at all on updating with webif the last and only time.

Best regards

Thorsten

(Last edited by banane on 30 Aug 2006, 22:53)

If your device has a vfat filesystem, then the problem most likely isn't samba at all.  It's how the kernel mounts it by default. 

Look at the permission on the files (e.g. "ls -la /mnt/disc0_1") and see for yourself.

Then look at what user context samba runs in.

Put 2 and 2 together and you get a daemon that has no authority to write to the filesystem.  See the problem?

That's why my suggestion fixes the problem.  Because now you'll have a vfat filesystem that's mounted to allow samba to write to it.  Problem solved.    Guest account = root is a *VERY* bad idea.

banane wrote:

changes will only be lost if you don't use squashfs!?

Right.  I use jffs on most of my units, so any changes I make are lost when I do upgrades.

Hi bluesguy!

Of course, I already "put 2 and 2 together" before you wrote that :-)

That's what I meant with:

banane wrote:

So I tried it with your other tipps.

So I already used exactly your suggestion :-)

But if I understand correctly, even if the permissions of the mounted files, do not allow access, you can extend the the access by the samba options force create mode and force directory mode (if you have the right samba version). Otherwise, why does "guest account = root" work?

Best regards

Thorsten

try this:

[tmp]
comment = /mnt/disc0_1
path = /mnt/disc0_1
browseable = yes
public = yes
writeable = yes
force user = root

dev wrote:

force user = root

Bad idea.  BAD idea.

banane wrote:

Of course, I already "put 2 and 2 together" before you wrote that :-)

Sorry.  Didn't mean to be snippy, had a bad day I guess. :-)  Just wanted to make sure the train of thought was clear.

banane wrote:

But if I understand correctly, even if the permissions of the mounted files, do not allow access, you can extend the the access by the samba options force create mode and force directory mode (if you have the right samba version). Otherwise, why does "guest account = root" work?

I'm not sure I follow you, but I take a stab at what I think you're getting at.  Unlike Linux, Windows boxes using the SMB protocol will always try to connect to a share using the credentials guest:{blank password} for legacy reasons (this is how WFW3.11 and Win95 did things by default).

So when you map the guest user account to root using the "guest account = root" option, you're giving the client root access to any files you're sharing, so the permissions on the individual files really don't matter.  Root can always manipulate files, regardless of the permissions or necessity.   (e.g. "rm -rf /" as root will kill your system, whether you meant it or not).  That's one reason why it's a bad idea to share as root.  Others involve the context the daemon runs in opening potential security holes to your system.  But that's beyond this discussion.

bluesguy wrote:

using the "guest account = root" option, you're giving the client root access to any files you're sharing, so the permissions on the individual files really don't matter.

Exactly! This is one (very fast and bad) way to give the guest more rights than the owner of the file system. (And perhaps to misuse the root account and its rights on the machine for actions beyond read, write and execute files.)

The other solution is clean vor vfat, but the automount command does not work for other filesystems anymore that have not those mount options!? Is there a way to check for the filesystem before mounting and to differentiate the mount commands resectively? How could it be expressed exactly in the automount?

(And I was wrong with my understanding of the samba  options "force ... mode". I did not realize, that they are restricted only to created and "changed" files.)

best regards

Thorsten

(Last edited by banane on 23 Oct 2006, 20:23)

banane wrote:

The other solution is clean vor vfat, but the automount command does not work for other filesystems anymore that have not those mount options!? Is there a way to check for the filesystem before mounting and to differentiate the mount commands resectively? How could it be expressed exactly in the automount?

Well normally this could be managed by hotplug, based on the device ID or however else you wanted to organize your USB devices.  I don't know if OpenWRT supports this, as RC5 doesn't have an /etc/hotplug/usb.agent by default.  It may very well work with some scripting, but you'd need to get the attention of a developer to know for sure.

Alternatively, you could modify /etc/hotplug.d/usb/01-mount to test the filesystem yourself before mounting it, but testing the filesystem of an unmounted partition isn't something that I know how to do easily.  I suppose if you knew which bytes in the partition table held the filesystem type you could dd them out, and set up a simple case statement to do the check and the mount based on the filesystem bytes.

But we're getting beyond the "General Discussion"  level here.  This might be better suited for the developers area if you're going to pursue it...

Maybe someone else knows an easier way?

yes, it is still very fast and bad, but my home is my castle
and my Firewall do the rest

well, I guess I can continue this.
I have ext2 file system and I can't write to it either. Wrtsl54gs RC5 with samba.

workgroup = Today
server string = OpenWRT Samba Server
wins support = no
dns proxy = no
name resolve order = lmhosts hosts bcast
log file = /opt/var/log/samba/log.%m
max log size = 1000
syslog = 0
security = share
encrypt passwords = true
obey pam restrictions = yes
guest account = nobody
passwd program = /usr/bin/passwd %u
load printers = no

[SambaShare]
comment = /mnt/usb2
path = /mnt/usb2
browseable = yes
public = yes
guest ok = yes
writeable = yes

Hopefully someone knows the answer smile

bluesguy wrote:

For vfat usb devices that I share with samba, I also mount with "uid=65534,gid=65534" options, so my command looks like this:

mount -o  auto,users,umask=000,dmask=000,fmask=000,uid=65534,gid=65534 ${part} ${path}

G

this works fine for me - i can write via smb to the USB hard disk.  Im using a wl500g (so only USB 1.1).  Its very slow - anyone have transfer speeds of their setup?  Im trying to figure out whether the USB or smb is limiting the speed.

EDIT
:

I get ~ 20 MB/min upload
       ~ 40 MB/min download (i from the wl500g USB drive to PC via ethernet).

I guess its not the usb1.1 then...

(Last edited by drwormy on 9 Sep 2006, 13:28)

windage wrote:

well, I guess I can continue this.
I have ext2 file system and I can't write to it either. Wrtsl54gs RC5 with samba.

If you would like to log in as root with write support, change these options...

security = user

[SambaShare]
writeable = no
write list = root

Than run "smbpasswd -a root" and enter your root-password.

Thx I'll try it.

I've the same problem, no write access to my mass-storgage device with samba
(the filesystem is vfat)

but samba isn't the problem, if I type "ls -l /mnt" it shows "-rwxr-xr-x" for every file,
I tried three different commands to mount my device:

mount /dev/scsi/host0/bus0/target0/lun0/part1 /mnt
mount /dev/scsi/host0/bus0/target0/lun0/part1 /mnt -o dmask=0,fmask=0
mount -o  auto,users,umask=000,dmask=000,fmask=000,uid=65534,gid=65534 /dev/scsi/host0/bus0/target0/lun0/part1 /mnt

and I tried to change the rights with "chmod 777 /mnt"

but nothing makes any difference

Did you pay attention to the earlier posts?  The problem can either be samba, or how OpenWRT mounts the device.

scales wrote:

but samba isn't the problem, if I type "ls -l /mnt" it shows "-rwxr-xr-x" for every file

If you think it's not a samba permission problem, than it's probably the file permissions.  You're showing that only the owner has write permissions, so who's the owner that it's getting mounted as (i.e. who are the user and group owners on that file)?  If it's the default way that OpenWRT will mount it, then it's root:root, and there's your problem most likely. 

Have you tested mounting it with different args, like I suggested in a previous post?  Try that, and report back with a full command line printout like:

root@OpenWRT:~# ls -la /mnt
drwxr-xr-x    1 root     root            0 Aug 19 08:32 .
drwxr-xr-x    1 root     root            0 Aug 22 20:44 ..
drwxrwxrwx    1 root     root            0 Aug 18 13:47 disc0_1

you're right the owner is root.

I tried three different argument-chains to mount the device:

mount /dev/scsi/host0/bus0/target0/lun0/part1 /mnt
mount /dev/scsi/host0/bus0/target0/lun0/part1 /mnt -o dmask=0,fmask=0
mount -o  auto,users,umask=000,dmask=000,fmask=000,uid=65534,gid=65534 /dev/scsi/host0/bus0/target0/lun0/part1 /mnt

but the result is always the same:

root@OpenWrt:/mnt# ls -la
drwxrwxrwx    1 root     root            0 Jan  1  2000 .
drwxrwxrwx    1 root     root            0 Jan  1  2000 ..
drwxr-xr-x   15 root     root        12288 Jan  1  1970 disc0_1

I'm not sure how that's even working.  It looks like you're trying to mount the device to /mnt directly.  You should be mounting to a directory within /mnt.  Unmount the drive and try:

mount -o  auto,users,umask=000,dmask=000,fmask=000,uid=65534,gid=65534 /dev/scsi/host0/bus0/target0/lun0/part1 /mnt/disc0_1

Let me know what the ls -la output looks like...

your're right that was the problem, if I mount to another directory it works without problems,
thanks

but now I have a problem with the hotplug script (/etc/hotplug.d/usb/01-mount)
I changed this line (in function "mount_storage()":

mount ${part}${path}

to this one:

mount -o auto,users,umask=000,dmask=000,fmask=000,uid=65534,gid=65534 ${part}${path}

to mount the usb-device directly with full write-access.
But it doesn't work, he don't mount anything

do anyone know what's wrong?
or how I can redirect the output of the mount command in the script to a file?

(Last edited by scales on 19 Sep 2006, 18:48)

umount the drive first, then unplug the cable, and plug it back in.  It should automatically mount with the permissions you defined in the hotplug script.

no, the hotplug script creates the directory for the drive but it doesn't mount it.
Is there a possibility to redirect the output of mount to a file?

EDIT:
I found the problem only a slip of the pen, there was a space missing between the arguments

(Last edited by scales on 20 Sep 2006, 16:05)

Thanks for the posting, I was going to try to modify the code in /etc/hotplug.d/usb/01-mount, but I had to do the research on mount first.  The above works great.  For the record the correct code is:

 mount -o auto,users,umask=000,dmask=000,fmask=000,uid=65534,gid=65534 ${part} ${path}

and should replace

 mount ${part} ${path}

I was able to connect easily from an XP client (I have changed by defualt so XP does not use the user acount "Guest" exclusively") but only by typing // and the ip address in file explorer, I could not browse.  Once connected I was easily able to transfer large quantities of files in the 500 KB to 1 MB range but I could not transfer files in the 250 MB range.

I use the samba client to as a backup mechanism to a usb hard drive, I would like it better if some password was used to minimize damage to the back up from other people on the network.  I believe that I can accomplish this by modifing the smb.conf file, but it will have to wait untill I have researced it.  In the mean time,  thanks to the above, I have minimal functionality.

my /etc/smb.conf/ is:

[global]
 syslog = 0
 syslog only = yes
 workgroup = mshome
 server string = OpenWrt Samba Server
 security = share
 encrypt passwords = yes
 guest account = nobody
 local master = yes
 name resolve order = lmhosts hosts bcast

[part01]
 comment = /part01
 path = /mnt/disc2_1
 browseable = yes
 public = yes
 writeable = yes

this thread got me closest to working, but i still have problems.  wl-hdd2.5 with whiterussuan squashfs 5 of a few days ago.  trying to mount from a winxp client.

with "security = share", i can mount and read and write.  with "security = user" winxp does the popup which screams about "not accessible.  You might not have permission ..."

i have the user in /etc/passwd and /etc/samba/smbpasswd.  the username and smbpasswd are the same as the set that works for other mounts from the same winxp client.  i am puzzled, and two hours into shotgun tweaking, always a bad sign.

clue bat please?

---

[global]
syslog = 0
syslog only = yes
workgroup = PSGNET
server string = WLHDD
security = user
encrypt passwords = yes
guest account = nobody
local master = yes
wins support = yes
name resolve order = lmhosts hosts bcast

[ide-p5]
comment = PSGnet Share
path = /ide-p5
browseable = yes
writeable = yes
read only = no
public = yes

(Last edited by randyqx on 16 Nov 2006, 06:51)

sorry to wake up this from the dead but i have a specific issue related to this

wr 0.9 with samba 2  <--> Mac OS X client

this is my smb.conf:

[global]
syslog = 0
syslog only = yes
workgroup = OpenWrt
server string = OpenWrt Samba Server
security = share
encrypt passwords = yes
guest account = root
name resolve order = lmhosts hosts bcast
guest only = yes

[tmp]
comment = /tmp
path = /mnt/disc0_1
browseable = yes
public = yes
writeable = yes
guest ok = yes 
guest only = yes

i tried the above after giving everything else a go... it just blows my mind..

so: i can write to the share, i can make new directories, can copy some files... but when i try to copy SOME files (ex. a few specific directories with music ) it gives me an error about not having permissions to write. it creates the directory though... but cannot delete it from the client..

example:
here are at the moment the list from my mount:

root@OpenWrt:/mnt/disc0_1$ ls -la /mnt/disc0_1/
drwxrwxrwx    5 root     root         4096 Jan  1 20:52 .
drwxr-xr-x    1 root     root            0 Jan  1 00:00 ..
-rwxr--r--    1 nobody   nogroup     15364 Jan  1 20:47 .DS_Store
drwxr-xr-x    2 root     root         4096 Jan  1 00:06 .Trashes
-rw-------    1 root     root    134217728 Jan  1  1970 .journal
drwxr-xr-x    2 root     root         4096 Jan  1  2007 Abba
drwxr-xr-x    2 root     root         4096 Jan  1  2007 cantece
-rw-r--r--    1 root     root    1024000000 Mar 17  2008 optware.img

both <Abba> and <cantece> were created by the samba client  (mac os x) but with one difference. Abba successfully copied, cantece popped an error about permissions, created the dir and the dir is not erasable  from the client side. both folders on the hfs+ client side have the same user permissions.

???

i am extremely confused!

The discussion might have continued from here.