[Samba] how to force Samba respects file locking?

Alceu R. de Freitas Jr. glasswalk3r at yahoo.com.br
Wed Jan 11 11:45:37 GMT 2006


Greetings,

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 on
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 --
#!/usr/bin/perl
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;

close(FH);
 
print "Finished\n";

-- code --
 
Thanks in advance.

Regards,


Alceu Rodrigues de Freitas Junior
--------------------------------------
glasswalk3r at yahoo.com.br
http://www.imortais.cjb.net
-----------------------------------------------------------------------
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



Alceu Rodrigues de Freitas Junior
--------------------------------------
glasswalk3r at yahoo.com.br
http://www.imortais.cjb.net
-----------------------------------------------------------------------
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. 
http://br.yahoo.com/homepageset.html 



More information about the samba mailing list