Changeset 76aafc4 in nscp


Ignore:
Timestamp:
10/26/06 07:03:39 (7 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2, stable
Children:
7aef770
Parents:
70f2d7b
Message:

* empty log message *

Files:
19 edited

Legend:

Unmodified
Added
Removed
  • NSC.dist

    raabbd97 r76aafc4  
    1919; CheckWMI IS AN EXTREM EARLY IDEA SO DONT USE FOR PRODUCTION ENVIROMNEMTS! 
    2020;CheckWMI.dll 
     21; 
     22; RemoteConfiguration IS AN EXTREM EARLY IDEA SO DONT USE FOR PRODUCTION ENVIROMNEMTS! 
     23;RemoteConfiguration.dll 
    2124 
    2225[Settings] 
     
    3740; 
    3841;# USE THIS FILE 
    39 ;  Use the INI file as opposed to the registry if this is 0 the registry will be used instead. 
     42;  Use the INI file as opposed to the registry if this is 0 and the use_reg in the registry is set to 1  
     43;  the registry will be used instead. 
    4044use_file=1 
    4145 
  • NSClient++.cpp

    r70f2d7b r76aafc4  
    608608  return NSCAPI::isSuccess; 
    609609} 
     610 
     611NSCAPI::errorReturn NSAPISetSettingsString(const char* section, const char* key, const char* value) { 
     612  Settings::getInstance()->setString(section, key, value); 
     613  return NSCAPI::isSuccess; 
     614} 
     615NSCAPI::errorReturn NSAPISetSettingsInt(const char* section, const char* key, int value) { 
     616  Settings::getInstance()->setInt(section, key, value); 
     617  return NSCAPI::isSuccess; 
     618} 
     619NSCAPI::errorReturn NSAPIWriteSettings(int type) { 
     620  try { 
     621    if (type == NSCAPI::settings_registry) 
     622      Settings::getInstance()->write(REGSettings::getType()); 
     623    else if (type == NSCAPI::settings_inifile) 
     624      Settings::getInstance()->write(INISettings::getType()); 
     625    else 
     626      Settings::getInstance()->write(); 
     627  } catch (SettingsException e) { 
     628    LOG_ERROR_STD(e.getMessage()); 
     629    return NSCAPI::hasFailed; 
     630  } 
     631  return NSCAPI::isSuccess; 
     632} 
     633NSCAPI::errorReturn NSAPIReadSettings(int type) { 
     634  try { 
     635    if (type == NSCAPI::settings_registry) 
     636      Settings::getInstance()->read(REGSettings::getType()); 
     637    else if (type == NSCAPI::settings_inifile) 
     638      Settings::getInstance()->read(INISettings::getType()); 
     639    else 
     640      Settings::getInstance()->read(); 
     641  } catch (SettingsException e) { 
     642    LOG_ERROR_STD(e.getMessage()); 
     643    return NSCAPI::hasFailed; 
     644  } 
     645  return NSCAPI::isSuccess; 
     646} 
     647NSCAPI::errorReturn NSAPIRehash(int flag) { 
     648  return NSCAPI::critical; 
     649} 
     650 
    610651 
    611652LPVOID NSAPILoader(char*buffer) { 
     
    634675  if (stricmp(buffer, "NSAPIDecrypt") == 0) 
    635676    return &NSAPIDecrypt; 
     677  if (stricmp(buffer, "NSAPISetSettingsString") == 0) 
     678    return &NSAPISetSettingsString; 
     679  if (stricmp(buffer, "NSAPISetSettingsInt") == 0) 
     680    return &NSAPISetSettingsInt; 
     681  if (stricmp(buffer, "NSAPIWriteSettings") == 0) 
     682    return &NSAPIWriteSettings; 
     683  if (stricmp(buffer, "NSAPIReadSettings") == 0) 
     684    return &NSAPIReadSettings; 
     685  if (stricmp(buffer, "NSAPIRehash") == 0) 
     686    return &NSAPIRehash; 
    636687  return NULL; 
    637688} 
  • NSClient++.h

    r70f2d7b r76aafc4  
    104104NSCAPI::errorReturn NSAPIEncrypt(unsigned int algorithm, const char* inBuffer, unsigned int inBufLen, char* outBuf, unsigned int *outBufLen); 
    105105NSCAPI::errorReturn NSAPIDecrypt(unsigned int algorithm, const char* inBuffer, unsigned int inBufLen, char* outBuf, unsigned int *outBufLen); 
     106NSCAPI::errorReturn NSAPISetSettingsString(const char* section, const char* key, const char* value); 
     107NSCAPI::errorReturn NSAPISetSettingsInt(const char* section, const char* key, int value); 
     108NSCAPI::errorReturn NSAPIWriteSettings(int type); 
     109NSCAPI::errorReturn NSAPIReadSettings(int type); 
     110NSCAPI::errorReturn NSAPIRehash(int flag); 
     111 
    106112////////////////////////////////////////////////////////////////////////// 
    107113// Log macros to simplify logging 
  • NSClient++.sln

    r70f2d7b r76aafc4  
    4747EndProject 
    4848Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CheckWMI", "modules\CheckWMI\CheckWMI.vcproj", "{E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}" 
     49  ProjectSection(ProjectDependencies) = postProject 
     50  EndProjectSection 
     51EndProject 
     52Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RemoteConfiguration", "modules\RemoteConfiguration\RemoteConfiguration.vcproj", "{E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}" 
    4953  ProjectSection(ProjectDependencies) = postProject 
    5054  EndProjectSection 
     
    117121    {BD93F0C3-E342-4D68-9717-FCAC2E7189AA}.Debug.Build.0 = Debug|Win32 
    118122    {BD93F0C3-E342-4D68-9717-FCAC2E7189AA}.Distribution.ActiveCfg = Debug|Win32 
    119     {BD93F0C3-E342-4D68-9717-FCAC2E7189AA}.Distribution.Build.0 = Debug|Win32 
    120123    {BD93F0C3-E342-4D68-9717-FCAC2E7189AA}.Release.ActiveCfg = Release|Win32 
     124    {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Debug.ActiveCfg = Debug|Win32 
     125    {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Debug.Build.0 = Debug|Win32 
     126    {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Distribution.ActiveCfg = Distribution|Win32 
     127    {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Distribution.Build.0 = Distribution|Win32 
     128    {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Release.ActiveCfg = Release|Win32 
     129    {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Release.Build.0 = Release|Win32 
    121130    {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Debug.ActiveCfg = Debug|Win32 
    122131    {E6E588AB-EFEF-481C-9AF7-DCDCB95CFF45}.Debug.Build.0 = Debug|Win32 
  • changelog

    rf42280d r76aafc4  
    88 * Fix WMI module 
    99 * Fix PDH problems 
     10 * Add API for rehashing the daemon (or implement it the API is there but does nothing) 
     11 * Add option to recheck DNS in real time 
     12 
     132006-10-05 MickeM 
     14 * Yayyy!!! (first fix in a looong while :) 
     15 * Fixed a W2k3 "bug" (actually just an incorrect error) but the: 
     16   "e .\PDHCollector.cpp(130) Failed to query performance counters..." is no more... 
     17 + Added option to NRPE/NSClient section to not-cache host names (for dyndns etc.) 
     18   NOTICE this is "not safe" really in so far as someone might hi-jack your DNS and quickly gain  
     19   access to your nagios box (probably only a theoretical problem but hey! :) 
     20   NOTICE this is "slow" since all hosts in the list are "looked up" each time you get a NRPE/NSClient  
     21   request it will be "slow" but I think it is not that much of a problem really. 
     22   NOTICE I dont have the posibility to test this so feel free to report if it works and if it doesn't. 
     23   Set cache_allowed_hosts=0 to disable host cache 
     24 
     252006-04-04 MickeM 
     26 * Fixed a few more bugs to the INI/REG readers 
     27 
     282006-04-02 MickeM 
     29 * Could all magicians stop trying to kill me?  
     30   *Please* i don't like to die! 
     31 
     322006-03-31 MickeM 
     33 * Damn necromancers! stop 0wning my ass all the time! 
     34  
     352006-03-29 MickeM 
     36 + Added API for saving/reading settings 
     37  
     382006-03-28 MickeM 
     39 + Added REG/INI parsers 
     40 * *NOTICE* You need to add an option (use_file=1) to your nsc.ini file or new builds wont work. 
     41 
     422006-03-25 MickeM 
     43 * Oblivion f*cking roxx! 
    1044 
    11452006-03-02 MickeM 
  • include/INISettings.h

    r70f2d7b r76aafc4  
    77#include <TSettings.h> 
    88#include <config.h> 
     9#include <iostream> 
    910 
    1011#define BUFF_LEN 4096 
     
    2728  std::string getActiveType() { 
    2829    return "INI-file"; 
     30  } 
     31  int getActiveTypeID() { 
     32    return INISettings::getType(); 
     33  } 
     34  static int getType() { 
     35    return 1; 
    2936  } 
    3037 
     
    7077      if (buffer[i] == '\0') { 
    7178        std::string s = &buffer[last]; 
    72         ret.push_back(s); 
     79        std::size_t p = s.find('='); 
     80        if (p == std::string::npos) 
     81          ret.push_back(s); 
     82        else 
     83          ret.push_back(s.substr(0,p)); 
    7384        last = i+1; 
    7485      } 
     
    93104 
    94105  void setString(std::string section, std::string key, std::string value) { 
     106//    if (value.size() > 0) 
     107    WritePrivateProfileString(section.c_str(), key.c_str(), NULL, file_.c_str()); 
    95108    WritePrivateProfileString(section.c_str(), key.c_str(), value.c_str(), file_.c_str()); 
     109//    else 
     110//      WritePrivateProfileString(section.c_str(), key.c_str(), NULL, file_.c_str()); 
    96111  } 
    97112 
  • include/NSCAPI.h

    r75d5e70 r76aafc4  
    3333  const int hasFailed = 0; 
    3434  const int isInvalidBufferLen = -2; 
     35 
     36 
    3537  typedef int nagiosReturn; 
    3638  typedef int boolReturn; 
     
    3941 
    4042  const int xor = 1; 
     43 
     44  // Settings types 
     45  const int settings_default = 0; 
     46  const int settings_registry = 1; 
     47  const int settings_inifile = 2; 
    4148 
    4249  // Various message Types 
  • include/NSCHelper.cpp

    r6817602 r76aafc4  
    110110  lpNSAPIEncrypt fNSAPIEncrypt = NULL; 
    111111  lpNSAPIDecrypt fNSAPIDecrypt = NULL; 
     112  lpNSAPISetSettingsString fNSAPISetSettingsString = NULL; 
     113  lpNSAPISetSettingsInt fNSAPISetSettingsInt = NULL; 
     114  lpNSAPIWriteSettings fNSAPIWriteSettings = NULL; 
     115  lpNSAPIReadSettings fNSAPIReadSettings = NULL; 
     116  lpNSAPIRehash fNSAPIRehash = NULL; 
     117 
    112118} 
    113119 
     
    374380} 
    375381 
    376  
    377  
    378  
    379382std::string NSCModuleHelper::Encrypt(std::string str, unsigned int algorithm) { 
    380383  if (!fNSAPIEncrypt) 
     
    408411  } 
    409412  return ""; 
     413} 
     414NSCAPI::errorReturn NSCModuleHelper::SetSettingsString(std::string section, std::string key, std::string value) { 
     415  if (!fNSAPISetSettingsString) 
     416    throw NSCMHExcpetion("NSCore has not been initiated..."); 
     417  return fNSAPISetSettingsString(section.c_str(), key.c_str(), value.c_str()); 
     418} 
     419NSCAPI::errorReturn NSCModuleHelper::SetSettingsInt(std::string section, std::string key, int value) { 
     420  if (!fNSAPISetSettingsInt) 
     421    throw NSCMHExcpetion("NSCore has not been initiated..."); 
     422  return fNSAPISetSettingsInt(section.c_str(), key.c_str(), value); 
     423} 
     424NSCAPI::errorReturn NSCModuleHelper::WriteSettings(int type) { 
     425  if (!fNSAPIWriteSettings) 
     426    throw NSCMHExcpetion("NSCore has not been initiated..."); 
     427  return fNSAPIWriteSettings(type); 
     428} 
     429NSCAPI::errorReturn NSCModuleHelper::ReadSettings(int type) { 
     430  if (!fNSAPIReadSettings) 
     431    throw NSCMHExcpetion("NSCore has not been initiated..."); 
     432  return fNSAPIReadSettings(type); 
     433} 
     434NSCAPI::errorReturn NSCModuleHelper::Rehash(int flag) { 
     435  if (!fNSAPIRehash) 
     436    throw NSCMHExcpetion("NSCore has not been initiated..."); 
     437  return fNSAPIRehash(flag); 
    410438} 
    411439 
     
    481509  NSCModuleHelper::fNSAPIDecrypt = (NSCModuleHelper::lpNSAPIDecrypt)f("NSAPIDecrypt"); 
    482510  NSCModuleHelper::fNSAPIEncrypt = (NSCModuleHelper::lpNSAPIEncrypt)f("NSAPIEncrypt"); 
     511  NSCModuleHelper::fNSAPISetSettingsString = (NSCModuleHelper::lpNSAPISetSettingsString)f("NSAPISetSettingsString"); 
     512  NSCModuleHelper::fNSAPISetSettingsInt = (NSCModuleHelper::lpNSAPISetSettingsInt)f("NSAPISetSettingsInt"); 
     513  NSCModuleHelper::fNSAPIWriteSettings = (NSCModuleHelper::lpNSAPIWriteSettings)f("NSAPIWriteSettings"); 
     514  NSCModuleHelper::fNSAPIReadSettings = (NSCModuleHelper::lpNSAPIReadSettings)f("NSAPIReadSettings"); 
     515  NSCModuleHelper::fNSAPIRehash = (NSCModuleHelper::lpNSAPIRehash)f("NSAPIRehash"); 
    483516  return NSCAPI::isSuccess; 
    484517} 
  • include/NSCHelper.h

    r6817602 r76aafc4  
    8787  typedef NSCAPI::errorReturn (*lpNSAPIEncrypt)(unsigned int, const char*, unsigned int, char*, unsigned int *); 
    8888  typedef NSCAPI::errorReturn (*lpNSAPIDecrypt)(unsigned int, const char*, unsigned int, char*, unsigned int *); 
     89  typedef NSCAPI::errorReturn (*lpNSAPISetSettingsString)(const char*, const char*, const char*); 
     90  typedef NSCAPI::errorReturn (*lpNSAPISetSettingsInt)(const char*, const char*, int); 
     91  typedef NSCAPI::errorReturn (*lpNSAPIWriteSettings)(int); 
     92  typedef NSCAPI::errorReturn (*lpNSAPIReadSettings)(int); 
     93  typedef NSCAPI::errorReturn (*lpNSAPIRehash)(int); 
    8994 
    9095  // Helper functions for calling into the core 
     
    105110  std::string Encrypt(std::string str, unsigned int algorithm = NSCAPI::xor); 
    106111  std::string Decrypt(std::string str, unsigned int algorithm = NSCAPI::xor); 
     112  NSCAPI::errorReturn SetSettingsString(std::string section, std::string key, std::string value); 
     113  NSCAPI::errorReturn SetSettingsInt(std::string section, std::string key, int value); 
     114  NSCAPI::errorReturn WriteSettings(int type); 
     115  NSCAPI::errorReturn ReadSettings(int type); 
     116  NSCAPI::errorReturn Rehash(int flag); 
    107117}; 
    108118 
  • include/PDHCounter.h

    r6817602 r76aafc4  
    8282      dwQueryUserData = info->dwQueryUserData; 
    8383      szFullPath = info->szFullPath; 
     84      if (info->szMachineName) 
     85        szMachineName = info->szMachineName; 
     86      if (info->szObjectName) 
     87        szObjectName = info->szObjectName; 
     88      if (info->szInstanceName) 
     89        szInstanceName = info->szInstanceName; 
     90      if (info->szParentInstance) 
     91        szParentInstance = info->szParentInstance; 
     92      dwInstanceIndex = info->dwInstanceIndex; 
     93      if (info->szCounterName) 
     94        szCounterName = info->szCounterName; 
    8495      if (explainText) { 
    85         if (info->szMachineName) 
    86           szMachineName = info->szMachineName; 
    87         if (info->szObjectName) 
    88           szObjectName = info->szObjectName; 
    89         if (info->szInstanceName) 
    90           szInstanceName = info->szInstanceName; 
    91         if (info->szParentInstance) 
    92           szParentInstance = info->szParentInstance; 
    93         dwInstanceIndex = info->dwInstanceIndex; 
    94         if (info->szCounterName) 
    95           szCounterName = info->szCounterName; 
     96        if (info->szExplainText) 
     97          szExplainText = info->szExplainText; 
    9698      } 
    9799    } 
     
    119121    } 
    120122 
    121     PDHCounterInfo getCounterInfo() { 
     123    PDHCounterInfo getCounterInfo(BOOL bExplainText = FALSE) { 
    122124      assert(hCounter_ != NULL); 
    123125      PDH_STATUS status; 
    124126      BYTE *lpBuffer = new BYTE[1025]; 
    125127      DWORD bufSize = 1024; 
    126       if ((status = PdhGetCounterInfo(hCounter_, TRUE, &bufSize, (PDH_COUNTER_INFO*)lpBuffer)) != ERROR_SUCCESS) { 
     128      if ((status = PdhGetCounterInfo(hCounter_, bExplainText, &bufSize, (PDH_COUNTER_INFO*)lpBuffer)) != ERROR_SUCCESS) { 
    127129        throw PDHException(name_, "getCounterInfo failed (no query)", status); 
    128130      } 
  • include/REGSettings.h

    r70f2d7b r76aafc4  
    2020 
    2121  static bool hasSettings() { 
    22     return getInt_(NS_HKEY_ROOT, NS_REG_ROOT, "use_reg", 0) == 1; 
     22    return getInt_(NS_HKEY_ROOT, NS_REG_ROOT "\\" MAIN_SECTION_TITLE, MAIN_USEREG, 0) == 1; 
    2323  } 
    2424 
     
    5151 
    5252  void setString(std::string section, std::string key, std::string value) { 
     53    setString_(NS_HKEY_ROOT, std::string((std::string)NS_REG_ROOT + "\\" + section).c_str(), key.c_str(), value.c_str()); 
    5354  } 
    5455 
     
    6465  } 
    6566  void setInt(std::string section, std::string key, int value) { 
    66   } 
    67  
     67    setInt_(NS_HKEY_ROOT, std::string((std::string)NS_REG_ROOT + "\\" + section).c_str(), key.c_str(), value); 
     68  } 
     69 
     70  static bool setString_(HKEY hKey, LPCTSTR lpszPath, LPCTSTR lpszKey, LPCTSTR value) { 
     71    HKEY hTemp; 
     72    if (RegCreateKeyEx(hKey, lpszPath, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hTemp, NULL) != ERROR_SUCCESS) { 
     73      return false; 
     74    } 
     75    DWORD cbData = static_cast<DWORD>(strlen(value)); 
     76    BYTE *bData = new BYTE[cbData+1]; 
     77    strncpy(reinterpret_cast<char*>(bData), value, cbData); 
     78    BOOL bRet = RegSetValueEx(hTemp, lpszKey, NULL, REG_SZ, bData, cbData); 
     79    RegCloseKey(hTemp); 
     80    delete [] bData; 
     81    return  (bRet == ERROR_SUCCESS); 
     82  } 
     83 
     84  int getActiveTypeID() { 
     85    return REGSettings::getType(); 
     86  } 
     87  static int getType() { 
     88    return 2; 
     89  } 
     90 
     91  static bool setInt_(HKEY hKey, LPCTSTR lpszPath, LPCTSTR lpszKey, DWORD value) { 
     92    HKEY hTemp; 
     93    if (RegCreateKeyEx(hKey, lpszPath, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hTemp, NULL) != ERROR_SUCCESS) { 
     94      return false; 
     95    } 
     96    BOOL bRet = RegSetValueEx(hTemp, lpszKey, NULL, REG_DWORD, reinterpret_cast<const BYTE*>(&value), sizeof(DWORD)); 
     97    RegCloseKey(hTemp); 
     98    return  (bRet == ERROR_SUCCESS); 
     99  } 
    68100 
    69101  static std::string getString_(HKEY hKey, LPCTSTR lpszPath, LPCTSTR lpszKey, std::string def) { 
     
    74106    } 
    75107    DWORD type; 
    76     DWORD cbData = 1024; 
     108    const DWORD data_length = 2048; 
     109    DWORD cbData = data_length; 
    77110    BYTE *bData = new BYTE[cbData]; 
    78     BOOL bRet = RegQueryValueEx(hTemp, lpszKey, NULL, &type, bData, &cbData); 
    79     if (type != REG_SZ) { 
    80       bRet = false; 
    81     } 
    82     RegCloseKey(hTemp); 
    83     if (bRet) { 
    84       ret = (LPCTSTR)bData; 
    85     } 
     111    LONG lRet = RegQueryValueEx(hTemp, lpszKey, NULL, &type, bData, &cbData); 
     112    if (lRet == ERROR_SUCCESS) { 
     113      if (type == REG_SZ) { 
     114        if (cbData < data_length-1) { 
     115          bData[cbData] = 0; 
     116          ret = reinterpret_cast<LPCTSTR>(bData); 
     117        } else { 
     118          std::cout << "getString_::Buffersize to small: " << lpszPath << "." << lpszKey << ": " << type << std::endl; 
     119        } 
     120      } else if (type == REG_DWORD) { 
     121        DWORD dw = *(reinterpret_cast<DWORD*>(bData)); 
     122        ret = strEx::itos(dw); 
     123      } else { 
     124        std::cout << "getString_::Unsupported type: " << lpszPath << "." << lpszKey << ": " << type << std::endl; 
     125      } 
     126    } else { 
     127      std::cout << "getString_::Error: " << lpszPath << "." << lpszKey << ": " << lRet << std::endl; 
     128    } 
     129    RegCloseKey(hTemp); 
    86130    delete [] bData; 
    87131    return ret; 
     
    95139    } 
    96140    DWORD type; 
    97     DWORD cbData = 1024; 
    98     BYTE *bData = new BYTE[sizeof(DWORD)]; 
     141    DWORD cbData = sizeof(DWORD); 
     142    BYTE *bData = new BYTE[cbData+1]; 
    99143    bRet = RegQueryValueEx(hTemp, lpszKey, NULL, &type, bData, &cbData); 
    100144    if (type != REG_DWORD) { 
     
    103147    RegCloseKey(hTemp); 
    104148    if (bRet == ERROR_SUCCESS) { 
    105       ret = (DWORD)*bData; 
     149      ret = static_cast<DWORD>(*bData); 
    106150    } 
    107151    delete [] bData; 
     
    115159      return ret; 
    116160    } 
    117     DWORD    cValues=0; 
    118     DWORD    cMaxValLen; 
     161    DWORD cValues=0; 
     162    DWORD cMaxValLen=0; 
    119163    // Get the class name and the value count.  
    120164    bRet = RegQueryInfoKey(hTemp,NULL,NULL,NULL,NULL,NULL,NULL,&cValues,&cMaxValLen,NULL,NULL,NULL); 
     165    cMaxValLen++; 
    121166    if ((bRet == ERROR_SUCCESS)&&(cValues>0)) { 
    122167      TCHAR *lpValueName = new TCHAR[cMaxValLen+1]; 
    123168      for (unsigned int i=0; i<cValues; i++) { 
    124169        DWORD len = cMaxValLen; 
    125         bRet = RegEnumValue(hKey, i, lpValueName, &len, NULL, NULL, NULL, NULL); 
     170        bRet = RegEnumValue(hTemp, i, lpValueName, &len, NULL, NULL, NULL, NULL); 
    126171        if (bRet == ERROR_SUCCESS) { 
    127172          ret.push_back(std::string(lpValueName)); 
     173        } else { 
     174          std::cout << "getValues_::Error: " << bRet << ": " << lpszPath << "[" << i << "]" << std::endl; 
     175 
    128176        } 
    129177      } 
     
    143191    // Get the class name and the value count.  
    144192    bRet = RegQueryInfoKey(hTemp,NULL,NULL,NULL,&cSubKeys,&cMaxKeyLen,NULL,NULL,NULL,NULL,NULL,NULL); 
     193    cMaxKeyLen++; 
    145194    if ((bRet == ERROR_SUCCESS)&&(cSubKeys>0)) { 
    146195      TCHAR *lpValueName = new TCHAR[cMaxKeyLen+1]; 
    147196      for (unsigned int i=0; i<cSubKeys; i++) { 
    148197        DWORD len = cMaxKeyLen; 
    149         bRet = RegEnumKey(hKey, i, lpValueName, len); 
     198        bRet = RegEnumKey(hTemp, i, lpValueName, len); 
    150199        if (bRet == ERROR_SUCCESS) { 
    151200          ret.push_back(std::string(lpValueName)); 
     201        } else { 
     202          std::cout << "getSubKeys_::Error: " << bRet << ": " << lpszPath << "[" << i << "]" << std::endl; 
    152203        } 
    153204      } 
  • include/Settings.h

    r70f2d7b r76aafc4  
    3232  typedef std::map<std::string,saveKeyList> saveSectionList; 
    3333  saveSectionList data_; 
     34  std::string file_; 
    3435  bool bHasInternalData; 
    3536  TSettings *settingsManager; 
     
    5758   */ 
    5859  void setFile(std::string file, bool forceini = false) { 
     60    file_ = file; 
    5961    if (forceini) { 
    6062      if (settingsManager) 
     
    7880#define UNLIKELY_VALUE_1 -1234 
    7981#define UNLIKELY_VALUE_2 -4321 
    80   void read() { 
    81     sectionList sections = getSections(); 
     82  void read(int type = -1) { 
     83    bool bNew = false; 
     84    TSettings *sM = settingsManager; 
     85    if ((type != -1)&&(type != settingsManager->getActiveTypeID())) { 
     86      if (type == REGSettings::getType()) { 
     87        sM = new REGSettings(); 
     88        bNew = true; 
     89      } else if (type == INISettings::getType()) { 
     90        sM = new INISettings(file_); 
     91        bNew = true; 
     92      } else { 
     93        throw SettingsException("Invalid settings subsystem specified"); 
     94      } 
     95    } 
     96    if (sM == NULL) { 
     97      throw SettingsException("Invalid settings subsystem specified"); 
     98    } 
     99    sectionList sections = sM->getSections(); 
    82100    for (sectionList::const_iterator it=sections.begin();it!=sections.end();++it) { 
    83       sectionList section = getSection(*it); 
     101      sectionList section = sM->getSection(*it); 
    84102      for (sectionList::const_iterator it2=section.begin();it2!=section.end();++it2) { 
    85         int i = getInt((*it), (*it2), UNLIKELY_VALUE_1); 
     103        std::string s = sM->getString((*it), (*it2)); 
     104        int i = strEx::stoi(s); 
     105        std::string s2 = strEx::itos(i); 
     106        std::cout << "importing: " << (*it) << "/" << (*it2) << "=" << s << std::endl; 
     107        if (s == s2) { 
     108          setInt((*it), (*it2), i); 
     109        } else { 
     110          setString((*it), (*it2), s); 
     111        } 
     112 
     113/* 
     114        std::cout << "  Key: " << (*it2) << std::endl; 
     115        int i = sM->getInt((*it), (*it2), UNLIKELY_VALUE_1); 
     116        std::cout << "Int vaöl: " << i << std::endl; 
    86117        if (i == UNLIKELY_VALUE_1) { 
    87           if (getInt((*it), (*it2), UNLIKELY_VALUE_2)==UNLIKELY_VALUE_2) 
    88             getString((*it), (*it2)); 
    89         } 
    90       } 
    91     } 
    92   } 
    93   void write() { 
     118          if (sM->getInt((*it), (*it2), UNLIKELY_VALUE_2)==UNLIKELY_VALUE_2) { 
     119            std::cout << "Writing: " << (*it) << " - " << (*it2) << " - " << sM->getString((*it), (*it2)) << std::endl; 
     120            setString((*it), (*it2), sM->getString((*it), (*it2))); 
     121          } else 
     122            setInt((*it), (*it2), i); 
     123        } else if (i == 0) { 
     124          std::string s = sM->getString((*it), (*it2)); 
     125          std::cout << "Size: " << s.size() << " |" << s << "| " << std::endl; 
     126          if (s.size() == 0) 
     127            setString((*it), (*it2), s); 
     128          else 
     129            setInt((*it), (*it2), i); 
     130        } else 
     131          setInt((*it), (*it2), i); 
     132          */ 
     133      } 
     134    } 
     135    if (bNew) { 
     136      delete sM; 
     137    } 
     138  } 
     139  void write(int type = -1) { 
     140    bool bNew = false; 
     141    TSettings *sM = settingsManager; 
     142    if ((type != -1)&&(type != settingsManager->getActiveTypeID())) { 
     143      if (type == REGSettings::getType()) { 
     144        sM = new REGSettings(); 
     145        bNew = true; 
     146      } else if (type == INISettings::getType()) { 
     147        sM = new INISettings(file_); 
     148        bNew = true; 
     149      } else { 
     150        throw SettingsException("Invalid settings subsystem specified"); 
     151      } 
     152    } 
     153    if (sM == NULL) { 
     154      throw SettingsException("Invalid settings subsystem specified"); 
     155    } 
    94156    if (bHasInternalData) { 
    95157      for (saveSectionList::const_iterator it=data_.begin();it!=data_.end();++it) { 
    96158        for (saveKeyList::const_iterator kit = it->second.begin(); kit != it->second.end(); ++kit) { 
    97159          if (kit->second.type == valueStruct::sType) 
    98             setString(it->first, kit->first, kit->second.sVal); 
    99           else 
    100             setInt(it->first, kit->first, kit->second.iVal); 
    101         } 
    102       } 
     160            sM->setString(it->first, kit->first, kit->second.sVal); 
     161          else 
     162            sM->setInt(it->first, kit->first, kit->second.iVal); 
     163        } 
     164      } 
     165    } 
     166    if (bNew) { 
     167      delete sM; 
    103168    } 
    104169  } 
  • include/Socket.h

    rf42280d r76aafc4  
    462462  private: 
    463463    host_list allowedHosts_; 
    464   public: 
    465     void setAllowedHosts(host_list allowedHosts) { 
     464    bool cachedAddresses_; 
     465  public: 
     466    allowedHosts() : cachedAddresses_(true) {} 
     467    void setAllowedHosts(host_list allowedHosts, bool cachedAddresses) { 
     468      cachedAddresses_ = cachedAddresses; 
    466469      if ((!allowedHosts.empty()) && (allowedHosts.front() == "") ) 
    467470        allowedHosts.pop_front(); 
    468471      allowedHosts_ = allowedHosts; 
    469       for (host_list::iterator it = allowedHosts_.begin();it!=allowedHosts_.end();++it) { 
    470         if (((*it).length() > 0) && (std::isalpha((*it)[0]))) { 
    471           std::string s = (*it); 
    472           try { 
    473             *it = simpleSocket::Socket::getHostByName(s); 
    474           } catch (simpleSocket::SocketException e) { 
    475             e; 
     472      if (cachedAddresses_) { 
     473        for (host_list::iterator it = allowedHosts_.begin();it!=allowedHosts_.end();++it) { 
     474          if (((*it).length() > 0) && (std::isalpha((*it)[0]))) { 
     475            std::string s = (*it); 
     476            try { 
     477              *it = simpleSocket::Socket::getHostByName(s); 
     478            } catch (simpleSocket::SocketException e) { 
     479              e; 
     480            } 
    476481          } 
    477482        } 
     
    482487        return true; 
    483488      host_list::const_iterator cit; 
     489      if (!cachedAddresses_) { 
     490        for (host_list::iterator it = allowedHosts_.begin();it!=allowedHosts_.end();++it) { 
     491          if (((*it).length() > 0) && (std::isalpha((*it)[0]))) { 
     492            std::string s = (*it); 
     493            try { 
     494              *it = simpleSocket::Socket::getHostByName(s); 
     495            } catch (simpleSocket::SocketException e) { 
     496              e; 
     497            } 
     498          } 
     499        } 
     500      } 
    484501      for (cit = allowedHosts_.begin();cit!=allowedHosts_.end();++cit) { 
    485502        if ( (*cit) == s) 
  • include/TSettings.h

    r70f2d7b r76aafc4  
    2323  virtual int getInt(std::string section, std::string key, int defaultValue = 0) = 0; 
    2424  virtual void setInt(std::string section, std::string key, int value) = 0; 
     25  virtual int getActiveTypeID() = 0; 
    2526}; 
  • include/config.h

    r70f2d7b r76aafc4  
    9696#define MAIN_SECTION_TITLE "Settings" 
    9797#define MAIN_USEFILE "use_file" 
     98#define MAIN_USEREG "use_reg" 
    9899#define MAIN_USEFILE_DEFAULT 0 
    99100#define MAIN_MASTERKEY "master_key"  
     
    105106#define MAIN_ALLOWED_HOSTS "allowed_hosts" 
    106107#define MAIN_ALLOWED_HOSTS_DEFAULT "127.0.0.1" 
     108#define MAIN_ALLOWED_HOSTS_CACHE "cache_allowed_hosts" 
     109#define MAIN_ALLOWED_HOSTS_CACHE_DEFAULT 1 
    107110 
    108111 
  • modules/CheckSystem/CheckSystem.cpp

    rf42280d r76aafc4  
    117117            std::string counter = "\\" + (*it).name + "(" + (*it2).name + ")\\" + (*it3).name; 
    118118            std::cout << "testing: " << counter << ": "; 
     119            std::list<std::string> errors; 
     120            std::list<std::string> status; 
    119121            std::string error; 
     122            bool bStatus = true; 
    120123            if (PDH::Enumerations::validate(counter, error)) { 
    121               std::cout << " found "; 
     124              status.push_back("open"); 
    122125            } else { 
    123               std::cout << " *NOT* found (" << error << ") " << std::endl; 
    124               break; 
     126              errors.push_back("NOT found: " + error); 
     127              bStatus = false; 
    125128            } 
    126             bool bOpend = false; 
    127             try { 
     129            if (bStatus) { 
     130              PDH::PDHCounter *pCounter = NULL; 
    128131              PDH::PDHQuery pdh; 
    129               PDHCollectors::StaticPDHCounterListener<double, PDH_FMT_DOUBLE> cDouble; 
    130               pdh.addCounter(counter, &cDouble); 
    131               pdh.open(); 
    132               pdh.gatherData(); 
    133               pdh.close(); 
    134               bOpend = true; 
    135             } catch (const PDH::PDHException e) { 
    136               std::cout << " could *not* be open (" << e.getError() << ") " << std::endl; 
    137               break; 
     132              try { 
     133                PDHCollectors::StaticPDHCounterListener<double, PDH_FMT_DOUBLE> cDouble; 
     134                pCounter = pdh.addCounter(counter, &cDouble); 
     135                pdh.open(); 
     136 
     137                if (pCounter != NULL) { 
     138                  try { 
     139                    PDH::PDHCounterInfo info = pCounter->getCounterInfo(); 
     140                    errors.push_back("CounterName: " + info.szCounterName); 
     141                    errors.push_back("ExplainText: " + info.szExplainText); 
     142                    errors.push_back("FullPath: " + info.szFullPath); 
     143                    errors.push_back("InstanceName: " + info.szInstanceName); 
     144                    errors.push_back("MachineName: " + info.szMachineName); 
     145                    errors.push_back("ObjectName: " + info.szObjectName); 
     146                    errors.push_back("ParentInstance: " + info.szParentInstance); 
     147                    errors.push_back("Type: " + strEx::itos(info.dwType)); 
     148                    errors.push_back("Scale: " + strEx::itos(info.lScale)); 
     149                    errors.push_back("Default Scale: " + strEx::itos(info.lDefaultScale)); 
     150                    errors.push_back("Status: " + strEx::itos(info.CStatus)); 
     151                    status.push_back("described"); 
     152                  } catch (const PDH::PDHException e) { 
     153                    errors.push_back("Describe failed: " + e.getError()); 
     154                    bStatus = false; 
     155                  } 
     156                } 
     157 
     158                pdh.gatherData(); 
     159                pdh.close(); 
     160                status.push_back("queried"); 
     161              } catch (const PDH::PDHException e) { 
     162                errors.push_back("Query failed: " + e.getError()); 
     163                bStatus = false; 
     164                try { 
     165                  pdh.gatherData(); 
     166                  pdh.close(); 
     167                  bStatus = true; 
     168                } catch (const PDH::PDHException e) { 
     169                  errors.push_back("Query failed (again!): " + e.getError()); 
     170                } 
     171              } 
     172 
    138173            } 
    139             std::cout << " open "; 
    140             std::cout << std::endl; 
     174            if (!bStatus) { 
     175              std::list<std::string>::const_iterator cit = status.begin(); 
     176              for (;cit != status.end(); ++cit) { 
     177                std::cout << *cit << ", "; 
     178              } 
     179              std::cout << std::endl; 
     180              std::cout << "  | Log" << std::endl; 
     181              std::cout << "--+------  --    -" << std::endl; 
     182              cit = errors.begin(); 
     183              for (;cit != errors.end(); ++cit) { 
     184                std::cout << "  | " << *cit << std::endl; 
     185              } 
     186            } else { 
     187              std::list<std::string>::const_iterator cit = status.begin(); 
     188              for (;cit != status.end(); ++cit) { 
     189                std::cout << *cit << ", ";; 
     190              } 
     191              std::cout << std::endl; 
     192            } 
    141193          } 
    142194        } 
  • modules/CheckSystem/PDHCollector.cpp

    raabbd97 r76aafc4  
    120120 
    121121  DWORD waitStatus = 0; 
     122  bool first = true; 
    122123  do { 
    123124    MutexLock mutex(mutexHandler); 
     
    128129        pdh.gatherData(); 
    129130      } catch (const PDH::PDHException &e) { 
    130         NSC_LOG_ERROR_STD("Failed to query performance counters: " + e.getError()); 
     131        if (first) {  // If this is the first run an error will be thrown since the data is not yet avalible 
     132                // This is "ok" but perhaps another solution would be better, but this works :) 
     133          first = false; 
     134        } else { 
     135          NSC_LOG_ERROR_STD("Failed to query performance counters: " + e.getError()); 
     136        } 
    131137      } 
    132138    }  
  • modules/NRPEListener/NRPEListener.cpp

    rf42280d r76aafc4  
    2828  return ret; 
    2929} 
     30bool getCacheAllowedHosts() { 
     31  int val = NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, MAIN_ALLOWED_HOSTS_CACHE, -1); 
     32  if (val == -1) 
     33    val = NSCModuleHelper::getSettingsInt(MAIN_SECTION_TITLE, MAIN_ALLOWED_HOSTS_CACHE, MAIN_ALLOWED_HOSTS_CACHE_DEFAULT); 
     34  return val==1?true:false; 
     35} 
    3036 
    3137bool NRPEListener::loadModule() { 
     
    3339  timeout = NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, NRPE_SETTINGS_TIMEOUT ,NRPE_SETTINGS_TIMEOUT_DEFAULT); 
    3440  std::list<std::string> commands = NSCModuleHelper::getSettingsSection(NRPE_HANDLER_SECTION_TITLE); 
    35   std::list<std::string>::iterator it; 
    36   for (it = commands.begin(); it != commands.end(); it++) { 
    37     strEx::token t = strEx::getToken(*it, '='); 
    38     if (t.first.substr(0,7) == "command") { 
    39       strEx::token t2 = strEx::getToken(t.first, '['); 
    40       t2 = strEx::getToken(t2.second, ']'); 
    41       t.first = t2.first; 
    42     } 
    43     if (t.first.empty() || t.second.empty()) { 
     41  std::list<std::string>::const_iterator it; 
     42  for (it = commands.begin(); it != commands.end(); ++it) { 
     43    std::string command_name; 
     44    if (((*it).length() > 7)&&((*it).substr(0,7) == "command")) { 
     45      strEx::token t = strEx::getToken((*it), '['); 
     46      t = strEx::getToken(t.second, ']'); 
     47      command_name = t.first; 
     48    } else { 
     49      command_name = (*it); 
     50    } 
     51    std::string s = NSCModuleHelper::getSettingsString(NRPE_HANDLER_SECTION_TITLE, (*it), ""); 
     52    if (command_name.empty() || s.empty()) { 
    4453      NSC_LOG_ERROR_STD("Invalid command definition: " + (*it)); 
    4554    } else { 
    46       addCommand(t.first.c_str(), t.second); 
    47     } 
    48   } 
    49  
    50   allowedHosts.setAllowedHosts(strEx::splitEx(getAllowedHosts(), ",")); 
     55      addCommand(command_name.c_str(), s); 
     56    } 
     57  } 
     58 
     59  allowedHosts.setAllowedHosts(strEx::splitEx(getAllowedHosts(), ","), getCacheAllowedHosts()); 
    5160  try { 
    5261    unsigned short port = NSCModuleHelper::getSettingsInt(NRPE_SECTION_TITLE, NRPE_SETTINGS_PORT, NRPE_SETTINGS_PORT_DEFAULT); 
  • modules/NSClientListener/NSClientListener.cpp

    raabbd97 r76aafc4  
    3838  return ret; 
    3939} 
     40bool getCacheAllowedHosts() { 
     41  int val = NSCModuleHelper::getSettingsInt(NSCLIENT_SECTION_TITLE, MAIN_ALLOWED_HOSTS_CACHE, -1); 
     42  if (val == -1) 
     43    val = NSCModuleHelper::getSettingsInt(MAIN_SECTION_TITLE, MAIN_ALLOWED_HOSTS_CACHE, MAIN_ALLOWED_HOSTS_CACHE_DEFAULT); 
     44  return val==1?true:false; 
     45} 
    4046 
    4147bool NSClientListener::loadModule() { 
    42   allowedHosts.setAllowedHosts(strEx::splitEx(getAllowedHosts(), ",")); 
     48  allowedHosts.setAllowedHosts(strEx::splitEx(getAllowedHosts(), ","), getCacheAllowedHosts()); 
    4349  unsigned short port = NSCModuleHelper::getSettingsInt(NSCLIENT_SECTION_TITLE, NSCLIENT_SETTINGS_PORT, NSCLIENT_SETTINGS_PORT_DEFAULT); 
    4450  std::string host = NSCModuleHelper::getSettingsString(NSCLIENT_SECTION_TITLE, NSCLIENT_SETTINGS_BINDADDR, NSCLIENT_SETTINGS_BINDADDR_DEFAULT); 
Note: See TracChangeset for help on using the changeset viewer.