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