/usr/share/doc/libfuse-perl/examples/rmount.pl is in libfuse-perl 0.16.1-1+b3.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | #!/usr/bin/perl -w
# This example needs some work before it can support threads.
use strict;
use Net::SSH 'sshopen2';
use IPC::Open2;
use Fuse;
use Data::Dumper;
my $port; if($ARGV[-1]=~/^--/){ $port = pop(@ARGV); $port =~ s/--port=//; }
my ($host, $dir, $mount) = @ARGV;
if(!defined($mount)) {
$mount = $dir;
if($host =~ /^(.*):(.*)$/) {
($host,$dir) = ($1,$2);
} else {
die "usage: $0 user\@host remotedir mountpoint [--port=<port>]\n".
"or : $0 user\@host:remotedir mountpoint [--port=<port>]\n";
}
}
`umount $mount` unless -d $mount;
die "mountpoint $mount isn't a directory!\n" unless -d $mount;
my (%args) = (mountpoint => $mount);
map { my ($str) = $_; $args{$str} = sub { netlink($str,@_) } }
qw(getattr getdir open read write readlink unlink rmdir
symlink rename link chown chmod truncate utime mkdir
rmdir mknod statfs);
sub connect_remote {
push(@Net::SSH::ssh_options, "-p $port") if $port;
sshopen2($host, *READER, *WRITER, "./rmount_remote.pl $dir")
or die "ssh: $!\n";
select WRITER;
$| = 1;
select STDOUT;
}
$SIG{CHLD} = sub {
use POSIX ":sys_wait_h";
my $kid;
do {
$kid = waitpid(-1,WNOHANG);
} until $kid < 1;
};
connect_remote;
sub netlink {
my ($str) = Dumper(\@_)."\n";
$str = sprintf("%08i\n%s",length($str),$str);
while(1) { # retry as necessary
my ($VAR1);
$VAR1 = undef;
eval {
local $SIG{ALRM} = sub { die "timeout\n" };
alarm 10;
print WRITER $str;
my ($len, $data);
$data = '';
if(sysread(READER,$len,9) == 9) {
sysread(READER,$data,$len-length($data),length($data))
while(length($data) < $len);
eval $data;
}
alarm 0;
};
if(defined $VAR1) {
return wantarray ? @{$VAR1} : $$VAR1[0];
}
print STDERR "failed to send command; reconnecting ssh\n";
close(READER);
close(WRITER);
connect_remote();
}
}
Fuse::main(%args);
netlink("bye");
close(READER);
close(WRITER);
|