/[docman]/htusers_ldap.php
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /htusers_ldap.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by dpavlin, Fri Feb 15 09:54:05 2002 UTC revision 1.2 by dpavlin, Wed Jan 8 16:38:58 2003 UTC
# Line 7  Line 7 
7                  Belenos INC                  Belenos INC
8                  For use with the DocMgr PHP scripts                  For use with the DocMgr PHP scripts
9    
10                    Modified by Benjamin Baez (bbaez@biospectra.com) 2002-12-03
11    
12          arguments in docman.conf file are:          arguments in docman.conf file are:
13          $ldapServer="x.x.x.x";          This can be in Dotted Notation or a DNS FQN          $ldapServer="x.x.x.x";          This can be in Dotted Notation or a DNS FQN
14          $ldapServerPort="389";          This is the default port and doesnt need to be changed          $ldapServerPort="389";          This is the default port and doesnt need to be changed
15          $basedn="o=CompanyName";        Branch of tree that your search will start on          $basedn="o=CompanyName";        Branch of tree that your search will start on
16    
17            If you don't enter following two parameters, it
18            will use credentials of user which is logged in!
19            
20          $bind="cn=Manager, o=CompanyName";      Login that allows password searching          $bind="cn=Manager, o=CompanyName";      Login that allows password searching
21          $bindpw="";                     Password for the above account          $bindpw="";                     Password for the above account
22    
# Line 31  Line 37 
37    
38  */  */
39    
40  if ($ds = ldap_connect_bind($bind, $bindpw, $ldapServer, $ldapServerPort)) {  // use hard-coded bind variables in docman.conf
41   $sres = ldap_search($ds, $basedn, "uid=".$PHP_AUTH_USER);  if (isset($bind) && isset($bindpw)) {
42   If ($sres) {          $ds = ldap_connect_bind($bind, $bindpw, $ldapServer, $ldapServerPort)) {
43       $entries = ldap_get_entries($ds, $sres);          $sres = ldap_search($ds, $basedn, "uid=".$PHP_AUTH_USER);
44       $gblUserName = $entries[0]["cn"][0]; //Full Name          If ($sres) {
45       $gblPw       = $entries[0]["userpassword"][0]; //Password                  $entries = ldap_get_entries($ds, $sres);
46       $gblEmail    = $entries[0]["mail"][0];  //Email                  $gblUserName = $entries[0]["cn"][0]; //Full Name
47   }else{                  $gblPw       = $entries[0]["userpassword"][0]; //Password
48       Error("Not Found","LDAP Search returned false");                  $gblEmail    = $entries[0]["mail"][0];  //Email
49   }          } else {
50   ldap_close($ds);                  Error("Not Found","LDAP Search returned false");
51            }
52            ldap_close($ds);
53    // use crednetials of user which is currently logged in
54    } elseif (isset($PHP_AUTH_PW)) { // This is required so that auth dialog appears
55            if ($ds = ldap_connect_bind($PHP_AUTH_USER, $PHP_AUTH_PW, $ldapServer, $ldapServerPort, $basedn)) {
56                    $sres = ldap_search($ds, $basedn, "uid=".$PHP_AUTH_USER);
57                    if ($sres) {
58                            $entries = ldap_get_entries($ds, $sres);
59                            $gblUserName = $entries[0]["cn"][0]; //Full Name
60                            $gblPw       = md5($PHP_AUTH_USER.$PHP_AUTH_PW); //Password format for Web Server
61                            $gblEmail    = $entries[0]["mail"][0];  //Email
62                    } else {
63                            Error("Not Found","LDAP Search returned false");
64                    }
65                    ldap_close($ds);
66            }
67  }  }
68    
69    
70  function ldap_connect_bind($bindRDN, $bindpass, $ldapServer, $ldapServerPort) {  function ldap_connect_bind($bindDN_or_user, $passwd, $ldapServer, $ldapServerPort, $basedn) {
71       $linkid = ldap_connect($ldapServer, $ldapServerPort);          $linkid = ldap_connect($ldapServer, $ldapServerPort);
72       if ($linkid) {          if (isset($basedn)) {
73         if (!ldap_bind($linkid, $bindRDN, $bindpass)) {                  // make a username to bind DN
74            Error("LDAP BIND","Unable to bind to LDAP server!");                  $bindDN_or_user = "uid=".$bindDN_or_user.",".$basedn;
75            return 0;          }
76         } else {          if ($linkid) {
77           return $linkid;                  if (!@ldap_bind($linkid, $bindDN_or_user, $passwd)) {
78         }                          Error("LDAP BIND","Unable to bind to LDAP server!");
79       } else {                          return 0;
80         Error("LDAP CONNECT","Unable to connect to LDAP server!");                  } else {
81         return 0;                          return $linkid;
82       }                  }
83            } else {
84                    Error("LDAP CONNECT","Unable to connect to LDAP server!");
85                    return 0;
86            }
87  }  }
88  ?>  ?>

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.26