netapi: fix some warnings in netdomjoin-gui.
[Samba.git] / source / modules / vfs_solarisacl.c
blob7bdfe8465b1bbdba5380c6bc68ef17cf49980ef8
1 /*
2 Unix SMB/Netbios implementation.
3 VFS module to get and set Solaris 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 "includes.h"
24 /* typedef struct acl SOLARIS_ACE_T; */
25 typedef aclent_t SOLARIS_ACE_T;
26 typedef aclent_t *SOLARIS_ACL_T;
27 typedef int SOLARIS_ACL_TAG_T; /* the type of an ACL entry */
28 typedef o_mode_t SOLARIS_PERM_T;
30 /* for convenience: check if solaris acl entry is a default entry? */
31 #define _IS_DEFAULT(ace) ((ace).a_type & ACL_DEFAULT)
32 #define _IS_OF_TYPE(ace, type) ( \
33 (((type) == SMB_ACL_TYPE_ACCESS) && !_IS_DEFAULT(ace)) \
34 || \
35 (((type) == SMB_ACL_TYPE_DEFAULT) && _IS_DEFAULT(ace)) \
39 /* prototypes for private functions */
41 static SOLARIS_ACL_T solaris_acl_init(int count);
42 static bool smb_acl_to_solaris_acl(SMB_ACL_T smb_acl,
43 SOLARIS_ACL_T *solariacl, int *count,
44 SMB_ACL_TYPE_T type);
45 static SMB_ACL_T solaris_acl_to_smb_acl(SOLARIS_ACL_T solarisacl, int count,
46 SMB_ACL_TYPE_T type);
47 static SOLARIS_ACL_TAG_T smb_tag_to_solaris_tag(SMB_ACL_TAG_T smb_tag);
48 static SMB_ACL_TAG_T solaris_tag_to_smb_tag(SOLARIS_ACL_TAG_T solaris_tag);
49 static bool solaris_add_to_acl(SOLARIS_ACL_T *solaris_acl, int *count,
50 SOLARIS_ACL_T add_acl, int add_count, SMB_ACL_TYPE_T type);
51 static bool solaris_acl_get_file(const char *name, SOLARIS_ACL_T *solarisacl,
52 int *count);
53 static bool solaris_acl_get_fd(int fd, SOLARIS_ACL_T *solarisacl, int *count);
54 static bool solaris_acl_sort(SOLARIS_ACL_T acl, int count);
55 static SMB_ACL_PERM_T solaris_perm_to_smb_perm(const SOLARIS_PERM_T perm);
56 static SOLARIS_PERM_T smb_perm_to_solaris_perm(const SMB_ACL_PERM_T perm);
57 static bool solaris_acl_check(SOLARIS_ACL_T solaris_acl, int count);
60 /* public functions - the api */
62 SMB_ACL_T solarisacl_sys_acl_get_file(vfs_handle_struct *handle,
63 const char *path_p,
64 SMB_ACL_TYPE_T type)
66 SMB_ACL_T result = NULL;
67 int count;
68 SOLARIS_ACL_T solaris_acl = NULL;
70 DEBUG(10, ("solarisacl_sys_acl_get_file called for file '%s'.\n",
71 path_p));
73 if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
74 DEBUG(10, ("invalid SMB_ACL_TYPE given (%d)\n", type));
75 errno = EINVAL;
76 goto done;
79 DEBUGADD(10, ("getting %s acl\n",
80 ((type == SMB_ACL_TYPE_ACCESS) ? "access" : "default")));
82 if (!solaris_acl_get_file(path_p, &solaris_acl, &count)) {
83 goto done;
85 result = solaris_acl_to_smb_acl(solaris_acl, count, type);
86 if (result == NULL) {
87 DEBUG(10, ("conversion solaris_acl -> smb_acl failed (%s).\n",
88 strerror(errno)));
91 done:
92 DEBUG(10, ("solarisacl_sys_acl_get_file %s.\n",
93 ((result == NULL) ? "failed" : "succeeded" )));
94 SAFE_FREE(solaris_acl);
95 return result;
100 * get the access ACL of a file referred to by a fd
102 SMB_ACL_T solarisacl_sys_acl_get_fd(vfs_handle_struct *handle,
103 files_struct *fsp)
105 SMB_ACL_T result = NULL;
106 int count;
107 SOLARIS_ACL_T solaris_acl = NULL;
109 DEBUG(10, ("entering solarisacl_sys_acl_get_fd.\n"));
111 if (!solaris_acl_get_fd(fsp->fh->fd, &solaris_acl, &count)) {
112 goto done;
115 * The facl call returns both ACCESS and DEFAULT acls (as present).
116 * The posix acl_get_fd function returns only the
117 * access acl. So we need to filter this out here.
119 result = solaris_acl_to_smb_acl(solaris_acl, count,
120 SMB_ACL_TYPE_ACCESS);
121 if (result == NULL) {
122 DEBUG(10, ("conversion solaris_acl -> smb_acl failed (%s).\n",
123 strerror(errno)));
126 done:
127 DEBUG(10, ("solarisacl_sys_acl_get_fd %s.\n",
128 ((result == NULL) ? "failed" : "succeeded")));
129 SAFE_FREE(solaris_acl);
130 return result;
133 int solarisacl_sys_acl_set_file(vfs_handle_struct *handle,
134 const char *name,
135 SMB_ACL_TYPE_T type,
136 SMB_ACL_T theacl)
138 int ret = -1;
139 struct stat s;
140 SOLARIS_ACL_T solaris_acl = NULL;
141 int count;
143 DEBUG(10, ("solarisacl_sys_acl_set_file called for file '%s'\n",
144 name));
146 if ((type != SMB_ACL_TYPE_ACCESS) && (type != SMB_ACL_TYPE_DEFAULT)) {
147 errno = EINVAL;
148 DEBUG(10, ("invalid smb acl type given (%d).\n", type));
149 goto done;
151 DEBUGADD(10, ("setting %s acl\n",
152 ((type == SMB_ACL_TYPE_ACCESS) ? "access" : "default")));
154 if(!smb_acl_to_solaris_acl(theacl, &solaris_acl, &count, type)) {
155 DEBUG(10, ("conversion smb_acl -> solaris_acl failed (%s).\n",
156 strerror(errno)));
157 goto done;
161 * if the file is a directory, there is extra work to do:
162 * since the solaris acl call stores both the access acl and
163 * the default acl as provided, we have to get the acl part
164 * that has not been specified in "type" from the file first
165 * and concatenate it with the acl provided.
167 if (SMB_VFS_STAT(handle->conn, name, &s) != 0) {
168 DEBUG(10, ("Error in stat call: %s\n", strerror(errno)));
169 goto done;
171 if (S_ISDIR(s.st_mode)) {
172 SOLARIS_ACL_T other_acl;
173 int other_count;
174 SMB_ACL_TYPE_T other_type;
176 other_type = (type == SMB_ACL_TYPE_ACCESS)
177 ? SMB_ACL_TYPE_DEFAULT
178 : SMB_ACL_TYPE_ACCESS;
179 DEBUGADD(10, ("getting acl from filesystem\n"));
180 if (!solaris_acl_get_file(name, &other_acl, &other_count)) {
181 DEBUG(10, ("error getting acl from directory\n"));
182 goto done;
184 DEBUG(10, ("adding %s part of fs acl to given acl\n",
185 ((other_type == SMB_ACL_TYPE_ACCESS)
186 ? "access"
187 : "default")));
188 if (!solaris_add_to_acl(&solaris_acl, &count, other_acl,
189 other_count, other_type))
191 DEBUG(10, ("error adding other acl.\n"));
192 SAFE_FREE(other_acl);
193 goto done;
195 SAFE_FREE(other_acl);
197 else if (type != SMB_ACL_TYPE_ACCESS) {
198 errno = EINVAL;
199 goto done;
202 if (!solaris_acl_sort(solaris_acl, count)) {
203 DEBUG(10, ("resulting acl is not valid!\n"));
204 goto done;
207 ret = acl(name, SETACL, count, solaris_acl);
209 done:
210 DEBUG(10, ("solarisacl_sys_acl_set_file %s.\n",
211 ((ret != 0) ? "failed" : "succeeded")));
212 SAFE_FREE(solaris_acl);
213 return ret;
217 * set the access ACL on the file referred to by a fd
219 int solarisacl_sys_acl_set_fd(vfs_handle_struct *handle,
220 files_struct *fsp,
221 SMB_ACL_T theacl)
223 SOLARIS_ACL_T solaris_acl = NULL;
224 SOLARIS_ACL_T default_acl = NULL;
225 int count, default_count;
226 int ret = -1;
228 DEBUG(10, ("entering solarisacl_sys_acl_set_fd\n"));
231 * the posix acl_set_fd call sets the access acl of the
232 * file referred to by fd. the solaris facl-SETACL call
233 * sets the access and default acl as provided, so we
234 * have to retrieve the default acl of the file and
235 * concatenate it with the access acl provided.
237 if (!smb_acl_to_solaris_acl(theacl, &solaris_acl, &count,
238 SMB_ACL_TYPE_ACCESS))
240 DEBUG(10, ("conversion smb_acl -> solaris_acl failed (%s).\n",
241 strerror(errno)));
242 goto done;
244 if (!solaris_acl_get_fd(fsp->fh->fd, &default_acl, &default_count)) {
245 DEBUG(10, ("error getting (default) acl from fd\n"));
246 goto done;
248 if (!solaris_add_to_acl(&solaris_acl, &count,
249 default_acl, default_count,
250 SMB_ACL_TYPE_DEFAULT))
252 DEBUG(10, ("error adding default acl to solaris acl\n"));
253 goto done;
255 if (!solaris_acl_sort(solaris_acl, count)) {
256 DEBUG(10, ("resulting acl is not valid!\n"));
257 goto done;
260 ret = facl(fsp->fh->fd, SETACL, count, solaris_acl);
261 if (ret != 0) {
262 DEBUG(10, ("call of facl failed (%s).\n", strerror(errno)));
265 done:
266 DEBUG(10, ("solarisacl_sys_acl_set_fd %s.\n",
267 ((ret == 0) ? "succeeded" : "failed" )));
268 SAFE_FREE(solaris_acl);
269 SAFE_FREE(default_acl);
270 return ret;
274 * delete the default ACL of a directory
276 * This is achieved by fetching the access ACL and rewriting it
277 * directly, via the solaris system call: the SETACL call on
278 * directories writes both the access and the default ACL as provided.
280 * XXX: posix acl_delete_def_file returns an error if
281 * the file referred to by path is not a directory.
282 * this function does not complain but the actions
283 * have no effect on a file other than a directory.
284 * But sys_acl_delete_default_file is only called in
285 * smbd/posixacls.c after having checked that the file
286 * is a directory, anyways. So implementing the extra
287 * check is considered unnecessary. --- Agreed? XXX
289 int solarisacl_sys_acl_delete_def_file(vfs_handle_struct *handle,
290 const char *path)
292 SMB_ACL_T smb_acl;
293 int ret = -1;
294 SOLARIS_ACL_T solaris_acl = NULL;
295 int count;
297 DEBUG(10, ("entering solarisacl_sys_acl_delete_def_file.\n"));
299 smb_acl = solarisacl_sys_acl_get_file(handle, path,
300 SMB_ACL_TYPE_ACCESS);
301 if (smb_acl == NULL) {
302 DEBUG(10, ("getting file acl failed!\n"));
303 goto done;
305 if (!smb_acl_to_solaris_acl(smb_acl, &solaris_acl, &count,
306 SMB_ACL_TYPE_ACCESS))
308 DEBUG(10, ("conversion smb_acl -> solaris_acl failed.\n"));
309 goto done;
311 if (!solaris_acl_sort(solaris_acl, count)) {
312 DEBUG(10, ("resulting acl is not valid!\n"));
313 goto done;
315 ret = acl(path, SETACL, count, solaris_acl);
316 if (ret != 0) {
317 DEBUG(10, ("settinge file acl failed!\n"));
320 done:
321 DEBUG(10, ("solarisacl_sys_acl_delete_def_file %s.\n",
322 ((ret != 0) ? "failed" : "succeeded" )));
323 SAFE_FREE(smb_acl);
324 return ret;
328 /* private functions */
330 static SOLARIS_ACL_T solaris_acl_init(int count)
332 SOLARIS_ACL_T solaris_acl =
333 (SOLARIS_ACL_T)SMB_MALLOC(sizeof(aclent_t) * count);
334 if (solaris_acl == NULL) {
335 errno = ENOMEM;
337 return solaris_acl;
341 * Convert the SMB acl to the ACCESS or DEFAULT part of a
342 * solaris ACL, as desired.
344 static bool smb_acl_to_solaris_acl(SMB_ACL_T smb_acl,
345 SOLARIS_ACL_T *solaris_acl, int *count,
346 SMB_ACL_TYPE_T type)
348 bool ret = False;
349 int i;
350 int check_which, check_rc;
352 DEBUG(10, ("entering smb_acl_to_solaris_acl\n"));
354 *solaris_acl = NULL;
355 *count = 0;
357 for (i = 0; i < smb_acl->count; i++) {
358 const struct smb_acl_entry *smb_entry = &(smb_acl->acl[i]);
359 SOLARIS_ACE_T solaris_entry;
361 ZERO_STRUCT(solaris_entry);
363 solaris_entry.a_type = smb_tag_to_solaris_tag(smb_entry->a_type);
364 if (solaris_entry.a_type == 0) {
365 DEBUG(10, ("smb_tag to solaris_tag failed\n"));
366 goto fail;
368 switch(solaris_entry.a_type) {
369 case USER:
370 DEBUG(10, ("got tag type USER with uid %d\n",
371 smb_entry->uid));
372 solaris_entry.a_id = (uid_t)smb_entry->uid;
373 break;
374 case GROUP:
375 DEBUG(10, ("got tag type GROUP with gid %d\n",
376 smb_entry->gid));
377 solaris_entry.a_id = (uid_t)smb_entry->gid;
378 break;
379 default:
380 break;
382 if (type == SMB_ACL_TYPE_DEFAULT) {
383 DEBUG(10, ("adding default bit to solaris ace\n"));
384 solaris_entry.a_type |= ACL_DEFAULT;
387 solaris_entry.a_perm =
388 smb_perm_to_solaris_perm(smb_entry->a_perm);
389 DEBUG(10, ("assembled the following solaris ace:\n"));
390 DEBUGADD(10, (" - type: 0x%04x\n", solaris_entry.a_type));
391 DEBUGADD(10, (" - id: %d\n", solaris_entry.a_id));
392 DEBUGADD(10, (" - perm: o%o\n", solaris_entry.a_perm));
393 if (!solaris_add_to_acl(solaris_acl, count, &solaris_entry,
394 1, type))
396 DEBUG(10, ("error adding acl entry\n"));
397 goto fail;
399 DEBUG(10, ("count after adding: %d (i: %d)\n", *count, i));
400 DEBUG(10, ("test, if entry has been copied into acl:\n"));
401 DEBUGADD(10, (" - type: 0x%04x\n",
402 (*solaris_acl)[(*count)-1].a_type));
403 DEBUGADD(10, (" - id: %d\n",
404 (*solaris_acl)[(*count)-1].a_id));
405 DEBUGADD(10, (" - perm: o%o\n",
406 (*solaris_acl)[(*count)-1].a_perm));
409 ret = True;
410 goto done;
412 fail:
413 SAFE_FREE(*solaris_acl);
414 done:
415 DEBUG(10, ("smb_acl_to_solaris_acl %s\n",
416 ((ret == True) ? "succeeded" : "failed")));
417 return ret;
421 * convert either the access or the default part of a
422 * soaris acl to the SMB_ACL format.
424 static SMB_ACL_T solaris_acl_to_smb_acl(SOLARIS_ACL_T solaris_acl, int count,
425 SMB_ACL_TYPE_T type)
427 SMB_ACL_T result;
428 int i;
430 if ((result = sys_acl_init(0)) == NULL) {
431 DEBUG(10, ("error allocating memory for SMB_ACL\n"));
432 goto fail;
434 for (i = 0; i < count; i++) {
435 SMB_ACL_ENTRY_T smb_entry;
436 SMB_ACL_PERM_T smb_perm;
438 if (!_IS_OF_TYPE(solaris_acl[i], type)) {
439 continue;
441 result = SMB_REALLOC(result,
442 sizeof(struct smb_acl_t) +
443 (sizeof(struct smb_acl_entry) *
444 (result->count + 1)));
445 if (result == NULL) {
446 DEBUG(10, ("error reallocating memory for SMB_ACL\n"));
447 goto fail;
449 smb_entry = &result->acl[result->count];
450 if (sys_acl_set_tag_type(smb_entry,
451 solaris_tag_to_smb_tag(solaris_acl[i].a_type)) != 0)
453 DEBUG(10, ("invalid tag type given: 0x%04x\n",
454 solaris_acl[i].a_type));
455 goto fail;
457 /* intentionally not checking return code here: */
458 sys_acl_set_qualifier(smb_entry, (void *)&solaris_acl[i].a_id);
459 smb_perm = solaris_perm_to_smb_perm(solaris_acl[i].a_perm);
460 if (sys_acl_set_permset(smb_entry, &smb_perm) != 0) {
461 DEBUG(10, ("invalid permset given: %d\n",
462 solaris_acl[i].a_perm));
463 goto fail;
465 result->count += 1;
467 goto done;
469 fail:
470 SAFE_FREE(result);
471 done:
472 DEBUG(10, ("solaris_acl_to_smb_acl %s\n",
473 ((result == NULL) ? "failed" : "succeeded")));
474 return result;
479 static SOLARIS_ACL_TAG_T smb_tag_to_solaris_tag(SMB_ACL_TAG_T smb_tag)
481 SOLARIS_ACL_TAG_T solaris_tag = 0;
483 DEBUG(10, ("smb_tag_to_solaris_tag\n"));
484 DEBUGADD(10, (" --> got smb tag 0x%04x\n", smb_tag));
486 switch (smb_tag) {
487 case SMB_ACL_USER:
488 solaris_tag = USER;
489 break;
490 case SMB_ACL_USER_OBJ:
491 solaris_tag = USER_OBJ;
492 break;
493 case SMB_ACL_GROUP:
494 solaris_tag = GROUP;
495 break;
496 case SMB_ACL_GROUP_OBJ:
497 solaris_tag = GROUP_OBJ;
498 break;
499 case SMB_ACL_OTHER:
500 solaris_tag = OTHER_OBJ;
501 break;
502 case SMB_ACL_MASK:
503 solaris_tag = CLASS_OBJ;
504 break;
505 default:
506 DEBUGADD(10, (" !!! unknown smb tag type 0x%04x\n", smb_tag));
507 break;
510 DEBUGADD(10, (" --> determined solaris tag 0x%04x\n", solaris_tag));
512 return solaris_tag;
515 static SMB_ACL_TAG_T solaris_tag_to_smb_tag(SOLARIS_ACL_TAG_T solaris_tag)
517 SMB_ACL_TAG_T smb_tag = 0;
519 DEBUG(10, ("solaris_tag_to_smb_tag:\n"));
520 DEBUGADD(10, (" --> got solaris tag 0x%04x\n", solaris_tag));
522 solaris_tag &= ~ACL_DEFAULT;
524 switch (solaris_tag) {
525 case USER:
526 smb_tag = SMB_ACL_USER;
527 break;
528 case USER_OBJ:
529 smb_tag = SMB_ACL_USER_OBJ;
530 break;
531 case GROUP:
532 smb_tag = SMB_ACL_GROUP;
533 break;
534 case GROUP_OBJ:
535 smb_tag = SMB_ACL_GROUP_OBJ;
536 break;
537 case OTHER_OBJ:
538 smb_tag = SMB_ACL_OTHER;
539 break;
540 case CLASS_OBJ:
541 smb_tag = SMB_ACL_MASK;
542 break;
543 default:
544 DEBUGADD(10, (" !!! unknown solaris tag type: 0x%04x\n",
545 solaris_tag));
546 break;
549 DEBUGADD(10, (" --> determined smb tag 0x%04x\n", smb_tag));
551 return smb_tag;
555 static SMB_ACL_PERM_T solaris_perm_to_smb_perm(const SOLARIS_PERM_T perm)
557 SMB_ACL_PERM_T smb_perm = 0;
558 smb_perm |= ((perm & SMB_ACL_READ) ? SMB_ACL_READ : 0);
559 smb_perm |= ((perm & SMB_ACL_WRITE) ? SMB_ACL_WRITE : 0);
560 smb_perm |= ((perm & SMB_ACL_EXECUTE) ? SMB_ACL_EXECUTE : 0);
561 return smb_perm;
565 static SOLARIS_PERM_T smb_perm_to_solaris_perm(const SMB_ACL_PERM_T perm)
567 SOLARIS_PERM_T solaris_perm = 0;
568 solaris_perm |= ((perm & SMB_ACL_READ) ? SMB_ACL_READ : 0);
569 solaris_perm |= ((perm & SMB_ACL_WRITE) ? SMB_ACL_WRITE : 0);
570 solaris_perm |= ((perm & SMB_ACL_EXECUTE) ? SMB_ACL_EXECUTE : 0);
571 return solaris_perm;
575 static bool solaris_acl_get_file(const char *name, SOLARIS_ACL_T *solaris_acl,
576 int *count)
578 bool result = False;
580 DEBUG(10, ("solaris_acl_get_file called for file '%s'\n", name));
583 * The original code tries some INITIAL_ACL_SIZE
584 * and only did the GETACLCNT call upon failure
585 * (for performance reasons).
586 * For the sake of simplicity, I skip this for now.
588 *count = acl(name, GETACLCNT, 0, NULL);
589 if (*count < 0) {
590 DEBUG(10, ("acl GETACLCNT failed: %s\n", strerror(errno)));
591 goto done;
593 *solaris_acl = solaris_acl_init(*count);
594 if (*solaris_acl == NULL) {
595 DEBUG(10, ("error allocating memory for solaris acl...\n"));
596 goto done;
598 *count = acl(name, GETACL, *count, *solaris_acl);
599 if (*count < 0) {
600 DEBUG(10, ("acl GETACL failed: %s\n", strerror(errno)));
601 goto done;
603 result = True;
605 done:
606 DEBUG(10, ("solaris_acl_get_file %s.\n",
607 ((result == True) ? "succeeded" : "failed" )));
608 return result;
612 static bool solaris_acl_get_fd(int fd, SOLARIS_ACL_T *solaris_acl, int *count)
614 bool ret = False;
616 DEBUG(10, ("entering solaris_acl_get_fd\n"));
619 * see solaris_acl_get_file for comment about omission
620 * of INITIAL_ACL_SIZE...
622 *count = facl(fd, GETACLCNT, 0, NULL);
623 if (*count < 0) {
624 DEBUG(10, ("facl GETACLCNT failed: %s\n", strerror(errno)));
625 goto done;
627 *solaris_acl = solaris_acl_init(*count);
628 if (*solaris_acl == NULL) {
629 DEBUG(10, ("error allocating memory for solaris acl...\n"));
630 goto done;
632 *count = facl(fd, GETACL, *count, *solaris_acl);
633 if (*count < 0) {
634 DEBUG(10, ("facl GETACL failed: %s\n", strerror(errno)));
635 goto done;
637 ret = True;
639 done:
640 DEBUG(10, ("solaris_acl_get_fd %s\n",
641 ((ret == True) ? "succeeded" : "failed")));
642 return ret;
648 * Add entries to a solaris ACL.
650 * Entries are directly added to the solarisacl parameter.
651 * if memory allocation fails, this may result in solarisacl
652 * being NULL. if the resulting acl is to be checked and is
653 * not valid, it is kept in solarisacl but False is returned.
655 * The type of ACEs (access/default) to be added to the ACL can
656 * be selected via the type parameter.
657 * I use the SMB_ACL_TYPE_T type here. Since SMB_ACL_TYPE_ACCESS
658 * is defined as "0", this means that one can only add either
659 * access or default ACEs, not both at the same time. If it
660 * should become necessary to add all of an ACL, one would have
661 * to replace this parameter by another type.
663 static bool solaris_add_to_acl(SOLARIS_ACL_T *solaris_acl, int *count,
664 SOLARIS_ACL_T add_acl, int add_count,
665 SMB_ACL_TYPE_T type)
667 int i;
669 if ((type != SMB_ACL_TYPE_ACCESS) && (type != SMB_ACL_TYPE_DEFAULT))
671 DEBUG(10, ("invalid acl type given: %d\n", type));
672 errno = EINVAL;
673 return False;
675 for (i = 0; i < add_count; i++) {
676 if (!_IS_OF_TYPE(add_acl[i], type)) {
677 continue;
679 ADD_TO_ARRAY(NULL, SOLARIS_ACE_T, add_acl[i],
680 solaris_acl, count);
681 if (solaris_acl == NULL) {
682 DEBUG(10, ("error enlarging acl.\n"));
683 errno = ENOMEM;
684 return False;
687 return True;
692 * sort the ACL and check it for validity
694 * [original comment from lib/sysacls.c:]
696 * if it's a minimal ACL with only 4 entries then we
697 * need to recalculate the mask permissions to make
698 * sure that they are the same as the GROUP_OBJ
699 * permissions as required by the UnixWare acl() system call.
701 * (note: since POSIX allows minimal ACLs which only contain
702 * 3 entries - ie there is no mask entry - we should, in theory,
703 * check for this and add a mask entry if necessary - however
704 * we "know" that the caller of this interface always specifies
705 * a mask, so in practice "this never happens" (tm) - if it *does*
706 * happen aclsort() will fail and return an error and someone will
707 * have to fix it...)
709 static bool solaris_acl_sort(SOLARIS_ACL_T solaris_acl, int count)
711 int fixmask = (count <= 4);
713 if (aclsort(count, fixmask, solaris_acl) != 0) {
714 errno = EINVAL;
715 return False;
717 return True;
721 * acl check function:
722 * unused at the moment but could be used to get more
723 * concrete error messages for debugging...
724 * (acl sort just says that the acl is invalid...)
726 static bool solaris_acl_check(SOLARIS_ACL_T solaris_acl, int count)
728 int check_rc;
729 int check_which;
731 check_rc = aclcheck(solaris_acl, count, &check_which);
732 if (check_rc != 0) {
733 DEBUG(10, ("acl is not valid:\n"));
734 DEBUGADD(10, (" - return code: %d\n", check_rc));
735 DEBUGADD(10, (" - which: %d\n", check_which));
736 if (check_which != -1) {
737 DEBUGADD(10, (" - invalid entry:\n"));
738 DEBUGADD(10, (" * type: %d:\n",
739 solaris_acl[check_which].a_type));
740 DEBUGADD(10, (" * id: %d\n",
741 solaris_acl[check_which].a_id));
742 DEBUGADD(10, (" * perm: 0o%o\n",
743 solaris_acl[check_which].a_perm));
745 return False;
747 return True;
751 /* VFS operations structure */
753 static vfs_op_tuple solarisacl_op_tuples[] = {
754 /* Disk operations */
755 {SMB_VFS_OP(solarisacl_sys_acl_get_file),
756 SMB_VFS_OP_SYS_ACL_GET_FILE,
757 SMB_VFS_LAYER_TRANSPARENT},
759 {SMB_VFS_OP(solarisacl_sys_acl_get_fd),
760 SMB_VFS_OP_SYS_ACL_GET_FD,
761 SMB_VFS_LAYER_TRANSPARENT},
763 {SMB_VFS_OP(solarisacl_sys_acl_set_file),
764 SMB_VFS_OP_SYS_ACL_SET_FILE,
765 SMB_VFS_LAYER_TRANSPARENT},
767 {SMB_VFS_OP(solarisacl_sys_acl_set_fd),
768 SMB_VFS_OP_SYS_ACL_SET_FD,
769 SMB_VFS_LAYER_TRANSPARENT},
771 {SMB_VFS_OP(solarisacl_sys_acl_delete_def_file),
772 SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
773 SMB_VFS_LAYER_TRANSPARENT},
775 {SMB_VFS_OP(NULL),
776 SMB_VFS_OP_NOOP,
777 SMB_VFS_LAYER_NOOP}
780 NTSTATUS vfs_solarisacl_init(void);
781 NTSTATUS vfs_solarisacl_init(void)
783 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "solarisacl",
784 solarisacl_op_tuples);
787 /* ENTE */