aboutsummaryrefslogtreecommitdiffstats
path: root/userdrake2
diff options
context:
space:
mode:
authorDaouda Lo <daouda@mandriva.com>2003-06-02 17:02:11 +0000
committerDaouda Lo <daouda@mandriva.com>2003-06-02 17:02:11 +0000
commit45afba2e65365a7080a3a6a85d67ee6a34d390cb (patch)
treec8caeb44be16e3ce6454513b69a17c1499d455b2 /userdrake2
parent63d7a47d47f4e5064632c89aff0a226e68a745d1 (diff)
downloaduserdrake-45afba2e65365a7080a3a6a85d67ee6a34d390cb.tar
userdrake-45afba2e65365a7080a3a6a85d67ee6a34d390cb.tar.gz
userdrake-45afba2e65365a7080a3a6a85d67ee6a34d390cb.tar.bz2
userdrake-45afba2e65365a7080a3a6a85d67ee6a34d390cb.tar.xz
userdrake-45afba2e65365a7080a3a6a85d67ee6a34d390cb.zip
- same function to get or set attributes
- use -65533 as an invalid number - more sanity checks
Diffstat (limited to 'userdrake2')
-rwxr-xr-xuserdrake292
1 files changed, 77 insertions, 15 deletions
diff --git a/userdrake2 b/userdrake2
index bfb4c71..67213ba 100755
--- a/userdrake2
+++ b/userdrake2
@@ -39,6 +39,7 @@ my $in = interactive->vnew('su', 'default');
my $us = {} ;
$us->{VERSION} = 0.91;
+my $error = 0;
my %prefs = getVarsFromSh($conffile);
my $sysfilter = text2bool($prefs{FILTER});
@@ -126,10 +127,10 @@ sub Refresh_Users_Full {
my $users = $ctx->UsersEnumerateFull();
$utree_model->clear();
my @UserReal;
- LOOP: foreach my $l (@$users) { next LOOP if ($filterusers && $l->Uid <= 499 || $l->Uid == 65534) ; push(@UserReal, $l) };
+ LOOP: foreach my $l (@$users) { next LOOP if ($filterusers && $l->Uid(-65533) <= 499 || $l->Uid(-65533) == 65534) ; push(@UserReal, $l) };
foreach my $l (@UserReal) {
- my $a = $l->Gid; my $group = $ctx->LookupGroupById($a);
- $utree_model->append_set([ 0 => $l->UserName, 1 => $l->Uid, 2 => $group->GroupName, 3 => $l->Gecos, 4 => $l->LoginShell, 5 => $l->HomeDir ]);
+ my $a = $l->Gid(-65533); my $group = $ctx->LookupGroupById($a);
+ $utree_model->append_set([ 0 => $l->UserName(-65533), 1 => $l->Uid(-65533), 2 => $group->GroupName(-65533), 3 => $l->Gecos(-65533), 4 => $l->LoginShell(-65533), 5 => $l->HomeDir(-65533) ]);
}
}
@@ -138,18 +139,18 @@ sub Refresh_Groups_Full {
my $groups = $ctx->GroupsEnumerateFull();
$gtree_model->clear();
my @GroupReal;
- LOOP:foreach my $g (@$groups) { next LOOP if ($filtergroups && $g->Gid <= 499 || $g->Gid == 65534); push(@GroupReal, $g) };
+ LOOP:foreach my $g (@$groups) { next LOOP if ($filtergroups && $g->Gid(-65533) <= 499 || $g->Gid(-65533) == 65534); push(@GroupReal, $g) };
foreach my $g (@GroupReal) {
- my $a = $g->Gid; my $group = $ctx->LookupGroupById($a);
- my $u_b_g = $ctx->EnumerateUsersByGroup($g->GroupName);
+ my $a = $g->Gid(-65533); my $group = $ctx->LookupGroupById($a);
+ my $u_b_g = $ctx->EnumerateUsersByGroup($g->GroupName(-65533));
my $listUbyG = join(',', @$u_b_g);
- $gtree_model->append_set([ 0 => $g->GroupName, 1 => $g->Gid, 2 => $listUbyG ]);
+ $gtree_model->append_set([ 0 => $g->GroupName(-65533), 1 => $g->Gid(-65533), 2 => $listUbyG ]);
}
}
sub AddUser {
my $w = ugtk2->new(N("Create New User"), grab => 1);
- my $mode = 0;
+ my $createhomedir = 1; my $is_system = 0;
my %u; my %sec = getVarsFromSh($secfile);
gtkadd($w->{window},
gtkpack_(Gtk2::VBox->new(0, 2),
@@ -170,15 +171,51 @@ sub AddUser {
gtksignal_connect(Gtk2::Button->new($_->[0]), clicked => sub {
if (!$r) {
$u{username} = $us->{o}->{log}->get_text();
- if (!valid($u{username})) { raiseerror($us->{error}); $mode = 1 };
- my $nm = $ctx->LookupGroupByName($u{username});
- if ($nm) { raiseerror(N("User already exists, please choose another User Name")); $mode = 1 };
- $mode and $us->{o}->{log}->set_text('');
+ if (!valid($u{username})) { raiseerror($us->{error}); $error = 1 };
+ my $nm = $ctx->LookupUserByName($u{username});
+ if ($nm) { raiseerror(N("User already exists, please choose another User Name")); $error = 1 ; $us->{o}->{log}->set_text('') };
$u{passwd} = $us->{o}->{passwd}->get_text();
- if ($us->{o}->{passwd}->get_text() ne $us->{o}->{confpasswd}->get_text()) { raiseerror(N("Password Mismatch")); $mode = 1 };
- !$mode and print "############# Test Succesfull ##############\n";
+ if ($us->{o}->{passwd}->get_text() 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 ($us->{o}->{userid}->get_active) {
+ if ((my $u{uid} = $us->{o}->{uid}->get_value) < 500) {
+ print 1;
+ }
+ };
+ if ($us->{o}{privategroup}->get_active) {
+ if (!$error) {
+ #Check if group exist
+ my $gr = $ctx->LookupGroupByName($u{username});
+ if ($gr) {
+ my $groupchoice = ChooseGroup();
+ if ($groupchoice == 0 && !$error) {
+ #You choose to put it in the existing group
+ $u{gid} = $gr->Gid(-65533);
+ printf("EXISTGROUP: le Gid du group sera %d\n groupchoice = %d\n", $u{gid}, $groupchoice);
+ } elsif ($groupchoice == 1) {
+ # Put it in 'users' group
+ $u{gid} = Add2UsersGroup();
+ printf("USERGROUP: le Gid du group sera %d\n groupchoice = %d\n", $u{gid}, $groupchoice);
+ }
+ } else {
+ #it's a new group: Add it
+ my $newgroup = $ctx->AddGroup($u{username},$is_system);
+ $u{gid} = $newgroup->Gid(-65533);
+ printf("NEWGROUP : le Gid du group sera %d\n", $u{gid});
+ }
+ }
+ } else {
+ $u{gid} = Add2UsersGroup();
+ printf("le Gid du group sera %d", $u{gid});
+ }
+ if(!$error) {
+ print "############# Test Succesfull ##############\n";
+ $u{gecos} = $us->{o}->{fullname}->get_text();
+ $u{homedir} = $us->{o}->{homedir}->get_text() || "";
+ $u{loginshell} = $us->{o}->{shells}->entry->get_text();
+ }
}
- !$mode and Gtk2->main_quit; $mode = 0 })
+ !$error and Gtk2->main_quit; $error = 0 })
} ([ N("Cancel"), 1 ], [ N("Ok"), 0 ])),
)
);
@@ -191,6 +228,30 @@ sub AddUser {
$w->{rwindow}->show_all;
$w->main;
}
+sub Add2UsersGroup() {
+ my $usersgroup = $ctx->LookupGroupByName('users');
+ return $usersgroup->Gid(-65533);
+}
+sub ChooseGroup {
+ my $w = ugtk2->new(N("Choose Group"), grab => 1, center => 1);
+ my $choice;
+ my @radio = gtkradio(N("Add to the existing group"), (N("Add to the existing group"), N("Add to the 'users' group")));
+ gtkadd($w->{window},
+ gtkpack__(Gtk2::VBox->new(0,5),
+ Gtk2::Label->new(N("A group with this name already exists. What would you like to do?")),
+ gtkpack(Gtk2::VBox->new(0,0), @radio),
+ Gtk2::HSeparator->new,
+ gtkpack(create_hbox(),
+ gtksignal_connect(Gtk2::Button->new(N("Ok")), clicked => sub {
+ each_index { $_->get_active and $choice = $::i } @radio;
+ Gtk2->main_quit;
+ }),
+ gtksignal_connect(Gtk2::Button->new(N("Cancel")), clicked => sub { $w->{retval} = 0; $error = 1; Gtk2->main_quit }))));
+ $w->main;
+ $choice;
+}
+
+
sub AddGroup {
my $w = ugtk2->new(N("Create New User"), grab => 1);
my $mode = 0;
@@ -220,6 +281,7 @@ sub AddGroup {
$w->main;
}
+
sub Delete {
}