diff -urN bugzilla-2.16.2/CGI.pl bugzilla-ldap/CGI.pl --- bugzilla-2.16.2/CGI.pl 2002-07-10 08:27:15.000000000 +0200 +++ bugzilla-ldap/CGI.pl 2003-03-14 09:59:58.540011000 +0100 @@ -1,4 +1,4 @@ -# -*- Mode: perl; indent-tabs-mode: nil -*- +#-*- Mode: perl; indent-tabs-mode: nil -*- # # The contents of this file are subject to the Mozilla Public # License Version 1.1 (the "License"); you may not use this file @@ -25,6 +25,11 @@ # Gervase Markham # Christian Reis +# +# Patched to use Net::LDAP instead of Mozilla::LDAP::Conn by +# Paul Dwerryhouse (paul@dwerryhouse.com.au) on March 14th, 2003. +# + # Contains some global routines used throughout the CGI scripts of Bugzilla. use diagnostics; @@ -36,8 +41,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. @@ -625,15 +630,15 @@ # 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 +662,7 @@ 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 +673,8 @@ 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 +691,9 @@ } # 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 +705,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->code()) { print "Content-type: text/html\n\n"; PutHeader("Login Failed"); print "The username or password you entered is not valid.\n"; @@ -712,8 +723,10 @@ # 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 +738,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 +749,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);