create-user.pl successful user creation test
This commit is contained in:
parent
6d708c3dee
commit
e1021e8a3d
@ -9,7 +9,7 @@ my $ACCOUNT_DIR = "test/";
|
|||||||
my $FULL_PATH = "$WORKING_DIR$ACCOUNT_DIR";
|
my $FULL_PATH = "$WORKING_DIR$ACCOUNT_DIR";
|
||||||
|
|
||||||
my $SHELL_ENUM = {
|
my $SHELL_ENUM = {
|
||||||
"SHELL_BASH" => "/bin/bash",
|
"SHELL_BASH" => "/usr/local/bin/bash",
|
||||||
"SHELL_KSH" => "/bin/ksh"
|
"SHELL_KSH" => "/bin/ksh"
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -22,8 +22,6 @@ sub fun1($){
|
|||||||
my $fn2 = $FULL_PATH.$id.".pub";
|
my $fn2 = $FULL_PATH.$id.".pub";
|
||||||
|
|
||||||
my $username;
|
my $username;
|
||||||
# my $displayname;
|
|
||||||
# my $name_pref;
|
|
||||||
my $shell_pref;
|
my $shell_pref;
|
||||||
my $user_email;
|
my $user_email;
|
||||||
|
|
||||||
@ -31,42 +29,43 @@ sub fun1($){
|
|||||||
$username = <FILE>;
|
$username = <FILE>;
|
||||||
chomp $username;
|
chomp $username;
|
||||||
|
|
||||||
# $displayname = <FILE>;
|
|
||||||
# chomp $displayname;
|
|
||||||
|
|
||||||
# # Save this for later
|
|
||||||
# $name_pref = <FILE>;
|
|
||||||
# chomp $name_pref;
|
|
||||||
|
|
||||||
$user_email = <FILE>;
|
$user_email = <FILE>;
|
||||||
chomp $user_email;
|
chomp $user_email;
|
||||||
|
|
||||||
{
|
{
|
||||||
my $shell_var = <FILE>;
|
my $shell_var = <FILE>;
|
||||||
chomp $shell_var;
|
chomp $shell_var;
|
||||||
# printf("\$shell_var: %s\n", $shell_var);
|
|
||||||
$shell_pref = $SHELL_ENUM->{$shell_var};
|
$shell_pref = $SHELL_ENUM->{$shell_var};
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("checking username %s\n", $username);
|
# printf("checking username %s\n", $username);
|
||||||
if(length($username) > 31 || !($username =~ /^[A-Za-z][A-Za-z0-9]+$/)){
|
if(length($username) > 31 || !($username =~ /^[A-Za-z][A-Za-z0-9]+$/)){
|
||||||
printf("%s has an INVALID username\n", $id);
|
printf("%s has an INVALID username\n", $id);
|
||||||
die ("oh no");
|
die ("oh no");
|
||||||
}
|
}
|
||||||
|
|
||||||
# if(length($displayname) > 31 || $displayname =~ /^[A-Za-z0-9]+$/){
|
|
||||||
# printf("%s has an INVALID username\n", $id);
|
|
||||||
# }
|
|
||||||
|
|
||||||
{
|
{
|
||||||
my $cmd;
|
my $cmd;
|
||||||
$cmd = "useradd -m -s $shell_pref $username";
|
$cmd = "useradd -m -s " . $shell_pref . " " . $username;
|
||||||
printf("gonna run this command: %s\n", $cmd);
|
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;
|
close FILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
fun1("00000");
|
fun1("00004");
|
||||||
|
|
||||||
die "test 0";
|
die "test 0";
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user