lib/param: handle non-constant strings properly by passing in a memory context
[sfrench/samba-autobuild/.git] / source4 / param / share_classic.c
index 3442d6bd50dba92f325dfe6ca6441dfb79ccc86b..67ea392824fb8fe3f2e1f77365df10c9b2280bb2 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,43 +69,43 @@ 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) {
-               return lpcfg_pathname(s, lpcfg_default_service(lp_ctx));
+               return lpcfg_path(s, lpcfg_default_service(lp_ctx), mem_ctx);
        }
 
        if (strcmp(opt_name, SHARE_COMMENT) == 0) {
-               return lpcfg_comment(s, lpcfg_default_service(lp_ctx));
+               return lpcfg_comment(s, lpcfg_default_service(lp_ctx), mem_ctx);
        }
 
        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_print_ok(s, lpcfg_default_service(lp_ctx))) {
-                       return "PRINTER";
+               if (lpcfg_printable(s, lpcfg_default_service(lp_ctx))) {
+                       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)
@@ -146,11 +147,11 @@ static int sclassic_int_option(struct share_config *scfg, const char *opt_name,
        }
 
        if (strcmp(opt_name, SHARE_DIR_MASK) == 0) {
-               return lpcfg_dir_mask(s, lpcfg_default_service(lp_ctx));
+               return lpcfg_directory_mask(s, lpcfg_default_service(lp_ctx));
        }
 
        if (strcmp(opt_name, SHARE_FORCE_DIR_MODE) == 0) {
-               return lpcfg_force_dir_mode(s, lpcfg_default_service(lp_ctx));
+               return lpcfg_force_directory_mode(s, lpcfg_default_service(lp_ctx));
        }
 
        if (strcmp(opt_name, SHARE_FORCE_CREATE_MODE) == 0) {
@@ -197,7 +198,7 @@ static bool sclassic_bool_option(struct share_config *scfg, const char *opt_name
        }
 
        if (strcmp(opt_name, SHARE_READONLY) == 0) {
-               return lpcfg_readonly(s, lpcfg_default_service(lp_ctx));
+               return lpcfg_read_only(s, lpcfg_default_service(lp_ctx));
        }
 
        if (strcmp(opt_name, SHARE_MAP_SYSTEM) == 0) {
@@ -229,7 +230,32 @@ static bool sclassic_bool_option(struct share_config *scfg, const char *opt_name
        }
 
        if (strcmp(opt_name, SHARE_CI_FILESYSTEM) == 0) {
-               return lpcfg_ci_filesystem(s, lpcfg_default_service(lp_ctx));
+               int case_sensitive = lpcfg_case_sensitive(s, lpcfg_default_service(lp_ctx));
+               /*
+                * Yes, this confusingly named option means Samba acts
+                * case sensitive, so that the filesystem can act case
+                * insensitive.
+                *
+                */
+               if (case_sensitive == Auto) {
+                       /* Auto is for unix extensions and unix
+                        * clients, which we don't support here.
+                        * Samba needs to do the case changing,
+                        * because the filesystem is case
+                        * sensitive  */
+                       return false;
+               } else if (case_sensitive) {
+                       /* True means that Samba won't do anything to
+                        * change the case of incoming requests.
+                        * Essentially this means we trust the file
+                        * system to be case insensitive */
+                       return true;
+               } else {
+                       /* False means that Smaba needs to do the case
+                        * changing, because the filesystem is case
+                        * sensitive */
+                       return false;
+               }
        }
 
        DEBUG(0,("request for unknown share bool option '%s'\n",
@@ -262,11 +288,11 @@ static const char **sclassic_string_list_option(TALLOC_CTX *mem_ctx, struct shar
        }
 
        if (strcmp(opt_name, SHARE_HOSTS_ALLOW) == 0) {
-               return lpcfg_hostsallow(s, lpcfg_default_service(lp_ctx));
+               return lpcfg_hosts_allow(s, lpcfg_default_service(lp_ctx));
        }
 
        if (strcmp(opt_name, SHARE_HOSTS_DENY) == 0) {
-               return lpcfg_hostsdeny(s, lpcfg_default_service(lp_ctx));
+               return lpcfg_hosts_deny(s, lpcfg_default_service(lp_ctx));
        }
 
        if (strcmp(opt_name, SHARE_NTVFS_HANDLER) == 0) {