resetting manifest requested domain to floor
[platform/upstream/acl.git] / libacl / __acl_from_xattr.c
1 /*
2   File: __acl_from_xattr.c
3
4   Copyright (C) 1999, 2000
5   Andreas Gruenbacher, <a.gruenbacher@bestbits.at>
6
7   This program is free software; you can redistribute it and/or
8   modify it under the terms of the GNU Lesser General Public
9   License as published by the Free Software Foundation; either
10   version 2.1 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   Lesser General Public License for more details.
16
17   You should have received a copy of the GNU Lesser 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 #include "byteorder.h"
25 #include "acl_ea.h"
26
27
28 acl_t
29 __acl_from_xattr(const char *ext_acl_p, size_t size)
30 {
31         acl_ea_header *ext_header_p = (acl_ea_header *)ext_acl_p;
32         acl_ea_entry *ext_entry_p = (acl_ea_entry *)(ext_header_p+1);
33         acl_ea_entry *ext_end_p;
34         acl_obj *acl_obj_p;
35         acl_entry_obj *entry_obj_p;
36         int entries, error;
37
38         if (size < sizeof(acl_ea_header)) {
39                 errno = EINVAL;
40                 return NULL;
41         }
42         if (ext_header_p->a_version != cpu_to_le32(ACL_EA_VERSION)) {
43                 errno = EINVAL;
44                 return NULL;
45         }
46         size -= sizeof(acl_ea_header);
47         if (size % sizeof(acl_ea_entry)) {
48                 errno = EINVAL;
49                 return NULL;
50         }
51         entries = size / sizeof(acl_ea_entry);
52         ext_end_p = ext_entry_p + entries;
53
54         acl_obj_p = __acl_init_obj(entries);
55         if (acl_obj_p == NULL)
56                 return NULL;
57         while (ext_end_p != ext_entry_p) {
58                 entry_obj_p = __acl_create_entry_obj(acl_obj_p);
59                 if (!entry_obj_p)
60                         goto fail;
61
62                 entry_obj_p->etag        = le16_to_cpu(ext_entry_p->e_tag);
63                 entry_obj_p->eperm.sperm = le16_to_cpu(ext_entry_p->e_perm);
64
65                 switch(entry_obj_p->etag) {
66                         case ACL_USER_OBJ:
67                         case ACL_GROUP_OBJ:
68                         case ACL_MASK:
69                         case ACL_OTHER:
70                                 entry_obj_p->eid.qid = ACL_UNDEFINED_ID;
71                                 break;
72
73                         case ACL_USER:
74                         case ACL_GROUP:
75                                 entry_obj_p->eid.qid =
76                                         le32_to_cpu(ext_entry_p->e_id);
77                                 break;
78
79                         default:
80                                 error = EINVAL;
81                                 goto fail;
82                 }
83                 ext_entry_p++;
84         }
85         if (__acl_reorder_obj_p(acl_obj_p))
86                 goto fail;
87         return int2ext(acl_obj_p);
88
89 fail:
90         __acl_free_acl_obj(acl_obj_p);
91         return NULL;
92 }
93