Avoid ID clashes in new allocation mode

This commit is contained in:
Jamie Cameron
2007-07-17 02:11:24 +00:00
parent 74f4e728ea
commit 3118112194
3 changed files with 23 additions and 4 deletions

View File

@@ -50,9 +50,14 @@ print "<td valign=top><input name=group size=10 value='$group'></td>\n";
print "<td valign=top><b>$text{'gedit_gid'}</b></td>\n";
if ($in{'new'} && $config{'next_gid'}) {
# Next GID comes from module config
while(1) {
$newgid = $config{'next_gid'};
$config{'next_gid'}++;
last if (!&check_uid_used($ldap, &get_group_base(),
"gidNumber", $newgid));
}
print "<td valign=top><input name=gid size=10 ",
"value='$config{'next_gid'}'></td>\n";
$config{'next_uid'}++;
"value='$newgid'></td>\n";
&save_module_config();
}
elsif ($in{'new'}) {

View File

@@ -116,8 +116,12 @@ print "<td><b>$text{'uid'}</b></td>\n";
if ($in{'new'}) {
# Find the first free UID above the base
if ($config{'next_uid'}) {
$newuid = $config{'next_uid'};
$config{'next_uid'}++;
while(1) {
$newuid = $config{'next_uid'};
$config{'next_uid'}++;
last if (!&check_uid_used($ldap, &get_user_base(),
"uidNumber", $newuid));
}
&save_module_config();
}
else {

View File

@@ -1137,5 +1137,15 @@ $string =~ s/
return $string;
}
# check_uid_used(&ldap, base, name, id)_
# Returns 1 if a user or group can be found with the given uid or gid
sub check_uid_used
{
local ($ldap, $base, $name, $id) = @_;
local $rv = $ldap->search('base' => $base,
'filter' => "($name=$id)");
return $rv->count ? 1 : 0;
}
1;