kernel - Update swapcache manual page
[dragonfly.git] / contrib / bind / lib / isc / fsaccess.c
blob5c9718318eaea273c02d1364cec086aef2036298
1 /*
2 * Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 2000, 2001 Internet Software Consortium.
5 * Permission to use, copy, modify, and/or 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.10 2007/06/19 23:47:17 tbox Exp $ */
20 /*! \file
21 * \brief
22 * This file contains the OS-independent functionality of the API.
24 #include <isc/fsaccess.h>
25 #include <isc/result.h>
26 #include <isc/util.h>
28 /*!
29 * Shorthand. Maybe ISC__FSACCESS_PERMISSIONBITS should not even be in
30 * <isc/fsaccess.h>. Could check consistency with sizeof(isc_fsaccess_t)
31 * and the number of bits in each function.
33 #define STEP (ISC__FSACCESS_PERMISSIONBITS)
34 #define GROUP (STEP)
35 #define OTHER (STEP * 2)
37 void
38 isc_fsaccess_add(int trustee, int permission, isc_fsaccess_t *access) {
39 REQUIRE(trustee <= 0x7);
40 REQUIRE(permission <= 0xFF);
42 if ((trustee & ISC_FSACCESS_OWNER) != 0)
43 *access |= permission;
45 if ((trustee & ISC_FSACCESS_GROUP) != 0)
46 *access |= (permission << GROUP);
48 if ((trustee & ISC_FSACCESS_OTHER) != 0)
49 *access |= (permission << OTHER);
52 void
53 isc_fsaccess_remove(int trustee, int permission, isc_fsaccess_t *access) {
54 REQUIRE(trustee <= 0x7);
55 REQUIRE(permission <= 0xFF);
58 if ((trustee & ISC_FSACCESS_OWNER) != 0)
59 *access &= ~permission;
61 if ((trustee & ISC_FSACCESS_GROUP) != 0)
62 *access &= ~(permission << GROUP);
64 if ((trustee & ISC_FSACCESS_OTHER) != 0)
65 *access &= ~(permission << OTHER);
68 static isc_result_t
69 check_bad_bits(isc_fsaccess_t access, isc_boolean_t is_dir) {
70 isc_fsaccess_t bits;
73 * Check for disallowed user bits.
75 if (is_dir)
76 bits = ISC_FSACCESS_READ |
77 ISC_FSACCESS_WRITE |
78 ISC_FSACCESS_EXECUTE;
79 else
80 bits = ISC_FSACCESS_CREATECHILD |
81 ISC_FSACCESS_ACCESSCHILD |
82 ISC_FSACCESS_DELETECHILD |
83 ISC_FSACCESS_LISTDIRECTORY;
86 * Set group bad bits.
88 bits |= bits << STEP;
90 * Set other bad bits.
92 bits |= bits << STEP;
94 if ((access & bits) != 0) {
95 if (is_dir)
96 return (ISC_R_NOTFILE);
97 else
98 return (ISC_R_NOTDIRECTORY);
101 return (ISC_R_SUCCESS);