--- loncom/lcpasswd 2000/10/29 22:38:21 1.7 +++ loncom/lcpasswd 2000/10/30 02:31:45 1.9 @@ -23,6 +23,19 @@ use strict; # Second line is CURRENT PASSWORD # Third line is NEW PASSWORD +# Valid passwords must consist of the +# ascii characters within the inclusive +# range of 0x20 (32) to 0x7E (126). +# These characters are: +# SPACE and +# !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNO +# PQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ + +# Valid user names must consist of ascii +# characters that are alphabetical characters +# (A-Z,a-z), numeric (0-9), or the underscore +# mark (_). (Essentially, the perl regex \w). + # Command-line arguments # Yes, but be very careful here (don't pass shell commands) # and this is only supported to allow perl-system calls. @@ -97,6 +110,21 @@ else { } my ($username,$oldpwd,$newpwd)=@input; +$username=~/^(\w+)$/; +my $safeusername=$1; +if ($username ne $safeusername) { + print "Error. The user name specified has invalid characters.\n"; + unlink('/tmp/lock_lcpasswd'); + exit 9; +} +my $pbad=0; +map {if (($_<32)&&($_>126)){$pbad=1;}} (split(//,$oldpwd)); +map {if (($_<32)&&($_>126)){$pbad=1;}} (split(//,$newpwd)); +if ($pbad) { + print "Error. A password entry had an invalid character.\n"; + unlink('/tmp/lock_lcpasswd'); + exit 10; +} # Grab the line corresponding to username my ($userid,$useroldcryptpwd); @@ -137,8 +165,7 @@ for my $l (@lines) { else {print PASSWORDFILE "$l\n";} } close PASSWORDFILE; -$username=~/^(\w+)$/; -my $safeusername=$1; + ($>,$<)=(0,0); # fool smbpasswd here to think this is not a setuid environment unless (-e '/etc/smbpasswd') { open (OUT,'>/etc/smbpasswd'); close OUT;