added search_domains() function
This commit is contained in:
parent
fc071a1407
commit
1512734ac1
|
@ -25,6 +25,7 @@ $Id$
|
|||
|
||||
include_once("config.inc");
|
||||
|
||||
// manages connection to LDAP and several helper functions
|
||||
class Ldap{
|
||||
|
||||
// object of Config to access preferences
|
||||
|
@ -158,6 +159,33 @@ class Ldap{
|
|||
return $ret;
|
||||
}
|
||||
|
||||
// returns an array with all Samba 3 domain entries under the given suffix
|
||||
function search_domains($suffix) {
|
||||
$ret = array();
|
||||
$attr = array("DN", "sambaDomainName", "sambaSID", "sambaNextRid", "sambaNextGroupRid",
|
||||
"sambaNextUserRid", "sambaAlgorithmicRidBase");
|
||||
$sr = @ldap_search($_SESSION["ldap"]->server(), $suffix, "sambaDomainName=*", $attr);
|
||||
if ($sr) {
|
||||
$units = ldap_get_entries($_SESSION["ldap"]->server, $sr);
|
||||
// delete count entry
|
||||
array_shift($units);
|
||||
// extract attributes
|
||||
for ($i = 0; $i < sizeof($units); $i++) {
|
||||
$ret[$i] = new samba3domain();
|
||||
$ret[$i]->dn = $units[$i]['dn'];
|
||||
$ret[$i]->name = $units[$i]['sambadomainname'][0];
|
||||
$ret[$i]->SID = $units[$i]['sambasid'][0];
|
||||
$ret[$i]->nextRID = $units[$i]['sambanextrid'][0];
|
||||
$ret[$i]->nextGroupRID = $units[$i]['sambanextgrouprid'][0];
|
||||
$ret[$i]->nextUserRID = $units[$i]['sambanextuserrid'][0];
|
||||
if (isset($units[$i]['sambaalgorithmicridbase'][0])) $ret[$i]->RIDbase = $units[$i]['sambaalgorithmicridbase'][0];
|
||||
}
|
||||
// sort array by domain name
|
||||
usort($ret, array($this,"cmp_domain"));
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
// returns the LDAP connection handle
|
||||
function server() {
|
||||
return $this->server;
|
||||
|
@ -249,7 +277,40 @@ class Ldap{
|
|||
else return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// helper function to sort the domains
|
||||
function cmp_domain($a, $b) {
|
||||
if ($a->name == $b->name) return 0;
|
||||
elseif ($a->name == max($a->name, $b->name)) return 1;
|
||||
else return -1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// represents a Samba 3 domain entry
|
||||
class samba3domain {
|
||||
|
||||
// DN
|
||||
var $dn;
|
||||
|
||||
// domain name
|
||||
var $name;
|
||||
|
||||
// domain SID
|
||||
var $SID;
|
||||
|
||||
// next RID
|
||||
var $nextRID;
|
||||
|
||||
// next user RID
|
||||
var $nextUserRID;
|
||||
|
||||
// next group RID
|
||||
var $nextGroupRID;
|
||||
|
||||
// RID base to calculate RIDs, default 1000
|
||||
var $RIDbase=1000;
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue