1d54cfbdroberto/*
2047f369cy * Copyright (C) 2004, 2007, 2009  Internet Systems Consortium, Inc. ("ISC")
3d54cfbdroberto * Copyright (C) 2001  Internet Software Consortium.
4d54cfbdroberto *
5d54cfbdroberto * Permission to use, copy, modify, and/or distribute this software for any
6d54cfbdroberto * purpose with or without fee is hereby granted, provided that the above
7d54cfbdroberto * copyright notice and this permission notice appear in all copies.
8d54cfbdroberto *
9d54cfbdroberto * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10d54cfbdroberto * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11d54cfbdroberto * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12d54cfbdroberto * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13d54cfbdroberto * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14d54cfbdroberto * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15d54cfbdroberto * PERFORMANCE OF THIS SOFTWARE.
16d54cfbdroberto */
17d54cfbdroberto
18047f369cy/* $Id: ntpaths.c,v 1.15 2009/07/14 22:54:57 each Exp $ */
19d54cfbdroberto
20d54cfbdroberto/*
21d54cfbdroberto * This module fetches the required path information that is specific
22d54cfbdroberto * to NT systems which can have its configuration and system files
23d54cfbdroberto * almost anywhere. It can be used to override whatever the application
24d54cfbdroberto * had previously assigned to the pointer. Basic information about the
25d54cfbdroberto * file locations are stored in the registry.
26d54cfbdroberto */
27d54cfbdroberto
28d54cfbdroberto#include <config.h>
29d54cfbdroberto#include <isc/bind_registry.h>
30d54cfbdroberto#include <isc/ntpaths.h>
31d54cfbdroberto
32d54cfbdroberto/*
33d54cfbdroberto * Module Variables
34d54cfbdroberto */
35d54cfbdroberto
36d54cfbdrobertostatic char systemDir[MAX_PATH];
37d54cfbdrobertostatic char namedBase[MAX_PATH];
38d54cfbdrobertostatic char ns_confFile[MAX_PATH];
39d54cfbdrobertostatic char lwresd_confFile[MAX_PATH];
40d54cfbdrobertostatic char lwresd_resolvconfFile[MAX_PATH];
41d54cfbdrobertostatic char rndc_confFile[MAX_PATH];
42d54cfbdrobertostatic char ns_defaultpidfile[MAX_PATH];
43d54cfbdrobertostatic char lwresd_defaultpidfile[MAX_PATH];
44d54cfbdrobertostatic char local_state_dir[MAX_PATH];
45d54cfbdrobertostatic char sys_conf_dir[MAX_PATH];
46d54cfbdrobertostatic char rndc_keyFile[MAX_PATH];
47047f369cystatic char session_keyFile[MAX_PATH];
48d54cfbdroberto
49d54cfbdrobertostatic DWORD baseLen = MAX_PATH;
50d54cfbdrobertostatic BOOL Initialized = FALSE;
51d54cfbdroberto
52d54cfbdrobertovoid
53d54cfbdrobertoisc_ntpaths_init() {
54d54cfbdroberto	HKEY hKey;
55d54cfbdroberto	BOOL keyFound = TRUE;
56d54cfbdroberto
57d54cfbdroberto	memset(namedBase, 0, MAX_PATH);
58d54cfbdroberto	if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, BIND_SUBKEY, 0, KEY_READ, &hKey)
59d54cfbdroberto		!= ERROR_SUCCESS)
60d54cfbdroberto		keyFound = FALSE;
61047f369cy
62d54cfbdroberto	if (keyFound == TRUE) {
63d54cfbdroberto		/* Get the named directory */
64d54cfbdroberto		if (RegQueryValueEx(hKey, "InstallDir", NULL, NULL,
65d54cfbdroberto			(LPBYTE)namedBase, &baseLen) != ERROR_SUCCESS)
66d54cfbdroberto			keyFound = FALSE;
67d54cfbdroberto		RegCloseKey(hKey);
68d54cfbdroberto	}
69d54cfbdroberto
70d54cfbdroberto	GetSystemDirectory(systemDir, MAX_PATH);
71d54cfbdroberto
72d54cfbdroberto	if (keyFound == FALSE)
73d54cfbdroberto		/* Use the System Directory as a default */
74d54cfbdroberto		strcpy(namedBase, systemDir);
75d54cfbdroberto
76d54cfbdroberto	strcpy(ns_confFile, namedBase);
77d54cfbdroberto	strcat(ns_confFile, "\\etc\\named.conf");
78d54cfbdroberto
79d54cfbdroberto	strcpy(lwresd_confFile, namedBase);
80d54cfbdroberto	strcat(lwresd_confFile, "\\etc\\lwresd.conf");
81d54cfbdroberto
82d54cfbdroberto	strcpy(lwresd_resolvconfFile, systemDir);
83d54cfbdroberto	strcat(lwresd_resolvconfFile, "\\Drivers\\etc\\resolv.conf");
84d54cfbdroberto
85d54cfbdroberto	strcpy(rndc_keyFile, namedBase);
86d54cfbdroberto	strcat(rndc_keyFile, "\\etc\\rndc.key");
87d54cfbdroberto
88047f369cy	strcpy(session_keyFile, namedBase);
89047f369cy	strcat(session_keyFile, "\\etc\\session.key");
90047f369cy
91d54cfbdroberto	strcpy(rndc_confFile, namedBase);
92d54cfbdroberto	strcat(rndc_confFile, "\\etc\\rndc.conf");
93d54cfbdroberto	strcpy(ns_defaultpidfile, namedBase);
94d54cfbdroberto	strcat(ns_defaultpidfile, "\\etc\\named.pid");
95d54cfbdroberto
96d54cfbdroberto	strcpy(lwresd_defaultpidfile, namedBase);
97d54cfbdroberto	strcat(lwresd_defaultpidfile, "\\etc\\lwresd.pid");
98d54cfbdroberto
99d54cfbdroberto	strcpy(local_state_dir, namedBase);
100d54cfbdroberto	strcat(local_state_dir, "\\bin");
101d54cfbdroberto
102d54cfbdroberto	strcpy(sys_conf_dir, namedBase);
103d54cfbdroberto	strcat(sys_conf_dir, "\\etc");
104047f369cy
105d54cfbdroberto	Initialized = TRUE;
106d54cfbdroberto}
107d54cfbdroberto
108d54cfbdrobertochar *
109d54cfbdrobertoisc_ntpaths_get(int ind) {
110d54cfbdroberto	if (!Initialized)
111d54cfbdroberto		isc_ntpaths_init();
112d54cfbdroberto
113d54cfbdroberto	switch (ind) {
114d54cfbdroberto	case NAMED_CONF_PATH:
115d54cfbdroberto		return (ns_confFile);
116d54cfbdroberto		break;
117d54cfbdroberto	case LWRES_CONF_PATH:
118d54cfbdroberto		return (lwresd_confFile);
119d54cfbdroberto		break;
120d54cfbdroberto	case RESOLV_CONF_PATH:
121d54cfbdroberto		return (lwresd_resolvconfFile);
122d54cfbdroberto		break;
123d54cfbdroberto	case RNDC_CONF_PATH:
124d54cfbdroberto		return (rndc_confFile);
125d54cfbdroberto		break;
126d54cfbdroberto	case NAMED_PID_PATH:
127d54cfbdroberto		return (ns_defaultpidfile);
128d54cfbdroberto		break;
129d54cfbdroberto	case LWRESD_PID_PATH:
130d54cfbdroberto		return (lwresd_defaultpidfile);
131d54cfbdroberto		break;
132d54cfbdroberto	case LOCAL_STATE_DIR:
133d54cfbdroberto		return (local_state_dir);
134d54cfbdroberto		break;
135d54cfbdroberto	case SYS_CONF_DIR:
136d54cfbdroberto		return (sys_conf_dir);
137d54cfbdroberto		break;
138d54cfbdroberto	case RNDC_KEY_PATH:
139d54cfbdroberto		return (rndc_keyFile);
140d54cfbdroberto		break;
141047f369cy	case SESSION_KEY_PATH:
142047f369cy		return (session_keyFile);
143047f369cy		break;
144d54cfbdroberto	default:
145d54cfbdroberto		return (NULL);
146d54cfbdroberto	}
147d54cfbdroberto}
148