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.

748 lines
24 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. config.cpp
  7. Registry Values for WINS
  8. FILE HISTORY:
  9. */
  10. #include "stdafx.h"
  11. #include "config.h"
  12. #include "tregkey.h"
  13. // these are things not defined in winscnst.h.
  14. // Registry Entries under HKEY_LOCAL_MACHINE\system\currentcontrolset\services\wins
  15. const CConfiguration::REGKEYNAME CConfiguration::lpstrRoot = _T("SYSTEM\\CurrentControlSet\\Services\\wins\\Parameters");
  16. // consistency checking
  17. const CConfiguration::REGKEYNAME CConfiguration::lpstrCCRoot = _T("SYSTEM\\CurrentControlSet\\Services\\wins\\Parameters\\ConsistencyCheck");
  18. const CConfiguration::REGKEYNAME CConfiguration::lpstrCC = _T("ConsistencyCheck");
  19. // default values for replication partners
  20. const CConfiguration::REGKEYNAME CConfiguration::lpstrDefaultsRoot = _T("SYSTEM\\CurrentControlSet\\Services\\wins\\Parameters\\Defaults");
  21. const CConfiguration::REGKEYNAME CConfiguration::lpstrPullDefaultsRoot = _T("SYSTEM\\CurrentControlSet\\Services\\wins\\Parameters\\Defaults\\Pull");
  22. const CConfiguration::REGKEYNAME CConfiguration::lpstrPushDefaultsRoot = _T("SYSTEM\\CurrentControlSet\\Services\\wins\\Parameters\\Defaults\\Push");
  23. // entries under HKEY_LOCAL_MACHINE\system\currentcontrolset\services\wins\partnets\pull
  24. const CConfiguration::REGKEYNAME CConfiguration::lpstrPullRoot = _T("SYSTEM\\CurrentControlSet\\Services\\wins\\Partners\\Pull");
  25. // entries under HKEY_LOCAL_MACHINE\system\currentcontrolset\services\wins\partnets\push
  26. const CConfiguration::REGKEYNAME CConfiguration::lpstrPushRoot = _T("SYSTEM\\CurrentControlSet\\Services\\wins\\Partners\\Push");
  27. // per-replication partner parameters
  28. const CConfiguration::REGKEYNAME CConfiguration::lpstrNetBIOSName = _T("NetBIOSName");
  29. // entry for global setting for persistence
  30. const CConfiguration::REGKEYNAME CConfiguration::lpstrPersistence = _T("PersistentRplOn");
  31. // for determining system version
  32. const CConfiguration::REGKEYNAME CConfiguration::lpstrCurrentVersion = _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion");
  33. const CConfiguration::REGKEYNAME CConfiguration::lpstrWinVersion = _T("CurrentVersion");
  34. const CConfiguration::REGKEYNAME CConfiguration::lpstrSPVersion = _T("CSDVersion");
  35. const CConfiguration::REGKEYNAME CConfiguration::lpstrBuildNumber = _T("CurrentBuildNumber");
  36. /*---------------------------------------------------------------------------
  37. CConfiguration::CConfiguration(CString strNetBIOSName)
  38. Constructor
  39. ---------------------------------------------------------------------------*/
  40. CConfiguration::CConfiguration(CString strNetBIOSName)
  41. : m_strNetBIOSName(strNetBIOSName)
  42. {
  43. m_dwMajorVersion = 0;
  44. m_dwMinorVersion = 0;
  45. m_dwBuildNumber = 0;
  46. m_dwServicePack = 0;
  47. m_dwPushPersistence = 0;
  48. m_dwPullPersistence = 0;
  49. m_fIsAdmin = FALSE;
  50. m_strDbName = _T("wins.mdb"); // default db name
  51. }
  52. /*---------------------------------------------------------------------------
  53. CConfiguration::~CConfiguration()
  54. Destructor
  55. ---------------------------------------------------------------------------*/
  56. CConfiguration::~CConfiguration()
  57. {
  58. }
  59. /*---------------------------------------------------------------------------
  60. CConfiguration:: operator =(const CConfiguration& configuration)
  61. Overloaded assignment operator
  62. ---------------------------------------------------------------------------*/
  63. CConfiguration&
  64. CConfiguration:: operator =(const CConfiguration& configuration)
  65. {
  66. m_strNetBIOSName = configuration.m_strNetBIOSName;
  67. m_strBackupPath = configuration.m_strBackupPath;
  68. m_dwRefreshInterval = configuration.m_dwRefreshInterval;
  69. m_dwTombstoneInterval = configuration.m_dwTombstoneInterval;
  70. m_dwTombstoneTimeout = configuration.m_dwTombstoneTimeout;
  71. m_dwVerifyInterval = configuration.m_dwVerifyInterval;
  72. m_dwVersCountStart_LowWord = configuration.m_dwVersCountStart_LowWord;
  73. m_dwVersCountStart_HighWord= configuration.m_dwVersCountStart_HighWord;
  74. m_dwNumberOfWorkerThreads = configuration.m_dwNumberOfWorkerThreads;
  75. m_fPullInitialReplication = configuration.m_fPullInitialReplication;
  76. m_dwPullRetryCount = configuration.m_dwPullRetryCount;
  77. m_dwPullTimeInterval = configuration.m_dwPullTimeInterval;
  78. m_dwPullSpTime = configuration.m_dwPullSpTime;
  79. m_fPushInitialReplication = configuration.m_fPushInitialReplication;
  80. m_fPushReplOnAddrChange = configuration.m_fPushReplOnAddrChange;
  81. m_dwPushUpdateCount = configuration.m_dwPushUpdateCount;
  82. m_fRplOnlyWithPartners = configuration.m_fRplOnlyWithPartners;
  83. m_fLogDetailedEvents = configuration.m_fLogDetailedEvents;
  84. m_fBackupOnTermination = configuration.m_fBackupOnTermination;
  85. m_fLoggingOn = configuration.m_fLoggingOn;
  86. m_fMigrateOn = configuration.m_fMigrateOn;
  87. m_fUseSelfFndPnrs = configuration.m_fUseSelfFndPnrs;
  88. m_dwMulticastInt = configuration.m_dwMulticastInt;
  89. m_dwMcastTtl = configuration.m_dwMcastTtl;
  90. m_dwPullPersistence = configuration.m_dwPullPersistence;
  91. m_dwPushPersistence = configuration.m_dwPushPersistence;
  92. m_fBurstHandling = configuration.m_fBurstHandling;
  93. m_dwBurstQueSize = configuration.m_dwBurstQueSize;
  94. m_fPeriodicConsistencyCheck = configuration.m_fPeriodicConsistencyCheck;
  95. m_fCCUseRplPnrs = configuration.m_fCCUseRplPnrs;
  96. m_dwMaxRecsAtATime = configuration.m_dwMaxRecsAtATime;
  97. m_dwCCTimeInterval = configuration.m_dwCCTimeInterval;
  98. m_itmCCStartTime = configuration.m_itmCCStartTime;
  99. m_dwMajorVersion = configuration.m_dwMajorVersion;
  100. m_dwMinorVersion = configuration.m_dwMinorVersion;
  101. m_dwBuildNumber = configuration.m_dwBuildNumber;
  102. m_dwServicePack = configuration.m_dwServicePack;
  103. m_fIsAdmin = configuration.m_fIsAdmin;
  104. m_strDbPath = configuration.m_strDbPath;
  105. return *this;
  106. }
  107. HRESULT
  108. CConfiguration::Touch()
  109. {
  110. HRESULT hr = hrOK;
  111. return hr;
  112. }
  113. /*---------------------------------------------------------------------------
  114. CConfiguration::Load()
  115. Reads the values from the registry
  116. ---------------------------------------------------------------------------*/
  117. HRESULT
  118. CConfiguration::Load(handle_t hBinding)
  119. {
  120. HRESULT hr = hrOK;
  121. DWORD err = ERROR_SUCCESS;
  122. CString strDefaultPullSpTime;
  123. err = GetSystemVersion();
  124. if (err)
  125. return err;
  126. RegKey rk;
  127. err = rk.Open(HKEY_LOCAL_MACHINE, (LPCTSTR) lpstrRoot, KEY_READ, m_strNetBIOSName);
  128. if (err)
  129. {
  130. // may not exist, try creating the key
  131. err = rk.Create(HKEY_LOCAL_MACHINE,(LPCTSTR) lpstrRoot, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,NULL, m_strNetBIOSName);
  132. }
  133. RegKey rkPull;
  134. err = rkPull.Open(HKEY_LOCAL_MACHINE, (LPCTSTR) lpstrPullRoot, KEY_READ, m_strNetBIOSName);
  135. if (err)
  136. {
  137. // may not exist, try creating the key
  138. err = rkPull.Create(HKEY_LOCAL_MACHINE, (LPCTSTR)lpstrPullRoot, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,NULL, m_strNetBIOSName);
  139. }
  140. RegKey rkPush;
  141. err = rkPush.Open(HKEY_LOCAL_MACHINE, (LPCTSTR) lpstrPushRoot, KEY_READ, m_strNetBIOSName);
  142. if (err)
  143. {
  144. // may not exist, try creating the key
  145. err = rkPush.Create(HKEY_LOCAL_MACHINE, (LPCTSTR)lpstrPushRoot, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,NULL, m_strNetBIOSName);
  146. }
  147. RegKey rkPullDefaults;
  148. err = rkPullDefaults.Open(HKEY_LOCAL_MACHINE, (LPCTSTR) lpstrPullDefaultsRoot, KEY_READ, m_strNetBIOSName);
  149. if (err)
  150. {
  151. // may not exist, try creating the key
  152. err = rkPullDefaults.Create(HKEY_LOCAL_MACHINE, (LPCTSTR)lpstrPullDefaultsRoot, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,NULL, m_strNetBIOSName);
  153. }
  154. RegKey rkPushDefaults;
  155. err = rkPushDefaults.Open(HKEY_LOCAL_MACHINE, (LPCTSTR) lpstrPushDefaultsRoot, KEY_READ, m_strNetBIOSName);
  156. if (err)
  157. {
  158. // may not exist, try creating the key
  159. err = rkPushDefaults.Create(HKEY_LOCAL_MACHINE, (LPCTSTR)lpstrPushDefaultsRoot, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,NULL, m_strNetBIOSName);
  160. }
  161. // if you could not locate the key, no point continuing
  162. //if (err)
  163. // return err;
  164. // now query for the various values
  165. err = ERROR_FILE_NOT_FOUND;
  166. if (
  167. ((HKEY) rk == NULL) ||
  168. (err = rk.QueryValue(WINSCNF_REFRESH_INTVL_NM, m_dwRefreshInterval)) ||
  169. (err = rk.QueryValue(WINSCNF_DO_BACKUP_ON_TERM_NM, (DWORD &) m_fBackupOnTermination)) ||
  170. (err = rk.QueryValue(WINSCNF_TOMBSTONE_INTVL_NM, m_dwTombstoneInterval)) ||
  171. (err = rk.QueryValue(WINSCNF_TOMBSTONE_TMOUT_NM, m_dwTombstoneTimeout)) ||
  172. (err = rk.QueryValue(WINSCNF_VERIFY_INTVL_NM, m_dwVerifyInterval)) ||
  173. (err = rk.QueryValue(WINSCNF_INIT_VERSNO_VAL_LW_NM, m_dwVersCountStart_LowWord)) ||
  174. (err = rk.QueryValue(WINSCNF_INIT_VERSNO_VAL_HW_NM, m_dwVersCountStart_HighWord)) ||
  175. (err = rk.QueryValue(WINSCNF_RPL_ONLY_W_CNF_PNRS_NM, (DWORD &) m_fRplOnlyWithPartners)) ||
  176. (err = rk.QueryValue(WINSCNF_LOG_DETAILED_EVTS_NM, (DWORD &) m_fLogDetailedEvents)) ||
  177. (err = rk.QueryValue(WINSCNF_LOG_FLAG_NM, (DWORD &) m_fLoggingOn)) ||
  178. (err = rk.QueryValue(WINSCNF_MIGRATION_ON_NM, (DWORD &) m_fMigrateOn))
  179. )
  180. {
  181. if (err == ERROR_FILE_NOT_FOUND)
  182. {
  183. // This error is ok, because it just means
  184. // that the registry entries did not exist
  185. // for them yet. Set some acceptible default
  186. // values.
  187. m_fBackupOnTermination = FALSE;
  188. m_dwVersCountStart_LowWord = 0;
  189. m_dwVersCountStart_HighWord = 0;
  190. m_fRplOnlyWithPartners = TRUE;
  191. m_fLogDetailedEvents = FALSE;
  192. m_fLoggingOn = TRUE;
  193. m_fMigrateOn = FALSE;
  194. m_dwNumberOfWorkerThreads = 1;
  195. err = ERROR_SUCCESS;
  196. }
  197. else
  198. {
  199. return err;
  200. }
  201. }
  202. // push stuff
  203. if (
  204. ((HKEY) rkPush == NULL) ||
  205. (err = rkPush.QueryValue(WINSCNF_INIT_TIME_RPL_NM, (DWORD &) m_fPushInitialReplication)) ||
  206. (err = rkPush.QueryValue(WINSCNF_ADDCHG_TRIGGER_NM, (DWORD &) m_fPushReplOnAddrChange))
  207. )
  208. {
  209. m_fPushInitialReplication = FALSE;
  210. m_fPushReplOnAddrChange = FALSE;
  211. err = ERROR_SUCCESS;
  212. }
  213. // pull stuff
  214. if (
  215. ((HKEY) rkPull == NULL) ||
  216. (err = rkPull.QueryValue(WINSCNF_INIT_TIME_RPL_NM, (DWORD &) m_fPullInitialReplication)) ||
  217. (err = rkPull.QueryValue(WINSCNF_RETRY_COUNT_NM, m_dwPullRetryCount))
  218. )
  219. {
  220. m_fPullInitialReplication = TRUE;
  221. m_dwPullRetryCount = WINSCNF_MAX_COMM_RETRIES;
  222. err = ERROR_SUCCESS;
  223. }
  224. // get the backup path.
  225. if (err = rk.QueryValue(WINSCNF_BACKUP_DIR_PATH_NM, m_strBackupPath))
  226. {
  227. m_strBackupPath = "";
  228. err = ERROR_SUCCESS;
  229. }
  230. // get the defaults for push update count and pull time interval.
  231. if (
  232. ((HKEY) rkPushDefaults == NULL) ||
  233. ((HKEY) rkPullDefaults == NULL) ||
  234. (err = rkPushDefaults.QueryValue(WINSCNF_UPDATE_COUNT_NM, m_dwPushUpdateCount)) ||
  235. (err = rkPullDefaults.QueryValue(WINSCNF_RPL_INTERVAL_NM, m_dwPullTimeInterval))
  236. )
  237. {
  238. // set defaults
  239. m_dwPushUpdateCount = 0;
  240. m_dwPullTimeInterval = 1800;
  241. err = ERROR_SUCCESS;
  242. }
  243. // get the default pull sptime
  244. err = rkPullDefaults.QueryValue(WINSCNF_SP_TIME_NM, strDefaultPullSpTime);
  245. if (err == ERROR_FILE_NOT_FOUND)
  246. {
  247. m_dwPullSpTime = 0;
  248. }
  249. else
  250. {
  251. // a string was loaded so
  252. // conver the string into a DWORD which is what we use
  253. CIntlTime timeDefault(strDefaultPullSpTime);
  254. m_dwPullSpTime = (DWORD) timeDefault;
  255. }
  256. // query for the multicast stuff
  257. err = ERROR_FILE_NOT_FOUND;
  258. if(
  259. ((HKEY) rk == NULL) ||
  260. (err = rk.QueryValue(WINSCNF_USE_SELF_FND_PNRS_NM, (DWORD &) m_fUseSelfFndPnrs)) ||
  261. (err = rk.QueryValue(WINSCNF_MCAST_INTVL_NM, (DWORD &) m_dwMulticastInt)) ||
  262. (err = rk.QueryValue(WINSCNF_MCAST_TTL_NM, (DWORD &) m_dwMcastTtl))
  263. )
  264. {
  265. // set the default values
  266. if (err == ERROR_FILE_NOT_FOUND)
  267. {
  268. m_fUseSelfFndPnrs = FALSE;
  269. m_dwMulticastInt = WINSCNF_DEF_MCAST_INTVL;
  270. m_dwMcastTtl = WINSCNF_DEF_MCAST_TTL;
  271. err = ERROR_SUCCESS;
  272. }
  273. else
  274. {
  275. return err;
  276. }
  277. }
  278. // query for the global persistence stuff
  279. err = ERROR_FILE_NOT_FOUND;
  280. if(
  281. ((HKEY) rkPush == NULL) ||
  282. ((HKEY) rkPull == NULL) ||
  283. (err = rkPush.QueryValue(lpstrPersistence, (DWORD &) m_dwPushPersistence)) ||
  284. (err = rkPull.QueryValue(lpstrPersistence, (DWORD &) m_dwPullPersistence))
  285. )
  286. {
  287. // set the default values
  288. if (err == ERROR_FILE_NOT_FOUND)
  289. {
  290. m_dwPushPersistence = 1;
  291. m_dwPullPersistence = 1;
  292. err = ERROR_SUCCESS;
  293. }
  294. else
  295. {
  296. return err;
  297. }
  298. }
  299. // query for the burst handling stuff
  300. err = ERROR_FILE_NOT_FOUND;
  301. if(
  302. ((HKEY) rk == NULL) ||
  303. (err = rk.QueryValue(WINSCNF_BURST_HANDLING_NM, (DWORD &) m_fBurstHandling)) ||
  304. (err = rk.QueryValue(WINSCNF_BURST_QUE_SIZE_NM, (DWORD &) m_dwBurstQueSize))
  305. )
  306. {
  307. // set the default values
  308. if (err == ERROR_FILE_NOT_FOUND)
  309. {
  310. // SP4 and greater burst handling is turned on by default
  311. // RamC changed m_dwServicePack == 4 check to
  312. // m_dwServicePack >= 4
  313. if ( (m_dwMajorVersion == 4 && m_dwServicePack >= 4) ||
  314. (m_dwMajorVersion >= 5) )
  315. {
  316. m_fBurstHandling = TRUE;
  317. }
  318. else
  319. {
  320. m_fBurstHandling = FALSE;
  321. }
  322. m_dwBurstQueSize = WINS_QUEUE_HWM;
  323. err = ERROR_SUCCESS;
  324. }
  325. else
  326. {
  327. return err;
  328. }
  329. }
  330. // read in the db name
  331. CString strDb;
  332. if (err = rk.QueryValue(WINSCNF_DB_FILE_NM, strDb))
  333. {
  334. m_strDbPath = _T("%windir%\\system32\\wins");
  335. }
  336. else
  337. {
  338. // take off the trailing filename
  339. int nLastBack = strDb.ReverseFind('\\');
  340. if (nLastBack != -1)
  341. {
  342. m_strDbPath = strDb.Left(nLastBack);
  343. m_strDbName = strDb.Right(strDb.GetLength() - nLastBack - 1);
  344. }
  345. }
  346. // consistency checking
  347. RegKey rkCC;
  348. err = rkCC.Open(HKEY_LOCAL_MACHINE, lpstrCCRoot, KEY_READ, m_strNetBIOSName);
  349. if (err == ERROR_FILE_NOT_FOUND)
  350. {
  351. // not there, use defaults
  352. m_fPeriodicConsistencyCheck = FALSE;
  353. m_fCCUseRplPnrs = FALSE;
  354. m_dwMaxRecsAtATime = WINSCNF_CC_DEF_RECS_AAT;
  355. m_dwCCTimeInterval = WINSCNF_CC_DEF_INTERVAL;
  356. CIntlTime timeDefault(_T("02:00:00"));
  357. m_itmCCStartTime = timeDefault;
  358. }
  359. else
  360. {
  361. m_fPeriodicConsistencyCheck = TRUE;
  362. CString strSpTime;
  363. // read in the values
  364. if (err = rkCC.QueryValue(WINSCNF_CC_MAX_RECS_AAT_NM, m_dwMaxRecsAtATime))
  365. {
  366. m_dwMaxRecsAtATime = WINSCNF_CC_DEF_RECS_AAT;
  367. }
  368. if (err = rkCC.QueryValue(WINSCNF_CC_USE_RPL_PNRS_NM, (DWORD &) m_fCCUseRplPnrs))
  369. {
  370. m_fCCUseRplPnrs = FALSE;
  371. }
  372. if (err = rkCC.QueryValue(WINSCNF_SP_TIME_NM, strSpTime))
  373. {
  374. strSpTime = _T("02:00:00");
  375. }
  376. CIntlTime time(strSpTime);
  377. m_itmCCStartTime = time;
  378. if (err = rkCC.QueryValue(WINSCNF_CC_INTVL_NM, m_dwCCTimeInterval))
  379. {
  380. m_dwCCTimeInterval = WINSCNF_CC_DEF_INTERVAL;
  381. }
  382. }
  383. GetAdminStatus();
  384. // Now read the "live" values and override the values read from the registry
  385. if (hBinding)
  386. {
  387. WINSINTF_RESULTS_T Results;
  388. Results.WinsStat.NoOfPnrs = 0;
  389. Results.WinsStat.pRplPnrs = NULL;
  390. Results.NoOfWorkerThds = 1;
  391. #ifdef WINS_CLIENT_APIS
  392. err = ::WinsStatus(hBinding, WINSINTF_E_CONFIG, &Results);
  393. #else
  394. err = ::WinsStatus(WINSINTF_E_CONFIG, &Results);
  395. #endif WINS_CLIENT_APIS
  396. m_dwRefreshInterval = Results.RefreshInterval;
  397. m_dwTombstoneInterval = Results.TombstoneInterval;
  398. m_dwTombstoneTimeout = Results.TombstoneTimeout;
  399. m_dwVerifyInterval = Results.VerifyInterval;
  400. m_dwNumberOfWorkerThreads = Results.NoOfWorkerThds;
  401. if (err != ERROR_SUCCESS)
  402. {
  403. return err;
  404. }
  405. }
  406. return hr;
  407. }
  408. /*---------------------------------------------------------------------------
  409. CConfiguration::Store()
  410. Stores back the values to the registry
  411. ---------------------------------------------------------------------------*/
  412. HRESULT
  413. CConfiguration::Store()
  414. {
  415. HRESULT hr = hrOK;
  416. DWORD err;
  417. RegKey rk;
  418. RegKey rkPull;
  419. RegKey rkPush;
  420. RegKey rkUser;
  421. RegKey rkPullDefaults;
  422. RegKey rkPushDefaults;
  423. RegKey rkCC;
  424. err = rk.Create(HKEY_LOCAL_MACHINE,(LPCTSTR) lpstrRoot, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,NULL, m_strNetBIOSName);
  425. err = rkPull.Create(HKEY_LOCAL_MACHINE, (LPCTSTR)lpstrPullRoot, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,NULL, m_strNetBIOSName);
  426. err= rkPush.Create(HKEY_LOCAL_MACHINE, (LPCTSTR)lpstrPushRoot, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,NULL, m_strNetBIOSName);
  427. err = rkPullDefaults.Create(HKEY_LOCAL_MACHINE, (LPCTSTR)lpstrPullDefaultsRoot, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,NULL, m_strNetBIOSName);
  428. err = rkPushDefaults.Create(HKEY_LOCAL_MACHINE, (LPCTSTR)lpstrPushDefaultsRoot, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS,NULL, m_strNetBIOSName);
  429. if (err)
  430. return err;
  431. if(
  432. (err = rk.SetValue(WINSCNF_REFRESH_INTVL_NM, m_dwRefreshInterval)) ||
  433. (err = rk.SetValue(WINSCNF_DO_BACKUP_ON_TERM_NM, (DWORD &) m_fBackupOnTermination)) ||
  434. (err = rk.SetValue(WINSCNF_TOMBSTONE_INTVL_NM, m_dwTombstoneInterval)) ||
  435. (err = rk.SetValue(WINSCNF_TOMBSTONE_TMOUT_NM, m_dwTombstoneTimeout)) ||
  436. (err = rk.SetValue(WINSCNF_VERIFY_INTVL_NM, m_dwVerifyInterval)) ||
  437. (err = rk.SetValue(WINSCNF_INIT_VERSNO_VAL_LW_NM, m_dwVersCountStart_LowWord)) ||
  438. (err = rk.SetValue(WINSCNF_INIT_VERSNO_VAL_HW_NM, m_dwVersCountStart_HighWord)) ||
  439. (err = rk.SetValue(WINSCNF_RPL_ONLY_W_CNF_PNRS_NM, (DWORD &) m_fRplOnlyWithPartners)) ||
  440. (err = rk.SetValue(WINSCNF_LOG_DETAILED_EVTS_NM, (DWORD &) m_fLogDetailedEvents)) ||
  441. (err = rk.SetValue(WINSCNF_LOG_FLAG_NM, (DWORD &) m_fLoggingOn)) ||
  442. (err = rk.SetValue(WINSCNF_MIGRATION_ON_NM, (DWORD &) m_fMigrateOn)) ||
  443. (err = rkPush.SetValue(WINSCNF_INIT_TIME_RPL_NM, (DWORD &) m_fPushInitialReplication)) ||
  444. (err = rkPush.SetValue(WINSCNF_ADDCHG_TRIGGER_NM, (DWORD &) m_fPushReplOnAddrChange)) ||
  445. (err = rkPush.SetValue(lpstrPersistence, m_dwPushPersistence)) ||
  446. (err = rkPull.SetValue(WINSCNF_INIT_TIME_RPL_NM, (DWORD &) m_fPullInitialReplication)) ||
  447. (err = rkPull.SetValue(WINSCNF_RETRY_COUNT_NM, m_dwPullRetryCount)) ||
  448. (err = rkPull.SetValue(lpstrPersistence, m_dwPullPersistence)) ||
  449. (err = rkPushDefaults.SetValue(WINSCNF_UPDATE_COUNT_NM, m_dwPushUpdateCount)) ||
  450. (err = rkPullDefaults.SetValue(WINSCNF_RPL_INTERVAL_NM, m_dwPullTimeInterval)) ||
  451. (err = rk.SetValue(WINSCNF_USE_SELF_FND_PNRS_NM, (DWORD &) m_fUseSelfFndPnrs)) ||
  452. (err = rk.SetValue(WINSCNF_MCAST_INTVL_NM, m_dwMulticastInt)) ||
  453. (err = rk.SetValue(WINSCNF_MCAST_TTL_NM, m_dwMcastTtl)) ||
  454. (err = rk.SetValue(WINSCNF_BURST_HANDLING_NM, (DWORD &) m_fBurstHandling)) ||
  455. (err = rk.SetValue(WINSCNF_BURST_QUE_SIZE_NM, m_dwBurstQueSize))
  456. )
  457. {
  458. return err;
  459. }
  460. if (m_dwPullSpTime)
  461. {
  462. CIntlTime timeDefaultPullSpTime(m_dwPullSpTime);
  463. err = rkPullDefaults.SetValue(WINSCNF_SP_TIME_NM, timeDefaultPullSpTime.IntlFormat(CIntlTime::TFRQ_MILITARY_TIME));
  464. }
  465. else
  466. {
  467. rkPullDefaults.DeleteValue(WINSCNF_SP_TIME_NM);
  468. }
  469. // Consistency checking
  470. if (m_fPeriodicConsistencyCheck)
  471. {
  472. err = rkCC.Open(HKEY_LOCAL_MACHINE, lpstrCCRoot, KEY_ALL_ACCESS, m_strNetBIOSName);
  473. if (err == ERROR_FILE_NOT_FOUND)
  474. {
  475. // isn't there, need to create
  476. err = rkCC.Create(HKEY_LOCAL_MACHINE, lpstrCCRoot, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, m_strNetBIOSName);
  477. if (err)
  478. return err;
  479. }
  480. // now update values
  481. if (
  482. (err = rkCC.SetValue(WINSCNF_CC_MAX_RECS_AAT_NM, m_dwMaxRecsAtATime)) ||
  483. (err = rkCC.SetValue(WINSCNF_CC_USE_RPL_PNRS_NM, (DWORD &) m_fCCUseRplPnrs)) ||
  484. (err = rkCC.SetValue(WINSCNF_SP_TIME_NM, m_itmCCStartTime.IntlFormat(CIntlTime::TFRQ_MILITARY_TIME))) ||
  485. (err = rkCC.SetValue(WINSCNF_CC_INTVL_NM, m_dwCCTimeInterval))
  486. )
  487. {
  488. return err;
  489. }
  490. }
  491. else
  492. {
  493. err = rkCC.Open(HKEY_LOCAL_MACHINE, lpstrCCRoot, KEY_ALL_ACCESS, m_strNetBIOSName);
  494. if (err == ERROR_FILE_NOT_FOUND)
  495. {
  496. // we're done. to turn this off, the key needs to be deleted
  497. }
  498. else
  499. {
  500. // remove the key
  501. rkCC.Close();
  502. err = rk.RecurseDeleteKey(lpstrCC);
  503. if (err)
  504. {
  505. return err;
  506. }
  507. }
  508. }
  509. //
  510. // Database path
  511. //
  512. CString strDbFull;
  513. strDbFull = m_strDbPath + _T("\\") + m_strDbName;
  514. if ( (err = rk.SetValue(WINSCNF_DB_FILE_NM, strDbFull, TRUE)) ||
  515. (err = rk.SetValue(WINSCNF_LOG_FILE_PATH_NM, m_strDbPath, TRUE)) )
  516. {
  517. return err;
  518. }
  519. //
  520. // NT 3.51 this key was REG_SZ, NT4 and above it is REG_EXPAND_SZ
  521. //
  522. BOOL fRegExpand = (m_dwMajorVersion < 4) ? FALSE : TRUE;
  523. err = rk.SetValue(WINSCNF_BACKUP_DIR_PATH_NM, m_strBackupPath, fRegExpand);
  524. if (err)
  525. return err;
  526. return ERROR_SUCCESS;
  527. }
  528. /*---------------------------------------------------------------------------
  529. CConfiguration::GetSystemVersion()
  530. Reads the windows system version information
  531. ---------------------------------------------------------------------------*/
  532. DWORD
  533. CConfiguration::GetSystemVersion()
  534. {
  535. CString strBuf, strValue;
  536. RegKey rk;
  537. int nPos, nLength;
  538. DWORD err = ERROR_SUCCESS;
  539. err = rk.Open(HKEY_LOCAL_MACHINE, (LPCTSTR) lpstrCurrentVersion, KEY_READ, m_strNetBIOSName);
  540. if (err)
  541. return err;
  542. // read the windows version and convert into our internal variables
  543. err = rk.QueryValue(lpstrWinVersion, strBuf.GetBuffer(256), 256, FALSE);
  544. strBuf.ReleaseBuffer();
  545. if (err)
  546. return err;
  547. nPos = strBuf.Find('.');
  548. nLength = strBuf.GetLength();
  549. strValue = strBuf.Left(nPos);
  550. m_dwMajorVersion = _ttoi(strValue);
  551. strValue = strBuf.Right(nLength - nPos - 1);
  552. m_dwMinorVersion = _ttoi(strValue);
  553. // now get the current build #
  554. err = rk.QueryValue(lpstrBuildNumber, strBuf.GetBuffer(256), 256, FALSE);
  555. strBuf.ReleaseBuffer();
  556. if (err)
  557. return err;
  558. m_dwBuildNumber = _ttoi(strBuf);
  559. // and finally the SP #
  560. err = rk.QueryValue(lpstrSPVersion, strBuf.GetBuffer(256), 256, FALSE);
  561. strBuf.ReleaseBuffer();
  562. if (err == ERROR_FILE_NOT_FOUND)
  563. {
  564. // this may not be there if a SP hasn't been installed.
  565. return ERROR_SUCCESS;
  566. }
  567. else
  568. if (err)
  569. {
  570. return err;
  571. }
  572. CString strServicePack = _T("Service Pack ");
  573. nLength = strBuf.GetLength();
  574. strValue = strBuf.Right(nLength - strServicePack.GetLength());
  575. m_dwServicePack = _ttoi(strValue);
  576. return err;
  577. }
  578. void
  579. CConfiguration::GetAdminStatus()
  580. {
  581. DWORD err = 0, dwDummy = 0;
  582. RegKey rk;
  583. err = rk.Open(HKEY_LOCAL_MACHINE, (LPCTSTR) lpstrRoot, KEY_ALL_ACCESS, m_strNetBIOSName);
  584. if (!err)
  585. {
  586. m_fIsAdmin = TRUE;
  587. }
  588. }
  589. BOOL
  590. CConfiguration::IsNt5()
  591. {
  592. if (m_dwMajorVersion >= 5)
  593. return TRUE;
  594. else
  595. return FALSE;
  596. }
  597. //
  598. // NT4 didn't support passing back the ownerId when we querried for bunches
  599. // of records. Querrying for a specific record will return the correct
  600. // owner id in all cases. This was fixed in NT5 and back proped into NT4
  601. // SP6.
  602. //
  603. BOOL
  604. CConfiguration::FSupportsOwnerId()
  605. {
  606. // if ( IsNt5() ||
  607. // ( (m_dwMajorVersion == 4) &&
  608. // (m_dwServicePack >= 6) ) )
  609. if ( m_dwMajorVersion >= 5)
  610. {
  611. return TRUE;
  612. }
  613. else
  614. {
  615. return FALSE;
  616. }
  617. }
  618. BOOL
  619. CConfiguration::IsAdmin()
  620. {
  621. return m_fIsAdmin;
  622. }