1*9034ec65Schristos /*	$NetBSD: fsaccess.h,v 1.6 2020/05/25 20:47:21 christos Exp $	*/
2abb0f93cSkardel 
3abb0f93cSkardel /*
4abb0f93cSkardel  * Copyright (C) 2004-2007, 2009  Internet Systems Consortium, Inc. ("ISC")
5abb0f93cSkardel  * Copyright (C) 2000, 2001  Internet Software Consortium.
6abb0f93cSkardel  *
7abb0f93cSkardel  * Permission to use, copy, modify, and/or distribute this software for any
8abb0f93cSkardel  * purpose with or without fee is hereby granted, provided that the above
9abb0f93cSkardel  * copyright notice and this permission notice appear in all copies.
10abb0f93cSkardel  *
11abb0f93cSkardel  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12abb0f93cSkardel  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13abb0f93cSkardel  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14abb0f93cSkardel  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15abb0f93cSkardel  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16abb0f93cSkardel  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17abb0f93cSkardel  * PERFORMANCE OF THIS SOFTWARE.
18abb0f93cSkardel  */
19abb0f93cSkardel 
20*9034ec65Schristos /* Id: fsaccess.h,v 1.16 2009/01/17 23:47:43 tbox Exp  */
21abb0f93cSkardel 
22abb0f93cSkardel #ifndef ISC_FSACCESS_H
23abb0f93cSkardel #define ISC_FSACCESS_H 1
24abb0f93cSkardel 
25abb0f93cSkardel /*! \file isc/fsaccess.h
26abb0f93cSkardel  * \brief The ISC filesystem access module encapsulates the setting of file
27abb0f93cSkardel  * and directory access permissions into one API that is meant to be
28abb0f93cSkardel  * portable to multiple operating systems.
29abb0f93cSkardel  *
30abb0f93cSkardel  * The two primary operating system flavors that are initially accommodated
31abb0f93cSkardel  * are POSIX and Windows NT 4.0 and later.  The Windows NT access model is
32abb0f93cSkardel  * considerable more flexible than POSIX's model (as much as I am loathe to
33abb0f93cSkardel  * admit it), and so the ISC API has a higher degree of complexity than would
34abb0f93cSkardel  * be needed to simply address POSIX's needs.
35abb0f93cSkardel  *
36abb0f93cSkardel  * The full breadth of NT's flexibility is not available either, for the
37abb0f93cSkardel  * present time.  Much of it is to provide compatibility with what Unix
38abb0f93cSkardel  * programmers are expecting.  This is also due to not yet really needing all
39abb0f93cSkardel  * of the functionality of an NT system (or, for that matter, a POSIX system)
40abb0f93cSkardel  * in BIND9, and so resolving how to handle the various incompatibilities has
41abb0f93cSkardel  * been a purely theoretical exercise with no operational experience to
42abb0f93cSkardel  * indicate how flawed the thinking may be.
43abb0f93cSkardel  *
44abb0f93cSkardel  * Some of the more notable dumbing down of NT for this API includes:
45abb0f93cSkardel  *
46abb0f93cSkardel  *\li   Each of FILE_READ_DATA and FILE_READ_EA are set with #ISC_FSACCESS_READ.
47abb0f93cSkardel  *
48abb0f93cSkardel  * \li  All of FILE_WRITE_DATA, FILE_WRITE_EA and FILE_APPEND_DATA are
49abb0f93cSkardel  *     set with #ISC_FSACCESS_WRITE.  FILE_WRITE_ATTRIBUTES is not set
50abb0f93cSkardel  *     so as to be consistent with Unix, where only the owner of the file
51abb0f93cSkardel  *     or the superuser can change the attributes/mode of a file.
52abb0f93cSkardel  *
53abb0f93cSkardel  * \li  Both of FILE_ADD_FILE and FILE_ADD_SUBDIRECTORY are set with
54abb0f93cSkardel  *     #ISC_FSACCESS_CREATECHILD.  This is similar to setting the WRITE
55abb0f93cSkardel  *     permission on a Unix directory.
56abb0f93cSkardel  *
57abb0f93cSkardel  * \li  SYNCHRONIZE is always set for files and directories, unless someone
58abb0f93cSkardel  *     can give me a reason why this is a bad idea.
59abb0f93cSkardel  *
60abb0f93cSkardel  * \li  READ_CONTROL and FILE_READ_ATTRIBUTES are always set; this is
61abb0f93cSkardel  *     consistent with Unix, where any file or directory can be stat()'d
62abb0f93cSkardel  *     unless the directory path disallows complete access somewhere along
63abb0f93cSkardel  *     the way.
64abb0f93cSkardel  *
65abb0f93cSkardel  * \li  WRITE_DAC is only set for the owner.  This too is consistent with
66abb0f93cSkardel  *     Unix, and is tighter security than allowing anyone else to be
67abb0f93cSkardel  *     able to set permissions.
68abb0f93cSkardel  *
69abb0f93cSkardel  * \li  DELETE is only set for the owner.  On Unix the ability to delete
70abb0f93cSkardel  *     a file is controlled by the directory permissions, but it isn't
71abb0f93cSkardel  *     currently clear to me what happens on NT if the directory has
72abb0f93cSkardel  *     FILE_DELETE_CHILD set but a file within it does not have DELETE
73abb0f93cSkardel  *     set.  Always setting DELETE on the file/directory for the owner
74abb0f93cSkardel  *     gives maximum flexibility to the owner without exposing the
75abb0f93cSkardel  *     file to deletion by others.
76abb0f93cSkardel  *
77abb0f93cSkardel  * \li  WRITE_OWNER is never set.  This too is consistent with Unix,
78abb0f93cSkardel  *     and is also tighter security than allowing anyone to change the
79abb0f93cSkardel  *     ownership of the file apart from the superu..ahem, Administrator.
80abb0f93cSkardel  *
81abb0f93cSkardel  * \li  Inheritance is set to NO_INHERITANCE.
82abb0f93cSkardel  *
83abb0f93cSkardel  * Unix's dumbing down includes:
84abb0f93cSkardel  *
85abb0f93cSkardel  * \li  The sticky bit cannot be set.
86abb0f93cSkardel  *
87abb0f93cSkardel  * \li  setuid and setgid cannot be set.
88abb0f93cSkardel  *
89abb0f93cSkardel  * \li  Only regular files and directories can be set.
90abb0f93cSkardel  *
91abb0f93cSkardel  * The rest of this comment discusses a few of the incompatibilities
92abb0f93cSkardel  * between the two systems that need more thought if this API is to
93abb0f93cSkardel  * be extended to accommodate them.
94abb0f93cSkardel  *
95abb0f93cSkardel  * The Windows standard access right "DELETE" doesn't have a direct
96abb0f93cSkardel  * equivalent in the Unix world, so it isn't clear what should be done
97abb0f93cSkardel  * with it.
98abb0f93cSkardel  *
99abb0f93cSkardel  * The Unix sticky bit is not supported.  While NT does have a concept
100abb0f93cSkardel  * of allowing users to create files in a directory but not delete or
101abb0f93cSkardel  * rename them, it does not have a concept of allowing them to be deleted
102abb0f93cSkardel  * if they are owned by the user trying to delete/rename.  While it is
103abb0f93cSkardel  * probable that something could be cobbled together in NT 5 with inheritance,
104abb0f93cSkardel  * it can't really be done in NT 4 as a single property that you could
105abb0f93cSkardel  * set on a directory.  You'd need to coordinate something with file creation
106abb0f93cSkardel  * so that every file created had DELETE set for the owner but noone else.
107abb0f93cSkardel  *
108abb0f93cSkardel  * On Unix systems, setting #ISC_FSACCESS_LISTDIRECTORY sets READ.
109abb0f93cSkardel  * ... setting either #ISC_FSACCESS_CREATECHILD or #ISC_FSACCESS_DELETECHILD
110abb0f93cSkardel  *      sets WRITE.
111abb0f93cSkardel  * ... setting #ISC_FSACCESS_ACCESSCHILD sets EXECUTE.
112abb0f93cSkardel  *
113abb0f93cSkardel  * On NT systems, setting #ISC_FSACCESS_LISTDIRECTORY sets FILE_LIST_DIRECTORY.
114abb0f93cSkardel  * ... setting #ISC_FSACCESS_CREATECHILD sets FILE_CREATE_CHILD independently.
115abb0f93cSkardel  * ... setting #ISC_FSACCESS_DELETECHILD sets FILE_DELETE_CHILD independently.
116abb0f93cSkardel  * ... setting #ISC_FSACCESS_ACCESSCHILD sets FILE_TRAVERSE.
117abb0f93cSkardel  *
118abb0f93cSkardel  * Unresolved:							XXXDCL
119abb0f93cSkardel  * \li  What NT access right controls the ability to rename a file?
120abb0f93cSkardel  * \li  How does DELETE work?  If a directory has FILE_DELETE_CHILD but a
121abb0f93cSkardel  *      file or directory within it does not have DELETE, is that file
122abb0f93cSkardel  *	or directory deletable?
123abb0f93cSkardel  * \li  To implement isc_fsaccess_get(), mapping an existing Unix permission
124abb0f93cSkardel  * 	mode_t back to an isc_fsaccess_t is pretty trivial; however, mapping
125abb0f93cSkardel  *	an NT DACL could be impossible to do in a responsible way.
126abb0f93cSkardel  * \li  Similarly, trying to implement the functionality of being able to
127abb0f93cSkardel  *	say "add group writability to whatever permissions already exist"
128abb0f93cSkardel  *	could be tricky on NT because of the order-of-entry issue combined
129abb0f93cSkardel  *	with possibly having one or more matching ACEs already explicitly
130abb0f93cSkardel  *	granting or denying access.  Because this functionality is
131abb0f93cSkardel  *	not yet needed by the ISC, no code has been written to try to
132abb0f93cSkardel  * 	solve this problem.
133abb0f93cSkardel  */
134abb0f93cSkardel 
135abb0f93cSkardel #include <isc/lang.h>
136abb0f93cSkardel #include <isc/types.h>
137abb0f93cSkardel 
138abb0f93cSkardel /*
139abb0f93cSkardel  * Trustees.
140abb0f93cSkardel  */
141abb0f93cSkardel #define ISC_FSACCESS_OWNER	0x1 /*%< User account. */
142abb0f93cSkardel #define ISC_FSACCESS_GROUP	0x2 /*%< Primary group owner. */
143abb0f93cSkardel #define ISC_FSACCESS_OTHER	0x4 /*%< Not the owner or the group owner. */
144abb0f93cSkardel #define ISC_FSACCESS_WORLD	0x7 /*%< User, Group, Other. */
145abb0f93cSkardel 
146abb0f93cSkardel /*
147abb0f93cSkardel  * Types of permission.
148abb0f93cSkardel  */
149abb0f93cSkardel #define ISC_FSACCESS_READ		0x00000001 /*%< File only. */
150abb0f93cSkardel #define ISC_FSACCESS_WRITE		0x00000002 /*%< File only. */
151abb0f93cSkardel #define ISC_FSACCESS_EXECUTE		0x00000004 /*%< File only. */
152abb0f93cSkardel #define ISC_FSACCESS_CREATECHILD	0x00000008 /*%< Dir only. */
153abb0f93cSkardel #define ISC_FSACCESS_DELETECHILD	0x00000010 /*%< Dir only. */
154abb0f93cSkardel #define ISC_FSACCESS_LISTDIRECTORY	0x00000020 /*%< Dir only. */
155abb0f93cSkardel #define ISC_FSACCESS_ACCESSCHILD	0x00000040 /*%< Dir only. */
156abb0f93cSkardel 
157abb0f93cSkardel /*%
158abb0f93cSkardel  * Adding any permission bits beyond 0x200 would mean typedef'ing
159abb0f93cSkardel  * isc_fsaccess_t as isc_uint64_t, and redefining this value to
160abb0f93cSkardel  * reflect the new range of permission types, Probably to 21 for
161abb0f93cSkardel  * maximum flexibility.  The number of bits has to accommodate all of
162abb0f93cSkardel  * the permission types, and three full sets of them have to fit
163abb0f93cSkardel  * within an isc_fsaccess_t.
164abb0f93cSkardel  */
165abb0f93cSkardel #define ISC__FSACCESS_PERMISSIONBITS 10
166abb0f93cSkardel 
167abb0f93cSkardel ISC_LANG_BEGINDECLS
168abb0f93cSkardel 
169abb0f93cSkardel void
170abb0f93cSkardel isc_fsaccess_add(int trustee, int permission, isc_fsaccess_t *access);
171abb0f93cSkardel 
172abb0f93cSkardel void
173abb0f93cSkardel isc_fsaccess_remove(int trustee, int permission, isc_fsaccess_t *access);
174abb0f93cSkardel 
175abb0f93cSkardel isc_result_t
176abb0f93cSkardel isc_fsaccess_set(const char *path, isc_fsaccess_t access);
177abb0f93cSkardel 
178abb0f93cSkardel ISC_LANG_ENDDECLS
179abb0f93cSkardel 
180abb0f93cSkardel #endif /* ISC_FSACCESS_H */
181