Skip to content

Commit

Permalink
#332 moved create group with same name
Browse files Browse the repository at this point in the history
  • Loading branch information
gruberroland committed Nov 5, 2024
1 parent 3ec2c41 commit a671b73
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions lam/lib/modules/posixAccount.inc
Original file line number Diff line number Diff line change
Expand Up @@ -673,29 +673,35 @@ class posixAccount extends baseModule implements passwordService, AccountStatusP
return [];
}
if (isset($this->attributes['gidNumber'][0]) && ($this->attributes['gidNumber'][0] === self::CREATE_GROUP_WITH_SAME_NAME)) {
$groupType = $this->getPosixGroupType();
$sessionKey = 'TMP' . generateRandomText();
$accountContainerTmp = new accountContainer($groupType, $sessionKey);
$_SESSION[$sessionKey] = &$accountContainerTmp;
$accountContainerTmp->new_account();
$posixGroupModule = $accountContainerTmp->getAccountModule('posixGroup');
$nextGid = $posixGroupModule->getNextGIDs(1, $errors, $groupType);
if ($nextGid !== null) {
$newGroupName = $this->attributes['uid'][0];
$dnNewGroup = 'cn=' . $newGroupName . ',' . $groupType->getSuffix();
$attributesNewGroup = [
'cn' => [$newGroupName],
'gidNumber' => $nextGid[0],
'objectClass' => ['posixGroup'],
];
$newGroupSuccess = @ldap_add(getLDAPServerHandle(), $dnNewGroup, $attributesNewGroup);
if ($newGroupSuccess) {
logNewMessage(LOG_NOTICE, 'Created new group: ' . $newGroupName);
$this->attributes['gidNumber'][0] = $nextGid[0];
$this->groupCache = null;
}
else {
logNewMessage(LOG_ERR, 'Unable to create new group: ' . getDefaultLDAPErrorString(getLDAPServerHandle()));
$newGroupName = $this->attributes['uid'][0];
$existingGid = $this->getGID($newGroupName);
if ($existingGid !== null) {
$this->attributes['gidNumber'][0] = $existingGid;
}
else {
$groupType = $this->getPosixGroupType();
$sessionKey = 'TMP' . generateRandomText();
$accountContainerTmp = new accountContainer($groupType, $sessionKey);
$_SESSION[$sessionKey] = &$accountContainerTmp;
$accountContainerTmp->new_account();
$posixGroupModule = $accountContainerTmp->getAccountModule('posixGroup');
$nextGid = $posixGroupModule->getNextGIDs(1, $errors, $groupType);
if ($nextGid !== null) {
$dnNewGroup = 'cn=' . $newGroupName . ',' . $groupType->getSuffix();
$attributesNewGroup = [
'cn' => [$newGroupName],
'gidNumber' => $nextGid[0],
'objectClass' => ['posixGroup'],
];
$newGroupSuccess = @ldap_add(getLDAPServerHandle(), $dnNewGroup, $attributesNewGroup);
if ($newGroupSuccess) {
logNewMessage(LOG_NOTICE, 'Created new group: ' . $newGroupName);
$this->attributes['gidNumber'][0] = $nextGid[0];
$this->groupCache = null;
}
else {
logNewMessage(LOG_ERR, 'Unable to create new group: ' . getDefaultLDAPErrorString(getLDAPServerHandle()));
}
}
}
}
Expand Down

0 comments on commit a671b73

Please sign in to comment.