*
'ldap.example.com' - connect to server on ldap.example.com address
* 'ldaps://ldap.example.com' - connect to server on ldap.example.com address
* and use SSL encrypted connection to default LDAPs port.
*
* defaults to imap server address.
* @link http://www.php.net/ldap-connect
* @global string $cpw_ldap_server
*/
global $cpw_ldap_server;
$cpw_ldap_server=$imapServerAddress;
/**
* Port of LDAP server.
* Used only when $cpw_ldap_server specifies IP address or DNS name.
* @global integer $cpw_ldap_port
*/
global $cpw_ldap_port;
$cpw_ldap_port=389;
/**
* LDAP basedn that is used for binding to LDAP server.
* this option must be set to correct value.
* @global string $cpw_ldap_basedn;
*/
global $cpw_ldap_basedn;
$cpw_ldap_basedn='';
/**
* LDAP connection options
* @link http://www.php.net/ldap-set-option
* @global array $cpw_ldap_connect_opts
*/
global $cpw_ldap_connect_opts;
$cpw_ldap_connect_opts=array();
/**
* Controls use of starttls on LDAP connection.
* Requires PHP 4.2+, PHP LDAP extension with SSL support and
* PROTOCOL_VERSION => 3 setting in $cpw_ldap_connect_opts
* @global boolean $cpw_ldap_use_tls
*/
global $cpw_ldap_use_tls;
$cpw_ldap_use_tls=false;
/**
* BindDN that should be able to search LDAP directory and find DN used by user.
* Uses anonymous bind if set to empty string. You should not use DN with write
* access to LDAP directory here. Write access is not required.
* @global string $cpw_ldap_binddn
*/
global $cpw_ldap_binddn;
$cpw_ldap_binddn='';
/**
* password used for $cpw_ldap_binddn
* @global string $cpw_ldap_bindpw
*/
global $cpw_ldap_bindpw;
$cpw_ldap_bindpw='';
/**
* BindDN that should be able to change password.
* WARNING: sometimes user has enough privileges to change own password.
* If you leave default value, plugin will try to connect with DN that
* is detected in $cpw_ldap_username_attr=$username search and current
* user password will be used for authentication.
* @global string $cpw_ldap_admindn
*/
global $cpw_ldap_admindn;
$cpw_ldap_admindn='';
/**
* password used for $cpw_ldap_admindn
* @global string $cpw_ldap_adminpw
*/
global $cpw_ldap_adminpw;
$cpw_ldap_adminpw='';
/**
* LDAP attribute that stores username.
* username entry should be unique for $cpw_ldap_basedn
* @global string $cpw_ldap_userid_attr
*/
global $cpw_ldap_userid_attr;
$cpw_ldap_userid_attr='uid';
/**
* crypto that is used to encode new password
* If set to empty string, system tries to keep same encoding/hashing algorithm
* @global string $cpw_ldap_default_crypto
*/
global $cpw_ldap_default_crypto;
$cpw_ldap_default_crypto='';
/** end of default config */
/** configuration overrides from config file */
if (isset($cpw_ldap['server'])) $cpw_ldap_server=$cpw_ldap['server'];
if (isset($cpw_ldap['port'])) $cpw_ldap_port=$cpw_ldap['port'];
if (isset($cpw_ldap['basedn'])) $cpw_ldap_basedn=$cpw_ldap['basedn'];
if (isset($cpw_ldap['connect_opts'])) $cpw_ldap_connect_opts=$cpw_ldap['connect_opts'];
if (isset($cpw_ldap['use_tls'])) $cpw_ldap_use_tls=$cpw_ldap['use_tls'];
if (isset($cpw_ldap['binddn'])) $cpw_ldap_binddn=$cpw_ldap['binddn'];
if (isset($cpw_ldap['bindpw'])) $cpw_ldap_bindpw=$cpw_ldap['bindpw'];
if (isset($cpw_ldap['admindn'])) $cpw_ldap_admindn=$cpw_ldap['admindn'];
if (isset($cpw_ldap['adminpw'])) $cpw_ldap_adminpw=$cpw_ldap['adminpw'];
if (isset($cpw_ldap['userid_attr'])) $cpw_ldap_userid_attr=$cpw_ldap['userid_attr'];
if (isset($cpw_ldap['default_crypto'])) $cpw_ldap_default_crypto=$cpw_ldap['default_crypto'];
/** make sure that setting does not contain mapping */
$cpw_ldap_server=sqimap_get_user_server($cpw_ldap_server,$username);
/**
* Adding plugin hooks
*/
global $squirrelmail_plugin_hooks;
$squirrelmail_plugin_hooks['change_password_dochange']['ldap'] =
'cpw_ldap_dochange';
$squirrelmail_plugin_hooks['change_password_init']['ldap'] =
'cpw_ldap_init';
/**
* Makes sure that required functions and configuration options are set.
*/
function cpw_ldap_init() {
global $color;
global $cpw_ldap_basedn;
// set initial value for error tracker
$cpw_ldap_initerr=false;
// check for ldap support in php
if (! function_exists('ldap_connect')) {
error_box(_("Current configuration requires LDAP support in PHP."),$color);
$cpw_ldap_initerr=true;
}
// chech required configuration settings.
if ($cpw_ldap_basedn=='') {
error_box(_("Plugin is not configured correctly."),$color);
$cpw_ldap_initerr=true;
}
// if error var is positive, close html and stop execution
if ($cpw_ldap_initerr) {
echo '