⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vfs-wrap.c

📁 samba-3.0.22.tar.gz 编译smb服务器的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*    Unix SMB/CIFS implementation.   Wrap disk only vfs functions to sidestep dodgy compilers.   Copyright (C) Tim Potter 1998      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.*/#include "includes.h"#undef DBGC_CLASS#define DBGC_CLASS DBGC_VFS/* Check for NULL pointer parameters in vfswrap_* functions *//* We don't want to have NULL function pointers lying around.  Someone   is sure to try and execute them.  These stubs are used to prevent   this possibility. */int vfswrap_dummy_connect(vfs_handle_struct *handle, connection_struct *conn, const char *service, const char *user){    return 0;    /* Return >= 0 for success */}void vfswrap_dummy_disconnect(vfs_handle_struct *handle, connection_struct *conn){}/* Disk operations */SMB_BIG_UINT vfswrap_disk_free(vfs_handle_struct *handle, connection_struct *conn, const char *path, BOOL small_query, SMB_BIG_UINT *bsize, 			       SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize){	SMB_BIG_UINT result;	result = sys_disk_free(conn, path, small_query, bsize, dfree, dsize);	return result;}int vfswrap_get_quota(struct vfs_handle_struct *handle, struct connection_struct *conn, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *qt){#ifdef HAVE_SYS_QUOTAS	int result;	START_PROFILE(syscall_get_quota);	result = sys_get_quota(conn->connectpath, qtype, id, qt);	END_PROFILE(syscall_get_quota);	return result;#else	errno = ENOSYS;	return -1;#endif	}int vfswrap_set_quota(struct vfs_handle_struct *handle, struct connection_struct *conn, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *qt){#ifdef HAVE_SYS_QUOTAS	int result;	START_PROFILE(syscall_set_quota);	result = sys_set_quota(conn->connectpath, qtype, id, qt);	END_PROFILE(syscall_set_quota);	return result;#else	errno = ENOSYS;	return -1;#endif	}int vfswrap_get_shadow_copy_data(struct vfs_handle_struct *handle, struct files_struct *fsp, SHADOW_COPY_DATA *shadow_copy_data, BOOL labels){	errno = ENOSYS;	return -1;  /* Not implemented. */}    int vfswrap_statvfs(struct vfs_handle_struct *handle, struct connection_struct *conn, const char *path, vfs_statvfs_struct *statbuf){	return sys_statvfs(path, statbuf);}/* Directory operations */SMB_STRUCT_DIR *vfswrap_opendir(vfs_handle_struct *handle, connection_struct *conn, const char *fname, const char *mask, uint32 attr){	SMB_STRUCT_DIR *result;	START_PROFILE(syscall_opendir);	result = sys_opendir(fname);	END_PROFILE(syscall_opendir);	return result;}SMB_STRUCT_DIRENT *vfswrap_readdir(vfs_handle_struct *handle, connection_struct *conn, SMB_STRUCT_DIR *dirp){	SMB_STRUCT_DIRENT *result;	START_PROFILE(syscall_readdir);	result = sys_readdir(dirp);	END_PROFILE(syscall_readdir);	return result;}void vfswrap_seekdir(vfs_handle_struct *handle, connection_struct *conn, SMB_STRUCT_DIR *dirp, long offset){	START_PROFILE(syscall_seekdir);	sys_seekdir(dirp, offset);	END_PROFILE(syscall_seekdir);}long vfswrap_telldir(vfs_handle_struct *handle, connection_struct *conn, SMB_STRUCT_DIR *dirp){	long result;	START_PROFILE(syscall_telldir);	result = sys_telldir(dirp);	END_PROFILE(syscall_telldir);	return result;}void vfswrap_rewinddir(vfs_handle_struct *handle, connection_struct *conn, SMB_STRUCT_DIR *dirp){	START_PROFILE(syscall_rewinddir);	sys_rewinddir(dirp);	END_PROFILE(syscall_rewinddir);}int vfswrap_mkdir(vfs_handle_struct *handle, connection_struct *conn, const char *path, mode_t mode){	int result;	BOOL has_dacl = False;	START_PROFILE(syscall_mkdir);	if (lp_inherit_acls(SNUM(conn)) && (has_dacl = directory_has_default_acl(conn, parent_dirname(path))))		mode = 0777;	result = mkdir(path, mode);	if (result == 0 && !has_dacl) {		/*		 * We need to do this as the default behavior of POSIX ACLs			 * is to set the mask to be the requested group permission		 * bits, not the group permission bits to be the requested		 * group permission bits. This is not what we want, as it will		 * mess up any inherited ACL bits that were set. JRA.		 */		int saved_errno = errno; /* We may get ENOSYS */		if ((SMB_VFS_CHMOD_ACL(conn, path, mode) == -1) && (errno == ENOSYS))			errno = saved_errno;	}	END_PROFILE(syscall_mkdir);	return result;}int vfswrap_rmdir(vfs_handle_struct *handle, connection_struct *conn, const char *path){	int result;	START_PROFILE(syscall_rmdir);	result = rmdir(path);	END_PROFILE(syscall_rmdir);	return result;}int vfswrap_closedir(vfs_handle_struct *handle, connection_struct *conn, SMB_STRUCT_DIR *dirp){	int result;	START_PROFILE(syscall_closedir);	result = sys_closedir(dirp);	END_PROFILE(syscall_closedir);	return result;}/* File operations */    int vfswrap_open(vfs_handle_struct *handle, connection_struct *conn, const char *fname, int flags, mode_t mode){	int result;	START_PROFILE(syscall_open);	result = sys_open(fname, flags, mode);	END_PROFILE(syscall_open);	return result;}int vfswrap_close(vfs_handle_struct *handle, files_struct *fsp, int fd){	int result;	START_PROFILE(syscall_close);	result = close(fd);	END_PROFILE(syscall_close);	return result;}ssize_t vfswrap_read(vfs_handle_struct *handle, files_struct *fsp, int fd, void *data, size_t n){	ssize_t result;	START_PROFILE_BYTES(syscall_read, n);	result = sys_read(fd, data, n);	END_PROFILE(syscall_read);	return result;}ssize_t vfswrap_pread(vfs_handle_struct *handle, files_struct *fsp, int fd, void *data,			size_t n, SMB_OFF_T offset){	ssize_t result;#if defined(HAVE_PREAD) || defined(HAVE_PREAD64)	START_PROFILE_BYTES(syscall_pread, n);	result = sys_pread(fd, data, n, offset);	END_PROFILE(syscall_pread); 	if (result == -1 && errno == ESPIPE) {		/* Maintain the fiction that pipes can be seeked (sought?) on. */		result = SMB_VFS_READ(fsp, fd, data, n);		fsp->fh->pos = 0;	}#else /* HAVE_PREAD */	SMB_OFF_T   curr;	int lerrno;   	curr = SMB_VFS_LSEEK(fsp, fd, 0, SEEK_CUR);	if (curr == -1 && errno == ESPIPE) {		/* Maintain the fiction that pipes can be seeked (sought?) on. */		result = SMB_VFS_READ(fsp, fd, data, n);		fsp->fh->pos = 0;		return result;	}	if (SMB_VFS_LSEEK(fsp, fd, offset, SEEK_SET) == -1) {		return -1;	}	errno = 0;	result = SMB_VFS_READ(fsp, fd, data, n);	lerrno = errno;	SMB_VFS_LSEEK(fsp, fd, curr, SEEK_SET);	errno = lerrno;#endif /* HAVE_PREAD */	return result;}ssize_t vfswrap_write(vfs_handle_struct *handle, files_struct *fsp, int fd, const void *data, size_t n){	ssize_t result;	START_PROFILE_BYTES(syscall_write, n);	result = sys_write(fd, data, n);	END_PROFILE(syscall_write);	return result;}ssize_t vfswrap_pwrite(vfs_handle_struct *handle, files_struct *fsp, int fd, const void *data,			size_t n, SMB_OFF_T offset){	ssize_t result;#if defined(HAVE_PWRITE) || defined(HAVE_PRWITE64)	START_PROFILE_BYTES(syscall_pwrite, n);	result = sys_pwrite(fd, data, n, offset);	END_PROFILE(syscall_pwrite);	if (result == -1 && errno == ESPIPE) {		/* Maintain the fiction that pipes can be sought on. */		result = SMB_VFS_WRITE(fsp, fd, data, n);	}#else /* HAVE_PWRITE */	SMB_OFF_T   curr;	int         lerrno;	curr = SMB_VFS_LSEEK(fsp, fd, 0, SEEK_CUR);	if (curr == -1) {		return -1;	}	if (SMB_VFS_LSEEK(fsp, fd, offset, SEEK_SET) == -1) {		return -1;	}	result = SMB_VFS_WRITE(fsp, fd, data, n);	lerrno = errno;	SMB_VFS_LSEEK(fsp, fd, curr, SEEK_SET);	errno = lerrno;#endif /* HAVE_PWRITE */	return result;}SMB_OFF_T vfswrap_lseek(vfs_handle_struct *handle, files_struct *fsp, int filedes, SMB_OFF_T offset, int whence){	SMB_OFF_T result = 0;	START_PROFILE(syscall_lseek);	/* Cope with 'stat' file opens. */	if (filedes != -1)		result = sys_lseek(filedes, offset, whence);	/*	 * We want to maintain the fiction that we can seek	 * on a fifo for file system purposes. This allows	 * people to set up UNIX fifo's that feed data to Windows	 * applications. JRA.	 */	if((result == -1) && (errno == ESPIPE)) {		result = 0;		errno = 0;	}	END_PROFILE(syscall_lseek);	return result;}ssize_t vfswrap_sendfile(vfs_handle_struct *handle, int tofd, files_struct *fsp, int fromfd, const DATA_BLOB *hdr,			SMB_OFF_T offset, size_t n){	ssize_t result;	START_PROFILE_BYTES(syscall_sendfile, n);	result = sys_sendfile(tofd, fromfd, hdr, offset, n);	END_PROFILE(syscall_sendfile);	return result;}/********************************************************* For rename across filesystems Patch from Warren Birnbaum <warrenb@hpcvscdp.cv.hp.com>**********************************************************/static int copy_reg(const char *source, const char *dest){	SMB_STRUCT_STAT source_stats;	int saved_errno;	int ifd = -1;	int ofd = -1;	if (sys_lstat (source, &source_stats) == -1)		return -1;	if (!S_ISREG (source_stats.st_mode))		return -1;	if((ifd = sys_open (source, O_RDONLY, 0)) < 0)		return -1;	if (unlink (dest) && errno != ENOENT)		return -1;#ifdef O_NOFOLLOW	if((ofd = sys_open (dest, O_WRONLY | O_CREAT | O_TRUNC | O_NOFOLLOW, 0600)) < 0 )#else	if((ofd = sys_open (dest, O_WRONLY | O_CREAT | O_TRUNC , 0600)) < 0 )#endif		goto err;	if (transfer_file(ifd, ofd, (size_t)-1) == -1)		goto err;	/*	 * Try to preserve ownership.  For non-root it might fail, but that's ok.	 * But root probably wants to know, e.g. if NFS disallows it.	 */#ifdef HAVE_FCHOWN	if ((fchown(ofd, source_stats.st_uid, source_stats.st_gid) == -1) && (errno != EPERM))#else	if ((chown(dest, source_stats.st_uid, source_stats.st_gid) == -1) && (errno != EPERM))#endif		goto err;	/*	 * fchown turns off set[ug]id bits for non-root,	 * so do the chmod last.	 */#if defined(HAVE_FCHMOD)	if (fchmod (ofd, source_stats.st_mode & 07777))#else	if (chmod (dest, source_stats.st_mode & 07777))#endif		goto err;	if (close (ifd) == -1)		goto err;	if (close (ofd) == -1)		return -1;	/* Try to copy the old file's modtime and access time.  */	{		struct utimbuf tv;		tv.actime = source_stats.st_atime;		tv.modtime = source_stats.st_mtime;		utime(dest, &tv);	}	if (unlink (source) == -1)		return -1;	return 0;  err:	saved_errno = errno;	if (ifd != -1)		close(ifd);	if (ofd != -1)		close(ofd);	errno = saved_errno;	return -1;}int vfswrap_rename(vfs_handle_struct *handle, connection_struct *conn, const char *oldname, const char *newname){	int result;	START_PROFILE(syscall_rename);	result = rename(oldname, newname);	if (errno == EXDEV) {		/* Rename across filesystems needed. */		result = copy_reg(oldname, newname);	}	END_PROFILE(syscall_rename);	return result;}int vfswrap_fsync(vfs_handle_struct *handle, files_struct *fsp, int fd){#ifdef HAVE_FSYNC	int result;	START_PROFILE(syscall_fsync);	result = fsync(fd);	END_PROFILE(syscall_fsync);	return result;#else	return 0;#endif}int vfswrap_stat(vfs_handle_struct *handle, connection_struct *conn, const char *fname, SMB_STRUCT_STAT *sbuf){	int result;	START_PROFILE(syscall_stat);	result = sys_stat(fname, sbuf);	END_PROFILE(syscall_stat);	return result;}int vfswrap_fstat(vfs_handle_struct *handle, files_struct *fsp, int fd, SMB_STRUCT_STAT *sbuf){	int result;	START_PROFILE(syscall_fstat);	result = sys_fstat(fd, sbuf);	END_PROFILE(syscall_fstat);	return result;}int vfswrap_lstat(vfs_handle_struct *handle, connection_struct *conn, const char *path, SMB_STRUCT_STAT *sbuf){	int result;	START_PROFILE(syscall_lstat);	result = sys_lstat(path, sbuf);	END_PROFILE(syscall_lstat);	return result;}int vfswrap_unlink(vfs_handle_struct *handle, connection_struct *conn, const char *path){	int result;	START_PROFILE(syscall_unlink);	result = unlink(path);	END_PROFILE(syscall_unlink);	return result;}int vfswrap_chmod(vfs_handle_struct *handle, connection_struct *conn, const char *path, mode_t mode){	int result;	START_PROFILE(syscall_chmod);	/*	 * We need to do this due to the fact that the default POSIX ACL	 * chmod modifies the ACL *mask* for the group owner, not the	 * group owner bits directly. JRA.	 */		{		int saved_errno = errno; /* We might get ENOSYS */		if ((result = SMB_VFS_CHMOD_ACL(conn, path, mode)) == 0) {			END_PROFILE(syscall_chmod);			return result;		}		/* Error - return the old errno. */		errno = saved_errno;	}	result = chmod(path, mode);	END_PROFILE(syscall_chmod);	return result;}int vfswrap_fchmod(vfs_handle_struct *handle, files_struct *fsp, int fd, mode_t mode){	int result;		START_PROFILE(syscall_fchmod);	/*	 * We need to do this due to the fact that the default POSIX ACL	 * chmod modifies the ACL *mask* for the group owner, not the	 * group owner bits directly. JRA.	 */	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -