3 ################################################################################
5 # changepass.pl - A program to allow users to change their passwords
11 # usermod and this file - http://www.cloudamster.com/cloudmaster/projects
14 # Version 0.1 - initial write
17 # ... the ToDo section is on the ToDo list...
20 # The password cannot contain single and double quotes.....welcome to quoting hell....
23 # This code is largely based on work done by Danny Sauer - http://www.cloudamster.com/cloudmaster/projects
24 # His work is not licensed and is marked as 'freely distributable'.
25 # Thank you to Danny for his hard work on the initial work.
27 ################################################################################
29 use CGI
qw(:standard);
32 # CONFIGURATION SECTION
33 $masterLDAP = "ldap.idealx.org";
34 $basedn = "dc=IDEALX,dc=org";
36 $masterDN = "cn=manager,$basedn";
37 $ldap_path = "/usr/bin";
39 $ldappasswd = "$ldap_path/ldappasswd $ldap_opts -h $masterLDAP -D '$masterDN' -w '$masterPw'";
40 $usersdn = "ou=Users,$basedn";
45 # DONT EDIT ANYTHING BELOW THIS LINE
47 $passtag = "Current password:";
48 $npasstag1 = "New password:";
49 $npasstag2 = "Retype new pasword:";
51 $color = "<FONT color='red'>";
52 $stopcolor = "</FONT>";
55 nologin
() unless ($username = param
('login'));
56 nopass
() unless ($oldpass = param
('oldpass'));
57 nonewpass
(1) unless ($newpass1 = param
('newpass'));
58 nonewpass
(2) unless ($newpass2 = param
('newpass2'));
59 verifyuser
($username) or die "bad user";
60 verifypass
($username, $oldpass) or die "bad pass";
61 testnewpass
($newpass1, $newpass2) or die "bad new pass";
62 changepass
($username, $newpass1) or die "couldn't change pass";
71 $ldap = Net
::LDAP
->new($masterLDAP) or die "can't make new LDAP object: $@";
73 if (0 < $ldap->search(base
=> $basedn, filter
=> "(uid=$user)")->count){
76 $logtag = $color . $logtag . $color;
77 $error = "No such user";
85 $ldap = Net
::LDAP
->new($masterLDAP) or die "can't make new LDAP object: $@";
86 $binddn = "uid=$uid,ou=People,$basedn";
87 return 1 if($ldap->bind( $binddn, password
=> $pass)->code == 0);
89 $passtag = $color . $passtag . $color;
90 $error = "Incorrect password";
94 print header
, start_html
(-title
=>"LDAP dead");
95 print h2
("<CENTER>The LDAP server is temporarily unavailable."),
96 p
,"Please try again later</CENTER>";
98 }die "Something (or someone) is defective, contact your friendly Systems Administrator";
102 $p1 = shift; $p2 = shift;
104 $npasstag1 = $color . $npasstag1 . $color;
105 $npasstag2 = $color . $npasstag2 . $color;
106 $error = "Passwords don't match ($p1 vs $p2)";
111 $npasstag1 = $color . $npasstag1 . $color;
112 $npasstag2 = $color . $npasstag2 . $color;
113 $error = "Passwords cannot contain double quotes. Sorry";
118 $npasstag1 = $color . $npasstag1 . $color;
119 $npasstag2 = $color . $npasstag2 . $color;
120 $error = "Passwords cannot contain single quotes. Sorry";
129 local $newpass = shift;
130 local $dn = "uid=$user,$usersdn";
131 system "$ldappasswd $dn -s '$newpass' > /dev/null";
132 `/usr/bin/sudo /usr/bin/smbpasswd $user "$newpass"`;
137 $logtag = $color . $logtag . $color;
138 $error = "You need to enter a Login Name";
144 $passtag = $color . $passtag . $color;
145 $error = "Please enter your old password";
152 $npasstag1 = $color . $npasstag1 . $color if($f==1);
153 $npasstag2 = $color . $npasstag2 . $color if($f==2);
154 $error = "You need to enter your new password";
155 $error .= " twice" if($f==2);
162 start_html
(-title
=> "Password Change Page",
163 -author
=> 'tdavis@birddog.com',
165 h3
('Password Change Page'),
166 startform
(-method
=>'POST'),
167 "<TABLE BORDER=0 WIDTH=50%>",
172 textfield
(-name
=>'login', -default=>$login,
173 -size
=>15, -maxlength
=>20),
177 password_field
(-name
=>'oldpass', -size
=>15, -maxlength
=>25),
181 password_field
(-name
=>'newpass', -size
=>15, -maxlength
=>25),
185 password_field
(-name
=>'newpass2', -size
=>15, -maxlength
=>25),
186 "</TD><TR><TD></TD><TD>",
187 submit
(-name
=>"change"),reset(),
188 "</TD></TR></TABLE>",
191 "<FONT color='red'>$error</FONT>",
197 start_html
(-title
=> "Success",
199 h1
("Password Succesfully Changed"),