[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: system user database
Veins wrote:
>
>I am developping a tool to allow users to change informations about their
>accounts on the system via a web interface (a big mix
>of php, perl, c and sh that calls sudo when data is parsed) and I am
>searching for the best solution to store and retrieve data for
>these users without using a sgbdr or any kind of database running as a
>service (mysql, postgresql and/or ldap are not options).
>
>Thanks for your help ;)
>veins
>
I'm unable to program C but I have done similar things in Perl. Maybe
there are better ways, then just parse the file line by line,
but that is how it works for me, having no Problem with 1300 Users (from
the view of speed).
To get the username you could do:
# SNIP
use Digest::MD5 qw(md5); ### Hope it's really md5
$entered_pw = md5 ($entered_pw);
$valid=0;
open (PASSWD, "< /etc/virtualusers_passwd") or die "Unable to open File
$!\n";
flock (PASSWD, 1) or die "Unable to Lock File $!\n"; # RECOMMEND ON THIS,
# is 1 also on OpenBSD for shared_lock ?
while (<PASSWD>)
{
if ($_ =~ m/^$entered_uid:$entered_pw:/)
{
$valid=1;
}
}
close(PASSWD);
######### SNIP #
When you want to change a users password there is no way I'm aware of
around of working with temporary copies,
(exeption: you'll put the whole File into an Array). Then make a
temporary copy search for the line containing the user name,
and write it together with the modified password back to the real file:
cp virtualusers_passwd virtualusers_passwd.tmp;
open (PASSWD, "> /etc/virtualusers_passwd") or die "Could not open File
for writing $!\n";
flock (PASSWD, 2) or die "Could not Lock the File $!\n"; # AGAIN, 2 also
on OpenBSD exclusive_lock ?
open (TEMP, "< /etc/virtualusers_passwd.tmp) or die "Unalble to open
temp file for reading $!\n";
flock (TEMP, 2) or die "Could not Lock Temporary file $!\n";
while (<TEMP>)
{
$_ =~ s/$entered_uid:$old_password:/$entered_uid:$new_password:/;
print PASSWD $_;
}
close (TEMP);
close(PASSWD);
unlink virtualusers_passwd.tmp;
But I would really recommend to have a virtual users password file not
letting them have system accounts, unless really needed.
Maybe you give it a try.
Carsten
P.S. Code untested written from scratch :-)