look in windows registry for nameservers, domainname and search list
This commit is contained in:
@@ -126,6 +126,10 @@ resconf_parsesortlist(irs_resconf_t *conf, FILE *fp);
|
||||
static isc_result_t
|
||||
resconf_parseoption(irs_resconf_t *ctx, FILE *fp);
|
||||
|
||||
#if HAVE_GET_WIN32_NAMESERVERS
|
||||
static isc_result_t get_win32_nameservers(irs_resconf_t *conf);
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* Eat characters from FP until EOL or EOF. Returns EOF or '\n'
|
||||
*/
|
||||
@@ -562,15 +566,6 @@ irs_resconf_load(isc_mem_t *mctx, const char *filename, irs_resconf_t **confp)
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* If we don't find a nameserver fall back to localhost */
|
||||
if (conf->numns == 0U) {
|
||||
INSIST(ISC_LIST_EMPTY(conf->nameservers));
|
||||
|
||||
/* XXX: should we catch errors? */
|
||||
(void)add_server(conf->mctx, "::1", &conf->nameservers);
|
||||
(void)add_server(conf->mctx, "127.0.0.1", &conf->nameservers);
|
||||
}
|
||||
|
||||
/*
|
||||
* Construct unified search list from domain or configured
|
||||
* search list
|
||||
@@ -585,6 +580,22 @@ irs_resconf_load(isc_mem_t *mctx, const char *filename, irs_resconf_t **confp)
|
||||
}
|
||||
}
|
||||
|
||||
#if HAVE_GET_WIN32_NAMESERVERS
|
||||
ret = get_win32_nameservers(conf);
|
||||
if (ret != ISC_R_SUCCESS) {
|
||||
goto error;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* If we don't find a nameserver fall back to localhost */
|
||||
if (conf->numns == 0U) {
|
||||
INSIST(ISC_LIST_EMPTY(conf->nameservers));
|
||||
|
||||
/* XXX: should we catch errors? */
|
||||
(void)add_server(conf->mctx, "::1", &conf->nameservers);
|
||||
(void)add_server(conf->mctx, "127.0.0.1", &conf->nameservers);
|
||||
}
|
||||
|
||||
error:
|
||||
conf->magic = IRS_RESCONF_MAGIC;
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
<ClCompile Include="..\getnameinfo.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\resconf.c">
|
||||
<ClCompile Include="resconf.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
@@ -66,4 +66,4 @@
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
@@ -67,7 +67,7 @@
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>..\..\isc\win32\$(Configuration);..\..\dns\win32\$(Configuration);..\..\isccfg\win32\$(Configuration);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>@OPENSSL_LIB@libisc.lib;libdns.lib;libisccfg.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>@OPENSSL_LIB@libisc.lib;libdns.lib;libisccfg.lib;ws2_32.lib;iphlpapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<ModuleDefinitionFile>.\libirs.def</ModuleDefinitionFile>
|
||||
<ImportLibrary>.\$(Configuration)\$(ProjectName).lib</ImportLibrary>
|
||||
<OutputFile>..\..\..\Build\$(Configuration)\$(TargetName)$(TargetExt)</OutputFile>
|
||||
@@ -98,7 +98,7 @@
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalLibraryDirectories>..\..\isc\win32\$(Configuration);..\..\dns\win32\$(Configuration);..\..\isccfg\win32\$(Configuration);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>@OPENSSL_LIB@libisc.lib;libdns.lib;libisccfg.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>@OPENSSL_LIB@libisc.lib;libdns.lib;libisccfg.lib;ws2_32.lib;iphlpapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<ModuleDefinitionFile>.\libirs.def</ModuleDefinitionFile>
|
||||
<ImportLibrary>.\$(Configuration)\$(ProjectName).lib</ImportLibrary>
|
||||
<LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration>
|
||||
@@ -114,8 +114,8 @@
|
||||
<ClCompile Include="..\gai_strerror.c" />
|
||||
<ClCompile Include="..\getaddrinfo.c" />
|
||||
<ClCompile Include="..\getnameinfo.c" />
|
||||
<ClCompile Include="..\resconf.c" />
|
||||
<ClCompile Include="DLLMain.c" />
|
||||
<ClCompile Include="resconf.c" />
|
||||
<ClCompile Include="version.c" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
131
lib/irs/win32/resconf.c
Normal file
131
lib/irs/win32/resconf.c
Normal file
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* See the COPYRIGHT file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Note that on Win32 there is normally no resolv.conf since all information
|
||||
* is stored in the registry. Therefore there is no ordering like the
|
||||
* contents of resolv.conf. Since the "search" or "domain" keyword, on
|
||||
* Win32 if a search list is found it is used, otherwise the domain name
|
||||
* is used since they are mutually exclusive. The search list can be entered
|
||||
* in the DNS tab of the "Advanced TCP/IP settings" window under the same place
|
||||
* that you add your nameserver list.
|
||||
*/
|
||||
|
||||
#define HAVE_GET_WIN32_NAMESERVERS 1
|
||||
|
||||
#include "../resconf.c"
|
||||
|
||||
#include <iphlpapi.h>
|
||||
|
||||
#define TCPIP_SUBKEY \
|
||||
"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters"
|
||||
|
||||
isc_result_t
|
||||
get_win32_searchlist(irs_resconf_t *conf) {
|
||||
isc_result_t result = ISC_R_SUCCESS;
|
||||
HKEY hKey;
|
||||
BOOL keyFound = TRUE;
|
||||
char searchlist[MAX_PATH];
|
||||
DWORD searchlen = MAX_PATH;
|
||||
LSTATUS status;
|
||||
char *cp;
|
||||
|
||||
REQUIRE(conf != NULL);
|
||||
|
||||
memset(searchlist, 0, MAX_PATH);
|
||||
status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, TCPIP_SUBKEY, 0, KEY_READ,
|
||||
&hKey);
|
||||
if (status != ERROR_SUCCESS) {
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
status = RegQueryValueEx(hKey, "SearchList", NULL, NULL,
|
||||
(LPBYTE)searchlist, &searchlen);
|
||||
RegCloseKey(hKey);
|
||||
if (status != ERROR_SUCCESS) {
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
cp = strtok((char *)searchlist, ", \0");
|
||||
while (cp != NULL) {
|
||||
result = add_search(conf, cp);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
cp = strtok(NULL, ", \0");
|
||||
}
|
||||
return (result);
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
get_win32_nameservers(irs_resconf_t *conf) {
|
||||
isc_result_t result;
|
||||
FIXED_INFO *FixedInfo;
|
||||
ULONG BufLen = sizeof(FIXED_INFO);
|
||||
DWORD dwRetVal;
|
||||
IP_ADDR_STRING *pIPAddr;
|
||||
|
||||
REQUIRE(conf != NULL);
|
||||
|
||||
FixedInfo = (FIXED_INFO *) GlobalAlloc(GPTR, BufLen);
|
||||
if (FixedInfo == NULL) {
|
||||
return (ISC_R_NOMEMORY);
|
||||
}
|
||||
dwRetVal = GetNetworkParams(FixedInfo, &BufLen);
|
||||
if (dwRetVal == ERROR_BUFFER_OVERFLOW) {
|
||||
GlobalFree(FixedInfo);
|
||||
FixedInfo = GlobalAlloc(GPTR, BufLen);
|
||||
if (FixedInfo == NULL) {
|
||||
return (ISC_R_NOMEMORY);
|
||||
}
|
||||
dwRetVal = GetNetworkParams(FixedInfo, &BufLen);
|
||||
}
|
||||
if (dwRetVal != ERROR_SUCCESS) {
|
||||
GlobalFree(FixedInfo);
|
||||
return (ISC_R_FAILURE);
|
||||
}
|
||||
|
||||
result = get_win32_searchlist(conf);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (ISC_LIST_EMPTY(conf->searchlist) &&
|
||||
strlen(FixedInfo->DomainName) > 0)
|
||||
{
|
||||
result = add_search(conf, FixedInfo->DomainName);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
/* Get the list of nameservers */
|
||||
pIPAddr = &FixedInfo->DnsServerList;
|
||||
while (pIPAddr) {
|
||||
if (conf->numns >= RESCONFMAXNAMESERVERS) {
|
||||
break;
|
||||
}
|
||||
|
||||
result = add_server(conf->mctx, pIPAddr->IpAddress.String,
|
||||
&conf->nameservers);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
conf->numns++;
|
||||
pIPAddr = pIPAddr->Next;
|
||||
}
|
||||
|
||||
cleanup:
|
||||
if (FixedInfo != NULL) {
|
||||
GlobalFree(FixedInfo);
|
||||
}
|
||||
return (result);
|
||||
}
|
||||
Reference in New Issue
Block a user