Start of work to create an LDAP group when adding a user

This commit is contained in:
Jamie Cameron
2022-10-14 16:15:12 -07:00
parent 5507f501df
commit 85ec6381a1
2 changed files with 62 additions and 9 deletions

View File

@ -302,9 +302,22 @@ if (&in_schema($schema, "sambaPwdLastSet")) {
print &ui_table_start($text{'uedit_gmem'}, "width=100%", 4, \@tds); print &ui_table_start($text{'uedit_gmem'}, "width=100%", 4, \@tds);
# Primary group # Primary group
print &ui_table_row($text{'group'}, if ($in{'new'}) {
&ui_textbox("gid", $grp || $gid, 13). print &ui_table_row($text{'group'},
" ".&group_chooser_button("gid"), 3); &ui_radio_table("gidmode",
$mconfig{'new_user_group'} ? 2 : $grp ? 1 : 0,
[ [ 2, $text{'uedit_samg'} ],
[ 1, $text{'uedit_newg'},
&ui_textbox("newgid", undef, 20) ],
[ 0, $text{'uedit_oldg'},
&ui_textbox("gid", $grp || $gid, 20).
" ".&group_chooser_button("gid") ] ]), 3);
}
else {
print &ui_table_row($text{'group'},
&ui_textbox("gid", $grp || $gid, 20)." ".
&group_chooser_button("gid"), 3);
}
if ($config{'secmode'} != 1) { if ($config{'secmode'} != 1) {
# Work out which secondary groups the user is in # Work out which secondary groups the user is in

View File

@ -203,15 +203,35 @@ else {
$quota = $in{'quota'}; $quota = $in{'quota'};
} }
#load main user group # Validate new group
if ($in{'gid'} =~ /^\d+$/) { if ($in{'gidmode'} == 0) {
$gid = $in{'gid'}; # An existing group
if ($in{'gid'} =~ /^\d+$/) {
$gid = $in{'gid'};
}
else {
$gid = &all_getgrnam($in{'gid'});
defined($gid) ||
&error(&text('usave_egid', $in{'gid'}));
}
$grp = &all_getgrgid($gid);
} }
else { else {
$gid = &all_getgrnam($in{'gid'}); # Creating a new group
defined($gid) || &error(&text('usave_egid', $in{'gid'})); if ($in{'gidmode'} == 2) {
# Same name as the user
$grp = $in{'user'};
}
else {
# Group name was entered
$in{'newgid'} =~ /^[^: \t]+$/ ||
&error(&text('gsave_ebadname', $in{'newgid'}));
$grp = $in{'newgid'};
}
# Check for a clash
&check_group_used($ldap, $grp) &&
&error(&text('usave_einuseg', $grp));
} }
$grp = &all_getgrgid($gid);
# Compute and validate home directory # Compute and validate home directory
if ($access{'autohome'}) { if ($access{'autohome'}) {
@ -315,6 +335,26 @@ else {
&unlock_file($home); &unlock_file($home);
} }
# Create a new group
if ($in{'gidmode'}) {
my $base = &get_group_base();
my $newdn = "cn=$grp,$base";
my @classes = ( &def_group_obj_class() );
push(@classes, split(/\s+/, $config{'gother_class'}));
$gid = $mconfig{'base_gid'};
while(&check_gid_used($ldap, $gid)) {
$gid++;
}
$rv = $ldap->add($newdn, attr =>
[ "cn" => $group,
"gidNumber" => $gid,
@props,
"objectClass" => \@classes ] );
if ($rv->code) {
&error(&text('gsave_eadd', $rv->error));
}
}
# Get configured properties for new users # Get configured properties for new users
local @props = &split_props($config{'props'}, \%uhash); local @props = &split_props($config{'props'}, \%uhash);
if ($in{'cyrus'}) { if ($in{'cyrus'}) {