diff options
author | Daouda Lo <daouda@mandriva.com> | 2003-06-19 16:40:01 +0000 |
---|---|---|
committer | Daouda Lo <daouda@mandriva.com> | 2003-06-19 16:40:01 +0000 |
commit | effbb6e71e8fdcc63875ea8e66625960b6b599c0 (patch) | |
tree | bdb2e5486527d692bd163cf73da10c0461c9d6e3 | |
parent | ca32c3f982f9d9f61690fcdb907fe0bd0917068c (diff) | |
download | userdrake-effbb6e71e8fdcc63875ea8e66625960b6b599c0.tar userdrake-effbb6e71e8fdcc63875ea8e66625960b6b599c0.tar.gz userdrake-effbb6e71e8fdcc63875ea8e66625960b6b599c0.tar.bz2 userdrake-effbb6e71e8fdcc63875ea8e66625960b6b599c0.tar.xz userdrake-effbb6e71e8fdcc63875ea8e66625960b6b599c0.zip |
- Password aging
-rwxr-xr-x | userdrake2 | 124 |
1 files changed, 80 insertions, 44 deletions
@@ -42,6 +42,7 @@ $us->{VERSION} = 0.91; my $error = 0; my $GetValue = -65533; my %prefs = getVarsFromSh($conffile); +my %sec = getVarsFromSh($secfile); my $sysfilter = text2bool($prefs{FILTER}); sub HelpSystem { system("drakhelp Drakxtools-Guide.html/userdrake.html &") }; @@ -165,7 +166,7 @@ sub Refresh { sub AddUser { my $w = ugtk2->new(N("Create New User"), grab => 1); my $dontcreatehomedir = 0; my $is_system = 0; - my %u; my %sec = getVarsFromSh($secfile); + my %u; gtkadd($w->{window}, gtkpack_(Gtk2::VBox->new(0, 2), 0, BuildUui(), @@ -185,12 +186,12 @@ sub AddUser { gtksignal_connect(Gtk2::Button->new($_->[0]), clicked => sub { if (!$r) { $u{username} = $us->{o}->{login}->get_text(); $error = 0; - if (!valid($u{username})) { raiseerror($us->{error}); $error = 1 }; + if (!valid($u{username})) { raiseerror($us->{error}) }; my $nm = $ctx->LookupUserByName($u{username}); - if ($nm) { raiseerror(N("User already exists, please choose another User Name")); $error = 1 ; $us->{o}->{login}->set_text('') }; + if ($nm) { raiseerror(N("User already exists, please choose another User Name")); $us->{o}->{login}->set_text('') }; $u{passwd} = $us->{o}->{passwd}->get_text(); - if ($u{passwd} ne $us->{o}->{confpasswd}->get_text()) { raiseerror(N("Password Mismatch")); $error = 1 }; - if ($sec{SECURE_LEVEL} > 3 && length($u{passwd}) < 6) { raiseerror(N("This password is too simple. \n Good passwords should be > 6 caracters")); $error = 1 }; + if ($u{passwd} ne $us->{o}->{confpasswd}->get_text()) { raiseerror(N("Password Mismatch")) }; + if ($sec{SECURE_LEVEL} > 3 && length($u{passwd}) < 6) { raiseerror(N("This password is too simple. \n Good passwords should be > 6 caracters")) }; my $userEnt = $ctx->InitUser($u{username}, $is_system); if ($us->{o}->{createhomedir}->get_active) { $dontcreatehomedir = 0; @@ -312,9 +313,9 @@ sub AddGroup { gtksignal_connect(Gtk2::Button->new($_->[0]), clicked => sub { if (!$r) { $g{groupname} = $us->{o}->{groupname}->get_text(); $error = 0; - if (!valid($g{groupname})) { raiseerror($us->{error}); $error = 1 }; + if (!valid($g{groupname})) { raiseerror($us->{error}) }; my $nm = $ctx->LookupUserByName($g{groupname}); - if ($nm) { raiseerror(N("Group already exists, please choose another Group Name")); $error = 1 ; $us->{o}->{groupname}->set_text('') }; + if ($nm) { raiseerror(N("Group already exists, please choose another Group Name")); $us->{o}->{groupname}->set_text('') }; my $groupEnt = $ctx->InitGroup($g{groupname}, $is_system); if ($us->{o}->{groupid}->get_active) { if (($g{gid} = $us->{o}->{gid}->get_value) < 500) { @@ -391,7 +392,6 @@ sub Delete { my $userEnt = $ctx->LookupUserByName($username); if ($userEnt->Gid($GetValue) == $groupEnt->Gid($GetValue)) { raiseerror(N("%s is a primary group for user %s\n Remove the user first", $groupname, $username)); - $error = 1; last GLOOP } } @@ -464,7 +464,7 @@ sub Edit { my $w = ugtk2->new('userdrake', grab => 1); my $model = Gtk2::ListStore->new(Gtk2::GType->OBJECT, Gtk2::GType->STRING, Gtk2::GType->INT); my $tree = Gtk2::TreeView->new_with_model($model); my %g; my %u; - my ($groupname, $username, $groupEnt, $userEnt, $members, $times, $min, $max, $warn, $inact); + my ($groupname, $username, $groupEnt, $userEnt, $members, $times, $min, $max, $warn, $inact, $primgid); my @primgroup; my @pix = ($pixdir.'selected.png', $pixdir.'unselected.png'); $tree->get_selection->set_mode('browse'); @@ -534,19 +534,21 @@ sub Edit { } #root account should never be locked !$Uid and $us->{o}->{lockuser}->set_sensitive(0); + # Check if user account is locked + $ctx->IsLocked($userEnt) and $us->{o}->{lockuser}->set_active(1); my $lastchg = $userEnt->ShadowLastChange($GetValue); if ($lastchg) { $times = TimeOfArray($lastchg); - $dayStr->set_text($times->{daystr}); $month->set_text($times->{month}); $dayInt->set_text($times->{dayint}); $year->set_text($times->{year}) ; + $dayStr->set_text($times->{daystr}); $month->set_text($times->{month}); $dayInt->set_text($times->{dayint}); $year->set_text($times->{year}); } $min = $userEnt->ShadowMin($GetValue); $max =$userEnt->ShadowMax($GetValue); $warn = $userEnt->ShadowWarn($GetValue); $inact = $userEnt->ShadowInact($GetValue); - if ($min && $min != -1 || $max && $max != -1 || $warn && $warn != -1 || $inact && $inact != -1) { + if ($min && $min != -1 || $max && $max != 99999 || $warn && $warn != -1 || $inact && $inact != -1) { $us->{o}->{pcheckexpire}->set_active(1); $v->set_sensitive(1); } $min && $min != -1 and $us->{o}->{dbca}->set_text($min); $max && $max != -1 and $us->{o}->{dbcr}->set_text($max); $warn && $warn != -1 and $us->{o}->{bwbc}->set_text($warn); $inact && $inact != -1 and $us->{o}->{dbai}->set_text($inact); my $grps = $ctx->GroupsEnumerate(); my @sgroups = sort(@$grps); $members = $ctx->EnumerateGroupsByUser($username); - my $primgid = $userEnt->Gid($GetValue); + $primgid = $userEnt->Gid($GetValue); my $Gent = $ctx->LookupGroupById($primgid); foreach my $group (@sgroups) { if (any { $_ eq $group } @$members) { @@ -555,8 +557,7 @@ sub Edit { } $us->{o}->{primgroup}->set_popdown_strings(@primgroup); $Gent and $us->{o}->{primgroup}->entry->set_text($Gent->GroupName($GetValue)); - - + } elsif ($p == 1) { $nbG->set_size_request(300, 200); gtkappend_page($nbG, gtkpack_(Gtk2::VBox->new(0, 2), 1, BuildGui()), gtkshow(Gtk2::Label->new(N("Group Data")))); @@ -576,6 +577,7 @@ sub Edit { } else { $model->append_set([ 0 => gtkcreate_pixbuf($pix[1]), 1 => $user, 2 => 0]); } } } + my ($ch, $name, $uEnt, $gEnt, $ugid); gtkadd($w->{window}, gtkpack_(Gtk2::VBox->new(0,5), 1, !$p ? $nbU : $nbG, @@ -586,42 +588,75 @@ sub Edit { gtksignal_connect(Gtk2::Button->new($_->[0]), clicked => sub { if (!$retv) { if ($p == 0) { - $u{username} = $us->{o}->{login}->get_text(); + $u{username} = $us->{o}->{login}->get_text(); $error = 0; + if(!valid($u{username})) { raiseerror($us->{error}) } + $u{gecos} = $us->{o}->{fullname}->get_text(); + $u{homedir} = $us->{o}->{homedir}->get_text(); + $u{pw} = $us->{o}->{passwd}->get_text(); + $u{confm} = $us->{o}->{confpasswd}->get_text(); + $u{shell} = $us->{o}->{shells}->entry->get_text(); + $u{primgroup} = $userEnt->Gid($GetValue); + if ($u{pw} ne $u{confm}) { + raiseerror(N("Password Mismatch")); + } elsif (($u{pw} eq $u{confm}) && $u{pw} ne ' ') { + if ($sec{SECURE_LEVEL} > 3 && length($u{pw}) < 6) { raiseerror(N("This password is too simple. \n Good passwords should be > 6 caracters")) } + !$error and $ctx->UserSetPass($userEnt, $u{pw}); + } + if (!$error) { + $userEnt->UserName($u{username}); $userEnt->Gecos($u{gecos}); + $userEnt->HomeDir($u{homedir}); $userEnt->LoginShell($u{shell}); + $username = $userEnt->UserName($GetValue); + $model->foreach(sub { + my ($mod, $path, $iter) = @_; + $ch = $mod->get($iter, 2); + $name = $mod->get($iter, 1); + $gEnt = $ctx->LookupGroupByName($name); + $ugid = $gEnt->Gid($GetValue); + my $m = $gEnt->MemberName(1,0); + if ($ch == 1 && !InArray($username, $m) && $primgid != $ugid) { + $gEnt->MemberName($username, 1); + } else { + if (InArray($username, $m)) { + $gEnt->MemberName($username, 2); + } + } + $ctx->GroupModify($gEnt); + $iter->free; + return 0; + }, undef); + } + } elsif ($p == 1) { $g{groupname} = $us->{o}->{groupname}->get_text(); $error = 0; - if (!valid($g{groupname})) { raiseerror($us->{error}); $error = 1 }; - printf("Old Groupname = $groupname \t\t New groupname = %s\n",$g{groupname}); + if (!valid($g{groupname})) { raiseerror($us->{error}) }; if (!$error && $groupname ne $g{groupname}) {$groupEnt->GroupName($g{groupname})} $groupname = $groupEnt->GroupName($GetValue); $members = $ctx->EnumerateUsersByGroup($groupname); my $gid = $groupEnt->Gid($GetValue); - my ($ch, $name, $userEnt, $ugid); - $model->foreach(sub { - my ($mod, $path, $iter) = @_; - $ch = $mod->get($iter, 2); - $name = $mod->get($iter, 1); - if ($ch == 1) { - if (!any { $_ eq $name } @$members) { - print "\n******* $name ****\n"; - $userEnt = $ctx->LookupUserByName($name); - $ugid = $userEnt->Gid($GetValue); - $ugid != $gid and $groupEnt->MemberName($name,1); - } - } else { - if (any { $_ eq $name } @$members) { - $userEnt = $ctx->LookupUserByName($name); - if ($userEnt->Gid($GetValue) == $groupEnt->Gid($GetValue)) { - $model->set($iter, [0 => gtkcreate_pixbuf($pix[0])]); - $model->set($iter, [2 => 1]); - raiseerror(N("You cannot remove user '%s' from their primary group", $name)); - $error = 1; - } - !$error and $groupEnt->MemberName($name,2); - } - } - $iter->free; - return 0; - }, undef); + !$error and $model->foreach(sub { + my ($mod, $path, $iter) = @_; + $ch = $mod->get($iter, 2); + $name = $mod->get($iter, 1); + if ($ch == 1) { + if (!InArray($name, $members)) { + $uEnt = $ctx->LookupUserByName($name); + $ugid = $uEnt->Gid($GetValue); + $ugid != $gid and $groupEnt->MemberName($name,1); + } + } else { + if (InArray($name, $members)) { + $uEnt = $ctx->LookupUserByName($name); + if ($uEnt->Gid($GetValue) == $groupEnt->Gid($GetValue)) { + $model->set($iter, [0 => gtkcreate_pixbuf($pix[0])]); + $model->set($iter, [2 => 1]); + raiseerror(N("You cannot remove user '%s' from their primary group", $name)); + } + !$error and $groupEnt->MemberName($name,2); + } + } + $iter->free; + return 0; + }, undef); if (!$error) { $ctx->GroupModify($groupEnt); Refresh($sysfilter); @@ -721,6 +756,7 @@ sub valid { } sub raiseerror { my $w = ugtk2->new(N("Error"), grab => 1, center => 1, transient => $us->{wnd}->{rwindow}); + $error = 1; gtkadd($w->{window}, gtkpack_(Gtk2::VBox->new, 1, Gtk2::Label->new($_[0]), |