From 17a80fc6593c7025a297cdcae46e18a3ce4d994c Mon Sep 17 00:00:00 2001 From: Quentin Gibeaux Date: Thu, 29 Oct 2015 13:48:27 +0100 Subject: [PATCH 1/2] lib/param: handle (ignore) substitution variable in smb.conf BUG: https://bugzilla.samba.org/show_bug.cgi?id=10722 The function handle_include returns false when trying to include files that have a substitution variable in filename (like %U), this patch makes handle_include to ignore this case, to make samba-tool work when there is such include in samba's configuration. Error was : Can't find include file %U.conf ERROR(runtime): uncaught exception - Unable to load default file Signed-off-by: Quentin Gibeaux --- lib/param/loadparm.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/param/loadparm.c b/lib/param/loadparm.c index a0700a9..b54d000 100644 --- a/lib/param/loadparm.c +++ b/lib/param/loadparm.c @@ -1090,6 +1090,8 @@ bool handle_include(struct loadparm_context *lp_ctx, struct loadparm_service *se const char *pszParmValue, char **ptr) { char *fname; + char *substitution_variable_substring; + char next_char; if (lp_ctx->s3_fns) { return lp_ctx->s3_fns->lp_include(lp_ctx, service, pszParmValue, ptr); @@ -1104,6 +1106,20 @@ bool handle_include(struct loadparm_context *lp_ctx, struct loadparm_service *se if (file_exist(fname)) return pm_process(fname, do_section, lpcfg_do_parameter, lp_ctx); + /* If the file doesn't exist, we check that it isn't due to variable + substitution */ + substitution_variable_substring = strchr(fname, '%'); + + if (substitution_variable_substring != NULL) { + next_char = substitution_variable_substring[1]; + if ((next_char >= 'a' && next_char <= 'z') + || (next_char >= 'A' && next_char <= 'Z')) { + DEBUG(2, ("Tried to load %s but variable substitution in " + "filename, ignoring file.\n", fname)); + return true; + } + } + DEBUG(2, ("Can't find include file %s\n", fname)); return false; -- 2.1.4 From 380a02ac1078e15cdf2f0411c224f324324ca0bf Mon Sep 17 00:00:00 2001 From: Quentin Gibeaux Date: Thu, 29 Oct 2015 14:22:13 +0100 Subject: [PATCH 2/2] Fix comment format Signed-off-by: Quentin Gibeaux --- lib/param/loadparm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/param/loadparm.c b/lib/param/loadparm.c index b54d000..eb34308 100644 --- a/lib/param/loadparm.c +++ b/lib/param/loadparm.c @@ -1106,8 +1106,10 @@ bool handle_include(struct loadparm_context *lp_ctx, struct loadparm_service *se if (file_exist(fname)) return pm_process(fname, do_section, lpcfg_do_parameter, lp_ctx); - /* If the file doesn't exist, we check that it isn't due to variable - substitution */ + /* + * If the file doesn't exist, we check that it isn't due to variable + * substitution + */ substitution_variable_substring = strchr(fname, '%'); if (substitution_variable_substring != NULL) { -- 2.1.4