new type API

This commit is contained in:
Roland Gruber 2017-03-24 18:23:52 +01:00
parent daa51d1659
commit 207c77b5f0
1 changed files with 65 additions and 53 deletions

View File

@ -1125,9 +1125,9 @@ class posixAccount extends baseModule implements passwordService {
} }
} }
// id-number is in use and account is a new account // id-number is in use and account is a new account
if ((in_array($this->attributes['uidNumber'][0], $uids)) && $this->orig['uidNumber'][0]=='') $errors[] = array('ERROR', _('ID-Number'), _('ID is already in use')); if ((in_array($this->attributes['uidNumber'][0], $uids)) && !isset($this->orig['uidNumber'][0])) $errors[] = array('ERROR', _('ID-Number'), _('ID is already in use'));
// id-number is in use, account is existing account and id-number is not used by itself // id-number is in use, account is existing account and id-number is not used by itself
if ((in_array($this->attributes['uidNumber'][0], $uids)) && $this->orig['uidNumber'][0]!='' && ($this->orig['uidNumber'][0] != $this->attributes['uidNumber'][0]) ) { if ((in_array($this->attributes['uidNumber'][0], $uids)) && isset($this->orig['uidNumber'][0]) && ($this->orig['uidNumber'][0] != $this->attributes['uidNumber'][0]) ) {
$errors[] = $this->messages['uidNumber'][3]; $errors[] = $this->messages['uidNumber'][3];
$this->attributes['uidNumber'][0] = $this->orig['uidNumber'][0]; $this->attributes['uidNumber'][0] = $this->orig['uidNumber'][0];
} }
@ -3050,31 +3050,38 @@ class posixAccount extends baseModule implements passwordService {
if ($this->skipObjectClass()) { if ($this->skipObjectClass()) {
$filter = '(uidNumber=*)'; $filter = '(uidNumber=*)';
} }
$types = $_SESSION['config']->get_ActiveTypes(); $typeManager = new TypeManager();
// get user UIDs $typesUser = $typeManager->getConfiguredTypesForScope('user');
if (in_array('user', $types)) { $typesHost = $typeManager->getConfiguredTypesForScope('host');
$suffixUsers = $_SESSION['config']->get_Suffix('user'); $suffixes = array();
if (isset($this->moduleSettings['posixAccount_uidCheckSuffixUser'][0]) && ($this->moduleSettings['posixAccount_uidCheckSuffixUser'][0] != '')) { if (!empty($typesUser)) {
$suffixUsers = $this->moduleSettings['posixAccount_uidCheckSuffixUser'][0]; if (!empty($this->moduleSettings['posixAccount_uidCheckSuffixUser'][0])) {
$suffixes[] = $this->moduleSettings['posixAccount_uidCheckSuffixUser'][0];
} }
$result = searchLDAP($suffixUsers, $filter, $attrs); else {
for ($i = 0; $i < sizeof($result); $i++) { foreach ($typesUser as $type) {
$this->cachedUIDList[] = $result[$i]['uidnumber'][0]; $suffixes[] = $type->getSuffix();
}
}
// get host UIDs
if (in_array('host', $types)) {
$suffixHosts = $_SESSION['config']->get_Suffix('host');
if (isset($this->moduleSettings['posixAccount_uidCheckSuffixHost'][0]) && ($this->moduleSettings['posixAccount_uidCheckSuffixHost'][0] != '')) {
$suffixHosts = $this->moduleSettings['posixAccount_uidCheckSuffixHost'][0];
}
if ($suffixUsers != $suffixHosts) {
$result = searchLDAP($suffixHosts, $filter, $attrs);
for ($i = 0; $i < sizeof($result); $i++) {
$this->cachedUIDList[] = $result[$i]['uidnumber'][0];
} }
} }
} }
if (!empty($typesHost)) {
if (!empty($this->moduleSettings['posixAccount_uidCheckSuffixHost'][0])) {
$suffixes[] = $this->moduleSettings['posixAccount_uidCheckSuffixHost'][0];
}
else {
foreach ($typesHost as $type) {
$suffixes[] = $type->getSuffix();
}
}
}
$suffixes = array_unique($suffixes);
foreach ($suffixes as $suffix) {
$result = searchLDAP($suffix, $filter, $attrs);
foreach ($result as $resultEntry) {
$this->cachedUIDList[] = $resultEntry['uidnumber'][0];
}
}
$this->cachedUIDList = array_values(array_unique($this->cachedUIDList));
sort($this->cachedUIDList, SORT_NUMERIC); sort($this->cachedUIDList, SORT_NUMERIC);
return $this->cachedUIDList; return $this->cachedUIDList;
} }
@ -3104,31 +3111,38 @@ class posixAccount extends baseModule implements passwordService {
if ($this->skipObjectClass()) { if ($this->skipObjectClass()) {
$filter = '(uid=*)'; $filter = '(uid=*)';
} }
$types = $_SESSION['config']->get_ActiveTypes(); $typeManager = new TypeManager();
// get user names $typesUser = $typeManager->getConfiguredTypesForScope('user');
if (in_array('user', $types)) { $typesHost = $typeManager->getConfiguredTypesForScope('host');
$suffixUsers = $_SESSION['config']->get_Suffix('user'); $suffixes = array();
if (isset($this->moduleSettings['posixAccount_uidCheckSuffixUser'][0]) && ($this->moduleSettings['posixAccount_uidCheckSuffixUser'][0] != '')) { if (!empty($typesUser)) {
$suffixUsers = $this->moduleSettings['posixAccount_uidCheckSuffixUser'][0]; if (!empty($this->moduleSettings['posixAccount_uidCheckSuffixUser'][0])) {
$suffixes[] = $this->moduleSettings['posixAccount_uidCheckSuffixUser'][0];
} }
$result = searchLDAP($suffixUsers, $filter, $attrs); else {
for ($i = 0; $i < sizeof($result); $i++) { foreach ($typesUser as $type) {
$this->cachedUserNameList[] = $result[$i]['uid'][0]; $suffixes[] = $type->getSuffix();
}
}
// get host UIDs
if (in_array('host', $types)) {
$suffixHosts = $_SESSION['config']->get_Suffix('host');
if (isset($this->moduleSettings['posixAccount_uidCheckSuffixHost'][0]) && ($this->moduleSettings['posixAccount_uidCheckSuffixHost'][0] != '')) {
$suffixHosts = $this->moduleSettings['posixAccount_uidCheckSuffixHost'][0];
}
if ($suffixUsers != $suffixHosts) {
$result = searchLDAP($suffixHosts, $filter, $attrs);
for ($i = 0; $i < sizeof($result); $i++) {
$this->cachedUserNameList[] = $result[$i]['uid'][0];
} }
} }
} }
if (!empty($typesHost)) {
if (!empty($this->moduleSettings['posixAccount_uidCheckSuffixHost'][0])) {
$suffixes[] = $this->moduleSettings['posixAccount_uidCheckSuffixHost'][0];
}
else {
foreach ($typesHost as $type) {
$suffixes[] = $type->getSuffix();
}
}
}
$suffixes = array_unique($suffixes);
foreach ($suffixes as $suffix) {
$result = searchLDAP($suffix, $filter, $attrs);
foreach ($result as $resultEntry) {
$this->cachedUserNameList[] = $resultEntry['uid'][0];
}
}
$this->cachedUserNameList = array_values(array_unique($this->cachedUserNameList));
return $this->cachedUserNameList; return $this->cachedUserNameList;
} }
@ -3141,15 +3155,13 @@ class posixAccount extends baseModule implements passwordService {
if (!isset($_SESSION['config'])) { if (!isset($_SESSION['config'])) {
return false; return false;
} }
if (in_array('group', $_SESSION['config']->get_ActiveTypes())) { $typeManager = new TypeManager();
$groupModules = $_SESSION['config']->get_AccountModules('group'); $types = $typeManager->getConfiguredTypesForScopes(array('group', 'gon'));
if (in_array('groupOfNames', $groupModules) || in_array('groupOfMembers', $groupModules) || in_array('groupOfUniqueNames', $groupModules)) { foreach ($types as $type) {
return true; $modules = $type->getModules();
} if (in_array('groupOfNames', $modules)
} || in_array('groupOfMembers', $modules)
if (in_array('gon', $_SESSION['config']->get_ActiveTypes())) { || in_array('groupOfUniqueNames', $modules)) {
$gonModules = $_SESSION['config']->get_AccountModules('gon');
if (in_array('groupOfNames', $gonModules) || in_array('groupOfMembers', $gonModules) || in_array('groupOfUniqueNames', $gonModules)) {
return true; return true;
} }
} }