1258945Sroberto/*
2280849Scy * Copyright (C) 2004, 2007, 2009  Internet Systems Consortium, Inc. ("ISC")
3258945Sroberto * Copyright (C) 2001  Internet Software Consortium.
4258945Sroberto *
5258945Sroberto * Permission to use, copy, modify, and/or distribute this software for any
6258945Sroberto * purpose with or without fee is hereby granted, provided that the above
7258945Sroberto * copyright notice and this permission notice appear in all copies.
8258945Sroberto *
9258945Sroberto * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10258945Sroberto * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11258945Sroberto * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12258945Sroberto * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13258945Sroberto * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14258945Sroberto * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15258945Sroberto * PERFORMANCE OF THIS SOFTWARE.
16258945Sroberto */
17258945Sroberto
18280849Scy/* $Id: ntpaths.c,v 1.15 2009/07/14 22:54:57 each Exp $ */
19258945Sroberto
20258945Sroberto/*
21258945Sroberto * This module fetches the required path information that is specific
22258945Sroberto * to NT systems which can have its configuration and system files
23258945Sroberto * almost anywhere. It can be used to override whatever the application
24258945Sroberto * had previously assigned to the pointer. Basic information about the
25258945Sroberto * file locations are stored in the registry.
26258945Sroberto */
27258945Sroberto
28258945Sroberto#include <config.h>
29258945Sroberto#include <isc/bind_registry.h>
30258945Sroberto#include <isc/ntpaths.h>
31258945Sroberto
32258945Sroberto/*
33258945Sroberto * Module Variables
34258945Sroberto */
35258945Sroberto
36258945Srobertostatic char systemDir[MAX_PATH];
37258945Srobertostatic char namedBase[MAX_PATH];
38258945Srobertostatic char ns_confFile[MAX_PATH];
39258945Srobertostatic char lwresd_confFile[MAX_PATH];
40258945Srobertostatic char lwresd_resolvconfFile[MAX_PATH];
41258945Srobertostatic char rndc_confFile[MAX_PATH];
42258945Srobertostatic char ns_defaultpidfile[MAX_PATH];
43258945Srobertostatic char lwresd_defaultpidfile[MAX_PATH];
44258945Srobertostatic char local_state_dir[MAX_PATH];
45258945Srobertostatic char sys_conf_dir[MAX_PATH];
46258945Srobertostatic char rndc_keyFile[MAX_PATH];
47280849Scystatic char session_keyFile[MAX_PATH];
48258945Sroberto
49258945Srobertostatic DWORD baseLen = MAX_PATH;
50258945Srobertostatic BOOL Initialized = FALSE;
51258945Sroberto
52258945Srobertovoid
53258945Srobertoisc_ntpaths_init() {
54258945Sroberto	HKEY hKey;
55258945Sroberto	BOOL keyFound = TRUE;
56258945Sroberto
57258945Sroberto	memset(namedBase, 0, MAX_PATH);
58258945Sroberto	if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, BIND_SUBKEY, 0, KEY_READ, &hKey)
59258945Sroberto		!= ERROR_SUCCESS)
60258945Sroberto		keyFound = FALSE;
61280849Scy
62258945Sroberto	if (keyFound == TRUE) {
63258945Sroberto		/* Get the named directory */
64258945Sroberto		if (RegQueryValueEx(hKey, "InstallDir", NULL, NULL,
65258945Sroberto			(LPBYTE)namedBase, &baseLen) != ERROR_SUCCESS)
66258945Sroberto			keyFound = FALSE;
67258945Sroberto		RegCloseKey(hKey);
68258945Sroberto	}
69258945Sroberto
70258945Sroberto	GetSystemDirectory(systemDir, MAX_PATH);
71258945Sroberto
72258945Sroberto	if (keyFound == FALSE)
73258945Sroberto		/* Use the System Directory as a default */
74258945Sroberto		strcpy(namedBase, systemDir);
75258945Sroberto
76258945Sroberto	strcpy(ns_confFile, namedBase);
77258945Sroberto	strcat(ns_confFile, "\\etc\\named.conf");
78258945Sroberto
79258945Sroberto	strcpy(lwresd_confFile, namedBase);
80258945Sroberto	strcat(lwresd_confFile, "\\etc\\lwresd.conf");
81258945Sroberto
82258945Sroberto	strcpy(lwresd_resolvconfFile, systemDir);
83258945Sroberto	strcat(lwresd_resolvconfFile, "\\Drivers\\etc\\resolv.conf");
84258945Sroberto
85258945Sroberto	strcpy(rndc_keyFile, namedBase);
86258945Sroberto	strcat(rndc_keyFile, "\\etc\\rndc.key");
87258945Sroberto
88280849Scy	strcpy(session_keyFile, namedBase);
89280849Scy	strcat(session_keyFile, "\\etc\\session.key");
90280849Scy
91258945Sroberto	strcpy(rndc_confFile, namedBase);
92258945Sroberto	strcat(rndc_confFile, "\\etc\\rndc.conf");
93258945Sroberto	strcpy(ns_defaultpidfile, namedBase);
94258945Sroberto	strcat(ns_defaultpidfile, "\\etc\\named.pid");
95258945Sroberto
96258945Sroberto	strcpy(lwresd_defaultpidfile, namedBase);
97258945Sroberto	strcat(lwresd_defaultpidfile, "\\etc\\lwresd.pid");
98258945Sroberto
99258945Sroberto	strcpy(local_state_dir, namedBase);
100258945Sroberto	strcat(local_state_dir, "\\bin");
101258945Sroberto
102258945Sroberto	strcpy(sys_conf_dir, namedBase);
103258945Sroberto	strcat(sys_conf_dir, "\\etc");
104280849Scy
105258945Sroberto	Initialized = TRUE;
106258945Sroberto}
107258945Sroberto
108258945Srobertochar *
109258945Srobertoisc_ntpaths_get(int ind) {
110258945Sroberto	if (!Initialized)
111258945Sroberto		isc_ntpaths_init();
112258945Sroberto
113258945Sroberto	switch (ind) {
114258945Sroberto	case NAMED_CONF_PATH:
115258945Sroberto		return (ns_confFile);
116258945Sroberto		break;
117258945Sroberto	case LWRES_CONF_PATH:
118258945Sroberto		return (lwresd_confFile);
119258945Sroberto		break;
120258945Sroberto	case RESOLV_CONF_PATH:
121258945Sroberto		return (lwresd_resolvconfFile);
122258945Sroberto		break;
123258945Sroberto	case RNDC_CONF_PATH:
124258945Sroberto		return (rndc_confFile);
125258945Sroberto		break;
126258945Sroberto	case NAMED_PID_PATH:
127258945Sroberto		return (ns_defaultpidfile);
128258945Sroberto		break;
129258945Sroberto	case LWRESD_PID_PATH:
130258945Sroberto		return (lwresd_defaultpidfile);
131258945Sroberto		break;
132258945Sroberto	case LOCAL_STATE_DIR:
133258945Sroberto		return (local_state_dir);
134258945Sroberto		break;
135258945Sroberto	case SYS_CONF_DIR:
136258945Sroberto		return (sys_conf_dir);
137258945Sroberto		break;
138258945Sroberto	case RNDC_KEY_PATH:
139258945Sroberto		return (rndc_keyFile);
140258945Sroberto		break;
141280849Scy	case SESSION_KEY_PATH:
142280849Scy		return (session_keyFile);
143280849Scy		break;
144258945Sroberto	default:
145258945Sroberto		return (NULL);
146258945Sroberto	}
147258945Sroberto}
148