diff options
Diffstat (limited to 'lib/AdminPanel')
-rw-r--r-- | lib/AdminPanel/Module/Users.pm | 85 | ||||
-rw-r--r-- | lib/AdminPanel/Shared/Users.pm | 137 |
2 files changed, 166 insertions, 56 deletions
diff --git a/lib/AdminPanel/Module/Users.pm b/lib/AdminPanel/Module/Users.pm index 4d735a29..3c0a1b81 100644 --- a/lib/AdminPanel/Module/Users.pm +++ b/lib/AdminPanel/Module/Users.pm @@ -1845,6 +1845,7 @@ sub _groupEdit_Ok { sub _userEdit_Ok { my ($self, $userData) = @_; + $DB::single = 1; # update last changes if any $self->_storeDataFromUserEditPreviousTab($userData); @@ -1858,46 +1859,32 @@ sub _userEdit_Ok { $self->sh_gui->msgBox({text => $self->loc->N("Password Mismatch")}); return 0; } - my $userEnt = $self->sh_users->ctx->LookupUserByName($userData->{username}); + if ($userData->{password} ne '') { if ($self->sh_users->weakPasswordForSecurityLevel($userData->{password})) { $self->sh_gui->msgBox({text => $self->loc->N("This password is too simple. \n Good passwords should be > 6 characters")}); return 0; } - $self->sh_users->ctx->UserSetPass($userEnt, $userData->{password}); } - $userEnt->UserName($userData->{username}); - $userEnt->Gecos($userData->{full_name}); - $userEnt->HomeDir($userData->{homedir}); - $userEnt->LoginShell($userData->{shell}); - my $username = $userEnt->UserName($self->sh_users->USER_GetValue); - my $grps = $self->sh_users->getGoups(); - my @sgroups = sort @$grps; - - my $members = $userData->{members}; - foreach my $group (@sgroups) { - my $gEnt = $self->sh_users->ctx->LookupGroupByName($group); - my $ugid = $gEnt->Gid($self->sh_users->USER_GetValue); - my $m = $gEnt->MemberName(1,0); - if (MDK::Common::DataStructure::member($group, @$members)) { - if (!AdminPanel::Shared::inArray($username, $m) && $userData->{primary_group} != $ugid) { - eval { $gEnt->MemberName($username, 1) }; - $self->sh_users->ctx->GroupModify($gEnt); - } - } - else { - if (AdminPanel::Shared::inArray($username, $m)) { - eval { $gEnt->MemberName($username, 2) }; - $self->sh_users->ctx->GroupModify($gEnt); - } - } - } if ($userData->{primary_group} == -1) { $self->sh_gui->msgBox({ text => $self->loc->N("Please select at least one group for the user")}); return 0; } - $userEnt->Gid($userData->{primary_group}); + + my $userInfo = { +# old_username => $TDODO, + username => $userData->{username}, + fullname => $userData->{full_name}, + homedir => $userData->{homedir}, + shell => $userData->{shell}, + members => $userData->{members}, + gid => $userData->{primary_group}, + lockuser => $userData->{lockuser}, + }; + + $userInfo->{password} = $userData->{password} if $userData->{password} ne ''; + if ($userData->{acc_check_exp}) { my $yr = $userData->{acc_expy}; @@ -1907,11 +1894,11 @@ sub _userEdit_Ok { $self->sh_gui->msgBox({text => $self->loc->N("Please specify Year, Month and Day \n for Account Expiration ")}); return 0; } - my $Exp = _ConvTime($dy, $mo, $yr); - $userEnt->ShadowExpire($Exp); - } - else { - $userEnt->ShadowExpire(ceil(-1)) + $userInfo->{acc_expires} = { + exp_y => $yr, + exp_m => $mo, + exp_d => $dy, + }; } if ($userData->{pwd_check_exp}) { @@ -1919,32 +1906,20 @@ sub _userEdit_Ok { my $required = int($userData->{pwd_exp_max}); my $warning = int($userData->{pwd_exp_warn}); my $inactive = int($userData->{pwd_exp_inact}); - if ($allowed && $required && $warning && $inactive) { - $userEnt->ShadowMin($allowed); - $userEnt->ShadowMax($required); - $userEnt->ShadowWarn($warning); - $userEnt->ShadowInact($inactive); - } - else { + if (!$allowed || !$required || !$warning || !$inactive) { $self->sh_gui->msgBox({text => $self->loc->N("Please fill up all fields in password aging\n")}); return 0; } + $userInfo->{password_expires} = { + exp_min => $allowed, + exp_max => $required, + exp_warn => $warning, + exp_inact => $inactive, + }; } - else { - $userEnt->ShadowMin(-1); - $userEnt->ShadowMax(99999); - $userEnt->ShadowWarn(-1); - $userEnt->ShadowInact(-1); - } - - $self->sh_users->ctx->UserModify($userEnt); - if ($userData->{lockuser}) { - !$self->sh_users->ctx->IsLocked($userEnt) and $self->sh_users->ctx->Lock($userEnt); - } - else { - $self->sh_users->ctx->IsLocked($userEnt) and $self->sh_users->ctx->UnLock($userEnt); - } + $self->sh_users->modifyUser($userInfo); + defined $userData->{icon_face} and $self->sh_users->addKdmIcon($userData->{username}, $userData->{icon_face}); $self->_refresh(); diff --git a/lib/AdminPanel/Shared/Users.pm b/lib/AdminPanel/Shared/Users.pm index 9d8fca2f..94077343 100644 --- a/lib/AdminPanel/Shared/Users.pm +++ b/lib/AdminPanel/Shared/Users.pm @@ -761,7 +761,8 @@ sub deleteGroup { groupname => group name members => users belonging to the group -=head3 INPUT +=head3 OUTPUT + $retval => HASH reference status => 1 (ok) 0 (error) error => error message if status is 0 @@ -1225,6 +1226,140 @@ sub addUser { #============================================================= +=head2 modifyUser + +=head3 INPUT + + $userInfo: HASH reference containing: + old_username => old name of the user (if renaming) + username => user name + fullname => full name of teh user + password => password + homedir => home directory + shell => user shell + members => groups the user belongs to + gid => primary group identifier + lockuser => lock user + acc_expires => account expire time - containing: + exp_y => year + exp_m => month + exp_d => day + password_expires => password expire time - containing: + exp_min => min + exp_max => max + exp_warn => when warn + exp_inact => when inactive + +=head3 DESCRIPTION + + This method modifies the group groupname + +=cut + +#============================================================= +sub modifyUser { + my ($self, $userInfo) = @_; + + die "user name is mandatory" if !defined($userInfo->{username}); + die "primary group identifier is mandatory" if !defined($userInfo->{gid}); + die "a valid group identifier is mandatory" if $userInfo->{gid} < 0; + + if (defined($userInfo->{acc_expires})) { + die "expiring year is mandatory" if !defined($userInfo->{acc_expires}->{exp_y}); + die "expiring month is mandatory" if !defined($userInfo->{acc_expires}->{exp_m}); + die "expiring day is mandatory" if !defined($userInfo->{acc_expires}->{exp_d}); + } + if (defined($userInfo->{password_expires})) { + die "password expiring min is mandatory" if !($userInfo->{password_expires}->{exp_min}); + die "password expiring max is mandatory" if !($userInfo->{password_expires}->{exp_max}); + die "password expiring warn is mandatory" if !($userInfo->{password_expires}->{exp_warn}); + die "password expiring inactive is mandatory" if !($userInfo->{password_expires}->{exp_inact}); + } + my $userEnt = defined($userInfo->{old_username}) ? + $self->ctx->LookupUserByName($userInfo->{old_username}) : + $self->ctx->LookupUserByName($userInfo->{username}); + + my $orig_username = $userInfo->{username}; + if (defined($userInfo->{old_username}) && + $userInfo->{old_username} ne $userInfo->{username}) { + $userEnt->UserName($userInfo->{username}); + $orig_username = $userInfo->{old_username}; + } + + # $userEnt->UserName($userInfo->{username}); + $userEnt->Gecos($userInfo->{fullname}) if defined($userInfo->{fullname}); + $userEnt->HomeDir($userInfo->{homedir}) if defined($userInfo->{homedir}); + $userEnt->LoginShell($userInfo->{shell}) if defined($userInfo->{shell}); + + + my $username = $userEnt->UserName($self->USER_GetValue); + my $grps = $self->getGoups(); + my @sgroups = sort @{$grps}; + + my $members = $userInfo->{members}; + foreach my $group (@sgroups) { + my $gEnt = $self->ctx->LookupGroupByName($group); + my $ugid = $gEnt->Gid($self->USER_GetValue); + my $m = $gEnt->MemberName(1,0); + if (MDK::Common::DataStructure::member($group, @$members)) { + if (!AdminPanel::Shared::inArray($username, $m) && $userInfo->{gid} != $ugid) { + eval { $gEnt->MemberName($username, 1) }; + $self->ctx->GroupModify($gEnt); + } + } + else { + if (AdminPanel::Shared::inArray($username, $m)) { + eval { $gEnt->MemberName($username, 2) }; + $self->ctx->GroupModify($gEnt); + } + } + } + + $userEnt->Gid($userInfo->{gid}) if defined($userInfo->{gid}); + + if (defined($userInfo->{acc_expires})) { + my $yr = $userInfo->{acc_expires}->{exp_y}; + my $mo = $userInfo->{acc_expires}->{exp_m}; + my $dy = $userInfo->{acc_expires}->{exp_d}; + my $Exp = _ConvTime($dy, $mo, $yr); + $userEnt->ShadowExpire($Exp); + } + else { + $userEnt->ShadowExpire(ceil(-1)) + } + if (defined($userInfo->{password_expires})) { + my $allowed = $userInfo->{password_expires}->{exp_min}; + my $required = $userInfo->{password_expires}->{exp_max}; + my $warning = $userInfo->{password_expires}->{exp_warn}; + my $inactive = $userInfo->{password_expires}->{exp_inact}; + $userEnt->ShadowMin($allowed); + $userEnt->ShadowMax($required); + $userEnt->ShadowWarn($warning); + $userEnt->ShadowInact($inactive); + } + else { + $userEnt->ShadowMin(-1); + $userEnt->ShadowMax(99999); + $userEnt->ShadowWarn(-1); + $userEnt->ShadowInact(-1); + } + + $self->ctx->UserSetPass($userEnt, $userInfo->{password}) if defined($userInfo->{password}); + $self->ctx->UserModify($userEnt); + + if ($userInfo->{lockuser}) { + !$self->ctx->IsLocked($userEnt) and $self->ctx->Lock($userEnt); + } + else { + $self->ctx->IsLocked($userEnt) and $self->ctx->UnLock($userEnt); + } + + return 1; +} + + +#============================================================= + =head2 deleteUser =head3 INPUT |