Changeset 978bd31 in nscp
- Timestamp:
- 11/28/07 20:33:21 (5 years ago)
- Branches:
- master, 0.4.0, 0.4.1, 0.4.2, stable
- Children:
- 013a71f
- Parents:
- 3f569d3
- Files:
-
- 19 edited
-
NSClient++.cpp (modified) (4 diffs)
-
changelog (modified) (1 diff)
-
include/EnumNtSrv.cpp (modified) (1 diff)
-
include/EnumProcess.cpp (modified) (5 diffs)
-
include/EnumProcess.h (modified) (3 diffs)
-
include/Mutex.h (modified) (1 diff)
-
include/MutexRW.h (modified) (1 diff)
-
include/NTService.h (modified) (1 diff)
-
include/PDHCounter.h (modified) (1 diff)
-
include/REGSettings.h (modified) (4 diffs)
-
include/Settings.h (modified) (2 diffs)
-
include/charEx.h (modified) (3 diffs)
-
include/strEx.h (modified) (1 diff)
-
modules/CheckDisk/CheckDisk.cpp (modified) (2 diffs)
-
modules/CheckSystem/CheckSystem.cpp (modified) (4 diffs)
-
modules/NRPEListener/NRPEListener.cpp (modified) (1 diff)
-
modules/RemoteConfiguration/RemoteConfiguration.cpp (modified) (2 diffs)
-
modules/SysTray/SysTray.cpp (modified) (1 diff)
-
modules/SysTray/TrayIcon.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
NSClient++.cpp
r7e33d82 r978bd31 76 76 std::wstring xor_pwd = Encrypt(password); 77 77 std::wcout << _T("obfuscated_password=") << xor_pwd << std::endl; 78 if (password != Decrypt(xor_pwd)) 79 std::wcout << _T("ERROR: Password did not match!") << std::endl; 78 std::wstring outPasswd = Decrypt(xor_pwd); 79 if (password != outPasswd) 80 std::wcout << _T("ERROR: Password did not match: ") << outPasswd<< std::endl; 80 81 Settings::destroyInstance(); 81 82 return 0; … … 508 509 ReadLock readLock(&m_mutexRW, true, 5000); 509 510 if (!readLock.IsLocked()) { 510 std:: cout << _T("Message was lost as the core was locked...") << std::endl;511 std::wcout << _T("Message was lost as the core was locked...") << std::endl; 511 512 return; 512 513 } … … 652 653 return NSCAPI::hasFailed; 653 654 } 654 std::wstring s = inBuffer;655 655 std::wstring key = Settings::getInstance()->getString(MAIN_SECTION_TITLE, MAIN_MASTERKEY, MAIN_MASTERKEY_DEFAULT); 656 TCHAR *c = new TCHAR[inBufLen+1]; 657 wcsncpy_s(c, inBufLen+1, inBuffer, inBufLen); 658 for (unsigned int i=0,j=0;i<inBufLen;i++,j++) { 656 int tcharInBufLen = 0; 657 char *c = charEx::tchar_to_char(inBuffer, inBufLen, tcharInBufLen); 658 std::wstring::size_type j=0; 659 for (int i=0;i<tcharInBufLen;i++,j++) { 659 660 if (j > key.size()) 660 661 j = 0; 661 662 c[i] ^= key[j]; 662 663 } 663 LOG_ERROR(_T("DISABLED FOR NOW!!!! REPORT THIS!!!")); 664 size_t len = 0; //b64::b64_encode(reinterpret_cast<void*>(c), inBufLen, outBuf, *outBufLen); 664 size_t cOutBufLen = b64::b64_encode(reinterpret_cast<void*>(c), tcharInBufLen, NULL, NULL); 665 if (!outBuf) { 666 *outBufLen = static_cast<unsigned int>(cOutBufLen*2); // TODO: Guessing wildly here but no proper way to tell without a lot of extra work 667 return NSCAPI::isSuccess; 668 } 669 char *cOutBuf = new char[cOutBufLen+1]; 670 size_t len = b64::b64_encode(reinterpret_cast<void*>(c), tcharInBufLen, cOutBuf, cOutBufLen); 665 671 delete [] c; 666 if (outBuf) { 667 if ((len == 0)||(len >= *outBufLen)) { 668 LOG_ERROR(_T("Invalid out buffer length.")); 669 return NSCAPI::isInvalidBufferLen; 670 } 671 outBuf[len] = 0; 672 *outBufLen = static_cast<unsigned int>(len); 673 } else { 674 *outBufLen = static_cast<unsigned int>(len); 675 } 672 if (len == 0) { 673 LOG_ERROR(_T("Invalid out buffer length.")); 674 return NSCAPI::isInvalidBufferLen; 675 } 676 int realOutLen; 677 TCHAR *realOut = charEx::char_to_tchar(cOutBuf, cOutBufLen, realOutLen); 678 if (static_cast<unsigned int>(realOutLen) >= *outBufLen) { 679 LOG_ERROR_STD(_T("Invalid out buffer length: ") + strEx::itos(realOutLen) + _T(" was needed but only ") + strEx::itos(*outBufLen) + _T(" was allocated.")); 680 return NSCAPI::isInvalidBufferLen; 681 } 682 wcsncpy_s(outBuf, *outBufLen, realOut, realOutLen); 683 delete [] realOut; 684 outBuf[realOutLen] = 0; 685 *outBufLen = static_cast<unsigned int>(realOutLen); 676 686 return NSCAPI::isSuccess; 677 687 } … … 682 692 return NSCAPI::hasFailed; 683 693 } 684 int inBufLenC = WideCharToMultiByte(CP_ACP, 0, inBuffer, inBufLen, NULL, 0, NULL, NULL); 685 if (inBufLenC == 0) { 686 LOG_ERROR_STD(_T("Could not convert string: ") + error::lookup::last_error()); 687 return NSCAPI::hasFailed; 688 } 689 char *inBufferC = new char[inBufLenC+1]; 690 inBufLenC = WideCharToMultiByte(CP_ACP, 0, inBuffer, inBufLen, inBufferC, inBufLenC, NULL, NULL); 691 if (inBufLenC == 0) { 692 LOG_ERROR_STD(_T("Could not convert string: ") + error::lookup::last_error()); 693 delete [] inBufferC; 694 return NSCAPI::hasFailed; 695 } 696 char *outBufferC = new char[*outBufLen]; 697 size_t len = b64::b64_decode(inBufferC, inBufLenC, reinterpret_cast<void*>(outBufferC), *outBufLen); 698 if (outBufferC) { 699 if (len == 0) { 700 delete [] inBufferC; 701 LOG_ERROR_STD(_T("Invalid out buffer length.")); 702 return NSCAPI::isInvalidBufferLen; 703 } 704 std::string key = strEx::wstring_to_string(Settings::getInstance()->getString(MAIN_SECTION_TITLE, MAIN_MASTERKEY, MAIN_MASTERKEY_DEFAULT)); 705 for (unsigned int i=0,j=0;i<len;i++,j++) { 706 if (j > key.size()) 707 j = 0; 708 outBufferC[i] ^= key[j]; 709 } 710 outBufferC[len] = 0; 711 712 int neededLen = MultiByteToWideChar(CP_ACP, 0, outBufferC, static_cast<int>(len), NULL, 0 ); 713 if (neededLen == 0 || neededLen < 0) { 714 LOG_ERROR_STD(_T("Could not convert string: ") + error::lookup::last_error()); 715 delete [] inBufferC; 716 return NSCAPI::hasFailed; 717 } 718 if (static_cast<unsigned int>(neededLen) > *outBufLen) { 719 LOG_ERROR_STD(_T("Invalid out buffer length.")); 720 return NSCAPI::isInvalidBufferLen; 721 } 722 *outBufLen = static_cast<unsigned int>(MultiByteToWideChar(CP_ACP, 0, outBufferC, static_cast<int>(len), outBuf, neededLen )); 723 delete [] inBufferC; 724 if (*outBufLen == 0) { 725 LOG_ERROR_STD(_T("Could not convert string: ") + error::lookup::last_error()); 726 return NSCAPI::hasFailed; 727 } 728 } else { 729 *outBufLen = static_cast<unsigned int>(len); 730 } 694 int inBufLenC = 0; 695 char *inBufferC = charEx::tchar_to_char(inBuffer, inBufLen, inBufLenC); 696 size_t cOutLen = b64::b64_decode(inBufferC, inBufLenC, NULL, NULL); 697 if (!outBuf) { 698 *outBufLen = static_cast<unsigned int>(cOutLen*2); // TODO: Guessing wildly here but no proper way to tell without a lot of extra work 699 return NSCAPI::isSuccess; 700 } 701 char *cOutBuf = new char[cOutLen+1]; 702 size_t len = b64::b64_decode(inBufferC, inBufLenC, reinterpret_cast<void*>(cOutBuf), cOutLen); 703 delete [] inBufferC; 704 if (len == 0) { 705 LOG_ERROR(_T("Invalid out buffer length.")); 706 return NSCAPI::isInvalidBufferLen; 707 } 708 int realOutLen; 709 710 std::wstring key = Settings::getInstance()->getString(MAIN_SECTION_TITLE, MAIN_MASTERKEY, MAIN_MASTERKEY_DEFAULT); 711 std::wstring::size_type j=0; 712 for (int i=0;i<cOutLen;i++,j++) { 713 if (j > key.size()) 714 j = 0; 715 cOutBuf[i] ^= key[j]; 716 } 717 718 TCHAR *realOut = charEx::char_to_tchar(cOutBuf, cOutLen, realOutLen); 719 if (static_cast<unsigned int>(realOutLen) >= *outBufLen) { 720 LOG_ERROR_STD(_T("Invalid out buffer length: ") + strEx::itos(realOutLen) + _T(" was needed but only ") + strEx::itos(*outBufLen) + _T(" was allocated.")); 721 return NSCAPI::isInvalidBufferLen; 722 } 723 wcsncpy_s(outBuf, *outBufLen, realOut, realOutLen); 724 delete [] realOut; 725 outBuf[realOutLen] = 0; 726 *outBufLen = static_cast<unsigned int>(realOutLen); 731 727 return NSCAPI::isSuccess; 732 728 } -
changelog
r3f569d3 r978bd31 5 5 * Add module for relaying events 6 6 * Add API for rehashing the daemon (or implement it the API is there but does nothing) 7 8 2007-11-28 MickeM 9 * Fixed some UNICODE issues with process-listings 10 + Added an error message if the "detected" process enumeration method is not available. 11 + Fixed some more unicode issues Password encrypt/decrypt: #107 12 * Fixed unicode issues with "external programs" #109 13 * Fixed so default string for check_nt:s FILEAGE command is "delta" is 5 minutes ago (and not absolute ie. 1970...), Issue #39 14 + added support for <date strings> to check_nt:s FILEAGE command, Issue #39 15 append: .<date string> if you want to use a "custom date" like so: ... -v FILEAGE -l c:\\windows,Date: %Y-%m-%d %H:%M:%S" -w 5 -c 6 ... 16 Only the above listed %<char> works, and default to 0 so might not be to pretty but works... 7 17 8 18 2007-11-26 MickeM -
include/EnumNtSrv.cpp
r99e4d8f r978bd31 191 191 DWORD bufLen = SC_BUF_LEN; 192 192 TCHAR *buf = new TCHAR[bufLen+1]; 193 //std::cout << "name: '" << name << "'" << std::endl;194 193 if (GetServiceKeyName(scman, name.c_str(), buf, &bufLen) == 0) { 195 194 ::CloseServiceHandle(scman); -
include/EnumProcess.cpp
r99e4d8f r978bd31 22 22 #include <windows.h> 23 23 #include <tchar.h> 24 #include <iostream> 24 25 25 26 #include "EnumProcess.h" … … 30 31 31 32 32 CEnumProcess::CEnumProcess() : m_pProcesses(NULL), m_pModules(NULL), m_pCurrentP(NULL), m_pCurrentM(NULL), lpString(NULL) 33 CEnumProcess::CEnumProcess() : m_pProcesses(NULL), m_pModules(NULL), m_pCurrentP(NULL), m_pCurrentM(NULL), lpString(NULL), PSAPI(NULL) 33 34 { 34 35 lpString = new TCHAR[MAX_FILENAME+1]; … … 61 62 m_me.dwSize = sizeof(m_me); 62 63 // Find ToolHelp functions 63 64 #ifdef UNICODE 64 65 FCreateToolhelp32Snapshot = (PFCreateToolhelp32Snapshot)::GetProcAddress(TOOLHELP, "CreateToolhelp32Snapshot"); 65 FProcess32First = (PFProcess32First)::GetProcAddress(TOOLHELP, "Process32First"); 66 FProcess32Next = (PFProcess32Next)::GetProcAddress(TOOLHELP, "Process32Next"); 67 FModule32First = (PFModule32First)::GetProcAddress(TOOLHELP, "Module32First"); 68 FModule32Next = (PFModule32Next)::GetProcAddress(TOOLHELP, "Module32Next"); 66 FProcess32First = (PFProcess32First)::GetProcAddress(TOOLHELP, "Process32FirstW"); 67 FProcess32Next = (PFProcess32Next)::GetProcAddress(TOOLHELP, "Process32NextW"); 68 FModule32First = (PFModule32First)::GetProcAddress(TOOLHELP, "Module32FirstW"); 69 FModule32Next = (PFModule32Next)::GetProcAddress(TOOLHELP, "Module32NextW"); 70 #else 71 FCreateToolhelp32Snapshot = (PFCreateToolhelp32Snapshot)::GetProcAddress(TOOLHELP, "CreateToolhelp32SnapshotA"); 72 FProcess32First = (PFProcess32First)::GetProcAddress(TOOLHELP, "Process32FirstA"); 73 FProcess32Next = (PFProcess32Next)::GetProcAddress(TOOLHELP, "Process32NextA"); 74 FModule32First = (PFModule32First)::GetProcAddress(TOOLHELP, "Module32FirstA"); 75 FModule32Next = (PFModule32Next)::GetProcAddress(TOOLHELP, "Module32NextA"); 76 #endif 69 77 } 70 78 … … 124 132 { 125 133 if (ENUM_METHOD::NONE == m_method) return FALSE; 126 127 134 128 135 if ((ENUM_METHOD::TOOLHELP|m_method) == m_method) … … 282 289 pEntry->sFilename = _T("N/A (error)"); 283 290 } else { 284 pEntry->sFilename = lpString; 291 std::wstring path = lpString; 292 std::wstring::size_type pos = path.find_last_of(_T("\\")); 293 if (pos != std::wstring::npos) { 294 path = path.substr(++pos); 295 } 296 pEntry->sFilename = path; 285 297 } 286 298 } -
include/EnumProcess.h
r99e4d8f r978bd31 36 36 const int MAX_FILENAME = 256; 37 37 38 #ifdef UNICODE 39 // Functions loaded from PSAPI 40 typedef BOOL (WINAPI *PFEnumProcesses)(DWORD * lpidProcess, DWORD cb, DWORD * cbNeeded); 41 typedef BOOL (WINAPI *PFEnumProcessModules)(HANDLE hProcess, HMODULE * lphModule, DWORD cb, LPDWORD lpcbNeeded); 42 typedef DWORD (WINAPI *PFGetModuleFileNameEx)(HANDLE hProcess, HMODULE hModule, LPTSTR lpFilename, DWORD nSize); 43 44 //Functions loaded from Kernel32 45 typedef HANDLE (WINAPI *PFCreateToolhelp32Snapshot)(DWORD dwFlags, DWORD th32ProcessID); 46 typedef BOOL (WINAPI *PFProcess32First)(HANDLE hSnapshot, LPPROCESSENTRY32W lppe); 47 typedef BOOL (WINAPI *PFProcess32Next)(HANDLE hSnapshot, LPPROCESSENTRY32W lppe); 48 typedef BOOL (WINAPI *PFModule32First)(HANDLE hSnapshot, LPMODULEENTRY32W lpme); 49 typedef BOOL (WINAPI *PFModule32Next)(HANDLE hSnapshot, LPMODULEENTRY32W lpme); 50 #else 38 51 // Functions loaded from PSAPI 39 52 typedef BOOL (WINAPI *PFEnumProcesses)(DWORD * lpidProcess, DWORD cb, DWORD * cbNeeded); … … 47 60 typedef BOOL (WINAPI *PFModule32First)(HANDLE hSnapshot, LPMODULEENTRY32 lpme); 48 61 typedef BOOL (WINAPI *PFModule32Next)(HANDLE hSnapshot, LPMODULEENTRY32 lpme); 49 62 #endif 50 63 51 64 class CEnumProcess … … 111 124 HANDLE m_hProcessSnap, m_hModuleSnap; 112 125 HMODULE TOOLHELP; //Handle to the module (Kernel32) 126 #ifdef UNICODE 127 PROCESSENTRY32W m_pe; 128 MODULEENTRY32W m_me; 129 #else 113 130 PROCESSENTRY32 m_pe; 114 131 MODULEENTRY32 m_me; 132 #endif 115 133 // ToolHelp related functions 116 134 PFCreateToolhelp32Snapshot FCreateToolhelp32Snapshot; -
include/Mutex.h
r478588b r978bd31 124 124 MutexLock(HANDLE hMutex, DWORD timeout = 5000L) : bHasMutex(false), hMutex_(hMutex) { 125 125 if (hMutex_ == NULL) 126 std:: cout << "Whops..." << std::endl;126 std::wcout << "Whops..." << std::endl; 127 127 assert(hMutex_ != NULL); 128 128 dwWaitResult = WaitForSingleObject(hMutex_, timeout); -
include/MutexRW.h
rdc65e35 r978bd31 58 58 NULL 59 59 ); 60 std:: cout << "***** ERROR: CreateSemaphore: %s\n" << (LPCTSTR)lpMsgBuf;60 std::wcout << "***** ERROR: CreateSemaphore: %s\n" << (LPCTSTR)lpMsgBuf; 61 61 // TRACE( "***** ERROR: CreateSemaphore: %s\n", (LPCTSTR)lpMsgBuf ); 62 62 LocalFree( lpMsgBuf ); -
include/NTService.h
r99e4d8f r978bd31 72 72 BOOL ret = ::StartServiceCtrlDispatcher(dispatchTable); 73 73 if (ret == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT) { 74 std:: cout << "We are running in console mode, terminating..." << std::endl;74 std::wcout << "We are running in console mode, terminating..." << std::endl; 75 75 return false; 76 76 } -
include/PDHCounter.h
r99e4d8f r978bd31 206 206 207 207 PDHCounter* addCounter(std::wstring name, PDHCounterListener *listener) { 208 //std::cout << "Adding counter: " << name << std::endl;209 208 PDHCounter *counter = new PDHCounter(name, listener); 210 209 counters_.push_back(counter); -
include/REGSettings.h
r99e4d8f r978bd31 119 119 ret = reinterpret_cast<LPCTSTR>(bData); 120 120 } else { 121 std:: cout << _T("getString_::Buffersize to small: ") << lpszPath << "." << lpszKey << ": " << type << std::endl;121 std::wcout << _T("getString_::Buffersize to small: ") << lpszPath << "." << lpszKey << ": " << type << std::endl; 122 122 } 123 123 } else if (type == REG_DWORD) { … … 125 125 ret = strEx::itos(dw); 126 126 } else { 127 std:: cout << _T("getString_::Unsupported type: ") << lpszPath << "." << lpszKey << ": " << type << std::endl;127 std::wcout << _T("getString_::Unsupported type: ") << lpszPath << "." << lpszKey << ": " << type << std::endl; 128 128 } 129 129 } else if (lRet == ERROR_FILE_NOT_FOUND) { … … 177 177 ret.push_back(std::wstring(lpValueName)); 178 178 } else { 179 std:: cout << _T("getValues_::Error: ") << bRet << ": " << lpszPath << _T("[") << i << _T("]") << std::endl;179 std::wcout << _T("getValues_::Error: ") << bRet << ": " << lpszPath << _T("[") << i << _T("]") << std::endl; 180 180 181 181 } … … 205 205 ret.push_back(std::wstring(lpValueName)); 206 206 } else { 207 std:: cout << _T("getSubKeys_::Error: ") << bRet << _T(": ") << lpszPath << _T("[") << i << _T("]") << std::endl;207 std::wcout << _T("getSubKeys_::Error: ") << bRet << _T(": ") << lpszPath << _T("[") << i << _T("]") << std::endl; 208 208 } 209 209 } -
include/Settings.h
r99e4d8f r978bd31 133 133 134 134 /* 135 std:: cout << " Key: " << (*it2) << std::endl;135 std::wcout << " Key: " << (*it2) << std::endl; 136 136 int i = sM->getInt((*it), (*it2), UNLIKELY_VALUE_1); 137 std:: cout << "Int vaöl: " << i << std::endl;137 std::wcout << "Int vaöl: " << i << std::endl; 138 138 if (i == UNLIKELY_VALUE_1) { 139 139 if (sM->getInt((*it), (*it2), UNLIKELY_VALUE_2)==UNLIKELY_VALUE_2) { 140 std:: cout << "Writing: " << (*it) << " - " << (*it2) << " - " << sM->getString((*it), (*it2)) << std::endl;140 std::wcout << "Writing: " << (*it) << " - " << (*it2) << " - " << sM->getString((*it), (*it2)) << std::endl; 141 141 setString((*it), (*it2), sM->getString((*it), (*it2))); 142 142 } else … … 144 144 } else if (i == 0) { 145 145 std::wstring s = sM->getString((*it), (*it2)); 146 std:: cout << "Size: " << s.size() << " |" << s << "| " << std::endl;146 std::wcout << "Size: " << s.size() << " |" << s << "| " << std::endl; 147 147 if (s.size() == 0) 148 148 setString((*it), (*it2), s); -
include/charEx.h
rdc65e35 r978bd31 21 21 #pragma once 22 22 #include <assert.h> 23 #include <windows.h> 24 #include <tchar.h> 23 25 24 26 namespace charEx { … … 29 31 * @return a list with strings 30 32 */ 31 inline std::list<std:: string> split(const char* buffer, charsplit) {32 std::list<std:: string> ret;33 const char*start = buffer;34 for (const char*p = buffer;*p!='\0';p++) {33 inline std::list<std::wstring> split(const TCHAR* buffer, TCHAR split) { 34 std::list<std::wstring> ret; 35 const TCHAR *start = buffer; 36 for (const TCHAR *p = buffer;*p!='\0';p++) { 35 37 if (*p==split) { 36 std:: string str(start, p-start);38 std::wstring str(start, p-start); 37 39 ret.push_back(str); 38 40 start = p+1; 39 41 } 40 42 } 41 ret.push_back(std::string(start)); 43 ret.push_back(std::wstring(start)); 44 return ret; 45 } 46 47 48 inline char* tchar_to_char( const wchar_t* pStr, int len, int &nChars) { 49 assert(pStr != NULL); 50 assert(len >= 0 || len == -1); 51 52 // figure out how many narrow characters we are going to get 53 nChars = WideCharToMultiByte(CP_ACP, 0, pStr, len, NULL, 0, NULL, NULL); 54 if (len == -1) 55 --nChars; 56 if (nChars==0) { 57 char *ret = new char[1]; 58 ret[0] = 0; 59 return ret; 60 } 61 62 // convert the wide string to a narrow string 63 char *ret = new char[nChars+1]; 64 WideCharToMultiByte(CP_ACP, 0, pStr, len, ret, nChars, NULL, NULL); 65 return ret; 66 } 67 68 inline wchar_t* char_to_tchar(const char* pStr, int len, int &nChars) { 69 assert( pStr != NULL); 70 assert( len >= 0 || len == -1); 71 72 // figure out how many wide characters we are going to get 73 nChars = MultiByteToWideChar( CP_ACP , 0 , pStr , len , NULL , 0 ); 74 if (len == -1) 75 --nChars; 76 if (nChars == 0) { 77 TCHAR *ret = new TCHAR[1]; 78 ret[0] = 0; 79 return ret; 80 } 81 82 // convert the narrow string to a wide string 83 TCHAR *ret = new TCHAR[nChars+1]; 84 MultiByteToWideChar(CP_ACP, 0 ,pStr ,len, const_cast<wchar_t*>(ret), nChars); 42 85 return ret; 43 86 } … … 45 88 46 89 47 typedef std::pair<std:: string,char*> token;48 inline token getToken( char *buffer, charsplit) {90 typedef std::pair<std::wstring,TCHAR*> token; 91 inline token getToken(TCHAR *buffer, TCHAR split) { 49 92 assert(buffer != NULL); 50 char *p = strchr(buffer, split);93 TCHAR *p = wcschr(buffer, split); 51 94 if (!p) 52 95 return token(buffer, NULL); 53 96 if (!p[1]) 54 return token(std:: string(buffer, p-buffer), NULL);97 return token(std::wstring(buffer, p-buffer), NULL); 55 98 p++; 56 return token(std:: string(buffer, p-buffer-1), p);99 return token(std::wstring(buffer, p-buffer-1), p); 57 100 } 58 101 #ifdef _DEBUG 59 inline void test_getToken( char* in1, char in2, std::string out1, char* out2) {102 inline void test_getToken(TCHAR* in1, TCHAR in2, std::wstring out1, TCHAR * out2) { 60 103 token t = getToken(in1, in2); 61 std:: cout << "charEx::test_getToken(" << in1 << ", " << in2 << ") : ";104 std::wcout << _T("charEx::test_getToken(") << in1 << _T(", ") << in2 << _T(") : "); 62 105 if (t.first == out1) { 63 106 if ((t.second == NULL) && (out2 == NULL)) 64 std:: cout << "Succeeded"<< std::endl;107 std::wcout << _T("Succeeded") << std::endl; 65 108 else if (t.second == NULL) 66 std:: cout << "Failed [NULL=" << out2 << "]"<< std::endl;109 std::wcout << _T("Failed [NULL=") << out2 << _T("]") << std::endl; 67 110 else if (out2 == NULL) 68 std:: cout << "Failed [" << t.second << "=NULL]"<< std::endl;69 else if ( strcmp(t.second, out2) == 0)70 std:: cout << "Succeeded"<< std::endl;111 std::wcout << _T("Failed [") << t.second << _T("=NULL]") << std::endl; 112 else if (wcscmp(t.second, out2) == 0) 113 std::wcout << _T("Succeeded") << std::endl; 71 114 else 72 std:: cout << "Failed"<< std::endl;115 std::wcout << _T("Failed") << std::endl; 73 116 } else 74 std:: cout << "Failed [" << out1 << "=" << t.first << "]"<< std::endl;117 std::wcout << _T("Failed [") << out1 << _T("=") << t.first << _T("]") << std::endl; 75 118 } 76 119 inline void run_test_getToken() { 77 test_getToken( "", '&', "", NULL);78 test_getToken( "&", '&', "", NULL);79 test_getToken( "&&", '&', "", "&");80 test_getToken( "foo", '&', "foo", NULL);81 test_getToken( "foo&", '&', "foo", NULL);82 test_getToken( "foo&bar", '&', "foo", "bar");83 test_getToken( "foo&bar&test", '&', "foo", "bar&test");120 test_getToken(_T(""), '&', _T(""), NULL); 121 test_getToken(_T("&"), '&', _T(""), NULL); 122 test_getToken(_T("&&"), '&', _T(""), _T("&")); 123 test_getToken(_T("foo"), '&', _T("foo"), NULL); 124 test_getToken(_T("foo&"), '&', _T("foo"), NULL); 125 test_getToken(_T("foo&bar"), '&', _T("foo"), _T("bar")); 126 test_getToken(_T("foo&bar&test"), '&', _T("foo"), _T("bar&test")); 84 127 } 85 128 #endif -
include/strEx.h
r7e33d82 r978bd31 208 208 } 209 209 210 #define MK_FORMAT_FTD(min, key, val) \ 211 if (mtm->tm_year > min) \ 212 strEx::replace(format, key, strEx::itos(val)); \ 213 else \ 214 strEx::replace(format, key, _T("0")); 215 216 inline std::wstring format_time_delta(std::wstring format, struct tm *mtm) { 217 // "Date: %Y-%m-%d %H:%M:%S" 218 MK_FORMAT_FTD(70, _T("%Y"), mtm->tm_year); 219 MK_FORMAT_FTD(0, _T("%m"), mtm->tm_mon); 220 MK_FORMAT_FTD(0, _T("%d"), mtm->tm_mday); 221 MK_FORMAT_FTD(0, _T("%H"), mtm->tm_hour); 222 MK_FORMAT_FTD(0, _T("%M"), mtm->tm_min); 223 MK_FORMAT_FTD(0, _T("%S"), mtm->tm_sec); 224 MK_FORMAT_FTD(0, _T("%Y"), mtm->tm_year); 225 return format; 226 } 227 210 228 #define WEEK (7 * 24 * 60 * 60 * 1000) 211 229 #define DAY (24 * 60 * 60 * 1000) -
modules/CheckDisk/CheckDisk.cpp
r99e4d8f r978bd31 472 472 return NSCAPI::returnUNKNOWN; 473 473 } 474 std::wstring dstr = _T("%#c");474 std::wstring format = _T("%Y years %m mon %d days %H hours %M min %S sec"); 475 475 std::wstring path; 476 476 find_first_file_info finder; 477 477 MAP_OPTIONS_BEGIN(stl_args) 478 478 MAP_OPTIONS_STR(_T("path"), path) 479 MAP_OPTIONS_FALLBACK(dstr) 479 MAP_OPTIONS_STR(_T("date"), format) 480 MAP_OPTIONS_FALLBACK(format) 480 481 MAP_OPTIONS_END() 481 482 … … 494 495 unsigned long long now = ((now_.dwHighDateTime * ((unsigned long long)MAXDWORD+1)) + (unsigned long long)now_.dwLowDateTime); 495 496 time_t value = (now-finder.info.ullLastWriteTime)/10000000; 496 497 TCHAR buf[51]; 498 size_t l = wcsftime(buf, 50, dstr.c_str(), gmtime(&value)); 499 if (l <= 0 || l >= 50) { 500 message = _T("ERROR: could format time."); 501 return NSCAPI::returnUNKNOWN; 502 } 503 buf[l] = 0; 504 message = strEx::itos(value/60) + _T("&") + buf; 497 message = strEx::itos(value/60) + _T("&") + strEx::format_time_delta(format, gmtime(&value)); 505 498 return NSCAPI::returnOK; 506 499 } -
modules/CheckSystem/CheckSystem.cpp
r99e4d8f r978bd31 70 70 if (systemInfo::isBelowNT4(osVer)) { 71 71 NSC_DEBUG_MSG_STD(_T("Autodetected NT4<, using PSAPI process enumeration.")); 72 processMethod_ = ENUM_METHOD::PSAPI; 72 if (method == (method|ENUM_METHOD::PSAPI)) { 73 processMethod_ = ENUM_METHOD::PSAPI; 74 } else { 75 NSC_LOG_ERROR_STD(_T("PSAPI method not available, since you are on NT4 you need to install \"Platform SDK Redistributable: PSAPI for Windows NT\" from Microsoft.")); 76 NSC_LOG_ERROR_STD(_T("Try this URL: http://www.microsoft.com/downloads/details.aspx?FamilyID=3d1fbaed-d122-45cf-9d46-1cae384097ac")); 77 } 73 78 } else if (systemInfo::isAboveW2K(osVer)) { 74 79 NSC_DEBUG_MSG_STD(_T("Autodetected W2K>, using TOOLHELP process enumeration.")); 75 processMethod_ = ENUM_METHOD::TOOLHELP; 80 if (method == (method|ENUM_METHOD::TOOLHELP)) { 81 processMethod_ = ENUM_METHOD::TOOLHELP; 82 } else { 83 NSC_LOG_ERROR_STD(_T("TOOLHELP was not available, since you are on > W2K you need top manually override the ") C_SYSTEM_ENUMPROC_METHOD _T("option in NSC:ini.")); 84 } 76 85 } else { 77 86 NSC_DEBUG_MSG_STD(_T("Autodetected failed, using PSAPI process enumeration.")); 78 87 processMethod_ = ENUM_METHOD::PSAPI; 88 if (method == (method|ENUM_METHOD::PSAPI)) { 89 processMethod_ = ENUM_METHOD::PSAPI; 90 } else { 91 NSC_LOG_ERROR_STD(_T("PSAPI method not availabletry installing \"Platform SDK Redistributable: PSAPI for Windows NT\" from Microsoft.")); 92 NSC_LOG_ERROR_STD(_T("Try this URL: http://www.microsoft.com/downloads/details.aspx?FamilyID=3d1fbaed-d122-45cf-9d46-1cae384097ac")); 93 } 79 94 } 80 95 } else if (wantedMethod == C_SYSTEM_ENUMPROC_METHOD_PSAPI) { … … 721 736 } 722 737 CEnumProcess enumeration; 723 enumeration.SetMethod(processMethod); 738 if (enumeration.SetMethod(processMethod) != processMethod) { 739 NSC_LOG_ERROR_STD(_T("Failed to set process enumeration method")); 740 return ret; 741 } 724 742 CEnumProcess::CProcessEntry entry; 725 743 for (BOOL OK = enumeration.GetProcessFirst(&entry); OK; OK = enumeration.GetProcessNext(&entry) ) { … … 797 815 for (std::list<StateConatiner>::iterator it = list.begin(); it != list.end(); ++it) { 798 816 NSPROCLST::iterator proc = runningProcs.find((*it).data); 799 bool bFound = proc != runningProcs.end();817 bool bFound = (proc != runningProcs.end()); 800 818 std::wstring tmp; 801 819 TNtServiceInfo info; … … 904 922 pdh.close(); 905 923 double value = cDouble.getValue(); 906 //std::wcout << "Collected double data: " << value << std::endl;907 924 if (bNSClient) { 908 925 msg += strEx::itos(static_cast<float>(value)); -
modules/NRPEListener/NRPEListener.cpp
r3f569d3 r978bd31 301 301 } else { 302 302 DWORD dwread; 303 TCHAR *buf = new TCHAR[MAX_INPUT_BUFFER+1]; 304 retval = ReadFile(hChildOutR, buf, MAX_INPUT_BUFFER, &dwread, NULL); 303 //TCHAR *buf = new TCHAR[MAX_INPUT_BUFFER+1]; 304 char *buf = new char[MAX_INPUT_BUFFER+1]; 305 //retval = ReadFile(hChildOutR, buf, MAX_INPUT_BUFFER*sizeof(WCHAR), &dwread, NULL); 306 retval = ReadFile(hChildOutR, buf, MAX_INPUT_BUFFER*sizeof(char), &dwread, NULL); 305 307 if (!retval || dwread == 0) { 306 308 msg = _T("No output available from command..."); 307 309 } else { 308 310 buf[dwread] = 0; 309 msg = buf; 311 msg = strEx::string_to_wstring(buf); 312 //msg = buf; 310 313 //strEx::token t = strEx::getToken(msg, '\n'); 311 314 strEx::token t = strEx::getToken(msg, '|'); 312 315 msg = t.first; 316 std::wstring::size_type pos = msg.find_last_not_of(_T("\n\r ")); 317 if (pos != std::wstring::npos) 318 msg = msg.substr(0,pos); 319 //if (msg[msg.size()-1] == '\n') 313 320 perf = t.second; 314 321 } -
modules/RemoteConfiguration/RemoteConfiguration.cpp
r99e4d8f r978bd31 145 145 setVariable(argLen, args, str); 146 146 } else if (_wcsicmp(command, _T("ini2reg")) == 0) { 147 std:: cout << _T("Migrating to registry settings...")<< std::endl;147 std::wcout << _T("Migrating to registry settings...")<< std::endl; 148 148 NSCModuleHelper::ReadSettings(NSCAPI::settings_inifile); 149 149 NSCModuleHelper::SetSettingsInt(MAIN_SECTION_TITLE, MAIN_USEFILE, 0); … … 152 152 NSCModuleHelper::WriteSettings(NSCAPI::settings_registry); 153 153 } else if (_wcsicmp(command, _T("reg2ini")) == 0) { 154 std:: cout << _T("Migrating to INI file settings...")<< std::endl;154 std::wcout << _T("Migrating to INI file settings...")<< std::endl; 155 155 NSCModuleHelper::ReadSettings(NSCAPI::settings_registry); 156 156 NSCModuleHelper::SetSettingsInt(MAIN_SECTION_TITLE, MAIN_USEREG, 0); -
modules/SysTray/SysTray.cpp
r99e4d8f r978bd31 50 50 bool SysTray::unloadModule() { 51 51 if (!icon.exitThread(20000)) { 52 std:: cout << _T("MAJOR ERROR: Could not unload thread...") << std::endl;52 std::wcout << _T("MAJOR ERROR: Could not unload thread...") << std::endl; 53 53 NSC_LOG_ERROR(_T("Could not exit the thread, memory leak and potential corruption may be the result...")); 54 54 return false; -
modules/SysTray/TrayIcon.cpp
r7e33d82 r978bd31 146 146 ndata.uCallbackMessage=WM_ICON_NOTIFY; 147 147 ndata.hIcon=::LoadIcon(NSCModuleWrapper::getModule(),MAKEINTRESOURCE(IDI_STANDBY)); 148 wcsncpy_s(ndata.szTip, 128, (NSCModuleHelper::getApplicationName() + _T(" - ") + NSCModuleHelper::getApplicationVersionString()).c_str(), 63); 148 std::wstring title = NSCModuleHelper::getApplicationName() + _T(" - ") + NSCModuleHelper::getApplicationVersionString(); 149 wcsncpy_s(ndata.szTip, 64, title.c_str(), min(64, title.size())); 149 150 Shell_NotifyIcon(NIM_ADD,&ndata); 150 151 }
Note: See TracChangeset
for help on using the changeset viewer.








