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.

460 lines
15 KiB

  1. // Copyright (c) 1996-1999 Microsoft Corporation
  2. #ifndef _CONFIG_HXX_
  3. #define _CONFIG_HXX_ 1
  4. //+----------------------------------------------------------------------------
  5. //
  6. // CMultiTsz
  7. //
  8. // This class represents a multi-string (i.e. a REG_MULTISZ). A subscript
  9. // operator overload is provided for access to the component strings. A
  10. // multi-string is a series of strings, each null terminated, where the last
  11. // string has an additional null terminator.
  12. //
  13. //+----------------------------------------------------------------------------
  14. #define CMULTITSZ_SIZE MAX_PATH
  15. class CMultiTsz
  16. {
  17. public:
  18. CMultiTsz()
  19. {
  20. memset( _tsz, 0, sizeof(_tsz) );
  21. _cStrings = 0;
  22. }
  23. public:
  24. static ULONG MaxSize()
  25. {
  26. return( CMULTITSZ_SIZE );
  27. }
  28. const TCHAR* operator[]( int iRequest ) const
  29. {
  30. int iSearch = 0;
  31. const TCHAR *ptszSearch = TEXT('\0') == _tsz[0] ? NULL : _tsz;
  32. // Scan through the strings until we get the index we want
  33. // or it goes off the end of the array.
  34. while( ptszSearch && iSearch < iRequest )
  35. {
  36. ptszSearch += _tcslen(ptszSearch) + 1;
  37. if( TEXT('\0') == *ptszSearch )
  38. ptszSearch = NULL;
  39. else
  40. iSearch++;
  41. }
  42. return( ptszSearch );
  43. }
  44. CMultiTsz & operator=( const TCHAR* ptsz )
  45. {
  46. memset( _tsz, 0, sizeof(_tsz) );
  47. _tcsncpy( _tsz, ptsz, ELEMENTS(_tsz)-1 );
  48. return(*this);
  49. }
  50. LPBYTE GetBuffer()
  51. {
  52. _cStrings = 0;
  53. return( reinterpret_cast<LPBYTE>(&_tsz[0]) );
  54. }
  55. // Randomly select one of the strings to return.
  56. operator const TCHAR*()
  57. {
  58. CalcNumStringsIf();
  59. if( 1 >= _cStrings )
  60. return( _tsz );
  61. else
  62. {
  63. DWORD dwRandom = static_cast<DWORD>(static_cast<LONGLONG>( CFILETIME() ));
  64. int iRandom = dwRandom % _cStrings;
  65. return( (*this)[ iRandom ] );
  66. }
  67. }
  68. ULONG NumStrings()
  69. {
  70. CalcNumStringsIf();
  71. return( _cStrings );
  72. }
  73. private:
  74. void CalcNumStringsIf()
  75. {
  76. if( 0 == _cStrings )
  77. CalcNumStrings();
  78. }
  79. void CalcNumStrings()
  80. {
  81. const TCHAR *ptszSearch = _tsz;
  82. _cStrings = 0;
  83. while( TEXT('\0') != ptszSearch[0] )
  84. {
  85. _cStrings++;
  86. ptszSearch += _tcslen(ptszSearch) + 1;
  87. }
  88. }
  89. private:
  90. TCHAR _tsz[ CMULTITSZ_SIZE ];
  91. ULONG _cStrings;
  92. };
  93. //-------------------------------------------------------------------//
  94. //
  95. // CTrkConfiguration
  96. //
  97. // Common configuration code for both services, in the form of the
  98. // CTrkConfiguration base class (inherited by CTrkWksConfiguration and
  99. // CTrkSvrConfiguration).
  100. //
  101. //-------------------------------------------------------------------//
  102. // CTrkConfiguration, CTrkWksConfiguration, and CTrkSvrConfiguration
  103. // hold the configurable parameters for the two services.
  104. // The base registry key under which the derived classes put a sub-key
  105. extern const TCHAR s_tszKeyNameLinkTrack[];
  106. // The CTrkConfiguration base class provides a generic enough
  107. // Read method that it can be used by both of the derived classes.
  108. #define TRK_TEST_FLAGS_NAME TEXT("TestFlags")
  109. #define TRK_TEST_FLAG_CALL_SERVER 0x00000001
  110. #define TRK_TEST_FLAG_WAIT_ON_EXIT 0x00000002
  111. #define TRK_TEST_FLAG_SET_VOLUME_ID 0x00000004
  112. #define TRK_TEST_FLAG_MOVE_BATCH_SYNC 0x00000008
  113. #define TRK_TEST_FLAG_TUNNEL_SYNC 0x00000010
  114. #define TRK_TEST_FLAG_ALLOC_TEST_VOLUME 0x00000020
  115. #define TRK_TEST_FLAGS_DEFAULT 0
  116. // DC name to use instead of calling DsGetDcName. Setting this
  117. // causes RPC security (Kerberos) *not* to be used.
  118. #define CUSTOM_DC_NAME_NAME TEXT("CustomDcName")
  119. #define CUSTOM_DC_NAME_DEFAULT TEXT("")
  120. // Similar to CustomDcName, except secure RPC is still used.
  121. // If CustomDcName is set, it takes precedence.
  122. #define CUSTOM_SECURE_DC_NAME_NAME TEXT("CustomSecureDcName")
  123. #define CUSTOM_SECURE_DC_NAME_DEFAULT TEXT("")
  124. // Filename for status log
  125. #define OPERATION_LOG_NAME_NAME TEXT("OperationLogName")
  126. #define OPERATION_LOG_NAME_DEFAULT TEXT("")
  127. #define TRK_DEBUG_FLAGS_NAME TEXT("TrkDebugFlags")
  128. #define TRK_DEBUG_FLAGS_DEFAULT TRKDBG_ERROR // (0xFFFFFFFF & ~TRKDBG_WORKMAN) == 0xff7fffff
  129. #define DEBUG_STORE_FLAGS_NAME TEXT("DebugStoreFlags")
  130. #define DEBUG_STORE_FLAGS_DEFAULT TRK_DBG_FLAGS_WRITE_TO_DBG
  131. class CTrkConfiguration
  132. {
  133. public:
  134. CTrkConfiguration()
  135. {
  136. _fInitialized = FALSE;
  137. _hkey = NULL;
  138. _dwTestFlags = 0;
  139. _dwDebugFlags = 0;
  140. }
  141. ~CTrkConfiguration()
  142. {
  143. UnInitialize();
  144. }
  145. DWORD GetTestFlags() const { return _dwTestFlags; }
  146. void Initialize();
  147. void UnInitialize();
  148. static BOOL UseOperationLog()
  149. {
  150. return( 0 != _mtszOperationLog.NumStrings() );
  151. }
  152. static const TCHAR* GetOperationLog()
  153. {
  154. return( _mtszOperationLog[0] );
  155. }
  156. protected:
  157. void Read( const TCHAR *ptszName, DWORD *pdwValue, DWORD dwDefault ) const;
  158. void Read( const TCHAR *ptszName, ULONG *pcbValue, TCHAR *ptszValue, TCHAR *ptszDefault ) const;
  159. void Read( const TCHAR *ptszName, CMultiTsz *pmtszValue, TCHAR *ptszDefault ) const;
  160. BOOL Write( const TCHAR *ptszName, DWORD dwValue ) const;
  161. BOOL Write( const TCHAR *ptszName, const TCHAR *ptszValue ) const;
  162. public:
  163. BOOL _fInitialized;
  164. HKEY _hkey;
  165. DWORD _dwTestFlags;
  166. DWORD _dwDebugFlags;
  167. DWORD _dwDebugStoreFlags;
  168. static CMultiTsz _mtszOperationLog;
  169. };
  170. #define TRKMINUTE 60
  171. #define TRKHOUR (TRKMINUTE*60)
  172. #define TRKDAY (TRKHOUR*24)
  173. #define TRKWEEK (TRKDAY*7)
  174. struct STrkConfigRecord
  175. {
  176. const TCHAR *ptszName;
  177. DWORD dwDefault;
  178. DWORD dwValue;
  179. DWORD dwFlags;
  180. #if DBG
  181. DWORD Index;
  182. #endif
  183. };
  184. // Flags
  185. #define TRKCONFIG_STATIC 0 // Dynamic parameters can be changed
  186. #define TRKCONFIG_DYNAMIC 1 // at run-time.
  187. #if DBG
  188. #define TRKCONFIGRECORD(v, w,x,y,z) { v, w, x, y, z }
  189. #else
  190. #define TRKCONFIGRECORD(v, w,x,y,z) { v, w, x, y }
  191. #endif
  192. //+-------------------------------------------------------------------------
  193. //
  194. // Class: CTrkSvrConfiguration
  195. //
  196. // Purpose: Holds configuration parameters (registry-settable) for
  197. // the Tracking (Server) Service.
  198. //
  199. // Notes:
  200. //
  201. //--------------------------------------------------------------------------
  202. #define HISTORY_PERIOD_NAME TEXT("HistoryPeriod")
  203. #define HISTORY_PERIOD_DEFAULT 10 // Seconds
  204. #define GC_PERIOD_NAME TEXT("GCPeriod")
  205. #define GC_PERIOD_DEFAULT (30*TRKDAY)
  206. #define GC_DIVISOR_NAME TEXT("GCDivisor")
  207. #define GC_DIVISOR_DEFAULT 30
  208. #define GC_MIN_CYCLES_NAME TEXT("GCMinCycles")
  209. #define GC_MIN_CYCLES_DEFAULT 90
  210. #define GC_HESITATION_NAME TEXT("GCHesitation")
  211. #define GC_HESITATION_DEFAULT (30*TRKMINUTE)
  212. #define GC_RETRY_NAME TEXT("GCRetry")
  213. #define GC_RETRY_DEFAULT (30*TRKHOUR)
  214. #define DC_UPDATE_COUNTER_PERIOD_NAME TEXT("DcUpdateCounterPeriod")
  215. #define DC_UPDATE_COUNTER_PERIOD_DEFAULT (4*TRKHOUR)
  216. #define MOVE_LIMIT_PER_VOLUME_LOWER_NAME TEXT("MoveLimitPerVolume")
  217. #define MOVE_LIMIT_PER_VOLUME_LOWER_DEFAULT 200 // entries per volume
  218. #define MOVE_LIMIT_PER_VOLUME_UPPER_NAME TEXT("MoveLimitPerVolumeUpper")
  219. #define MOVE_LIMIT_PER_VOLUME_UPPER_DEFAULT 100 // entries per volume
  220. #define MOVE_LIMIT_TRANSITION_NAME TEXT("MoveLimitPerVolumeTransition")
  221. #define MOVE_LIMIT_TRANSITION_DEFAULT 5000
  222. #define CACHE_MIN_TIME_TO_LIVE_NAME TEXT("CacheMinTimeToLive")
  223. #define CACHE_MIN_TIME_TO_LIVE_DEFAULT (4*TRKHOUR)
  224. #define CACHE_MAX_TIME_TO_LIVE_NAME TEXT("CacheMaxTimeToLive")
  225. #define CACHE_MAX_TIME_TO_LIVE_DEFAULT TRKDAY
  226. #define DESIGNATED_DC_CACHE_TTL_NAME TEXT("DesignatedDcCacheTTL")
  227. #define DESIGNATED_DC_CACHE_TTL_DEFAULT (5*TRKMINUTE)
  228. #define DESIGNATED_DC_CLEANUP_NAME TEXT("DesignatedDcCleanup")
  229. #define DESIGNATED_DC_CLEANUP_DEFAULT (3*TRKDAY)
  230. #define VOLUME_TABLE_LIMIT_NAME TEXT("VolumeLimit")
  231. #define VOLUME_TABLE_LIMIT_DEFAULT 26 // entries per machine
  232. #define SVR_MAX_RPC_CALLS_NAME TEXT("SvrMaxRpcCallsName")
  233. #define SVR_MAX_RPC_CALLS_DEFAULT 20
  234. #define MAX_DS_WRITES_PER_HOUR_NAME TEXT("MaxDsWritesPerHour")
  235. #define MAX_DS_WRITES_PER_HOUR_DEFAULT 1000
  236. #define MAX_DS_WRITES_PERIOD_NAME TEXT("MaxDsWritesPeriod")
  237. #define MAX_DS_WRITES_PERIOD_DEFAULT TRKHOUR
  238. #define REPETITIVE_TASK_DELAY_NAME TEXT("RepetitiveTaskDelay")
  239. #define REPETITIVE_TASK_DELAY_DEFAULT 100 // Milliseconds
  240. #define REFRESH_STORAGE_TTL_NAME TEXT("RefreshStorageTTL")
  241. #define REFRESH_STORAGE_TTL_DEFAULT (5*TRKMINUTE)
  242. class CTrkSvrConfiguration : public CTrkConfiguration
  243. {
  244. public:
  245. inline CTrkSvrConfiguration();
  246. inline ~CTrkSvrConfiguration();
  247. public:
  248. inline void Initialize();
  249. inline void UnInitialize();
  250. public:
  251. DWORD GetHistoryPeriod() const { return _dwHistoryPeriod; }
  252. DWORD GetGCPeriod() const { return _dwGCPeriod; }
  253. DWORD GetGCMinCycles() const { return _dwGCMinCycles; }
  254. DWORD GetGCDivisor() const { return _dwGCDivisor; }
  255. DWORD GetGCHesitation() const { return _dwGCHesitation; }
  256. DWORD GetGCRetry() const { return _dwGCRetry; }
  257. DWORD GetVolumeQueryPeriods() const { return _dwVolumeQueryPeriods; }
  258. DWORD GetVolumeQueryPeriod() const { return _dwVolumeQueryPeriod; }
  259. DWORD GetDcUpdateCounterPeriod() const{ return _dwDcUpdateCounterPeriod; }
  260. DWORD GetCacheMinTimeToLive() const { return _dwCacheMinTimeToLive; }
  261. DWORD GetCacheMaxTimeToLive() const { return _dwCacheMaxTimeToLive; }
  262. DWORD GetMoveLimitPerVolumeLower() const { return _dwMoveLimitPerVolumeLower; }
  263. DWORD GetMoveLimitPerVolumeUpper() const { return _dwMoveLimitPerVolumeUpper; }
  264. DWORD GetMoveLimitTransition() const { return _dwMoveLimitTransition; }
  265. DWORD GetMoveLimitTimeToLive() const { return _dwMoveLimitTimeToLive; }
  266. DWORD GetVolumeLimit() const { return _dwVolumeLimit; }
  267. DWORD GetSvrMaxRpcCalls() const { return _dwSvrMaxRpcCalls; }
  268. DWORD GetMaxDSWritesPerHour() const { return _dwMaxDSWritesPerHour; }
  269. DWORD GetMaxDSWritesPeriod() const { return _dwMaxDSWritesPeriod; }
  270. DWORD GetRepetitiveTaskDelay() const { return _dwRepetitiveTaskDelay; }
  271. DWORD GetDesignatedDcCacheTTL() const { return _dwDesignatedDcCacheTTL; }
  272. DWORD GetDesignatedDcCleanup() const { return _dwDesignatedDcCleanup; }
  273. DWORD GetRefreshStorageTTL() const { return _dwRefreshStorageTTL; }
  274. BOOL _fInitialized;
  275. DWORD _dwHistoryPeriod; // Seconds
  276. DWORD _dwGCPeriod; // Seconds
  277. DWORD _dwGCDivisor;
  278. DWORD _dwGCMinCycles; // Seconds
  279. DWORD _dwGCHesitation;
  280. DWORD _dwGCRetry;
  281. DWORD _dwVolumeQueryPeriod; // Seconds
  282. DWORD _dwVolumeQueryPeriods; // # of VolumeQueryPeriods
  283. DWORD _dwDcUpdateCounterPeriod; // seconds
  284. DWORD _dwCacheMinTimeToLive;
  285. DWORD _dwCacheMaxTimeToLive;
  286. DWORD _dwMoveLimitPerVolumeLower;
  287. DWORD _dwMoveLimitPerVolumeUpper;
  288. DWORD _dwMoveLimitTransition;
  289. DWORD _dwMoveLimitTimeToLive; // seconds
  290. DWORD _dwVolumeLimit; // # of entries
  291. DWORD _dwSvrMaxRpcCalls;
  292. DWORD _dwMaxDSWritesPerHour;
  293. DWORD _dwMaxDSWritesPeriod;
  294. DWORD _dwRepetitiveTaskDelay; // Milliseconds
  295. DWORD _dwDesignatedDcCacheTTL;
  296. DWORD _dwDesignatedDcCleanup;
  297. DWORD _dwRefreshStorageTTL;
  298. };
  299. inline
  300. CTrkSvrConfiguration::CTrkSvrConfiguration()
  301. {
  302. memset( this, 0, sizeof(*this) );
  303. }
  304. inline
  305. CTrkSvrConfiguration::~CTrkSvrConfiguration()
  306. {
  307. UnInitialize();
  308. }
  309. inline VOID
  310. CTrkSvrConfiguration::Initialize()
  311. {
  312. _fInitialized = TRUE;
  313. CTrkConfiguration::Initialize( );
  314. Read( HISTORY_PERIOD_NAME, &_dwHistoryPeriod, HISTORY_PERIOD_DEFAULT );
  315. Read( GC_PERIOD_NAME, &_dwGCPeriod, GC_PERIOD_DEFAULT );
  316. Read( GC_MIN_CYCLES_NAME, &_dwGCMinCycles, GC_MIN_CYCLES_DEFAULT );
  317. Read( GC_DIVISOR_NAME, &_dwGCDivisor, GC_DIVISOR_DEFAULT );
  318. Read( GC_HESITATION_NAME, &_dwGCHesitation, GC_HESITATION_DEFAULT );
  319. Read( GC_RETRY_NAME, &_dwGCRetry, GC_RETRY_DEFAULT );
  320. Read( DC_UPDATE_COUNTER_PERIOD_NAME, &_dwDcUpdateCounterPeriod, DC_UPDATE_COUNTER_PERIOD_DEFAULT);
  321. Read( CACHE_MIN_TIME_TO_LIVE_NAME, &_dwCacheMinTimeToLive, CACHE_MIN_TIME_TO_LIVE_DEFAULT);
  322. Read( CACHE_MAX_TIME_TO_LIVE_NAME, &_dwCacheMaxTimeToLive, CACHE_MAX_TIME_TO_LIVE_DEFAULT);
  323. Read( MOVE_LIMIT_PER_VOLUME_LOWER_NAME, &_dwMoveLimitPerVolumeLower, MOVE_LIMIT_PER_VOLUME_LOWER_DEFAULT);
  324. Read( MOVE_LIMIT_PER_VOLUME_UPPER_NAME, &_dwMoveLimitPerVolumeUpper, MOVE_LIMIT_PER_VOLUME_UPPER_DEFAULT);
  325. Read( MOVE_LIMIT_TRANSITION_NAME, &_dwMoveLimitTransition, MOVE_LIMIT_TRANSITION_DEFAULT);
  326. Read( VOLUME_TABLE_LIMIT_NAME, &_dwVolumeLimit, VOLUME_TABLE_LIMIT_DEFAULT);
  327. Read( SVR_MAX_RPC_CALLS_NAME, &_dwSvrMaxRpcCalls, SVR_MAX_RPC_CALLS_DEFAULT );
  328. Read( MAX_DS_WRITES_PER_HOUR_NAME, &_dwMaxDSWritesPerHour, MAX_DS_WRITES_PER_HOUR_DEFAULT );
  329. Read( MAX_DS_WRITES_PERIOD_NAME, &_dwMaxDSWritesPeriod, MAX_DS_WRITES_PERIOD_DEFAULT );
  330. Read( REPETITIVE_TASK_DELAY_NAME, &_dwRepetitiveTaskDelay, REPETITIVE_TASK_DELAY_DEFAULT );
  331. Read( DESIGNATED_DC_CACHE_TTL_NAME, &_dwDesignatedDcCacheTTL, DESIGNATED_DC_CACHE_TTL_DEFAULT );
  332. Read( DESIGNATED_DC_CLEANUP_NAME, &_dwDesignatedDcCleanup, DESIGNATED_DC_CLEANUP_DEFAULT );
  333. Read( REFRESH_STORAGE_TTL_NAME, &_dwRefreshStorageTTL, REFRESH_STORAGE_TTL_DEFAULT );
  334. // We've got our configuration cached, so we can uninit the base class
  335. CTrkConfiguration::UnInitialize();
  336. }
  337. inline VOID
  338. CTrkSvrConfiguration::UnInitialize()
  339. {
  340. if( _fInitialized )
  341. {
  342. CTrkConfiguration::UnInitialize();
  343. _fInitialized = FALSE;
  344. }
  345. }
  346. #endif // #ifndef _CONFIG_HXX_