Added code to read the domain from the registry and use it if search suffixes are missing

This commit is contained in:
gmadkat 2016-03-27 22:37:54 -07:00
parent 5d2a05f5e0
commit af7f384cf3
1 changed files with 24 additions and 9 deletions

View File

@ -822,11 +822,13 @@ upstream_init(getdns_upstream *upstream,
/* /*
Read the Windows search suffix and add to context Read the Windows search suffix and add to context
There may or may not be domains and suffixes so do not error if missing
*/ */
static int get_dns_suffix_windows(getdns_list *suffix) static int get_dns_suffix_windows(getdns_list *suffix, char* domain)
{ {
char *parse, *token, prev_ch; char *parse, *token, prev_ch;
char lszValue[255]; char lszValue[255] = "";
char lszDomain[255] = "";
HKEY hKey; HKEY hKey;
LONG returnStatus; LONG returnStatus;
DWORD dwType=REG_SZ; DWORD dwType=REG_SZ;
@ -848,21 +850,30 @@ static int get_dns_suffix_windows(getdns_list *suffix)
TEXT("SearchList"), 0, &dwType,(LPBYTE)&lszValue, &dwSize); TEXT("SearchList"), 0, &dwType,(LPBYTE)&lszValue, &dwSize);
if (returnStatus == ERROR_SUCCESS) if (returnStatus == ERROR_SUCCESS)
{ {
if ((strlen(lszValue)) > 0) {
parse = lszValue; parse = lszValue;
do { do {
parse += strspn(parse, ","); parse += strspn(parse, ",");
token = parse + strcspn(parse, ","); token = parse + strcspn(parse, ",");
prev_ch = *token; prev_ch = *token;
*token = 0; *token = 0;
_getdns_list_append_string(suffix, parse); _getdns_list_append_string(suffix, parse);
*token = prev_ch; *token = prev_ch;
parse = token; parse = token;
} while (*parse); } while (*parse);
} else {
return 0; /* no DNS suffixes keys */
} }
}
dwSize = 255;
returnStatus = RegQueryValueEx(hKey,
TEXT("Domain"), 0, &dwType,(LPBYTE)&lszDomain, &dwSize);
if (returnStatus == ERROR_SUCCESS)
{
strcpy_s(domain, dwSize, lszDomain);
}
RegCloseKey(hKey); RegCloseKey(hKey);
} else { } else {
return 0; /* no DNS keys or suffixes */ return 0; /* no DNS keys or suffixes */
@ -947,12 +958,16 @@ set_os_defaults_windows(struct getdns_context *context)
suffix = getdns_list_create_with_context(context); suffix = getdns_list_create_with_context(context);
if (get_dns_suffix_windows(suffix)) { if (get_dns_suffix_windows(suffix, domain)) {
(void) getdns_list_get_length(suffix, &length); (void) getdns_list_get_length(suffix, &length);
if (length > 0) if (*domain != 0) {
_getdns_list_append_string(suffix, domain);
}
(void) getdns_list_get_length(suffix, &length);
if (length > 0) {
(void )getdns_context_set_suffix(context, suffix); (void )getdns_context_set_suffix(context, suffix);
} }
}
getdns_list_destroy(suffix); getdns_list_destroy(suffix);
return GETDNS_RETURN_GOOD; return GETDNS_RETURN_GOOD;