From a5a0520e0bfca8ab6be9fa83dd453c9a4e8c94c5 Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Tue, 30 Nov 2004 11:35:00 +0000 Subject: - move some functions from any.pm to authentication.pm - create authentication::ask_root_password_and_authentication() out of install_steps_interactive::setRootPassword() --- perl-install/any.pm | 45 +------------------ perl-install/authentication.pm | 72 +++++++++++++++++++++++++++++++ perl-install/install_steps.pm | 3 +- perl-install/install_steps_interactive.pm | 25 +---------- 4 files changed, 77 insertions(+), 68 deletions(-) diff --git a/perl-install/any.pm b/perl-install/any.pm index b1dcbb78c..0099ecf92 100644 --- a/perl-install/any.pm +++ b/perl-install/any.pm @@ -71,9 +71,10 @@ sub create_user { run_program::rooted($::prefix, 'groupadd', '-g', $gid, $u->{name}); } } + require authentication; run_program::rooted($::prefix, 'adduser', - '-p', user_crypted_passwd($u, $isMD5), + '-p', authentication::user_crypted_passwd($u, $isMD5), if_($uid, '-u', $uid), if_($gid, '-g', $gid), $u->{name}); } @@ -470,17 +471,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'; @@ -826,37 +816,6 @@ sub selectCountry { $locale->{country} = $other || !@best ? $ext_country : $country; } -sub user_crypted_passwd { - my ($u, $isMD5) = @_; - $u->{password} ? &crypt($u->{password}, $isMD5) : $u->{pw} || ''; -} - -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} = user_crypted_passwd($u, $isMD5); - $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) = @_; diff --git a/perl-install/authentication.pm b/perl-install/authentication.pm index fecbbdb06..7ff1b6a1c 100644 --- a/perl-install/authentication.pm +++ b/perl-install/authentication.pm @@ -146,6 +146,36 @@ The command 'wbinfo -t' will test whether your authentication secrets are good." 1; } +sub ask_root_password_and_authentication { + my ($in, $netc, $superuser, $authentication, $meta_class, $security) = @_; + + my $kind = to_kind($authentication); + + $in->ask_from_({ + title => N("Set root password and network authentication methods"), + messages => N("Set root password"), + advanced_messages => kind2description(), + interactive_help_id => "setRootPassword", + cancel => ($security <= 2 ? + #-PO: keep this short or else the buttons will not fit in the window + N("No password") : ''), + focus_first => 1, + callbacks => { + complete => sub { + $superuser->{password} eq $superuser->{password2} or $in->ask_warn('', [ N("The passwords do not match"), N("Please try again") ]), return 1,0; + length $superuser->{password} < 2 * $security + and $in->ask_warn('', N("This password is too short (it must be at least %d characters long)", 2 * $security)), return 1,0; + return 0; + } } }, [ +{ label => N("Password"), val => \$superuser->{password}, hidden => 1 }, +{ label => N("Password (again)"), val => \$superuser->{password2}, hidden => 1 }, +{ label => N("Authentication"), val => \$kind, type => 'list', list => [ authentication::kinds($meta_class) ], format => \&authentication::kind2name, advanced => 1 }, + ]) or delete $superuser->{password}; + + ask_parameters($in, $netc, $authentication, $kind) or goto &ask_root_password_and_authentication; +} + + sub get() { my $system_auth = cat_("/etc/pam.d/system-auth"); { md5 => $system_auth =~ /md5/, shadow => $system_auth =~ /shadow/ }; @@ -579,5 +609,47 @@ sub query_srv_names { map { $_->target } $query->answer; } +sub user_crypted_passwd { + my ($u, $isMD5) = @_; + $u->{password} ? &crypt($u->{password}, $isMD5) : $u->{pw} || ''; +} + +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} = user_crypted_passwd($u, $isMD5); + $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"; +} + +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"; +} + 1; diff --git a/perl-install/install_steps.pm b/perl-install/install_steps.pm index f7c911d1f..104c8bd19 100644 --- a/perl-install/install_steps.pm +++ b/perl-install/install_steps.pm @@ -759,7 +759,8 @@ sub configurePrinter { sub setRootPassword { my ($o) = @_; $o->{superuser} ||= {}; - any::set_root_passwd($o->{superuser}, $o->{authentication}); + require authentication; + authentication::set_root_passwd($o->{superuser}, $o->{authentication}); install_any::set_authentication($o); } diff --git a/perl-install/install_steps_interactive.pm b/perl-install/install_steps_interactive.pm index 40ab337bb..08683cd0e 100644 --- a/perl-install/install_steps_interactive.pm +++ b/perl-install/install_steps_interactive.pm @@ -1200,30 +1200,7 @@ sub setRootPassword { if ($o->{security} >= 1 || $clicked) { require authentication; - my $authentication_kind = authentication::to_kind($o->{authentication} ||= {}); - - $o->ask_from_({ - title => N("Set root password and network authentication methods"), - messages => N("Set root password"), - advanced_messages => authentication::kind2description(), - interactive_help_id => "setRootPassword", - cancel => ($o->{security} <= 2 ? - #-PO: keep this short or else the buttons will not fit in the window - N("No password") : ''), - focus_first => 1, - callbacks => { - complete => sub { - $sup->{password} eq $sup->{password2} or $o->ask_warn('', [ N("The passwords do not match"), N("Please try again") ]), return 1,0; - length $sup->{password} < 2 * $o->{security} - and $o->ask_warn('', N("This password is too short (it must be at least %d characters long)", 2 * $o->{security})), return 1,0; - return 0; - } } }, [ -{ label => N("Password"), val => \$sup->{password}, hidden => 1 }, -{ label => N("Password (again)"), val => \$sup->{password2}, hidden => 1 }, -{ label => N("Authentication"), val => \$authentication_kind, type => 'list', list => [ authentication::kinds($o->{meta_class}) ], format => \&authentication::kind2name, advanced => 1 }, - ]) or delete $sup->{password}; - - authentication::ask_parameters($o, $o->{netc}, $o->{authentication}, $authentication_kind) or goto &setRootPassword; + authentication::ask_root_password_and_authentication($o, $o->{netc}, $sup, $o->{authentication} ||= {}, $o->{meta_class}, $o->{security}); } install_steps::setRootPassword($o); } -- cgit v1.2.1