summaryrefslogtreecommitdiffstats
path: root/perl-install/fs
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2008-11-06 08:18:51 +0000
committerPascal Rigaux <pixel@mandriva.com>2008-11-06 08:18:51 +0000
commita0f2da8ac9ffe8c53b7935d4ad7ff3bf3d14d6ba (patch)
treecb9d0b28ded9d5fbff33ed98065af3a502e30161 /perl-install/fs
parent4645260b7eab7372180fb024cda981635b964379 (diff)
downloaddrakx-a0f2da8ac9ffe8c53b7935d4ad7ff3bf3d14d6ba.tar
drakx-a0f2da8ac9ffe8c53b7935d4ad7ff3bf3d14d6ba.tar.gz
drakx-a0f2da8ac9ffe8c53b7935d4ad7ff3bf3d14d6ba.tar.bz2
drakx-a0f2da8ac9ffe8c53b7935d4ad7ff3bf3d14d6ba.tar.xz
drakx-a0f2da8ac9ffe8c53b7935d4ad7ff3bf3d14d6ba.zip
- diskdrake
o --dav: handle davfs2 credentials in /etc/davfs2/secrets (#44190)
Diffstat (limited to 'perl-install/fs')
-rw-r--r--perl-install/fs/remote/davfs.pm68
1 files changed, 68 insertions, 0 deletions
diff --git a/perl-install/fs/remote/davfs.pm b/perl-install/fs/remote/davfs.pm
new file mode 100644
index 000000000..ce708f0c0
--- /dev/null
+++ b/perl-install/fs/remote/davfs.pm
@@ -0,0 +1,68 @@
+package fs::remote::davfs; # $Id: smb.pm 231184 2007-10-24 14:36:29Z pixel $
+
+use strict;
+use diagnostics;
+
+use common;
+use fs::mount_options;
+
+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);
+ $h{mntpoint} = $part->{mntpoint} or return;
+ fs::mount_options::pack_($part, $options, $unknown), \%h;
+}
+
+sub save_credentials {
+ my ($credentials) = @_;
+ @$credentials or return;
+
+ output_with_perm(secrets_file(), 0600,
+ map { to_double_quoted($_->{mntpoint}, $_->{username}, $_->{password}) . "\n" } @$credentials);
+}
+
+
+sub read_credentials_raw {
+ my ($file) = @_;
+ map {
+ my %h;
+ @h{'mntpoint', 'username', 'password'} = from_double_quoted($_);
+ \%h;
+ } cat_(secrets_file());
+}
+
+sub read_credentials {
+ my ($mntpoint) = @_;
+ find { $mntpoint eq $_->{mntpoint} } read_credentials_raw();
+}
+
+sub from_double_quoted {
+ my ($s) = @_;
+ 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 '';
+ }
+ @l;
+}
+
+sub to_double_quoted {
+ my (@l) = @_;
+ join(' ', map {
+ s/(["\\])/\\$1/g;
+ /\s/ ? qq("$_") : $_;
+ } @l);
+}
+
+1;