[Openupload-svn-update] SF.net SVN: openupload:[77] trunk/lib/modules/auth/ldap.inc.php
Status: Beta
Brought to you by:
tsdogs
|
From: <ts...@us...> - 2008-10-24 09:48:29
|
Revision: 77
http://openupload.svn.sourceforge.net/openupload/?rev=77&view=rev
Author: tsdogs
Date: 2008-10-24 09:45:48 +0000 (Fri, 24 Oct 2008)
Log Message:
-----------
some normalization
Modified Paths:
--------------
trunk/lib/modules/auth/ldap.inc.php
Modified: trunk/lib/modules/auth/ldap.inc.php
===================================================================
--- trunk/lib/modules/auth/ldap.inc.php 2008-10-24 09:32:52 UTC (rev 76)
+++ trunk/lib/modules/auth/ldap.inc.php 2008-10-24 09:45:48 UTC (rev 77)
@@ -14,29 +14,44 @@
$this->features = array('useradmin' => 'no', 'groupadmin' => 'no');
}
+ function connect() {
+ $this->ds=@ldap_connect($this->config['host']);
+ if ($this->ds) {
+ @ldap_set_option($this->ds, LDAP_OPT_PROTOCOL_VERSION, 3);
+ return true;
+ }
+ return false;
+ }
+
+ function disconnect() {
+ @ldap_close($this->ds);
+ }
+
+ function bind() {
+ if (@ldap_bind($this->ds, $this->config['user'],$this->config['password']) )
+ return true;
+ return false;
+ }
+
function authenticate($login,$password) {
- $ds=ldap_connect($this->config['host']);
- if ($ds) {
+ if ($this->connect()) {
$uid = $this->ufield.'='.$login.','.$this->config['userdn'];
- if (ldap_bind($ds, $uid, $password) ) {
- /* authentication was successfull, save username and password for additional info */
- $this->uid = $uid;
- $this->password = $password;
+ if (@ldap_bind($this->ds, $uid, $password)) {
return true;
}
- ldap_close($ds);
+ $this->disconnect();
}
return false;
}
function userinfo($login) {
- $ds=@ldap_connect($this->config['host']);
+
$result = array();
- if (ldap_bind($ds, $this->config['user'],$this->config['password']) ) {
- $r = @ldap_search($ds, $this->config['userdn'],
+ if ($this->connect() and $this->bind()) {
+ $r = @ldap_search($this->ds, $this->config['userdn'],
'(&('.$this->ufield.'='.$login.')(objectclass='.$this->config['userclass'].'))');
if ($r) {
- $res = @ldap_get_entries($ds, $r);
+ $res = @ldap_get_entries($this->ds, $r);
/* associate user fields */
$res = $res[0];
foreach ($this->config['userfields'] as $n => $f) {
@@ -44,10 +59,10 @@
}
}
/* now retrieve the main group */
- $r = @ldap_search($ds, $this->config['groupdn'],
+ $r = @ldap_search($this->ds, $this->config['groupdn'],
'(&('.$this->gfield.'='.$result['group_id'].')(objectclass='.$this->config['groupclass'].'))');
if ($r) {
- $res = @ldap_get_entries($ds, $r);
+ $res = @ldap_get_entries($this->ds, $r);
/* associate user fields */
$res = $res[0];
foreach ($this->config['groupfields'] as $n => $f) {
@@ -58,10 +73,10 @@
}
if (isset($this->config['sgid'])) {
$result['group'] = array($result['group']);
- $r = @ldap_search($ds, $this->config['groupdn'],
+ $r = @ldap_search($this->ds, $this->config['groupdn'],
'(&('.$this->config['sgid'].'='.$result['login'].')(objectclass='.$this->config['groupclass'].'))');
if ($r) {
- $res = @ldap_get_entries($ds, $r);
+ $res = @ldap_get_entries($this->ds, $r);
for ($i = 0; $i<$res['count']; $i++) {
foreach ($this->config['sgroupfields'] as $n => $f) {
if ($f == 'name') {
@@ -72,30 +87,31 @@
}
}
}
- ldap_close($ds);
+ $this->disconnect();
return $result;
}
function groupinfo($group = '') {
- $ds=@ldap_connect($this->config['host']);
$result = array();
- @ldap_bind($ds, $this->config['user'], $this->config['password']);
- if (group != '') {
- $r = @ldap_search($ds, $this->config['groupdn'],'(objectclass='.$this->config['groupclass'].')');
- } else {
- $r = @ldap_search($ds, $this->config['groupdn'],
- '(&('.$this->gfield.'='.$group.')(objectclass='.$this->config['groupclass'].'))');
- }
- if ($r) {
- $res = @ldap_get_entries($ds, $r);
- /* associate user fields */
- for ($i = 0; $i<$res['count']; $i++) {
- foreach ($this->config['sgroupfields'] as $n => $f) {
- $result[$i][$f] = $res[$i][$n][0];
+ if ($this->connect()) {
+ $this->bind();
+ if (group != '') {
+ $r = @ldap_search($this->ds, $this->config['groupdn'],'(objectclass='.$this->config['groupclass'].')');
+ } else {
+ $r = @ldap_search($this->ds, $this->config['groupdn'],
+ '(&('.$this->gfield.'='.$group.')(objectclass='.$this->config['groupclass'].'))');
+ }
+ if ($r) {
+ $res = @ldap_get_entries($this->ds, $r);
+ /* associate user fields */
+ for ($i = 0; $i<$res['count']; $i++) {
+ foreach ($this->config['sgroupfields'] as $n => $f) {
+ $result[$i][$f] = $res[$i][$n][0];
+ }
}
}
+ $this->disconnect();
}
- ldap_close($ds);
return $result;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|