2 Unix SMB/Netbios implementation.
3 VFS module to get and set Tru64 acls
4 Copyright (C) Michael Adam 2006
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 2 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, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 /* prototypes for private functions first - for clarity */
25 static struct smb_acl_t
*tru64_acl_to_smb_acl(const struct acl
*tru64_acl
);
26 static BOOL
tru64_ace_to_smb_ace(acl_entry_t tru64_ace
,
27 struct smb_acl_entry
*smb_ace
);
28 static acl_t
smb_acl_to_tru64_acl(const SMB_ACL_T smb_acl
);
29 static acl_tag_t
smb_tag_to_tru64(SMB_ACL_TAG_T smb_tag
);
30 static SMB_ACL_TAG_T
tru64_tag_to_smb(acl_tag_t tru64_tag
);
31 static acl_perm_t
smb_permset_to_tru64(SMB_ACL_PERM_T smb_permset
);
32 static SMB_ACL_PERM_T
tru64_permset_to_smb(const acl_perm_t tru64_permset
);
35 /* public functions - the api */
37 SMB_ACL_T
tru64acl_sys_acl_get_file(vfs_handle_struct
*handle
,
41 struct smb_acl_t
*result
;
42 acl_type_t the_acl_type
;
45 DEBUG(10, ("Hi! This is tru64acl_sys_acl_get_file.\n"));
48 case SMB_ACL_TYPE_ACCESS
:
49 the_acl_type
= ACL_TYPE_ACCESS
;
51 case SMB_ACL_TYPE_DEFAULT
:
52 the_acl_type
= ACL_TYPE_DEFAULT
;
59 tru64_acl
= acl_get_file((char *)path_p
, the_acl_type
);
61 if (tru64_acl
== NULL
) {
65 result
= tru64_acl_to_smb_acl(tru64_acl
);
70 SMB_ACL_T
tru64acl_sys_acl_get_fd(vfs_handle_struct
*handle
,
74 struct smb_acl_t
*result
;
75 acl_t tru64_acl
= acl_get_fd(fd
, ACL_TYPE_ACCESS
);
77 if (tru64_acl
== NULL
) {
81 result
= tru64_acl_to_smb_acl(tru64_acl
);
86 int tru64acl_sys_acl_set_file(vfs_handle_struct
*handle
,
92 acl_type_t the_acl_type
;
95 DEBUG(10, ("tru64acl_sys_acl_set_file called with name %s, type %d\n",
99 case SMB_ACL_TYPE_ACCESS
:
100 DEBUGADD(10, ("got acl type ACL_TYPE_ACCESS\n"));
101 the_acl_type
= ACL_TYPE_ACCESS
;
103 case SMB_ACL_TYPE_DEFAULT
:
104 DEBUGADD(10, ("got acl type ACL_TYPE_DEFAULT\n"));
105 the_acl_type
= ACL_TYPE_DEFAULT
;
108 DEBUGADD(10, ("invalid acl type\n"));
113 tru64_acl
= smb_acl_to_tru64_acl(theacl
);
114 if (tru64_acl
== NULL
) {
115 DEBUG(10, ("smb_acl_to_tru64_acl failed!\n"));
118 DEBUG(10, ("got tru64 acl...\n"));
119 res
= acl_set_file((char *)name
, the_acl_type
, tru64_acl
);
122 DEBUG(10, ("acl_set_file failed: %s\n", strerror(errno
)));
127 DEBUG(1, ("tru64acl_sys_acl_set_file failed!\n"));
131 int tru64acl_sys_acl_set_fd(vfs_handle_struct
*handle
,
133 int fd
, SMB_ACL_T theacl
)
136 acl_t tru64_acl
= smb_acl_to_tru64_acl(theacl
);
137 if (tru64_acl
== NULL
) {
140 res
= acl_set_fd(fd
, ACL_TYPE_ACCESS
, tru64_acl
);
146 int tru64acl_sys_acl_delete_def_file(vfs_handle_struct
*handle
,
149 return acl_delete_def_file((char *)path
);
153 /* private functions */
155 static struct smb_acl_t
*tru64_acl_to_smb_acl(const struct acl
*tru64_acl
)
157 struct smb_acl_t
*result
;
160 DEBUG(10, ("Hi! This is tru64_acl_to_smb_acl.\n"));
162 if ((result
= SMB_MALLOC_P(struct smb_acl_t
)) == NULL
) {
163 DEBUG(0, ("SMB_MALLOC_P failed in tru64_acl_to_smb_acl\n"));
167 ZERO_STRUCTP(result
);
168 if (acl_first_entry((struct acl
*)tru64_acl
) != 0) {
169 DEBUG(10, ("acl_first_entry failed: %s\n", strerror(errno
)));
172 while ((entry
= acl_get_entry((struct acl
*)tru64_acl
)) != NULL
) {
173 result
= SMB_REALLOC(result
, sizeof(struct smb_acl_t
) +
174 (sizeof(struct smb_acl_entry
) *
175 (result
->count
+ 1)));
176 if (result
== NULL
) {
177 DEBUG(0, ("SMB_REALLOC failed in tru64_acl_to_smb_acl\n"));
182 if (!tru64_ace_to_smb_ace(entry
, &result
->acl
[result
->count
])) {
191 if (result
!= NULL
) {
194 DEBUG(1, ("tru64_acl_to_smb_acl failed!\n"));
198 static BOOL
tru64_ace_to_smb_ace(acl_entry_t tru64_ace
,
199 struct smb_acl_entry
*smb_ace
)
202 acl_permset_t permset
;
203 SMB_ACL_TAG_T smb_tag_type
;
204 SMB_ACL_PERM_T smb_permset
;
207 if (acl_get_tag_type(tru64_ace
, &tru64_tag
) != 0) {
208 DEBUG(0, ("acl_get_tag_type failed: %s\n", strerror(errno
)));
212 /* On could set the tag type directly to save a function call,
213 * but I like this better... */
214 smb_tag_type
= tru64_tag_to_smb(tru64_tag
);
215 if (smb_tag_type
== 0) {
216 DEBUG(3, ("invalid tag type given: %d\n", tru64_tag
));
219 if (sys_acl_set_tag_type(smb_ace
, smb_tag_type
) != 0) {
220 DEBUG(3, ("sys_acl_set_tag_type failed: %s\n",
224 qualifier
= acl_get_qualifier(tru64_ace
);
225 if (qualifier
!= NULL
) {
226 if (sys_acl_set_qualifier(smb_ace
, qualifier
) != 0) {
227 DEBUG(3, ("sys_acl_set_qualifier failed\n"));
231 if (acl_get_permset(tru64_ace
, &permset
) != 0) {
232 DEBUG(3, ("acl_get_permset failed: %s\n", strerror(errno
)));
235 smb_permset
= tru64_permset_to_smb(*permset
);
236 if (sys_acl_set_permset(smb_ace
, &smb_permset
) != 0) {
237 DEBUG(3, ("sys_acl_set_permset failed: %s\n", strerror(errno
)));
243 static acl_t
smb_acl_to_tru64_acl(const SMB_ACL_T smb_acl
)
246 acl_entry_t tru64_entry
;
249 ssize_t acl_text_len
;
251 /* The tru64 acl_init function takes a size_t value
252 * instead of a count of entries (as with posix).
253 * the size parameter "Specifies the size of the working
254 * storage in bytes" (according to the man page).
255 * But it is unclear to me, how this size is to be
258 * It should not matter, since acl_create_entry enlarges
259 * the working storage at need. ... */
261 DEBUG(10, ("Hi! This is smb_acl_to_tru64_acl.\n"));
263 result
= acl_init(1);
265 if (result
== NULL
) {
266 DEBUG(3, ("acl_init failed!\n"));
270 DEBUGADD(10, ("parsing acl entries...\n"));
271 for (i
= 0; i
< smb_acl
->count
; i
++) {
272 /* XYZ - maybe eliminate this direct access? */
273 const struct smb_acl_entry
*smb_entry
= &smb_acl
->acl
[i
];
275 acl_perm_t tru64_permset
;
277 tru64_tag
= smb_tag_to_tru64(smb_entry
->a_type
);
278 if (tru64_tag
== -1) {
279 DEBUG(3, ("smb_tag_to_tru64 failed!\n"));
283 if (tru64_tag
== ACL_MASK
) {
284 DEBUGADD(10, (" - acl type ACL_MASK: not implemented on Tru64 ==> skipping\n"));
288 tru64_entry
= acl_create_entry(&result
);
289 if (tru64_entry
== NULL
) {
290 DEBUG(3, ("acl_create_entry failed: %s\n",
295 if (acl_set_tag_type(tru64_entry
, tru64_tag
) != 0) {
296 DEBUG(3, ("acl_set_tag_type(%d) failed: %s\n",
301 switch (smb_entry
->a_type
) {
303 if (acl_set_qualifier(tru64_entry
,
304 (int *)&smb_entry
->uid
) != 0)
306 DEBUG(3, ("acl_set_qualifier failed: %s\n",
310 DEBUGADD(10, (" - setting uid to %d\n", smb_entry
->uid
));
313 if (acl_set_qualifier(tru64_entry
,
314 (int *)&smb_entry
->gid
) != 0)
316 DEBUG(3, ("acl_set_qualifier failed: %s\n",
320 DEBUGADD(10, (" - setting gid to %d\n", smb_entry
->gid
));
326 tru64_permset
= smb_permset_to_tru64(smb_entry
->a_perm
);
327 if (tru64_permset
== -1) {
328 DEBUG(3, ("smb_permset_to_tru64 failed!\n"));
331 DEBUGADD(10, (" - setting perms to %0d\n", tru64_permset
));
332 if (acl_set_permset(tru64_entry
, &tru64_permset
) != 0)
334 DEBUG(3, ("acl_set_permset failed: %s\n", strerror(errno
)));
338 DEBUGADD(10, ("done parsing acl entries\n"));
341 if (acl_valid(result
, &tru64_entry
) != 0) {
342 DEBUG(1, ("smb_acl_to_tru64_acl: ACL is invalid (%s)\n",
344 if (tru64_entry
!= NULL
) {
345 DEBUGADD(1, ("the acl contains duplicate entries\n"));
349 DEBUGADD(10, ("acl is valid\n"));
351 acl_text
= acl_to_text(result
, &acl_text_len
);
352 if (acl_text
== NULL
) {
353 DEBUG(3, ("acl_to_text failed: %s\n", strerror(errno
)));
356 DEBUG(1, ("acl_text: %s\n", acl_text
));
362 if (result
!= NULL
) {
365 DEBUG(1, ("smb_acl_to_tru64_acl failed!\n"));
369 static acl_tag_t
smb_tag_to_tru64(SMB_ACL_TAG_T smb_tag
)
375 DEBUGADD(10, ("got acl type ACL_USER\n"));
377 case SMB_ACL_USER_OBJ
:
378 result
= ACL_USER_OBJ
;
379 DEBUGADD(10, ("got acl type ACL_USER_OBJ\n"));
383 DEBUGADD(10, ("got acl type ACL_GROUP\n"));
385 case SMB_ACL_GROUP_OBJ
:
386 result
= ACL_GROUP_OBJ
;
387 DEBUGADD(10, ("got acl type ACL_GROUP_OBJ\n"));
391 DEBUGADD(10, ("got acl type ACL_OTHER\n"));
395 DEBUGADD(10, ("got acl type ACL_MASK\n"));
398 DEBUG(1, ("Unknown tag type %d\n", smb_tag
));
405 static SMB_ACL_TAG_T
tru64_tag_to_smb(acl_tag_t tru64_tag
)
407 SMB_ACL_TAG_T smb_tag_type
;
410 smb_tag_type
= SMB_ACL_USER
;
411 DEBUGADD(10, ("got smb acl tag type SMB_ACL_USER\n"));
414 smb_tag_type
= SMB_ACL_USER_OBJ
;
415 DEBUGADD(10, ("got smb acl tag type SMB_ACL_USER_OBJ\n"));
418 smb_tag_type
= SMB_ACL_GROUP
;
419 DEBUGADD(10, ("got smb acl tag type SMB_ACL_GROUP\n"));
422 smb_tag_type
= SMB_ACL_GROUP_OBJ
;
423 DEBUGADD(10, ("got smb acl tag type SMB_ACL_GROUP_OBJ\n"));
426 smb_tag_type
= SMB_ACL_OTHER
;
427 DEBUGADD(10, ("got smb acl tag type SMB_ACL_OTHER\n"));
430 smb_tag_type
= SMB_ACL_MASK
;
431 DEBUGADD(10, ("got smb acl tag type SMB_ACL_MASK\n"));
434 DEBUG(0, ("Unknown tag type %d\n", (unsigned int)tru64_tag
));
440 static acl_perm_t
smb_permset_to_tru64(SMB_ACL_PERM_T smb_permset
)
442 /* originally, I thought that acl_clear_perm was the
443 * proper way to reset the permset to 0. but without
444 * initializing it to 0, acl_clear_perm fails.
445 * so probably, acl_clear_perm is not necessary here... ?! */
446 acl_perm_t tru64_permset
= 0;
447 if (acl_clear_perm(&tru64_permset
) != 0) {
448 DEBUG(5, ("acl_clear_perm failed: %s\n", strerror(errno
)));
451 /* according to original lib/sysacls.c, acl_add_perm is
452 * broken on tru64 ... */
453 tru64_permset
|= ((smb_permset
& SMB_ACL_READ
) ? ACL_READ
: 0);
454 tru64_permset
|= ((smb_permset
& SMB_ACL_WRITE
) ? ACL_WRITE
: 0);
455 tru64_permset
|= ((smb_permset
& SMB_ACL_EXECUTE
) ? ACL_EXECUTE
: 0);
456 return tru64_permset
;
459 static SMB_ACL_PERM_T
tru64_permset_to_smb(const acl_perm_t tru64_permset
)
461 SMB_ACL_PERM_T smb_permset
= 0;
462 smb_permset
|= ((tru64_permset
& ACL_READ
) ? SMB_ACL_READ
: 0);
463 smb_permset
|= ((tru64_permset
& ACL_WRITE
) ? SMB_ACL_WRITE
: 0);
464 smb_permset
|= ((tru64_permset
& ACL_EXECUTE
) ? SMB_ACL_EXECUTE
: 0);
469 /* VFS operations structure */
471 static vfs_op_tuple tru64acl_op_tuples
[] = {
472 /* Disk operations */
473 {SMB_VFS_OP(tru64acl_sys_acl_get_file
),
474 SMB_VFS_OP_SYS_ACL_GET_FILE
,
475 SMB_VFS_LAYER_TRANSPARENT
},
477 {SMB_VFS_OP(tru64acl_sys_acl_get_fd
),
478 SMB_VFS_OP_SYS_ACL_GET_FD
,
479 SMB_VFS_LAYER_TRANSPARENT
},
481 {SMB_VFS_OP(tru64acl_sys_acl_set_file
),
482 SMB_VFS_OP_SYS_ACL_SET_FILE
,
483 SMB_VFS_LAYER_TRANSPARENT
},
485 {SMB_VFS_OP(tru64acl_sys_acl_set_fd
),
486 SMB_VFS_OP_SYS_ACL_SET_FD
,
487 SMB_VFS_LAYER_TRANSPARENT
},
489 {SMB_VFS_OP(tru64acl_sys_acl_delete_def_file
),
490 SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE
,
491 SMB_VFS_LAYER_TRANSPARENT
},
498 NTSTATUS
vfs_tru64acl_init(void);
499 NTSTATUS
vfs_tru64acl_init(void)
501 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "tru64acl",