summaryrefslogtreecommitdiff
path: root/examples/VFS
diff options
context:
space:
mode:
Diffstat (limited to 'examples/VFS')
-rw-r--r--examples/VFS/.cvsignore1
-rw-r--r--examples/VFS/Makefile21
-rw-r--r--examples/VFS/README31
-rw-r--r--examples/VFS/audit.c208
-rw-r--r--examples/VFS/skel.c225
5 files changed, 486 insertions, 0 deletions
diff --git a/examples/VFS/.cvsignore b/examples/VFS/.cvsignore
new file mode 100644
index 0000000000..9c0e66ecaf
--- /dev/null
+++ b/examples/VFS/.cvsignore
@@ -0,0 +1 @@
+.libs
diff --git a/examples/VFS/Makefile b/examples/VFS/Makefile
new file mode 100644
index 0000000000..fb9976893b
--- /dev/null
+++ b/examples/VFS/Makefile
@@ -0,0 +1,21 @@
+#
+# Makefile for samba-vfs examples
+#
+# $Id: Makefile,v 1.1 2000/02/03 04:40:56 tpot Exp $
+#
+
+# Variables
+
+SAMBA_SRC = ../../source
+
+CFLAGS = -I$(SAMBA_SRC)/include
+CC = gcc
+
+VFS_OBJS = audit.o skel.o
+
+# Targets
+
+default: $(VFS_OBJS)
+
+clean:
+ rm -f core $(VFS_OBJS) *~ *% *.bak
diff --git a/examples/VFS/README b/examples/VFS/README
new file mode 100644
index 0000000000..dc7398892d
--- /dev/null
+++ b/examples/VFS/README
@@ -0,0 +1,31 @@
+README for Samba Virtual File System (VFS) Examples
+===================================================
+
+This directory contains some sample code to demonstrate VFS
+construction. The following VFS modules are given:
+
+ skel
+ A skeleton VFS module. When used, this module simply
+ passes all requests back to the disk functions (i.e it
+ operates as a passthrough filter). It should be
+ useful as a starting point for developing new VFS
+ modules.
+
+ audit
+ A simple module to audit file access to the syslog
+ facility. The following operations are logged: share
+ connect/disconnect, directory opens/create/remove,
+ file open/close/rename/unlink/chmod.
+
+ streamer
+ Stream file writes to a network address instead of to
+ disk.
+
+ perlfs
+ A wrapper for writing Samba VFS modules in Perl.
+
+The modules need only to be compiled with -I/samba/source/dir added to
+CFLAGS.
+
+Further documentation on writing VFS modules for Samba can be found in
+docs directory of the Samba source distribution.
diff --git a/examples/VFS/audit.c b/examples/VFS/audit.c
new file mode 100644
index 0000000000..3d84c579c7
--- /dev/null
+++ b/examples/VFS/audit.c
@@ -0,0 +1,208 @@
+/*
+ * Auditing VFS module for samba. Log select file operations to syslog
+ * facility.
+ *
+ * Copyright (C) Tim Potter, 1999
+ *
+ * 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.
+ *
+ * $Id: audit.c,v 1.1 2000/02/03 04:40:56 tpot Exp $
+ */
+
+#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 <vfs.h>
+
+#ifndef SYSLOG_FACILITY
+#define SYSLOG_FACILITY LOG_USER
+#endif
+
+#ifndef SYSLOG_PRIORITY
+#define SYSLOG_PRIORITY LOG_NOTICE
+#endif
+
+/* Function prototypes */
+
+int audit_connect(struct vfs_connection_struct *conn, char *svc, char *user);
+void audit_disconnect(void);
+DIR *audit_opendir(char *fname);
+int audit_mkdir(char *path, mode_t mode);
+int audit_rmdir(char *path);
+int audit_open(char *fname, int flags, mode_t mode);
+int audit_close(int fd);
+int audit_rename(char *old, char *new);
+int audit_unlink(char *path);
+int audit_chmod(char *path, mode_t mode);
+
+/* VFS operations */
+
+extern struct vfs_ops default_vfs_ops; /* For passthrough operation */
+
+struct vfs_ops audit_ops = {
+
+ /* Disk operations */
+
+ audit_connect,
+ audit_disconnect,
+ NULL, /* disk free */
+
+ /* Directory operations */
+
+ audit_opendir,
+ NULL, /* readdir */
+ audit_mkdir,
+ audit_rmdir,
+ NULL, /* closedir */
+
+ /* File operations */
+
+ audit_open,
+ audit_close,
+ NULL, /* read */
+ NULL, /* write */
+ NULL, /* lseek */
+ audit_rename,
+ NULL, /* sync */
+ NULL, /* stat */
+ NULL, /* fstat */
+ NULL, /* lstat */
+ NULL, /* fcntl_lock */
+ audit_unlink,
+ NULL, /* chmod */
+ NULL /* utime */
+};
+
+/* VFS initialisation function. Return initialised vfs_ops structure
+ back to SAMBA. */
+
+struct vfs_ops *vfs_init(void)
+{
+ openlog("smbd_audit", LOG_PID, SYSLOG_FACILITY);
+ return(&audit_ops);
+}
+
+/* Implementation of vfs_ops. Pass everything on to the default
+ operation but log event first. */
+
+int audit_connect(struct vfs_connection_struct *conn, char *svc, char *user)
+{
+ syslog(SYSLOG_PRIORITY, "connect to service %s by user %s\n", svc, user);
+
+ return default_vfs_ops.connect(conn, svc, user);
+}
+
+void audit_disconnect(void)
+{
+ syslog(SYSLOG_PRIORITY, "disconnected\n");
+ default_vfs_ops.disconnect();
+}
+
+DIR *audit_opendir(char *fname)
+{
+ DIR *result = default_vfs_ops.opendir(fname);
+
+ syslog(SYSLOG_PRIORITY, "opendir %s %s%s\n",
+ fname,
+ (result == NULL) ? "failed: " : "",
+ (result == NULL) ? strerror(errno) : "");
+
+ return result;
+}
+
+int audit_mkdir(char *path, mode_t mode)
+{
+ int result = default_vfs_ops.mkdir(path, mode);
+
+ syslog(SYSLOG_PRIORITY, "mkdir %s %s%s\n",
+ path,
+ (result < 0) ? "failed: " : "",
+ (result < 0) ? strerror(errno) : "");
+
+ return result;
+}
+
+int audit_rmdir(char *path)
+{
+ int result = default_vfs_ops.rmdir(path);
+
+ syslog(SYSLOG_PRIORITY, "rmdir %s %s%s\n",
+ path,
+ (result < 0) ? "failed: " : "",
+ (result < 0) ? strerror(errno) : "");
+
+ return result;
+}
+
+int audit_open(char *fname, int flags, mode_t mode)
+{
+ int result = default_vfs_ops.open(fname, flags, mode);
+
+ syslog(SYSLOG_PRIORITY, "open %s (fd %d) %s%s%s\n",
+ fname, result,
+ ((mode & O_WRONLY) || (mode & O_RDWR)) ? "for writing " : "",
+ (result < 0) ? "failed: " : "",
+ (result < 0) ? strerror(errno) : "");
+
+ return result;
+}
+
+int audit_close(int fd)
+{
+ int result = default_vfs_ops.close(fd);
+
+ syslog(SYSLOG_PRIORITY, "close fd %d %s%s\n",
+ fd,
+ (result < 0) ? "failed: " : "",
+ (result < 0) ? strerror(errno) : "");
+
+ return result;
+}
+
+int audit_rename(char *old, char *new)
+{
+ int result = default_vfs_ops.rename(old, new);
+
+ syslog(SYSLOG_PRIORITY, "rename %s -> %s %s%s\n",
+ old, new,
+ (result < 0) ? "failed: " : "",
+ (result < 0) ? strerror(errno) : "");
+
+ return result;
+}
+
+int audit_unlink(char *path)
+{
+ int result = default_vfs_ops.unlink(path);
+
+ syslog(SYSLOG_PRIORITY, "unlink %s %s%s\n",
+ path,
+ (result < 0) ? "failed: " : "",
+ (result < 0) ? strerror(errno) : "");
+
+ return result;
+}
diff --git a/examples/VFS/skel.c b/examples/VFS/skel.c
new file mode 100644
index 0000000000..fae2bc51df
--- /dev/null
+++ b/examples/VFS/skel.c
@@ -0,0 +1,225 @@
+/*
+ * Skeleton VFS module.
+ *
+ * Copyright (C) Tim Potter, 1999
+ *
+ * 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.
+ *
+ * $Id: skel.c,v 1.1 2000/02/03 04:40:56 tpot Exp $
+ */
+
+#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
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
+#endif
+#include <errno.h>
+#include <string.h>
+
+#include <vfs.h>
+
+/* Function prototypes */
+
+int skel_connect(struct vfs_connection_struct *conn, char *svc, char *user);
+void skel_disconnect(void);
+SMB_BIG_UINT skel_disk_free(char *path, SMB_BIG_UINT *bsize,
+ SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize);
+
+DIR *skel_opendir(char *fname);
+struct dirent *skel_readdir(DIR *dirp);
+int skel_mkdir(char *path, mode_t mode);
+int skel_rmdir(char *path);
+int skel_closedir(DIR *dir);
+
+int skel_open(char *fname, int flags, mode_t mode);
+int skel_close(int fd);
+ssize_t skel_read(int fd, char *data, size_t n);
+ssize_t skel_write(int fd, char *data, size_t n);
+SMB_OFF_T skel_lseek(int filedes, SMB_OFF_T offset, int whence);
+int skel_rename(char *old, char *new);
+void skel_sync(int fd);
+int skel_stat(char *fname, SMB_STRUCT_STAT *sbuf);
+int skel_fstat(int fd, SMB_STRUCT_STAT *sbuf);
+int skel_lstat(char *path, SMB_STRUCT_STAT *sbuf);
+BOOL skel_lock(int fd, int op, SMB_OFF_T offset, SMB_OFF_T count, int type);
+int skel_unlink(char *path);
+int skel_chmod(char *path, mode_t mode);
+int skel_utime(char *path, struct utimbuf *times);
+
+/* VFS operations structure */
+
+struct vfs_ops skel_ops = {
+
+ /* Disk operations */
+
+ skel_connect,
+ skel_disconnect,
+ skel_disk_free,
+
+ /* Directory operations */
+
+ skel_opendir,
+ skel_readdir,
+ skel_mkdir,
+ skel_rmdir,
+ skel_closedir,
+
+ /* File operations */
+
+ skel_open,
+ skel_close,
+ skel_read,
+ skel_write,
+ skel_lseek,
+ skel_rename,
+ skel_sync,
+ skel_stat,
+ skel_fstat,
+ skel_lstat,
+ skel_lock,
+ skel_unlink,
+ skel_chmod,
+ skel_utime
+};
+
+/* VFS initialisation - return vfs_ops function pointer structure */
+
+struct vfs_ops *vfs_init(void)
+{
+ return(&skel_ops);
+}
+
+/* Implementation of VFS functions. Insert your useful stuff here */
+
+extern struct vfs_ops default_vfs_ops; /* For passthrough operation */
+
+int skel_connect(struct vfs_connection_struct *conn, char *svc, char *user)
+{
+ return default_vfs_ops.connect(conn, svc, user);
+}
+
+void skel_disconnect(void)
+{
+ default_vfs_ops.disconnect();
+}
+
+SMB_BIG_UINT skel_disk_free(char *path, SMB_BIG_UINT *bsize,
+ SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)
+{
+ return default_vfs_ops.disk_free(path, bsize, dfree, dsize);
+}
+
+DIR *skel_opendir(char *fname)
+{
+ return default_vfs_ops.opendir(fname);
+}
+
+struct dirent *skel_readdir(DIR *dirp)
+{
+ return default_vfs_ops.readdir(dirp);
+}
+
+int skel_mkdir(char *path, mode_t mode)
+{
+ return default_vfs_ops.mkdir(path, mode);
+}
+
+int skel_rmdir(char *path)
+{
+ return default_vfs_ops.rmdir(path);
+}
+
+int skel_closedir(DIR *dir)
+{
+ return default_vfs_ops.closedir(dir);
+}
+
+int skel_open(char *fname, int flags, mode_t mode)
+{
+ return default_vfs_ops.open(fname, flags, mode);
+}
+
+int skel_close(int fd)
+{
+ return default_vfs_ops.close(fd);
+}
+
+ssize_t skel_read(int fd, char *data, size_t n)
+{
+ return default_vfs_ops.read(fd, data, n);
+}
+
+ssize_t skel_write(int fd, char *data, size_t n)
+{
+ return default_vfs_ops.write(fd, data, n);
+}
+
+SMB_OFF_T skel_lseek(int filedes, SMB_OFF_T offset, int whence)
+{
+ return default_vfs_ops.lseek(filedes, offset, whence);
+}
+
+int skel_rename(char *old, char *new)
+{
+ return default_vfs_ops.rename(old, new);
+}
+
+void skel_sync(int fd)
+{
+ default_vfs_ops.sync(fd);
+}
+
+int skel_stat(char *fname, SMB_STRUCT_STAT *sbuf)
+{
+ return default_vfs_ops.stat(fname, sbuf);
+}
+
+int skel_fstat(int fd, SMB_STRUCT_STAT *sbuf)
+{
+ return default_vfs_ops.fstat(fd, sbuf);
+}
+
+int skel_lstat(char *path, SMB_STRUCT_STAT *sbuf)
+{
+ return default_vfs_ops.lstat(path, sbuf);
+}
+
+BOOL skel_lock(int fd, int op, SMB_OFF_T offset, SMB_OFF_T count, int type)
+{
+ return default_vfs_ops.lock(fd, op, offset, count, type);
+}
+
+int skel_unlink(char *path)
+{
+ return default_vfs_ops.unlink(path);
+}
+
+int skel_chmod(char *path, mode_t mode)
+{
+ return default_vfs_ops.chmod(path, mode);
+}
+
+int skel_utime(char *path, struct utimbuf *times)
+{
+ return default_vfs_ops.utime(path, times);
+}