4 * Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 2000, 2001 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id: fsaccess.c,v 1.10 2007/06/19 23:47:17 tbox Exp */
24 * This file contains the OS-independent functionality of the API.
26 #include <isc/fsaccess.h>
27 #include <isc/result.h>
31 * Shorthand. Maybe ISC__FSACCESS_PERMISSIONBITS should not even be in
32 * <isc/fsaccess.h>. Could check consistency with sizeof(isc_fsaccess_t)
33 * and the number of bits in each function.
35 #define STEP (ISC__FSACCESS_PERMISSIONBITS)
37 #define OTHER (STEP * 2)
40 isc_fsaccess_add(int trustee
, int permission
, isc_fsaccess_t
*access
) {
41 REQUIRE(trustee
<= 0x7);
42 REQUIRE(permission
<= 0xFF);
44 if ((trustee
& ISC_FSACCESS_OWNER
) != 0)
45 *access
|= permission
;
47 if ((trustee
& ISC_FSACCESS_GROUP
) != 0)
48 *access
|= (permission
<< GROUP
);
50 if ((trustee
& ISC_FSACCESS_OTHER
) != 0)
51 *access
|= (permission
<< OTHER
);
55 isc_fsaccess_remove(int trustee
, int permission
, isc_fsaccess_t
*access
) {
56 REQUIRE(trustee
<= 0x7);
57 REQUIRE(permission
<= 0xFF);
60 if ((trustee
& ISC_FSACCESS_OWNER
) != 0)
61 *access
&= ~permission
;
63 if ((trustee
& ISC_FSACCESS_GROUP
) != 0)
64 *access
&= ~(permission
<< GROUP
);
66 if ((trustee
& ISC_FSACCESS_OTHER
) != 0)
67 *access
&= ~(permission
<< OTHER
);
71 check_bad_bits(isc_fsaccess_t access
, isc_boolean_t is_dir
) {
75 * Check for disallowed user bits.
78 bits
= ISC_FSACCESS_READ
|
82 bits
= ISC_FSACCESS_CREATECHILD
|
83 ISC_FSACCESS_ACCESSCHILD
|
84 ISC_FSACCESS_DELETECHILD
|
85 ISC_FSACCESS_LISTDIRECTORY
;
96 if ((access
& bits
) != 0) {
98 return (ISC_R_NOTFILE
);
100 return (ISC_R_NOTDIRECTORY
);
103 return (ISC_R_SUCCESS
);