On Wednesday 26 September 2001 02:11, Kurt Wall wrote:
> Here's the promised code. I build it with:
> $ gcc -Wall -ansi -pedantic crypt.c -o crypt -lcrypt
following on, here's some perl stuff I use
---------
#!/usr/bin/perl
# call: install_newuser $password $username
sub install_newuser
{
$pwd = crypt($password,'ab');
sys_playback("useradd $username -p $pwd");
#system "sh", '-c', "useradd $username -p $pwd";
}
sub sys_playback
{
if (system("sh",'-c',"@_ ")) {errmsg("failed on @_");}
}
#####################
# #
# PASSWORD FILE #
# #
#####################
#
# &check_password $username,$password
#
# returns 1 correct
# 0 not correct
# -1 username not found
#
sub check_password
{
local ($user,$pass)= @_;
local ($login,$passwd,$uid,$gid,$gcos,$home,$shell);
if ($user eq "" or $pass eq "") {errmsg('user or password not supplied');}
open_file($pwd_file);
while(<OLD>)
{
chop;
($login,$passwd,$uid,$gid,$gcos,$home,$shell) = split(/:/);
if(index($login,$user) > -1 && index($user,$login) > -1)
{
if(crypt($pass,$passwd) eq $passwd)
{
close(OLD);
return 1;
}
else
{
close(OLD);
return 0;
}
last;
}
}
close(OLD);
return -1;
}
#
# CHANGE PASSWORD
#
# &change_password($username,$new);
#
# old password verification must be done elsewhere
#
sub change_password
{
local ($user,$new)=@_;
local ($login,$passwd,$uid,$gid,$gcos,$home,$shell);
local ($found);
if ($user eq "" or $new eq "") {errmsg("user or password not supplied
properly");}
open_for_copy($pwd_file,'tmp');
while(<OLD>)
{
$maybe=$_;
if (!$found)
{
chop;
($login,$passwd,$uid,$gid,$gcos,$home,$shell) = split(/:/);
if(index($login,$user) > -1 && index($user,$login) > -1)
{
$found=1;
$new=crypt($new,$passwd);
print NEW ("$login:$new:$uid:$gid:$gcos:$home:$shell\n");
}
else {print NEW ($maybe); }
}
else
{
print NEW ($maybe);
}
}
close(OLD);
close (NEW);
if (!$found)
{
unlink 'tmp';
errmsg("$user not found");
}
set_new_pwd_file('tmp');
return $found;
}
--
http://linux.nf -- [EMAIL PROTECTED]
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
_______________________________________________
http://linux.nf -- [EMAIL PROTECTED]
Archives, Subscribe, Unsubscribe, Digest, Etc
->http://linux.nf/mailman/listinfo/linux-users