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.

1101 lines
34 KiB

  1. /**************************************************************************
  2. Copyright (C) 1999 Microsoft Corporation. All Rights Reserved.
  3. MODULE: REGCFG.CPP
  4. PURPOSE: Source module reading/writing PM config sets from the registry
  5. FUNCTIONS:
  6. COMMENTS:
  7. **************************************************************************/
  8. /**************************************************************************
  9. Include Files
  10. **************************************************************************/
  11. #include "pmcfg.h"
  12. #include "keycrypto.h"
  13. // Reg Keys/values that we care about
  14. TCHAR g_szPassportReg[] = TEXT("Software\\Microsoft\\Passport");
  15. TCHAR g_szPassportSites[] = TEXT("Software\\Microsoft\\Passport\\Sites");
  16. TCHAR g_szEncryptionKeyData[] = TEXT("KeyData");
  17. TCHAR g_szInstallDir[] = TEXT("InstallDir");
  18. TCHAR g_szVersion[] = TEXT("Version");
  19. TCHAR g_szTimeWindow[] = TEXT("TimeWindow");
  20. TCHAR g_szForceSignIn[] = TEXT("ForceSignIn");
  21. TCHAR g_szLanguageID[] = TEXT("LanguageID");
  22. TCHAR g_szCoBrandTemplate[] = TEXT("CoBrandTemplate");
  23. TCHAR g_szSiteID[] = TEXT("SiteID");
  24. TCHAR g_szReturnURL[] = TEXT("ReturnURL");
  25. TCHAR g_szTicketDomain[] = TEXT("TicketDomain");
  26. TCHAR g_szTicketPath[] = TEXT("TicketPath");
  27. TCHAR g_szProfileDomain[] = TEXT("ProfileDomain");
  28. TCHAR g_szProfilePath[] = TEXT("ProfilePath");
  29. TCHAR g_szSecureDomain[] = TEXT("SecureDomain");
  30. TCHAR g_szSecurePath[] = TEXT("SecurePath");
  31. TCHAR g_szCurrentKey[] = TEXT("CurrentKey");
  32. TCHAR g_szStandAlone[] = TEXT("StandAlone");
  33. TCHAR g_szDisableCookies[] = TEXT("DisableCookies");
  34. TCHAR g_szDisasterURL[] = TEXT("DisasterURL");
  35. TCHAR g_szHostName[] = TEXT("HostName");
  36. TCHAR g_szHostIP[] = TEXT("HostIP");
  37. /**************************************************************************
  38. WriteRegTestKey
  39. Installs the default test key for the named config set. This is
  40. only called in the case where a new config set key was created in
  41. OpenRegConfigSet.
  42. **************************************************************************/
  43. BOOL
  44. WriteRegTestKey
  45. (
  46. HKEY hkeyConfigKey
  47. )
  48. {
  49. BOOL bReturn;
  50. CKeyCrypto kc;
  51. HKEY hkDataKey = NULL, hkTimeKey = NULL;
  52. TCHAR szKeyNum[2];
  53. DWORD dwKeyVer = 1;
  54. // Try to encrypt it with MAC address
  55. BYTE original[CKeyCrypto::RAWKEY_SIZE];
  56. DATA_BLOB iBlob;
  57. DATA_BLOB oBlob;
  58. iBlob.cbData = sizeof(original);
  59. iBlob.pbData = original;
  60. ZeroMemory(&oBlob, sizeof(oBlob));
  61. memcpy(original, "123456781234567812345678", CKeyCrypto::RAWKEY_SIZE);
  62. if (kc.encryptKey(&iBlob, &oBlob) != S_OK)
  63. {
  64. bReturn = FALSE;
  65. goto Cleanup;
  66. }
  67. // Now add it to registry
  68. lstrcpy(szKeyNum, TEXT("1"));
  69. if(ERROR_SUCCESS != RegCreateKeyEx(hkeyConfigKey,
  70. TEXT("KeyData"),
  71. 0,
  72. TEXT(""),
  73. 0,
  74. KEY_ALL_ACCESS,
  75. NULL,
  76. &hkDataKey,
  77. NULL))
  78. {
  79. bReturn = FALSE;
  80. goto Cleanup;
  81. }
  82. if(ERROR_SUCCESS != RegCreateKeyEx(hkeyConfigKey,
  83. TEXT("KeyTimes"),
  84. 0,
  85. TEXT(""),
  86. 0,
  87. KEY_ALL_ACCESS,
  88. NULL,
  89. &hkTimeKey,
  90. NULL))
  91. {
  92. bReturn = FALSE;
  93. goto Cleanup;
  94. }
  95. if(ERROR_SUCCESS != RegSetValueExA(hkDataKey,
  96. szKeyNum,
  97. 0,
  98. REG_BINARY,
  99. oBlob.pbData,
  100. oBlob.cbData))
  101. {
  102. bReturn = FALSE;
  103. goto Cleanup;
  104. }
  105. if(ERROR_SUCCESS != RegSetValueExA(hkeyConfigKey,
  106. "CurrentKey",
  107. 0,
  108. REG_DWORD,
  109. (LPBYTE)&dwKeyVer,
  110. sizeof(DWORD)))
  111. {
  112. bReturn = FALSE;
  113. goto Cleanup;
  114. }
  115. bReturn = TRUE;
  116. Cleanup:
  117. if (hkDataKey)
  118. RegCloseKey(hkDataKey);
  119. if (hkTimeKey)
  120. RegCloseKey(hkTimeKey);
  121. if (oBlob.pbData)
  122. ::LocalFree(oBlob.pbData);
  123. return bReturn;
  124. }
  125. /**************************************************************************
  126. OpenRegConfigSet
  127. Open and return an HKEY for a named configuration set
  128. current passport manager config set from the registry
  129. **************************************************************************/
  130. HKEY OpenRegConfigSet
  131. (
  132. HKEY hkeyLocalMachine, // Local or remote HKLM
  133. LPTSTR lpszConfigSetName // Name of config set
  134. )
  135. {
  136. HKEY hkeyConfigSets = NULL;
  137. HKEY hkeyConfigSet;
  138. DWORD dwDisp;
  139. //
  140. // Can't create an unnamed config set.
  141. //
  142. if(lpszConfigSetName == NULL ||
  143. lpszConfigSetName[0] == TEXT('\0'))
  144. {
  145. hkeyConfigSet = NULL;
  146. goto Cleanup;
  147. }
  148. if (ERROR_SUCCESS != RegCreateKeyEx(hkeyLocalMachine,
  149. g_szPassportSites,
  150. 0,
  151. TEXT(""),
  152. 0,
  153. KEY_ALL_ACCESS,
  154. NULL,
  155. &hkeyConfigSets,
  156. NULL))
  157. {
  158. hkeyConfigSet = NULL;
  159. goto Cleanup;
  160. }
  161. //
  162. // Create the key if it doesn't exist, otherwise
  163. // open it.
  164. //
  165. if (ERROR_SUCCESS != RegCreateKeyEx(hkeyConfigSets,
  166. lpszConfigSetName,
  167. 0,
  168. TEXT(""),
  169. 0,
  170. KEY_ALL_ACCESS,
  171. NULL,
  172. &hkeyConfigSet,
  173. &dwDisp))
  174. {
  175. hkeyConfigSet = NULL;
  176. goto Cleanup;
  177. }
  178. //
  179. // If we created a new regkey, add encryption keys
  180. //
  181. if(dwDisp == REG_CREATED_NEW_KEY)
  182. {
  183. WriteRegTestKey(hkeyConfigSet);
  184. }
  185. Cleanup:
  186. if(hkeyConfigSets)
  187. RegCloseKey(hkeyConfigSets);
  188. return hkeyConfigSet;
  189. }
  190. /**************************************************************************
  191. ReadRegConfigSet
  192. Read the current passport manager config set from the registry
  193. **************************************************************************/
  194. BOOL ReadRegConfigSet
  195. (
  196. HWND hWndDlg,
  197. LPPMSETTINGS lpPMConfig,
  198. LPTSTR lpszRemoteComputer,
  199. LPTSTR lpszConfigSetName
  200. )
  201. {
  202. BOOL bReturn;
  203. HKEY hkeyPassport = NULL; // Regkey where Passport Setting live
  204. HKEY hkeyConfigSets = NULL;
  205. HKEY hkeyConfig = NULL;
  206. HKEY hklm = NULL;
  207. DWORD dwcbTemp;
  208. DWORD dwType;
  209. TCHAR szText[MAX_RESOURCE];
  210. TCHAR szTitle[MAX_RESOURCE];
  211. // Open the Passport Regkey ( either locally or remotly
  212. if (lpszRemoteComputer && ('\0' != lpszRemoteComputer[0]))
  213. {
  214. //
  215. // Attempt to connect to the HKEY_LOCAL_MACHINE of the remote computer.
  216. // If this fails, assume that the computer doesn't exist or doesn't have
  217. // the registry server running.
  218. //
  219. switch (RegConnectRegistry(lpszRemoteComputer,
  220. HKEY_LOCAL_MACHINE,
  221. &hklm))
  222. {
  223. case ERROR_SUCCESS:
  224. break;
  225. case ERROR_ACCESS_DENIED:
  226. ReportError(hWndDlg, IDS_CONNECTACCESSDENIED);
  227. bReturn = FALSE;
  228. goto Cleanup;
  229. default:
  230. ReportError(hWndDlg, IDS_CONNECTBADNAME);
  231. bReturn = FALSE;
  232. goto Cleanup;
  233. }
  234. }
  235. else
  236. {
  237. hklm = HKEY_LOCAL_MACHINE;
  238. }
  239. // Open the key we want
  240. if (ERROR_SUCCESS != RegOpenKeyEx(hklm,
  241. g_szPassportReg,
  242. 0,
  243. KEY_ALL_ACCESS,
  244. &hkeyPassport))
  245. {
  246. ReportError(hWndDlg, IDS_CONFIGREAD_ERROR);
  247. bReturn = FALSE;
  248. goto Cleanup;
  249. }
  250. if(lpszConfigSetName && lpszConfigSetName[0] != TEXT('\0'))
  251. {
  252. hkeyConfig = OpenRegConfigSet(hklm, lpszConfigSetName);
  253. if(hkeyConfig == NULL)
  254. {
  255. ReportError(hWndDlg, IDS_CONFIGREAD_ERROR);
  256. bReturn = FALSE;
  257. goto Cleanup;
  258. }
  259. }
  260. else
  261. {
  262. hkeyConfig = hkeyPassport;
  263. }
  264. // The Install dir and Version number go into globals, because they are read
  265. // only values that must come from the target machine's registry.
  266. // Read the Install Dir.
  267. dwcbTemp = MAX_PATH;
  268. dwType = REG_SZ;
  269. g_szInstallPath[0] = '\0'; // Default value
  270. RegQueryValueEx(hkeyPassport,
  271. g_szInstallDir,
  272. NULL,
  273. &dwType,
  274. (LPBYTE)g_szInstallPath,
  275. &dwcbTemp);
  276. // Read the version Number
  277. dwcbTemp = MAX_REGISTRY_STRING;
  278. dwType = REG_SZ;
  279. g_szPMVersion[0] = '\0'; // Default value
  280. RegQueryValueEx(hkeyPassport,
  281. g_szVersion,
  282. NULL,
  283. &dwType,
  284. (LPBYTE)&g_szPMVersion,
  285. &dwcbTemp);
  286. // The Remaining settings are read/write and get put into a PMSETTINGS struct
  287. // Read the Time Window Number
  288. dwcbTemp = sizeof(DWORD);
  289. dwType = REG_DWORD;
  290. lpPMConfig->dwTimeWindow = DEFAULT_TIME_WINDOW;
  291. RegQueryValueEx(hkeyConfig,
  292. g_szTimeWindow,
  293. NULL,
  294. &dwType,
  295. (LPBYTE)&lpPMConfig->dwTimeWindow,
  296. &dwcbTemp);
  297. // Read the value for Forced Signin
  298. dwcbTemp = sizeof(DWORD);
  299. dwType = REG_DWORD;
  300. lpPMConfig->dwForceSignIn = 0; // Don't force a signin by default
  301. RegQueryValueEx(hkeyConfig,
  302. g_szForceSignIn,
  303. NULL,
  304. &dwType,
  305. (LPBYTE)&lpPMConfig->dwForceSignIn,
  306. &dwcbTemp);
  307. // Read the default language ID
  308. dwcbTemp = sizeof(DWORD);
  309. dwType = REG_DWORD;
  310. lpPMConfig->dwLanguageID = DEFAULT_LANGID; // english
  311. RegQueryValueEx(hkeyConfig,
  312. g_szLanguageID,
  313. NULL,
  314. &dwType,
  315. (LPBYTE)&lpPMConfig->dwLanguageID,
  316. &dwcbTemp);
  317. // Get the co-branding template
  318. dwcbTemp = lpPMConfig->cbCoBrandTemplate;
  319. dwType = REG_SZ;
  320. lpPMConfig->szCoBrandTemplate[0] = '\0'; // Default value
  321. RegQueryValueEx(hkeyConfig,
  322. g_szCoBrandTemplate,
  323. NULL,
  324. &dwType,
  325. (LPBYTE)lpPMConfig->szCoBrandTemplate,
  326. &dwcbTemp);
  327. // Get the SiteID
  328. dwcbTemp = sizeof(DWORD);
  329. dwType = REG_DWORD;
  330. lpPMConfig->dwSiteID = 1; // Default Site ID
  331. RegQueryValueEx(hkeyConfig,
  332. g_szSiteID,
  333. NULL,
  334. &dwType,
  335. (LPBYTE)&lpPMConfig->dwSiteID,
  336. &dwcbTemp);
  337. // Get the return URL template
  338. dwcbTemp = lpPMConfig->cbReturnURL;
  339. dwType = REG_SZ;
  340. lpPMConfig->szReturnURL[0] = '\0'; // Set a default for the current value
  341. RegQueryValueEx(hkeyConfig,
  342. g_szReturnURL,
  343. NULL,
  344. &dwType,
  345. (LPBYTE)lpPMConfig->szReturnURL,
  346. &dwcbTemp);
  347. // Get the ticket cookie domain
  348. dwcbTemp = lpPMConfig->cbTicketDomain;
  349. dwType = REG_SZ;
  350. lpPMConfig->szTicketDomain[0] = '\0'; // Set a default for the current value
  351. RegQueryValueEx(hkeyConfig,
  352. g_szTicketDomain,
  353. NULL,
  354. &dwType,
  355. (LPBYTE)lpPMConfig->szTicketDomain,
  356. &dwcbTemp);
  357. // Get the ticket cookie path
  358. dwcbTemp = lpPMConfig->cbTicketPath;
  359. dwType = REG_SZ;
  360. lpPMConfig->szTicketPath[0] = '\0'; // Set a default for the current value
  361. RegQueryValueEx(hkeyConfig,
  362. g_szTicketPath,
  363. NULL,
  364. &dwType,
  365. (LPBYTE)lpPMConfig->szTicketPath,
  366. &dwcbTemp);
  367. // Get the profile cookie domain
  368. dwcbTemp = lpPMConfig->cbProfileDomain;
  369. dwType = REG_SZ;
  370. lpPMConfig->szProfileDomain[0] = '\0'; // Set a default for the current value
  371. RegQueryValueEx(hkeyConfig,
  372. g_szProfileDomain,
  373. NULL,
  374. &dwType,
  375. (LPBYTE)lpPMConfig->szProfileDomain,
  376. &dwcbTemp);
  377. // Get the profile cookie path
  378. dwcbTemp = lpPMConfig->cbProfilePath;
  379. dwType = REG_SZ;
  380. lpPMConfig->szProfilePath[0] = '\0'; // Set a default for the current value
  381. RegQueryValueEx(hkeyConfig,
  382. g_szProfilePath,
  383. NULL,
  384. &dwType,
  385. (LPBYTE)lpPMConfig->szProfilePath,
  386. &dwcbTemp);
  387. // Get the secure cookie domain
  388. dwcbTemp = lpPMConfig->cbSecureDomain;
  389. dwType = REG_SZ;
  390. lpPMConfig->szSecureDomain[0] = '\0'; // Set a default for the current value
  391. RegQueryValueEx(hkeyConfig,
  392. g_szSecureDomain,
  393. NULL,
  394. &dwType,
  395. (LPBYTE)lpPMConfig->szSecureDomain,
  396. &dwcbTemp);
  397. // Get the secure cookie path
  398. dwcbTemp = lpPMConfig->cbSecurePath;
  399. dwType = REG_SZ;
  400. lpPMConfig->szSecurePath[0] = '\0'; // Set a default for the current value
  401. RegQueryValueEx(hkeyConfig,
  402. g_szSecurePath,
  403. NULL,
  404. &dwType,
  405. (LPBYTE)lpPMConfig->szSecurePath,
  406. &dwcbTemp);
  407. // Get the Disaster URL
  408. dwcbTemp = lpPMConfig->cbDisasterURL;
  409. dwType = REG_SZ;
  410. lpPMConfig->szDisasterURL[0] = '\0'; // Set a default for the current value
  411. RegQueryValueEx(hkeyConfig,
  412. g_szDisasterURL,
  413. NULL,
  414. &dwType,
  415. (LPBYTE)lpPMConfig->szDisasterURL,
  416. &dwcbTemp);
  417. // Get Standalone mode setting
  418. dwcbTemp = sizeof(DWORD);
  419. dwType = REG_DWORD;
  420. lpPMConfig->dwStandAlone = 0; // NOT standalone by default
  421. RegQueryValueEx(hkeyConfig,
  422. g_szStandAlone,
  423. NULL,
  424. &dwType,
  425. (LPBYTE)&lpPMConfig->dwStandAlone,
  426. &dwcbTemp);
  427. // Get DisableCookies mode setting
  428. dwcbTemp = sizeof(DWORD);
  429. dwType = REG_DWORD;
  430. lpPMConfig->dwDisableCookies = 0; // Cookies ENABLED by default
  431. RegQueryValueEx(hkeyConfig,
  432. g_szDisableCookies,
  433. NULL,
  434. &dwType,
  435. (LPBYTE)&lpPMConfig->dwDisableCookies,
  436. &dwcbTemp);
  437. #ifdef DO_KEYSTUFF
  438. // Get the current encryption key
  439. dwcbTemp = sizeof(DWORD);
  440. dwType = REG_DWORD;
  441. lpPMConfig->dwCurrentKey = 1;
  442. RegQueryValueEx(hkeyConfig,
  443. g_szCurrentKey,
  444. NULL,
  445. &dwType,
  446. (LPBYTE)&lpPMConfig->dwCurrentKey,
  447. &dwcbTemp);
  448. #endif
  449. // For these next two, since they're required for named configs, we need
  450. // to check for too much data and truncate it.
  451. // Get the Host Name
  452. dwcbTemp = lpPMConfig->cbHostName;
  453. dwType = REG_SZ;
  454. lpPMConfig->szHostName[0] = '\0'; // Set a default for the current value
  455. if(ERROR_MORE_DATA == RegQueryValueEx(hkeyConfig,
  456. g_szHostName,
  457. NULL,
  458. &dwType,
  459. (LPBYTE)lpPMConfig->szHostName,
  460. &dwcbTemp))
  461. {
  462. LPBYTE pb = (LPBYTE)malloc(dwcbTemp);
  463. if(pb)
  464. {
  465. RegQueryValueEx(hkeyConfig,
  466. g_szHostName,
  467. NULL,
  468. &dwType,
  469. pb,
  470. &dwcbTemp);
  471. memcpy(lpPMConfig->szHostName, pb, lpPMConfig->cbHostName);
  472. free(pb);
  473. ReportError(hWndDlg, IDS_HOSTNAMETRUNC_WARN);
  474. }
  475. }
  476. // Get the Host IP
  477. dwcbTemp = lpPMConfig->cbHostIP;
  478. dwType = REG_SZ;
  479. lpPMConfig->szHostIP[0] = '\0'; // Set a default for the current value
  480. if(ERROR_MORE_DATA == RegQueryValueEx(hkeyConfig,
  481. g_szHostIP,
  482. NULL,
  483. &dwType,
  484. (LPBYTE)lpPMConfig->szHostIP,
  485. &dwcbTemp))
  486. {
  487. LPBYTE pb = (LPBYTE)malloc(dwcbTemp);
  488. if(pb)
  489. {
  490. RegQueryValueEx(hkeyConfig,
  491. g_szHostIP,
  492. NULL,
  493. &dwType,
  494. pb,
  495. &dwcbTemp);
  496. memcpy(lpPMConfig->szHostIP, pb, lpPMConfig->cbHostIP);
  497. free(pb);
  498. ReportError(hWndDlg, IDS_HOSTIPTRUNC_WARN);
  499. }
  500. }
  501. // If we got empty strings for HostName or
  502. // HostIP, and we have a named config it
  503. // means someone's been mucking with
  504. // the registry. Give them a warning and
  505. // return FALSE.
  506. if(lpszConfigSetName && lpszConfigSetName[0] &&
  507. (lpPMConfig->szHostName[0] == TEXT('\0') ||
  508. lpPMConfig->szHostIP[0] == TEXT('\0')))
  509. {
  510. ReportError(hWndDlg, IDS_CONFIGREAD_ERROR);
  511. bReturn = FALSE;
  512. goto Cleanup;
  513. }
  514. bReturn = TRUE;
  515. Cleanup:
  516. if (hkeyConfig && hkeyConfig != hkeyPassport)
  517. RegCloseKey(hkeyConfig);
  518. if (hkeyPassport)
  519. RegCloseKey(hkeyPassport);
  520. if (hkeyConfigSets)
  521. RegCloseKey(hkeyConfigSets);
  522. if (hklm && hklm != HKEY_LOCAL_MACHINE)
  523. RegCloseKey(hklm);
  524. return bReturn;
  525. }
  526. /**************************************************************************
  527. WriteRegConfigSet
  528. Write the current passport manager config set from the registry
  529. **************************************************************************/
  530. BOOL WriteRegConfigSet
  531. (
  532. HWND hWndDlg,
  533. LPPMSETTINGS lpPMConfig,
  534. LPTSTR lpszRemoteComputer,
  535. LPTSTR lpszConfigSetName
  536. )
  537. {
  538. BOOL bReturn;
  539. HKEY hkeyPassport = NULL; // Regkey where Passport Setting live
  540. HKEY hkeyConfigSets = NULL;
  541. HKEY hklm = NULL;
  542. // Open the Passport Regkey ( either locally or remotly
  543. if (lpszRemoteComputer && ('\0' != lpszRemoteComputer[0]))
  544. {
  545. //
  546. // Attempt to connect to the HKEY_LOCAL_MACHINE of the remote computer.
  547. // If this fails, assume that the computer doesn't exist or doesn't have
  548. // the registry server running.
  549. //
  550. switch (RegConnectRegistry(lpszRemoteComputer,
  551. HKEY_LOCAL_MACHINE,
  552. &hklm))
  553. {
  554. case ERROR_SUCCESS:
  555. break;
  556. case ERROR_ACCESS_DENIED:
  557. ReportError(hWndDlg, IDS_CONNECTACCESSDENIED);
  558. bReturn = FALSE;
  559. goto Cleanup;
  560. default:
  561. ReportError(hWndDlg, IDS_CONNECTBADNAME);
  562. bReturn = FALSE;
  563. goto Cleanup;
  564. }
  565. }
  566. else
  567. {
  568. hklm = HKEY_LOCAL_MACHINE;
  569. }
  570. // Open the key we want
  571. if(lpszConfigSetName && lpszConfigSetName[0] != TEXT('\0'))
  572. {
  573. hkeyPassport = OpenRegConfigSet(hklm, lpszConfigSetName);
  574. if(hkeyPassport == NULL)
  575. {
  576. ReportError(hWndDlg, IDS_CONFIGREAD_ERROR);
  577. bReturn = FALSE;
  578. goto Cleanup;
  579. }
  580. }
  581. else
  582. {
  583. if (ERROR_SUCCESS != RegOpenKeyEx(hklm,
  584. g_szPassportReg,
  585. 0,
  586. KEY_ALL_ACCESS,
  587. &hkeyPassport))
  588. {
  589. ReportError(hWndDlg, IDS_CONFIGREAD_ERROR);
  590. bReturn = FALSE;
  591. goto Cleanup;
  592. }
  593. }
  594. // Write the Time Window Number
  595. RegSetValueEx(hkeyPassport,
  596. g_szTimeWindow,
  597. NULL,
  598. REG_DWORD,
  599. (LPBYTE)&lpPMConfig->dwTimeWindow,
  600. sizeof(DWORD));
  601. // Write the value for Forced Signin
  602. RegSetValueEx(hkeyPassport,
  603. g_szForceSignIn,
  604. NULL,
  605. REG_DWORD,
  606. (LPBYTE)&lpPMConfig->dwForceSignIn,
  607. sizeof(DWORD));
  608. // Write the default language ID
  609. RegSetValueEx(hkeyPassport,
  610. g_szLanguageID,
  611. NULL,
  612. REG_DWORD,
  613. (LPBYTE)&lpPMConfig->dwLanguageID,
  614. sizeof(DWORD));
  615. // Write the co-branding template
  616. RegSetValueEx(hkeyPassport,
  617. g_szCoBrandTemplate,
  618. NULL,
  619. REG_SZ,
  620. (LPBYTE)lpPMConfig->szCoBrandTemplate,
  621. lstrlen(lpPMConfig->szCoBrandTemplate) + 1);
  622. // Write the SiteID
  623. RegSetValueEx(hkeyPassport,
  624. g_szSiteID,
  625. NULL,
  626. REG_DWORD,
  627. (LPBYTE)&lpPMConfig->dwSiteID,
  628. sizeof(DWORD));
  629. // Write the return URL template
  630. RegSetValueEx(hkeyPassport,
  631. g_szReturnURL,
  632. NULL,
  633. REG_SZ,
  634. (LPBYTE)lpPMConfig->szReturnURL,
  635. lstrlen(lpPMConfig->szReturnURL) + 1);
  636. // Write the ticket cookie domain
  637. RegSetValueEx(hkeyPassport,
  638. g_szTicketDomain,
  639. NULL,
  640. REG_SZ,
  641. (LPBYTE)lpPMConfig->szTicketDomain,
  642. lstrlen(lpPMConfig->szTicketDomain) + 1);
  643. // Write the ticket cookie path
  644. RegSetValueEx(hkeyPassport,
  645. g_szTicketPath,
  646. NULL,
  647. REG_SZ,
  648. (LPBYTE)lpPMConfig->szTicketPath,
  649. lstrlen(lpPMConfig->szTicketPath) + 1);
  650. // Write the profile cookie domain
  651. RegSetValueEx(hkeyPassport,
  652. g_szProfileDomain,
  653. NULL,
  654. REG_SZ,
  655. (LPBYTE)lpPMConfig->szProfileDomain,
  656. lstrlen(lpPMConfig->szProfileDomain) + 1);
  657. // Write the profile cookie path
  658. RegSetValueEx(hkeyPassport,
  659. g_szProfilePath,
  660. NULL,
  661. REG_SZ,
  662. (LPBYTE)lpPMConfig->szProfilePath,
  663. lstrlen(lpPMConfig->szProfilePath) + 1);
  664. // Write the secure cookie domain
  665. RegSetValueEx(hkeyPassport,
  666. g_szSecureDomain,
  667. NULL,
  668. REG_SZ,
  669. (LPBYTE)lpPMConfig->szSecureDomain,
  670. lstrlen(lpPMConfig->szSecureDomain) + 1);
  671. // Write the secure cookie path
  672. RegSetValueEx(hkeyPassport,
  673. g_szSecurePath,
  674. NULL,
  675. REG_SZ,
  676. (LPBYTE)lpPMConfig->szSecurePath,
  677. lstrlen(lpPMConfig->szSecurePath) + 1);
  678. // Write the DisasterURL
  679. RegSetValueEx(hkeyPassport,
  680. g_szDisasterURL,
  681. NULL,
  682. REG_SZ,
  683. (LPBYTE)lpPMConfig->szDisasterURL,
  684. lstrlen(lpPMConfig->szDisasterURL) + 1);
  685. // Write Standalone mode setting
  686. RegSetValueEx(hkeyPassport,
  687. g_szStandAlone,
  688. NULL,
  689. REG_DWORD,
  690. (LPBYTE)&lpPMConfig->dwStandAlone,
  691. sizeof(DWORD));
  692. // Write DisableCookies mode setting
  693. RegSetValueEx(hkeyPassport,
  694. g_szDisableCookies,
  695. NULL,
  696. REG_DWORD,
  697. (LPBYTE)&lpPMConfig->dwDisableCookies,
  698. sizeof(DWORD));
  699. // Only write HostName and HostIP for non-default config sets.
  700. if(lpszConfigSetName && lpszConfigSetName[0])
  701. {
  702. // Write the HostName
  703. RegSetValueEx(hkeyPassport,
  704. g_szHostName,
  705. NULL,
  706. REG_SZ,
  707. (LPBYTE)lpPMConfig->szHostName,
  708. lstrlen(lpPMConfig->szHostName) + 1);
  709. // Write the HostIP
  710. RegSetValueEx(hkeyPassport,
  711. g_szHostIP,
  712. NULL,
  713. REG_SZ,
  714. (LPBYTE)lpPMConfig->szHostIP,
  715. lstrlen(lpPMConfig->szHostIP) + 1);
  716. }
  717. bReturn = TRUE;
  718. Cleanup:
  719. if(hklm && hklm != HKEY_LOCAL_MACHINE)
  720. RegCloseKey(hklm);
  721. if(hkeyConfigSets)
  722. RegCloseKey(hkeyConfigSets);
  723. if(hkeyPassport)
  724. RegCloseKey(hkeyPassport);
  725. return bReturn;
  726. }
  727. /**************************************************************************
  728. RemoveRegConfigSet
  729. Verify that the passed in config set is consistent with the current
  730. values in the registry.
  731. **************************************************************************/
  732. BOOL RemoveRegConfigSet
  733. (
  734. HWND hWndDlg,
  735. LPTSTR lpszRemoteComputer,
  736. LPTSTR lpszConfigSetName
  737. )
  738. {
  739. BOOL bReturn;
  740. HKEY hklm = NULL;
  741. HKEY hkeyPassportConfigSets = NULL;
  742. // Can't delete the default configuration set.
  743. if(lpszConfigSetName == NULL || lpszConfigSetName[0] == TEXT('\0'))
  744. {
  745. bReturn = FALSE;
  746. goto Cleanup;
  747. }
  748. // Open the Passport Configuration Sets Regkey ( either locally or remotly
  749. if (lpszRemoteComputer && ('\0' != lpszRemoteComputer[0]))
  750. {
  751. //
  752. // Attempt to connect to the HKEY_LOCAL_MACHINE of the remote computer.
  753. // If this fails, assume that the computer doesn't exist or doesn't have
  754. // the registry server running.
  755. //
  756. switch (RegConnectRegistry(lpszRemoteComputer,
  757. HKEY_LOCAL_MACHINE,
  758. &hklm))
  759. {
  760. case ERROR_SUCCESS:
  761. break;
  762. case ERROR_ACCESS_DENIED:
  763. ReportError(hWndDlg, IDS_CONNECTACCESSDENIED);
  764. bReturn = FALSE;
  765. goto Cleanup;
  766. default:
  767. ReportError(hWndDlg, IDS_CONNECTBADNAME);
  768. bReturn = FALSE;
  769. goto Cleanup;
  770. }
  771. }
  772. else
  773. {
  774. hklm = HKEY_LOCAL_MACHINE;
  775. }
  776. // Open the key we want
  777. if (ERROR_SUCCESS != RegOpenKeyEx(hklm,
  778. g_szPassportSites,
  779. 0,
  780. KEY_ALL_ACCESS,
  781. &hkeyPassportConfigSets))
  782. {
  783. ReportError(hWndDlg, IDS_CONFIGREAD_ERROR);
  784. bReturn = FALSE;
  785. goto Cleanup;
  786. }
  787. // Delete the config set key
  788. if (ERROR_SUCCESS != SHDeleteKey(hkeyPassportConfigSets, lpszConfigSetName))
  789. {
  790. ReportError(hWndDlg, IDS_CONFIGREAD_ERROR);
  791. bReturn = FALSE;
  792. goto Cleanup;
  793. }
  794. bReturn = TRUE;
  795. Cleanup:
  796. if(hklm && hklm != HKEY_LOCAL_MACHINE)
  797. RegCloseKey(hklm);
  798. if(hkeyPassportConfigSets)
  799. RegCloseKey(hkeyPassportConfigSets);
  800. return bReturn;
  801. }
  802. /**************************************************************************
  803. VerifyRegConfigSet
  804. Verify that the passed in config set is consistent with the current
  805. values in the registry.
  806. **************************************************************************/
  807. BOOL VerifyRegConfigSet
  808. (
  809. HWND hWndDlg,
  810. LPPMSETTINGS lpPMConfig,
  811. LPTSTR lpszRemoteComputer,
  812. LPTSTR lpszConfigSetName
  813. )
  814. {
  815. PMSETTINGS pmCurrent;
  816. InitializePMConfigStruct(&pmCurrent);
  817. ReadRegConfigSet(hWndDlg, &pmCurrent, lpszRemoteComputer, lpszConfigSetName);
  818. return (0 == memcmp(&pmCurrent, lpPMConfig, sizeof(PMSETTINGS)));
  819. }
  820. /**************************************************************************
  821. ReadRegConfigSetNames
  822. Get back a list of config set names on a local or remote machine.
  823. Caller is responsible for calling free() on the returned pointer.
  824. When this function returns TRUE, lppszConfigSetNames will either
  825. contain NULL or a string containing the NULL delimited config set
  826. names on the given computer.
  827. When this function returns FALSE, *lppszConfigSetNames will not
  828. be modified.
  829. **************************************************************************/
  830. BOOL ReadRegConfigSetNames
  831. (
  832. HWND hWndDlg,
  833. LPTSTR lpszRemoteComputer,
  834. LPTSTR* lppszConfigSetNames
  835. )
  836. {
  837. BOOL bReturn;
  838. HKEY hklm = NULL;
  839. HKEY hkeyConfigSets = NULL;
  840. DWORD dwIndex;
  841. DWORD dwNumSubKeys;
  842. DWORD dwMaxKeyNameLen;
  843. TCHAR achKeyName[MAX_PATH];
  844. ULONGLONG ullAllocSize;
  845. LPTSTR lpszConfigSetNames;
  846. LPTSTR lpszCur;
  847. // Open the Passport Regkey ( either locally or remotly
  848. if (lpszRemoteComputer && (TEXT('\0') != lpszRemoteComputer[0]))
  849. {
  850. //
  851. // Attempt to connect to the HKEY_LOCAL_MACHINE of the remote computer.
  852. // If this fails, assume that the computer doesn't exist or doesn't have
  853. // the registry server running.
  854. //
  855. switch (RegConnectRegistry(lpszRemoteComputer,
  856. HKEY_LOCAL_MACHINE,
  857. &hklm))
  858. {
  859. case ERROR_SUCCESS:
  860. break;
  861. case ERROR_ACCESS_DENIED:
  862. ReportError(hWndDlg, IDS_CONNECTACCESSDENIED);
  863. bReturn = FALSE;
  864. goto Cleanup;
  865. default:
  866. ReportError(hWndDlg, IDS_CONNECTBADNAME);
  867. bReturn = FALSE;
  868. goto Cleanup;
  869. }
  870. }
  871. else
  872. {
  873. hklm = HKEY_LOCAL_MACHINE;
  874. }
  875. if (ERROR_SUCCESS != RegOpenKeyEx(hklm,
  876. g_szPassportSites,
  877. 0,
  878. KEY_ALL_ACCESS,
  879. &hkeyConfigSets))
  880. {
  881. bReturn = FALSE;
  882. goto Cleanup;
  883. }
  884. if (ERROR_SUCCESS != RegQueryInfoKey(hkeyConfigSets,
  885. NULL,
  886. NULL,
  887. NULL,
  888. &dwNumSubKeys,
  889. &dwMaxKeyNameLen,
  890. NULL,
  891. NULL,
  892. NULL,
  893. NULL,
  894. NULL,
  895. NULL))
  896. {
  897. bReturn = FALSE;
  898. goto Cleanup;
  899. }
  900. //
  901. // Nothing to do!
  902. //
  903. if(dwNumSubKeys == 0)
  904. {
  905. bReturn = TRUE;
  906. *lppszConfigSetNames = NULL;
  907. goto Cleanup;
  908. }
  909. // Too big? BUGBUG - We should make sure we check for this
  910. // When writing out config sets.
  911. ullAllocSize = UInt32x32To64(dwNumSubKeys, dwMaxKeyNameLen);
  912. if(ullAllocSize & 0xFFFFFFFF00000000)
  913. {
  914. bReturn = FALSE;
  915. goto Cleanup;
  916. }
  917. // This should allocate more space than we need.
  918. lpszConfigSetNames = (LPTSTR)malloc(((dwNumSubKeys * (dwMaxKeyNameLen + 1)) + 1) * sizeof(TCHAR));
  919. if(lpszConfigSetNames == NULL)
  920. {
  921. bReturn = FALSE;
  922. goto Cleanup;
  923. }
  924. // Read all names into the buffer. Names are NULL delimited and
  925. // two NULLs end the entire thing.
  926. dwIndex = 0;
  927. lpszCur = lpszConfigSetNames;
  928. while (ERROR_SUCCESS == RegEnumKey(hkeyConfigSets, dwIndex++, achKeyName, sizeof(achKeyName)))
  929. {
  930. _tcscpy(lpszCur, achKeyName);
  931. lpszCur = _tcschr(lpszCur, TEXT('\0')) + 1;
  932. }
  933. *lpszCur = TEXT('\0');
  934. *lppszConfigSetNames = lpszConfigSetNames;
  935. bReturn = TRUE;
  936. Cleanup:
  937. if(hklm)
  938. RegCloseKey(hklm);
  939. if(hkeyConfigSets)
  940. RegCloseKey(hkeyConfigSets);
  941. return bReturn;
  942. }