1290001Sglebius/* 2290001Sglebius * Copyright (C) 2004, 2007, 2009 Internet Systems Consortium, Inc. ("ISC") 3290001Sglebius * Copyright (C) 2001 Internet Software Consortium. 4290001Sglebius * 5290001Sglebius * Permission to use, copy, modify, and/or distribute this software for any 6290001Sglebius * purpose with or without fee is hereby granted, provided that the above 7290001Sglebius * copyright notice and this permission notice appear in all copies. 8290001Sglebius * 9290001Sglebius * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 10290001Sglebius * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11290001Sglebius * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 12290001Sglebius * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13290001Sglebius * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 14290001Sglebius * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15290001Sglebius * PERFORMANCE OF THIS SOFTWARE. 16290001Sglebius */ 17290001Sglebius 18290001Sglebius/* $Id: ntpaths.c,v 1.15 2009/07/14 22:54:57 each Exp $ */ 19290001Sglebius 20290001Sglebius/* 21290001Sglebius * This module fetches the required path information that is specific 22290001Sglebius * to NT systems which can have its configuration and system files 23290001Sglebius * almost anywhere. It can be used to override whatever the application 24290001Sglebius * had previously assigned to the pointer. Basic information about the 25290001Sglebius * file locations are stored in the registry. 26290001Sglebius */ 27290001Sglebius 28290001Sglebius#include <config.h> 29290001Sglebius#include <isc/bind_registry.h> 30290001Sglebius#include <isc/ntpaths.h> 31290001Sglebius 32290001Sglebius/* 33290001Sglebius * Module Variables 34290001Sglebius */ 35290001Sglebius 36290001Sglebiusstatic char systemDir[MAX_PATH]; 37290001Sglebiusstatic char namedBase[MAX_PATH]; 38290001Sglebiusstatic char ns_confFile[MAX_PATH]; 39290001Sglebiusstatic char lwresd_confFile[MAX_PATH]; 40290001Sglebiusstatic char lwresd_resolvconfFile[MAX_PATH]; 41290001Sglebiusstatic char rndc_confFile[MAX_PATH]; 42290001Sglebiusstatic char ns_defaultpidfile[MAX_PATH]; 43290001Sglebiusstatic char lwresd_defaultpidfile[MAX_PATH]; 44290001Sglebiusstatic char local_state_dir[MAX_PATH]; 45290001Sglebiusstatic char sys_conf_dir[MAX_PATH]; 46290001Sglebiusstatic char rndc_keyFile[MAX_PATH]; 47290001Sglebiusstatic char session_keyFile[MAX_PATH]; 48290001Sglebius 49290001Sglebiusstatic DWORD baseLen = MAX_PATH; 50290001Sglebiusstatic BOOL Initialized = FALSE; 51290001Sglebius 52290001Sglebiusvoid 53290001Sglebiusisc_ntpaths_init() { 54290001Sglebius HKEY hKey; 55290001Sglebius BOOL keyFound = TRUE; 56290001Sglebius 57290001Sglebius memset(namedBase, 0, MAX_PATH); 58290001Sglebius if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, BIND_SUBKEY, 0, KEY_READ, &hKey) 59290001Sglebius != ERROR_SUCCESS) 60290001Sglebius keyFound = FALSE; 61290001Sglebius 62290001Sglebius if (keyFound == TRUE) { 63290001Sglebius /* Get the named directory */ 64290001Sglebius if (RegQueryValueEx(hKey, "InstallDir", NULL, NULL, 65290001Sglebius (LPBYTE)namedBase, &baseLen) != ERROR_SUCCESS) 66290001Sglebius keyFound = FALSE; 67290001Sglebius RegCloseKey(hKey); 68290001Sglebius } 69290001Sglebius 70290001Sglebius GetSystemDirectory(systemDir, MAX_PATH); 71290001Sglebius 72290001Sglebius if (keyFound == FALSE) 73290001Sglebius /* Use the System Directory as a default */ 74290001Sglebius strcpy(namedBase, systemDir); 75290001Sglebius 76290001Sglebius strcpy(ns_confFile, namedBase); 77290001Sglebius strcat(ns_confFile, "\\etc\\named.conf"); 78290001Sglebius 79290001Sglebius strcpy(lwresd_confFile, namedBase); 80290001Sglebius strcat(lwresd_confFile, "\\etc\\lwresd.conf"); 81290001Sglebius 82290001Sglebius strcpy(lwresd_resolvconfFile, systemDir); 83290001Sglebius strcat(lwresd_resolvconfFile, "\\Drivers\\etc\\resolv.conf"); 84290001Sglebius 85290001Sglebius strcpy(rndc_keyFile, namedBase); 86290001Sglebius strcat(rndc_keyFile, "\\etc\\rndc.key"); 87290001Sglebius 88290001Sglebius strcpy(session_keyFile, namedBase); 89290001Sglebius strcat(session_keyFile, "\\etc\\session.key"); 90290001Sglebius 91290001Sglebius strcpy(rndc_confFile, namedBase); 92290001Sglebius strcat(rndc_confFile, "\\etc\\rndc.conf"); 93290001Sglebius strcpy(ns_defaultpidfile, namedBase); 94290001Sglebius strcat(ns_defaultpidfile, "\\etc\\named.pid"); 95290001Sglebius 96290001Sglebius strcpy(lwresd_defaultpidfile, namedBase); 97290001Sglebius strcat(lwresd_defaultpidfile, "\\etc\\lwresd.pid"); 98290001Sglebius 99290001Sglebius strcpy(local_state_dir, namedBase); 100290001Sglebius strcat(local_state_dir, "\\bin"); 101290001Sglebius 102290001Sglebius strcpy(sys_conf_dir, namedBase); 103290001Sglebius strcat(sys_conf_dir, "\\etc"); 104290001Sglebius 105290001Sglebius Initialized = TRUE; 106290001Sglebius} 107290001Sglebius 108290001Sglebiuschar * 109290001Sglebiusisc_ntpaths_get(int ind) { 110290001Sglebius if (!Initialized) 111290001Sglebius isc_ntpaths_init(); 112290001Sglebius 113290001Sglebius switch (ind) { 114290001Sglebius case NAMED_CONF_PATH: 115290001Sglebius return (ns_confFile); 116290001Sglebius break; 117290001Sglebius case LWRES_CONF_PATH: 118290001Sglebius return (lwresd_confFile); 119290001Sglebius break; 120290001Sglebius case RESOLV_CONF_PATH: 121290001Sglebius return (lwresd_resolvconfFile); 122290001Sglebius break; 123290001Sglebius case RNDC_CONF_PATH: 124290001Sglebius return (rndc_confFile); 125290001Sglebius break; 126290001Sglebius case NAMED_PID_PATH: 127290001Sglebius return (ns_defaultpidfile); 128290001Sglebius break; 129290001Sglebius case LWRESD_PID_PATH: 130290001Sglebius return (lwresd_defaultpidfile); 131290001Sglebius break; 132290001Sglebius case LOCAL_STATE_DIR: 133290001Sglebius return (local_state_dir); 134290001Sglebius break; 135290001Sglebius case SYS_CONF_DIR: 136290001Sglebius return (sys_conf_dir); 137290001Sglebius break; 138290001Sglebius case RNDC_KEY_PATH: 139290001Sglebius return (rndc_keyFile); 140290001Sglebius break; 141290001Sglebius case SESSION_KEY_PATH: 142290001Sglebius return (session_keyFile); 143290001Sglebius break; 144290001Sglebius default: 145290001Sglebius return (NULL); 146290001Sglebius } 147290001Sglebius} 148