xref: /freebsd/lib/libc/posix1e/acl_flag.c (revision aa015c8e)
1 /*-
2  * Copyright (c) 2008, 2009 Edward Tomasz Napierała <trasz@FreeBSD.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  */
26 
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
29 
30 #include <stdio.h>
31 #include <errno.h>
32 #include <sys/acl.h>
33 
34 #include "acl_support.h"
35 
36 static int
37 _flag_is_invalid(acl_flag_t flag)
38 {
39 
40 	if ((flag & ACL_FLAGS_BITS) == flag)
41 		return (0);
42 
43 	errno = EINVAL;
44 
45 	return (1);
46 }
47 
48 int
49 acl_add_flag_np(acl_flagset_t flagset_d, acl_flag_t flag)
50 {
51 
52 	if (flagset_d == NULL) {
53 		errno = EINVAL;
54 		return (-1);
55 	}
56 
57 	if (_flag_is_invalid(flag))
58 		return (-1);
59 
60 	*flagset_d |= flag;
61 
62 	return (0);
63 }
64 
65 int
66 acl_clear_flags_np(acl_flagset_t flagset_d)
67 {
68 
69 	if (flagset_d == NULL) {
70 		errno = EINVAL;
71 		return (-1);
72 	}
73 
74 	*flagset_d |= 0;
75 
76 	return (0);
77 }
78 
79 int
80 acl_delete_flag_np(acl_flagset_t flagset_d, acl_flag_t flag)
81 {
82 
83 	if (flagset_d == NULL) {
84 		errno = EINVAL;
85 		return (-1);
86 	}
87 
88 	if (_flag_is_invalid(flag))
89 		return (-1);
90 
91 	*flagset_d &= ~flag;
92 
93 	return (0);
94 }
95 
96 int
97 acl_get_flag_np(acl_flagset_t flagset_d, acl_flag_t flag)
98 {
99 
100 	if (flagset_d == NULL) {
101 		errno = EINVAL;
102 		return (-1);
103 	}
104 
105 	if (_flag_is_invalid(flag))
106 		return (-1);
107 
108 	if (*flagset_d & flag)
109 		return (1);
110 
111 	return (0);
112 }
113 
114 int
115 acl_get_flagset_np(acl_entry_t entry_d, acl_flagset_t *flagset_p)
116 {
117 
118 	if (entry_d == NULL || flagset_p == NULL) {
119 		errno = EINVAL;
120 		return (-1);
121 	}
122 
123 	if (!_entry_brand_may_be(entry_d, ACL_BRAND_NFS4)) {
124 		errno = EINVAL;
125 		return (-1);
126 	}
127 
128 	*flagset_p = &entry_d->ae_flags;
129 
130 	return (0);
131 }
132 
133 int
134 acl_set_flagset_np(acl_entry_t entry_d, acl_flagset_t flagset_d)
135 {
136 
137 	if (entry_d == NULL) {
138 		errno = EINVAL;
139 		return (-1);
140 	}
141 
142 	if (!_entry_brand_may_be(entry_d, ACL_BRAND_NFS4)) {
143 		errno = EINVAL;
144 		return (-1);
145 	}
146 
147 	_entry_brand_as(entry_d, ACL_BRAND_NFS4);
148 
149 	if (_flag_is_invalid(*flagset_d))
150 		return (-1);
151 
152 	entry_d->ae_flags = *flagset_d;
153 
154 	return (0);
155 }
156 /*-
157  * Copyright (c) 2008, 2009 Edward Tomasz Napierała <trasz@FreeBSD.org>
158  * All rights reserved.
159  *
160  * Redistribution and use in source and binary forms, with or without
161  * modification, are permitted provided that the following conditions
162  * are met:
163  * 1. Redistributions of source code must retain the above copyright
164  *    notice, this list of conditions and the following disclaimer.
165  * 2. Redistributions in binary form must reproduce the above copyright
166  *    notice, this list of conditions and the following disclaimer in the
167  *    documentation and/or other materials provided with the distribution.
168  *
169  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
170  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
171  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
172  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
173  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
174  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
175  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
176  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
177  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
178  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
179  * SUCH DAMAGE.
180  */
181 
182 #include <sys/cdefs.h>
183 __FBSDID("$FreeBSD$");
184 
185 #include <stdio.h>
186 #include <errno.h>
187 #include <sys/acl.h>
188 
189 #include "acl_support.h"
190 
191 static int
192 _flag_is_invalid(acl_flag_t flag)
193 {
194 
195 	if ((flag & ACL_FLAGS_BITS) == flag)
196 		return (0);
197 
198 	errno = EINVAL;
199 
200 	return (1);
201 }
202 
203 int
204 acl_add_flag_np(acl_flagset_t flagset_d, acl_flag_t flag)
205 {
206 
207 	if (flagset_d == NULL) {
208 		errno = EINVAL;
209 		return (-1);
210 	}
211 
212 	if (_flag_is_invalid(flag))
213 		return (-1);
214 
215 	*flagset_d |= flag;
216 
217 	return (0);
218 }
219 
220 int
221 acl_clear_flags_np(acl_flagset_t flagset_d)
222 {
223 
224 	if (flagset_d == NULL) {
225 		errno = EINVAL;
226 		return (-1);
227 	}
228 
229 	*flagset_d |= 0;
230 
231 	return (0);
232 }
233 
234 int
235 acl_delete_flag_np(acl_flagset_t flagset_d, acl_flag_t flag)
236 {
237 
238 	if (flagset_d == NULL) {
239 		errno = EINVAL;
240 		return (-1);
241 	}
242 
243 	if (_flag_is_invalid(flag))
244 		return (-1);
245 
246 	*flagset_d &= ~flag;
247 
248 	return (0);
249 }
250 
251 int
252 acl_get_flag_np(acl_flagset_t flagset_d, acl_flag_t flag)
253 {
254 
255 	if (flagset_d == NULL) {
256 		errno = EINVAL;
257 		return (-1);
258 	}
259 
260 	if (_flag_is_invalid(flag))
261 		return (-1);
262 
263 	if (*flagset_d & flag)
264 		return (1);
265 
266 	return (0);
267 }
268 
269 int
270 acl_get_flagset_np(acl_entry_t entry_d, acl_flagset_t *flagset_p)
271 {
272 
273 	if (entry_d == NULL || flagset_p == NULL) {
274 		errno = EINVAL;
275 		return (-1);
276 	}
277 
278 	if (!_entry_brand_may_be(entry_d, ACL_BRAND_NFS4)) {
279 		errno = EINVAL;
280 		return (-1);
281 	}
282 
283 	*flagset_p = &entry_d->ae_flags;
284 
285 	return (0);
286 }
287 
288 int
289 acl_set_flagset_np(acl_entry_t entry_d, acl_flagset_t flagset_d)
290 {
291 
292 	if (entry_d == NULL) {
293 		errno = EINVAL;
294 		return (-1);
295 	}
296 
297 	if (!_entry_brand_may_be(entry_d, ACL_BRAND_NFS4)) {
298 		errno = EINVAL;
299 		return (-1);
300 	}
301 
302 	_entry_brand_as(entry_d, ACL_BRAND_NFS4);
303 
304 	if (_flag_is_invalid(*flagset_d))
305 		return (-1);
306 
307 	entry_d->ae_flags = *flagset_d;
308 
309 	return (0);
310 }
311 /*-
312  * Copyright (c) 2008, 2009 Edward Tomasz Napierała <trasz@FreeBSD.org>
313  * All rights reserved.
314  *
315  * Redistribution and use in source and binary forms, with or without
316  * modification, are permitted provided that the following conditions
317  * are met:
318  * 1. Redistributions of source code must retain the above copyright
319  *    notice, this list of conditions and the following disclaimer.
320  * 2. Redistributions in binary form must reproduce the above copyright
321  *    notice, this list of conditions and the following disclaimer in the
322  *    documentation and/or other materials provided with the distribution.
323  *
324  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
325  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
326  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
327  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
328  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
329  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
330  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
331  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
332  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
333  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
334  * SUCH DAMAGE.
335  */
336 
337 #include <sys/cdefs.h>
338 __FBSDID("$FreeBSD$");
339 
340 #include <stdio.h>
341 #include <errno.h>
342 #include <sys/acl.h>
343 
344 #include "acl_support.h"
345 
346 static int
347 _flag_is_invalid(acl_flag_t flag)
348 {
349 
350 	if ((flag & ACL_FLAGS_BITS) == flag)
351 		return (0);
352 
353 	errno = EINVAL;
354 
355 	return (1);
356 }
357 
358 int
359 acl_add_flag_np(acl_flagset_t flagset_d, acl_flag_t flag)
360 {
361 
362 	if (flagset_d == NULL) {
363 		errno = EINVAL;
364 		return (-1);
365 	}
366 
367 	if (_flag_is_invalid(flag))
368 		return (-1);
369 
370 	*flagset_d |= flag;
371 
372 	return (0);
373 }
374 
375 int
376 acl_clear_flags_np(acl_flagset_t flagset_d)
377 {
378 
379 	if (flagset_d == NULL) {
380 		errno = EINVAL;
381 		return (-1);
382 	}
383 
384 	*flagset_d |= 0;
385 
386 	return (0);
387 }
388 
389 int
390 acl_delete_flag_np(acl_flagset_t flagset_d, acl_flag_t flag)
391 {
392 
393 	if (flagset_d == NULL) {
394 		errno = EINVAL;
395 		return (-1);
396 	}
397 
398 	if (_flag_is_invalid(flag))
399 		return (-1);
400 
401 	*flagset_d &= ~flag;
402 
403 	return (0);
404 }
405 
406 int
407 acl_get_flag_np(acl_flagset_t flagset_d, acl_flag_t flag)
408 {
409 
410 	if (flagset_d == NULL) {
411 		errno = EINVAL;
412 		return (-1);
413 	}
414 
415 	if (_flag_is_invalid(flag))
416 		return (-1);
417 
418 	if (*flagset_d & flag)
419 		return (1);
420 
421 	return (0);
422 }
423 
424 int
425 acl_get_flagset_np(acl_entry_t entry_d, acl_flagset_t *flagset_p)
426 {
427 
428 	if (entry_d == NULL || flagset_p == NULL) {
429 		errno = EINVAL;
430 		return (-1);
431 	}
432 
433 	if (!_entry_brand_may_be(entry_d, ACL_BRAND_NFS4)) {
434 		errno = EINVAL;
435 		return (-1);
436 	}
437 
438 	*flagset_p = &entry_d->ae_flags;
439 
440 	return (0);
441 }
442 
443 int
444 acl_set_flagset_np(acl_entry_t entry_d, acl_flagset_t flagset_d)
445 {
446 
447 	if (entry_d == NULL) {
448 		errno = EINVAL;
449 		return (-1);
450 	}
451 
452 	if (!_entry_brand_may_be(entry_d, ACL_BRAND_NFS4)) {
453 		errno = EINVAL;
454 		return (-1);
455 	}
456 
457 	_entry_brand_as(entry_d, ACL_BRAND_NFS4);
458 
459 	if (_flag_is_invalid(*flagset_d))
460 		return (-1);
461 
462 	entry_d->ae_flags = *flagset_d;
463 
464 	return (0);
465 }
466