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.

418 lines
14 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[] = "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, sizeof(szTitle));
  49. LoadString(g_hInst, IDS_PMCONFIGDEFEXT, szDefaultExtension, sizeof(szDefaultExtension));
  50. if (LoadString(g_hInst, FilterID, szFilter, sizeof(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. /**************************************************************************
  89. ReadFileConfigSet
  90. Read the current passport manager config set from the specified file
  91. **************************************************************************/
  92. BOOL ReadFileConfigSet
  93. (
  94. LPPMSETTINGS lpPMConfig,
  95. LPCTSTR lpszFileName
  96. )
  97. {
  98. DWORD dwTemp;
  99. TCHAR achTemp[INTERNET_MAX_URL_LENGTH];
  100. // makesure the specified file exists.
  101. if (!PathFileExists(lpszFileName))
  102. {
  103. ReportError(NULL, IDS_FILENOTFOUND);
  104. return FALSE;
  105. }
  106. // Read the Time Window Number
  107. dwTemp = GetPrivateProfileInt(g_szPassportManager,
  108. g_szTimeWindow,
  109. -1,
  110. lpszFileName);
  111. if(dwTemp != -1)
  112. lpPMConfig->dwTimeWindow = dwTemp;
  113. // Read the value for Forced Signin
  114. dwTemp = GetPrivateProfileInt(g_szPassportManager,
  115. g_szForceSignIn,
  116. -1,
  117. lpszFileName);
  118. if(dwTemp != -1)
  119. lpPMConfig->dwForceSignIn = dwTemp;
  120. // Read the default language ID
  121. dwTemp = GetPrivateProfileInt(g_szPassportManager,
  122. g_szLanguageID,
  123. -1,
  124. lpszFileName);
  125. if(dwTemp != -1)
  126. lpPMConfig->dwLanguageID = dwTemp;
  127. // Get the co-branding template
  128. GetPrivateProfileString(g_szPassportManager,
  129. g_szCoBrandTemplate,
  130. (LPTSTR)TEXT("\xFF"),
  131. achTemp,
  132. sizeof(achTemp),
  133. lpszFileName);
  134. if(lstrcmp(achTemp, TEXT("\xFF")) != 0)
  135. lstrcpy(lpPMConfig->szCoBrandTemplate, achTemp);
  136. // Get the SiteID
  137. dwTemp = GetPrivateProfileInt(g_szPassportManager,
  138. g_szSiteID,
  139. -1,
  140. lpszFileName);
  141. if(dwTemp != -1)
  142. lpPMConfig->dwSiteID = dwTemp;
  143. // Get the return URL template
  144. GetPrivateProfileString(g_szPassportManager,
  145. g_szReturnURL,
  146. (LPTSTR)TEXT("\xFF"),
  147. achTemp,
  148. sizeof(achTemp),
  149. lpszFileName);
  150. if(lstrcmp(achTemp, TEXT("\xFF")) != 0)
  151. lstrcpy(lpPMConfig->szReturnURL, achTemp);
  152. // Get the ticket cookie domain
  153. GetPrivateProfileString(g_szPassportManager,
  154. g_szTicketDomain,
  155. (LPTSTR)TEXT("\xFF"),
  156. achTemp,
  157. sizeof(achTemp),
  158. lpszFileName);
  159. if(lstrcmp(achTemp, TEXT("\xFF")) != 0)
  160. lstrcpy(lpPMConfig->szTicketDomain, achTemp);
  161. // Get the ticket cookie path
  162. GetPrivateProfileString(g_szPassportManager,
  163. g_szTicketPath,
  164. (LPTSTR)TEXT("\xFF"),
  165. achTemp,
  166. sizeof(achTemp),
  167. lpszFileName);
  168. if(lstrcmp(achTemp, TEXT("\xFF")) != 0)
  169. lstrcpy(lpPMConfig->szTicketPath, achTemp);
  170. // Get the profile cookie domain
  171. GetPrivateProfileString(g_szPassportManager,
  172. g_szProfileDomain,
  173. (LPTSTR)TEXT("\xFF"),
  174. achTemp,
  175. sizeof(achTemp),
  176. lpszFileName);
  177. if(lstrcmp(achTemp, TEXT("\xFF")) != 0)
  178. lstrcpy(lpPMConfig->szProfileDomain, achTemp);
  179. // Get the profile cookie path
  180. GetPrivateProfileString(g_szPassportManager,
  181. g_szProfilePath,
  182. (LPTSTR)TEXT("\xFF"),
  183. achTemp,
  184. sizeof(achTemp),
  185. lpszFileName);
  186. if(lstrcmp(achTemp, TEXT("\xFF")) != 0)
  187. lstrcpy(lpPMConfig->szProfilePath, achTemp);
  188. // Get the secure cookie domain
  189. GetPrivateProfileString(g_szPassportManager,
  190. g_szSecureDomain,
  191. (LPTSTR)TEXT("\xFF"),
  192. achTemp,
  193. sizeof(achTemp),
  194. lpszFileName);
  195. if(lstrcmp(achTemp, TEXT("\xFF")) != 0)
  196. lstrcpy(lpPMConfig->szSecureDomain, achTemp);
  197. // Get the secure cookie path
  198. GetPrivateProfileString(g_szPassportManager,
  199. g_szSecurePath,
  200. (LPTSTR)TEXT("\xFF"),
  201. achTemp,
  202. sizeof(achTemp),
  203. lpszFileName);
  204. if(lstrcmp(achTemp, TEXT("\xFF")) != 0)
  205. lstrcpy(lpPMConfig->szSecurePath, achTemp);
  206. // Get the DisasterURL
  207. GetPrivateProfileString(g_szPassportManager,
  208. g_szDisasterURL,
  209. (LPTSTR)TEXT("\xFF"),
  210. achTemp,
  211. sizeof(achTemp),
  212. lpszFileName);
  213. if(lstrcmp(achTemp, TEXT("\xFF")) != 0)
  214. lstrcpy(lpPMConfig->szDisasterURL, achTemp);
  215. // Get Standalone mode setting
  216. dwTemp = GetPrivateProfileInt(g_szPassportManager,
  217. g_szStandAlone,
  218. -1,
  219. lpszFileName);
  220. if(dwTemp != -1)
  221. lpPMConfig->dwStandAlone = dwTemp;
  222. // Get DisableCookies mode setting
  223. dwTemp = GetPrivateProfileInt(g_szPassportManager,
  224. g_szDisableCookies,
  225. -1,
  226. lpszFileName);
  227. if(dwTemp != -1)
  228. lpPMConfig->dwDisableCookies = dwTemp;
  229. // Get the HostName
  230. GetPrivateProfileString(g_szPassportManager,
  231. g_szHostName,
  232. (LPTSTR)TEXT("\xFF"),
  233. achTemp,
  234. sizeof(achTemp),
  235. lpszFileName);
  236. if(lstrcmp(achTemp, TEXT("\xFF")) != 0)
  237. lstrcpy(lpPMConfig->szHostName, achTemp);
  238. // Get the HostIP
  239. GetPrivateProfileString(g_szPassportManager,
  240. g_szHostIP,
  241. (LPTSTR)TEXT("\xFF"),
  242. achTemp,
  243. sizeof(achTemp),
  244. lpszFileName);
  245. if(lstrcmp(achTemp, TEXT("\xFF")) != 0)
  246. lstrcpy(lpPMConfig->szHostIP, achTemp);
  247. return TRUE;
  248. }
  249. /**************************************************************************
  250. WriteFileConfigSet
  251. Writes the current passport manager config set to the specified file
  252. **************************************************************************/
  253. BOOL WriteFileConfigSet
  254. (
  255. LPPMSETTINGS lpPMConfig,
  256. LPCTSTR lpszFileName
  257. )
  258. {
  259. TCHAR szTemp[MAX_PATH];
  260. // Write the Time Window Number
  261. wsprintf (szTemp, "%d", lpPMConfig->dwTimeWindow);
  262. WritePrivateProfileString(g_szPassportManager,
  263. g_szTimeWindow,
  264. szTemp,
  265. lpszFileName);
  266. // write the value for Forced Signin
  267. wsprintf (szTemp, "%d", lpPMConfig->dwForceSignIn);
  268. WritePrivateProfileString(g_szPassportManager,
  269. g_szForceSignIn,
  270. szTemp,
  271. lpszFileName);
  272. // Read the default language ID
  273. wsprintf (szTemp, "%d", lpPMConfig->dwLanguageID);
  274. WritePrivateProfileString(g_szPassportManager,
  275. g_szLanguageID,
  276. szTemp,
  277. lpszFileName);
  278. // Write the co-branding template
  279. WritePrivateProfileString(g_szPassportManager,
  280. g_szCoBrandTemplate,
  281. lpPMConfig->szCoBrandTemplate,
  282. lpszFileName);
  283. // Write the SiteID
  284. wsprintf (szTemp, "%d",lpPMConfig->dwSiteID);
  285. WritePrivateProfileString(g_szPassportManager,
  286. g_szSiteID,
  287. szTemp,
  288. lpszFileName);
  289. // Write the return URL template
  290. WritePrivateProfileString(g_szPassportManager,
  291. g_szReturnURL,
  292. lpPMConfig->szReturnURL,
  293. lpszFileName);
  294. // Write the ticket cookie domain
  295. WritePrivateProfileString(g_szPassportManager,
  296. g_szTicketDomain,
  297. lpPMConfig->szTicketDomain,
  298. lpszFileName);
  299. // Write the ticket cookie path
  300. WritePrivateProfileString(g_szPassportManager,
  301. g_szTicketPath,
  302. lpPMConfig->szTicketPath,
  303. lpszFileName);
  304. // Write the profile cookie domain
  305. WritePrivateProfileString(g_szPassportManager,
  306. g_szProfileDomain,
  307. lpPMConfig->szProfileDomain,
  308. lpszFileName);
  309. // Write the profile cookie path
  310. WritePrivateProfileString(g_szPassportManager,
  311. g_szProfilePath,
  312. lpPMConfig->szProfilePath,
  313. lpszFileName);
  314. // Write the secure cookie domain
  315. WritePrivateProfileString(g_szPassportManager,
  316. g_szSecureDomain,
  317. lpPMConfig->szSecureDomain,
  318. lpszFileName);
  319. // Write the secure profile cookie path
  320. WritePrivateProfileString(g_szPassportManager,
  321. g_szSecurePath,
  322. lpPMConfig->szSecurePath,
  323. lpszFileName);
  324. // Write the Disaster URL
  325. WritePrivateProfileString(g_szPassportManager,
  326. g_szDisasterURL,
  327. lpPMConfig->szDisasterURL,
  328. lpszFileName);
  329. // Write Standalone mode setting
  330. wsprintf (szTemp, "%d", lpPMConfig->dwStandAlone);
  331. WritePrivateProfileString(g_szPassportManager,
  332. g_szStandAlone,
  333. szTemp,
  334. lpszFileName);
  335. // Write DisableCookies mode setting
  336. wsprintf (szTemp, "%d", lpPMConfig->dwDisableCookies);
  337. WritePrivateProfileString(g_szPassportManager,
  338. g_szDisableCookies,
  339. szTemp,
  340. lpszFileName);
  341. // Write the Host Name
  342. WritePrivateProfileString(g_szPassportManager,
  343. g_szHostName,
  344. lpPMConfig->szHostName,
  345. lpszFileName);
  346. // Write the Host IP
  347. WritePrivateProfileString(g_szPassportManager,
  348. g_szHostIP,
  349. lpPMConfig->szHostIP,
  350. lpszFileName);
  351. return TRUE;
  352. }