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.

462 lines
16 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. CFGMGR.H
  5. Abstract:
  6. This file implements the WinMgmt configuration manager class.
  7. See cfgmgr.h for documentation.
  8. Classes implemented:
  9. ConfigMgr configuration manager
  10. History:
  11. 09-Jul-96 raymcc Created.
  12. 3/10/97 levn Fully documented (ha ha)
  13. --*/
  14. #ifndef _CFGMGR_H_
  15. #define _CFGMGR_H_
  16. class CWbemObject;
  17. class CDynasty;
  18. class CWbemQueue;
  19. class CAsyncServiceQueue;
  20. struct IWbemEventSubsystem_m4;
  21. #define READONLY
  22. #include <wmiutils.h>
  23. #include <ql.h>
  24. #include <reposit.h>
  25. #include "coreq.h"
  26. //******************************************************************************
  27. //******************************************************************************
  28. //
  29. // class ConfigMgr
  30. //
  31. // This completely static class represents global configuration data for WinMgmt.
  32. // The rest of WinMgmt uses this class instead of global data itself.
  33. //
  34. //******************************************************************************
  35. //
  36. // static GetProviderCache
  37. //
  38. // Returns the pointer to the global provider cache object, as defined and
  39. // described in prvcache.h.
  40. //
  41. // Returns:
  42. //
  43. // CProviderCache*: internal pointer not to be modified or deleted!
  44. //
  45. //******************************************************************************
  46. //
  47. // GetDbPtr
  48. //
  49. // Returns the pointer to the WinMgmt static database object. The static database
  50. // is defined and described in objdb.h.
  51. //
  52. // Returns:
  53. //
  54. // CObjectDatabase*: internal pointer not to be modified or deleted!
  55. //
  56. //******************************************************************************
  57. //
  58. // GetUnRefedSvcQueue
  59. //
  60. // Returns the pointer to the global queue handling requests to providers.
  61. // Whenever WinMgmt needs to communicate to a provider, a request us added to
  62. // this queue. This queue is defined and described in provsvcq.h.
  63. //
  64. // Returns:
  65. //
  66. // CAsyncSvcQueue*: internal pointer not to be modified or deleted!
  67. //
  68. //******************************************************************************
  69. //
  70. // GetAsyncSvcQueue
  71. //
  72. // Returns the pointer to the global queue handling asynchrnous requests to
  73. // WinMgmt. Whenever a client makes a call into IWbemServices, WinMgmt adds a request
  74. // to this queue. This queue is defined and described in svcq.h
  75. //
  76. // Returns:
  77. //
  78. // CAsyncServiceQueue*: internal pointer not to be modified or deleted!
  79. //
  80. //******************************************************************************
  81. //
  82. // GetMachineName
  83. //
  84. // Returns the name of the computer we are running on as a UNICODE string,
  85. // even on Win95 where machine names are ASCII.
  86. //
  87. // Returns:
  88. //
  89. // LPWSTR: machine name. internal poitner not to be deleted!
  90. //
  91. //******************************************************************************
  92. //
  93. // GetWorkingDir
  94. //
  95. // Returns the working directory of WinMgmt, that is, where the database is
  96. // located.
  97. //
  98. // Returns:
  99. //
  100. // LPWSTR: internal pointer not to be deleted!
  101. //
  102. //******************************************************************************
  103. //
  104. // static InitSystem
  105. //
  106. // System initialization function invoked from wbemcore.dll entry point.
  107. // Performs the following tasks:
  108. //
  109. // 1) Looks for other copies of WinMgmt already running and stops with a fatal
  110. // error message if found.
  111. // 2) Reads the registry for initialization information.
  112. // 3) Creates the database object (this will in turn create the database file
  113. // if not found. See CObjectDatabase in objdb.h for details).
  114. // 4) Writes appropriate information (like database location) into the
  115. // registry.
  116. //
  117. // NOTE: since this function is invoked from inside the DLL entry point, there
  118. // are many restrictions on what it can do. In particular, it cannot create
  119. // threads and expect them to run. Thus, due to the multi-threaded nature of
  120. // WinMgmt, this function may not attempt to perform any WinMgmt operations at the
  121. // COM layer or the system will hang!
  122. //
  123. //******************************************************************************
  124. //
  125. // static Shutdown
  126. //
  127. // System Shutdown function invoked from wbemcore.dll entry point on PROCESS_
  128. // DETACH. Deletes the CObjectDatabase instance (see objdb.h).
  129. //
  130. //******************************************************************************
  131. //
  132. // static LoggingEnabled
  133. //
  134. // Checks if logging has been enabled. If it is, Trace calls output data to
  135. // a log file. If not, Trace calls are noops.
  136. //
  137. // Returns:
  138. //
  139. // BOOL: TRUE iff logging is enabled.
  140. //
  141. //******************************************************************************
  142. //
  143. // static GetEssSink
  144. //
  145. // Retrieves the pointer to the Event Subsystem. Event subsystem pointer will
  146. // only be available if EnableEvents registry value is set to TRUE. Otherwise,
  147. // this function returns NULL. Note, that the Event Subsystem is loaded only
  148. // by ConfigMgr::SetReady function which is invoked the first time
  149. // DllGetClassObject is called in wbemcore.dll. Thus, ESS is not available
  150. // during WinMgmt initialization (InitSystem).
  151. //
  152. // Returns:
  153. //
  154. // IWbemObjectSink*: the pointer to the ESS. Not to be released or
  155. // deleted by the caller! May be NULL, see above.
  156. //
  157. //******************************************************************************
  158. //
  159. // static SetReady
  160. //
  161. // This function performs initialization, once WinMgmt is ready to go.
  162. // It is invoked the first type DllGetClassObject is called in wbemcore.dll.
  163. // By now, wbemcorwbemcore.dll has exited its entry point and so it is safe to load
  164. // additional DLLs and perform multi-threaded operations (unlike InitSystem).
  165. //
  166. //******************************************************************************
  167. //
  168. // static SetIdentificationObject
  169. //
  170. // This function (invoked from the SetReady function) stores proper information
  171. // in the root and root\defualt __WinMgmtIdentification objects. Namely, it
  172. // creates instances of this class in both namespace if not already there and
  173. // sets the current build of WinMgmt in the appropriate fields.
  174. //
  175. // Parameters:
  176. //
  177. // IN WCHAR* pwcNamespace The namespace to initialize.
  178. //
  179. //******************************************************************************
  180. //
  181. // static GetDllVersion
  182. //
  183. // Retrives a string from a given DLLs resource table. If the string is longer
  184. // that the buffer, it is trucated.
  185. //
  186. // Parameters:
  187. //
  188. // IN char * pDLLName The filename of the DLL. The DLL must be
  189. // located in WinMgmt working directory (See
  190. // GetWorkingDir) and a relative path is
  191. // expected here.
  192. // IN char * pResStringName The resource string to query, e.g.,
  193. // "ProductVersion".
  194. // OUT WCHAR * pRes Destination buffer.
  195. // IN DWORD dwResSize Size of the destination buffer.
  196. //
  197. // Returns:
  198. //
  199. // BOOL: TRUE on success, FALSE if DLL or string was not found.
  200. //
  201. //******************************************************************************
  202. //
  203. // static RaiseClassDeletionEvent
  204. //
  205. // Temporarary: raises a class deletion event. This function is used in the
  206. // object database, since events need to be raised for every deleted class.
  207. //
  208. // Parameters:
  209. //
  210. // LPWSTR wszNamespace The name of the namespace where the class
  211. // is being deleted.
  212. // LPWSTR wszClass The name of the class being deleted.
  213. // IWbemClassObject* pClass The definition of the class being deleted.
  214. //
  215. // Returns:
  216. //
  217. // HRESULT: Whatever error code the ESS returns. Only WBEM_S_NO_ERROR is
  218. // documented.
  219. //
  220. //******************************************************************************
  221. //
  222. // static LoadResourceStr
  223. //
  224. // Loads a string resource from the string table in WBEMCORE.RC.
  225. //
  226. // Parameters:
  227. // DWORD dwId The string id.
  228. //
  229. // Return value:
  230. // A dynamically allocated LPWSTR. This string is loaded in DBCS form
  231. // for compatibility with Win98, but is returned in UNICODE form on both
  232. // Win98 and Windows NT. Deallocate with operator delete.
  233. //
  234. //******************************************************************************
  235. //
  236. // static GetPersistentCfgValue
  237. //
  238. // retrieves a persistent value from the $WINMGMT.cfg file (or from the memory
  239. // cache of it if already loaded).
  240. //
  241. // Parameters:
  242. // DWORD dwOffset Persistent value index
  243. //
  244. // Return Values
  245. // DWORD &dwValue Returned value
  246. // BOOL returns TRUE if successful, FALSE otherwise.
  247. //******************************************************************************
  248. //
  249. // static SetPersistentCfgValue
  250. //
  251. // sets a persistent value in the $WinMgmt.cfg file (and in the memory cache).
  252. //
  253. // Parameters:
  254. // DWORD dwOffset Persistent value index
  255. //
  256. // Return Values
  257. // DWORD &dwValue Returned value
  258. // BOOL returns TRUE if successful, FALSE otherwise.
  259. //******************************************************************************
  260. //
  261. // static SetADAPStatus
  262. //
  263. // This function (invoked from the SetReady function) stores an __ADAPStatus
  264. // instance in the root\default namespace on W2k boxes. Namely, it creates
  265. // the class if it doesn't exist as well as a singleton instance if it is
  266. // not there.
  267. //
  268. // Parameters:
  269. //
  270. // IN WCHAR* pwcNamespace The namespace to initialize.
  271. //
  272. //******************************************************************************
  273. class CAsyncReq;
  274. class ConfigMgr
  275. {
  276. static CStaticCritSec g_csEss;
  277. public:
  278. static READONLY CWbemQueue* GetUnRefedSvcQueue();
  279. static READONLY CAsyncServiceQueue* GetAsyncSvcQueue();
  280. static HRESULT EnqueueRequest(CAsyncReq * pRequest);
  281. static HRESULT EnqueueRequestAndWait(CAsyncReq * pRequest);
  282. static READONLY LPWSTR GetMachineName();
  283. static LPTSTR GetWorkingDir();
  284. static DWORD InitSystem();
  285. static DWORD Shutdown(BOOL bProcessShutdown, BOOL bIsSystemShutDown);
  286. static BOOL ShutdownInProgress();
  287. static IWbemEventSubsystem_m4* GetEssSink();
  288. static HRESULT SetReady();
  289. static HRESULT PrepareForClients(long lFlags);
  290. static void FatalInitializationError(HRESULT hRes);
  291. static HRESULT WaitUntilClientReady();
  292. static HRESULT SetIdentificationObject(IWmiDbHandle *pNs, IWmiDbSession *pSess);
  293. static HRESULT SetAdapStatusObject(IWmiDbHandle *pNs, IWmiDbSession *pSess);
  294. //static void ProcessIdentificationObject(IWmiDbHandle *pNs, IWbemClassObject *pInst);
  295. static BOOL GetDllVersion(TCHAR * pDLLName, TCHAR * pResStringName,
  296. WCHAR * pRes, DWORD dwResSize);
  297. static IWbemContext* GetNewContext();
  298. static LPTSTR GetDbDir();
  299. static class CEventLog* GetEventLog();
  300. static DWORD GetMaxMemoryQuota();
  301. static DWORD GetUncheckedTaskCount();
  302. static DWORD GetMaxTaskCount();
  303. static DWORD GetMaxWaitBeforeDenial();
  304. static DWORD GetNewTaskResistance();
  305. static BOOL GetEnableQueryArbitration( void );
  306. static BOOL GetMergerThrottlingEnabled( void );
  307. static BOOL GetMergerThresholdValues( DWORD* pdwThrottle, DWORD* pdwRelease, DWORD* pdwBatching );
  308. static BOOL GetArbitratorValues( DWORD* pdwEnabled, DWORD* pdwSystemHigh, DWORD* pdwMaxSleep,
  309. double* pdHighThreshold1, long* plMultiplier1, double* pdHighThreshold2,
  310. long* plMultiplier2, double* pdHighThreshold3, long* plMultiplier3 );
  311. static ULONG GetMinimumMemoryRequirements ( ) ;
  312. static BOOL GetEnableArbitratorDiagnosticThread( void );
  313. static DWORD GetProviderDeliveryTimeout( void );
  314. static HRESULT GetDefaultRepDriverClsId(CLSID &);
  315. static IWbemPath *GetNewPath(); // Returns NULL on error, requires Release() if successful.
  316. static BOOL GetPersistentCfgValue(DWORD dwOffset, DWORD &dwValue);
  317. static BOOL SetPersistentCfgValue(DWORD dwOffset, DWORD dwValue);
  318. //Retrieve a list of MOFs which need to be loaded when we have
  319. //have an empty database. User needs to "delete []" the
  320. //returned string. String is in a REG_MULTI_SZ format.
  321. //dwSize is the length of the buffer returned.
  322. static TCHAR* GetAutoRecoverMofs(DWORD &dwSize);
  323. static BOOL GetAutoRecoverDateTimeStamp(LARGE_INTEGER &liDateTimeStamp);
  324. static void ReadMaxQueueSize();
  325. static DWORD GetMaxQueueSize();
  326. static void SetDefaultMofLoadingNeeded();
  327. static HRESULT LoadDefaultMofs();
  328. static void GetSystemLimits();
  329. };
  330. //
  331. //
  332. // The Hook Class for trapping the creation of Win32_PerRawData
  333. //
  334. ///////////////////////////////////////////////////////////
  335. extern _IWmiCoreWriteHook * g_pRAHook; // = NULL;
  336. class CRAHooks : public _IWmiCoreWriteHook
  337. {
  338. public:
  339. CRAHooks(_IWmiCoreServices *pSvc);
  340. ~CRAHooks();
  341. _IWmiCoreServices * GetSvc(){ return m_pSvc; };
  342. STDMETHOD(QueryInterface)(REFIID riid, void ** ppv);
  343. ULONG STDMETHODCALLTYPE AddRef();
  344. ULONG STDMETHODCALLTYPE Release();
  345. STDMETHOD(PrePut)(long lFlags, long lUserFlags, IWbemContext* pContext,
  346. IWbemPath* pPath, LPCWSTR wszNamespace,
  347. LPCWSTR wszClass, _IWmiObject* pCopy);
  348. STDMETHOD(PostPut)(long lFlags, HRESULT hApiResult,
  349. IWbemContext* pContext,
  350. IWbemPath* pPath, LPCWSTR wszNamespace,
  351. LPCWSTR wszClass, _IWmiObject* pNew,
  352. _IWmiObject* pOld);
  353. STDMETHOD(PreDelete)(long lFlags, long lUserFlags,
  354. IWbemContext* pContext,
  355. IWbemPath* pPath, LPCWSTR wszNamespace,
  356. LPCWSTR wszClass);
  357. STDMETHOD(PostDelete)(long lFlags, HRESULT hApiResult,
  358. IWbemContext* pContext,
  359. IWbemPath* pPath, LPCWSTR wszNamespace,
  360. LPCWSTR wszClass, _IWmiObject* pOld);
  361. private:
  362. LONG m_cRef;
  363. _IWmiCoreServices * m_pSvc;
  364. };
  365. //
  366. //
  367. // Data for the interception
  368. //
  369. #define GUARDED_NAMESPACE L"root\\cimv2"
  370. #define GUARDED_CLASS L"win32_perfrawdata"
  371. #define GUARDED_HIPERF L"hiperf"
  372. #define GUARDED_PERFCTR L"genericperfctr"
  373. #define WMISVC_DLL L"wmisvc.dll"
  374. #define FUNCTION_DREDGERA "DredgeRA"
  375. class ExceptionCounter
  376. {
  377. private:
  378. static LONG s_Count;
  379. public:
  380. ExceptionCounter(){ InterlockedIncrement(&s_Count); };
  381. };
  382. HRESULT InitSubsystems();
  383. HRESULT InitESS(_IWmiCoreServices *pSvc, BOOL bAutoRecoverd);
  384. HRESULT ShutdownESS();
  385. HRESULT ShutdownSubsystems(BOOL bIsSystemShutDown);
  386. HRESULT SecureKey(WCHAR * pKeyName,WCHAR * pSDDLString);
  387. #define ARB_DEFAULT_SYSTEM_MINIMUM 0x1E8480 // minimum is 2mb
  388. // Defaults for arbitrator
  389. #define ARB_DEFAULT_SYSTEM_HIGH 0x4c4b400 // System limits [80megs]
  390. #define ARB_DEFAULT_SYSTEM_HIGH_FACTOR 50 // System limits [80megs] factor
  391. #define ARB_DEFAULT_MAX_SLEEP_TIME 300000 // Default max sleep time for each task
  392. #define ARB_DEFAULT_HIGH_THRESHOLD1 90 // High threshold 1
  393. #define ARB_DEFAULT_HIGH_THRESHOLD1MULT 2 // High threshold 1 multiplier
  394. #define ARB_DEFAULT_HIGH_THRESHOLD2 95 // High threshold 1
  395. #define ARB_DEFAULT_HIGH_THRESHOLD2MULT 3 // High threshold 1 multiplier
  396. #define ARB_DEFAULT_HIGH_THRESHOLD3 98 // High threshold 1
  397. #define ARB_DEFAULT_HIGH_THRESHOLD3MULT 4 // High threshold 1 multiplier
  398. // system limits reg keys
  399. #define MAX_IDENTIFIER_WBEM L"IdentifierLimit"
  400. #define MAX_QUERY_WBEM L"QueryLimit"
  401. #define MAX_PATH_WBEM L"PathLimit"
  402. ///////////// system limits adjustment
  403. // an instance of __namespace is put with a __RELAPATH __namespace.name="X"
  404. #define NAMESPACE_ADJUSTMENT (19) // lstrlen of __namespace.name=""
  405. // a class must allow an object to be put
  406. // if it is a singleton, it is '=@' othewise '.P="X"' , the maximum is 6
  407. #define CLASSNAME_ADJUSTMENT (6)
  408. #define MINIMUM_MAX_QUERY 64
  409. #define MINIMUM_MAX_IDENTIFIER 64
  410. #endif