"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.11.23/lib/isc/win32/ntpaths.c" (7 Sep 2020, 4310 Bytes) of package /linux/misc/dns/bind9/9.11.23/bind-9.11.23.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "ntpaths.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
    3  *
    4  * This Source Code Form is subject to the terms of the Mozilla Public
    5  * License, v. 2.0. If a copy of the MPL was not distributed with this
    6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
    7  *
    8  * See the COPYRIGHT file distributed with this work for additional
    9  * information regarding copyright ownership.
   10  */
   11 
   12 
   13 /*
   14  * This module fetches the required path information that is specific
   15  * to NT systems which can have its configuration and system files
   16  * almost anywhere. It can be used to override whatever the application
   17  * had previously assigned to the pointer. Basic information about the
   18  * file locations are stored in the registry.
   19  */
   20 
   21 #include <config.h>
   22 
   23 #include <isc/bind_registry.h>
   24 #include <isc/ntpaths.h>
   25 #include <isc/string.h>
   26 
   27 /*
   28  * Module Variables
   29  */
   30 
   31 static char systemDir[MAX_PATH];
   32 static char namedBase[MAX_PATH];
   33 static char ns_confFile[MAX_PATH];
   34 static char lwresd_confFile[MAX_PATH];
   35 static char lwresd_resolvconfFile[MAX_PATH];
   36 static char rndc_confFile[MAX_PATH];
   37 static char ns_defaultpidfile[MAX_PATH];
   38 static char lwresd_defaultpidfile[MAX_PATH];
   39 static char ns_lockfile[MAX_PATH];
   40 static char local_state_dir[MAX_PATH];
   41 static char sys_conf_dir[MAX_PATH];
   42 static char rndc_keyFile[MAX_PATH];
   43 static char session_keyFile[MAX_PATH];
   44 
   45 static DWORD baseLen = MAX_PATH;
   46 static BOOL Initialized = FALSE;
   47 
   48 void
   49 isc_ntpaths_init(void) {
   50     HKEY hKey;
   51     BOOL keyFound = TRUE;
   52 
   53     memset(namedBase, 0, sizeof(namedBase));
   54     if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, BIND_SUBKEY, 0, KEY_READ, &hKey)
   55         != ERROR_SUCCESS)
   56         keyFound = FALSE;
   57 
   58     if (keyFound == TRUE) {
   59         /* Get the named directory */
   60         if (RegQueryValueEx(hKey, "InstallDir", NULL, NULL,
   61             (LPBYTE)namedBase, &baseLen) != ERROR_SUCCESS)
   62             keyFound = FALSE;
   63         RegCloseKey(hKey);
   64     }
   65 
   66     GetSystemDirectory(systemDir, MAX_PATH);
   67 
   68     if (keyFound == FALSE) {
   69         /* Use the System Directory as a default */
   70         strlcpy(namedBase, systemDir, sizeof(namedBase));
   71     }
   72 
   73     strlcpy(lwresd_confFile, namedBase, sizeof(lwresd_confFile)) ;
   74     strlcat(lwresd_confFile, "\\etc\\lwresd.conf",
   75         sizeof(lwresd_confFile));
   76 
   77     strlcpy(lwresd_defaultpidfile, namedBase,
   78         sizeof(lwresd_defaultpidfile));
   79     strlcat(lwresd_defaultpidfile, "\\etc\\lwresd.pid",
   80         sizeof(lwresd_defaultpidfile));
   81 
   82     strlcpy(lwresd_resolvconfFile, systemDir,
   83         sizeof(lwresd_resolvconfFile));
   84     strlcat(lwresd_resolvconfFile, "\\Drivers\\etc\\resolv.conf",
   85         sizeof(lwresd_resolvconfFile));
   86 
   87     strlcpy(ns_confFile, namedBase, sizeof(ns_confFile));
   88     strlcat(ns_confFile, "\\etc\\named.conf", sizeof(ns_confFile));
   89 
   90     strlcpy(rndc_keyFile, namedBase, sizeof(rndc_keyFile));
   91     strlcat(rndc_keyFile, "\\etc\\rndc.key", sizeof(rndc_keyFile));
   92 
   93     strlcpy(session_keyFile, namedBase, sizeof(session_keyFile));
   94     strlcat(session_keyFile, "\\etc\\session.key", sizeof(session_keyFile));
   95 
   96     strlcpy(rndc_confFile, namedBase, sizeof(rndc_confFile));
   97     strlcat(rndc_confFile, "\\etc\\rndc.conf", sizeof(rndc_confFile));
   98 
   99     strlcpy(ns_defaultpidfile, namedBase, sizeof(ns_defaultpidfile));
  100     strlcat(ns_defaultpidfile, "\\etc\\named.pid",
  101         sizeof(ns_defaultpidfile));
  102 
  103     strlcpy(ns_lockfile, namedBase, sizeof(ns_lockfile));
  104     strlcat(ns_lockfile, "\\etc\\named.lock", sizeof(ns_lockfile));
  105 
  106     strlcpy(local_state_dir, namedBase, sizeof(local_state_dir));
  107     strlcat(local_state_dir, "\\bin", sizeof(local_state_dir));
  108 
  109     strlcpy(sys_conf_dir, namedBase, sizeof(sys_conf_dir));
  110     strlcat(sys_conf_dir, "\\etc", sizeof(sys_conf_dir));
  111 
  112     Initialized = TRUE;
  113 }
  114 
  115 char *
  116 isc_ntpaths_get(int ind) {
  117     if (!Initialized)
  118         isc_ntpaths_init();
  119 
  120     switch (ind) {
  121     case NAMED_CONF_PATH:
  122         return (ns_confFile);
  123         break;
  124     case LWRES_CONF_PATH:
  125         return (lwresd_confFile);
  126         break;
  127     case RESOLV_CONF_PATH:
  128         return (lwresd_resolvconfFile);
  129         break;
  130     case RNDC_CONF_PATH:
  131         return (rndc_confFile);
  132         break;
  133     case NAMED_PID_PATH:
  134         return (ns_defaultpidfile);
  135         break;
  136     case LWRESD_PID_PATH:
  137         return (lwresd_defaultpidfile);
  138         break;
  139     case NAMED_LOCK_PATH:
  140         return (ns_lockfile);
  141         break;
  142     case LOCAL_STATE_DIR:
  143         return (local_state_dir);
  144         break;
  145     case SYS_CONF_DIR:
  146         return (sys_conf_dir);
  147         break;
  148     case RNDC_KEY_PATH:
  149         return (rndc_keyFile);
  150         break;
  151     case SESSION_KEY_PATH:
  152         return (session_keyFile);
  153         break;
  154     default:
  155         return (NULL);
  156     }
  157 }