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.

678 lines
19 KiB

  1. /****************************************************************************\
  2. *
  3. * MSLUDLG.C
  4. *
  5. * Updated: Ann McCurdy
  6. * Updated: Mark Hammond (t-markh) 8/98
  7. *
  8. \****************************************************************************/
  9. /*INCLUDES--------------------------------------------------------------------*/
  10. #include "msrating.h"
  11. #include "ratings.h"
  12. #include "mslubase.h"
  13. #include "msluprop.h"
  14. #include "commctrl.h"
  15. #include "commdlg.h"
  16. #include "debug.h"
  17. #include "buffer.h"
  18. #include "picsrule.h"
  19. #include "picsdlg.h" // CPicsDialog
  20. #include "apprdlg.h" // CApprovedSitesDialog
  21. #include "gendlg.h" // CGeneralDialog
  22. #include "advdlg.h" // CAdvancedDialog
  23. #include "introdlg.h" // CIntroDialog
  24. #include "passdlg.h" // CPasswordDialog
  25. #include "chngdlg.h" // CChangePasswordDialog
  26. #include "toffdlg.h" // CTurnOffDialog
  27. #include <shlwapip.h>
  28. #include <shellapi.h>
  29. #include <wininet.h>
  30. #include <contxids.h>
  31. #include <mluisupp.h>
  32. extern array<PICSRulesRatingSystem*> g_arrpPRRS;
  33. extern PICSRulesRatingSystem * g_pPRRS;
  34. extern PICSRulesRatingSystem * g_pApprovedPRRS;
  35. extern HMODULE g_hURLMON,g_hWININET;
  36. extern HANDLE g_HandleGlobalCounter,g_ApprovedSitesHandleGlobalCounter;
  37. extern long g_lGlobalCounterValue,g_lApprovedSitesGlobalCounterValue;
  38. PICSRulesRatingSystem * g_pApprovedPRRSPreApply;
  39. array<PICSRulesRatingSystem*> g_arrpPICSRulesPRRSPreApply;
  40. extern bool IsRegistryModifiable( HWND p_hwndParent );
  41. //The FN_INTERNETCRACKURL type describes the URLMON function InternetCrackUrl
  42. typedef BOOL (*FN_INTERNETCRACKURL)(LPCTSTR lpszUrl,DWORD dwUrlLength,DWORD dwFlags,LPURL_COMPONENTS lpUrlComponents);
  43. #define NUM_PAGES 4
  44. // Initialize the Specialized Common Controls (tree controls, etc.)
  45. void InitializeCommonControls( void )
  46. {
  47. INITCOMMONCONTROLSEX ex;
  48. ex.dwSize = sizeof(ex);
  49. ex.dwICC = ICC_NATIVEFNTCTL_CLASS;
  50. InitCommonControlsEx(&ex);
  51. }
  52. BOOL PicsOptionsDialog( HWND hwnd, PicsRatingSystemInfo * pPRSI, PicsUser * pPU )
  53. {
  54. PropSheet ps;
  55. PRSD *pPRSD;
  56. char pszBuf[MAXPATHLEN];
  57. BOOL fRet = FALSE;
  58. InitializeCommonControls();
  59. MLLoadStringA(IDS_GENERIC, pszBuf, sizeof(pszBuf));
  60. ps.Init( hwnd, NUM_PAGES, pszBuf, TRUE );
  61. pPRSD = new PRSD;
  62. if (!pPRSD) return FALSE;
  63. pPRSD->pPU = pPU;
  64. pPRSD->pTempRatings = NULL;
  65. pPRSD->hwndBitmapCategory = NULL;
  66. pPRSD->hwndBitmapLabel = NULL;
  67. pPRSD->pPRSI = pPRSI;
  68. pPRSD->fNewProviders = FALSE;
  69. HPROPSHEETPAGE hPage;
  70. CPicsDialog picsDialog( pPRSD );
  71. hPage = picsDialog.Create();
  72. ps.MakePropPage( hPage );
  73. CApprovedSitesDialog approvedSitesDialog( pPRSD );
  74. hPage = approvedSitesDialog.Create();
  75. ps.MakePropPage( hPage );
  76. CGeneralDialog generalDialog( pPRSD );
  77. hPage = generalDialog.Create();
  78. ps.MakePropPage( hPage );
  79. CAdvancedDialog advancedDialog( pPRSD );
  80. hPage = advancedDialog.Create();
  81. ps.MakePropPage( hPage );
  82. if ( ps.PropPageCount() == NUM_PAGES )
  83. {
  84. fRet = ps.Run();
  85. }
  86. delete pPRSD;
  87. pPRSD = NULL;
  88. return fRet;
  89. }
  90. INT_PTR DoPasswordConfirm(HWND hDlg)
  91. {
  92. if ( SUCCEEDED( VerifySupervisorPassword() ) )
  93. {
  94. CPasswordDialog passDlg( IDS_PASSWORD_LABEL );
  95. return passDlg.DoModal( hDlg );
  96. }
  97. else
  98. {
  99. CChangePasswordDialog<IDD_CREATE_PASSWORD> createPassDlg;
  100. return createPassDlg.DoModal( hDlg ) ? PASSCONFIRM_NEW : PASSCONFIRM_FAIL;
  101. }
  102. }
  103. #define NO_EXISTING_PASSWORD PASSCONFIRM_NEW
  104. UINT_PTR DoExistingPasswordConfirm(HWND hDlg,BOOL * fExistingPassword)
  105. {
  106. if ( SUCCEEDED( VerifySupervisorPassword() ) )
  107. {
  108. *fExistingPassword=TRUE;
  109. CPasswordDialog passDlg( IDS_PASSWORD_LABEL );
  110. return passDlg.DoModal( hDlg );
  111. }
  112. else
  113. {
  114. *fExistingPassword=FALSE;
  115. return(NO_EXISTING_PASSWORD);
  116. }
  117. }
  118. STDAPI RatingSetupUI(HWND hDlg, LPCSTR pszUsername)
  119. {
  120. BOOL fExistingPassword;
  121. UINT_PTR passConfirm = DoExistingPasswordConfirm(hDlg,&fExistingPassword);
  122. if (passConfirm == PASSCONFIRM_FAIL)
  123. {
  124. TraceMsg( TF_WARNING, "RatingSetupUI() - Failed Existing Password Confirmation!" );
  125. return E_ACCESSDENIED;
  126. }
  127. HRESULT hres = NOERROR;
  128. BOOL fFreshInstall = FALSE;
  129. if (!gPRSI->fRatingInstalled)
  130. {
  131. gPRSI->FreshInstall();
  132. fFreshInstall = TRUE;
  133. }
  134. if ( ! PicsOptionsDialog( hDlg, gPRSI, GetUserObject(pszUsername) ) )
  135. {
  136. /* If we have no saved settings and they cancelled the settings UI, and
  137. * they just entered a new supervisor password, then we need to remove
  138. * the supervisor password too, otherwise it looks like there's been
  139. * tampering. The other option would be to actually commit the
  140. * settings in that case but disable enforcement, but the case we're
  141. * looking to treat here is the casual exploring user who goes past
  142. * entering the password but decides he doesn't want ratings after all.
  143. * If we leave the password and ratings settings there, then he's not
  144. * going to remember what the password was when he decides he does want
  145. * ratings a year from now. Best to just remove the password and let
  146. * him enter and confirm a new one next time.
  147. */
  148. if (fFreshInstall)
  149. {
  150. if (passConfirm == PASSCONFIRM_NEW)
  151. {
  152. RemoveSupervisorPassword();
  153. }
  154. }
  155. TraceMsg( TF_WARNING, "RatingSetupUI() - PicsOptionsDialog() Failed!" );
  156. return E_FAIL;
  157. }
  158. if ( ! IsRegistryModifiable( hDlg ) )
  159. {
  160. TraceMsg( TF_WARNING, "RatingSetupUI() - Registry is Not Modifiable!" );
  161. return E_ACCESSDENIED;
  162. }
  163. if ( FAILED( VerifySupervisorPassword() ) )
  164. {
  165. passConfirm = DoPasswordConfirm(hDlg);
  166. if(passConfirm==PASSCONFIRM_FAIL)
  167. {
  168. TraceMsg( TF_WARNING, "RatingSetupUI() - PicsOptionsDialog() Failed Password Confirmation!" );
  169. gPRSI->fRatingInstalled = FALSE;
  170. return E_FAIL;
  171. }
  172. }
  173. gPRSI->fSettingsValid = TRUE;
  174. gPRSI->SaveRatingSystemInfo();
  175. return NOERROR;
  176. }
  177. CIntroDialog g_introDialog;
  178. STDAPI RatingAddPropertyPages(LPFNADDPROPSHEETPAGE pfnAddPage, LPARAM lparam, DWORD dwPageFlags)
  179. {
  180. HRESULT hr = NOERROR;
  181. ASSERT( pfnAddPage );
  182. if ( ! pfnAddPage )
  183. {
  184. TraceMsg( TF_ERROR, "RatingAddPropertyPages() - pfnAddPage is NULL!" );
  185. return E_INVALIDARG;
  186. }
  187. // Initialize the Property Page DLL Instance
  188. g_introDialog.m_psp.hInstance = MLGetHinst();
  189. HPROPSHEETPAGE hPage;
  190. hPage = g_introDialog.Create();
  191. if ( hPage )
  192. {
  193. if ( ! pfnAddPage( hPage, lparam ) )
  194. {
  195. DestroyPropertySheetPage( hPage );
  196. hr = E_FAIL;
  197. }
  198. }
  199. else
  200. {
  201. hr = E_OUTOFMEMORY;
  202. }
  203. return hr;
  204. }
  205. STDAPI RatingEnable(HWND hwndParent, LPCSTR pszUsername, BOOL fEnable)
  206. {
  207. // Display the Ratings UI if the Ratings are not fully installed or settings are not valid.
  208. if (!gPRSI || !gPRSI->fRatingInstalled || !gPRSI->fSettingsValid)
  209. {
  210. if (!fEnable)
  211. {
  212. TraceMsg( TF_WARNING, "RatingEnable() - Ratings are disabled by not being installed!" );
  213. return NOERROR; /* ratings are disabled by not being installed */
  214. }
  215. HRESULT hres = RatingSetupUI(hwndParent, pszUsername);
  216. /* User clicked "Turn On" but we installed and let him choose his
  217. * settings, so give him friendly confirmation that we set things
  218. * up for him and he can click Settings later to change things
  219. * (therefore implying that he doesn't need to click Settings now).
  220. */
  221. if (SUCCEEDED(hres))
  222. {
  223. MyMessageBox(hwndParent, IDS_NOWENABLED, IDS_ENABLE_WARNING,
  224. IDS_GENERIC, MB_ICONINFORMATION | MB_OK);
  225. }
  226. return hres;
  227. }
  228. if ( ! IsRegistryModifiable( hwndParent ) )
  229. {
  230. TraceMsg( TF_WARNING, "RatingEnable() - Registry is Not Modifiable!" );
  231. return E_ACCESSDENIED;
  232. }
  233. PicsUser *pUser = ::GetUserObject(pszUsername);
  234. if (pUser == NULL)
  235. {
  236. return HRESULT_FROM_WIN32(ERROR_BAD_USERNAME);
  237. }
  238. /* !a == !b to normalize non-zero values */
  239. if (!fEnable == !pUser->fEnabled)
  240. {
  241. return NOERROR; /* already in state caller wants */
  242. }
  243. if (DoPasswordConfirm(hwndParent))
  244. {
  245. PicsUser *pUser = ::GetUserObject();
  246. if (pUser != NULL)
  247. {
  248. pUser->fEnabled = !pUser->fEnabled;
  249. gPRSI->SaveRatingSystemInfo();
  250. if (pUser->fEnabled)
  251. {
  252. MyMessageBox(hwndParent, IDS_NOW_ON, IDS_ENABLE_WARNING,
  253. IDS_GENERIC, MB_OK);
  254. }
  255. else
  256. {
  257. CRegKey keyRatings;
  258. if ( keyRatings.Open( HKEY_LOCAL_MACHINE, szRATINGS ) == ERROR_SUCCESS )
  259. {
  260. DWORD dwFlag;
  261. if ( keyRatings.QueryValue( dwFlag, szTURNOFF ) == ERROR_SUCCESS )
  262. {
  263. if ( dwFlag != 1 )
  264. {
  265. CTurnOffDialog turnOffDialog;
  266. turnOffDialog.DoModal( hwndParent );
  267. }
  268. }
  269. else
  270. {
  271. CTurnOffDialog turnOffDialog;
  272. turnOffDialog.DoModal( hwndParent );
  273. }
  274. }
  275. }
  276. }
  277. return NOERROR;
  278. }
  279. else
  280. {
  281. return E_ACCESSDENIED;
  282. }
  283. }
  284. STDAPI_(int) ClickedOnPRF(HWND hWndOwner,HINSTANCE p_hInstance,PSTR lpszFileName,int nShow)
  285. {
  286. BOOL bExists=FALSE,fPICSRulesSaved=FALSE,fExistingPassword;
  287. int iReplaceInstalled=IDYES;
  288. char szTitle[MAX_PATH],szMessage[MAX_PATH];
  289. PropSheet ps;
  290. PRSD *pPRSD;
  291. char pszBuf[MAXPATHLEN];
  292. BOOL fRet=FALSE;
  293. UINT_PTR passConfirm;
  294. if ( ! IsRegistryModifiable( hWndOwner ) )
  295. {
  296. TraceMsg( TF_WARNING, "ClickedOnPRF() - Registry is Not Modifiable!" );
  297. return E_ACCESSDENIED;
  298. }
  299. InitializeCommonControls();
  300. //Make sure the user wants to do this
  301. if( SUCCEEDED( VerifySupervisorPassword() ) )
  302. {
  303. fExistingPassword=TRUE;
  304. CPasswordDialog passDlg( IDS_PICS_RULES_LABEL, true );
  305. passConfirm = passDlg.DoModal( hWndOwner );
  306. }
  307. else
  308. {
  309. fExistingPassword=FALSE;
  310. CPasswordDialog passDlg( IDS_PICS_RULES_LABEL, false );
  311. passConfirm = passDlg.DoModal( hWndOwner );
  312. }
  313. if(passConfirm==PASSCONFIRM_FAIL)
  314. {
  315. TraceMsg( TF_WARNING, "ClickedOnPRF() - Password Confirmation Failed!" );
  316. return E_ACCESSDENIED;
  317. }
  318. if(fExistingPassword==FALSE)
  319. {
  320. passConfirm=NO_EXISTING_PASSWORD;
  321. }
  322. BOOL fFreshInstall=FALSE;
  323. if(!gPRSI->fRatingInstalled)
  324. {
  325. gPRSI->FreshInstall();
  326. fFreshInstall=TRUE;
  327. }
  328. gPRSI->lpszFileName=lpszFileName;
  329. MLLoadStringA(IDS_GENERIC,pszBuf,sizeof(pszBuf));
  330. ps.Init( hWndOwner, NUM_PAGES, pszBuf, TRUE );
  331. pPRSD=new PRSD;
  332. if (!pPRSD)
  333. {
  334. TraceMsg( TF_ERROR, "ClickedOnPRF() - Failed PRSD Creation!" );
  335. return FALSE;
  336. }
  337. pPRSD->pPU =GetUserObject((LPCTSTR) NULL);
  338. pPRSD->pTempRatings =NULL;
  339. pPRSD->hwndBitmapCategory =NULL;
  340. pPRSD->hwndBitmapLabel =NULL;
  341. pPRSD->pPRSI =gPRSI;
  342. pPRSD->fNewProviders =FALSE;
  343. HPROPSHEETPAGE hPage;
  344. CPicsDialog picsDialog( pPRSD );
  345. hPage = picsDialog.Create();
  346. ps.MakePropPage( hPage );
  347. CApprovedSitesDialog approvedSitesDialog( pPRSD );
  348. hPage = approvedSitesDialog.Create();
  349. ps.MakePropPage( hPage );
  350. CGeneralDialog generalDialog( pPRSD );
  351. hPage = generalDialog.Create();
  352. ps.MakePropPage( hPage );
  353. CAdvancedDialog advancedDialog( pPRSD );
  354. hPage = advancedDialog.Create();
  355. ps.MakePropPage( hPage );
  356. if ( ps.PropPageCount() == NUM_PAGES )
  357. {
  358. if(fExistingPassword==FALSE)
  359. {
  360. picsDialog.InstallDefaultProvider();
  361. picsDialog.PicsDlgSave();
  362. }
  363. ps.SetStartPage( ps.PropPageCount() - 1 );
  364. fRet=ps.Run();
  365. }
  366. delete pPRSD;
  367. pPRSD = NULL;
  368. if(!fRet)
  369. {
  370. // If we have no saved settings and they cancelled the settings UI, and
  371. // they just entered a new supervisor password, then we need to remove
  372. // the supervisor password too, otherwise it looks like there's been
  373. // tampering. The other option would be to actually commit the
  374. // settings in that case but disable enforcement, but the case we're
  375. // looking to treat here is the casual exploring user who goes past
  376. // entering the password but decides he doesn't want ratings after all.
  377. // If we leave the password and ratings settings there, then he's not
  378. // going to remember what the password was when he decides he does want
  379. // ratings a year from now. Best to just remove the password and let
  380. // him enter and confirm a new one next time.
  381. if(fFreshInstall)
  382. {
  383. if(passConfirm==PASSCONFIRM_NEW)
  384. {
  385. RemoveSupervisorPassword();
  386. }
  387. }
  388. return(FALSE);
  389. }
  390. if ( FAILED( VerifySupervisorPassword() ) )
  391. {
  392. passConfirm=DoPasswordConfirm(hWndOwner);
  393. if(passConfirm==PASSCONFIRM_FAIL)
  394. {
  395. gPRSI->fRatingInstalled=FALSE;
  396. return(FALSE);
  397. }
  398. }
  399. gPRSI->fSettingsValid=TRUE;
  400. gPRSI->SaveRatingSystemInfo();
  401. MLLoadString(IDS_PICSRULES_CLICKIMPORTTITLE,(LPTSTR) szTitle,MAX_PATH);
  402. MLLoadString(IDS_PICSRULES_CLICKFINISHED,(LPTSTR) szMessage,MAX_PATH);
  403. MessageBox(hWndOwner,(LPCTSTR) szMessage,(LPCTSTR) szTitle,MB_OK);
  404. return(TRUE);
  405. }
  406. STDAPI_(int) ClickedOnRAT(HWND hWndOwner,HINSTANCE p_hInstance,PSTR lpszFileName,int nShow)
  407. {
  408. BOOL bExists=FALSE,fPICSRulesSaved=FALSE,fExistingPassword;
  409. int iReplaceInstalled=IDYES;
  410. char szTitle[MAX_PATH],szMessage[MAX_PATH],szNewFile[MAX_PATH];
  411. char *lpszFile,*lpszTemp;
  412. PropSheet ps;
  413. PRSD *pPRSD;
  414. char pszBuf[MAXPATHLEN];
  415. BOOL fRet=FALSE;
  416. UINT_PTR passConfirm;
  417. if ( ! IsRegistryModifiable( hWndOwner ) )
  418. {
  419. TraceMsg( TF_WARNING, "ClickedOnRAT() - Registry is Not Modifiable!" );
  420. return E_ACCESSDENIED;
  421. }
  422. InitializeCommonControls();
  423. //Make sure the user wants to do this
  424. if ( SUCCEEDED ( VerifySupervisorPassword() ) )
  425. {
  426. fExistingPassword=TRUE;
  427. CPasswordDialog passDlg( IDS_RATING_SYSTEM_LABEL, true );
  428. passConfirm = passDlg.DoModal( hWndOwner );
  429. }
  430. else
  431. {
  432. fExistingPassword=FALSE;
  433. CPasswordDialog passDlg( IDS_RATING_SYSTEM_LABEL, false );
  434. passConfirm = passDlg.DoModal( hWndOwner );
  435. }
  436. if(passConfirm==PASSCONFIRM_FAIL)
  437. {
  438. TraceMsg( TF_WARNING, "ClickedOnRAT() - Password Confirmation Failed!" );
  439. return E_ACCESSDENIED;
  440. }
  441. if(fExistingPassword==FALSE)
  442. {
  443. passConfirm=NO_EXISTING_PASSWORD;
  444. }
  445. //Copy the file to the windows system directory
  446. GetSystemDirectory(szNewFile,MAX_PATH);
  447. lpszTemp=lpszFileName;
  448. do{
  449. lpszFile=lpszTemp;
  450. }
  451. while((lpszTemp=strchrf(lpszTemp+1,'\\'))!=NULL);
  452. lstrcat(szNewFile,lpszFile);
  453. CopyFile(lpszFileName,szNewFile,FALSE);
  454. BOOL fFreshInstall = FALSE;
  455. if (!gPRSI->fRatingInstalled)
  456. {
  457. gPRSI->FreshInstall();
  458. fFreshInstall = TRUE;
  459. }
  460. gPRSI->lpszFileName=szNewFile;
  461. MLLoadStringA(IDS_GENERIC,pszBuf,sizeof(pszBuf));
  462. ps.Init( hWndOwner, NUM_PAGES, pszBuf, TRUE );
  463. pPRSD=new PRSD;
  464. if (!pPRSD)
  465. {
  466. TraceMsg( TF_ERROR, "ClickedOnRAT() - Failed PRSD Creation!" );
  467. return FALSE;
  468. }
  469. pPRSD->pPU =GetUserObject((LPCTSTR) NULL);
  470. pPRSD->pTempRatings =NULL;
  471. pPRSD->hwndBitmapCategory =NULL;
  472. pPRSD->hwndBitmapLabel =NULL;
  473. pPRSD->pPRSI =gPRSI;
  474. pPRSD->fNewProviders =FALSE;
  475. HPROPSHEETPAGE hPage;
  476. CPicsDialog picsDialog( pPRSD );
  477. hPage = picsDialog.Create();
  478. ps.MakePropPage( hPage );
  479. CApprovedSitesDialog approvedSitesDialog( pPRSD );
  480. hPage = approvedSitesDialog.Create();
  481. ps.MakePropPage( hPage );
  482. CGeneralDialog generalDialog( pPRSD );
  483. hPage = generalDialog.Create();
  484. ps.MakePropPage( hPage );
  485. CAdvancedDialog advancedDialog( pPRSD );
  486. hPage = advancedDialog.Create();
  487. ps.MakePropPage( hPage );
  488. if ( ps.PropPageCount() == NUM_PAGES )
  489. {
  490. if(fExistingPassword==FALSE)
  491. {
  492. picsDialog.InstallDefaultProvider();
  493. picsDialog.PicsDlgSave();
  494. }
  495. ps.SetStartPage( ps.PropPageCount() - 2 );
  496. fRet=ps.Run();
  497. }
  498. delete pPRSD;
  499. pPRSD = NULL;
  500. if(!fRet)
  501. {
  502. // If we have no saved settings and they cancelled the settings UI, and
  503. // they just entered a new supervisor password, then we need to remove
  504. // the supervisor password too, otherwise it looks like there's been
  505. // tampering. The other option would be to actually commit the
  506. // settings in that case but disable enforcement, but the case we're
  507. // looking to treat here is the casual exploring user who goes past
  508. // entering the password but decides he doesn't want ratings after all.
  509. // If we leave the password and ratings settings there, then he's not
  510. // going to remember what the password was when he decides he does want
  511. // ratings a year from now. Best to just remove the password and let
  512. // him enter and confirm a new one next time.
  513. if(fFreshInstall)
  514. {
  515. if(passConfirm==PASSCONFIRM_NEW)
  516. {
  517. RemoveSupervisorPassword();
  518. }
  519. }
  520. return(FALSE);
  521. }
  522. if ( FAILED( VerifySupervisorPassword() ) )
  523. {
  524. passConfirm=DoPasswordConfirm(hWndOwner);
  525. if(passConfirm==PASSCONFIRM_FAIL)
  526. {
  527. gPRSI->fRatingInstalled=FALSE;
  528. return(FALSE);
  529. }
  530. }
  531. gPRSI->fSettingsValid=TRUE;
  532. gPRSI->SaveRatingSystemInfo();
  533. MLLoadString(IDS_PICSRULES_CLICKIMPORTTITLE,(LPTSTR) szTitle,MAX_PATH);
  534. MLLoadString(IDS_PICSRULES_CLICKFINISHED,(LPTSTR) szMessage,MAX_PATH);
  535. MessageBox(hWndOwner,(LPCTSTR) szMessage,(LPCTSTR) szTitle,MB_OK);
  536. return(TRUE);
  537. }