Make the smbd VFS typesafe
[samba.git] / source3 / modules / vfs_afsacl.c
index 9409f3fa2039c18d7a5ae54c1357d99fa636e951..1c310c7185983dc6bb3db02125ddccaf4b731181 100644 (file)
@@ -592,7 +592,6 @@ static size_t afs_to_nt_acl_common(struct afs_acl *afs_acl,
 {
        SEC_ACE *nt_ace_list;
        DOM_SID owner_sid, group_sid;
-       SEC_ACCESS mask;
        SEC_ACL *psa = NULL;
        int good_aces;
        size_t sd_size;
@@ -600,8 +599,8 @@ static size_t afs_to_nt_acl_common(struct afs_acl *afs_acl,
 
        struct afs_ace *afs_ace;
 
-       uid_to_sid(&owner_sid, psbuf->st_uid);
-       gid_to_sid(&group_sid, psbuf->st_gid);
+       uid_to_sid(&owner_sid, psbuf->st_ex_uid);
+       gid_to_sid(&group_sid, psbuf->st_ex_gid);
 
        if (afs_acl->num_aces) {
                nt_ace_list = TALLOC_ARRAY(mem_ctx, SEC_ACE, afs_acl->num_aces);
@@ -616,7 +615,7 @@ static size_t afs_to_nt_acl_common(struct afs_acl *afs_acl,
        good_aces = 0;
 
        while (afs_ace != NULL) {
-               uint32 nt_rights;
+               uint32_t nt_rights;
                uint8 flag = SEC_ACE_FLAG_OBJECT_INHERIT |
                        SEC_ACE_FLAG_CONTAINER_INHERIT;
 
@@ -627,15 +626,14 @@ static size_t afs_to_nt_acl_common(struct afs_acl *afs_acl,
                        continue;
                }
 
-               if (S_ISDIR(psbuf->st_mode))
+               if (S_ISDIR(psbuf->st_ex_mode))
                        afs_to_nt_dir_rights(afs_ace->rights, &nt_rights,
                                             &flag);
                else
                        nt_rights = afs_to_nt_file_rights(afs_ace->rights);
 
-               init_sec_access(&mask, nt_rights);
                init_sec_ace(&nt_ace_list[good_aces++], &(afs_ace->sid),
-                            SEC_ACE_TYPE_ACCESS_ALLOWED, mask, flag);
+                            SEC_ACE_TYPE_ACCESS_ALLOWED, nt_rights, flag);
                afs_ace = afs_ace->next;
        }
 
@@ -657,18 +655,17 @@ static size_t afs_to_nt_acl_common(struct afs_acl *afs_acl,
 
 static size_t afs_to_nt_acl(struct afs_acl *afs_acl,
                            struct connection_struct *conn,
-                           const char *name,
+                           struct smb_filename *smb_fname,
                            uint32 security_info,
                            struct security_descriptor **ppdesc)
 {
-       SMB_STRUCT_STAT sbuf;
-
        /* Get the stat struct for the owner info. */
-       if(SMB_VFS_STAT(conn, name, &sbuf) != 0) {
+       if(SMB_VFS_STAT(conn, smb_fname) != 0) {
                return 0;
        }
 
-       return afs_to_nt_acl_common(afs_acl, &sbuf, security_info, ppdesc);
+       return afs_to_nt_acl_common(afs_acl, &smb_fname->st, security_info,
+                                   ppdesc);
 }
 
 static size_t afs_fto_nt_acl(struct afs_acl *afs_acl,
@@ -717,12 +714,12 @@ static bool mappable_sid(const DOM_SID *sid)
 
 static bool nt_to_afs_acl(const char *filename,
                          uint32 security_info_sent,
-                         struct security_descriptor *psd,
+                         const struct security_descriptor *psd,
                          uint32 (*nt_to_afs_rights)(const char *filename,
                                                     const SEC_ACE *ace),
                          struct afs_acl *afs_acl)
 {
-       SEC_ACL *dacl;
+       const SEC_ACL *dacl;
        int i;
 
        /* Currently we *only* look at the dacl */
@@ -737,7 +734,7 @@ static bool nt_to_afs_acl(const char *filename,
        dacl = psd->dacl;
 
        for (i = 0; i < dacl->num_aces; i++) {
-               SEC_ACE *ace = &(dacl->aces[i]);
+               const SEC_ACE *ace = &(dacl->aces[i]);
                const char *dom_name, *name;
                enum lsa_SidType name_type;
                char *p;
@@ -887,7 +884,7 @@ static void merge_unknown_aces(struct afs_acl *src, struct afs_acl *dst)
 
 static NTSTATUS afs_set_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
                           uint32 security_info_sent,
-                          struct security_descriptor *psd)
+                          const struct security_descriptor *psd)
 {
        struct afs_acl old_afs_acl, new_afs_acl;
        struct afs_acl dir_acl, file_acl;
@@ -907,7 +904,7 @@ static NTSTATUS afs_set_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
        ZERO_STRUCT(dir_acl);
        ZERO_STRUCT(file_acl);
 
-       name = talloc_strdup(talloc_tos(), fsp->fsp_name);
+       name = talloc_strdup(talloc_tos(), fsp->fsp_name->base_name);
        if (!name) {
                return NT_STATUS_NO_MEMORY;
        }
@@ -927,7 +924,7 @@ static NTSTATUS afs_set_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
        }
 
        if (!afs_get_afs_acl(name, &old_afs_acl)) {
-               DEBUG(3, ("Could not get old ACL of %s\n", fsp->fsp_name));
+               DEBUG(3, ("Could not get old ACL of %s\n", fsp_str_dbg(fsp)));
                goto done;
        }
 
@@ -943,7 +940,8 @@ static NTSTATUS afs_set_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
                }
 
                free_afs_acl(&dir_acl);
-               if (!nt_to_afs_acl(fsp->fsp_name, security_info_sent, psd,
+               if (!nt_to_afs_acl(fsp->fsp_name->base_name,
+                                  security_info_sent, psd,
                                   nt_to_afs_dir_rights, &dir_acl))
                        goto done;
        } else {
@@ -958,7 +956,8 @@ static NTSTATUS afs_set_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
                }
 
                free_afs_acl(&file_acl);
-               if (!nt_to_afs_acl(fsp->fsp_name, security_info_sent, psd,
+               if (!nt_to_afs_acl(fsp->fsp_name->base_name,
+                                  security_info_sent, psd,
                                   nt_to_afs_file_rights, &file_acl))
                        goto done;
        }
@@ -999,11 +998,11 @@ static NTSTATUS afsacl_fget_nt_acl(struct vfs_handle_struct *handle,
        struct afs_acl acl;
        size_t sd_size;
 
-       DEBUG(5, ("afsacl_fget_nt_acl: %s\n", fsp->fsp_name));
+       DEBUG(5, ("afsacl_fget_nt_acl: %s\n", fsp_str_dbg(fsp)));
 
        sidpts = lp_parm_bool(SNUM(fsp->conn), "afsacl", "sidpts", False);
 
-       if (!afs_get_afs_acl(fsp->fsp_name, &acl)) {
+       if (!afs_get_afs_acl(fsp->fsp_name->base_name, &acl)) {
                return NT_STATUS_ACCESS_DENIED;
        }
 
@@ -1020,6 +1019,8 @@ static NTSTATUS afsacl_get_nt_acl(struct vfs_handle_struct *handle,
 {
        struct afs_acl acl;
        size_t sd_size;
+       struct smb_filename *smb_fname = NULL;
+       NTSTATUS status;
 
        DEBUG(5, ("afsacl_get_nt_acl: %s\n", name));
 
@@ -1029,8 +1030,16 @@ static NTSTATUS afsacl_get_nt_acl(struct vfs_handle_struct *handle,
                return NT_STATUS_ACCESS_DENIED;
        }
 
-       sd_size = afs_to_nt_acl(&acl, handle->conn, name, security_info,
+       status = create_synthetic_smb_fname(talloc_tos(), name, NULL, NULL,
+                                           &smb_fname);
+       if (!NT_STATUS_IS_OK(status)) {
+               free_afs_acl(&acl);
+               return status;
+       }
+
+       sd_size = afs_to_nt_acl(&acl, handle->conn, smb_fname, security_info,
                                ppdesc);
+       TALLOC_FREE(smb_fname);
 
        free_afs_acl(&acl);
 
@@ -1040,7 +1049,7 @@ static NTSTATUS afsacl_get_nt_acl(struct vfs_handle_struct *handle,
 NTSTATUS afsacl_fset_nt_acl(vfs_handle_struct *handle,
                         files_struct *fsp,
                         uint32 security_info_sent,
-                        SEC_DESC *psd)
+                        const SEC_DESC *psd)
 {
        return afs_set_nt_acl(handle, fsp, security_info_sent, psd);
 }
@@ -1059,23 +1068,16 @@ static int afsacl_connect(vfs_handle_struct *handle,
        return SMB_VFS_NEXT_CONNECT(handle, service, user);
 }
 
-/* VFS operations structure */
-
-static vfs_op_tuple afsacl_ops[] = {   
-       {SMB_VFS_OP(afsacl_connect), SMB_VFS_OP_CONNECT,
-        SMB_VFS_LAYER_TRANSPARENT},
-       {SMB_VFS_OP(afsacl_fget_nt_acl), SMB_VFS_OP_FGET_NT_ACL,
-        SMB_VFS_LAYER_TRANSPARENT},
-       {SMB_VFS_OP(afsacl_get_nt_acl), SMB_VFS_OP_GET_NT_ACL,
-        SMB_VFS_LAYER_TRANSPARENT},
-       {SMB_VFS_OP(afsacl_fset_nt_acl), SMB_VFS_OP_FSET_NT_ACL,
-        SMB_VFS_LAYER_TRANSPARENT},
-       {SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP}
+static struct vfs_fn_pointers vfs_afsacl_fns = {
+       .connect_fn = afsacl_connect,
+       .fget_nt_acl = afsacl_fget_nt_acl,
+       .get_nt_acl = afsacl_get_nt_acl,
+       .fset_nt_acl = afsacl_fset_nt_acl
 };
 
 NTSTATUS vfs_afsacl_init(void);
 NTSTATUS vfs_afsacl_init(void)
 {
        return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "afsacl",
-                               afsacl_ops);
+                               &vfs_afsacl_fns);
 }