Source code of Windows XP (NT5)
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.

338 lines
7.2 KiB

  1. #ifndef __WINMGT_H__
  2. #define __WINMGT_H__
  3. #include <cntserv.h>
  4. #include <reg.h>
  5. #include <stdio.h>
  6. #include "resync2.h"
  7. #include "writer.h"
  8. #define SERVICE_NAME _T("winmgmt")
  9. #define HOME_REG_PATH _T("Software\\Microsoft\\WBEM\\CIMOM")
  10. #define INITIAL_BREAK _T("Break")
  11. #define WBEM_REG_ADAP __TEXT("Software\\Microsoft\\WBEM\\CIMOM\\ADAP")
  12. #define WBEM_REG_REVERSE_KEY __TEXT("SOFTWARE\\Microsoft\\WBEM\\PROVIDERS\\Performance")
  13. #define WBEM_REG_REVERSE_VALUE __TEXT("Performance Refresh")
  14. #define WBEM_NORESYNCPERF __TEXT("NoResyncPerf")
  15. #define WBEM_NOSHELL __TEXT("NoShell")
  16. #define WBEM_WMISETUP __TEXT("WMISetup")
  17. #define WBEM_ADAPEXTDLL __TEXT("ADAPExtDll")
  18. #define DO_THROTTLE __TEXT("ThrottleDrege")
  19. //
  20. // CHANGE CHANGE
  21. //
  22. #if 1
  23. #define DBG_PRINTFA( a ) { char pBuff[128]; sprintf a ; OutputDebugStringA(pBuff); }
  24. #else
  25. #define DBG_PRINTFA( a )
  26. #endif
  27. //
  28. // For Fast ShutDown
  29. //
  30. ///////////////////////////////////////
  31. #define SERVICE_SHUTDOWN 0x80000000
  32. // prototype for reg code
  33. DWORD RegSetDWORD(HKEY hKey,
  34. TCHAR * pName,
  35. TCHAR * pValue,
  36. DWORD dwValue);
  37. DWORD RegGetDWORD(HKEY hKey,
  38. TCHAR * pName,
  39. TCHAR * pValue,
  40. DWORD * pdwValue);
  41. //
  42. //
  43. // prototype for the wbemcore!ShutDown function
  44. //
  45. //////////////////////////////////
  46. typedef HRESULT (STDAPICALLTYPE *pfnShutDown)(DWORD,DWORD);
  47. //
  48. // The DeltaDredge Function (implementing the Pre-Delta) will return
  49. //
  50. ///////////////////////////////////
  51. #define FULL_DREDGE 2
  52. #define PARTIAL_DREDGE 1
  53. #define NO_DREDGE 0
  54. //
  55. //
  56. /////////////////////////////////////
  57. #define WMIADAP_DEFAULT_DELAY 240 // 4 minutes
  58. #define WMIADAP_DEFAULT_DELAY_LODCTR 60 // 1 minute
  59. #define WMIADAP_DEFAULT_TIMETOFULL ((DWORD)-1)
  60. #define ADAP_TIMESTAMP_FULL _T("LastFullDredgeTimestamp")
  61. #define ADAP_TIME_TO_FULL _T("TimeToFullDredge")
  62. #define ADAP_TIME_TO_KILL_ADAP _T("TimeToTerminateAdap")
  63. #ifdef COUNTER
  64. //
  65. // Counter
  66. //
  67. //////////////////////////////////////
  68. class StartStop {
  69. public:
  70. static LARGE_INTEGER g_liFreq;
  71. static char g_pBuff[256];
  72. LARGE_INTEGER liTimeStart;
  73. LARGE_INTEGER liTimeStop;
  74. char * m_pString;
  75. StartStop(char * pString):m_pString(pString)
  76. {
  77. QueryPerformanceCounter(&liTimeStart);
  78. };
  79. ~StartStop()
  80. {
  81. QueryPerformanceCounter(&liTimeStop);
  82. //__int64 val = 1000000;
  83. wsprintfA(g_pBuff,"%I64u %I64u %I64u %s\n",
  84. (liTimeStop.QuadPart)/(g_liFreq.QuadPart),
  85. (liTimeStart.QuadPart)/(g_liFreq.QuadPart),
  86. (liTimeStop.QuadPart-liTimeStart.QuadPart)/(g_liFreq.QuadPart),
  87. m_pString);
  88. OutputDebugStringA(g_pBuff);
  89. };
  90. };
  91. #endif
  92. #include <flexarry.h>
  93. //
  94. // from the old winmgmt.exe
  95. //
  96. //
  97. // _PROG_RESOURCES
  98. //
  99. // Holds various resource that need to be freed at the end of execution.
  100. //
  101. //////////////////////////////////////////////////////////////////
  102. struct _PROG_RESOURCES
  103. {
  104. HANDLE m_hExclusive;
  105. HANDLE m_hTerminateEvent;
  106. BOOL m_bOleInitialized;
  107. IClassFactory* m_pLoginFactory;
  108. IClassFactory* m_pBackupFactory;
  109. DWORD m_dwLoginClsFacReg;
  110. DWORD m_dwBackupClsFacReg;
  111. /*
  112. CFlexArray m_TransportArray;
  113. */
  114. //-----------
  115. BOOL g_fSetup;
  116. BOOL g_fDoResync;
  117. HANDLE hMainMutex;
  118. BOOL bShuttingDownWinMgmt;
  119. BOOL gbCoreLoaded;
  120. HANDLE ghCoreCanUnload;
  121. HANDLE ghProviderCanUnload;
  122. HANDLE ghCoreUnloaded;
  123. HANDLE ghCoreLoaded;
  124. HANDLE ghNeedRegistration;
  125. HANDLE ghRegistrationDone;
  126. HANDLE ghMofDirChange;
  127. HANDLE ghLoadCtrEvent;
  128. HANDLE ghUnloadCtrEvent;
  129. HANDLE ghHoldOffNewClients;
  130. TCHAR * szHotMofDirectory;
  131. CMonitorEvents m_Monitor;
  132. DWORD ServiceStatus;
  133. CWbemVssWriter* pWbemVssWriter;
  134. bool bWbemVssWriterSubscribed;
  135. //------------------------------
  136. void Init();
  137. BOOL Phase1Build();
  138. BOOL Phase2Build(HANDLE hTerminate);
  139. BOOL RegisterLogin();
  140. BOOL RevokeLogin();
  141. BOOL RegisterBackup();
  142. BOOL RevokeBackup();
  143. BOOL Phase1Delete(BOOL bIsSystemShutDown);
  144. BOOL Phase2Delete(BOOL bIsSystemShutdown);
  145. BOOL Phase3Delete();
  146. };
  147. extern struct _PROG_RESOURCES g_ProgRes;
  148. extern HINSTANCE g_hInstance;
  149. inline
  150. BOOL GLOB_Monitor_IsRegistred()
  151. {
  152. BOOL bRet;
  153. g_ProgRes.m_Monitor.Lock();
  154. bRet = g_ProgRes.m_Monitor.IsRegistred();
  155. g_ProgRes.m_Monitor.Unlock();
  156. return bRet;
  157. };
  158. inline
  159. CMonitorEvents * GLOB_GetMonitor()
  160. {
  161. return &g_ProgRes.m_Monitor;
  162. }
  163. //
  164. // Adap might be disallowed because of Setup running
  165. // or because of a registry setting
  166. //
  167. /////////////////////////////////////////////////////
  168. inline
  169. BOOL GLOB_IsResyncAllowed()
  170. {
  171. return (g_ProgRes.g_fDoResync && !g_ProgRes.g_fSetup);
  172. }
  173. //
  174. //
  175. // functions exported from mofdutil.cpp
  176. //
  177. //////////////////////////////////////////////////////////////////
  178. BOOL
  179. AddAccountToDacl(HANDLE hToken,
  180. BYTE SubCount,
  181. DWORD dw0,
  182. DWORD dw1,
  183. DWORD dw2,
  184. DWORD dw3,
  185. DWORD dw4,
  186. DWORD dw5,
  187. DWORD dw6,
  188. DWORD dw7,
  189. DWORD Access,
  190. DWORD AceFlag);
  191. BOOL SetEventDacl(HANDLE hEvent,DWORD Permission = GENERIC_ALL);
  192. BOOL InitHotMofStuff( IN OUT struct _PROG_RESOURCES * pProgRes);
  193. void LoadMofsInDirectory(const TCHAR *szDirectory);
  194. BOOL CheckSetupSwitch( void );
  195. void SetNoShellADAPSwitch( void );
  196. BOOL CheckNoResyncSwitch( void );
  197. void AddToAutoRecoverList(TCHAR * pFileName);
  198. BOOL IsValidMulti(TCHAR * pMultStr, DWORD dwSize);
  199. BOOL IsStringPresent(TCHAR * pTest, TCHAR * pMultStr);
  200. //
  201. //
  202. // yet an other class factory
  203. //
  204. ///////////////////////////////////////////////////////////////////
  205. class CForwardFactory : public IClassFactory
  206. {
  207. protected:
  208. long m_lRef;
  209. CLSID m_ForwardClsid;
  210. public:
  211. CForwardFactory(REFCLSID rForwardClsid)
  212. : m_lRef(0), m_ForwardClsid(rForwardClsid)
  213. {}
  214. ~CForwardFactory();
  215. ULONG STDMETHODCALLTYPE AddRef();
  216. ULONG STDMETHODCALLTYPE Release();
  217. HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppv);
  218. HRESULT STDMETHODCALLTYPE CreateInstance(IUnknown* pUnkOuter,
  219. REFIID riid, void** ppv);
  220. HRESULT STDMETHODCALLTYPE LockServer(BOOL fLock);
  221. };
  222. //
  223. //
  224. // MyService
  225. //
  226. //
  227. //////////////////////////////////////////////////////////////////
  228. class MyService : public CNtService
  229. {
  230. public:
  231. MyService(DWORD CtrlAccepted);
  232. ~MyService();
  233. // CNtService interface
  234. DWORD WorkerThread();
  235. void Stop(BOOL bSystemShutDownCalled);
  236. void Log(LPCSTR lpszMsg);
  237. VOID Pause();
  238. VOID Continue();
  239. //
  240. VOID FinalCleanup();
  241. private:
  242. HANDLE m_hStopEvent;
  243. };
  244. //
  245. //
  246. // yet another smart mutex
  247. //
  248. //
  249. //////////////////////////////////////////////////////////////////
  250. class CInMutex
  251. {
  252. protected:
  253. HANDLE m_hMutex;
  254. WCHAR * m_pString;
  255. public:
  256. CInMutex(HANDLE hMutex) : m_hMutex(hMutex)
  257. {
  258. if(m_hMutex)
  259. WaitForSingleObject(m_hMutex, INFINITE);
  260. }
  261. ~CInMutex()
  262. {
  263. if(m_hMutex)
  264. ReleaseMutex(m_hMutex);
  265. }
  266. };
  267. #endif