Skip to content
Commits on Source (3)
......@@ -128,16 +128,8 @@ if (isset($_REQUEST['signupid']) && isset($_REQUEST['signuppw'])) {
);
$failed = true;
} else {
// determine the uid range
if ($row[type] == 2) {
$baseuid = 8;
} else {
$baseuid = 29;
}
$minuid = $baseuid * 1000;
$maxuid = $minuid + 999;
//get the new uid
$uid = findUid($minuid, $maxuid);
//generate the new uid
$uid = generateUid();
// make a password
$password = make_password();
// make the ldif
......
......@@ -29,21 +29,30 @@ function make_password($length = 8)
return $password;
}
function findUid($start, $end)
function generateUid()
{
$ds = ldap_connect("localhost");
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
$r = ldap_bind($ds);
$sr = ldap_search($ds, "dc=sucs,dc=org", "uid=*", array(uidNumber));
$info = ldap_get_entries($ds, $sr);
for ($i = 0; $i < $info[count]; $i++) {
$uids[$info[$i][uidnumber][0]] = true;
}
for ($i = $start; $i < $end; $i++) {
if (!isset($uids[$i])) {
$safeuid = $i;
break;
//get the year, this'll be the start/prefix of the uid
$prefix = date("Y");
//generate a uid
//check to see if it's taken/safe to use
$ok = false;
while ($ok == false) {
//generate random number between 00000 and 99999
$uid = sprintf("%05d", mt_rand(0, 99999));
//id return 1 for error (safe to take). 0 for success (taken) not safe
exec("id ".$prefix.$uid, $output, $returnVal);
//check the result of id
if ($returnVal == 1) {
// We have an unused one!
$ok = true;
$safeuid = $prefix.$uid;
}
}
return $safeuid;
......