Source for file auth.php
Documentation is available at auth.php
require_once (UTIL_PKG_PATH. "pear/Auth/Auth.php");
// THIS may need changing if a different PEAR installation is used
include_once("Auth/Auth.php");
* Class that manages the PEAR:ldap autentication method
function validate($user,$pass,$challenge,$response) {
parent::validate($user,$pass,$challenge,$response);
if ( empty($user) or empty($pass) ) {
$this->mInfo["real_name"] = ''; // This needs fixing in the base code - real_name will only exist if a user has been identiied
// Use V3, which requires UTF-8:
// Skip the SSL certificate check:
// (This assumes PHP is using the OpenLDAP client library.)
putenv('LDAPTLS_REQCERT=never');
if ( $this->mConfig['activedirectory'] ) {
$this->mConfig['attributes'] = (array) null;
$this->mConfig['userfilter'] = '(objectClass='. $this->mConfig['useroc']. ')';
$this->mConfig['groupfilter'] = '(objectClass='. $this->mConfig['groupoc']. ')';
// Using bitweaver groups with LDAP still needs completing so disable for now
$a = new Auth('LDAP', $this->mConfig, "", false);
$a->_loadStorage(); // set up connection to ldap via user details
// First, try by username. If that fails, try by email address.
$success = $a->storage->fetchData($user_utf8, $pass, false);
// The user wasn't found. Try again by email address:
$this->mConfig['userattrsto'] = $this->mConfig['userattr']; // Keep this for later
$this->mConfig['userattr'] = $this->mConfig['email']; // Tell PEAR::Auth() to look at the 'mail' attribute
// this needs testing better, should be no need to create second instance of Auth!
$a = new Auth('LDAP', $this->mConfig, "", false);
$a->_loadStorage(); // set up connection to ldap via user details
$success = $a->storage->fetchData($user_utf8, $pass, false);
$this->mErrors['login'] = isset ($a->storage->options['status']) ? $a->storage->options['status'] : 'Not authenticated';
// At this point, there was a successful ldap_bind() using the
// user's Distinguished Name (DN) and password for login.
// The call to ldap_get_attributes() has been saved into $a->getAuthData('attributes')
if ( $this->mConfig['activedirectory'] ) {
// Active Directory does some things differently - mainly in the returns
$attributes = $a->getAuthData();
// Warning: ldap_get_attributes() uses case-sensitive array keys
$this->mInfo["login"] = $attributes[ $this->mConfig['userattr'] ];
$this->mInfo["email"] = $attributes[ $this->mConfig['email'] ];
$this->mInfo["real_name"] = empty($attributes[$this->mConfig['name']]) ? $this->mInfo["login"] : $attributes[$this->mConfig['name']];
$attributes = $a->getAuthData('attributes');
// Warning: ldap_get_attributes() uses case-sensitive array keys
$this->mInfo["login"] = $attributes[ $this->mConfig['userattr'] ][0];
$this->mInfo["email"] = $attributes[ $this->mConfig['email'] ][0];
$this->mInfo["real_name"] = empty($attributes[$this->mConfig['name']][0]) ? $this->mInfo["login"] : $attributes[$this->mConfig['name']][0];
// Note, the new (or updated) SQL user will be created by the calling BitUser class.
$this->mErrors['support']= tra("LDAP Authentication is not supported as PEAR Package Auth is not availible.");
$this->mErrors['support']= tra("LDAP Authentication is not supported as PHP LDAP Extention not loaded.");
// create a new user in the Auth directory
// set additional attributes here
if (empty($userattr["email"])) {
$userattr["email"] = $gBitDb->getOne("select `email` from `". BIT_DB_PREFIX. "users_users` where `login`=?", array($userattr["login"]));
$a = new Auth("LDAP", $this->mConfig);
// check if the login correct
if ($a->addUser($userattr["login"], $userattr["password"], $userattr) === true) {
// otherwise use the error status given back
$this->mErrors['create'] = $a->getStatus();
// Roles are not inteneded to match with ldap groups
// This area needs a closer look if it needs to be used
if ( !defined ('ROLE_MODEL') ) $groups = $gBitUser->getAllGroups($listHash);
foreach ($groups as $g) {
$groupsD[$g['group_id']]= "{ $g['group_name']} ( {$g['group_desc']} )";
'users_ldap_url' => array(
'label' => "LDAP Connection URL",
'note' => "You can specify an LDAP URL, like ldap://localhost/ or ldaps://some-server/.",
'users_ldap_host' => array(
'note' => "Instead of a URL, you can specify a hostname and port explicitly. Give either a URL, or else a hostname/port (but not both).",
'default' => 'localhost',
'users_ldap_port' => array(
'users_ldap_start_tls' => array(
'label' => "Use Start-TLS?",
'note' => "Please note there is a difference between ldaps:// and Start-TLS for ldap. Start-TLS uses port 389, while ldaps:// uses port 636. Both encrypted LDAP (with Start-TLS) and unencrypted LDAP can run on port 389 concurrently.",
'users_ldap_reqcert' => array(
'label' => "Skip the SSL Cert validation?",
'note' => "If Start-TLS is checked, then your LDAP server needs a trusted SSL cert -- unless you check this option, in which case you can use a self-signed (untrusted) cert.",
'users_ldap_referrals' => array(
'label' => "Use Referrals?",
'note' => "This should probably be 'yes'. (Only applies to LDAP V3 servers.)",
'users_ldap_basedn' => array(
'label' => "LDAP Base DN",
'users_ldap_userdn' => array(
'label' => "LDAP User DN",
'users_ldap_userattr' => array(
'label' => "LDAP User Attribute",
'note' => "The LDAP Attribute to use for the user's login in Bitweaver. (This is the first attribute searched when the user logs in.)",
'users_ldap_email' => array(
'label' => "LDAP User E-Mail Address",
'note' => "The LDAP Attribute to use for the user's email address in Bitweaver. (This is the second attribute searched when the user logs in.)",
'users_ldap_name' => array(
'label' => "LDAP User Display Name",
'note' => "The LDAP Attribute to use for the user's Full Name in Bitweaver.",
'default' => 'displayName',
'users_ldap_useroc' => array(
'label' => "LDAP User OC",
'default' => '(objectClass=inetOrgPerson)',
'users_ldap_groupdn' => array(
'label' => "LDAP Group DN",
'users_ldap_groupattr' => array(
'label' => "LDAP Group Atribute",
'users_ldap_groupoc' => array(
'label' => "LDAP Group OC",
'default' => '(objectClass=groupOfUniqueNames)',
'users_ldap_memberattr' => array(
'label' => "LDAP Member Attribute",
'default' => 'uniqueMember',
'users_ldap_memberisdn' => array(
'label' => "LDAP Member Is DN",
'users_ldap_binddn' => array(
'label' => "LDAP Bind DN",
'note' => "This DN will be used to search the LDAP directory for users. If left blank, 'anonymous bind' is used.",
'users_ldap_bindpw' => array(
'label' => "LDAP Bind Pwd",
'users_ldap_userscope' => array(
'label' => "LDAP Scope to use when searching for users",
'users_ldap_group' => array(
'label' => "LDAP Group Requirement",
'note' => "If this is specified, then the LDAP user must also be a member of this LDAP group to connect.",
'users_ldap_activedirectory' => array(
'label' => "Active Directory?",
|