First compiling version of code that sets NT ACLs as POSIX ACLs.
[samba.git] / source3 / lib / sysacls.c
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 2.2.
4    Samba system utilities for ACL support.
5    Copyright (C) Jeremy Allison 2000.
6    
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include "includes.h"
23
24 extern int DEBUGLEVEL;
25
26 /*
27  This file wraps all differing system ACL interfaces into a consistent
28  one based on the POSIX interface. It also returns the correct errors
29  for older UNIX systems that don't support ACLs.
30
31  The interfaces that each ACL implementation must support are as follows :
32
33  int sys_acl_get_entry( SMB_ACL_T theacl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
34  int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
35  int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p
36  void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
37  SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
38  SMB_ACL_T sys_acl_get_fd(int fd)
39  int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
40  int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
41  char *sys_acl_to_text( SMB_ACL_T theacl, ssize_t *plen)
42  SMB_ACL_T sys_acl_init( int count)
43  int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
44  int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
45  int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
46  int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
47  int sys_acl_valid( SMB_ACL_T theacl )
48  int sys_acl_set_file( char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
49  int sys_acl_set_fd( int fd, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
50
51  This next one is not POSIX complient - but we *have* to have it !
52  More POSIX braindamage.
53
54  int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
55
56  The generic POSIX free is the following call. We split this into
57  several different free functions as we may need to add tag info
58  to structures when emulating the POSIX interface.
59
60  int sys_acl_free( void *obj_p)
61
62  The calls we actually use are :
63
64  int sys_acl_free_text(char *text) - free acl_to_text
65  int sys_acl_free_acl(SMB_ACL_T posix_acl)
66
67 */
68
69 #if defined(HAVE_POSIX_ACLS)
70
71 /* Identity mapping - easy. */
72
73 int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
74 {
75         return acl_get_entry( the_acl, entry_id, entry_p);
76 }
77
78 int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
79 {
80         return acl_get_tag_type( entry_d, tag_type_p);
81 }
82
83 int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
84 {
85         return acl_get_permset( entry_d, permset_p);
86 }
87
88 void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
89 {
90         return acl_get_qualifier( entry_d);
91 }
92
93 SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
94 {
95         return acl_get_file( path_p, type);
96 }
97
98 SMB_ACL_T sys_acl_get_fd(int fd)
99 {
100         return acl_get_fd(fd);
101 }
102
103 int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
104 {
105         return acl_clear_perms(permset);
106 }
107
108 int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
109 {
110         return acl_add_perm(permset, perm);
111 }
112
113 int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
114 {
115         return acl_get_perm(permset, perm);
116 }
117
118 char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
119 {
120         return acl_to_text( the_acl, plen);
121 }
122
123 SMB_ACL_T sys_acl_init( int count)
124 {
125         return acl_init(count);
126 }
127
128 int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
129 {
130         return acl_create_entry(pacl, pentry);
131 }
132
133 int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
134 {
135         return acl_set_tag_type(entry, tagtype);
136 }
137
138 int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
139 {
140         return acl_set_qualifier(entry, qual);
141 }
142
143 int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
144 {
145         return acl_set_permset(entry, permset);
146 }
147
148 int sys_acl_valid( SMB_ACL_T theacl )
149 {
150         return acl_valid(thacl);
151 }
152
153 int sys_acl_set_file( char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
154 {
155         return acl_set_file(name, acltype, theacl);
156 }
157
158 int sys_acl_set_fd( int fd, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
159 {
160         return acl_set_fd(fd, acltype, theacl);
161 }
162
163 int sys_acl_free_text(char *text)
164 {
165         return acl_free(text);
166 }
167
168 int sys_acl_free_acl(SMB_ACL_T the_acl) 
169 {
170         return acl_free(the_acl);
171 }
172
173 #elif defined(HAVE_SOLARIS_ACLS)
174
175 #elif defined(HAVE_IRIX_ACLS)
176
177 #else /* No ACLs. */
178
179 int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p)
180 {
181         return -1;
182 }
183
184 int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p)
185 {
186         return -1;
187 }
188
189 int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p)
190 {
191         return -1;
192 }
193
194 void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d)
195 {
196         return NULL;
197 }
198
199 SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type)
200 {
201         return (SMB_ACL_T)NULL;
202 }
203
204 SMB_ACL_T sys_acl_get_fd(int fd)
205 {
206         return (SMB_ACL_T)NULL;
207 }
208
209 int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset)
210 {
211         return -1;
212 }
213
214 int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
215 {
216         return -1;
217 }
218
219 int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm)
220 {
221         return (permset & perm) ? 1 : 0;
222 }
223
224 char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen)
225 {
226         return NULL;
227 }
228
229 int sys_acl_free_text(char *text)
230 {
231         return -1;
232 }
233
234 SMB_ACL_T sys_acl_init( int count)
235 {
236         return NULL;
237 }
238
239 int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
240 {
241         return -1;
242 }
243
244 int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype)
245 {
246         return -1;
247 }
248
249 int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual)
250 {
251         return -1;
252 }
253
254 int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset)
255 {
256         return -1;
257 }
258
259 int sys_acl_valid( SMB_ACL_T theacl )
260 {
261         return -1;
262 }
263
264 int sys_acl_set_file( char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
265 {
266         return -1;
267 }
268
269 int sys_acl_set_fd( int fd, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
270 {
271         return -1;
272 }
273
274 int sys_acl_free_acl(SMB_ACL_T the_acl) 
275 {
276         return -1;
277 }
278 #endif /* No ACLs. */