Compare commits
2 Commits
0ae11d062b
...
e1021e8a3d
Author | SHA1 | Date | |
---|---|---|---|
|
e1021e8a3d | ||
|
6d708c3dee |
3
.gitignore
vendored
3
.gitignore
vendored
@ -2,3 +2,6 @@ venv/*
|
||||
test/*
|
||||
*~
|
||||
test_*.txt
|
||||
*/p0.pl
|
||||
*/p1.pl
|
||||
*/p2.pl
|
||||
|
@ -8,8 +8,64 @@ my $ACCOUNT_DIR = "test/";
|
||||
|
||||
my $FULL_PATH = "$WORKING_DIR$ACCOUNT_DIR";
|
||||
|
||||
my $SHELL_ENUM = {
|
||||
"SHELL_BASH" => "/usr/local/bin/bash",
|
||||
"SHELL_KSH" => "/bin/ksh"
|
||||
};
|
||||
|
||||
my @g;
|
||||
|
||||
sub fun1($){
|
||||
my $id = $_[0];
|
||||
|
||||
my $fn1 = $FULL_PATH.$id.".ident";
|
||||
my $fn2 = $FULL_PATH.$id.".pub";
|
||||
|
||||
my $username;
|
||||
my $shell_pref;
|
||||
my $user_email;
|
||||
|
||||
open FILE, $fn1 or die "could not open file";
|
||||
$username = <FILE>;
|
||||
chomp $username;
|
||||
|
||||
$user_email = <FILE>;
|
||||
chomp $user_email;
|
||||
|
||||
{
|
||||
my $shell_var = <FILE>;
|
||||
chomp $shell_var;
|
||||
$shell_pref = $SHELL_ENUM->{$shell_var};
|
||||
}
|
||||
|
||||
# printf("checking username %s\n", $username);
|
||||
if(length($username) > 31 || !($username =~ /^[A-Za-z][A-Za-z0-9]+$/)){
|
||||
printf("%s has an INVALID username\n", $id);
|
||||
die ("oh no");
|
||||
}
|
||||
|
||||
{
|
||||
my $cmd;
|
||||
$cmd = "useradd -m -s " . $shell_pref . " " . $username;
|
||||
printf("Y/N is this command OK?: %s\n", $cmd);
|
||||
|
||||
if(<STDIN> ne "Y\n"){
|
||||
die "invalid characters?!!";
|
||||
}
|
||||
|
||||
system($cmd);
|
||||
#system("mkdir /home/$username/.ssh");
|
||||
system("chmod 700 /home/$username/.ssh");
|
||||
system("mv $FULL_PATH/$id.pub /home/$username/.ssh/authorized_keys");
|
||||
system("chmod 600 /home/$username/.ssh/authorized_keys");
|
||||
system("chown $username:$username /home/$username/.ssh");
|
||||
system("chown $username:$username /home/$username/.ssh/authorized_keys");
|
||||
system("rm $FULL_PATH/$id.ident");
|
||||
}
|
||||
close FILE;
|
||||
}
|
||||
|
||||
fun1("00004");
|
||||
|
||||
die "test 0";
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user