- #!/usr/bin/perl
- =pod
- This file was transferred by kio_fish, a network client part of the
- KDE project. You may safely delete it, it will be transferred again
- when needed. It's only purpose is to make kio_fish access faster and
- more reliable.
- =cut
- use Fcntl;
- $|++;
- #open(DEBUG,">/tmp/kio_fish.debug.$$.log");
- $|=1;
- $code.=$_;
- }
- }
- use strict;
- $SIG{'CHLD'} = 'IGNORE';
- $| = 1;
- #print DEBUG "$_n";
- s/^#//;
- };
- };
- };
- while ($size > 32768 && ($read = sysread(FH,$buffer,32768)) > 0) {
- $size -= $read;
- if (syswrite(OFH,$buffer,$read) != $read) {
- close(FH); close(OFH);
- print "### 500 $!n";
- next MAIN;
- }
- }
- while ($size > 0 && ($read = sysread(FH,$buffer,$size)) > 0) {
- $size -= $read;
- if (syswrite(OFH,$buffer,$read) != $read) {
- close(FH); close(OFH);
- print "### 500 $!n";
- next MAIN;
- }
- }
- close(FH);
- close(OFH);
- }
- if ($read > 0) {
- print "### 200n";
- } else {
- print "### 500 $!n";
- }
- next;
- };
- /^LINKs+((?:\.|[^\])*?)s+((?:\.|[^\])*?)s*$/ && do {
- my $ofn = unquote($1);
- my $fn = unquote($2);
- print (link($ofn,$fn)?"### 200n":"### 500 $!n");
- next;
- };
- /^RENAMEs+((?:\.|[^\])*?)s+((?:\.|[^\])*?)s*$/ && do {
- my $ofn = unquote($1);
- my $fn = unquote($2);
- print (rename($ofn,$fn)?"### 200n":"### 500 $!n");
- next;
- };
- /^CHGRPs+(d+)s+((?:\.|[^\])*?)s*$/ && do {
- my $fn = unquote($2);
- print (chown(-1,int($1),$fn)?"### 200n":"### 500 $!n");
- next;
- };
- /^CHOWNs+(d+)s+((?:\.|[^\])*?)s*$/ && do {
- my $fn = unquote($2);
- print (chown(int($1),-1,$fn)?"### 200n":"### 500 $!n");
- next;
- };
- /^CHMODs+([0-7]+)s+((?:\.|[^\])*?)s*$/ && do {
- my $fn = unquote($2);
- print (chmod(oct($1),$fn)?"### 200n":"### 500 $!n");
- next;
- };
- /^DELEs+((?:\.|[^\])*?)s*$/ && do {
- my $fn = unquote($1);
- print (unlink($fn)?"### 200n":"### 500 $!n");
- next;
- };
- /^RMDs+((?:\.|[^\])*?)s*$/ && do {
- my $dn = unquote($1);
- print (rmdir($dn)?"### 200n":"### 500 $!n");
- next;
- };
- /^MKDs+((?:\.|[^\])*?)s*$/ && do {
- my $dn = unquote($1);
- if (mkdir($dn,0777)) {
- print "### 200n";
- } else {
- my $err = $!;
- print (chdir($dn)?"### 501 $errn":"### 500 $errn");
- }
- next;
- };
- /^CWDs+((?:\.|[^\])*?)s*$/ && do {
- my $dn = unquote($1);
- print (chdir($dn)?"### 200n":"### 500 $!n");
- next;
- };
- /^LISTs+((?:\.|[^\])*?)s*$/ && do {
- list($1, 1);
- next;
- };
- /^STATs+((?:\.|[^\])*?)s*$/ && do {
- list($1, 0);
- next;
- };
- /^WRITEs+(d+)s+(d+)s+((?:\.|[^\])*?)s*$/ && do {
- write_loop($2,$3,O_WRONLY|O_CREAT,$1);
- next;
- };
- /^APPENDs+(d+)s+((?:\.|[^\])*?)s*$/ && do {
- write_loop($1,$2,O_WRONLY|O_APPEND);
- next;
- };
- /^STORs+(d+)s+((?:\.|[^\])*?)s*$/ && do {
- write_loop($1,$2,O_WRONLY|O_CREAT|O_TRUNC);
- next;
- };
- /^RETRs+((?:\.|[^\])*?)s*$/ && do {
- read_loop($1);
- next;
- };
- /^READs+(d+)s+(d+)s+((?:\.|[^\])*?)s*$/ && do {
- read_loop($3,$2,$1);
- next;
- };
- /^EXECs+((?:\.|[^\])*?)s+((?:\.|[^\])*?)s*$/ && do {
- my $tempfile = unquote($2);
- my $command = unquote($1);
- $command = $command . ";echo "###RESULT: $?"";
- print("### 500 $!n"), next
- if (!sysopen(FH,$tempfile,O_CREAT|O_EXCL|O_WRONLY,0600));
- my $pid = fork();
- print("### 500 $!n"), next
- if (!defined $pid);
- if ($pid == 0) {
- open(STDOUT,'>>&FH');
- open(STDERR,'>>&FH');
- open(STDIN,'</dev/null'); # not sure here, ms windows anyone?
- exec('/bin/sh','-c',$command);
- exit(255);
- }
- waitpid($pid,0);
- close(FH);
- print "### 200n";
- };
- }
- sub list {
- }
- }
- }
- sub read_loop {
- print "### 501 Is directoryn" and return if -d $fn;
- sysopen(FH,$fn,O_RDONLY) || ($error = $!);
- if ($_[2]) {
- sysseek(FH,int($_[2]),0) || do { close(FH); $error ||= $!; };
- }
- print "### 500 $errorn" and return if $error;
- if (@_ < 2) {
- print "$sizen";
- }
- print "### 100n";
- my $buffer = '';
- my $read = 1;
- while ($size > 32768 && ($read = sysread(FH,$buffer,32768)) > 0) {
- #print DEBUG "$size left, $read readn";
- $size -= $read;
- print $buffer;
- }
- while ($size > 0 && ($read = sysread(FH,$buffer,$size)) > 0) {
- #print DEBUG "$size left, $read readn";
- $size -= $read;
- print $buffer;
- }
- while ($size > 0) {
- print ' ';
- $size--;
- }
- $error ||= $! if $read <= 0;
- close(FH);
- if (!$error) {
- print "### 200n";
- } else {
- print "### 500 $errorn";
- }
- }
- sub write_loop {
- my $size = int($_[0]);
- my $fn = unquote($_[1]);
- #print DEBUG "write_loop called $size size, $fn fn, $_[2]n";
- my $error = '';
- sysopen(FH,$fn,$_[2]) || do { print "### 400 $!n"; return; };
- eval { flock(FH,2); };
- if ($_[3]) {
- sysseek(FH,int($_[3]),0) || do { close(FH);print "### 400 $!n"; return; };
- }
- <STDIN>;
- print "### 100n";
- my $buffer = '';
- my $read = 1;
- while ($size > 32768 && ($read = read(STDIN,$buffer,32768)) > 0) {
- #print DEBUG "$size left, $read readn";
- $size -= $read;
- $error ||= $! if (syswrite(FH,$buffer,$read) != $read);
- }
- while ($size > 0 && ($read = read(STDIN,$buffer,$size)) > 0) {
- #print DEBUG "$size left, $read readn";
- $size -= $read;
- $error ||= $! if (syswrite(FH,$buffer,$read) != $read);
- }
- close(FH);
- if (!$error) {
- print "### 200n";
- } else {
- print "### 500 $errorn";
- }
- }
- sub unquote { $_ = shift; s/\(.)/$1/g; return $_; }
- sub filetype {
- my ($mode,$link,$uid,$gid) = @_;
- my $result = 'P';
- while (1) {
- -f _ && do { $result .= '-'; last; };
- -d _ && do { $result .= 'd'; last; };
- defined($link) && do { $result .= 'l'; last; };
- -c _ && do { $result .= 'c'; last; };
- -b _ && do { $result .= 'b'; last; };
- -S _ && do { $result .= 's'; last; };
- -p _ && do { $result .= 'p'; last; };
- $result .= '?'; last;
- }
- $result .= ($mode & 0400?'r':'-');
- $result .= ($mode & 0200?'w':'-');
- $result .= ($mode & 0100?($mode&04000?'s':'x'):($mode&04000?'S':'-'));
- $result .= ($mode & 0040?'r':'-');
- $result .= ($mode & 0020?'w':'-');
- $result .= ($mode & 0010?($mode&02000?'s':'x'):($mode&02000?'S':'-'));
- $result .= ($mode & 0004?'r':'-');
- $result .= ($mode & 0002?'w':'-');
- $result .= ($mode & 0001?($mode&01000?'t':'x'):($mode&01000?'T':'-'));
- $result .= ' ';
- $result .= (getpwuid($uid)||$uid);
- $result .= '.';
- $result .= (getgrgid($gid)||$gid);
- $result .= "n";
- return $result;
- }
- sub mimetype {
- my $fn = shift;
- return "Minode/directoryn" if -d $fn;
- pipe(IN,OUT);
- my $pid = fork();
- return '' if (!defined $pid);
- if ($pid) {
- close(OUT);
- my $type = <IN>;
- close(IN);
- chomp $type;
- chomp $type;
- $type =~ s/[,; ].*//;
- return '' if ($type !~ m///);
- return "M$typen"
- }
- close(IN);
- sysopen(NULL,'/dev/null',O_RDWR);
- dup2(fileno(NULL),fileno(STDIN));
- dup2(fileno(OUT),fileno(STDOUT));
- dup2(fileno(NULL),fileno(STDERR));
- exec('/usr/bin/file','-i','-b','-L',$fn);
- exit(0);
- }
Download as Text : January 6th, 2009
This work is licensed under a