Add acl_xattr:ignore system acls boolean (normally false) to allow
[idra/samba.git] / source3 / modules / vfs_acl_tdb.c
index 2afe69d764581ba37747af0eadf311c7dfafa271..6364b7b9f89e7efe50b7a554b1260edf5c8bf3ad 100644 (file)
 #include "librpc/gen_ndr/xattr.h"
 #include "librpc/gen_ndr/ndr_xattr.h"
 #include "../lib/crypto/crypto.h"
+#include "dbwrap.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_VFS
 
+#define ACL_MODULE_NAME "acl_tdb"
 #include "modules/vfs_acl_common.c"
 
 static unsigned int ref_count;
@@ -37,12 +39,11 @@ static struct db_context *acl_db;
  Open acl_db if not already open, increment ref count.
 *******************************************************************/
 
-static bool acl_tdb_init(struct db_context **pp_db)
+static bool acl_tdb_init(void)
 {
        char *dbname;
 
        if (acl_db) {
-               *pp_db = acl_db;
                ref_count++;
                return true;
        }
@@ -55,10 +56,10 @@ static bool acl_tdb_init(struct db_context **pp_db)
        }
 
        become_root();
-       *pp_db = db_open(NULL, dbname, 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
+       acl_db = db_open(NULL, dbname, 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
        unbecome_root();
 
-       if (*pp_db == NULL) {
+       if (acl_db == NULL) {
 #if defined(ENOTSUP)
                errno = ENOTSUP;
 #else
@@ -77,14 +78,12 @@ static bool acl_tdb_init(struct db_context **pp_db)
  Lower ref count and close acl_db if zero.
 *******************************************************************/
 
-static void free_acl_tdb_data(void **pptr)
+static void disconnect_acl_tdb(struct vfs_handle_struct *handle)
 {
-       struct db_context **pp_db = (struct db_context **)pptr;
-
+       SMB_VFS_NEXT_DISCONNECT(handle);
        ref_count--;
        if (ref_count == 0) {
-               TALLOC_FREE(*pp_db);
-               acl_db = NULL;
+               TALLOC_FREE(acl_db);
        }
 }
 
@@ -146,13 +145,10 @@ static NTSTATUS get_acl_blob(TALLOC_CTX *ctx,
        uint8 id_buf[16];
        TDB_DATA data;
        struct file_id id;
-       struct db_context *db;
-       NTSTATUS status;
+       struct db_context *db = acl_db;
+       NTSTATUS status = NT_STATUS_OK;
        SMB_STRUCT_STAT sbuf;
 
-       SMB_VFS_HANDLE_GET_DATA(handle, db, struct db_context,
-               return NT_STATUS_INTERNAL_DB_CORRUPTION);
-
        ZERO_STRUCT(sbuf);
 
        if (fsp) {
@@ -204,16 +200,13 @@ static NTSTATUS store_acl_blob_fsp(vfs_handle_struct *handle,
        uint8 id_buf[16];
        struct file_id id;
        TDB_DATA data;
-       struct db_context *db;
+       struct db_context *db = acl_db;
        struct db_record *rec;
        NTSTATUS status;
 
        DEBUG(10,("store_acl_blob_fsp: storing blob length %u on file %s\n",
                  (unsigned int)pblob->length, fsp_str_dbg(fsp)));
 
-       SMB_VFS_HANDLE_GET_DATA(handle, db, struct db_context,
-               return NT_STATUS_INTERNAL_DB_CORRUPTION);
-
        status = vfs_stat_fsp(fsp);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
@@ -243,12 +236,10 @@ static int unlink_acl_tdb(vfs_handle_struct *handle,
                          const struct smb_filename *smb_fname)
 {
        struct smb_filename *smb_fname_tmp = NULL;
-       struct db_context *db;
+       struct db_context *db = acl_db;
        NTSTATUS status;
        int ret = -1;
 
-       SMB_VFS_HANDLE_GET_DATA(handle, db, struct db_context, return -1);
-
        status = copy_smb_filename(talloc_tos(), smb_fname, &smb_fname_tmp);
        if (!NT_STATUS_IS_OK(status)) {
                errno = map_errno_from_nt_status(status);
@@ -284,11 +275,9 @@ static int rmdir_acl_tdb(vfs_handle_struct *handle, const char *path)
 {
 
        SMB_STRUCT_STAT sbuf;
-       struct db_context *db;
+       struct db_context *db = acl_db;
        int ret = -1;
 
-       SMB_VFS_HANDLE_GET_DATA(handle, db, struct db_context, return -1);
-
        if (lp_posix_pathnames()) {
                ret = vfs_lstat_smb_fname(handle->conn, path, &sbuf);
        } else {
@@ -299,7 +288,7 @@ static int rmdir_acl_tdb(vfs_handle_struct *handle, const char *path)
                return -1;
        }
 
-       ret = SMB_VFS_NEXT_RMDIR(handle, path);
+       ret = rmdir_acl_common(handle, path);
        if (ret == -1) {
                return -1;
        }
@@ -316,21 +305,17 @@ static int connect_acl_tdb(struct vfs_handle_struct *handle,
                                const char *service,
                                const char *user)
 {
-       struct db_context *db;
        int ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
 
        if (ret < 0) {
                return ret;
        }
 
-       if (!acl_tdb_init(&db)) {
+       if (!acl_tdb_init()) {
                SMB_VFS_NEXT_DISCONNECT(handle);
                return -1;
        }
 
-       SMB_VFS_HANDLE_SET_DATA(handle, db, free_acl_tdb_data,
-                               struct db_context, return -1);
-
        /* Ensure we have "inherit acls = yes" if we're
         * using this module. */
        DEBUG(2,("connect_acl_tdb: setting 'inherit acls = true' "
@@ -352,11 +337,9 @@ static int sys_acl_set_file_tdb(vfs_handle_struct *handle,
                               SMB_ACL_T theacl)
 {
        SMB_STRUCT_STAT sbuf;
-       struct db_context *db;
+       struct db_context *db = acl_db;
        int ret = -1;
 
-       SMB_VFS_HANDLE_GET_DATA(handle, db, struct db_context, return -1);
-
        if (lp_posix_pathnames()) {
                ret = vfs_lstat_smb_fname(handle->conn, path, &sbuf);
        } else {
@@ -387,12 +370,10 @@ static int sys_acl_set_fd_tdb(vfs_handle_struct *handle,
                             files_struct *fsp,
                             SMB_ACL_T theacl)
 {
-       struct db_context *db;
+       struct db_context *db = acl_db;
        NTSTATUS status;
        int ret;
 
-       SMB_VFS_HANDLE_GET_DATA(handle, db, struct db_context, return -1);
-
        status = vfs_stat_fsp(fsp);
        if (!NT_STATUS_IS_OK(status)) {
                return -1;
@@ -411,9 +392,9 @@ static int sys_acl_set_fd_tdb(vfs_handle_struct *handle,
 
 static struct vfs_fn_pointers vfs_acl_tdb_fns = {
        .connect_fn = connect_acl_tdb,
+       .disconnect = disconnect_acl_tdb,
        .opendir = opendir_acl_common,
        .mkdir = mkdir_acl_common,
-       .rmdir = rmdir_acl_common,
        .open = open_acl_common,
        .create_file = create_file_acl_common,
        .unlink = unlink_acl_tdb,