Operating System - HP-UX
1822430 Members
2909 Online
109642 Solutions
New Discussion юеВ

How to set file locks from Samba for Unix processes?

 
Denis Medvedyuk_1
New Member

How to set file locks from Samba for Unix processes?

Hello, All!

I have next configuration: NT machine puts files to Samba share on the Unix host and then other clients take these files from this share via FTP.

But sometimes they take these files a bit earlier than NT machine finishes to write them. Of course, in this case clients take a broken files (zero-padded).

I tried to set up next options in smb.conf:
oplocks = no
locking = yes
strict locking = yes
but it doesn't help.

I checked a presence of /var/opt/samba/locks dir. It's exists but contains four files only: status.lck, browse.dat, smbd.pid, nmbd.pid.

But problem still exists: Smbd can't prevent locked files from being taken by ftpd.

My next idea is to use "map share modes" but I don't sure that it is right option.

I use HP9000 K420 server, HP-UX 11i and standard Samba/CIFS9000 Server shipped with this HP-UX distributive.

What must I do to solve this problem?

Thanks for any advices.
4 REPLIES 4
Mark Grant
Honored Contributor

Re: How to set file locks from Samba for Unix processes?

I'm not sure if you solve this with samba. A simple solution would be to have a script that runs at regular intervals on the unix box checking that the ftp files are not open "fuser". Those files that are not open are then copied to a completely different directory. Your client sofware then uses ftp to get the files but from this new directory.

It's an option!
Never preceed any demonstration with anything more predictive than "watch this"
A. Clay Stephenson
Acclaimed Contributor

Re: How to set file locks from Samba for Unix processes?

You need to understand that file locks in UNIX (Samba or not) are advisory only meaning that unless the program accessing the file actually tests for locks then the access is not restricted at all. You can change the file locking from advisory to forced by setting the setgid bit (02000) on regular files that ARE NOT GROUP executable.

e.g. Suppose that myfile was originally given 664 permission; by setting myfile to 2644 file locking is enforced. Now for the bad news: File locks for network files (NFS) are ALWAYS advisory regardless of the setgid bit and I strongly suspect that Samba shares adopt this policy.
If it ain't broke, I can fix that.
U.SivaKumar_2
Honored Contributor

Re: How to set file locks from Samba for Unix processes?

Hi,

Put this option in global section of smb.conf

kernel oplocks = yes

Restart samba daemons and if possible the server.

I assume that HP-UX 11i supports kernel oplocks.

regards,

U.SivaKumar


Innovations are made when conventions are broken
Don McCall_1
Occasional Advisor

Re: How to set file locks from Samba for Unix processes?

Samba (CIFS Server) on HP-UX does NOT support kernel oplocks, so this will not help.
In addition, Samba will not override permissions set at the OS level, so if as was suggested, doing setgid will actually force HP-UX OS to enforce fcntl locks, rather than them being advisory, then samba would respect this (unless of course you are sharing out an NFS filesystem, where the previous poster notes that the setgid trick does not work). Bottom line, though - samba respects the permissions and ownership at the HP-UX level -if the HPUX program (ftp or any other) does not respect an fcntl lock, then samba will not be able to protect that file from abuse.
Hope this helps.