XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
auth_ads.php
Go to the documentation of this file.
1 <?php
21 defined('XOOPS_ROOT_PATH') or die('Restricted access');
22 
31 include_once $GLOBALS['xoops']->path('class/auth/auth_ldap.php');
32 
43 {
47  function XoopsAuthAds(&$dao)
48  {
49  parent::XoopsAuthLdap($dao);
50  }
51 
62  function authenticate($uname, $pwd = null)
63  {
64  $authenticated = false;
65  if (!extension_loaded('ldap')) {
66  $this->setErrors(0, _AUTH_LDAP_EXTENSION_NOT_LOAD);
67  return $authenticated;
68  }
69  $this->_ds = ldap_connect($this->ldap_server, $this->ldap_port);
70  if ($this->_ds) {
71  ldap_set_option($this->_ds, LDAP_OPT_PROTOCOL_VERSION, $this->ldap_version);
72  ldap_set_option($this->_ds, LDAP_OPT_REFERRALS, 0);
73  if ($this->ldap_use_TLS) { // We use TLS secure connection
74  if (!ldap_start_tls($this->_ds)) {
75  $this->setErrors(0, _AUTH_LDAP_START_TLS_FAILED);
76  }
77  }
78  // If the uid is not in the DN we proceed to a search
79  // The uid is not always in the dn
80  $userUPN = $this->getUPN($uname);
81  if (!$userUPN) {
82  return false;
83  }
84  // We bind as user to test the credentials
85  $authenticated = ldap_bind($this->_ds, $userUPN, $this->cp1252_to_utf8(stripslashes($pwd)));
86  if ($authenticated) {
87  // We load the Xoops User database
88  $dn = $this->getUserDN($uname);
89  if ($dn) {
90  return $this->loadXoopsUser($dn, $uname, $pwd);
91  } else {
92  return false;
93  }
94  } else {
95  $this->setErrors(ldap_errno($this->_ds), ldap_err2str(ldap_errno($this->_ds)) . '(' . $userUPN . ')');
96  }
97  } else {
98  $this->setErrors(0, _AUTH_LDAP_SERVER_NOT_FOUND);
99  }
100  @ldap_close($this->_ds);
101  return $authenticated;
102  }
103 
112  function getUPN($uname)
113  {
114  $userDN = $uname . '@' . $this->ldap_domain_name;
115  return $userDN;
116  }
117 } // end class
118 
119 ?>