2 Unix SMB/Netbios implementation.
3 VFS module to get and set Tru64 acls
4 Copyright (C) Michael Adam 2006,2008
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "system/filesys.h"
22 #include "smbd/smbd.h"
23 #include "modules/vfs_tru64acl.h"
25 /* prototypes for private functions first - for clarity */
27 static struct smb_acl_t *tru64_acl_to_smb_acl(const struct acl *tru64_acl,
29 static bool tru64_ace_to_smb_ace(acl_entry_t tru64_ace,
30 struct smb_acl_entry *smb_ace);
31 static acl_t smb_acl_to_tru64_acl(const SMB_ACL_T smb_acl);
32 static acl_tag_t smb_tag_to_tru64(SMB_ACL_TAG_T smb_tag);
33 static SMB_ACL_TAG_T tru64_tag_to_smb(acl_tag_t tru64_tag);
34 static acl_perm_t smb_permset_to_tru64(SMB_ACL_PERM_T smb_permset);
35 static SMB_ACL_PERM_T tru64_permset_to_smb(const acl_perm_t tru64_permset);
38 /* public functions - the api */
40 SMB_ACL_T tru64acl_sys_acl_get_file(vfs_handle_struct *handle,
41 const struct smb_filename *smb_fname,
45 struct smb_acl_t *result;
46 acl_type_t the_acl_type;
49 DEBUG(10, ("Hi! This is tru64acl_sys_acl_get_file.\n"));
52 case SMB_ACL_TYPE_ACCESS:
53 the_acl_type = ACL_TYPE_ACCESS;
55 case SMB_ACL_TYPE_DEFAULT:
56 the_acl_type = ACL_TYPE_DEFAULT;
63 tru64_acl = acl_get_file((char *)smb_fname->base_name, the_acl_type);
65 if (tru64_acl == NULL) {
69 result = tru64_acl_to_smb_acl(tru64_acl, mem_ctx);
74 SMB_ACL_T tru64acl_sys_acl_get_fd(vfs_handle_struct *handle,
78 struct smb_acl_t *result;
79 acl_t tru64_acl = acl_get_fd(fsp_get_io_fd(fsp), ACL_TYPE_ACCESS);
81 if (tru64_acl == NULL) {
85 result = tru64_acl_to_smb_acl(tru64_acl, mem_ctx);
90 int tru64acl_sys_acl_set_fd(vfs_handle_struct *handle,
96 acl_t tru64_acl = smb_acl_to_tru64_acl(theacl);
97 acl_type_t the_acl_type;
100 case SMB_ACL_TYPE_ACCESS:
101 the_acl_type = ACL_TYPE_ACCESS;
103 case SMB_ACL_TYPE_DEFAULT:
104 the_acl_type = ACL_TYPE_DEFAULT;
111 if (tru64_acl == NULL) {
114 res = acl_set_fd(fsp_get_io_fd(fsp), the_acl_type, tru64_acl);
120 int tru64acl_sys_acl_delete_def_file(vfs_handle_struct *handle,
121 const struct smb_filename *smb_fname)
123 return acl_delete_def_file((char *)smb_fname->base_name);
127 /* private functions */
129 static struct smb_acl_t *tru64_acl_to_smb_acl(const struct acl *tru64_acl,
132 struct smb_acl_t *result;
135 DEBUG(10, ("Hi! This is tru64_acl_to_smb_acl.\n"));
137 if ((result = sys_acl_init(mem_ctx)) == NULL) {
138 DEBUG(0, ("sys_acl_init() failed in tru64_acl_to_smb_acl\n"));
142 if (acl_first_entry((struct acl *)tru64_acl) != 0) {
143 DEBUG(10, ("acl_first_entry failed: %s\n", strerror(errno)));
146 while ((entry = acl_get_entry((struct acl *)tru64_acl)) != NULL) {
147 result->acl = talloc_realloc(result, result->acl, struct smb_acl_entry,
149 if (result->acl == NULL) {
151 DEBUG(0, ("talloc_realloc failed in tru64_acl_to_smb_acl\n"));
156 if (!tru64_ace_to_smb_ace(entry, &result->acl[result->count])) {
166 DEBUG(1, ("tru64_acl_to_smb_acl failed!\n"));
170 static bool tru64_ace_to_smb_ace(acl_entry_t tru64_ace,
171 struct smb_acl_entry *smb_ace)
174 acl_permset_t permset;
175 SMB_ACL_TAG_T smb_tag_type;
176 SMB_ACL_PERM_T smb_permset;
179 if (acl_get_tag_type(tru64_ace, &tru64_tag) != 0) {
180 DEBUG(0, ("acl_get_tag_type failed: %s\n", strerror(errno)));
184 /* On could set the tag type directly to save a function call,
185 * but I like this better... */
186 smb_tag_type = tru64_tag_to_smb(tru64_tag);
187 if (smb_tag_type == 0) {
188 DEBUG(3, ("invalid tag type given: %d\n", tru64_tag));
191 if (sys_acl_set_tag_type(smb_ace, smb_tag_type) != 0) {
192 DEBUG(3, ("sys_acl_set_tag_type failed: %s\n",
196 qualifier = acl_get_qualifier(tru64_ace);
197 if (qualifier != NULL) {
198 if (sys_acl_set_qualifier(smb_ace, qualifier) != 0) {
199 DEBUG(3, ("sys_acl_set_qualifier failed\n"));
203 if (acl_get_permset(tru64_ace, &permset) != 0) {
204 DEBUG(3, ("acl_get_permset failed: %s\n", strerror(errno)));
207 smb_permset = tru64_permset_to_smb(*permset);
208 if (sys_acl_set_permset(smb_ace, &smb_permset) != 0) {
209 DEBUG(3, ("sys_acl_set_permset failed: %s\n", strerror(errno)));
215 static acl_t smb_acl_to_tru64_acl(const SMB_ACL_T smb_acl)
218 acl_entry_t tru64_entry;
221 ssize_t acl_text_len;
223 /* The tru64 acl_init function takes a size_t value
224 * instead of a count of entries (as with posix).
225 * the size parameter "Specifies the size of the working
226 * storage in bytes" (according to the man page).
227 * But it is unclear to me, how this size is to be
230 * It should not matter, since acl_create_entry enlarges
231 * the working storage at need. ... */
233 DEBUG(10, ("Hi! This is smb_acl_to_tru64_acl.\n"));
235 result = acl_init(1);
237 if (result == NULL) {
238 DEBUG(3, ("acl_init failed!\n"));
242 DEBUGADD(10, ("parsing acl entries...\n"));
243 for (i = 0; i < smb_acl->count; i++) {
244 /* XYZ - maybe eliminate this direct access? */
245 const struct smb_acl_entry *smb_entry = &smb_acl->acl[i];
247 acl_perm_t tru64_permset;
249 tru64_tag = smb_tag_to_tru64(smb_entry->a_type);
250 if (tru64_tag == -1) {
251 DEBUG(3, ("smb_tag_to_tru64 failed!\n"));
255 if (tru64_tag == ACL_MASK) {
256 DEBUGADD(10, (" - acl type ACL_MASK: not implemented on Tru64 ==> skipping\n"));
260 tru64_entry = acl_create_entry(&result);
261 if (tru64_entry == NULL) {
262 DEBUG(3, ("acl_create_entry failed: %s\n",
267 if (acl_set_tag_type(tru64_entry, tru64_tag) != 0) {
268 DEBUG(3, ("acl_set_tag_type(%d) failed: %s\n",
273 switch (smb_entry->a_type) {
275 if (acl_set_qualifier(tru64_entry,
276 (int *)&smb_entry->info.user.uid) != 0)
278 DEBUG(3, ("acl_set_qualifier failed: %s\n",
282 DEBUGADD(10, (" - setting uid to %d\n", smb_entry->info.user.uid));
285 if (acl_set_qualifier(tru64_entry,
286 (int *)&smb_entry->info.group.gid) != 0)
288 DEBUG(3, ("acl_set_qualifier failed: %s\n",
292 DEBUGADD(10, (" - setting gid to %d\n", smb_entry->info.group.gid));
298 tru64_permset = smb_permset_to_tru64(smb_entry->a_perm);
299 if (tru64_permset == -1) {
300 DEBUG(3, ("smb_permset_to_tru64 failed!\n"));
303 DEBUGADD(10, (" - setting perms to %0d\n", tru64_permset));
304 if (acl_set_permset(tru64_entry, &tru64_permset) != 0)
306 DEBUG(3, ("acl_set_permset failed: %s\n", strerror(errno)));
310 DEBUGADD(10, ("done parsing acl entries\n"));
313 if (acl_valid(result, &tru64_entry) != 0) {
314 DEBUG(1, ("smb_acl_to_tru64_acl: ACL is invalid (%s)\n",
316 if (tru64_entry != NULL) {
317 DEBUGADD(1, ("the acl contains duplicate entries\n"));
321 DEBUGADD(10, ("acl is valid\n"));
323 acl_text = acl_to_text(result, &acl_text_len);
324 if (acl_text == NULL) {
325 DEBUG(3, ("acl_to_text failed: %s\n", strerror(errno)));
328 DEBUG(1, ("acl_text: %s\n", acl_text));
334 if (result != NULL) {
337 DEBUG(1, ("smb_acl_to_tru64_acl failed!\n"));
341 static acl_tag_t smb_tag_to_tru64(SMB_ACL_TAG_T smb_tag)
347 DEBUGADD(10, ("got acl type ACL_USER\n"));
349 case SMB_ACL_USER_OBJ:
350 result = ACL_USER_OBJ;
351 DEBUGADD(10, ("got acl type ACL_USER_OBJ\n"));
355 DEBUGADD(10, ("got acl type ACL_GROUP\n"));
357 case SMB_ACL_GROUP_OBJ:
358 result = ACL_GROUP_OBJ;
359 DEBUGADD(10, ("got acl type ACL_GROUP_OBJ\n"));
363 DEBUGADD(10, ("got acl type ACL_OTHER\n"));
367 DEBUGADD(10, ("got acl type ACL_MASK\n"));
370 DEBUG(1, ("Unknown tag type %d\n", smb_tag));
377 static SMB_ACL_TAG_T tru64_tag_to_smb(acl_tag_t tru64_tag)
379 SMB_ACL_TAG_T smb_tag_type;
382 smb_tag_type = SMB_ACL_USER;
383 DEBUGADD(10, ("got smb acl tag type SMB_ACL_USER\n"));
386 smb_tag_type = SMB_ACL_USER_OBJ;
387 DEBUGADD(10, ("got smb acl tag type SMB_ACL_USER_OBJ\n"));
390 smb_tag_type = SMB_ACL_GROUP;
391 DEBUGADD(10, ("got smb acl tag type SMB_ACL_GROUP\n"));
394 smb_tag_type = SMB_ACL_GROUP_OBJ;
395 DEBUGADD(10, ("got smb acl tag type SMB_ACL_GROUP_OBJ\n"));
398 smb_tag_type = SMB_ACL_OTHER;
399 DEBUGADD(10, ("got smb acl tag type SMB_ACL_OTHER\n"));
402 smb_tag_type = SMB_ACL_MASK;
403 DEBUGADD(10, ("got smb acl tag type SMB_ACL_MASK\n"));
406 DEBUG(0, ("Unknown tag type %d\n", (unsigned int)tru64_tag));
412 static acl_perm_t smb_permset_to_tru64(SMB_ACL_PERM_T smb_permset)
414 /* originally, I thought that acl_clear_perm was the
415 * proper way to reset the permset to 0. but without
416 * initializing it to 0, acl_clear_perm fails.
417 * so probably, acl_clear_perm is not necessary here... ?! */
418 acl_perm_t tru64_permset = 0;
419 if (acl_clear_perm(&tru64_permset) != 0) {
420 DEBUG(5, ("acl_clear_perm failed: %s\n", strerror(errno)));
423 /* according to original lib/sysacls.c, acl_add_perm is
424 * broken on tru64 ... */
425 tru64_permset |= ((smb_permset & SMB_ACL_READ) ? ACL_READ : 0);
426 tru64_permset |= ((smb_permset & SMB_ACL_WRITE) ? ACL_WRITE : 0);
427 tru64_permset |= ((smb_permset & SMB_ACL_EXECUTE) ? ACL_EXECUTE : 0);
428 return tru64_permset;
431 static SMB_ACL_PERM_T tru64_permset_to_smb(const acl_perm_t tru64_permset)
433 SMB_ACL_PERM_T smb_permset = 0;
434 smb_permset |= ((tru64_permset & ACL_READ) ? SMB_ACL_READ : 0);
435 smb_permset |= ((tru64_permset & ACL_WRITE) ? SMB_ACL_WRITE : 0);
436 smb_permset |= ((tru64_permset & ACL_EXECUTE) ? SMB_ACL_EXECUTE : 0);
441 /* VFS operations structure */
443 static struct vfs_fn_pointers tru64acl_fns = {
444 .sys_acl_get_file_fn = tru64acl_sys_acl_get_file,
445 .sys_acl_get_fd_fn = tru64acl_sys_acl_get_fd,
446 .sys_acl_blob_get_file_fn = posix_sys_acl_blob_get_file,
447 .sys_acl_blob_get_fd_fn = posix_sys_acl_blob_get_fd,
448 .sys_acl_set_fd_fn = tru64acl_sys_acl_set_fd,
449 .sys_acl_delete_def_file_fn = tru64acl_sys_acl_delete_def_file,
453 NTSTATUS vfs_tru64acl_init(TALLOC_CTX *ctx)
455 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "tru64acl",