1/*
2  File: acl_calc_mask.c
3
4  Copyright (C) 1999, 2000
5  Andreas Gruenbacher, <a.gruenbacher@computer.org>
6
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  Library General Public License for more details.
16
17  You should have received a copy of the GNU Library General Public
18  License along with this library; if not, write to the Free Software
19  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20*/
21
22#include "libacl.h"
23
24
25/* 23.4.2 */
26int
27acl_calc_mask(acl_t *acl_p)
28{
29	acl_obj *acl_obj_p;
30	acl_entry_obj *entry_obj_p, *mask_obj_p = NULL;
31	permset_t perm = ACL_PERM_NONE;
32	if (!acl_p) {
33		errno = EINVAL;
34		return -1;
35	}
36	acl_obj_p = ext2int(acl, *acl_p);
37	if (!acl_obj_p)
38		return -1;
39	FOREACH_ACL_ENTRY(entry_obj_p, acl_obj_p) {
40		switch(entry_obj_p->etag) {
41			case ACL_USER_OBJ:
42			case ACL_OTHER:
43				break;
44			case ACL_MASK:
45				mask_obj_p = entry_obj_p;
46				break;
47			case ACL_USER:
48			case ACL_GROUP_OBJ:
49			case ACL_GROUP:
50				perm |= entry_obj_p->eperm.sperm;
51				break;
52			default:
53				errno = EINVAL;
54				return -1;
55		}
56	}
57	if (mask_obj_p == NULL) {
58		mask_obj_p = __acl_create_entry_obj(acl_obj_p);
59		if (mask_obj_p == NULL)
60			return -1;
61		mask_obj_p->etag = ACL_MASK;
62		__acl_reorder_entry_obj_p(mask_obj_p);
63	}
64	mask_obj_p->eperm.sperm = perm;
65	return 0;
66}
67
68