1999-04-13 06:10:45 +04:00
|
|
|
/* Virtual File System: Midnight Commander file system.
|
2003-04-03 14:45:03 +04:00
|
|
|
|
1999-04-13 06:10:45 +04:00
|
|
|
Copyright (C) 1995, 1996, 1997 The Free Software Foundation
|
|
|
|
|
2003-04-03 14:45:03 +04:00
|
|
|
Written by Wayne Roberts <wroberts1@home.com>, 1997
|
|
|
|
Andrew V. Samoilov <sav@bcs.zp.ua> 2002, 2003
|
2001-04-09 15:34:15 +04:00
|
|
|
|
1999-04-13 06:10:45 +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.
|
2003-04-03 14:45:03 +04:00
|
|
|
|
1999-04-13 06:10:45 +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
|
|
|
|
GNU Library General Public License for more details.
|
|
|
|
|
|
|
|
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. */
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2003-10-13 02:25:53 +04:00
|
|
|
/* Namespace: exports init_smbfs, smbfs_set_debug(), smbfs_set_debugf() */
|
2001-10-30 15:20:11 +03:00
|
|
|
#include <config.h>
|
1999-06-22 23:56:36 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/types.h>
|
2002-10-07 14:05:36 +04:00
|
|
|
|
2002-09-24 19:26:55 +04:00
|
|
|
#undef USE_NCURSES /* Don't include *curses.h */
|
2005-02-19 19:36:38 +03:00
|
|
|
#include "../src/global.h"
|
|
|
|
#include "../src/tty.h" /* enable/disable interrupt key */
|
|
|
|
#include "../src/wtools.h" /* message() */
|
|
|
|
#include "../src/main.h" /* print_vfs_message */
|
2001-05-22 17:26:59 +04:00
|
|
|
#include "utilvfs.h"
|
2002-06-21 16:26:45 +04:00
|
|
|
|
|
|
|
#undef PACKAGE_BUGREPORT
|
|
|
|
#undef PACKAGE_NAME
|
|
|
|
#undef PACKAGE_STRING
|
|
|
|
#undef PACKAGE_TARNAME
|
|
|
|
#undef PACKAGE_VERSION
|
|
|
|
|
1999-06-22 23:56:36 +04:00
|
|
|
#include "samba/include/config.h"
|
1999-09-14 22:20:02 +04:00
|
|
|
/* don't load crap in "samba/include/includes.h" we don't use and which
|
2001-03-04 21:55:17 +03:00
|
|
|
conflicts with definitions in other includes */
|
1999-09-14 22:20:02 +04:00
|
|
|
#undef HAVE_LIBREADLINE
|
1999-09-18 00:11:53 +04:00
|
|
|
#define NO_CONFIG_H
|
2001-08-01 14:40:15 +04:00
|
|
|
#undef VERSION
|
2002-06-21 16:26:45 +04:00
|
|
|
|
1999-04-13 06:10:45 +04:00
|
|
|
#include "samba/include/includes.h"
|
1999-09-14 22:20:02 +04:00
|
|
|
|
1999-08-20 09:42:02 +04:00
|
|
|
#include <string.h>
|
1999-04-13 06:10:45 +04:00
|
|
|
|
|
|
|
#include "vfs.h"
|
2004-08-17 03:25:49 +04:00
|
|
|
#include "vfs-impl.h"
|
1999-04-13 06:10:45 +04:00
|
|
|
#include "smbfs.h"
|
|
|
|
|
|
|
|
#define SMBFS_MAX_CONNECTIONS 16
|
2001-06-27 16:26:27 +04:00
|
|
|
static const char * const IPC = "IPC$";
|
|
|
|
static const char * const URL_HEADER = "/#smb:";
|
1999-06-22 23:56:36 +04:00
|
|
|
#define HEADER_LEN 6
|
1999-04-13 06:10:45 +04:00
|
|
|
|
|
|
|
static int my_errno;
|
2001-06-27 16:26:27 +04:00
|
|
|
static uint32 err;
|
1999-04-13 06:10:45 +04:00
|
|
|
|
|
|
|
/* stuff that is same with each connection */
|
|
|
|
extern int DEBUGLEVEL;
|
2001-10-30 17:40:46 +03:00
|
|
|
extern pstring myhostname;
|
2002-12-20 21:16:45 +03:00
|
|
|
static mode_t myumask = 0755;
|
1999-04-13 06:10:45 +04:00
|
|
|
extern pstring global_myname;
|
|
|
|
static int smbfs_open_connections = 0;
|
2001-06-27 16:26:27 +04:00
|
|
|
static gboolean got_user = FALSE;
|
|
|
|
static gboolean got_pass = FALSE;
|
2001-05-22 17:26:59 +04:00
|
|
|
static pstring password;
|
|
|
|
static pstring username;
|
2003-10-13 02:25:53 +04:00
|
|
|
static struct vfs_class vfs_smbfs_ops;
|
1999-04-13 06:10:45 +04:00
|
|
|
|
|
|
|
static struct _smbfs_connection {
|
|
|
|
struct cli_state *cli;
|
|
|
|
struct in_addr dest_ip;
|
|
|
|
BOOL have_ip;
|
1999-09-14 22:20:02 +04:00
|
|
|
char *host; /* server name */
|
|
|
|
char *service; /* share name */
|
|
|
|
char *domain;
|
1999-04-13 06:10:45 +04:00
|
|
|
char *user;
|
|
|
|
char *home;
|
1999-09-14 22:20:02 +04:00
|
|
|
char *password;
|
1999-04-13 06:10:45 +04:00
|
|
|
int port;
|
|
|
|
int name_type;
|
1999-04-27 02:38:40 +04:00
|
|
|
time_t last_use;
|
1999-04-13 06:10:45 +04:00
|
|
|
} smbfs_connections [SMBFS_MAX_CONNECTIONS];
|
|
|
|
/* unique to each connection */
|
|
|
|
|
2004-08-17 15:18:47 +04:00
|
|
|
/* modifies *share */
|
2002-06-21 16:26:45 +04:00
|
|
|
static struct cli_state * smbfs_do_connect (const char *server, char *share);
|
|
|
|
|
1999-04-13 06:10:45 +04:00
|
|
|
typedef struct _smbfs_connection smbfs_connection;
|
2001-06-27 16:26:27 +04:00
|
|
|
static smbfs_connection *current_bucket;
|
1999-04-13 06:10:45 +04:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
struct cli_state *cli;
|
|
|
|
int fnum;
|
|
|
|
off_t nread;
|
|
|
|
uint16 attr;
|
|
|
|
} smbfs_handle;
|
|
|
|
|
2001-06-27 16:26:27 +04:00
|
|
|
static GSList *auth_list;
|
1999-09-14 22:20:02 +04:00
|
|
|
|
2005-06-08 04:23:44 +04:00
|
|
|
/* this function allows you to write:
|
|
|
|
* char *s = g_strdup("hello, world");
|
|
|
|
* s = free_after(g_strconcat(s, s, (char *)0), s);
|
|
|
|
*/
|
|
|
|
static inline char *
|
|
|
|
free_after (char *result, char *string_to_free)
|
|
|
|
{
|
|
|
|
g_free(string_to_free);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-09-14 22:20:02 +04:00
|
|
|
static void
|
2003-10-28 03:57:02 +03:00
|
|
|
smbfs_auth_free (struct smb_authinfo const *a)
|
1999-09-14 22:20:02 +04:00
|
|
|
{
|
|
|
|
g_free (a->host);
|
|
|
|
g_free (a->share);
|
|
|
|
g_free (a->domain);
|
|
|
|
g_free (a->user);
|
|
|
|
wipe_password (a->password);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-08-16 20:59:43 +04:00
|
|
|
smbfs_auth_free_all (void)
|
1999-09-14 22:20:02 +04:00
|
|
|
{
|
|
|
|
if (auth_list) {
|
2003-10-28 03:57:02 +03:00
|
|
|
g_slist_foreach (auth_list, (GFunc)smbfs_auth_free, 0);
|
1999-09-14 22:20:02 +04:00
|
|
|
g_slist_free (auth_list);
|
|
|
|
auth_list = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
2003-10-28 03:57:02 +03:00
|
|
|
smbfs_auth_cmp_host_and_share (gconstpointer _a, gconstpointer _b)
|
1999-09-14 22:20:02 +04:00
|
|
|
{
|
2001-07-15 11:01:41 +04:00
|
|
|
struct smb_authinfo const *a = (struct smb_authinfo const *)_a;
|
|
|
|
struct smb_authinfo const *b = (struct smb_authinfo const *)_b;
|
1999-09-14 22:20:02 +04:00
|
|
|
|
|
|
|
if (!a->host || !a->share || !b->host || !b->share)
|
|
|
|
return 1;
|
|
|
|
if (strcmp (a->host, b->host) != 0)
|
|
|
|
return 1;
|
|
|
|
if (strcmp (a->share, b->share) != 0)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
2003-10-28 03:57:02 +03:00
|
|
|
smbfs_auth_cmp_host (gconstpointer _a, gconstpointer _b)
|
1999-09-14 22:20:02 +04:00
|
|
|
{
|
2001-07-15 11:01:41 +04:00
|
|
|
struct smb_authinfo const *a = (struct smb_authinfo const *)_a;
|
|
|
|
struct smb_authinfo const *b = (struct smb_authinfo const *)_b;
|
1999-09-14 22:20:02 +04:00
|
|
|
|
|
|
|
if (!a->host || !b->host)
|
|
|
|
return 1;
|
|
|
|
if (strcmp (a->host, b->host) != 0)
|
|
|
|
return 1;
|
|
|
|
if (strcmp (a->share, IPC) != 0)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-10-28 03:57:02 +03:00
|
|
|
smbfs_auth_add (const char *host, const char *share, const char *domain,
|
1999-09-14 22:20:02 +04:00
|
|
|
const char *user, const char *password)
|
|
|
|
{
|
2001-07-15 11:01:41 +04:00
|
|
|
struct smb_authinfo *auth = g_new (struct smb_authinfo, 1);
|
1999-09-14 22:20:02 +04:00
|
|
|
|
|
|
|
if (!auth)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Don't check for NULL, g_strdup already does. */
|
|
|
|
auth->host = g_strdup (host);
|
|
|
|
auth->share = g_strdup (share);
|
|
|
|
auth->domain = g_strdup (domain);
|
|
|
|
auth->user = g_strdup (user);
|
|
|
|
auth->password = g_strdup (password);
|
|
|
|
auth_list = g_slist_prepend (auth_list, auth);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-10-28 03:57:02 +03:00
|
|
|
smbfs_auth_remove (const char *host, const char *share)
|
1999-09-14 22:20:02 +04:00
|
|
|
{
|
2001-07-15 11:01:41 +04:00
|
|
|
struct smb_authinfo data;
|
|
|
|
struct smb_authinfo *auth;
|
1999-09-14 22:20:02 +04:00
|
|
|
GSList *list;
|
|
|
|
|
|
|
|
data.host = g_strdup (host);
|
|
|
|
data.share = g_strdup (share);
|
|
|
|
list = g_slist_find_custom (auth_list,
|
|
|
|
&data,
|
2003-10-28 03:57:02 +03:00
|
|
|
smbfs_auth_cmp_host_and_share);
|
1999-09-14 22:20:02 +04:00
|
|
|
g_free (data.host);
|
|
|
|
g_free (data.share);
|
|
|
|
if (!list)
|
|
|
|
return;
|
|
|
|
auth = list->data;
|
|
|
|
auth_list = g_slist_remove (auth_list, auth);
|
2003-10-28 03:57:02 +03:00
|
|
|
smbfs_auth_free (auth);
|
1999-09-14 22:20:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set authentication information in bucket. Return 1 if successful, else 0 */
|
|
|
|
/* Information in auth_list overrides user if pass is NULL. */
|
|
|
|
/* bucket->host and bucket->service must be valid. */
|
|
|
|
static int
|
2003-10-28 03:57:02 +03:00
|
|
|
smbfs_bucket_set_authinfo (smbfs_connection *bucket,
|
1999-09-14 22:20:02 +04:00
|
|
|
const char *domain, const char *user, const char *pass,
|
|
|
|
int fallback_to_host)
|
|
|
|
{
|
2001-07-15 11:01:41 +04:00
|
|
|
struct smb_authinfo data;
|
|
|
|
struct smb_authinfo *auth;
|
1999-09-14 22:20:02 +04:00
|
|
|
GSList *list;
|
|
|
|
|
|
|
|
if (domain && user && pass) {
|
|
|
|
g_free (bucket->domain);
|
|
|
|
g_free (bucket->user);
|
|
|
|
g_free (bucket->password);
|
|
|
|
bucket->domain = g_strdup (domain);
|
|
|
|
bucket->user = g_strdup (user);
|
|
|
|
bucket->password = g_strdup (pass);
|
2003-10-28 03:57:02 +03:00
|
|
|
smbfs_auth_remove (bucket->host, bucket->service);
|
|
|
|
smbfs_auth_add (bucket->host, bucket->service,
|
1999-09-14 22:20:02 +04:00
|
|
|
domain, user, pass);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
data.host = bucket->host;
|
|
|
|
data.share = bucket->service;
|
2003-10-28 03:57:02 +03:00
|
|
|
list = g_slist_find_custom (auth_list, &data, smbfs_auth_cmp_host_and_share);
|
1999-09-14 22:20:02 +04:00
|
|
|
if (!list && fallback_to_host)
|
2003-10-28 03:57:02 +03:00
|
|
|
list = g_slist_find_custom (auth_list, &data, smbfs_auth_cmp_host);
|
1999-09-14 22:20:02 +04:00
|
|
|
if (list) {
|
|
|
|
auth = list->data;
|
|
|
|
bucket->domain = g_strdup (auth->domain);
|
|
|
|
bucket->user = g_strdup (auth->user);
|
|
|
|
bucket->password = g_strdup (auth->password);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (got_pass) {
|
|
|
|
bucket->domain = g_strdup (lp_workgroup ());
|
|
|
|
bucket->user = g_strdup (got_user ? username : user);
|
|
|
|
bucket->password = g_strdup (password);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2001-07-15 11:01:41 +04:00
|
|
|
auth = vfs_smb_get_authinfo (bucket->host,
|
|
|
|
bucket->service,
|
|
|
|
(domain ? domain : lp_workgroup ()),
|
|
|
|
user);
|
1999-09-14 22:20:02 +04:00
|
|
|
if (auth) {
|
|
|
|
g_free (bucket->domain);
|
|
|
|
g_free (bucket->user);
|
|
|
|
g_free (bucket->password);
|
|
|
|
bucket->domain = g_strdup (auth->domain);
|
|
|
|
bucket->user = g_strdup (auth->user);
|
|
|
|
bucket->password = g_strdup (auth->password);
|
2003-10-28 03:57:02 +03:00
|
|
|
smbfs_auth_remove (bucket->host, bucket->service);
|
1999-09-14 22:20:02 +04:00
|
|
|
auth_list = g_slist_prepend (auth_list, auth);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-04-27 02:38:40 +04:00
|
|
|
void
|
2002-09-13 13:46:33 +04:00
|
|
|
smbfs_set_debug (int arg)
|
1999-04-27 02:38:40 +04:00
|
|
|
{
|
2002-09-13 13:46:33 +04:00
|
|
|
DEBUGLEVEL = arg;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
smbfs_set_debugf (const char *filename)
|
|
|
|
{
|
|
|
|
extern pstring debugf;
|
|
|
|
extern FILE *dbf;
|
|
|
|
if (DEBUGLEVEL > 0) {
|
|
|
|
FILE *outfile = fopen (filename, "w");
|
|
|
|
if (outfile) {
|
2005-09-05 07:17:03 +04:00
|
|
|
setup_logging ("", True); /* No needs for timestamp for each message */
|
2002-09-13 13:46:33 +04:00
|
|
|
dbf = outfile;
|
|
|
|
setbuf (dbf, NULL);
|
|
|
|
pstrcpy (debugf, filename);
|
|
|
|
}
|
|
|
|
}
|
1999-04-13 06:10:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/********************** The callbacks ******************************/
|
1999-04-27 02:38:40 +04:00
|
|
|
static int
|
2003-10-12 04:24:00 +04:00
|
|
|
smbfs_init (struct vfs_class * me)
|
1999-04-27 02:38:40 +04:00
|
|
|
{
|
2004-08-17 15:18:47 +04:00
|
|
|
const char *servicesf = CONFIGDIR PATH_SEP_STR "smb.conf";
|
2002-08-06 10:02:52 +04:00
|
|
|
|
|
|
|
/* DEBUGLEVEL = 4; */
|
|
|
|
|
|
|
|
TimeInit ();
|
|
|
|
charset_initialise ();
|
|
|
|
|
|
|
|
DEBUG (3, ("smbfs_init(%s)\n", me->name));
|
|
|
|
|
|
|
|
if (!get_myname (myhostname, NULL))
|
|
|
|
DEBUG (0, ("Failed to get my hostname.\n"));
|
|
|
|
|
2005-09-05 07:17:03 +04:00
|
|
|
if (!lp_load (servicesf, True, False, False))
|
2002-08-06 10:02:52 +04:00
|
|
|
DEBUG (0, ("Cannot load %s - run testparm to debug it\n", servicesf));
|
|
|
|
|
|
|
|
codepage_initialise (lp_client_code_page ());
|
|
|
|
|
|
|
|
load_interfaces ();
|
|
|
|
|
2002-12-20 21:16:45 +03:00
|
|
|
myumask = umask (0);
|
|
|
|
umask (myumask);
|
|
|
|
myumask = ~myumask;
|
|
|
|
|
2002-08-06 10:02:52 +04:00
|
|
|
if (getenv ("USER")) {
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
pstrcpy (username, getenv ("USER"));
|
|
|
|
got_user = TRUE;
|
|
|
|
DEBUG (3, ("smbfs_init(): $USER:%s\n", username));
|
|
|
|
if ((p = strchr (username, '%'))) {
|
|
|
|
*p = 0;
|
|
|
|
pstrcpy (password, p + 1);
|
|
|
|
got_pass = TRUE;
|
|
|
|
memset (strchr (getenv ("USER"), '%') + 1, 'X', strlen (password));
|
|
|
|
DEBUG (3, ("smbfs_init(): $USER%%pass: %s%%%s\n",
|
|
|
|
username, password));
|
|
|
|
}
|
|
|
|
strupper (username);
|
1999-04-13 06:10:45 +04:00
|
|
|
}
|
2002-08-06 10:02:52 +04:00
|
|
|
if (getenv ("PASSWD")) {
|
|
|
|
pstrcpy (password, getenv ("PASSWD"));
|
|
|
|
got_pass = TRUE;
|
1999-04-13 06:10:45 +04:00
|
|
|
}
|
2002-08-06 10:02:52 +04:00
|
|
|
return 1;
|
1999-04-13 06:10:45 +04:00
|
|
|
}
|
|
|
|
|
1999-04-27 02:38:40 +04:00
|
|
|
static void
|
2004-08-16 20:34:11 +04:00
|
|
|
smbfs_fill_names (struct vfs_class *me, fill_names_f func)
|
1999-04-27 02:38:40 +04:00
|
|
|
{
|
2001-04-09 15:34:15 +04:00
|
|
|
int i;
|
|
|
|
char *path;
|
2005-02-22 21:35:22 +03:00
|
|
|
|
|
|
|
(void) me;
|
|
|
|
|
2001-04-09 15:34:15 +04:00
|
|
|
for (i = 0; i < SMBFS_MAX_CONNECTIONS; i++) {
|
|
|
|
if (smbfs_connections [i].cli) {
|
|
|
|
path = g_strconcat (URL_HEADER,
|
2002-10-09 17:18:10 +04:00
|
|
|
smbfs_connections[i].user, "@",
|
|
|
|
smbfs_connections[i].host,
|
2001-04-09 15:34:15 +04:00
|
|
|
"/", smbfs_connections[i].service,
|
|
|
|
NULL);
|
|
|
|
(*func)(path);
|
|
|
|
g_free (path);
|
|
|
|
}
|
|
|
|
}
|
1999-04-13 06:10:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#define CNV_LANG(s) dos_to_unix(s,False)
|
1999-09-14 22:20:02 +04:00
|
|
|
#define GNAL_VNC(s) unix_to_dos(s,False)
|
1999-04-13 06:10:45 +04:00
|
|
|
/* does same as do_get() in client.c */
|
|
|
|
/* called from vfs.c:1080, count = buffer size */
|
1999-04-27 02:38:40 +04:00
|
|
|
static int
|
|
|
|
smbfs_read (void *data, char *buffer, int count)
|
1999-04-13 06:10:45 +04:00
|
|
|
{
|
|
|
|
smbfs_handle *info = (smbfs_handle *) data;
|
|
|
|
int n;
|
|
|
|
|
1999-06-22 23:56:36 +04:00
|
|
|
DEBUG(3, ("smbfs_read(fnum:%d, nread:%d, count:%d)\n",
|
1999-04-13 06:10:45 +04:00
|
|
|
info->fnum, (int)info->nread, count));
|
|
|
|
n = cli_read(info->cli, info->fnum, buffer, info->nread, count);
|
|
|
|
if (n > 0)
|
|
|
|
info->nread += n;
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
1999-04-27 02:38:40 +04:00
|
|
|
static int
|
2004-08-17 01:16:54 +04:00
|
|
|
smbfs_write (void *data, const char *buf, int nbyte)
|
1999-04-13 06:10:45 +04:00
|
|
|
{
|
|
|
|
smbfs_handle *info = (smbfs_handle *) data;
|
|
|
|
int n;
|
|
|
|
|
1999-06-22 23:56:36 +04:00
|
|
|
DEBUG(3, ("smbfs_write(fnum:%d, nread:%d, nbyte:%d)\n",
|
1999-04-13 06:10:45 +04:00
|
|
|
info->fnum, (int)info->nread, nbyte));
|
2005-09-05 07:17:03 +04:00
|
|
|
n = cli_write(info->cli, info->fnum, 0, buf, info->nread, nbyte);
|
1999-04-13 06:10:45 +04:00
|
|
|
if (n > 0)
|
|
|
|
info->nread += n;
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
1999-04-27 02:38:40 +04:00
|
|
|
static int
|
|
|
|
smbfs_close (void *data)
|
1999-04-13 06:10:45 +04:00
|
|
|
{
|
|
|
|
smbfs_handle *info = (smbfs_handle *) data;
|
2002-09-02 14:54:22 +04:00
|
|
|
DEBUG (3, ("smbfs_close(fnum:%d)\n", info->fnum));
|
|
|
|
|
|
|
|
/* FIXME: Why too different cli have the same outbuf
|
|
|
|
* if file is copied to share
|
|
|
|
*/
|
|
|
|
if (info->cli->outbuf == NULL) {
|
|
|
|
my_errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
/* if imlementing archive_level: add rname to smbfs_handle */
|
1999-04-13 06:10:45 +04:00
|
|
|
if (archive_level >= 2 && (inf->attr & aARCH)) {
|
2002-09-02 14:54:22 +04:00
|
|
|
cli_setatr (info->cli, rname, info->attr & ~(uint16) aARCH, 0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return (cli_close (info->cli, info->fnum) == True) ? 0 : -1;
|
1999-04-13 06:10:45 +04:00
|
|
|
}
|
|
|
|
|
1999-04-27 02:38:40 +04:00
|
|
|
static int
|
2003-10-12 04:24:00 +04:00
|
|
|
smbfs_errno (struct vfs_class *me)
|
1999-04-13 06:10:45 +04:00
|
|
|
{
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
|
|
|
|
|
|
|
DEBUG(3, ("smbfs_errno: %s\n", g_strerror(my_errno)));
|
1999-04-13 06:10:45 +04:00
|
|
|
return my_errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct dir_entry {
|
|
|
|
char *text;
|
|
|
|
struct dir_entry *next;
|
|
|
|
struct stat my_stat;
|
|
|
|
int merrno;
|
|
|
|
} dir_entry;
|
|
|
|
|
|
|
|
typedef struct {
|
2002-09-11 16:53:58 +04:00
|
|
|
gboolean server_list;
|
|
|
|
char *dirname;
|
|
|
|
char *path; /* the dir originally passed to smbfs_opendir */
|
1999-04-13 06:10:45 +04:00
|
|
|
smbfs_connection *conn;
|
|
|
|
dir_entry *entries;
|
|
|
|
dir_entry *current;
|
|
|
|
} opendir_info;
|
|
|
|
|
2001-06-27 16:26:27 +04:00
|
|
|
static opendir_info
|
1999-06-22 23:56:36 +04:00
|
|
|
*previous_info,
|
|
|
|
*current_info,
|
|
|
|
*current_share_info,
|
|
|
|
*current_server_info;
|
|
|
|
|
2001-06-27 16:26:27 +04:00
|
|
|
static gboolean first_direntry;
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2002-11-07 17:49:13 +03:00
|
|
|
static dir_entry *
|
2003-10-28 03:57:02 +03:00
|
|
|
smbfs_new_dir_entry (const char *name)
|
2001-08-03 14:19:45 +04:00
|
|
|
{
|
2002-11-07 17:49:13 +03:00
|
|
|
static int inode_counter;
|
|
|
|
dir_entry *new_entry;
|
|
|
|
new_entry = g_new0 (dir_entry, 1);
|
|
|
|
new_entry->text = dos_to_unix (g_strdup (name), 1);
|
|
|
|
|
|
|
|
if (first_direntry) {
|
|
|
|
current_info->entries = new_entry;
|
|
|
|
first_direntry = FALSE;
|
|
|
|
} else {
|
|
|
|
current_info->current->next = new_entry;
|
|
|
|
}
|
|
|
|
current_info->current = new_entry;
|
|
|
|
new_entry->my_stat.st_ino = inode_counter++;
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2002-11-07 17:49:13 +03:00
|
|
|
return new_entry;
|
2001-08-03 14:19:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* browse for shares on server */
|
|
|
|
static void
|
2003-10-28 03:57:02 +03:00
|
|
|
smbfs_browsing_helper (const char *name, uint32 type, const char *comment, void *state)
|
2001-08-03 14:19:45 +04:00
|
|
|
{
|
2004-08-17 15:18:47 +04:00
|
|
|
const char *typestr = "";
|
2003-10-28 03:57:02 +03:00
|
|
|
dir_entry *new_entry = smbfs_new_dir_entry (name);
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) state;
|
|
|
|
|
2002-09-11 16:53:58 +04:00
|
|
|
switch (type) {
|
|
|
|
case STYPE_DISKTREE:
|
|
|
|
typestr = "Disk";
|
|
|
|
/* show this as dir */
|
|
|
|
new_entry->my_stat.st_mode =
|
2002-12-20 21:16:45 +03:00
|
|
|
(S_IFDIR | S_IRUSR | S_IRGRP | S_IROTH | S_IXUSR | S_IXGRP |
|
|
|
|
S_IXOTH) & myumask;
|
2002-09-11 16:53:58 +04:00
|
|
|
break;
|
|
|
|
case STYPE_PRINTQ:
|
|
|
|
typestr = "Printer";
|
|
|
|
break;
|
|
|
|
case STYPE_DEVICE:
|
|
|
|
typestr = "Device";
|
|
|
|
break;
|
|
|
|
case STYPE_IPC:
|
|
|
|
typestr = "IPC";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
DEBUG (3, ("\t%-15.15s%-10.10s%s\n", name, typestr, comment));
|
|
|
|
}
|
2002-09-11 19:35:55 +04:00
|
|
|
|
1999-04-27 02:38:40 +04:00
|
|
|
static void
|
2003-10-28 03:57:02 +03:00
|
|
|
smbfs_loaddir_helper (file_info * finfo, const char *mask, void *entry)
|
1999-04-27 02:38:40 +04:00
|
|
|
{
|
2002-09-12 10:25:21 +04:00
|
|
|
dir_entry *new_entry = (dir_entry *) entry;
|
2002-09-11 16:53:58 +04:00
|
|
|
time_t t = finfo->mtime; /* the time is assumed to be passed as GMT */
|
2005-02-22 21:35:22 +03:00
|
|
|
|
|
|
|
(void) mask;
|
|
|
|
|
2002-09-11 16:53:58 +04:00
|
|
|
#if 0 /* I want to see dot files */
|
|
|
|
if (finfo->mode & aHIDDEN)
|
|
|
|
return; /* don't bother with hidden files, "~$" screws up mc */
|
2001-05-22 17:26:59 +04:00
|
|
|
#endif
|
2002-09-12 10:25:21 +04:00
|
|
|
if (!entry)
|
2003-10-28 03:57:02 +03:00
|
|
|
new_entry = smbfs_new_dir_entry (finfo->name);
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2002-09-11 16:53:58 +04:00
|
|
|
new_entry->my_stat.st_size = finfo->size;
|
|
|
|
new_entry->my_stat.st_mtime = finfo->mtime;
|
|
|
|
new_entry->my_stat.st_atime = finfo->atime;
|
|
|
|
new_entry->my_stat.st_ctime = finfo->ctime;
|
|
|
|
new_entry->my_stat.st_uid = finfo->uid;
|
|
|
|
new_entry->my_stat.st_gid = finfo->gid;
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2002-09-12 10:25:21 +04:00
|
|
|
new_entry->my_stat.st_mode = /* rw-rw-rw */
|
2002-09-11 16:53:58 +04:00
|
|
|
S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR | S_IWGRP | S_IWOTH;
|
1999-04-13 06:10:45 +04:00
|
|
|
|
|
|
|
/* if (finfo->mode & aVOLID); nothing similar in real world */
|
2002-09-11 16:53:58 +04:00
|
|
|
if (finfo->mode & aDIR)
|
2002-09-12 10:25:21 +04:00
|
|
|
new_entry->my_stat.st_mode |= /* drwxrwxrwx */
|
2002-09-11 16:53:58 +04:00
|
|
|
S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH;
|
|
|
|
else
|
|
|
|
new_entry->my_stat.st_mode |= S_IFREG; /* if not dir, regular file? */
|
1999-04-13 06:10:45 +04:00
|
|
|
/* if (finfo->mode & aARCH); DOS archive */
|
|
|
|
/* if (finfo->mode & aHIDDEN); like a dot file? */
|
|
|
|
/* if (finfo->mode & aSYSTEM); like a kernel? */
|
2002-09-11 16:53:58 +04:00
|
|
|
if (finfo->mode & aRONLY)
|
|
|
|
new_entry->my_stat.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
|
2002-12-20 21:16:45 +03:00
|
|
|
new_entry->my_stat.st_mode &= myumask;
|
2002-09-11 16:53:58 +04:00
|
|
|
|
2002-09-12 10:25:21 +04:00
|
|
|
DEBUG (entry ? 3 : 6, (" %-30s%7.7s%8.0f %s",
|
|
|
|
CNV_LANG (finfo->name),
|
|
|
|
attrib_string (finfo->mode),
|
|
|
|
(double) finfo->size,
|
|
|
|
asctime (LocalTime (&t))));
|
1999-04-13 06:10:45 +04:00
|
|
|
}
|
|
|
|
|
2001-08-06 19:36:33 +04:00
|
|
|
/* takes "/foo/bar/file" and gives malloced "\\foo\\bar\\file" */
|
2004-08-19 16:05:54 +04:00
|
|
|
static char *
|
|
|
|
smbfs_convert_path (const char *remote_file, gboolean trailing_asterik)
|
1999-04-27 02:38:40 +04:00
|
|
|
{
|
2004-08-19 16:05:54 +04:00
|
|
|
const char *p, *my_remote;
|
|
|
|
char *result;
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2004-08-19 16:05:54 +04:00
|
|
|
my_remote = remote_file;
|
1999-06-22 23:56:36 +04:00
|
|
|
if (strncmp (my_remote, URL_HEADER, HEADER_LEN) == 0) { /* if passed directly */
|
2004-08-19 16:05:54 +04:00
|
|
|
my_remote += HEADER_LEN;
|
1999-04-27 02:38:40 +04:00
|
|
|
if (*my_remote == '/') /* from server browsing */
|
|
|
|
my_remote++;
|
1999-08-20 09:42:02 +04:00
|
|
|
p = strchr(my_remote, '/');
|
|
|
|
if (p)
|
|
|
|
my_remote = p+1; /* advance to end of server name */
|
1999-04-13 06:10:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (*my_remote == '/')
|
|
|
|
my_remote++; /* strip off leading '/' */
|
1999-08-20 09:42:02 +04:00
|
|
|
p = strchr(my_remote, '/');
|
|
|
|
if (p)
|
|
|
|
my_remote = p; /* strip off share/service name */
|
1999-04-13 06:10:45 +04:00
|
|
|
/* create remote filename as understood by smb clientgen */
|
2004-08-19 16:05:54 +04:00
|
|
|
result = g_strconcat (my_remote, trailing_asterik ? "/*" : "", 0);
|
|
|
|
unix_to_dos (result, /* inplace = */ 1); /* code page conversion */
|
|
|
|
str_replace(result, '/', '\\');
|
|
|
|
return result;
|
1999-04-13 06:10:45 +04:00
|
|
|
}
|
|
|
|
|
1999-04-27 02:38:40 +04:00
|
|
|
static void
|
2003-10-28 03:57:02 +03:00
|
|
|
smbfs_srv_browsing_helper (const char *name, uint32 m, const char *comment,
|
|
|
|
void *state)
|
1999-04-27 02:38:40 +04:00
|
|
|
{
|
2003-10-28 03:57:02 +03:00
|
|
|
dir_entry *new_entry = smbfs_new_dir_entry (name);
|
1999-04-27 02:38:40 +04:00
|
|
|
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) m;
|
|
|
|
(void) state;
|
|
|
|
|
2002-09-11 16:53:58 +04:00
|
|
|
/* show this as dir */
|
|
|
|
new_entry->my_stat.st_mode =
|
2003-10-28 03:57:02 +03:00
|
|
|
(S_IFDIR | S_IRUSR | S_IRGRP | S_IROTH | S_IXUSR | S_IXGRP |
|
|
|
|
S_IXOTH) & myumask;
|
1999-04-27 02:38:40 +04:00
|
|
|
|
2002-09-11 16:53:58 +04:00
|
|
|
DEBUG (3, ("\t%-16.16s %s\n", name, comment));
|
1999-06-22 23:56:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL
|
2003-10-28 03:57:02 +03:00
|
|
|
smbfs_reconnect(smbfs_connection *conn, int *retries)
|
2001-05-22 17:26:59 +04:00
|
|
|
{
|
1999-06-22 23:56:36 +04:00
|
|
|
char *host;
|
|
|
|
DEBUG(3, ("RECONNECT\n"));
|
|
|
|
|
2001-03-04 21:55:17 +03:00
|
|
|
if (*(conn->host) == 0)
|
1999-06-22 23:56:36 +04:00
|
|
|
host = g_strdup(conn->cli->desthost); /* server browsing */
|
|
|
|
else
|
|
|
|
host = g_strdup(conn->host);
|
|
|
|
|
|
|
|
cli_shutdown(conn->cli);
|
|
|
|
|
2002-06-21 16:26:45 +04:00
|
|
|
if (!(conn->cli = smbfs_do_connect(host, conn->service))) {
|
2003-10-26 07:47:20 +03:00
|
|
|
message (1, MSG_ERROR,
|
2004-01-28 03:01:30 +03:00
|
|
|
_(" reconnect to %s failed\n "), conn->host);
|
1999-06-22 23:56:36 +04:00
|
|
|
g_free(host);
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
g_free(host);
|
|
|
|
if (++(*retries) == 2)
|
|
|
|
return False;
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL
|
2003-10-28 03:57:02 +03:00
|
|
|
smbfs_send(struct cli_state *cli)
|
1999-06-22 23:56:36 +04:00
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
size_t nwritten=0;
|
|
|
|
ssize_t ret;
|
|
|
|
|
|
|
|
len = smb_len(cli->outbuf) + 4;
|
|
|
|
|
|
|
|
while (nwritten < len) {
|
|
|
|
ret = write_socket(cli->fd, cli->outbuf+nwritten, len - nwritten);
|
2004-10-16 23:19:27 +04:00
|
|
|
if (ret <= 0) {
|
|
|
|
if (errno == EPIPE)
|
1999-06-22 23:56:36 +04:00
|
|
|
return False;
|
2004-10-16 23:19:27 +04:00
|
|
|
} else
|
|
|
|
nwritten += ret;
|
1999-06-22 23:56:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
See if server has cut us off by checking for EPIPE when writing.
|
|
|
|
Taken from cli_chkpath()
|
|
|
|
****************************************************************************/
|
|
|
|
static BOOL
|
2004-08-17 15:18:47 +04:00
|
|
|
smbfs_chkpath(struct cli_state *cli, const char *path, BOOL send_only)
|
1999-06-22 23:56:36 +04:00
|
|
|
{
|
|
|
|
fstring path2;
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
fstrcpy(path2,path);
|
1999-09-14 22:20:02 +04:00
|
|
|
unix_to_dos (path2, 1);
|
1999-06-22 23:56:36 +04:00
|
|
|
trim_string(path2,NULL,"\\");
|
|
|
|
if (!*path2) *path2 = '\\';
|
|
|
|
|
|
|
|
memset(cli->outbuf,'\0',smb_size);
|
|
|
|
set_message(cli->outbuf,0,4 + strlen(path2),True);
|
|
|
|
SCVAL(cli->outbuf,smb_com,SMBchkpth);
|
|
|
|
SSVAL(cli->outbuf,smb_tid,cli->cnum);
|
|
|
|
|
|
|
|
cli->rap_error = 0;
|
|
|
|
cli->nt_error = 0;
|
|
|
|
SSVAL(cli->outbuf,smb_pid,cli->pid);
|
|
|
|
SSVAL(cli->outbuf,smb_uid,cli->vuid);
|
|
|
|
SSVAL(cli->outbuf,smb_mid,cli->mid);
|
|
|
|
if (cli->protocol > PROTOCOL_CORE) {
|
|
|
|
SCVAL(cli->outbuf,smb_flg,0x8);
|
|
|
|
SSVAL(cli->outbuf,smb_flg2,0x1);
|
|
|
|
}
|
|
|
|
|
|
|
|
p = smb_buf(cli->outbuf);
|
|
|
|
*p++ = 4;
|
|
|
|
fstrcpy(p,path2);
|
|
|
|
|
2003-10-28 03:57:02 +03:00
|
|
|
if (!smbfs_send(cli)) {
|
|
|
|
DEBUG(3, ("smbfs_chkpath: couldnt send\n"));
|
1999-06-22 23:56:36 +04:00
|
|
|
return False;
|
|
|
|
}
|
|
|
|
if (send_only) {
|
|
|
|
client_receive_smb(cli->fd, cli->inbuf, cli->timeout);
|
2003-10-28 03:57:02 +03:00
|
|
|
DEBUG(3, ("smbfs_chkpath: send only OK\n"));
|
1999-06-22 23:56:36 +04:00
|
|
|
return True; /* just testing for EPIPE */
|
|
|
|
}
|
|
|
|
if (!client_receive_smb(cli->fd, cli->inbuf, cli->timeout)) {
|
2003-10-28 03:57:02 +03:00
|
|
|
DEBUG(3, ("smbfs_chkpath: receive error\n"));
|
1999-06-22 23:56:36 +04:00
|
|
|
return False;
|
|
|
|
}
|
|
|
|
if ((my_errno = cli_error(cli, NULL, NULL, NULL))) {
|
|
|
|
if (my_errno == 20 || my_errno == 13)
|
|
|
|
return True; /* ignore if 'not a directory' error */
|
2003-10-28 03:57:02 +03:00
|
|
|
DEBUG(3, ("smbfs_chkpath: cli_error: %s\n", g_strerror(my_errno)));
|
1999-06-22 23:56:36 +04:00
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
|
|
|
return True;
|
1999-04-27 02:38:40 +04:00
|
|
|
}
|
|
|
|
|
2002-09-24 19:26:55 +04:00
|
|
|
#if 1
|
1999-06-22 23:56:36 +04:00
|
|
|
static int
|
2003-10-28 03:57:02 +03:00
|
|
|
smbfs_fs (const char *text)
|
1999-06-22 23:56:36 +04:00
|
|
|
{
|
2001-03-15 21:19:23 +03:00
|
|
|
const char *p = text;
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
while ((p = strchr(p, '/')) != NULL) {
|
1999-06-22 23:56:36 +04:00
|
|
|
count++;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
if (count == 1)
|
|
|
|
return strlen(text);
|
|
|
|
return count;
|
|
|
|
}
|
2002-09-24 19:26:55 +04:00
|
|
|
#endif
|
1999-06-22 23:56:36 +04:00
|
|
|
|
1999-04-27 02:38:40 +04:00
|
|
|
static int
|
|
|
|
smbfs_loaddir (opendir_info *smbfs_info)
|
|
|
|
{
|
2003-10-28 03:57:02 +03:00
|
|
|
uint16 attribute = aDIR | aSYSTEM | aHIDDEN;
|
|
|
|
int servlen = strlen (smbfs_info->conn->service);
|
2004-08-19 16:05:54 +04:00
|
|
|
const char *info_dirname = smbfs_info->dirname;
|
|
|
|
char *my_dirname;
|
2003-10-28 03:57:02 +03:00
|
|
|
|
2004-08-19 16:05:54 +04:00
|
|
|
DEBUG (3, ("smbfs_loaddir: dirname:%s\n", info_dirname));
|
2003-10-28 03:57:02 +03:00
|
|
|
first_direntry = TRUE;
|
|
|
|
|
|
|
|
if (current_info) {
|
|
|
|
DEBUG (3,
|
2004-08-19 16:05:54 +04:00
|
|
|
("smbfs_loaddir: new:'%s', cached:'%s'\n", info_dirname,
|
2003-10-28 03:57:02 +03:00
|
|
|
current_info->dirname));
|
|
|
|
/* if new desired dir is longer than cached in current_info */
|
2004-08-19 16:05:54 +04:00
|
|
|
if (smbfs_fs (info_dirname) > smbfs_fs (current_info->dirname)) {
|
2003-10-28 03:57:02 +03:00
|
|
|
DEBUG (3, ("saving to previous_info\n"));
|
|
|
|
previous_info = current_info;
|
1999-06-22 23:56:36 +04:00
|
|
|
}
|
2003-10-28 03:57:02 +03:00
|
|
|
}
|
1999-06-23 01:16:11 +04:00
|
|
|
|
2003-10-28 03:57:02 +03:00
|
|
|
current_info = smbfs_info;
|
2001-08-06 19:36:33 +04:00
|
|
|
|
2004-08-19 16:05:54 +04:00
|
|
|
if (strcmp (info_dirname, "/") == 0) {
|
2003-10-28 03:57:02 +03:00
|
|
|
if (!strcmp (smbfs_info->path, URL_HEADER)) {
|
|
|
|
DEBUG (6, ("smbfs_loaddir: browsing %s\n", IPC));
|
|
|
|
/* browse for servers */
|
|
|
|
if (!cli_NetServerEnum
|
|
|
|
(smbfs_info->conn->cli, smbfs_info->conn->domain,
|
|
|
|
SV_TYPE_ALL, smbfs_srv_browsing_helper, NULL))
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
current_server_info = smbfs_info;
|
|
|
|
smbfs_info->server_list = TRUE;
|
|
|
|
} else {
|
|
|
|
/* browse for shares */
|
|
|
|
if (cli_RNetShareEnum
|
|
|
|
(smbfs_info->conn->cli, smbfs_browsing_helper, NULL) < 1)
|
1999-06-22 23:56:36 +04:00
|
|
|
return 0;
|
2003-10-28 03:57:02 +03:00
|
|
|
else
|
|
|
|
current_share_info = smbfs_info;
|
1999-04-13 06:10:45 +04:00
|
|
|
}
|
2003-10-28 03:57:02 +03:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* do regular directory listing */
|
2004-08-19 16:05:54 +04:00
|
|
|
if (strncmp (smbfs_info->conn->service, info_dirname + 1, servlen) == 0) {
|
2003-10-28 03:57:02 +03:00
|
|
|
/* strip share name from dir */
|
2004-08-19 16:05:54 +04:00
|
|
|
my_dirname = g_strdup (info_dirname + servlen);
|
|
|
|
*my_dirname = '/';
|
|
|
|
my_dirname = free_after(smbfs_convert_path (my_dirname, TRUE), my_dirname);
|
2003-10-28 03:57:02 +03:00
|
|
|
} else
|
2004-08-19 16:05:54 +04:00
|
|
|
my_dirname = smbfs_convert_path (info_dirname, TRUE);
|
2003-10-28 03:57:02 +03:00
|
|
|
|
|
|
|
DEBUG (6, ("smbfs_loaddir: service: %s\n", smbfs_info->conn->service));
|
|
|
|
DEBUG (6,
|
|
|
|
("smbfs_loaddir: cli->share: %s\n",
|
|
|
|
smbfs_info->conn->cli->share));
|
|
|
|
DEBUG (6,
|
|
|
|
("smbfs_loaddir: calling cli_list with mask %s\n", my_dirname));
|
|
|
|
/* do file listing: cli_list returns number of files */
|
|
|
|
if (cli_list
|
|
|
|
(smbfs_info->conn->cli, my_dirname, attribute,
|
|
|
|
smbfs_loaddir_helper, NULL) < 0) {
|
|
|
|
/* cli_list returns -1 if directory empty or cannot read socket */
|
|
|
|
my_errno = cli_error (smbfs_info->conn->cli, NULL, &err, NULL);
|
2001-08-06 19:36:33 +04:00
|
|
|
g_free (my_dirname);
|
2003-10-28 03:57:02 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (*(my_dirname) == 0)
|
|
|
|
smbfs_info->dirname = smbfs_info->conn->service;
|
|
|
|
g_free (my_dirname);
|
2001-04-09 15:34:15 +04:00
|
|
|
/* do_dskattr(); */
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2003-10-28 03:57:02 +03:00
|
|
|
done:
|
1999-04-13 06:10:45 +04:00
|
|
|
/* current_info->parent = smbfs_info->dirname; */
|
2001-04-09 15:34:15 +04:00
|
|
|
|
2003-10-28 03:57:02 +03:00
|
|
|
smbfs_info->current = smbfs_info->entries;
|
|
|
|
return 1; /* 1 = ok */
|
1999-04-13 06:10:45 +04:00
|
|
|
}
|
|
|
|
|
2001-05-22 17:26:59 +04:00
|
|
|
#ifdef SMBFS_FREE_DIR
|
1999-04-27 02:38:40 +04:00
|
|
|
static void
|
|
|
|
smbfs_free_dir (dir_entry *de)
|
1999-04-13 06:10:45 +04:00
|
|
|
{
|
|
|
|
if (!de) return;
|
|
|
|
|
|
|
|
smbfs_free_dir (de->next);
|
|
|
|
g_free (de->text);
|
|
|
|
g_free (de);
|
|
|
|
}
|
2001-05-22 17:26:59 +04:00
|
|
|
#endif
|
1999-04-13 06:10:45 +04: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 */
|
1999-04-27 02:38:40 +04:00
|
|
|
static void *
|
2002-08-16 01:15:17 +04:00
|
|
|
smbfs_readdir(void *info)
|
1999-04-13 06:10:45 +04:00
|
|
|
{
|
2002-08-16 01:15:17 +04:00
|
|
|
static union vfs_dirent smbfs_readdir_data;
|
|
|
|
static char *const dirent_dest = smbfs_readdir_data.dent.d_name;
|
|
|
|
opendir_info *smbfs_info = (opendir_info *) info;
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2001-05-22 17:26:59 +04:00
|
|
|
DEBUG(4, ("smbfs_readdir(%s)\n", smbfs_info->dirname));
|
2002-08-16 01:15:17 +04:00
|
|
|
|
1999-04-13 06:10:45 +04:00
|
|
|
if (!smbfs_info->entries)
|
2002-08-16 01:15:17 +04:00
|
|
|
if (!smbfs_loaddir(smbfs_info))
|
|
|
|
return NULL;
|
1999-04-13 06:10:45 +04:00
|
|
|
|
|
|
|
if (smbfs_info->current == 0) { /* reached end of dir entries */
|
2002-08-16 01:15:17 +04:00
|
|
|
DEBUG(3, ("smbfs_readdir: smbfs_info->current = 0\n"));
|
2001-05-22 17:26:59 +04:00
|
|
|
#ifdef SMBFS_FREE_DIR
|
2002-08-16 01:15:17 +04:00
|
|
|
smbfs_free_dir(smbfs_info->entries);
|
|
|
|
smbfs_info->entries = 0;
|
2001-05-22 17:26:59 +04:00
|
|
|
#endif
|
2002-08-16 01:15:17 +04:00
|
|
|
return NULL;
|
1999-04-13 06:10:45 +04:00
|
|
|
}
|
2004-08-26 12:47:50 +04:00
|
|
|
g_strlcpy(dirent_dest, smbfs_info->current->text, MC_MAXPATHLEN);
|
1999-04-13 06:10:45 +04:00
|
|
|
smbfs_info->current = smbfs_info->current->next;
|
|
|
|
|
2002-08-15 23:38:17 +04:00
|
|
|
compute_namelen(&smbfs_readdir_data.dent);
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2002-08-16 01:15:17 +04:00
|
|
|
return &smbfs_readdir_data;
|
1999-04-13 06:10:45 +04:00
|
|
|
}
|
|
|
|
|
1999-04-27 02:38:40 +04:00
|
|
|
static int
|
|
|
|
smbfs_closedir (void *info)
|
1999-04-13 06:10:45 +04:00
|
|
|
{
|
|
|
|
opendir_info *smbfs_info = (opendir_info *) info;
|
|
|
|
/* dir_entry *p, *q; */
|
|
|
|
|
1999-06-22 23:56:36 +04:00
|
|
|
DEBUG(3, ("smbfs_closedir(%s)\n", smbfs_info->dirname));
|
1999-04-13 06:10:45 +04:00
|
|
|
/* CLOSE HERE */
|
|
|
|
|
|
|
|
/* for (p = smbfs_info->entries; p;){
|
|
|
|
q = p;
|
|
|
|
p = p->next;
|
|
|
|
g_free (q->text);
|
|
|
|
g_free (q);
|
|
|
|
}
|
|
|
|
g_free (info); */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-04-27 02:38:40 +04:00
|
|
|
static int
|
2004-08-17 01:36:39 +04:00
|
|
|
smbfs_chmod (struct vfs_class *me, const char *path, int mode)
|
1999-04-13 06:10:45 +04:00
|
|
|
{
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
|
|
|
|
1999-06-22 23:56:36 +04:00
|
|
|
DEBUG(3, ("smbfs_chmod(path:%s, mode:%d)\n", path, mode));
|
1999-04-13 06:10:45 +04:00
|
|
|
/* my_errno = EOPNOTSUPP;
|
2002-10-11 19:29:55 +04:00
|
|
|
return -1; */ /* cannot chmod on smb filesystem */
|
1999-04-13 06:10:45 +04:00
|
|
|
return 0; /* make mc happy */
|
|
|
|
}
|
|
|
|
|
1999-04-27 02:38:40 +04:00
|
|
|
static int
|
2004-08-17 01:36:39 +04:00
|
|
|
smbfs_chown (struct vfs_class *me, const char *path, int owner, int group)
|
1999-04-13 06:10:45 +04:00
|
|
|
{
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
|
|
|
|
1999-06-22 23:56:36 +04:00
|
|
|
DEBUG(3, ("smbfs_chown(path:%s, owner:%d, group:%d)\n", path, owner, group));
|
1999-04-13 06:10:45 +04:00
|
|
|
my_errno = EOPNOTSUPP; /* ready for your labotomy? */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
1999-04-27 02:38:40 +04:00
|
|
|
static int
|
2004-08-17 01:36:39 +04:00
|
|
|
smbfs_utime (struct vfs_class *me, const char *path, struct utimbuf *times)
|
1999-04-13 06:10:45 +04:00
|
|
|
{
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
|
|
|
(void) times;
|
|
|
|
|
1999-06-22 23:56:36 +04:00
|
|
|
DEBUG(3, ("smbfs_utime(path:%s)\n", path));
|
1999-04-13 06:10:45 +04:00
|
|
|
my_errno = EOPNOTSUPP;
|
2005-02-22 21:35:22 +03:00
|
|
|
return -1;
|
1999-04-13 06:10:45 +04:00
|
|
|
}
|
|
|
|
|
1999-04-27 02:38:40 +04:00
|
|
|
static int
|
2004-09-02 18:12:21 +04:00
|
|
|
smbfs_readlink (struct vfs_class *me, const char *path, char *buf, size_t size)
|
1999-04-13 06:10:45 +04:00
|
|
|
{
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
|
|
|
|
2004-09-02 18:12:21 +04:00
|
|
|
DEBUG (3,
|
|
|
|
("smbfs_readlink(path:%s, buf:%s, size:%d)\n", path, buf,
|
|
|
|
(int) size));
|
1999-04-13 06:10:45 +04:00
|
|
|
my_errno = EOPNOTSUPP;
|
2005-02-22 21:35:22 +03:00
|
|
|
return -1; /* no symlinks on smb filesystem? */
|
1999-04-13 06:10:45 +04:00
|
|
|
}
|
|
|
|
|
1999-04-27 02:38:40 +04:00
|
|
|
static int
|
2004-08-17 02:15:28 +04:00
|
|
|
smbfs_symlink (struct vfs_class *me, const char *n1, const char *n2)
|
1999-04-13 06:10:45 +04:00
|
|
|
{
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
|
|
|
|
1999-06-22 23:56:36 +04:00
|
|
|
DEBUG(3, ("smbfs_symlink(n1:%s, n2:%s)\n", n1, n2));
|
1999-04-13 06:10:45 +04:00
|
|
|
my_errno = EOPNOTSUPP;
|
2005-02-22 21:35:22 +03:00
|
|
|
return -1; /* no symlinks on smb filesystem? */
|
1999-04-13 06:10:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Extract the hostname and username from the path */
|
2002-10-09 17:18:10 +04:00
|
|
|
/* path is in the form: [user@]hostname/share/remote-dir */
|
2001-08-01 16:24:35 +04:00
|
|
|
#define smbfs_get_host_and_username(path, host, user, port, pass) \
|
|
|
|
vfs_split_url (*path, host, user, port, pass, SMB_PORT, 0)
|
2002-10-09 17:18:10 +04:00
|
|
|
|
1999-04-13 06:10:45 +04:00
|
|
|
/*****************************************************
|
|
|
|
return a connection to a SMB server
|
|
|
|
current_bucket needs to be set before calling
|
|
|
|
*******************************************************/
|
2002-06-21 16:26:45 +04:00
|
|
|
static struct cli_state *
|
|
|
|
smbfs_do_connect (const char *server, char *share)
|
1999-04-13 06:10:45 +04:00
|
|
|
{
|
|
|
|
struct cli_state *c;
|
|
|
|
struct nmb_name called, calling;
|
|
|
|
struct in_addr ip;
|
|
|
|
extern struct in_addr ipzero;
|
|
|
|
|
2002-06-21 16:26:45 +04:00
|
|
|
DEBUG(3, ("smbfs_do_connect(%s, %s)\n", server, share));
|
1999-04-13 06:10:45 +04:00
|
|
|
if (*share == '\\') {
|
|
|
|
server = share+2;
|
|
|
|
share = strchr(server,'\\');
|
|
|
|
if (!share) return NULL;
|
|
|
|
*share = 0;
|
|
|
|
share++;
|
|
|
|
}
|
|
|
|
|
2002-09-01 10:51:24 +04:00
|
|
|
make_nmb_name(&calling, global_myname, 0x0);
|
|
|
|
make_nmb_name(&called , server, current_bucket->name_type);
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2001-08-01 14:40:15 +04:00
|
|
|
for (;;) {
|
|
|
|
|
2002-06-21 16:26:45 +04:00
|
|
|
ip = (current_bucket->have_ip) ? current_bucket->dest_ip : ipzero;
|
1999-04-13 06:10:45 +04:00
|
|
|
|
|
|
|
/* have to open a new connection */
|
1999-06-22 23:56:36 +04:00
|
|
|
if (!(c = cli_initialise(NULL))) {
|
|
|
|
my_errno = ENOMEM;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
pwd_init(&(c->pwd)); /* should be moved into cli_initialise()? */
|
|
|
|
pwd_set_cleartext(&(c->pwd), current_bucket->password);
|
|
|
|
|
|
|
|
if ((cli_set_port(c, current_bucket->port) == 0) ||
|
2001-08-01 14:40:15 +04:00
|
|
|
!cli_connect(c, server, &ip)) {
|
|
|
|
DEBUG(1, ("Connection to %s failed\n", server));
|
|
|
|
break;
|
1999-04-13 06:10:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!cli_session_request(c, &calling, &called)) {
|
1999-06-22 23:56:36 +04:00
|
|
|
my_errno = cli_error(c, NULL, &err, NULL);
|
1999-04-27 02:38:40 +04:00
|
|
|
DEBUG(1, ("session request to %s failed\n", called.name));
|
1999-04-13 06:10:45 +04:00
|
|
|
cli_shutdown(c);
|
|
|
|
if (strcmp(called.name, "*SMBSERVER")) {
|
2002-09-01 10:51:24 +04:00
|
|
|
make_nmb_name(&called , "*SMBSERVER", 0x20);
|
2001-08-01 14:40:15 +04:00
|
|
|
continue;
|
1999-04-13 06:10:45 +04:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1999-06-22 23:56:36 +04:00
|
|
|
DEBUG(3, (" session request ok\n"));
|
1999-04-13 06:10:45 +04:00
|
|
|
|
|
|
|
if (!cli_negprot(c)) {
|
1999-04-27 02:38:40 +04:00
|
|
|
DEBUG(1, ("protocol negotiation failed\n"));
|
2001-08-01 14:40:15 +04:00
|
|
|
break;
|
1999-04-13 06:10:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!cli_session_setup(c, current_bucket->user,
|
|
|
|
current_bucket->password, strlen(current_bucket->password),
|
|
|
|
current_bucket->password, strlen(current_bucket->password),
|
1999-09-15 08:24:22 +04:00
|
|
|
current_bucket->domain)) {
|
1999-04-13 06:10:45 +04:00
|
|
|
DEBUG(1,("session setup failed: %s\n", cli_errstr(c)));
|
2003-10-28 03:57:02 +03:00
|
|
|
smbfs_auth_remove (server, share);
|
2001-08-01 14:40:15 +04:00
|
|
|
break;
|
1999-04-13 06:10:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (*c->server_domain || *c->server_os || *c->server_type)
|
1999-06-22 23:56:36 +04:00
|
|
|
DEBUG(5,("Domain=[%s] OS=[%s] Server=[%s]\n",
|
1999-04-13 06:10:45 +04:00
|
|
|
c->server_domain,c->server_os,c->server_type));
|
|
|
|
|
1999-06-22 23:56:36 +04:00
|
|
|
DEBUG(3, (" session setup ok\n"));
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2005-09-05 07:17:03 +04:00
|
|
|
if (!cli_send_tconX(c, share, "?????",
|
1999-04-13 06:10:45 +04:00
|
|
|
current_bucket->password, strlen(current_bucket->password)+1)) {
|
1999-06-22 23:56:36 +04:00
|
|
|
DEBUG(1,("%s: tree connect failed: %s\n", share, cli_errstr(c)));
|
2001-08-01 14:40:15 +04:00
|
|
|
break;
|
1999-04-13 06:10:45 +04:00
|
|
|
}
|
|
|
|
|
1999-06-22 23:56:36 +04:00
|
|
|
DEBUG(3, (" tconx ok\n"));
|
1999-04-13 06:10:45 +04:00
|
|
|
|
1999-06-22 23:56:36 +04:00
|
|
|
my_errno = 0;
|
1999-04-13 06:10:45 +04:00
|
|
|
return c;
|
2001-08-01 14:40:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
my_errno = cli_error(c, NULL, &err, NULL);
|
|
|
|
cli_shutdown(c);
|
|
|
|
return NULL;
|
|
|
|
|
1999-04-13 06:10:45 +04:00
|
|
|
}
|
|
|
|
|
1999-04-27 02:38:40 +04:00
|
|
|
static int
|
2003-10-28 03:57:02 +03:00
|
|
|
smbfs_get_master_browser(char **host)
|
1999-04-27 02:38:40 +04:00
|
|
|
{
|
2005-09-07 11:33:39 +04:00
|
|
|
static char so_broadcast[] = "SO_BROADCAST";
|
1999-04-27 02:38:40 +04:00
|
|
|
int count;
|
2001-10-30 17:40:46 +03:00
|
|
|
struct in_addr *ip_list, bcast_addr;
|
|
|
|
extern struct in_addr ipzero;
|
|
|
|
|
1999-06-22 23:56:36 +04:00
|
|
|
/* does port = 137 for win95 master browser? */
|
|
|
|
int fd= open_socket_in( SOCK_DGRAM, 0, 3,
|
1999-04-27 02:38:40 +04:00
|
|
|
interpret_addr(lp_socket_address()), True );
|
|
|
|
if (fd == -1)
|
|
|
|
return 0;
|
2005-09-07 11:33:39 +04:00
|
|
|
set_socket_options(fd, so_broadcast);
|
1999-06-22 23:56:36 +04:00
|
|
|
ip_list = iface_bcast(ipzero);
|
|
|
|
bcast_addr = *ip_list;
|
1999-04-27 02:38:40 +04:00
|
|
|
if ((ip_list = name_query(fd, "\01\02__MSBROWSE__\02", 1, True,
|
|
|
|
True, bcast_addr, &count, NULL))) {
|
|
|
|
if (!count)
|
|
|
|
return 0;
|
|
|
|
/* just return first master browser */
|
|
|
|
*host = g_strdup(inet_ntoa(ip_list[0]));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-09-14 22:20:02 +04:00
|
|
|
static void
|
2003-10-28 03:57:02 +03:00
|
|
|
smbfs_free_bucket (smbfs_connection *bucket)
|
1999-09-14 22:20:02 +04:00
|
|
|
{
|
|
|
|
g_free (bucket->host);
|
|
|
|
g_free (bucket->service);
|
|
|
|
g_free (bucket->domain);
|
|
|
|
g_free (bucket->user);
|
|
|
|
wipe_password (bucket->password);
|
2004-09-25 03:00:18 +04:00
|
|
|
g_free (bucket->home);
|
2002-07-15 09:31:43 +04:00
|
|
|
memset (bucket, 0, sizeof (smbfs_connection));
|
1999-09-14 22:20:02 +04:00
|
|
|
}
|
|
|
|
|
1999-04-27 02:38:40 +04:00
|
|
|
static smbfs_connection *
|
2004-08-16 20:59:43 +04:00
|
|
|
smbfs_get_free_bucket (void)
|
1999-04-13 06:10:45 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
1999-04-27 02:38:40 +04:00
|
|
|
for (i = 0; i < SMBFS_MAX_CONNECTIONS; i++)
|
1999-04-13 06:10:45 +04:00
|
|
|
if (!smbfs_connections [i].cli) return &smbfs_connections [i];
|
1999-04-27 02:38:40 +04:00
|
|
|
|
|
|
|
{ /* search for most dormant connection */
|
2001-03-04 21:55:17 +03:00
|
|
|
int oldest = 0; /* index */
|
2001-11-05 16:16:17 +03:00
|
|
|
time_t oldest_time = smbfs_connections[0].last_use;
|
|
|
|
for (i = 1; i < SMBFS_MAX_CONNECTIONS; i++) {
|
1999-04-27 02:38:40 +04:00
|
|
|
if (smbfs_connections[i].last_use < oldest_time) {
|
|
|
|
oldest_time = smbfs_connections[i].last_use;
|
|
|
|
oldest = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cli_shutdown(smbfs_connections[oldest].cli);
|
2003-10-28 03:57:02 +03:00
|
|
|
smbfs_free_bucket (&smbfs_connections[oldest]);
|
1999-04-27 02:38:40 +04:00
|
|
|
return &smbfs_connections[oldest];
|
|
|
|
}
|
|
|
|
|
1999-04-13 06:10:45 +04:00
|
|
|
/* This can't happend, since we have checked for max connections before */
|
|
|
|
vfs_die("Internal error: smbfs_get_free_bucket");
|
|
|
|
return 0; /* shut up, stupid gcc */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This routine keeps track of open connections */
|
|
|
|
/* Returns a connected socket to host */
|
1999-04-27 02:38:40 +04:00
|
|
|
static smbfs_connection *
|
2002-10-09 17:18:10 +04:00
|
|
|
smbfs_open_link (char *host, char *path, const char *user, int *port,
|
|
|
|
char *this_pass)
|
1999-04-13 06:10:45 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
smbfs_connection *bucket;
|
2001-03-04 21:55:17 +03:00
|
|
|
pstring service;
|
|
|
|
struct in_addr *dest_ip = NULL;
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2002-10-09 17:18:10 +04:00
|
|
|
DEBUG (3, ("smbfs_open_link(host:%s, path:%s)\n", host, path));
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2002-10-09 17:18:10 +04:00
|
|
|
if (strcmp (host, path) == 0) /* if host & path are same: */
|
|
|
|
pstrcpy (service, IPC); /* setup for browse */
|
|
|
|
else { /* get share name from path, path starts with server name */
|
|
|
|
char *p;
|
|
|
|
if ((p = strchr (path, '/'))) /* get share aka */
|
|
|
|
pstrcpy (service, ++p); /* service name from path */
|
|
|
|
else
|
|
|
|
pstrcpy (service, "");
|
|
|
|
/* now check for trailing directory/filenames */
|
|
|
|
p = strchr (service, '/');
|
|
|
|
if (p)
|
|
|
|
*p = 0; /* cut off dir/files: sharename only */
|
|
|
|
if (!*service)
|
|
|
|
pstrcpy (service, IPC); /* setup for browse */
|
|
|
|
DEBUG (6, ("smbfs_open_link: service from path:%s\n", service));
|
|
|
|
}
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2002-10-09 17:18:10 +04:00
|
|
|
if (got_user)
|
|
|
|
user = username; /* global from getenv */
|
1999-04-13 06:10:45 +04:00
|
|
|
|
|
|
|
/* Is the link actually open? */
|
2001-08-06 19:36:33 +04:00
|
|
|
for (i = 0; i < SMBFS_MAX_CONNECTIONS; i++) {
|
2002-10-09 17:18:10 +04:00
|
|
|
if (!smbfs_connections[i].cli)
|
|
|
|
continue;
|
|
|
|
if ((strcmp (host, smbfs_connections[i].host) == 0) &&
|
|
|
|
(strcmp (user, smbfs_connections[i].user) == 0) &&
|
|
|
|
(strcmp (service, smbfs_connections[i].service) == 0)) {
|
|
|
|
int retries = 0;
|
|
|
|
BOOL inshare = (*host != 0 && *path != 0 && strchr (path, '/'));
|
|
|
|
/* check if this connection has died */
|
2003-10-28 03:57:02 +03:00
|
|
|
while (!smbfs_chkpath (smbfs_connections[i].cli, "\\", !inshare)) {
|
|
|
|
if (!smbfs_reconnect (&smbfs_connections[i], &retries))
|
2002-10-09 17:18:10 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
DEBUG (6, ("smbfs_open_link: returning smbfs_connection[%d]\n", i));
|
|
|
|
current_bucket = &smbfs_connections[i];
|
|
|
|
smbfs_connections[i].last_use = time (NULL);
|
|
|
|
return &smbfs_connections[i];
|
|
|
|
}
|
|
|
|
/* connection not found, find if we have ip for new connection */
|
|
|
|
if (strcmp (host, smbfs_connections[i].host) == 0)
|
|
|
|
dest_ip = &smbfs_connections[i].cli->dest_ip;
|
1999-04-13 06:10:45 +04:00
|
|
|
}
|
1999-04-27 02:38:40 +04:00
|
|
|
|
2002-10-09 17:18:10 +04:00
|
|
|
/* make new connection */
|
1999-04-13 06:10:45 +04:00
|
|
|
bucket = smbfs_get_free_bucket ();
|
2002-10-09 17:18:10 +04:00
|
|
|
bucket->name_type = 0x20;
|
1999-04-13 06:10:45 +04:00
|
|
|
bucket->home = 0;
|
2002-10-09 17:18:10 +04:00
|
|
|
bucket->port = *port;
|
|
|
|
bucket->have_ip = False;
|
|
|
|
if (dest_ip) {
|
|
|
|
bucket->have_ip = True;
|
|
|
|
bucket->dest_ip = *dest_ip;
|
|
|
|
}
|
|
|
|
current_bucket = bucket;
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2002-10-09 17:18:10 +04:00
|
|
|
bucket->user = g_strdup (user);
|
|
|
|
bucket->service = g_strdup (service);
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2002-10-09 17:18:10 +04:00
|
|
|
if (!(*host)) { /* if blank host name, browse for servers */
|
2003-10-28 03:57:02 +03:00
|
|
|
if (!smbfs_get_master_browser (&host)) /* set host to ip of master browser */
|
2002-10-09 17:18:10 +04:00
|
|
|
return 0; /* could not find master browser? */
|
|
|
|
g_free (host);
|
|
|
|
bucket->host = g_strdup (""); /* blank host means master browser */
|
|
|
|
} else
|
|
|
|
bucket->host = g_strdup (host);
|
1999-04-27 02:38:40 +04:00
|
|
|
|
2003-10-28 03:57:02 +03:00
|
|
|
if (!smbfs_bucket_set_authinfo (bucket, 0, /* domain currently not used */
|
2002-10-09 17:18:10 +04:00
|
|
|
user, this_pass, 1))
|
|
|
|
return 0;
|
1999-09-14 22:20:02 +04:00
|
|
|
|
2002-10-09 17:18:10 +04:00
|
|
|
/* connect to share */
|
|
|
|
while (!(bucket->cli = smbfs_do_connect (host, service))) {
|
2001-03-04 21:55:17 +03:00
|
|
|
|
1999-09-14 22:20:02 +04:00
|
|
|
if (my_errno != EPERM)
|
2002-10-09 17:18:10 +04:00
|
|
|
return 0;
|
2003-10-26 07:47:20 +03:00
|
|
|
message (1, MSG_ERROR, _(" Authentication failed "));
|
1999-09-14 22:20:02 +04:00
|
|
|
|
2002-10-09 17:18:10 +04:00
|
|
|
/* authentication failed, try again */
|
2003-10-28 03:57:02 +03:00
|
|
|
smbfs_auth_remove (bucket->host, bucket->service);
|
|
|
|
if (!smbfs_bucket_set_authinfo (bucket, bucket->domain, bucket->user, 0, 0))
|
2002-10-09 17:18:10 +04:00
|
|
|
return 0;
|
1999-09-14 22:20:02 +04:00
|
|
|
|
|
|
|
}
|
1999-04-27 02:38:40 +04:00
|
|
|
|
1999-04-13 06:10:45 +04:00
|
|
|
smbfs_open_connections++;
|
2002-10-09 17:18:10 +04:00
|
|
|
DEBUG (3, ("smbfs_open_link:smbfs_open_connections: %d\n",
|
|
|
|
smbfs_open_connections));
|
1999-04-13 06:10:45 +04:00
|
|
|
return bucket;
|
|
|
|
}
|
|
|
|
|
1999-04-27 02:38:40 +04:00
|
|
|
static char *
|
2002-10-11 19:29:55 +04:00
|
|
|
smbfs_get_path (smbfs_connection ** sc, const char *path)
|
1999-04-27 02:38:40 +04:00
|
|
|
{
|
2002-10-09 17:18:10 +04:00
|
|
|
char *user, *host, *remote_path, *pass;
|
|
|
|
int port = SMB_PORT;
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2002-10-09 17:18:10 +04:00
|
|
|
DEBUG (3, ("smbfs_get_path(%s)\n", path));
|
1999-06-22 23:56:36 +04:00
|
|
|
if (strncmp (path, URL_HEADER, HEADER_LEN))
|
2002-10-09 17:18:10 +04:00
|
|
|
return NULL;
|
1999-06-22 23:56:36 +04:00
|
|
|
path += HEADER_LEN;
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2002-10-09 17:18:10 +04:00
|
|
|
if (*path == '/') /* '/' leading server name */
|
|
|
|
path++; /* probably came from server browsing */
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2002-10-09 17:18:10 +04:00
|
|
|
if ((remote_path =
|
|
|
|
smbfs_get_host_and_username (&path, &host, &user, &port, &pass)))
|
|
|
|
if ((*sc =
|
|
|
|
smbfs_open_link (host, remote_path, user, &port, pass)) == NULL) {
|
|
|
|
g_free (remote_path);
|
|
|
|
remote_path = NULL;
|
|
|
|
}
|
1999-04-13 06:10:45 +04:00
|
|
|
g_free (host);
|
|
|
|
g_free (user);
|
2002-10-09 17:18:10 +04:00
|
|
|
if (pass)
|
|
|
|
wipe_password (pass);
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2002-10-09 17:18:10 +04:00
|
|
|
if (!remote_path)
|
|
|
|
return NULL;
|
1999-04-13 06:10:45 +04:00
|
|
|
|
|
|
|
/* NOTE: tildes are deprecated. See ftpfs.c */
|
|
|
|
{
|
2002-10-09 17:18:10 +04:00
|
|
|
int f = !strcmp (remote_path, "/~");
|
|
|
|
if (f || !strncmp (remote_path, "/~/", 3)) {
|
|
|
|
char *s;
|
|
|
|
s = concat_dir_and_file ((*sc)->home, remote_path + 3 - f);
|
|
|
|
g_free (remote_path);
|
|
|
|
return s;
|
1999-04-13 06:10:45 +04:00
|
|
|
}
|
2002-10-09 17:18:10 +04:00
|
|
|
}
|
|
|
|
return remote_path;
|
1999-04-13 06:10:45 +04:00
|
|
|
}
|
|
|
|
|
2001-05-22 17:26:59 +04:00
|
|
|
#if 0
|
1999-04-27 02:38:40 +04:00
|
|
|
static int
|
|
|
|
is_error (int result, int errno_num)
|
1999-04-13 06:10:45 +04:00
|
|
|
{
|
|
|
|
if (!(result == -1))
|
|
|
|
return my_errno = 0;
|
|
|
|
else
|
|
|
|
my_errno = errno_num;
|
|
|
|
return 1;
|
|
|
|
}
|
2001-05-22 17:26:59 +04:00
|
|
|
#endif
|
1999-04-13 06:10:45 +04:00
|
|
|
|
1999-04-27 02:38:40 +04:00
|
|
|
static void *
|
2003-11-13 11:29:37 +03:00
|
|
|
smbfs_opendir (struct vfs_class *me, const char *dirname)
|
1999-04-13 06:10:45 +04:00
|
|
|
{
|
|
|
|
opendir_info *smbfs_info;
|
|
|
|
smbfs_connection *sc;
|
|
|
|
char *remote_dir;
|
|
|
|
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
|
|
|
|
|
|
|
DEBUG(3, ("smbfs_opendir(dirname:%s)\n", dirname));
|
1999-04-13 06:10:45 +04:00
|
|
|
|
|
|
|
if (!(remote_dir = smbfs_get_path (&sc, dirname)))
|
2005-02-22 21:35:22 +03:00
|
|
|
return NULL;
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2005-02-22 21:35:22 +03:00
|
|
|
/* FIXME: where freed? */
|
1999-04-13 06:10:45 +04:00
|
|
|
smbfs_info = g_new (opendir_info, 1);
|
1999-04-27 02:38:40 +04:00
|
|
|
smbfs_info->server_list = FALSE;
|
|
|
|
smbfs_info->path = g_strdup(dirname); /* keep original */
|
1999-04-13 06:10:45 +04:00
|
|
|
smbfs_info->dirname = remote_dir;
|
|
|
|
smbfs_info->conn = sc;
|
|
|
|
smbfs_info->entries = 0;
|
|
|
|
smbfs_info->current = 0;
|
|
|
|
|
|
|
|
return smbfs_info;
|
|
|
|
}
|
|
|
|
|
1999-04-27 02:38:40 +04:00
|
|
|
static int
|
2003-10-28 03:57:02 +03:00
|
|
|
smbfs_fake_server_stat (const char *server_url, const char *path, struct stat *buf)
|
1999-04-27 02:38:40 +04:00
|
|
|
{
|
2003-02-19 15:56:03 +03:00
|
|
|
dir_entry *dentry;
|
2004-08-16 20:59:43 +04:00
|
|
|
const char *p;
|
1999-04-27 02:38:40 +04:00
|
|
|
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) server_url;
|
|
|
|
|
2003-02-19 15:56:03 +03:00
|
|
|
if ((p = strrchr (path, '/')))
|
|
|
|
path = p + 1; /* advance until last '/' */
|
1999-04-27 02:38:40 +04:00
|
|
|
|
2003-02-19 15:56:03 +03:00
|
|
|
if (!current_info->entries) {
|
2004-08-16 20:59:43 +04:00
|
|
|
if (!smbfs_loaddir (current_info)) /* browse host */
|
|
|
|
return -1;
|
2003-02-19 15:56:03 +03:00
|
|
|
}
|
2001-10-30 18:24:01 +03:00
|
|
|
|
|
|
|
if (current_info->server_list == True) {
|
1999-04-27 02:38:40 +04:00
|
|
|
dentry = current_info->entries;
|
2003-02-19 15:56:03 +03:00
|
|
|
DEBUG (4, ("fake stat for SERVER \"%s\"\n", path));
|
1999-04-27 02:38:40 +04:00
|
|
|
while (dentry) {
|
2003-02-19 15:56:03 +03:00
|
|
|
if (strcmp (dentry->text, path) == 0) {
|
2003-10-28 03:57:02 +03:00
|
|
|
DEBUG (4, ("smbfs_fake_server_stat: %s:%4o\n",
|
2003-02-19 15:56:03 +03:00
|
|
|
dentry->text, (int)dentry->my_stat.st_mode));
|
|
|
|
memcpy (buf, &dentry->my_stat, sizeof (struct stat));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
dentry = dentry->next;
|
1999-04-27 02:38:40 +04:00
|
|
|
}
|
2001-10-30 18:24:01 +03:00
|
|
|
}
|
2003-02-19 15:56:03 +03:00
|
|
|
my_errno = ENOENT;
|
|
|
|
return -1;
|
1999-04-27 02:38:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2003-10-28 03:57:02 +03:00
|
|
|
smbfs_fake_share_stat (const char *server_url, const char *path, struct stat *buf)
|
1999-04-27 02:38:40 +04:00
|
|
|
{
|
2002-10-11 19:29:55 +04:00
|
|
|
dir_entry *dentry;
|
|
|
|
if (strlen (path) < strlen (server_url))
|
|
|
|
return -1;
|
1999-04-27 02:38:40 +04:00
|
|
|
|
2002-10-11 19:29:55 +04:00
|
|
|
if (!current_share_info) { /* Server was not stat()ed */
|
|
|
|
/* Make sure there is such share at server */
|
|
|
|
smbfs_connection *sc;
|
|
|
|
char *p;
|
|
|
|
p = smbfs_get_path (&sc, path);
|
|
|
|
g_free (p);
|
|
|
|
if (p) {
|
|
|
|
memset (buf, 0, sizeof (*buf));
|
|
|
|
/* show this as dir */
|
|
|
|
buf->st_mode =
|
2002-12-20 21:16:45 +03:00
|
|
|
(S_IFDIR | S_IRUSR | S_IRGRP | S_IROTH | S_IXUSR | S_IXGRP |
|
|
|
|
S_IXOTH) & myumask;
|
2002-10-11 19:29:55 +04:00
|
|
|
return 0;
|
1999-04-13 06:10:45 +04:00
|
|
|
}
|
|
|
|
return -1;
|
2002-10-11 19:29:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
path += strlen (server_url); /* we only want share name */
|
|
|
|
path++;
|
|
|
|
|
|
|
|
if (*path == '/') /* '/' leading server name */
|
|
|
|
path++; /* probably came from server browsing */
|
|
|
|
|
|
|
|
if (!current_share_info->entries) {
|
|
|
|
if (!smbfs_loaddir (current_share_info)) /* browse host */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
dentry = current_share_info->entries;
|
2003-10-28 03:57:02 +03:00
|
|
|
DEBUG (3, ("smbfs_fake_share_stat: %s on %s\n", path, server_url));
|
2002-10-11 19:29:55 +04:00
|
|
|
while (dentry) {
|
|
|
|
if (strcmp (dentry->text, path) == 0) {
|
2003-10-28 03:57:02 +03:00
|
|
|
DEBUG (6, ("smbfs_fake_share_stat: %s:%4o\n",
|
2003-02-19 15:56:03 +03:00
|
|
|
dentry->text, (int) dentry->my_stat.st_mode));
|
2002-10-11 19:29:55 +04:00
|
|
|
memcpy (buf, &dentry->my_stat, sizeof (struct stat));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
dentry = dentry->next;
|
|
|
|
}
|
|
|
|
my_errno = ENOENT;
|
|
|
|
return -1;
|
1999-04-13 06:10:45 +04:00
|
|
|
}
|
|
|
|
|
2003-10-28 03:57:02 +03:00
|
|
|
/* stat a single file, smbfs_get_remote_stat callback */
|
2001-06-27 16:26:27 +04:00
|
|
|
static dir_entry *single_entry;
|
2002-09-11 19:35:55 +04:00
|
|
|
|
2002-09-12 10:25:21 +04:00
|
|
|
/* stat a single file */
|
|
|
|
static int
|
2004-08-17 00:26:42 +04:00
|
|
|
smbfs_get_remote_stat (smbfs_connection * sc, const char *path, struct stat *buf)
|
1999-04-27 02:38:40 +04:00
|
|
|
{
|
2002-09-12 10:25:21 +04:00
|
|
|
uint16 attribute = aDIR | aSYSTEM | aHIDDEN;
|
2004-08-19 16:05:54 +04:00
|
|
|
char *mypath;
|
2002-09-12 10:25:21 +04:00
|
|
|
|
2004-08-19 16:05:54 +04:00
|
|
|
DEBUG (3, ("smbfs_get_remote_stat(): mypath:%s\n", path));
|
2001-06-27 16:26:27 +04:00
|
|
|
|
2004-08-19 16:05:54 +04:00
|
|
|
mypath = smbfs_convert_path (path, FALSE);
|
2002-09-12 10:25:21 +04:00
|
|
|
|
|
|
|
#if 0 /* single_entry is never free()d now. And only my_stat is used */
|
2002-09-11 19:35:55 +04:00
|
|
|
single_entry = g_new (dir_entry, 1);
|
2001-06-27 16:26:27 +04:00
|
|
|
|
2002-09-11 19:35:55 +04:00
|
|
|
single_entry->text = dos_to_unix (g_strdup (finfo->name), 1);
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2002-09-11 19:35:55 +04:00
|
|
|
single_entry->next = 0;
|
2001-06-27 16:26:27 +04:00
|
|
|
#endif
|
2002-09-11 19:35:55 +04:00
|
|
|
if (!single_entry)
|
|
|
|
single_entry = g_new0 (dir_entry, 1);
|
2001-06-27 16:26:27 +04:00
|
|
|
|
2002-09-12 10:25:21 +04:00
|
|
|
if (cli_list
|
2003-10-28 03:57:02 +03:00
|
|
|
(sc->cli, mypath, attribute, smbfs_loaddir_helper, single_entry) < 1) {
|
2002-09-12 10:25:21 +04:00
|
|
|
my_errno = ENOENT;
|
|
|
|
g_free (mypath);
|
|
|
|
return -1; /* cli_list returns number of files */
|
|
|
|
}
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2002-09-12 10:25:21 +04:00
|
|
|
memcpy (buf, &single_entry->my_stat, sizeof (struct stat));
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2002-09-11 19:35:55 +04:00
|
|
|
/* don't free here, use for smbfs_fstat() */
|
1999-04-13 06:10:45 +04:00
|
|
|
/* g_free(single_entry->text);
|
|
|
|
g_free(single_entry); */
|
2002-09-12 10:25:21 +04:00
|
|
|
g_free (mypath);
|
|
|
|
return 0;
|
1999-04-13 06:10:45 +04:00
|
|
|
}
|
|
|
|
|
1999-06-22 23:56:36 +04:00
|
|
|
static int
|
2003-10-28 03:57:02 +03:00
|
|
|
smbfs_search_dir_entry (dir_entry *dentry, const char *text, struct stat *buf)
|
1999-06-22 23:56:36 +04:00
|
|
|
{
|
|
|
|
while (dentry) {
|
|
|
|
if (strcmp(text, dentry->text) == 0) {
|
|
|
|
memcpy(buf, &dentry->my_stat, sizeof(struct stat));
|
1999-07-13 06:36:32 +04:00
|
|
|
memcpy(&single_entry->my_stat, &dentry->my_stat,
|
|
|
|
sizeof(struct stat));
|
1999-06-22 23:56:36 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
dentry = dentry->next;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
1999-04-27 02:38:40 +04:00
|
|
|
static int
|
2004-08-17 00:26:42 +04:00
|
|
|
smbfs_get_stat_info (smbfs_connection * sc, const char *path, struct stat *buf)
|
1999-04-27 02:38:40 +04:00
|
|
|
{
|
2002-09-13 15:29:35 +04:00
|
|
|
char *p;
|
1999-09-14 22:20:02 +04:00
|
|
|
#if 0
|
2002-09-13 15:29:35 +04:00
|
|
|
dir_entry *dentry = current_info->entries;
|
1999-09-14 22:20:02 +04:00
|
|
|
#endif
|
2002-09-13 15:29:35 +04:00
|
|
|
const char *mypath = path;
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2002-09-13 15:29:35 +04:00
|
|
|
mypath++; /* cut off leading '/' */
|
|
|
|
if ((p = strrchr (mypath, '/')))
|
|
|
|
mypath = p + 1; /* advance until last file/dir name */
|
2003-10-28 03:57:02 +03:00
|
|
|
DEBUG (3, ("smbfs_get_stat_info: mypath:%s, current_info->dirname:%s\n",
|
2002-09-13 15:29:35 +04:00
|
|
|
mypath, current_info->dirname));
|
1999-06-22 23:56:36 +04:00
|
|
|
#if 0
|
2002-09-13 15:29:35 +04:00
|
|
|
if (!dentry) {
|
|
|
|
DEBUG (1, ("No dir entries (empty dir) cached:'%s', wanted:'%s'\n",
|
|
|
|
current_info->dirname, path));
|
|
|
|
return -1;
|
|
|
|
}
|
1999-06-22 23:56:36 +04:00
|
|
|
#endif
|
2002-09-13 15:29:35 +04:00
|
|
|
if (!single_entry) /* when found, this will be written too */
|
|
|
|
single_entry = g_new (dir_entry, 1);
|
2003-10-28 03:57:02 +03:00
|
|
|
if (smbfs_search_dir_entry (current_info->entries, mypath, buf) == 0) {
|
2002-09-13 15:29:35 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* now try to identify mypath as PARENT dir */
|
|
|
|
{
|
|
|
|
char *mdp;
|
|
|
|
char *mydir;
|
|
|
|
mdp = mydir = g_strdup (current_info->dirname);
|
|
|
|
if ((p = strrchr (mydir, '/')))
|
|
|
|
*p = 0; /* advance util last '/' */
|
|
|
|
if ((p = strrchr (mydir, '/')))
|
|
|
|
mydir = p + 1; /* advance util last '/' */
|
|
|
|
if (strcmp (mydir, mypath) == 0) { /* fake a stat for ".." */
|
|
|
|
memset (buf, 0, sizeof (struct stat));
|
2002-12-20 21:16:45 +03:00
|
|
|
buf->st_mode = (S_IFDIR | S_IRUSR | S_IRGRP | S_IROTH) & myumask;
|
2002-09-13 15:29:35 +04:00
|
|
|
memcpy (&single_entry->my_stat, buf, sizeof (struct stat));
|
|
|
|
g_free (mdp);
|
|
|
|
DEBUG (1, (" PARENT:found in %s\n", current_info->dirname));
|
|
|
|
return 0;
|
1999-04-27 02:38:40 +04:00
|
|
|
}
|
2002-09-13 15:29:35 +04:00
|
|
|
g_free (mdp);
|
|
|
|
}
|
|
|
|
/* now try to identify as CURRENT dir? */
|
|
|
|
{
|
|
|
|
char *dnp = current_info->dirname;
|
2003-10-28 03:57:02 +03:00
|
|
|
DEBUG (6, ("smbfs_get_stat_info: is %s current dir? this dir is: %s\n",
|
2002-09-13 15:29:35 +04:00
|
|
|
mypath, current_info->dirname));
|
|
|
|
if (*dnp == '/')
|
|
|
|
dnp++;
|
|
|
|
else {
|
|
|
|
return -1;
|
1999-04-13 06:10:45 +04:00
|
|
|
}
|
2002-09-13 15:29:35 +04:00
|
|
|
if (strcmp (mypath, dnp) == 0) {
|
|
|
|
memset (buf, 0, sizeof (struct stat));
|
2002-12-20 21:16:45 +03:00
|
|
|
buf->st_mode = (S_IFDIR | S_IRUSR | S_IRGRP | S_IROTH) & myumask;
|
2002-09-13 15:29:35 +04:00
|
|
|
memcpy (&single_entry->my_stat, buf, sizeof (struct stat));
|
|
|
|
DEBUG (1, (" CURRENT:found in %s\n", current_info->dirname));
|
|
|
|
return 0;
|
1999-06-22 23:56:36 +04:00
|
|
|
}
|
2002-09-13 15:29:35 +04:00
|
|
|
}
|
|
|
|
DEBUG (3, ("'%s' not found in current_info '%s'\n", path,
|
|
|
|
current_info->dirname));
|
|
|
|
/* try to find this in the PREVIOUS listing */
|
|
|
|
if (previous_info) {
|
2003-10-28 03:57:02 +03:00
|
|
|
if (smbfs_search_dir_entry (previous_info->entries, mypath, buf) == 0)
|
2002-09-13 15:29:35 +04:00
|
|
|
return 0;
|
|
|
|
DEBUG (3, ("'%s' not found in previous_info '%s'\n", path,
|
|
|
|
previous_info->dirname));
|
|
|
|
}
|
|
|
|
/* try to find this in the SHARE listing */
|
|
|
|
if (current_share_info) {
|
2003-10-28 03:57:02 +03:00
|
|
|
if (smbfs_search_dir_entry (current_share_info->entries, mypath, buf) == 0)
|
2002-09-13 15:29:35 +04:00
|
|
|
return 0;
|
|
|
|
DEBUG (3, ("'%s' not found in share_info '%s'\n", path,
|
|
|
|
current_share_info->dirname));
|
|
|
|
}
|
|
|
|
/* try to find this in the SERVER listing */
|
|
|
|
if (current_server_info) {
|
2003-10-28 03:57:02 +03:00
|
|
|
if (smbfs_search_dir_entry (current_server_info->entries, mypath, buf) == 0)
|
2002-09-13 15:29:35 +04:00
|
|
|
return 0;
|
|
|
|
DEBUG (3, ("'%s' not found in server_info '%s'\n", path,
|
|
|
|
current_server_info->dirname));
|
|
|
|
}
|
|
|
|
/* nothing found. get stat file info from server */
|
2003-10-28 03:57:02 +03:00
|
|
|
return smbfs_get_remote_stat (sc, path, buf);
|
1999-04-13 06:10:45 +04:00
|
|
|
}
|
|
|
|
|
1999-06-22 23:56:36 +04:00
|
|
|
static int
|
2003-11-13 11:29:37 +03:00
|
|
|
smbfs_chdir (struct vfs_class *me, const char *path)
|
1999-06-22 23:56:36 +04:00
|
|
|
{
|
2003-11-13 11:29:37 +03:00
|
|
|
char *remote_dir;
|
|
|
|
smbfs_connection *sc;
|
|
|
|
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
|
|
|
|
2003-11-13 11:29:37 +03:00
|
|
|
DEBUG (3, ("smbfs_chdir(path:%s)\n", path));
|
1999-06-22 23:56:36 +04:00
|
|
|
if (!(remote_dir = smbfs_get_path (&sc, path)))
|
2003-11-13 11:29:37 +03:00
|
|
|
return -1;
|
2001-08-01 14:40:15 +04:00
|
|
|
g_free (remote_dir);
|
2003-11-13 11:29:37 +03:00
|
|
|
|
1999-06-22 23:56:36 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-02-19 15:56:03 +03:00
|
|
|
static int
|
2003-10-28 03:57:02 +03:00
|
|
|
smbfs_loaddir_by_name (struct vfs_class *me, const char *path)
|
1999-06-22 23:56:36 +04:00
|
|
|
{
|
|
|
|
void *info;
|
|
|
|
char *mypath, *p;
|
2001-10-30 18:24:01 +03:00
|
|
|
|
1999-06-22 23:56:36 +04:00
|
|
|
mypath = g_strdup(path);
|
2001-11-05 16:16:17 +03:00
|
|
|
p = strrchr(mypath, '/');
|
2001-10-30 18:24:01 +03:00
|
|
|
|
|
|
|
if (p > mypath)
|
|
|
|
*p = 0;
|
2003-10-28 03:57:02 +03:00
|
|
|
DEBUG(6, ("smbfs_loaddir_by_name(%s)\n", mypath));
|
1999-06-22 23:56:36 +04:00
|
|
|
smbfs_chdir(me, mypath);
|
|
|
|
info = smbfs_opendir (me, mypath);
|
|
|
|
g_free(mypath);
|
|
|
|
if (!info)
|
|
|
|
return -1;
|
|
|
|
smbfs_readdir(info);
|
|
|
|
smbfs_loaddir(info);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-04-27 02:38:40 +04:00
|
|
|
static int
|
2004-08-17 00:26:42 +04:00
|
|
|
smbfs_stat (struct vfs_class * me, const char *path, struct stat *buf)
|
1999-04-13 06:10:45 +04:00
|
|
|
{
|
2002-10-09 17:18:10 +04:00
|
|
|
smbfs_connection *sc;
|
|
|
|
pstring server_url;
|
2002-10-10 14:04:41 +04:00
|
|
|
char *service, *pp, *at;
|
2002-10-09 17:18:10 +04:00
|
|
|
const char *p;
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2002-10-09 17:18:10 +04:00
|
|
|
DEBUG (3, ("smbfs_stat(path:%s)\n", path));
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2002-10-09 17:18:10 +04:00
|
|
|
if (!current_info) {
|
|
|
|
DEBUG (1, ("current_info = NULL: "));
|
2003-10-28 03:57:02 +03:00
|
|
|
if (smbfs_loaddir_by_name (me, path) < 0)
|
2002-10-09 17:18:10 +04:00
|
|
|
return -1;
|
|
|
|
}
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2002-10-09 17:18:10 +04:00
|
|
|
/* check if stating server */
|
|
|
|
p = path;
|
|
|
|
if (strncmp (p, URL_HEADER, HEADER_LEN)) {
|
|
|
|
DEBUG (1, ("'%s' doesnt start with '%s' (length %d)\n",
|
|
|
|
p, URL_HEADER, HEADER_LEN));
|
|
|
|
return -1;
|
|
|
|
}
|
1999-06-22 23:56:36 +04:00
|
|
|
|
2002-10-09 17:18:10 +04:00
|
|
|
p += HEADER_LEN;
|
|
|
|
if (*p == '/')
|
|
|
|
p++;
|
1999-06-22 23:56:36 +04:00
|
|
|
|
2002-10-09 17:18:10 +04:00
|
|
|
pp = strchr (p, '/'); /* advance past next '/' */
|
2002-10-10 14:04:41 +04:00
|
|
|
at = strchr (p, '@');
|
2002-10-09 17:18:10 +04:00
|
|
|
pstrcpy (server_url, URL_HEADER);
|
2002-10-10 14:04:41 +04:00
|
|
|
if (at && at < pp) { /* user@server */
|
|
|
|
char *z = &(server_url[sizeof (server_url) - 1]);
|
|
|
|
const char *s = p;
|
|
|
|
|
|
|
|
at = &(server_url [HEADER_LEN]) + (at - p + 1);
|
|
|
|
if (z > at)
|
|
|
|
z = at;
|
|
|
|
at = &(server_url [HEADER_LEN]);
|
|
|
|
while (at < z)
|
|
|
|
*at++ = *s++;
|
|
|
|
*z = 0;
|
2002-10-09 17:18:10 +04:00
|
|
|
}
|
|
|
|
pstrcat (server_url, current_bucket->host);
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2002-10-09 17:18:10 +04:00
|
|
|
if (!pp) {
|
|
|
|
if (!current_info->server_list) {
|
2003-10-28 03:57:02 +03:00
|
|
|
if (smbfs_loaddir_by_name (me, path) < 0)
|
1999-04-13 06:10:45 +04:00
|
|
|
return -1;
|
|
|
|
}
|
2003-10-28 03:57:02 +03:00
|
|
|
return smbfs_fake_server_stat (server_url, path, buf);
|
2002-10-09 17:18:10 +04:00
|
|
|
}
|
2002-10-11 19:29:55 +04:00
|
|
|
|
2002-10-09 17:18:10 +04:00
|
|
|
if (!strchr (++pp, '/')) {
|
2003-10-28 03:57:02 +03:00
|
|
|
return smbfs_fake_share_stat (server_url, path, buf);
|
2002-10-09 17:18:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* stating inside share at this point */
|
|
|
|
if (!(service = smbfs_get_path (&sc, path))) /* connects if necessary */
|
|
|
|
return -1;
|
|
|
|
{
|
|
|
|
int hostlen = strlen (current_bucket->host);
|
2004-08-17 15:18:47 +04:00
|
|
|
char *ppp = service + strlen (service) - hostlen;
|
2002-10-09 17:18:10 +04:00
|
|
|
char *sp = server_url + strlen (server_url) - hostlen;
|
|
|
|
|
2004-08-17 15:18:47 +04:00
|
|
|
if (strcmp (sp, ppp) == 0) {
|
2002-10-09 17:18:10 +04:00
|
|
|
/* make server name appear as directory */
|
|
|
|
DEBUG (1, ("smbfs_stat: showing server as directory\n"));
|
|
|
|
memset (buf, 0, sizeof (struct stat));
|
2002-12-20 21:16:45 +03:00
|
|
|
buf->st_mode = (S_IFDIR | S_IRUSR | S_IRGRP | S_IROTH) & myumask;
|
2002-10-09 17:18:10 +04:00
|
|
|
g_free (service);
|
|
|
|
return 0;
|
2002-06-21 16:26:45 +04:00
|
|
|
}
|
2002-10-09 17:18:10 +04:00
|
|
|
}
|
|
|
|
/* check if current_info is in share requested */
|
|
|
|
p = service;
|
|
|
|
pp = strchr (p, '/');
|
|
|
|
if (pp) {
|
|
|
|
p = ++pp; /* advance past server name */
|
|
|
|
pp = strchr (p, '/');
|
|
|
|
}
|
|
|
|
if (pp)
|
|
|
|
*pp = 0; /* cut off everthing after service name */
|
|
|
|
else
|
|
|
|
p = IPC; /* browsing for services */
|
|
|
|
pp = current_info->dirname;
|
|
|
|
if (*pp == '/')
|
|
|
|
pp++;
|
|
|
|
if (strncmp (p, pp, strlen (p)) != 0) {
|
|
|
|
DEBUG (6, ("desired '%s' is not loaded, we have '%s'\n", p, pp));
|
2003-10-28 03:57:02 +03:00
|
|
|
if (smbfs_loaddir_by_name (me, path) < 0) {
|
2002-10-09 17:18:10 +04:00
|
|
|
g_free (service);
|
|
|
|
return -1;
|
1999-06-22 23:56:36 +04:00
|
|
|
}
|
2002-10-09 17:18:10 +04:00
|
|
|
DEBUG (6, ("loaded dir: '%s'\n", current_info->dirname));
|
|
|
|
}
|
|
|
|
g_free (service);
|
|
|
|
/* stat dirs & files under shares now */
|
2003-10-28 03:57:02 +03:00
|
|
|
return smbfs_get_stat_info (sc, path, buf);
|
1999-04-13 06:10:45 +04:00
|
|
|
}
|
|
|
|
|
2002-06-21 16:26:45 +04:00
|
|
|
#define smbfs_lstat smbfs_stat /* no symlinks on smb filesystem? */
|
1999-04-13 06:10:45 +04:00
|
|
|
|
1999-04-27 02:38:40 +04:00
|
|
|
static int
|
|
|
|
smbfs_lseek (void *data, off_t offset, int whence)
|
1999-04-13 06:10:45 +04:00
|
|
|
{
|
2003-02-19 15:56:03 +03:00
|
|
|
smbfs_handle *info = (smbfs_handle *) data;
|
|
|
|
size_t size;
|
|
|
|
|
|
|
|
DEBUG (3,
|
|
|
|
("smbfs_lseek(info->nread => %d, offset => %d, whence => %d) \n",
|
|
|
|
(int) info->nread, (int) offset, whence));
|
|
|
|
|
|
|
|
switch (whence) {
|
|
|
|
case SEEK_SET:
|
|
|
|
info->nread = offset;
|
|
|
|
break;
|
|
|
|
case SEEK_CUR:
|
|
|
|
info->nread += offset;
|
|
|
|
break;
|
|
|
|
case SEEK_END:
|
|
|
|
if (!cli_qfileinfo (info->cli, info->fnum,
|
|
|
|
NULL, &size, NULL, NULL, NULL,
|
|
|
|
NULL, NULL) &&
|
|
|
|
!cli_getattrE (info->cli, info->fnum,
|
|
|
|
NULL, &size, NULL, NULL, NULL)) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
info->nread = size + offset;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return info->nread;
|
1999-04-13 06:10:45 +04:00
|
|
|
}
|
|
|
|
|
1999-04-27 02:38:40 +04:00
|
|
|
static int
|
2004-08-17 02:15:28 +04:00
|
|
|
smbfs_mknod (struct vfs_class *me, const char *path, int mode, int dev)
|
1999-04-13 06:10:45 +04:00
|
|
|
{
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
|
|
|
|
1999-06-22 23:56:36 +04:00
|
|
|
DEBUG(3, ("smbfs_mknod(path:%s, mode:%d, dev:%d)\n", path, mode, dev));
|
1999-04-13 06:10:45 +04:00
|
|
|
my_errno = EOPNOTSUPP;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
1999-04-27 02:38:40 +04:00
|
|
|
static int
|
2004-08-17 02:15:28 +04:00
|
|
|
smbfs_mkdir (struct vfs_class * me, const char *path, mode_t mode)
|
1999-04-13 06:10:45 +04:00
|
|
|
{
|
2003-02-19 15:56:03 +03:00
|
|
|
smbfs_connection *sc;
|
|
|
|
char *remote_file;
|
2004-08-19 16:05:54 +04:00
|
|
|
char *cpath;
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
|
|
|
|
2003-02-19 15:56:03 +03:00
|
|
|
DEBUG (3, ("smbfs_mkdir(path:%s, mode:%d)\n", path, (int) mode));
|
|
|
|
if ((remote_file = smbfs_get_path (&sc, path)) == 0)
|
|
|
|
return -1;
|
|
|
|
g_free (remote_file);
|
2004-08-19 16:05:54 +04:00
|
|
|
cpath = smbfs_convert_path (path, FALSE);
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2004-08-17 02:15:28 +04:00
|
|
|
if (!cli_mkdir (sc->cli, cpath)) {
|
2003-02-19 15:56:03 +03:00
|
|
|
my_errno = cli_error (sc->cli, NULL, &err, NULL);
|
2003-10-26 07:47:20 +03:00
|
|
|
message (1, MSG_ERROR, _(" Error %s creating directory %s "),
|
2004-08-17 02:15:28 +04:00
|
|
|
cli_errstr (sc->cli), CNV_LANG (cpath));
|
|
|
|
g_free (cpath);
|
2003-02-19 15:56:03 +03:00
|
|
|
return -1;
|
|
|
|
}
|
2004-08-17 02:15:28 +04:00
|
|
|
g_free (cpath);
|
2003-02-19 15:56:03 +03:00
|
|
|
return 0;
|
1999-04-13 06:10:45 +04:00
|
|
|
}
|
|
|
|
|
1999-04-27 02:38:40 +04:00
|
|
|
static int
|
2004-08-17 02:15:28 +04:00
|
|
|
smbfs_rmdir (struct vfs_class *me, const char *path)
|
1999-04-13 06:10:45 +04:00
|
|
|
{
|
|
|
|
smbfs_connection *sc;
|
|
|
|
char *remote_file;
|
2004-08-19 16:05:54 +04:00
|
|
|
char *cpath;
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
|
|
|
|
1999-06-22 23:56:36 +04:00
|
|
|
DEBUG(3, ("smbfs_rmdir(path:%s)\n", path));
|
1999-04-13 06:10:45 +04:00
|
|
|
if ((remote_file = smbfs_get_path (&sc, path)) == 0)
|
|
|
|
return -1;
|
2001-08-01 14:40:15 +04:00
|
|
|
g_free (remote_file);
|
2004-08-19 16:05:54 +04:00
|
|
|
cpath = smbfs_convert_path (path, FALSE);
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2004-08-17 02:15:28 +04:00
|
|
|
if (!cli_rmdir(sc->cli, cpath)) {
|
1999-06-22 23:56:36 +04:00
|
|
|
my_errno = cli_error(sc->cli, NULL, &err, NULL);
|
2003-10-26 07:47:20 +03:00
|
|
|
message (1, MSG_ERROR, _(" Error %s removing directory %s "),
|
2004-08-17 02:15:28 +04:00
|
|
|
cli_errstr(sc->cli), CNV_LANG(cpath));
|
|
|
|
g_free (cpath);
|
1999-04-13 06:10:45 +04:00
|
|
|
return -1;
|
|
|
|
}
|
2001-08-06 19:36:33 +04:00
|
|
|
|
2004-08-17 02:15:28 +04:00
|
|
|
g_free (cpath);
|
2001-08-06 19:36:33 +04:00
|
|
|
return 0;
|
1999-04-13 06:10:45 +04:00
|
|
|
}
|
|
|
|
|
1999-04-27 02:38:40 +04:00
|
|
|
static int
|
2004-08-17 02:15:28 +04:00
|
|
|
smbfs_link (struct vfs_class *me, const char *p1, const char *p2)
|
1999-04-13 06:10:45 +04:00
|
|
|
{
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
|
|
|
|
2003-01-24 23:55:55 +03:00
|
|
|
DEBUG (3, ("smbfs_link(p1:%s, p2:%s)\n", p1, p2));
|
|
|
|
my_errno = EOPNOTSUPP;
|
1999-04-13 06:10:45 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
1999-04-27 02:38:40 +04:00
|
|
|
static void
|
|
|
|
smbfs_free (vfsid id)
|
1999-04-13 06:10:45 +04:00
|
|
|
{
|
2003-01-24 23:55:55 +03:00
|
|
|
DEBUG (3, ("smbfs_free(%p)\n", id));
|
2003-10-28 03:57:02 +03:00
|
|
|
smbfs_auth_free_all ();
|
1999-04-13 06:10:45 +04:00
|
|
|
}
|
|
|
|
|
2001-03-04 21:55:17 +03:00
|
|
|
/* Gives up on a socket and reopens the connection, the child own the socket
|
1999-04-13 06:10:45 +04:00
|
|
|
* now
|
|
|
|
*/
|
|
|
|
static void
|
2004-08-17 02:15:28 +04:00
|
|
|
smbfs_forget (const char *path)
|
1999-04-13 06:10:45 +04:00
|
|
|
{
|
2001-03-04 21:55:17 +03:00
|
|
|
char *host, *user, *p;
|
2004-09-28 13:30:53 +04:00
|
|
|
int port, i;
|
1999-04-13 06:10:45 +04:00
|
|
|
|
1999-06-22 23:56:36 +04:00
|
|
|
if (strncmp (path, URL_HEADER, HEADER_LEN))
|
2004-09-28 13:30:53 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
DEBUG (3, ("smbfs_forget(path:%s)\n", path));
|
1999-04-13 06:10:45 +04:00
|
|
|
|
|
|
|
path += 6;
|
|
|
|
if (path[0] == '/' && path[1] == '/')
|
|
|
|
path += 2;
|
|
|
|
|
2001-08-01 16:24:35 +04:00
|
|
|
if ((p = smbfs_get_host_and_username (&path, &host, &user, &port, NULL))) {
|
2001-08-01 14:40:15 +04:00
|
|
|
g_free (p);
|
|
|
|
for (i = 0; i < SMBFS_MAX_CONNECTIONS; i++) {
|
2004-09-28 13:30:53 +04:00
|
|
|
if (smbfs_connections[i].cli
|
|
|
|
&& (strcmp (host, smbfs_connections[i].host) == 0)
|
|
|
|
&& (strcmp (user, smbfs_connections[i].user) == 0)
|
|
|
|
&& (port == smbfs_connections[i].port)) {
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2004-09-28 13:30:53 +04:00
|
|
|
/* close socket: the child owns it now */
|
|
|
|
cli_shutdown (smbfs_connections[i].cli);
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2004-09-28 13:30:53 +04:00
|
|
|
/* reopen the connection */
|
|
|
|
smbfs_connections[i].cli =
|
|
|
|
smbfs_do_connect (host, smbfs_connections[i].service);
|
|
|
|
}
|
2001-08-01 14:40:15 +04:00
|
|
|
}
|
1999-04-13 06:10:45 +04:00
|
|
|
}
|
|
|
|
g_free (host);
|
|
|
|
g_free (user);
|
|
|
|
}
|
|
|
|
|
2003-10-16 20:12:19 +04:00
|
|
|
static int
|
2004-08-17 02:15:28 +04:00
|
|
|
smbfs_setctl (struct vfs_class *me, const char *path, int ctlop, void *arg)
|
1999-04-13 06:10:45 +04:00
|
|
|
{
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
|
|
|
(void) arg;
|
|
|
|
|
2003-10-16 20:12:19 +04:00
|
|
|
DEBUG (3, ("smbfs_setctl(path:%s, ctlop:%d)\n", path, ctlop));
|
1999-04-13 06:10:45 +04:00
|
|
|
switch (ctlop) {
|
2003-10-16 20:12:19 +04:00
|
|
|
case VFS_SETCTL_FORGET:
|
2003-10-28 03:57:02 +03:00
|
|
|
smbfs_forget (path);
|
2003-10-16 20:12:19 +04:00
|
|
|
return 0;
|
1999-04-13 06:10:45 +04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-04-27 02:38:40 +04:00
|
|
|
static smbfs_handle *
|
2003-10-28 03:57:02 +03:00
|
|
|
smbfs_open_readwrite (smbfs_handle *remote_handle, char *rname, int flags, int mode)
|
1999-04-27 02:38:40 +04:00
|
|
|
{
|
2003-04-03 14:45:03 +04:00
|
|
|
size_t size;
|
|
|
|
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) mode;
|
|
|
|
|
2003-04-03 14:45:03 +04:00
|
|
|
if (flags & O_TRUNC) /* if it exists truncate to zero */
|
|
|
|
DEBUG (3, ("smbfs_open: O_TRUNC\n"));
|
|
|
|
|
|
|
|
remote_handle->fnum =
|
2004-10-25 12:15:19 +04:00
|
|
|
#if 1 /* Don't play with flags, it is cli_open() headache */
|
|
|
|
cli_open (remote_handle->cli, rname, flags, DENY_NONE);
|
|
|
|
#else /* What's a reasons to has this code ? */
|
2004-08-26 23:51:38 +04:00
|
|
|
cli_open (remote_handle->cli, rname, ((flags & O_CREAT)
|
|
|
|
|| (flags ==
|
|
|
|
(O_WRONLY | O_APPEND))) ?
|
|
|
|
flags : O_RDONLY, DENY_NONE);
|
2004-10-25 12:15:19 +04:00
|
|
|
#endif
|
2003-04-03 14:45:03 +04:00
|
|
|
if (remote_handle->fnum == -1) {
|
2003-10-26 07:47:20 +03:00
|
|
|
message (1, MSG_ERROR, _(" %s opening remote file %s "),
|
2003-04-03 14:45:03 +04:00
|
|
|
cli_errstr (remote_handle->cli), CNV_LANG (rname));
|
|
|
|
DEBUG (1, ("smbfs_open(rname:%s) error:%s\n",
|
|
|
|
rname, cli_errstr (remote_handle->cli)));
|
|
|
|
my_errno = cli_error (remote_handle->cli, NULL, &err, NULL);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & O_CREAT)
|
|
|
|
return remote_handle;
|
|
|
|
|
|
|
|
if (!cli_qfileinfo (remote_handle->cli, remote_handle->fnum,
|
|
|
|
&remote_handle->attr, &size, NULL, NULL, NULL, NULL,
|
|
|
|
NULL)
|
|
|
|
&& !cli_getattrE (remote_handle->cli, remote_handle->fnum,
|
|
|
|
&remote_handle->attr, &size, NULL, NULL, NULL)) {
|
2003-10-26 07:47:20 +03:00
|
|
|
message (1, MSG_ERROR, " getattrib: %s ",
|
2003-04-03 14:45:03 +04:00
|
|
|
cli_errstr (remote_handle->cli));
|
|
|
|
DEBUG (1,
|
|
|
|
("smbfs_open(rname:%s) getattrib:%s\n", rname,
|
|
|
|
cli_errstr (remote_handle->cli)));
|
|
|
|
my_errno = cli_error (remote_handle->cli, NULL, &err, NULL);
|
|
|
|
cli_close (remote_handle->cli, remote_handle->fnum);
|
|
|
|
return NULL;
|
1999-04-13 06:10:45 +04:00
|
|
|
}
|
|
|
|
|
2004-08-26 23:51:38 +04:00
|
|
|
if ((flags == (O_WRONLY | O_APPEND)) /* file.c:copy_file_file() -> do_append */
|
|
|
|
&& smbfs_lseek (remote_handle, 0, SEEK_END) == -1) {
|
|
|
|
cli_close (remote_handle->cli, remote_handle->fnum);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1999-04-13 06:10:45 +04:00
|
|
|
return remote_handle;
|
|
|
|
}
|
|
|
|
|
1999-04-27 02:38:40 +04:00
|
|
|
static void *
|
2003-10-28 05:10:33 +03:00
|
|
|
smbfs_open (struct vfs_class *me, const char *file, int flags, int mode)
|
1999-04-13 06:10:45 +04:00
|
|
|
{
|
2004-08-19 16:05:54 +04:00
|
|
|
char *remote_file;
|
2001-08-01 14:40:15 +04:00
|
|
|
void *ret;
|
1999-04-13 06:10:45 +04:00
|
|
|
smbfs_connection *sc;
|
2001-08-01 14:40:15 +04:00
|
|
|
smbfs_handle *remote_handle;
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
|
|
|
|
2003-04-03 14:45:03 +04:00
|
|
|
DEBUG(3, ("smbfs_open(file:%s, flags:%d, mode:%o)\n", file, flags, mode));
|
1999-04-13 06:10:45 +04:00
|
|
|
|
|
|
|
if (!(remote_file = smbfs_get_path (&sc, file)))
|
2001-08-01 14:40:15 +04:00
|
|
|
return 0;
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2004-08-19 16:05:54 +04:00
|
|
|
remote_file = free_after(smbfs_convert_path (remote_file, FALSE), remote_file);
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2001-08-01 14:40:15 +04:00
|
|
|
remote_handle = g_new (smbfs_handle, 2);
|
1999-04-13 06:10:45 +04:00
|
|
|
remote_handle->cli = sc->cli;
|
2001-08-01 14:40:15 +04:00
|
|
|
remote_handle->nread = 0;
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2003-10-28 03:57:02 +03:00
|
|
|
ret = smbfs_open_readwrite (remote_handle, remote_file, flags, mode);
|
2001-08-01 14:40:15 +04:00
|
|
|
|
|
|
|
g_free (remote_file);
|
2003-04-03 14:45:03 +04:00
|
|
|
if (!ret)
|
|
|
|
g_free (remote_handle);
|
2001-08-01 14:40:15 +04:00
|
|
|
|
|
|
|
return ret;
|
1999-04-13 06:10:45 +04:00
|
|
|
}
|
|
|
|
|
1999-04-27 02:38:40 +04:00
|
|
|
static int
|
2004-08-17 02:15:28 +04:00
|
|
|
smbfs_unlink (struct vfs_class *me, const char *path)
|
1999-04-13 06:10:45 +04:00
|
|
|
{
|
|
|
|
smbfs_connection *sc;
|
2004-08-19 16:05:54 +04:00
|
|
|
char *remote_file;
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
|
|
|
|
1999-04-13 06:10:45 +04:00
|
|
|
if ((remote_file = smbfs_get_path (&sc, path)) == 0)
|
2001-08-01 14:40:15 +04:00
|
|
|
return -1;
|
2001-08-06 19:36:33 +04:00
|
|
|
|
2004-08-19 16:05:54 +04:00
|
|
|
remote_file = free_after(smbfs_convert_path (remote_file, FALSE), remote_file);
|
1999-04-13 06:10:45 +04:00
|
|
|
|
|
|
|
if (!cli_unlink(sc->cli, remote_file)) {
|
2003-10-26 07:47:20 +03:00
|
|
|
message (1, MSG_ERROR, _(" %s removing remote file %s "),
|
1999-04-13 06:10:45 +04:00
|
|
|
cli_errstr(sc->cli), CNV_LANG(remote_file));
|
2001-08-01 14:40:15 +04:00
|
|
|
g_free (remote_file);
|
|
|
|
return -1;
|
1999-04-13 06:10:45 +04:00
|
|
|
}
|
2001-08-01 14:40:15 +04:00
|
|
|
g_free (remote_file);
|
1999-04-13 06:10:45 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-04-27 02:38:40 +04:00
|
|
|
static int
|
2004-08-17 02:15:28 +04:00
|
|
|
smbfs_rename (struct vfs_class *me, const char *a, const char *b)
|
1999-04-13 06:10:45 +04:00
|
|
|
{
|
|
|
|
smbfs_connection *sc;
|
2001-08-01 14:40:15 +04:00
|
|
|
char *ra, *rb;
|
|
|
|
int retval;
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
|
|
|
|
1999-04-13 06:10:45 +04:00
|
|
|
if ((ra = smbfs_get_path (&sc, a)) == 0)
|
2001-08-01 14:40:15 +04:00
|
|
|
return -1;
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2001-08-01 14:40:15 +04:00
|
|
|
if ((rb = smbfs_get_path (&sc, b)) == 0) {
|
|
|
|
g_free (ra);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2004-08-19 16:05:54 +04:00
|
|
|
ra = free_after (smbfs_convert_path (ra, FALSE), ra);
|
|
|
|
rb = free_after (smbfs_convert_path (rb, FALSE), rb);
|
2001-08-01 14:40:15 +04:00
|
|
|
|
|
|
|
retval = cli_rename(sc->cli, ra, rb);
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2001-08-01 14:40:15 +04:00
|
|
|
g_free (ra);
|
|
|
|
g_free (rb);
|
|
|
|
|
|
|
|
if (!retval) {
|
2003-10-26 07:47:20 +03:00
|
|
|
message (1, MSG_ERROR, _(" %s renaming files\n"),
|
1999-04-13 06:10:45 +04:00
|
|
|
cli_errstr(sc->cli));
|
2001-08-01 14:40:15 +04:00
|
|
|
return -1;
|
1999-04-13 06:10:45 +04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1999-04-27 02:38:40 +04:00
|
|
|
static int
|
|
|
|
smbfs_fstat (void *data, struct stat *buf)
|
1999-04-13 06:10:45 +04:00
|
|
|
{
|
|
|
|
smbfs_handle *remote_handle = (smbfs_handle *)data;
|
|
|
|
|
1999-06-22 23:56:36 +04:00
|
|
|
DEBUG(3, ("smbfs_fstat(fnum:%d)\n", remote_handle->fnum));
|
1999-04-13 06:10:45 +04:00
|
|
|
|
2003-10-28 03:57:02 +03:00
|
|
|
/* use left over from previous smbfs_get_remote_stat, if available */
|
1999-04-13 06:10:45 +04:00
|
|
|
if (single_entry)
|
|
|
|
memcpy(buf, &single_entry->my_stat, sizeof(struct stat));
|
1999-07-13 06:36:32 +04:00
|
|
|
else { /* single_entry not set up: bug */
|
2001-08-03 14:19:45 +04:00
|
|
|
my_errno = EFAULT;
|
1999-07-13 06:36:32 +04:00
|
|
|
return -EFAULT;
|
|
|
|
}
|
1999-04-13 06:10:45 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-10-13 02:25:53 +04:00
|
|
|
void
|
|
|
|
init_smbfs (void)
|
|
|
|
{
|
|
|
|
vfs_smbfs_ops.name = "smbfs";
|
|
|
|
vfs_smbfs_ops.prefix = "smb:";
|
|
|
|
vfs_smbfs_ops.flags = VFSF_NOLINKS;
|
|
|
|
vfs_smbfs_ops.init = smbfs_init;
|
|
|
|
vfs_smbfs_ops.fill_names = smbfs_fill_names;
|
|
|
|
vfs_smbfs_ops.open = smbfs_open;
|
|
|
|
vfs_smbfs_ops.close = smbfs_close;
|
|
|
|
vfs_smbfs_ops.read = smbfs_read;
|
|
|
|
vfs_smbfs_ops.write = smbfs_write;
|
|
|
|
vfs_smbfs_ops.opendir = smbfs_opendir;
|
|
|
|
vfs_smbfs_ops.readdir = smbfs_readdir;
|
|
|
|
vfs_smbfs_ops.closedir = smbfs_closedir;
|
|
|
|
vfs_smbfs_ops.stat = smbfs_stat;
|
|
|
|
vfs_smbfs_ops.lstat = smbfs_lstat;
|
|
|
|
vfs_smbfs_ops.fstat = smbfs_fstat;
|
|
|
|
vfs_smbfs_ops.chmod = smbfs_chmod;
|
|
|
|
vfs_smbfs_ops.chown = smbfs_chown;
|
|
|
|
vfs_smbfs_ops.utime = smbfs_utime;
|
|
|
|
vfs_smbfs_ops.readlink = smbfs_readlink;
|
|
|
|
vfs_smbfs_ops.symlink = smbfs_symlink;
|
|
|
|
vfs_smbfs_ops.link = smbfs_link;
|
|
|
|
vfs_smbfs_ops.unlink = smbfs_unlink;
|
|
|
|
vfs_smbfs_ops.rename = smbfs_rename;
|
|
|
|
vfs_smbfs_ops.chdir = smbfs_chdir;
|
|
|
|
vfs_smbfs_ops.ferrno = smbfs_errno;
|
|
|
|
vfs_smbfs_ops.lseek = smbfs_lseek;
|
|
|
|
vfs_smbfs_ops.mknod = smbfs_mknod;
|
|
|
|
vfs_smbfs_ops.free = smbfs_free;
|
|
|
|
vfs_smbfs_ops.mkdir = smbfs_mkdir;
|
|
|
|
vfs_smbfs_ops.rmdir = smbfs_rmdir;
|
|
|
|
vfs_smbfs_ops.setctl = smbfs_setctl;
|
|
|
|
vfs_register_class (&vfs_smbfs_ops);
|
|
|
|
}
|