Esempio n. 1
0
int
acl_cmp(acl_t acl1, acl_t acl2)
{
	acl_obj *acl1_obj_p = ext2int(acl, acl1),
	        *acl2_obj_p = ext2int(acl, acl2);
	acl_entry_obj *p1_obj_p, *p2_obj_p;
	if (!acl1_obj_p || !acl2_obj_p)
		return -1;
	if (acl1_obj_p->aused != acl2_obj_p->aused)
		return 1;
	p2_obj_p = acl2_obj_p->anext;
	FOREACH_ACL_ENTRY(p1_obj_p, acl1_obj_p) {
		if (p1_obj_p->etag != p2_obj_p->etag)
			return 1;
		if (!permset_obj_equal(p1_obj_p->eperm,p2_obj_p->eperm))
			return 1;
		switch(p1_obj_p->etag) {
			case ACL_USER:
			case ACL_GROUP:
				if (qualifier_obj_id(p1_obj_p->eid) !=
				    qualifier_obj_id(p2_obj_p->eid))
					return 1;
				
		}
		p2_obj_p = p2_obj_p->enext;
	}
	return 0;
}
Esempio n. 2
0
/* 23.4.23 */
int
acl_set_permset(acl_entry_t entry_d, acl_permset_t permset_d)
{
	acl_entry_obj *entry_obj_p = ext2int(acl_entry, entry_d);
	acl_permset_obj *acl_permset_obj_p = ext2int(acl_permset, permset_d);
	if (!entry_obj_p || !acl_permset_obj_p)
		return -1;
	entry_obj_p->eperm.i = acl_permset_obj_p->i;
	return 0;
}
/* 23.4.5 */
ssize_t
acl_copy_ext(void *buf_p, acl_t acl, ssize_t size)
{
	struct __acl *acl_ext = (struct __acl *)buf_p;
	struct __acl_entry *ent_p = acl_ext->x_entries;
	acl_obj *acl_obj_p = ext2int(acl, acl);
	acl_entry_obj *entry_obj_p;
	ssize_t size_required;
	
	if (!acl_obj_p)
		return -1;
	size_required = sizeof(struct __acl) +
	                acl_obj_p->aused * sizeof(struct __acl_entry);
	if (size < size_required) {
		errno = ERANGE;
		return -1;
	}
	acl_ext->x_size = size_required;
	FOREACH_ACL_ENTRY(entry_obj_p, acl_obj_p) {
		//ent_p->e_tag  = cpu_to_le16(entry_obj_p->etag);
		//ent_p->e_perm = cpu_to_le16(entry_obj_p->eperm.sperm);
		//ent_p->e_id   = cpu_to_le32(entry_obj_p->eid.quid);
		*ent_p++ = entry_obj_p->eentry;
	}
	return 0;
}
Esempio n. 4
0
/* 23.4.22 */
int
acl_set_file(const char *path_p, acl_type_t type, acl_t acl)
{
	acl_obj *acl_obj_p = ext2int(acl, acl);
	char *ext_acl_p;
	const char *name;
	size_t size;
	int error;

	if (!acl_obj_p)
		return -1;
	switch (type) {
		case ACL_TYPE_ACCESS:
			name = ACL_EA_ACCESS;
			break;
		case ACL_TYPE_DEFAULT:
			name = ACL_EA_DEFAULT;
			break;
		default:
			errno = EINVAL;
			return -1;
	}

	ext_acl_p = __acl_to_xattr(acl_obj_p, &size);
	if (!ext_acl_p)
		return -1;
	error = setxattr(path_p, name, (char *)ext_acl_p, size, 0);
	free(ext_acl_p);
	return error;
}
Esempio n. 5
0
int
acl_get_perm(acl_permset_t permset_d, acl_perm_t perm)
{
	acl_permset_obj *acl_permset_obj_p = ext2int(acl_permset, permset_d);
	if (!acl_permset_obj_p || (perm & !(ACL_READ|ACL_WRITE|ACL_EXECUTE)))
		return -1;
	return (acl_permset_obj_p->sperm & perm) != 0;
}
Esempio n. 6
0
int
acl_entries(acl_t acl)
{
	acl_obj *acl_obj_p = ext2int(acl, acl);
	if (!acl_obj_p)
		return -1;
	return acl_obj_p->aused;
}
Esempio n. 7
0
/* 23.4.3 */
int
acl_clear_perms(acl_permset_t permset_d)
{
	acl_permset_obj *acl_permset_obj_p = ext2int(acl_permset, permset_d);
	if (!acl_permset_obj_p)
		return -1;
	acl_permset_obj_p->sperm = ACL_PERM_NONE;
	return 0;
}
/* 23.4.9 */
int
acl_delete_entry(acl_t acl, acl_entry_t entry_d)
{
	acl_obj *acl_obj_p = ext2int(acl, acl);
	acl_entry_obj *entry_obj_p = ext2int(acl_entry, entry_d);
	if (!acl_obj_p || !entry_obj_p)
		return -1;


	if (acl_obj_p->acurr == entry_obj_p)
		acl_obj_p->acurr = acl_obj_p->acurr->eprev;
	entry_obj_p->eprev->enext = entry_obj_p->enext;
	entry_obj_p->enext->eprev = entry_obj_p->eprev;

	free_obj_p(entry_obj_p);
	acl_obj_p->aused--;
	return 0;
}
Esempio n. 9
0
/* 23.4.21 */
int
acl_set_fd(int fd, acl_t acl)
{
	acl_obj *acl_obj_p = ext2int(acl, acl);
	char *ext_acl_p;
	const char *name = ACL_EA_ACCESS;
	size_t size;
	int error;

	if (!acl_obj_p)
		return -1;
	ext_acl_p = __acl_to_xattr(acl_obj_p, &size);
	if (!ext_acl_p)
		return -1;
	error = fsetxattr(fd, name, (char *)ext_acl_p, size, 0);
	free(ext_acl_p);
	return error;
}
Esempio n. 10
0
/* 23.4.22 */
int
acl_set_file(const char *path_p, acl_type_t type, acl_t acl)
{
	acl_obj *acl_obj_p = ext2int(acl, acl);
	char *ext_acl_p;
	const char *name;
	size_t size;
	int error;

	if (!acl_obj_p)
		return -1;
	switch (type) {
		case ACL_TYPE_ACCESS:
			name = ACL_EA_ACCESS;
			break;
		case ACL_TYPE_DEFAULT:
			name = ACL_EA_DEFAULT;
			break;
		default:
			errno = EINVAL;
			return -1;
	}

	if (type == ACL_TYPE_DEFAULT) {
		struct stat st;

		if (stat(path_p, &st) != 0)
			return -1;

		/* Only directories may have default ACLs. */
		if (!S_ISDIR(st.st_mode)) {
			errno = EACCES;
			return -1;
		}
	}

	ext_acl_p = __acl_to_xattr(acl_obj_p, &size);
	if (!ext_acl_p)
		return -1;
	error = setxattr(path_p, name, (char *)ext_acl_p, size, 0);
	free(ext_acl_p);
	return error;
}
Esempio n. 11
0
int
acl_equiv_mode(acl_t acl, mode_t *mode_p)
{
	acl_obj *acl_obj_p = ext2int(acl, acl);
	acl_entry_obj *entry_obj_p, *mask_obj_p = NULL;
	int not_equiv = 0;
	mode_t mode = 0;
	if (!acl_obj_p)
		return -1;
	FOREACH_ACL_ENTRY(entry_obj_p, acl_obj_p) {
		switch(entry_obj_p->etag) {
			case ACL_USER_OBJ:
				mode |= (entry_obj_p->eperm.sperm
				         & S_IRWXO) << 6;
				break;
			case ACL_GROUP_OBJ:
				mode |= (entry_obj_p->eperm.sperm &
				         S_IRWXO) << 3;
				break;
			case ACL_OTHER:
				mode |= (entry_obj_p->eperm.sperm &
				         S_IRWXO);
				break;
			case ACL_MASK:
				mask_obj_p = entry_obj_p;
				/* fall through */
			case ACL_USER:
			case ACL_GROUP:
				not_equiv = 1;
				break;
			default:
				errno = EINVAL;
				return -1;
		}
	}
	if (mode_p) {
		if (mask_obj_p)
			mode = (mode & ~S_IRWXG) |
			       ((mask_obj_p->eperm.sperm & S_IRWXO) << 3);
		*mode_p = mode;
	}
	return not_equiv;
}
Esempio n. 12
0
/* 23.4.7 */
int
acl_create_entry(acl_t *acl_p, acl_entry_t *entry_p)
{
    acl_obj *acl_obj_p;
    acl_entry_obj *entry_obj_p;
    if (!acl_p || !entry_p) {
        if (entry_p)
            *entry_p = NULL;
        errno = EINVAL;
        return -1;
    }
    acl_obj_p = ext2int(acl, *acl_p);
    if (!acl_obj_p)
        return -1;
    entry_obj_p = __acl_create_entry_obj(acl_obj_p);
    if (entry_obj_p == NULL)
        return -1;
    *entry_p = int2ext(entry_obj_p);
    return 0;
}
Esempio n. 13
0
/* 23.4.2 */
int
acl_calc_mask(acl_t *acl_p)
{
	acl_obj *acl_obj_p;
	acl_entry_obj *entry_obj_p, *mask_obj_p = NULL;
	permset_t perm = ACL_PERM_NONE;
	if (!acl_p) {
		errno = EINVAL;
		return -1;
	}
	acl_obj_p = ext2int(acl, *acl_p);
	if (!acl_obj_p)
		return -1;
	FOREACH_ACL_ENTRY(entry_obj_p, acl_obj_p) {
		switch(entry_obj_p->etag) {
			case ACL_USER_OBJ:
			case ACL_OTHER:
				break;
			case ACL_MASK:
				mask_obj_p = entry_obj_p;
				break;
			case ACL_USER:
			case ACL_GROUP_OBJ:
			case ACL_GROUP:
				perm |= entry_obj_p->eperm.sperm;
				break;
			default:
				errno = EINVAL;
				return -1;
		}
	}
	if (mask_obj_p == NULL) {
		mask_obj_p = __acl_create_entry_obj(acl_obj_p);
		if (mask_obj_p == NULL)
			return -1;
		mask_obj_p->etag = ACL_MASK;
		__acl_reorder_entry_obj_p(mask_obj_p);
	}
	mask_obj_p->eperm.sperm = perm;
	return 0;
}
Esempio n. 14
0
/* 23.4.11 */
acl_t
acl_dup(acl_t acl)
{
	acl_entry_obj *entry_obj_p, *dup_entry_obj_p;
	acl_obj *acl_obj_p = ext2int(acl, acl);
	acl_obj *dup_obj_p;

	if (!acl_obj_p)
		return NULL;
	dup_obj_p = __acl_init_obj(acl_obj_p->aused);
	if (!dup_obj_p)
		return NULL;

	FOREACH_ACL_ENTRY(entry_obj_p, acl_obj_p) {
		dup_entry_obj_p = __acl_create_entry_obj(dup_obj_p);
		if (dup_entry_obj_p == NULL)
			goto fail;

		dup_entry_obj_p->etag  = entry_obj_p->etag;
		dup_entry_obj_p->eid   = entry_obj_p->eid;
		dup_entry_obj_p->eperm = entry_obj_p->eperm;
	}
/* 23.4.24 */
int
acl_set_qualifier(acl_entry_t entry_d, const void *tag_qualifier_p)
{
	acl_entry_obj *entry_obj_p = ext2int(acl_entry, entry_d);
	if (!entry_obj_p)
		return -1;


	switch(entry_obj_p->etag) {
		case ACL_USER:
			entry_obj_p->eid.qid = *(id_t *)tag_qualifier_p;
			break;
		case ACL_GROUP:
			entry_obj_p->eid.qid = *(id_t *)tag_qualifier_p;
			break;
		default:
			errno = EINVAL;
			return -1;
	}
	__acl_reorder_entry_obj_p(entry_obj_p);
	return 0;
}
int
acl_equiv_mode(acl_t acl, mode_t *mode_p)
{
	acl_obj *acl_obj_p = ext2int(acl, acl);
	acl_entry_obj *entry_obj_p;
	int not_equiv = 0;
	mode_t mode = 0;
	if (!acl_obj_p)
		return -1;
	FOREACH_ACL_ENTRY(entry_obj_p, acl_obj_p) {
		switch(entry_obj_p->etag) {
			case ACL_USER_OBJ:
				mode |= (entry_obj_p->eperm.sperm
				         & S_IRWXO) << 6;
				break;
			case ACL_GROUP_OBJ:
				mode |= (entry_obj_p->eperm.sperm &
				         S_IRWXO) << 3;
				break;
			case ACL_OTHER:
				mode |= (entry_obj_p->eperm.sperm &
				         S_IRWXO);
				break;
			case ACL_USER:
			case ACL_GROUP:
			case ACL_MASK:
				not_equiv = 1;
				break;
			default:
				errno = EINVAL;
				return -1;
		}
	}
	if (mode_p)
		*mode_p = mode;
	return not_equiv;
}