]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- Fix bug#434: on windows check registry for config file location
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Mon, 27 Feb 2012 13:20:29 +0000 (13:20 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Mon, 27 Feb 2012 13:20:29 +0000 (13:20 +0000)
  for unbound-control.exe, and unbound-checkconf.exe.

git-svn-id: file:///svn/unbound/trunk@2635 be551aaa-1e26-0410-a405-d3ace91eadb9

doc/Changelog
smallapp/unbound-checkconf.c
smallapp/unbound-control.c
util/config_file.c
util/config_file.h

index b0a5697eaaca67137a04536e37d9e7cac8c508f6..0d7b1d44ae30d53d9e706d357985e395874f7273 100644 (file)
@@ -1,3 +1,7 @@
+27 February 2012: Wouter
+       - Fix bug#434: on windows check registry for config file location
+         for unbound-control.exe, and unbound-checkconf.exe.
+
 23 February 2012: Wouter
        - Fix to squelch 'network unreachable' errors from tcp connect in
          logs, high verbosity will show them.
index 10b23bebd85ed8ec6ba73a865aadad134b54a7d4..c73d8bdc7c9c10957bdb0a2a031234c555428eda 100644 (file)
@@ -483,9 +483,15 @@ int main(int argc, char* argv[])
        int c;
        const char* f;
        const char* opt = NULL;
+       const char* cfgfile = CONFIGFILE;
        log_ident_set("unbound-checkconf");
        log_init(NULL, 0, NULL);
        checklock_start();
+#ifdef USE_WINSOCK
+       /* use registry config file in preference to compiletime location */
+       if(!(cfgfile=w_lookup_reg_str("Software\\Unbound", "ConfigFile")))
+               cfgfile = CONFIGFILE;
+#endif /* USE_WINSOCK */
        /* parse the options */
        while( (c=getopt(argc, argv, "ho:")) != -1) {
                switch(c) {
@@ -504,7 +510,7 @@ int main(int argc, char* argv[])
                usage();
        if(argc == 1)
                f = argv[0];
-       else    f = CONFIGFILE;
+       else    f = cfgfile;
        checkconf(f, opt);
        checklock_stop();
        return 0;
index 757d2798872147f3e7860972a4f898016db0740f..58be7b7abfc02ea27b961e8d1e35debdb7828ef3 100644 (file)
@@ -366,6 +366,9 @@ int main(int argc, char* argv[])
 #ifdef USE_WINSOCK
        if((r = WSAStartup(MAKEWORD(2,2), &wsa_data)) != 0)
                fatal_exit("WSAStartup failed: %s", wsa_strerror(r));
+       /* use registry config file in preference to compiletime location */
+       if(!(cfgfile=w_lookup_reg_str("Software\\Unbound", "ConfigFile")))
+               cfgfile = CONFIGFILE;
 #endif
 
        ERR_load_crypto_strings();
index 41ae87e9cc32585f1e692bb7840030afc64caf01..8108cd9467c01276467d7b64bdc203204dba7e60 100644 (file)
@@ -1333,6 +1333,42 @@ char* cfg_ptr_reverse(char* str)
        return result;
 }
 
+#ifdef UB_ON_WINDOWS
+char*
+w_lookup_reg_str(const char* key, const char* name)
+{
+       HKEY hk = NULL;
+       DWORD type = 0;
+       BYTE buf[1024];
+       DWORD len = (DWORD)sizeof(buf);
+       LONG ret;
+       char* result = NULL;
+       ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, key, 0, KEY_READ, &hk);
+       if(ret == ERROR_FILE_NOT_FOUND)
+               return NULL; /* key does not exist */
+       else if(ret != ERROR_SUCCESS) {
+               log_err("RegOpenKeyEx failed");
+               return NULL;
+       }
+       ret = RegQueryValueEx(hk, (LPCTSTR)name, 0, &type, buf, &len);
+       if(RegCloseKey(hk))
+               log_err("RegCloseKey");
+       if(ret == ERROR_FILE_NOT_FOUND)
+               return NULL; /* name does not exist */
+       else if(ret != ERROR_SUCCESS) {
+               log_err("RegQueryValueEx failed");
+               return NULL;
+       }
+       if(type == REG_SZ || type == REG_MULTI_SZ || type == REG_EXPAND_SZ) {
+               buf[sizeof(buf)-1] = 0;
+               buf[sizeof(buf)-2] = 0; /* for multi_sz */
+               result = strdup((char*)buf);
+               if(!result) log_err("out of memory");
+       }
+       return result;
+}
+#endif /* UB_ON_WINDOWS */
+
 void errinf(struct module_qstate* qstate, const char* str)
 {
        struct config_strlist* p;
index 050c3a00be462fbfc06fdf1a3435f3d16875dcdf..be53244466df8463d5609365e8bf212db759a591 100644 (file)
@@ -629,4 +629,15 @@ void ub_c_error(const char* msg);
 /** parsing helpers: print error with file and line numbers */
 void ub_c_error_msg(const char* fmt, ...) ATTR_FORMAT(printf, 1, 2);
 
+#ifdef UB_ON_WINDOWS
+/**
+ * Obtain registry string (if it exists).
+ * @param key: key string
+ * @param name: name of value to fetch.
+ * @return malloced string with the result or NULL if it did not
+ *     exist on an error (logged with log_err) was encountered.
+ */
+char* w_lookup_reg_str(const char* key, const char* name);
+#endif /* UB_ON_WINDOWS */
+
 #endif /* UTIL_CONFIG_FILE_H */