| 1 | /*
|
|---|
| 2 | * NFS4 ACL handling
|
|---|
| 3 | *
|
|---|
| 4 | * Copyright (C) Jim McDonough, 2006
|
|---|
| 5 | *
|
|---|
| 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.
|
|---|
| 10 | *
|
|---|
| 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.
|
|---|
| 15 | *
|
|---|
| 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/>.
|
|---|
| 18 | */
|
|---|
| 19 |
|
|---|
| 20 | #include "includes.h"
|
|---|
| 21 | #include "nfs4_acls.h"
|
|---|
| 22 |
|
|---|
| 23 | #undef DBGC_CLASS
|
|---|
| 24 | #define DBGC_CLASS DBGC_ACLS
|
|---|
| 25 |
|
|---|
| 26 | #define SMBACL4_PARAM_TYPE_NAME "nfs4"
|
|---|
| 27 |
|
|---|
| 28 | extern const struct generic_mapping file_generic_mapping;
|
|---|
| 29 |
|
|---|
| 30 | #define SMB_ACE4_INT_MAGIC 0x76F8A967
|
|---|
| 31 | typedef struct _SMB_ACE4_INT_T
|
|---|
| 32 | {
|
|---|
| 33 | uint32 magic;
|
|---|
| 34 | SMB_ACE4PROP_T prop;
|
|---|
| 35 | void *next;
|
|---|
| 36 | } SMB_ACE4_INT_T;
|
|---|
| 37 |
|
|---|
| 38 | #define SMB_ACL4_INT_MAGIC 0x29A3E792
|
|---|
| 39 | typedef struct _SMB_ACL4_INT_T
|
|---|
| 40 | {
|
|---|
| 41 | uint32 magic;
|
|---|
| 42 | uint32 naces;
|
|---|
| 43 | SMB_ACE4_INT_T *first;
|
|---|
| 44 | SMB_ACE4_INT_T *last;
|
|---|
| 45 | } SMB_ACL4_INT_T;
|
|---|
| 46 |
|
|---|
| 47 | static SMB_ACL4_INT_T *get_validated_aclint(SMB4ACL_T *theacl)
|
|---|
| 48 | {
|
|---|
| 49 | SMB_ACL4_INT_T *aclint = (SMB_ACL4_INT_T *)theacl;
|
|---|
| 50 | if (theacl==NULL)
|
|---|
| 51 | {
|
|---|
| 52 | DEBUG(2, ("acl is NULL\n"));
|
|---|
| 53 | errno = EINVAL;
|
|---|
| 54 | return NULL;
|
|---|
| 55 | }
|
|---|
| 56 | if (aclint->magic!=SMB_ACL4_INT_MAGIC)
|
|---|
| 57 | {
|
|---|
| 58 | DEBUG(2, ("aclint bad magic 0x%x\n", aclint->magic));
|
|---|
| 59 | errno = EINVAL;
|
|---|
| 60 | return NULL;
|
|---|
| 61 | }
|
|---|
| 62 | return aclint;
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | static SMB_ACE4_INT_T *get_validated_aceint(SMB4ACE_T *ace)
|
|---|
| 66 | {
|
|---|
| 67 | SMB_ACE4_INT_T *aceint = (SMB_ACE4_INT_T *)ace;
|
|---|
| 68 | if (ace==NULL)
|
|---|
| 69 | {
|
|---|
| 70 | DEBUG(2, ("ace is NULL\n"));
|
|---|
| 71 | errno = EINVAL;
|
|---|
| 72 | return NULL;
|
|---|
| 73 | }
|
|---|
| 74 | if (aceint->magic!=SMB_ACE4_INT_MAGIC)
|
|---|
| 75 | {
|
|---|
| 76 | DEBUG(2, ("aceint bad magic 0x%x\n", aceint->magic));
|
|---|
| 77 | errno = EINVAL;
|
|---|
| 78 | return NULL;
|
|---|
| 79 | }
|
|---|
| 80 | return aceint;
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | SMB4ACL_T *smb_create_smb4acl(void)
|
|---|
| 84 | {
|
|---|
| 85 | TALLOC_CTX *mem_ctx = talloc_tos();
|
|---|
| 86 | SMB_ACL4_INT_T *theacl = (SMB_ACL4_INT_T *)TALLOC_ZERO_SIZE(mem_ctx, sizeof(SMB_ACL4_INT_T));
|
|---|
| 87 | if (theacl==NULL)
|
|---|
| 88 | {
|
|---|
| 89 | DEBUG(0, ("TALLOC_SIZE failed\n"));
|
|---|
| 90 | errno = ENOMEM;
|
|---|
| 91 | return NULL;
|
|---|
| 92 | }
|
|---|
| 93 | theacl->magic = SMB_ACL4_INT_MAGIC;
|
|---|
| 94 | /* theacl->first, last = NULL not needed */
|
|---|
| 95 | return (SMB4ACL_T *)theacl;
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | SMB4ACE_T *smb_add_ace4(SMB4ACL_T *theacl, SMB_ACE4PROP_T *prop)
|
|---|
| 99 | {
|
|---|
| 100 | SMB_ACL4_INT_T *aclint = get_validated_aclint(theacl);
|
|---|
| 101 | TALLOC_CTX *mem_ctx = talloc_tos();
|
|---|
| 102 | SMB_ACE4_INT_T *ace;
|
|---|
| 103 |
|
|---|
| 104 | ace = (SMB_ACE4_INT_T *)TALLOC_ZERO_SIZE(mem_ctx, sizeof(SMB_ACE4_INT_T));
|
|---|
| 105 | if (ace==NULL)
|
|---|
| 106 | {
|
|---|
| 107 | DEBUG(0, ("TALLOC_SIZE failed\n"));
|
|---|
| 108 | errno = ENOMEM;
|
|---|
| 109 | return NULL;
|
|---|
| 110 | }
|
|---|
| 111 | ace->magic = SMB_ACE4_INT_MAGIC;
|
|---|
| 112 | /* ace->next = NULL not needed */
|
|---|
| 113 | memcpy(&ace->prop, prop, sizeof(SMB_ACE4PROP_T));
|
|---|
| 114 |
|
|---|
| 115 | if (aclint->first==NULL)
|
|---|
| 116 | {
|
|---|
| 117 | aclint->first = ace;
|
|---|
| 118 | aclint->last = ace;
|
|---|
| 119 | } else {
|
|---|
| 120 | aclint->last->next = (void *)ace;
|
|---|
| 121 | aclint->last = ace;
|
|---|
| 122 | }
|
|---|
| 123 | aclint->naces++;
|
|---|
| 124 |
|
|---|
| 125 | return (SMB4ACE_T *)ace;
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 | SMB_ACE4PROP_T *smb_get_ace4(SMB4ACE_T *ace)
|
|---|
| 129 | {
|
|---|
| 130 | SMB_ACE4_INT_T *aceint = get_validated_aceint(ace);
|
|---|
| 131 | if (aceint==NULL)
|
|---|
| 132 | return NULL;
|
|---|
| 133 |
|
|---|
| 134 | return &aceint->prop;
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 | SMB4ACE_T *smb_next_ace4(SMB4ACE_T *ace)
|
|---|
| 138 | {
|
|---|
| 139 | SMB_ACE4_INT_T *aceint = get_validated_aceint(ace);
|
|---|
| 140 | if (aceint==NULL)
|
|---|
| 141 | return NULL;
|
|---|
| 142 |
|
|---|
| 143 | return (SMB4ACE_T *)aceint->next;
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
|
|---|