From a671b73a807cc704a4f7bec909dd486789580bef Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Tue, 5 Nov 2024 20:50:58 +0100 Subject: [PATCH] #332 moved create group with same name --- lam/lib/modules/posixAccount.inc | 52 ++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/lam/lib/modules/posixAccount.inc b/lam/lib/modules/posixAccount.inc index 41bf8d9d3..aca3eea87 100644 --- a/lam/lib/modules/posixAccount.inc +++ b/lam/lib/modules/posixAccount.inc @@ -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())); + } } } }