--- CGI.pl.org 2004-02-29 22:34:46.000000000 +0100 +++ CGI.pl 2004-02-29 23:19:02.000000000 +0100 @@ -36,8 +36,8 @@ # commented out the following snippet of code. this tosses errors into the # CGI if you are perl 5.6, and doesn't if you have perl 5.003. # We want to check for the existence of the LDAP modules here. -# eval "use Mozilla::LDAP::Conn"; -# my $have_ldap = $@ ? 0 : 1; +eval "use Net::LDAP"; +my $have_ldap = $@ ? 0 : 1; # Shut up misguided -w warnings about "used only once". For some reason, # "use vars" chokes on me when I try it here. @@ -622,18 +622,18 @@ # If we're using LDAP for login, we've got an entirely different # set of things to check. -# see comment at top of file near eval # First, if we don't have the LDAP modules available to us, we can't # do this. -# if(!$have_ldap) { -# print "Content-type: text/html\n\n"; -# PutHeader("LDAP not enabled"); -# print "The necessary modules for LDAP login are not installed on "; -# print "this machine. Please send mail to ".Param("maintainer"); -# print " and notify him of this problem.\n"; -# PutFooter(); -# exit; -# } + if(!$have_ldap) { + print "Content-type: text/html\n\n"; + PutHeader("LDAP not enabled"); + print "The necessary modules for LDAP login are not installed on "; + print "this machine. Please send mail to ".Param("maintainer"); + print " and notify him of this problem.\n"; + PutFooter(); + exit; + } + # Next, we need to bind anonymously to the LDAP server. This is # because we need to get the Distinguished Name of the user trying @@ -657,7 +657,8 @@ if($LDAPserver =~ /:/) { ($LDAPserver, $LDAPport) = split(":",$LDAPserver); } - my $LDAPconn = new Mozilla::LDAP::Conn($LDAPserver,$LDAPport); + my $LDAPconn = Net::LDAP->new($LDAPserver, port=>$LDAPport); + if(!$LDAPconn) { print "Content-type: text/html\n\n"; PutHeader("Unable to connect to LDAP server"); @@ -668,6 +669,9 @@ exit; } + $LDAPconn->bind; + + # if no password was provided, then fail the authentication # while it may be valid to not have an LDAP password, when you # bind without a password (regardless of the binddn value), you @@ -684,7 +688,7 @@ } # We've got our anonymous bind; let's look up this user. - my $dnEntry = $LDAPconn->search(Param("LDAPBaseDN"),"subtree","uid=".$::FORM{"LDAP_login"}); + my $dnEntry = $LDAPconn->search(base=>Param("LDAPBaseDN"), scope=>"sub", filter=>"uid=".$::FORM{"LDAP_login"})->pop_entry; if(!$dnEntry) { print "Content-type: text/html\n\n"; PutHeader("Login Failed"); @@ -696,12 +700,14 @@ # Now we get the DN from this search. Once we've got that, we're # done with the anonymous bind, so we close it. - my $userDN = $dnEntry->getDN; - $LDAPconn->close; + my $userDN = $dnEntry->dn(); + $LDAPconn->unbind; + + $LDAPconn = Net::LDAP->new($LDAPserver, port=>$LDAPport); # Now we attempt to bind as the specified user. - $LDAPconn = new Mozilla::LDAP::Conn($LDAPserver,$LDAPport,$userDN,$::FORM{"LDAP_password"}); - if(!$LDAPconn) { + my $bindmesg = $LDAPconn->bind($userDN,password => $::FORM{"LDAP_password"}); + if(!$bindmesg || $bindmesg->{resultCode} != 0) { print "Content-type: text/html\n\n"; PutHeader("Login Failed"); print "The username or password you entered is not valid.\n"; @@ -712,8 +718,9 @@ # And now we're going to repeat the search, so that we can get the # mail attribute for this user. - my $userEntry = $LDAPconn->search(Param("LDAPBaseDN"),"subtree","uid=".$::FORM{"LDAP_login"}); - if(!$userEntry->exists(Param("LDAPmailattribute"))) { + my $userEntry = $LDAPconn->search(base=>Param("LDAPBaseDN"), scope=>"sub", filter=>"uid=".$::FORM{"LDAP_login"})->pop_entry; + if(!$userEntry->get_value(Param("LDAPmailattribute"))) { + print "Content-type: text/html\n\n"; PutHeader("LDAP authentication error"); print "I was unable to retrieve the ".Param("LDAPmailattribute"); @@ -725,7 +732,7 @@ # Mozilla::LDAP::Entry->getValues returns an array for the attribute # requested, even if there's only one entry. - $enteredlogin = ($userEntry->getValues(Param("LDAPmailattribute")))[0]; + $enteredlogin = ($userEntry->get_value(Param("LDAPmailattribute")))[0]; # We're going to need the cryptpwd for this user from the database # so that we can set the cookie below, even though we're not going @@ -736,9 +743,9 @@ # Bugzilla's database yet, so we've got to add them. if($realcryptpwd eq "") { # We'll want the user's name for this. - my $userRealName = ($userEntry->getValues("displayName"))[0]; + my $userRealName = ($userEntry->get_value("displayName"))[0]; if($userRealName eq "") { - $userRealName = ($userEntry->getValues("cn"))[0]; + $userRealName = ($userEntry->get_value("cn"))[0]; } InsertNewUser($enteredlogin, $userRealName); $realcryptpwd = PasswordForLogin($enteredlogin);