From bb7b4db353c14906fc877a798164268e2a1fc295 Mon Sep 17 00:00:00 2001 From: Wouter Wijngaards Date: Tue, 1 Dec 2015 09:12:30 +0000 Subject: [PATCH] Fixup #724 in unbound-checkconf and fname_after_chroot calls. git-svn-id: file:///svn/unbound/trunk@3558 be551aaa-1e26-0410-a405-d3ace91eadb9 --- smallapp/unbound-checkconf.c | 4 +++- util/config_file.c | 22 ++++++++++++++++++++++ util/config_file.h | 3 +++ winrc/win_svc.c | 19 +------------------ 4 files changed, 29 insertions(+), 19 deletions(-) diff --git a/smallapp/unbound-checkconf.c b/smallapp/unbound-checkconf.c index 0524edeaa..ec0771306 100644 --- a/smallapp/unbound-checkconf.c +++ b/smallapp/unbound-checkconf.c @@ -335,7 +335,9 @@ morechecks(struct config_file* cfg, const char* fname) if(cfg->edns_buffer_size > cfg->msg_buffer_size) fatal_exit("edns-buffer-size larger than msg-buffer-size, " "answers will not fit in processing buffer"); - +#ifdef UB_ON_WINDOWS + w_config_adjust_directory(cfg); +#endif if(cfg->chrootdir && cfg->chrootdir[0] && cfg->chrootdir[strlen(cfg->chrootdir)-1] == '/') fatal_exit("chootdir %s has trailing slash '/' please remove.", diff --git a/util/config_file.c b/util/config_file.c index cc00fda2a..cc7d99086 100644 --- a/util/config_file.c +++ b/util/config_file.c @@ -1558,6 +1558,28 @@ w_lookup_reg_str(const char* key, const char* name) } return result; } + +void w_config_adjust_directory(struct config_file* cfg) +{ + if(cfg->directory && cfg->directory[0]) { + TCHAR dirbuf[2*MAX_PATH+4]; + if(strcmp(cfg->directory, "%EXECUTABLE%") == 0) { + /* get executable path, and if that contains + * directories, snip off the filename part */ + dirbuf[0] = 0; + if(!GetModuleFileName(NULL, dirbuf, MAX_PATH)) + log_err("could not GetModuleFileName"); + if(strrchr(dirbuf, '\\')) { + (strrchr(dirbuf, '\\'))[0] = 0; + } else log_err("GetModuleFileName had no path"); + if(dirbuf[0]) { + /* adjust directory for later lookups to work*/ + free(cfg->directory); + cfg->directory = memdup(dirbuf, strlen(dirbuf)+1); + } + } + } +} #endif /* UB_ON_WINDOWS */ void errinf(struct module_qstate* qstate, const char* str) diff --git a/util/config_file.h b/util/config_file.h index e6dbc8162..d746791ea 100644 --- a/util/config_file.h +++ b/util/config_file.h @@ -741,6 +741,9 @@ void ub_c_error_msg(const char* fmt, ...) ATTR_FORMAT(printf, 1, 2); * exist on an error (logged with log_err) was encountered. */ char* w_lookup_reg_str(const char* key, const char* name); + +/** Modify directory in options for module file name */ +void w_config_adjust_directory(struct config_file* cfg); #endif /* UB_ON_WINDOWS */ #endif /* UTIL_CONFIG_FILE_H */ diff --git a/winrc/win_svc.c b/winrc/win_svc.c index 09b78adbc..9d6926dbe 100644 --- a/winrc/win_svc.c +++ b/winrc/win_svc.c @@ -333,26 +333,9 @@ service_init(int r, struct daemon** d, struct config_file** c) verbose(VERB_QUERY, "winservice - apply settings"); /* apply settings and init */ verbosity = cfg->verbosity + service_cmdline_verbose; + w_config_adjust_directory(cfg); if(cfg->directory && cfg->directory[0]) { - TCHAR dirbuf[2*MAX_PATH+4]; char* dir = cfg->directory; - if(strcmp(dir, "%EXECUTABLE%") == 0) { - /* get executable path, and if that contains - * directories, snip off the filename part */ - dirbuf[0] = 0; - if(!GetModuleFileName(NULL, dirbuf, MAX_PATH)) - log_err("could not GetModuleFileName"); - if(strrchr(dirbuf, '\\')) { - (strrchr(dirbuf, '\\'))[0] = 0; - } else log_err("GetModuleFileName had no path"); - dir = dirbuf; - if(dirbuf[0]) { - /* adjust cfg->directory for the - * fname_after_chroot calls later to work */ - free(cfg->directory); - cfg->directory = memdup(dir, strlen(dir)+1); - } - } if(chdir(dir)) { log_err("could not chdir to %s: %s", dir, strerror(errno)); -- 2.47.2