1998-02-27 07:54:42 +03:00
|
|
|
/* Virtual File System: Midnight Commander file system.
|
|
|
|
|
|
|
|
Copyright (C) 1995, 1996, 1997 The Free Software Foundation
|
|
|
|
|
|
|
|
Written by Miguel de Icaza
|
|
|
|
Andrej Borsenkow
|
|
|
|
Norbert Warmuth
|
|
|
|
|
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.
|
1998-02-27 07:54:42 +03: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-02-27 07:54:42 +03: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
|
2000-08-23 02:50:00 +04:00
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1998-10-13 02:07:53 +04:00
|
|
|
/* Namespace: exports mcfs_vfs_ops, tcp_invalidate_socket */
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
#include <config.h>
|
2002-09-22 03:01:41 +04:00
|
|
|
|
|
|
|
#ifdef WITH_MCFS
|
1998-02-27 07:54:42 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <pwd.h>
|
1999-02-14 00:39:18 +03:00
|
|
|
#include <sys/types.h> /* POSIX-required by sys/socket.h and netdb.h */
|
1998-02-27 07:54:42 +03:00
|
|
|
#include <netdb.h> /* struct hostent */
|
|
|
|
#include <sys/socket.h> /* AF_INET */
|
|
|
|
#include <netinet/in.h> /* struct in_addr */
|
2002-09-06 05:02:25 +04:00
|
|
|
#ifdef HAVE_ARPA_INET_H
|
1998-02-27 07:54:42 +03:00
|
|
|
#include <arpa/inet.h>
|
2002-09-06 05:02:25 +04:00
|
|
|
#endif
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2002-10-01 08:09:31 +04:00
|
|
|
#ifdef HAVE_PMAP_SET
|
|
|
|
#include <rpc/rpc.h>
|
|
|
|
#include <rpc/pmap_prot.h>
|
|
|
|
#ifdef HAVE_RPC_PMAP_CLNT_H
|
|
|
|
#include <rpc/pmap_clnt.h>
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
1999-01-21 01:01:11 +03:00
|
|
|
#include "utilvfs.h"
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
#include "vfs.h"
|
|
|
|
#include "mcfs.h"
|
2002-10-05 05:02:07 +04:00
|
|
|
#include "mcfsutil.h"
|
1998-02-27 07:54:42 +03:00
|
|
|
#include "tcputil.h"
|
|
|
|
#include "../src/dialog.h"
|
|
|
|
|
|
|
|
#define MCFS_MAX_CONNECTIONS 32
|
|
|
|
|
1998-10-13 02:07:53 +04:00
|
|
|
static struct _mcfs_connection {
|
1998-02-27 07:54:42 +03:00
|
|
|
char *host;
|
|
|
|
char *user;
|
|
|
|
char *home;
|
2002-10-05 05:55:58 +04:00
|
|
|
int sock;
|
|
|
|
int port;
|
|
|
|
int version;
|
|
|
|
} mcfs_connections[MCFS_MAX_CONNECTIONS];
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2002-08-19 11:22:01 +04:00
|
|
|
|
|
|
|
#define mcserver_port 9876
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
typedef struct _mcfs_connection mcfs_connection;
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
typedef struct {
|
|
|
|
int handle;
|
|
|
|
mcfs_connection *conn;
|
|
|
|
} mcfs_handle;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1998-10-13 02:07:53 +04:00
|
|
|
static int my_errno;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static char *mcfs_gethome (mcfs_connection * mc);
|
1998-05-26 04:53:24 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
/* Extract the hostname and username from the path */
|
|
|
|
/* path is in the form: hostname:user/remote-dir */
|
2002-10-05 05:55:58 +04:00
|
|
|
static char *
|
|
|
|
mcfs_get_host_and_username (char *path, char **host, char **user,
|
|
|
|
int *port, char **pass)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2002-10-05 05:55:58 +04:00
|
|
|
return vfs_split_url (path, host, user, port, pass, 0, 0);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static void
|
|
|
|
mcfs_fill_names (vfs *me, void (*func) (char *))
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char *name;
|
2002-10-05 05:55:58 +04:00
|
|
|
|
|
|
|
for (i = 0; i < MCFS_MAX_CONNECTIONS; i++) {
|
|
|
|
if (mcfs_connections[i].host == 0)
|
1998-02-27 07:54:42 +03:00
|
|
|
continue;
|
2002-10-05 05:55:58 +04:00
|
|
|
name = g_strconcat ("/#mc:", mcfs_connections[i].user,
|
|
|
|
"@", mcfs_connections[i].host, NULL);
|
1998-02-27 07:54:42 +03:00
|
|
|
(*func) (name);
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (name);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This routine checks the server RPC version and logs the user in */
|
2002-10-05 05:55:58 +04:00
|
|
|
static int
|
|
|
|
mcfs_login_server (int my_socket, char *user, int port,
|
|
|
|
int port_autodetected, char *netrcpass, int *version)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
int result;
|
|
|
|
char *pass;
|
2002-10-05 05:55:58 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
/* Send the version number */
|
|
|
|
rpc_send (my_socket, RPC_INT, *version, RPC_END);
|
|
|
|
if (0 == rpc_get (my_socket, RPC_INT, &result, RPC_END))
|
|
|
|
return 0;
|
2002-10-05 05:55:58 +04:00
|
|
|
|
|
|
|
if (result != MC_VERSION_OK) {
|
|
|
|
message_1s (1, _(" MCFS "),
|
|
|
|
_(" The server does not support this version "));
|
1998-02-27 07:54:42 +03:00
|
|
|
close (my_socket);
|
|
|
|
return 0;
|
|
|
|
}
|
2002-10-05 05:55:58 +04:00
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
/* FIXME: figure out why last_current_dir used to be passed here */
|
|
|
|
rpc_send (my_socket, RPC_INT, MC_LOGIN, RPC_STRING, "/",
|
2002-10-05 05:55:58 +04:00
|
|
|
RPC_STRING, user, RPC_END);
|
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
if (0 == rpc_get (my_socket, RPC_INT, &result, RPC_END))
|
1998-02-27 07:54:42 +03:00
|
|
|
return 0;
|
2002-10-05 05:55:58 +04:00
|
|
|
|
|
|
|
if (result == MC_NEED_PASSWORD) {
|
|
|
|
if (port > 1024 && port_autodetected) {
|
1998-02-27 07:54:42 +03:00
|
|
|
int v;
|
2002-10-21 08:13:49 +04:00
|
|
|
v = query_dialog (_("Warning"),
|
2002-10-05 05:55:58 +04:00
|
|
|
_
|
|
|
|
(" The remote server is not running on a system port \n"
|
|
|
|
" you need a password to log in, but the information may \n"
|
|
|
|
" not be safe on the remote side. Continue? \n"),
|
2002-10-22 01:56:20 +04:00
|
|
|
3, 2, _("&Yes"), _("&No"));
|
1998-05-26 04:53:24 +04:00
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
if (v == 1) {
|
1998-02-27 07:54:42 +03:00
|
|
|
close (my_socket);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (netrcpass != NULL)
|
1999-01-21 01:01:11 +03:00
|
|
|
pass = g_strdup (netrcpass);
|
1998-02-27 07:54:42 +03:00
|
|
|
else
|
1998-05-26 04:53:24 +04:00
|
|
|
pass = vfs_get_password (_(" MCFS Password required "));
|
2002-10-05 05:55:58 +04:00
|
|
|
if (!pass) {
|
1998-02-27 07:54:42 +03:00
|
|
|
rpc_send (my_socket, RPC_INT, MC_QUIT, RPC_END);
|
|
|
|
close (my_socket);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
rpc_send (my_socket, RPC_INT, MC_PASS, RPC_STRING, pass, RPC_END);
|
|
|
|
|
|
|
|
wipe_password (pass);
|
|
|
|
|
|
|
|
if (0 == rpc_get (my_socket, RPC_INT, &result, RPC_END))
|
|
|
|
return 0;
|
2002-10-05 05:55:58 +04:00
|
|
|
|
|
|
|
if (result != MC_LOGINOK) {
|
1999-12-16 15:55:16 +03:00
|
|
|
message_1s (1, _(" MCFS "), _(" Invalid password "));
|
1998-02-27 07:54:42 +03:00
|
|
|
rpc_send (my_socket, RPC_INT, MC_QUIT, RPC_END);
|
|
|
|
close (my_socket);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return my_socket;
|
|
|
|
}
|
|
|
|
|
2002-10-01 08:09:31 +04:00
|
|
|
static int
|
|
|
|
get_remote_port (struct sockaddr_in *sin, int *version)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_PMAP_GETMAPS
|
|
|
|
int port;
|
|
|
|
struct pmaplist *pl;
|
|
|
|
|
|
|
|
*version = 1;
|
|
|
|
port = mcserver_port;
|
|
|
|
for (pl = pmap_getmaps (sin); pl; pl = pl->pml_next)
|
|
|
|
if (pl->pml_map.pm_prog == RPC_PROGNUM
|
|
|
|
&& pl->pml_map.pm_prot == IPPROTO_TCP
|
|
|
|
&& pl->pml_map.pm_vers >= *version) {
|
|
|
|
*version = pl->pml_map.pm_vers;
|
|
|
|
port = pl->pml_map.pm_port;
|
|
|
|
}
|
|
|
|
return port;
|
|
|
|
#else
|
|
|
|
#ifdef HAVE_PMAP_GETPORT
|
|
|
|
int port;
|
|
|
|
for (*version = RPC_PROGVER; *version >= 1; (*version)--)
|
|
|
|
if (port = pmap_getport (sin, RPC_PROGNUM, *version, IPPROTO_TCP))
|
|
|
|
return port;
|
|
|
|
#endif /* HAVE_PMAP_GETPORT */
|
|
|
|
#endif /* HAVE_PMAP_GETMAPS */
|
|
|
|
*version = 1;
|
|
|
|
return mcserver_port;
|
|
|
|
}
|
|
|
|
|
1998-10-13 02:07:53 +04:00
|
|
|
/* This used to be in utilvfs.c, but as it deals with portmapper, it
|
|
|
|
is probably usefull for mcfs */
|
2002-10-01 07:47:46 +04:00
|
|
|
static int
|
2002-10-05 05:55:58 +04:00
|
|
|
open_tcp_link (char *host, int *port, int *version, char *caller)
|
1998-10-13 02:07:53 +04:00
|
|
|
{
|
2002-10-05 05:55:58 +04:00
|
|
|
struct sockaddr_in server_address;
|
1998-10-13 02:07:53 +04:00
|
|
|
unsigned long inaddr;
|
2002-10-05 05:55:58 +04:00
|
|
|
struct hostent *hp;
|
|
|
|
int my_socket;
|
1998-10-13 02:07:53 +04:00
|
|
|
|
|
|
|
if (!*host)
|
|
|
|
return 0;
|
2002-10-05 05:55:58 +04:00
|
|
|
|
2002-07-15 09:31:43 +04:00
|
|
|
memset ((char *) &server_address, 0, sizeof (server_address));
|
1998-10-13 02:07:53 +04:00
|
|
|
server_address.sin_family = AF_INET;
|
2002-10-05 05:55:58 +04:00
|
|
|
|
1998-10-13 02:07:53 +04:00
|
|
|
/* Try to use the dotted decimal number */
|
|
|
|
if ((inaddr = inet_addr (host)) != -1)
|
2002-07-15 09:31:43 +04:00
|
|
|
memcpy ((char *) &server_address.sin_addr, (char *) &inaddr,
|
|
|
|
sizeof (inaddr));
|
1998-10-13 02:07:53 +04:00
|
|
|
else {
|
2002-10-05 05:55:58 +04:00
|
|
|
if ((hp = gethostbyname (host)) == NULL) {
|
|
|
|
message_2s (1, caller, _(" Cannot locate hostname: %s "),
|
|
|
|
host);
|
1998-10-13 02:07:53 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2002-07-15 09:31:43 +04:00
|
|
|
memcpy ((char *) &server_address.sin_addr, (char *) hp->h_addr,
|
|
|
|
hp->h_length);
|
1998-10-13 02:07:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Try to contact a remote portmapper to obtain the listening port */
|
2002-10-05 05:55:58 +04:00
|
|
|
if (*port == 0) {
|
1998-10-13 02:07:53 +04:00
|
|
|
*port = get_remote_port (&server_address, version);
|
|
|
|
if (*port < 1)
|
|
|
|
return 0;
|
|
|
|
} else
|
|
|
|
*version = 1;
|
2002-10-05 05:55:58 +04:00
|
|
|
|
1998-10-13 02:07:53 +04:00
|
|
|
server_address.sin_port = htons (*port);
|
2002-10-05 05:55:58 +04:00
|
|
|
|
|
|
|
if ((my_socket = socket (AF_INET, SOCK_STREAM, 0)) < 0) {
|
2001-08-14 04:55:34 +04:00
|
|
|
message_2s (1, caller, _(" Cannot create socket: %s "),
|
2002-10-05 05:55:58 +04:00
|
|
|
unix_error_string (errno));
|
1998-10-13 02:07:53 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (connect (my_socket, (struct sockaddr *) &server_address,
|
2002-10-05 05:55:58 +04:00
|
|
|
sizeof (server_address)) < 0) {
|
2001-08-14 04:55:34 +04:00
|
|
|
message_2s (1, caller, _(" Cannot connect to server: %s "),
|
2002-10-05 05:55:58 +04:00
|
|
|
unix_error_string (errno));
|
1998-10-13 02:07:53 +04:00
|
|
|
close (my_socket);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return my_socket;
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static int
|
|
|
|
mcfs_open_tcp_link (char *host, char *user,
|
|
|
|
int *port, char *netrcpass, int *version)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
int my_socket;
|
|
|
|
int old_port = *port;
|
2002-10-05 05:55:58 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
my_socket = open_tcp_link (host, port, version, " MCfs ");
|
|
|
|
if (my_socket <= 0)
|
|
|
|
return 0;
|
2002-10-05 05:55:58 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
/* We got the connection to the server, verify if the server
|
|
|
|
implements our version of the RPC mechanism and then login
|
|
|
|
the user.
|
2002-10-05 05:55:58 +04:00
|
|
|
*/
|
1998-02-27 07:54:42 +03:00
|
|
|
return mcfs_login_server (my_socket, user, *port, old_port == 0,
|
|
|
|
netrcpass, version);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mcfs_get_free_bucket_init = 1;
|
2002-10-05 05:55:58 +04:00
|
|
|
static mcfs_connection *
|
|
|
|
mcfs_get_free_bucket (void)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
int i;
|
2002-10-05 05:55:58 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
if (mcfs_get_free_bucket_init) {
|
2002-10-05 05:55:58 +04:00
|
|
|
mcfs_get_free_bucket_init = 0;
|
|
|
|
for (i = 0; i < MCFS_MAX_CONNECTIONS; i++)
|
|
|
|
mcfs_connections[i].host = 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
2002-10-05 05:55:58 +04:00
|
|
|
for (i = 0; i < MCFS_MAX_CONNECTIONS; i++) {
|
|
|
|
if (!mcfs_connections[i].host)
|
|
|
|
return &mcfs_connections[i];
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
/* This can't happend, since we have checked for max connections before */
|
2002-10-05 05:55:58 +04:00
|
|
|
vfs_die ("Internal error: mcfs_get_free_bucket");
|
|
|
|
return 0; /* shut up, stupid gcc */
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This routine keeps track of open connections */
|
|
|
|
/* Returns a connected socket to host */
|
2002-10-05 05:55:58 +04:00
|
|
|
static mcfs_connection *
|
|
|
|
mcfs_open_link (char *host, char *user, int *port, char *netrcpass)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2001-03-08 04:04:58 +03:00
|
|
|
static int mcfs_open_connections = 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
int i, sock, version;
|
|
|
|
mcfs_connection *bucket;
|
|
|
|
|
|
|
|
/* Is the link actually open? */
|
|
|
|
if (mcfs_get_free_bucket_init) {
|
2002-10-05 05:55:58 +04:00
|
|
|
mcfs_get_free_bucket_init = 0;
|
|
|
|
for (i = 0; i < MCFS_MAX_CONNECTIONS; i++)
|
|
|
|
mcfs_connections[i].host = 0;
|
|
|
|
} else
|
|
|
|
for (i = 0; i < MCFS_MAX_CONNECTIONS; i++) {
|
|
|
|
if (!mcfs_connections[i].host)
|
|
|
|
continue;
|
|
|
|
if ((strcmp (host, mcfs_connections[i].host) == 0) &&
|
|
|
|
(strcmp (user, mcfs_connections[i].user) == 0))
|
|
|
|
return &mcfs_connections[i];
|
|
|
|
}
|
|
|
|
if (mcfs_open_connections == MCFS_MAX_CONNECTIONS) {
|
1998-05-26 04:53:24 +04:00
|
|
|
message_1s (1, MSG_ERROR, _(" Too many open connections "));
|
1998-02-27 07:54:42 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
if (!
|
|
|
|
(sock =
|
|
|
|
mcfs_open_tcp_link (host, user, port, netrcpass, &version)))
|
1998-02-27 07:54:42 +03:00
|
|
|
return 0;
|
2002-10-05 05:55:58 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
bucket = mcfs_get_free_bucket ();
|
|
|
|
mcfs_open_connections++;
|
2002-10-05 05:55:58 +04:00
|
|
|
bucket->host = g_strdup (host);
|
|
|
|
bucket->user = g_strdup (user);
|
|
|
|
bucket->home = 0;
|
|
|
|
bucket->port = *port;
|
|
|
|
bucket->sock = sock;
|
1998-02-27 07:54:42 +03:00
|
|
|
bucket->version = version;
|
|
|
|
|
|
|
|
return bucket;
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static int
|
|
|
|
is_error (int result, int errno_num)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
if (!(result == -1))
|
1998-10-13 02:07:53 +04:00
|
|
|
return my_errno = 0;
|
2002-10-05 05:55:58 +04:00
|
|
|
else
|
1998-10-13 02:07:53 +04:00
|
|
|
my_errno = errno_num;
|
1998-02-27 07:54:42 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static int
|
|
|
|
the_error (int result, int errno_num)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
if (result == -1)
|
1998-10-13 02:07:53 +04:00
|
|
|
my_errno = errno_num;
|
1998-02-27 07:54:42 +03:00
|
|
|
else
|
1998-10-13 02:07:53 +04:00
|
|
|
my_errno = 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static char *
|
|
|
|
mcfs_get_path (mcfs_connection **mc, char *path)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
char *user, *host, *remote_path;
|
|
|
|
char *pass;
|
2002-10-05 05:55:58 +04:00
|
|
|
int port;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
/* An absolute path name, try to determine connection socket */
|
1998-10-23 12:26:25 +04:00
|
|
|
if (strncmp (path, "/#mc:", 5))
|
2002-10-05 05:55:58 +04:00
|
|
|
return NULL;
|
1998-05-26 04:53:24 +04:00
|
|
|
path += 5;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
/* Port = 0 means that open_tcp_link will try to contact the
|
|
|
|
* remote portmapper to get the port number
|
|
|
|
*/
|
|
|
|
port = 0;
|
2002-10-05 05:55:58 +04:00
|
|
|
if ((remote_path =
|
|
|
|
mcfs_get_host_and_username (path, &host, &user, &port, &pass)))
|
|
|
|
if (!(*mc = mcfs_open_link (host, user, &port, pass))) {
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (remote_path);
|
1998-05-26 04:53:24 +04:00
|
|
|
remote_path = NULL;
|
|
|
|
}
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (host);
|
|
|
|
g_free (user);
|
1998-05-26 04:53:24 +04:00
|
|
|
if (pass)
|
2002-10-05 05:55:58 +04:00
|
|
|
wipe_password (pass);
|
1998-05-26 04:53:24 +04:00
|
|
|
|
|
|
|
if (!remote_path)
|
2002-10-05 05:55:58 +04:00
|
|
|
return NULL;
|
1998-05-26 04:53:24 +04:00
|
|
|
|
|
|
|
/* NOTE: tildes are deprecated. See ftpfs.c */
|
|
|
|
{
|
2002-10-05 05:55:58 +04:00
|
|
|
int f = !strcmp (remote_path, "/~");
|
|
|
|
if (f || !strncmp (remote_path, "/~/", 3)) {
|
1998-05-26 04:53:24 +04:00
|
|
|
char *s;
|
2002-10-05 05:55:58 +04:00
|
|
|
s = concat_dir_and_file (mcfs_gethome (*mc),
|
|
|
|
remote_path + 3 - f);
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (remote_path);
|
1998-05-26 04:53:24 +04:00
|
|
|
remote_path = s;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
}
|
1998-05-26 04:53:24 +04:00
|
|
|
return remote_path;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Simple function for routines returning only an integer from the server */
|
2002-10-05 05:55:58 +04:00
|
|
|
static int
|
|
|
|
mcfs_handle_simple_error (int sock, int return_status)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
int status, error;
|
2002-10-05 05:55:58 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
if (0 == rpc_get (sock, RPC_INT, &status, RPC_INT, &error, RPC_END))
|
|
|
|
return the_error (-1, EIO);
|
|
|
|
|
|
|
|
if (is_error (status, error))
|
|
|
|
return -1;
|
|
|
|
if (return_status)
|
|
|
|
return status;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Nice wrappers */
|
2002-10-05 05:55:58 +04:00
|
|
|
static int
|
|
|
|
mcfs_rpc_two_paths (int command, char *s1, char *s2)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
mcfs_connection *mc;
|
|
|
|
char *r1, *r2;
|
|
|
|
|
|
|
|
if ((r1 = mcfs_get_path (&mc, s1)) == 0)
|
|
|
|
return -1;
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
if ((r2 = mcfs_get_path (&mc, s2)) == 0) {
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (r1);
|
1998-02-27 07:54:42 +03:00
|
|
|
return -1;
|
|
|
|
}
|
2002-10-05 05:55:58 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
rpc_send (mc->sock,
|
2002-10-05 05:55:58 +04:00
|
|
|
RPC_INT, command, RPC_STRING, r1, RPC_STRING, r2, RPC_END);
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (r1);
|
|
|
|
g_free (r2);
|
1998-02-27 07:54:42 +03:00
|
|
|
return mcfs_handle_simple_error (mc->sock, 0);
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static int
|
|
|
|
mcfs_rpc_path (int command, char *path)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
mcfs_connection *mc;
|
|
|
|
char *remote_file;
|
|
|
|
|
|
|
|
if ((remote_file = mcfs_get_path (&mc, path)) == 0)
|
|
|
|
return -1;
|
2002-10-05 05:55:58 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
rpc_send (mc->sock,
|
2002-10-05 05:55:58 +04:00
|
|
|
RPC_INT, command, RPC_STRING, remote_file, RPC_END);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (remote_file);
|
1998-02-27 07:54:42 +03:00
|
|
|
return mcfs_handle_simple_error (mc->sock, 0);
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static int
|
|
|
|
mcfs_rpc_path_int (int command, char *path, int data)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
mcfs_connection *mc;
|
|
|
|
char *remote_file;
|
|
|
|
|
|
|
|
if ((remote_file = mcfs_get_path (&mc, path)) == 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
rpc_send (mc->sock,
|
2002-10-05 05:55:58 +04:00
|
|
|
RPC_INT, command,
|
|
|
|
RPC_STRING, remote_file, RPC_INT, data, RPC_END);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (remote_file);
|
1998-02-27 07:54:42 +03:00
|
|
|
return mcfs_handle_simple_error (mc->sock, 0);
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static int
|
|
|
|
mcfs_rpc_path_int_int (int command, char *path, int n1, int n2)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
mcfs_connection *mc;
|
|
|
|
char *remote_file;
|
|
|
|
|
|
|
|
if ((remote_file = mcfs_get_path (&mc, path)) == 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
rpc_send (mc->sock,
|
|
|
|
RPC_INT, command,
|
2002-10-05 05:55:58 +04:00
|
|
|
RPC_STRING, remote_file, RPC_INT, n1, RPC_INT, n2, RPC_END);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (remote_file);
|
1998-02-27 07:54:42 +03:00
|
|
|
return mcfs_handle_simple_error (mc->sock, 0);
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static char *
|
|
|
|
mcfs_gethome (mcfs_connection *mc)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
char *buffer;
|
|
|
|
|
|
|
|
if (mc->home)
|
1999-01-21 01:01:11 +03:00
|
|
|
return g_strdup (mc->home);
|
1998-02-27 07:54:42 +03:00
|
|
|
else {
|
|
|
|
rpc_send (mc->sock, RPC_INT, MC_GETHOME, RPC_END);
|
|
|
|
if (0 == rpc_get (mc->sock, RPC_STRING, &buffer, RPC_END))
|
1999-01-21 01:01:11 +03:00
|
|
|
return g_strdup (PATH_SEP_STR);
|
1998-02-27 07:54:42 +03:00
|
|
|
mc->home = buffer;
|
1999-01-21 01:01:11 +03:00
|
|
|
return g_strdup (buffer);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The callbacks */
|
2002-10-05 05:55:58 +04:00
|
|
|
static void *
|
|
|
|
mcfs_open (vfs *me, char *file, int flags, int mode)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
char *remote_file;
|
|
|
|
mcfs_connection *mc;
|
2002-10-05 05:55:58 +04:00
|
|
|
int result, error_num;
|
|
|
|
mcfs_handle *remote_handle;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
if (!(remote_file = mcfs_get_path (&mc, file)))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
rpc_send (mc->sock, RPC_INT, MC_OPEN, RPC_STRING, remote_file,
|
|
|
|
RPC_INT, flags, RPC_INT, mode, RPC_END);
|
2002-10-05 05:55:58 +04:00
|
|
|
g_free (remote_file);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
if (0 ==
|
|
|
|
rpc_get (mc->sock, RPC_INT, &result, RPC_INT, &error_num, RPC_END))
|
1998-02-27 07:54:42 +03:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (is_error (result, error_num))
|
|
|
|
return 0;
|
|
|
|
|
1999-01-21 01:01:11 +03:00
|
|
|
remote_handle = g_new (mcfs_handle, 2);
|
2002-10-05 05:55:58 +04:00
|
|
|
remote_handle->handle = result;
|
|
|
|
remote_handle->conn = mc;
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
return remote_handle;
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static int
|
|
|
|
mcfs_read (void *data, char *buffer, int count)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
mcfs_handle *info = (mcfs_handle *) data;
|
|
|
|
int result, error;
|
|
|
|
int handle;
|
|
|
|
mcfs_connection *mc;
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
mc = info->conn;
|
|
|
|
handle = info->handle;
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
rpc_send (mc->sock, RPC_INT, MC_READ, RPC_INT, handle,
|
|
|
|
RPC_INT, count, RPC_END);
|
2002-10-05 05:55:58 +04:00
|
|
|
|
|
|
|
if (0 ==
|
|
|
|
rpc_get (mc->sock, RPC_INT, &result, RPC_INT, &error, RPC_END))
|
1998-02-27 07:54:42 +03:00
|
|
|
return the_error (-1, EIO);
|
2002-10-05 05:55:58 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
if (is_error (result, error))
|
|
|
|
return 0;
|
2002-10-05 05:55:58 +04:00
|
|
|
|
|
|
|
if (0 == rpc_get (mc->sock, RPC_BLOCK, result, buffer, RPC_END))
|
1998-02-27 07:54:42 +03:00
|
|
|
return the_error (-1, EIO);
|
2002-10-05 05:55:58 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static int
|
|
|
|
mcfs_write (void *data, char *buf, int nbyte)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
mcfs_handle *info = (mcfs_handle *) data;
|
|
|
|
mcfs_connection *mc;
|
|
|
|
int handle;
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
mc = info->conn;
|
1998-02-27 07:54:42 +03:00
|
|
|
handle = info->handle;
|
2002-10-05 05:55:58 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
rpc_send (mc->sock,
|
|
|
|
RPC_INT, MC_WRITE,
|
|
|
|
RPC_INT, handle,
|
2002-10-05 05:55:58 +04:00
|
|
|
RPC_INT, nbyte, RPC_BLOCK, nbyte, buf, RPC_END);
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
return mcfs_handle_simple_error (mc->sock, 1);
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static int
|
|
|
|
mcfs_close (void *data)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
mcfs_handle *info = (mcfs_handle *) data;
|
|
|
|
mcfs_connection *mc;
|
|
|
|
int handle, result, error;
|
|
|
|
|
|
|
|
if (!data)
|
|
|
|
return -1;
|
2002-10-05 05:55:58 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
handle = info->handle;
|
2002-10-05 05:55:58 +04:00
|
|
|
mc = info->conn;
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
rpc_send (mc->sock, RPC_INT, MC_CLOSE, RPC_INT, handle, RPC_END);
|
2002-10-05 05:55:58 +04:00
|
|
|
|
|
|
|
if (0 ==
|
|
|
|
rpc_get (mc->sock, RPC_INT, &result, RPC_INT, &error, RPC_END))
|
1998-02-27 07:54:42 +03:00
|
|
|
return the_error (-1, EIO);
|
2002-10-05 05:55:58 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
is_error (result, error);
|
|
|
|
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (data);
|
1998-02-27 07:54:42 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static int
|
|
|
|
mcfs_errno (vfs *me)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
1998-10-13 02:07:53 +04:00
|
|
|
return my_errno;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct dir_entry {
|
|
|
|
char *text;
|
|
|
|
struct dir_entry *next;
|
|
|
|
struct stat my_stat;
|
2002-10-05 05:55:58 +04:00
|
|
|
int merrno;
|
1998-02-27 07:54:42 +03:00
|
|
|
} dir_entry;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
mcfs_connection *conn;
|
|
|
|
int handle;
|
|
|
|
dir_entry *entries;
|
|
|
|
dir_entry *current;
|
|
|
|
} opendir_info;
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static void *
|
|
|
|
mcfs_opendir (vfs *me, char *dirname)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
opendir_info *mcfs_info;
|
|
|
|
mcfs_connection *mc;
|
|
|
|
int handle, error_num;
|
|
|
|
char *remote_dir;
|
2002-10-05 05:55:58 +04:00
|
|
|
int result;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
if (!(remote_dir = mcfs_get_path (&mc, dirname)))
|
|
|
|
return 0;
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
rpc_send (mc->sock, RPC_INT, MC_OPENDIR, RPC_STRING, remote_dir,
|
|
|
|
RPC_END);
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (remote_dir);
|
2002-10-05 05:55:58 +04:00
|
|
|
|
|
|
|
if (0 ==
|
|
|
|
rpc_get (mc->sock, RPC_INT, &result, RPC_INT, &error_num, RPC_END))
|
1998-02-27 07:54:42 +03:00
|
|
|
return 0;
|
2002-10-05 05:55:58 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
if (is_error (result, error_num))
|
|
|
|
return 0;
|
2002-10-05 05:55:58 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
handle = result;
|
|
|
|
|
1999-01-21 01:01:11 +03:00
|
|
|
mcfs_info = g_new (opendir_info, 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
mcfs_info->conn = mc;
|
|
|
|
mcfs_info->handle = handle;
|
|
|
|
mcfs_info->entries = 0;
|
|
|
|
mcfs_info->current = 0;
|
2002-10-05 05:55:58 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
return mcfs_info;
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static int get_stat_info (mcfs_connection * mc, struct stat *buf);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static int
|
|
|
|
mcfs_loaddir (opendir_info *mcfs_info)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2002-10-05 05:55:58 +04:00
|
|
|
int status, error;
|
|
|
|
mcfs_connection *mc = mcfs_info->conn;
|
|
|
|
int link = mc->sock;
|
|
|
|
int first = 1;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
rpc_send (link, RPC_INT, MC_READDIR, RPC_INT, mcfs_info->handle,
|
|
|
|
RPC_END);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
for (;;) {
|
|
|
|
int entry_len;
|
1998-02-27 07:54:42 +03:00
|
|
|
dir_entry *new_entry;
|
|
|
|
|
|
|
|
if (!rpc_get (link, RPC_INT, &entry_len, RPC_END))
|
|
|
|
return 0;
|
2002-10-05 05:55:58 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
if (entry_len == 0)
|
|
|
|
break;
|
|
|
|
|
1999-01-21 01:01:11 +03:00
|
|
|
new_entry = g_new (dir_entry, 1);
|
|
|
|
new_entry->text = g_new0 (char, entry_len + 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
new_entry->next = 0;
|
2002-10-05 05:55:58 +04:00
|
|
|
if (first) {
|
1998-02-27 07:54:42 +03:00
|
|
|
mcfs_info->entries = new_entry;
|
|
|
|
mcfs_info->current = new_entry;
|
|
|
|
first = 0;
|
|
|
|
} else {
|
|
|
|
mcfs_info->current->next = new_entry;
|
|
|
|
mcfs_info->current = new_entry;
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
if (!rpc_get
|
|
|
|
(link, RPC_BLOCK, entry_len, new_entry->text, RPC_END))
|
1998-02-27 07:54:42 +03:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Then we get the status from the lstat */
|
|
|
|
if (!rpc_get (link, RPC_INT, &status, RPC_INT, &error, RPC_END))
|
|
|
|
return 0;
|
2002-10-05 05:55:58 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
if (is_error (status, error))
|
|
|
|
new_entry->merrno = error;
|
|
|
|
else {
|
|
|
|
new_entry->merrno = 0;
|
|
|
|
if (!get_stat_info (mc, &(new_entry->my_stat)))
|
|
|
|
return 0;
|
|
|
|
}
|
2002-10-05 05:55:58 +04:00
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
mcfs_info->current = mcfs_info->entries;
|
2002-10-05 05:55:58 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static void
|
|
|
|
mcfs_free_dir (dir_entry *de)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
if (!de)
|
|
|
|
return;
|
|
|
|
mcfs_free_dir (de->next);
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (de->text);
|
|
|
|
g_free (de);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
2002-08-16 01:15:17 +04:00
|
|
|
static union vfs_dirent mcfs_readdir_data;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
/* The readdir routine loads the complete directory */
|
|
|
|
/* It's too slow to ask the server each time */
|
|
|
|
/* It now also sends the complete lstat information for each file */
|
|
|
|
static struct stat *cached_lstat_info;
|
2002-08-16 01:15:17 +04:00
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static void *
|
|
|
|
mcfs_readdir (void *info)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2002-08-16 01:15:17 +04:00
|
|
|
opendir_info *mcfs_info;
|
1998-02-27 07:54:42 +03:00
|
|
|
char *dirent_dest;
|
|
|
|
|
|
|
|
mcfs_info = (opendir_info *) info;
|
|
|
|
|
|
|
|
if (!mcfs_info->entries)
|
2002-10-05 05:55:58 +04:00
|
|
|
if (!mcfs_loaddir (mcfs_info))
|
1998-02-27 07:54:42 +03:00
|
|
|
return NULL;
|
|
|
|
|
2002-08-16 01:15:17 +04:00
|
|
|
if (mcfs_info->current == 0) {
|
1998-02-27 07:54:42 +03:00
|
|
|
cached_lstat_info = 0;
|
2002-10-05 05:55:58 +04:00
|
|
|
mcfs_free_dir (mcfs_info->entries);
|
1998-02-27 07:54:42 +03:00
|
|
|
mcfs_info->entries = 0;
|
|
|
|
return NULL;
|
|
|
|
}
|
2002-08-16 01:15:17 +04:00
|
|
|
dirent_dest = mcfs_readdir_data.dent.d_name;
|
2002-10-05 05:55:58 +04:00
|
|
|
strncpy (dirent_dest, mcfs_info->current->text, MC_MAXPATHLEN);
|
2002-08-16 01:15:17 +04:00
|
|
|
dirent_dest[MC_MAXPATHLEN] = 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
cached_lstat_info = &mcfs_info->current->my_stat;
|
|
|
|
mcfs_info->current = mcfs_info->current->next;
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
compute_namelen (&mcfs_readdir_data.dent);
|
2002-08-16 01:15:17 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
return &mcfs_readdir_data;
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static int
|
|
|
|
mcfs_closedir (void *info)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
opendir_info *mcfs_info = (opendir_info *) info;
|
|
|
|
dir_entry *p, *q;
|
|
|
|
|
|
|
|
rpc_send (mcfs_info->conn->sock, RPC_INT, MC_CLOSEDIR,
|
|
|
|
RPC_INT, mcfs_info->handle, RPC_END);
|
2002-10-05 05:55:58 +04:00
|
|
|
|
|
|
|
for (p = mcfs_info->entries; p;) {
|
1998-02-27 07:54:42 +03:00
|
|
|
q = p;
|
|
|
|
p = p->next;
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (q->text);
|
|
|
|
g_free (q);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (info);
|
1998-02-27 07:54:42 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static time_t
|
|
|
|
mcfs_get_time (mcfs_connection *mc)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2002-10-05 05:55:58 +04:00
|
|
|
int sock = mc->sock;
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
if (mc->version == 1) {
|
|
|
|
struct tm tt;
|
|
|
|
|
|
|
|
rpc_get (sock,
|
|
|
|
RPC_INT, &tt.tm_sec,
|
|
|
|
RPC_INT, &tt.tm_min,
|
|
|
|
RPC_INT, &tt.tm_hour,
|
|
|
|
RPC_INT, &tt.tm_mday,
|
2002-10-05 05:55:58 +04:00
|
|
|
RPC_INT, &tt.tm_year, RPC_INT, &tt.tm_mon, RPC_END);
|
1998-02-27 07:54:42 +03:00
|
|
|
tt.tm_year -= 1900;
|
|
|
|
tt.tm_isdst = 0;
|
|
|
|
|
|
|
|
return mktime (&tt);
|
|
|
|
} else {
|
2002-10-05 05:55:58 +04:00
|
|
|
char *buf;
|
|
|
|
long tm;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
rpc_get (sock, RPC_STRING, &buf, RPC_END);
|
1998-02-27 07:54:42 +03:00
|
|
|
sscanf (buf, "%lx", &tm);
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (buf);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
return (time_t) tm;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static int
|
|
|
|
get_stat_info (mcfs_connection *mc, struct stat *buf)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
long mylong;
|
2002-10-05 05:55:58 +04:00
|
|
|
int sock = mc->sock;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1999-02-16 13:16:59 +03:00
|
|
|
buf->st_dev = 0;
|
2002-10-05 05:55:58 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
rpc_get (sock, RPC_INT, &mylong, RPC_END);
|
1999-02-16 13:16:59 +03:00
|
|
|
#ifdef HAVE_ST_RDEV
|
|
|
|
buf->st_rdev = mylong;
|
|
|
|
#endif
|
1998-02-27 07:54:42 +03:00
|
|
|
rpc_get (sock, RPC_INT, &mylong, RPC_END);
|
|
|
|
buf->st_ino = mylong;
|
|
|
|
rpc_get (sock, RPC_INT, &mylong, RPC_END);
|
|
|
|
buf->st_mode = mylong;
|
|
|
|
rpc_get (sock, RPC_INT, &mylong, RPC_END);
|
|
|
|
buf->st_nlink = mylong;
|
|
|
|
rpc_get (sock, RPC_INT, &mylong, RPC_END);
|
|
|
|
buf->st_uid = mylong;
|
|
|
|
rpc_get (sock, RPC_INT, &mylong, RPC_END);
|
|
|
|
buf->st_gid = mylong;
|
|
|
|
rpc_get (sock, RPC_INT, &mylong, RPC_END);
|
|
|
|
buf->st_size = mylong;
|
2002-10-05 05:55:58 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
if (!rpc_get (sock, RPC_INT, &mylong, RPC_END))
|
|
|
|
return 0;
|
|
|
|
#ifdef HAVE_ST_BLOCKS
|
|
|
|
buf->st_blocks = mylong;
|
|
|
|
#endif
|
|
|
|
buf->st_atime = mcfs_get_time (mc);
|
|
|
|
buf->st_mtime = mcfs_get_time (mc);
|
|
|
|
buf->st_ctime = mcfs_get_time (mc);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static int
|
|
|
|
mcfs_stat_cmd (int cmd, char *path, struct stat *buf)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
char *remote_file;
|
|
|
|
mcfs_connection *mc;
|
2002-10-05 05:55:58 +04:00
|
|
|
int status, error;
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
if ((remote_file = mcfs_get_path (&mc, path)) == 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
rpc_send (mc->sock, RPC_INT, cmd, RPC_STRING, remote_file, RPC_END);
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (remote_file);
|
1998-02-27 07:54:42 +03:00
|
|
|
if (!rpc_get (mc->sock, RPC_INT, &status, RPC_INT, &error, RPC_END))
|
|
|
|
return the_error (-1, errno);
|
|
|
|
|
|
|
|
if (is_error (status, error))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (get_stat_info (mc, buf))
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return the_error (-1, EIO);
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static int
|
|
|
|
mcfs_stat (vfs *me, char *path, struct stat *buf)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
return mcfs_stat_cmd (MC_STAT, path, buf);
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static int
|
|
|
|
mcfs_lstat (vfs *me, char *path, struct stat *buf)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
int path_len = strlen (path);
|
|
|
|
int entry_len = strlen (mcfs_readdir_data.dent.d_name);
|
|
|
|
|
|
|
|
/* Hack ... */
|
|
|
|
if (strcmp (path + path_len - entry_len,
|
2002-10-05 05:55:58 +04:00
|
|
|
mcfs_readdir_data.dent.d_name) == 0 && cached_lstat_info) {
|
1998-02-27 07:54:42 +03:00
|
|
|
*buf = *cached_lstat_info;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return mcfs_stat_cmd (MC_LSTAT, path, buf);
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static int
|
|
|
|
mcfs_fstat (void *data, struct stat *buf)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
mcfs_handle *info = (mcfs_handle *) data;
|
|
|
|
int result, error;
|
|
|
|
int handle, sock;
|
2002-10-05 05:55:58 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
sock = info->conn->sock;
|
|
|
|
handle = info->handle;
|
2002-10-05 05:55:58 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
rpc_send (sock, RPC_INT, MC_FSTAT, RPC_INT, handle, RPC_END);
|
|
|
|
if (!rpc_get (sock, RPC_INT, &result, RPC_INT, &error, RPC_END))
|
|
|
|
return the_error (-1, EIO);
|
|
|
|
|
|
|
|
if (is_error (result, error))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (get_stat_info (info->conn, buf))
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return the_error (-1, EIO);
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static int
|
|
|
|
mcfs_chmod (vfs *me, char *path, int mode)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
return mcfs_rpc_path_int (MC_CHMOD, path, mode);
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static int
|
|
|
|
mcfs_chown (vfs *me, char *path, int owner, int group)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
return mcfs_rpc_path_int_int (MC_CHOWN, path, owner, group);
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static int
|
|
|
|
mcfs_utime (vfs *me, char *path, struct utimbuf *times)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2002-10-05 05:55:58 +04:00
|
|
|
mcfs_connection *mc;
|
1998-02-27 07:54:42 +03:00
|
|
|
int status;
|
|
|
|
char *file;
|
|
|
|
|
|
|
|
if (!(file = mcfs_get_path (&mc, path)))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
status = 0;
|
|
|
|
if (mc->version >= 2) {
|
2002-10-05 05:55:58 +04:00
|
|
|
char abuf[BUF_SMALL];
|
|
|
|
char mbuf[BUF_SMALL];
|
|
|
|
long atime, mtime;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
atime = (long) times->actime;
|
|
|
|
mtime = (long) times->modtime;
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
g_snprintf (abuf, sizeof (abuf), "%lx", atime);
|
|
|
|
g_snprintf (mbuf, sizeof (mbuf), "%lx", mtime);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
rpc_send (mc->sock, RPC_INT, MC_UTIME,
|
2002-10-05 05:55:58 +04:00
|
|
|
RPC_STRING, file,
|
|
|
|
RPC_STRING, abuf, RPC_STRING, mbuf, RPC_END);
|
1998-02-27 07:54:42 +03:00
|
|
|
status = mcfs_handle_simple_error (mc->sock, 0);
|
2002-10-05 05:55:58 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (file);
|
1998-02-27 07:54:42 +03:00
|
|
|
return (status);
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static int
|
|
|
|
mcfs_readlink (vfs *me, char *path, char *buf, int size)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
char *remote_file, *stat_str;
|
2002-10-05 05:55:58 +04:00
|
|
|
int status, error;
|
1998-02-27 07:54:42 +03:00
|
|
|
mcfs_connection *mc;
|
|
|
|
|
|
|
|
if (!(remote_file = mcfs_get_path (&mc, path)))
|
|
|
|
return -1;
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
rpc_send (mc->sock, RPC_INT, MC_READLINK, RPC_STRING, remote_file,
|
|
|
|
RPC_END);
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (remote_file);
|
1998-02-27 07:54:42 +03:00
|
|
|
if (!rpc_get (mc->sock, RPC_INT, &status, RPC_INT, &error, RPC_END))
|
|
|
|
return the_error (-1, EIO);
|
|
|
|
|
|
|
|
if (is_error (status, errno))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (!rpc_get (mc->sock, RPC_STRING, &stat_str, RPC_END))
|
|
|
|
return the_error (-1, EIO);
|
2002-10-05 05:55:58 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
strncpy (buf, stat_str, size);
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (stat_str);
|
1998-02-27 07:54:42 +03:00
|
|
|
return strlen (buf);
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static int
|
|
|
|
mcfs_unlink (vfs *me, char *path)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
return mcfs_rpc_path (MC_UNLINK, path);
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static int
|
|
|
|
mcfs_symlink (vfs *me, char *n1, char *n2)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
return mcfs_rpc_two_paths (MC_SYMLINK, n1, n2);
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static int
|
|
|
|
mcfs_rename (vfs *me, char *a, char *b)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
return mcfs_rpc_two_paths (MC_RENAME, a, b);
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static int
|
|
|
|
mcfs_chdir (vfs *me, char *path)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
char *remote_dir;
|
|
|
|
mcfs_connection *mc;
|
2002-10-05 05:55:58 +04:00
|
|
|
int status, error;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
if (!(remote_dir = mcfs_get_path (&mc, path)))
|
|
|
|
return -1;
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
rpc_send (mc->sock, RPC_INT, MC_CHDIR, RPC_STRING, remote_dir,
|
|
|
|
RPC_END);
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (remote_dir);
|
1998-02-27 07:54:42 +03:00
|
|
|
if (!rpc_get (mc->sock, RPC_INT, &status, RPC_INT, &error, RPC_END))
|
|
|
|
return the_error (-1, EIO);
|
2002-10-05 05:55:58 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
if (is_error (status, error))
|
|
|
|
return -1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static int
|
|
|
|
mcfs_lseek (void *data, off_t offset, int whence)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
mcfs_handle *info = (mcfs_handle *) data;
|
|
|
|
int handle, sock;
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
sock = info->conn->sock;
|
1998-02-27 07:54:42 +03:00
|
|
|
handle = info->handle;
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
/* FIXME: off_t may be too long to fit */
|
|
|
|
rpc_send (sock, RPC_INT, MC_LSEEK, RPC_INT, handle, RPC_INT,
|
|
|
|
(int) offset, RPC_INT, whence, RPC_END);
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
return mcfs_handle_simple_error (sock, 1);
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static int
|
|
|
|
mcfs_mknod (vfs *me, char *path, int mode, int dev)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
return mcfs_rpc_path_int_int (MC_MKNOD, path, mode, dev);
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static int
|
|
|
|
mcfs_mkdir (vfs *me, char *path, mode_t mode)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
return mcfs_rpc_path_int (MC_MKDIR, path, mode);
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static int
|
|
|
|
mcfs_rmdir (vfs *me, char *path)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
return mcfs_rpc_path (MC_RMDIR, path);
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static int
|
|
|
|
mcfs_link (vfs *me, char *p1, char *p2)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
return mcfs_rpc_two_paths (MC_LINK, p1, p2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We do not free anything right now: we free resources when we run
|
|
|
|
* out of them
|
|
|
|
*/
|
2002-10-05 05:55:58 +04:00
|
|
|
static vfsid
|
|
|
|
mcfs_getid (vfs *me, char *p, struct vfs_stamping **parent)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
*parent = NULL;
|
2002-10-05 05:55:58 +04:00
|
|
|
|
|
|
|
return (vfsid) - 1;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static int
|
|
|
|
mcfs_nothingisopen (vfsid id)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static void
|
|
|
|
mcfs_free (vfsid id)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
/* FIXME: Should not be empty */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Gives up on a socket and reopnes the connection, the child own the socket
|
|
|
|
* now
|
|
|
|
*/
|
1998-09-27 23:27:58 +04:00
|
|
|
static void
|
|
|
|
my_forget (char *path)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
char *host, *user, *pass, *p;
|
2002-10-05 05:55:58 +04:00
|
|
|
int port, i, vers;
|
1998-09-27 23:27:58 +04:00
|
|
|
|
1998-10-23 12:26:25 +04:00
|
|
|
if (strncmp (path, "/#mc:", 5))
|
1998-12-03 02:44:06 +03:00
|
|
|
return;
|
2002-10-05 05:55:58 +04:00
|
|
|
|
1998-09-27 23:27:58 +04:00
|
|
|
path += 5;
|
1998-02-27 07:54:42 +03:00
|
|
|
if (path[0] == '/' && path[1] == '/')
|
|
|
|
path += 2;
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
if ((p =
|
|
|
|
mcfs_get_host_and_username (path, &host, &user, &port,
|
|
|
|
&pass)) == 0) {
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (host);
|
|
|
|
g_free (user);
|
1998-02-27 07:54:42 +03:00
|
|
|
if (pass)
|
|
|
|
wipe_password (pass);
|
|
|
|
return;
|
|
|
|
}
|
2002-10-05 05:55:58 +04:00
|
|
|
for (i = 0; i < MCFS_MAX_CONNECTIONS; i++) {
|
|
|
|
if ((strcmp (host, mcfs_connections[i].host) == 0) &&
|
|
|
|
(strcmp (user, mcfs_connections[i].user) == 0) &&
|
|
|
|
(port == mcfs_connections[i].port)) {
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
/* close socket: the child owns it now */
|
2002-10-05 05:55:58 +04:00
|
|
|
close (mcfs_connections[i].sock);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
/* reopen the connection */
|
2002-10-05 05:55:58 +04:00
|
|
|
mcfs_connections[i].sock =
|
|
|
|
mcfs_open_tcp_link (host, user, &port, pass, &vers);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
}
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (p);
|
|
|
|
g_free (host);
|
|
|
|
g_free (user);
|
1998-02-27 07:54:42 +03:00
|
|
|
if (pass)
|
|
|
|
wipe_password (pass);
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static int
|
1998-09-27 23:27:58 +04:00
|
|
|
mcfs_setctl (vfs *me, char *path, int ctlop, char *arg)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
1998-09-27 23:27:58 +04:00
|
|
|
switch (ctlop) {
|
2002-10-05 05:55:58 +04:00
|
|
|
case MCCTL_FORGET_ABOUT:
|
|
|
|
my_forget (path);
|
|
|
|
return 0;
|
1998-09-27 23:27:58 +04:00
|
|
|
}
|
|
|
|
return 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
1998-10-13 02:07:53 +04:00
|
|
|
vfs vfs_mcfs_ops = {
|
2002-10-05 05:55:58 +04:00
|
|
|
NULL, /* This is place of next pointer */
|
2001-06-12 01:58:58 +04:00
|
|
|
"mcfs",
|
2002-10-05 05:55:58 +04:00
|
|
|
F_NET, /* flags */
|
|
|
|
"mc:", /* prefix */
|
|
|
|
NULL, /* data */
|
|
|
|
0, /* errno */
|
1998-09-27 23:27:58 +04:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
mcfs_fill_names,
|
|
|
|
NULL,
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
mcfs_open,
|
|
|
|
mcfs_close,
|
|
|
|
mcfs_read,
|
|
|
|
mcfs_write,
|
2002-10-05 05:55:58 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
mcfs_opendir,
|
|
|
|
mcfs_readdir,
|
|
|
|
mcfs_closedir,
|
1998-05-26 04:53:24 +04:00
|
|
|
NULL,
|
|
|
|
NULL,
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
mcfs_stat,
|
|
|
|
mcfs_lstat,
|
|
|
|
mcfs_fstat,
|
|
|
|
|
|
|
|
mcfs_chmod,
|
|
|
|
mcfs_chown,
|
|
|
|
mcfs_utime,
|
|
|
|
|
|
|
|
mcfs_readlink,
|
|
|
|
mcfs_symlink,
|
|
|
|
mcfs_link,
|
|
|
|
mcfs_unlink,
|
|
|
|
|
|
|
|
mcfs_rename,
|
|
|
|
mcfs_chdir,
|
|
|
|
mcfs_errno,
|
|
|
|
mcfs_lseek,
|
|
|
|
mcfs_mknod,
|
2002-10-05 05:55:58 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
mcfs_getid,
|
|
|
|
mcfs_nothingisopen,
|
|
|
|
mcfs_free,
|
2002-10-05 05:55:58 +04:00
|
|
|
|
1998-09-27 23:27:58 +04:00
|
|
|
NULL,
|
|
|
|
NULL,
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
mcfs_mkdir,
|
|
|
|
mcfs_rmdir,
|
|
|
|
NULL,
|
2002-10-05 05:55:58 +04:00
|
|
|
mcfs_setctl MMAPNULL
|
1998-02-27 07:54:42 +03:00
|
|
|
};
|
2002-08-19 11:22:01 +04:00
|
|
|
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static void
|
|
|
|
mcfs_free_bucket (int bucket)
|
2002-08-19 11:22:01 +04:00
|
|
|
{
|
2002-10-05 05:55:58 +04:00
|
|
|
g_free (mcfs_connections[bucket].host);
|
|
|
|
g_free (mcfs_connections[bucket].user);
|
|
|
|
g_free (mcfs_connections[bucket].home);
|
2002-08-19 11:22:01 +04:00
|
|
|
|
|
|
|
/* Set all the fields to zero */
|
2002-10-05 05:55:58 +04:00
|
|
|
mcfs_connections[bucket].host =
|
|
|
|
mcfs_connections[bucket].user = mcfs_connections[bucket].home = 0;
|
|
|
|
mcfs_connections[bucket].sock = mcfs_connections[bucket].version = 0;
|
2002-08-19 11:22:01 +04:00
|
|
|
}
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
static int
|
|
|
|
mcfs_invalidate_socket (int sock)
|
2002-08-19 11:22:01 +04:00
|
|
|
{
|
|
|
|
int i, j = -1;
|
2002-10-05 05:55:58 +04:00
|
|
|
|
2002-08-19 11:22:01 +04:00
|
|
|
for (i = 0; i < MCFS_MAX_CONNECTIONS; i++)
|
2002-10-05 05:55:58 +04:00
|
|
|
if (mcfs_connections[i].sock == sock) {
|
2002-08-19 11:22:01 +04:00
|
|
|
mcfs_free_bucket (i);
|
|
|
|
j = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (j == -1)
|
2002-10-05 05:55:58 +04:00
|
|
|
return -1; /* It was not our sock */
|
2002-08-19 11:22:01 +04:00
|
|
|
/* Break from any possible loop */
|
|
|
|
mc_chdir ("/");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
void
|
|
|
|
tcp_invalidate_socket (int sock)
|
2002-08-19 11:22:01 +04:00
|
|
|
{
|
2002-10-05 05:55:58 +04:00
|
|
|
mcfs_invalidate_socket (sock);
|
2002-08-19 11:22:01 +04:00
|
|
|
}
|
2002-09-19 18:37:22 +04:00
|
|
|
|
2002-10-05 05:55:58 +04:00
|
|
|
#endif /* WITH_MCFS */
|