lib: modules: Change XXX_init interface from XXX_init(void) to XXX_init(TALLOC_CTX *)
[ambi/samba-autobuild/.git] / source4 / ntvfs / posix / vfs_posix.c
index 601c876cfb9aa2bc28bfa1ec611ccc72ef1d0d9c..4133723c50a78cac8f1ed9f2f4e66f3b2915cdbb 100644 (file)
@@ -26,9 +26,8 @@
 #include "includes.h"
 #include "vfs_posix.h"
 #include "librpc/gen_ndr/security.h"
-#include "../tdb/include/tdb.h"
-#include "tdb_wrap.h"
-#include "../lib/util/util_ldb.h"
+#include <tdb.h>
+#include "lib/tdb_wrap/tdb_wrap.h"
 #include "libcli/security/security.h"
 #include "lib/events/events.h"
 #include "param/param.h"
@@ -39,7 +38,9 @@
 static void pvfs_setup_options(struct pvfs_state *pvfs)
 {
        struct share_config *scfg = pvfs->ntvfs->ctx->config;
-       const char *eadb;
+       char *eadb;
+       char *xattr_backend;
+       bool def_perm_override = false;
 
        if (share_bool_option(scfg, SHARE_MAP_HIDDEN, SHARE_MAP_HIDDEN_DEFAULT))
                pvfs->flags |= PVFS_FLAG_MAP_HIDDEN;
@@ -60,6 +61,15 @@ static void pvfs_setup_options(struct pvfs_state *pvfs)
        if (share_bool_option(scfg, PVFS_AIO, false))
                pvfs->flags |= PVFS_FLAG_LINUX_AIO;
 
+#if defined(O_DIRECTORY) && defined(O_NOFOLLOW)
+       /* set PVFS_PERM_OVERRIDE by default only if the system
+        * supports the necessary capabilities to make it secure
+        */
+       def_perm_override = true;
+#endif
+       if (share_bool_option(scfg, PVFS_PERM_OVERRIDE, def_perm_override))
+               pvfs->flags |= PVFS_FLAG_PERM_OVERRIDE;
+
        /* file perm options */
        pvfs->options.create_mask       = share_int_option(scfg,
                                                           SHARE_CREATE_MASK,
@@ -104,14 +114,16 @@ static void pvfs_setup_options(struct pvfs_state *pvfs)
        pvfs->fs_attribs = 
                FS_ATTR_CASE_SENSITIVE_SEARCH | 
                FS_ATTR_CASE_PRESERVED_NAMES |
-               FS_ATTR_UNICODE_ON_DISK |
-               FS_ATTR_SPARSE_FILES;
+               FS_ATTR_UNICODE_ON_DISK;
 
        /* allow xattrs to be stored in a external tdb */
-       eadb = share_string_option(scfg, PVFS_EADB, NULL);
+       eadb = share_string_option(pvfs, scfg, PVFS_EADB, NULL);
        if (eadb != NULL) {
-               pvfs->ea_db = tdb_wrap_open(pvfs, eadb, 50000,  
-                                           TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
+               pvfs->ea_db = tdb_wrap_open(
+                       pvfs, eadb, 50000,
+                       lpcfg_tdb_flags(pvfs->ntvfs->ctx->lp_ctx, TDB_DEFAULT),
+                       O_RDWR|O_CREAT, 0600);
+               TALLOC_FREE(eadb);
                if (pvfs->ea_db != NULL) {
                        pvfs->flags |= PVFS_FLAG_XATTR_ENABLE;
                } else {
@@ -137,7 +149,9 @@ static void pvfs_setup_options(struct pvfs_state *pvfs)
        }
 
        /* enable an ACL backend */
-       pvfs->acl_ops = pvfs_acl_backend_byname(share_string_option(scfg, PVFS_ACL, "xattr"));
+       xattr_backend = share_string_option(pvfs, scfg, PVFS_ACL, "xattr");
+       pvfs->acl_ops = pvfs_acl_backend_byname(xattr_backend);
+       TALLOC_FREE(xattr_backend);
 }
 
 static int pvfs_state_destructor(struct pvfs_state *pvfs)
@@ -169,25 +183,48 @@ static int pvfs_state_destructor(struct pvfs_state *pvfs)
   that comes later)
 */
 static NTSTATUS pvfs_connect(struct ntvfs_module_context *ntvfs,
-                            struct ntvfs_request *req, const char *sharename)
+                            struct ntvfs_request *req,
+                            union smb_tcon* tcon)
 {
        struct pvfs_state *pvfs;
        struct stat st;
        char *base_directory;
        NTSTATUS status;
+       const char *sharename;
+
+       switch (tcon->generic.level) {
+       case RAW_TCON_TCON:
+               sharename = tcon->tcon.in.service;
+               break;
+       case RAW_TCON_TCONX:
+               sharename = tcon->tconx.in.path;
+               break;
+       case RAW_TCON_SMB2:
+               sharename = tcon->smb2.in.path;
+               break;
+       default:
+               return NT_STATUS_INVALID_LEVEL;
+       }
+
+       if (strncmp(sharename, "\\\\", 2) == 0) {
+               char *p = strchr(sharename+2, '\\');
+               if (p) {
+                       sharename = p + 1;
+               }
+       }
 
        /*
         * TODO: call this from ntvfs_posix_init()
         *       but currently we don't have a lp_ctx there
         */
-       status = pvfs_acl_init(ntvfs->ctx->lp_ctx);
+       status = pvfs_acl_init();
        NT_STATUS_NOT_OK_RETURN(status);
 
        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, share_string_option(ntvfs->ctx->config, SHARE_PATH, ""));
+       base_directory = share_string_option(pvfs, ntvfs->ctx->config, SHARE_PATH, "");
        NT_STATUS_HAVE_NO_MEMORY(base_directory);
        if (strcmp(base_directory, "/") != 0) {
                trim_string(base_directory, NULL, "/");
@@ -210,9 +247,14 @@ static NTSTATUS pvfs_connect(struct ntvfs_module_context *ntvfs,
        ntvfs->ctx->dev_type = talloc_strdup(ntvfs->ctx, "A:");
        NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->dev_type);
 
+       if (tcon->generic.level == RAW_TCON_TCONX) {
+               tcon->tconx.out.fs_type = ntvfs->ctx->fs_type;
+               tcon->tconx.out.dev_type = ntvfs->ctx->dev_type;
+       }
+
        ntvfs->private_data = pvfs;
 
-       pvfs->brl_context = brl_init(pvfs, 
+       pvfs->brl_context = brlock_init(pvfs, 
                                     pvfs->ntvfs->ctx->server_id,
                                     pvfs->ntvfs->ctx->lp_ctx,
                                     pvfs->ntvfs->ctx->msg_ctx);
@@ -229,17 +271,10 @@ static NTSTATUS pvfs_connect(struct ntvfs_module_context *ntvfs,
        pvfs->notify_context = notify_init(pvfs, 
                                           pvfs->ntvfs->ctx->server_id,  
                                           pvfs->ntvfs->ctx->msg_ctx, 
-                                          pvfs->ntvfs->ctx->lp_ctx, 
+                                          pvfs->ntvfs->ctx->lp_ctx,
                                           pvfs->ntvfs->ctx->event_ctx,
                                           pvfs->ntvfs->ctx->config);
 
-       pvfs->wbc_ctx = wbc_init(pvfs,
-                                pvfs->ntvfs->ctx->msg_ctx,
-                                pvfs->ntvfs->ctx->event_ctx);
-       if (pvfs->wbc_ctx == NULL) {
-               return NT_STATUS_INTERNAL_DB_CORRUPTION;
-       }
-
        /* allocate the search handle -> ptr tree */
        pvfs->search.idtree = idr_init(pvfs);
        NT_STATUS_HAVE_NO_MEMORY(pvfs->search.idtree);
@@ -275,7 +310,8 @@ static NTSTATUS pvfs_chkpath(struct ntvfs_module_context *ntvfs,
                             struct ntvfs_request *req,
                             union smb_chkpath *cp)
 {
-       struct pvfs_state *pvfs = ntvfs->private_data;
+       struct pvfs_state *pvfs = talloc_get_type(ntvfs->private_data,
+                                 struct pvfs_state);
        struct pvfs_filename *name;
        NTSTATUS status;
 
@@ -323,7 +359,7 @@ static NTSTATUS pvfs_trans(struct ntvfs_module_context *ntvfs,
 /*
   initialialise the POSIX disk backend, registering ourselves with the ntvfs subsystem
  */
-NTSTATUS ntvfs_posix_init(void)
+NTSTATUS ntvfs_posix_init(TALLOC_CTX *ctx)
 {
        NTSTATUS ret;
        struct ntvfs_ops ops;
@@ -334,37 +370,37 @@ NTSTATUS ntvfs_posix_init(void)
        ops.type = NTVFS_DISK;
        
        /* fill in all the operations */
-       ops.connect = pvfs_connect;
-       ops.disconnect = pvfs_disconnect;
-       ops.unlink = pvfs_unlink;
-       ops.chkpath = pvfs_chkpath;
-       ops.qpathinfo = pvfs_qpathinfo;
-       ops.setpathinfo = pvfs_setpathinfo;
-       ops.open = pvfs_open;
-       ops.mkdir = pvfs_mkdir;
-       ops.rmdir = pvfs_rmdir;
-       ops.rename = pvfs_rename;
-       ops.copy = pvfs_copy;
-       ops.ioctl = pvfs_ioctl;
-       ops.read = pvfs_read;
-       ops.write = pvfs_write;
-       ops.seek = pvfs_seek;
-       ops.flush = pvfs_flush; 
-       ops.close = pvfs_close;
-       ops.exit = pvfs_exit;
-       ops.lock = pvfs_lock;
-       ops.setfileinfo = pvfs_setfileinfo;
-       ops.qfileinfo = pvfs_qfileinfo;
-       ops.fsinfo = pvfs_fsinfo;
-       ops.lpq = pvfs_lpq;
-       ops.search_first = pvfs_search_first;
-       ops.search_next = pvfs_search_next;
-       ops.search_close = pvfs_search_close;
-       ops.trans = pvfs_trans;
-       ops.logoff = pvfs_logoff;
-       ops.async_setup = pvfs_async_setup;
-       ops.cancel = pvfs_cancel;
-       ops.notify = pvfs_notify;
+       ops.connect_fn = pvfs_connect;
+       ops.disconnect_fn = pvfs_disconnect;
+       ops.unlink_fn = pvfs_unlink;
+       ops.chkpath_fn = pvfs_chkpath;
+       ops.qpathinfo_fn = pvfs_qpathinfo;
+       ops.setpathinfo_fn = pvfs_setpathinfo;
+       ops.open_fn = pvfs_open;
+       ops.mkdir_fn = pvfs_mkdir;
+       ops.rmdir_fn = pvfs_rmdir;
+       ops.rename_fn = pvfs_rename;
+       ops.copy_fn = pvfs_copy;
+       ops.ioctl_fn = pvfs_ioctl;
+       ops.read_fn = pvfs_read;
+       ops.write_fn = pvfs_write;
+       ops.seek_fn = pvfs_seek;
+       ops.flush_fn = pvfs_flush;
+       ops.close_fn = pvfs_close;
+       ops.exit_fn = pvfs_exit;
+       ops.lock_fn = pvfs_lock;
+       ops.setfileinfo_fn = pvfs_setfileinfo;
+       ops.qfileinfo_fn = pvfs_qfileinfo;
+       ops.fsinfo_fn = pvfs_fsinfo;
+       ops.lpq_fn = pvfs_lpq;
+       ops.search_first_fn = pvfs_search_first;
+       ops.search_next_fn = pvfs_search_next;
+       ops.search_close_fn = pvfs_search_close;
+       ops.trans_fn = pvfs_trans;
+       ops.logoff_fn = pvfs_logoff;
+       ops.async_setup_fn = pvfs_async_setup;
+       ops.cancel_fn = pvfs_cancel;
+       ops.notify_fn = pvfs_notify;
 
        /* register ourselves with the NTVFS subsystem. We register
           under the name 'default' as we wish to be the default