Skip to content

Commit a85da39

Browse files
authored
make ID select less confusing (#307)
* make ID selection less confusing * rename variable
1 parent b6dd299 commit a85da39

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

resources/lib/UnityLDAP.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ public function getDefUserShell()
9393
public function getNextUIDGIDNumber($uid)
9494
{
9595
$IDNumsInUse = array_merge($this->getAllUIDNumbersInUse(), $this->getAllGIDNumbersInUse());
96-
$start = $this->offset_UIDGID;
9796
$customIDMappings = $this->getCustomIDMappings();
9897
$customMappedID = $customIDMappings[$uid] ?? null;
9998
if (!is_null($customMappedID) && !in_array($customMappedID, $IDNumsInUse)) {
@@ -105,21 +104,26 @@ public function getNextUIDGIDNumber($uid)
105104
"user '$uid' has a custom mapped IDNumber $customMappedID but it's already in use!",
106105
);
107106
}
108-
return $this->getNextIDNumber($start, $IDNumsInUse);
107+
return $this->getNextIDNumber(
108+
$this->offset_UIDGID,
109+
array_merge($IDNumsInUse, array_values($this->getCustomIDMappings()))
110+
);
109111
}
110112

111113
public function getNextPIGIDNumber()
112114
{
113-
$IDNumsInUse = $this->getAllGIDNumbersInUse();
114-
$start = $this->offset_PIGID;
115-
return $this->getNextIDNumber($start, $IDNumsInUse);
115+
return $this->getNextIDNumber(
116+
$this->offset_PIGID,
117+
array_merge($this->getAllGIDNumbersInUse(), array_values($this->getCustomIDMappings()))
118+
);
116119
}
117120

118121
public function getNextOrgGIDNumber()
119122
{
120-
$IDNumsInUse = $this->getAllGIDNumbersInUse();
121-
$start = $this->offset_ORGGID;
122-
return $this->getNextIDNumber($start, $IDNumsInUse);
123+
return $this->getNextIDNumber(
124+
$this->offset_ORGGID,
125+
array_merge($this->getAllGIDNumbersInUse(), array_values($this->getCustomIDMappings()))
126+
);
123127
}
124128

125129
private function isIDNumberForbidden($id)
@@ -129,12 +133,10 @@ private function isIDNumberForbidden($id)
129133
return (($id <= 999) || ($id >= 60000 && $id <= 64999));
130134
}
131135

132-
private function getNextIDNumber($start, $IDNumsInUse)
136+
private function getNextIDNumber($start, $IDsToSkip)
133137
{
134-
// custom ID mappings are considered both UIDs and GIDs
135-
$IDNumsInUse = array_merge($IDNumsInUse, array_values($this->getCustomIDMappings()));
136138
$new_id = $start;
137-
while ($this->isIDNumberForbidden($new_id) || in_array($new_id, $IDNumsInUse)) {
139+
while ($this->isIDNumberForbidden($new_id) || in_array($new_id, $IDsToSkip)) {
138140
$new_id++;
139141
}
140142
return $new_id;

0 commit comments

Comments
 (0)