Skip to content

Commit 6232722

Browse files
committed
When pql_get_next_ugidnumber() is called to generate a gidNumber,
make absolutly sure that we get a number which isn't used by either a user NOR group! + Make sure that when looking for a number hole, we're looking at a number which is higher than the minimum specified (if it is) + Add support for having a minimum[UG]IDNumber value in the (sub)branch. + Use this when generating uid/gid number when adding user.
1 parent cab1704 commit 6232722

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

include/pql.inc

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,17 @@ function pql_get_next_ugidnumber($type, $rootdn) {
960960
elseif(!$minimum)
961961
$minimum = array(100);
962962

963+
// Possibly overwrite the minimum UID number from the branch
964+
if($_REQUEST["domain"]) {
965+
if($type == 'uid')
966+
$results = $_pql->search($_REQUEST["domain"], pql_get_define("PQL_ATTR_MINIMUM_UIDNUMBER")."=*");
967+
else
968+
$results = $_pql->search($_REQUEST["domain"], pql_get_define("PQL_ATTR_MINIMUM_GIDNUMBER")."=*");
969+
970+
if($results[pql_get_define("PQL_ATTR_MINIMUM_UIDNUMBER")])
971+
$minimum = array($results[pql_get_define("PQL_ATTR_MINIMUM_UIDNUMBER")]);
972+
}
973+
963974
$min_id_val = 100; // Set an absolute min so no one becomes root.
964975
foreach ($minimum as $min) {
965976
if ($min > $min_id_val) {
@@ -968,8 +979,15 @@ function pql_get_next_ugidnumber($type, $rootdn) {
968979
}
969980

970981
// Make a list of all the already used IDs.
971-
$filter = "(&($attrib=*)(".pql_get_define("PQL_ATTR_OBJECTCLASS")."=posixaccount))";
972-
982+
if($type == 'uid')
983+
$filter = "(&($attrib=*)(".pql_get_define("PQL_ATTR_OBJECTCLASS")."=posixAccount))";
984+
else {
985+
// Complicated - need to make absolutly sure that:
986+
// 1. We don't have a user with the gidNumber=x
987+
// 2. We don't have a group with the gidNumber=x
988+
$filter = "(&($attrib=*)(|(".pql_get_define("PQL_ATTR_OBJECTCLASS")."=posixAccount)(".pql_get_define("PQL_ATTR_OBJECTCLASS")."=posixGroup)))";
989+
}
990+
973991
$ids = array();
974992
foreach($_SESSION["BASE_DN"] as $dn) {
975993
$results = $_pql->search($dn, $filter);
@@ -988,7 +1006,7 @@ function pql_get_next_ugidnumber($type, $rootdn) {
9881006
sort($ids, SORT_NUMERIC);
9891007
$prev_id = $ids[0];
9901008
foreach ($ids as $id) {
991-
if ($id > $prev_id + 1) {
1009+
if(($id > $min_id_val) && ($id > $prev_id + 1)) {
9921010
$found_id = $prev_id + 1;
9931011
break;
9941012
}

0 commit comments

Comments
 (0)