s4-loadparm: 2nd half of lp_ to lpcfg_ conversion
[sfrench/samba-autobuild/.git] / source4 / ntvfs / posix / vfs_posix.c
index 2c414065cb2634bb9527b051c72b8021c6fbf6f5..1e0efcddc8481c34ac2d7db1c90dc7f7f9ab7ea2 100644 (file)
 #include "includes.h"
 #include "vfs_posix.h"
 #include "librpc/gen_ndr/security.h"
-#include "lib/tdb/include/tdb.h"
-#include "db_wrap.h"
+#include "../tdb/include/tdb.h"
+#include "tdb_wrap.h"
 #include "libcli/security/security.h"
 #include "lib/events/events.h"
-
+#include "param/param.h"
 
 /*
   setup config options for a posix share
@@ -39,6 +39,7 @@ static void pvfs_setup_options(struct pvfs_state *pvfs)
 {
        struct share_config *scfg = pvfs->ntvfs->ctx->config;
        const char *eadb;
+       bool def_perm_override = false;
 
        if (share_bool_option(scfg, SHARE_MAP_HIDDEN, SHARE_MAP_HIDDEN_DEFAULT))
                pvfs->flags |= PVFS_FLAG_MAP_HIDDEN;
@@ -56,9 +57,18 @@ static void pvfs_setup_options(struct pvfs_state *pvfs)
                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))
+       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,
@@ -90,6 +100,14 @@ static void pvfs_setup_options(struct pvfs_state *pvfs)
                                                        PVFS_SHARE_DELAY,
                                                        PVFS_SHARE_DELAY_DEFAULT);
 
+       pvfs->oplock_break_timeout = share_int_option(scfg,
+                                                     PVFS_OPLOCK_TIMEOUT,
+                                                     PVFS_OPLOCK_TIMEOUT_DEFAULT);
+
+       pvfs->writetime_delay = share_int_option(scfg,
+                                                PVFS_WRITETIME_DELAY,
+                                                PVFS_WRITETIME_DELAY_DEFAULT);
+
        pvfs->share_name = talloc_strdup(pvfs, scfg->name);
 
        pvfs->fs_attribs = 
@@ -160,12 +178,42 @@ 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);
+       NT_STATUS_NOT_OK_RETURN(status);
 
        pvfs = talloc_zero(ntvfs, struct pvfs_state);
        NT_STATUS_HAVE_NO_MEMORY(pvfs);
@@ -194,10 +242,16 @@ 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->ntvfs->ctx->server_id,
+                                    pvfs->ntvfs->ctx->lp_ctx,
                                     pvfs->ntvfs->ctx->msg_ctx);
        if (pvfs->brl_context == NULL) {
                return NT_STATUS_INTERNAL_DB_CORRUPTION;
@@ -212,11 +266,14 @@ 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, 
-                                          event_context_find(pvfs),
+                                          pvfs->ntvfs->ctx->lp_ctx,
+                                          pvfs->ntvfs->ctx->event_ctx,
                                           pvfs->ntvfs->ctx->config);
 
-       pvfs->sidmap = sidmap_open(pvfs);
-       if (pvfs->sidmap == NULL) {
+       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;
        }
 
@@ -234,7 +291,7 @@ static NTSTATUS pvfs_connect(struct ntvfs_module_context *ntvfs,
 #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;
@@ -255,7 +312,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;