s3: VFS: Change SMB_VFS_SYS_ACL_DELETE_DEF_FILE to use const struct smb_filename...
[sfrench/samba-autobuild/.git] / source3 / modules / vfs_zfsacl.c
index 0fe21b2909883483d76160544d96eb209f3e4276..c59a910626046803e5f977e8e9edd0b1f9ad9cc3 100644 (file)
  */
 
 #include "includes.h"
+#include "system/filesys.h"
+#include "smbd/smbd.h"
 #include "nfs4_acls.h"
 
+#if HAVE_FREEBSD_SUNACL_H
+#include "sunacl.h"
+#endif
+
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_VFS
 
  * read the local file's acls and return it in NT form
  * using the NFSv4 format conversion
  */
-static NTSTATUS zfs_get_nt_acl(struct files_struct *fsp, uint32 security_info,
-                            struct security_descriptor **ppdesc)
+static NTSTATUS zfs_get_nt_acl_common(TALLOC_CTX *mem_ctx,
+                                     const char *name,
+                                     struct SMB4ACL_T **ppacl)
 {
        int naces, i;
        ace_t *acebuf;
-       SMB4ACL_T *pacl;
-       TALLOC_CTX      *mem_ctx;
+       struct SMB4ACL_T *pacl;
 
        /* read the number of file aces */
-       if((naces = acl(fsp->fsp_name, ACE_GETACLCNT, 0, NULL)) == -1) {
+       if((naces = acl(name, ACE_GETACLCNT, 0, NULL)) == -1) {
                if(errno == ENOSYS) {
-                       DEBUG(9, ("acl(ACE_GETACLCNT, %s): Operation is not supported on the filesystem where the file reside"));
+                       DEBUG(9, ("acl(ACE_GETACLCNT, %s): Operation is not "
+                                 "supported on the filesystem where the file "
+                                 "reside\n", name));
                } else {
-                       DEBUG(9, ("acl(ACE_GETACLCNT, %s): %s ", fsp->fsp_name,
+                       DEBUG(9, ("acl(ACE_GETACLCNT, %s): %s ", name,
                                        strerror(errno)));
                }
                return map_nt_error_from_unix(errno);
@@ -59,22 +67,22 @@ static NTSTATUS zfs_get_nt_acl(struct files_struct *fsp, uint32 security_info,
                return NT_STATUS_NO_MEMORY;
        }
        /* read the aces into the field */
-       if(acl(fsp->fsp_name, ACE_GETACL, naces, acebuf) < 0) {
-               DEBUG(9, ("acl(ACE_GETACL, %s): %s ", fsp->fsp_name,
+       if(acl(name, ACE_GETACL, naces, acebuf) < 0) {
+               DEBUG(9, ("acl(ACE_GETACL, %s): %s ", name,
                                strerror(errno)));
                return map_nt_error_from_unix(errno);
        }
        /* create SMB4ACL data */
-       if((pacl = smb_create_smb4acl()) == NULL) {
+       if((pacl = smb_create_smb4acl(mem_ctx)) == NULL) {
                return NT_STATUS_NO_MEMORY;
        }
        for(i=0; i<naces; i++) {
                SMB_ACE4PROP_T aceprop;
 
-               aceprop.aceType  = (uint32) acebuf[i].a_type;
-               aceprop.aceFlags = (uint32) acebuf[i].a_flags;
-               aceprop.aceMask  = (uint32) acebuf[i].a_access_mask;
-               aceprop.who.id   = (uint32) acebuf[i].a_who;
+               aceprop.aceType  = (uint32_t) acebuf[i].a_type;
+               aceprop.aceFlags = (uint32_t) acebuf[i].a_flags;
+               aceprop.aceMask  = (uint32_t) acebuf[i].a_access_mask;
+               aceprop.who.id   = (uint32_t) acebuf[i].a_who;
 
                if(aceprop.aceFlags & ACE_OWNER) {
                        aceprop.flags = SMB_ACE4_ID_SPECIAL;
@@ -92,16 +100,19 @@ static NTSTATUS zfs_get_nt_acl(struct files_struct *fsp, uint32 security_info,
                        return NT_STATUS_NO_MEMORY;
        }
 
-       return smb_get_nt_acl_nfs4(fsp, security_info, ppdesc, pacl);
+       *ppacl = pacl;
+       return NT_STATUS_OK;
 }
 
 /* call-back function processing the NT acl -> ZFS acl using NFSv4 conv. */
-static bool zfs_process_smbacl(files_struct *fsp, SMB4ACL_T *smbacl)
+static bool zfs_process_smbacl(vfs_handle_struct *handle, files_struct *fsp,
+                              struct SMB4ACL_T *smbacl)
 {
        int naces = smb_get_naces(smbacl), i;
        ace_t *acebuf;
-       SMB4ACE_T *smbace;
+       struct SMB4ACE_T *smbace;
        TALLOC_CTX      *mem_ctx;
+       bool have_special_id = false;
 
        /* allocate the field of ZFS aces */
        mem_ctx = talloc_tos();
@@ -119,6 +130,9 @@ static bool zfs_process_smbacl(files_struct *fsp, SMB4ACL_T *smbacl)
                acebuf[i].a_type        = aceprop->aceType;
                acebuf[i].a_flags       = aceprop->aceFlags;
                acebuf[i].a_access_mask = aceprop->aceMask;
+               /* SYNC on acls is a no-op on ZFS.
+                  See bug #7909. */
+               acebuf[i].a_access_mask &= ~SMB_ACE4_SYNCHRONIZE;
                acebuf[i].a_who         = aceprop->who.id;
                if(aceprop->flags & SMB_ACE4_ID_SPECIAL) {
                        switch(aceprop->who.special_id) {
@@ -129,24 +143,35 @@ static bool zfs_process_smbacl(files_struct *fsp, SMB4ACL_T *smbacl)
                                acebuf[i].a_flags |= ACE_OWNER;
                                break;
                        case SMB_ACE4_WHO_GROUP:
-                               acebuf[i].a_flags |= ACE_GROUP;
+                               acebuf[i].a_flags |= ACE_GROUP|ACE_IDENTIFIER_GROUP;
                                break;
                        default:
                                DEBUG(8, ("unsupported special_id %d\n", \
                                        aceprop->who.special_id));
                                continue; /* don't add it !!! */
                        }
+                       have_special_id = true;
                }
        }
+
+       if (!have_special_id
+           && lp_parm_bool(fsp->conn->params->service, "zfsacl",
+                           "denymissingspecial", false)) {
+               errno = EACCES;
+               return false;
+       }
+
        SMB_ASSERT(i == naces);
 
        /* store acl */
-       if(acl(fsp->fsp_name, ACE_SETACL, naces, acebuf)) {
+       if(acl(fsp->fsp_name->base_name, ACE_SETACL, naces, acebuf)) {
                if(errno == ENOSYS) {
-                       DEBUG(9, ("acl(ACE_SETACL, %s): Operation is not supported on the filesystem where the file reside"));
+                       DEBUG(9, ("acl(ACE_SETACL, %s): Operation is not "
+                                 "supported on the filesystem where the file "
+                                 "reside", fsp_str_dbg(fsp)));
                } else {
-                       DEBUG(9, ("acl(ACE_SETACL, %s): %s ", fsp->fsp_name,
-                                       strerror(errno)));
+                       DEBUG(9, ("acl(ACE_SETACL, %s): %s ", fsp_str_dbg(fsp),
+                                 strerror(errno)));
                }
                return 0;
        }
@@ -159,77 +184,169 @@ static bool zfs_process_smbacl(files_struct *fsp, SMB4ACL_T *smbacl)
  * using the NFSv4 format conversion
  */
 static NTSTATUS zfs_set_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
-                          uint32 security_info_sent,
-                          struct security_descriptor *psd)
+                          uint32_t security_info_sent,
+                          const struct security_descriptor *psd)
 {
-       return smb_set_nt_acl_nfs4(fsp, security_info_sent, psd,
-                       zfs_process_smbacl);
+        return smb_set_nt_acl_nfs4(handle, fsp, NULL, security_info_sent, psd,
+                                  zfs_process_smbacl);
 }
 
 static NTSTATUS zfsacl_fget_nt_acl(struct vfs_handle_struct *handle,
-                                struct files_struct *fsp,
-                                int fd,  uint32 security_info,
-                                struct security_descriptor **ppdesc)
+                                  struct files_struct *fsp,
+                                  uint32_t security_info,
+                                  TALLOC_CTX *mem_ctx,
+                                  struct security_descriptor **ppdesc)
 {
-       return zfs_get_nt_acl(fsp, security_info, ppdesc);
+       struct SMB4ACL_T *pacl;
+       NTSTATUS status;
+       TALLOC_CTX *frame = talloc_stackframe();
+
+       status = zfs_get_nt_acl_common(frame,
+                                      fsp->fsp_name->base_name,
+                                      &pacl);
+       if (!NT_STATUS_IS_OK(status)) {
+               TALLOC_FREE(frame);
+               return status;
+       }
+
+       status = smb_fget_nt_acl_nfs4(fsp, NULL, security_info, mem_ctx,
+                                     ppdesc, pacl);
+       TALLOC_FREE(frame);
+       return status;
 }
 
 static NTSTATUS zfsacl_get_nt_acl(struct vfs_handle_struct *handle,
-                               struct files_struct *fsp,
-                               const char *name,  uint32 security_info,
+                               const struct smb_filename *smb_fname,
+                               uint32_t security_info,
+                               TALLOC_CTX *mem_ctx,
                                struct security_descriptor **ppdesc)
 {
-       return zfs_get_nt_acl(fsp, security_info, ppdesc);
+       struct SMB4ACL_T *pacl;
+       NTSTATUS status;
+       TALLOC_CTX *frame = talloc_stackframe();
+
+       status = zfs_get_nt_acl_common(frame,
+                                       smb_fname->base_name,
+                                       &pacl);
+       if (!NT_STATUS_IS_OK(status)) {
+               TALLOC_FREE(frame);
+               return status;
+       }
+
+       status = smb_get_nt_acl_nfs4(handle->conn,
+                                       smb_fname,
+                                       NULL,
+                                       security_info,
+                                       mem_ctx,
+                                       ppdesc,
+                                       pacl);
+       TALLOC_FREE(frame);
+       return status;
 }
 
 static NTSTATUS zfsacl_fset_nt_acl(vfs_handle_struct *handle,
                         files_struct *fsp,
-                        int fd, uint32 security_info_sent,
-                        SEC_DESC *psd)
+                        uint32_t security_info_sent,
+                        const struct security_descriptor *psd)
 {
        return zfs_set_nt_acl(handle, fsp, security_info_sent, psd);
 }
 
-static NTSTATUS zfsacl_set_nt_acl(vfs_handle_struct *handle,
-                      files_struct *fsp,
-                      const char *name, uint32 security_info_sent,
-                      SEC_DESC *psd)
+/* nils.goroll@hamburg.de 2008-06-16 :
+
+   See also
+   - https://bugzilla.samba.org/show_bug.cgi?id=5446
+   - http://bugs.opensolaris.org/view_bug.do?bug_id=6688240
+
+   Solaris supports NFSv4 and ZFS ACLs through a common system call, acl(2)
+   with ACE_SETACL / ACE_GETACL / ACE_GETACLCNT, which is being wrapped for
+   use by samba in this module.
+
+   As the acl(2) interface is identical for ZFS and for NFS, this module,
+   vfs_zfsacl, can not only be used for ZFS, but also for sharing NFSv4
+   mounts on Solaris.
+
+   But while "traditional" POSIX DRAFT ACLs (using acl(2) with SETACL
+   / GETACL / GETACLCNT) fail for ZFS, the Solaris NFS client
+   implemets a compatibility wrapper, which will make calls to
+   traditional ACL calls though vfs_solarisacl succeed. As the
+   compatibility wrapper's implementation is (by design) incomplete,
+   we want to make sure that it is never being called.
+
+   As long as Samba does not support an exiplicit method for a module
+   to define conflicting vfs methods, we should override all conflicting
+   methods here.
+
+   For this to work, we need to make sure that this module is initialised
+   *after* vfs_solarisacl
+
+   Function declarations taken from vfs_solarisacl
+*/
+
+static SMB_ACL_T zfsacl_fail__sys_acl_get_file(vfs_handle_struct *handle,
+                                              const char *path_p,
+                                              SMB_ACL_TYPE_T type,
+                                              TALLOC_CTX *mem_ctx)
 {
-       return zfs_set_nt_acl(handle, fsp, security_info_sent, psd);
+       return (SMB_ACL_T)NULL;
 }
 
-/* VFS operations structure */
+static SMB_ACL_T zfsacl_fail__sys_acl_get_fd(vfs_handle_struct *handle,
+                                            files_struct *fsp,
+                                            TALLOC_CTX *mem_ctx)
+{
+       return (SMB_ACL_T)NULL;
+}
 
-static vfs_op_tuple zfsacl_ops[] = {   
-       {SMB_VFS_OP(zfsacl_fget_nt_acl), SMB_VFS_OP_FGET_NT_ACL,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(zfsacl_get_nt_acl), SMB_VFS_OP_GET_NT_ACL,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(zfsacl_fset_nt_acl), SMB_VFS_OP_FSET_NT_ACL,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(zfsacl_set_nt_acl), SMB_VFS_OP_SET_NT_ACL,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP}
-};
+static int zfsacl_fail__sys_acl_set_file(vfs_handle_struct *handle,
+                                        const char *name,
+                                        SMB_ACL_TYPE_T type,
+                                        SMB_ACL_T theacl)
+{
+       return -1;
+}
 
-/* != 0 if this module will be compiled as static */
+static int zfsacl_fail__sys_acl_set_fd(vfs_handle_struct *handle,
+                                      files_struct *fsp,
+                                      SMB_ACL_T theacl)
+{
+       return -1;
+}
 
-#define STATIC 0
+static int zfsacl_fail__sys_acl_delete_def_file(vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname)
+{
+       return -1;
+}
 
-#if STATIC
-NTSTATUS vfs_zfsacl_init(void);
-#else
-NTSTATUS init_module(void);
-#endif
+static int zfsacl_fail__sys_acl_blob_get_file(vfs_handle_struct *handle, const char *path_p, TALLOC_CTX *mem_ctx, char **blob_description, DATA_BLOB *blob)
+{
+       return -1;
+}
 
-NTSTATUS
-#if STATIC
-       vfs_zfsacl_init
-#else
-       init_module
-#endif
-               (void)
+static int zfsacl_fail__sys_acl_blob_get_fd(vfs_handle_struct *handle, files_struct *fsp, TALLOC_CTX *mem_ctx, char **blob_description, DATA_BLOB *blob)
+{
+       return -1;
+}
+
+/* VFS operations structure */
+
+static struct vfs_fn_pointers zfsacl_fns = {
+       .sys_acl_get_file_fn = zfsacl_fail__sys_acl_get_file,
+       .sys_acl_get_fd_fn = zfsacl_fail__sys_acl_get_fd,
+       .sys_acl_blob_get_file_fn = zfsacl_fail__sys_acl_blob_get_file,
+       .sys_acl_blob_get_fd_fn = zfsacl_fail__sys_acl_blob_get_fd,
+       .sys_acl_set_file_fn = zfsacl_fail__sys_acl_set_file,
+       .sys_acl_set_fd_fn = zfsacl_fail__sys_acl_set_fd,
+       .sys_acl_delete_def_file_fn = zfsacl_fail__sys_acl_delete_def_file,
+       .fget_nt_acl_fn = zfsacl_fget_nt_acl,
+       .get_nt_acl_fn = zfsacl_get_nt_acl,
+       .fset_nt_acl_fn = zfsacl_fset_nt_acl,
+};
+
+NTSTATUS vfs_zfsacl_init(TALLOC_CTX *);
+NTSTATUS vfs_zfsacl_init(TALLOC_CTX *ctx)
 {
        return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "zfsacl",
-                               zfsacl_ops);
+                               &zfsacl_fns);
 }