diff --git a/configure.ac b/configure.ac index 01dcbdb9..2337754a 100644 --- a/configure.ac +++ b/configure.ac @@ -345,6 +345,22 @@ AC_CHECK_FUNCS([strptime],[AC_CHECK_STRPTIME_WORKS],[AC_LIBOBJ([strptime])]) AC_CHECK_HEADERS([windows.h winsock.h stdio.h winsock2.h ws2tcpip.h],,, [AC_INCLUDES_DEFAULT]) ACX_CHECK_GETADDRINFO_WITH_INCLUDES +AC_ARG_WITH(resolvconf, AS_HELP_STRING([--with-resolvconf=PATH], + [Set the resolver configuration file path. Defaults to /etc/resolv.conf or values retrieved via GetNetworkParams() on Windows]), + [], [withval="/etc/resolv.conf"]) +AC_DEFINE_UNQUOTED([GETDNS_FN_RESOLVCONF], ["$withval"], [Path to resolver configuration file]) + +AC_ARG_WITH(hosts, AS_HELP_STRING([--with-hosts=PATH], + [Set the static table lookup for hostnames path. Defaults to /etc/hosts or C:\Windows\System32\Drivers\etc\hosts on Windows]), + [], [ +if test "$USE_WINSOCK" = 1; then + withval="C:\\\\Windows\\\\System32\\\\Drivers\\\\etc\\\\hosts" +else + withval="/etc/hosts" +fi +]) +AC_DEFINE_UNQUOTED([GETDNS_FN_HOSTS], ["$withval"], [Path to static table lookup for hostnames]) + AC_ARG_WITH(fd-setsize, AS_HELP_STRING([--with-fd-setsize=size], [Set maximum file descriptor number that can be used by select]), [], [withval="no"]) diff --git a/src/context.c b/src/context.c index 62678873..6db0745d 100644 --- a/src/context.c +++ b/src/context.c @@ -505,11 +505,7 @@ create_local_hosts(getdns_context *context) int start_of_line = 1; getdns_dict *address = NULL; -#ifdef USE_WINSOCK - in = fopen("c:\\WINDOWS\\system32\\drivers\\etc\\hosts", "r"); -#else - in = fopen("/etc/hosts", "r"); -#endif + in = fopen(GETDNS_FN_HOSTS, "r"); while (fgets(pos, (int)(sizeof(buf) - (pos - buf)), in)) { pos = buf; /* Break out of for to read more */ @@ -1207,7 +1203,7 @@ set_os_defaults(struct getdns_context *context) GETDNS_MALLOC(context->my_mf, struct filechg); if(context->fchg_resolvconf == NULL) return GETDNS_RETURN_MEMORY_ERROR; - context->fchg_resolvconf->fn = "/etc/resolv.conf"; + context->fchg_resolvconf->fn = GETDNS_FN_RESOLVCONF; context->fchg_resolvconf->prevstat = NULL; context->fchg_resolvconf->changes = GETDNS_FCHG_NOCHANGES; context->fchg_resolvconf->errors = GETDNS_FCHG_NOERROR; @@ -3869,6 +3865,8 @@ _get_context_settings(getdns_context* context) (void) getdns_dict_util_set_string(result, "trust_anchors_verify_CA", str_value); if (!getdns_context_get_trust_anchors_verify_email(context, &str_value) && str_value) (void) getdns_dict_util_set_string(result, "trust_anchors_verify_email", str_value); + if (context->fchg_resolvconf && context->fchg_resolvconf->fn) + (void) getdns_dict_util_set_string(result, "resolvconf_file", context->fchg_resolvconf->fn); return result; error: @@ -3905,6 +3903,12 @@ getdns_context_get_api_information(getdns_context* context) && ! getdns_dict_util_set_string( result, "default_trust_anchor_location", TRUST_ANCHOR_FILE) + && ! getdns_dict_util_set_string( + result, "default_resolvconf_location", GETDNS_FN_RESOLVCONF) + + && ! getdns_dict_util_set_string( + result, "default_hosts_location", GETDNS_FN_HOSTS) + && ! getdns_dict_set_int( result, "resolution_type", context->resolution_type) @@ -4624,6 +4628,8 @@ _getdns_context_config_setting(getdns_context *context, && !_streq(setting, "api_version_number") && !_streq(setting, "trust_anchor_file") && !_streq(setting, "default_trust_anchor_location") + && !_streq(setting, "default_resolvconf_location") + && !_streq(setting, "default_hosts_location") && !_streq(setting, "compilation_comment") ) { r = GETDNS_RETURN_NOT_IMPLEMENTED; diff --git a/src/context.h b/src/context.h index 1a6d93a4..048137b5 100644 --- a/src/context.h +++ b/src/context.h @@ -54,9 +54,6 @@ struct getdns_dns_req; struct ub_ctx; -#define GETDNS_FN_RESOLVCONF "/etc/resolv.conf" -#define GETDNS_FN_HOSTS "/etc/hosts" - enum filechgs { GETDNS_FCHG_ERRORS = -1 , GETDNS_FCHG_NOERROR = 0 , GETDNS_FCHG_NOCHANGES = 0