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
,
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 *)path_p
, 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
->fh
->fd
, 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_file(vfs_handle_struct
*handle
,
96 acl_type_t the_acl_type
;
99 DEBUG(10, ("tru64acl_sys_acl_set_file called with name %s, type %d\n",
103 case SMB_ACL_TYPE_ACCESS
:
104 DEBUGADD(10, ("got acl type ACL_TYPE_ACCESS\n"));
105 the_acl_type
= ACL_TYPE_ACCESS
;
107 case SMB_ACL_TYPE_DEFAULT
:
108 DEBUGADD(10, ("got acl type ACL_TYPE_DEFAULT\n"));
109 the_acl_type
= ACL_TYPE_DEFAULT
;
112 DEBUGADD(10, ("invalid acl type\n"));
117 tru64_acl
= smb_acl_to_tru64_acl(theacl
);
118 if (tru64_acl
== NULL
) {
119 DEBUG(10, ("smb_acl_to_tru64_acl failed!\n"));
122 DEBUG(10, ("got tru64 acl...\n"));
123 res
= acl_set_file((char *)name
, the_acl_type
, tru64_acl
);
126 DEBUG(10, ("acl_set_file failed: %s\n", strerror(errno
)));
131 DEBUG(1, ("tru64acl_sys_acl_set_file failed!\n"));
135 int tru64acl_sys_acl_set_fd(vfs_handle_struct
*handle
,
140 acl_t tru64_acl
= smb_acl_to_tru64_acl(theacl
);
141 if (tru64_acl
== NULL
) {
144 res
= acl_set_fd(fsp
->fh
->fd
, ACL_TYPE_ACCESS
, tru64_acl
);
150 int tru64acl_sys_acl_delete_def_file(vfs_handle_struct
*handle
,
153 return acl_delete_def_file((char *)path
);
157 /* private functions */
159 static struct smb_acl_t
*tru64_acl_to_smb_acl(const struct acl
*tru64_acl
,
162 struct smb_acl_t
*result
;
165 DEBUG(10, ("Hi! This is tru64_acl_to_smb_acl.\n"));
167 if ((result
= sys_acl_init(mem_ctx
)) == NULL
) {
168 DEBUG(0, ("sys_acl_init() failed in tru64_acl_to_smb_acl\n"));
172 if (acl_first_entry((struct acl
*)tru64_acl
) != 0) {
173 DEBUG(10, ("acl_first_entry failed: %s\n", strerror(errno
)));
176 while ((entry
= acl_get_entry((struct acl
*)tru64_acl
)) != NULL
) {
177 result
->acl
= talloc_realloc(result
, result
->acl
, struct smb_acl_entry
,
179 if (result
->acl
== NULL
) {
181 DEBUG(0, ("talloc_realloc failed in tru64_acl_to_smb_acl\n"));
186 if (!tru64_ace_to_smb_ace(entry
, &result
->acl
[result
->count
])) {
196 DEBUG(1, ("tru64_acl_to_smb_acl failed!\n"));
200 static bool tru64_ace_to_smb_ace(acl_entry_t tru64_ace
,
201 struct smb_acl_entry
*smb_ace
)
204 acl_permset_t permset
;
205 SMB_ACL_TAG_T smb_tag_type
;
206 SMB_ACL_PERM_T smb_permset
;
209 if (acl_get_tag_type(tru64_ace
, &tru64_tag
) != 0) {
210 DEBUG(0, ("acl_get_tag_type failed: %s\n", strerror(errno
)));
214 /* On could set the tag type directly to save a function call,
215 * but I like this better... */
216 smb_tag_type
= tru64_tag_to_smb(tru64_tag
);
217 if (smb_tag_type
== 0) {
218 DEBUG(3, ("invalid tag type given: %d\n", tru64_tag
));
221 if (sys_acl_set_tag_type(smb_ace
, smb_tag_type
) != 0) {
222 DEBUG(3, ("sys_acl_set_tag_type failed: %s\n",
226 qualifier
= acl_get_qualifier(tru64_ace
);
227 if (qualifier
!= NULL
) {
228 if (sys_acl_set_qualifier(smb_ace
, qualifier
) != 0) {
229 DEBUG(3, ("sys_acl_set_qualifier failed\n"));
233 if (acl_get_permset(tru64_ace
, &permset
) != 0) {
234 DEBUG(3, ("acl_get_permset failed: %s\n", strerror(errno
)));
237 smb_permset
= tru64_permset_to_smb(*permset
);
238 if (sys_acl_set_permset(smb_ace
, &smb_permset
) != 0) {
239 DEBUG(3, ("sys_acl_set_permset failed: %s\n", strerror(errno
)));
245 static acl_t
smb_acl_to_tru64_acl(const SMB_ACL_T smb_acl
)
248 acl_entry_t tru64_entry
;
251 ssize_t acl_text_len
;
253 /* The tru64 acl_init function takes a size_t value
254 * instead of a count of entries (as with posix).
255 * the size parameter "Specifies the size of the working
256 * storage in bytes" (according to the man page).
257 * But it is unclear to me, how this size is to be
260 * It should not matter, since acl_create_entry enlarges
261 * the working storage at need. ... */
263 DEBUG(10, ("Hi! This is smb_acl_to_tru64_acl.\n"));
265 result
= acl_init(1);
267 if (result
== NULL
) {
268 DEBUG(3, ("acl_init failed!\n"));
272 DEBUGADD(10, ("parsing acl entries...\n"));
273 for (i
= 0; i
< smb_acl
->count
; i
++) {
274 /* XYZ - maybe eliminate this direct access? */
275 const struct smb_acl_entry
*smb_entry
= &smb_acl
->acl
[i
];
277 acl_perm_t tru64_permset
;
279 tru64_tag
= smb_tag_to_tru64(smb_entry
->a_type
);
280 if (tru64_tag
== -1) {
281 DEBUG(3, ("smb_tag_to_tru64 failed!\n"));
285 if (tru64_tag
== ACL_MASK
) {
286 DEBUGADD(10, (" - acl type ACL_MASK: not implemented on Tru64 ==> skipping\n"));
290 tru64_entry
= acl_create_entry(&result
);
291 if (tru64_entry
== NULL
) {
292 DEBUG(3, ("acl_create_entry failed: %s\n",
297 if (acl_set_tag_type(tru64_entry
, tru64_tag
) != 0) {
298 DEBUG(3, ("acl_set_tag_type(%d) failed: %s\n",
303 switch (smb_entry
->a_type
) {
305 if (acl_set_qualifier(tru64_entry
,
306 (int *)&smb_entry
->info
.user
.uid
) != 0)
308 DEBUG(3, ("acl_set_qualifier failed: %s\n",
312 DEBUGADD(10, (" - setting uid to %d\n", smb_entry
->info
.user
.uid
));
315 if (acl_set_qualifier(tru64_entry
,
316 (int *)&smb_entry
->info
.group
.gid
) != 0)
318 DEBUG(3, ("acl_set_qualifier failed: %s\n",
322 DEBUGADD(10, (" - setting gid to %d\n", smb_entry
->info
.group
.gid
));
328 tru64_permset
= smb_permset_to_tru64(smb_entry
->a_perm
);
329 if (tru64_permset
== -1) {
330 DEBUG(3, ("smb_permset_to_tru64 failed!\n"));
333 DEBUGADD(10, (" - setting perms to %0d\n", tru64_permset
));
334 if (acl_set_permset(tru64_entry
, &tru64_permset
) != 0)
336 DEBUG(3, ("acl_set_permset failed: %s\n", strerror(errno
)));
340 DEBUGADD(10, ("done parsing acl entries\n"));
343 if (acl_valid(result
, &tru64_entry
) != 0) {
344 DEBUG(1, ("smb_acl_to_tru64_acl: ACL is invalid (%s)\n",
346 if (tru64_entry
!= NULL
) {
347 DEBUGADD(1, ("the acl contains duplicate entries\n"));
351 DEBUGADD(10, ("acl is valid\n"));
353 acl_text
= acl_to_text(result
, &acl_text_len
);
354 if (acl_text
== NULL
) {
355 DEBUG(3, ("acl_to_text failed: %s\n", strerror(errno
)));
358 DEBUG(1, ("acl_text: %s\n", acl_text
));
364 if (result
!= NULL
) {
367 DEBUG(1, ("smb_acl_to_tru64_acl failed!\n"));
371 static acl_tag_t
smb_tag_to_tru64(SMB_ACL_TAG_T smb_tag
)
377 DEBUGADD(10, ("got acl type ACL_USER\n"));
379 case SMB_ACL_USER_OBJ
:
380 result
= ACL_USER_OBJ
;
381 DEBUGADD(10, ("got acl type ACL_USER_OBJ\n"));
385 DEBUGADD(10, ("got acl type ACL_GROUP\n"));
387 case SMB_ACL_GROUP_OBJ
:
388 result
= ACL_GROUP_OBJ
;
389 DEBUGADD(10, ("got acl type ACL_GROUP_OBJ\n"));
393 DEBUGADD(10, ("got acl type ACL_OTHER\n"));
397 DEBUGADD(10, ("got acl type ACL_MASK\n"));
400 DEBUG(1, ("Unknown tag type %d\n", smb_tag
));
407 static SMB_ACL_TAG_T
tru64_tag_to_smb(acl_tag_t tru64_tag
)
409 SMB_ACL_TAG_T smb_tag_type
;
412 smb_tag_type
= SMB_ACL_USER
;
413 DEBUGADD(10, ("got smb acl tag type SMB_ACL_USER\n"));
416 smb_tag_type
= SMB_ACL_USER_OBJ
;
417 DEBUGADD(10, ("got smb acl tag type SMB_ACL_USER_OBJ\n"));
420 smb_tag_type
= SMB_ACL_GROUP
;
421 DEBUGADD(10, ("got smb acl tag type SMB_ACL_GROUP\n"));
424 smb_tag_type
= SMB_ACL_GROUP_OBJ
;
425 DEBUGADD(10, ("got smb acl tag type SMB_ACL_GROUP_OBJ\n"));
428 smb_tag_type
= SMB_ACL_OTHER
;
429 DEBUGADD(10, ("got smb acl tag type SMB_ACL_OTHER\n"));
432 smb_tag_type
= SMB_ACL_MASK
;
433 DEBUGADD(10, ("got smb acl tag type SMB_ACL_MASK\n"));
436 DEBUG(0, ("Unknown tag type %d\n", (unsigned int)tru64_tag
));
442 static acl_perm_t
smb_permset_to_tru64(SMB_ACL_PERM_T smb_permset
)
444 /* originally, I thought that acl_clear_perm was the
445 * proper way to reset the permset to 0. but without
446 * initializing it to 0, acl_clear_perm fails.
447 * so probably, acl_clear_perm is not necessary here... ?! */
448 acl_perm_t tru64_permset
= 0;
449 if (acl_clear_perm(&tru64_permset
) != 0) {
450 DEBUG(5, ("acl_clear_perm failed: %s\n", strerror(errno
)));
453 /* according to original lib/sysacls.c, acl_add_perm is
454 * broken on tru64 ... */
455 tru64_permset
|= ((smb_permset
& SMB_ACL_READ
) ? ACL_READ
: 0);
456 tru64_permset
|= ((smb_permset
& SMB_ACL_WRITE
) ? ACL_WRITE
: 0);
457 tru64_permset
|= ((smb_permset
& SMB_ACL_EXECUTE
) ? ACL_EXECUTE
: 0);
458 return tru64_permset
;
461 static SMB_ACL_PERM_T
tru64_permset_to_smb(const acl_perm_t tru64_permset
)
463 SMB_ACL_PERM_T smb_permset
= 0;
464 smb_permset
|= ((tru64_permset
& ACL_READ
) ? SMB_ACL_READ
: 0);
465 smb_permset
|= ((tru64_permset
& ACL_WRITE
) ? SMB_ACL_WRITE
: 0);
466 smb_permset
|= ((tru64_permset
& ACL_EXECUTE
) ? SMB_ACL_EXECUTE
: 0);
471 /* VFS operations structure */
473 static struct vfs_fn_pointers tru64acl_fns
= {
474 .sys_acl_get_file_fn
= tru64acl_sys_acl_get_file
,
475 .sys_acl_get_fd_fn
= tru64acl_sys_acl_get_fd
,
476 .sys_acl_set_file_fn
= tru64acl_sys_acl_set_file
,
477 .sys_acl_set_fd_fn
= tru64acl_sys_acl_set_fd
,
478 .sys_acl_delete_def_file_fn
= tru64acl_sys_acl_delete_def_file
,
481 NTSTATUS
vfs_tru64acl_init(void);
482 NTSTATUS
vfs_tru64acl_init(void)
484 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "tru64acl",