vfs_btrfs: add snapshot create/delete calls
[Samba.git] / source3 / modules / vfs_solarisacl.c
blob9b3c4f60a56858dba0fcf0481020a7786ffde75b
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"
22 #include "system/filesys.h"
23 #include "smbd/smbd.h"
24 #include "modules/vfs_solarisacl.h"
26 /* typedef struct acl SOLARIS_ACE_T; */
27 typedef aclent_t SOLARIS_ACE_T;
28 typedef aclent_t *SOLARIS_ACL_T;
29 typedef int SOLARIS_ACL_TAG_T; /* the type of an ACL entry */
30 typedef o_mode_t SOLARIS_PERM_T;
32 /* for convenience: check if solaris acl entry is a default entry? */
33 #define _IS_DEFAULT(ace) ((ace).a_type & ACL_DEFAULT)
34 #define _IS_OF_TYPE(ace, type) ( \
35 (((type) == SMB_ACL_TYPE_ACCESS) && !_IS_DEFAULT(ace)) \
36 || \
37 (((type) == SMB_ACL_TYPE_DEFAULT) && _IS_DEFAULT(ace)) \
41 /* prototypes for private functions */
43 static SOLARIS_ACL_T solaris_acl_init(int count);
44 static bool smb_acl_to_solaris_acl(SMB_ACL_T smb_acl,
45 SOLARIS_ACL_T *solariacl, int *count,
46 SMB_ACL_TYPE_T type);
47 static SMB_ACL_T solaris_acl_to_smb_acl(SOLARIS_ACL_T solarisacl, int count,
48 SMB_ACL_TYPE_T type, TALLOC_CTX *mem_ctx);
49 static SOLARIS_ACL_TAG_T smb_tag_to_solaris_tag(SMB_ACL_TAG_T smb_tag);
50 static SMB_ACL_TAG_T solaris_tag_to_smb_tag(SOLARIS_ACL_TAG_T solaris_tag);
51 static bool solaris_add_to_acl(SOLARIS_ACL_T *solaris_acl, int *count,
52 SOLARIS_ACL_T add_acl, int add_count, SMB_ACL_TYPE_T type);
53 static bool solaris_acl_get_file(const char *name, SOLARIS_ACL_T *solarisacl,
54 int *count);
55 static bool solaris_acl_get_fd(int fd, SOLARIS_ACL_T *solarisacl, int *count);
56 static bool solaris_acl_sort(SOLARIS_ACL_T theacl, int count);
57 static SMB_ACL_PERM_T solaris_perm_to_smb_perm(const SOLARIS_PERM_T perm);
58 static SOLARIS_PERM_T smb_perm_to_solaris_perm(const SMB_ACL_PERM_T perm);
59 #if 0
60 static bool solaris_acl_check(SOLARIS_ACL_T solaris_acl, int count);
61 #endif
63 /* public functions - the api */
65 SMB_ACL_T solarisacl_sys_acl_get_file(vfs_handle_struct *handle,
66 const char *path_p,
67 SMB_ACL_TYPE_T type, TALLOC_CTX *mem_ctx)
69 SMB_ACL_T result = NULL;
70 int count;
71 SOLARIS_ACL_T solaris_acl = NULL;
73 DEBUG(10, ("solarisacl_sys_acl_get_file called for file '%s'.\n",
74 path_p));
76 if (type != SMB_ACL_TYPE_ACCESS && type != SMB_ACL_TYPE_DEFAULT) {
77 DEBUG(10, ("invalid SMB_ACL_TYPE given (%d)\n", type));
78 errno = EINVAL;
79 goto done;
82 DEBUGADD(10, ("getting %s acl\n",
83 ((type == SMB_ACL_TYPE_ACCESS) ? "access" : "default")));
85 if (!solaris_acl_get_file(path_p, &solaris_acl, &count)) {
86 goto done;
88 result = solaris_acl_to_smb_acl(solaris_acl, count, type, mem_ctx);
89 if (result == NULL) {
90 DEBUG(10, ("conversion solaris_acl -> smb_acl failed (%s).\n",
91 strerror(errno)));
94 done:
95 DEBUG(10, ("solarisacl_sys_acl_get_file %s.\n",
96 ((result == NULL) ? "failed" : "succeeded" )));
97 SAFE_FREE(solaris_acl);
98 return result;
103 * get the access ACL of a file referred to by a fd
105 SMB_ACL_T solarisacl_sys_acl_get_fd(vfs_handle_struct *handle,
106 files_struct *fsp, TALLOC_CTX *mem_ctx)
108 SMB_ACL_T result = NULL;
109 int count;
110 SOLARIS_ACL_T solaris_acl = NULL;
112 DEBUG(10, ("entering solarisacl_sys_acl_get_fd.\n"));
114 if (!solaris_acl_get_fd(fsp->fh->fd, &solaris_acl, &count)) {
115 goto done;
118 * The facl call returns both ACCESS and DEFAULT acls (as present).
119 * The posix acl_get_fd function returns only the
120 * access acl. So we need to filter this out here.
122 result = solaris_acl_to_smb_acl(solaris_acl, count,
123 SMB_ACL_TYPE_ACCESS, mem_ctx);
124 if (result == NULL) {
125 DEBUG(10, ("conversion solaris_acl -> smb_acl failed (%s).\n",
126 strerror(errno)));
129 done:
130 DEBUG(10, ("solarisacl_sys_acl_get_fd %s.\n",
131 ((result == NULL) ? "failed" : "succeeded")));
132 SAFE_FREE(solaris_acl);
133 return result;
136 int solarisacl_sys_acl_set_file(vfs_handle_struct *handle,
137 const char *name,
138 SMB_ACL_TYPE_T type,
139 SMB_ACL_T theacl)
141 int ret = -1;
142 struct stat_ex s;
143 SOLARIS_ACL_T solaris_acl = NULL;
144 int count;
146 DEBUG(10, ("solarisacl_sys_acl_set_file called for file '%s'\n",
147 name));
149 if ((type != SMB_ACL_TYPE_ACCESS) && (type != SMB_ACL_TYPE_DEFAULT)) {
150 errno = EINVAL;
151 DEBUG(10, ("invalid smb acl type given (%d).\n", type));
152 goto done;
154 DEBUGADD(10, ("setting %s acl\n",
155 ((type == SMB_ACL_TYPE_ACCESS) ? "access" : "default")));
157 if(!smb_acl_to_solaris_acl(theacl, &solaris_acl, &count, type)) {
158 DEBUG(10, ("conversion smb_acl -> solaris_acl failed (%s).\n",
159 strerror(errno)));
160 goto done;
164 * if the file is a directory, there is extra work to do:
165 * since the solaris acl call stores both the access acl and
166 * the default acl as provided, we have to get the acl part
167 * that has not been specified in "type" from the file first
168 * and concatenate it with the acl provided.
170 if (vfs_stat_smb_fname(handle->conn, name, &s) != 0) {
171 DEBUG(10, ("Error in stat call: %s\n", strerror(errno)));
172 goto done;
174 if (S_ISDIR(s.st_ex_mode)) {
175 SOLARIS_ACL_T other_acl;
176 int other_count;
177 SMB_ACL_TYPE_T other_type;
179 other_type = (type == SMB_ACL_TYPE_ACCESS)
180 ? SMB_ACL_TYPE_DEFAULT
181 : SMB_ACL_TYPE_ACCESS;
182 DEBUGADD(10, ("getting acl from filesystem\n"));
183 if (!solaris_acl_get_file(name, &other_acl, &other_count)) {
184 DEBUG(10, ("error getting acl from directory\n"));
185 goto done;
187 DEBUG(10, ("adding %s part of fs acl to given acl\n",
188 ((other_type == SMB_ACL_TYPE_ACCESS)
189 ? "access"
190 : "default")));
191 if (!solaris_add_to_acl(&solaris_acl, &count, other_acl,
192 other_count, other_type))
194 DEBUG(10, ("error adding other acl.\n"));
195 SAFE_FREE(other_acl);
196 goto done;
198 SAFE_FREE(other_acl);
200 else if (type != SMB_ACL_TYPE_ACCESS) {
201 errno = EINVAL;
202 goto done;
205 if (!solaris_acl_sort(solaris_acl, count)) {
206 DEBUG(10, ("resulting acl is not valid!\n"));
207 goto done;
210 ret = acl(name, SETACL, count, solaris_acl);
212 done:
213 DEBUG(10, ("solarisacl_sys_acl_set_file %s.\n",
214 ((ret != 0) ? "failed" : "succeeded")));
215 SAFE_FREE(solaris_acl);
216 return ret;
220 * set the access ACL on the file referred to by a fd
222 int solarisacl_sys_acl_set_fd(vfs_handle_struct *handle,
223 files_struct *fsp,
224 SMB_ACL_T theacl)
226 SOLARIS_ACL_T solaris_acl = NULL;
227 SOLARIS_ACL_T default_acl = NULL;
228 int count, default_count;
229 int ret = -1;
231 DEBUG(10, ("entering solarisacl_sys_acl_set_fd\n"));
234 * the posix acl_set_fd call sets the access acl of the
235 * file referred to by fd. the solaris facl-SETACL call
236 * sets the access and default acl as provided, so we
237 * have to retrieve the default acl of the file and
238 * concatenate it with the access acl provided.
240 if (!smb_acl_to_solaris_acl(theacl, &solaris_acl, &count,
241 SMB_ACL_TYPE_ACCESS))
243 DEBUG(10, ("conversion smb_acl -> solaris_acl failed (%s).\n",
244 strerror(errno)));
245 goto done;
247 if (!solaris_acl_get_fd(fsp->fh->fd, &default_acl, &default_count)) {
248 DEBUG(10, ("error getting (default) acl from fd\n"));
249 goto done;
251 if (!solaris_add_to_acl(&solaris_acl, &count,
252 default_acl, default_count,
253 SMB_ACL_TYPE_DEFAULT))
255 DEBUG(10, ("error adding default acl to solaris acl\n"));
256 goto done;
258 if (!solaris_acl_sort(solaris_acl, count)) {
259 DEBUG(10, ("resulting acl is not valid!\n"));
260 goto done;
263 ret = facl(fsp->fh->fd, SETACL, count, solaris_acl);
264 if (ret != 0) {
265 DEBUG(10, ("call of facl failed (%s).\n", strerror(errno)));
268 done:
269 DEBUG(10, ("solarisacl_sys_acl_set_fd %s.\n",
270 ((ret == 0) ? "succeeded" : "failed" )));
271 SAFE_FREE(solaris_acl);
272 SAFE_FREE(default_acl);
273 return ret;
277 * delete the default ACL of a directory
279 * This is achieved by fetching the access ACL and rewriting it
280 * directly, via the solaris system call: the SETACL call on
281 * directories writes both the access and the default ACL as provided.
283 * XXX: posix acl_delete_def_file returns an error if
284 * the file referred to by path is not a directory.
285 * this function does not complain but the actions
286 * have no effect on a file other than a directory.
287 * But sys_acl_delete_default_file is only called in
288 * smbd/posixacls.c after having checked that the file
289 * is a directory, anyways. So implementing the extra
290 * check is considered unnecessary. --- Agreed? XXX
292 int solarisacl_sys_acl_delete_def_file(vfs_handle_struct *handle,
293 const char *path)
295 SMB_ACL_T smb_acl;
296 int ret = -1;
297 SOLARIS_ACL_T solaris_acl = NULL;
298 int count;
300 DEBUG(10, ("entering solarisacl_sys_acl_delete_def_file.\n"));
302 smb_acl = solarisacl_sys_acl_get_file(handle, path,
303 SMB_ACL_TYPE_ACCESS, talloc_tos());
304 if (smb_acl == NULL) {
305 DEBUG(10, ("getting file acl failed!\n"));
306 goto done;
308 if (!smb_acl_to_solaris_acl(smb_acl, &solaris_acl, &count,
309 SMB_ACL_TYPE_ACCESS))
311 DEBUG(10, ("conversion smb_acl -> solaris_acl failed.\n"));
312 goto done;
314 if (!solaris_acl_sort(solaris_acl, count)) {
315 DEBUG(10, ("resulting acl is not valid!\n"));
316 goto done;
318 ret = acl(path, SETACL, count, solaris_acl);
319 if (ret != 0) {
320 DEBUG(10, ("settinge file acl failed!\n"));
323 done:
324 DEBUG(10, ("solarisacl_sys_acl_delete_def_file %s.\n",
325 ((ret != 0) ? "failed" : "succeeded" )));
326 TALLOC_FREE(smb_acl);
327 return ret;
331 /* private functions */
333 static SOLARIS_ACL_T solaris_acl_init(int count)
335 SOLARIS_ACL_T solaris_acl =
336 (SOLARIS_ACL_T)SMB_MALLOC(sizeof(aclent_t) * count);
337 if (solaris_acl == NULL) {
338 errno = ENOMEM;
340 return solaris_acl;
344 * Convert the SMB acl to the ACCESS or DEFAULT part of a
345 * solaris ACL, as desired.
347 static bool smb_acl_to_solaris_acl(SMB_ACL_T smb_acl,
348 SOLARIS_ACL_T *solaris_acl, int *count,
349 SMB_ACL_TYPE_T type)
351 bool ret = False;
352 int i;
354 DEBUG(10, ("entering smb_acl_to_solaris_acl\n"));
356 *solaris_acl = NULL;
357 *count = 0;
359 for (i = 0; i < smb_acl->count; i++) {
360 const struct smb_acl_entry *smb_entry = &(smb_acl->acl[i]);
361 SOLARIS_ACE_T solaris_entry;
363 ZERO_STRUCT(solaris_entry);
365 solaris_entry.a_type = smb_tag_to_solaris_tag(smb_entry->a_type);
366 if (solaris_entry.a_type == 0) {
367 DEBUG(10, ("smb_tag to solaris_tag failed\n"));
368 goto fail;
370 switch(solaris_entry.a_type) {
371 case USER:
372 DEBUG(10, ("got tag type USER with uid %u\n",
373 (unsigned int)smb_entry->info.user.uid));
374 solaris_entry.a_id = (uid_t)smb_entry->info.user.uid;
375 break;
376 case GROUP:
377 DEBUG(10, ("got tag type GROUP with gid %u\n",
378 (unsigned int)smb_entry->info.group.gid));
379 solaris_entry.a_id = (uid_t)smb_entry->info.group.gid;
380 break;
381 default:
382 break;
384 if (type == SMB_ACL_TYPE_DEFAULT) {
385 DEBUG(10, ("adding default bit to solaris ace\n"));
386 solaris_entry.a_type |= ACL_DEFAULT;
389 solaris_entry.a_perm =
390 smb_perm_to_solaris_perm(smb_entry->a_perm);
391 DEBUG(10, ("assembled the following solaris ace:\n"));
392 DEBUGADD(10, (" - type: 0x%04x\n", solaris_entry.a_type));
393 DEBUGADD(10, (" - id: %u\n", (unsigned int)solaris_entry.a_id));
394 DEBUGADD(10, (" - perm: o%o\n", solaris_entry.a_perm));
395 if (!solaris_add_to_acl(solaris_acl, count, &solaris_entry,
396 1, type))
398 DEBUG(10, ("error adding acl entry\n"));
399 goto fail;
401 DEBUG(10, ("count after adding: %d (i: %d)\n", *count, i));
402 DEBUG(10, ("test, if entry has been copied into acl:\n"));
403 DEBUGADD(10, (" - type: 0x%04x\n",
404 (*solaris_acl)[(*count)-1].a_type));
405 DEBUGADD(10, (" - id: %u\n",
406 (unsigned int)(*solaris_acl)[(*count)-1].a_id));
407 DEBUGADD(10, (" - perm: o%o\n",
408 (*solaris_acl)[(*count)-1].a_perm));
411 ret = True;
412 goto done;
414 fail:
415 SAFE_FREE(*solaris_acl);
416 done:
417 DEBUG(10, ("smb_acl_to_solaris_acl %s\n",
418 ((ret == True) ? "succeeded" : "failed")));
419 return ret;
423 * convert either the access or the default part of a
424 * soaris acl to the SMB_ACL format.
426 static SMB_ACL_T solaris_acl_to_smb_acl(SOLARIS_ACL_T solaris_acl, int count,
427 SMB_ACL_TYPE_T type, TALLOC_CTX *mem_ctx)
429 SMB_ACL_T result;
430 int i;
432 if ((result = sys_acl_init(mem_ctx)) == NULL) {
433 DEBUG(10, ("error allocating memory for SMB_ACL\n"));
434 goto fail;
436 for (i = 0; i < count; i++) {
437 SMB_ACL_ENTRY_T smb_entry;
438 SMB_ACL_PERM_T smb_perm;
440 if (!_IS_OF_TYPE(solaris_acl[i], type)) {
441 continue;
443 result->acl = talloc_realloc(result, result->acl, struct smb_acl_entry, result->count + 1);
444 if (result->acl == NULL) {
445 DEBUG(10, ("error reallocating memory for SMB_ACL\n"));
446 goto fail;
448 smb_entry = &result->acl[result->count];
449 if (sys_acl_set_tag_type(smb_entry,
450 solaris_tag_to_smb_tag(solaris_acl[i].a_type)) != 0)
452 DEBUG(10, ("invalid tag type given: 0x%04x\n",
453 solaris_acl[i].a_type));
454 goto fail;
456 /* intentionally not checking return code here: */
457 sys_acl_set_qualifier(smb_entry, (void *)&solaris_acl[i].a_id);
458 smb_perm = solaris_perm_to_smb_perm(solaris_acl[i].a_perm);
459 if (sys_acl_set_permset(smb_entry, &smb_perm) != 0) {
460 DEBUG(10, ("invalid permset given: %d\n",
461 solaris_acl[i].a_perm));
462 goto fail;
464 result->count += 1;
466 goto done;
468 fail:
469 TALLOC_FREE(result);
470 done:
471 DEBUG(10, ("solaris_acl_to_smb_acl %s\n",
472 ((result == NULL) ? "failed" : "succeeded")));
473 return result;
478 static SOLARIS_ACL_TAG_T smb_tag_to_solaris_tag(SMB_ACL_TAG_T smb_tag)
480 SOLARIS_ACL_TAG_T solaris_tag = 0;
482 DEBUG(10, ("smb_tag_to_solaris_tag\n"));
483 DEBUGADD(10, (" --> got smb tag 0x%04x\n", smb_tag));
485 switch (smb_tag) {
486 case SMB_ACL_USER:
487 solaris_tag = USER;
488 break;
489 case SMB_ACL_USER_OBJ:
490 solaris_tag = USER_OBJ;
491 break;
492 case SMB_ACL_GROUP:
493 solaris_tag = GROUP;
494 break;
495 case SMB_ACL_GROUP_OBJ:
496 solaris_tag = GROUP_OBJ;
497 break;
498 case SMB_ACL_OTHER:
499 solaris_tag = OTHER_OBJ;
500 break;
501 case SMB_ACL_MASK:
502 solaris_tag = CLASS_OBJ;
503 break;
504 default:
505 DEBUGADD(10, (" !!! unknown smb tag type 0x%04x\n", smb_tag));
506 break;
509 DEBUGADD(10, (" --> determined solaris tag 0x%04x\n", solaris_tag));
511 return solaris_tag;
514 static SMB_ACL_TAG_T solaris_tag_to_smb_tag(SOLARIS_ACL_TAG_T solaris_tag)
516 SMB_ACL_TAG_T smb_tag = 0;
518 DEBUG(10, ("solaris_tag_to_smb_tag:\n"));
519 DEBUGADD(10, (" --> got solaris tag 0x%04x\n", solaris_tag));
521 solaris_tag &= ~ACL_DEFAULT;
523 switch (solaris_tag) {
524 case USER:
525 smb_tag = SMB_ACL_USER;
526 break;
527 case USER_OBJ:
528 smb_tag = SMB_ACL_USER_OBJ;
529 break;
530 case GROUP:
531 smb_tag = SMB_ACL_GROUP;
532 break;
533 case GROUP_OBJ:
534 smb_tag = SMB_ACL_GROUP_OBJ;
535 break;
536 case OTHER_OBJ:
537 smb_tag = SMB_ACL_OTHER;
538 break;
539 case CLASS_OBJ:
540 smb_tag = SMB_ACL_MASK;
541 break;
542 default:
543 DEBUGADD(10, (" !!! unknown solaris tag type: 0x%04x\n",
544 solaris_tag));
545 break;
548 DEBUGADD(10, (" --> determined smb tag 0x%04x\n", smb_tag));
550 return smb_tag;
554 static SMB_ACL_PERM_T solaris_perm_to_smb_perm(const SOLARIS_PERM_T perm)
556 SMB_ACL_PERM_T smb_perm = 0;
557 smb_perm |= ((perm & SMB_ACL_READ) ? SMB_ACL_READ : 0);
558 smb_perm |= ((perm & SMB_ACL_WRITE) ? SMB_ACL_WRITE : 0);
559 smb_perm |= ((perm & SMB_ACL_EXECUTE) ? SMB_ACL_EXECUTE : 0);
560 return smb_perm;
564 static SOLARIS_PERM_T smb_perm_to_solaris_perm(const SMB_ACL_PERM_T perm)
566 SOLARIS_PERM_T solaris_perm = 0;
567 solaris_perm |= ((perm & SMB_ACL_READ) ? SMB_ACL_READ : 0);
568 solaris_perm |= ((perm & SMB_ACL_WRITE) ? SMB_ACL_WRITE : 0);
569 solaris_perm |= ((perm & SMB_ACL_EXECUTE) ? SMB_ACL_EXECUTE : 0);
570 return solaris_perm;
574 static bool solaris_acl_get_file(const char *name, SOLARIS_ACL_T *solaris_acl,
575 int *count)
577 bool result = False;
579 DEBUG(10, ("solaris_acl_get_file called for file '%s'\n", name));
582 * The original code tries some INITIAL_ACL_SIZE
583 * and only did the GETACLCNT call upon failure
584 * (for performance reasons).
585 * For the sake of simplicity, I skip this for now.
587 *count = acl(name, GETACLCNT, 0, NULL);
588 if (*count < 0) {
589 DEBUG(10, ("acl GETACLCNT failed: %s\n", strerror(errno)));
590 goto done;
592 *solaris_acl = solaris_acl_init(*count);
593 if (*solaris_acl == NULL) {
594 DEBUG(10, ("error allocating memory for solaris acl...\n"));
595 goto done;
597 *count = acl(name, GETACL, *count, *solaris_acl);
598 if (*count < 0) {
599 DEBUG(10, ("acl GETACL failed: %s\n", strerror(errno)));
600 goto done;
602 result = True;
604 done:
605 DEBUG(10, ("solaris_acl_get_file %s.\n",
606 ((result == True) ? "succeeded" : "failed" )));
607 return result;
611 static bool solaris_acl_get_fd(int fd, SOLARIS_ACL_T *solaris_acl, int *count)
613 bool ret = False;
615 DEBUG(10, ("entering solaris_acl_get_fd\n"));
618 * see solaris_acl_get_file for comment about omission
619 * of INITIAL_ACL_SIZE...
621 *count = facl(fd, GETACLCNT, 0, NULL);
622 if (*count < 0) {
623 DEBUG(10, ("facl GETACLCNT failed: %s\n", strerror(errno)));
624 goto done;
626 *solaris_acl = solaris_acl_init(*count);
627 if (*solaris_acl == NULL) {
628 DEBUG(10, ("error allocating memory for solaris acl...\n"));
629 goto done;
631 *count = facl(fd, GETACL, *count, *solaris_acl);
632 if (*count < 0) {
633 DEBUG(10, ("facl GETACL failed: %s\n", strerror(errno)));
634 goto done;
636 ret = True;
638 done:
639 DEBUG(10, ("solaris_acl_get_fd %s\n",
640 ((ret == True) ? "succeeded" : "failed")));
641 return ret;
647 * Add entries to a solaris ACL.
649 * Entries are directly added to the solarisacl parameter.
650 * if memory allocation fails, this may result in solarisacl
651 * being NULL. if the resulting acl is to be checked and is
652 * not valid, it is kept in solarisacl but False is returned.
654 * The type of ACEs (access/default) to be added to the ACL can
655 * be selected via the type parameter.
656 * I use the SMB_ACL_TYPE_T type here. Since SMB_ACL_TYPE_ACCESS
657 * is defined as "0", this means that one can only add either
658 * access or default ACEs, not both at the same time. If it
659 * should become necessary to add all of an ACL, one would have
660 * to replace this parameter by another type.
662 static bool solaris_add_to_acl(SOLARIS_ACL_T *solaris_acl, int *count,
663 SOLARIS_ACL_T add_acl, int add_count,
664 SMB_ACL_TYPE_T type)
666 int i;
668 if ((type != SMB_ACL_TYPE_ACCESS) && (type != SMB_ACL_TYPE_DEFAULT))
670 DEBUG(10, ("invalid acl type given: %d\n", type));
671 errno = EINVAL;
672 return False;
674 for (i = 0; i < add_count; i++) {
675 if (!_IS_OF_TYPE(add_acl[i], type)) {
676 continue;
678 ADD_TO_ARRAY(NULL, SOLARIS_ACE_T, add_acl[i],
679 solaris_acl, count);
680 if (solaris_acl == NULL) {
681 DEBUG(10, ("error enlarging acl.\n"));
682 errno = ENOMEM;
683 return False;
686 return True;
691 * sort the ACL and check it for validity
693 * [original comment from lib/sysacls.c:]
695 * if it's a minimal ACL with only 4 entries then we
696 * need to recalculate the mask permissions to make
697 * sure that they are the same as the GROUP_OBJ
698 * permissions as required by the UnixWare acl() system call.
700 * (note: since POSIX allows minimal ACLs which only contain
701 * 3 entries - ie there is no mask entry - we should, in theory,
702 * check for this and add a mask entry if necessary - however
703 * we "know" that the caller of this interface always specifies
704 * a mask, so in practice "this never happens" (tm) - if it *does*
705 * happen aclsort() will fail and return an error and someone will
706 * have to fix it...)
708 static bool solaris_acl_sort(SOLARIS_ACL_T solaris_acl, int count)
710 int fixmask = (count <= 4);
712 if (aclsort(count, fixmask, solaris_acl) != 0) {
713 errno = EINVAL;
714 return False;
716 return True;
719 #if 0
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;
749 #endif
751 static struct vfs_fn_pointers solarisacl_fns = {
752 .sys_acl_get_file_fn = solarisacl_sys_acl_get_file,
753 .sys_acl_get_fd_fn = solarisacl_sys_acl_get_fd,
754 .sys_acl_blob_get_file_fn = posix_sys_acl_blob_get_file,
755 .sys_acl_blob_get_fd_fn = posix_sys_acl_blob_get_fd,
756 .sys_acl_set_file_fn = solarisacl_sys_acl_set_file,
757 .sys_acl_set_fd_fn = solarisacl_sys_acl_set_fd,
758 .sys_acl_delete_def_file_fn = solarisacl_sys_acl_delete_def_file,
761 NTSTATUS vfs_solarisacl_init(void);
762 NTSTATUS vfs_solarisacl_init(void)
764 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "solarisacl",
765 &solarisacl_fns);
768 /* ENTE */