From e0d7030f6f3df4f97e151dfa14f3952cc5064efb Mon Sep 17 00:00:00 2001 From: gashapwn Date: Thu, 26 Nov 2020 22:31:34 +0000 Subject: [PATCH] changed format of new user files --- perl-script/create-user.pl | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/perl-script/create-user.pl b/perl-script/create-user.pl index 95155cc..b06d11c 100644 --- a/perl-script/create-user.pl +++ b/perl-script/create-user.pl @@ -19,13 +19,14 @@ sub create($){ my $id = $_[0]; my $fn1 = $FULL_PATH.$id.".ident"; - my $fn2 = $FULL_PATH.$id.".pub"; + # my $fn2 = $FULL_PATH.$id.".pub"; my $username; my $shell_pref; my $user_email; + my $pub_key; - open FILE, $fn1 or die "could not open file"; + open FILE, $fn1 or die "could not open file $fn1"; $username = ; chomp $username; @@ -33,11 +34,14 @@ sub create($){ chomp $user_email; { - my $shell_var = ; - chomp $shell_var; - $shell_pref = $SHELL_ENUM->{$shell_var}; + my $s0 = ; + chomp $s0; + $shell_pref = $SHELL_ENUM->{$s0}; } + $pub_key = ; + chomp $pub_key; + if(length($username) > 31 || !($username =~ /^[A-Za-z][A-Za-z0-9]+$/)){ printf("%s has an INVALID username\n", $id); die ("oh no"); @@ -48,22 +52,23 @@ sub create($){ $cmd = "useradd -m -s " . $shell_pref . " " . $username; printf("Y/N is this command OK?: %s\n", $cmd); - if( ne "Y\n"){ + if(!( =~ /^y/i)){ die "invalid characters?!!"; } system($cmd); - system("cat $FULL_PATH/$id.pub > /home/$username/.ssh/authorized_keys"); + # system("cat $FULL_PATH/$id.pub > /home/$username/.ssh/authorized_keys"); + system("echo '$pub_key' > /home/$username/.ssh/authorized_keys"); system("chmod 711 /home/$username"); - system("rm $FULL_PATH/$id.ident"); - system("rm $FULL_PATH/$id.pub"); + system("rm $fn1"); + # system("rm $FULL_PATH/$id.pub"); system("echo $username >> user_list.txt"); } close FILE; } @g = glob("$FULL_PATH*"); -@g = map { s/.*\/([^\/]*).pub$/$1/; $_ } grep {$_ =~ /pub$/} @g; +@g = map { s/.*\/([^\/]*).ident$/$1/; $_ } grep {$_ =~ /ident$/} @g; for my $fn (@g){ create($fn);