Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

199 lines
4.3 KiB

  1. //***************************************************************************
  2. //
  3. // NTEVTLOGR.H
  4. //
  5. // Module: WBEM NT EVENT PROVIDER
  6. //
  7. // Copyright (c) 1996-2001 Microsoft Corporation, All Rights Reserved
  8. //
  9. //***************************************************************************
  10. #ifndef _NT_EVT_PROV_EVTLOGR_H
  11. #define _NT_EVT_PROV_EVTLOGR_H
  12. template <typename T>
  13. class ScopeLock
  14. {
  15. private:
  16. T & t_;
  17. public:
  18. ScopeLock(T & t):t_(t){ t_.Lock(); }
  19. ~ScopeLock(){ t_.Unlock(); }
  20. };
  21. class MyPSID
  22. {
  23. public:
  24. PSID m_SID;
  25. MyPSID(PSID psid = NULL) { m_SID = psid; }
  26. };
  27. template <> inline void AFXAPI DestructElements<HINSTANCE> (HINSTANCE* ptr_e, int x)
  28. {
  29. //x is always one for a CMap!
  30. if (*ptr_e != NULL)
  31. {
  32. FreeLibrary(*ptr_e);
  33. }
  34. }
  35. template <> inline void AFXAPI DestructElements<MyPSID> (MyPSID* ptr_e, int x)
  36. {
  37. //x is always one for a CMap!
  38. if ((ptr_e != NULL) && (ptr_e->m_SID != NULL))
  39. {
  40. delete ptr_e->m_SID;
  41. }
  42. }
  43. template <> inline UINT AFXAPI HashKey<LPCWSTR> (LPCWSTR key)
  44. {
  45. return HashKeyLPCWSTR(key);
  46. }
  47. template <> inline UINT AFXAPI HashKey<MyPSID> (MyPSID key)
  48. {
  49. UINT ret = 0;
  50. UCHAR* tmp = (UCHAR*) key.m_SID;
  51. DWORD sidlen = GetLengthSid(key.m_SID);
  52. for (DWORD x = 0; x < sidlen; x++)
  53. {
  54. ret = (ret<<5) + ret + *tmp++;
  55. }
  56. return ret;
  57. }
  58. template <> inline BOOL AFXAPI CompareElements<MyPSID, MyPSID> (const MyPSID* p1, const MyPSID* p2)
  59. {
  60. return EqualSid(p1->m_SID, p2->m_SID);
  61. }
  62. class CSIDMap : public CMap<MyPSID, MyPSID, CStringW, LPCWSTR>
  63. {
  64. private:
  65. CCriticalSection m_Lock;
  66. public:
  67. BOOL Lock() { return m_Lock.Lock(); }
  68. BOOL Unlock() { return m_Lock.Unlock(); }
  69. };
  70. class CDllMap : public CMap<CStringW, LPCWSTR, HINSTANCE, HINSTANCE>
  71. {
  72. private:
  73. CCriticalSection m_Lock;
  74. public:
  75. BOOL Lock() { return m_Lock.Lock(); }
  76. BOOL Unlock() { return m_Lock.Unlock(); }
  77. };
  78. //taken from the NT eventlog private include (MAXLIST)
  79. #define MAX_NUM_OF_INS_STRS 256
  80. class CEventlogRecord
  81. {
  82. private:
  83. CStringW m_Logfile;
  84. DWORD m_Record;
  85. DWORD m_EvtID;
  86. CStringW m_SourceName;
  87. CStringW m_Type;
  88. WORD m_Category;
  89. CStringW m_CategoryString;
  90. CStringW m_TimeGen;
  91. CStringW m_TimeWritten;
  92. CStringW m_CompName;
  93. CStringW m_User;
  94. CStringW m_Message;
  95. wchar_t* m_InsStrs[MAX_NUM_OF_INS_STRS];
  96. LONG m_NumStrs;
  97. CStringW m_TypeArray[TYPE_ARRAY_LEN];
  98. UCHAR* m_Data;
  99. LONG m_DataLen;
  100. BYTE m_EvtType;
  101. IWbemClassObject* m_Obj;
  102. IWbemClassObject* m_pClass;
  103. IWbemClassObject *m_pAClass;
  104. IWbemServices* m_nspace;
  105. BOOL m_Valid;
  106. static CDllMap sm_dllMap;
  107. static CSIDMap sm_usersMap;
  108. BOOL Init(const EVENTLOGRECORD* pEvt);
  109. BOOL SetProperty(wchar_t* prop, CStringW val);
  110. BOOL SetProperty(wchar_t* prop, DWORD val);
  111. void SetUser(PSID psidUserSid);
  112. void SetMessage();
  113. void SetTimeStr(CStringW& str, DWORD timeVal);
  114. void SetType(WORD type);
  115. BOOL GetInstance();
  116. ULONG CheckInsertionStrings(HKEY hk, HKEY hkPrimary);
  117. CStringW GetMappedGUID(LPCWSTR strDcName, LPCWSTR strGuid);
  118. static HINSTANCE GetDll(CStringW path);
  119. static ULONG GetIndex(wchar_t* indexStr, BOOL* bError);
  120. HRESULT ReplaceStringInsert (
  121. LPWSTR* ppwszBuf,
  122. ULONG nOffset,
  123. LPWSTR* ppwszReplacement,
  124. ULONG* pulSize
  125. );
  126. HRESULT ReplaceParameterInsert (
  127. HINSTANCE& hParamModule,
  128. CStringW& paramModule,
  129. LPWSTR* ppwszBuf,
  130. ULONG nOffset,
  131. LPWSTR* ppwszReplacement,
  132. ULONG* pulSize
  133. );
  134. HRESULT ReplaceSubStr (
  135. LPCWSTR pwszToInsert,
  136. LPWSTR *ppwszBuf,
  137. ULONG nOffset,
  138. ULONG nCharsOld,
  139. LPWSTR *pptrReplacement,
  140. ULONG *pulSize
  141. );
  142. public:
  143. static BOOL SetEnumArray(IWbemClassObject* pClass, wchar_t* propname, CStringW* strArray, ULONG strArrayLen, GetIndexFunc IndexFunc);
  144. static void EmptyDllMap();
  145. static void EmptyUsersMap();
  146. static CStringW GetUser(PSID userSid);
  147. CEventlogRecord(const wchar_t* logfile, const EVENTLOGRECORD* pEvt, IWbemServices* ns,
  148. IWbemClassObject* pClass = NULL, IWbemClassObject* pAClass = NULL);
  149. BOOL GenerateInstance(IWbemClassObject** ppInst);
  150. BOOL IsValid() { return m_Valid; }
  151. ~CEventlogRecord();
  152. };
  153. #endif //_NT_EVT_PROV_EVTLOGR_H