From: Nick J. <nje...@us...> - 2001-10-07 14:16:59
|
Update of /cvsroot/sandweb/sandweb/bin In directory usw-pr-cvs1:/tmp/cvs-serv5544/bin Modified Files: sandweb-admin Log Message: Fixed little problem with authentication (newline character needed to be chomped) Index: sandweb-admin =================================================================== RCS file: /cvsroot/sandweb/sandweb/bin/sandweb-admin,v retrieving revision 1.6 retrieving revision 1.7 diff -U2 -r1.6 -r1.7 --- sandweb-admin 2001/10/07 13:44:50 1.6 +++ sandweb-admin 2001/10/07 14:16:57 1.7 @@ -15,95 +15,73 @@ sub main { - if (@ARGV) { - if ($ARGV[0] eq '--list-users') { - list_users(); - exit 0; - } - elsif ($ARGV[0] eq '--add-user') { - add_user($ARGV[1]); - exit 0; - } - elsif ($ARGV[0] eq '--remove-user') { - remove_user($ARGV[1]); - exit 0; - } - else { - syntax(); - exit 1; - } - } - else { - syntax(); - exit 1; - } + if (@ARGV) { + if ($ARGV[0] eq '--list-users') { + list_users(); + exit 0; + } + elsif ($ARGV[0] eq '--add-user') { + add_user($ARGV[1]); + exit 0; + } + elsif ($ARGV[0] eq '--remove-user') { + remove_user($ARGV[1]); + exit 0; + } + else { + syntax(); + exit 1; + } + } + else { + syntax(); + exit 1; + } } sub add_user { - my $name = shift; - my $enc_pwd = ''; - my $full_name = ''; - my $uid = ''; - - if (! $name) { - print "must specify a username to create!\n"; - exit 21; - } - chomp $name; - - my @file = (); - if (-f $passwd_file) { - open(PW, "<$passwd_file") or - fexit('22', "Unable to open $passwd_file : $!"); - @file = <PW>; - close PW; - - # make sure username is unique - foreach my $line (@file) { - chomp $line; - my ($un, $uid, $pw, $fn) = split(':', $line); - if ($un eq $name) { - print "username $name already exists!\n"; - exit 23; - } - } - } - - # get password - print "Enter password for $name: "; - my $tmp = <STDIN>; - chomp ($tmp); - if ($tmp) { - #encrypt passwd - my $salt = substr($tmp, 0, 2); - $enc_pwd = crypt($tmp, $salt); - } - else { - print "error: no password entered, aborting.\n"; - exit 24; - } - - # get highest UID and inc by 1 - my $last_line = $file[$#file + 1]; - if ($last_line) { - my ($junk1, $last_uid, $junk2, $junk3) = split(':', $last_line); - $uid = $last_uid++; - } - else { - $uid = 1; - } - - # get full name - #print "Enter full name for $name: "; - #$tmp = <STDIN>; - #chomp ($tmp); - #if ($tmp) { - # $full_name = $tmp; - #} - #else { - # print "error: no full name entered, aborting.\n"; - # exit 25; - #} + my $name = shift; + my $enc_pwd = ''; + my $full_name = ''; + my $max_uid = 0; + if (! $name) { + fexit('21', "must specify a username to create!"); + } + chomp $name; + my @file = (); + if (-f $passwd_file) { + open(PW, "<$passwd_file") or + fexit('22', "Unable to open $passwd_file : $!"); + @file = <PW>; + close PW; + + # make sure username is unique + foreach my $line (@file) { + chomp $line; + my ($un, $uid, $pw, $fn) = split(':', $line); + if ($un eq $name) { + fexit('23', "username $name already exists!"); + } + if ($uid > $max_uid) { + $max_uid = $uid; + } + } + } + + # get password + print "Enter password for $name: "; + my $tmp = <STDIN>; + chomp ($tmp); + if ($tmp) { + #encrypt passwd + my $salt = substr($tmp, 0, 2); + $enc_pwd = crypt($tmp, $salt); + } + else { + fexit('24', "error: no password entered, aborting."); + } + + # added user's sandbox dir system('mkdir', "$users_dir/$name"); @@ -123,7 +101,8 @@ } + $max_uid++; open(PW, ">>$passwd_file") or fexit('26', "Unable to open $passwd_file : $!"); - print PW "$name:$uid:$enc_pwd\n"; + print PW "$name:$max_uid:$enc_pwd\n"; close PW; @@ -139,5 +118,5 @@ open(PW, "<$passwd_file") or - fexit('2', "Unable to open $passwd_file : $!"); + fexit('31', "Unable to open $passwd_file : $!"); my @file = <PW>; close PW; @@ -152,8 +131,13 @@ open(PW, ">$passwd_file") or - fexit('3', "Unable to open $passwd_file : $!"); + fexit('32', "Unable to open $passwd_file : $!"); print PW join('', @o_file); close PW; + system('rm', '-rf', "$data_dir/$name"); + if ($?) { + fexit('33', "Unable to remove $name.\n"); + } + system('rm', '-rf', "$users_dir/$name"); if (!$?) { @@ -161,6 +145,6 @@ } else { - system('rm', '-rf', "$users_dir/$name"); - fexit('38', "Unable to remove $name.\n"); + system('rm', '-rf', "$data_dir/$name"); + fexit('34', "Unable to remove $name.\n"); } |