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
, TALLOC_CTX
*mem_ctx
);
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 static SMB_ACL_T
hpuxacl_sys_acl_get_file(vfs_handle_struct
*handle
,
142 const struct smb_filename
*smb_fname
,
146 SMB_ACL_T result
= NULL
;
148 HPUX_ACL_T hpux_acl
= NULL
;
149 const char *path_p
= smb_fname
->base_name
;
151 DEBUG(10, ("hpuxacl_sys_acl_get_file called for file '%s'.\n",
154 if(hpux_acl_call_present() == False
) {
155 /* Looks like we don't have the acl() system call on HPUX.
156 * May be the system doesn't have the latest version of JFS.
161 if (type
!= SMB_ACL_TYPE_ACCESS
&& type
!= SMB_ACL_TYPE_DEFAULT
) {
162 DEBUG(10, ("invalid SMB_ACL_TYPE given (%d)\n", type
));
167 DEBUGADD(10, ("getting %s acl\n",
168 ((type
== SMB_ACL_TYPE_ACCESS
) ? "access" : "default")));
170 if (!hpux_acl_get_file(path_p
, &hpux_acl
, &count
)) {
173 result
= hpux_acl_to_smb_acl(hpux_acl
, count
, type
, mem_ctx
);
174 if (result
== NULL
) {
175 DEBUG(10, ("conversion hpux_acl -> smb_acl failed (%s).\n",
180 DEBUG(10, ("hpuxacl_sys_acl_get_file %s.\n",
181 ((result
== NULL
) ? "failed" : "succeeded" )));
188 * get the access ACL of a file referred to by a fd
190 SMB_ACL_T
hpuxacl_sys_acl_get_fd(vfs_handle_struct
*handle
,
196 * HPUX doesn't have the facl call. Fake it using the path.... JRA.
199 * We know we're in the same conn context. So we
200 * can use the relative path.
202 DEBUG(10, ("redirecting call of hpuxacl_sys_acl_get_fd to "
203 "hpuxacl_sys_acl_get_file (no facl syscall on HPUX).\n"));
205 return hpuxacl_sys_acl_get_file(handle
,
206 fsp
->fsp_name
->base_name
,
212 int hpuxacl_sys_acl_set_file(vfs_handle_struct
*handle
,
213 const struct smb_filename
*smb_fname_in
,
218 HPUX_ACL_T hpux_acl
= NULL
;
220 struct smb_filename
*smb_fname
= NULL
;
223 DEBUG(10, ("hpuxacl_sys_acl_set_file called for file '%s'\n",
226 smb_fname
= cp_smb_filename(talloc_tos(), smb_fname_in
);
227 if (smb_fname
== NULL
) {
228 status
= NT_STATUS_NO_MEMORY
;
232 if(hpux_acl_call_present() == False
) {
233 /* Looks like we don't have the acl() system call on HPUX.
234 * May be the system doesn't have the latest version of JFS.
239 if ((type
!= SMB_ACL_TYPE_ACCESS
) && (type
!= SMB_ACL_TYPE_DEFAULT
)) {
241 DEBUG(10, ("invalid smb acl type given (%d).\n", type
));
244 DEBUGADD(10, ("setting %s acl\n",
245 ((type
== SMB_ACL_TYPE_ACCESS
) ? "access" : "default")));
247 if(!smb_acl_to_hpux_acl(theacl
, &hpux_acl
, &count
, type
)) {
248 DEBUG(10, ("conversion smb_acl -> hpux_acl failed (%s).\n",
254 * We can directly use SMB_VFS_STAT here, as if this was a
255 * POSIX call on a symlink, we've already refused it.
256 * For a Windows acl mapped call on a symlink, we want to follow
259 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
)) {
266 * if the file is a directory, there is extra work to do:
267 * since the hpux acl call stores both the access acl and
268 * the default acl as provided, we have to get the acl part
269 * that has _not_ been specified in "type" from the file first
270 * and concatenate it with the acl provided.
272 HPUX_ACL_T other_acl
;
274 SMB_ACL_TYPE_T other_type
;
276 other_type
= (type
== SMB_ACL_TYPE_ACCESS
)
277 ? SMB_ACL_TYPE_DEFAULT
278 : SMB_ACL_TYPE_ACCESS
;
279 DEBUGADD(10, ("getting acl from filesystem\n"));
280 if (!hpux_acl_get_file(smb_fname
->base_name
, &other_acl
,
282 DEBUG(10, ("error getting acl from directory\n"));
285 DEBUG(10, ("adding %s part of fs acl to given acl\n",
286 ((other_type
== SMB_ACL_TYPE_ACCESS
)
289 if (!hpux_add_to_acl(&hpux_acl
, &count
, other_acl
,
290 other_count
, other_type
))
292 DEBUG(10, ("error adding other acl.\n"));
293 SAFE_FREE(other_acl
);
296 SAFE_FREE(other_acl
);
298 else if (type
!= SMB_ACL_TYPE_ACCESS
) {
303 if (!hpux_acl_sort(hpux_acl
, count
)) {
304 DEBUG(10, ("resulting acl is not valid!\n"));
307 DEBUG(10, ("resulting acl is valid.\n"));
309 ret
= acl(discard_const_p(char, smb_fname
->base_name
), ACL_SET
, count
,
312 DEBUG(0, ("ERROR calling acl: %s\n", strerror(errno
)));
316 DEBUG(10, ("hpuxacl_sys_acl_set_file %s.\n",
317 ((ret
!= 0) ? "failed" : "succeeded")));
318 TALLOC_FREE(smb_fname
);
324 * set the access ACL on the file referred to by a fd
326 int hpuxacl_sys_acl_set_fd(vfs_handle_struct
*handle
,
332 * HPUX doesn't have the facl call. Fake it using the path.... JRA.
335 * We know we're in the same conn context. So we
336 * can use the relative path.
338 DEBUG(10, ("redirecting call of hpuxacl_sys_acl_set_fd to "
339 "hpuxacl_sys_acl_set_file (no facl syscall on HPUX)\n"));
341 return hpuxacl_sys_acl_set_file(handle
,
342 fsp
->fsp_name
->base_name
,
347 * delete the default ACL of a directory
349 * This is achieved by fetching the access ACL and rewriting it
350 * directly, via the hpux system call: the ACL_SET call on
351 * directories writes both the access and the default ACL as provided.
353 * XXX: posix acl_delete_def_file returns an error if
354 * the file referred to by path is not a directory.
355 * this function does not complain but the actions
356 * have no effect on a file other than a directory.
357 * But sys_acl_delete_default_file is only called in
358 * smbd/posixacls.c after having checked that the file
359 * is a directory, anyways. So implementing the extra
360 * check is considered unnecessary. --- Agreed? XXX
362 int hpuxacl_sys_acl_delete_def_fd(vfs_handle_struct
*handle
,
370 DBG_DEBUG("entering hpuxacl_sys_acl_delete_def_fd.\n");
372 smb_acl
= hpuxacl_sys_acl_get_file(handle
, fsp
->fsp_name
->base_name
,
373 SMB_ACL_TYPE_ACCESS
);
374 if (smb_acl
== NULL
) {
375 DBG_DEBUG("getting file acl failed!\n");
378 if (!smb_acl_to_hpux_acl(smb_acl
, &hpux_acl
, &count
,
379 SMB_ACL_TYPE_ACCESS
))
381 DBG_DEBUG("conversion smb_acl -> hpux_acl failed.\n");
384 if (!hpux_acl_sort(hpux_acl
, count
)) {
385 DBG_DEBUG("resulting acl is not valid!\n");
388 ret
= acl(discard_const_p(char, fsp
->fsp_name
->base_name
),
389 ACL_SET
, count
, hpux_acl
);
391 DBG_DEBUG("settinge file acl failed!\n");
395 DBG_DEBUG("hpuxacl_sys_acl_delete_def_fd %s.\n",
396 ((ret
!= 0) ? "failed" : "succeeded" ));
397 TALLOC_FREE(smb_acl
);
405 static HPUX_ACL_T
hpux_acl_init(int count
)
407 HPUX_ACL_T hpux_acl
=
408 (HPUX_ACL_T
)SMB_MALLOC(sizeof(HPUX_ACE_T
) * count
);
409 if (hpux_acl
== NULL
) {
416 * Convert the SMB acl to the ACCESS or DEFAULT part of a
417 * hpux ACL, as desired.
419 static bool smb_acl_to_hpux_acl(SMB_ACL_T smb_acl
,
420 HPUX_ACL_T
*hpux_acl
, int *count
,
425 int check_which
, check_rc
;
427 DEBUG(10, ("entering smb_acl_to_hpux_acl\n"));
432 for (i
= 0; i
< smb_acl
->count
; i
++) {
433 const struct smb_acl_entry
*smb_entry
= &(smb_acl
->acl
[i
]);
434 HPUX_ACE_T hpux_entry
;
436 ZERO_STRUCT(hpux_entry
);
438 hpux_entry
.a_type
= smb_tag_to_hpux_tag(smb_entry
->a_type
);
439 if (hpux_entry
.a_type
== 0) {
440 DEBUG(10, ("smb_tag to hpux_tag failed\n"));
443 switch(hpux_entry
.a_type
) {
445 DEBUG(10, ("got tag type USER with uid %d\n",
446 smb_entry
->info
.user
.uid
));
447 hpux_entry
.a_id
= (uid_t
)smb_entry
->info
.user
.uid
;
450 DEBUG(10, ("got tag type GROUP with gid %d\n",
451 smb_entry
->info
.group
.gid
));
452 hpux_entry
.a_id
= (uid_t
)smb_entry
->info
.group
.gid
;
457 if (type
== SMB_ACL_TYPE_DEFAULT
) {
458 DEBUG(10, ("adding default bit to hpux ace\n"));
459 hpux_entry
.a_type
|= ACL_DEFAULT
;
463 smb_perm_to_hpux_perm(smb_entry
->a_perm
);
464 DEBUG(10, ("assembled the following hpux ace:\n"));
465 DEBUGADD(10, (" - type: 0x%04x\n", hpux_entry
.a_type
));
466 DEBUGADD(10, (" - id: %d\n", hpux_entry
.a_id
));
467 DEBUGADD(10, (" - perm: o%o\n", hpux_entry
.a_perm
));
468 if (!hpux_add_to_acl(hpux_acl
, count
, &hpux_entry
,
471 DEBUG(10, ("error adding acl entry\n"));
474 DEBUG(10, ("count after adding: %d (i: %d)\n", *count
, i
));
475 DEBUG(10, ("test, if entry has been copied into acl:\n"));
476 DEBUGADD(10, (" - type: 0x%04x\n",
477 (*hpux_acl
)[(*count
)-1].a_type
));
478 DEBUGADD(10, (" - id: %d\n",
479 (*hpux_acl
)[(*count
)-1].a_id
));
480 DEBUGADD(10, (" - perm: o%o\n",
481 (*hpux_acl
)[(*count
)-1].a_perm
));
488 SAFE_FREE(*hpux_acl
);
490 DEBUG(10, ("smb_acl_to_hpux_acl %s\n",
491 ((ret
== True
) ? "succeeded" : "failed")));
496 * convert either the access or the default part of a
497 * soaris acl to the SMB_ACL format.
499 static SMB_ACL_T
hpux_acl_to_smb_acl(HPUX_ACL_T hpux_acl
, int count
,
500 SMB_ACL_TYPE_T type
, TALLOC_CTX
*mem_ctx
)
505 if ((result
= sys_acl_init(mem_ctx
)) == NULL
) {
506 DEBUG(10, ("error allocating memory for SMB_ACL\n"));
509 for (i
= 0; i
< count
; i
++) {
510 SMB_ACL_ENTRY_T smb_entry
;
511 SMB_ACL_PERM_T smb_perm
;
513 if (!_IS_OF_TYPE(hpux_acl
[i
], type
)) {
516 result
->acl
= talloc_realloc(result
, result
->acl
, struct smb_acl_entry
, result
->count
+ 1);
517 if (result
->acl
== NULL
) {
518 DEBUG(10, ("error reallocating memory for SMB_ACL\n"));
521 smb_entry
= &result
->acl
[result
->count
];
522 if (sys_acl_set_tag_type(smb_entry
,
523 hpux_tag_to_smb_tag(hpux_acl
[i
].a_type
)) != 0)
525 DEBUG(10, ("invalid tag type given: 0x%04x\n",
526 hpux_acl
[i
].a_type
));
529 /* intentionally not checking return code here: */
530 sys_acl_set_qualifier(smb_entry
, (void *)&hpux_acl
[i
].a_id
);
531 smb_perm
= hpux_perm_to_smb_perm(hpux_acl
[i
].a_perm
);
532 if (sys_acl_set_permset(smb_entry
, &smb_perm
) != 0) {
533 DEBUG(10, ("invalid permset given: %d\n",
534 hpux_acl
[i
].a_perm
));
543 DEBUG(10, ("hpux_acl_to_smb_acl %s\n",
544 ((result
== NULL
) ? "failed" : "succeeded")));
550 static HPUX_ACL_TAG_T
smb_tag_to_hpux_tag(SMB_ACL_TAG_T smb_tag
)
552 HPUX_ACL_TAG_T hpux_tag
= 0;
554 DEBUG(10, ("smb_tag_to_hpux_tag\n"));
555 DEBUGADD(10, (" --> got smb tag 0x%04x\n", smb_tag
));
561 case SMB_ACL_USER_OBJ
:
567 case SMB_ACL_GROUP_OBJ
:
568 hpux_tag
= GROUP_OBJ
;
571 hpux_tag
= OTHER_OBJ
;
574 hpux_tag
= CLASS_OBJ
;
577 DEBUGADD(10, (" !!! unknown smb tag type 0x%04x\n", smb_tag
));
581 DEBUGADD(10, (" --> determined hpux tag 0x%04x\n", hpux_tag
));
586 static SMB_ACL_TAG_T
hpux_tag_to_smb_tag(HPUX_ACL_TAG_T hpux_tag
)
588 SMB_ACL_TAG_T smb_tag
= 0;
590 DEBUG(10, ("hpux_tag_to_smb_tag:\n"));
591 DEBUGADD(10, (" --> got hpux tag 0x%04x\n", hpux_tag
));
593 hpux_tag
&= ~ACL_DEFAULT
;
597 smb_tag
= SMB_ACL_USER
;
600 smb_tag
= SMB_ACL_USER_OBJ
;
603 smb_tag
= SMB_ACL_GROUP
;
606 smb_tag
= SMB_ACL_GROUP_OBJ
;
609 smb_tag
= SMB_ACL_OTHER
;
612 smb_tag
= SMB_ACL_MASK
;
615 DEBUGADD(10, (" !!! unknown hpux tag type: 0x%04x\n",
620 DEBUGADD(10, (" --> determined smb tag 0x%04x\n", smb_tag
));
627 * The permission bits used in the following two permission conversion
628 * functions are same, but the functions make us independent of the concrete
629 * permission data types.
631 static SMB_ACL_PERM_T
hpux_perm_to_smb_perm(const HPUX_PERM_T perm
)
633 SMB_ACL_PERM_T smb_perm
= 0;
634 smb_perm
|= ((perm
& SMB_ACL_READ
) ? SMB_ACL_READ
: 0);
635 smb_perm
|= ((perm
& SMB_ACL_WRITE
) ? SMB_ACL_WRITE
: 0);
636 smb_perm
|= ((perm
& SMB_ACL_EXECUTE
) ? SMB_ACL_EXECUTE
: 0);
641 static HPUX_PERM_T
smb_perm_to_hpux_perm(const SMB_ACL_PERM_T perm
)
643 HPUX_PERM_T hpux_perm
= 0;
644 hpux_perm
|= ((perm
& SMB_ACL_READ
) ? SMB_ACL_READ
: 0);
645 hpux_perm
|= ((perm
& SMB_ACL_WRITE
) ? SMB_ACL_WRITE
: 0);
646 hpux_perm
|= ((perm
& SMB_ACL_EXECUTE
) ? SMB_ACL_EXECUTE
: 0);
651 static bool hpux_acl_get_file(const char *name
, HPUX_ACL_T
*hpux_acl
,
655 static HPUX_ACE_T dummy_ace
;
657 DEBUG(10, ("hpux_acl_get_file called for file '%s'\n", name
));
660 * The original code tries some INITIAL_ACL_SIZE
661 * and only did the ACL_CNT call upon failure
662 * (for performance reasons).
663 * For the sake of simplicity, I skip this for now.
665 * NOTE: There is a catch here on HP-UX: acl with cmd parameter
666 * ACL_CNT fails with errno EINVAL when called with a NULL
667 * pointer as last argument. So we need to use a dummy acl
668 * struct here (we make it static so it does not need to be
669 * instantiated or malloced each time this function is
670 * called). Btw: the count parameter does not seem to matter...
672 *count
= acl(discard_const_p(char, name
), ACL_CNT
, 0, &dummy_ace
);
674 DEBUG(10, ("acl ACL_CNT failed: %s\n", strerror(errno
)));
677 *hpux_acl
= hpux_acl_init(*count
);
678 if (*hpux_acl
== NULL
) {
679 DEBUG(10, ("error allocating memory for hpux acl...\n"));
682 *count
= acl(discard_const_p(char, name
), ACL_GET
, *count
, *hpux_acl
);
684 DEBUG(10, ("acl ACL_GET failed: %s\n", strerror(errno
)));
690 DEBUG(10, ("hpux_acl_get_file %s.\n",
691 ((result
== True
) ? "succeeded" : "failed" )));
699 * Add entries to a hpux ACL.
701 * Entries are directly added to the hpuxacl parameter.
702 * if memory allocation fails, this may result in hpuxacl
703 * being NULL. if the resulting acl is to be checked and is
704 * not valid, it is kept in hpuxacl but False is returned.
706 * The type of ACEs (access/default) to be added to the ACL can
707 * be selected via the type parameter.
708 * I use the SMB_ACL_TYPE_T type here. Since SMB_ACL_TYPE_ACCESS
709 * is defined as "0", this means that one can only add either
710 * access or default ACEs from the given ACL, not both at the same
711 * time. If it should become necessary to add all of an ACL, one
712 * would have to replace this parameter by another type.
714 static bool hpux_add_to_acl(HPUX_ACL_T
*hpux_acl
, int *count
,
715 HPUX_ACL_T add_acl
, int add_count
,
720 if ((type
!= SMB_ACL_TYPE_ACCESS
) && (type
!= SMB_ACL_TYPE_DEFAULT
))
722 DEBUG(10, ("invalid acl type given: %d\n", type
));
726 for (i
= 0; i
< add_count
; i
++) {
727 if (!_IS_OF_TYPE(add_acl
[i
], type
)) {
730 ADD_TO_ARRAY(NULL
, HPUX_ACE_T
, add_acl
[i
],
732 if (hpux_acl
== NULL
) {
733 DEBUG(10, ("error enlarging acl.\n"));
743 * sort the ACL and check it for validity
745 * [original comment from lib/sysacls.c:]
747 * if it's a minimal ACL with only 4 entries then we
748 * need to recalculate the mask permissions to make
749 * sure that they are the same as the GROUP_OBJ
750 * permissions as required by the UnixWare acl() system call.
752 * (note: since POSIX allows minimal ACLs which only contain
753 * 3 entries - ie there is no mask entry - we should, in theory,
754 * check for this and add a mask entry if necessary - however
755 * we "know" that the caller of this interface always specifies
756 * a mask, so in practice "this never happens" (tm) - if it *does*
757 * happen aclsort() will fail and return an error and someone will
760 static bool hpux_acl_sort(HPUX_ACL_T hpux_acl
, int count
)
762 int fixmask
= (count
<= 4);
764 if (hpux_internal_aclsort(count
, fixmask
, hpux_acl
) != 0) {
773 * Helpers for hpux_internal_aclsort:
775 * - hpux_swap_acl_entries
776 * - hpux_prohibited_duplicate_type
777 * - hpux_get_needed_class_perm
781 * Counts the different number of objects in a given array of ACL
785 * acl_count - Count of ACLs in the array of ACL structures.
786 * aclp - Array of ACL structures.
787 * acl_type_count - Pointer to acl_types structure. Should already be
791 * acl_type_count - This structure is filled up with counts of various
795 static void hpux_count_obj(int acl_count
, HPUX_ACL_T aclp
, struct hpux_acl_types
*acl_type_count
)
799 memset(acl_type_count
, 0, sizeof(struct hpux_acl_types
));
801 for(i
=0;i
<acl_count
;i
++) {
802 switch(aclp
[i
].a_type
) {
804 acl_type_count
->n_user
++;
807 acl_type_count
->n_user_obj
++;
810 acl_type_count
->n_def_user_obj
++;
813 acl_type_count
->n_group
++;
816 acl_type_count
->n_group_obj
++;
819 acl_type_count
->n_def_group_obj
++;
822 acl_type_count
->n_other_obj
++;
825 acl_type_count
->n_def_other_obj
++;
828 acl_type_count
->n_class_obj
++;
831 acl_type_count
->n_def_class_obj
++;
834 acl_type_count
->n_def_user
++;
837 acl_type_count
->n_def_group
++;
840 acl_type_count
->n_illegal_obj
++;
846 /* hpux_swap_acl_entries: Swaps two ACL entries.
848 * Inputs: aclp0, aclp1 - ACL entries to be swapped.
851 static void hpux_swap_acl_entries(HPUX_ACE_T
*aclp0
, HPUX_ACE_T
*aclp1
)
855 temp_acl
.a_type
= aclp0
->a_type
;
856 temp_acl
.a_id
= aclp0
->a_id
;
857 temp_acl
.a_perm
= aclp0
->a_perm
;
859 aclp0
->a_type
= aclp1
->a_type
;
860 aclp0
->a_id
= aclp1
->a_id
;
861 aclp0
->a_perm
= aclp1
->a_perm
;
863 aclp1
->a_type
= temp_acl
.a_type
;
864 aclp1
->a_id
= temp_acl
.a_id
;
865 aclp1
->a_perm
= temp_acl
.a_perm
;
868 /* hpux_prohibited_duplicate_type
869 * Identifies if given ACL type can have duplicate entries or
872 * Inputs: acl_type - ACL Type.
878 * True - If the ACL type matches any of the prohibited types.
879 * False - If the ACL type doesn't match any of the prohibited types.
882 static bool hpux_prohibited_duplicate_type(int acl_type
)
895 /* hpux_get_needed_class_perm
896 * Returns the permissions of a ACL structure only if the ACL
897 * type matches one of the pre-determined types for computing
898 * CLASS_OBJ permissions.
900 * Inputs: aclp - Pointer to ACL structure.
903 static int hpux_get_needed_class_perm(struct acl
*aclp
)
905 switch(aclp
->a_type
) {
921 /* hpux_internal_aclsort: aclsort for HPUX.
923 * -> The aclsort() system call is available on the latest HPUX General
924 * -> Patch Bundles. So for HPUX, we developed our version of aclsort
925 * -> function. Because, we don't want to update to a new
926 * -> HPUX GR bundle just for aclsort() call.
928 * aclsort sorts the array of ACL structures as per the description in
929 * aclsort man page. Refer to aclsort man page for more details
933 * acl_count - Count of ACLs in the array of ACL structures.
934 * calclass - If this is not zero, then we compute the CLASS_OBJ
936 * aclp - Array of ACL structures.
940 * aclp - Sorted array of ACL structures.
944 * Returns 0 for success -1 for failure. Prints a message to the Samba
945 * debug log in case of failure.
948 static int hpux_internal_aclsort(int acl_count
, int calclass
, HPUX_ACL_T aclp
)
950 struct hpux_acl_types acl_obj_count
;
951 int n_class_obj_perm
= 0;
954 DEBUG(10,("Entering hpux_internal_aclsort. (calclass = %d)\n", calclass
));
956 if (hpux_aclsort_call_present()) {
957 DEBUG(10, ("calling hpux aclsort\n"));
958 return aclsort(acl_count
, calclass
, aclp
);
961 DEBUG(10, ("using internal aclsort\n"));
964 DEBUG(10,("Zero acl count passed. Returning Success\n"));
969 DEBUG(0,("Null ACL pointer in hpux_acl_sort. Returning Failure. \n"));
973 /* Count different types of ACLs in the ACLs array */
975 hpux_count_obj(acl_count
, aclp
, &acl_obj_count
);
977 /* There should be only one entry each of type USER_OBJ, GROUP_OBJ,
978 * CLASS_OBJ and OTHER_OBJ
981 if ( (acl_obj_count
.n_user_obj
!= 1) ||
982 (acl_obj_count
.n_group_obj
!= 1) ||
983 (acl_obj_count
.n_class_obj
!= 1) ||
984 (acl_obj_count
.n_other_obj
!= 1) )
986 DEBUG(0,("hpux_internal_aclsort: More than one entry or no entries for \
987 USER OBJ or GROUP_OBJ or OTHER_OBJ or CLASS_OBJ\n"));
991 /* If any of the default objects are present, there should be only
995 if ( (acl_obj_count
.n_def_user_obj
> 1) ||
996 (acl_obj_count
.n_def_group_obj
> 1) ||
997 (acl_obj_count
.n_def_other_obj
> 1) ||
998 (acl_obj_count
.n_def_class_obj
> 1) )
1000 DEBUG(0,("hpux_internal_aclsort: More than one entry for DEF_CLASS_OBJ \
1001 or DEF_USER_OBJ or DEF_GROUP_OBJ or DEF_OTHER_OBJ\n"));
1005 /* We now have proper number of OBJ and DEF_OBJ entries. Now sort the acl
1008 * Sorting crieteria - First sort by ACL type. If there are multiple entries of
1009 * same ACL type, sort by ACL id.
1011 * I am using the trivial kind of sorting method here because, performance isn't
1012 * really effected by the ACLs feature. More over there aren't going to be more
1013 * than 17 entries on HPUX.
1016 for(i
=0; i
<acl_count
;i
++) {
1017 for (j
=i
+1; j
<acl_count
; j
++) {
1018 if( aclp
[i
].a_type
> aclp
[j
].a_type
) {
1019 /* ACL entries out of order, swap them */
1020 hpux_swap_acl_entries((aclp
+i
), (aclp
+j
));
1021 } else if ( aclp
[i
].a_type
== aclp
[j
].a_type
) {
1022 /* ACL entries of same type, sort by id */
1023 if(aclp
[i
].a_id
> aclp
[j
].a_id
) {
1024 hpux_swap_acl_entries((aclp
+i
), (aclp
+j
));
1025 } else if (aclp
[i
].a_id
== aclp
[j
].a_id
) {
1026 /* We have a duplicate entry. */
1027 if(hpux_prohibited_duplicate_type(aclp
[i
].a_type
)) {
1028 DEBUG(0, ("hpux_internal_aclsort: Duplicate entry: Type(hex): %x Id: %d\n",
1029 aclp
[i
].a_type
, aclp
[i
].a_id
));
1037 /* set the class obj permissions to the computed one. */
1039 int n_class_obj_index
= -1;
1041 for(i
=0;i
<acl_count
;i
++) {
1042 n_class_obj_perm
|= hpux_get_needed_class_perm((aclp
+i
));
1044 if(aclp
[i
].a_type
== CLASS_OBJ
)
1045 n_class_obj_index
= i
;
1047 aclp
[n_class_obj_index
].a_perm
= n_class_obj_perm
;
1055 * hpux_acl_call_present:
1057 * This checks if the POSIX ACL system call is defined
1058 * which basically corresponds to whether JFS 3.3 or
1059 * higher is installed. If acl() was called when it
1060 * isn't defined, it causes the process to core dump
1061 * so it is important to check this and avoid acl()
1062 * calls if it isn't there.
1065 static bool hpux_acl_call_present(void)
1068 shl_t handle
= NULL
;
1071 static bool already_checked
= False
;
1078 ret_val
= shl_findsym(&handle
, "acl", TYPE_PROCEDURE
, &value
);
1081 DEBUG(5, ("hpux_acl_call_present: shl_findsym() returned %d, errno = %d, error %s\n",
1082 ret_val
, errno
, strerror(errno
)));
1083 DEBUG(5,("hpux_acl_call_present: acl() system call is not present. Check if you have JFS 3.3 and above?\n"));
1088 DEBUG(10,("hpux_acl_call_present: acl() system call is present. We have JFS 3.3 or above \n"));
1090 already_checked
= True
;
1095 * runtime check for presence of aclsort library call.
1096 * same code as for acl call. if there are more of these,
1097 * a dispatcher function could be handy...
1100 static bool hpux_aclsort_call_present(void)
1102 shl_t handle
= NULL
;
1105 static bool already_checked
= False
;
1107 if (already_checked
) {
1112 ret_val
= shl_findsym(&handle
, "aclsort", TYPE_PROCEDURE
, &value
);
1114 DEBUG(5, ("hpux_aclsort_call_present: shl_findsym "
1115 "returned %d, errno = %d, error %s",
1116 ret_val
, errno
, strerror(errno
)));
1117 DEBUG(5, ("hpux_aclsort_call_present: "
1118 "aclsort() function not available.\n"));
1121 DEBUG(10,("hpux_aclsort_call_present: aclsort() function present.\n"));
1122 already_checked
= True
;
1128 * acl check function:
1129 * unused at the moment but could be used to get more
1130 * concrete error messages for debugging...
1131 * (acl sort just says that the acl is invalid...)
1133 static bool hpux_acl_check(HPUX_ACL_T hpux_acl
, int count
)
1138 check_rc
= aclcheck(hpux_acl
, count
, &check_which
);
1139 if (check_rc
!= 0) {
1140 DEBUG(10, ("acl is not valid:\n"));
1141 DEBUGADD(10, (" - return code: %d\n", check_rc
));
1142 DEBUGADD(10, (" - which: %d\n", check_which
));
1143 if (check_which
!= -1) {
1144 DEBUGADD(10, (" - invalid entry:\n"));
1145 DEBUGADD(10, (" * type: %d:\n",
1146 hpux_acl
[check_which
].a_type
));
1147 DEBUGADD(10, (" * id: %d\n",
1148 hpux_acl
[check_which
].a_id
));
1149 DEBUGADD(10, (" * perm: 0o%o\n",
1150 hpux_acl
[check_which
].a_perm
));
1158 /* VFS operations structure */
1160 static struct vfs_fn_pointers hpuxacl_fns
= {
1161 .sys_acl_get_fd_fn
= hpuxacl_sys_acl_get_fd
,
1162 .sys_acl_blob_get_fd_fn
= posix_sys_acl_blob_get_fd
,
1163 sys_acl_set_fd_fn
= hpuxacl_sys_acl_set_fd
,
1164 .sys_acl_delete_def_fd_fn
= hpuxacl_sys_acl_delete_def_fd
,
1168 NTSTATUS
vfs_hpuxacl_init(TALLOC_CTX
*ctx
)
1170 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "hpuxacl",