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

📄 system.c

📁 samba-3.0.22.tar.gz 编译smb服务器的源码
💻 C
📖 第 1 页 / 共 4 页
字号:
	errno = ENOSYS;	return -1;#else	return readlink(path, buf, bufsiz);#endif}/*******************************************************************system wrapper for link********************************************************************/int sys_link(const char *oldpath, const char *newpath){#ifndef HAVE_LINK	errno = ENOSYS;	return -1;#else	return link(oldpath, newpath);#endif}/*******************************************************************chown isn't used much but OS/2 doesn't have it********************************************************************/int sys_chown(const char *fname,uid_t uid,gid_t gid){#ifndef HAVE_CHOWN	static int done;	if (!done) {		DEBUG(1,("WARNING: no chown!\n"));		done=1;	}	errno = ENOSYS;	return -1;#else	return(chown(fname,uid,gid));#endif}/*******************************************************************os/2 also doesn't have chroot********************************************************************/int sys_chroot(const char *dname){#ifndef HAVE_CHROOT	static int done;	if (!done) {		DEBUG(1,("WARNING: no chroot!\n"));		done=1;	}	errno = ENOSYS;	return -1;#else	return(chroot(dname));#endif}/**************************************************************************A wrapper for gethostbyname() that tries avoids looking up hostnames in the root domain, which can cause dial-on-demand links to come up for noapparent reason.****************************************************************************/struct hostent *sys_gethostbyname(const char *name){#ifdef REDUCE_ROOT_DNS_LOOKUPS	char query[256], hostname[256];	char *domain;	/* Does this name have any dots in it? If so, make no change */	if (strchr_m(name, '.'))		return(gethostbyname(name));	/* Get my hostname, which should have domain name 		attached. If not, just do the gethostname on the		original string. 	*/	gethostname(hostname, sizeof(hostname) - 1);	hostname[sizeof(hostname) - 1] = 0;	if ((domain = strchr_m(hostname, '.')) == NULL)		return(gethostbyname(name));	/* Attach domain name to query and do modified query.		If names too large, just do gethostname on the		original string.	*/	if((strlen(name) + strlen(domain)) >= sizeof(query))		return(gethostbyname(name));	slprintf(query, sizeof(query)-1, "%s%s", name, domain);	return(gethostbyname(query));#else /* REDUCE_ROOT_DNS_LOOKUPS */	return(gethostbyname(name));#endif /* REDUCE_ROOT_DNS_LOOKUPS */}#if defined(HAVE_IRIX_SPECIFIC_CAPABILITIES)/************************************************************************** Try and abstract process capabilities (for systems that have them).****************************************************************************/static BOOL set_process_capability( uint32 cap_flag, BOOL enable ){	if(cap_flag == KERNEL_OPLOCK_CAPABILITY) {		cap_t cap = cap_get_proc();		if (cap == NULL) {			DEBUG(0,("set_process_capability: cap_get_proc failed. Error was %s\n",				strerror(errno)));			return False;		}		if(enable)			cap->cap_effective |= CAP_NETWORK_MGT;		else			cap->cap_effective &= ~CAP_NETWORK_MGT;		if (cap_set_proc(cap) == -1) {			DEBUG(0,("set_process_capability: cap_set_proc failed. Error was %s\n",				strerror(errno)));			cap_free(cap);			return False;		}		cap_free(cap);		DEBUG(10,("set_process_capability: Set KERNEL_OPLOCK_CAPABILITY.\n"));	}	return True;}/************************************************************************** Try and abstract inherited process capabilities (for systems that have them).****************************************************************************/static BOOL set_inherited_process_capability( uint32 cap_flag, BOOL enable ){	if(cap_flag == KERNEL_OPLOCK_CAPABILITY) {		cap_t cap = cap_get_proc();		if (cap == NULL) {			DEBUG(0,("set_inherited_process_capability: cap_get_proc failed. Error was %s\n",				strerror(errno)));			return False;		}		if(enable)			cap->cap_inheritable |= CAP_NETWORK_MGT;		else			cap->cap_inheritable &= ~CAP_NETWORK_MGT;		if (cap_set_proc(cap) == -1) {			DEBUG(0,("set_inherited_process_capability: cap_set_proc failed. Error was %s\n", 				strerror(errno)));			cap_free(cap);			return False;		}		cap_free(cap);		DEBUG(10,("set_inherited_process_capability: Set KERNEL_OPLOCK_CAPABILITY.\n"));	}	return True;}#endif/**************************************************************************** Gain the oplock capability from the kernel if possible.****************************************************************************/void oplock_set_capability(BOOL this_process, BOOL inherit){#if HAVE_KERNEL_OPLOCKS_IRIX	set_process_capability(KERNEL_OPLOCK_CAPABILITY,this_process);	set_inherited_process_capability(KERNEL_OPLOCK_CAPABILITY,inherit);#endif}/************************************************************************** Wrapper for random().****************************************************************************/long sys_random(void){#if defined(HAVE_RANDOM)	return (long)random();#elif defined(HAVE_RAND)	return (long)rand();#else	DEBUG(0,("Error - no random function available !\n"));	exit(1);#endif}/************************************************************************** Wrapper for srandom().****************************************************************************/void sys_srandom(unsigned int seed){#if defined(HAVE_SRANDOM)	srandom(seed);#elif defined(HAVE_SRAND)	srand(seed);#else	DEBUG(0,("Error - no srandom function available !\n"));	exit(1);#endif}/************************************************************************** Returns equivalent to NGROUPS_MAX - using sysconf if needed.****************************************************************************/int groups_max(void){#if defined(SYSCONF_SC_NGROUPS_MAX)	int ret = sysconf(_SC_NGROUPS_MAX);	return (ret == -1) ? NGROUPS_MAX : ret;#else	return NGROUPS_MAX;#endif}/************************************************************************** Wrapper for getgroups. Deals with broken (int) case.****************************************************************************/int sys_getgroups(int setlen, gid_t *gidset){#if !defined(HAVE_BROKEN_GETGROUPS)	return getgroups(setlen, gidset);#else	GID_T gid;	GID_T *group_list;	int i, ngroups;	if(setlen == 0) {		return getgroups(setlen, &gid);	}	/*	 * Broken case. We need to allocate a	 * GID_T array of size setlen.	 */	if(setlen < 0) {		errno = EINVAL; 		return -1;	} 	if (setlen == 0)		setlen = groups_max();	if((group_list = (GID_T *)malloc(setlen * sizeof(GID_T))) == NULL) {		DEBUG(0,("sys_getgroups: Malloc fail.\n"));		return -1;	}	if((ngroups = getgroups(setlen, group_list)) < 0) {		int saved_errno = errno;		SAFE_FREE(group_list);		errno = saved_errno;		return -1;	}	for(i = 0; i < ngroups; i++)		gidset[i] = (gid_t)group_list[i];	SAFE_FREE(group_list);	return ngroups;#endif /* HAVE_BROKEN_GETGROUPS */}/************************************************************************** Wrapper for setgroups. Deals with broken (int) case. Automatically used if we have broken getgroups.****************************************************************************/int sys_setgroups(int setlen, gid_t *gidset){#if !defined(HAVE_SETGROUPS)	errno = ENOSYS;	return -1;#endif /* HAVE_SETGROUPS */#if !defined(HAVE_BROKEN_GETGROUPS)	return setgroups(setlen, gidset);#else	GID_T *group_list;	int i ; 	if (setlen == 0)		return 0 ;	if (setlen < 0 || setlen > groups_max()) {		errno = EINVAL; 		return -1;   	}	/*	 * Broken case. We need to allocate a	 * GID_T array of size setlen.	 */	if((group_list = (GID_T *)malloc(setlen * sizeof(GID_T))) == NULL) {		DEBUG(0,("sys_setgroups: Malloc fail.\n"));		return -1;    	} 	for(i = 0; i < setlen; i++) 		group_list[i] = (GID_T) gidset[i]; 	if(setgroups(setlen, group_list) != 0) {		int saved_errno = errno;		SAFE_FREE(group_list);		errno = saved_errno;		return -1;	} 	SAFE_FREE(group_list);	return 0 ;#endif /* HAVE_BROKEN_GETGROUPS */}/************************************************************************** Wrappers for setpwent(), getpwent() and endpwent()****************************************************************************/void sys_setpwent(void){	setpwent();}struct passwd *sys_getpwent(void){	return getpwent();}void sys_endpwent(void){	endpwent();}/************************************************************************** Wrappers for getpwnam(), getpwuid(), getgrnam(), getgrgid()****************************************************************************/struct passwd *sys_getpwnam(const char *name){	return getpwnam(name);}struct passwd *sys_getpwuid(uid_t uid){	return getpwuid(uid);}struct group *sys_getgrnam(const char *name){	return getgrnam(name);}struct group *sys_getgrgid(gid_t gid){	return getgrgid(gid);}#if 0 /* NOT CURRENTLY USED - JRA *//************************************************************************** The following are the UNICODE versions of *all* system interface functions called within Samba. Ok, ok, the exceptions are the gethostbyXX calls, which currently are left as ascii as they are not used other than in name resolution.****************************************************************************//************************************************************************** Wide stat. Just narrow and call sys_xxx.****************************************************************************/int wsys_stat(const smb_ucs2_t *wfname,SMB_STRUCT_STAT *sbuf){	pstring fname;	return sys_stat(unicode_to_unix(fname,wfname,sizeof(fname)), sbuf);}/************************************************************************** Wide lstat. Just narrow and call sys_xxx.****************************************************************************/int wsys_lstat(const smb_ucs2_t *wfname,SMB_STRUCT_STAT *sbuf){	pstring fname;	return sys_lstat(unicode_to_unix(fname,wfname,sizeof(fname)), sbuf);}/************************************************************************** Wide creat. Just narrow and call sys_xxx.****************************************************************************/int wsys_creat(const smb_ucs2_t *wfname, mode_t mode){	pstring fname;	return sys_creat(unicode_to_unix(fname,wfname,sizeof(fname)), mode);}/************************************************************************** Wide open. Just narrow and call sys_xxx.****************************************************************************/int wsys_open(const smb_ucs2_t *wfname, int oflag, mode_t mode){	pstring fname;	return sys_open(unicode_to_unix(fname,wfname,sizeof(fname)), oflag, mode);}/************************************************************************** Wide fopen. Just narrow and call sys_xxx.****************************************************************************/FILE *wsys_fopen(const smb_ucs2_t *wfname, const char *type){	pstring fname;	return sys_fopen(unicode_to_unix(fname,wfname,sizeof(fname)), type);}/************************************************************************** Wide opendir. Just narrow and call sys_xxx.****************************************************************************/SMB_STRUCT_DIR *wsys_opendir(const smb_ucs2_t *wfname){	pstring fname;	return opendir(unicode_to_unix(fname,wfname,sizeof(fname)));}/************************************************************************** Wide readdir. Return a structure pointer containing a wide filename.****************************************************************************/SMB_STRUCT_WDIRENT *wsys_readdir(SMB_STRUCT_DIR *dirp){	static SMB_STRUCT_WDIRENT retval;	SMB_STRUCT_DIRENT *dirval = sys_readdir(dirp);	if(!dirval)		return NULL;	/*	 * The only POSIX defined member of this struct is d_name.	 */	unix_to_unicode(retval.d_name,dirval->d_name,sizeof(retval.d_name));	return &retval;}/************************************************************************** Wide getwd. Call sys_xxx and widen. Assumes s points to a wpstring.****************************************************************************/smb_ucs2_t *wsys_getwd(smb_ucs2_t *s){	pstring fname;	char *p = sys_getwd(fname);	if(!p)		return NULL;	return unix_to_unicode(s, p, sizeof(wpstring));}/************************************************************************** Wide chown. Just narrow and call sys_xxx.****************************************************************************/int wsys_chown(const smb_ucs2_t *wfname, uid_t uid, gid_t gid){	pstring fname;	return chown(unicode_to_unix(fname,wfname,sizeof(fname)), uid, gid);}/************************************************************************** Wide chroot. Just narrow and call sys_xxx.****************************************************************************/int wsys_chroot(const smb_ucs2_t *wfname){	pstring fname;	return chroot(unicode_to_unix(fname,wfname,sizeof(fname)));}/************************************************************************** Wide getpwnam. Return a structure pointer containing wide names.****************************************************************************/SMB_STRUCT_WPASSWD *wsys_getpwnam(const smb_ucs2_t *wname){	static SMB_STRUCT_WPASSWD retval;	fstring name;	struct passwd *pwret = sys_getpwnam(unicode_to_unix(name,wname,sizeof(name)));	if(!pwret)		return NULL;	unix_to_unicode(retval.pw_name, pwret->pw_name, sizeof(retval.pw_name));	retval.pw_passwd = pwret->pw_passwd;	retval.pw_uid = pwret->pw_uid;	retval.pw_gid = pwret->pw_gid;	unix_to_unicode(retval.pw_gecos, pwret->pw_gecos, sizeof(retval.pw_gecos));	unix_to_unicode(retval.pw_dir, pwret->pw_dir, sizeof(retval.pw_dir));	unix_to_unicode(retval.pw_shell, pwret->pw_shell, sizeof(retval.pw_shell));	return &retval;}/************************************************************************** Wide getpwuid. Return a structure pointer containing wide names.

⌨️ 快捷键说明

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