diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2004-11-30 11:35:00 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2004-11-30 11:35:00 +0000 |
commit | a5a0520e0bfca8ab6be9fa83dd453c9a4e8c94c5 (patch) | |
tree | 23ca265db4ca4c3299c2812f685302445040032b /perl-install/authentication.pm | |
parent | b6d2621f3a4a327d23d5a16247df839fca62dfec (diff) | |
download | drakx-a5a0520e0bfca8ab6be9fa83dd453c9a4e8c94c5.tar drakx-a5a0520e0bfca8ab6be9fa83dd453c9a4e8c94c5.tar.gz drakx-a5a0520e0bfca8ab6be9fa83dd453c9a4e8c94c5.tar.bz2 drakx-a5a0520e0bfca8ab6be9fa83dd453c9a4e8c94c5.tar.xz drakx-a5a0520e0bfca8ab6be9fa83dd453c9a4e8c94c5.zip |
- move some functions from any.pm to authentication.pm
- create authentication::ask_root_password_and_authentication() out of install_steps_interactive::setRootPassword()
Diffstat (limited to 'perl-install/authentication.pm')
-rw-r--r-- | perl-install/authentication.pm | 72 |
1 files changed, 72 insertions, 0 deletions
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; |