| 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 | extern struct current_user current_user;
|
|---|
| 48 | extern int try_chown(connection_struct *conn, const char *fname, uid_t uid, gid_t gid);
|
|---|
| 49 | extern NTSTATUS unpack_nt_owners(int snum, uid_t *puser, gid_t *pgrp,
|
|---|
| 50 | uint32 security_info_sent, SEC_DESC *psd);
|
|---|
| 51 |
|
|---|
| 52 | static SMB_ACL4_INT_T *get_validated_aclint(SMB4ACL_T *acl)
|
|---|
| 53 | {
|
|---|
| 54 | SMB_ACL4_INT_T *aclint = (SMB_ACL4_INT_T *)acl;
|
|---|
| 55 | if (acl==NULL)
|
|---|
| 56 | {
|
|---|
| 57 | DEBUG(2, ("acl is NULL\n"));
|
|---|
| 58 | errno = EINVAL;
|
|---|
| 59 | return NULL;
|
|---|
| 60 | }
|
|---|
| 61 | if (aclint->magic!=SMB_ACL4_INT_MAGIC)
|
|---|
| 62 | {
|
|---|
| 63 | DEBUG(2, ("aclint bad magic 0x%x\n", aclint->magic));
|
|---|
| 64 | errno = EINVAL;
|
|---|
| 65 | return NULL;
|
|---|
| 66 | }
|
|---|
| 67 | return aclint;
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | static SMB_ACE4_INT_T *get_validated_aceint(SMB4ACE_T *ace)
|
|---|
| 71 | {
|
|---|
| 72 | SMB_ACE4_INT_T *aceint = (SMB_ACE4_INT_T *)ace;
|
|---|
| 73 | if (ace==NULL)
|
|---|
| 74 | {
|
|---|
| 75 | DEBUG(2, ("ace is NULL\n"));
|
|---|
| 76 | errno = EINVAL;
|
|---|
| 77 | return NULL;
|
|---|
| 78 | }
|
|---|
| 79 | if (aceint->magic!=SMB_ACE4_INT_MAGIC)
|
|---|
| 80 | {
|
|---|
| 81 | DEBUG(2, ("aceint bad magic 0x%x\n", aceint->magic));
|
|---|
| 82 | errno = EINVAL;
|
|---|
| 83 | return NULL;
|
|---|
| 84 | }
|
|---|
| 85 | return aceint;
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | SMB4ACL_T *smb_create_smb4acl(void)
|
|---|
| 89 | {
|
|---|
| 90 | TALLOC_CTX *mem_ctx = talloc_tos();
|
|---|
| 91 | SMB_ACL4_INT_T *acl = (SMB_ACL4_INT_T *)TALLOC_ZERO_SIZE(mem_ctx, sizeof(SMB_ACL4_INT_T));
|
|---|
| 92 | if (acl==NULL)
|
|---|
| 93 | {
|
|---|
| 94 | DEBUG(0, ("TALLOC_SIZE failed\n"));
|
|---|
| 95 | errno = ENOMEM;
|
|---|
| 96 | return NULL;
|
|---|
| 97 | }
|
|---|
| 98 | acl->magic = SMB_ACL4_INT_MAGIC;
|
|---|
| 99 | /* acl->first, last = NULL not needed */
|
|---|
| 100 | return (SMB4ACL_T *)acl;
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 | SMB4ACE_T *smb_add_ace4(SMB4ACL_T *acl, SMB_ACE4PROP_T *prop)
|
|---|
| 104 | {
|
|---|
| 105 | SMB_ACL4_INT_T *aclint = get_validated_aclint(acl);
|
|---|
| 106 | TALLOC_CTX *mem_ctx = talloc_tos();
|
|---|
| 107 | SMB_ACE4_INT_T *ace;
|
|---|
| 108 |
|
|---|
| 109 | ace = (SMB_ACE4_INT_T *)TALLOC_ZERO_SIZE(mem_ctx, sizeof(SMB_ACE4_INT_T));
|
|---|
| 110 | if (ace==NULL)
|
|---|
| 111 | {
|
|---|
| 112 | DEBUG(0, ("TALLOC_SIZE failed\n"));
|
|---|
| 113 | errno = ENOMEM;
|
|---|
| 114 | return NULL;
|
|---|
| 115 | }
|
|---|
| 116 | ace->magic = SMB_ACE4_INT_MAGIC;
|
|---|
| 117 | /* ace->next = NULL not needed */
|
|---|
| 118 | memcpy(&ace->prop, prop, sizeof(SMB_ACE4PROP_T));
|
|---|
| 119 |
|
|---|
| 120 | if (aclint->first==NULL)
|
|---|
| 121 | {
|
|---|
| 122 | aclint->first = ace;
|
|---|
| 123 | aclint->last = ace;
|
|---|
| 124 | } else {
|
|---|
| 125 | aclint->last->next = (void *)ace;
|
|---|
| 126 | aclint->last = ace;
|
|---|
| 127 | }
|
|---|
| 128 | aclint->naces++;
|
|---|
| 129 |
|
|---|
| 130 | return (SMB4ACE_T *)ace;
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 | SMB_ACE4PROP_T *smb_get_ace4(SMB4ACE_T *ace)
|
|---|
| 134 | {
|
|---|
| 135 | SMB_ACE4_INT_T *aceint = get_validated_aceint(ace);
|
|---|
| 136 | if (aceint==NULL)
|
|---|
| 137 | return NULL;
|
|---|
| 138 |
|
|---|
| 139 | return &aceint->prop;
|
|---|
| 140 | }
|
|---|
| 141 |
|
|---|
| 142 | SMB4ACE_T *smb_next_ace4(SMB4ACE_T *ace)
|
|---|
| 143 | {
|
|---|
| 144 | SMB_ACE4_INT_T *aceint = get_validated_aceint(ace);
|
|---|
| 145 | if (aceint==NULL)
|
|---|
| 146 | return NULL;
|
|---|
| 147 |
|
|---|
| 148 | return (SMB4ACE_T *)aceint->next;
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | SMB4ACE_T *smb_first_ace4(SMB4ACL_T *acl)
|
|---|
| 152 | {
|
|---|
| 153 | SMB_ACL4_INT_T *aclint = get_validated_aclint(acl);
|
|---|
| 154 | if (aclint==NULL)
|
|---|
| 155 | return NULL;
|
|---|
| 156 |
|
|---|
| 157 | return (SMB4ACE_T *)aclint->first;
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | uint32 smb_get_naces(SMB4ACL_T *acl)
|
|---|
| 161 | {
|
|---|
| 162 | SMB_ACL4_INT_T *aclint = get_validated_aclint(acl);
|
|---|
| 163 | if (aclint==NULL)
|
|---|
| 164 | return 0;
|
|---|
| 165 |
|
|---|
| 166 | return aclint->naces;
|
|---|
| 167 | }
|
|---|
| 168 |
|
|---|
| 169 | static int smbacl4_GetFileOwner(struct connection_struct *conn,
|
|---|
| 170 | const char *filename,
|
|---|
| 171 | SMB_STRUCT_STAT *psbuf)
|
|---|
| 172 | {
|
|---|
| 173 | memset(psbuf, 0, sizeof(SMB_STRUCT_STAT));
|
|---|
| 174 |
|
|---|
| 175 | /* Get the stat struct for the owner info. */
|
|---|
| 176 | if (SMB_VFS_STAT(conn, filename, psbuf) != 0)
|
|---|
| 177 | {
|
|---|
| 178 | DEBUG(8, ("SMB_VFS_STAT failed with error %s\n",
|
|---|
| 179 | strerror(errno)));
|
|---|
| 180 | return -1;
|
|---|
| 181 | }
|
|---|
| 182 |
|
|---|
| 183 | return 0;
|
|---|
|
|---|