diff options
Diffstat (limited to 'perl-install/fs/remote')
-rw-r--r-- | perl-install/fs/remote/davfs.pm | 71 | ||||
-rw-r--r-- | perl-install/fs/remote/nfs.pm | 45 | ||||
-rw-r--r-- | perl-install/fs/remote/smb.pm | 3 |
3 files changed, 77 insertions, 42 deletions
diff --git a/perl-install/fs/remote/davfs.pm b/perl-install/fs/remote/davfs.pm index ce708f0c0..890530cb9 100644 --- a/perl-install/fs/remote/davfs.pm +++ b/perl-install/fs/remote/davfs.pm @@ -1,4 +1,4 @@ -package fs::remote::davfs; # $Id: smb.pm 231184 2007-10-24 14:36:29Z pixel $ +package fs::remote::davfs; use strict; use diagnostics; @@ -6,14 +6,16 @@ use diagnostics; use common; use fs::mount_options; -sub secrets_file { "$::prefix/etc/davfs2/secrets" } +sub secrets_file() { "$::prefix/etc/davfs2/secrets" } sub fstab_entry_to_credentials { my ($part) = @_; my ($options, $unknown) = fs::mount_options::unpack($part); - $options->{'username='} && $options->{'password='} or return; my %h = map { $_ => delete $options->{"$_="} } qw(username password); + foreach (qw(username password)) { + $h{$_} ||= 'nobody'; + } $h{mntpoint} = $part->{mntpoint} or return; fs::mount_options::pack_($part, $options, $unknown), \%h; } @@ -26,14 +28,25 @@ sub save_credentials { map { to_double_quoted($_->{mntpoint}, $_->{username}, $_->{password}) . "\n" } @$credentials); } +sub mountpoint_credentials_save { + my ($mntpoint, $mount_opt) = @_; + my @entries = read_credentials_raw(); + my $entry = find { $mntpoint eq $_->{mntpoint} } @entries; + die "mountpoint not found" if !$entry; + my %h; + foreach (@$mount_opt) { + my @var = split(/=/); + $h{$var[0]} = $var[1]; + } + foreach my $key (qw(username password)) { + $entry->{$key} = $h{$key}; + } + save_credentials(\@entries); +} + -sub read_credentials_raw { - my ($file) = @_; - map { - my %h; - @h{'mntpoint', 'username', 'password'} = from_double_quoted($_); - \%h; - } cat_(secrets_file()); +sub read_credentials_raw() { + from_double_quoted(cat_(secrets_file())); } sub read_credentials { @@ -41,18 +54,36 @@ sub read_credentials { find { $mntpoint eq $_->{mntpoint} } read_credentials_raw(); } +# Comments are indicated by a '#' character and the rest of the line +# is ignored. Empty lines are ignored too. +# +# Each line consists of two or three items separated by spaces or tabs. +# If an item contains one of the characters space, tab, #, \ or ", this +# character must be escaped by a preceding \. Alternatively, the item +# may be enclosed in double quotes. + sub from_double_quoted { - my ($s) = @_; + my ($file) = @_; my @l; - while (1) { - (my $e1, my $e2, $s) = - $s =~ /^( "((?:\\.|[^"])*)" | (?:\\.|[^"\s])+ ) (.*)$/x or die "bad entry $_[0]\n"; - my $entry = defined $e2 ? $e2 : $e1; - $entry =~ s/\\(.)/$1/g; - push @l, $entry; - last if $s eq ''; - $s =~ s/^\s+// or die "bad entry $_[0]\n"; - last if $s eq ''; + my @lines = split("\n",$file); + foreach (@lines) { + my ($mnt, $user, $pass, $comment); + if (/^\s*(#.*)?$/) { + $comment = $1; + } else { + if (/^(?:"((?:\\.|[^"])*)"|((?:\\.|[^"\s#])+))\s+(?:"((?:\\.|[^"])*)"|((?:\\.|[^"\s#])+))(?:\s+(?:"((?:\\.|[^"])*)"|((?:\\.|[^"\s#])+)))?(?:\s*|\s*(#.*))?$/) { + $mnt = "$1$2"; + $mnt =~ s/\\(.)/$1/g; + $user = "$3$4"; + $user =~ s/\\(.)/$1/g; + $pass = "$5$6"; + $pass =~ s/\\(.)/$1/g; + $comment=$7; + } else { + die "bad entry $_"; + } + } + push @l, { 'mntpoint' => $mnt, 'username' => $user, 'password' => $pass, 'comment' => $comment }; } @l; } diff --git a/perl-install/fs/remote/nfs.pm b/perl-install/fs/remote/nfs.pm index 816c152a5..f7a98cb69 100644 --- a/perl-install/fs/remote/nfs.pm +++ b/perl-install/fs/remote/nfs.pm @@ -1,10 +1,11 @@ -package fs::remote::nfs; # $Id$ +package fs::remote::nfs; use strict; use diagnostics; use common; use fs::remote; +use network::tools; use log; our @ISA = 'fs::remote'; @@ -28,34 +29,36 @@ sub to_dev_raw { sub check { my ($_class, $in) = @_; - $in->do_pkgs->ensure_binary_is_installed('nfs-utils-clients', 'showmount') or return; + $in->do_pkgs->ensure_files_are_installed([ [ qw(nfs-utils showmount) ] , [ qw(nmap nmap) ] ]); require services; - services::start_not_running_service('portmap'); + services::start_not_running_service('rpcbind'); services::start('nfs-common'); #- TODO: once nfs-common is fixed, it could use start_not_running_service() 1; } sub find_servers { - open(my $F2, "rpcinfo-flushed -b mountd 2 |"); - open(my $F3, "rpcinfo-flushed -b mountd 3 |"); - - common::nonblock($F2); - common::nonblock($F3); - my $domain = chomp_(`domainname`); - my ($s, %servers); - my $quit; - while (!$quit) { - $quit = 1; - sleep 1; - while ($s = <$F2> || <$F3>) { - $quit = 0; - my ($ip, $name) = $s =~ /(\S+)\s+(\S+)/ or log::explanations("bad line in rpcinfo output"), next; - $name =~ s/\.$//; - $domain && $name =~ s/\Q.$domain\E$// - || $name =~ s/^([^.]*)\.local$/$1/; - $servers{$ip} ||= { ip => $ip, if_($name ne '(unknown)', name => $name) }; + my @hosts; + my %servers; + my @routes = cat_("/proc/net/route"); + @routes = reverse(@routes) if common::cmp_kernel_versions(c::kernel_version(), "2.6.39") >= 0; + foreach (@routes) { + if (/^(\S+)\s+([0-9A-F]+)\s+([0-9A-F]+)\s+[0-9A-F]+\s+\d+\s+\d+\s+(\d+)\s+([0-9A-F]+)/) { + my $net = network::tools::host_hex_to_dotted($2); + my $gateway = $3; + # get the netmask in binary and remove leading zeros + my $mask = unpack('B*', pack('h*', $5)); + $mask =~ s/^0*//; + push @hosts, $net . "/" . length($mask) if $gateway eq '00000000' && $net ne '169.254.0.0'; } + } + # runs the nmap command on the local subnet + my $cmd = "/usr/bin/nmap -p 111 --open --system-dns -oG - " . (join ' ',@hosts); + open my $FH, "$cmd |" or die "Could not perform nmap scan - $!"; + foreach (<$FH>) { + my ($ip, $name) = /^H\S+\s(\S+)\s+\((\S*)\).+Port/ or next; + $servers{$ip} ||= { ip => $ip, name => $name || $ip }; } + close $FH; values %servers; } diff --git a/perl-install/fs/remote/smb.pm b/perl-install/fs/remote/smb.pm index 84a58318a..d440fc174 100644 --- a/perl-install/fs/remote/smb.pm +++ b/perl-install/fs/remote/smb.pm @@ -1,4 +1,4 @@ -package fs::remote::smb; # $Id$ +package fs::remote::smb; use strict; use diagnostics; @@ -57,6 +57,7 @@ sub find_servers { s/\s.*\n// foreach @l; require network::network; my @servers = grep { network::network::is_ip($_) } @l; + return unless @servers; my %servers; $servers{$_}{ip} = $_ foreach @servers; my ($ip, $browse); |