+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.
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) {
usage();
if(argc == 1)
f = argv[0];
- else f = CONFIGFILE;
+ else f = cfgfile;
checkconf(f, opt);
checklock_stop();
return 0;
#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();
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;
/** 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 */