diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2004-01-08 17:31:36 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2004-01-08 17:31:36 +0000 |
commit | 6887bb46366245ba10c35d907dc6a3f206d804b1 (patch) | |
tree | ef66e7dcc4f74ebac72ed8574365e8807136e0a3 | |
parent | 85f7d9cca33fdfb0688789e4116db9f0b1c88fa5 (diff) | |
download | drakx-backup-do-not-use-6887bb46366245ba10c35d907dc6a3f206d804b1.tar drakx-backup-do-not-use-6887bb46366245ba10c35d907dc6a3f206d804b1.tar.gz drakx-backup-do-not-use-6887bb46366245ba10c35d907dc6a3f206d804b1.tar.bz2 drakx-backup-do-not-use-6887bb46366245ba10c35d907dc6a3f206d804b1.tar.xz drakx-backup-do-not-use-6887bb46366245ba10c35d907dc6a3f206d804b1.zip |
- integrate chkauth (which is now deprecated)
- new module authentication
-rw-r--r-- | perl-install/any.pm | 97 | ||||
-rw-r--r-- | perl-install/authentication.pm | 237 | ||||
-rw-r--r-- | perl-install/install_any.pm | 3 | ||||
-rw-r--r-- | perl-install/install_steps_interactive.pm | 7 | ||||
-rwxr-xr-x | perl-install/standalone/drakauth | 13 |
5 files changed, 251 insertions, 106 deletions
diff --git a/perl-install/any.pm b/perl-install/any.pm index 8592edc43..68f994407 100644 --- a/perl-install/any.pm +++ b/perl-install/any.pm @@ -954,101 +954,4 @@ sub config_mtools { } $file; } - -sub authentication_kinds() { - ('local', 'LDAP', 'NIS', 'winbind'); -} -sub authentication_kind2description { - my ($kind) = @_; - ${{ local => N("Local files"), LDAP => N("LDAP"), NIS => N("NIS"), winbind => N("Windows Domain") }}{$kind}; -} -sub authentication2authentication_kind { - my ($authentication) = @_; - (find { $authentication->{$_} } authentication_kinds()) || 'local'; -} - -sub ask_authentification_parameters { - my ($in, $netc, $authentication, $authentication_kind) = @_; - - my $val = $authentication->{$authentication_kind}; - - if ($authentication_kind eq 'LDAP') { - $val ||= 'ldap.' . $netc->{DOMAINNAME}; - $netc->{LDAPDOMAIN} ||= join(',', map { "dc=$_" } split /\./, $netc->{DOMAINNAME}); - $in->ask_from('', - N("Authentication LDAP"), - [ { label => N("LDAP Base dn"), val => \$netc->{LDAPDOMAIN} }, - { label => N("LDAP Server"), val => \$val }, - ]) or return; - } elsif ($authentication_kind eq 'NIS') { - $val ||= 'broadcast'; - $in->ask_from('', - N("Authentication NIS"), - [ { label => N("NIS Domain"), val => \ ($netc->{NISDOMAIN} ||= $netc->{DOMAINNAME}) }, - { label => N("NIS Server"), val => \$val, list => ["broadcast"], not_edit => 0 }, - ]) or return; - } elsif ($authentication_kind eq 'winbind') { - #- maybe we should browse the network like diskdrake --smb and get the 'doze server names in a list - #- but networking isn't setup yet necessarily - $in->ask_warn('', N("For this to work for a W2K PDC, you will probably need to have the admin run: C:\\>net localgroup \"Pre-Windows 2000 Compatible Access\" everyone /add and reboot the server.\nYou will also need the username/password of a Domain Admin to join the machine to the Windows(TM) domain.\nIf networking is not yet enabled, Drakx will attempt to join the domain after the network setup step.\nShould this setup fail for some reason and domain authentication is not working, run 'smbpasswd -j DOMAIN -U USER%%PASSWORD' using your Windows(tm) Domain, and Admin Username/Password, after system boot.\nThe command 'wbinfo -t' will test whether your authentication secrets are good.")); - $in->ask_from('', - N("Authentication Windows Domain"), - [ { label => N("Windows Domain"), val => \ ($netc->{WINDOMAIN} ||= $netc->{DOMAINNAME}) }, - { label => N("Domain Admin User Name"), val => \$val }, - { label => N("Domain Admin Password"), val => \$authentication->{winpass}, hidden => 1 }, - ]) or return; - } - #- keep only one authentication - delete $authentication->{$_} foreach authentication_kinds(); - $authentication->{$authentication_kind} = $val; - 1; -} - -sub set_authentication { - my ($in, $netc, $authentication, $when_network_is_up) = @_; - my ($shadow, $ldap, $nis, $winbind, $winpass) = @$authentication{qw(shadow LDAP NIS winbind winpass)}; - enableShadow() if $shadow; - if ($ldap) { - $in->do_pkgs->install(qw(chkauth openldap-clients nss_ldap pam_ldap autofs)); - run_program::rooted($::prefix, "/usr/sbin/chkauth", "ldap", "-D", $netc->{LDAPDOMAIN}, "-s", $ldap); - } elsif ($nis) { - #$o->pkg_install(qw(chkauth ypbind yp-tools net-tools)); - #run_program::rooted($::prefix, "/usr/sbin/chkauth", "yp", $domain, "-s", $nis); - $in->do_pkgs->install("ypbind"); - my $domain = $netc->{NISDOMAIN}; - $domain || $nis ne "broadcast" or die \N("Can't use broadcast with no NIS domain"); - my $t = $domain ? "domain $domain" . ($nis ne "broadcast" && " server") : "ypserver"; - substInFile { - $_ = "#~$_" unless /^#/; - $_ .= "$t $nis\n" if eof; - } "$::prefix/etc/yp.conf"; - require network::network; - network::network::write_conf("$::prefix/etc/sysconfig/network", $netc); - - $when_network_is_up->(sub { - run_program::rooted($::prefix, 'nisdomainname', $domain); - run_program::rooted($::prefix, 'service', 'ypbind', 'restart'); - }) if !$::isInstall; #- TODO: also do it during install since nis can be useful to resolve domain names. Not done because 9.2-RC - } elsif ($winbind) { - my $domain = $netc->{WINDOMAIN}; - $domain =~ tr/a-z/A-Z/; - - $in->do_pkgs->install(qw(samba-winbind samba-common)); - { #- setup pam - my $f = "$::prefix/etc/pam.d/system-auth"; - cp_af($f, "$f.orig"); - cp_af("$f-winbind", $f); - } - require network::smb; - network::smb::write_smb_conf($domain); - run_program::rooted($::prefix, "chkconfig", "--level", "35", "winbind", "on"); - mkdir_p("$::prefix/home/$domain"); - - #- defer running smbpassword until the network is up - $when_network_is_up->(sub { - run_program::rooted($::prefix, "/usr/bin/smbpasswd", "-j", $domain, "-U", $winbind . "%" . $winpass); - }); - } -} - 1; diff --git a/perl-install/authentication.pm b/perl-install/authentication.pm new file mode 100644 index 000000000..c085adc35 --- /dev/null +++ b/perl-install/authentication.pm @@ -0,0 +1,237 @@ +package authentication; # $Id$ + +use common; +use any; + + +sub kinds() { + ('local', 'LDAP', 'NIS', 'winbind'); +} +sub kind2description { + my ($kind) = @_; + ${{ local => N("Local files"), LDAP => N("LDAP"), NIS => N("NIS"), winbind => N("Windows Domain") }}{$kind}; +} +sub to_kind { + my ($authentication) = @_; + (find { $authentication->{$_} } kinds()) || 'local'; +} + +sub ask_parameters { + my ($in, $netc, $authentication, $kind) = @_; + + my $val = $authentication->{$kind}; + + if ($kind eq 'LDAP') { + $val ||= 'ldap.' . $netc->{DOMAINNAME}; + $netc->{LDAPDOMAIN} ||= join(',', map { "dc=$_" } split /\./, $netc->{DOMAINNAME}); + $in->ask_from('', + N("Authentication LDAP"), + [ { label => N("LDAP Base dn"), val => \$netc->{LDAPDOMAIN} }, + { label => N("LDAP Server"), val => \$val }, + ]) or return; + } elsif ($kind eq 'NIS') { + $val ||= 'broadcast'; + $in->ask_from('', + N("Authentication NIS"), + [ { label => N("NIS Domain"), val => \ ($netc->{NISDOMAIN} ||= $netc->{DOMAINNAME}) }, + { label => N("NIS Server"), val => \$val, list => ["broadcast"], not_edit => 0 }, + ]) or return; + } elsif ($kind eq 'winbind') { + #- maybe we should browse the network like diskdrake --smb and get the 'doze server names in a list + #- but networking isn't setup yet necessarily + $in->ask_warn('', N("For this to work for a W2K PDC, you will probably need to have the admin run: C:\\>net localgroup \"Pre-Windows 2000 Compatible Access\" everyone /add and reboot the server.\nYou will also need the username/password of a Domain Admin to join the machine to the Windows(TM) domain.\nIf networking is not yet enabled, Drakx will attempt to join the domain after the network setup step.\nShould this setup fail for some reason and domain authentication is not working, run 'smbpasswd -j DOMAIN -U USER%%PASSWORD' using your Windows(tm) Domain, and Admin Username/Password, after system boot.\nThe command 'wbinfo -t' will test whether your authentication secrets are good.")); + $in->ask_from('', + N("Authentication Windows Domain"), + [ { label => N("Windows Domain"), val => \ ($netc->{WINDOMAIN} ||= $netc->{DOMAINNAME}) }, + { label => N("Domain Admin User Name"), val => \$val }, + { label => N("Domain Admin Password"), val => \$authentication->{winpass}, hidden => 1 }, + ]) or return; + } + #- keep only one authentication + delete $authentication->{$_} foreach kinds(); + $authentication->{$kind} = $val; + 1; +} + +sub set { + my ($in, $netc, $authentication, $when_network_is_up) = @_; + + any::enableShadow() if $authentication->{shadow}; + + my $kind = authentication::to_kind($authentication); + my $val = $authentication->{$kind}; + + log::l("authentication::set $kind with $val"); + + if ($kind eq 'LDAP') { + + my $domain = $netc->{LDAPDOMAIN} || do { + my $s = run_program::rooted_get_stdout($::prefix, 'ldapsearch', '-x', '-h', $val, '-b', '', '-s', 'base', '+'); + first($s =~ /namingContexts: (.+)/); + } or log::l("no ldap domain found on server $val"), return; + + $in->do_pkgs->install(qw(openldap-clients nss_ldap pam_ldap autofs)); + + set_nsswitch_priority('ldap'); + set_pam_authentication('ldap'); + set_ldap_conf($domain, $val, 1); + } elsif ($kind eq 'NIS') { + $in->do_pkgs->install('ypbind'); + my $domain = $netc->{NISDOMAIN}; + $domain || $val ne "broadcast" or die \N("Can't use broadcast with no NIS domain"); + my $t = $domain ? "domain $domain" . ($val ne "broadcast" && " server") : "ypserver"; + substInFile { + $_ = "#~$_" unless /^#/; + $_ .= "$t $val\n" if eof; + } "$::prefix/etc/yp.conf"; + + set_nsswitch_priority('nis'); + #- no need to modify system-auth for nis + + $when_network_is_up->(sub { + run_program::rooted($::prefix, 'nisdomainname', $domain); + run_program::rooted($::prefix, 'service', 'ypbind', 'restart'); + }) if !$::isInstall; #- TODO: also do it during install since nis can be useful to resolve domain names. Not done because 9.2-RC + } elsif ($kind eq 'winbind') { + my $domain = $netc->{WINDOMAIN}; + $domain =~ tr/a-z/A-Z/; + + $in->do_pkgs->install(qw(samba-winbind samba-common)); + set_pam_authentication('winbind'); + + require network::smb; + network::smb::write_smb_conf($domain); + run_program::rooted($::prefix, "chkconfig", "--level", "35", "winbind", "on"); + mkdir_p("$::prefix/home/$domain"); + + #- defer running smbpassword until the network is up + $when_network_is_up->(sub { + run_program::rooted($::prefix, 'smbpasswd', '-j', $domain, '-U', $val . '%' . $authentication->{winpass}); + }); + } +} + + +sub pam_modules() { + 'pam_ldap', 'pam_winbind', 'pam_mkhomedir'; +} +sub pam_module_from_path { + $_[0] && $_[0] =~ m|/lib/security/(pam_.*)\.so| && $1; +} +sub pam_module_to_path { + "/lib/security/$_[0].so"; +} +sub pam_format_line { + my ($type, $control, $module, @para) = @_; + sprintf("%-11s %-13s %s\n", $type, $control, join(' ', pam_module_to_path($module), @para)); +} + +sub get_raw_pam_authentication() { + my %before_deny; + foreach (cat_("$::prefix/etc/pam.d/system-auth")) { + my ($type, $control, $module, @para) = split; + if ($module = pam_module_from_path($module)) { + $before_deny{$type}{$module} = \@para if $control eq 'sufficient' && member($module, pam_modules()); + } + } + \%before_deny; +} + +sub set_raw_pam_authentication { + my ($before_deny, $before_first) = @_; + substInFile { + my ($type, $control, $module, @para) = split; + my $added_pre_line = ''; + if ($module = pam_module_from_path($module)) { + if ($module eq 'pam_unix' && member($type, 'auth', 'account')) { + #- ensure use_first_pass option is there + $_ = pam_format_line($type, 'sufficient', $module, uniq(@para, 'use_first_pass')); + if ($control eq 'required') { + #- ensure a pam_deny line is there + ($control, $module, @para) = ('required', 'pam_deny'); + ($added_pre_line, $_) = ($_, pam_format_line($type, $control, $module)); + } + } + if (member($module, pam_modules())) { + #- first removing previous config + warn "dropping line $_"; + $_ = ''; + } else { + if ($before_first->{$type}) { + foreach my $module (keys %{$before_first->{$type}}) { + $_ = pam_format_line($type, 'required', $module, @{$before_first->{$type}{$module}}) . $_; + } + delete $before_first->{$type}; + } + if ($control eq 'required' && $module eq 'pam_deny') { + if ($before_deny->{$type}) { + foreach my $module (keys %{$before_deny->{$type}}) { + $_ = pam_format_line($type, 'sufficient', $module, @{$before_deny->{$type}{$module}}) . $_; + } + } + } + } + $_ = $added_pre_line . $_; + } + } "$::prefix/etc/pam.d/system-auth"; +} + +sub get_pam_authentication_kinds() { + my $before_deny = get_raw_pam_authentication(); + map { s/pam_//; $_ } keys %{$before_deny->{auth}}; +} + +sub set_pam_authentication { + my (@authentication_kinds) = @_; + my $before_deny = {}; + my $before_first = {}; + foreach (@authentication_kinds) { + my $module = 'pam_' . $_; + $before_deny->{auth}{$module} = []; + $before_deny->{account}{$module} = []; + $before_deny->{password}{$module} = [] if $_ eq 'ldap'; + $before_first->{session}{pam_mkhomedir} = [ 'skel=/etc/skel/', 'umask=0022' ] if $_ eq 'winbind'; + } + set_raw_pam_authentication($before_deny, $before_first); +} + +sub set_nsswitch_priority { + my (@kinds) = @_; + # allowed: files nis ldap dns + substInFile { + if (my ($database, $l) = /^(\s*(?:passwd|shadow|group|automount):\s*)(.*)/) { + $_ = $database . join(' ', uniq('files', @kinds, split(' ', $l))) . "\n"; + } + } "$::prefix/etc/nsswitch.conf"; +} + +sub read_ldap_conf() { + my %conf = map { s/^\s*#.*//; if_(/(\S+)\s+(.*)/, $1 => $2) } cat_("$::prefix/etc/ldap.conf"); + \%conf; +} + +sub set_ldap_conf { + my ($domain, $servers, $b_ssl) = @_; + + my %wanted_conf = ( + host => $servers, + base => $domain, + port => $b_ssl ? 636 : 389, + ssl => $b_ssl ? 'on' : 'off', + nss_base_shadow => "ou=People,$domain", + nss_base_passwd => "ou=People,$domain", + nss_base_group => "ou=Group,$domain", + ); + + substInFile { + my ($cmd) = /^#?\s*(\w+)\s/; + if ($cmd && exists $wanted_conf{$cmd}) { + my $val = $wanted_conf{$cmd}; + $wanted_conf{$cmd} = ''; + $_ = $val ? "$cmd $val\n" : ''; + } + } "$::prefix/etc/ldap.conf"; +} + +1; + diff --git a/perl-install/install_any.pm b/perl-install/install_any.pm index 5a0e355e8..aaf0b2e8c 100644 --- a/perl-install/install_any.pm +++ b/perl-install/install_any.pm @@ -454,7 +454,8 @@ sub set_authentication { $f->(); } 'configureNetwork'; }; - any::set_authentication($o, $o->{netc}, $o->{authentication} ||= {}, $when_network_is_up); + require authentication; + authentication::set($o, $o->{netc}, $o->{authentication} ||= {}, $when_network_is_up); } sub killCardServices() { diff --git a/perl-install/install_steps_interactive.pm b/perl-install/install_steps_interactive.pm index 9c915051f..356d2e1c1 100644 --- a/perl-install/install_steps_interactive.pm +++ b/perl-install/install_steps_interactive.pm @@ -1126,7 +1126,8 @@ sub setRootPassword { $sup->{password2} ||= $sup->{password} ||= ""; if ($o->{security} >= 1 || $clicked) { - my $authentication_kind = any::authentication2authentication_kind($o->{authentication} ||= {}); + require authentication; + my $authentication_kind = authentication::to_kind($o->{authentication} ||= {}); $o->ask_from_({ title => N("Set root password and network authentication methods"), @@ -1145,10 +1146,10 @@ sub setRootPassword { } } }, [ { label => N("Password"), val => \$sup->{password}, hidden => 1 }, { label => N("Password (again)"), val => \$sup->{password2}, hidden => 1 }, -{ label => N("Authentication"), val => \$authentication_kind, list => [ any::authentication_kinds() ], format => \&any::authentication_kind2description, advanced => 1 }, +{ label => N("Authentication"), val => \$authentication_kind, list => [ authentication::kinds() ], format => \&authentication::kind2description, advanced => 1 }, ]) or delete $sup->{password}; - any::ask_authentification_parameters($o, $o->{netc}, $o->{authentication}, $authentication_kind) or goto &setRootPassword; + authentication::ask_parameters($o, $o->{netc}, $o->{authentication}, $authentication_kind) or goto &setRootPassword; } install_steps::setRootPassword($o); } diff --git a/perl-install/standalone/drakauth b/perl-install/standalone/drakauth index 6f2dfe236..f091a3000 100755 --- a/perl-install/standalone/drakauth +++ b/perl-install/standalone/drakauth @@ -6,7 +6,7 @@ use standalone; #- warning, standalone must be loaded very first, for 'expla use common; use interactive; -use any; +use authentication; use network::network; my $netc = {}; @@ -18,17 +18,20 @@ my $in = 'interactive'->vnew('su'); my $authentication = {}; # TODO -my $authentication_kind = any::authentication2authentication_kind($authentication); +my $kind = authentication::to_kind($authentication); main: $in->ask_from('', '', [ - { label => N("Authentication"), val => \$authentication_kind, list => [ any::authentication_kinds() ], format => \&any::authentication_kind2description }, + { label => N("Authentication"), val => \$kind, list => [ authentication::kinds() ], format => \&authentication::kind2description }, ]) or $in->exit; -any::ask_authentification_parameters($in, $netc, $authentication, $authentication_kind) or goto main; +authentication::ask_parameters($in, $netc, $authentication, $kind) or goto main; -eval { any::set_authentication($in, $netc, $authentication, sub { my ($f) = @_; $f->() }) }; +eval { + authentication::set($in, $netc, $authentication, sub { my ($f) = @_; $f->() }); + network::network::write_conf("$::prefix/etc/sysconfig/network", $netc); +}; if (my $err = $@) { $in->ask_warn(N("Error"), formatError($err)); goto main; |