@@ -93,7 +93,6 @@ public function getDefUserShell()
93
93
public function getNextUIDGIDNumber ($ uid )
94
94
{
95
95
$ IDNumsInUse = array_merge ($ this ->getAllUIDNumbersInUse (), $ this ->getAllGIDNumbersInUse ());
96
- $ start = $ this ->offset_UIDGID ;
97
96
$ customIDMappings = $ this ->getCustomIDMappings ();
98
97
$ customMappedID = $ customIDMappings [$ uid ] ?? null ;
99
98
if (!is_null ($ customMappedID ) && !in_array ($ customMappedID , $ IDNumsInUse )) {
@@ -105,21 +104,26 @@ public function getNextUIDGIDNumber($uid)
105
104
"user ' $ uid' has a custom mapped IDNumber $ customMappedID but it's already in use! " ,
106
105
);
107
106
}
108
- return $ this ->getNextIDNumber ($ start , $ IDNumsInUse );
107
+ return $ this ->getNextIDNumber (
108
+ $ this ->offset_UIDGID ,
109
+ array_merge ($ IDNumsInUse , array_values ($ this ->getCustomIDMappings ()))
110
+ );
109
111
}
110
112
111
113
public function getNextPIGIDNumber ()
112
114
{
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
+ );
116
119
}
117
120
118
121
public function getNextOrgGIDNumber ()
119
122
{
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
+ );
123
127
}
124
128
125
129
private function isIDNumberForbidden ($ id )
@@ -129,12 +133,10 @@ private function isIDNumberForbidden($id)
129
133
return (($ id <= 999 ) || ($ id >= 60000 && $ id <= 64999 ));
130
134
}
131
135
132
- private function getNextIDNumber ($ start , $ IDNumsInUse )
136
+ private function getNextIDNumber ($ start , $ IDsToSkip )
133
137
{
134
- // custom ID mappings are considered both UIDs and GIDs
135
- $ IDNumsInUse = array_merge ($ IDNumsInUse , array_values ($ this ->getCustomIDMappings ()));
136
138
$ 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 )) {
138
140
$ new_id ++;
139
141
}
140
142
return $ new_id ;
0 commit comments