summaryrefslogtreecommitdiff
path: root/Users
diff options
context:
space:
mode:
authorcarlosg <carlosg>2006-10-05 12:27:21 +0000
committercarlosg <carlosg>2006-10-05 12:27:21 +0000
commitf47a9349484ace8adec505c846b54da36b7321d8 (patch)
tree10da5bfaa0d1367f18b18d1f7c4b87c6cf4655ed /Users
parent416f7fa1c0224f5ff2cada729b6238d23d6f00ec (diff)
2006-10-05 Carlos Garnacho <carlosg@gnome.org>
Ported to 1.9.x a huge and incredible patch by Darren Kenny <Darren.Kenny@Sun.COM> and Erast Benson <erast@gnusolaris.com> to make s-t-b recognize and configure SunOS based systems. * Utils/Platform.pm: recognize OpenSolaris and Nexenta properly. * Utils/File.pm (read_joined_lines): added. * Users/Shells.pm, Users.pm, Groups.pm: add SunOS case paths. * Time/NTP.pm, TimeDate.pm: ditto. * Shares/NFS.pm: parse/modify dfstab in the SunOS case * Network/Hosts.pm, Ifaces.pm: add code to deal with SunOS network configuration. * Init/Services.pm: deal with SMF init system.
Diffstat (limited to 'Users')
-rw-r--r--Users/Groups.pm82
-rw-r--r--Users/Shells.pm48
-rw-r--r--Users/Users.pm86
3 files changed, 168 insertions, 48 deletions
diff --git a/Users/Groups.pm b/Users/Groups.pm
index 118ad66..8b13f00 100644
--- a/Users/Groups.pm
+++ b/Users/Groups.pm
@@ -41,6 +41,7 @@ $cmd_groupmod = &Utils::File::locate_tool ("groupmod");
$cmd_delgroup = &Utils::File::locate_tool ("delgroup");
$cmd_addgroup = &Utils::File::locate_tool ("addgroup");
+$cmd_usermod = &Utils::File::locate_tool ("usermod");
$cmd_gpasswd = &Utils::File::locate_tool ("gpasswd");
$cmd_pw = &Utils::File::locate_tool ("pw");
@@ -61,6 +62,70 @@ sub del_group
&Utils::File::run ($command);
}
+# This is only for Linux and SunOS,
+# pw groupadd manages this in FreeBSD
+sub add_user_to_group
+{
+ my ($group, $user) = @_;
+ my ($command);
+
+ if ($Utils::Backend::tool{"system"} eq "SunOS")
+ {
+ my ($groups, @arr);
+
+ $groups = &Utils::File::run_backtick ("groups $user");
+ $groups =~ s/.*://;
+ chomp ($groups);
+
+ @arr = split (/ /, $groups);
+ push @arr, $group;
+ $groups = join (',', @arr);
+ $groups =~ s/^,//;
+ $groups =~ s/,$//;
+
+ $command = "$cmd_usermod -G $groups $user";
+ }
+ else
+ {
+ $command = "$cmd_gpasswd -a \'" . $user . "\' " . $group;
+ }
+
+ &Utils::File::run ($command);
+}
+
+# This is only for Linux and SunOS,
+# pw groupdel manages this in FreeBSD
+sub delete_user_from_group
+{
+ my ($group, $user) = @_;
+ my ($command);
+
+ if ($Utils::Backend::tool{"system"} eq "SunOS")
+ {
+ my ($groups, @arr);
+
+ $groups = &Utils::File::run_backtick ("groups $user");
+ $groups =~ s/.*://;
+ chomp ($groups);
+
+ # delete the user
+ $groups =~ s/[ \t]+$group//;
+
+ @arr = split (/ /, $groups);
+ $groups = join (',', @arr);
+ $groups =~ s/^,//;
+ $groups =~ s/,$//;
+
+ $command = "$cmd_usermod -G $groups $user";
+ }
+ else
+ {
+ $command = "$cmd_gpasswd -d \'" . $user . "\' \'" . $group . "\'";
+ }
+
+ &Utils::File::run ($command);
+}
+
sub add_group
{
my ($group) = @_;
@@ -95,10 +160,7 @@ sub add_group
foreach $user (sort @$u)
{
- $command = "$cmd_gpasswd -a \'" . $user .
- "\' " . $$group[$LOGIN];
-
- &Utils::File::run ($command);
+ &add_user_to_group ($$group[$LOGIN], $user);
}
}
}
@@ -144,19 +206,13 @@ sub change_group
{
# users with state 2 are those that only appeared
# in the old group configuration, so we must delete them
- $command = "$cmd_gpasswd -d \'" . $user . "\' \'" .
- $$new_group[$LOGIN] . "\'";
-
- &Utils::File::run ($command);
+ &delete_user_from_group ($$new_group [$LOGIN], $user);
}
- else
+ elsif ($state == 1)
{
# users with state 1 are those who were added
# to the new group configuration
- $command = "$cmd_gpasswd -a \'" . $user . "\' \'" .
- $$new_group[$LOGIN] . "\'";
-
- &Utils::File::run ($command);
+ &add_user_to_group ($$new_group[$LOGIN], $user);
}
}
}
diff --git a/Users/Shells.pm b/Users/Shells.pm
index 1c473ec..6ebcfa3 100644
--- a/Users/Shells.pm
+++ b/Users/Shells.pm
@@ -37,27 +37,46 @@ sub get_files
return $shells_file;
}
+sub push_shell
+{
+ my ($shells, $shell) = @_;
+ push @$shells, $shell if (stat ($shell));
+}
+
sub get
{
- my ($ifh, @shells);
+ my ($ifh, @shells, $shell);
# Init @shells, I think every *nix has /bin/false.
- if (stat ("/bin/false"))
- {
- push @shells, "/bin/false";
- }
-
- $ifh = &Utils::File::open_read_from_names($shells_file);
- return unless $ifh;
+ &push_shell (\@shells, "/bin/false");
- while (<$ifh>)
+ if ($Utils::Backend::tool{"system"} eq "SunOS")
{
- next if &Utils::Util::ignore_line ($_);
- chomp;
- push @shells, $_ if (stat ($_));
+ #SunOS doesn't have anything like /etc/shells
+ my $possible_shells =
+ [ "/bin/bash", "/bin/csh", "/bin/jsh", "/bin/ksh", "/bin/pfcsh", "/bin/pfksh", "/bin/pfsh", "/bin/sh",
+ "/bin/tcsh", "/bin/zsh", "/sbin/jsh", "/sbin/jsh", "/sbin/pfsh", "/sbin/sh", "/usr/bin/bash",
+ "/usr/bin/csh", "/usr/bin/jsh", "/usr/bin/ksh", "/usr/bin/pfcsh", "/usr/bin/pfksh", "/usr/bin/pfsh",
+ "/usr/bin/sh", "/usr/bin/tcsh", "/usr/bin/zsh", "/usr/xpg4/bin/sh" ];
+
+ foreach $shell (@$possible_shells)
+ {
+ &push_shell (\@shells, $shell);
+ }
}
+ else
+ {
+ $ifh = &Utils::File::open_read_from_names($shells_file);
+
+ while (<$ifh>)
+ {
+ next if &Utils::Util::ignore_line ($_);
+ chomp;
+ &push_shell (\@shells, $_);
+ }
- &Utils::File::close_file ($ifh);
+ &Utils::File::close_file ($ifh);
+ }
return \@shells;
}
@@ -67,6 +86,9 @@ sub set
my ($shells) = @_;
my ($buff, $line, $nline);
+ #SunOS doesn't have /etc/shells
+ return if ($Utils::Backend::tool{"system"} eq "SunOS");
+
$buff = &Utils::File::load_buffer ($shells_file);
return unless $buff;
diff --git a/Users/Users.pm b/Users/Users.pm
index edf6c98..846eeff 100644
--- a/Users/Users.pm
+++ b/Users/Users.pm
@@ -207,6 +207,7 @@ sub get_profiles_prop_array
}
}
+#FIXME: do not hardcode GIDs like that
my $rh_logindefs_defaults = {
'shell' => '/bin/bash',
'group' => -1,
@@ -242,6 +243,7 @@ my $logindefs_dist_map = {
'slackware-9.1.0' => $gentoo_logindefs_defaults,
'freebsd-5' => $freebsd_logindefs_defaults,
'suse-9.0' => $gentoo_logindefs_defaults,
+ 'solaris-2.11' => $gentoo_logindefs_defaults,
};
@@ -397,7 +399,7 @@ sub get
# we need to make sure that there are 5 elements
push @comment, "" while (scalar (@comment) < 5);
$line[$COMMENT] = [@comment];
-
+
$users_hash{$login} = [@line];
}
@@ -417,6 +419,9 @@ sub get
$login = shift @line;
$passwd = shift @line;
+ # do not add data if the user isn't present
+ next if (!exists $users_hash{$login});
+
$users_hash{$login}[$PASSWD] = $passwd;
# FIXME: add the rest of the fields?
@@ -474,44 +479,52 @@ sub change_user_chfn
{
my ($login, $old_comment, $comment) = @_;
my ($fname, $office, $office_phone, $home_phone);
- my ($command);
+ my ($command, $str);
return if !$login;
# Compare old and new data
return if (Utils::Util::struct_eq ($old_comment, $comment));
+ $str = join (",", @$comment);
if ($Utils::Backend::tool{"system"} eq "FreeBSD")
{
- my ($str);
-
- $str = join (",", @$comment);
$command = "$cmd_pw usermod -n " . $login . " -c \'" . $str . "\'";
}
else
{
- ($fname, $office, $office_phone, $home_phone) = @$comment;
+ $command = "$cmd_usermod -c \'" . $str . "\' " . $login;
+ }
- $command = "$cmd_chfn" .
- " -f \'" . $fname . "\'" .
- " -h \'" . $home_phone . "\'";
+ &Utils::File::run ($command);
+}
- if ($Utils::Backend::tool{"platform"} =~ /^debian/ ||
- $Utils::Backend::tool{"platform"} =~ /^archlinux/)
- {
- $command .= " -r \'" . $office . "\'" .
- " -w \'" . $office_phone . "\'";
- }
- else
+# modifies /etc/shadow directly, not good practice,
+# but better than passing clean passwords around
+sub modify_shadow_password
+{
+ my ($login, $password) = @_;
+ my ($buffer, $i, @arr);
+
+ $buffer = &Utils::File::load_buffer (@shadow_names);
+ return if (!$buffer);
+ $i = 0;
+
+ while ($$buffer[$i])
+ {
+ @arr = split ':', $$buffer[$i], -1;
+
+ if ($arr[0] eq $login)
{
- $command .= " -o \'" . $office . "\'" .
- " -p \'" . $office_phone . "\'";
+ $arr[1] = $password;
+ $$buffer[$i] = join (':', @arr) . "\n";
+ last;
}
- $command .= " $login";
+ $i++;
}
- &Utils::File::run ($command);
+ &Utils::File::save_buffer ($buffer, @shadow_names);
}
sub add_user
@@ -542,6 +555,22 @@ sub add_user
print $pwdpipe $$user[$PASSWD];
&Utils::File::close_file ($pwdpipe);
}
+ elsif ($Utils::Backend::tool{"system"} eq "SunOS")
+ {
+ $home_parents = $$user[$HOME];
+ $home_parents =~ s/\/+[^\/]+\/*$//;
+ &Utils::File::run ("$tool_mkdir -p $home_parents");
+
+ $command = "$cmd_useradd" .
+ " -d \'" . $$user[$HOME] . "\'" .
+ " -g \'" . $$user[$GID] . "\'" .
+ " -s \'" . $$user[$SHELL] . "\'" .
+ " -u \'" . $$user[$UID] . "\'" .
+ " \'" . $$user[$LOGIN] . "\'";
+
+ &Utils::File::run ($command);
+ &modify_shadow_password ($$user[$LOGIN], $$user[$PASSWD]);
+ }
else
{
$home_parents = $$user[$HOME];
@@ -606,6 +635,19 @@ sub change_user
print $pwdpipe $$new_user[$PASSWD];
&Utils::File::close_file ($pwdpipe);
}
+ elsif ($Utils::Backend::tool{"system"} eq "SunOS")
+ {
+ $command = "$cmd_usermod" .
+ " -d \'" . $$new_user[$HOME] . "\'" .
+ " -g \'" . $$new_user[$GID] . "\'" .
+ " -l \'" . $$new_user[$LOGIN] . "\'" .
+ " -s \'" . $$new_user[$SHELL] . "\'" .
+ " -u \'" . $$new_user[$UID] . "\'" .
+ " \'" . $$old_user[$LOGIN] . "\'";
+
+ &Utils::File::run ($command);
+ &modify_shadow_password ($$new_user[$LOGIN], $$new_user[$PASSWD]);
+ }
else
{
$command = "$cmd_usermod" .
@@ -675,7 +717,7 @@ sub set
{
$users{$$i[0]} |= 1;
$config_hash{$$i[0]} = $i;
- }
+ }
foreach $i (@$old_config)
{
@@ -703,7 +745,7 @@ sub set
{
&change_user ($old_config_hash{$i}, $config_hash{$i});
}
- }
+ }
}
}