Skip to content

Commit 4719bb4

Browse files
authored
prevent user/pi/org uid/gid conflicts, avoid debian reserved ranges (#154)
* prevent user/pi/org uid/gid conflicts, avoid debian reserved ranges * fix whitespace * return false * more similar to original * more similar to original * old functions dont exist anymore * more similar to original * more similar to original
1 parent 18175ba commit 4719bb4

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

resources/lib/UnityLDAP.php

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public function getNextUIDNumber($UnitySQL)
124124
$max_uid = $UnitySQL->getSiteVar('MAX_UID');
125125
$new_uid = $max_uid + 1;
126126

127-
while ($this->UIDNumInUse($new_uid)) {
127+
while ($this->IDNumInUse($new_uid)) {
128128
$new_uid++;
129129
}
130130

@@ -138,7 +138,7 @@ public function getNextPiGIDNumber($UnitySQL)
138138
$max_pigid = $UnitySQL->getSiteVar('MAX_PIGID');
139139
$new_pigid = $max_pigid + 1;
140140

141-
while ($this->PIGIDNumInUse($new_pigid)) {
141+
while ($this->IDNumInUse($new_pigid)) {
142142
$new_pigid++;
143143
}
144144

@@ -152,7 +152,7 @@ public function getNextOrgGIDNumber($UnitySQL)
152152
$max_gid = $UnitySQL->getSiteVar('MAX_GID');
153153
$new_gid = $max_gid + 1;
154154

155-
while ($this->GIDNumInUse($new_gid)) {
155+
while ($this->IDNumInUse($new_gid)) {
156156
$new_gid++;
157157
}
158158

@@ -161,32 +161,24 @@ public function getNextOrgGIDNumber($UnitySQL)
161161
return $new_gid;
162162
}
163163

164-
private function UIDNumInUse($id)
164+
private function IDNumInUse($id)
165165
{
166+
// id reserved for debian packages
167+
if (($id >= 100 && $id <= 999) || ($id >= 60000 && $id <= 64999)) {
168+
return true;
169+
}
166170
$users = $this->userOU->getChildrenArray(true);
167171
foreach ($users as $user) {
168172
if ($user["uidnumber"][0] == $id) {
169173
return true;
170174
}
171175
}
172-
173-
return false;
174-
}
175-
176-
private function PIGIDNumInUse($id)
177-
{
178176
$pi_groups = $this->pi_groupOU->getChildrenArray(true);
179177
foreach ($pi_groups as $pi_group) {
180178
if ($pi_group["gidnumber"][0] == $id) {
181179
return true;
182180
}
183181
}
184-
185-
return false;
186-
}
187-
188-
private function GIDNumInUse($id)
189-
{
190182
$groups = $this->groupOU->getChildrenArray(true);
191183
foreach ($groups as $group) {
192184
if ($group["gidnumber"][0] == $id) {
@@ -212,7 +204,7 @@ public function getUnassignedID($uid, $UnitySQL)
212204

213205
if ($uid == $netid_match || $netid == $netid_match) {
214206
// found a match
215-
if (!$this->UIDNumInUse($uid_match) && !$this->GIDNumInUse($uid_match)) {
207+
if (!$this->IDNumInUse($uid_match)) {
216208
return $uid_match;
217209
}
218210
}

0 commit comments

Comments
 (0)