s4: pass down a memory context when performing share_string_option, to allow substitu...
authorGarming Sam <garming@catalyst.net.nz>
Thu, 16 Jan 2014 21:16:12 +0000 (10:16 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 19 Feb 2014 21:11:00 +0000 (10:11 +1300)
Signed-off-by: Garming Sam <garming@catalyst.net.nz>
Change-Id: I24b36db3ac11834c3268b2da929e214c10268b16
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Nadezhda Ivanova <nivanova@samba.org>
17 files changed:
source4/ntvfs/cifs/vfs_cifs.c
source4/ntvfs/cifs_posix_cli/vfs_cifs_posix.c
source4/ntvfs/ipc/rap_server.c
source4/ntvfs/posix/vfs_posix.c
source4/ntvfs/simple/vfs_simple.c
source4/ntvfs/smb2/vfs_smb2.c
source4/ntvfs/sysdep/sys_lease.c
source4/ntvfs/sysdep/sys_notify.c
source4/param/share.c
source4/param/share.h
source4/param/share_classic.c
source4/param/share_ldb.c
source4/rpc_server/common/share_info.c
source4/rpc_server/srvsvc/dcesrv_srvsvc.c
source4/rpc_server/srvsvc/srvsvc_ntvfs.c
source4/smb_server/smb/service.c
source4/smb_server/smb2/tcon.c

index 552f664d8a1aba87c57bf0c96272439a56e27e6d..16bbf970b49f28ff48453ed4f22a6143b342c535 100644 (file)
@@ -155,6 +155,12 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs,
        bool machine_account;
        bool s4u2proxy;
        const char* sharename;
+       TALLOC_CTX *tmp_ctx;
+
+       tmp_ctx = talloc_new(req);
+       if (tmp_ctx == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
 
        switch (tcon->generic.level) {
        case RAW_TCON_TCON:
@@ -180,11 +186,11 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs,
        /* Here we need to determine which server to connect to.
         * For now we use parametric options, type cifs.
         */
-       host = share_string_option(scfg, CIFS_SERVER, NULL);
-       user = share_string_option(scfg, CIFS_USER, NULL);
-       pass = share_string_option(scfg, CIFS_PASSWORD, NULL);
-       domain = share_string_option(scfg, CIFS_DOMAIN, NULL);
-       remote_share = share_string_option(scfg, CIFS_SHARE, NULL);
+       host = share_string_option(tmp_ctx, scfg, CIFS_SERVER, NULL);
+       user = share_string_option(tmp_ctx, scfg, CIFS_USER, NULL);
+       pass = share_string_option(tmp_ctx, scfg, CIFS_PASSWORD, NULL);
+       domain = share_string_option(tmp_ctx, scfg, CIFS_DOMAIN, NULL);
+       remote_share = share_string_option(tmp_ctx, scfg, CIFS_SHARE, NULL);
        if (!remote_share) {
                remote_share = sharename;
        }
@@ -194,6 +200,7 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs,
 
        p = talloc_zero(ntvfs, struct cvfs_private);
        if (!p) {
+               TALLOC_FREE(tmp_ctx);
                return NT_STATUS_NO_MEMORY;
        }
 
@@ -208,6 +215,7 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs,
                DEBUG(5, ("CIFS backend: Using specified password\n"));
                credentials = cli_credentials_init(p);
                if (!credentials) {
+                       TALLOC_FREE(tmp_ctx);
                        return NT_STATUS_NO_MEMORY;
                }
                cli_credentials_set_conf(credentials, ntvfs->ctx->lp_ctx);
@@ -225,6 +233,7 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs,
                }
                status = cli_credentials_set_machine_account(credentials, ntvfs->ctx->lp_ctx);
                if (!NT_STATUS_IS_OK(status)) {
+                       TALLOC_FREE(tmp_ctx);
                        return status;
                }
        } else if (req->session_info->credentials) {
@@ -256,6 +265,7 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs,
                }
                status = cli_credentials_set_machine_account(credentials, ntvfs->ctx->lp_ctx);
                if (!NT_STATUS_IS_OK(status)) {
+                       TALLOC_FREE(tmp_ctx);
                        return status;
                }
                cli_credentials_invalidate_ccache(credentials, CRED_SPECIFIED);
@@ -272,11 +282,13 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs,
                        status = NT_STATUS_CROSSREALM_DELEGATION_FAILURE;
                        DEBUG(1,("S4U2Proxy: cli_credentials_get_ccache() gave: ret[%d] str[%s] - %s\n",
                                ret, err_str, nt_errstr(status)));
+                       TALLOC_FREE(tmp_ctx);
                        return status;
                }
 
        } else {
                DEBUG(1,("CIFS backend: NO delegated credentials found: You must supply server, user and password or the client must supply delegated credentials\n"));
+               TALLOC_FREE(tmp_ctx);
                return NT_STATUS_INTERNAL_ERROR;
        }
 
@@ -302,7 +314,10 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs,
                                          lpcfg_resolve_context(ntvfs->ctx->lp_ctx),
                                          ntvfs->ctx->event_ctx);
        status = smb_composite_connect_recv(creq, p);
-       NT_STATUS_NOT_OK_RETURN(status);
+       if (!NT_STATUS_IS_OK(status)) {
+               TALLOC_FREE(tmp_ctx);
+               return status;
+       }
 
        p->tree = io.out.tree;
 
@@ -311,9 +326,15 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs,
        p->ntvfs = ntvfs;
 
        ntvfs->ctx->fs_type = talloc_strdup(ntvfs->ctx, "NTFS");
-       NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->fs_type);
+       if (!ntvfs->ctx->fs_type) {
+               TALLOC_FREE(tmp_ctx);
+               return NT_STATUS_NO_MEMORY;
+       }
        ntvfs->ctx->dev_type = talloc_strdup(ntvfs->ctx, "A:");
-       NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->dev_type);
+       if (!ntvfs->ctx->dev_type) {
+               TALLOC_FREE(tmp_ctx);
+               return NT_STATUS_NO_MEMORY;
+       }
 
        if (tcon->generic.level == RAW_TCON_TCONX) {
                tcon->tconx.out.fs_type = ntvfs->ctx->fs_type;
@@ -327,6 +348,7 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs,
 
        p->map_trans2 = share_bool_option(scfg, CIFS_MAP_TRANS2, CIFS_MAP_TRANS2_DEFAULT);
 
+       TALLOC_FREE(tmp_ctx);
        return NT_STATUS_OK;
 }
 
index 8c5a53b6f8e8239a073a47ba40899f5b9559be1b..d384dbbca058b018cc9ec0fe948ecd7d2ebee978 100644 (file)
@@ -81,7 +81,7 @@ static NTSTATUS cifspsx_connect(struct ntvfs_module_context *ntvfs,
        NT_STATUS_HAVE_NO_MEMORY(p);
        p->ntvfs = ntvfs;
        p->next_search_handle = 0;
-       p->connectpath = talloc_strdup(p, share_string_option(scfg, SHARE_PATH, ""));
+       p->connectpath = share_string_option(p, scfg, SHARE_PATH, "");
        p->open_files = NULL;
        p->search = NULL;
 
index 8f36c09ebcac96fbaf062be9ab87b21efc6efec4..3a133f568da6f1cc3acc88c9deae30fdb4a5c120 100644 (file)
@@ -72,7 +72,7 @@ NTSTATUS rap_netshareenum(TALLOC_CTX *mem_ctx,
                        sizeof(r->out.info[0].info1.share_name));
                r->out.info[i].info1.reserved1 = 0;
                r->out.info[i].info1.share_type = dcesrv_common_get_share_type(mem_ctx, NULL, scfg);
-               r->out.info[i].info1.comment = talloc_strdup(mem_ctx, share_string_option(scfg, SHARE_COMMENT, ""));
+               r->out.info[i].info1.comment = share_string_option(mem_ctx, scfg, SHARE_COMMENT, "");
                talloc_free(scfg);
                j++;
        }
index 2ca024b6187e8dc23f0a8da9cb65deec6f332533..519ca98f39de2227978656e7b30712d96b202d58 100644 (file)
@@ -38,7 +38,8 @@
 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))
@@ -117,11 +118,12 @@ static void pvfs_setup_options(struct pvfs_state *pvfs)
                FS_ATTR_SPARSE_FILES;
 
        /* 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->ntvfs->ctx->lp_ctx);
+               TALLOC_FREE(eadb);
                if (pvfs->ea_db != NULL) {
                        pvfs->flags |= PVFS_FLAG_XATTR_ENABLE;
                } else {
@@ -147,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)
@@ -220,7 +224,7 @@ static NTSTATUS pvfs_connect(struct ntvfs_module_context *ntvfs,
        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, "/");
index a652494dc17a02cb3e810bd90b4bc78aa99f70fb..38ecdfe66b31f049d1cf4143e4aba562a0df4443 100644 (file)
@@ -80,7 +80,7 @@ static NTSTATUS svfs_connect(struct ntvfs_module_context *ntvfs,
        NT_STATUS_HAVE_NO_MEMORY(p);
        p->ntvfs = ntvfs;
        p->next_search_handle = 0;
-       p->connectpath = talloc_strdup(p, share_string_option(scfg, SHARE_PATH, ""));
+       p->connectpath = share_string_option(p, scfg, SHARE_PATH, "");
        p->open_files = NULL;
        p->search = NULL;
 
index 9447b2478c544ac2d29419c14b2636ebf84ff90c..bb9a235e3260bdb587ed7d7c62ecd8c297d045ab 100644 (file)
@@ -167,6 +167,12 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs,
        struct cli_credentials *credentials;
        bool machine_account;
        struct smbcli_options options;
+       TALLOC_CTX *tmp_ctx;
+
+       tmp_ctx = talloc_new(req);
+       if (tmp_ctx == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
 
        switch (tcon->generic.level) {
        case RAW_TCON_TCON:
@@ -179,6 +185,7 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs,
                sharename = tcon->smb2.in.path;
                break;
        default:
+               TALLOC_FREE(tmp_ctx);
                return NT_STATUS_INVALID_LEVEL;
        }
 
@@ -192,11 +199,11 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs,
        /* Here we need to determine which server to connect to.
         * For now we use parametric options, type cifs.
         */
-       host = share_string_option(scfg, SMB2_SERVER, NULL);
-       user = share_string_option(scfg, SMB2_USER, NULL);
-       pass = share_string_option(scfg, SMB2_PASSWORD, NULL);
-       domain = share_string_option(scfg, SMB2_DOMAIN, NULL);
-       remote_share = share_string_option(scfg, SMB2_SHARE, NULL);
+       host = share_string_option(tmp_ctx, scfg, SMB2_SERVER, NULL);
+       user = share_string_option(tmp_ctx, scfg, SMB2_USER, NULL);
+       pass = share_string_option(tmp_ctx, scfg, SMB2_PASSWORD, NULL);
+       domain = share_string_option(tmp_ctx, scfg, SMB2_DOMAIN, NULL);
+       remote_share = share_string_option(tmp_ctx, scfg, SMB2_SHARE, NULL);
        if (!remote_share) {
                remote_share = sharename;
        }
@@ -205,6 +212,7 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs,
 
        p = talloc_zero(ntvfs, struct cvfs_private);
        if (!p) {
+               TALLOC_FREE(tmp_ctx);
                return NT_STATUS_NO_MEMORY;
        }
 
@@ -212,6 +220,7 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs,
 
        if (!host) {
                DEBUG(1,("CIFS backend: You must supply server\n"));
+               TALLOC_FREE(tmp_ctx);
                return NT_STATUS_INVALID_PARAMETER;
        } 
        
@@ -219,6 +228,7 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs,
                DEBUG(5, ("CIFS backend: Using specified password\n"));
                credentials = cli_credentials_init(p);
                if (!credentials) {
+                       TALLOC_FREE(tmp_ctx);
                        return NT_STATUS_NO_MEMORY;
                }
                cli_credentials_set_conf(credentials, ntvfs->ctx->lp_ctx);
@@ -236,6 +246,7 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs,
                }
                status = cli_credentials_set_machine_account(credentials, ntvfs->ctx->lp_ctx);
                if (!NT_STATUS_IS_OK(status)) {
+                       TALLOC_FREE(tmp_ctx);
                        return status;
                }
        } else if (req->session_info->credentials) {
@@ -243,6 +254,7 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs,
                credentials = req->session_info->credentials;
        } else {
                DEBUG(1,("CIFS backend: NO delegated credentials found: You must supply server, user and password or the client must supply delegated credentials\n"));
+               TALLOC_FREE(tmp_ctx);
                return NT_STATUS_INVALID_PARAMETER;
        }
 
@@ -257,19 +269,31 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs,
                        ntvfs->ctx->event_ctx, &options,
                        lpcfg_socket_options(ntvfs->ctx->lp_ctx),
                        lpcfg_gensec_settings(p, ntvfs->ctx->lp_ctx));
-       NT_STATUS_NOT_OK_RETURN(status);
+       if (!NT_STATUS_IS_OK(status)) {
+               TALLOC_FREE(tmp_ctx);
+               return status;
+       }
 
        status = smb2_get_roothandle(tree, &p->roothandle);
-       NT_STATUS_NOT_OK_RETURN(status);
+       if (!NT_STATUS_IS_OK(status)) {
+               TALLOC_FREE(tmp_ctx);
+               return status;
+       }
 
        p->tree = tree;
        p->transport = p->tree->session->transport;
        p->ntvfs = ntvfs;
 
        ntvfs->ctx->fs_type = talloc_strdup(ntvfs->ctx, "NTFS");
-       NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->fs_type);
+       if (!ntvfs->ctx->fs_type) {
+               TALLOC_FREE(tmp_ctx);
+               return NT_STATUS_NO_MEMORY;
+       }
        ntvfs->ctx->dev_type = talloc_strdup(ntvfs->ctx, "A:");
-       NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->dev_type);
+       if (!ntvfs->ctx->dev_type) {
+               TALLOC_FREE(tmp_ctx);
+               return NT_STATUS_NO_MEMORY;
+       }
 
        if (tcon->generic.level == RAW_TCON_TCONX) {
                tcon->tconx.out.fs_type = ntvfs->ctx->fs_type;
@@ -280,6 +304,8 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs,
        /* TODO: enable oplocks 
        smbcli_oplock_handler(p->transport, oplock_handler, p);
        */
+
+       TALLOC_FREE(tmp_ctx);
        return NT_STATUS_OK;
 }
 
index 9adb89827422bbd62b59dfbcc4f53c8b3122510c..1c8c33f3cf1736a5318f0dd5d5576060c967e706 100644 (file)
@@ -48,6 +48,7 @@ _PUBLIC_ struct sys_lease_context *sys_lease_context_create(struct share_config
        const char *bname;
        int i;
        NTSTATUS status;
+       TALLOC_CTX * tmp_ctx;
 
        if (num_backends == 0) {
                return NULL;
@@ -62,11 +63,16 @@ _PUBLIC_ struct sys_lease_context *sys_lease_context_create(struct share_config
                return NULL;
        }
 
+       tmp_ctx = talloc_new(ctx);
+       if (tmp_ctx == NULL) {
+               return NULL;
+       }
+
        ctx->event_ctx = ev;
        ctx->msg_ctx = msg;
        ctx->break_send = break_send;
 
-       bname = share_string_option(scfg, LEASE_BACKEND, NULL);
+       bname = share_string_option(tmp_ctx, scfg, LEASE_BACKEND, NULL);
        if (!bname) {
                talloc_free(ctx);
                return NULL;
@@ -90,6 +96,7 @@ _PUBLIC_ struct sys_lease_context *sys_lease_context_create(struct share_config
                return NULL;
        }
 
+       TALLOC_FREE(tmp_ctx);
        return ctx;
 }
 
index 00300cd25a6332b4111bc96f1698a25cc50040c1..dee3295de80fee8353212fcfebf2b3513c0c36b0 100644 (file)
@@ -62,7 +62,7 @@ _PUBLIC_ struct sys_notify_context *sys_notify_context_create(struct share_confi
 
        ctx->ev = ev;
 
-       bname = share_string_option(scfg, NOTIFY_BACKEND, NULL);
+       bname = share_string_option(ctx, scfg, NOTIFY_BACKEND, NULL);
        if (!bname) {
                if (num_backends) {
                        bname = backends[0].name;
index da0470d5606c5924bd2c34e95ce4e7ce60dd3eae..2bf4b89c23cc25ffdac544b82095b29185f8ee15 100644 (file)
@@ -24,9 +24,9 @@
 #include "param/param.h"
 #include "lib/util/samba_modules.h"
 
-const char *share_string_option(struct share_config *scfg, const char *opt_name, const char *defval)
+char *share_string_option(TALLOC_CTX *mem_ctx, struct share_config *scfg, const char *opt_name, const char *defval)
 {
-       return scfg->ctx->ops->string_option(scfg, opt_name, defval);
+       return scfg->ctx->ops->string_option(mem_ctx, scfg, opt_name, defval);
 }
 
 int share_int_option(struct share_config *scfg, const char *opt_name, int defval)
index ab20c8a2441c1d87549157ba1d14eaa79cb27448..9fa37289d28493fa424af2d7f843264851009c08 100644 (file)
@@ -54,7 +54,7 @@ struct share_ops {
        NTSTATUS (*init)(TALLOC_CTX *, const struct share_ops*, struct tevent_context *ev_ctx,
                         struct loadparm_context *lp_ctx,
                         struct share_context **);
-       const char *(*string_option)(struct share_config *, const char *, const char *);
+       char *(*string_option)(TALLOC_CTX *, struct share_config *, const char *, const char *);
        int (*int_option)(struct share_config *, const char *, int);
        bool (*bool_option)(struct share_config *, const char *, bool);
        const char **(*string_list_option)(TALLOC_CTX *, struct share_config *, const char *);
@@ -67,7 +67,7 @@ struct share_ops {
 
 struct loadparm_context;
 
-const char *share_string_option(struct share_config *scfg, const char *opt_name, const char *defval);
+char *share_string_option(TALLOC_CTX *mem_ctx, struct share_config *scfg, const char *opt_name, const char *defval);
 int share_int_option(struct share_config *scfg, const char *opt_name, int defval);
 bool share_bool_option(struct share_config *scfg, const char *opt_name, bool defval);
 const char **share_string_list_option(TALLOC_CTX *mem_ctx, struct share_config *scfg, const char *opt_name);
index 9f00a6847ff1102547631fec1ef5804d20f8852a..74a454e5e1689078d30cb05a0dd99a5f9ae39040 100644 (file)
@@ -43,9 +43,10 @@ static NTSTATUS sclassic_init(TALLOC_CTX *mem_ctx,
        return NT_STATUS_OK;
 }
 
-static const char *sclassic_string_option(struct share_config *scfg, 
-                                         const char *opt_name, 
-                                         const char *defval)
+static char *sclassic_string_option(TALLOC_CTX *mem_ctx,
+                                   struct share_config *scfg,
+                                   const char *opt_name,
+                                   const char *defval)
 {
        struct loadparm_service *s = talloc_get_type(scfg->opaque, 
                                                     struct loadparm_service);
@@ -68,11 +69,11 @@ static const char *sclassic_string_option(struct share_config *scfg,
                        ret = defval;
                }
                talloc_free(parm);
-               return ret;
+               return talloc_strdup(mem_ctx, ret);
        }
 
        if (strcmp(opt_name, SHARE_NAME) == 0) {
-               return scfg->name;
+               return talloc_strdup(mem_ctx, scfg->name);
        }
 
        if (strcmp(opt_name, SHARE_PATH) == 0) {
@@ -84,27 +85,27 @@ static const char *sclassic_string_option(struct share_config *scfg,
        }
 
        if (strcmp(opt_name, SHARE_VOLUME) == 0) {
-               return lpcfg_volume_label(s, lpcfg_default_service(lp_ctx));
+               return talloc_strdup(mem_ctx, lpcfg_volume_label(s, lpcfg_default_service(lp_ctx)));
        }
 
        if (strcmp(opt_name, SHARE_TYPE) == 0) {
                if (lpcfg_printable(s, lpcfg_default_service(lp_ctx))) {
-                       return "PRINTER";
+                       return talloc_strdup(mem_ctx, "PRINTER");
                }
                if (strcmp("NTFS", lpcfg_fstype(s, lpcfg_default_service(lp_ctx))) == 0) {
-                       return "DISK";
+                       return talloc_strdup(mem_ctx, "DISK");
                }
-               return lpcfg_fstype(s, lpcfg_default_service(lp_ctx));
+               return talloc_strdup(mem_ctx, lpcfg_fstype(s, lpcfg_default_service(lp_ctx)));
        }
 
        if (strcmp(opt_name, SHARE_PASSWORD) == 0) {
-               return defval;
+               return talloc_strdup(mem_ctx, defval);
        }
 
        DEBUG(0,("request for unknown share string option '%s'\n",
                 opt_name));
 
-       return defval;
+       return talloc_strdup(mem_ctx, defval);
 }
 
 static int sclassic_int_option(struct share_config *scfg, const char *opt_name, int defval)
index 0e27376e96d2b378abf308dbab7c3e8a38716497..0257cd1b93727686c240709cc53167e4eeac0361 100644 (file)
@@ -58,13 +58,13 @@ static NTSTATUS sldb_init(TALLOC_CTX *mem_ctx, const struct share_ops *ops,
        return NT_STATUS_OK;
 }
 
-static const char *sldb_string_option(struct share_config *scfg, const char *opt_name, const char *defval)
+static char *sldb_string_option(TALLOC_CTX *mem_ctx, struct share_config *scfg, const char *opt_name, const char *defval)
 {
        struct ldb_message *msg;
        struct ldb_message_element *el;
        const char *colon;
 
-       if (scfg == NULL) return defval;
+       if (scfg == NULL) return talloc_strdup(mem_ctx, defval);
 
        msg = talloc_get_type(scfg->opaque, struct ldb_message);
 
@@ -85,22 +85,24 @@ static const char *sldb_string_option(struct share_config *scfg, const char *opt
        }
 
        if (el == NULL) {
-               return defval;
+               return talloc_strdup(mem_ctx, defval);
        }
 
-       return (const char *)(el->values[0].data);
+       return (char *)(el->values[0].data);
 }
 
 static int sldb_int_option(struct share_config *scfg, const char *opt_name, int defval)
 {
-       const char *val;
+       char *val;
        int ret;
 
-               val = sldb_string_option(scfg, opt_name, NULL);
+       val = sldb_string_option(scfg, scfg, opt_name, NULL);
        if (val == NULL) return defval;
 
        errno = 0;
        ret = (int)strtol(val, NULL, 10);
+       TALLOC_FREE(val);
+
        if (errno) return -1;
 
        return ret;
@@ -108,13 +110,17 @@ static int sldb_int_option(struct share_config *scfg, const char *opt_name, int
 
 static bool sldb_bool_option(struct share_config *scfg, const char *opt_name, bool defval)
 {
-       const char *val;
+       char *val;
 
-               val = sldb_string_option(scfg, opt_name, NULL);
+       val = sldb_string_option(scfg, scfg, opt_name, NULL);
        if (val == NULL) return defval;
 
-       if (strcasecmp(val, "true") == 0) return true;
+       if (strcasecmp(val, "true") == 0) {
+               TALLOC_FREE(val);
+               return true;
+       }
 
+       TALLOC_FREE(val);
        return false;
 }
 
index 218901026f4e2214d2d8b3acef031afd18155f84..34330b92ca10fe65dbc196b339b5a66ef09acbaf 100644 (file)
@@ -53,23 +53,26 @@ enum srvsvc_ShareType dcesrv_common_get_share_type(TALLOC_CTX *mem_ctx, struct d
         * this ones are hidden in NetShareEnum, but shown in NetShareEnumAll
         */
        enum srvsvc_ShareType share_type = 0;
-       const char *sharetype;
+       char *sharetype;
 
        if (!share_bool_option(scfg, SHARE_BROWSEABLE, SHARE_BROWSEABLE_DEFAULT)) {
                share_type |= STYPE_HIDDEN;
        }
 
-       sharetype = share_string_option(scfg, SHARE_TYPE, SHARE_TYPE_DEFAULT);
+       sharetype = share_string_option(mem_ctx, scfg, SHARE_TYPE, SHARE_TYPE_DEFAULT);
        if (sharetype && strcasecmp(sharetype, "IPC") == 0) {
                share_type |= STYPE_IPC;
+               TALLOC_FREE(sharetype);
                return share_type;
        }
 
        if (sharetype && strcasecmp(sharetype, "PRINTER") == 0) {
                share_type |= STYPE_PRINTQ;
+               TALLOC_FREE(sharetype);
                return share_type;
        }
 
+       TALLOC_FREE(sharetype);
        share_type |= STYPE_DISKTREE;
 
        return share_type;
@@ -78,16 +81,20 @@ enum srvsvc_ShareType dcesrv_common_get_share_type(TALLOC_CTX *mem_ctx, struct d
 /* This hardcoded value should go into a ldb database! */
 const char *dcesrv_common_get_share_path(TALLOC_CTX *mem_ctx, struct dcesrv_context *dce_ctx, struct share_config *scfg)
 {
-       const char *sharetype;
+       char *sharetype;
        char *p;
-       
-       sharetype = share_string_option(scfg, SHARE_TYPE, SHARE_TYPE_DEFAULT);
+       char *path;
+
+       sharetype = share_string_option(mem_ctx, scfg, SHARE_TYPE, SHARE_TYPE_DEFAULT);
        
        if (sharetype && strcasecmp(sharetype, "IPC") == 0) {
+               TALLOC_FREE(sharetype);
                return talloc_strdup(mem_ctx, "");
        }
 
-       p = talloc_strdup(mem_ctx, share_string_option(scfg, SHARE_PATH, ""));
+       TALLOC_FREE(sharetype);
+
+       p = share_string_option(mem_ctx, scfg, SHARE_PATH, "");
        if (!p) {
                return NULL;
        }
@@ -96,7 +103,9 @@ const char *dcesrv_common_get_share_path(TALLOC_CTX *mem_ctx, struct dcesrv_cont
        }
        all_string_sub(p, "/", "\\", 0);
        
-       return talloc_asprintf(mem_ctx, "C:%s", p);
+       path = talloc_asprintf(mem_ctx, "C:%s", p);
+       TALLOC_FREE(p);
+       return path;
 }
 
 /* This hardcoded value should go into a ldb database! */
index 0ef676638bcf614f192309d52178a907e006e63d..6521aea503980bf9e9c00a11b9d989748bd4bce0 100644 (file)
@@ -622,7 +622,7 @@ static WERROR dcesrv_srvsvc_fiel_ShareInfo(struct dcesrv_call_state *dce_call, T
                info->info1->name       = talloc_strdup(mem_ctx, scfg->name);
                W_ERROR_HAVE_NO_MEMORY(info->info1->name);
                info->info1->type       = dcesrv_common_get_share_type(mem_ctx, dce_ctx, scfg);
-               info->info1->comment    = talloc_strdup(mem_ctx, share_string_option(scfg, SHARE_COMMENT, ""));
+               info->info1->comment    = share_string_option(mem_ctx, scfg, SHARE_COMMENT, "");
                W_ERROR_HAVE_NO_MEMORY(info->info1->comment);
 
                return WERR_OK;
@@ -632,14 +632,14 @@ static WERROR dcesrv_srvsvc_fiel_ShareInfo(struct dcesrv_call_state *dce_call, T
                info->info2->name               = talloc_strdup(mem_ctx, scfg->name);
                W_ERROR_HAVE_NO_MEMORY(info->info2->name);
                info->info2->type               = dcesrv_common_get_share_type(mem_ctx, dce_ctx, scfg);
-               info->info2->comment            = talloc_strdup(mem_ctx, share_string_option(scfg, SHARE_COMMENT, ""));
+               info->info2->comment            = share_string_option(mem_ctx, scfg, SHARE_COMMENT, "");
                W_ERROR_HAVE_NO_MEMORY(info->info2->comment);
                info->info2->permissions        = dcesrv_common_get_share_permissions(mem_ctx, dce_ctx, scfg);
                info->info2->max_users          = share_int_option(scfg, SHARE_MAX_CONNECTIONS, SHARE_MAX_CONNECTIONS_DEFAULT);
                info->info2->current_users      = dcesrv_common_get_share_current_users(mem_ctx, dce_ctx, scfg);
                info->info2->path               = dcesrv_common_get_share_path(mem_ctx, dce_ctx, scfg);
                W_ERROR_HAVE_NO_MEMORY(info->info2->path);
-               info->info2->password           = talloc_strdup(mem_ctx, share_string_option(scfg, SHARE_PASSWORD, NULL));
+               info->info2->password           = share_string_option(mem_ctx, scfg, SHARE_PASSWORD, NULL);
 
                return WERR_OK;
        }
@@ -648,7 +648,7 @@ static WERROR dcesrv_srvsvc_fiel_ShareInfo(struct dcesrv_call_state *dce_call, T
                info->info501->name             = talloc_strdup(mem_ctx, scfg->name);
                W_ERROR_HAVE_NO_MEMORY(info->info501->name);
                info->info501->type             = dcesrv_common_get_share_type(mem_ctx, dce_ctx, scfg);
-               info->info501->comment          = talloc_strdup(mem_ctx, share_string_option(scfg, SHARE_COMMENT, ""));
+               info->info501->comment          = share_string_option(mem_ctx, scfg, SHARE_COMMENT, "");
                W_ERROR_HAVE_NO_MEMORY(info->info501->comment);
                info->info501->csc_policy       = share_int_option(scfg, SHARE_CSC_POLICY, SHARE_CSC_POLICY_DEFAULT);
 
@@ -659,14 +659,14 @@ static WERROR dcesrv_srvsvc_fiel_ShareInfo(struct dcesrv_call_state *dce_call, T
                info->info502->name             = talloc_strdup(mem_ctx, scfg->name);
                W_ERROR_HAVE_NO_MEMORY(info->info502->name);
                info->info502->type             = dcesrv_common_get_share_type(mem_ctx, dce_ctx, scfg);
-               info->info502->comment          = talloc_strdup(mem_ctx, share_string_option(scfg, SHARE_COMMENT, ""));
+               info->info502->comment          = share_string_option(mem_ctx, scfg, SHARE_COMMENT, "");
                W_ERROR_HAVE_NO_MEMORY(info->info502->comment);
                info->info502->permissions      = dcesrv_common_get_share_permissions(mem_ctx, dce_ctx, scfg);
                info->info502->max_users        = share_int_option(scfg, SHARE_MAX_CONNECTIONS, SHARE_MAX_CONNECTIONS_DEFAULT);
                info->info502->current_users    = dcesrv_common_get_share_current_users(mem_ctx, dce_ctx, scfg);
                info->info502->path             = dcesrv_common_get_share_path(mem_ctx, dce_ctx, scfg);
                W_ERROR_HAVE_NO_MEMORY(info->info502->path);
-               info->info502->password         = talloc_strdup(mem_ctx, share_string_option(scfg, SHARE_PASSWORD, NULL));
+               info->info502->password         = share_string_option(mem_ctx, scfg, SHARE_PASSWORD, NULL);
                info->info502->sd_buf.sd        = dcesrv_common_get_security_descriptor(mem_ctx, dce_ctx, scfg);
 
                return WERR_OK;
@@ -1396,11 +1396,11 @@ static WERROR dcesrv_srvsvc_NetShareCheck(struct dcesrv_call_state *dce_call, TA
                if (!NT_STATUS_IS_OK(nterr)) {
                        return ntstatus_to_werror(nterr);
                }
-               path = share_string_option(scfg, SHARE_PATH, NULL);
+               path = share_string_option(mem_ctx, scfg, SHARE_PATH, NULL);
                if (!path) continue;
 
-               if (strcmp(device, path) == 0) {                
-                       type = share_string_option(scfg, SHARE_TYPE, NULL);
+               if (strcmp(device, path) == 0) {
+                       type = share_string_option(mem_ctx, scfg, SHARE_TYPE, NULL);
                        if (!type) continue;
 
                        if (strcmp(type, "DISK") == 0) {
index 49beb50d869d5e053b59542b29bfd5325806419d..5d6fc92859ac30b366ef6a6dcc0220cd59bad635 100644 (file)
@@ -45,7 +45,7 @@ NTSTATUS srvsvc_create_ntvfs_context(struct dcesrv_call_state *dce_call,
        enum ntvfs_type type;
        struct share_context *sctx;
        struct share_config *scfg;
-       const char *sharetype;
+       char *sharetype;
        union smb_tcon tcon;
        const struct tsocket_address *local_address;
        const struct tsocket_address *remote_address;
@@ -71,7 +71,7 @@ NTSTATUS srvsvc_create_ntvfs_context(struct dcesrv_call_state *dce_call,
 #endif
 
        /* work out what sort of connection this is */
-       sharetype = share_string_option(scfg, SHARE_TYPE, SHARE_TYPE_DEFAULT);
+       sharetype = share_string_option(mem_ctx, scfg, SHARE_TYPE, SHARE_TYPE_DEFAULT);
        if (sharetype && strcmp(sharetype, "IPC") == 0) {
                type = NTVFS_IPC;
        } else if (sharetype && strcmp(sharetype, "PRINTER")) {
@@ -80,6 +80,8 @@ NTSTATUS srvsvc_create_ntvfs_context(struct dcesrv_call_state *dce_call,
                type = NTVFS_DISK;
        }
 
+       TALLOC_FREE(sharetype);
+
        c = talloc(mem_ctx, struct srvsvc_ntvfs_ctx);
        NT_STATUS_HAVE_NO_MEMORY(c);
        
index 9ad0f3894ed3f852b37add476984880d3cb6c35f..e25be1c382d75eae851d1d06c350e805493f92a4 100644 (file)
@@ -111,7 +111,7 @@ static NTSTATUS make_connection(struct smbsrv_request *req,
        enum ntvfs_type type;
        const char *type_str;
        struct share_config *scfg;
-       const char *sharetype;
+       char *sharetype;
 
        /* the service might be of the form \\SERVER\SHARE. Should we put
           the server name we get from this somewhere? */
@@ -138,7 +138,7 @@ static NTSTATUS make_connection(struct smbsrv_request *req,
        }
 
        /* work out what sort of connection this is */
-       sharetype = share_string_option(scfg, "type", "DISK");
+       sharetype = share_string_option(req, scfg, "type", "DISK");
        if (sharetype && strcmp(sharetype, "IPC") == 0) {
                type = NTVFS_IPC;
                type_str = "IPC";
@@ -149,6 +149,7 @@ static NTSTATUS make_connection(struct smbsrv_request *req,
                type = NTVFS_DISK;
                type_str = "A:";
        }
+       TALLOC_FREE(sharetype);
 
        if (strcmp(dev, "?????") != 0 && strcasecmp(type_str, dev) != 0) {
                /* the client gave us the wrong device type */
index 6ee2eb5f8ece4bab5b14ee25c74448458950a478..e7d28479c14fdf8bd7d1359a9aa1d55c3a6cb872 100644 (file)
@@ -241,7 +241,7 @@ static NTSTATUS smb2srv_tcon_backend(struct smb2srv_request *req, union smb_tcon
        enum ntvfs_type type;
        const char *service = io->smb2.in.path;
        struct share_config *scfg;
-       const char *sharetype;
+       char *sharetype;
        uint64_t ntvfs_caps = 0;
 
        if (strncmp(service, "\\\\", 2) == 0) {
@@ -265,7 +265,7 @@ static NTSTATUS smb2srv_tcon_backend(struct smb2srv_request *req, union smb_tcon
        }
 
        /* work out what sort of connection this is */
-       sharetype = share_string_option(scfg, SHARE_TYPE, "DISK");
+       sharetype = share_string_option(req, scfg, SHARE_TYPE, "DISK");
        if (sharetype && strcmp(sharetype, "IPC") == 0) {
                type = NTVFS_IPC;
        } else if (sharetype && strcmp(sharetype, "PRINTER") == 0) {
@@ -273,6 +273,7 @@ static NTSTATUS smb2srv_tcon_backend(struct smb2srv_request *req, union smb_tcon
        } else {
                type = NTVFS_DISK;
        }
+       TALLOC_FREE(sharetype);
 
        tcon = smbsrv_smb2_tcon_new(req->session, scfg->name);
        if (!tcon) {