This source file includes following definitions.
- acl_extended_nontrivial
- acl_access_nontrivial
- acl_default_nontrivial
- acl_nontrivial
- acl_ace_nontrivial
- acl_nontrivial
- aclv_nontrivial
- acl_nontrivial
- acl_nfs4_nontrivial
- acl_nontrivial
- free_permission_context
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 #include <config.h>
21
22 #include "acl.h"
23
24 #include "acl-internal.h"
25
26 #if USE_ACL && HAVE_ACL_GET_FILE
27
28 # if HAVE_ACL_TYPE_EXTENDED
29
30
31
32
33 int
34 acl_extended_nontrivial (acl_t acl)
35 {
36
37 return (acl_entries (acl) > 0);
38 }
39
40 # else
41
42
43
44
45
46 int
47 acl_access_nontrivial (acl_t acl)
48 {
49
50
51
52
53
54 # if HAVE_ACL_FIRST_ENTRY
55
56 acl_entry_t ace;
57 int got_one;
58
59 for (got_one = acl_get_entry (acl, ACL_FIRST_ENTRY, &ace);
60 got_one > 0;
61 got_one = acl_get_entry (acl, ACL_NEXT_ENTRY, &ace))
62 {
63 acl_tag_t tag;
64 if (acl_get_tag_type (ace, &tag) < 0)
65 return -1;
66 if (!(tag == ACL_USER_OBJ || tag == ACL_GROUP_OBJ || tag == ACL_OTHER))
67 return 1;
68 }
69 return got_one;
70
71 # elif HAVE_ACL_TO_SHORT_TEXT
72
73
74 int count = acl->acl_cnt;
75 int i;
76
77 for (i = 0; i < count; i++)
78 {
79 acl_entry_t ace = &acl->acl_entry[i];
80 acl_tag_t tag = ace->ae_tag;
81
82 if (!(tag == ACL_USER_OBJ || tag == ACL_GROUP_OBJ
83 || tag == ACL_OTHER_OBJ))
84 return 1;
85 }
86 return 0;
87
88 # elif HAVE_ACL_FREE_TEXT
89
90
91 int count = acl->acl_num;
92 acl_entry_t ace;
93
94 for (ace = acl->acl_first; count > 0; ace = ace->next, count--)
95 {
96 acl_tag_t tag;
97 acl_perm_t perm;
98
99 tag = ace->entry->acl_type;
100 if (!(tag == ACL_USER_OBJ || tag == ACL_GROUP_OBJ || tag == ACL_OTHER))
101 return 1;
102
103 perm = ace->entry->acl_perm;
104
105
106 if ((perm & ~(ACL_READ | ACL_WRITE | ACL_EXECUTE)) != 0)
107 return 1;
108 }
109 return 0;
110
111 # else
112
113 errno = ENOSYS;
114 return -1;
115 # endif
116 }
117
118 int
119 acl_default_nontrivial (acl_t acl)
120 {
121
122 return (acl_entries (acl) > 0);
123 }
124
125 # endif
126
127 #elif USE_ACL && HAVE_FACL && defined GETACL
128
129
130
131
132 int
133 acl_nontrivial (int count, aclent_t *entries)
134 {
135 int i;
136
137 for (i = 0; i < count; i++)
138 {
139 aclent_t *ace = &entries[i];
140
141
142
143
144 if (!(ace->a_type == USER_OBJ
145 || ace->a_type == GROUP_OBJ
146 || ace->a_type == OTHER_OBJ
147
148
149 || ace->a_type == CLASS_OBJ))
150 return 1;
151 }
152 return 0;
153 }
154
155 # ifdef ACE_GETACL
156
157
158 # define NEW_ACE_WRITEA_DATA (NEW_ACE_WRITE_DATA | NEW_ACE_APPEND_DATA)
159
160
161
162
163 int
164 acl_ace_nontrivial (int count, ace_t *entries)
165 {
166 int i;
167
168
169
170
171
172
173
174 int old_convention = 0;
175
176 for (i = 0; i < count; i++)
177 if (entries[i].a_flags & (OLD_ACE_OWNER | OLD_ACE_GROUP | OLD_ACE_OTHER))
178 {
179 old_convention = 1;
180 break;
181 }
182
183 if (old_convention)
184
185 for (i = 0; i < count; i++)
186 {
187 ace_t *ace = &entries[i];
188
189
190
191
192
193 if (!(ace->a_type == OLD_ALLOW
194 && (ace->a_flags == OLD_ACE_OWNER
195 || ace->a_flags == OLD_ACE_GROUP
196 || ace->a_flags == OLD_ACE_OTHER)))
197 return 1;
198 }
199 else
200 {
201
202 unsigned int access_masks[6] =
203 {
204 0,
205 0,
206 0,
207 0,
208 0,
209 0
210 };
211
212 for (i = 0; i < count; i++)
213 {
214 ace_t *ace = &entries[i];
215 unsigned int index1;
216 unsigned int index2;
217
218 if (ace->a_type == NEW_ACE_ACCESS_ALLOWED_ACE_TYPE)
219 index1 = 1;
220 else if (ace->a_type == NEW_ACE_ACCESS_DENIED_ACE_TYPE)
221 index1 = 0;
222 else
223 return 1;
224
225 if (ace->a_flags == NEW_ACE_OWNER)
226 index2 = 0;
227 else if (ace->a_flags == (NEW_ACE_GROUP | NEW_ACE_IDENTIFIER_GROUP))
228 index2 = 2;
229 else if (ace->a_flags == NEW_ACE_EVERYONE)
230 index2 = 4;
231 else
232 return 1;
233
234 access_masks[index1 + index2] |= ace->a_access_mask;
235 }
236
237
238 if (access_masks[0] & access_masks[1])
239 return 1;
240 if (access_masks[2] & access_masks[3])
241 return 1;
242 if (access_masks[4] & access_masks[5])
243 return 1;
244
245
246 if ((NEW_ACE_WRITE_NAMED_ATTRS
247 | NEW_ACE_WRITE_ATTRIBUTES
248 | NEW_ACE_WRITE_ACL
249 | NEW_ACE_WRITE_OWNER)
250 & ~ access_masks[1])
251 return 1;
252 access_masks[1] &= ~(NEW_ACE_WRITE_NAMED_ATTRS
253 | NEW_ACE_WRITE_ATTRIBUTES
254 | NEW_ACE_WRITE_ACL
255 | NEW_ACE_WRITE_OWNER);
256 if ((NEW_ACE_READ_NAMED_ATTRS
257 | NEW_ACE_READ_ATTRIBUTES
258 | NEW_ACE_READ_ACL
259 | NEW_ACE_SYNCHRONIZE)
260 & ~ access_masks[5])
261 return 1;
262 access_masks[5] &= ~(NEW_ACE_READ_NAMED_ATTRS
263 | NEW_ACE_READ_ATTRIBUTES
264 | NEW_ACE_READ_ACL
265 | NEW_ACE_SYNCHRONIZE);
266
267
268 switch ((access_masks[0] | access_masks[1])
269 & ~(NEW_ACE_READ_NAMED_ATTRS
270 | NEW_ACE_READ_ATTRIBUTES
271 | NEW_ACE_READ_ACL
272 | NEW_ACE_SYNCHRONIZE))
273 {
274 case 0:
275 case NEW_ACE_READ_DATA:
276 case NEW_ACE_WRITEA_DATA:
277 case NEW_ACE_READ_DATA | NEW_ACE_WRITEA_DATA:
278 case NEW_ACE_EXECUTE:
279 case NEW_ACE_READ_DATA | NEW_ACE_EXECUTE:
280 case NEW_ACE_WRITEA_DATA | NEW_ACE_EXECUTE:
281 case NEW_ACE_READ_DATA | NEW_ACE_WRITEA_DATA | NEW_ACE_EXECUTE:
282 break;
283 default:
284 return 1;
285 }
286 switch ((access_masks[2] | access_masks[3])
287 & ~(NEW_ACE_READ_NAMED_ATTRS
288 | NEW_ACE_READ_ATTRIBUTES
289 | NEW_ACE_READ_ACL
290 | NEW_ACE_SYNCHRONIZE))
291 {
292 case 0:
293 case NEW_ACE_READ_DATA:
294 case NEW_ACE_WRITEA_DATA:
295 case NEW_ACE_READ_DATA | NEW_ACE_WRITEA_DATA:
296 case NEW_ACE_EXECUTE:
297 case NEW_ACE_READ_DATA | NEW_ACE_EXECUTE:
298 case NEW_ACE_WRITEA_DATA | NEW_ACE_EXECUTE:
299 case NEW_ACE_READ_DATA | NEW_ACE_WRITEA_DATA | NEW_ACE_EXECUTE:
300 break;
301 default:
302 return 1;
303 }
304 switch ((access_masks[4] | access_masks[5])
305 & ~(NEW_ACE_WRITE_NAMED_ATTRS
306 | NEW_ACE_WRITE_ATTRIBUTES
307 | NEW_ACE_WRITE_ACL
308 | NEW_ACE_WRITE_OWNER))
309 {
310 case 0:
311 case NEW_ACE_READ_DATA:
312 case NEW_ACE_WRITEA_DATA:
313 case NEW_ACE_READ_DATA | NEW_ACE_WRITEA_DATA:
314 case NEW_ACE_EXECUTE:
315 case NEW_ACE_READ_DATA | NEW_ACE_EXECUTE:
316 case NEW_ACE_WRITEA_DATA | NEW_ACE_EXECUTE:
317 case NEW_ACE_READ_DATA | NEW_ACE_WRITEA_DATA | NEW_ACE_EXECUTE:
318 break;
319 default:
320 return 1;
321 }
322
323
324
325 if (((access_masks[0] & NEW_ACE_WRITE_DATA) != 0)
326 != ((access_masks[0] & NEW_ACE_APPEND_DATA) != 0))
327 return 1;
328 if (((access_masks[2] & NEW_ACE_WRITE_DATA) != 0)
329 != ((access_masks[2] & NEW_ACE_APPEND_DATA) != 0))
330 return 1;
331 if (((access_masks[4] & NEW_ACE_WRITE_DATA) != 0)
332 != ((access_masks[4] & NEW_ACE_APPEND_DATA) != 0))
333 return 1;
334 }
335
336 return 0;
337 }
338
339 # endif
340
341 #elif USE_ACL && HAVE_GETACL
342
343
344
345 int
346 acl_nontrivial (int count, struct acl_entry *entries)
347 {
348 int i;
349
350 if (count > 3)
351 return 1;
352
353 for (i = 0; i < count; i++)
354 {
355 struct acl_entry *ace = &entries[i];
356
357 if (ace->uid != ACL_NSUSER && ace->gid != ACL_NSGROUP)
358 return 1;
359 }
360 return 0;
361 }
362
363 # if HAVE_ACLV_H
364
365
366
367 int
368 aclv_nontrivial (int count, struct acl *entries)
369 {
370 int i;
371
372 for (i = 0; i < count; i++)
373 {
374 struct acl *ace = &entries[i];
375
376
377
378
379 if (!(ace->a_type == USER_OBJ
380 || ace->a_type == GROUP_OBJ
381 || ace->a_type == CLASS_OBJ
382 || ace->a_type == OTHER_OBJ))
383 return 1;
384 }
385 return 0;
386 }
387
388 # endif
389
390 #elif USE_ACL && (HAVE_ACLX_GET || HAVE_STATACL)
391
392
393
394 int
395 acl_nontrivial (struct acl *a)
396 {
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413 return (acl_last (a) != a->acl_ext ? 1 : 0);
414 }
415
416 # if HAVE_ACLX_GET && defined ACL_AIX_WIP
417
418
419
420 int
421 acl_nfs4_nontrivial (nfs4_acl_int_t *a)
422 {
423 # if 1
424 return (a->aclEntryN > 0 ? 1 : 0);
425 # else
426 int count = a->aclEntryN;
427 int i;
428
429 for (i = 0; i < count; i++)
430 {
431 nfs4_ace_int_t *ace = &a->aclEntry[i];
432
433 if (!((ace->flags & ACE4_ID_SPECIAL) != 0
434 && (ace->aceWho.special_whoid == ACE4_WHO_OWNER
435 || ace->aceWho.special_whoid == ACE4_WHO_GROUP
436 || ace->aceWho.special_whoid == ACE4_WHO_EVERYONE)
437 && ace->aceType == ACE4_ACCESS_ALLOWED_ACE_TYPE
438 && ace->aceFlags == 0
439 && (ace->aceMask & ~(ACE4_READ_DATA | ACE4_LIST_DIRECTORY
440 | ACE4_WRITE_DATA | ACE4_ADD_FILE
441 | ACE4_EXECUTE)) == 0))
442 return 1;
443 }
444 return 0;
445 # endif
446 }
447
448 # endif
449
450 #elif USE_ACL && HAVE_ACLSORT
451
452
453
454
455 int
456 acl_nontrivial (int count, struct acl *entries)
457 {
458 int i;
459
460 for (i = 0; i < count; i++)
461 {
462 struct acl *ace = &entries[i];
463
464
465
466
467 if (!(ace->a_type == USER_OBJ
468 || ace->a_type == GROUP_OBJ
469 || ace->a_type == CLASS_OBJ
470 || ace->a_type == OTHER_OBJ))
471 return 1;
472 }
473 return 0;
474 }
475
476 #endif
477
478 void
479 free_permission_context (struct permission_context *ctx)
480 {
481 #if USE_ACL
482 # if HAVE_ACL_GET_FILE
483 if (ctx->acl)
484 acl_free (ctx->acl);
485 # if !HAVE_ACL_TYPE_EXTENDED
486 if (ctx->default_acl)
487 acl_free (ctx->default_acl);
488 # endif
489
490 # elif defined GETACL
491 free (ctx->entries);
492 # ifdef ACE_GETACL
493 free (ctx->ace_entries);
494 # endif
495
496 # elif HAVE_GETACL
497
498 # if HAVE_ACLV_H
499 # endif
500
501 # elif HAVE_STATACL
502
503 # elif HAVE_ACLSORT
504
505 # endif
506 #endif
507 }