diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2002-06-28 21:15:04 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2002-06-28 21:15:04 +0000 |
commit | 4026ee6b73851ac1dc2c9a77c85f6c3138456c5b (patch) | |
tree | ef3ba91d1153c23f331b033fe763f484fdfc3f6f /perl-install/fs.pm | |
parent | 8ca92b87576d9aa7e98654186fcac7855fdec530 (diff) | |
download | drakx-4026ee6b73851ac1dc2c9a77c85f6c3138456c5b.tar drakx-4026ee6b73851ac1dc2c9a77c85f6c3138456c5b.tar.gz drakx-4026ee6b73851ac1dc2c9a77c85f6c3138456c5b.tar.bz2 drakx-4026ee6b73851ac1dc2c9a77c85f6c3138456c5b.tar.xz drakx-4026ee6b73851ac1dc2c9a77c85f6c3138456c5b.zip |
- add authentification in diskdrake --smb (esp. for windows NT)
- use "credentials=" to put the passwords
(ideas and investigations from Stew Benedict,
integrated by Pixel, but need testing)
Known bug: if you want to change the password when there are 2 entries in fstab
using the same username=/password=, writing the credentials is done in random order,
=> you've got one chance in 2 that the password is changed :-(
Diffstat (limited to 'perl-install/fs.pm')
-rw-r--r-- | perl-install/fs.pm | 51 |
1 files changed, 45 insertions, 6 deletions
diff --git a/perl-install/fs.pm b/perl-install/fs.pm index 9b5d6236f..cb8d751cd 100644 --- a/perl-install/fs.pm +++ b/perl-install/fs.pm @@ -4,6 +4,7 @@ use diagnostics; use strict; use MDK::Common::System; +use MDK::Common::Various; use common; use log; use devices; @@ -62,6 +63,21 @@ sub read_fstab { $h->{device} = $dev; } } + + if ($h->{options} =~ /credentials=/) { + require network::smb; + #- remove credentials=file with username=foo,password=bar,domain=zoo + #- the other way is done in fstab_to_string + my ($options, $unknown) = mount_options_unpack($h); + my $file = delete $options->{'credentials='}; + my $credentials = network::smb::read_credentials_raw("$prefix$file"); + if ($credentials->{username}) { + $options->{"$_="} = $credentials->{$_} foreach qw(username password domain); + mount_options_pack($h, $options, $unknown); + } + } + + $h; } cat_("$prefix$file"); } @@ -143,8 +159,8 @@ sub merge_info_from_fstab { merge_fstabs($fstab, @l); } -sub fstab_to_string { - my ($all_hds, $prefix) = @_; +sub prepare_write_fstab { + my ($all_hds, $prefix, $keep_smb_credentials) = @_; $prefix ||= ''; my @l1 = (fsedit::get_really_all_fstab($all_hds), @{$all_hds->{special}}); @@ -160,6 +176,7 @@ sub fstab_to_string { } my %new; + my @smb_credentials; my @l = map { my $device = $_->{device} eq 'none' || member($_->{type}, qw(nfs smbfs)) ? @@ -189,6 +206,15 @@ sub fstab_to_string { $new{$mntpoint} = 1; my $options = $_->{options}; + + if (isThisFs('smbfs', $_) && $options =~ /password=/ && !$keep_smb_credentials) { + require network::smb; + if (my ($opts, $smb_credentials) = network::smb::fstab_entry_to_credentials($_)) { + $options = $opts; + push @smb_credentials, $smb_credentials; + } + } + my $type = type2fs($_); my $dev = $_->{device_alias} ? "/dev/$_->{device_alias}" : $device; @@ -211,13 +237,21 @@ sub fstab_to_string { } } grep { $_->{device} && ($_->{mntpoint} || $_->{real_mntpoint}) && $_->{type} } (@l1, @l2); - join('', map { join(' ', @$_) . "\n" } sort { $a->[1] cmp $b->[1] } @l); + join('', map { join(' ', @$_) . "\n" } sort { $a->[1] cmp $b->[1] } @l), \@smb_credentials; +} + +sub fstab_to_string { + my ($all_hds, $prefix) = @_; + my ($s, undef) = prepare_write_fstab($all_hds, $prefix, 'keep_smb_credentials'); + $s; } sub write_fstab { my ($all_hds, $prefix) = @_; log::l("writing $prefix/etc/fstab"); - output("$prefix/etc/fstab", fstab_to_string($all_hds, $prefix)); + my ($s, $smb_credentials) = prepare_write_fstab($all_hds, $prefix, ''); + output("$prefix/etc/fstab", $s); + network::smb::save_credentials($_) foreach @$smb_credentials; } sub auto_fs() { @@ -290,7 +324,7 @@ sub mount_options_unpack { \%options, $unknown; } -sub mount_options_pack { +sub mount_options_pack_ { my ($part, $options, $unknown) = @_; my ($non_defaults, $user_implies) = mount_options(); @@ -308,7 +342,12 @@ sub mount_options_pack { push @l, map_each { if_($::b, $::a =~ /=$/ ? "$::a$::b" : $::a) } %$options; push @l, $unknown; - $part->{options} = join(",", uniq(grep { $_ } @l)); + join(",", uniq(grep { $_ } @l)); +} +sub mount_options_pack { + my ($part, $options, $unknown) = @_; + $part->{options} = mount_options_pack_($part, $options, $unknown); + MDK::Common::Various::noreturn(); } sub mount_options_help { |