how to force Samba respects file locking?

Alceu R. de Freitas Jr. glasswalk3r at
Tue Jan 10 14:31:28 GMT 2006


I'm trying to lock files using a Debian GNU Linux
(unstable) and Perl, but looks like the smbpasswd
command from Samba is not respecting the lock. Perl
has "advisory" file locking using C flock() or lockf()
or fcntl(), depending which one is first available in
the system.

While this is not a Perl mailing list, I need to know
which scheme Samba uses for file locking to decide if
I can implement such scheme using Perl. I would be
very glad if someone could give me some hints about
that since searching thru the Internet didn't bring me
any help at all.

In my test, the Perl script would hold the file
smbpasswd (the password backend) for 30 seconds. After
that I started the program smbpasswd to change the
user passwords and for my surprise the file was
changed without mercy. :-)

I wrote the code below to implement this test:

-- code --
use strict;
use warnings;
use Fcntl qw(:DEFAULT :flock);

my $sec = 30;

print 'Please type the file that I should lock for
$sec: ';
my $file = <STDIN>;
chomp $file;

sysopen( FH, $file, O_RDWR ) or die "Cannot edit
$file: $!\n";
flock( FH, LOCK_EX ) or die "Cannot lock $file: $!\n";

print 'Ok, holding the file for $sec seconds. I will
not change anythingin the file', "\n";
sleep $sec;


print "Finished\n";

-- code --

Thanks in advance.


Alceu Rodrigues de Freitas Junior
glasswalk3r at
A well-used door needs no oil on its hinges.
A swift-flowing stream does not grow stagnant.
Neither sound nor thoughts can travel through a vacuum.
Software rots if not used.
These are great mysteries -- The Tao Of Programming, 5.1


Yahoo! doce lar. Faça do Yahoo! sua homepage. 

More information about the samba-technical mailing list