summaryrefslogtreecommitdiffstats
path: root/perl-install/any.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perl-install/any.pm')
-rw-r--r--perl-install/any.pm88
1 files changed, 44 insertions, 44 deletions
diff --git a/perl-install/any.pm b/perl-install/any.pm
index 1d9648403..a679ad0af 100644
--- a/perl-install/any.pm
+++ b/perl-install/any.pm
@@ -43,7 +43,7 @@ sub addKdmIcon {
eval { cp_af(facesdir() . $icon . ".png", $dest) } if $icon;
}
-sub allocUsers {
+sub alloc_user_faces {
my ($users) = @_;
my @m = my @l = facesnames();
foreach (grep { !$_->{icon} || $_->{icon} eq "automagic" } @$users) {
@@ -53,13 +53,50 @@ sub allocUsers {
}
}
-sub addUsers {
- my ($users) = @_;
+sub create_user {
+ my ($u, $isMD5) = @_;
+
+ my @existing = stat("$::prefix/home/$u->{name}");
+
+ if (!getpwnam($u->{name})) {
+ my $uid = $u->{uid} || $existing[4];
+ if ($uid && getpwuid($uid)) {
+ undef $uid; #- suggested uid already in use
+ }
+ my $gid = $u->{gid} || $existing[5] || int getgrnam($u->{name});
+ if ($gid) {
+ if (getgrgid($gid)) {
+ undef $gid if getgrgid($gid) ne $u->{name};
+ } else {
+ run_program::rooted($::prefix, 'groupadd', '-g', $gid, $u->{name});
+ }
+ }
+ require authentication;
+ run_program::rooted($::prefix,
+ 'adduser',
+ '-p', authentication::user_crypted_passwd($u, $isMD5),
+ if_($uid, '-u', $uid), if_($gid, '-g', $gid),
+ $u->{name});
+ }
+
+ my (undef, undef, $uid, $gid, undef, undef, undef, $home) = getpwnam($u->{name});
+
+ if (@existing && $::isInstall && ($uid != $existing[4] || $gid != $existing[5])) {
+ log::l("chown'ing $home from $existing[4].$existing[5] to $uid.$gid");
+ require commands;
+ eval { commands::chown_("-r", "$uid.$gid", "$::prefix$home") };
+ }
+}
+
+sub add_users {
+ my ($users, $authentication) = @_;
+
+ alloc_user_faces($users);
- allocUsers($users);
- foreach my $u (@$users) {
- run_program::rooted($::prefix, "usermod", "-G", join(",", @{$u->{groups}}), $u->{name}) if !is_empty_array_ref($u->{groups});
- addKdmIcon($u->{name}, delete $u->{auto_icon} || $u->{icon});
+ foreach (@$users) {
+ create_user($_, $authentication->{md5});
+ run_program::rooted($::prefix, "usermod", "-G", join(",", @{$_->{groups}}), $_->{name}) if !is_empty_array_ref($_->{groups});
+ addKdmIcon($_->{name}, delete $_->{auto_icon} || $_->{icon});
}
}
@@ -435,17 +472,6 @@ You can create additional entries or change the existing ones."), [ {
}
}
-my @etc_pass_fields = qw(name pw uid gid realname home shell);
-sub unpack_passwd {
- my ($l) = @_;
- my %l; @l{@etc_pass_fields} = split ':', chomp_($l);
- \%l;
-}
-sub pack_passwd {
- my ($l) = @_;
- join(':', @$l{@etc_pass_fields}) . "\n";
-}
-
sub get_autologin() {
my %desktop = getVarsFromSh("$::prefix/etc/sysconfig/desktop");
my $desktop = $desktop{DESKTOP} || 'KDE';
@@ -783,32 +809,6 @@ sub selectCountry {
$locale->{country} = $other || !@best ? $ext_country : $country;
}
-sub set_root_passwd {
- my ($superuser, $authentication) = @_;
- $superuser->{name} = 'root';
- write_passwd_user($superuser, $authentication->{md5});
- delete $superuser->{name};
-}
-
-sub write_passwd_user {
- my ($u, $isMD5) = @_;
-
- $u->{pw} = $u->{password} ? &crypt($u->{password}, $isMD5) : $u->{pw} || '';
- $u->{shell} ||= '/bin/bash';
-
- substInFile {
- my $l = unpack_passwd($_);
- if ($l->{name} eq $u->{name}) {
- add2hash_($u, $l);
- $_ = pack_passwd($u);
- $u = {};
- }
- if (eof && $u->{name}) {
- $_ .= pack_passwd($u);
- }
- } "$::prefix/etc/passwd";
-}
-
sub set_login_serial_console {
my ($port, $speed) = @_;