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.

1949 lines
62 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_szPassportPartner[] = TEXT("Software\\Microsoft\\Passport\\Nexus\\Partner");
  16. TCHAR g_szPassportEnvironments[] = TEXT("Software\\Microsoft\\Passport\\Environments");
  17. TCHAR g_szEncryptionKeyData[] = TEXT("KeyData");
  18. TCHAR g_szKeyTimes[] = TEXT("KeyTimes");
  19. TCHAR g_szNexus[] = TEXT("Nexus");
  20. TCHAR g_szPartner[] = TEXT("Partner");
  21. TCHAR g_szInstallDir[] = TEXT("InstallDir");
  22. TCHAR g_szVersion[] = TEXT("Version");
  23. TCHAR g_szTimeWindow[] = TEXT("TimeWindow");
  24. TCHAR g_szForceSignIn[] = TEXT("ForceSignIn");
  25. TCHAR g_szNSRefresh[] = TEXT("NSRefresh");
  26. TCHAR g_szLanguageID[] = TEXT("LanguageID");
  27. TCHAR g_szCoBrandTemplate[] = TEXT("CoBrandTemplate");
  28. TCHAR g_szSiteID[] = TEXT("SiteID");
  29. TCHAR g_szReturnURL[] = TEXT("ReturnURL");
  30. TCHAR g_szTicketDomain[] = TEXT("TicketDomain");
  31. TCHAR g_szTicketPath[] = TEXT("TicketPath");
  32. TCHAR g_szProfileDomain[] = TEXT("ProfileDomain");
  33. TCHAR g_szProfilePath[] = TEXT("ProfilePath");
  34. TCHAR g_szSecureDomain[] = TEXT("SecureDomain");
  35. TCHAR g_szSecurePath[] = TEXT("SecurePath");
  36. TCHAR g_szCurrentKey[] = TEXT("CurrentKey");
  37. TCHAR g_szStandAlone[] = TEXT("StandAlone");
  38. TCHAR g_szDisableCookies[] = TEXT("DisableCookies");
  39. TCHAR g_szDisasterURL[] = TEXT("DisasterURL");
  40. TCHAR g_szHostName[] = TEXT("HostName");
  41. TCHAR g_szHostIP[] = TEXT("HostIP");
  42. //JVP 3/2/2000
  43. TCHAR g_szVerboseMode[] = TEXT("Verbose");
  44. TCHAR g_szEnvName[] = TEXT("Environment");
  45. TCHAR g_szRemoteFile[] = TEXT("CCDRemoteFile");
  46. TCHAR g_szLocalFile[] = TEXT("CCDLocalFile");
  47. TCHAR g_szVersion14[] = TEXT("1.4");
  48. TCHAR g_szSecureLevel[] = TEXT("SecureLevel");
  49. #define REG_PASSPORT_SITES_VALUE TEXT("Software\\Microsoft\\Passport\\Sites")
  50. #define REG_PASSPORT_SITES_LEN (sizeof(REG_PASSPORT_SITES_VALUE) / sizeof(TCHAR) - 1)
  51. #define REG_CLOSE_KEY_NULL(a) { if ((a) != NULL) { RegCloseKey(a); (a) = NULL; } }
  52. // -------------------------------------------------------------------------------
  53. //
  54. //
  55. // -------------------------------------------------------------------------------
  56. BOOL WriteGlobalConfigSettings(HWND hWndDlg, HKEY hklm, LPPMSETTINGS lpPMConfig, LPTSTR lpszRemoteComputer)
  57. {
  58. HKEY hkeyPassport = NULL, hkeyPassportSubKey = NULL;
  59. long lRet;
  60. BOOL bReturn = FALSE;
  61. TCHAR szConfigName[MAX_CONFIGSETNAME];
  62. TCHAR szTmpBuf[REG_PASSPORT_SITES_LEN + 1 + MAX_CONFIGSETNAME + 1] = REG_PASSPORT_SITES_VALUE;
  63. ULONG nConfigNameSize = MAX_CONFIGSETNAME;
  64. FILETIME ftime;
  65. long nCurrentSubKey;
  66. // First, open the keys for the default set
  67. //
  68. if ((lRet = RegOpenKeyEx(hklm, g_szPassportReg, 0, KEY_ALL_ACCESS, &hkeyPassport)) != ERROR_SUCCESS)
  69. {
  70. LPVOID lpMsgBuf;
  71. if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
  72. FORMAT_MESSAGE_FROM_SYSTEM |
  73. FORMAT_MESSAGE_IGNORE_INSERTS,
  74. NULL,
  75. lRet,
  76. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  77. (LPTSTR) &lpMsgBuf,
  78. 0,
  79. NULL) != 0)
  80. {
  81. TCHAR pszTitle[MAX_RESOURCE];
  82. // Display the string
  83. LoadString(g_hInst, IDS_ERROR, pszTitle, DIMENSION(pszTitle));
  84. MessageBox( NULL, (LPCTSTR)lpMsgBuf, pszTitle, MB_OK | MB_ICONINFORMATION );
  85. // Free the buffer.
  86. LocalFree( lpMsgBuf );
  87. }
  88. bReturn = FALSE;
  89. goto Cleanup;
  90. }
  91. // Write the value for NSRefresh
  92. RegSetValueEx(hkeyPassport,
  93. g_szNSRefresh,
  94. NULL,
  95. REG_DWORD,
  96. (LPBYTE)&lpPMConfig->dwEnableManualRefresh,
  97. sizeof(DWORD));
  98. // Write the environment
  99. RegSetValueEx(hkeyPassport,
  100. g_szEnvName,
  101. NULL,
  102. REG_SZ,
  103. (LPBYTE)lpPMConfig->szEnvName,
  104. (lstrlen(lpPMConfig->szEnvName) + 1) * sizeof(TCHAR));
  105. RegCloseKey(hkeyPassport);
  106. hkeyPassport = NULL;
  107. // If the "Sites" key was not found, then there are no Sites to configure
  108. //
  109. if ((lRet = RegOpenKeyEx(hklm,
  110. REG_PASSPORT_SITES_VALUE,
  111. 0,
  112. KEY_ALL_ACCESS,
  113. &hkeyPassport)) != ERROR_SUCCESS)
  114. {
  115. bReturn = TRUE;
  116. goto Cleanup;
  117. }
  118. nCurrentSubKey = 0;
  119. while (lRet = RegEnumKeyEx(hkeyPassport,
  120. nCurrentSubKey++,
  121. szConfigName,
  122. &nConfigNameSize,
  123. NULL,
  124. NULL,
  125. NULL,
  126. &ftime) == ERROR_SUCCESS)
  127. {
  128. *(szTmpBuf + REG_PASSPORT_SITES_LEN) = _T('\\');
  129. *(szTmpBuf + REG_PASSPORT_SITES_LEN + 1) = _T('\0');
  130. _tcscat(szTmpBuf + REG_PASSPORT_SITES_LEN + 1, szConfigName);
  131. if ((lRet = RegOpenKeyEx(hklm,
  132. szTmpBuf,
  133. 0,
  134. KEY_ALL_ACCESS,
  135. &hkeyPassportSubKey)) != ERROR_SUCCESS)
  136. {
  137. ReportError(hWndDlg, IDS_CONFIGREAD_ERROR);
  138. bReturn = FALSE;
  139. goto Cleanup;
  140. }
  141. // Write the value for NSRefresh
  142. RegSetValueEx(hkeyPassportSubKey,
  143. g_szNSRefresh,
  144. NULL,
  145. REG_DWORD,
  146. (LPBYTE) &lpPMConfig->dwEnableManualRefresh,
  147. sizeof(DWORD));
  148. // Write the environment
  149. RegSetValueEx(hkeyPassportSubKey,
  150. g_szEnvName,
  151. NULL,
  152. REG_SZ,
  153. (LPBYTE) lpPMConfig->szEnvName,
  154. (lstrlen(lpPMConfig->szEnvName) + 1) * sizeof(TCHAR));
  155. RegCloseKey(hkeyPassportSubKey);
  156. hkeyPassportSubKey = NULL;
  157. nConfigNameSize = MAX_CONFIGSETNAME * sizeof(TCHAR);
  158. }
  159. if (lRet == ERROR_SUCCESS)
  160. bReturn = TRUE;
  161. Cleanup:
  162. if (hkeyPassport)
  163. RegCloseKey(hkeyPassport);
  164. if (hkeyPassportSubKey)
  165. RegCloseKey(hkeyPassportSubKey);
  166. return bReturn;
  167. }
  168. /**************************************************************************
  169. WriteRegTestKey
  170. Installs the default test key for the named config set. This is
  171. only called in the case where a new config set key was created in
  172. OpenRegConfigSet.
  173. **************************************************************************/
  174. BOOL
  175. WriteRegTestKey
  176. (
  177. HKEY hkeyConfigKey,
  178. PSECURITY_DESCRIPTOR pSD
  179. )
  180. {
  181. BOOL bReturn;
  182. CKeyCrypto kc;
  183. HKEY hkDataKey = NULL, hkTimeKey = NULL;
  184. TCHAR szKeyNum[2];
  185. DWORD dwKeyVer = 1;
  186. // Try to encrypt it with MAC address
  187. BYTE original[CKeyCrypto::RAWKEY_SIZE];
  188. DATA_BLOB iBlob;
  189. DATA_BLOB oBlob;
  190. SECURITY_ATTRIBUTES SecAttrib;
  191. iBlob.cbData = sizeof(original);
  192. iBlob.pbData = original;
  193. ZeroMemory(&oBlob, sizeof(oBlob));
  194. memcpy(original, "123456781234567812345678", CKeyCrypto::RAWKEY_SIZE);
  195. if (kc.encryptKey(&iBlob, &oBlob) != S_OK)
  196. {
  197. bReturn = FALSE;
  198. goto Cleanup;
  199. }
  200. // Now add it to registry
  201. lstrcpy(szKeyNum, TEXT("1"));
  202. // set up the security attributes structure for the KeyData reg key
  203. SecAttrib.nLength = sizeof(SECURITY_ATTRIBUTES);
  204. SecAttrib.lpSecurityDescriptor = pSD;
  205. SecAttrib.bInheritHandle = FALSE;
  206. if(ERROR_SUCCESS != RegCreateKeyEx(hkeyConfigKey,
  207. TEXT("KeyData"),
  208. 0,
  209. TEXT(""),
  210. 0,
  211. KEY_ALL_ACCESS,
  212. &SecAttrib,
  213. &hkDataKey,
  214. NULL))
  215. {
  216. bReturn = FALSE;
  217. goto Cleanup;
  218. }
  219. if(ERROR_SUCCESS != RegCreateKeyEx(hkeyConfigKey,
  220. TEXT("KeyTimes"),
  221. 0,
  222. TEXT(""),
  223. 0,
  224. KEY_ALL_ACCESS,
  225. NULL,
  226. &hkTimeKey,
  227. NULL))
  228. {
  229. bReturn = FALSE;
  230. goto Cleanup;
  231. }
  232. if(ERROR_SUCCESS != RegSetValueEx(hkDataKey,
  233. szKeyNum,
  234. 0,
  235. REG_BINARY,
  236. oBlob.pbData,
  237. oBlob.cbData))
  238. {
  239. bReturn = FALSE;
  240. goto Cleanup;
  241. }
  242. if(ERROR_SUCCESS != RegSetValueEx(hkeyConfigKey,
  243. TEXT("CurrentKey"),
  244. 0,
  245. REG_DWORD,
  246. (LPBYTE) &dwKeyVer,
  247. sizeof(DWORD)))
  248. {
  249. bReturn = FALSE;
  250. goto Cleanup;
  251. }
  252. bReturn = TRUE;
  253. Cleanup:
  254. if (hkDataKey)
  255. RegCloseKey(hkDataKey);
  256. if (hkTimeKey)
  257. RegCloseKey(hkTimeKey);
  258. if (oBlob.pbData)
  259. ::LocalFree(oBlob.pbData);
  260. return bReturn;
  261. }
  262. /**************************************************************************
  263. OpenRegConfigSet
  264. Open and return an HKEY for a named configuration set
  265. current passport manager config set from the registry
  266. **************************************************************************/
  267. HKEY OpenRegConfigSet
  268. (
  269. HKEY hkeyLocalMachine, // Local or remote HKLM
  270. LPTSTR lpszConfigSetName // Name of config set
  271. )
  272. {
  273. HKEY hkeyConfigSets = NULL;
  274. HKEY hkeyConfigSet = NULL;
  275. DWORD dwDisp;
  276. PSECURITY_DESCRIPTOR pSD = NULL;
  277. HKEY hDefKeyData = NULL;
  278. DWORD cbSD = 0;
  279. long lRet;
  280. //
  281. // Can't create an unnamed config set.
  282. //
  283. if(lpszConfigSetName == NULL ||
  284. lpszConfigSetName[0] == TEXT('\0'))
  285. {
  286. lRet = ERROR_INVALID_PARAMETER;
  287. goto Cleanup;
  288. }
  289. if (ERROR_SUCCESS != (lRet = RegCreateKeyEx(hkeyLocalMachine,
  290. REG_PASSPORT_SITES_VALUE,
  291. 0,
  292. TEXT(""),
  293. 0,
  294. KEY_ALL_ACCESS,
  295. NULL,
  296. &hkeyConfigSets,
  297. NULL)))
  298. {
  299. goto Cleanup;
  300. }
  301. //
  302. // Create the key if it doesn't exist, otherwise
  303. // open it.
  304. //
  305. if (ERROR_SUCCESS != (lRet = RegCreateKeyEx(hkeyConfigSets,
  306. lpszConfigSetName,
  307. 0,
  308. TEXT(""),
  309. 0,
  310. KEY_ALL_ACCESS,
  311. NULL,
  312. &hkeyConfigSet,
  313. &dwDisp)))
  314. {
  315. goto Cleanup;
  316. }
  317. //
  318. // If we created a new regkey, add encryption keys
  319. //
  320. if(dwDisp == REG_CREATED_NEW_KEY)
  321. {
  322. // first read the SD from the default key data
  323. if (ERROR_SUCCESS !=
  324. RegOpenKeyEx(hkeyLocalMachine,
  325. L"Software\\Microsoft\\Passport\\KeyData",
  326. 0,
  327. KEY_READ,
  328. &hDefKeyData))
  329. {
  330. RegCloseKey(hkeyConfigSet);
  331. hkeyConfigSet = NULL;
  332. goto Cleanup;
  333. }
  334. if (ERROR_INSUFFICIENT_BUFFER !=
  335. RegGetKeySecurity(hDefKeyData,
  336. DACL_SECURITY_INFORMATION,
  337. &cbSD,
  338. &cbSD))
  339. {
  340. RegCloseKey(hkeyConfigSet);
  341. hkeyConfigSet = NULL;
  342. goto Cleanup;
  343. }
  344. if (NULL == (pSD = (PSECURITY_DESCRIPTOR)LocalAlloc(LMEM_FIXED, cbSD)))
  345. {
  346. RegCloseKey(hkeyConfigSet);
  347. hkeyConfigSet = NULL;
  348. goto Cleanup;
  349. }
  350. if (ERROR_SUCCESS !=
  351. RegGetKeySecurity(hDefKeyData,
  352. DACL_SECURITY_INFORMATION,
  353. pSD,
  354. &cbSD))
  355. {
  356. RegCloseKey(hkeyConfigSet);
  357. hkeyConfigSet = NULL;
  358. goto Cleanup;
  359. }
  360. // create the new key data
  361. if (!WriteRegTestKey(hkeyConfigSet, pSD))
  362. {
  363. RegCloseKey(hkeyConfigSet);
  364. hkeyConfigSet = NULL;
  365. goto Cleanup;
  366. }
  367. }
  368. Cleanup:
  369. if (pSD)
  370. {
  371. LocalFree(pSD);
  372. }
  373. if (hDefKeyData)
  374. {
  375. RegCloseKey(hDefKeyData);
  376. }
  377. if(hkeyConfigSets)
  378. RegCloseKey(hkeyConfigSets);
  379. else {
  380. LPVOID lpMsgBuf;
  381. if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
  382. FORMAT_MESSAGE_FROM_SYSTEM |
  383. FORMAT_MESSAGE_IGNORE_INSERTS,
  384. NULL,
  385. lRet,
  386. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  387. (LPTSTR) &lpMsgBuf,
  388. 0,
  389. NULL) != 0)
  390. {
  391. TCHAR pszTitle[MAX_RESOURCE];
  392. // Display the string.
  393. LoadString(g_hInst, IDS_ERROR, pszTitle, DIMENSION(pszTitle));
  394. MessageBox( NULL, (LPCTSTR) lpMsgBuf, pszTitle, MB_OK | MB_ICONINFORMATION );
  395. // Free the buffer.
  396. LocalFree( lpMsgBuf );
  397. }
  398. }
  399. return hkeyConfigSet;
  400. }
  401. /**************************************************************************
  402. OpenTopRegKey
  403. Open the top reg key, if we aren't allowed to then fail.
  404. **************************************************************************/
  405. BOOL OpenTopRegKey
  406. (
  407. HWND hWndDlg,
  408. LPTSTR lpszRemoteComputer,
  409. HKEY *phklm,
  410. HKEY *phkeyPassport
  411. )
  412. {
  413. BOOL bReturn;
  414. long lRet;
  415. // Open the Passport Regkey ( either locally or remotly
  416. if (lpszRemoteComputer && (TEXT('\0') != lpszRemoteComputer[0]))
  417. {
  418. //
  419. // Attempt to connect to the HKEY_LOCAL_MACHINE of the remote computer.
  420. // If this fails, assume that the computer doesn't exist or doesn't have
  421. // the registry server running.
  422. //
  423. switch (lRet = RegConnectRegistry(lpszRemoteComputer,
  424. HKEY_LOCAL_MACHINE,
  425. phklm))
  426. {
  427. case ERROR_SUCCESS:
  428. break;
  429. case ERROR_ACCESS_DENIED:
  430. ReportError(hWndDlg, IDS_CONNECTACCESSDENIED);
  431. bReturn = FALSE;
  432. goto Cleanup;
  433. default:
  434. ReportError(hWndDlg, IDS_CONNECTBADNAME);
  435. bReturn = FALSE;
  436. goto Cleanup;
  437. }
  438. }
  439. else
  440. {
  441. *phklm = HKEY_LOCAL_MACHINE;
  442. }
  443. // Open the key we want
  444. if (ERROR_SUCCESS != (lRet = RegOpenKeyEx(*phklm,
  445. g_szPassportReg,
  446. 0,
  447. KEY_ALL_ACCESS,
  448. phkeyPassport)))
  449. {
  450. LPVOID lpMsgBuf;
  451. FormatMessage(
  452. FORMAT_MESSAGE_ALLOCATE_BUFFER |
  453. FORMAT_MESSAGE_FROM_SYSTEM |
  454. FORMAT_MESSAGE_IGNORE_INSERTS,
  455. NULL,
  456. lRet,
  457. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  458. (LPTSTR) &lpMsgBuf,
  459. 0,
  460. NULL
  461. );
  462. // Display the string.
  463. {
  464. TCHAR pszTitle[MAX_RESOURCE];
  465. LoadString(g_hInst, IDS_ERROR, pszTitle, DIMENSION(pszTitle));
  466. MessageBox( NULL, (LPCTSTR) lpMsgBuf, pszTitle, MB_OK | MB_ICONINFORMATION );
  467. }
  468. // Free the buffer.
  469. LocalFree( lpMsgBuf );
  470. // ReportError(hWndDlg, IDS_CONFIGREAD_ERROR);
  471. bReturn = FALSE;
  472. goto Cleanup;
  473. }
  474. bReturn = TRUE;
  475. Cleanup:
  476. return bReturn;
  477. }
  478. /**************************************************************************
  479. ReadRegConfigSet
  480. Read the current passport manager config set from the registry
  481. **************************************************************************/
  482. BOOL ReadRegConfigSet
  483. (
  484. HWND hWndDlg,
  485. LPPMSETTINGS lpPMConfig,
  486. LPTSTR lpszRemoteComputer,
  487. LPTSTR lpszConfigSetName
  488. )
  489. {
  490. BOOL bReturn;
  491. HKEY hkeyPassport = NULL; // Regkey where Passport Setting live
  492. HKEY hkeyConfigSets = NULL;
  493. HKEY hkeyConfig = NULL;
  494. HKEY hkeyPartner = NULL;
  495. HKEY hklm = NULL;
  496. DWORD dwcbTemp;
  497. DWORD dwType;
  498. TCHAR szText[MAX_RESOURCE];
  499. TCHAR szTitle[MAX_RESOURCE];
  500. long lRet;
  501. if (!OpenTopRegKey(hWndDlg, lpszRemoteComputer, &hklm, &hkeyPassport))
  502. {
  503. bReturn = FALSE;
  504. goto Cleanup;
  505. }
  506. // Open Partner key
  507. if (ERROR_SUCCESS != (lRet = RegOpenKeyEx(hklm,
  508. g_szPassportPartner,
  509. 0,
  510. KEY_ALL_ACCESS,
  511. &hkeyPartner)))
  512. {
  513. LPVOID lpMsgBuf;
  514. if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
  515. FORMAT_MESSAGE_FROM_SYSTEM |
  516. FORMAT_MESSAGE_IGNORE_INSERTS,
  517. NULL,
  518. lRet,
  519. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  520. (LPTSTR) &lpMsgBuf,
  521. 0,
  522. NULL) != 0)
  523. {
  524. TCHAR pszTitle[MAX_RESOURCE];
  525. // Display the string.
  526. LoadString(g_hInst, IDS_ERROR, pszTitle, DIMENSION(pszTitle));
  527. MessageBox( NULL, (LPCTSTR) lpMsgBuf, pszTitle, MB_OK | MB_ICONINFORMATION );
  528. // Free the buffer.
  529. LocalFree( lpMsgBuf );
  530. }
  531. // ReportError(hWndDlg, IDS_CONFIGREAD_ERROR);
  532. bReturn = FALSE;
  533. goto Cleanup;
  534. }
  535. // open Site key
  536. if(lpszConfigSetName && lpszConfigSetName[0] != TEXT('\0'))
  537. {
  538. hkeyConfig = OpenRegConfigSet(hklm, lpszConfigSetName);
  539. if(hkeyConfig == NULL)
  540. {
  541. ReportError(hWndDlg, IDS_CONFIGREAD_ERROR);
  542. bReturn = FALSE;
  543. goto Cleanup;
  544. }
  545. }
  546. else
  547. {
  548. hkeyConfig = hkeyPassport;
  549. }
  550. // The Install dir and Version number go into globals, because they are read
  551. // only values that must come from the target machine's registry.
  552. // Read the Install Dir.
  553. dwcbTemp = MAX_PATH;
  554. dwType = REG_SZ;
  555. g_szInstallPath[0] = TEXT('\0'); // Default value
  556. RegQueryValueEx(hkeyPassport,
  557. g_szInstallDir,
  558. NULL,
  559. &dwType,
  560. (LPBYTE)g_szInstallPath,
  561. &dwcbTemp);
  562. // Read the version Number
  563. dwcbTemp = MAX_REGISTRY_STRING;
  564. dwType = REG_SZ;
  565. g_szPMVersion[0] = TEXT('\0'); // Default value
  566. RegQueryValueEx(hkeyPassport,
  567. g_szVersion,
  568. NULL,
  569. &dwType,
  570. (LPBYTE)&g_szPMVersion,
  571. &dwcbTemp);
  572. // The Remaining settings are read/write and get put into a PMSETTINGS struct
  573. // Read the Time Window Number
  574. dwcbTemp = sizeof(DWORD);
  575. dwType = REG_DWORD;
  576. lpPMConfig->dwTimeWindow = DEFAULT_TIME_WINDOW;
  577. RegQueryValueEx(hkeyConfig,
  578. g_szTimeWindow,
  579. NULL,
  580. &dwType,
  581. (LPBYTE)&lpPMConfig->dwTimeWindow,
  582. &dwcbTemp);
  583. // Read the value for Forced Signin
  584. dwcbTemp = sizeof(DWORD);
  585. dwType = REG_DWORD;
  586. lpPMConfig->dwForceSignIn = 0; // Don't force a signin by default
  587. RegQueryValueEx(hkeyConfig,
  588. g_szForceSignIn,
  589. NULL,
  590. &dwType,
  591. (LPBYTE)&lpPMConfig->dwForceSignIn,
  592. &dwcbTemp);
  593. // Read the value for NSRefresh
  594. dwcbTemp = sizeof(DWORD);
  595. dwType = REG_DWORD;
  596. lpPMConfig->dwEnableManualRefresh = 0; // Don't enable NS Manual Refresh by default
  597. RegQueryValueEx(hkeyConfig,
  598. g_szNSRefresh,
  599. NULL,
  600. &dwType,
  601. (LPBYTE)&lpPMConfig->dwEnableManualRefresh,
  602. &dwcbTemp);
  603. // Read the default language ID
  604. dwcbTemp = sizeof(DWORD);
  605. dwType = REG_DWORD;
  606. lpPMConfig->dwLanguageID = DEFAULT_LANGID; // english
  607. RegQueryValueEx(hkeyConfig,
  608. g_szLanguageID,
  609. NULL,
  610. &dwType,
  611. (LPBYTE)&lpPMConfig->dwLanguageID,
  612. &dwcbTemp);
  613. // Get the co-branding template
  614. dwcbTemp = lpPMConfig->cbCoBrandTemplate;
  615. dwType = REG_SZ;
  616. lpPMConfig->szCoBrandTemplate[0] = TEXT('\0'); // Default value
  617. RegQueryValueEx(hkeyConfig,
  618. g_szCoBrandTemplate,
  619. NULL,
  620. &dwType,
  621. (LPBYTE)lpPMConfig->szCoBrandTemplate,
  622. &dwcbTemp);
  623. // Get the SiteID
  624. dwcbTemp = sizeof(DWORD);
  625. dwType = REG_DWORD;
  626. lpPMConfig->dwSiteID = 1; // Default Site ID
  627. RegQueryValueEx(hkeyConfig,
  628. g_szSiteID,
  629. NULL,
  630. &dwType,
  631. (LPBYTE)&lpPMConfig->dwSiteID,
  632. &dwcbTemp);
  633. // Get the return URL template
  634. dwcbTemp = lpPMConfig->cbReturnURL;
  635. dwType = REG_SZ;
  636. lpPMConfig->szReturnURL[0] = TEXT('\0'); // Set a default for the current value
  637. RegQueryValueEx(hkeyConfig,
  638. g_szReturnURL,
  639. NULL,
  640. &dwType,
  641. (LPBYTE)lpPMConfig->szReturnURL,
  642. &dwcbTemp);
  643. // Get the ticket cookie domain
  644. dwcbTemp = lpPMConfig->cbTicketDomain;
  645. dwType = REG_SZ;
  646. lpPMConfig->szTicketDomain[0] = TEXT('\0'); // Set a default for the current value
  647. RegQueryValueEx(hkeyConfig,
  648. g_szTicketDomain,
  649. NULL,
  650. &dwType,
  651. (LPBYTE)lpPMConfig->szTicketDomain,
  652. &dwcbTemp);
  653. // Get the ticket cookie path
  654. dwcbTemp = lpPMConfig->cbTicketPath;
  655. dwType = REG_SZ;
  656. lpPMConfig->szTicketPath[0] = TEXT('\0'); // Set a default for the current value
  657. RegQueryValueEx(hkeyConfig,
  658. g_szTicketPath,
  659. NULL,
  660. &dwType,
  661. (LPBYTE)lpPMConfig->szTicketPath,
  662. &dwcbTemp);
  663. // Get the profile cookie domain
  664. dwcbTemp = lpPMConfig->cbProfileDomain;
  665. dwType = REG_SZ;
  666. lpPMConfig->szProfileDomain[0] = TEXT('\0'); // Set a default for the current value
  667. RegQueryValueEx(hkeyConfig,
  668. g_szProfileDomain,
  669. NULL,
  670. &dwType,
  671. (LPBYTE)lpPMConfig->szProfileDomain,
  672. &dwcbTemp);
  673. // Get the profile cookie path
  674. dwcbTemp = lpPMConfig->cbProfilePath;
  675. dwType = REG_SZ;
  676. lpPMConfig->szProfilePath[0] = TEXT('\0'); // Set a default for the current value
  677. RegQueryValueEx(hkeyConfig,
  678. g_szProfilePath,
  679. NULL,
  680. &dwType,
  681. (LPBYTE)lpPMConfig->szProfilePath,
  682. &dwcbTemp);
  683. // Get the secure cookie domain
  684. dwcbTemp = lpPMConfig->cbSecureDomain;
  685. dwType = REG_SZ;
  686. lpPMConfig->szSecureDomain[0] = TEXT('\0'); // Set a default for the current value
  687. RegQueryValueEx(hkeyConfig,
  688. g_szSecureDomain,
  689. NULL,
  690. &dwType,
  691. (LPBYTE)lpPMConfig->szSecureDomain,
  692. &dwcbTemp);
  693. // Get the secure cookie path
  694. dwcbTemp = lpPMConfig->cbSecurePath;
  695. dwType = REG_SZ;
  696. lpPMConfig->szSecurePath[0] = TEXT('\0'); // Set a default for the current value
  697. RegQueryValueEx(hkeyConfig,
  698. g_szSecurePath,
  699. NULL,
  700. &dwType,
  701. (LPBYTE)lpPMConfig->szSecurePath,
  702. &dwcbTemp);
  703. // Get the Disaster URL
  704. dwcbTemp = lpPMConfig->cbDisasterURL;
  705. dwType = REG_SZ;
  706. lpPMConfig->szDisasterURL[0] = TEXT('\0'); // Set a default for the current value
  707. RegQueryValueEx(hkeyConfig,
  708. g_szDisasterURL,
  709. NULL,
  710. &dwType,
  711. (LPBYTE)lpPMConfig->szDisasterURL,
  712. &dwcbTemp);
  713. // Get Standalone mode setting
  714. dwcbTemp = sizeof(DWORD);
  715. dwType = REG_DWORD;
  716. lpPMConfig->dwStandAlone = 0; // NOT standalone by default
  717. RegQueryValueEx(hkeyConfig,
  718. g_szStandAlone,
  719. NULL,
  720. &dwType,
  721. (LPBYTE)&lpPMConfig->dwStandAlone,
  722. &dwcbTemp);
  723. /////////////////////////////////////////////////////////////////////////
  724. //JVP 3/2/2000 START CHANGES
  725. /////////////////////////////////////////////////////////////////////////
  726. // Get Verbose mode setting
  727. dwcbTemp = sizeof(DWORD);
  728. dwType = REG_DWORD;
  729. lpPMConfig->dwVerboseMode = 0; // NOT verbose by default
  730. RegQueryValueEx(hkeyConfig,
  731. g_szVerboseMode,
  732. NULL,
  733. &dwType,
  734. (LPBYTE)&lpPMConfig->dwVerboseMode,
  735. &dwcbTemp);
  736. /////////////////////////////////////////////////////////////////////////
  737. //JVP 3/2/2000 END CHANGES
  738. /////////////////////////////////////////////////////////////////////////
  739. // Get the current environment
  740. dwcbTemp = lpPMConfig->cbEnvName;
  741. dwType = REG_SZ;
  742. lpPMConfig->szEnvName[0] = TEXT('\0'); // Set a default for the current value
  743. RegQueryValueEx(hkeyConfig,
  744. g_szEnvName,
  745. NULL,
  746. &dwType,
  747. (LPBYTE)lpPMConfig->szEnvName,
  748. &dwcbTemp);
  749. // Get the current environment
  750. dwcbTemp = lpPMConfig->cbRemoteFile;
  751. dwType = REG_SZ;
  752. lpPMConfig->szRemoteFile[0] = TEXT('\0'); // Set a default for the current value
  753. RegQueryValueEx(hkeyPartner,
  754. g_szRemoteFile,
  755. NULL,
  756. &dwType,
  757. (LPBYTE)lpPMConfig->szRemoteFile,
  758. &dwcbTemp);
  759. // Get DisableCookies mode setting
  760. dwcbTemp = sizeof(DWORD);
  761. dwType = REG_DWORD;
  762. lpPMConfig->dwDisableCookies = 0; // Cookies ENABLED by default
  763. RegQueryValueEx(hkeyConfig,
  764. g_szDisableCookies,
  765. NULL,
  766. &dwType,
  767. (LPBYTE)&lpPMConfig->dwDisableCookies,
  768. &dwcbTemp);
  769. #ifdef DO_KEYSTUFF
  770. // Get the current encryption key
  771. dwcbTemp = sizeof(DWORD);
  772. dwType = REG_DWORD;
  773. lpPMConfig->dwCurrentKey = 1;
  774. RegQueryValueEx(hkeyConfig,
  775. g_szCurrentKey,
  776. NULL,
  777. &dwType,
  778. (LPBYTE)&lpPMConfig->dwCurrentKey,
  779. &dwcbTemp);
  780. #endif
  781. // For these next two, since they're required for named configs, we need
  782. // to check for too much data and truncate it.
  783. // Get the Host Name
  784. dwcbTemp = lpPMConfig->cbHostName;
  785. dwType = REG_SZ;
  786. lpPMConfig->szHostName[0] = TEXT('\0'); // Set a default for the current value
  787. if(ERROR_MORE_DATA == RegQueryValueEx(hkeyConfig,
  788. g_szHostName,
  789. NULL,
  790. &dwType,
  791. (LPBYTE)lpPMConfig->szHostName,
  792. &dwcbTemp))
  793. {
  794. LPBYTE pb = (LPBYTE)malloc(dwcbTemp);
  795. if(pb)
  796. {
  797. RegQueryValueEx(hkeyConfig,
  798. g_szHostName,
  799. NULL,
  800. &dwType,
  801. pb,
  802. &dwcbTemp);
  803. memcpy(lpPMConfig->szHostName, pb, lpPMConfig->cbHostName);
  804. free(pb);
  805. ReportError(hWndDlg, IDS_HOSTNAMETRUNC_WARN);
  806. }
  807. }
  808. // Get the Host IP
  809. dwcbTemp = lpPMConfig->cbHostIP;
  810. dwType = REG_SZ;
  811. lpPMConfig->szHostIP[0] = TEXT('\0'); // Set a default for the current value
  812. if(ERROR_MORE_DATA == RegQueryValueEx(hkeyConfig,
  813. g_szHostIP,
  814. NULL,
  815. &dwType,
  816. (LPBYTE)lpPMConfig->szHostIP,
  817. &dwcbTemp))
  818. {
  819. LPBYTE pb = (LPBYTE)malloc(dwcbTemp);
  820. if(pb)
  821. {
  822. RegQueryValueEx(hkeyConfig,
  823. g_szHostIP,
  824. NULL,
  825. &dwType,
  826. pb,
  827. &dwcbTemp);
  828. memcpy(lpPMConfig->szHostIP, pb, lpPMConfig->cbHostIP);
  829. free(pb);
  830. ReportError(hWndDlg, IDS_HOSTIPTRUNC_WARN);
  831. }
  832. }
  833. // Query for the secure level setting
  834. dwcbTemp = sizeof(DWORD);
  835. dwType = REG_DWORD;
  836. lpPMConfig->dwSecureLevel = 0; // If this is an existing site then we level set the
  837. // secure level at 0 so that we don't break anyone,
  838. // even though the default for a new site is level 10.
  839. RegQueryValueEx(hkeyConfig,
  840. g_szSecureLevel,
  841. NULL,
  842. &dwType,
  843. (LPBYTE)&lpPMConfig->dwSecureLevel,
  844. &dwcbTemp);
  845. // If we got empty strings for HostName or
  846. // HostIP, and we have a named config it
  847. // means someone's been mucking with
  848. // the registry. Give them a warning and
  849. // return FALSE.
  850. if(lpszConfigSetName && lpszConfigSetName[0] &&
  851. (lpPMConfig->szHostName[0] == TEXT('\0') ||
  852. lpPMConfig->szHostIP[0] == TEXT('\0')))
  853. {
  854. ReportError(hWndDlg, IDS_CONFIGREAD_ERROR);
  855. bReturn = FALSE;
  856. goto Cleanup;
  857. }
  858. bReturn = TRUE;
  859. Cleanup:
  860. if (hkeyConfig && hkeyConfig != hkeyPassport)
  861. RegCloseKey(hkeyConfig);
  862. if (hkeyPassport)
  863. RegCloseKey(hkeyPassport);
  864. if (hkeyConfigSets)
  865. RegCloseKey(hkeyConfigSets);
  866. if (hklm && hklm != HKEY_LOCAL_MACHINE)
  867. RegCloseKey(hklm);
  868. if (hkeyPartner)
  869. RegCloseKey(hkeyPartner);
  870. return bReturn;
  871. }
  872. /**************************************************************************
  873. WriteRegConfigSet
  874. Write the current passport manager config set from the registry
  875. **************************************************************************/
  876. BOOL WriteRegConfigSet
  877. (
  878. HWND hWndDlg,
  879. LPPMSETTINGS lpPMConfig,
  880. LPTSTR lpszRemoteComputer,
  881. LPTSTR lpszConfigSetName
  882. )
  883. {
  884. BOOL bReturn;
  885. HKEY hkeyPassport = NULL; // Regkey where Passport Setting live
  886. HKEY hkeyConfigSets = NULL;
  887. HKEY hkeyPartner = NULL;
  888. HKEY hklm = NULL;
  889. long lRet;
  890. // Open the Passport Regkey ( either locally or remotly
  891. if (lpszRemoteComputer && (TEXT('\0') != lpszRemoteComputer[0]))
  892. {
  893. //
  894. // Attempt to connect to the HKEY_LOCAL_MACHINE of the remote computer.
  895. // If this fails, assume that the computer doesn't exist or doesn't have
  896. // the registry server running.
  897. //
  898. switch (lRet = RegConnectRegistry(lpszRemoteComputer,
  899. HKEY_LOCAL_MACHINE,
  900. &hklm))
  901. {
  902. case ERROR_SUCCESS:
  903. break;
  904. case ERROR_ACCESS_DENIED:
  905. ReportError(hWndDlg, IDS_CONNECTACCESSDENIED);
  906. bReturn = FALSE;
  907. goto Cleanup;
  908. default:
  909. ReportError(hWndDlg, IDS_CONNECTBADNAME);
  910. bReturn = FALSE;
  911. goto Cleanup;
  912. }
  913. }
  914. else
  915. {
  916. hklm = HKEY_LOCAL_MACHINE;
  917. }
  918. // Open the key we want
  919. if(lpszConfigSetName && lpszConfigSetName[0] != TEXT('\0'))
  920. {
  921. hkeyPassport = OpenRegConfigSet(hklm, lpszConfigSetName);
  922. if(hkeyPassport == NULL)
  923. {
  924. ReportError(hWndDlg, IDS_CONFIGREAD_ERROR);
  925. bReturn = FALSE;
  926. goto Cleanup;
  927. }
  928. }
  929. else
  930. {
  931. if (ERROR_SUCCESS != (lRet = RegOpenKeyEx(hklm,
  932. g_szPassportReg,
  933. 0,
  934. KEY_ALL_ACCESS,
  935. &hkeyPassport)))
  936. {
  937. LPVOID lpMsgBuf;
  938. FormatMessage(
  939. FORMAT_MESSAGE_ALLOCATE_BUFFER |
  940. FORMAT_MESSAGE_FROM_SYSTEM |
  941. FORMAT_MESSAGE_IGNORE_INSERTS,
  942. NULL,
  943. lRet,
  944. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  945. (LPTSTR) &lpMsgBuf,
  946. 0,
  947. NULL
  948. );
  949. {
  950. TCHAR pszTitle[MAX_RESOURCE];
  951. // Display the string.
  952. LoadString(g_hInst, IDS_ERROR, pszTitle, DIMENSION(pszTitle));
  953. MessageBox( NULL, (LPCTSTR) lpMsgBuf, pszTitle, MB_OK | MB_ICONINFORMATION );
  954. }
  955. // Free the buffer.
  956. LocalFree( lpMsgBuf );
  957. // ReportError(hWndDlg, IDS_CONFIGREAD_ERROR);
  958. bReturn = FALSE;
  959. goto Cleanup;
  960. }
  961. }
  962. WriteGlobalConfigSettings(hWndDlg, hklm, lpPMConfig, lpszRemoteComputer);
  963. // Open Partner key
  964. if (ERROR_SUCCESS != (lRet = RegOpenKeyEx(hklm,
  965. g_szPassportPartner,
  966. 0,
  967. KEY_ALL_ACCESS,
  968. &hkeyPartner)))
  969. {
  970. LPVOID lpMsgBuf;
  971. if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
  972. FORMAT_MESSAGE_FROM_SYSTEM |
  973. FORMAT_MESSAGE_IGNORE_INSERTS,
  974. NULL,
  975. lRet,
  976. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  977. (LPTSTR) &lpMsgBuf,
  978. 0,
  979. NULL) != 0)
  980. {
  981. TCHAR pszTitle[MAX_RESOURCE];
  982. // Display the string.
  983. LoadString(g_hInst, IDS_ERROR, pszTitle, DIMENSION(pszTitle));
  984. MessageBox( NULL, (LPCTSTR) lpMsgBuf, pszTitle, MB_OK | MB_ICONINFORMATION );
  985. // Free the buffer.
  986. LocalFree( lpMsgBuf );
  987. }
  988. // ReportError(hWndDlg, IDS_CONFIGREAD_ERROR);
  989. bReturn = FALSE;
  990. goto Cleanup;
  991. }
  992. // Write the Time Window Number
  993. RegSetValueEx(hkeyPassport,
  994. g_szTimeWindow,
  995. NULL,
  996. REG_DWORD,
  997. (LPBYTE)&lpPMConfig->dwTimeWindow,
  998. sizeof(DWORD));
  999. // Write the value for Forced Signin
  1000. RegSetValueEx(hkeyPassport,
  1001. g_szForceSignIn,
  1002. NULL,
  1003. REG_DWORD,
  1004. (LPBYTE)&lpPMConfig->dwForceSignIn,
  1005. sizeof(DWORD));
  1006. // Write the default language ID
  1007. RegSetValueEx(hkeyPassport,
  1008. g_szLanguageID,
  1009. NULL,
  1010. REG_DWORD,
  1011. (LPBYTE)&lpPMConfig->dwLanguageID,
  1012. sizeof(DWORD));
  1013. // Write the co-branding template
  1014. RegSetValueEx(hkeyPassport,
  1015. g_szCoBrandTemplate,
  1016. NULL,
  1017. REG_SZ,
  1018. (LPBYTE)lpPMConfig->szCoBrandTemplate,
  1019. (lstrlen(lpPMConfig->szCoBrandTemplate) + 1) * sizeof(TCHAR));
  1020. // Write the SiteID
  1021. RegSetValueEx(hkeyPassport,
  1022. g_szSiteID,
  1023. NULL,
  1024. REG_DWORD,
  1025. (LPBYTE)&lpPMConfig->dwSiteID,
  1026. sizeof(DWORD));
  1027. // Write the return URL template
  1028. RegSetValueEx(hkeyPassport,
  1029. g_szReturnURL,
  1030. NULL,
  1031. REG_SZ,
  1032. (LPBYTE)lpPMConfig->szReturnURL,
  1033. (lstrlen(lpPMConfig->szReturnURL) + 1) * sizeof(TCHAR));
  1034. // Write the ticket cookie domain
  1035. RegSetValueEx(hkeyPassport,
  1036. g_szTicketDomain,
  1037. NULL,
  1038. REG_SZ,
  1039. (LPBYTE)lpPMConfig->szTicketDomain,
  1040. (lstrlen(lpPMConfig->szTicketDomain) + 1) * sizeof(TCHAR));
  1041. // Write the ticket cookie path
  1042. RegSetValueEx(hkeyPassport,
  1043. g_szTicketPath,
  1044. NULL,
  1045. REG_SZ,
  1046. (LPBYTE)lpPMConfig->szTicketPath,
  1047. (lstrlen(lpPMConfig->szTicketPath) + 1) * sizeof(TCHAR));
  1048. // Write the profile cookie domain
  1049. RegSetValueEx(hkeyPassport,
  1050. g_szProfileDomain,
  1051. NULL,
  1052. REG_SZ,
  1053. (LPBYTE)lpPMConfig->szProfileDomain,
  1054. (lstrlen(lpPMConfig->szProfileDomain) + 1) * sizeof(TCHAR));
  1055. // Write the profile cookie path
  1056. RegSetValueEx(hkeyPassport,
  1057. g_szProfilePath,
  1058. NULL,
  1059. REG_SZ,
  1060. (LPBYTE)lpPMConfig->szProfilePath,
  1061. (lstrlen(lpPMConfig->szProfilePath) + 1) * sizeof(TCHAR));
  1062. // Write the secure cookie domain
  1063. RegSetValueEx(hkeyPassport,
  1064. g_szSecureDomain,
  1065. NULL,
  1066. REG_SZ,
  1067. (LPBYTE)lpPMConfig->szSecureDomain,
  1068. (lstrlen(lpPMConfig->szSecureDomain) + 1) * sizeof(TCHAR));
  1069. // Write the secure cookie path
  1070. RegSetValueEx(hkeyPassport,
  1071. g_szSecurePath,
  1072. NULL,
  1073. REG_SZ,
  1074. (LPBYTE)lpPMConfig->szSecurePath,
  1075. (lstrlen(lpPMConfig->szSecurePath) + 1) * sizeof(TCHAR));
  1076. // Write the DisasterURL
  1077. RegSetValueEx(hkeyPassport,
  1078. g_szDisasterURL,
  1079. NULL,
  1080. REG_SZ,
  1081. (LPBYTE)lpPMConfig->szDisasterURL,
  1082. (lstrlen(lpPMConfig->szDisasterURL) + 1) * sizeof(TCHAR));
  1083. // Write Standalone mode setting
  1084. RegSetValueEx(hkeyPassport,
  1085. g_szStandAlone,
  1086. NULL,
  1087. REG_DWORD,
  1088. (LPBYTE)&lpPMConfig->dwStandAlone,
  1089. sizeof(DWORD));
  1090. /////////////////////////////////////////////////////////////////////////
  1091. //JVP 3/2/2000 START CHANGES
  1092. /////////////////////////////////////////////////////////////////////////
  1093. // Write Verbose mode setting
  1094. RegSetValueEx(hkeyPassport,
  1095. g_szVerboseMode,
  1096. NULL,
  1097. REG_DWORD,
  1098. (LPBYTE)&lpPMConfig->dwVerboseMode,
  1099. sizeof(DWORD));
  1100. /////////////////////////////////////////////////////////////////////////
  1101. //JVP 3/2/2000 END CHANGES
  1102. /////////////////////////////////////////////////////////////////////////
  1103. // Write the Partner RemoteFile
  1104. RegSetValueEx(hkeyPartner,
  1105. g_szRemoteFile,
  1106. NULL,
  1107. REG_SZ,
  1108. (LPBYTE)lpPMConfig->szRemoteFile,
  1109. (lstrlen(lpPMConfig->szRemoteFile) + 1) * sizeof(TCHAR));
  1110. // Write Environment RemoteFile
  1111. if (lstrcmp(g_szPMVersion, g_szVersion14) >= 0) // Write EnvName for 1.4 and later
  1112. WriteRegEnv(hWndDlg, lpPMConfig, hklm, lpPMConfig->szEnvName);
  1113. // Write DisableCookies mode setting
  1114. RegSetValueEx(hkeyPassport,
  1115. g_szDisableCookies,
  1116. NULL,
  1117. REG_DWORD,
  1118. (LPBYTE)&lpPMConfig->dwDisableCookies,
  1119. sizeof(DWORD));
  1120. // Only write HostName and HostIP for non-default config sets.
  1121. if(lpszConfigSetName && lpszConfigSetName[0])
  1122. {
  1123. // Write the HostName
  1124. RegSetValueEx(hkeyPassport,
  1125. g_szHostName,
  1126. NULL,
  1127. REG_SZ,
  1128. (LPBYTE)lpPMConfig->szHostName,
  1129. (lstrlen(lpPMConfig->szHostName) + 1) * sizeof(TCHAR));
  1130. // Write the HostIP
  1131. RegSetValueEx(hkeyPassport,
  1132. g_szHostIP,
  1133. NULL,
  1134. REG_SZ,
  1135. (LPBYTE)lpPMConfig->szHostIP,
  1136. (lstrlen(lpPMConfig->szHostIP) + 1) * sizeof(TCHAR));
  1137. }
  1138. // Write the secure level (note this reg value is not exposed through the UI
  1139. // users need to go directly to the registry to edit this value)
  1140. RegSetValueEx(hkeyPassport,
  1141. g_szSecureLevel,
  1142. NULL,
  1143. REG_DWORD,
  1144. (LPBYTE)&lpPMConfig->dwSecureLevel,
  1145. sizeof(DWORD));
  1146. bReturn = TRUE;
  1147. Cleanup:
  1148. if(hklm && hklm != HKEY_LOCAL_MACHINE)
  1149. RegCloseKey(hklm);
  1150. if(hkeyConfigSets)
  1151. RegCloseKey(hkeyConfigSets);
  1152. if(hkeyPassport)
  1153. RegCloseKey(hkeyPassport);
  1154. if(hkeyPartner)
  1155. RegCloseKey(hkeyPartner);
  1156. return bReturn;
  1157. }
  1158. /**************************************************************************
  1159. RemoveRegConfigSet
  1160. Verify that the passed in config set is consistent with the current
  1161. values in the registry.
  1162. **************************************************************************/
  1163. BOOL RemoveRegConfigSet
  1164. (
  1165. HWND hWndDlg,
  1166. LPTSTR lpszRemoteComputer,
  1167. LPTSTR lpszConfigSetName
  1168. )
  1169. {
  1170. BOOL bReturn;
  1171. HKEY hklm = NULL;
  1172. HKEY hkeyPassportConfigSets = NULL;
  1173. long lRet;
  1174. // Can't delete the default configuration set.
  1175. if(lpszConfigSetName == NULL || lpszConfigSetName[0] == TEXT('\0'))
  1176. {
  1177. bReturn = FALSE;
  1178. goto Cleanup;
  1179. }
  1180. // Open the Passport Configuration Sets Regkey ( either locally or remotly
  1181. if (lpszRemoteComputer && (TEXT('\0') != lpszRemoteComputer[0]))
  1182. {
  1183. //
  1184. // Attempt to connect to the HKEY_LOCAL_MACHINE of the remote computer.
  1185. // If this fails, assume that the computer doesn't exist or doesn't have
  1186. // the registry server running.
  1187. //
  1188. switch (RegConnectRegistry(lpszRemoteComputer,
  1189. HKEY_LOCAL_MACHINE,
  1190. &hklm))
  1191. {
  1192. case ERROR_SUCCESS:
  1193. break;
  1194. case ERROR_ACCESS_DENIED:
  1195. ReportError(hWndDlg, IDS_CONNECTACCESSDENIED);
  1196. bReturn = FALSE;
  1197. goto Cleanup;
  1198. default:
  1199. ReportError(hWndDlg, IDS_CONNECTBADNAME);
  1200. bReturn = FALSE;
  1201. goto Cleanup;
  1202. }
  1203. }
  1204. else
  1205. {
  1206. hklm = HKEY_LOCAL_MACHINE;
  1207. }
  1208. // Open the key we want
  1209. if (ERROR_SUCCESS != (lRet = RegOpenKeyEx(hklm,
  1210. REG_PASSPORT_SITES_VALUE,
  1211. 0,
  1212. KEY_ALL_ACCESS,
  1213. &hkeyPassportConfigSets)))
  1214. {
  1215. LPVOID lpMsgBuf;
  1216. if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
  1217. FORMAT_MESSAGE_FROM_SYSTEM |
  1218. FORMAT_MESSAGE_IGNORE_INSERTS,
  1219. NULL,
  1220. lRet,
  1221. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  1222. (LPTSTR) &lpMsgBuf,
  1223. 0,
  1224. NULL) != 0)
  1225. {
  1226. TCHAR pszTitle[MAX_RESOURCE];
  1227. // Display the string.
  1228. LoadString(g_hInst, IDS_ERROR, pszTitle, DIMENSION(pszTitle));
  1229. MessageBox( NULL, (LPCTSTR) lpMsgBuf, pszTitle, MB_OK | MB_ICONINFORMATION );
  1230. // Free the buffer.
  1231. LocalFree( lpMsgBuf );
  1232. }
  1233. // ReportError(hWndDlg, IDS_CONFIGREAD_ERROR);
  1234. bReturn = FALSE;
  1235. goto Cleanup;
  1236. }
  1237. // Delete the config set key
  1238. if (ERROR_SUCCESS != SHDeleteKey(hkeyPassportConfigSets, lpszConfigSetName))
  1239. {
  1240. ReportError(hWndDlg, IDS_CONFIGREAD_ERROR);
  1241. bReturn = FALSE;
  1242. goto Cleanup;
  1243. }
  1244. bReturn = TRUE;
  1245. Cleanup:
  1246. if(hklm && hklm != HKEY_LOCAL_MACHINE)
  1247. RegCloseKey(hklm);
  1248. if(hkeyPassportConfigSets)
  1249. RegCloseKey(hkeyPassportConfigSets);
  1250. return bReturn;
  1251. }
  1252. /**************************************************************************
  1253. VerifyRegConfigSet
  1254. Verify that the passed in config set is consistent with the current
  1255. values in the registry.
  1256. **************************************************************************/
  1257. BOOL VerifyRegConfigSet
  1258. (
  1259. HWND hWndDlg,
  1260. LPPMSETTINGS lpPMConfig,
  1261. LPTSTR lpszRemoteComputer,
  1262. LPTSTR lpszConfigSetName
  1263. )
  1264. {
  1265. BOOL fResult = FALSE;
  1266. PMSETTINGS *pPMCurrent = NULL;
  1267. pPMCurrent = (PMSETTINGS*)LocalAlloc(LMEM_FIXED, sizeof(PMSETTINGS));
  1268. if (NULL == pPMCurrent)
  1269. {
  1270. goto Cleanup;
  1271. }
  1272. InitializePMConfigStruct(pPMCurrent);
  1273. ReadRegConfigSet(hWndDlg, pPMCurrent, lpszRemoteComputer, lpszConfigSetName);
  1274. fResult = (0 == memcmp(pPMCurrent, lpPMConfig, sizeof(PMSETTINGS)));
  1275. Cleanup:
  1276. if (pPMCurrent)
  1277. {
  1278. LocalFree(pPMCurrent);
  1279. }
  1280. return fResult;
  1281. }
  1282. /**************************************************************************
  1283. ReadRegConfigSetNames
  1284. Get back a list of config set names on a local or remote machine.
  1285. Caller is responsible for calling free() on the returned pointer.
  1286. When this function returns TRUE, lppszConfigSetNames will either
  1287. contain NULL or a string containing the NULL delimited config set
  1288. names on the given computer.
  1289. When this function returns FALSE, *lppszConfigSetNames will not
  1290. be modified.
  1291. **************************************************************************/
  1292. BOOL ReadRegConfigSetNames
  1293. (
  1294. HWND hWndDlg,
  1295. LPTSTR lpszRemoteComputer,
  1296. LPTSTR* lppszConfigSetNames
  1297. )
  1298. {
  1299. BOOL bReturn;
  1300. HKEY hklm = NULL;
  1301. HKEY hkeyConfigSets = NULL;
  1302. DWORD dwIndex;
  1303. DWORD dwNumSubKeys;
  1304. DWORD dwMaxKeyNameLen;
  1305. TCHAR achKeyName[MAX_PATH];
  1306. ULONGLONG ullAllocSize;
  1307. LPTSTR lpszConfigSetNames;
  1308. LPTSTR lpszCur;
  1309. // Open the Passport Regkey ( either locally or remotly
  1310. if (lpszRemoteComputer && (TEXT('\0') != lpszRemoteComputer[0]))
  1311. {
  1312. //
  1313. // Attempt to connect to the HKEY_LOCAL_MACHINE of the remote computer.
  1314. // If this fails, assume that the computer doesn't exist or doesn't have
  1315. // the registry server running.
  1316. //
  1317. switch (RegConnectRegistry(lpszRemoteComputer,
  1318. HKEY_LOCAL_MACHINE,
  1319. &hklm))
  1320. {
  1321. case ERROR_SUCCESS:
  1322. break;
  1323. case ERROR_ACCESS_DENIED:
  1324. ReportError(hWndDlg, IDS_CONNECTACCESSDENIED);
  1325. bReturn = FALSE;
  1326. goto Cleanup;
  1327. default:
  1328. ReportError(hWndDlg, IDS_CONNECTBADNAME);
  1329. bReturn = FALSE;
  1330. goto Cleanup;
  1331. }
  1332. }
  1333. else
  1334. {
  1335. hklm = HKEY_LOCAL_MACHINE;
  1336. }
  1337. if (ERROR_SUCCESS != RegOpenKeyEx(hklm,
  1338. REG_PASSPORT_SITES_VALUE,
  1339. 0,
  1340. KEY_ALL_ACCESS,
  1341. &hkeyConfigSets))
  1342. {
  1343. bReturn = FALSE;
  1344. goto Cleanup;
  1345. }
  1346. if (ERROR_SUCCESS != RegQueryInfoKey(hkeyConfigSets,
  1347. NULL,
  1348. NULL,
  1349. NULL,
  1350. &dwNumSubKeys,
  1351. &dwMaxKeyNameLen,
  1352. NULL,
  1353. NULL,
  1354. NULL,
  1355. NULL,
  1356. NULL,
  1357. NULL))
  1358. {
  1359. bReturn = FALSE;
  1360. goto Cleanup;
  1361. }
  1362. //
  1363. // Nothing to do!
  1364. //
  1365. if(dwNumSubKeys == 0)
  1366. {
  1367. bReturn = TRUE;
  1368. *lppszConfigSetNames = NULL;
  1369. goto Cleanup;
  1370. }
  1371. // Too big? BUGBUG - We should make sure we check for this
  1372. // When writing out config sets.
  1373. ullAllocSize = UInt32x32To64(dwNumSubKeys, dwMaxKeyNameLen + 1);
  1374. ullAllocSize = (ullAllocSize+1)*sizeof(TCHAR);
  1375. if(ullAllocSize & 0xFFFFFFFF00000000)
  1376. {
  1377. bReturn = FALSE;
  1378. goto Cleanup;
  1379. }
  1380. // This should allocate more space than we need.
  1381. lpszConfigSetNames = (LPTSTR)malloc(((dwNumSubKeys * (dwMaxKeyNameLen + 1)) + 1) * sizeof(TCHAR));
  1382. if(lpszConfigSetNames == NULL)
  1383. {
  1384. bReturn = FALSE;
  1385. goto Cleanup;
  1386. }
  1387. // Read all names into the buffer. Names are NULL delimited and
  1388. // two NULLs end the entire thing.
  1389. dwIndex = 0;
  1390. lpszCur = lpszConfigSetNames;
  1391. while (ERROR_SUCCESS == RegEnumKey(hkeyConfigSets, dwIndex++, achKeyName, DIMENSION(achKeyName)))
  1392. {
  1393. _tcscpy(lpszCur, achKeyName);
  1394. lpszCur = _tcschr(lpszCur, TEXT('\0')) + 1;
  1395. }
  1396. *lpszCur = TEXT('\0');
  1397. *lppszConfigSetNames = lpszConfigSetNames;
  1398. bReturn = TRUE;
  1399. Cleanup:
  1400. if(hklm)
  1401. RegCloseKey(hklm);
  1402. if(hkeyConfigSets)
  1403. RegCloseKey(hkeyConfigSets);
  1404. return bReturn;
  1405. }
  1406. /**************************************************************************
  1407. WriteRegEnv
  1408. Write the current passport manager env set from the registry
  1409. **************************************************************************/
  1410. BOOL WriteRegEnv
  1411. (
  1412. HWND hWndDlg,
  1413. LPPMSETTINGS lpPMConfig,
  1414. HKEY hklm,
  1415. LPTSTR lpszEnvName
  1416. )
  1417. {
  1418. BOOL bReturn;
  1419. HKEY hkeyEnv = NULL;
  1420. long lRet;
  1421. // Open Env key
  1422. TCHAR szTemp[MAX_RESOURCE];
  1423. wsprintf(szTemp, TEXT("%s\\%s"), g_szPassportEnvironments, lpszEnvName);
  1424. if (ERROR_SUCCESS != (lRet = RegOpenKeyEx(hklm,
  1425. szTemp,
  1426. 0,
  1427. KEY_ALL_ACCESS,
  1428. &hkeyEnv)))
  1429. {
  1430. LPVOID lpMsgBuf;
  1431. FormatMessage(
  1432. FORMAT_MESSAGE_ALLOCATE_BUFFER |
  1433. FORMAT_MESSAGE_FROM_SYSTEM |
  1434. FORMAT_MESSAGE_IGNORE_INSERTS,
  1435. NULL,
  1436. lRet,
  1437. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  1438. (LPTSTR) &lpMsgBuf,
  1439. 0,
  1440. NULL
  1441. );
  1442. {
  1443. TCHAR pszTitle[MAX_RESOURCE];
  1444. // Display the string.
  1445. LoadString(g_hInst, IDS_ERROR, pszTitle, DIMENSION(pszTitle));
  1446. MessageBox( NULL, (LPCTSTR) lpMsgBuf, pszTitle, MB_OK | MB_ICONINFORMATION );
  1447. }
  1448. // Free the buffer.
  1449. LocalFree( lpMsgBuf );
  1450. // ReportError(hWndDlg, IDS_CONFIGREAD_ERROR);
  1451. bReturn = FALSE;
  1452. goto Cleanup;
  1453. }
  1454. // Write the Env RemoteFile
  1455. RegSetValueEx(hkeyEnv,
  1456. g_szRemoteFile,
  1457. NULL,
  1458. REG_SZ,
  1459. (LPBYTE)lpPMConfig->szRemoteFile,
  1460. (lstrlen(lpPMConfig->szRemoteFile) + 1) * sizeof(TCHAR));
  1461. bReturn = TRUE;
  1462. Cleanup:
  1463. REG_CLOSE_KEY_NULL(hkeyEnv);
  1464. return bReturn;
  1465. }
  1466. /**************************************************************************
  1467. ReadRegEnv
  1468. Read the current passport manager env set from the registry
  1469. **************************************************************************/
  1470. BOOL ReadRegRemoteFile
  1471. (
  1472. HWND hWndDlg,
  1473. LPTSTR lpszRemoteFile,
  1474. LPTSTR lpszRemoteComputer,
  1475. LPTSTR lpszEnvName
  1476. )
  1477. {
  1478. BOOL bReturn;
  1479. HKEY hklm = NULL;
  1480. HKEY hkeyEnv = NULL;
  1481. long lRet;
  1482. // Open the Passport Regkey ( either locally or remotly
  1483. if (lpszRemoteComputer && (TEXT('\0') != lpszRemoteComputer[0]))
  1484. {
  1485. //
  1486. // Attempt to connect to the HKEY_LOCAL_MACHINE of the remote computer.
  1487. // If this fails, assume that the computer doesn't exist or doesn't have
  1488. // the registry server running.
  1489. //
  1490. switch (RegConnectRegistry(lpszRemoteComputer,
  1491. HKEY_LOCAL_MACHINE,
  1492. &hklm))
  1493. {
  1494. case ERROR_SUCCESS:
  1495. break;
  1496. case ERROR_ACCESS_DENIED:
  1497. ReportError(hWndDlg, IDS_CONNECTACCESSDENIED);
  1498. bReturn = FALSE;
  1499. goto Cleanup;
  1500. default:
  1501. ReportError(hWndDlg, IDS_CONNECTBADNAME);
  1502. bReturn = FALSE;
  1503. goto Cleanup;
  1504. }
  1505. }
  1506. else
  1507. {
  1508. hklm = HKEY_LOCAL_MACHINE;
  1509. }
  1510. // Open Env key
  1511. TCHAR szTemp[MAX_RESOURCE];
  1512. wsprintf(szTemp, TEXT("%s\\%s"), g_szPassportEnvironments, lpszEnvName);
  1513. if (ERROR_SUCCESS != (lRet = RegOpenKeyEx(hklm,
  1514. szTemp,
  1515. 0,
  1516. KEY_ALL_ACCESS,
  1517. &hkeyEnv)))
  1518. {
  1519. LPVOID lpMsgBuf;
  1520. FormatMessage(
  1521. FORMAT_MESSAGE_ALLOCATE_BUFFER |
  1522. FORMAT_MESSAGE_FROM_SYSTEM |
  1523. FORMAT_MESSAGE_IGNORE_INSERTS,
  1524. NULL,
  1525. lRet,
  1526. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  1527. (LPTSTR) &lpMsgBuf,
  1528. 0,
  1529. NULL
  1530. );
  1531. {
  1532. TCHAR pszTitle[MAX_RESOURCE];
  1533. // Display the string.
  1534. LoadString(g_hInst, IDS_ERROR, pszTitle, DIMENSION(pszTitle));
  1535. MessageBox( NULL, (LPCTSTR) lpMsgBuf, pszTitle, MB_OK | MB_ICONINFORMATION );
  1536. }
  1537. // Free the buffer.
  1538. LocalFree( lpMsgBuf );
  1539. // ReportError(hWndDlg, IDS_CONFIGREAD_ERROR);
  1540. bReturn = FALSE;
  1541. goto Cleanup;
  1542. }
  1543. // Get the current environment
  1544. DWORD dwcbTemp;
  1545. DWORD dwType;
  1546. TCHAR szName[INTERNET_MAX_URL_LENGTH];
  1547. dwcbTemp = sizeof(szName);
  1548. dwType = REG_SZ;
  1549. szName[0] = TEXT('\0'); // Set a default for the current value
  1550. if (ERROR_SUCCESS == RegQueryValueEx(hkeyEnv,
  1551. g_szRemoteFile,
  1552. NULL,
  1553. &dwType,
  1554. (LPBYTE)szName,
  1555. &dwcbTemp))
  1556. {
  1557. lstrcpy(lpszRemoteFile, szName);
  1558. bReturn = TRUE;
  1559. }
  1560. else
  1561. bReturn = FALSE;
  1562. Cleanup:
  1563. REG_CLOSE_KEY_NULL(hklm);
  1564. REG_CLOSE_KEY_NULL(hkeyEnv);
  1565. return bReturn;
  1566. }
  1567. /**************************************************************************
  1568. ReadRegEnv
  1569. Read the current passport manager env set from the registry
  1570. **************************************************************************/
  1571. BOOL ReadRegLocalFile
  1572. (
  1573. HWND hWndDlg,
  1574. LPTSTR lpszRemoteComputer,
  1575. LPTSTR lpszLocalFile
  1576. )
  1577. {
  1578. BOOL bReturn;
  1579. HKEY hklm = NULL;
  1580. HKEY hkeyPartner = NULL;
  1581. long lRet;
  1582. // Open the Passport Regkey ( either locally or remotly
  1583. if (lpszRemoteComputer && (TEXT('\0') != lpszRemoteComputer[0]))
  1584. {
  1585. //
  1586. // Attempt to connect to the HKEY_LOCAL_MACHINE of the remote computer.
  1587. // If this fails, assume that the computer doesn't exist or doesn't have
  1588. // the registry server running.
  1589. //
  1590. switch (RegConnectRegistry(lpszRemoteComputer,
  1591. HKEY_LOCAL_MACHINE,
  1592. &hklm))
  1593. {
  1594. case ERROR_SUCCESS:
  1595. break;
  1596. case ERROR_ACCESS_DENIED:
  1597. ReportError(hWndDlg, IDS_CONNECTACCESSDENIED);
  1598. bReturn = FALSE;
  1599. goto Cleanup;
  1600. default:
  1601. ReportError(hWndDlg, IDS_CONNECTBADNAME);
  1602. bReturn = FALSE;
  1603. goto Cleanup;
  1604. }
  1605. }
  1606. else
  1607. {
  1608. hklm = HKEY_LOCAL_MACHINE;
  1609. }
  1610. // Open Partner key
  1611. if (ERROR_SUCCESS != (lRet = RegOpenKeyEx(hklm,
  1612. g_szPassportPartner,
  1613. 0,
  1614. KEY_ALL_ACCESS,
  1615. &hkeyPartner)))
  1616. {
  1617. LPVOID lpMsgBuf;
  1618. if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
  1619. FORMAT_MESSAGE_FROM_SYSTEM |
  1620. FORMAT_MESSAGE_IGNORE_INSERTS,
  1621. NULL,
  1622. lRet,
  1623. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  1624. (LPTSTR) &lpMsgBuf,
  1625. 0,
  1626. NULL) != 0)
  1627. {
  1628. TCHAR pszTitle[MAX_RESOURCE];
  1629. // Display the string.
  1630. LoadString(g_hInst, IDS_ERROR, pszTitle, DIMENSION(pszTitle));
  1631. MessageBox( NULL, (LPCTSTR) lpMsgBuf, pszTitle, MB_OK | MB_ICONINFORMATION );
  1632. // Free the buffer.
  1633. LocalFree( lpMsgBuf );
  1634. }
  1635. // ReportError(hWndDlg, IDS_CONFIGREAD_ERROR);
  1636. bReturn = FALSE;
  1637. goto Cleanup;
  1638. }
  1639. // Get the current environment
  1640. DWORD dwcbTemp;
  1641. DWORD dwType;
  1642. TCHAR szName[INTERNET_MAX_URL_LENGTH];
  1643. dwcbTemp = sizeof(szName);
  1644. dwType = REG_SZ;
  1645. lpszLocalFile[0] = TEXT('\0'); // Set a default for the current value
  1646. if (ERROR_SUCCESS == RegQueryValueEx(hkeyPartner,
  1647. g_szLocalFile,
  1648. NULL,
  1649. &dwType,
  1650. (LPBYTE)szName,
  1651. &dwcbTemp))
  1652. {
  1653. lstrcpy(lpszLocalFile, szName);
  1654. bReturn = TRUE;
  1655. }
  1656. else
  1657. bReturn = FALSE;
  1658. Cleanup:
  1659. REG_CLOSE_KEY_NULL(hklm);
  1660. REG_CLOSE_KEY_NULL(hkeyPartner);
  1661. return bReturn;
  1662. }