MSDfs Samba2.2.4 lower case ??

Kevin Wheatley hxpro at cinesite.co.uk
Wed May 8 06:52:03 GMT 2002


Hi,

I've been writing a VFS module that provides an alternative syntax for
msdfs links on the unix side and wondered why the strlower() call is
needed in msdfs/msdfs.c line 168, I need my redirects to contain mixed
case letters. It appears to work in my initial testing without it.

I've attatched the VFS code I'm writing so you can see what the code
does ... (not much really !) but it's quite useful for us UNIX centric
places that have existing NFS mounts... My end goal is to have a DFS
share which is a directory tree of links all pointing to other
servers,

e.g.

/dfsroot/foo/bar/tree/TR/ -> /hosts/machine1/path123/TR
/dfsroot/foo/bar/ABCDE/ -> /hosts/machine2/path456/ABCDE

and

[dfs]
        path = /dfsroot
        vfs object = /usr/samba/lib/vdisk.so
        msdfs root = yes

Thanks

Kevin

-- 
| Kevin Wheatley              | These are the opinions of nobody   |
| Special Services (Projects) | and are not shared by my employers |
| Cinesite Digital Studios    |                                    |
-------------- next part --------------
/* 
 * vidsk VFS module for samba.  /hosts -> msdfs convertor
 *
 * Copyright (C) 2002, Jeremy Allison - original VFS example
 * Copyright (C) 2002, Kevin Wheatley - turned into vdisk remapper
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *  
 * 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 General Public License for more details.
 *  
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/*
 * Version 0.1
 *
 * Overides the read link and maps links of the form:
 *    /hosts/<server>/<share>/<path>
 *
 * into
 *
 *    msdfs:server\share\path
 *
 */

#include "config.h"
#include <stdio.h>
#include <sys/stat.h>
#ifdef HAVE_UTIME_H
#include <utime.h>
#endif
#ifdef HAVE_DIRENT_H
#include <dirent.h>
#endif
#include <syslog.h>
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
#include <errno.h>
#include <string.h>
#include <includes.h>
#include <vfs.h>
 
/* VFS operations */

extern struct vfs_ops default_vfs_ops;   /* For passthrough operation */
static BOOL vdisk_readlink(struct connection_struct *conn, const char *path, char *buf, size_t bufsiz);

struct vfs_ops vdisk_ops = {
    
	/* Disk operations */

	NULL,				/* connect */
	NULL,				/* disconnect */
	NULL,				/* disk free */

	/* Directory operations */

	NULL,				/* opendir */
	NULL,				/* readdir */
	NULL,				/* mkdir */
	NULL,				/* rmdir */
	NULL,				/* closedir */

	/* File operations */

	NULL,				/* open */
	NULL,				/* close */
	NULL,				/* read  */
	NULL,				/* write */
	NULL,				/* lseek */
	NULL,				/* rename */
	NULL,				/* fsync */
	NULL,				/* stat  */
	NULL,				/* fstat */
	NULL,				/* lstat */
	NULL,				/* unlink */
	NULL,				/* chmod */
	NULL,				/* fchmod */
	NULL,				/* chown */
	NULL,				/* fchown */
	NULL,				/* chdir */
	NULL,				/* getwd */
	NULL,				/* utime */
	NULL,				/* ftruncate */
	NULL,				/* lock */
	NULL,				/* symlink */
	vdisk_readlink,			/* readlink */
	NULL,				/* link */
	NULL,				/* mknod */
	NULL,				/* realpath */
	NULL,				/* fget_nt_acl */
	NULL,				/* get_nt_acl */
	NULL,				/* fset_nt_acl */
	NULL,				/* set_nt_acl */

	NULL,				/* chmod_acl */
	NULL,				/* fchmod_acl */

	NULL,				/* sys_acl_get_entry */
	NULL,				/* sys_acl_get_tag_type */
	NULL,				/* sys_acl_get_permset */
	NULL,				/* sys_acl_get_qualifier */
	NULL,				/* sys_acl_get_file */
	NULL,				/* sys_acl_get_fd */
	NULL,				/* sys_acl_clear_perms */
	NULL,				/* sys_acl_add_perm */
	NULL,				/* sys_acl_to_text */
	NULL,				/* sys_acl_init */
	NULL,				/* sys_acl_create_entry */
	NULL,				/* sys_acl_set_tag_type */
	NULL,				/* sys_acl_set_qualifier */
	NULL,				/* sys_acl_set_permset */
	NULL,				/* sys_acl_valid */
	NULL,				/* sys_acl_set_file */
	NULL,				/* sys_acl_set_fd */
	NULL,				/* sys_acl_delete_def_file */
	NULL,				/* sys_acl_get_perm */
	NULL,				/* sys_acl_free_text */
	NULL,				/* sys_acl_free_acl */
	NULL				/* sys_acl_free_qualifier */
};

/* VFS initialisation function.  Return initialised vfs_ops structure
   back to SAMBA. */

struct vfs_ops *vfs_init(int *vfs_version, struct vfs_ops *def_vfs_ops)
{
	struct vfs_ops tmp_ops;

	*vfs_version = SMB_VFS_INTERFACE_VERSION;
	memcpy(&tmp_ops, def_vfs_ops, sizeof(struct vfs_ops));
	tmp_ops.readlink = vdisk_readlink;
	memcpy(&vdisk_ops, &tmp_ops, sizeof(struct vfs_ops));
	return &vdisk_ops;
}

static BOOL vdisk_readlink(struct connection_struct *conn, const char *path, char *buf, size_t bufsiz)
{
#define HOSTS_PREFIX_LENGTH 7
#define MSDFS_PREFIX_LENGTH 6

	int result;
	char *temp;
	char *p;

	result = default_vfs_ops.readlink(conn, path, buf, bufsiz);
	if ((result > HOSTS_PREFIX_LENGTH) && (!strncmp(buf, "/hosts/", HOSTS_PREFIX_LENGTH))) {
	        if (!(temp = malloc(result + 1)))
			return -1;
		strncpy(temp, buf, result);
        	temp[result] = '\0';		/* ensure null terminated */
		strncpy(buf, "msdfs:", bufsiz);
		strncat(buf, temp + HOSTS_PREFIX_LENGTH, bufsiz - MSDFS_PREFIX_LENGTH); 
		while (p = strchr(buf, '/'))
			*p = '\\';		/* Replace slashes */
		DEBUG(10,("vdisk_readlink: link %s path %s (%d) -> %s\n", path, temp, result, buf));
		free(temp);
		result = strlen(buf);
	}
	return result;
}


More information about the samba-technical mailing list