#!/usr/bin/perl # --== this file has been hacked by Ryan ==-- # After being stolen from a web requision form $webmaster = "rborowski\@tembec\.ca"; $machine_name = "localhost"; ### Run it locally (security) &parse_form_data (*webreq); $username = $webreq{'Username'}; $password = $webreq{'Password'}; $newpassword = $webreq{'NewPassword'}; $newpassword2 = $webreq{'VerifyNewPassword'}; $now_string = localtime; ($yp_name,$yp_passwd,$yp_uid,$yp_gid,$yp_quota,$yp_gcos,$yp_comment,$yp_dir,$yp_shell)=getpwnam $username; if ($yp_command =~ /,/) { @temp_real = split(/,/,$yp_comment); $realname = $temp_real[0]; } else {$realname = $yp_comment; } $hash = crypt($password, $yp_passwd); if (crypt ($password, $yp_passwd) eq $yp_passwd) { # Password matches $passwd_match = "TRUE"; } else { ### Someone hacking - shouldn't be able to get this far elsewise $passwd_match = "FALSE"; } if ( $newpassword eq $newpassword2 ) { $new_passwd_match = "TRUE"; } else { ### New Password Mismatch $new_passwd_match = "FALSE"; } if ( $passwd_match eq "TRUE" && $new_passwd_match eq "TRUE" ) { &password_ok ($yp_name, $password, $newpassword); } else { &password_bad; } ############################################################################# ### Print out web page here ################################################ ############################################################################# sub parse_form_data { local (*FORM_DATA) = @_; local ( $request_method, $query_string, @key_value_pairs, $key_value, $key, $value); $request_method = $ENV{'REQUEST_METHOD'}; if ($request_method eq "GET") { $query_string = $ENV{'QUERY_STRING'}; } elsif ($request_method eq "POST") { read (STDIN, $query_string, $ENV{'CONTENT_LENGTH'}); } else { &return_error (500, "Server Error", "Server uses unsupported method"); } @key_value_pairs = split (/&/, $query_string); foreach $key_value (@key_value_pairs) { ($key, $value) = split (/=/, $key_value); $value =~ tr/+/ /; $value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C", hex ($1))/eg; if (defined($FORM_DATA{$key})) { $FORM_DATA{$key} = join ("\0", $FORM_DATA{$key}, $value); } else { $FORM_DATA{$key} = $value; } } } sub return_error { local ($status, $keyword, $message) = @_; print "Content-type: text/html", "\n"; print "Status: ", $status, " ", $keyword, "\n\n"; print <CGI Program - Unexpected Error

$keyword


$message Please contact $webmaster for more information. End_of_Error exit(1); } sub password_bad { print "Content-type: text/html\n\n"; print "\n\n"; print "Identity Crisis\n"; print "\n"; print "

Identity Crisis

\n"; print "
\n"; if ( $passwd_match eq "FALSE" ) { print "Sorry, either that user doesn't exist, or has\n"; print "a different password\n"; } else { print "Sorry, your new password failed verification\n"; } print "click here to try again\n"; print "Return to support Home Page\n"; print "\n"; print "\n"; } sub password_ok { local ($user, $pass, $newpass) = @_; &display_web_page ($username, $password, $newpassword); } sub display_web_page { local ($l_user, $l_pass, $l_newpass) = @_; ############################################## ### This code block handles the .vacation file ### Now write out web page print "Content-type: text/html\n\n"; print "\n\n"; print "Password Change\n"; print "\n"; $vac_command = sprintf ("./ChangePassword.exp %s %s %s", $username, $password, $newpassword ); system("$vac_command"); $exit_value = $? >> 8; if ( $exit_value eq 0 ) { print "

Password Changed

\n"; } else { print "

Password Change Failed

\n"; } print "
\n"; print "
\n";
        print "Unix Password for user: $l_user ($realname)";
        print "\n";

        if ( $exit_value eq 1 )
        {
                print "Error: Unknown login ID. \n";
        }
        elseif ( $exit_value eq 2 )
        {
                print "Error: Timeout while attempting to change password. \n";
        }
        elseif ( $exit_value eq 3 )
        {
                print "Error: Unknown user. \n";
        }
        elseif ( $exit_value eq 4 )
        {
                print "Error: Insufficient priviledge. \n";
        }
        elseif ( $exit_value eq 5 )
        {
                print "Error: Password too short. \n";
        }
        elseif ( $exit_value eq 6 )
        {
                print "Error: Password is all lower-case. \n";
        }
        else
        {
                print "Successfully Changed. \n";
        }
       
        if ( $exit_value != 0 )
        {
                print "Passwords must be at least 5 characters in length. \n";
                print "At least one of the first 8 characters must be \n";
                print "upper-case or a number. \n";
                print "For example asdf1 is valid, but asdfi is not. \n";
                print "\nPlease go back and try again. \n";
        }

        print "
\n"; print "Revision A\n"; print "Return to support Home Page\n"; print "
\n"; print "\n"; exit(0); }