]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
Fixup #724 in unbound-checkconf and fname_after_chroot calls.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Tue, 1 Dec 2015 09:12:30 +0000 (09:12 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Tue, 1 Dec 2015 09:12:30 +0000 (09:12 +0000)
git-svn-id: file:///svn/unbound/trunk@3558 be551aaa-1e26-0410-a405-d3ace91eadb9

smallapp/unbound-checkconf.c
util/config_file.c
util/config_file.h
winrc/win_svc.c

index 0524edeaab1230b24395c62f496f4d7e65b01f3c..ec0771306b9a4d20782a7a9c2e2159bad0852631 100644 (file)
@@ -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.",
index cc00fda2ac199d404a3b5d1001c770ccdce61ff8..cc7d99086b81b23674c3aa09cae6c92b5c0e2b29 100644 (file)
@@ -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)
index e6dbc8162e17e325eb7ee5fea09ac42a2d1dd948..d746791ea7a7a4ba0352e8d540e62f6a5e885437 100644 (file)
@@ -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 */
index 09b78adbc9bf9482ae0764b9e316d852481a594f..9d6926dbe590a6aa3456a5b67b9b5f64a05ae352 100644 (file)
@@ -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));