]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
param: add FN_{GLOBAL,LOCAL}_SUBSTITUTED_STRING support
authorStefan Metzmacher <metze@samba.org>
Tue, 15 Oct 2019 14:52:30 +0000 (16:52 +0200)
committerStefan Metzmacher <metze@samba.org>
Wed, 27 Nov 2019 10:25:32 +0000 (10:25 +0000)
Pair-Programmed-With: Ralph Boehme <slow@samba.org>

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Signed-off-by: Ralph Boehme <slow@samba.org>
lib/param/loadparm.c
lib/param/param.h
script/generate_param.py
source3/lib/util_path.c
source3/param/loadparm.c

index 759a0a8ca4571dd6c1027245ec46dff29f8e8341..25cf4eb7785579345b8a523f08787f56e2b76ec7 100644 (file)
@@ -167,6 +167,15 @@ static struct loadparm_context *global_loadparm_context;
         return lp_ctx->globals->var_name ? talloc_strdup(ctx, lpcfg_string(lp_ctx->globals->var_name)) : talloc_strdup(ctx, ""); \
 }
 
+#define FN_GLOBAL_SUBSTITUTED_STRING(fn_name,var_name) \
+ _PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx, \
+                const struct loadparm_substitution *lp_sub, TALLOC_CTX *mem_ctx) \
+{ \
+        if (lp_ctx == NULL) return NULL;                               \
+        return lpcfg_substituted_string(mem_ctx, lp_sub, \
+                        lp_ctx->globals->var_name ? lp_ctx->globals->var_name : ""); \
+}
+
 #define FN_GLOBAL_CONST_STRING(fn_name,var_name)                               \
  _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
        if (lp_ctx == NULL) return NULL;                                \
@@ -199,6 +208,9 @@ static struct loadparm_context *global_loadparm_context;
         return(talloc_strdup(ctx, lpcfg_string((const char *)((service != NULL && service->val != NULL) ? service->val : sDefault->val)))); \
  }
 
+/* just a copy for now */
+#define FN_LOCAL_SUBSTITUTED_STRING(fn_name,val) FN_LOCAL_STRING(fn_name,val)
+
 #define FN_LOCAL_CONST_STRING(fn_name,val) \
  _PUBLIC_ const char *lpcfg_ ## fn_name(struct loadparm_service *service, \
                                        struct loadparm_service *sDefault) { \
index 0a3bde6c5cb52daff9f26bfa40d9d20083c6d2c1..762a827048184d5017c10d1e2d2ae2d8ac929da2 100644 (file)
@@ -21,6 +21,7 @@
 #define _PARAM_H 
 
 struct loadparm_s3_helpers;
+struct loadparm_substitution;
 
 struct parmlist_entry;
 
index 5f8a50562d4ca9fbca868b8ebe08aa664794e4da..55f2b65271ba14ae03dd1db73496e41b161584d6 100644 (file)
@@ -75,6 +75,7 @@ def iterate_all(path):
             continue
 
         constant = parameter.attrib.get("constant")
+        substitution = parameter.attrib.get("substitution")
         parm = parameter.attrib.get("parm")
         if name is None or param_type is None or context is None:
             raise Exception("Error parsing parameter: " + name)
@@ -89,6 +90,7 @@ def iterate_all(path):
                'context': context,
                'function': func,
                'constant': (constant == '1'),
+               'substitution': (substitution == '1'),
                'parm': (parm == '1'),
                'synonym' : synonym,
                'generated' : generated,
@@ -135,6 +137,8 @@ def generate_functions(path_in, path_out):
             output_string += temp
             if parameter['constant']:
                 output_string += "_CONST"
+            if parameter['substitution']:
+                output_string += "_SUBSTITUTED"
             if parameter['parm']:
                 output_string += "_PARM"
             temp = param_type_dict.get(parameter['type'])
@@ -192,7 +196,14 @@ def make_s3_param_proto(path_in, path_out):
             else:
                 param = "int"
 
-            if parameter['type'] == 'string' and not parameter['constant']:
+            if parameter['type'] == 'string' and parameter['substitution']:
+                if parameter['context'] == 'G':
+                    output_string += '(TALLOC_CTX *ctx, const struct loadparm_substitution *lp_sub);\n'
+                elif parameter['context'] == 'S':
+                    output_string += '(TALLOC_CTX *ctx, const struct loadparm_substitution *lp_sub, %s);\n' % param
+                else:
+                    raise Exception(parameter['name'] + " has an invalid param type " + parameter['type'])
+            elif parameter['type'] == 'string' and not parameter['constant']:
                 if parameter['context'] == 'G':
                     output_string += '(TALLOC_CTX *ctx);\n'
                 elif parameter['context'] == 'S':
@@ -237,7 +248,14 @@ def make_lib_proto(path_in, path_out):
 
             output_string += "lpcfg_%s" % parameter['function']
 
-            if parameter['type'] == 'string' and not parameter['constant']:
+            if parameter['type'] == 'string' and parameter['substitution']:
+                if parameter['context'] == 'G':
+                    output_string += '(struct loadparm_context *, const struct loadparm_substitution *lp_sub, TALLOC_CTX *ctx);\n'
+                elif parameter['context'] == 'S':
+                    output_string += '(struct loadparm_service *, struct loadparm_service *, TALLOC_CTX *ctx);\n'
+                else:
+                    raise Exception(parameter['name'] + " has an invalid context " + parameter['context'])
+            elif parameter['type'] == 'string' and not parameter['constant']:
                 if parameter['context'] == 'G':
                     output_string += '(struct loadparm_context *, TALLOC_CTX *ctx);\n'
                 elif parameter['context'] == 'S':
index d9fed29c2a519d4a12acc049f6fbe0f7ccc1ed2e..63d01b81000550c0bc9c38d5c55522c593ae4e6a 100644 (file)
@@ -26,6 +26,7 @@
 #include "lib/util/samba_util.h"
 #include "lib/util_path.h"
 
+struct loadparm_substitution;
 struct share_params;
 #include "source3/param/param_proto.h"
 
index 03e8ec435ba4dffe859a6e6dacd5d2b43f594045..b08589b22fb007bfc25163197aab216322ecb723 100644 (file)
@@ -1049,6 +1049,9 @@ char *lp_string(TALLOC_CTX *ctx, const char *s)
 
 #define FN_GLOBAL_STRING(fn_name,ptr) \
 char *lp_ ## fn_name(TALLOC_CTX *ctx) {return(lp_string((ctx), *(char **)(&Globals.ptr) ? *(char **)(&Globals.ptr) : ""));}
+#define FN_GLOBAL_SUBSTITUTED_STRING(fn_name,ptr) \
+char *lp_ ## fn_name(TALLOC_CTX *ctx, const struct loadparm_substitution *lp_sub) \
+ {return lpcfg_substituted_string(ctx, lp_sub, *(char **)(&Globals.ptr) ? *(char **)(&Globals.ptr) : "");}
 #define FN_GLOBAL_CONST_STRING(fn_name,ptr) \
  const char *lp_ ## fn_name(void) {return(*(const char * const *)(&Globals.ptr) ? *(const char * const *)(&Globals.ptr) : "");}
 #define FN_GLOBAL_LIST(fn_name,ptr) \
@@ -1062,6 +1065,9 @@ char *lp_ ## fn_name(TALLOC_CTX *ctx) {return(lp_string((ctx), *(char **)(&Globa
 
 #define FN_LOCAL_STRING(fn_name,val) \
 char *lp_ ## fn_name(TALLOC_CTX *ctx,int i) {return(lp_string((ctx), (LP_SNUM_OK(i) && ServicePtrs[(i)]->val) ? ServicePtrs[(i)]->val : sDefault.val));}
+#define FN_LOCAL_SUBSTITUTED_STRING(fn_name,val) \
+char *lp_ ## fn_name(TALLOC_CTX *ctx, const struct loadparm_substitution *lp_sub, int i) \
+ {return lpcfg_substituted_string((ctx), lp_sub, (LP_SNUM_OK(i) && ServicePtrs[(i)]->val) ? ServicePtrs[(i)]->val : sDefault.val);}
 #define FN_LOCAL_CONST_STRING(fn_name,val) \
  const char *lp_ ## fn_name(int i) {return (const char *)((LP_SNUM_OK(i) && ServicePtrs[(i)]->val) ? ServicePtrs[(i)]->val : sDefault.val);}
 #define FN_LOCAL_LIST(fn_name,val) \