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

Updated VFS examples to use ftruncate() and lock() functions.

This commit is contained in:
Tim Potter 0001-01-01 00:00:00 +00:00
parent 2e0a39204a
commit def0da145a
2 changed files with 141 additions and 126 deletions

View File

@ -1,5 +1,5 @@
/*
* Auditing VFS module for samba. Log select file operations to syslog
* Auditing VFS module for samba. Log selected file operations to syslog
* facility.
*
* Copyright (C) Tim Potter, 1999-2000
@ -17,8 +17,6 @@
* 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.2 2000/02/04 05:08:16 tpot Exp $
*/
#include "config.h"
@ -65,35 +63,37 @@ extern struct vfs_ops default_vfs_ops; /* For passthrough operation */
struct vfs_ops audit_ops = {
/* Disk operations */
/* Disk operations */
audit_connect,
audit_disconnect,
NULL, /* disk free */
audit_connect,
audit_disconnect,
NULL, /* disk free */
/* Directory operations */
/* Directory operations */
audit_opendir,
NULL, /* readdir */
audit_mkdir,
audit_rmdir,
NULL, /* closedir */
audit_opendir,
NULL, /* readdir */
audit_mkdir,
audit_rmdir,
NULL, /* closedir */
/* File operations */
/* File operations */
audit_open,
audit_close,
NULL, /* read */
NULL, /* write */
NULL, /* lseek */
audit_rename,
NULL, /* fsync */
NULL, /* stat */
NULL, /* fstat */
NULL, /* lstat */
audit_unlink,
NULL, /* chmod */
NULL /* utime */
audit_open,
audit_close,
NULL, /* read */
NULL, /* write */
NULL, /* lseek */
audit_rename,
NULL, /* fsync */
NULL, /* stat */
NULL, /* fstat */
NULL, /* lstat */
audit_unlink,
NULL, /* chmod */
NULL, /* utime */
NULL, /* ftruncate */
NULL /* lock */
};
/* VFS initialisation function. Return initialised vfs_ops structure
@ -101,8 +101,8 @@ struct vfs_ops audit_ops = {
struct vfs_ops *vfs_init(void)
{
openlog("smbd_audit", LOG_PID, SYSLOG_FACILITY);
return(&audit_ops);
openlog("smbd_audit", LOG_PID, SYSLOG_FACILITY);
return(&audit_ops);
}
/* Implementation of vfs_ops. Pass everything on to the default
@ -110,98 +110,99 @@ struct vfs_ops *vfs_init(void)
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);
syslog(SYSLOG_PRIORITY, "connect to service %s by user %s\n",
svc, user);
return default_vfs_ops.connect(conn, svc, user);
return default_vfs_ops.connect(conn, svc, user);
}
void audit_disconnect(void)
{
syslog(SYSLOG_PRIORITY, "disconnected\n");
default_vfs_ops.disconnect();
syslog(SYSLOG_PRIORITY, "disconnected\n");
default_vfs_ops.disconnect();
}
DIR *audit_opendir(char *fname)
{
DIR *result = default_vfs_ops.opendir(fname);
DIR *result = default_vfs_ops.opendir(fname);
syslog(SYSLOG_PRIORITY, "opendir %s %s%s\n",
fname,
(result == NULL) ? "failed: " : "",
(result == NULL) ? strerror(errno) : "");
syslog(SYSLOG_PRIORITY, "opendir %s %s%s\n",
fname,
(result == NULL) ? "failed: " : "",
(result == NULL) ? strerror(errno) : "");
return result;
return result;
}
int audit_mkdir(char *path, mode_t mode)
{
int result = default_vfs_ops.mkdir(path, 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) : "");
syslog(SYSLOG_PRIORITY, "mkdir %s %s%s\n",
path,
(result < 0) ? "failed: " : "",
(result < 0) ? strerror(errno) : "");
return result;
return result;
}
int audit_rmdir(char *path)
{
int result = default_vfs_ops.rmdir(path);
int result = default_vfs_ops.rmdir(path);
syslog(SYSLOG_PRIORITY, "rmdir %s %s%s\n",
path,
(result < 0) ? "failed: " : "",
(result < 0) ? strerror(errno) : "");
syslog(SYSLOG_PRIORITY, "rmdir %s %s%s\n",
path,
(result < 0) ? "failed: " : "",
(result < 0) ? strerror(errno) : "");
return result;
return result;
}
int audit_open(char *fname, int flags, mode_t mode)
{
int result = default_vfs_ops.open(fname, flags, mode);
int result = default_vfs_ops.open(fname, flags, mode);
syslog(SYSLOG_PRIORITY, "open %s (fd %d) %s%s%s\n",
fname, result,
((flags & O_WRONLY) || (flags & O_RDWR)) ? "for writing " : "",
(result < 0) ? "failed: " : "",
(result < 0) ? strerror(errno) : "");
syslog(SYSLOG_PRIORITY, "open %s (fd %d) %s%s%s\n",
fname, result,
((flags & O_WRONLY) || (flags & O_RDWR)) ? "for writing " : "",
(result < 0) ? "failed: " : "",
(result < 0) ? strerror(errno) : "");
return result;
return result;
}
int audit_close(int fd)
{
int result = default_vfs_ops.close(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) : "");
syslog(SYSLOG_PRIORITY, "close fd %d %s%s\n",
fd,
(result < 0) ? "failed: " : "",
(result < 0) ? strerror(errno) : "");
return result;
return result;
}
int audit_rename(char *old, char *new)
{
int result = default_vfs_ops.rename(old, 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) : "");
syslog(SYSLOG_PRIORITY, "rename %s -> %s %s%s\n",
old, new,
(result < 0) ? "failed: " : "",
(result < 0) ? strerror(errno) : "");
return result;
return result;
}
int audit_unlink(char *path)
{
int result = default_vfs_ops.unlink(path);
int result = default_vfs_ops.unlink(path);
syslog(SYSLOG_PRIORITY, "unlink %s %s%s\n",
path,
(result < 0) ? "failed: " : "",
(result < 0) ? strerror(errno) : "");
syslog(SYSLOG_PRIORITY, "unlink %s %s%s\n",
path,
(result < 0) ? "failed: " : "",
(result < 0) ? strerror(errno) : "");
return result;
return result;
}

View File

@ -1,5 +1,6 @@
/*
* Skeleton VFS module.
* Skeleton VFS module. Implements passthrough operation of all VFS
* calls to disk functions.
*
* Copyright (C) Tim Potter, 1999-2000
*
@ -16,8 +17,6 @@
* 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.3 2000/04/05 22:42:26 tpot Exp $
*/
#include "config.h"
@ -64,47 +63,51 @@ int skel_lstat(char *path, SMB_STRUCT_STAT *sbuf);
int skel_unlink(char *path);
int skel_chmod(char *path, mode_t mode);
int skel_utime(char *path, struct utimbuf *times);
int skel_ftruncate(int fd, SMB_OFF_T offset);
BOOL skel_lock(int fd, int op, SMB_OFF_T offset, SMB_OFF_T count, int type);
/* VFS operations structure */
struct vfs_ops skel_ops = {
/* Disk operations */
/* Disk operations */
skel_connect,
skel_disconnect,
skel_disk_free,
skel_connect,
skel_disconnect,
skel_disk_free,
/* Directory operations */
/* Directory operations */
skel_opendir,
skel_readdir,
skel_mkdir,
skel_rmdir,
skel_closedir,
skel_opendir,
skel_readdir,
skel_mkdir,
skel_rmdir,
skel_closedir,
/* File operations */
/* File operations */
skel_open,
skel_close,
skel_read,
skel_write,
skel_lseek,
skel_rename,
skel_fsync,
skel_stat,
skel_fstat,
skel_lstat,
skel_unlink,
skel_chmod,
skel_utime
skel_open,
skel_close,
skel_read,
skel_write,
skel_lseek,
skel_rename,
skel_fsync,
skel_stat,
skel_fstat,
skel_lstat,
skel_unlink,
skel_chmod,
skel_utime,
skel_ftruncate,
skel_lock
};
/* VFS initialisation - return vfs_ops function pointer structure */
struct vfs_ops *vfs_init(void)
{
return(&skel_ops);
return(&skel_ops);
}
/* Implementation of VFS functions. Insert your useful stuff here */
@ -113,106 +116,117 @@ 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);
return default_vfs_ops.connect(conn, svc, user);
}
void skel_disconnect(void)
{
default_vfs_ops.disconnect();
default_vfs_ops.disconnect();
}
SMB_BIG_UINT skel_disk_free(char *path, BOOL small_query, SMB_BIG_UINT *bsize,
SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)
{
return default_vfs_ops.disk_free(path, small_query, bsize, dfree, dsize);
return default_vfs_ops.disk_free(path, small_query, bsize,
dfree, dsize);
}
DIR *skel_opendir(char *fname)
{
return default_vfs_ops.opendir(fname);
return default_vfs_ops.opendir(fname);
}
struct dirent *skel_readdir(DIR *dirp)
{
return default_vfs_ops.readdir(dirp);
return default_vfs_ops.readdir(dirp);
}
int skel_mkdir(char *path, mode_t mode)
{
return default_vfs_ops.mkdir(path, mode);
return default_vfs_ops.mkdir(path, mode);
}
int skel_rmdir(char *path)
{
return default_vfs_ops.rmdir(path);
return default_vfs_ops.rmdir(path);
}
int skel_closedir(DIR *dir)
{
return default_vfs_ops.closedir(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);
return default_vfs_ops.open(fname, flags, mode);
}
int skel_close(int fd)
{
return default_vfs_ops.close(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);
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);
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);
return default_vfs_ops.lseek(filedes, offset, whence);
}
int skel_rename(char *old, char *new)
{
return default_vfs_ops.rename(old, new);
return default_vfs_ops.rename(old, new);
}
int skel_fsync(int fd)
{
default_vfs_ops.fsync(fd);
return default_vfs_ops.fsync(fd);
}
int skel_stat(char *fname, SMB_STRUCT_STAT *sbuf)
{
return default_vfs_ops.stat(fname, sbuf);
return default_vfs_ops.stat(fname, sbuf);
}
int skel_fstat(int fd, SMB_STRUCT_STAT *sbuf)
{
return default_vfs_ops.fstat(fd, sbuf);
return default_vfs_ops.fstat(fd, sbuf);
}
int skel_lstat(char *path, SMB_STRUCT_STAT *sbuf)
{
return default_vfs_ops.lstat(path, sbuf);
return default_vfs_ops.lstat(path, sbuf);
}
int skel_unlink(char *path)
{
return default_vfs_ops.unlink(path);
return default_vfs_ops.unlink(path);
}
int skel_chmod(char *path, mode_t mode)
{
return default_vfs_ops.chmod(path, mode);
return default_vfs_ops.chmod(path, mode);
}
int skel_utime(char *path, struct utimbuf *times)
{
return default_vfs_ops.utime(path, times);
return default_vfs_ops.utime(path, times);
}
int skel_ftruncate(int fd, SMB_OFF_T offset)
{
return default_vfs_ops.ftruncate(fd, offset);
}
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);
}