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.

514 lines
18 KiB

  1. /**************************************************************************
  2. Copyright (C) 1999 Microsoft Corporation. All Rights Reserved.
  3. MODULE: FILECFG.CPP
  4. PURPOSE: Source module reading/writing PM config sets from a file
  5. FUNCTIONS:
  6. COMMENTS:
  7. **************************************************************************/
  8. /**************************************************************************
  9. Include Files
  10. **************************************************************************/
  11. #include "pmcfg.h"
  12. #define MAX_EXT 10
  13. #define MAX_FILTER 256
  14. TCHAR g_szPassportManager[] = TEXT("PassportManager");
  15. /**************************************************************************
  16. PMAdmin_GetFileName
  17. *******************************************************************************/
  18. BOOL PMAdmin_GetFileName
  19. (
  20. HWND hWnd,
  21. BOOL fOpen,
  22. LPTSTR lpFileName,
  23. DWORD cbFileName
  24. )
  25. {
  26. UINT TitleStringID, FilterID;
  27. TCHAR szTitle[MAX_TITLE];
  28. TCHAR szDefaultExtension[MAX_EXT];
  29. TCHAR szFilter[MAX_FILTER];
  30. LPTSTR lpFilterChar;
  31. OPENFILENAME OpenFileName;
  32. BOOL fSuccess;
  33. //
  34. // Load various strings that will be displayed and used by the common open
  35. // or save dialog box. Note that if any of these fail, the error is not
  36. // fatal-- the common dialog box may look odd, but will still work.
  37. //
  38. if (fOpen)
  39. {
  40. TitleStringID = IDS_OPENFILETITLE;
  41. FilterID = IDS_PMOPENFILEFILTER;
  42. }
  43. else
  44. {
  45. TitleStringID = IDS_SAVEFILETITLE;
  46. FilterID = IDS_PMSAVEFILEFILTER;
  47. }
  48. LoadString(g_hInst, TitleStringID, szTitle, DIMENSION(szTitle));
  49. LoadString(g_hInst, IDS_PMCONFIGDEFEXT, szDefaultExtension, DIMENSION(szDefaultExtension));
  50. if (LoadString(g_hInst, FilterID, szFilter, DIMENSION(szFilter)))
  51. {
  52. //
  53. // The common dialog library requires that the substrings of the
  54. // filter string be separated by nulls, but we cannot load a string
  55. // containing nulls. So we use some dummy character in the resource
  56. // that we now convert to nulls.
  57. //
  58. for (lpFilterChar = szFilter;
  59. *lpFilterChar != 0;
  60. lpFilterChar = CharNext(lpFilterChar))
  61. {
  62. if (*lpFilterChar == TEXT('#'))
  63. *lpFilterChar++ = 0;
  64. }
  65. }
  66. ZeroMemory(&OpenFileName, sizeof(OPENFILENAME));
  67. OpenFileName.lStructSize = sizeof(OPENFILENAME);
  68. OpenFileName.hwndOwner = hWnd;
  69. OpenFileName.hInstance = g_hInst;
  70. OpenFileName.lpstrFilter = szFilter;
  71. OpenFileName.lpstrFile = lpFileName;
  72. OpenFileName.nMaxFile = cbFileName;
  73. OpenFileName.lpstrTitle = szTitle;
  74. OpenFileName.lpstrDefExt = szDefaultExtension;
  75. if (fOpen)
  76. {
  77. OpenFileName.Flags = OFN_HIDEREADONLY | OFN_EXPLORER | OFN_FILEMUSTEXIST;
  78. fSuccess = GetOpenFileName(&OpenFileName);
  79. }
  80. else
  81. {
  82. OpenFileName.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT |
  83. OFN_EXPLORER | OFN_NOREADONLYRETURN | OFN_PATHMUSTEXIST;
  84. fSuccess = GetSaveFileName(&OpenFileName);
  85. }
  86. return fSuccess;
  87. }
  88. // prototype of function implemented in regcfg.cpp
  89. BOOL OpenTopRegKey
  90. (
  91. HWND hWndDlg,
  92. LPTSTR lpszRemoteComputer,
  93. HKEY *phklm,
  94. HKEY *phkeyPassport
  95. );
  96. /**************************************************************************
  97. ReadFileConfigSet
  98. Read the current passport manager config set from the specified file
  99. **************************************************************************/
  100. BOOL ReadFileConfigSet
  101. (
  102. LPPMSETTINGS lpPMConfig,
  103. LPCTSTR lpszFileName
  104. )
  105. {
  106. HKEY hklm = 0;
  107. HKEY hkeyPassport = 0;
  108. DWORD dwTemp;
  109. TCHAR achTemp[INTERNET_MAX_URL_LENGTH];
  110. // makesure the specified file exists.
  111. if (!PathFileExists(lpszFileName))
  112. {
  113. ReportError(NULL, IDS_FILENOTFOUND);
  114. return FALSE;
  115. }
  116. // make sure this user can save any changes, if not simply bail
  117. if (!OpenTopRegKey(NULL, g_szRemoteComputer, &hklm, &hkeyPassport))
  118. {
  119. if (hklm && hklm != HKEY_LOCAL_MACHINE)
  120. RegCloseKey(hklm);
  121. return FALSE;
  122. }
  123. RegCloseKey(hkeyPassport);
  124. if (hklm != HKEY_LOCAL_MACHINE)
  125. RegCloseKey(hklm);
  126. // Zero Init the structure
  127. ZeroMemory(lpPMConfig, sizeof(PMSETTINGS));
  128. // Read the Time Window Number
  129. dwTemp = GetPrivateProfileInt(g_szPassportManager,
  130. g_szTimeWindow,
  131. -1,
  132. lpszFileName);
  133. if(dwTemp != -1)
  134. lpPMConfig->dwTimeWindow = dwTemp;
  135. // Read the value for Forced Signin
  136. dwTemp = GetPrivateProfileInt(g_szPassportManager,
  137. g_szForceSignIn,
  138. -1,
  139. lpszFileName);
  140. if(dwTemp != -1)
  141. lpPMConfig->dwForceSignIn = dwTemp;
  142. // Read the value for NSRefresh
  143. dwTemp = GetPrivateProfileInt(g_szPassportManager,
  144. g_szNSRefresh,
  145. -1,
  146. lpszFileName);
  147. if(dwTemp != -1)
  148. lpPMConfig->dwEnableManualRefresh = dwTemp;
  149. // Read the default language ID
  150. dwTemp = GetPrivateProfileInt(g_szPassportManager,
  151. g_szLanguageID,
  152. -1,
  153. lpszFileName);
  154. if(dwTemp != -1)
  155. lpPMConfig->dwLanguageID = dwTemp;
  156. // Get the co-branding template
  157. GetPrivateProfileString(g_szPassportManager,
  158. g_szCoBrandTemplate,
  159. (LPTSTR)TEXT("\xFF"),
  160. achTemp,
  161. DIMENSION(achTemp),
  162. lpszFileName);
  163. if(lstrcmp(achTemp, TEXT("\xFF")) != 0)
  164. lstrcpy(lpPMConfig->szCoBrandTemplate, achTemp);
  165. // Get the SiteID
  166. dwTemp = GetPrivateProfileInt(g_szPassportManager,
  167. g_szSiteID,
  168. -1,
  169. lpszFileName);
  170. if(dwTemp != -1)
  171. lpPMConfig->dwSiteID = dwTemp;
  172. // Get the return URL template
  173. GetPrivateProfileString(g_szPassportManager,
  174. g_szReturnURL,
  175. (LPTSTR)TEXT("\xFF"),
  176. achTemp,
  177. DIMENSION(achTemp),
  178. lpszFileName);
  179. if(lstrcmp(achTemp, TEXT("\xFF")) != 0)
  180. lstrcpy(lpPMConfig->szReturnURL, achTemp);
  181. // Get the ticket cookie domain
  182. GetPrivateProfileString(g_szPassportManager,
  183. g_szTicketDomain,
  184. (LPTSTR)TEXT("\xFF"),
  185. achTemp,
  186. DIMENSION(achTemp),
  187. lpszFileName);
  188. if(lstrcmp(achTemp, TEXT("\xFF")) != 0)
  189. lstrcpy(lpPMConfig->szTicketDomain, achTemp);
  190. // Get the ticket cookie path
  191. GetPrivateProfileString(g_szPassportManager,
  192. g_szTicketPath,
  193. (LPTSTR)TEXT("\xFF"),
  194. achTemp,
  195. DIMENSION(achTemp),
  196. lpszFileName);
  197. if(lstrcmp(achTemp, TEXT("\xFF")) != 0)
  198. lstrcpy(lpPMConfig->szTicketPath, achTemp);
  199. // Get the profile cookie domain
  200. GetPrivateProfileString(g_szPassportManager,
  201. g_szProfileDomain,
  202. (LPTSTR)TEXT("\xFF"),
  203. achTemp,
  204. DIMENSION(achTemp),
  205. lpszFileName);
  206. if(lstrcmp(achTemp, TEXT("\xFF")) != 0)
  207. lstrcpy(lpPMConfig->szProfileDomain, achTemp);
  208. // Get the profile cookie path
  209. GetPrivateProfileString(g_szPassportManager,
  210. g_szProfilePath,
  211. (LPTSTR)TEXT("\xFF"),
  212. achTemp,
  213. DIMENSION(achTemp),
  214. lpszFileName);
  215. if(lstrcmp(achTemp, TEXT("\xFF")) != 0)
  216. lstrcpy(lpPMConfig->szProfilePath, achTemp);
  217. // Get the secure cookie domain
  218. GetPrivateProfileString(g_szPassportManager,
  219. g_szSecureDomain,
  220. (LPTSTR)TEXT("\xFF"),
  221. achTemp,
  222. DIMENSION(achTemp),
  223. lpszFileName);
  224. if(lstrcmp(achTemp, TEXT("\xFF")) != 0)
  225. lstrcpy(lpPMConfig->szSecureDomain, achTemp);
  226. // Get the secure cookie path
  227. GetPrivateProfileString(g_szPassportManager,
  228. g_szSecurePath,
  229. (LPTSTR)TEXT("\xFF"),
  230. achTemp,
  231. DIMENSION(achTemp),
  232. lpszFileName);
  233. if(lstrcmp(achTemp, TEXT("\xFF")) != 0)
  234. lstrcpy(lpPMConfig->szSecurePath, achTemp);
  235. // Get the DisasterURL
  236. GetPrivateProfileString(g_szPassportManager,
  237. g_szDisasterURL,
  238. (LPTSTR)TEXT("\xFF"),
  239. achTemp,
  240. DIMENSION(achTemp),
  241. lpszFileName);
  242. if(lstrcmp(achTemp, TEXT("\xFF")) != 0)
  243. lstrcpy(lpPMConfig->szDisasterURL, achTemp);
  244. // Get Standalone mode setting
  245. dwTemp = GetPrivateProfileInt(g_szPassportManager,
  246. g_szStandAlone,
  247. -1,
  248. lpszFileName);
  249. if(dwTemp != -1)
  250. lpPMConfig->dwStandAlone = dwTemp;
  251. // Get DisableCookies mode setting
  252. dwTemp = GetPrivateProfileInt(g_szPassportManager,
  253. g_szDisableCookies,
  254. -1,
  255. lpszFileName);
  256. if(dwTemp != -1)
  257. lpPMConfig->dwDisableCookies = dwTemp;
  258. // Get the HostName
  259. GetPrivateProfileString(g_szPassportManager,
  260. g_szHostName,
  261. (LPTSTR)TEXT("\xFF"),
  262. achTemp,
  263. DIMENSION(achTemp),
  264. lpszFileName);
  265. if(lstrcmp(achTemp, TEXT("\xFF")) != 0)
  266. lstrcpyn(lpPMConfig->szHostName, achTemp, DIMENSION(lpPMConfig->szHostName));
  267. // Get the HostIP
  268. GetPrivateProfileString(g_szPassportManager,
  269. g_szHostIP,
  270. (LPTSTR)TEXT("\xFF"),
  271. achTemp,
  272. DIMENSION(achTemp),
  273. lpszFileName);
  274. if(lstrcmp(achTemp, TEXT("\xFF")) != 0)
  275. lstrcpyn(lpPMConfig->szHostIP, achTemp, DIMENSION(lpPMConfig->szHostIP));
  276. // Get the Verbose Mode
  277. dwTemp = GetPrivateProfileInt(g_szPassportManager,
  278. g_szVerboseMode,
  279. -1,
  280. lpszFileName);
  281. if(dwTemp != -1)
  282. lpPMConfig->dwVerboseMode = dwTemp;
  283. // Get the EnvName
  284. GetPrivateProfileString(g_szPassportManager,
  285. g_szEnvName,
  286. (LPTSTR)TEXT("\xFF"),
  287. achTemp,
  288. DIMENSION(achTemp),
  289. lpszFileName);
  290. if(lstrcmp(achTemp, TEXT("\xFF")) != 0)
  291. lstrcpyn(lpPMConfig->szEnvName, achTemp, DIMENSION(lpPMConfig->szEnvName));
  292. // Get the RemoteFile
  293. GetPrivateProfileString(g_szPassportManager,
  294. g_szRemoteFile,
  295. (LPTSTR)TEXT("\xFF"),
  296. achTemp,
  297. DIMENSION(achTemp),
  298. lpszFileName);
  299. if(lstrcmp(achTemp, TEXT("\xFF")) != 0)
  300. lstrcpy(lpPMConfig->szRemoteFile, achTemp);
  301. return TRUE;
  302. }
  303. /**************************************************************************
  304. WriteFileConfigSet
  305. Writes the current passport manager config set to the specified file
  306. **************************************************************************/
  307. BOOL WriteFileConfigSet
  308. (
  309. LPPMSETTINGS lpPMConfig,
  310. LPCTSTR lpszFileName
  311. )
  312. {
  313. TCHAR szTemp[MAX_PATH];
  314. // Write the Time Window Number
  315. wsprintf (szTemp, TEXT("%lu"), lpPMConfig->dwTimeWindow);
  316. WritePrivateProfileString(g_szPassportManager,
  317. g_szTimeWindow,
  318. szTemp,
  319. lpszFileName);
  320. // write the value for Forced Signin
  321. wsprintf (szTemp, TEXT("%lu"), lpPMConfig->dwForceSignIn);
  322. WritePrivateProfileString(g_szPassportManager,
  323. g_szForceSignIn,
  324. szTemp,
  325. lpszFileName);
  326. // write the value for NSRefresh
  327. wsprintf (szTemp, TEXT("%lu"), lpPMConfig->dwEnableManualRefresh);
  328. WritePrivateProfileString(g_szPassportManager,
  329. g_szNSRefresh,
  330. szTemp,
  331. lpszFileName);
  332. // Read the default language ID
  333. wsprintf (szTemp, TEXT("%lu"), lpPMConfig->dwLanguageID);
  334. WritePrivateProfileString(g_szPassportManager,
  335. g_szLanguageID,
  336. szTemp,
  337. lpszFileName);
  338. // Write the co-branding template
  339. WritePrivateProfileString(g_szPassportManager,
  340. g_szCoBrandTemplate,
  341. lpPMConfig->szCoBrandTemplate,
  342. lpszFileName);
  343. // Write the SiteID
  344. wsprintf (szTemp, TEXT("%lu"),lpPMConfig->dwSiteID);
  345. WritePrivateProfileString(g_szPassportManager,
  346. g_szSiteID,
  347. szTemp,
  348. lpszFileName);
  349. // Write the return URL template
  350. WritePrivateProfileString(g_szPassportManager,
  351. g_szReturnURL,
  352. lpPMConfig->szReturnURL,
  353. lpszFileName);
  354. // Write the ticket cookie domain
  355. WritePrivateProfileString(g_szPassportManager,
  356. g_szTicketDomain,
  357. lpPMConfig->szTicketDomain,
  358. lpszFileName);
  359. // Write the ticket cookie path
  360. WritePrivateProfileString(g_szPassportManager,
  361. g_szTicketPath,
  362. lpPMConfig->szTicketPath,
  363. lpszFileName);
  364. // Write the profile cookie domain
  365. WritePrivateProfileString(g_szPassportManager,
  366. g_szProfileDomain,
  367. lpPMConfig->szProfileDomain,
  368. lpszFileName);
  369. // Write the profile cookie path
  370. WritePrivateProfileString(g_szPassportManager,
  371. g_szProfilePath,
  372. lpPMConfig->szProfilePath,
  373. lpszFileName);
  374. // Write the secure cookie domain
  375. WritePrivateProfileString(g_szPassportManager,
  376. g_szSecureDomain,
  377. lpPMConfig->szSecureDomain,
  378. lpszFileName);
  379. // Write the secure profile cookie path
  380. WritePrivateProfileString(g_szPassportManager,
  381. g_szSecurePath,
  382. lpPMConfig->szSecurePath,
  383. lpszFileName);
  384. // Write the Disaster URL
  385. WritePrivateProfileString(g_szPassportManager,
  386. g_szDisasterURL,
  387. lpPMConfig->szDisasterURL,
  388. lpszFileName);
  389. // Write Standalone mode setting
  390. wsprintf (szTemp, TEXT("%lu"), lpPMConfig->dwStandAlone);
  391. WritePrivateProfileString(g_szPassportManager,
  392. g_szStandAlone,
  393. szTemp,
  394. lpszFileName);
  395. // Write DisableCookies mode setting
  396. wsprintf (szTemp, TEXT("%lu"), lpPMConfig->dwDisableCookies);
  397. WritePrivateProfileString(g_szPassportManager,
  398. g_szDisableCookies,
  399. szTemp,
  400. lpszFileName);
  401. // Write the Host Name
  402. WritePrivateProfileString(g_szPassportManager,
  403. g_szHostName,
  404. lpPMConfig->szHostName,
  405. lpszFileName);
  406. // Write the Host IP
  407. WritePrivateProfileString(g_szPassportManager,
  408. g_szHostIP,
  409. lpPMConfig->szHostIP,
  410. lpszFileName);
  411. // Write the Verbose Mode
  412. wsprintf (szTemp, TEXT("%lu"), lpPMConfig->dwVerboseMode);
  413. WritePrivateProfileString(g_szPassportManager,
  414. g_szVerboseMode,
  415. szTemp,
  416. lpszFileName);
  417. // Write the EnvName
  418. WritePrivateProfileString(g_szPassportManager,
  419. g_szEnvName,
  420. lpPMConfig->szEnvName,
  421. lpszFileName);
  422. // Write the RemoteFile
  423. WritePrivateProfileString(g_szPassportManager,
  424. g_szRemoteFile,
  425. lpPMConfig->szRemoteFile,
  426. lpszFileName);
  427. return TRUE;
  428. }