moved Samba 3 domain object to account.inc
This commit is contained in:
parent
b9fe20574f
commit
2ed32f3ca0
|
@ -341,4 +341,79 @@ function pwd_is_enabled($hash) {
|
|||
else return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array with all Samba 3 domain entries under the given suffix
|
||||
*
|
||||
* @param string $suffix search suffix
|
||||
* @return array list of samba3domain objects
|
||||
*/
|
||||
function search_domains($suffix) {
|
||||
$ret = array();
|
||||
$attr = array("DN", "sambaDomainName", "sambaSID", "sambaNextRid", "sambaNextGroupRid",
|
||||
"sambaNextUserRid", "sambaAlgorithmicRidBase");
|
||||
$sr = @ldap_search($_SESSION['ldap']->server(), $suffix, "objectClass=sambaDomain", $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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to sort the domains
|
||||
*
|
||||
* @param string $a first argument to compare
|
||||
* @param string $b second argument to compare
|
||||
* @return integer 0 if equal, 1 if $a is greater, -1 if $b is greater
|
||||
*/
|
||||
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
|
||||
*
|
||||
* @package modules
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -139,26 +139,6 @@ class Ldap{
|
|||
@ldap_close($this->server);
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches LDAP for a specific user name and returns its DN entry
|
||||
*
|
||||
* @param string $name user name
|
||||
* @return string DN
|
||||
*/
|
||||
function search_username($name) {
|
||||
$filter = "(uid=$name)";
|
||||
$attrs = array();
|
||||
$sr = @ldap_search($this->server, $this->conf->get_UserSuffix(), $filter, $attrs);
|
||||
if ($sr) {
|
||||
$info = ldap_get_entries($this->server, $sr);
|
||||
// return only first DN entry
|
||||
$ret = $info[0]["dn"];
|
||||
ldap_free_result($sr);
|
||||
return $ret;
|
||||
}
|
||||
else return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array with all organizational units under the given suffix
|
||||
*
|
||||
|
@ -190,38 +170,6 @@ class Ldap{
|
|||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array with all Samba 3 domain entries under the given suffix
|
||||
*
|
||||
* @param string $suffix search suffix
|
||||
* @return array list of samba3domain objects
|
||||
*/
|
||||
function search_domains($suffix) {
|
||||
$ret = array();
|
||||
$attr = array("DN", "sambaDomainName", "sambaSID", "sambaNextRid", "sambaNextGroupRid",
|
||||
"sambaNextUserRid", "sambaAlgorithmicRidBase");
|
||||
$sr = @ldap_search($this->server(), $suffix, "objectClass=sambaDomain", $attr);
|
||||
if ($sr) {
|
||||
$units = ldap_get_entries($this->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;
|
||||
}
|
||||
|
||||
/** Reads the array of objectClasses from the LDAP server */
|
||||
function updateClasses() {
|
||||
// read from default cn
|
||||
|
@ -309,7 +257,7 @@ class Ldap{
|
|||
*/
|
||||
function encrypt($data) {
|
||||
// use MCrypt if available
|
||||
if (function_exists(mcrypt_create_iv)) {
|
||||
if (function_exists('mcrypt_create_iv')) {
|
||||
// read key and iv from cookie
|
||||
$iv = base64_decode($_COOKIE["IV"]);
|
||||
$key = base64_decode($_COOKIE["Key"]);
|
||||
|
@ -336,7 +284,7 @@ class Ldap{
|
|||
*/
|
||||
function decrypt($data) {
|
||||
// use MCrypt if available
|
||||
if (function_exists(mcrypt_create_iv)) {
|
||||
if (function_exists('mcrypt_create_iv')) {
|
||||
// read key and iv from cookie
|
||||
$iv = base64_decode($_COOKIE["IV"]);
|
||||
$key = base64_decode($_COOKIE["Key"]);
|
||||
|
@ -424,49 +372,7 @@ class Ldap{
|
|||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to sort the domains
|
||||
*
|
||||
* @param string $a first argument to compare
|
||||
* @param string $b second argument to compare
|
||||
* @return integer 0 if equal, 1 if $a is greater, -1 if $b is greater
|
||||
*/
|
||||
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
|
||||
*
|
||||
* @package LDAP
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -97,6 +97,7 @@ class sambaGroupMapping extends baseModule {
|
|||
'required' => false
|
||||
)
|
||||
);
|
||||
$return['upload_preDepends'] = array('posixGroup');
|
||||
// help Entries
|
||||
$return['help'] = array ( 'displayName' => array ("ext" => "FALSE", "Headline" => _("Display name"), "Text" => _("Windows clients will show display name as group description.")),
|
||||
'sambaSID' => array ("ext" => "FALSE", "Headline" => _("Windows groupname"), "Text" => _("If you want to use a well known RID you can selcet a well known group.")),
|
||||
|
@ -168,7 +169,7 @@ class sambaGroupMapping extends baseModule {
|
|||
*/
|
||||
function save_attributes() {
|
||||
// Get Domain SID from name
|
||||
$sambaDomains = $_SESSION['ldap']->search_domains($_SESSION['config']->get_domainSuffix());
|
||||
$sambaDomains = search_domains($_SESSION['config']->get_domainSuffix());
|
||||
// Get Domain-SID from group SID
|
||||
$domainSID = substr($this->attributes['sambaSID'][0], 0, strrpos($this->attributes['sambaSID'][0], "-"));
|
||||
for ($i=0; $i<count($sambaDomains); $i++ )
|
||||
|
@ -199,7 +200,7 @@ class sambaGroupMapping extends baseModule {
|
|||
|
||||
if (!$profile) {
|
||||
// Get Domain SID from name
|
||||
$sambaDomains = $_SESSION['ldap']->search_domains($_SESSION['config']->get_domainSuffix());
|
||||
$sambaDomains = search_domains($_SESSION['config']->get_domainSuffix());
|
||||
for ($i=0; $i<count($sambaDomains); $i++ )
|
||||
if ($post['sambaDomainName'] == $sambaDomains[$i]->name) {
|
||||
$SID = $sambaDomains[$i]->SID;
|
||||
|
@ -236,7 +237,7 @@ class sambaGroupMapping extends baseModule {
|
|||
*/
|
||||
function display_html_attributes($post, $profile=false) {
|
||||
// Get Domain SID from name
|
||||
$sambaDomains = $_SESSION['ldap']->search_domains($_SESSION['config']->get_domainSuffix());
|
||||
$sambaDomains = search_domains($_SESSION['config']->get_domainSuffix());
|
||||
// Get Domain-SID from group SID
|
||||
$domainSID = substr($this->attributes['sambaSID'][0], 0, strrpos($this->attributes['sambaSID'][0], "-"));
|
||||
for ($i=0; $i<count($sambaDomains); $i++ ) {
|
||||
|
@ -279,10 +280,15 @@ class sambaGroupMapping extends baseModule {
|
|||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of elements for the account profiles.
|
||||
*
|
||||
* @return profile elements
|
||||
*/
|
||||
function get_profileOptions() {
|
||||
$return = array();
|
||||
// get list of domains
|
||||
$sambaDomains = $_SESSION['ldap']->search_domains($_SESSION['config']->get_domainSuffix());
|
||||
$sambaDomains = search_domains($_SESSION['config']->get_domainSuffix());
|
||||
$sambaDomainNames = array();
|
||||
for ($i = 0; $i < count($sambaDomains); $i++ ) {
|
||||
// extract names
|
||||
|
|
|
@ -256,7 +256,7 @@ class sambaSamAccount extends baseModule {
|
|||
* it's psssible uidNumber has changed
|
||||
*/
|
||||
// Get Domain SID from name
|
||||
$sambaDomains = $_SESSION['ldap']->search_domains($_SESSION['config']->get_domainSuffix());
|
||||
$sambaDomains = search_domains($_SESSION['config']->get_domainSuffix());
|
||||
for ($i=0; $i<count($sambaDomains); $i++ )
|
||||
if ($this->attributes['sambaDomainName'][0] == $sambaDomains[$i]->name) {
|
||||
$SID = $sambaDomains[$i]->SID;
|
||||
|
@ -303,7 +303,7 @@ class sambaSamAccount extends baseModule {
|
|||
// Load attributes
|
||||
$this->attributes['sambaDomainName'][0] = $post['sambaDomainName'];
|
||||
// Get Domain SID from name
|
||||
$sambaDomains = $_SESSION['ldap']->search_domains($_SESSION['config']->get_domainSuffix());
|
||||
$sambaDomains = search_domains($_SESSION['config']->get_domainSuffix());
|
||||
for ($i=0; $i<count($sambaDomains); $i++ )
|
||||
if ($this->attributes['sambaDomainName'][0] == $sambaDomains[$i]->name) {
|
||||
$SID = $sambaDomains[$i]->SID;
|
||||
|
@ -473,7 +473,7 @@ class sambaSamAccount extends baseModule {
|
|||
*/
|
||||
function display_html_attributes($post, $profile=false) {
|
||||
// Get Domain SID from name
|
||||
$sambaDomains = $_SESSION['ldap']->search_domains($_SESSION['config']->get_domainSuffix());
|
||||
$sambaDomains = search_domains($_SESSION['config']->get_domainSuffix());
|
||||
for ($i=0; $i<count($sambaDomains); $i++ ) {
|
||||
$sambaDomainNames[] = $sambaDomains[$i]->name;
|
||||
if ($this->attributes['sambaDomainName'][0] == $sambaDomains[$i]->name)
|
||||
|
@ -644,6 +644,11 @@ class sambaSamAccount extends baseModule {
|
|||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of elements for the account profiles.
|
||||
*
|
||||
* @return profile elements
|
||||
*/
|
||||
function get_profileOptions() {
|
||||
$return = array();
|
||||
if ($_SESSION[$this->base]->type=='user') {
|
||||
|
@ -704,7 +709,7 @@ class sambaSamAccount extends baseModule {
|
|||
2 => array('kind' => 'help', 'value' => 'TODO')
|
||||
);
|
||||
// domains
|
||||
$sambaDomains = $_SESSION['ldap']->search_domains($_SESSION['config']->get_domainSuffix());
|
||||
$sambaDomains = search_domains($_SESSION['config']->get_domainSuffix());
|
||||
$sambaDomainNames = array();
|
||||
for ($i = 0; $i < count($sambaDomains); $i++) {
|
||||
$sambaDomainNames[] = $sambaDomains[$i]->name;
|
||||
|
@ -717,7 +722,7 @@ class sambaSamAccount extends baseModule {
|
|||
}
|
||||
elseif ($_SESSION[$this->base]->type=='host') {
|
||||
// domains
|
||||
$sambaDomains = $_SESSION['ldap']->search_domains($_SESSION['config']->get_domainSuffix());
|
||||
$sambaDomains = search_domains($_SESSION['config']->get_domainSuffix());
|
||||
$sambaDomainNames = array();
|
||||
for ($i = 0; $i < count($sambaDomains); $i++) {
|
||||
$sambaDomainNames[] = $sambaDomains[$i]->name;
|
||||
|
|
|
@ -32,6 +32,8 @@ $Id$
|
|||
include_once ("../lib/config.inc");
|
||||
/** access to LDAP server */
|
||||
include_once ("../lib/ldap.inc");
|
||||
/** Samba 3 domain object */
|
||||
include_once ("../lib/account.inc");
|
||||
|
||||
// start session
|
||||
session_save_path("../sess");
|
||||
|
@ -43,7 +45,7 @@ setlanguage();
|
|||
// add/edit domain
|
||||
if (($_GET['action'] == "edit") || ($_GET['action'] == "new")) {
|
||||
// get list of domains
|
||||
$domlist = $_SESSION['ldap']->search_domains($_SESSION['config']->get_domainSuffix());
|
||||
$domlist = search_domains($_SESSION['config']->get_domainSuffix());
|
||||
// get possible suffixes
|
||||
$domsuff = $_SESSION['ldap']->search_units($_SESSION['config']->get_domainSuffix());
|
||||
if ($_GET['action'] == "edit") {
|
||||
|
|
Loading…
Reference in New Issue