I get an error at line: system("/usr/sbin/chpasswd $user:$password")==0 or die "Error: $?"; and I changed it to: system("echo $user:$password | /usr/sbin/chpasswd")==0 or die "Error: $?"; in such way it works fine.
Any comment? ----- Original Message ----- From: "Janek Schleicher" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, May 23, 2003 12:51 AM Subject: Re: Adding user to the system by using Perl? > Puth Chan Choth wrote at Wed, 21 May 2003 18:01:24 +0700: > > > Do you mean that I write a script like this: > > Not definitly, but at least you better locate the error now ... > > > #!/usr/bin/perl > > use strict; > > use warnings; > > use CGI::Carp 'fatalsToBrowser'; > > use CGI; > > my $q = CGI->new(); > > my $user = $q->param('txtUserName') || 'No User Name Provided'; > > my $password = $q->param('txtPassword') || 'No Password Provided'; > > $user =~ /^\w+$/ or die "No valid user specified: $user"; > > $password =~ /^\S+$/ or die "No valid password specified: $password"; > > print > > $q->header(), > > $q->start_html( -title => 'User Administration For SuSE Linux' ), > > $q->end_html; > > system("/bin/mkdir -p /home/$user")==0 or die "Error:$?"; > > system("/usr/sbin/useradd -d /home/$user -s /bin/false $user")==0 or die > > "Error:$?"; > > system("/bin/chown $user.users /home/$user -R")==0 or die "Error:$?"; > > system("/usr/sbin/chpasswd $user:$password")==0 or die "Error: $?"; > > print "Successfully added $user with password $password"; > > > > Now I got the error on line 15. > > (That is the system("...mkdir...") ... line, isn't it) > > Seems like the script doesn't have the right to create a directory > in the /home directory, what seems to be logical, > as normal users (and cgi-scripts run normally not as root), > normally don't have this right! > > > For me, I do not know so much about Perl regular expression. Would you mind > > telling me what these mean: > > Better you start also reading perldoc perlre. > Programming in Perl without a basic knowledge of regular expressions is > like driving a racing car only in the team's box. > Not much better than Java, erm I meant a bicycle :-) > > > ~ /^\w+$/ > > The ^ anchor stands for the beginning of the string, > the $ for the end. > Thus the string must look like \w+ from the beginning to the end. > \w stands for a word character, > + stands for at least one without any boundary to the top how much. > Conclusionary the regexp stands for > a string consisting only of word characters (like a-zA-Z_) > > > ~ /^\S+$/ > > Similar like above, > \S stands for all non-white-space-characters. > I wasn't sure what characters are useful for passwords and where exactly > you would use them. > (It's always dangerous to use them in a cmd line for many reasons, > so I supposed you wouldn't really want it) > > > $? > > Read perldoc perlvar. > From it: > $? The status returned by the last pipe close, > backtick (``) command, successful call to wait() > or waitpid(), or from the system() operator. > ... > ... [and much more useful explications] > > > > Greetings, > Janek > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]