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.

279 lines
6.0 KiB

  1. /*++
  2. Copyright (C) 2000-2001 Microsoft Corporation
  3. Module Name:
  4. winmgmt.h
  5. Abstract:
  6. defines constant useful for the entire project
  7. --*/
  8. #ifndef __WINMGT_H__
  9. #define __WINMGT_H__
  10. #include <cntserv.h>
  11. #include <reg.h>
  12. #include <stdio.h>
  13. #include "resync2.h"
  14. #include "writer.h"
  15. #include <stdio.h>
  16. #include <helper.h>
  17. #include <flexarry.h>
  18. #define SERVICE_NAME TEXT("winmgmt")
  19. #define HOME_REG_PATH TEXT("Software\\Microsoft\\WBEM\\CIMOM")
  20. #define INITIAL_BREAK TEXT("Break")
  21. #define WBEM_REG_ADAP __TEXT("Software\\Microsoft\\WBEM\\CIMOM\\ADAP")
  22. #define WBEM_REG_REVERSE_KEY __TEXT("SOFTWARE\\Microsoft\\WBEM\\PROVIDERS\\Performance")
  23. #define WBEM_REG_REVERSE_VALUE __TEXT("Performance Refresh")
  24. #define WBEM_NORESYNCPERF __TEXT("NoResyncPerf")
  25. #define WBEM_NOSHELL __TEXT("NoShell")
  26. #define WBEM_WMISETUP __TEXT("WMISetup")
  27. #define WBEM_ADAPEXTDLL __TEXT("ADAPExtDll")
  28. #define DO_THROTTLE __TEXT("ThrottleDrege")
  29. //
  30. // For Fast ShutDown
  31. //
  32. ///////////////////////////////////////
  33. #define SERVICE_SHUTDOWN 0x80000000
  34. // prototype for reg code
  35. DWORD RegSetDWORD(HKEY hKey,
  36. TCHAR * pName,
  37. TCHAR * pValue,
  38. DWORD dwValue);
  39. DWORD RegGetDWORD(HKEY hKey,
  40. TCHAR * pName,
  41. TCHAR * pValue,
  42. DWORD * pdwValue);
  43. //
  44. //
  45. // prototype for the wbemcore!ShutDown function
  46. //
  47. //////////////////////////////////
  48. typedef HRESULT (STDAPICALLTYPE *pfnShutDown)(DWORD,DWORD);
  49. //
  50. // The DeltaDredge Function (implementing the Pre-Delta) will return
  51. //
  52. ///////////////////////////////////
  53. #define FULL_DREDGE 2
  54. #define PARTIAL_DREDGE 1
  55. #define NO_DREDGE 0
  56. //
  57. //
  58. /////////////////////////////////////
  59. #define WMIADAP_DEFAULT_DELAY 240 // 4 minutes
  60. #define WMIADAP_DEFAULT_DELAY_LODCTR 60 // 1 minute
  61. #define WMIADAP_DEFAULT_TIMETOFULL ((DWORD)-1)
  62. #define ADAP_TIMESTAMP_FULL TEXT("LastFullDredgeTimestamp")
  63. #define ADAP_TIME_TO_FULL TEXT("TimeToFullDredge")
  64. #define ADAP_TIME_TO_KILL_ADAP TEXT("TimeToTerminateAdap")
  65. //
  66. // _PROG_RESOURCES
  67. //
  68. // Holds various resource that need to be freed at the end of execution.
  69. //
  70. //////////////////////////////////////////////////////////////////
  71. struct _PROG_RESOURCES
  72. {
  73. BOOL m_bOleInitialized;
  74. IClassFactory* m_pLoginFactory;
  75. IClassFactory* m_pBackupFactory;
  76. DWORD m_dwLoginClsFacReg;
  77. DWORD m_dwBackupClsFacReg;
  78. //-----------
  79. BOOL g_fSetup;
  80. BOOL g_fDoResync;
  81. HANDLE hMainMutex;
  82. BOOL bShuttingDownWinMgmt;
  83. BOOL gbCoreLoaded;
  84. HANDLE ghCoreCanUnload;
  85. HANDLE ghProviderCanUnload;
  86. HANDLE ghMofDirChange;
  87. TCHAR * szHotMofDirectory;
  88. CMonitorEvents m_Monitor;
  89. DWORD ServiceStatus;
  90. CWbemVssWriter* pWbemVssWriter;
  91. bool bWbemVssWriterSubscribed;
  92. DWORD dwWaitThreadID;
  93. //------------------------------
  94. void Init();
  95. BOOL Phase1Build();
  96. BOOL Phase2Build(HANDLE hTerminate);
  97. BOOL RegisterLogin();
  98. BOOL RevokeLogin();
  99. BOOL RegisterBackup();
  100. BOOL RevokeBackup();
  101. BOOL Phase1Delete(BOOL bIsSystemShutDown);
  102. BOOL Phase2Delete(BOOL bIsSystemShutdown);
  103. BOOL Phase3Delete();
  104. };
  105. extern struct _PROG_RESOURCES g_ProgRes;
  106. extern HINSTANCE g_hInstance;
  107. inline
  108. BOOL GLOB_Monitor_IsRegistred()
  109. {
  110. BOOL bRet;
  111. g_ProgRes.m_Monitor.Lock();
  112. bRet = g_ProgRes.m_Monitor.IsRegistred();
  113. g_ProgRes.m_Monitor.Unlock();
  114. return bRet;
  115. };
  116. inline
  117. CMonitorEvents * GLOB_GetMonitor()
  118. {
  119. return &g_ProgRes.m_Monitor;
  120. }
  121. //
  122. // Adap might be disallowed because of Setup running
  123. // or because of a registry setting
  124. //
  125. /////////////////////////////////////////////////////
  126. inline
  127. BOOL GLOB_IsResyncAllowed()
  128. {
  129. return (g_ProgRes.g_fDoResync && !g_ProgRes.g_fSetup);
  130. }
  131. //
  132. //
  133. // functions exported from mofdutil.cpp
  134. //
  135. //////////////////////////////////////////////////////////////////
  136. BOOL InitHotMofStuff( IN OUT struct _PROG_RESOURCES * pProgRes);
  137. void LoadMofsInDirectory(const TCHAR *szDirectory);
  138. BOOL CheckSetupSwitch( void );
  139. void SetNoShellADAPSwitch( void );
  140. BOOL CheckNoResyncSwitch( void );
  141. void AddToAutoRecoverList(TCHAR * pFileName);
  142. BOOL IsValidMulti(TCHAR * pMultStr, DWORD dwSize);
  143. BOOL IsStringPresent(TCHAR * pTest, TCHAR * pMultStr);
  144. //
  145. //
  146. // yet an other class factory
  147. //
  148. ///////////////////////////////////////////////////////////////////
  149. class CForwardFactory : public IClassFactory
  150. {
  151. protected:
  152. long m_lRef;
  153. CLSID m_ForwardClsid;
  154. public:
  155. CForwardFactory(REFCLSID rForwardClsid)
  156. : m_lRef(1), m_ForwardClsid(rForwardClsid)
  157. {}
  158. ~CForwardFactory();
  159. ULONG STDMETHODCALLTYPE AddRef();
  160. ULONG STDMETHODCALLTYPE Release();
  161. HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppv);
  162. HRESULT STDMETHODCALLTYPE CreateInstance(IUnknown* pUnkOuter,
  163. REFIID riid, void** ppv);
  164. HRESULT STDMETHODCALLTYPE LockServer(BOOL fLock);
  165. };
  166. //
  167. //
  168. // MyService
  169. //
  170. //
  171. //////////////////////////////////////////////////////////////////
  172. class MyService : public CNtService
  173. {
  174. public:
  175. MyService(DWORD CtrlAccepted);
  176. ~MyService();
  177. // CNtService interface
  178. DWORD WorkerThread();
  179. void Stop(BOOL bSystemShutDownCalled);
  180. void Log(LPCSTR lpszMsg);
  181. VOID Pause();
  182. VOID Continue();
  183. //
  184. VOID FinalCleanup();
  185. private:
  186. HANDLE m_hStopEvent;
  187. };
  188. //
  189. //
  190. // yet another smart mutex
  191. //
  192. //
  193. //////////////////////////////////////////////////////////////////
  194. class CInMutex
  195. {
  196. protected:
  197. HANDLE m_hMutex;
  198. public:
  199. CInMutex(HANDLE hMutex) : m_hMutex(hMutex)
  200. {
  201. if(m_hMutex)
  202. WaitForSingleObject(m_hMutex, INFINITE);
  203. }
  204. ~CInMutex()
  205. {
  206. if(m_hMutex)
  207. ReleaseMutex(m_hMutex);
  208. }
  209. };
  210. #endif