#!/usr/local/bin/perl -U # version: 1.01 ################################################################################# #passwd_sync.pl : Program to Setup Unix and Windows password over web. # # Copyright (C) 2001 Rajeev Kumar (rajeev@rajeevnet.com) # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # # #Obtain Latest version of this software from: # http://www.rajeevnet.com/linux/pass_sync/passwd_sync.tar.gz ################################################################################ ################## Edit_Section: site specific variables below #################### $smbpasswd="/usr/local/bin/smbpasswd"; #Location of smbpasswd(1) from samba distro. $p_domain_controller="DomainController"; #Netbios Name (your Primary domain controller) $cgiserver="fqdnOfYourServer"; #Your Webserver $cgi_url="https://$cgiserver/index.cgi"; #Exact cgi-bin URL for this script ################# No Need to edit after this ###################################### BEGIN { $|=1; #Flush all I/O as soon as possible. } use CGI qw(:standard); use Expect; ################################################################## $header=header(); $bottom=end_html(); #Print Common HTML header print $header; #################################################### #Parse Form data: $pform{instance} = param('instance'); $pform{username} = param('username'); $pform{old_passwd_nis} = param('old_passwd_nis'); $pform{old_passwd_windows} = param('old_passwd_windows'); $pform{new_passwd} = param('new_passwd'); $pform{new_passwd_2} = param('new_passwd_2'); $pform{os} = param('os'); #################################################### if($pform{instance} eq "sync") { if($pform{username} eq "" || $pform{old_passwd_windows} eq "" || $pform{new_passwd} eq "" || $pform{new_passwd} eq "") { &print_error("Insufficient Data. Provide all fields in the form"); } if($pform{username}=~ /^([-\@\w.]+)$/) { $username=$pform{username}; $old_passwd_nis=$pform{old_passwd_nis}; $old_passwd_windows=$pform{old_passwd_windows}; $new_passwd=$pform{new_passwd}; $new_passwd_2=$pform{new_passwd_2}; } else { &print_error("Illegal Character(s) sent..."); } if($new_passwd ne $new_passwd_2) { &print_error("New Password Mismatch :: Please type new password same twice"); } ################################################################### ### Change Windows Passwd: ############ ################################################################### if($old_passwd_windows eq "") { &print_error("Insufficient Data. Provide Old Windows password"); } print "

"; print "Changing Windows Password on Domain Controller $p_domain_controller\n"; ($win_passwd=Expect->spawn("$smbpasswd -r $p_domain_controller -U $username")) || &print_error("Unable to spawn $smbpasswd\n"); unless($win_passwd->expect(30,"Old SMB password:")) { &print_error("101: Unable to change Windows password \n"); } print $win_passwd "$old_passwd_windows\r"; unless($win_passwd->expect(30,"New SMB password:")) { &print_error("102: Unable to change Windows password \n"); } print $win_passwd "$new_passwd\r"; unless($win_passwd->expect(30,"Retype new SMB password:")) { &print_error("103: Unable to change Windows password \n"); } print $win_passwd "$new_passwd_2\r"; #Must soft close this file handle otherwise on some system #command may fail to complete. $win_passwd->soft_close(); print "
"; print "
"; } else { &print_form(); } ##################################################### ## Subroutimes ##################################################### sub print_form { ############################# # Printing Header and Info. ############################# print < INFORM ################################# #### Printing Actual Form ################################# print <
Username
Old Password
New Password
New Password
bgs_4_2.gif
PRINTFORM } ######################## # Print Error in Red ######################## sub print_error { local($message)=@_; print <$message ERROR print $bottom; exit(0); }