1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-24 21:34:56 +03:00

r15237: Add primitive Samba 4 backend for cifs posix clients (based on simple backend).

(This used to be commit f054e1a9e6)
This commit is contained in:
Steve French 2006-04-25 11:36:15 +00:00 committed by Gerald (Jerry) Carter
parent 5c818491fc
commit 1e8e6aeb6f
5 changed files with 1265 additions and 1 deletions

View File

@ -0,0 +1,10 @@
This module (ntvfs 'simple') provides a very, very simple posix backend.
WARNING: All file access is done as user 'root'!!!
Only use this module for testing, with only test data!!!
For activating this module use:
[testshare]
path = /tmp/testshare
nfvfs handler = simple

View File

@ -0,0 +1,35 @@
struct svfs_private {
/* the base directory */
char *connectpath;
/* a linked list of open searches */
struct search_state *search;
/* next available search handle */
uint16_t next_search_handle;
struct svfs_file *open_files;
};
struct svfs_dir {
uint_t count;
char *unix_dir;
struct svfs_dirfile {
char *name;
struct stat st;
} *files;
};
struct svfs_file {
struct svfs_file *next, *prev;
int fd;
char *name;
};
struct search_state {
struct search_state *next, *prev;
uint16_t handle;
uint_t current_index;
struct svfs_dir *dir;
};

View File

@ -0,0 +1,185 @@
/*
Unix SMB/CIFS implementation.
simple NTVFS filesystem backend
Copyright (C) Andrew Tridgell 2003
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.
*/
/*
utility functions for simple backend
*/
#include "includes.h"
#include "system/filesys.h"
#include "cvfs.h"
#include "system/time.h"
#include "system/dir.h"
#include "ntvfs/ntvfs.h"
/*
convert a windows path to a unix path - don't do any manging or case sensitive handling
*/
char *cvfs_unix_path(struct ntvfs_module_context *ntvfs,
struct ntvfs_request *req, const char *name)
{
struct svfs_private *private = ntvfs->private_data;
char *ret;
if (*name != '\\') {
ret = talloc_asprintf(req, "%s/%s", private->connectpath, name);
} else {
ret = talloc_asprintf(req, "%s%s", private->connectpath, name);
}
all_string_sub(ret, "\\", "/", 0);
strlower(ret + strlen(private->connectpath));
return ret;
}
/*
read a directory and find all matching file names and stat info
returned names are separate unix and DOS names. The returned names
are relative to the directory
*/
struct svfs_dir *cvfs_list_unix(TALLOC_CTX *mem_ctx, struct ntvfs_request *req, const char *unix_path)
{
char *p, *mask;
struct svfs_dir *dir;
DIR *odir;
struct dirent *dent;
uint_t allocated = 0;
char *low_mask;
dir = talloc(mem_ctx, struct svfs_dir);
if (!dir) { return NULL; }
dir->count = 0;
dir->files = 0;
/* find the base directory */
p = strrchr(unix_path, '/');
if (!p) { return NULL; }
dir->unix_dir = talloc_strndup(mem_ctx, unix_path, PTR_DIFF(p, unix_path));
if (!dir->unix_dir) { return NULL; }
/* the wildcard pattern is the last part */
mask = p+1;
low_mask = talloc_strdup(mem_ctx, mask);
if (!low_mask) { return NULL; }
strlower(low_mask);
odir = opendir(dir->unix_dir);
if (!odir) { return NULL; }
while ((dent = readdir(odir))) {
uint_t i = dir->count;
char *full_name;
char *low_name;
if (strchr(dent->d_name, ':') && !strchr(unix_path, ':')) {
/* don't show streams in dir listing */
continue;
}
low_name = talloc_strdup(mem_ctx, dent->d_name);
if (!low_name) { continue; }
strlower(low_name);
/* check it matches the wildcard pattern */
if (ms_fnmatch(low_mask, low_name, PROTOCOL_NT1) != 0) {
continue;
}
if (dir->count >= allocated) {
allocated = (allocated + 100) * 1.2;
dir->files = talloc_realloc(dir, dir->files, struct svfs_dirfile, allocated);
if (!dir->files) {
closedir(odir);
return NULL;
}
}
dir->files[i].name = low_name;
if (!dir->files[i].name) { continue; }
asprintf(&full_name, "%s/%s", dir->unix_dir, dir->files[i].name);
if (!full_name) { continue; }
if (stat(full_name, &dir->files[i].st) == 0) {
dir->count++;
}
free(full_name);
}
closedir(odir);
return dir;
}
/*
read a directory and find all matching file names and stat info
returned names are separate unix and DOS names. The returned names
are relative to the directory
*/
struct svfs_dir *cvfs_list(struct ntvfs_module_context *ntvfs, struct ntvfs_request *req, const char *pattern)
{
struct svfs_private *private = ntvfs->private_data;
char *unix_path;
unix_path = cvfs_unix_path(ntvfs, req, pattern);
if (!unix_path) { return NULL; }
return cvfs_list_unix(private, req, unix_path);
}
/*******************************************************************
set the time on a file via file descriptor
*******************************************************************/
int cvfs_file_utime(int fd, struct utimbuf *times)
{
char *fd_path = NULL;
int ret;
asprintf(&fd_path, "/proc/self/%d", fd);
if (!fd_path) {
errno = ENOMEM;
return -1;
}
ret = utime(fd_path, times);
free(fd_path);
return ret;
}
/*
map a unix file attrib to a DOS attribute
*/
uint16_t cvfs_unix_to_dos_attrib(mode_t mode)
{
uint16_t ret = 0;
if (S_ISDIR(mode)) ret |= FILE_ATTRIBUTE_DIRECTORY;
if (!(mode & S_IWUSR)) ret |= FILE_ATTRIBUTE_READONLY;
return ret;
}

File diff suppressed because it is too large Load Diff

View File

@ -25,7 +25,19 @@ PRIVATE_PROTO_HEADER = simple/proto.h
OBJ_FILES = \
simple/vfs_simple.o \
simple/svfs_util.o
# End MODULE ntvfs_cifs
# End MODULE ntvfs_simple
################################################
################################################
# Start MODULE ntvfs_cifs_posix_cli
[MODULE::ntvfs_cifs_posix]
INIT_FUNCTION = ntvfs_cifs_posix_init
SUBSYSTEM = ntvfs
PRIVATE_PROTO_HEADER = cifs_posix_cli/proto.h
OBJ_FILES = \
cifs_posix_cli/vfs_simple.o \
cifs_posix_cli/svfs_util.o
# End MODULE ntvfs_cifs_posix_cli
################################################
################################################