#define lwres_conf_parse generic_lwres_conf_parse
#include "../lwconfig.c"
#undef lwres_conf_parse
#include <iphlpapi.h>
#define TCPIP_SUBKEY \
"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters"
void
get_win32_searchlist(lwres_context_t *ctx) {
HKEY hKey;
BOOL keyFound = TRUE;
char searchlist[MAX_PATH];
DWORD searchlen = MAX_PATH;
char *cp;
int idx;
lwres_conf_t *confdata;
REQUIRE(ctx != NULL);
confdata = &ctx->confdata;
memset(searchlist, 0, MAX_PATH);
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, TCPIP_SUBKEY, 0, KEY_READ, &hKey)
!= ERROR_SUCCESS)
keyFound = FALSE;
if (keyFound == TRUE) {
if (RegQueryValueEx(hKey, "SearchList", NULL, NULL,
(LPBYTE)searchlist, &searchlen) != ERROR_SUCCESS)
keyFound = FALSE;
}
RegCloseKey(hKey);
confdata->searchnxt = 0;
idx = 0;
cp = strtok((char *)searchlist, ", \0");
while (cp != NULL) {
if (confdata->searchnxt == LWRES_CONFMAXSEARCH)
break;
if (strlen(cp) <= MAX_PATH && strlen(cp) > 0) {
confdata->search[idx] = lwres_strdup(ctx, cp);
}
idx++;
confdata->searchnxt++;
cp = strtok(NULL, ", \0");
}
}
lwres_result_t
lwres_conf_parse(lwres_context_t *ctx, const char *filename) {
lwres_result_t ret = LWRES_R_SUCCESS;
lwres_result_t res;
lwres_conf_t *confdata;
FIXED_INFO * FixedInfo;
ULONG BufLen = sizeof(FIXED_INFO);
DWORD dwRetVal;
IP_ADDR_STRING *pIPAddr;
REQUIRE(ctx != NULL);
confdata = &ctx->confdata;
REQUIRE(confdata != NULL);
ret = generic_lwres_conf_parse(ctx, filename);
if ((ret != LWRES_R_NOTFOUND && ret != LWRES_R_SUCCESS) ||
(ret == LWRES_R_SUCCESS && confdata->nsnext > 0))
return (ret);
FixedInfo = (FIXED_INFO *) GlobalAlloc(GPTR, BufLen);
dwRetVal = GetNetworkParams(FixedInfo, &BufLen);
if (dwRetVal == ERROR_BUFFER_OVERFLOW) {
GlobalFree(FixedInfo);
FixedInfo = GlobalAlloc(GPTR, BufLen);
dwRetVal = GetNetworkParams(FixedInfo, &BufLen);
}
if (dwRetVal != ERROR_SUCCESS) {
GlobalFree(FixedInfo);
return (LWRES_R_FAILURE);
}
get_win32_searchlist(ctx);
if (confdata->searchnxt == 0) {
confdata->domainname = lwres_strdup(ctx, FixedInfo->DomainName);
if (confdata->domainname == NULL) {
GlobalFree(FixedInfo);
return (LWRES_R_FAILURE);
}
}
pIPAddr = &FixedInfo->DnsServerList;
while (pIPAddr) {
if (confdata->nsnext >= LWRES_CONFMAXNAMESERVERS)
break;
res = lwres_create_addr(pIPAddr->IpAddress.String,
&confdata->nameservers[confdata->nsnext++], 1);
if (res != LWRES_R_SUCCESS) {
GlobalFree(FixedInfo);
return (res);
}
pIPAddr = pIPAddr ->Next;
}
GlobalFree(FixedInfo);
return (LWRES_R_SUCCESS);
}