From: Stefan Metzmacher Date: Tue, 15 Oct 2019 14:52:30 +0000 (+0200) Subject: param: add FN_{GLOBAL,LOCAL}_SUBSTITUTED_STRING support X-Git-Tag: ldb-2.1.0~589 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ef1f0e9ffe76eaee4b92241ea39d81ea553fa841;p=thirdparty%2Fsamba.git param: add FN_{GLOBAL,LOCAL}_SUBSTITUTED_STRING support Pair-Programmed-With: Ralph Boehme Signed-off-by: Stefan Metzmacher Signed-off-by: Ralph Boehme --- diff --git a/lib/param/loadparm.c b/lib/param/loadparm.c index 759a0a8ca45..25cf4eb7785 100644 --- a/lib/param/loadparm.c +++ b/lib/param/loadparm.c @@ -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) { \ diff --git a/lib/param/param.h b/lib/param/param.h index 0a3bde6c5cb..762a8270481 100644 --- a/lib/param/param.h +++ b/lib/param/param.h @@ -21,6 +21,7 @@ #define _PARAM_H struct loadparm_s3_helpers; +struct loadparm_substitution; struct parmlist_entry; diff --git a/script/generate_param.py b/script/generate_param.py index 5f8a50562d4..55f2b65271b 100644 --- a/script/generate_param.py +++ b/script/generate_param.py @@ -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': diff --git a/source3/lib/util_path.c b/source3/lib/util_path.c index d9fed29c2a5..63d01b81000 100644 --- a/source3/lib/util_path.c +++ b/source3/lib/util_path.c @@ -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" diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c index 03e8ec435ba..b08589b22fb 100644 --- a/source3/param/loadparm.c +++ b/source3/param/loadparm.c @@ -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) \