[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

mantis ldap active directory

Posted on 2009-04-27
4
Medium Priority
?
1,401 Views
Last Modified: 2013-12-24
i am geting errror  in ldap_bind functin

ldap_bind() [function.ldap-bind]: Unable to bind to server: Can't contact LDAP server in
<? 
$server="10.202.1.41";    //change to ip address of ldap server 
$basedn="cn=tarun sadan tiwari(243917),dc=example,dc=com";    //change to reflect the ou 
$script=$_SERVER['SCRIPT_NAME']; 
if (isset($HTTP_COOKIE_VARS['cookie'])) {       //If cookie exists, retrieve it and 
    $cookie=$HTTP_COOKIE_VARS['cookie']; 
    } 
if (isset($cookie)) {  
 
                
    $username=$cookie['user']; 
    
    $password=($cookie['token']);
     
    $fullname=$cookie['fullname'];
     
    $fqdn=$cookie['fqdn'];
     
    $dn = "cn=$username, "; 
    
    
        if (!($connect = ldap_connect($server))) { 
            die ("Could not connect to LDAP server"); 
        } 
 
        if (!($bind = ldap_bind($connect, "$dn" . "$basedn", $password))) { 
                   die ("Could not bind to $dn$basedn"); 
        } 
    } else { 
        if ((isset($_POST['username'])) && (isset($_POST['password']))) { 
            $username=$_POST['username']; 
            $password=$_POST['password']; 
           /*$filter="(&(|(!(displayname=Tarun*))(! 
(displayname=Tiwari)))(cn=$username))";*/   //define an appropriate ldap search filter 
            $dn = "cn=$username, "; 
                if (!($connect = ldap_connect($server))) { 
                    die ("Could not connect to LDAP server"); 
                } 
echo $connect.$dn.$basedn;
                if (!($bind = ldap_bind($connect, "$dn" . "$basedn", 
$password))) { 
                    die ("Could not bind to $dn"); 
                } 
                echo $connect;
       $sr = ldap_search($connect, $basedn,"$filter"); 
       // $sr = ldap_search($connect,"OU=orginizational unit,DC=domain,DC=com", "");
        $info = ldap_get_entries($connect, $sr); 
        $fullname=$info[0]["displayname"][0]; 
        $fqdn=$info[0]["dn"]; 
        setcookie("cookie[user]",$username); 
        setcookie("cookie[token]",$password); 
        setcookie("cookie[fullname]",$fullname); 
        setcookie("cookie[fqdn]", $fqdn); 
    } else { 
?> 
 
 
<html> 
<head> 
<title>Portal Login</title> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> 
<meta http-equiv="expires" content="0"> 
<meta http-equiv="pragma" content="no-cache"> 
</head> 
<SCRIPT LANGUAGE="JavaScript"> 
    <!-- 
        document.onmousedown=click; 
        function click() 
        { 
            if (event.button==2) {alert('Right-clicking has been 
disabled by 
the administrator.');} 
        } 
         
    //--> 
    </SCRIPT> 
<div align="center"> 
  <form method="post" action="<? echo $script; ?>"> 
         <div align="center"> 
             
             <table width="210" border="0" cellspacing="0" cellpadding="0"> 
              <tr> 
              <td align="center"> 
              <fieldset> 
                 <Legend><font face="Verdana,Tahoma,Arial,sans-serif" size="1" 
color="gray">Enter Credentials</font></Legend> 
                    <table border="0" cellspacing="3" cellpadding="0"> 
                     <tr> 
                        <td align="right" valign="middle"><b><font 
face="Verdana,Tahoma,Arial,sans- 
serif" size="1" color="gray">Username:</font></td> 
                        <td align="center" valign="middle"> 
                          <input class="clear" type="text" size="15" name="username"> 
                        </td> 
                      </tr> 
                      <tr> 
                        <td align="right" valign="middle"><b><font 
face="Verdana,Tahoma,Arial,sans- 
serif" size="1" color="gray">Password:</font></td> 
                        <td align="center" valign="middle"> 
                          <input class="pass" type="password" size="15" 
name="password"> 
                        </td> 
                      </tr> 
                      </table> 
                    <input type=image src="images/login.gif" alt="Login" 
name="image"> 
                    <br> 
                  </div> 
                </td> 
               </tr> 
           </fieldset>              
             </table> 
             <br> 
             <table width="640"><tr><td align="center"> 
             <font face="Verdana,Tahoma,Arial,sans-serif" size="1" 
color="silver">This System is 
for the use of authorized users only.  Individuals using this computer system 
without 
authority, or in excess of their authority, are subject to having their activities 
on this system 
monitored and recorded by system personnel.  In the course of monitoring individuals 
improperly using this system, or in the course of system maintenance, the activities 
of 
authorized users may also be monitored. Anyone using this system expressly consents 
to 
such monitoring and is advised that if such monitoring reveals possible criminal 
activity, 
system personnel may provide the evidence of such monitoring to law enforcement 
officals. 
This warning has been provided by the United States Department of Justice and is 
intended to 
ensure that monitoring of user activity is not in violation of the Communications 
Privacy Act of 
1986.</font> 
          </td></tr></table> 
             
          </div> 
  </form> 
 
</div> 
</body> 
</html> 
<? 
die (); 
} 
} 
?>

Open in new window

0
Comment
Question by:taruntiwari
  • 2
4 Comments
 
LVL 3

Assisted Solution

by:a_ro_no
a_ro_no earned 300 total points
ID: 24248696
Does this program run on a windows machine? If yes,I dont see a reason why you hardcode an ldap server ip address, you should use serverless bind instead. Btw did you try with the FQDN of the server?
0
 
LVL 71

Accepted Solution

by:
Chris Dent earned 450 total points
ID: 24248700

Verify that the server running this code can connect to Port 389 on the server specified. Telnet can be used to test that:

telnet 10.202.1.41 389

Success is indicated by a blank screen, failure by it saying the connection failed.

Chris
0
 

Author Closing Comment

by:taruntiwari
ID: 31575318
still not able to make mantis user to authenticate.
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 24248978

Why did you close the question then? :)

Has it successfully connected now?

I'm not convinced this value can be correct:

$basedn="cn=tarun sadan tiwari(243917),dc=example,dc=com"

If it's an OU then the prefix is OU= not CN=. e.g.

$basedn = "ou=tarun sadan tiwari(243917),dc=example,dc=com"

What value are you giving to this?

$dn = "cn=$username

If find the way it builds the authentication string to be pretty crap, I would change that. At the moment the user used to create the connection has to live in the same OU as the search base.

Chris
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I’ll look at how you can use a backup to start a secondary instance for MongoDB.
How much do you know about the future of data centers? If you're like 50% of organizations, then it's probably not enough. Read on to get up to speed on this emerging field.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question