Gossamer Forum
Home : Products : DBMan : Customization :

Open/Close Issue

Quote Reply
Open/Close Issue
db.cgi has the following code. There seems to be a 'close PASS;' missing for the second 'open (PASS,' function? Can anyone comment on this one - where should the second 'close' actually go?

# If we have a username, and the admin didn't press inquire, then
# we are updating a user.
($in{'username'} && !$in{'inquire'}) and do {
open (PASS, "<$auth_pw_file") or &cgierr ("unable to open: $auth_pw_file.\nReason: $!");
if ($db_use_flock) { flock(PASS, 1); }
@lines = <PASS>;
close PASS;

open (PASS, ">$auth_pw_file") or &cgierr ("unable to open: $auth_pw_file.\nReason: $!");
if ($db_use_flock) {
flock(PASS, 2) or &cgierr("unable to get exclusive lock on $auth_pw_file.\nReason: $!");
}
my $found = 0;
foreach $line (@lines) {
if ($line =~ /^$in{'username'}:/) {
my $password = (split (/:/, $line))[1];
unless ($password eq $in{'password'}) {
my @salt_chars = ('A' .. 'Z', 0 .. 9, 'a' .. 'z', '.', '/');
my $salt = join '', @salt_chars[rand 64, rand 64];
$password = crypt($in{'password'}, $salt);
}
print PASS "$in{'username'}:$password:$in{'per_view'}:$in{'per_add'}:$in{'per_del'}:$in{'per_mod'}:$in{'per_admin'}\n";
$found = 1;
}
else {
print PASS $line;
}
}
$in{'inquire'} = $in{'username'};
$found ?
($message = "User: $in{'username'} updated.") :
($message = "Unable to find user: '$in{'username'}' in the password file.");
last CASE;
};

Quote Reply
Re: Open/Close Issue In reply to
Never did get a response on this one. Can anyone with knowledge on 'flock' and closing database files comment?

I think the missing close could cause problems with the password file if two people try to access it at the same time.

There have been other posts reporting password file problems.

Quote Reply
Re: Open/Close Issue In reply to
It would help greatly if you posted which file and sub you are taking the code above from.




Unoffical DBMan FAQ
http://webmagic.hypermart.net/dbman/
Quote Reply
Re: Open/Close Issue In reply to
Hi Lois,

1. The file is 'db.cgi'

2. The sub is 'sub admin_display'

Quote Reply
Re: Open/Close Issue In reply to
There probably should be a

close PASS;

line there. However, it works fine without it. If you'd like to add it, feel free.

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Open/Close Issue In reply to
I am sure it will work fine without the 'close pass', but could it explain other reported DBMan problems?

Please go see 'UID/Password Errors' in the DBMan Installation Forum, posted on 24-Aug-2000 - I would value your comments.

Quote Reply
Re: Open/Close Issue In reply to
I don't think this would cause the problems described in that thread. Once the script finishes running -- which is when you see a page displayed -- it automatically closes all open files.

However, it is possible I suppose that it could cause the problem on some servers. If you come up with that sort of error, add the line and see if that fixes it.

It would be good programming to have the line in there, there is no doubt. But I don't think anything's going to change with the official DBMan distribution.

JPD
http://www.jpdeni.com/dbman/