2 * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 2000, 2001 Internet Software Consortium.
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: fsaccess.c,v 1.5.206.1 2004/03/06 08:14:29 marka Exp $ */
21 * This file contains the OS-independent functionality of the API.
23 #include <isc/fsaccess.h>
24 #include <isc/result.h>
28 * Shorthand. Maybe ISC__FSACCESS_PERMISSIONBITS should not even be in
29 * <isc/fsaccess.h>. Could check consistency with sizeof(isc_fsaccess_t)
30 * and the number of bits in each function.
32 #define STEP (ISC__FSACCESS_PERMISSIONBITS)
34 #define OTHER (STEP * 2)
37 isc_fsaccess_add(int trustee, int permission, isc_fsaccess_t *access) {
38 REQUIRE(trustee <= 0x7);
39 REQUIRE(permission <= 0xFF);
41 if ((trustee & ISC_FSACCESS_OWNER) != 0)
42 *access |= permission;
44 if ((trustee & ISC_FSACCESS_GROUP) != 0)
45 *access |= (permission << GROUP);
47 if ((trustee & ISC_FSACCESS_OTHER) != 0)
48 *access |= (permission << OTHER);
52 isc_fsaccess_remove(int trustee, int permission, isc_fsaccess_t *access) {
53 REQUIRE(trustee <= 0x7);
54 REQUIRE(permission <= 0xFF);
57 if ((trustee & ISC_FSACCESS_OWNER) != 0)
58 *access &= ~permission;
60 if ((trustee & ISC_FSACCESS_GROUP) != 0)
61 *access &= ~(permission << GROUP);
63 if ((trustee & ISC_FSACCESS_OTHER) != 0)
64 *access &= ~(permission << OTHER);
68 check_bad_bits(isc_fsaccess_t access, isc_boolean_t is_dir) {
72 * Check for disallowed user bits.
75 bits = ISC_FSACCESS_READ |
79 bits = ISC_FSACCESS_CREATECHILD |
80 ISC_FSACCESS_ACCESSCHILD |
81 ISC_FSACCESS_DELETECHILD |
82 ISC_FSACCESS_LISTDIRECTORY;
93 if ((access & bits) != 0) {
95 return (ISC_R_NOTFILE);
97 return (ISC_R_NOTDIRECTORY);
100 return (ISC_R_SUCCESS);