r25554: Convert last instances of BOOL, True and False to the standard types.
[jelmer/samba4-debian.git] / source / ntvfs / posix / vfs_posix.c
index 8dc87b160d4424b2ab2b7ab11e102262e64d430d..208c9e62b70e9117727c6b71ebcd6786f54c8880 100644 (file)
@@ -7,7 +7,7 @@
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 /*
   this implements most of the POSIX NTVFS backend
   This is the default backend
 */
 
-#include "include/includes.h"
+#include "includes.h"
 #include "vfs_posix.h"
+#include "librpc/gen_ndr/security.h"
+#include "lib/tdb/include/tdb.h"
+#include "db_wrap.h"
+#include "libcli/security/security.h"
+#include "lib/events/events.h"
 
 
 /*
 */
 static void pvfs_setup_options(struct pvfs_state *pvfs)
 {
-       int snum = pvfs->tcon->service;
+       struct share_config *scfg = pvfs->ntvfs->ctx->config;
+       const char *eadb;
+
+       if (share_bool_option(scfg, SHARE_MAP_HIDDEN, SHARE_MAP_HIDDEN_DEFAULT))
+               pvfs->flags |= PVFS_FLAG_MAP_HIDDEN;
+       if (share_bool_option(scfg, SHARE_MAP_ARCHIVE, SHARE_MAP_ARCHIVE_DEFAULT))
+               pvfs->flags |= PVFS_FLAG_MAP_ARCHIVE;
+       if (share_bool_option(scfg, SHARE_MAP_SYSTEM, SHARE_MAP_SYSTEM_DEFAULT))
+               pvfs->flags |= PVFS_FLAG_MAP_SYSTEM;
+       if (share_bool_option(scfg, SHARE_READONLY, SHARE_READONLY_DEFAULT))
+               pvfs->flags |= PVFS_FLAG_READONLY;
+       if (share_bool_option(scfg, SHARE_STRICT_SYNC, SHARE_STRICT_SYNC_DEFAULT))
+               pvfs->flags |= PVFS_FLAG_STRICT_SYNC;
+       if (share_bool_option(scfg, SHARE_STRICT_LOCKING, SHARE_STRICT_LOCKING_DEFAULT))
+               pvfs->flags |= PVFS_FLAG_STRICT_LOCKING;
+       if (share_bool_option(scfg, SHARE_CI_FILESYSTEM, SHARE_CI_FILESYSTEM_DEFAULT))
+               pvfs->flags |= PVFS_FLAG_CI_FILESYSTEM;
+       if (share_bool_option(scfg, PVFS_FAKE_OPLOCKS, PVFS_FAKE_OPLOCKS_DEFAULT))
+               pvfs->flags |= PVFS_FLAG_FAKE_OPLOCKS;
+       if (share_bool_option(scfg, PVFS_AIO, false))
+               pvfs->flags |= PVFS_FLAG_LINUX_AIO;
+
+       /* file perm options */
+       pvfs->options.create_mask       = share_int_option(scfg,
+                                                          SHARE_CREATE_MASK,
+                                                          SHARE_CREATE_MASK_DEFAULT);
+       pvfs->options.dir_mask          = share_int_option(scfg,
+                                                          SHARE_DIR_MASK,
+                                                          SHARE_DIR_MASK_DEFAULT);
+       pvfs->options.force_dir_mode    = share_int_option(scfg,
+                                                          SHARE_FORCE_DIR_MODE,
+                                                          SHARE_FORCE_DIR_MODE_DEFAULT);
+       pvfs->options.force_create_mode = share_int_option(scfg,
+                                                          SHARE_FORCE_CREATE_MODE,
+                                                          SHARE_FORCE_CREATE_MODE_DEFAULT);
+       /* this must be a power of 2 */
+       pvfs->alloc_size_rounding = share_int_option(scfg,
+                                                       PVFS_ALLOCATION_ROUNDING,
+                                                       PVFS_ALLOCATION_ROUNDING_DEFAULT);
+
+       pvfs->search.inactivity_time = share_int_option(scfg,
+                                                       PVFS_SEARCH_INACTIVITY,
+                                                       PVFS_SEARCH_INACTIVITY_DEFAULT);
+
+#if HAVE_XATTR_SUPPORT
+       if (share_bool_option(scfg, PVFS_XATTR, PVFS_XATTR_DEFAULT))
+               pvfs->flags |= PVFS_FLAG_XATTR_ENABLE;
+#endif
+
+       pvfs->sharing_violation_delay = share_int_option(scfg,
+                                                       PVFS_SHARE_DELAY,
+                                                       PVFS_SHARE_DELAY_DEFAULT);
+
+       pvfs->share_name = talloc_strdup(pvfs, scfg->name);
+
+       pvfs->fs_attribs = 
+               FS_ATTR_CASE_SENSITIVE_SEARCH | 
+               FS_ATTR_CASE_PRESERVED_NAMES |
+               FS_ATTR_UNICODE_ON_DISK |
+               FS_ATTR_SPARSE_FILES;
+
+       /* allow xattrs to be stored in a external tdb */
+       eadb = share_string_option(scfg, PVFS_EADB, NULL);
+       if (eadb != NULL) {
+               pvfs->ea_db = tdb_wrap_open(pvfs, eadb, 50000,  
+                                           TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
+               if (pvfs->ea_db != NULL) {
+                       pvfs->flags |= PVFS_FLAG_XATTR_ENABLE;
+               } else {
+                       DEBUG(0,("Failed to open eadb '%s' - %s\n",
+                                eadb, strerror(errno)));
+                       pvfs->flags &= ~PVFS_FLAG_XATTR_ENABLE;
+               }
+       }
+
+       if (pvfs->flags & PVFS_FLAG_XATTR_ENABLE) {
+               pvfs->fs_attribs |= FS_ATTR_NAMED_STREAMS;
+       }
+       if (pvfs->flags & PVFS_FLAG_XATTR_ENABLE) {
+               pvfs->fs_attribs |= FS_ATTR_PERSISTANT_ACLS;
+       }
+
+       pvfs->sid_cache.creator_owner = dom_sid_parse_talloc(pvfs, SID_CREATOR_OWNER);
+       pvfs->sid_cache.creator_group = dom_sid_parse_talloc(pvfs, SID_CREATOR_GROUP);
 
-       if (lp_map_hidden(snum))     pvfs->flags |= PVFS_FLAG_MAP_HIDDEN;
-       if (lp_map_archive(snum))    pvfs->flags |= PVFS_FLAG_MAP_ARCHIVE;
-       if (lp_map_system(snum))     pvfs->flags |= PVFS_FLAG_MAP_SYSTEM;
-       if (lp_readonly(snum))       pvfs->flags |= PVFS_FLAG_READONLY;
-       if (lp_strict_sync(snum))    pvfs->flags |= PVFS_FLAG_STRICT_SYNC;
-       if (lp_strict_locking(snum)) pvfs->flags |= PVFS_FLAG_STRICT_LOCKING;
-       if (lp_ci_filesystem(snum))  pvfs->flags |= PVFS_FLAG_CI_FILESYSTEM;
+       /* check if the system really supports xattrs */
+       if (pvfs->flags & PVFS_FLAG_XATTR_ENABLE) {
+               pvfs_xattr_probe(pvfs);
+       }
 
-       pvfs->share_name = talloc_strdup(pvfs, lp_servicename(snum));
+       /* enable an ACL backend */
+       pvfs->acl_ops = pvfs_acl_backend_byname(share_string_option(scfg, PVFS_ACL, "xattr"));
 }
 
+static int pvfs_state_destructor(struct pvfs_state *pvfs)
+{
+       struct pvfs_file *f, *fn;
+       struct pvfs_search_state *s, *sn;
+
+       /* 
+        * make sure we cleanup files and searches before anything else
+        * because there destructors need to acess the pvfs_state struct
+        */
+       for (f=pvfs->files.list; f; f=fn) {
+               fn = f->next;
+               talloc_free(f);
+       }
+
+       for (s=pvfs->search.list; s; s=sn) {
+               sn = s->next;
+               talloc_free(s);
+       }
+
+       return 0;
+}
 
 /*
   connect to a share - used when a tree_connect operation comes
@@ -54,24 +160,24 @@ static void pvfs_setup_options(struct pvfs_state *pvfs)
   that comes later)
 */
 static NTSTATUS pvfs_connect(struct ntvfs_module_context *ntvfs,
-                            struct smbsrv_request *req, const char *sharename)
+                            struct ntvfs_request *req, const char *sharename)
 {
-       struct smbsrv_tcon *tcon = req->tcon;
        struct pvfs_state *pvfs;
        struct stat st;
        char *base_directory;
        NTSTATUS status;
 
-       pvfs = talloc_zero_p(tcon, struct pvfs_state);
-       if (pvfs == NULL) {
-               return NT_STATUS_NO_MEMORY;
-       }
+       pvfs = talloc_zero(ntvfs, struct pvfs_state);
+       NT_STATUS_HAVE_NO_MEMORY(pvfs);
 
        /* for simplicity of path construction, remove any trailing slash now */
-       base_directory = talloc_strdup(pvfs, lp_pathname(tcon->service));
-       trim_string(base_directory, NULL, "/");
+       base_directory = talloc_strdup(pvfs, share_string_option(ntvfs->ctx->config, SHARE_PATH, ""));
+       NT_STATUS_HAVE_NO_MEMORY(base_directory);
+       if (strcmp(base_directory, "/") != 0) {
+               trim_string(base_directory, NULL, "/");
+       }
 
-       pvfs->tcon = tcon;
+       pvfs->ntvfs = ntvfs;
        pvfs->base_directory = base_directory;
 
        /* the directory must exist. Note that we deliberately don't
@@ -82,50 +188,53 @@ static NTSTATUS pvfs_connect(struct ntvfs_module_context *ntvfs,
                return NT_STATUS_BAD_NETWORK_NAME;
        }
 
-       tcon->fs_type = talloc_strdup(tcon, "NTFS");
-       tcon->dev_type = talloc_strdup(tcon, "A:");
+       ntvfs->ctx->fs_type = talloc_strdup(ntvfs->ctx, "NTFS");
+       NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->fs_type);
+
+       ntvfs->ctx->dev_type = talloc_strdup(ntvfs->ctx, "A:");
+       NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->dev_type);
 
        ntvfs->private_data = pvfs;
 
        pvfs->brl_context = brl_init(pvfs, 
-                                    pvfs->tcon->smb_conn->connection->server_id,  
-                                    pvfs->tcon->service,
-                                    pvfs->tcon->smb_conn->connection->messaging_ctx);
+                                    pvfs->ntvfs->ctx->server_id,
+                                    pvfs->ntvfs->ctx->msg_ctx);
        if (pvfs->brl_context == NULL) {
                return NT_STATUS_INTERNAL_DB_CORRUPTION;
        }
 
-       pvfs->odb_context = odb_init(pvfs, 
-                                    pvfs->tcon->smb_conn->connection->server_id,  
-                                    pvfs->tcon->service,
-                                    pvfs->tcon->smb_conn->connection->messaging_ctx);
+       pvfs->odb_context = odb_init(pvfs, pvfs->ntvfs->ctx);
        if (pvfs->odb_context == NULL) {
                return NT_STATUS_INTERNAL_DB_CORRUPTION;
        }
 
-       /* allocate the fnum id -> ptr tree */
-       pvfs->idtree_fnum = idr_init(pvfs);
-       if (pvfs->idtree_fnum == NULL) {
-               return NT_STATUS_NO_MEMORY;
+       /* allow this to be NULL - we just disable change notify */
+       pvfs->notify_context = notify_init(pvfs, 
+                                          pvfs->ntvfs->ctx->server_id,  
+                                          pvfs->ntvfs->ctx->msg_ctx, 
+                                          event_context_find(pvfs),
+                                          pvfs->ntvfs->ctx->config);
+
+       pvfs->sidmap = sidmap_open(pvfs);
+       if (pvfs->sidmap == NULL) {
+               return NT_STATUS_INTERNAL_DB_CORRUPTION;
        }
 
        /* allocate the search handle -> ptr tree */
-       pvfs->idtree_search = idr_init(pvfs);
-       if (pvfs->idtree_search == NULL) {
-               return NT_STATUS_NO_MEMORY;
-       }
+       pvfs->search.idtree = idr_init(pvfs);
+       NT_STATUS_HAVE_NO_MEMORY(pvfs->search.idtree);
 
        status = pvfs_mangle_init(pvfs);
-       if (!NT_STATUS_IS_OK(status)) {
-               return status;
-       }
+       NT_STATUS_NOT_OK_RETURN(status);
 
        pvfs_setup_options(pvfs);
 
+       talloc_set_destructor(pvfs, pvfs_state_destructor);
+
 #ifdef SIGXFSZ
        /* who had the stupid idea to generate a signal on a large
           file write instead of just failing it!? */
-       BlockSignals(True, SIGXFSZ);
+       BlockSignals(true, SIGXFSZ);
 #endif
 
        return NT_STATUS_OK;
@@ -134,8 +243,7 @@ static NTSTATUS pvfs_connect(struct ntvfs_module_context *ntvfs,
 /*
   disconnect from a share
 */
-static NTSTATUS pvfs_disconnect(struct ntvfs_module_context *ntvfs,
-                               struct smbsrv_tcon *tcon)
+static NTSTATUS pvfs_disconnect(struct ntvfs_module_context *ntvfs)
 {
        return NT_STATUS_OK;
 }
@@ -144,18 +252,16 @@ static NTSTATUS pvfs_disconnect(struct ntvfs_module_context *ntvfs,
   check if a directory exists
 */
 static NTSTATUS pvfs_chkpath(struct ntvfs_module_context *ntvfs,
-                            struct smbsrv_request *req, struct smb_chkpath *cp)
+                            struct ntvfs_request *req,
+                            union smb_chkpath *cp)
 {
        struct pvfs_state *pvfs = ntvfs->private_data;
        struct pvfs_filename *name;
        NTSTATUS status;
 
        /* resolve the cifs name to a posix name */
-       status = pvfs_resolve_name(pvfs, req, cp->in.path, 
-                                  PVFS_RESOLVE_NO_WILDCARD, &name);
-       if (!NT_STATUS_IS_OK(status)) {
-               return status;
-       }
+       status = pvfs_resolve_name(pvfs, req, cp->chkpath.in.path, 0, &name);
+       NT_STATUS_NOT_OK_RETURN(status);
 
        if (!name->exists) {
                return NT_STATUS_OBJECT_NAME_NOT_FOUND;
@@ -172,7 +278,7 @@ static NTSTATUS pvfs_chkpath(struct ntvfs_module_context *ntvfs,
   copy a set of files
 */
 static NTSTATUS pvfs_copy(struct ntvfs_module_context *ntvfs,
-                         struct smbsrv_request *req, struct smb_copy *cp)
+                         struct ntvfs_request *req, struct smb_copy *cp)
 {
        DEBUG(0,("pvfs_copy not implemented\n"));
        return NT_STATUS_NOT_SUPPORTED;
@@ -182,14 +288,14 @@ static NTSTATUS pvfs_copy(struct ntvfs_module_context *ntvfs,
   return print queue info
 */
 static NTSTATUS pvfs_lpq(struct ntvfs_module_context *ntvfs,
-                        struct smbsrv_request *req, union smb_lpq *lpq)
+                        struct ntvfs_request *req, union smb_lpq *lpq)
 {
        return NT_STATUS_NOT_SUPPORTED;
 }
 
 /* SMBtrans - not used on file shares */
 static NTSTATUS pvfs_trans(struct ntvfs_module_context *ntvfs,
-                          struct smbsrv_request *req, struct smb_trans2 *trans2)
+                          struct ntvfs_request *req, struct smb_trans2 *trans2)
 {
        return NT_STATUS_ACCESS_DENIED;
 }
@@ -201,6 +307,7 @@ NTSTATUS ntvfs_posix_init(void)
 {
        NTSTATUS ret;
        struct ntvfs_ops ops;
+       NTVFS_CURRENT_CRITICAL_SIZES(vers);
 
        ZERO_STRUCT(ops);
 
@@ -236,18 +343,28 @@ NTSTATUS ntvfs_posix_init(void)
        ops.trans = pvfs_trans;
        ops.logoff = pvfs_logoff;
        ops.async_setup = pvfs_async_setup;
+       ops.cancel = pvfs_cancel;
+       ops.notify = pvfs_notify;
 
        /* register ourselves with the NTVFS subsystem. We register
           under the name 'default' as we wish to be the default
           backend, and also register as 'posix' */
        ops.name = "default";
-       ret = register_backend("ntvfs", &ops);
+       ret = ntvfs_register(&ops, &vers);
+
+       if (!NT_STATUS_IS_OK(ret)) {
+               DEBUG(0,("Failed to register POSIX backend as '%s'!\n", ops.name));
+       }
 
        ops.name = "posix";
-       ret = register_backend("ntvfs", &ops);
+       ret = ntvfs_register(&ops, &vers);
 
        if (!NT_STATUS_IS_OK(ret)) {
-               DEBUG(0,("Failed to register POSIX backend!\n"));
+               DEBUG(0,("Failed to register POSIX backend as '%s'!\n", ops.name));
+       }
+
+       if (NT_STATUS_IS_OK(ret)) {
+               ret = ntvfs_common_init();
        }
 
        return ret;