Exemple #1
0
static lwres_result_t
lwres_conf_parsesearch(lwres_context_t *ctx,  FILE *fp) {
	int idx, delim;
	char word[LWRES_CONFMAXLINELEN];
	lwres_conf_t *confdata;

	confdata = &ctx->confdata;

	if (confdata->domainname != NULL) {
		/*
		 * Search and domain are mutually exclusive.
		 */
		CTXFREE(confdata->domainname,
			strlen(confdata->domainname) + 1);
		confdata->domainname = NULL;
	}

	/*
	 * Remove any previous search definitions.
	 */
	for (idx = 0; idx < LWRES_CONFMAXSEARCH; idx++) {
		if (confdata->search[idx] != NULL) {
			CTXFREE(confdata->search[idx],
				strlen(confdata->search[idx])+1);
			confdata->search[idx] = NULL;
		}
	}
	confdata->searchnxt = 0;

	delim = getword(fp, word, sizeof(word));
	if (strlen(word) == 0U)
		return (LWRES_R_FAILURE); /* Nothing else on line. */

	idx = 0;
	while (strlen(word) > 0U) {
		if (confdata->searchnxt == LWRES_CONFMAXSEARCH)
			goto ignore; /* Too many domains. */

		confdata->search[idx] = lwres_strdup(ctx, word);
		if (confdata->search[idx] == NULL)
			return (LWRES_R_FAILURE);
		idx++;
		confdata->searchnxt++;

	ignore:
		if (delim == EOF || delim == '\n')
			break;
		else
			delim = getword(fp, word, sizeof(word));
	}

	return (LWRES_R_SUCCESS);
}
Exemple #2
0
void
get_win32_searchlist(lwres_context_t *ctx) {
	HKEY hKey;
	BOOL keyFound = TRUE;
	char searchlist[MAX_PATH];
	DWORD searchlen = MAX_PATH;
	char *cp;
	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) {
		/* Get the named directory */
		if (RegQueryValueEx(hKey, "SearchList", NULL, NULL,
			(LPBYTE)searchlist, &searchlen) != ERROR_SUCCESS)
			keyFound = FALSE;
		RegCloseKey(hKey);
	}

	confdata->searchnxt = 0;

	if (!keyFound)
		return;

	cp = strtok((char *)searchlist, ", \0");
	while (cp != NULL) {
		if (confdata->searchnxt == LWRES_CONFMAXSEARCH)
			break;
		if (strlen(cp) <= MAX_PATH && strlen(cp) > 0) {
			confdata->search[confdata->searchnxt] = lwres_strdup(ctx, cp);
			if (confdata->search[confdata->searchnxt] != NULL)
				confdata->searchnxt++;
		}
		cp = strtok(NULL, ", \0");
	}
}
Exemple #3
0
static lwres_result_t
lwres_conf_parsedomain(lwres_context_t *ctx,  FILE *fp) {
	char word[LWRES_CONFMAXLINELEN];
	int res, i;
	lwres_conf_t *confdata;

	confdata = &ctx->confdata;

	res = getword(fp, word, sizeof(word));
	if (strlen(word) == 0U)
		return (LWRES_R_FAILURE); /* Nothing else on line. */
	else if (res == ' ' || res == '\t')
		res = eatwhite(fp);

	if (res != EOF && res != '\n')
		return (LWRES_R_FAILURE); /* Extra junk on line. */

	if (confdata->domainname != NULL)
		CTXFREE(confdata->domainname,
			strlen(confdata->domainname) + 1); /*  */

	/*
	 * Search and domain are mutually exclusive.
	 */
	for (i = 0; i < LWRES_CONFMAXSEARCH; i++) {
		if (confdata->search[i] != NULL) {
			CTXFREE(confdata->search[i],
				strlen(confdata->search[i])+1);
			confdata->search[i] = NULL;
		}
	}
	confdata->searchnxt = 0;

	confdata->domainname = lwres_strdup(ctx, word);

	if (confdata->domainname == NULL)
		return (LWRES_R_FAILURE);

	return (LWRES_R_SUCCESS);
}
Exemple #4
0
lwres_result_t
lwres_conf_parse(lwres_context_t *ctx, const char *filename) {
	lwres_result_t ret;
	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);

	/* Use the resolver if there is one */
	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);

	/*
	 * We didn't get any nameservers so we need to do this ourselves
	 */
	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 the search list from the registry */
	get_win32_searchlist(ctx);

	/* Use only if there is no search list */
	if (confdata->searchnxt == 0 && strlen(FixedInfo->DomainName) > 0) {
		confdata->domainname = lwres_strdup(ctx, FixedInfo->DomainName);
		if (confdata->domainname == NULL) {
			GlobalFree(FixedInfo);
			return (LWRES_R_FAILURE);
		}
	} else
		confdata->domainname = NULL;

	/* Get the list of nameservers */
	pIPAddr = &FixedInfo->DnsServerList;
	while (pIPAddr) {
		if (confdata->nsnext >= LWRES_CONFMAXNAMESERVERS)
			break;

		ret = lwres_create_addr(pIPAddr->IpAddress.String,
				&confdata->nameservers[confdata->nsnext++], 1);
		if (ret != LWRES_R_SUCCESS) {
			GlobalFree(FixedInfo);
			return (ret);
		}
		pIPAddr = pIPAddr ->Next;
	}

	GlobalFree(FixedInfo);
	return (LWRES_R_SUCCESS);
}