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.

651 lines
16 KiB

  1. /*
  2. * paranoia - For paranoid people
  3. */
  4. #include "tweakui.h"
  5. /*
  6. * OLE.
  7. */
  8. #ifndef BEGIN_INTERFACE
  9. #define BEGIN_INTERFACE
  10. #define END_INTERFACE
  11. #endif
  12. #include <urlhist.h>
  13. #pragma BEGIN_CONST_DATA
  14. KL const c_klParanoia = { &g_hkCUSMWCV, c_tszAppletTweakUI, c_tszParanoia };
  15. KL const c_klAudioPlay = { &c_hkCR, c_tszAudioCDBSShell, 0 };
  16. KL const c_klNoAutorun =
  17. { &g_hkCUSMWCV, c_tszRestrictions, c_tszNoDriveTypeAutoRun };
  18. KL const c_klFault = { &g_hkLMSMWCV, c_tszFault, c_tszLogFile };
  19. KL const c_klHistoryDir = { &g_hkLMSMIE, c_tszMain, c_tszHistoryDir };
  20. KL const c_klLastUser = { &c_hkLM, c_tszNetLogon, c_tszUserName };
  21. KL const c_klNukeUser = { &g_hkLMSMWNTCV, c_tszWinlogon, c_tszDontDisplayLast };
  22. GUID const CLSID_CUrlHistory = {
  23. 0x3C374A40, 0xBAE4, 0x11CF, 0xBF, 0x7D, 0x00, 0xAA, 0x00, 0x69, 0x46, 0xEE
  24. };
  25. IID const IID_IUrlHistoryStg = {
  26. 0x3C374A41, 0xBAE4, 0x11CF, 0xBF, 0x7D, 0x00, 0xAA, 0x00, 0x69, 0x46, 0xEE
  27. };
  28. const static DWORD CODESEG rgdwHelp[] = {
  29. IDC_CLEARGROUP, IDH_GROUP,
  30. IDC_LISTVIEW, IDH_CLEARLV,
  31. IDC_CLEARNOW, IDH_CLEARNOW,
  32. IDC_CDROMGROUP, IDH_GROUP,
  33. IDC_CDROMAUDIO, IDH_CDROMAUDIO,
  34. IDC_CDROMDATA, IDH_CDROMDATA,
  35. IDC_FAULTLOG, IDH_FAULTLOG,
  36. 0, 0,
  37. };
  38. #pragma END_CONST_DATA
  39. /*
  40. * Paranoia flags.
  41. *
  42. * These must be less than 64K because we overload the lParam of
  43. * the checklist structure; if it is above 64K, then it's treated
  44. * as a function.
  45. */
  46. #define pflRun 0x0001
  47. #define pflFindDocs 0x0002
  48. #define pflFindComp 0x0004
  49. #define pflDoc 0x0008
  50. #define pflUrl 0x0010
  51. #define pflNetUse 0x0020
  52. #define pflTelnet 0x0040
  53. #define pflToDisk 0x7FFF /* The flags that get written to disk */
  54. #define pflNukeUser 0x8000 /* Never actually written */
  55. typedef UINT PFL;
  56. typedef PFL (PASCAL *CANCHANGEPROC)(void);
  57. /*****************************************************************************
  58. *
  59. * Paranoia_IsIEInstalled
  60. *
  61. * Returns nonzero if IE3 is installed.
  62. *
  63. *****************************************************************************/
  64. PFL PASCAL
  65. Paranoia_IsIEInstalled(void)
  66. {
  67. if (g_hkCUSMIE) {
  68. return pflUrl;
  69. } else {
  70. return 0;
  71. }
  72. }
  73. /*****************************************************************************
  74. *
  75. * Paranoia_CanNukeUser
  76. *
  77. * Returns nonzero if the user has permission to mess with the
  78. * network logon key.
  79. *
  80. *****************************************************************************/
  81. BOOL PASCAL
  82. Paranoia_CanNukeUser(void)
  83. {
  84. if (RegCanModifyKey(g_hkLMSMWNTCV, c_tszWinlogon)) {
  85. return pflNukeUser;
  86. } else {
  87. return 0;
  88. }
  89. }
  90. /*****************************************************************************
  91. *
  92. * Paranoia_GetPfl
  93. *
  94. * Extract a PFL bit from a PFL. If the corresponding PFL is not
  95. * supported, then return -1.
  96. *
  97. * lParam is the pfl bit to test (or the CANCHANGE function).
  98. *
  99. * pvRef is the pfl value to test.
  100. *
  101. *****************************************************************************/
  102. BOOL PASCAL
  103. Paranoia_GetPfl(LPARAM lParam, LPVOID pvRef)
  104. {
  105. PFL pfl = PtrToUlong(pvRef);
  106. PFL pflTest = (PFL)lParam;
  107. if (HIWORD(lParam)) {
  108. CANCHANGEPROC CanChange = (CANCHANGEPROC)lParam;
  109. pflTest = CanChange();
  110. }
  111. if (pflTest) {
  112. if (pfl & pflTest) {
  113. return 1;
  114. } else {
  115. return 0;
  116. }
  117. } else {
  118. return -1;
  119. }
  120. }
  121. /*****************************************************************************
  122. *
  123. * Paranoia_SetPfl
  124. *
  125. * Set a PFL bit in a PFL.
  126. *
  127. * lParam is the pfl bit to test (or the CANCHANGE function).
  128. *
  129. * pvRef is the pfl value receive the bit.
  130. *
  131. *****************************************************************************/
  132. BOOL PASCAL
  133. Paranoia_SetPfl(BOOL f, LPARAM lParam, LPVOID pvRef)
  134. {
  135. PFL *ppfl = (PFL *)pvRef;
  136. PFL pflTest = (PFL)lParam;
  137. if (HIWORD(lParam)) {
  138. CANCHANGEPROC CanChange = (CANCHANGEPROC)lParam;
  139. pflTest = CanChange();
  140. }
  141. /*
  142. * Note that the right thing happens if pflTest == 0
  143. * (i.e., nothing).
  144. */
  145. if (f) {
  146. *ppfl |= pflTest;
  147. }
  148. return TRUE;
  149. }
  150. #pragma BEGIN_CONST_DATA
  151. /*
  152. * Note that this needs to be in sync with the IDS_PARANOIA
  153. * strings.
  154. */
  155. CHECKLISTITEM c_rgcliParanoia[] = {
  156. { Paranoia_GetPfl, Paranoia_SetPfl, pflRun, },
  157. { Paranoia_GetPfl, Paranoia_SetPfl, pflFindDocs, },
  158. { Paranoia_GetPfl, Paranoia_SetPfl, pflFindComp, },
  159. { Paranoia_GetPfl, Paranoia_SetPfl, pflDoc, },
  160. { Paranoia_GetPfl, Paranoia_SetPfl, (LPARAM)Paranoia_IsIEInstalled, },
  161. { Paranoia_GetPfl, Paranoia_SetPfl, pflNetUse, },
  162. { Paranoia_GetPfl, Paranoia_SetPfl, (LPARAM)Paranoia_CanNukeUser, },
  163. { Paranoia_GetPfl, Paranoia_SetPfl, pflTelnet, },
  164. };
  165. #pragma END_CONST_DATA
  166. /*****************************************************************************
  167. *
  168. * Paranoia_ClearUrl
  169. *
  170. * Clear the IE URL history.
  171. *
  172. *****************************************************************************/
  173. void PASCAL
  174. Paranoia_ClearUrl(void)
  175. {
  176. IUrlHistoryStg *phst;
  177. HRESULT hres;
  178. RegDeleteKey(g_hkCUSMIE, c_tszTypedURLs);
  179. /*
  180. * Also wipe out the MSN URL history.
  181. *
  182. * Note that MSNVIEWER ignores the WM_SETTINGCHANGE message, so
  183. * there is nothing we can do to tell it "Hey, I dorked your regkeys!"
  184. */
  185. RegDeleteKey(c_hkCU, c_tszMSNTypedURLs);
  186. /*
  187. * Tell the IE address bar that its history has been wiped.
  188. *
  189. * Note that this cannot be a SendNotifyMessage since it contains
  190. * a string.
  191. */
  192. SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)c_tszIETypedURLs);
  193. /*
  194. * We yielded during that broadcast. Put the hourglass back.
  195. */
  196. SetCursor(LoadCursor(0, IDC_WAIT));
  197. /*
  198. * Now wipe the history cache.
  199. */
  200. hres = mit.SHCoCreateInstance(0, &CLSID_CUrlHistory, 0, IID_IUrlHistoryStg,
  201. (PPV)&phst);
  202. if (SUCCEEDED(hres)) {
  203. IEnumSTATURL *peurl;
  204. hres = phst->EnumUrls(&peurl);
  205. if (SUCCEEDED(hres)) {
  206. STATURL su;
  207. su.cbSize = cbX(su);
  208. while (peurl->Next(1, &su, 0) == S_OK) {
  209. phst->DeleteUrl(su.pwcsUrl, 0);
  210. Ole_Free(su.pwcsUrl);
  211. if (su.pwcsTitle) {
  212. Ole_Free(su.pwcsTitle);
  213. }
  214. }
  215. Ole_Release(peurl);
  216. }
  217. Ole_Release(phst);
  218. } else {
  219. /*
  220. * Couldn't do it via OLE. Do it by brute force.
  221. */
  222. TCHAR tszPath[MAX_PATH];
  223. GetStrPkl(tszPath, cbX(tszPath), &c_klHistoryDir);
  224. if (tszPath[0]) {
  225. EmptyDirectory(tszPath, 0, 0);
  226. }
  227. }
  228. }
  229. /*****************************************************************************
  230. *
  231. * Paranoia_ClearTelnet
  232. *
  233. * Clear the telnet history.
  234. *
  235. *****************************************************************************/
  236. LPCTSTR c_rgptszValD[] = {
  237. c_tszMachineD, /* Machine1 through Machine8 */
  238. c_tszServiceD, /* Service1 through Service8 */
  239. c_tszTermTypeD, /* TermType1 through TermType8 */
  240. };
  241. void PASCAL
  242. Paranoia_ClearTelnet(void)
  243. {
  244. HKEY hk;
  245. if (_RegOpenKey(HKEY_CURRENT_USER, c_tszTelnet, &hk) == 0) {
  246. int i;
  247. for (i = 1; i <= 8; i++) {
  248. int iptsz;
  249. for (iptsz = 0; iptsz < cA(c_rgptszValD); iptsz++) {
  250. TCHAR tszValue[64];
  251. wsprintf(tszValue, c_rgptszValD[iptsz], i);
  252. RegDeleteValue(hk, tszValue);
  253. }
  254. }
  255. /*
  256. * And then the LastMumble items.
  257. */
  258. RegDeleteValue(hk, c_tszLastMachine);
  259. RegDeleteValue(hk, c_tszLastService);
  260. RegDeleteValue(hk, c_tszLastTermType);
  261. RegCloseKey(hk);
  262. }
  263. }
  264. /*****************************************************************************
  265. *
  266. * Paranoia_ClearNow
  267. *
  268. * Clear the things that the pfl says.
  269. *
  270. * The logon goo is kept in a separate registry key, so we pass it
  271. * separately.
  272. *
  273. * The telnet goo is weird, so we do that separately, too.
  274. *
  275. *****************************************************************************/
  276. void PASCAL
  277. Paranoia_ClearNow(PFL pfl)
  278. {
  279. HCURSOR hcurPrev = GetCursor();
  280. SetCursor(LoadCursor(0, IDC_WAIT));
  281. if (pfl & pflRun) {
  282. RegDeleteValues(pcdii->hkCUExplorer, c_tszRunMRU);
  283. }
  284. if (pfl & pflFindDocs) {
  285. RegDeleteValues(pcdii->hkCUExplorer, c_tszFindDocsMRU);
  286. }
  287. if (pfl & pflFindComp) {
  288. RegDeleteValues(pcdii->hkCUExplorer, c_tszFindCompMRU);
  289. }
  290. if (pfl & pflDoc) {
  291. SHAddToRecentDocs(0, 0);
  292. }
  293. if (pfl & pflUrl) {
  294. if (g_hkCUSMIE && g_hkLMSMIE) {
  295. Paranoia_ClearUrl();
  296. }
  297. }
  298. if (pfl & pflNetUse) {
  299. if (g_fNT) {
  300. RegDeleteValues(hkCU, c_tszNetHistoryNT);
  301. } else {
  302. RegDeleteKey(hkCU, c_tszNetHistory95);
  303. }
  304. }
  305. if (!g_fNT && (pfl & pflNukeUser)) {
  306. DelPkl(&c_klLastUser);
  307. }
  308. if (pfl & pflTelnet) {
  309. Paranoia_ClearTelnet();
  310. }
  311. SetCursor(hcurPrev);
  312. }
  313. /*****************************************************************************
  314. *
  315. * Paranoia_GetDlgPfl
  316. *
  317. * Compute the pfl for the dialog box.
  318. *
  319. *****************************************************************************/
  320. PFL PASCAL
  321. Paranoia_GetDlgPfl(HWND hdlg)
  322. {
  323. PFL pfl;
  324. pfl = 0;
  325. Checklist_OnApply(hdlg, c_rgcliParanoia, &pfl, TRUE);
  326. return pfl;
  327. }
  328. /*****************************************************************************
  329. *
  330. * Paranoia_GetRegPfl
  331. *
  332. * Compute the pfl from the registry.
  333. *
  334. *****************************************************************************/
  335. PFL PASCAL
  336. Paranoia_GetRegPfl(void)
  337. {
  338. PFL pfl;
  339. pfl = GetIntPkl(0, &c_klParanoia);
  340. if (GetIntPkl(0, &c_klNukeUser)) {
  341. pfl |= pflNukeUser;
  342. }
  343. return pfl;
  344. }
  345. /*****************************************************************************
  346. *
  347. * Paranoia_CoverTracks
  348. *
  349. *****************************************************************************/
  350. void PASCAL
  351. Paranoia_CoverTracks(void)
  352. {
  353. Paranoia_ClearNow(Paranoia_GetRegPfl());
  354. }
  355. /*****************************************************************************
  356. *
  357. * Paranoia_OnWhatsThis
  358. *
  359. *****************************************************************************/
  360. void PASCAL
  361. Paranoia_OnWhatsThis(HWND hwnd, int iItem)
  362. {
  363. LV_ITEM lvi;
  364. Misc_LV_GetItemInfo(hwnd, &lvi, iItem, LVIF_PARAM);
  365. WinHelp(hwnd, c_tszMyHelp, HELP_CONTEXTPOPUP,
  366. IDH_CLEARRUN + lvi.lParam);
  367. }
  368. /*****************************************************************************
  369. *
  370. * Paranoia_OnCommand
  371. *
  372. * Ooh, we got a command.
  373. *
  374. *****************************************************************************/
  375. void PASCAL
  376. Paranoia_OnCommand(HWND hdlg, int id, UINT codeNotify)
  377. {
  378. switch (id) {
  379. case IDC_CLEARNOW:
  380. if (codeNotify == BN_CLICKED) {
  381. PFL pfl = Paranoia_GetDlgPfl(hdlg);
  382. if (pfl) {
  383. Paranoia_ClearNow(pfl);
  384. } else {
  385. MessageBoxId(hdlg, IDS_NOTHINGTOCLEAR, g_tszName, MB_OK);
  386. }
  387. }
  388. break;
  389. case IDC_CDROMAUDIO:
  390. case IDC_CDROMDATA:
  391. case IDC_FAULTLOG:
  392. if (codeNotify == BN_CLICKED) Common_SetDirty(hdlg);
  393. break;
  394. }
  395. }
  396. /*****************************************************************************
  397. *
  398. * Paranoia_OnInitDialog
  399. *
  400. * Audio CD play is enabled if HKCR\AudioCD\shell = "play".
  401. *
  402. * Fault logging is disabled on NT.
  403. *
  404. *****************************************************************************/
  405. BOOL PASCAL
  406. Paranoia_OnInitDialog(HWND hwnd)
  407. {
  408. PFL pfl;
  409. HWND hdlg = GetParent(hwnd);
  410. TCHAR tsz[MAX_PATH];
  411. pfl = Paranoia_GetRegPfl();
  412. Checklist_OnInitDialog(hwnd, c_rgcliParanoia, cA(c_rgcliParanoia),
  413. IDS_PARANOIA, IntToPtr(pfl));
  414. GetStrPkl(tsz, cbX(tsz), &c_klAudioPlay);
  415. CheckDlgButton(hdlg, IDC_CDROMAUDIO, tsz[0] ? 1 : 0);
  416. CheckDlgButton(hdlg, IDC_CDROMDATA,
  417. (GetDwordPkl(&c_klNoAutorun, 0) & (1 << DRIVE_CDROM)) ? 0 : 1);
  418. if (g_fNT) {
  419. UINT id;
  420. for (id = IDC_PARANOIA95ONLYMIN; id < IDC_PARANOIA95ONLYMAX; id++) {
  421. ShowWindow(GetDlgItem(hdlg, id), SW_HIDE);
  422. }
  423. } else {
  424. TCHAR tszPath[MAX_PATH];
  425. CheckDlgButton(hdlg, IDC_FAULTLOG,
  426. GetStrPkl(tszPath, cbX(tszPath), &c_klFault));
  427. }
  428. return 1;
  429. }
  430. /*****************************************************************************
  431. *
  432. * Paranoia_OnApply
  433. *
  434. *****************************************************************************/
  435. #pragma BEGIN_CONST_DATA
  436. TCHAR c_tszFaultLog[] = TEXT("FAULTLOG.TXT");
  437. #pragma END_CONST_DATA
  438. void PASCAL
  439. Paranoia_OnApply(HWND hdlg)
  440. {
  441. DWORD fl;
  442. PFL pfl;
  443. pfl = Paranoia_GetDlgPfl(hdlg);
  444. SetIntPkl(pfl & pflToDisk, &c_klParanoia);
  445. SetIntPkl((pfl & pflNukeUser) != 0, &c_klNukeUser);
  446. SetStrPkl(&c_klAudioPlay, IsDlgButtonChecked(hdlg, IDC_CDROMAUDIO)
  447. ? c_tszPlay : c_tszNil);
  448. fl = GetDwordPkl(&c_klNoAutorun, 0) & ~(1 << DRIVE_CDROM);
  449. if (!IsDlgButtonChecked(hdlg, IDC_CDROMDATA)) {
  450. fl |= (1 << DRIVE_CDROM);
  451. }
  452. SetDwordPkl(&c_klNoAutorun, fl);
  453. if (!g_fNT) {
  454. if (IsDlgButtonChecked(hdlg, IDC_FAULTLOG)) {
  455. TCHAR tszPath[MAX_PATH];
  456. GetWindowsDirectory(tszPath, cA(tszPath) - cA(c_tszFaultLog));
  457. lstrcatnBs(tszPath, c_tszFaultLog, cA(tszPath));
  458. SetStrPkl(&c_klFault, tszPath);
  459. } else {
  460. DelPkl(&c_klFault);
  461. }
  462. }
  463. }
  464. #if 0
  465. /*****************************************************************************
  466. *
  467. * Paranoia_OnNotify
  468. *
  469. * Ooh, we got a notification.
  470. *
  471. *****************************************************************************/
  472. BOOL PASCAL
  473. Paranoia_OnNotify(HWND hdlg, NMHDR FAR *pnm)
  474. {
  475. switch (pnm->code) {
  476. case PSN_APPLY:
  477. Paranoia_Apply(hdlg);
  478. break;
  479. }
  480. return 0;
  481. }
  482. /*****************************************************************************
  483. *
  484. * Our window procedure.
  485. *
  486. *****************************************************************************/
  487. /*
  488. * The HANDLE_WM_* macros weren't designed to be used from a dialog
  489. * proc, so we need to handle the messages manually. (But carefully.)
  490. */
  491. BOOL EXPORT
  492. Paranoia_DlgProc(HWND hdlg, UINT wm, WPARAM wParam, LPARAM lParam)
  493. {
  494. switch (wm) {
  495. case WM_INITDIALOG: return Paranoia_OnInitDialog(hdlg);
  496. case WM_COMMAND:
  497. Paranoia_OnCommand(hdlg,
  498. (int)GET_WM_COMMAND_ID(wParam, lParam),
  499. (UINT)GET_WM_COMMAND_CMD(wParam, lParam));
  500. return 0;
  501. case WM_NOTIFY:
  502. return Paranoia_OnNotify(hdlg, (NMHDR FAR *)lParam);
  503. case WM_HELP: Common_OnHelp(lParam, &rgdwHelp[0]); break;
  504. case WM_CONTEXTMENU: Common_OnContextMenu(wParam, &rgdwHelp[0]); break;
  505. default: return 0; /* Unhandled */
  506. }
  507. return 1; /* Handled */
  508. }
  509. #endif
  510. /*****************************************************************************
  511. *
  512. * Oh yeah, we need this too.
  513. *
  514. *****************************************************************************/
  515. #pragma BEGIN_CONST_DATA
  516. LVCI lvciParanoia[] = {
  517. { IDC_WHATSTHIS, Paranoia_OnWhatsThis },
  518. { 0, 0 },
  519. };
  520. LVV lvvParanoia = {
  521. Paranoia_OnCommand,
  522. 0, /* Paranoia_OnInitContextMenu */
  523. 0, /* Paranoia_Dirtify */
  524. 0, /* Paranoia_GetIcon */
  525. Paranoia_OnInitDialog,
  526. Paranoia_OnApply,
  527. 0, /* Paranoia_OnDestroy */
  528. 0, /* Paranoia_OnSelChange */
  529. 5, /* iMenu */
  530. rgdwHelp,
  531. 0, /* Double-click action */
  532. lvvflCanCheck, /* We need check boxes */
  533. lvciParanoia,
  534. };
  535. #pragma END_CONST_DATA
  536. /*****************************************************************************
  537. *
  538. * Our window procedure.
  539. *
  540. *****************************************************************************/
  541. INT_PTR EXPORT
  542. Paranoia_DlgProc(HWND hdlg, UINT wm, WPARAM wParam, LPARAM lParam)
  543. {
  544. return LV_DlgProc(&lvvParanoia, hdlg, wm, wParam, lParam);
  545. }