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

📄 smbw.c

📁 samba-3.0.22.tar.gz 编译smb服务器的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
}/***************************************************** a wrapper for pwrite()*******************************************************/ssize_t smbw_pwrite(int smbw_fd, void *buf, size_t count, SMBW_OFF_T ofs){        int saved_errno;        int client_fd;	ssize_t ret;        SMBW_OFF_T old_ofs;                if (count == 0) {                return 0;        }        client_fd = smbw_fd_map[smbw_fd];        if ((old_ofs = smbc_lseek(client_fd, 0, SEEK_CUR)) < 0 ||            smbc_lseek(client_fd, ofs, SEEK_SET) < 0) {                return -1;        }        if ((ret = smbc_write(client_fd, buf, count)) < 0) {                saved_errno = errno;                (void) smbc_lseek(client_fd, old_ofs, SEEK_SET);                errno = saved_errno;                return -1;        }        return ret;}/***************************************************** a wrapper for close()*******************************************************/int smbw_close(int smbw_fd){        int client_fd;        client_fd = smbw_fd_map[smbw_fd];        if (smbw_ref(client_fd, SMBW_RCT_Decrement) > 0) {                return 0;        }                (* smbw_libc.close)(smbw_fd);        smbw_fd_map[smbw_fd] = -1;        return smbc_close(client_fd);}/***************************************************** a wrapper for fcntl()*******************************************************/int smbw_fcntl(int smbw_fd, int cmd, long arg){	return 0;}/***************************************************** a wrapper for access()*******************************************************/int smbw_access(const char *name, int mode){	struct SMBW_stat st;        SMBW_INIT();	if (smbw_stat(name, &st)) return -1;	if (((mode & R_OK) && !(st.s_mode & S_IRUSR)) ||	    ((mode & W_OK) && !(st.s_mode & S_IWUSR)) ||	    ((mode & X_OK) && !(st.s_mode & S_IXUSR))) {		errno = EACCES;		return -1;	}		return 0;}/***************************************************** a wrapper for readlink() - needed for correct errno setting*******************************************************/int smbw_readlink(const char *fname, char *buf, size_t bufsize){	struct SMBW_stat st;	int ret;        SMBW_INIT();	ret = smbw_stat(fname, &st);	if (ret != 0) {		return -1;	}		/* it exists - say it isn't a link */	errno = EINVAL;	return -1;}/***************************************************** a wrapper for unlink()*******************************************************/int smbw_unlink(const char *fname){        char path[PATH_MAX];                SMBW_INIT();        smbw_fix_path(fname, path);        return smbc_unlink(path);}/***************************************************** a wrapper for rename()*******************************************************/int smbw_rename(const char *oldname, const char *newname){        char path_old[PATH_MAX];        char path_new[PATH_MAX];        SMBW_INIT();        smbw_fix_path(oldname, path_old);        smbw_fix_path(newname, path_new);        return smbc_rename(path_old, path_new);}/***************************************************** a wrapper for utimes*******************************************************/int smbw_utimes(const char *fname, void *buf){        char path[PATH_MAX];        smbw_fix_path(fname, path);	return smbc_utimes(path, buf);}/***************************************************** a wrapper for utime *******************************************************/int smbw_utime(const char *fname, void *buf){        char path[PATH_MAX];        smbw_fix_path(fname, path);        return smbc_utime(path, buf);}/***************************************************** a wrapper for chown()*******************************************************/int smbw_chown(const char *fname, uid_t owner, gid_t group){        /* always indiciate that this is not supported. */        errno = ENOTSUP;        return -1;}/***************************************************** a wrapper for chmod()*******************************************************/int smbw_chmod(const char *fname, mode_t newmode){        char path[PATH_MAX];        smbw_fix_path(fname, path);        return smbc_chmod(path, newmode);}/***************************************************** a wrapper for lseek()*******************************************************/SMBW_OFF_T smbw_lseek(int smbw_fd,                      SMBW_OFF_T offset,                      int whence){        int client_fd;        SMBW_OFF_T ret;                client_fd = smbw_fd_map[smbw_fd];        ret = smbc_lseek(client_fd, offset, whence);        if (smbw_debug)        {                printf("smbw_lseek(%d/%d, 0x%llx) returned 0x%llx\n",                       smbw_fd, client_fd,                       (unsigned long long) offset,                       (unsigned long long) ret);        }        return ret;}/***************************************************** a wrapper for dup()*******************************************************/int smbw_dup(int smbw_fd){	int fd2;	fd2 = (smbw_libc.dup)(smbw_fd);	if (fd2 == -1) {                return -1;	}        smbw_fd_map[fd2] = smbw_fd_map[smbw_fd];        smbw_ref(smbw_fd_map[smbw_fd], SMBW_RCT_Increment);	return fd2;}/***************************************************** a wrapper for dup2()*******************************************************/int smbw_dup2(int smbw_fd, int fd2){	if ((* smbw_libc.dup2)(smbw_fd, fd2) != fd2) {                return -1;	}        smbw_fd_map[fd2] = smbw_fd_map[smbw_fd];        smbw_ref(smbw_fd_map[smbw_fd], SMBW_RCT_Increment);	return fd2;}/***************************************************** when we fork we have to close all connections and filesin the child*******************************************************/int smbw_fork(void){        int i;	pid_t child_pid;	int p[2];	char c = 0;        SMBW_INIT();	if (pipe(p)) return (* smbw_libc.fork)();	child_pid = (* smbw_libc.fork)();	if (child_pid) {		/* block the parent for a moment until the sockets are                   closed */		(* smbw_libc.close)(p[1]);		(* smbw_libc.read)(p[0], &c, 1);		(* smbw_libc.close)(p[0]);		return child_pid;        }	(* smbw_libc.close)(p[0]);        /* close all server connections and locally-opened files */        for (i = 0; i < __FD_SETSIZE; i++) {                if (smbw_fd_map[i] > 0 &&                    smbw_ref(smbw_fd_map[i], SMBW_RCT_Get) > 0) {                                                smbc_close(smbw_fd_map[i]);                        smbw_ref(smbw_fd_map[i], SMBW_RCT_Set, 0);                        (* smbw_libc.close)(i);                }                smbw_fd_map[i] = -1;        }	/* unblock the parent */	write(p[1], &c, 1);	(* smbw_libc.close)(p[1]);        /* specify directory to start in, if it's simulated smb */        if (*smbw_cwd != '\0') {                setenv("SMBW_DIR", smbw_cwd, 1);        } else {                unsetenv("SMBW_DIR");        }        /* Re-initialize this library for the child */        do_init(StartupType_Fake);	/* and continue in the child */	return 0;}int smbw_setxattr(const char *fname,                  const char *name,                  const void *value,                  size_t size,                  int flags){        char path[PATH_MAX];        if (strcmp(name, "system.posix_acl_access") == 0)        {                name = "system.*";        }        smbw_fix_path(fname, path);        return smbc_setxattr(path, name, value, size, flags);}int smbw_lsetxattr(const char *fname,                   const char *name,                   const void *value,                   size_t size,                   int flags){        char path[PATH_MAX];        if (strcmp(name, "system.posix_acl_access") == 0)        {                name = "system.*";        }        smbw_fix_path(fname, path);        return smbc_lsetxattr(path, name, value, size, flags);}int smbw_fsetxattr(int smbw_fd,                   const char *name,                   const void *value,                   size_t size,                   int flags){        int client_fd;                if (strcmp(name, "system.posix_acl_access") == 0)        {                name = "system.*";        }        client_fd = smbw_fd_map[smbw_fd];        return smbc_fsetxattr(client_fd, name, value, size, flags);}int smbw_getxattr(const char *fname,                  const char *name,                  const void *value,                  size_t size){        char path[PATH_MAX];        if (strcmp(name, "system.posix_acl_access") == 0)        {                name = "system.*";        }        smbw_fix_path(fname, path);        return smbc_getxattr(path, name, value, size);}int smbw_lgetxattr(const char *fname,                   const char *name,                   const void *value,                   size_t size){        char path[PATH_MAX];        if (strcmp(name, "system.posix_acl_access") == 0)        {                name = "system.*";        }        smbw_fix_path(fname, path);        return smbc_lgetxattr(path, name, value, size);}int smbw_fgetxattr(int smbw_fd,                   const char *name,                   const void *value,                   size_t size){        int client_fd;                if (strcmp(name, "system.posix_acl_access") == 0)        {                name = "system.*";        }        client_fd = smbw_fd_map[smbw_fd];        return smbc_fgetxattr(client_fd, name, value, size);}int smbw_removexattr(const char *fname,                     const char *name){        char path[PATH_MAX];        if (strcmp(name, "system.posix_acl_access") == 0)        {                name = "system.*";        }        smbw_fix_path(fname, path);        return smbc_removexattr(path, name);}int smbw_lremovexattr(const char *fname,                      const char *name){        char path[PATH_MAX];        if (strcmp(name, "system.posix_acl_access") == 0)        {                name = "system.*";        }        smbw_fix_path(fname, path);        return smbc_lremovexattr(path, name);}int smbw_fremovexattr(int smbw_fd,                      const char *name){        int client_fd;                if (strcmp(name, "system.posix_acl_access") == 0)        {                name = "system.*";        }        client_fd = smbw_fd_map[smbw_fd];        return smbc_fremovexattr(client_fd, name);}int smbw_listxattr(const char *fname,                   char *list,                   size_t size){        char path[PATH_MAX];        smbw_fix_path(fname, path);        return smbc_listxattr(path, list, size);}int smbw_llistxattr(const char *fname,                    char *list,                    size_t size){        char path[PATH_MAX];        smbw_fix_path(fname, path);        return smbc_llistxattr(path, list, size);}int smbw_flistxattr(int smbw_fd,                    char *list,                    size_t size){        int client_fd;                client_fd = smbw_fd_map[smbw_fd];        return smbc_flistxattr(client_fd, list, size);}

⌨️ 快捷键说明

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