1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-21 18:04:06 +03:00

param: use loadparm_globals struct instead of lp function pointers in s3_helpers

Signed-off-by: Garming Sam <garming@catalyst.net.nz>
Change-Id: I4507cdbf111b7f9dca3ca18ee2bf242ffdfeb4e7
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Nadezhda Ivanova <nivanova@samba.org>
This commit is contained in:
Garming Sam 2014-01-24 15:38:59 +13:00 committed by Andrew Bartlett
parent 12aa85a90c
commit 9780113846
5 changed files with 19 additions and 54 deletions

View File

@ -210,8 +210,7 @@ static struct loadparm_context *global_loadparm_context;
_PUBLIC_ char *lpcfg_ ## fn_name(struct loadparm_context *lp_ctx, TALLOC_CTX *ctx) {\
if (lp_ctx == NULL) return NULL; \
if (lp_ctx->s3_fns) { \
SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
return lp_ctx->s3_fns->fn_name(ctx); \
return lp_ctx->globals->var_name ? lp_ctx->s3_fns->lp_string(ctx, lp_ctx->globals->var_name) : talloc_strdup(ctx, ""); \
} \
return lp_ctx->globals->var_name ? talloc_strdup(ctx, lpcfg_string(lp_ctx->globals->var_name)) : talloc_strdup(ctx, ""); \
}
@ -219,39 +218,23 @@ static struct loadparm_context *global_loadparm_context;
#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; \
if (lp_ctx->s3_fns) { \
SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
return lp_ctx->s3_fns->fn_name(); \
} \
return lp_ctx->globals->var_name ? lpcfg_string(lp_ctx->globals->var_name) : ""; \
}
#define FN_GLOBAL_LIST(fn_name,var_name) \
_PUBLIC_ const char **lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
if (lp_ctx == NULL) return NULL; \
if (lp_ctx->s3_fns) { \
SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
return lp_ctx->s3_fns->fn_name(); \
} \
return lp_ctx->globals->var_name; \
}
#define FN_GLOBAL_BOOL(fn_name,var_name) \
_PUBLIC_ bool lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) {\
if (lp_ctx == NULL) return false; \
if (lp_ctx->s3_fns) { \
SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
return lp_ctx->s3_fns->fn_name(); \
} \
return lp_ctx->globals->var_name; \
}
#define FN_GLOBAL_INTEGER(fn_name,var_name) \
_PUBLIC_ int lpcfg_ ## fn_name(struct loadparm_context *lp_ctx) { \
if (lp_ctx->s3_fns) { \
SMB_ASSERT(lp_ctx->s3_fns->fn_name); \
return lp_ctx->s3_fns->fn_name(); \
} \
return lp_ctx->globals->var_name; \
}
@ -2403,6 +2386,7 @@ struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx,
return NULL;
}
loadparm_context->s3_fns = s3_fns;
loadparm_context->globals = s3_fns->globals;
return loadparm_context;
}

View File

@ -252,6 +252,9 @@ int lp_find_server_role(int server_role, int security, int domain_logons, int do
int lp_find_security(int server_role, int security);
bool lp_is_security_and_server_role_valid(int server_role, int security);
struct loadparm_global * get_globals(void);
char * lp_string(TALLOC_CTX *, const char *);
/**
* Check if two parameters are equal.
*/

View File

@ -278,27 +278,8 @@ def make_s3_param(path_in, path_out):
file_out.write("\tbool (*set_cmdline)(const char *pszParmName, const char *pszParmValue);\n")
file_out.write("\tvoid (*dump)(FILE *f, bool show_defaults, int maxtoprint);\n")
file_out.write("\tconst char * (*dnsdomain)(void);\n")
for parameter in iterate_all(path_in):
# filter out parameteric options
if ':' in parameter['name']:
continue
if parameter['context'] != 'G':
continue
output_string = "\t"
if parameter['constant'] or parameter['type'] == 'string':
output_string += 'const '
param_type = mapping.get(parameter['type'])
if param_type is None:
raise Exception(parameter['name'] + " has an invalid context " + parameter['context'])
output_string += param_type
if parameter['type'] == 'string' and not parameter['constant']:
output_string += " (*%s)(TALLOC_CTX *);\n" % parameter['function']
else:
output_string += " (*%s)(void);\n" % parameter['function']
file_out.write(output_string)
file_out.write("\tchar * (*lp_string)(TALLOC_CTX *ctx, const char *in);\n")
file_out.write("\tstruct loadparm_global *globals;\n")
file_out.write("};\n")
file_out.write("\n#endif /* %s */\n\n" % header)
finally:
@ -308,7 +289,7 @@ def make_s3_param_ctx_table(path_in, path_out):
file_out = open(path_out, 'w')
try:
file_out.write('/* This file was automatically generated by generate_param.py. DO NOT EDIT */\n\n')
file_out.write("static const struct loadparm_s3_helpers s3_fns =\n")
file_out.write("static struct loadparm_s3_helpers s3_fns =\n")
file_out.write("{\n")
file_out.write("\t.get_parametric = lp_parm_const_string_service,\n")
file_out.write("\t.get_parm_struct = lp_get_parameter,\n")
@ -321,18 +302,6 @@ def make_s3_param_ctx_table(path_in, path_out):
file_out.write("\t.set_cmdline = lp_set_cmdline,\n")
file_out.write("\t.dump = lp_dump,\n")
file_out.write("\t.dnsdomain = lp_dnsdomain,\n")
header = get_header(path_out)
for parameter in iterate_all(path_in):
# filter out parameteric options
if ':' in parameter['name']:
continue
if parameter['context'] != 'G':
continue
output_string = "\t.%s" % parameter['function']
output_string += " = lp_%s,\n" % parameter['function']
file_out.write(output_string)
file_out.write("};")
finally:
file_out.close()

View File

@ -1072,7 +1072,7 @@ static void init_globals(bool reinit_globals)
callers without affecting the source string.
********************************************************************/
static char *lp_string(TALLOC_CTX *ctx, const char *s)
char *lp_string(TALLOC_CTX *ctx, const char *s)
{
char *ret;
@ -5263,3 +5263,8 @@ int lp_security(void)
return lp_find_security(lp__server_role(),
lp__security());
}
struct loadparm_global * get_globals(void)
{
return &Globals;
}

View File

@ -60,5 +60,9 @@ static bool lp_load_for_s4_ctx(const char *filename)
const struct loadparm_s3_helpers *loadparm_s3_helpers(void)
{
return &s3_fns;
struct loadparm_s3_helpers *helpers;
helpers = &s3_fns;
helpers->globals = get_globals();
helpers->lp_string = lp_string;
return helpers;
}