2 * Unix SMB/Netbios implementation.
3 * VFS module to get and set HP-UX 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 * This module supports JFS (POSIX) ACLs on VxFS (Veritas * Filesystem).
22 * These are available on HP-UX 11.00 if JFS 3.3 is installed.
23 * On HP-UX 11i (11.11 and above) these ACLs are supported out of
26 * There is another form of ACLs on HFS. These ACLs have a
27 * completely different API and their own set of userland tools.
28 * Since HFS seems to be considered deprecated, HFS acls
29 * are not supported. (They could be supported through a separate
30 * vfs-module if there is demand.)
33 /* =================================================================
36 * The original hpux-acl code in lib/sysacls.c was based upon the
37 * solaris acl code in the same file. Now for the new modularized
38 * acl implementation, I have taken the code from vfs_solarisacls.c
39 * and did similar adaptations as were done before, essentially
40 * reusing the original internal aclsort functions.
41 * The check for the presence of the acl() call has been adopted, and
42 * a check for the presence of the aclsort() call has been added.
44 * Michael Adam <obnox@samba.org>
46 * ================================================================= */
50 #include "system/filesys.h"
51 #include "smbd/smbd.h"
52 #include "modules/vfs_hpuxacl.h"
56 * including standard header <sys/aclv.h>
58 * included here as a quick hack for the special HP-UX-situation:
60 * The problem is that, on HP-UX, jfs/posix acls are
61 * defined in <sys/aclv.h>, while the deprecated hfs acls
62 * are defined inside <sys/acl.h>.
65 /* GROUP is defined somewhere else so undef it here... */
68 /* dl.h: needed to check for acl call via shl_findsym */
71 typedef struct acl HPUX_ACE_T
;
72 typedef struct acl
*HPUX_ACL_T
;
73 typedef int HPUX_ACL_TAG_T
; /* the type of an ACL entry */
74 typedef ushort HPUX_PERM_T
;
76 /* Structure to capture the count for each type of ACE.
77 * (for hpux_internal_aclsort */
78 struct hpux_acl_types
{
99 /* for convenience: check if hpux acl entry is a default entry? */
100 #define _IS_DEFAULT(ace) ((ace).a_type & ACL_DEFAULT)
101 #define _IS_OF_TYPE(ace, type) ( \
102 (((type) == SMB_ACL_TYPE_ACCESS) && !_IS_DEFAULT(ace)) \
104 (((type) == SMB_ACL_TYPE_DEFAULT) && _IS_DEFAULT(ace)) \
108 /* prototypes for private functions */
110 static HPUX_ACL_T
hpux_acl_init(int count
);
111 static bool smb_acl_to_hpux_acl(SMB_ACL_T smb_acl
,
112 HPUX_ACL_T
*solariacl
, int *count
,
113 SMB_ACL_TYPE_T type
);
114 static SMB_ACL_T
hpux_acl_to_smb_acl(HPUX_ACL_T hpuxacl
, int count
,
115 SMB_ACL_TYPE_T type
);
116 static HPUX_ACL_TAG_T
smb_tag_to_hpux_tag(SMB_ACL_TAG_T smb_tag
);
117 static SMB_ACL_TAG_T
hpux_tag_to_smb_tag(HPUX_ACL_TAG_T hpux_tag
);
118 static bool hpux_add_to_acl(HPUX_ACL_T
*hpux_acl
, int *count
,
119 HPUX_ACL_T add_acl
, int add_count
, SMB_ACL_TYPE_T type
);
120 static bool hpux_acl_get_file(const char *name
, HPUX_ACL_T
*hpuxacl
,
122 static SMB_ACL_PERM_T
hpux_perm_to_smb_perm(const HPUX_PERM_T perm
);
123 static HPUX_PERM_T
smb_perm_to_hpux_perm(const SMB_ACL_PERM_T perm
);
125 static bool hpux_acl_check(HPUX_ACL_T hpux_acl
, int count
);
127 /* aclsort (internal) and helpers: */
128 static bool hpux_acl_sort(HPUX_ACL_T acl
, int count
);
129 static int hpux_internal_aclsort(int acl_count
, int calclass
, HPUX_ACL_T aclp
);
130 static void hpux_count_obj(int acl_count
, HPUX_ACL_T aclp
,
131 struct hpux_acl_types
*acl_type_count
);
132 static void hpux_swap_acl_entries(HPUX_ACE_T
*aclp0
, HPUX_ACE_T
*aclp1
);
133 static bool hpux_prohibited_duplicate_type(int acl_type
);
135 static bool hpux_acl_call_present(void);
136 static bool hpux_aclsort_call_present(void);
139 /* public functions - the api */
141 SMB_ACL_T
hpuxacl_sys_acl_get_file(vfs_handle_struct
*handle
,
145 SMB_ACL_T result
= NULL
;
147 HPUX_ACL_T hpux_acl
= NULL
;
149 DEBUG(10, ("hpuxacl_sys_acl_get_file called for file '%s'.\n",
152 if(hpux_acl_call_present() == False
) {
153 /* Looks like we don't have the acl() system call on HPUX.
154 * May be the system doesn't have the latest version of JFS.
159 if (type
!= SMB_ACL_TYPE_ACCESS
&& type
!= SMB_ACL_TYPE_DEFAULT
) {
160 DEBUG(10, ("invalid SMB_ACL_TYPE given (%d)\n", type
));
165 DEBUGADD(10, ("getting %s acl\n",
166 ((type
== SMB_ACL_TYPE_ACCESS
) ? "access" : "default")));
168 if (!hpux_acl_get_file(path_p
, &hpux_acl
, &count
)) {
171 result
= hpux_acl_to_smb_acl(hpux_acl
, count
, type
);
172 if (result
== NULL
) {
173 DEBUG(10, ("conversion hpux_acl -> smb_acl failed (%s).\n",
178 DEBUG(10, ("hpuxacl_sys_acl_get_file %s.\n",
179 ((result
== NULL
) ? "failed" : "succeeded" )));
186 * get the access ACL of a file referred to by a fd
188 SMB_ACL_T
hpuxacl_sys_acl_get_fd(vfs_handle_struct
*handle
,
192 * HPUX doesn't have the facl call. Fake it using the path.... JRA.
195 * We know we're in the same conn context. So we
196 * can use the relative path.
198 DEBUG(10, ("redirecting call of hpuxacl_sys_acl_get_fd to "
199 "hpuxacl_sys_acl_get_file (no facl syscall on HPUX).\n"));
201 return hpuxacl_sys_acl_get_file(handle
,
202 fsp
->fsp_name
->base_name
,
203 SMB_ACL_TYPE_ACCESS
);
207 int hpuxacl_sys_acl_set_file(vfs_handle_struct
*handle
,
213 HPUX_ACL_T hpux_acl
= NULL
;
215 struct smb_filename
*smb_fname
= NULL
;
218 DEBUG(10, ("hpuxacl_sys_acl_set_file called for file '%s'\n",
221 status
= create_synthetic_smb_fname(talloc_tos(), name
, NULL
, NULL
,
223 if (!NT_STATUS_IS_OK(status
)) {
227 if(hpux_acl_call_present() == False
) {
228 /* Looks like we don't have the acl() system call on HPUX.
229 * May be the system doesn't have the latest version of JFS.
234 if ((type
!= SMB_ACL_TYPE_ACCESS
) && (type
!= SMB_ACL_TYPE_DEFAULT
)) {
236 DEBUG(10, ("invalid smb acl type given (%d).\n", type
));
239 DEBUGADD(10, ("setting %s acl\n",
240 ((type
== SMB_ACL_TYPE_ACCESS
) ? "access" : "default")));
242 if(!smb_acl_to_hpux_acl(theacl
, &hpux_acl
, &count
, type
)) {
243 DEBUG(10, ("conversion smb_acl -> hpux_acl failed (%s).\n",
249 * if the file is a directory, there is extra work to do:
250 * since the hpux acl call stores both the access acl and
251 * the default acl as provided, we have to get the acl part
252 * that has _not_ been specified in "type" from the file first
253 * and concatenate it with the acl provided.
255 if (lp_posix_pathnames()) {
256 ret
= SMB_VFS_LSTAT(handle
->conn
, smb_fname
);
258 ret
= SMB_VFS_STAT(handle
->conn
, smb_fname
);
261 DEBUG(10, ("Error in stat call: %s\n", strerror(errno
)));
264 if (S_ISDIR(smb_fname
->st
.st_ex_mode
)) {
265 HPUX_ACL_T other_acl
;
267 SMB_ACL_TYPE_T other_type
;
269 other_type
= (type
== SMB_ACL_TYPE_ACCESS
)
270 ? SMB_ACL_TYPE_DEFAULT
271 : SMB_ACL_TYPE_ACCESS
;
272 DEBUGADD(10, ("getting acl from filesystem\n"));
273 if (!hpux_acl_get_file(smb_fname
->base_name
, &other_acl
,
275 DEBUG(10, ("error getting acl from directory\n"));
278 DEBUG(10, ("adding %s part of fs acl to given acl\n",
279 ((other_type
== SMB_ACL_TYPE_ACCESS
)
282 if (!hpux_add_to_acl(&hpux_acl
, &count
, other_acl
,
283 other_count
, other_type
))
285 DEBUG(10, ("error adding other acl.\n"));
286 SAFE_FREE(other_acl
);
289 SAFE_FREE(other_acl
);
291 else if (type
!= SMB_ACL_TYPE_ACCESS
) {
296 if (!hpux_acl_sort(hpux_acl
, count
)) {
297 DEBUG(10, ("resulting acl is not valid!\n"));
300 DEBUG(10, ("resulting acl is valid.\n"));
302 ret
= acl(discard_const_p(char, smb_fname
->base_name
), ACL_SET
, count
,
305 DEBUG(0, ("ERROR calling acl: %s\n", strerror(errno
)));
309 DEBUG(10, ("hpuxacl_sys_acl_set_file %s.\n",
310 ((ret
!= 0) ? "failed" : "succeeded")));
311 TALLOC_FREE(smb_fname
);
317 * set the access ACL on the file referred to by a fd
319 int hpuxacl_sys_acl_set_fd(vfs_handle_struct
*handle
,
324 * HPUX doesn't have the facl call. Fake it using the path.... JRA.
327 * We know we're in the same conn context. So we
328 * can use the relative path.
330 DEBUG(10, ("redirecting call of hpuxacl_sys_acl_set_fd to "
331 "hpuxacl_sys_acl_set_file (no facl syscall on HPUX)\n"));
333 return hpuxacl_sys_acl_set_file(handle
,
334 fsp
->fsp_name
->base_name
,
335 SMB_ACL_TYPE_ACCESS
, theacl
);
340 * delete the default ACL of a directory
342 * This is achieved by fetching the access ACL and rewriting it
343 * directly, via the hpux system call: the ACL_SET call on
344 * directories writes both the access and the default ACL as provided.
346 * XXX: posix acl_delete_def_file returns an error if
347 * the file referred to by path is not a directory.
348 * this function does not complain but the actions
349 * have no effect on a file other than a directory.
350 * But sys_acl_delete_default_file is only called in
351 * smbd/posixacls.c after having checked that the file
352 * is a directory, anyways. So implementing the extra
353 * check is considered unnecessary. --- Agreed? XXX
355 int hpuxacl_sys_acl_delete_def_file(vfs_handle_struct
*handle
,
363 DEBUG(10, ("entering hpuxacl_sys_acl_delete_def_file.\n"));
365 smb_acl
= hpuxacl_sys_acl_get_file(handle
, path
,
366 SMB_ACL_TYPE_ACCESS
);
367 if (smb_acl
== NULL
) {
368 DEBUG(10, ("getting file acl failed!\n"));
371 if (!smb_acl_to_hpux_acl(smb_acl
, &hpux_acl
, &count
,
372 SMB_ACL_TYPE_ACCESS
))
374 DEBUG(10, ("conversion smb_acl -> hpux_acl failed.\n"));
377 if (!hpux_acl_sort(hpux_acl
, count
)) {
378 DEBUG(10, ("resulting acl is not valid!\n"));
381 ret
= acl(discard_const_p(char, path
), ACL_SET
, count
, hpux_acl
);
383 DEBUG(10, ("settinge file acl failed!\n"));
387 DEBUG(10, ("hpuxacl_sys_acl_delete_def_file %s.\n",
388 ((ret
!= 0) ? "failed" : "succeeded" )));
389 TALLOC_FREE(smb_acl
);
398 static HPUX_ACL_T
hpux_acl_init(int count
)
400 HPUX_ACL_T hpux_acl
=
401 (HPUX_ACL_T
)SMB_MALLOC(sizeof(HPUX_ACE_T
) * count
);
402 if (hpux_acl
== NULL
) {
409 * Convert the SMB acl to the ACCESS or DEFAULT part of a
410 * hpux ACL, as desired.
412 static bool smb_acl_to_hpux_acl(SMB_ACL_T smb_acl
,
413 HPUX_ACL_T
*hpux_acl
, int *count
,
418 int check_which
, check_rc
;
420 DEBUG(10, ("entering smb_acl_to_hpux_acl\n"));
425 for (i
= 0; i
< smb_acl
->count
; i
++) {
426 const struct smb_acl_entry
*smb_entry
= &(smb_acl
->acl
[i
]);
427 HPUX_ACE_T hpux_entry
;
429 ZERO_STRUCT(hpux_entry
);
431 hpux_entry
.a_type
= smb_tag_to_hpux_tag(smb_entry
->a_type
);
432 if (hpux_entry
.a_type
== 0) {
433 DEBUG(10, ("smb_tag to hpux_tag failed\n"));
436 switch(hpux_entry
.a_type
) {
438 DEBUG(10, ("got tag type USER with uid %d\n",
440 hpux_entry
.a_id
= (uid_t
)smb_entry
->uid
;
443 DEBUG(10, ("got tag type GROUP with gid %d\n",
445 hpux_entry
.a_id
= (uid_t
)smb_entry
->gid
;
450 if (type
== SMB_ACL_TYPE_DEFAULT
) {
451 DEBUG(10, ("adding default bit to hpux ace\n"));
452 hpux_entry
.a_type
|= ACL_DEFAULT
;
456 smb_perm_to_hpux_perm(smb_entry
->a_perm
);
457 DEBUG(10, ("assembled the following hpux ace:\n"));
458 DEBUGADD(10, (" - type: 0x%04x\n", hpux_entry
.a_type
));
459 DEBUGADD(10, (" - id: %d\n", hpux_entry
.a_id
));
460 DEBUGADD(10, (" - perm: o%o\n", hpux_entry
.a_perm
));
461 if (!hpux_add_to_acl(hpux_acl
, count
, &hpux_entry
,
464 DEBUG(10, ("error adding acl entry\n"));
467 DEBUG(10, ("count after adding: %d (i: %d)\n", *count
, i
));
468 DEBUG(10, ("test, if entry has been copied into acl:\n"));
469 DEBUGADD(10, (" - type: 0x%04x\n",
470 (*hpux_acl
)[(*count
)-1].a_type
));
471 DEBUGADD(10, (" - id: %d\n",
472 (*hpux_acl
)[(*count
)-1].a_id
));
473 DEBUGADD(10, (" - perm: o%o\n",
474 (*hpux_acl
)[(*count
)-1].a_perm
));
481 SAFE_FREE(*hpux_acl
);
483 DEBUG(10, ("smb_acl_to_hpux_acl %s\n",
484 ((ret
== True
) ? "succeeded" : "failed")));
489 * convert either the access or the default part of a
490 * soaris acl to the SMB_ACL format.
492 static SMB_ACL_T
hpux_acl_to_smb_acl(HPUX_ACL_T hpux_acl
, int count
,
498 if ((result
= sys_acl_init(0)) == NULL
) {
499 DEBUG(10, ("error allocating memory for SMB_ACL\n"));
502 for (i
= 0; i
< count
; i
++) {
503 SMB_ACL_ENTRY_T smb_entry
;
504 SMB_ACL_PERM_T smb_perm
;
506 if (!_IS_OF_TYPE(hpux_acl
[i
], type
)) {
509 result
->acl
= talloc_realloc(result
, result
->acl
, struct smb_acl_entry
, result
->count
+ 1);
510 if (result
->acl
== NULL
) {
511 DEBUG(10, ("error reallocating memory for SMB_ACL\n"));
514 smb_entry
= &result
->acl
[result
->count
];
515 if (sys_acl_set_tag_type(smb_entry
,
516 hpux_tag_to_smb_tag(hpux_acl
[i
].a_type
)) != 0)
518 DEBUG(10, ("invalid tag type given: 0x%04x\n",
519 hpux_acl
[i
].a_type
));
522 /* intentionally not checking return code here: */
523 sys_acl_set_qualifier(smb_entry
, (void *)&hpux_acl
[i
].a_id
);
524 smb_perm
= hpux_perm_to_smb_perm(hpux_acl
[i
].a_perm
);
525 if (sys_acl_set_permset(smb_entry
, &smb_perm
) != 0) {
526 DEBUG(10, ("invalid permset given: %d\n",
527 hpux_acl
[i
].a_perm
));
536 DEBUG(10, ("hpux_acl_to_smb_acl %s\n",
537 ((result
== NULL
) ? "failed" : "succeeded")));
543 static HPUX_ACL_TAG_T
smb_tag_to_hpux_tag(SMB_ACL_TAG_T smb_tag
)
545 HPUX_ACL_TAG_T hpux_tag
= 0;
547 DEBUG(10, ("smb_tag_to_hpux_tag\n"));
548 DEBUGADD(10, (" --> got smb tag 0x%04x\n", smb_tag
));
554 case SMB_ACL_USER_OBJ
:
560 case SMB_ACL_GROUP_OBJ
:
561 hpux_tag
= GROUP_OBJ
;
564 hpux_tag
= OTHER_OBJ
;
567 hpux_tag
= CLASS_OBJ
;
570 DEBUGADD(10, (" !!! unknown smb tag type 0x%04x\n", smb_tag
));
574 DEBUGADD(10, (" --> determined hpux tag 0x%04x\n", hpux_tag
));
579 static SMB_ACL_TAG_T
hpux_tag_to_smb_tag(HPUX_ACL_TAG_T hpux_tag
)
581 SMB_ACL_TAG_T smb_tag
= 0;
583 DEBUG(10, ("hpux_tag_to_smb_tag:\n"));
584 DEBUGADD(10, (" --> got hpux tag 0x%04x\n", hpux_tag
));
586 hpux_tag
&= ~ACL_DEFAULT
;
590 smb_tag
= SMB_ACL_USER
;
593 smb_tag
= SMB_ACL_USER_OBJ
;
596 smb_tag
= SMB_ACL_GROUP
;
599 smb_tag
= SMB_ACL_GROUP_OBJ
;
602 smb_tag
= SMB_ACL_OTHER
;
605 smb_tag
= SMB_ACL_MASK
;
608 DEBUGADD(10, (" !!! unknown hpux tag type: 0x%04x\n",
613 DEBUGADD(10, (" --> determined smb tag 0x%04x\n", smb_tag
));
620 * The permission bits used in the following two permission conversion
621 * functions are same, but the functions make us independent of the concrete
622 * permission data types.
624 static SMB_ACL_PERM_T
hpux_perm_to_smb_perm(const HPUX_PERM_T perm
)
626 SMB_ACL_PERM_T smb_perm
= 0;
627 smb_perm
|= ((perm
& SMB_ACL_READ
) ? SMB_ACL_READ
: 0);
628 smb_perm
|= ((perm
& SMB_ACL_WRITE
) ? SMB_ACL_WRITE
: 0);
629 smb_perm
|= ((perm
& SMB_ACL_EXECUTE
) ? SMB_ACL_EXECUTE
: 0);
634 static HPUX_PERM_T
smb_perm_to_hpux_perm(const SMB_ACL_PERM_T perm
)
636 HPUX_PERM_T hpux_perm
= 0;
637 hpux_perm
|= ((perm
& SMB_ACL_READ
) ? SMB_ACL_READ
: 0);
638 hpux_perm
|= ((perm
& SMB_ACL_WRITE
) ? SMB_ACL_WRITE
: 0);
639 hpux_perm
|= ((perm
& SMB_ACL_EXECUTE
) ? SMB_ACL_EXECUTE
: 0);
644 static bool hpux_acl_get_file(const char *name
, HPUX_ACL_T
*hpux_acl
,
648 static HPUX_ACE_T dummy_ace
;
650 DEBUG(10, ("hpux_acl_get_file called for file '%s'\n", name
));
653 * The original code tries some INITIAL_ACL_SIZE
654 * and only did the ACL_CNT call upon failure
655 * (for performance reasons).
656 * For the sake of simplicity, I skip this for now.
658 * NOTE: There is a catch here on HP-UX: acl with cmd parameter
659 * ACL_CNT fails with errno EINVAL when called with a NULL
660 * pointer as last argument. So we need to use a dummy acl
661 * struct here (we make it static so it does not need to be
662 * instantiated or malloced each time this function is
663 * called). Btw: the count parameter does not seem to matter...
665 *count
= acl(discard_const_p(char, name
), ACL_CNT
, 0, &dummy_ace
);
667 DEBUG(10, ("acl ACL_CNT failed: %s\n", strerror(errno
)));
670 *hpux_acl
= hpux_acl_init(*count
);
671 if (*hpux_acl
== NULL
) {
672 DEBUG(10, ("error allocating memory for hpux acl...\n"));
675 *count
= acl(discard_const_p(char, name
), ACL_GET
, *count
, *hpux_acl
);
677 DEBUG(10, ("acl ACL_GET failed: %s\n", strerror(errno
)));
683 DEBUG(10, ("hpux_acl_get_file %s.\n",
684 ((result
== True
) ? "succeeded" : "failed" )));
692 * Add entries to a hpux ACL.
694 * Entries are directly added to the hpuxacl parameter.
695 * if memory allocation fails, this may result in hpuxacl
696 * being NULL. if the resulting acl is to be checked and is
697 * not valid, it is kept in hpuxacl but False is returned.
699 * The type of ACEs (access/default) to be added to the ACL can
700 * be selected via the type parameter.
701 * I use the SMB_ACL_TYPE_T type here. Since SMB_ACL_TYPE_ACCESS
702 * is defined as "0", this means that one can only add either
703 * access or default ACEs from the given ACL, not both at the same
704 * time. If it should become necessary to add all of an ACL, one
705 * would have to replace this parameter by another type.
707 static bool hpux_add_to_acl(HPUX_ACL_T
*hpux_acl
, int *count
,
708 HPUX_ACL_T add_acl
, int add_count
,
713 if ((type
!= SMB_ACL_TYPE_ACCESS
) && (type
!= SMB_ACL_TYPE_DEFAULT
))
715 DEBUG(10, ("invalid acl type given: %d\n", type
));
719 for (i
= 0; i
< add_count
; i
++) {
720 if (!_IS_OF_TYPE(add_acl
[i
], type
)) {
723 ADD_TO_ARRAY(NULL
, HPUX_ACE_T
, add_acl
[i
],
725 if (hpux_acl
== NULL
) {
726 DEBUG(10, ("error enlarging acl.\n"));
736 * sort the ACL and check it for validity
738 * [original comment from lib/sysacls.c:]
740 * if it's a minimal ACL with only 4 entries then we
741 * need to recalculate the mask permissions to make
742 * sure that they are the same as the GROUP_OBJ
743 * permissions as required by the UnixWare acl() system call.
745 * (note: since POSIX allows minimal ACLs which only contain
746 * 3 entries - ie there is no mask entry - we should, in theory,
747 * check for this and add a mask entry if necessary - however
748 * we "know" that the caller of this interface always specifies
749 * a mask, so in practice "this never happens" (tm) - if it *does*
750 * happen aclsort() will fail and return an error and someone will
753 static bool hpux_acl_sort(HPUX_ACL_T hpux_acl
, int count
)
755 int fixmask
= (count
<= 4);
757 if (hpux_internal_aclsort(count
, fixmask
, hpux_acl
) != 0) {
766 * Helpers for hpux_internal_aclsort:
768 * - hpux_swap_acl_entries
769 * - hpux_prohibited_duplicate_type
770 * - hpux_get_needed_class_perm
774 * Counts the different number of objects in a given array of ACL
778 * acl_count - Count of ACLs in the array of ACL strucutres.
779 * aclp - Array of ACL structures.
780 * acl_type_count - Pointer to acl_types structure. Should already be
784 * acl_type_count - This structure is filled up with counts of various
788 static void hpux_count_obj(int acl_count
, HPUX_ACL_T aclp
, struct hpux_acl_types
*acl_type_count
)
792 memset(acl_type_count
, 0, sizeof(struct hpux_acl_types
));
794 for(i
=0;i
<acl_count
;i
++) {
795 switch(aclp
[i
].a_type
) {
797 acl_type_count
->n_user
++;
800 acl_type_count
->n_user_obj
++;
803 acl_type_count
->n_def_user_obj
++;
806 acl_type_count
->n_group
++;
809 acl_type_count
->n_group_obj
++;
812 acl_type_count
->n_def_group_obj
++;
815 acl_type_count
->n_other_obj
++;
818 acl_type_count
->n_def_other_obj
++;
821 acl_type_count
->n_class_obj
++;
824 acl_type_count
->n_def_class_obj
++;
827 acl_type_count
->n_def_user
++;
830 acl_type_count
->n_def_group
++;
833 acl_type_count
->n_illegal_obj
++;
839 /* hpux_swap_acl_entries: Swaps two ACL entries.
841 * Inputs: aclp0, aclp1 - ACL entries to be swapped.
844 static void hpux_swap_acl_entries(HPUX_ACE_T
*aclp0
, HPUX_ACE_T
*aclp1
)
848 temp_acl
.a_type
= aclp0
->a_type
;
849 temp_acl
.a_id
= aclp0
->a_id
;
850 temp_acl
.a_perm
= aclp0
->a_perm
;
852 aclp0
->a_type
= aclp1
->a_type
;
853 aclp0
->a_id
= aclp1
->a_id
;
854 aclp0
->a_perm
= aclp1
->a_perm
;
856 aclp1
->a_type
= temp_acl
.a_type
;
857 aclp1
->a_id
= temp_acl
.a_id
;
858 aclp1
->a_perm
= temp_acl
.a_perm
;
861 /* hpux_prohibited_duplicate_type
862 * Identifies if given ACL type can have duplicate entries or
865 * Inputs: acl_type - ACL Type.
871 * True - If the ACL type matches any of the prohibited types.
872 * False - If the ACL type doesn't match any of the prohibited types.
875 static bool hpux_prohibited_duplicate_type(int acl_type
)
888 /* hpux_get_needed_class_perm
889 * Returns the permissions of a ACL structure only if the ACL
890 * type matches one of the pre-determined types for computing
891 * CLASS_OBJ permissions.
893 * Inputs: aclp - Pointer to ACL structure.
896 static int hpux_get_needed_class_perm(struct acl
*aclp
)
898 switch(aclp
->a_type
) {
914 /* hpux_internal_aclsort: aclsort for HPUX.
916 * -> The aclsort() system call is availabe on the latest HPUX General
917 * -> Patch Bundles. So for HPUX, we developed our version of aclsort
918 * -> function. Because, we don't want to update to a new
919 * -> HPUX GR bundle just for aclsort() call.
921 * aclsort sorts the array of ACL structures as per the description in
922 * aclsort man page. Refer to aclsort man page for more details
926 * acl_count - Count of ACLs in the array of ACL structures.
927 * calclass - If this is not zero, then we compute the CLASS_OBJ
929 * aclp - Array of ACL structures.
933 * aclp - Sorted array of ACL structures.
937 * Returns 0 for success -1 for failure. Prints a message to the Samba
938 * debug log in case of failure.
941 static int hpux_internal_aclsort(int acl_count
, int calclass
, HPUX_ACL_T aclp
)
943 struct hpux_acl_types acl_obj_count
;
944 int n_class_obj_perm
= 0;
947 DEBUG(10,("Entering hpux_internal_aclsort. (calclass = %d)\n", calclass
));
949 if (hpux_aclsort_call_present()) {
950 DEBUG(10, ("calling hpux aclsort\n"));
951 return aclsort(acl_count
, calclass
, aclp
);
954 DEBUG(10, ("using internal aclsort\n"));
957 DEBUG(10,("Zero acl count passed. Returning Success\n"));
962 DEBUG(0,("Null ACL pointer in hpux_acl_sort. Returning Failure. \n"));
966 /* Count different types of ACLs in the ACLs array */
968 hpux_count_obj(acl_count
, aclp
, &acl_obj_count
);
970 /* There should be only one entry each of type USER_OBJ, GROUP_OBJ,
971 * CLASS_OBJ and OTHER_OBJ
974 if ( (acl_obj_count
.n_user_obj
!= 1) ||
975 (acl_obj_count
.n_group_obj
!= 1) ||
976 (acl_obj_count
.n_class_obj
!= 1) ||
977 (acl_obj_count
.n_other_obj
!= 1) )
979 DEBUG(0,("hpux_internal_aclsort: More than one entry or no entries for \
980 USER OBJ or GROUP_OBJ or OTHER_OBJ or CLASS_OBJ\n"));
984 /* If any of the default objects are present, there should be only
988 if ( (acl_obj_count
.n_def_user_obj
> 1) ||
989 (acl_obj_count
.n_def_group_obj
> 1) ||
990 (acl_obj_count
.n_def_other_obj
> 1) ||
991 (acl_obj_count
.n_def_class_obj
> 1) )
993 DEBUG(0,("hpux_internal_aclsort: More than one entry for DEF_CLASS_OBJ \
994 or DEF_USER_OBJ or DEF_GROUP_OBJ or DEF_OTHER_OBJ\n"));
998 /* We now have proper number of OBJ and DEF_OBJ entries. Now sort the acl
1001 * Sorting crieteria - First sort by ACL type. If there are multiple entries of
1002 * same ACL type, sort by ACL id.
1004 * I am using the trival kind of sorting method here because, performance isn't
1005 * really effected by the ACLs feature. More over there aren't going to be more
1006 * than 17 entries on HPUX.
1009 for(i
=0; i
<acl_count
;i
++) {
1010 for (j
=i
+1; j
<acl_count
; j
++) {
1011 if( aclp
[i
].a_type
> aclp
[j
].a_type
) {
1012 /* ACL entries out of order, swap them */
1013 hpux_swap_acl_entries((aclp
+i
), (aclp
+j
));
1014 } else if ( aclp
[i
].a_type
== aclp
[j
].a_type
) {
1015 /* ACL entries of same type, sort by id */
1016 if(aclp
[i
].a_id
> aclp
[j
].a_id
) {
1017 hpux_swap_acl_entries((aclp
+i
), (aclp
+j
));
1018 } else if (aclp
[i
].a_id
== aclp
[j
].a_id
) {
1019 /* We have a duplicate entry. */
1020 if(hpux_prohibited_duplicate_type(aclp
[i
].a_type
)) {
1021 DEBUG(0, ("hpux_internal_aclsort: Duplicate entry: Type(hex): %x Id: %d\n",
1022 aclp
[i
].a_type
, aclp
[i
].a_id
));
1030 /* set the class obj permissions to the computed one. */
1032 int n_class_obj_index
= -1;
1034 for(i
=0;i
<acl_count
;i
++) {
1035 n_class_obj_perm
|= hpux_get_needed_class_perm((aclp
+i
));
1037 if(aclp
[i
].a_type
== CLASS_OBJ
)
1038 n_class_obj_index
= i
;
1040 aclp
[n_class_obj_index
].a_perm
= n_class_obj_perm
;
1048 * hpux_acl_call_present:
1050 * This checks if the POSIX ACL system call is defined
1051 * which basically corresponds to whether JFS 3.3 or
1052 * higher is installed. If acl() was called when it
1053 * isn't defined, it causes the process to core dump
1054 * so it is important to check this and avoid acl()
1055 * calls if it isn't there.
1058 static bool hpux_acl_call_present(void)
1061 shl_t handle
= NULL
;
1064 static bool already_checked
= False
;
1071 ret_val
= shl_findsym(&handle
, "acl", TYPE_PROCEDURE
, &value
);
1074 DEBUG(5, ("hpux_acl_call_present: shl_findsym() returned %d, errno = %d, error %s\n",
1075 ret_val
, errno
, strerror(errno
)));
1076 DEBUG(5,("hpux_acl_call_present: acl() system call is not present. Check if you have JFS 3.3 and above?\n"));
1081 DEBUG(10,("hpux_acl_call_present: acl() system call is present. We have JFS 3.3 or above \n"));
1083 already_checked
= True
;
1088 * runtime check for presence of aclsort library call.
1089 * same code as for acl call. if there are more of these,
1090 * a dispatcher function could be handy...
1093 static bool hpux_aclsort_call_present(void)
1095 shl_t handle
= NULL
;
1098 static bool already_checked
= False
;
1100 if (already_checked
) {
1105 ret_val
= shl_findsym(&handle
, "aclsort", TYPE_PROCEDURE
, &value
);
1107 DEBUG(5, ("hpux_aclsort_call_present: shl_findsym "
1108 "returned %d, errno = %d, error %s",
1109 ret_val
, errno
, strerror(errno
)));
1110 DEBUG(5, ("hpux_aclsort_call_present: "
1111 "aclsort() function not available.\n"));
1114 DEBUG(10,("hpux_aclsort_call_present: aclsort() function present.\n"));
1115 already_checked
= True
;
1121 * acl check function:
1122 * unused at the moment but could be used to get more
1123 * concrete error messages for debugging...
1124 * (acl sort just says that the acl is invalid...)
1126 static bool hpux_acl_check(HPUX_ACL_T hpux_acl
, int count
)
1131 check_rc
= aclcheck(hpux_acl
, count
, &check_which
);
1132 if (check_rc
!= 0) {
1133 DEBUG(10, ("acl is not valid:\n"));
1134 DEBUGADD(10, (" - return code: %d\n", check_rc
));
1135 DEBUGADD(10, (" - which: %d\n", check_which
));
1136 if (check_which
!= -1) {
1137 DEBUGADD(10, (" - invalid entry:\n"));
1138 DEBUGADD(10, (" * type: %d:\n",
1139 hpux_acl
[check_which
].a_type
));
1140 DEBUGADD(10, (" * id: %d\n",
1141 hpux_acl
[check_which
].a_id
));
1142 DEBUGADD(10, (" * perm: 0o%o\n",
1143 hpux_acl
[check_which
].a_perm
));
1151 /* VFS operations structure */
1153 static struct vfs_fn_pointers hpuxacl_fns
= {
1154 .sys_acl_get_file_fn
= hpuxacl_sys_acl_get_file
,
1155 .sys_acl_get_fd_fn
= hpuxacl_sys_acl_get_fd
,
1156 .sys_acl_set_file_fn
= hpuxacl_sys_acl_set_file
,
1157 .sys_acl_set_fd_fn
= hpuxacl_sys_acl_set_fd
,
1158 .sys_acl_delete_def_file_fn
= hpuxacl_sys_acl_delete_def_file
,
1161 NTSTATUS
vfs_hpuxacl_init(void)
1163 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "hpuxacl",