upload: check for existing users and groups
This commit is contained in:
parent
675a666497
commit
d58048c975
|
@ -81,6 +81,8 @@ class posixAccount extends baseModule {
|
||||||
$this->messages['uid'][6] = array('WARN', _('Hostname'), _('Host name in use. Selected next free host name.'));
|
$this->messages['uid'][6] = array('WARN', _('Hostname'), _('Host name in use. Selected next free host name.'));
|
||||||
$this->messages['uid'][7] = array('ERROR', _('Account %s:') . ' posixAccount_userName', _('User name contains invalid characters. Valid characters are: a-z, A-Z, 0-9 and .-_ !'));
|
$this->messages['uid'][7] = array('ERROR', _('Account %s:') . ' posixAccount_userName', _('User name contains invalid characters. Valid characters are: a-z, A-Z, 0-9 and .-_ !'));
|
||||||
$this->messages['uid'][8] = array('ERROR', _('Account %s:') . ' posixAccount_hostName', _('Host name contains invalid characters. Valid characters are: a-z, A-Z, 0-9 and .-_ !'));
|
$this->messages['uid'][8] = array('ERROR', _('Account %s:') . ' posixAccount_hostName', _('Host name contains invalid characters. Valid characters are: a-z, A-Z, 0-9 and .-_ !'));
|
||||||
|
$this->messages['uid'][9] = array('ERROR', _('Account %s:') . ' posixAccount_userName', _('User name already exists!'));
|
||||||
|
$this->messages['uid'][10] = array('ERROR', _('Account %s:') . ' posixAccount_hostName', _('Host name already exists!'));
|
||||||
$this->messages['gidNumber'][0] = array('ERROR', _('Account %s:') . ' posixAccount_group', _('LAM was unable to find a group with this name!'));
|
$this->messages['gidNumber'][0] = array('ERROR', _('Account %s:') . ' posixAccount_group', _('LAM was unable to find a group with this name!'));
|
||||||
$this->messages['gidNumber'][1] = array('ERROR', _('Account %s:') . ' posixAccount_group', _('This GID number is invalid! Please provide either a number or a group name.'));
|
$this->messages['gidNumber'][1] = array('ERROR', _('Account %s:') . ' posixAccount_group', _('This GID number is invalid! Please provide either a number or a group name.'));
|
||||||
$this->messages['gecos'][0] = array('ERROR', _('Account %s:') . ' posixAccount_gecos', _('This gecos value is invalid!'));
|
$this->messages['gecos'][0] = array('ERROR', _('Account %s:') . ' posixAccount_gecos', _('This gecos value is invalid!'));
|
||||||
|
@ -1177,6 +1179,15 @@ class posixAccount extends baseModule {
|
||||||
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts) {
|
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts) {
|
||||||
$triggered_messages = array();
|
$triggered_messages = array();
|
||||||
$needAutoUID = array();
|
$needAutoUID = array();
|
||||||
|
// get list of existing users
|
||||||
|
$dnUsers = $_SESSION['cache']->get_cache('uid', 'posixAccount', '*');
|
||||||
|
$existingUsers = array();
|
||||||
|
foreach ($dnUsers as $dn) {
|
||||||
|
$existingUsers[] = $dn[0];
|
||||||
|
}
|
||||||
|
// get list of existing groups
|
||||||
|
$existingGroups = $_SESSION['cache']->findgroups();
|
||||||
|
// check input
|
||||||
for ($i = 0; $i < sizeof($rawAccounts); $i++) {
|
for ($i = 0; $i < sizeof($rawAccounts); $i++) {
|
||||||
if (!in_array("posixAccount", $partialAccounts[$i]['objectClass'])) $partialAccounts[$i]['objectClass'][] = "posixAccount";
|
if (!in_array("posixAccount", $partialAccounts[$i]['objectClass'])) $partialAccounts[$i]['objectClass'][] = "posixAccount";
|
||||||
// UID
|
// UID
|
||||||
|
@ -1247,8 +1258,22 @@ class posixAccount extends baseModule {
|
||||||
}
|
}
|
||||||
// user specific attributes
|
// user specific attributes
|
||||||
if ($this->scope == 'user') {
|
if ($this->scope == 'user') {
|
||||||
|
// additional groups
|
||||||
|
if ($rawAccounts[$i][$ids['posixAccount_additionalGroups']] != "") {
|
||||||
|
$groups = explode(",", $rawAccounts[$i][$ids['posixAccount_additionalGroups']]);
|
||||||
|
for ($g = 0; $g < sizeof($groups); $g++) {
|
||||||
|
if (!in_array($groups[$g], $existingGroups)) {
|
||||||
|
$triggered_messages[] = array('ERROR', _('Unable to find group in LDAP.'), $groups[$g]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
// user name
|
// user name
|
||||||
if (get_preg($rawAccounts[$i][$ids['posixAccount_userName']], 'username')) {
|
if (in_array($rawAccounts[$i][$ids['posixAccount_userName']], $existingUsers)) {
|
||||||
|
$errMsg = $this->messages['uid'][9];
|
||||||
|
array_push($errMsg, array($i));
|
||||||
|
$triggered_messages[] = $errMsg;
|
||||||
|
}
|
||||||
|
elseif (get_preg($rawAccounts[$i][$ids['posixAccount_userName']], 'username')) {
|
||||||
$partialAccounts[$i]['uid'] = $rawAccounts[$i][$ids['posixAccount_userName']];
|
$partialAccounts[$i]['uid'] = $rawAccounts[$i][$ids['posixAccount_userName']];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -1317,7 +1342,12 @@ class posixAccount extends baseModule {
|
||||||
// host specific attributes
|
// host specific attributes
|
||||||
elseif ($this->scope == 'host') {
|
elseif ($this->scope == 'host') {
|
||||||
// host name
|
// host name
|
||||||
if (get_preg($rawAccounts[$i][$ids['posixAccount_hostName']], 'hostname')) {
|
if (in_array($rawAccounts[$i][$ids['posixAccount_hostName']], $existingUsers)) {
|
||||||
|
$errMsg = $this->messages['uid'][10];
|
||||||
|
array_push($errMsg, array($i));
|
||||||
|
$triggered_messages[] = $errMsg;
|
||||||
|
}
|
||||||
|
elseif (get_preg($rawAccounts[$i][$ids['posixAccount_hostName']], 'hostname')) {
|
||||||
$partialAccounts[$i]['uid'] = $rawAccounts[$i][$ids['posixAccount_hostName']];
|
$partialAccounts[$i]['uid'] = $rawAccounts[$i][$ids['posixAccount_hostName']];
|
||||||
$partialAccounts[$i]['cn'] = $rawAccounts[$i][$ids['posixAccount_hostName']];
|
$partialAccounts[$i]['cn'] = $rawAccounts[$i][$ids['posixAccount_hostName']];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue