1998-09-13 14:40:43 +04:00
|
|
|
/* Virtual File System: FISH implementation for transfering files over
|
|
|
|
shell connections.
|
|
|
|
|
2007-09-25 19:33:35 +04:00
|
|
|
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
|
|
|
|
2007 Free Software Foundation, Inc.
|
2010-03-30 12:10:25 +04:00
|
|
|
|
1998-09-13 14:40:43 +04:00
|
|
|
Written by: 1998 Pavel Machek
|
2000-03-29 17:36:54 +04:00
|
|
|
Spaces fix: 2000 Michal Svec
|
1998-09-13 14:40:43 +04:00
|
|
|
|
|
|
|
Derived from ftpfs.c.
|
2010-03-30 12:10:25 +04:00
|
|
|
|
1998-09-27 23:27:58 +04:00
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2 of
|
|
|
|
the License, or (at your option) any later version.
|
2010-03-30 12:10:25 +04:00
|
|
|
|
1998-09-13 14:40:43 +04:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
1998-09-27 23:27:58 +04:00
|
|
|
GNU Library General Public License for more details.
|
1998-09-13 14:40:43 +04:00
|
|
|
|
1998-09-27 23:27:58 +04:00
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
License along with this program; if not, write to the Free Software
|
2005-05-27 07:35:10 +04:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
|
1998-09-13 14:40:43 +04:00
|
|
|
|
2009-02-07 15:54:58 +03:00
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
* \brief Source: Virtual File System: FISH implementation for transfering files over
|
|
|
|
* shell connections
|
|
|
|
* \author Pavel Machek
|
|
|
|
* \author Michal Svec
|
|
|
|
* \date 1998, 2000
|
|
|
|
*
|
|
|
|
* Derived from ftpfs.c
|
1998-09-13 14:40:43 +04:00
|
|
|
* Read README.fish for protocol specification.
|
|
|
|
*
|
2009-12-07 20:38:59 +03:00
|
|
|
* Syntax of path is: \verbatim /#sh:user@host[:Cr]/path \endverbatim
|
2009-02-07 15:54:58 +03:00
|
|
|
* where C means you want compressed connection,
|
|
|
|
* and r means you want to use rsh
|
1998-10-13 02:07:53 +04:00
|
|
|
*
|
|
|
|
* Namespace: fish_vfs_ops exported.
|
1998-09-13 14:40:43 +04:00
|
|
|
*/
|
1998-11-21 22:36:01 +03:00
|
|
|
|
|
|
|
/* Define this if your ssh can take -I option */
|
|
|
|
|
2001-06-26 01:34:46 +04:00
|
|
|
#include <config.h>
|
2003-10-16 12:47:33 +04:00
|
|
|
#include <errno.h>
|
2009-02-06 02:30:45 +03:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <pwd.h>
|
|
|
|
#include <grp.h>
|
2010-03-30 12:10:25 +04:00
|
|
|
#include <sys/time.h> /* gettimeofday() */
|
2009-06-19 14:36:36 +04:00
|
|
|
#include <stdlib.h>
|
2009-02-06 02:30:45 +03:00
|
|
|
#include <string.h>
|
2001-06-26 01:34:46 +04:00
|
|
|
|
2010-01-20 18:11:52 +03:00
|
|
|
#include "lib/global.h"
|
|
|
|
#include "lib/fs.h"
|
2010-03-30 12:10:25 +04:00
|
|
|
#include "lib/tty/tty.h" /* enable/disable interrupt key */
|
2010-01-21 16:31:29 +03:00
|
|
|
#include "lib/strescape.h"
|
2010-01-21 13:47:01 +03:00
|
|
|
#include "lib/unixcompat.h"
|
2009-05-08 14:01:05 +04:00
|
|
|
|
2010-03-30 12:10:25 +04:00
|
|
|
#include "src/wtools.h" /* message() */
|
|
|
|
#include "src/main.h" /* print_vfs_message */
|
1999-01-21 01:01:11 +03:00
|
|
|
#include "utilvfs.h"
|
1998-11-21 22:36:01 +03:00
|
|
|
#include "xdirentry.h"
|
1998-09-13 14:40:43 +04:00
|
|
|
#include "vfs.h"
|
2004-08-17 03:18:42 +04:00
|
|
|
#include "vfs-impl.h"
|
2010-03-30 12:10:25 +04:00
|
|
|
#include "gc.h" /* vfs_stamp_create */
|
2010-01-13 16:16:57 +03:00
|
|
|
#include "netutil.h"
|
2006-02-23 18:32:18 +03:00
|
|
|
#include "fish.h"
|
2003-10-11 03:38:03 +04:00
|
|
|
|
2006-02-23 18:32:18 +03:00
|
|
|
int fish_directory_timeout = 900;
|
2003-10-11 03:38:03 +04:00
|
|
|
|
|
|
|
#define DO_RESOLVE_SYMLINK 1
|
|
|
|
#define DO_OPEN 2
|
|
|
|
#define DO_FREE_RESOURCE 4
|
|
|
|
|
|
|
|
#define FISH_FLAG_COMPRESSED 1
|
|
|
|
#define FISH_FLAG_RSH 2
|
|
|
|
|
|
|
|
#define OPT_FLUSH 1
|
|
|
|
#define OPT_IGNORE_ERROR 2
|
1998-10-23 12:26:25 +04:00
|
|
|
|
1998-09-13 14:40:43 +04:00
|
|
|
/*
|
|
|
|
* Reply codes.
|
|
|
|
*/
|
2010-03-30 12:10:25 +04:00
|
|
|
#define PRELIM 1 /* positive preliminary */
|
|
|
|
#define COMPLETE 2 /* positive completion */
|
|
|
|
#define CONTINUE 3 /* positive intermediate */
|
|
|
|
#define TRANSIENT 4 /* transient negative completion */
|
|
|
|
#define ERROR 5 /* permanent negative completion */
|
1998-09-13 14:40:43 +04:00
|
|
|
|
|
|
|
/* command wait_flag: */
|
|
|
|
#define NONE 0x00
|
|
|
|
#define WAIT_REPLY 0x01
|
|
|
|
#define WANT_STRING 0x02
|
2010-03-30 12:10:25 +04:00
|
|
|
static char reply_str[80];
|
1998-09-13 14:40:43 +04:00
|
|
|
|
2003-10-11 03:38:03 +04:00
|
|
|
static struct vfs_class vfs_fish_ops;
|
|
|
|
|
2001-10-20 07:41:31 +04:00
|
|
|
static int
|
2010-03-30 12:10:25 +04:00
|
|
|
fish_command (struct vfs_class *me, struct vfs_s_super *super,
|
|
|
|
int wait_reply, const char *fmt, ...) __attribute__ ((format (__printf__, 4, 5)));
|
2001-10-20 07:41:31 +04:00
|
|
|
|
2010-03-30 12:10:25 +04:00
|
|
|
static int
|
|
|
|
fish_decode_reply (char *s, int was_garbage)
|
1998-09-13 14:40:43 +04:00
|
|
|
{
|
1998-11-21 22:36:01 +03:00
|
|
|
int code;
|
2010-03-30 12:10:25 +04:00
|
|
|
if (!sscanf (s, "%d", &code))
|
|
|
|
{
|
|
|
|
code = 500;
|
|
|
|
return 5;
|
1998-09-13 14:40:43 +04:00
|
|
|
}
|
2010-03-30 12:10:25 +04:00
|
|
|
if (code < 100)
|
|
|
|
return was_garbage ? ERROR : (!code ? COMPLETE : PRELIM);
|
1998-09-13 14:40:43 +04:00
|
|
|
return code / 100;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns a reply code, check /usr/include/arpa/ftp.h for possible values */
|
2010-03-30 12:10:25 +04:00
|
|
|
static int
|
|
|
|
fish_get_reply (struct vfs_class *me, int sock, char *string_buf, int string_len)
|
1998-09-13 14:40:43 +04:00
|
|
|
{
|
|
|
|
char answer[1024];
|
|
|
|
int was_garbage = 0;
|
2010-03-30 12:10:25 +04:00
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if (!vfs_s_get_line (me, sock, answer, sizeof (answer), '\n'))
|
|
|
|
{
|
|
|
|
if (string_buf)
|
|
|
|
*string_buf = 0;
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strncmp (answer, "### ", 4))
|
|
|
|
{
|
|
|
|
was_garbage = 1;
|
|
|
|
if (string_buf)
|
|
|
|
g_strlcpy (string_buf, answer, string_len);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return fish_decode_reply (answer + 4, was_garbage);
|
1998-09-13 14:40:43 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-11-21 22:36:01 +03:00
|
|
|
#define SUP super->u.fish
|
1998-09-13 14:40:43 +04:00
|
|
|
|
2001-10-20 07:41:31 +04:00
|
|
|
static int
|
2010-03-30 12:10:25 +04:00
|
|
|
fish_command (struct vfs_class *me, struct vfs_s_super *super, int wait_reply, const char *fmt, ...)
|
1998-09-13 14:40:43 +04:00
|
|
|
{
|
|
|
|
va_list ap;
|
1998-10-30 20:45:43 +03:00
|
|
|
char *str;
|
1999-01-11 03:48:23 +03:00
|
|
|
int status;
|
1998-11-21 22:36:01 +03:00
|
|
|
FILE *logfile = MEDATA->logfile;
|
1998-10-30 20:45:43 +03:00
|
|
|
|
1998-09-13 14:40:43 +04:00
|
|
|
va_start (ap, fmt);
|
1998-11-21 22:36:01 +03:00
|
|
|
|
1998-10-30 20:45:43 +03:00
|
|
|
str = g_strdup_vprintf (fmt, ap);
|
1998-09-13 14:40:43 +04:00
|
|
|
va_end (ap);
|
1998-11-21 22:36:01 +03:00
|
|
|
|
2010-03-30 12:10:25 +04:00
|
|
|
if (logfile)
|
|
|
|
{
|
2010-04-30 17:31:06 +04:00
|
|
|
size_t ret;
|
2009-12-29 01:53:09 +03:00
|
|
|
ret = fwrite (str, strlen (str), 1, logfile);
|
|
|
|
ret = fflush (logfile);
|
1998-09-13 14:40:43 +04:00
|
|
|
}
|
|
|
|
|
2009-05-19 17:42:37 +04:00
|
|
|
tty_enable_interrupt_key ();
|
1998-11-21 22:36:01 +03:00
|
|
|
|
2003-10-28 03:57:02 +03:00
|
|
|
status = write (SUP.sockw, str, strlen (str));
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (str);
|
1998-11-21 22:36:01 +03:00
|
|
|
|
2009-05-19 17:42:37 +04:00
|
|
|
tty_disable_interrupt_key ();
|
1998-11-21 22:36:01 +03:00
|
|
|
if (status < 0)
|
2010-03-30 12:10:25 +04:00
|
|
|
return TRANSIENT;
|
2003-10-28 03:57:02 +03:00
|
|
|
|
1998-09-13 14:40:43 +04:00
|
|
|
if (wait_reply)
|
2010-03-30 12:10:25 +04:00
|
|
|
return fish_get_reply (me, SUP.sockr,
|
|
|
|
(wait_reply & WANT_STRING) ? reply_str :
|
|
|
|
NULL, sizeof (reply_str) - 1);
|
1998-09-13 14:40:43 +04:00
|
|
|
return COMPLETE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-10-28 03:57:02 +03:00
|
|
|
fish_free_archive (struct vfs_class *me, struct vfs_s_super *super)
|
1998-09-13 14:40:43 +04:00
|
|
|
{
|
2010-03-30 12:10:25 +04:00
|
|
|
if ((SUP.sockw != -1) || (SUP.sockr != -1))
|
|
|
|
{
|
|
|
|
print_vfs_message (_("fish: Disconnecting from %s"), super->name ? super->name : "???");
|
|
|
|
fish_command (me, super, NONE, "#BYE\nexit\n");
|
|
|
|
close (SUP.sockw);
|
|
|
|
close (SUP.sockr);
|
|
|
|
SUP.sockw = SUP.sockr = -1;
|
1998-09-13 14:40:43 +04:00
|
|
|
}
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (SUP.host);
|
|
|
|
g_free (SUP.user);
|
|
|
|
g_free (SUP.cwdir);
|
|
|
|
g_free (SUP.password);
|
1998-09-13 14:40:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-03-30 12:10:25 +04:00
|
|
|
fish_pipeopen (struct vfs_s_super *super, const char *path, const char *argv[])
|
1998-09-13 14:40:43 +04:00
|
|
|
{
|
|
|
|
int fileset1[2], fileset2[2];
|
|
|
|
int res;
|
|
|
|
|
2010-03-30 12:10:25 +04:00
|
|
|
if ((pipe (fileset1) < 0) || (pipe (fileset2) < 0))
|
|
|
|
vfs_die ("Cannot pipe(): %m.");
|
|
|
|
|
2010-03-30 22:59:41 +04:00
|
|
|
res = fork ();
|
|
|
|
|
|
|
|
if (res != 0)
|
2010-03-30 12:10:25 +04:00
|
|
|
{
|
|
|
|
if (res < 0)
|
|
|
|
vfs_die ("Cannot fork(): %m.");
|
|
|
|
/* We are the parent */
|
|
|
|
close (fileset1[0]);
|
|
|
|
SUP.sockw = fileset1[1];
|
|
|
|
close (fileset2[1]);
|
|
|
|
SUP.sockr = fileset2[0];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-12-29 01:53:09 +03:00
|
|
|
res = dup2 (fileset1[0], 0);
|
2010-03-30 12:10:25 +04:00
|
|
|
close (fileset1[0]);
|
|
|
|
close (fileset1[1]);
|
2009-12-29 01:53:09 +03:00
|
|
|
res = dup2 (fileset2[1], 1);
|
2010-03-30 12:10:25 +04:00
|
|
|
close (2);
|
|
|
|
/* stderr to /dev/null */
|
2009-12-29 01:53:09 +03:00
|
|
|
res = open ("/dev/null", O_WRONLY);
|
2010-03-30 12:10:25 +04:00
|
|
|
close (fileset2[0]);
|
|
|
|
close (fileset2[1]);
|
|
|
|
execvp (path, const_cast (char **, argv));
|
|
|
|
_exit (3);
|
1998-09-13 14:40:43 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-11-21 22:36:01 +03:00
|
|
|
/* The returned directory should always contain a trailing slash */
|
2010-03-30 12:10:25 +04:00
|
|
|
static char *
|
|
|
|
fish_getcwd (struct vfs_class *me, struct vfs_s_super *super)
|
1998-11-21 22:36:01 +03:00
|
|
|
{
|
2003-10-28 03:57:02 +03:00
|
|
|
if (fish_command (me, super, WANT_STRING, "#PWD\npwd; echo '### 200'\n") == COMPLETE)
|
2010-03-30 12:10:25 +04:00
|
|
|
return g_strconcat (reply_str, "/", (char *) NULL);
|
1998-11-21 22:36:01 +03:00
|
|
|
ERRNOR (EIO, NULL);
|
|
|
|
}
|
2003-10-28 03:57:02 +03:00
|
|
|
|
1998-11-21 22:36:01 +03:00
|
|
|
static int
|
2003-10-28 03:57:02 +03:00
|
|
|
fish_open_archive_int (struct vfs_class *me, struct vfs_s_super *super)
|
1998-09-13 14:40:43 +04:00
|
|
|
{
|
2003-12-06 07:24:56 +03:00
|
|
|
{
|
2010-03-30 12:10:25 +04:00
|
|
|
char gbuf[10];
|
|
|
|
const char *argv[10]; /* All of 10 is used now */
|
|
|
|
const char *xsh = (SUP.flags == FISH_FLAG_RSH ? "rsh" : "ssh");
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
argv[i++] = xsh;
|
|
|
|
if (SUP.flags == FISH_FLAG_COMPRESSED)
|
|
|
|
argv[i++] = "-C";
|
|
|
|
|
|
|
|
if (SUP.flags > FISH_FLAG_RSH)
|
|
|
|
{
|
|
|
|
argv[i++] = "-p";
|
|
|
|
g_snprintf (gbuf, sizeof (gbuf), "%d", SUP.flags);
|
|
|
|
argv[i++] = gbuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add the user name to the ssh command line only if it was explicitly
|
|
|
|
* set in vfs URL. rsh/ssh will get current user by default
|
|
|
|
* plus we can set convenient overrides in ~/.ssh/config (explicit -l
|
|
|
|
* option breaks it for some)
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (SUP.user)
|
|
|
|
{
|
|
|
|
argv[i++] = "-l";
|
|
|
|
argv[i++] = SUP.user;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* The rest of the code assumes it to be a valid username */
|
|
|
|
SUP.user = vfs_get_local_username ();
|
|
|
|
}
|
|
|
|
|
|
|
|
argv[i++] = SUP.host;
|
|
|
|
argv[i++] = "echo FISH:; /bin/sh";
|
|
|
|
argv[i++] = NULL;
|
|
|
|
|
|
|
|
fish_pipeopen (super, xsh, argv);
|
2003-12-06 07:24:56 +03:00
|
|
|
}
|
1998-09-13 14:40:43 +04:00
|
|
|
{
|
2010-03-30 12:10:25 +04:00
|
|
|
char answer[2048];
|
|
|
|
print_vfs_message (_("fish: Waiting for initial line..."));
|
|
|
|
if (!vfs_s_get_line (me, SUP.sockr, answer, sizeof (answer), ':'))
|
|
|
|
ERRNOR (E_PROTO, -1);
|
|
|
|
print_vfs_message ("%s", answer);
|
|
|
|
if (strstr (answer, "assword"))
|
|
|
|
{
|
|
|
|
/* Currently, this does not work. ssh reads passwords from
|
|
|
|
/dev/tty, not from stdin :-(. */
|
|
|
|
|
|
|
|
message (D_ERROR, MSG_ERROR,
|
|
|
|
_("Sorry, we cannot do password authenticated connections for now."));
|
|
|
|
ERRNOR (EPERM, -1);
|
|
|
|
if (!SUP.password)
|
|
|
|
{
|
|
|
|
char *p, *op;
|
|
|
|
p = g_strconcat (_(" fish: Password required for "), SUP.user, " ", (char *) NULL);
|
|
|
|
op = vfs_get_password (p);
|
|
|
|
g_free (p);
|
|
|
|
if (op == NULL)
|
|
|
|
ERRNOR (EPERM, -1);
|
|
|
|
SUP.password = op;
|
|
|
|
}
|
|
|
|
print_vfs_message (_("fish: Sending password..."));
|
2009-12-29 01:53:09 +03:00
|
|
|
|
|
|
|
{
|
|
|
|
size_t str_len;
|
|
|
|
str_len = strlen (SUP.password);
|
2010-04-30 17:31:06 +04:00
|
|
|
if ((write (SUP.sockw, SUP.password, str_len) != (ssize_t) str_len)
|
2009-12-29 01:53:09 +03:00
|
|
|
|| (write (SUP.sockw, "\n", 1) != 1))
|
|
|
|
{
|
2010-04-30 17:31:06 +04:00
|
|
|
ERRNOR (EIO, -1);
|
2009-12-29 01:53:09 +03:00
|
|
|
}
|
|
|
|
}
|
2010-03-30 12:10:25 +04:00
|
|
|
}
|
1998-09-13 14:40:43 +04:00
|
|
|
}
|
|
|
|
|
2003-10-28 03:57:02 +03:00
|
|
|
print_vfs_message (_("fish: Sending initial line..."));
|
2001-04-17 23:48:03 +04:00
|
|
|
/*
|
|
|
|
* Run `start_fish_server'. If it doesn't exist - no problem,
|
|
|
|
* we'll talk directly to the shell.
|
|
|
|
*/
|
2003-10-28 03:57:02 +03:00
|
|
|
if (fish_command
|
2010-03-30 12:10:25 +04:00
|
|
|
(me, super, WAIT_REPLY,
|
|
|
|
"#FISH\necho; start_fish_server 2>&1; echo '### 200'\n") != COMPLETE)
|
|
|
|
ERRNOR (E_PROTO, -1);
|
2003-10-28 03:57:02 +03:00
|
|
|
|
|
|
|
print_vfs_message (_("fish: Handshaking version..."));
|
2010-03-30 12:10:25 +04:00
|
|
|
if (fish_command (me, super, WAIT_REPLY, "#VER 0.0.0\necho '### 000'\n") != COMPLETE)
|
|
|
|
ERRNOR (E_PROTO, -1);
|
1998-09-13 14:40:43 +04:00
|
|
|
|
2002-07-14 20:27:15 +04:00
|
|
|
/* Set up remote locale to C, otherwise dates cannot be recognized */
|
2003-10-28 03:57:02 +03:00
|
|
|
if (fish_command
|
2010-03-30 12:10:25 +04:00
|
|
|
(me, super, WAIT_REPLY,
|
|
|
|
"LANG=C; LC_ALL=C; LC_TIME=C\n"
|
|
|
|
"export LANG; export LC_ALL; export LC_TIME\n" "echo '### 200'\n") != COMPLETE)
|
|
|
|
ERRNOR (E_PROTO, -1);
|
2003-10-28 03:57:02 +03:00
|
|
|
|
|
|
|
print_vfs_message (_("fish: Setting up current directory..."));
|
2002-07-19 20:36:32 +04:00
|
|
|
SUP.cwdir = fish_getcwd (me, super);
|
2003-10-28 03:57:02 +03:00
|
|
|
print_vfs_message (_("fish: Connected, home %s."), SUP.cwdir);
|
1998-11-21 22:36:01 +03:00
|
|
|
#if 0
|
2010-03-30 12:10:25 +04:00
|
|
|
super->name = g_strconcat ("/#sh:", SUP.user, "@", SUP.host, "/", (char *) NULL);
|
1998-11-21 22:36:01 +03:00
|
|
|
#endif
|
2009-02-06 01:40:32 +03:00
|
|
|
super->name = g_strdup (PATH_SEP_STR);
|
1998-11-21 22:36:01 +03:00
|
|
|
|
2010-03-30 12:10:25 +04:00
|
|
|
super->root = vfs_s_new_inode (me, super, vfs_s_default_stat (me, S_IFDIR | 0755));
|
1998-11-21 22:36:01 +03:00
|
|
|
return 0;
|
1998-09-13 14:40:43 +04:00
|
|
|
}
|
|
|
|
|
1999-11-11 17:23:40 +03:00
|
|
|
static int
|
2003-10-28 05:10:33 +03:00
|
|
|
fish_open_archive (struct vfs_class *me, struct vfs_s_super *super,
|
2010-03-30 12:10:25 +04:00
|
|
|
const char *archive_name, char *op)
|
1998-09-13 14:40:43 +04:00
|
|
|
{
|
2000-04-10 16:00:43 +04:00
|
|
|
char *host, *user, *password, *p;
|
1998-11-21 22:36:01 +03:00
|
|
|
int flags;
|
|
|
|
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) archive_name;
|
|
|
|
|
2003-10-28 05:10:33 +03:00
|
|
|
p = vfs_split_url (strchr (op, ':') + 1, &host, &user, &flags,
|
2010-03-30 12:10:25 +04:00
|
|
|
&password, 0, URL_NOSLASH | URL_USE_ANONYMOUS);
|
2000-04-10 16:00:43 +04:00
|
|
|
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (p);
|
2000-04-10 16:00:43 +04:00
|
|
|
|
|
|
|
SUP.host = host;
|
|
|
|
SUP.user = user;
|
1998-11-21 22:36:01 +03:00
|
|
|
SUP.flags = flags;
|
2003-10-28 05:10:33 +03:00
|
|
|
if (!strncmp (op, "rsh:", 4))
|
2010-03-30 12:10:25 +04:00
|
|
|
SUP.flags = FISH_FLAG_RSH;
|
2002-07-19 20:36:32 +04:00
|
|
|
SUP.cwdir = NULL;
|
1998-11-21 22:36:01 +03:00
|
|
|
if (password)
|
2010-03-30 12:10:25 +04:00
|
|
|
SUP.password = password;
|
2003-10-28 03:57:02 +03:00
|
|
|
return fish_open_archive_int (me, super);
|
1998-09-13 14:40:43 +04:00
|
|
|
}
|
|
|
|
|
1998-11-21 22:36:01 +03:00
|
|
|
static int
|
2003-10-28 05:10:33 +03:00
|
|
|
fish_archive_same (struct vfs_class *me, struct vfs_s_super *super,
|
2010-03-30 12:10:25 +04:00
|
|
|
const char *archive_name, char *op, void *cookie)
|
2003-10-28 05:10:33 +03:00
|
|
|
{
|
2000-04-10 16:00:43 +04:00
|
|
|
char *host, *user;
|
1998-11-21 22:36:01 +03:00
|
|
|
int flags;
|
2009-12-25 18:03:23 +03:00
|
|
|
int result;
|
2000-04-10 16:00:43 +04:00
|
|
|
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
|
|
|
(void) archive_name;
|
|
|
|
(void) cookie;
|
|
|
|
|
2003-10-28 05:10:33 +03:00
|
|
|
op = vfs_split_url (strchr (op, ':') + 1, &host, &user, &flags, 0, 0,
|
2009-12-25 18:03:23 +03:00
|
|
|
URL_NOSLASH | URL_USE_ANONYMOUS);
|
2000-04-10 16:00:43 +04:00
|
|
|
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (op);
|
2000-04-10 16:00:43 +04:00
|
|
|
|
2009-12-25 18:03:23 +03:00
|
|
|
if (user == NULL)
|
2010-03-30 12:10:25 +04:00
|
|
|
user = vfs_get_local_username ();
|
2009-12-25 18:03:23 +03:00
|
|
|
|
|
|
|
result = ((strcmp (host, SUP.host) == 0)
|
2010-03-30 12:10:25 +04:00
|
|
|
&& (strcmp (user, SUP.user) == 0) && (flags == SUP.flags));
|
2009-12-25 18:03:23 +03:00
|
|
|
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (host);
|
|
|
|
g_free (user);
|
2000-04-10 16:00:43 +04:00
|
|
|
|
2009-12-25 18:03:23 +03:00
|
|
|
return result;
|
1998-09-13 14:40:43 +04:00
|
|
|
}
|
|
|
|
|
1998-11-21 22:36:01 +03:00
|
|
|
static int
|
2010-03-30 12:10:25 +04:00
|
|
|
fish_dir_load (struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path)
|
1998-09-13 14:40:43 +04:00
|
|
|
{
|
2003-10-12 05:00:44 +04:00
|
|
|
struct vfs_s_super *super = dir->super;
|
1998-09-13 14:40:43 +04:00
|
|
|
char buffer[8192];
|
2003-10-12 05:00:44 +04:00
|
|
|
struct vfs_s_entry *ent = NULL;
|
1998-11-21 22:36:01 +03:00
|
|
|
FILE *logfile;
|
2009-02-06 02:09:35 +03:00
|
|
|
char *quoted_path;
|
2007-11-02 17:50:41 +03:00
|
|
|
int reply_code;
|
2009-04-24 02:47:22 +04:00
|
|
|
gchar *shell_commands;
|
1998-09-13 14:40:43 +04:00
|
|
|
|
2009-01-25 05:01:48 +03:00
|
|
|
#if 0
|
|
|
|
/*
|
|
|
|
* Simple FISH debug interface :]
|
|
|
|
*/
|
|
|
|
if (!(MEDATA->logfile))
|
|
|
|
{
|
2010-03-30 12:10:25 +04:00
|
|
|
MEDATA->logfile = fopen ("/tmp/mc-FISH.sh", "w");
|
2009-01-25 05:01:48 +03:00
|
|
|
}
|
2009-04-24 02:47:22 +04:00
|
|
|
#endif /* 0 */
|
2009-01-25 05:01:48 +03:00
|
|
|
|
1998-11-21 22:36:01 +03:00
|
|
|
logfile = MEDATA->logfile;
|
1998-09-13 14:40:43 +04:00
|
|
|
|
2010-03-30 12:10:25 +04:00
|
|
|
print_vfs_message (_("fish: Reading directory %s..."), remote_path);
|
1998-11-21 22:36:01 +03:00
|
|
|
|
2010-03-30 12:10:25 +04:00
|
|
|
gettimeofday (&dir->timestamp, NULL);
|
2006-02-23 18:32:18 +03:00
|
|
|
dir->timestamp.tv_sec += fish_directory_timeout;
|
2009-06-09 13:12:17 +04:00
|
|
|
quoted_path = strutils_shell_escape (remote_path);
|
2010-03-30 12:10:25 +04:00
|
|
|
/* *INDENT-OFF* */
|
|
|
|
shell_commands = g_strconcat (
|
|
|
|
"#LIST /%s\n"
|
|
|
|
"if `perl -v > /dev/null 2>&1` ; then\n"
|
|
|
|
"perl -e '\n"
|
|
|
|
"use strict;\n"
|
|
|
|
"use POSIX;\n"
|
|
|
|
"use Fcntl;\n"
|
|
|
|
"use POSIX \":fcntl_h\"; #S_ISLNK was here until 5.6\n"
|
|
|
|
"import Fcntl \":mode\" unless defined &S_ISLNK; #and is now here\n"
|
|
|
|
"my $dirname = $ARGV[0];\n"
|
|
|
|
"if (opendir ( DIR, $dirname )) {\n"
|
|
|
|
"while( (my $filename = readdir(DIR))){\n"
|
|
|
|
"my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = lstat(\"$dirname/$filename\");\n"
|
|
|
|
"my $mloctime= strftime(\"%%m-%%d-%%Y %%H:%%M\", localtime $mtime);\n"
|
|
|
|
,
|
|
|
|
"my $strutils_shell_escape_regex = s/([;<>\\*\\|`&\\$!#\\(\\)\\[\\]\\{\\}:'\\''\"\\ \\\\])/\\\\$1/g;\n"
|
|
|
|
"my $e_filename = $filename;\n"
|
|
|
|
"$e_filename =~ $strutils_shell_escape_regex;\n"
|
|
|
|
"if (S_ISLNK($mode) ) {\n"
|
|
|
|
"my $linkname = readlink (\"$dirname/$filename\");\n"
|
|
|
|
"$linkname =~ $strutils_shell_escape_regex;\n"
|
|
|
|
"\n"
|
|
|
|
"printf(\"R%%o %%o $uid.$gid\\n" "S$size\\n"
|
|
|
|
"d$mloctime\\n"
|
|
|
|
":\\\"$e_filename\\\" -> \\\"$linkname\\\"\\n"
|
|
|
|
"\\n\", S_IMODE($mode), S_IFMT($mode));\n"
|
|
|
|
"} else {\n"
|
|
|
|
"printf(\"R%%o %%o $uid.$gid\\n"
|
|
|
|
"S$size\\n"
|
|
|
|
"d$mloctime\\n"
|
|
|
|
":\\\"$e_filename\\\"\\n"
|
|
|
|
"\\n\", S_IMODE($mode), S_IFMT($mode));\n"
|
|
|
|
"}}\n"
|
|
|
|
,
|
|
|
|
"printf(\"### 200\\n\");\n"
|
|
|
|
"closedir(DIR);\n"
|
|
|
|
"} else {\n"
|
|
|
|
"printf(\"### 500\\n\");\n"
|
|
|
|
"}\n"
|
|
|
|
"exit 0\n"
|
|
|
|
"' /%s ||\n" /* ARGV[0] - path to browse */
|
|
|
|
" echo '### 500'\n" /* do not hang if perl is to eval it */
|
|
|
|
"elif `ls -1 /%s >/dev/null 2>&1` ; then\n"
|
|
|
|
"if `ls -Q /%s >/dev/null 2>&1`; then\n"
|
|
|
|
"LSOPT=\"-Qlan\";\n"
|
|
|
|
"ADD=0;\n"
|
|
|
|
"else\n"
|
|
|
|
"LSOPT=\"-lan\";\n"
|
|
|
|
"ADD=1;\n"
|
|
|
|
"fi\n"
|
|
|
|
"ls $LSOPT /%s 2>/dev/null | grep '^[^cbt]' | (\n"
|
|
|
|
"while read p l u g s m d y n n2 n3; do\n"
|
|
|
|
"if test \"$m\" = \"0\" ; then \n"
|
|
|
|
"s=$d; m=$y; d=$n y=$n2; n=$n3\n"
|
|
|
|
"else\n"
|
|
|
|
"n=$n\" \"$n2\" \"$n3\n"
|
|
|
|
"fi\n"
|
|
|
|
"if [ $ADD = 0 ]; then\n"
|
|
|
|
"echo \"P$p $u.$g\nS$s\nd$m $d $y\n:$n\n\"\n"
|
|
|
|
"elif `sed --version >/dev/null 2>&1` ; then\n"
|
|
|
|
"file=`echo $n | sed -e 's#^\\(.*\\) -> \\(.*\\)#\\1\" -> \"\\2#'`\n",
|
|
|
|
"echo \"P$p $u $g\nS$s\nd$m $d $y\n:\"$file\"\n\"\n"
|
|
|
|
"else\n"
|
|
|
|
"echo \"P$p $u $g\nS$s\nd$m $d $y\n:\"$n\"\n\"\n"
|
|
|
|
"fi\n"
|
|
|
|
"done )\n"
|
|
|
|
"ls $LSOPT /%s 2>/dev/null | grep '^[cb]' | (\n"
|
|
|
|
"while read p l u g a i m d y n n2 n3; do\n"
|
|
|
|
"if test \"$a\" = \"0\" ; then \n"
|
|
|
|
"a=$m; i=$d; m=$y; d=$n y=$n2; n=$n3\n"
|
|
|
|
"else\n"
|
|
|
|
"n=$n\" \"$n2\" \"$n3\n"
|
|
|
|
"fi\n"
|
|
|
|
"if [ $ADD = 0 ]; then\n"
|
|
|
|
"echo \"P$p $u.$g\nE$a$i\nd$m $d $y\n:$n\n\"\n"
|
|
|
|
"elif `sed --version >/dev/null 2>&1` ; then\n"
|
|
|
|
"file=`echo $n | sed -e 's#^\\(.*\\) -> \\(.*\\)#\\1\" -> \"\\2#'`\n"
|
|
|
|
"echo \"P$p $u $g\nS$s\nd$m $d $y\n:\"$file\"\n\"\n"
|
|
|
|
"else\n"
|
|
|
|
"echo \"P$p $u $g\nS$s\nd$m $d $y\n:\"$n\"\n\"\n"
|
|
|
|
"fi\n"
|
|
|
|
"done)\n"
|
|
|
|
"echo '### 200'\n"
|
|
|
|
"else\n"
|
|
|
|
"echo '### 500'\n"
|
|
|
|
"fi\n"
|
|
|
|
,
|
|
|
|
(char *) NULL);
|
|
|
|
/* *INDENT-ON* */
|
2009-04-24 02:47:22 +04:00
|
|
|
|
|
|
|
fish_command (me, super, NONE, shell_commands,
|
2010-03-30 12:10:25 +04:00
|
|
|
quoted_path, quoted_path, quoted_path, quoted_path, quoted_path, quoted_path);
|
2009-04-24 02:47:22 +04:00
|
|
|
|
2010-03-30 12:10:25 +04:00
|
|
|
g_free (shell_commands);
|
2009-02-06 02:34:50 +03:00
|
|
|
g_free (quoted_path);
|
2010-03-30 12:10:25 +04:00
|
|
|
ent = vfs_s_generate_entry (me, NULL, dir, 0);
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
int res = vfs_s_get_line_interruptible (me, buffer, sizeof (buffer), SUP.sockr);
|
|
|
|
if ((!res) || (res == EINTR))
|
|
|
|
{
|
|
|
|
vfs_s_free_entry (me, ent);
|
|
|
|
me->verrno = ECONNRESET;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (logfile)
|
|
|
|
{
|
|
|
|
fputs (buffer, logfile);
|
1998-09-13 14:40:43 +04:00
|
|
|
fputs ("\n", logfile);
|
2010-03-30 12:10:25 +04:00
|
|
|
fflush (logfile);
|
|
|
|
}
|
|
|
|
if (!strncmp (buffer, "### ", 4))
|
|
|
|
break;
|
|
|
|
if ((!buffer[0]))
|
|
|
|
{
|
|
|
|
if (ent->name)
|
|
|
|
{
|
|
|
|
vfs_s_insert_entry (me, dir, ent);
|
|
|
|
ent = vfs_s_generate_entry (me, NULL, dir, 0);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
1998-11-21 22:36:01 +03:00
|
|
|
#define ST ent->ino->st
|
1998-09-13 14:40:43 +04:00
|
|
|
|
2010-03-30 12:10:25 +04:00
|
|
|
switch (buffer[0])
|
|
|
|
{
|
|
|
|
case ':':
|
|
|
|
{
|
|
|
|
char *temp;
|
|
|
|
char *data_start = buffer + 1;
|
|
|
|
char *filename = data_start;
|
|
|
|
char *linkname = data_start;
|
|
|
|
char *filename_bound = filename + strlen (filename);
|
|
|
|
char *linkname_bound = filename_bound;
|
|
|
|
if (!strcmp (data_start, "\".\"") || !strcmp (data_start, "\"..\""))
|
|
|
|
break; /* We'll do "." and ".." ourselves */
|
|
|
|
|
|
|
|
if (S_ISLNK (ST.st_mode))
|
|
|
|
{
|
|
|
|
/* we expect: "escaped-name" -> "escaped-name"
|
|
|
|
// -> cannot occur in filenames,
|
|
|
|
// because it will be escaped to -\> */
|
|
|
|
|
|
|
|
if (*filename == '"')
|
|
|
|
++filename;
|
|
|
|
|
|
|
|
linkname = strstr (filename, "\" -> \"");
|
|
|
|
if (!linkname)
|
|
|
|
{
|
|
|
|
/* broken client, or smth goes wrong */
|
|
|
|
linkname = filename_bound;
|
|
|
|
if (filename_bound > filename && *(filename_bound - 1) == '"')
|
|
|
|
--filename_bound; /* skip trailing " */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
filename_bound = linkname;
|
|
|
|
linkname += 6; /* strlen ("\" -> \"") */
|
|
|
|
if (*(linkname_bound - 1) == '"')
|
|
|
|
--linkname_bound; /* skip trailing " */
|
|
|
|
}
|
|
|
|
|
|
|
|
ent->name = str_dup_range (filename, filename_bound);
|
|
|
|
temp = ent->name;
|
|
|
|
ent->name = strutils_shell_unescape (ent->name);
|
|
|
|
g_free (temp);
|
|
|
|
|
|
|
|
ent->ino->linkname = str_dup_range (linkname, linkname_bound);
|
|
|
|
temp = ent->ino->linkname;
|
|
|
|
ent->ino->linkname = strutils_shell_unescape (ent->ino->linkname);
|
|
|
|
g_free (temp);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* we expect: "escaped-name" */
|
|
|
|
if (filename_bound - filename > 2)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
there is at least 2 "
|
|
|
|
and we skip them
|
|
|
|
*/
|
|
|
|
if (*filename == '"')
|
|
|
|
++filename;
|
|
|
|
if (*(filename_bound - 1) == '"')
|
|
|
|
--filename_bound;
|
|
|
|
}
|
|
|
|
ent->name = str_dup_range (filename, filename_bound);
|
|
|
|
temp = ent->name;
|
|
|
|
ent->name = strutils_shell_unescape (ent->name);
|
|
|
|
g_free (temp);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'S':
|
2004-08-30 22:36:58 +04:00
|
|
|
#ifdef HAVE_ATOLL
|
2010-03-30 12:10:25 +04:00
|
|
|
ST.st_size = (off_t) atoll (buffer + 1);
|
2004-08-30 22:36:58 +04:00
|
|
|
#else
|
2010-03-30 12:10:25 +04:00
|
|
|
ST.st_size = (off_t) atof (buffer + 1);
|
2004-08-30 22:36:58 +04:00
|
|
|
#endif
|
2010-03-30 12:10:25 +04:00
|
|
|
break;
|
|
|
|
case 'P':
|
|
|
|
{
|
|
|
|
size_t skipped;
|
|
|
|
vfs_parse_filemode (buffer + 1, &skipped, &ST.st_mode);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'R':
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
raw filemode:
|
|
|
|
we expect: Roctal-filemode octal-filetype uid.gid
|
|
|
|
*/
|
|
|
|
size_t skipped;
|
|
|
|
vfs_parse_raw_filemode (buffer + 1, &skipped, &ST.st_mode);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'd':
|
|
|
|
{
|
|
|
|
vfs_split_text (buffer + 1);
|
|
|
|
if (!vfs_parse_filedate (0, &ST.st_ctime))
|
|
|
|
break;
|
|
|
|
ST.st_atime = ST.st_mtime = ST.st_ctime;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'D':
|
|
|
|
{
|
|
|
|
struct tm tim;
|
|
|
|
if (sscanf (buffer + 1, "%d %d %d %d %d %d", &tim.tm_year, &tim.tm_mon,
|
|
|
|
&tim.tm_mday, &tim.tm_hour, &tim.tm_min, &tim.tm_sec) != 6)
|
|
|
|
break;
|
|
|
|
ST.st_atime = ST.st_mtime = ST.st_ctime = mktime (&tim);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'E':
|
|
|
|
{
|
|
|
|
int maj, min;
|
|
|
|
if (sscanf (buffer + 1, "%d,%d", &maj, &min) != 2)
|
|
|
|
break;
|
2003-10-29 20:36:16 +03:00
|
|
|
#ifdef HAVE_STRUCT_STAT_ST_RDEV
|
2010-03-30 12:10:25 +04:00
|
|
|
ST.st_rdev = makedev (maj, min);
|
1998-09-13 14:40:43 +04:00
|
|
|
#endif
|
2010-03-30 12:10:25 +04:00
|
|
|
}
|
|
|
|
}
|
1998-09-13 14:40:43 +04:00
|
|
|
}
|
2010-03-30 12:10:25 +04:00
|
|
|
|
1998-11-21 22:36:01 +03:00
|
|
|
vfs_s_free_entry (me, ent);
|
2010-03-30 12:10:25 +04:00
|
|
|
reply_code = fish_decode_reply (buffer + 4, 0);
|
|
|
|
if (reply_code == COMPLETE)
|
|
|
|
{
|
|
|
|
g_free (SUP.cwdir);
|
|
|
|
SUP.cwdir = g_strdup (remote_path);
|
|
|
|
print_vfs_message (_("%s: done."), me->name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else if (reply_code == ERROR)
|
|
|
|
{
|
|
|
|
me->verrno = EACCES;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
me->verrno = E_REMOTE;
|
2002-07-19 08:29:37 +04:00
|
|
|
}
|
1998-11-21 22:36:01 +03:00
|
|
|
|
2010-03-30 12:10:25 +04:00
|
|
|
error:
|
2002-07-19 08:29:37 +04:00
|
|
|
print_vfs_message (_("%s: failure"), me->name);
|
2007-11-02 17:50:41 +03:00
|
|
|
return -1;
|
1998-09-13 14:40:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-03-30 12:10:25 +04:00
|
|
|
fish_file_store (struct vfs_class *me, struct vfs_s_fh *fh, char *name, char *localname)
|
1998-09-13 14:40:43 +04:00
|
|
|
{
|
2003-10-12 05:00:44 +04:00
|
|
|
struct vfs_s_super *super = FH_SUPER;
|
1998-11-21 22:36:01 +03:00
|
|
|
int n, total;
|
1998-09-13 14:40:43 +04:00
|
|
|
char buffer[8192];
|
|
|
|
struct stat s;
|
|
|
|
int was_error = 0;
|
1998-11-21 22:36:01 +03:00
|
|
|
int h;
|
2009-02-06 02:09:35 +03:00
|
|
|
char *quoted_name;
|
1998-09-13 14:40:43 +04:00
|
|
|
|
2002-11-01 19:55:02 +03:00
|
|
|
h = open (localname, O_RDONLY);
|
1998-09-13 14:40:43 +04:00
|
|
|
|
2002-11-01 19:55:02 +03:00
|
|
|
if (h == -1)
|
2010-03-30 12:10:25 +04:00
|
|
|
ERRNOR (EIO, -1);
|
|
|
|
if (fstat (h, &s) < 0)
|
|
|
|
{
|
|
|
|
close (h);
|
|
|
|
ERRNOR (EIO, -1);
|
2002-11-01 19:55:02 +03:00
|
|
|
}
|
2006-03-30 18:39:33 +04:00
|
|
|
|
|
|
|
/* First, try this as stor:
|
|
|
|
*
|
|
|
|
* ( head -c number ) | ( cat > file; cat >/dev/null )
|
|
|
|
*
|
|
|
|
* If `head' is not present on the remote system, `dd' will be used.
|
|
|
|
* Unfortunately, we cannot trust most non-GNU `head' implementations
|
|
|
|
* even if `-c' options is supported. Therefore, we separate GNU head
|
|
|
|
* (and other modern heads?) using `-q' and `-' . This causes another
|
|
|
|
* implementations to fail (because of "incorrect options").
|
|
|
|
*
|
2010-03-30 12:10:25 +04:00
|
|
|
* Fallback is:
|
2006-03-30 18:39:33 +04:00
|
|
|
*
|
2010-03-30 12:10:25 +04:00
|
|
|
* rest=<number>
|
|
|
|
* while [ $rest -gt 0 ]
|
|
|
|
* do
|
|
|
|
* cnt=`expr \( $rest + 255 \) / 256`
|
|
|
|
* n=`dd bs=256 count=$cnt | tee -a <target_file> | wc -c`
|
|
|
|
* rest=`expr $rest - $n`
|
|
|
|
* done
|
2006-03-30 18:39:33 +04:00
|
|
|
*
|
2010-03-30 12:10:25 +04:00
|
|
|
* `dd' was not designed for full filling of input buffers,
|
|
|
|
* and does not report exact number of bytes (not blocks).
|
|
|
|
* Therefore a more complex shell script is needed.
|
2006-03-31 18:29:37 +04:00
|
|
|
*
|
2010-03-30 12:10:25 +04:00
|
|
|
* On some systems non-GNU head writes "Usage:" error report to stdout
|
|
|
|
* instead of stderr. It makes impossible the use of "head || dd"
|
|
|
|
* algorithm for file appending case, therefore just "dd" is used for it.
|
2006-03-30 18:39:33 +04:00
|
|
|
*/
|
1998-09-13 14:40:43 +04:00
|
|
|
|
2010-03-30 12:10:25 +04:00
|
|
|
quoted_name = strutils_shell_escape (name);
|
|
|
|
print_vfs_message (_("fish: store %s: sending command..."), quoted_name);
|
2003-05-08 10:04:04 +04:00
|
|
|
|
|
|
|
/* FIXME: File size is limited to ULONG_MAX */
|
2002-07-26 05:33:40 +04:00
|
|
|
if (!fh->u.fish.append)
|
2010-04-30 17:31:06 +04:00
|
|
|
{
|
2010-03-30 12:10:25 +04:00
|
|
|
/* *INDENT-OFF* */
|
|
|
|
n = fish_command (me, super, WAIT_REPLY,
|
|
|
|
"#STOR %lu /%s\n"
|
|
|
|
"echo '### 001'\n"
|
|
|
|
"file=/%s\n"
|
|
|
|
"res=`exec 3>&1\n"
|
|
|
|
"(\n"
|
|
|
|
"head -c %lu -q - || echo DD >&3\n"
|
|
|
|
") 2>/dev/null | (\n"
|
|
|
|
"cat > $file\n"
|
|
|
|
"cat > /dev/null\n"
|
|
|
|
")`; [ \"$res\" = DD ] && {\n"
|
|
|
|
"> \"$file\"\n"
|
|
|
|
"rest=%lu\n"
|
|
|
|
"while [ $rest -gt 0 ]\n"
|
|
|
|
"do\n"
|
|
|
|
" cnt=`expr \\( $rest + 255 \\) / 256`\n"
|
|
|
|
" n=`dd bs=256 count=$cnt | tee -a \"$file\" | wc -c`\n"
|
|
|
|
" rest=`expr $rest - $n`\n"
|
|
|
|
"done\n"
|
|
|
|
"}; echo '### 200'\n",
|
|
|
|
(unsigned long) s.st_size, quoted_name,
|
|
|
|
quoted_name, (unsigned long) s.st_size, (unsigned long) s.st_size);
|
|
|
|
/* *INDENT-ON* */
|
2010-04-30 17:31:06 +04:00
|
|
|
}
|
2002-07-26 05:33:40 +04:00
|
|
|
else
|
2010-04-30 17:31:06 +04:00
|
|
|
{
|
2010-03-30 12:10:25 +04:00
|
|
|
/* *INDENT-OFF* */
|
|
|
|
n = fish_command (me, super, WAIT_REPLY,
|
|
|
|
"#STOR %lu /%s\n"
|
|
|
|
"echo '### 001'\n"
|
|
|
|
"{\n"
|
|
|
|
"file=/%s\n"
|
|
|
|
"rest=%lu\n"
|
|
|
|
"while [ $rest -gt 0 ]\n"
|
|
|
|
"do\n"
|
|
|
|
" cnt=`expr \\( $rest + 255 \\) / 256`\n"
|
|
|
|
" n=`dd bs=256 count=$cnt | tee -a $file | wc -c`\n"
|
|
|
|
" rest=`expr $rest - $n`\n"
|
|
|
|
"done\n"
|
|
|
|
"}; echo '### 200'\n",
|
|
|
|
(unsigned long) s.st_size, quoted_name,
|
|
|
|
quoted_name, (unsigned long) s.st_size);
|
|
|
|
/* *INDENT-ON* */
|
2010-04-30 17:31:06 +04:00
|
|
|
}
|
2010-03-30 12:10:25 +04:00
|
|
|
if (n != PRELIM)
|
|
|
|
{
|
|
|
|
close (h);
|
|
|
|
ERRNOR (E_REMOTE, -1);
|
2002-11-01 19:55:02 +03:00
|
|
|
}
|
2010-03-30 12:10:25 +04:00
|
|
|
|
1998-09-13 14:40:43 +04:00
|
|
|
total = 0;
|
2010-03-30 12:10:25 +04:00
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
int t;
|
|
|
|
while ((n = read (h, buffer, sizeof (buffer))) < 0)
|
|
|
|
{
|
|
|
|
if ((errno == EINTR) && tty_got_interrupt ())
|
|
|
|
continue;
|
|
|
|
print_vfs_message (_("fish: Local read failed, sending zeros"));
|
|
|
|
close (h);
|
|
|
|
h = open ("/dev/zero", O_RDONLY);
|
|
|
|
}
|
2010-03-30 22:59:41 +04:00
|
|
|
|
2010-03-30 12:10:25 +04:00
|
|
|
if (n == 0)
|
|
|
|
break;
|
2010-03-30 22:59:41 +04:00
|
|
|
|
|
|
|
t = write (SUP.sockw, buffer, n);
|
|
|
|
if (t != n)
|
2010-03-30 12:10:25 +04:00
|
|
|
{
|
|
|
|
if (t == -1)
|
|
|
|
me->verrno = errno;
|
|
|
|
else
|
|
|
|
me->verrno = EIO;
|
|
|
|
goto error_return;
|
|
|
|
}
|
|
|
|
tty_disable_interrupt_key ();
|
|
|
|
total += n;
|
|
|
|
print_vfs_message (_("fish: storing %s %d (%lu)"),
|
|
|
|
was_error ? _("zeros") : _("file"), total, (unsigned long) s.st_size);
|
1998-09-13 14:40:43 +04:00
|
|
|
}
|
2010-03-30 12:10:25 +04:00
|
|
|
close (h);
|
|
|
|
g_free (quoted_name);
|
2003-10-28 03:57:02 +03:00
|
|
|
if ((fish_get_reply (me, SUP.sockr, NULL, 0) != COMPLETE) || was_error)
|
2000-02-23 10:43:14 +03:00
|
|
|
ERRNOR (E_REMOTE, -1);
|
1998-09-13 14:40:43 +04:00
|
|
|
return 0;
|
2010-03-30 12:10:25 +04:00
|
|
|
error_return:
|
|
|
|
close (h);
|
|
|
|
fish_get_reply (me, SUP.sockr, NULL, 0);
|
|
|
|
g_free (quoted_name);
|
1998-11-21 22:36:01 +03:00
|
|
|
return -1;
|
1998-09-13 14:40:43 +04:00
|
|
|
}
|
|
|
|
|
2004-10-07 01:20:17 +04:00
|
|
|
static int
|
|
|
|
fish_linear_start (struct vfs_class *me, struct vfs_s_fh *fh, off_t offset)
|
1998-09-21 13:52:07 +04:00
|
|
|
{
|
1998-11-21 22:36:01 +03:00
|
|
|
char *name;
|
2009-02-06 02:09:35 +03:00
|
|
|
char *quoted_name;
|
1998-10-13 02:07:53 +04:00
|
|
|
if (offset)
|
1998-11-21 22:36:01 +03:00
|
|
|
ERRNOR (E_NOTSUPP, 0);
|
|
|
|
name = vfs_s_fullpath (me, fh->ino);
|
2010-03-17 12:07:46 +03:00
|
|
|
if (name == NULL)
|
2010-03-30 12:10:25 +04:00
|
|
|
return 0;
|
2010-03-17 12:07:46 +03:00
|
|
|
quoted_name = strutils_shell_escape (name);
|
|
|
|
g_free (name);
|
2002-07-26 05:33:40 +04:00
|
|
|
fh->u.fish.append = 0;
|
2007-10-26 17:46:42 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check whether the remote file is readable by using `dd' to copy
|
|
|
|
* a single byte from the remote file to /dev/null. If `dd' completes
|
|
|
|
* with exit status of 0 use `cat' to send the file contents to the
|
|
|
|
* standard output (i.e. over the network).
|
|
|
|
*/
|
2010-03-30 12:10:25 +04:00
|
|
|
/* *INDENT-OFF* */
|
2003-10-28 03:57:02 +03:00
|
|
|
offset = fish_command (me, FH_SUPER, WANT_STRING,
|
2010-03-30 12:10:25 +04:00
|
|
|
"#RETR /%s\n"
|
|
|
|
"if dd if=/%s of=/dev/null bs=1 count=1 2>/dev/null ;\n"
|
|
|
|
"then\n"
|
|
|
|
"ls -ln /%s 2>/dev/null | (\n"
|
|
|
|
"read p l u g s r\n"
|
|
|
|
"echo $s\n"
|
|
|
|
")\n"
|
|
|
|
"echo '### 100'\n"
|
|
|
|
"cat /%s\n"
|
|
|
|
"echo '### 200'\n"
|
|
|
|
"else\n"
|
|
|
|
"echo '### 500'\n"
|
|
|
|
"fi\n",
|
|
|
|
quoted_name, quoted_name, quoted_name, quoted_name);
|
|
|
|
/* *INDENT-ON* */
|
2009-02-06 02:34:50 +03:00
|
|
|
g_free (quoted_name);
|
2010-03-30 12:10:25 +04:00
|
|
|
if (offset != PRELIM)
|
|
|
|
ERRNOR (E_REMOTE, 0);
|
1998-11-21 22:36:01 +03:00
|
|
|
fh->linear = LS_LINEAR_OPEN;
|
|
|
|
fh->u.fish.got = 0;
|
2007-10-11 16:32:42 +04:00
|
|
|
errno = 0;
|
|
|
|
#if SIZEOF_OFF_T == SIZEOF_LONG
|
|
|
|
fh->u.fish.total = strtol (reply_str, NULL, 10);
|
2007-04-26 19:10:02 +04:00
|
|
|
#else
|
2007-10-11 16:32:42 +04:00
|
|
|
fh->u.fish.total = strtoll (reply_str, NULL, 10);
|
2007-04-26 19:10:02 +04:00
|
|
|
#endif
|
2007-10-11 16:32:42 +04:00
|
|
|
if (errno != 0)
|
2010-03-30 12:10:25 +04:00
|
|
|
ERRNOR (E_REMOTE, 0);
|
1998-09-21 13:52:07 +04:00
|
|
|
return 1;
|
|
|
|
}
|
1998-09-13 14:40:43 +04:00
|
|
|
|
|
|
|
static void
|
2003-10-28 03:57:02 +03:00
|
|
|
fish_linear_abort (struct vfs_class *me, struct vfs_s_fh *fh)
|
1998-09-13 14:40:43 +04:00
|
|
|
{
|
2003-10-12 05:00:44 +04:00
|
|
|
struct vfs_s_super *super = FH_SUPER;
|
1998-09-21 13:52:07 +04:00
|
|
|
char buffer[8192];
|
1998-09-13 14:40:43 +04:00
|
|
|
int n;
|
|
|
|
|
2010-03-30 12:10:25 +04:00
|
|
|
print_vfs_message (_("Aborting transfer..."));
|
|
|
|
do
|
|
|
|
{
|
|
|
|
n = MIN (8192, fh->u.fish.total - fh->u.fish.got);
|
2010-03-30 22:59:41 +04:00
|
|
|
if (n != 0)
|
2010-03-30 12:10:25 +04:00
|
|
|
{
|
2010-03-30 22:59:41 +04:00
|
|
|
n = read (SUP.sockr, buffer, n);
|
|
|
|
if (n < 0)
|
2010-03-30 12:10:25 +04:00
|
|
|
return;
|
|
|
|
fh->u.fish.got += n;
|
|
|
|
}
|
|
|
|
}
|
2010-03-30 22:59:41 +04:00
|
|
|
while (n != 0);
|
1998-09-13 14:40:43 +04:00
|
|
|
|
2003-10-28 03:57:02 +03:00
|
|
|
if (fish_get_reply (me, SUP.sockr, NULL, 0) != COMPLETE)
|
2010-03-30 12:10:25 +04:00
|
|
|
print_vfs_message (_("Error reported after abort."));
|
1998-09-13 14:40:43 +04:00
|
|
|
else
|
2010-03-30 12:10:25 +04:00
|
|
|
print_vfs_message (_("Aborted transfer would be successful."));
|
1998-09-13 14:40:43 +04:00
|
|
|
}
|
|
|
|
|
1998-09-21 13:52:07 +04:00
|
|
|
static int
|
2003-10-28 03:57:02 +03:00
|
|
|
fish_linear_read (struct vfs_class *me, struct vfs_s_fh *fh, void *buf, int len)
|
1998-09-13 14:40:43 +04:00
|
|
|
{
|
2003-10-12 05:00:44 +04:00
|
|
|
struct vfs_s_super *super = FH_SUPER;
|
1998-09-21 13:52:07 +04:00
|
|
|
int n = 0;
|
2010-03-30 12:10:25 +04:00
|
|
|
len = MIN (fh->u.fish.total - fh->u.fish.got, len);
|
2009-05-19 17:42:37 +04:00
|
|
|
tty_disable_interrupt_key ();
|
2010-03-30 12:10:25 +04:00
|
|
|
while (len && ((n = read (SUP.sockr, buf, len)) < 0))
|
|
|
|
{
|
2009-05-19 17:42:37 +04:00
|
|
|
if ((errno == EINTR) && !tty_got_interrupt ())
|
2010-03-30 12:10:25 +04:00
|
|
|
continue;
|
|
|
|
break;
|
1998-09-21 13:52:07 +04:00
|
|
|
}
|
2010-03-30 12:10:25 +04:00
|
|
|
tty_enable_interrupt_key ();
|
1998-09-13 14:40:43 +04:00
|
|
|
|
2010-03-30 12:10:25 +04:00
|
|
|
if (n > 0)
|
|
|
|
fh->u.fish.got += n;
|
2010-03-30 22:59:41 +04:00
|
|
|
else if (n < 0)
|
2010-03-30 12:10:25 +04:00
|
|
|
fish_linear_abort (me, fh);
|
2010-03-30 22:59:41 +04:00
|
|
|
else if (fish_get_reply (me, SUP.sockr, NULL, 0) != COMPLETE)
|
1998-11-21 22:36:01 +03:00
|
|
|
ERRNOR (E_REMOTE, -1);
|
1998-09-21 13:52:07 +04:00
|
|
|
ERRNOR (errno, n);
|
1998-09-13 14:40:43 +04:00
|
|
|
}
|
|
|
|
|
1998-09-27 23:27:58 +04:00
|
|
|
static void
|
2003-10-28 03:57:02 +03:00
|
|
|
fish_linear_close (struct vfs_class *me, struct vfs_s_fh *fh)
|
1998-09-13 14:40:43 +04:00
|
|
|
{
|
1998-11-21 22:36:01 +03:00
|
|
|
if (fh->u.fish.total != fh->u.fish.got)
|
2010-03-30 12:10:25 +04:00
|
|
|
fish_linear_abort (me, fh);
|
1998-09-13 14:40:43 +04:00
|
|
|
}
|
|
|
|
|
1998-10-13 02:07:53 +04:00
|
|
|
static int
|
2003-10-16 20:12:19 +04:00
|
|
|
fish_ctl (void *fh, int ctlop, void *arg)
|
1998-09-13 14:40:43 +04:00
|
|
|
{
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) arg;
|
2009-04-24 02:47:22 +04:00
|
|
|
(void) fh;
|
|
|
|
(void) ctlop;
|
1998-11-21 22:36:01 +03:00
|
|
|
return 0;
|
2005-06-08 04:31:25 +04:00
|
|
|
#if 0
|
2010-03-30 12:10:25 +04:00
|
|
|
switch (ctlop)
|
|
|
|
{
|
|
|
|
case VFS_CTL_IS_NOTREADY:
|
|
|
|
{
|
|
|
|
int v;
|
|
|
|
|
|
|
|
if (!FH->linear)
|
|
|
|
vfs_die ("You may not do this");
|
|
|
|
if (FH->linear == LS_LINEAR_CLOSED || FH->linear == LS_LINEAR_PREOPEN)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
v = vfs_s_select_on_two (FH_SUPER->u.fish.sockr, 0);
|
|
|
|
if (((v < 0) && (errno == EINTR)) || v == 0)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return 0;
|
1998-09-13 14:40:43 +04:00
|
|
|
}
|
2005-06-08 04:31:25 +04:00
|
|
|
#endif
|
1998-09-13 14:40:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-03-30 12:10:25 +04:00
|
|
|
fish_send_command (struct vfs_class *me, struct vfs_s_super *super, const char *cmd, int flags)
|
1998-09-13 14:40:43 +04:00
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
2003-12-06 07:05:35 +03:00
|
|
|
r = fish_command (me, super, WAIT_REPLY, "%s", cmd);
|
2003-11-27 00:10:42 +03:00
|
|
|
vfs_stamp_create (&vfs_fish_ops, super);
|
2010-03-30 12:10:25 +04:00
|
|
|
if (r != COMPLETE)
|
|
|
|
ERRNOR (E_REMOTE, -1);
|
1998-11-21 22:36:01 +03:00
|
|
|
if (flags & OPT_FLUSH)
|
2010-03-30 12:10:25 +04:00
|
|
|
vfs_s_invalidate (me, super);
|
1998-09-13 14:40:43 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define PREFIX \
|
1999-01-21 01:01:11 +03:00
|
|
|
char buf[BUF_LARGE]; \
|
2005-09-05 04:52:56 +04:00
|
|
|
const char *crpath; \
|
2009-02-06 02:09:35 +03:00
|
|
|
char *rpath, *mpath = g_strdup (path); \
|
2003-10-12 05:00:44 +04:00
|
|
|
struct vfs_s_super *super; \
|
2010-03-30 22:59:41 +04:00
|
|
|
crpath = vfs_s_get_path_mangle (me, mpath, &super, 0); \
|
|
|
|
if (crpath == NULL) \
|
2010-03-30 12:10:25 +04:00
|
|
|
{ \
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (mpath); \
|
2002-11-01 19:55:02 +03:00
|
|
|
return -1; \
|
2004-11-29 15:45:42 +03:00
|
|
|
} \
|
2010-03-30 22:59:41 +04:00
|
|
|
rpath = strutils_shell_escape (crpath); \
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (mpath);
|
1998-09-13 14:40:43 +04:00
|
|
|
|
|
|
|
#define POSTFIX(flags) \
|
2009-02-06 02:09:35 +03:00
|
|
|
g_free (rpath); \
|
2010-03-30 22:59:41 +04:00
|
|
|
return fish_send_command (me, super, buf, flags);
|
1998-09-13 14:40:43 +04:00
|
|
|
|
1998-10-13 02:07:53 +04:00
|
|
|
static int
|
2004-08-17 01:36:39 +04:00
|
|
|
fish_chmod (struct vfs_class *me, const char *path, int mode)
|
1998-09-13 14:40:43 +04:00
|
|
|
{
|
2010-03-30 12:10:25 +04:00
|
|
|
/* *INDENT-OFF* */
|
2010-04-30 17:31:06 +04:00
|
|
|
PREFIX
|
2010-03-30 12:10:25 +04:00
|
|
|
g_snprintf (buf, sizeof (buf),
|
|
|
|
"#CHMOD %4.4o /%s\n"
|
|
|
|
"if chmod %4.4o /%s 2>/dev/null; then\n"
|
|
|
|
"echo '### 000'\n"
|
|
|
|
"else\n"
|
|
|
|
"echo '### 500'\n"
|
|
|
|
"fi\n",
|
|
|
|
mode & 07777, rpath, mode & 07777, rpath);
|
|
|
|
POSTFIX (OPT_FLUSH);
|
2010-04-30 17:31:06 +04:00
|
|
|
/* *INDENT-ON* */
|
1998-09-13 14:40:43 +04:00
|
|
|
}
|
|
|
|
|
2010-04-30 17:31:06 +04:00
|
|
|
/* *INDENT-OFF* */
|
2007-10-29 16:31:44 +03:00
|
|
|
#define FISH_OP(name, string) \
|
2004-08-17 02:15:28 +04:00
|
|
|
static int fish_##name (struct vfs_class *me, const char *path1, const char *path2) \
|
1998-09-13 14:40:43 +04:00
|
|
|
{ \
|
1999-01-21 01:01:11 +03:00
|
|
|
char buf[BUF_LARGE]; \
|
2005-09-05 04:52:56 +04:00
|
|
|
const char *crpath1, *crpath2; \
|
2009-02-06 02:09:35 +03:00
|
|
|
char *rpath1, *rpath2, *mpath1, *mpath2; \
|
2003-10-12 05:00:44 +04:00
|
|
|
struct vfs_s_super *super1, *super2; \
|
2010-03-30 22:59:41 +04:00
|
|
|
crpath1 = vfs_s_get_path_mangle (me, mpath1 = g_strdup(path1), &super1, 0); \
|
|
|
|
if (crpath1 == NULL) \
|
2010-03-30 12:10:25 +04:00
|
|
|
{ \
|
|
|
|
g_free (mpath1); \
|
|
|
|
return -1; \
|
2004-11-29 15:45:42 +03:00
|
|
|
} \
|
2010-03-30 22:59:41 +04:00
|
|
|
crpath2 = vfs_s_get_path_mangle (me, mpath2 = g_strdup(path2), &super2, 0); \
|
|
|
|
if (crpath2 == NULL) \
|
2010-03-30 12:10:25 +04:00
|
|
|
{ \
|
|
|
|
g_free (mpath1); \
|
|
|
|
g_free (mpath2); \
|
|
|
|
return -1; \
|
2004-11-29 15:45:42 +03:00
|
|
|
} \
|
2009-06-09 13:12:17 +04:00
|
|
|
rpath1 = strutils_shell_escape (crpath1); \
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (mpath1); \
|
2009-06-09 13:12:17 +04:00
|
|
|
rpath2 = strutils_shell_escape (crpath2); \
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (mpath2); \
|
2010-03-30 12:10:25 +04:00
|
|
|
g_snprintf (buf, sizeof(buf), string "\n", rpath1, rpath2, rpath1, rpath2); \
|
2009-02-06 02:34:50 +03:00
|
|
|
g_free (rpath1); \
|
|
|
|
g_free (rpath2); \
|
2003-10-28 03:57:02 +03:00
|
|
|
return fish_send_command(me, super2, buf, OPT_FLUSH); \
|
1998-09-13 14:40:43 +04:00
|
|
|
}
|
|
|
|
|
2010-03-30 12:10:25 +04:00
|
|
|
FISH_OP (rename,
|
|
|
|
"#RENAME /%s /%s\n"
|
|
|
|
"if mv /%s /%s 2>/dev/null; then\n"
|
|
|
|
"echo '### 000'\n"
|
|
|
|
"else\n"
|
|
|
|
"echo '### 500'\n"
|
|
|
|
"fi\n")
|
|
|
|
|
|
|
|
FISH_OP (link,
|
|
|
|
"#LINK /%s /%s\n"
|
|
|
|
"if ln /%s /%s 2>/dev/null; then\n"
|
|
|
|
"echo '### 000'\n"
|
|
|
|
"else\n"
|
|
|
|
"echo '### 500'\n"
|
|
|
|
"fi\n")
|
|
|
|
/* *INDENT-ON* */
|
|
|
|
|
|
|
|
static int
|
|
|
|
fish_symlink (struct vfs_class *me, const char *setto, const char *path)
|
1998-11-21 22:36:01 +03:00
|
|
|
{
|
2009-02-06 02:09:35 +03:00
|
|
|
char *qsetto;
|
2010-03-30 12:10:25 +04:00
|
|
|
PREFIX qsetto = strutils_shell_escape (setto);
|
|
|
|
/* *INDENT-OFF* */
|
|
|
|
g_snprintf (buf, sizeof (buf),
|
|
|
|
"#SYMLINK %s /%s\n"
|
|
|
|
"if ln -s %s /%s 2>/dev/null; then\n"
|
|
|
|
"echo '### 000'\n"
|
|
|
|
"else\n"
|
|
|
|
"echo '### 500'\n"
|
|
|
|
"fi\n",
|
|
|
|
qsetto, rpath, qsetto, rpath);
|
|
|
|
/* *INDENT-ON* */
|
2009-02-06 02:09:35 +03:00
|
|
|
g_free (qsetto);
|
2010-03-30 12:10:25 +04:00
|
|
|
POSTFIX (OPT_FLUSH);
|
1998-11-21 22:36:01 +03:00
|
|
|
}
|
1998-09-13 14:40:43 +04:00
|
|
|
|
1998-10-13 02:07:53 +04:00
|
|
|
static int
|
2004-08-17 01:36:39 +04:00
|
|
|
fish_chown (struct vfs_class *me, const char *path, int owner, int group)
|
1998-09-13 14:40:43 +04:00
|
|
|
{
|
|
|
|
char *sowner, *sgroup;
|
2001-07-09 20:15:33 +04:00
|
|
|
struct passwd *pw;
|
|
|
|
struct group *gr;
|
|
|
|
|
2010-03-30 22:59:41 +04:00
|
|
|
pw = getpwuid (owner);
|
|
|
|
if (pw == NULL)
|
2010-03-30 12:10:25 +04:00
|
|
|
return 0;
|
2001-07-09 20:15:33 +04:00
|
|
|
|
2010-03-30 22:59:41 +04:00
|
|
|
gr = getgrgid (group);
|
|
|
|
if (gr == NULL)
|
2010-03-30 12:10:25 +04:00
|
|
|
return 0;
|
2001-07-09 20:15:33 +04:00
|
|
|
|
|
|
|
sowner = pw->pw_name;
|
|
|
|
sgroup = gr->gr_name;
|
2004-11-29 15:45:42 +03:00
|
|
|
{
|
2010-03-30 12:10:25 +04:00
|
|
|
/* *INDENT-OFF* */
|
2010-04-30 17:31:06 +04:00
|
|
|
PREFIX
|
2010-03-30 12:10:25 +04:00
|
|
|
g_snprintf (buf, sizeof (buf),
|
|
|
|
"#CHOWN %s:%s /%s\n"
|
|
|
|
"if chown %s:%s /%s 2>/dev/null; then\n"
|
|
|
|
"echo '### 000'\n"
|
|
|
|
"else\n"
|
|
|
|
"echo '### 500'\n"
|
|
|
|
"fi\n",
|
|
|
|
sowner, sgroup, rpath, sowner, sgroup, rpath);
|
|
|
|
/* *INDENT-ON* */
|
|
|
|
fish_send_command (me, super, buf, OPT_FLUSH);
|
|
|
|
/* FIXME: what should we report if chgrp succeeds but chown fails? */
|
|
|
|
/* fish_send_command(me, super, buf, OPT_FLUSH); */
|
|
|
|
POSTFIX (OPT_FLUSH)}
|
1998-09-13 14:40:43 +04:00
|
|
|
}
|
|
|
|
|
2010-03-30 12:10:25 +04:00
|
|
|
static int
|
|
|
|
fish_unlink (struct vfs_class *me, const char *path)
|
1998-09-13 14:40:43 +04:00
|
|
|
{
|
2010-04-30 17:31:06 +04:00
|
|
|
/* *INDENT-OFF* */
|
1998-09-13 14:40:43 +04:00
|
|
|
PREFIX
|
2010-03-30 12:10:25 +04:00
|
|
|
|
|
|
|
g_snprintf (buf, sizeof (buf),
|
|
|
|
"#DELE /%s\n"
|
|
|
|
"if rm -f /%s 2>/dev/null; then\n"
|
|
|
|
"echo '### 000'\n"
|
|
|
|
"else\n"
|
|
|
|
"echo '### 500'\n"
|
|
|
|
"fi\n",
|
|
|
|
rpath, rpath);
|
|
|
|
/* *INDENT-ON* */
|
|
|
|
|
|
|
|
POSTFIX (OPT_FLUSH);
|
1998-09-13 14:40:43 +04:00
|
|
|
}
|
|
|
|
|
2010-03-30 12:10:25 +04:00
|
|
|
static int
|
|
|
|
fish_exists (struct vfs_class *me, const char *path)
|
2009-07-14 19:11:52 +04:00
|
|
|
{
|
2010-04-30 17:31:06 +04:00
|
|
|
/* *INDENT-OFF* */
|
2009-07-14 19:11:52 +04:00
|
|
|
PREFIX
|
|
|
|
|
2010-03-30 12:10:25 +04:00
|
|
|
g_snprintf (buf, sizeof (buf),
|
|
|
|
"#ISEXISTS /%s\n"
|
|
|
|
"ls -l /%s >/dev/null 2>/dev/null\n"
|
|
|
|
"echo '### '$?\n",
|
|
|
|
rpath, rpath);
|
|
|
|
/* *INDENT-ON* */
|
2009-07-14 19:11:52 +04:00
|
|
|
|
|
|
|
g_free (rpath);
|
|
|
|
|
2010-03-30 22:59:41 +04:00
|
|
|
return (fish_send_command (me, super, buf, OPT_FLUSH) == 0) ? 1 : 0;
|
2009-07-14 19:11:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-30 12:10:25 +04:00
|
|
|
static int
|
|
|
|
fish_mkdir (struct vfs_class *me, const char *path, mode_t mode)
|
1998-09-13 14:40:43 +04:00
|
|
|
{
|
2009-07-14 19:11:52 +04:00
|
|
|
int ret_code;
|
|
|
|
|
2010-04-30 17:31:06 +04:00
|
|
|
/* *INDENT-OFF* */
|
2010-03-30 12:10:25 +04:00
|
|
|
PREFIX (void) mode;
|
2005-02-22 21:38:58 +03:00
|
|
|
|
2010-03-30 12:10:25 +04:00
|
|
|
g_snprintf (buf, sizeof (buf),
|
|
|
|
"#MKD /%s\n"
|
|
|
|
"if mkdir /%s 2>/dev/null; then\n"
|
|
|
|
"echo '### 000'\n"
|
|
|
|
"else\n"
|
|
|
|
"echo '### 500'\n"
|
|
|
|
"fi\n",
|
|
|
|
rpath, rpath);
|
|
|
|
/* *INDENT-ON* */
|
2009-07-14 19:11:52 +04:00
|
|
|
|
|
|
|
g_free (rpath);
|
2010-03-30 12:10:25 +04:00
|
|
|
ret_code = fish_send_command (me, super, buf, OPT_FLUSH);
|
2009-07-14 19:11:52 +04:00
|
|
|
|
2010-03-30 12:10:25 +04:00
|
|
|
if (ret_code != 0)
|
|
|
|
return ret_code;
|
2009-07-14 19:11:52 +04:00
|
|
|
|
2010-03-30 12:10:25 +04:00
|
|
|
if (!fish_exists (me, path))
|
|
|
|
{
|
|
|
|
ERRNOR (EACCES, -1);
|
2009-07-14 19:11:52 +04:00
|
|
|
}
|
|
|
|
return 0;
|
1998-09-13 14:40:43 +04:00
|
|
|
}
|
|
|
|
|
2010-03-30 12:10:25 +04:00
|
|
|
static int
|
|
|
|
fish_rmdir (struct vfs_class *me, const char *path)
|
1998-09-13 14:40:43 +04:00
|
|
|
{
|
2010-03-30 12:10:25 +04:00
|
|
|
/* *INDENT-OFF* */
|
2010-04-30 17:31:06 +04:00
|
|
|
PREFIX
|
2010-03-30 12:10:25 +04:00
|
|
|
g_snprintf (buf, sizeof (buf),
|
|
|
|
"#RMD /%s\n"
|
|
|
|
"if rmdir /%s 2>/dev/null; then\n"
|
|
|
|
"echo '### 000'\n"
|
|
|
|
"else\n"
|
|
|
|
"echo '### 500'\n"
|
|
|
|
"fi\n",
|
|
|
|
rpath, rpath);
|
|
|
|
/* *INDENT-ON* */
|
|
|
|
POSTFIX (OPT_FLUSH);
|
1998-09-13 14:40:43 +04:00
|
|
|
}
|
|
|
|
|
2003-10-29 04:35:36 +03:00
|
|
|
static int
|
2010-03-30 12:10:25 +04:00
|
|
|
fish_fh_open (struct vfs_class *me, struct vfs_s_fh *fh, int flags, int mode)
|
1998-11-21 22:36:01 +03:00
|
|
|
{
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) mode;
|
|
|
|
|
2002-07-26 05:33:40 +04:00
|
|
|
fh->u.fish.append = 0;
|
2002-05-21 14:50:55 +04:00
|
|
|
/* File will be written only, so no need to retrieve it */
|
2010-03-30 12:10:25 +04:00
|
|
|
if (((flags & O_WRONLY) == O_WRONLY) && !(flags & (O_RDONLY | O_RDWR)))
|
|
|
|
{
|
|
|
|
fh->u.fish.append = flags & O_APPEND;
|
|
|
|
if (!fh->ino->localname)
|
|
|
|
{
|
|
|
|
int tmp_handle = vfs_mkstemps (&fh->ino->localname, me->name,
|
|
|
|
fh->ino->ent->name);
|
|
|
|
if (tmp_handle == -1)
|
|
|
|
return -1;
|
|
|
|
close (tmp_handle);
|
|
|
|
}
|
|
|
|
return 0;
|
2002-05-21 14:50:55 +04:00
|
|
|
}
|
1998-11-21 22:36:01 +03:00
|
|
|
if (!fh->ino->localname)
|
2010-03-30 12:10:25 +04:00
|
|
|
if (vfs_s_retrieve_file (me, fh->ino) == -1)
|
|
|
|
return -1;
|
1998-11-21 22:36:01 +03:00
|
|
|
if (!fh->ino->localname)
|
2010-03-30 12:10:25 +04:00
|
|
|
vfs_die ("retrieve_file failed to fill in localname");
|
1998-11-21 22:36:01 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-07-19 09:29:31 +04:00
|
|
|
static void
|
2004-08-16 20:34:11 +04:00
|
|
|
fish_fill_names (struct vfs_class *me, fill_names_f func)
|
2002-07-19 09:29:31 +04:00
|
|
|
{
|
2003-10-16 20:40:11 +04:00
|
|
|
struct vfs_s_super *super = MEDATA->supers;
|
2002-07-19 09:29:31 +04:00
|
|
|
char *name;
|
2009-01-26 17:56:55 +03:00
|
|
|
|
|
|
|
char gbuf[10];
|
|
|
|
|
|
|
|
while (super)
|
|
|
|
{
|
2010-03-30 12:10:25 +04:00
|
|
|
const char *flags = "";
|
|
|
|
switch (SUP.flags)
|
|
|
|
{
|
|
|
|
case FISH_FLAG_RSH:
|
|
|
|
flags = ":r";
|
|
|
|
break;
|
|
|
|
case FISH_FLAG_COMPRESSED:
|
|
|
|
flags = ":C";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (SUP.flags > FISH_FLAG_RSH)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
g_snprintf (gbuf, sizeof (gbuf), ":%d", SUP.flags);
|
|
|
|
flags = gbuf;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
name = g_strconcat ("/#sh:", SUP.user, "@", SUP.host, flags, "/", SUP.cwdir, (char *) NULL);
|
|
|
|
(*func) (name);
|
|
|
|
g_free (name);
|
|
|
|
super = super->next;
|
2002-07-19 09:29:31 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-09 16:42:10 +04:00
|
|
|
static void *
|
|
|
|
fish_open (struct vfs_class *me, const char *file, int flags, int mode)
|
|
|
|
{
|
|
|
|
/*
|
2010-03-30 12:10:25 +04:00
|
|
|
sorry, i've places hack here
|
|
|
|
cause fish don't able to open files with O_EXCL flag
|
|
|
|
*/
|
2009-07-09 16:42:10 +04:00
|
|
|
flags &= ~O_EXCL;
|
|
|
|
return vfs_s_open (me, file, flags, mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-11 03:38:03 +04:00
|
|
|
void
|
|
|
|
init_fish (void)
|
|
|
|
{
|
2003-10-16 20:40:11 +04:00
|
|
|
static struct vfs_s_subclass fish_subclass;
|
|
|
|
|
2010-03-30 12:10:25 +04:00
|
|
|
tcp_init ();
|
2009-11-14 19:02:28 +03:00
|
|
|
|
2003-10-28 10:09:39 +03:00
|
|
|
fish_subclass.flags = VFS_S_REMOTE;
|
2003-10-28 03:57:02 +03:00
|
|
|
fish_subclass.archive_same = fish_archive_same;
|
|
|
|
fish_subclass.open_archive = fish_open_archive;
|
|
|
|
fish_subclass.free_archive = fish_free_archive;
|
2003-10-16 20:40:11 +04:00
|
|
|
fish_subclass.fh_open = fish_fh_open;
|
2003-10-28 03:57:02 +03:00
|
|
|
fish_subclass.dir_load = fish_dir_load;
|
|
|
|
fish_subclass.file_store = fish_file_store;
|
|
|
|
fish_subclass.linear_start = fish_linear_start;
|
|
|
|
fish_subclass.linear_read = fish_linear_read;
|
|
|
|
fish_subclass.linear_close = fish_linear_close;
|
2003-10-16 20:40:11 +04:00
|
|
|
|
2003-10-28 10:09:39 +03:00
|
|
|
vfs_s_init_class (&vfs_fish_ops, &fish_subclass);
|
2003-10-11 03:38:03 +04:00
|
|
|
vfs_fish_ops.name = "fish";
|
|
|
|
vfs_fish_ops.prefix = "sh:";
|
|
|
|
vfs_fish_ops.fill_names = fish_fill_names;
|
|
|
|
vfs_fish_ops.chmod = fish_chmod;
|
|
|
|
vfs_fish_ops.chown = fish_chown;
|
2009-07-09 16:42:10 +04:00
|
|
|
vfs_fish_ops.open = fish_open;
|
2003-10-11 03:38:03 +04:00
|
|
|
vfs_fish_ops.symlink = fish_symlink;
|
|
|
|
vfs_fish_ops.link = fish_link;
|
|
|
|
vfs_fish_ops.unlink = fish_unlink;
|
|
|
|
vfs_fish_ops.rename = fish_rename;
|
|
|
|
vfs_fish_ops.mkdir = fish_mkdir;
|
|
|
|
vfs_fish_ops.rmdir = fish_rmdir;
|
|
|
|
vfs_fish_ops.ctl = fish_ctl;
|
|
|
|
vfs_register_class (&vfs_fish_ops);
|
|
|
|
}
|