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

📄 sysacls.c

📁 samba-3.0.22.tar.gz 编译smb服务器的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
/*    Unix SMB/CIFS implementation.   Samba system utilities for ACL support.   Copyright (C) Jeremy Allison 2000.      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_ACLS/* This file wraps all differing system ACL interfaces into a consistent one based on the POSIX interface. It also returns the correct errors for older UNIX systems that don't support ACLs. The interfaces that each ACL implementation must support are as follows : int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p) int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p) int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d) SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type) SMB_ACL_T sys_acl_get_fd(int fd) int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset); int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm); char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen) SMB_ACL_T sys_acl_init( int count) int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry) int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype) int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual) int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset) int sys_acl_valid( SMB_ACL_T theacl ) int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl) int sys_acl_set_fd( int fd, SMB_ACL_T theacl) int sys_acl_delete_def_file(const char *path) This next one is not POSIX complient - but we *have* to have it ! More POSIX braindamage. int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm) The generic POSIX free is the following call. We split this into several different free functions as we may need to add tag info to structures when emulating the POSIX interface. int sys_acl_free( void *obj_p) The calls we actually use are : int sys_acl_free_text(char *text) - free acl_to_text int sys_acl_free_acl(SMB_ACL_T posix_acl) int sys_acl_free_qualifier(void *qualifier, SMB_ACL_TAG_T tagtype)*/#if defined(HAVE_POSIX_ACLS)/* Identity mapping - easy. */int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p){	return acl_get_entry( the_acl, entry_id, entry_p);}int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p){	return acl_get_tag_type( entry_d, tag_type_p);}int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p){	return acl_get_permset( entry_d, permset_p);}void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d){	return acl_get_qualifier( entry_d);}SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type){	return acl_get_file( path_p, type);}SMB_ACL_T sys_acl_get_fd(int fd){	return acl_get_fd(fd);}int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset){	return acl_clear_perms(permset);}int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm){	return acl_add_perm(permset, perm);}int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm){#if defined(HAVE_ACL_GET_PERM_NP)	/*	 * Required for TrustedBSD-based ACL implementations where	 * non-POSIX.1e functions are denoted by a _np (non-portable)	 * suffix.	 */	return acl_get_perm_np(permset, perm);#else	return acl_get_perm(permset, perm);#endif}char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen){	return acl_to_text( the_acl, plen);}SMB_ACL_T sys_acl_init( int count){	return acl_init(count);}int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry){	return acl_create_entry(pacl, pentry);}int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype){	return acl_set_tag_type(entry, tagtype);}int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual){	return acl_set_qualifier(entry, qual);}int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset){	return acl_set_permset(entry, permset);}int sys_acl_valid( SMB_ACL_T theacl ){	return acl_valid(theacl);}int sys_acl_set_file(const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl){	return acl_set_file(name, acltype, theacl);}int sys_acl_set_fd( int fd, SMB_ACL_T theacl){	return acl_set_fd(fd, theacl);}int sys_acl_delete_def_file(const char *name){	return acl_delete_def_file(name);}int sys_acl_free_text(char *text){	return acl_free(text);}int sys_acl_free_acl(SMB_ACL_T the_acl) {	return acl_free(the_acl);}int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype){	return acl_free(qual);}#elif defined(HAVE_TRU64_ACLS)/* * The interface to DEC/Compaq Tru64 UNIX ACLs * is based on Draft 13 of the POSIX spec which is * slightly different from the Draft 16 interface. *  * Also, some of the permset manipulation functions * such as acl_clear_perm() and acl_add_perm() appear * to be broken on Tru64 so we have to manipulate * the permission bits in the permset directly. */int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p){	SMB_ACL_ENTRY_T	entry;	if (entry_id == SMB_ACL_FIRST_ENTRY && acl_first_entry(the_acl) != 0) {		return -1;	}	errno = 0;	if ((entry = acl_get_entry(the_acl)) != NULL) {		*entry_p = entry;		return 1;	}	return errno ? -1 : 0;}int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p){	return acl_get_tag_type( entry_d, tag_type_p);}int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p){	return acl_get_permset( entry_d, permset_p);}void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d){	return acl_get_qualifier( entry_d);}SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type){	return acl_get_file((char *)path_p, type);}SMB_ACL_T sys_acl_get_fd(int fd){	return acl_get_fd(fd, ACL_TYPE_ACCESS);}int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset){	*permset = 0;		/* acl_clear_perm() is broken on Tru64	*/	return 0;}int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm){	if (perm & ~(SMB_ACL_READ | SMB_ACL_WRITE | SMB_ACL_EXECUTE)) {		errno = EINVAL;		return -1;	}	*permset |= perm;	/* acl_add_perm() is broken on Tru64	*/	return 0;}int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm){	return *permset & perm;	/* Tru64 doesn't have acl_get_perm() */}char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen){	return acl_to_text( the_acl, plen);}SMB_ACL_T sys_acl_init( int count){	return acl_init(count);}int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry){	SMB_ACL_ENTRY_T entry;	if ((entry = acl_create_entry(pacl)) == NULL) {		return -1;	}	*pentry = entry;	return 0;}int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype){	return acl_set_tag_type(entry, tagtype);}int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual){	return acl_set_qualifier(entry, qual);}int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset){	return acl_set_permset(entry, permset);}int sys_acl_valid( SMB_ACL_T theacl ){	acl_entry_t	entry;	return acl_valid(theacl, &entry);}int sys_acl_set_file( const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl){	return acl_set_file((char *)name, acltype, theacl);}int sys_acl_set_fd( int fd, SMB_ACL_T theacl){	return acl_set_fd(fd, ACL_TYPE_ACCESS, theacl);}int sys_acl_delete_def_file(const char *name){	return acl_delete_def_file((char *)name);}int sys_acl_free_text(char *text){	/*	 * (void) cast and explicit return 0 are for DEC UNIX	 *  which just #defines acl_free_text() to be free()	 */	(void) acl_free_text(text);	return 0;}int sys_acl_free_acl(SMB_ACL_T the_acl) {	return acl_free(the_acl);}int sys_acl_free_qualifier(void *qual, SMB_ACL_TAG_T tagtype){	return acl_free_qualifier(qual, tagtype);}#elif defined(HAVE_UNIXWARE_ACLS) || defined(HAVE_SOLARIS_ACLS)/* * Donated by Michael Davidson <md@sco.COM> for UnixWare / OpenUNIX. * Modified by Toomas Soome <tsoome@ut.ee> for Solaris. *//* * Note that while this code implements sufficient functionality * to support the sys_acl_* interfaces it does not provide all * of the semantics of the POSIX ACL interfaces. * * In particular, an ACL entry descriptor (SMB_ACL_ENTRY_T) returned * from a call to sys_acl_get_entry() should not be assumed to be * valid after calling any of the following functions, which may * reorder the entries in the ACL. * *	sys_acl_valid() *	sys_acl_set_file() *	sys_acl_set_fd() *//* * The only difference between Solaris and UnixWare / OpenUNIX is * that the #defines for the ACL operations have different names */#if defined(HAVE_UNIXWARE_ACLS)#define	SETACL		ACL_SET#define	GETACL		ACL_GET#define	GETACLCNT	ACL_CNT#endifint sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p){	if (entry_id != SMB_ACL_FIRST_ENTRY && entry_id != SMB_ACL_NEXT_ENTRY) {		errno = EINVAL;		return -1;	}	if (entry_p == NULL) {		errno = EINVAL;		return -1;	}	if (entry_id == SMB_ACL_FIRST_ENTRY) {		acl_d->next = 0;	}	if (acl_d->next < 0) {		errno = EINVAL;		return -1;	}	if (acl_d->next >= acl_d->count) {		return 0;	}	*entry_p = &acl_d->acl[acl_d->next++];	return 1;}int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p){	*type_p = entry_d->a_type;	return 0;}int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p){	*permset_p = &entry_d->a_perm;	return 0;}void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d){	if (entry_d->a_type != SMB_ACL_USER	    && entry_d->a_type != SMB_ACL_GROUP) {		errno = EINVAL;		return NULL;	}	return &entry_d->a_id;}/* * There is no way of knowing what size the ACL returned by * GETACL will be unless you first call GETACLCNT which means * making an additional system call. * * In the hope of avoiding the cost of the additional system * call in most cases, we initially allocate enough space for * an ACL with INITIAL_ACL_SIZE entries. If this turns out to * be too small then we use GETACLCNT to find out the actual * size, reallocate the ACL buffer, and then call GETACL again. */#define	INITIAL_ACL_SIZE	16SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type){	SMB_ACL_T	acl_d;	int		count;		/* # of ACL entries allocated	*/	int		naccess;	/* # of access ACL entries	*/	int		ndefault;	/* # of default ACL entries	*/	if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {		errno = EINVAL;		return NULL;	}	count = INITIAL_ACL_SIZE;	if ((acl_d = sys_acl_init(count)) == NULL) {		return NULL;	}	/*	 * If there isn't enough space for the ACL entries we use	 * GETACLCNT to determine the actual number of ACL entries	 * reallocate and try again. This is in a loop because it	 * is possible that someone else could modify the ACL and	 * increase the number of entries between the call to	 * GETACLCNT and the call to GETACL.	 */	while ((count = acl(path_p, GETACL, count, &acl_d->acl[0])) < 0	    && errno == ENOSPC) {		sys_acl_free_acl(acl_d);		if ((count = acl(path_p, GETACLCNT, 0, NULL)) < 0) {			return NULL;		}		if ((acl_d = sys_acl_init(count)) == NULL) {			return NULL;		}	}	if (count < 0) {		sys_acl_free_acl(acl_d);		return NULL;	}	/*	 * calculate the number of access and default ACL entries	 *	 * Note: we assume that the acl() system call returned a	 * well formed ACL which is sorted so that all of the	 * access ACL entries preceed any default ACL entries	 */	for (naccess = 0; naccess < count; naccess++) {		if (acl_d->acl[naccess].a_type & ACL_DEFAULT)			break;	}	ndefault = count - naccess;		/*	 * if the caller wants the default ACL we have to copy	 * the entries down to the start of the acl[] buffer	 * and mask out the ACL_DEFAULT flag from the type field	 */	if (type == SMB_ACL_TYPE_DEFAULT) {		int	i, j;		for (i = 0, j = naccess; i < ndefault; i++, j++) {			acl_d->acl[i] = acl_d->acl[j];			acl_d->acl[i].a_type &= ~ACL_DEFAULT;		}		acl_d->count = ndefault;	} else {		acl_d->count = naccess;	}	return acl_d;}SMB_ACL_T sys_acl_get_fd(int fd){	SMB_ACL_T	acl_d;	int		count;		/* # of ACL entries allocated	*/	int		naccess;	/* # of access ACL entries	*/	count = INITIAL_ACL_SIZE;	if ((acl_d = sys_acl_init(count)) == NULL) {		return NULL;	}	while ((count = facl(fd, GETACL, count, &acl_d->acl[0])) < 0	    && errno == ENOSPC) {		sys_acl_free_acl(acl_d);		if ((count = facl(fd, GETACLCNT, 0, NULL)) < 0) {			return NULL;		}		if ((acl_d = sys_acl_init(count)) == NULL) {			return NULL;		}	}	if (count < 0) {		sys_acl_free_acl(acl_d);		return NULL;	}	/*	 * calculate the number of access ACL entries	 */	for (naccess = 0; naccess < count; naccess++) {		if (acl_d->acl[naccess].a_type & ACL_DEFAULT)			break;	}		acl_d->count = naccess;

⌨️ 快捷键说明

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