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.

958 lines
28 KiB

  1. //--------------------------------------------------------------------------------
  2. //
  3. // File: sigtab.cpp
  4. //
  5. // General handling of OLE Entry points, CClassFactory and CPropSheetExt
  6. //
  7. // Common Code for all display property sheet extension
  8. //
  9. // Copyright (c) Microsoft Corp. 1992-1998 All Rights Reserved
  10. //
  11. //--------------------------------------------------------------------------------
  12. #include "sigtab.h"
  13. //---------------------------------------------------------------------------
  14. // Globals
  15. //---------------------------------------------------------------------------
  16. //
  17. // Count number of objects and number of locks.
  18. //
  19. HINSTANCE g_hInst = NULL;
  20. LPDATAOBJECT g_lpdoTarget = NULL;
  21. ULONG g_cObj = 0;
  22. ULONG g_cLock = 0;
  23. DEFINE_GUID(g_CLSID_SigTab, /* 95b2ac50-840c-11d2-aeaf-0020afe7266d */
  24. 0x95b2ac50,0x840c,0x11d2,0xae,0xaf,0x00,0x20,0xaf,0xe7,0x26,0x6d);
  25. //---------------------------------------------------------------------------
  26. // DllMain()
  27. //---------------------------------------------------------------------------
  28. int APIENTRY DllMain( HINSTANCE hInstance, DWORD dwReason, LPVOID )
  29. {
  30. if ( dwReason == DLL_PROCESS_ATTACH ) { // Initializing
  31. g_hInst = hInstance;
  32. DisableThreadLibraryCalls(hInstance);
  33. }
  34. return 1;
  35. }
  36. //---------------------------------------------------------------------------
  37. // DllGetClassObject()
  38. //
  39. // If someone calls with our CLSID, create an IClassFactory and pass it to
  40. // them, so they can create and use one of our CPropSheetExt objects.
  41. //
  42. //---------------------------------------------------------------------------
  43. STDAPI DllGetClassObject( REFCLSID rclsid, REFIID riid, LPVOID* ppvOut )
  44. {
  45. *ppvOut = NULL; // Assume Failure
  46. if ( IsEqualCLSID( rclsid, g_CLSID_SigTab ) ) {
  47. //
  48. //Check that we can provide the interface
  49. //
  50. if ( IsEqualIID( riid, IID_IUnknown) ||
  51. IsEqualIID( riid, IID_IClassFactory )
  52. ) {
  53. //Return our IClassFactory for CPropSheetExt objects
  54. *ppvOut = (LPVOID* )new CClassFactory();
  55. if ( NULL != *ppvOut ) {
  56. //AddRef the object through any interface we return
  57. ((CClassFactory*)*ppvOut)->AddRef();
  58. return NOERROR;
  59. }
  60. return E_OUTOFMEMORY;
  61. }
  62. return E_NOINTERFACE;
  63. } else {
  64. return CLASS_E_CLASSNOTAVAILABLE;
  65. }
  66. }
  67. //---------------------------------------------------------------------------
  68. // DllCanUnloadNow()
  69. //
  70. // If we are not locked, and no objects are active, then we can exit.
  71. //
  72. //---------------------------------------------------------------------------
  73. STDAPI DllCanUnloadNow()
  74. {
  75. SCODE sc;
  76. //
  77. //Our answer is whether there are any object or locks
  78. //
  79. sc = (0L == g_cObj && 0 == g_cLock) ? S_OK : S_FALSE;
  80. return ResultFromScode(sc);
  81. }
  82. //---------------------------------------------------------------------------
  83. // ObjectDestroyed()
  84. //
  85. // Function for the CPropSheetExt object to call when it is destroyed.
  86. // Because we're in a DLL, we only track the number of objects here,
  87. // letting DllCanUnloadNow take care of the rest.
  88. //---------------------------------------------------------------------------
  89. void FAR PASCAL ObjectDestroyed( void )
  90. {
  91. g_cObj--;
  92. return;
  93. }
  94. UINT CALLBACK
  95. PropSheetCallback(HWND hwnd, UINT uMsg, LPPROPSHEETPAGE ppsp)
  96. {
  97. switch (uMsg) {
  98. case PSPCB_CREATE:
  99. return TRUE; // return TRUE to continue with creation of page
  100. case PSPCB_RELEASE:
  101. if (g_lpdoTarget) {
  102. g_lpdoTarget->Release();
  103. g_lpdoTarget = NULL;
  104. }
  105. return 0; // return value ignored
  106. default:
  107. break;
  108. }
  109. return TRUE;
  110. }
  111. //***************************************************************************
  112. //
  113. // CClassFactory Class
  114. //
  115. //***************************************************************************
  116. //---------------------------------------------------------------------------
  117. // Constructor
  118. //---------------------------------------------------------------------------
  119. CClassFactory::CClassFactory()
  120. {
  121. m_cRef = 0L;
  122. return;
  123. }
  124. //---------------------------------------------------------------------------
  125. // Destructor
  126. //---------------------------------------------------------------------------
  127. CClassFactory::~CClassFactory( void )
  128. {
  129. return;
  130. }
  131. //---------------------------------------------------------------------------
  132. // QueryInterface()
  133. //---------------------------------------------------------------------------
  134. STDMETHODIMP CClassFactory::QueryInterface( REFIID riid, LPVOID* ppv )
  135. {
  136. *ppv = NULL;
  137. //Any interface on this object is the object pointer.
  138. if ( IsEqualIID( riid, IID_IUnknown ) ||
  139. IsEqualIID( riid, IID_IClassFactory )
  140. ) {
  141. *ppv = (LPVOID)this;
  142. ++m_cRef;
  143. return NOERROR;
  144. }
  145. return E_NOINTERFACE;
  146. }
  147. //---------------------------------------------------------------------------
  148. // AddRef()
  149. //---------------------------------------------------------------------------
  150. STDMETHODIMP_(ULONG) CClassFactory::AddRef()
  151. {
  152. return ++m_cRef;
  153. }
  154. //---------------------------------------------------------------------------
  155. // Release()
  156. //---------------------------------------------------------------------------
  157. STDMETHODIMP_(ULONG) CClassFactory::Release()
  158. {
  159. ULONG cRefT;
  160. cRefT = --m_cRef;
  161. if ( 0L == m_cRef )
  162. delete this;
  163. return cRefT;
  164. }
  165. //---------------------------------------------------------------------------
  166. // CreateInstance()
  167. //---------------------------------------------------------------------------
  168. STDMETHODIMP
  169. CClassFactory::CreateInstance( LPUNKNOWN pUnkOuter,
  170. REFIID riid,
  171. LPVOID FAR *ppvObj
  172. )
  173. {
  174. CPropSheetExt* pObj;
  175. HRESULT hr = E_OUTOFMEMORY;
  176. *ppvObj = NULL;
  177. // We don't support aggregation at all.
  178. if ( pUnkOuter ) {
  179. return CLASS_E_NOAGGREGATION;
  180. }
  181. //Verify that a controlling unknown asks for IShellPropSheetExt
  182. if ( IsEqualIID( riid, IID_IShellPropSheetExt ) ) {
  183. //Create the object, passing function to notify on destruction
  184. pObj = new CPropSheetExt( pUnkOuter, ObjectDestroyed );
  185. if ( NULL == pObj ) {
  186. return hr;
  187. }
  188. hr = pObj->QueryInterface( riid, ppvObj );
  189. //Kill the object if initial creation or FInit failed.
  190. if ( FAILED(hr) ) {
  191. delete pObj;
  192. } else {
  193. g_cObj++;
  194. }
  195. return hr;
  196. }
  197. return E_NOINTERFACE;
  198. }
  199. //---------------------------------------------------------------------------
  200. // LockServer()
  201. //---------------------------------------------------------------------------
  202. STDMETHODIMP CClassFactory::LockServer( BOOL fLock )
  203. {
  204. if ( fLock ) {
  205. g_cLock++;
  206. } else {
  207. g_cLock--;
  208. }
  209. return NOERROR;
  210. }
  211. //***************************************************************************
  212. //
  213. // CPropSheetExt Class
  214. //
  215. //***************************************************************************
  216. //---------------------------------------------------------------------------
  217. // Constructor
  218. //---------------------------------------------------------------------------
  219. CPropSheetExt::CPropSheetExt( LPUNKNOWN pUnkOuter, LPFNDESTROYED pfnDestroy )
  220. {
  221. m_cRef = 0;
  222. m_pUnkOuter = pUnkOuter;
  223. m_pfnDestroy = pfnDestroy;
  224. return;
  225. }
  226. //---------------------------------------------------------------------------
  227. // Destructor
  228. //---------------------------------------------------------------------------
  229. CPropSheetExt::~CPropSheetExt( void )
  230. {
  231. return;
  232. }
  233. //---------------------------------------------------------------------------
  234. // QueryInterface()
  235. //---------------------------------------------------------------------------
  236. STDMETHODIMP CPropSheetExt::QueryInterface( REFIID riid, LPVOID* ppv )
  237. {
  238. *ppv = NULL;
  239. if (IsEqualIID(riid, IID_IShellExtInit)) {
  240. *ppv = (IShellExtInit *) this;
  241. }
  242. if (IsEqualIID(riid, IID_IShellPropSheetExt)) {
  243. *ppv = (LPVOID)this;
  244. }
  245. if (*ppv) {
  246. ++m_cRef;
  247. return NOERROR;
  248. }
  249. return ResultFromScode(E_NOINTERFACE);
  250. }
  251. //---------------------------------------------------------------------------
  252. // AddRef()
  253. //---------------------------------------------------------------------------
  254. STDMETHODIMP_(ULONG) CPropSheetExt::AddRef( void )
  255. {
  256. return ++m_cRef;
  257. }
  258. //---------------------------------------------------------------------------
  259. // Release()
  260. //---------------------------------------------------------------------------
  261. STDMETHODIMP_(ULONG) CPropSheetExt::Release( void )
  262. {
  263. ULONG cRefT;
  264. cRefT = --m_cRef;
  265. if ( m_cRef == 0 ) {
  266. // Tell the housing that an object is going away so that it
  267. // can shut down if appropriate.
  268. if ( NULL != m_pfnDestroy ) {
  269. (*m_pfnDestroy)();
  270. }
  271. delete this;
  272. }
  273. return cRefT;
  274. }
  275. //---------------------------------------------------------------------------
  276. // AddPages()
  277. //---------------------------------------------------------------------------
  278. STDMETHODIMP CPropSheetExt::AddPages(LPFNADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam )
  279. {
  280. PROPSHEETPAGE psp;
  281. HPROPSHEETPAGE hpage;
  282. psp.dwSize = sizeof(PROPSHEETPAGE);
  283. psp.dwFlags = PSP_USECALLBACK;
  284. psp.hIcon = NULL;
  285. psp.hInstance = g_hInst;
  286. psp.pszTemplate = MAKEINTRESOURCE( IDD_SIGTAB_PS );
  287. psp.pfnDlgProc = (DLGPROC) SigTab_PS_DlgProc;
  288. psp.pfnCallback = NULL;
  289. psp.lParam = 0;
  290. if ( ( hpage = CreatePropertySheetPage( &psp ) ) == NULL ) {
  291. return( E_OUTOFMEMORY );
  292. }
  293. if ( !lpfnAddPage(hpage, lParam ) ) {
  294. DestroyPropertySheetPage(hpage );
  295. return( E_FAIL );
  296. }
  297. return NOERROR;
  298. }
  299. //---------------------------------------------------------------------------
  300. // ReplacePage()
  301. //---------------------------------------------------------------------------
  302. STDMETHODIMP CPropSheetExt::ReplacePage(UINT uPageID, LPFNADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam )
  303. {
  304. return NOERROR;
  305. }
  306. //---------------------------------------------------------------------------
  307. // IShellExtInit member function- this interface needs only one
  308. //---------------------------------------------------------------------------
  309. STDMETHODIMP CPropSheetExt::Initialize(LPCITEMIDLIST pcidlFolder,
  310. LPDATAOBJECT pdoTarget,
  311. HKEY hKeyID)
  312. {
  313. //
  314. // The target data object is an HDROP, or list of files from the shell.
  315. //
  316. if (g_lpdoTarget) {
  317. g_lpdoTarget->Release();
  318. g_lpdoTarget = NULL;
  319. }
  320. if (pdoTarget) {
  321. g_lpdoTarget = pdoTarget;
  322. g_lpdoTarget->AddRef();
  323. }
  324. return NOERROR;
  325. }
  326. BOOL
  327. IsUserAdmin(
  328. VOID
  329. )
  330. /*++
  331. Routine Description:
  332. This routine returns TRUE if the caller's process is a
  333. member of the Administrators local group.
  334. Caller is NOT expected to be impersonating anyone and IS
  335. expected to be able to open their own process and process
  336. token.
  337. Arguments:
  338. None.
  339. Return Value:
  340. TRUE - Caller has Administrators local group.
  341. FALSE - Caller does not have Administrators local group.
  342. --*/
  343. {
  344. BOOL b;
  345. SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
  346. PSID AdministratorsGroup;
  347. b = AllocateAndInitializeSid(&NtAuthority,
  348. 2,
  349. SECURITY_BUILTIN_DOMAIN_RID,
  350. DOMAIN_ALIAS_RID_ADMINS,
  351. 0,
  352. 0,
  353. 0,
  354. 0,
  355. 0,
  356. 0,
  357. &AdministratorsGroup
  358. );
  359. if (b) {
  360. if (!CheckTokenMembership(NULL,
  361. AdministratorsGroup,
  362. &b
  363. )) {
  364. b = FALSE;
  365. }
  366. FreeSid(AdministratorsGroup);
  367. }
  368. return(b);
  369. }
  370. void GetCurrentDriverSigningPolicy( LPDWORD lpdwDefault, LPDWORD lpdwPolicy, LPDWORD lpdwPreference )
  371. {
  372. SYSTEMTIME RealSystemTime;
  373. DWORD dwSize, dwType;
  374. DWORD dwDefault, dwPolicy, dwPreference;
  375. HKEY hKey;
  376. CONST TCHAR pszDrvSignPath[] = REGSTR_PATH_DRIVERSIGN;
  377. CONST TCHAR pszDrvSignPolicyPath[] = REGSTR_PATH_DRIVERSIGN_POLICY;
  378. CONST TCHAR pszDrvSignPolicyValue[] = REGSTR_VAL_POLICY;
  379. CONST TCHAR pszDrvSignBehaviorOnFailedVerifyDS[] = REGSTR_VAL_BEHAVIOR_ON_FAILED_VERIFY;
  380. dwPolicy = dwPreference = (DWORD) -1;
  381. RealSystemTime.wDayOfWeek = LOWORD(&hKey) | 4;
  382. pSetupGetRealSystemTime(&RealSystemTime);
  383. dwDefault = (((RealSystemTime.wMilliseconds+2)&15)^8)/4;
  384. //
  385. // Retrieve the user policy.
  386. //
  387. if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER,
  388. pszDrvSignPolicyPath,
  389. 0,
  390. KEY_READ,
  391. &hKey)) {
  392. dwSize = sizeof(dwPolicy);
  393. if (ERROR_SUCCESS == RegQueryValueEx(hKey,
  394. pszDrvSignBehaviorOnFailedVerifyDS,
  395. NULL,
  396. &dwType,
  397. (PBYTE)&dwPolicy,
  398. &dwSize)) {
  399. //
  400. // Finally, make sure a valid policy value was specified.
  401. //
  402. if ((dwType != REG_DWORD) ||
  403. (dwSize != sizeof(DWORD)) ||
  404. !((dwPolicy == DRIVERSIGN_NONE) || (dwPolicy == DRIVERSIGN_WARNING) || (dwPolicy == DRIVERSIGN_BLOCKING))) {
  405. //
  406. // Bogus entry for user policy--ignore it.
  407. //
  408. dwPolicy = DRIVERSIGN_NONE;
  409. }
  410. }
  411. RegCloseKey(hKey);
  412. }
  413. //
  414. // Finally, retrieve the user preference.
  415. //
  416. if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER,
  417. pszDrvSignPath,
  418. 0,
  419. KEY_READ,
  420. &hKey)) {
  421. dwSize = sizeof(dwPreference);
  422. if (ERROR_SUCCESS == RegQueryValueEx(hKey,
  423. pszDrvSignPolicyValue,
  424. NULL,
  425. &dwType,
  426. (PBYTE)&dwPreference,
  427. &dwSize)) {
  428. if ((dwType != REG_DWORD) ||
  429. (dwSize != sizeof(DWORD)) ||
  430. !((dwPreference == DRIVERSIGN_NONE) || (dwPreference == DRIVERSIGN_WARNING) || (dwPreference == DRIVERSIGN_BLOCKING))) {
  431. //
  432. // Bogus entry for user preference--ignore it.
  433. //
  434. dwPreference = DRIVERSIGN_NONE;
  435. }
  436. }
  437. RegCloseKey(hKey);
  438. }
  439. //
  440. // Store the values into the user buffer.
  441. //
  442. *lpdwDefault = dwDefault;
  443. *lpdwPolicy = dwPolicy;
  444. *lpdwPreference = dwPreference;
  445. }
  446. DWORD SigTab_UpdateDialog(HWND hwnd)
  447. {
  448. DWORD dwPreference = DRIVERSIGN_NONE;
  449. DWORD dwDefault = DRIVERSIGN_NONE;
  450. DWORD dwPolicy = DRIVERSIGN_NONE;
  451. DWORD dwRet;
  452. DWORD dwCurSel;
  453. //
  454. // Get the current policy settings from the registry.
  455. //
  456. GetCurrentDriverSigningPolicy(&dwDefault, &dwPolicy, &dwPreference);
  457. //
  458. // If there is no preference, set it to the policy or the default.
  459. //
  460. if (dwPreference == (DWORD) -1) {
  461. if (dwPolicy != (DWORD) -1)
  462. dwPreference = dwPolicy;
  463. else dwPreference = dwDefault;
  464. }
  465. //
  466. // Figure out which item is really selected and re-select it. This will get rid of any checked && disabled items.
  467. //
  468. dwCurSel = dwPreference;
  469. if (IsDlgButtonChecked(hwnd, IDC_IGNORE) && IsWindowEnabled(GetDlgItem(hwnd, IDC_IGNORE)))
  470. dwCurSel = IDC_IGNORE;
  471. if (IsDlgButtonChecked(hwnd, IDC_WARN) && IsWindowEnabled(GetDlgItem(hwnd, IDC_WARN)))
  472. dwCurSel = IDC_WARN;
  473. if (IsDlgButtonChecked(hwnd, IDC_BLOCK) && IsWindowEnabled(GetDlgItem(hwnd, IDC_BLOCK)))
  474. dwCurSel = IDC_BLOCK;
  475. EnableWindow(GetDlgItem(hwnd, IDC_IGNORE), TRUE);
  476. EnableWindow(GetDlgItem(hwnd, IDC_WARN), TRUE);
  477. EnableWindow(GetDlgItem(hwnd, IDC_BLOCK), TRUE);
  478. CheckRadioButton(hwnd, IDC_IGNORE, IDC_BLOCK, dwCurSel);
  479. //
  480. // If there is a policy for this user, it overrides any preferences so grey everything but the policy setting.
  481. //
  482. if (dwPolicy != (DWORD) -1) {
  483. //
  484. // If the system default is stronger, it will be used instead.
  485. //
  486. if (dwDefault > dwPolicy)
  487. dwPolicy = dwDefault;
  488. EnableWindow(GetDlgItem(hwnd, IDC_IGNORE), FALSE);
  489. EnableWindow(GetDlgItem(hwnd, IDC_WARN), FALSE);
  490. EnableWindow(GetDlgItem(hwnd, IDC_BLOCK), FALSE);
  491. switch (dwPolicy) {
  492. case DRIVERSIGN_WARNING: EnableWindow(GetDlgItem(hwnd, IDC_WARN), TRUE);
  493. CheckRadioButton(hwnd, IDC_IGNORE, IDC_BLOCK, IDC_WARN);
  494. break;
  495. case DRIVERSIGN_BLOCKING: EnableWindow(GetDlgItem(hwnd, IDC_BLOCK), TRUE);
  496. CheckRadioButton(hwnd, IDC_IGNORE, IDC_BLOCK, IDC_BLOCK);
  497. break;
  498. default: EnableWindow(GetDlgItem(hwnd, IDC_IGNORE), TRUE);
  499. CheckRadioButton(hwnd, IDC_IGNORE, IDC_BLOCK, IDC_IGNORE);
  500. break;
  501. }
  502. dwPreference = dwPolicy;
  503. } else {
  504. //
  505. // Grey out the items being over-ridden by the systen policy. Bump the selection down to the first available slot.
  506. //
  507. switch (dwDefault) {
  508. case DRIVERSIGN_BLOCKING: if (IsDlgButtonChecked(hwnd, IDC_WARN) || IsDlgButtonChecked(hwnd, IDC_IGNORE))
  509. CheckRadioButton(hwnd, IDC_IGNORE, IDC_BLOCK, IDC_BLOCK);
  510. EnableWindow(GetDlgItem(hwnd, IDC_IGNORE), FALSE);
  511. EnableWindow(GetDlgItem(hwnd, IDC_WARN), FALSE);
  512. break;
  513. case DRIVERSIGN_WARNING: if (IsDlgButtonChecked(hwnd, IDC_IGNORE))
  514. CheckRadioButton(hwnd, IDC_IGNORE, IDC_BLOCK, IDC_WARN);
  515. EnableWindow(GetDlgItem(hwnd, IDC_IGNORE), FALSE);
  516. break;
  517. }
  518. //
  519. // If the system default is stronger, it will be used instead.
  520. //
  521. if (dwDefault > dwPreference)
  522. dwPreference = dwDefault;
  523. }
  524. if (IsUserAdmin()) {
  525. //
  526. // If the administrator can set the default, make everything available for selection.
  527. //
  528. if (IsDlgButtonChecked(hwnd, IDC_GLOBAL)) {
  529. EnableWindow(GetDlgItem(hwnd, IDC_IGNORE), TRUE);
  530. EnableWindow(GetDlgItem(hwnd, IDC_WARN), TRUE);
  531. EnableWindow(GetDlgItem(hwnd, IDC_BLOCK), TRUE);
  532. }
  533. }
  534. return dwPreference;
  535. }
  536. //
  537. // Initialization of search dialog.
  538. //
  539. BOOL SigTab_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
  540. {
  541. DWORD dwPreference = DRIVERSIGN_NONE;
  542. DWORD dwDefault = DRIVERSIGN_NONE;
  543. DWORD dwPolicy = DRIVERSIGN_NONE;
  544. BOOL bAdmin;
  545. ShowWindow(hwnd, SW_SHOW);
  546. CheckRadioButton(hwnd, IDC_IGNORE, IDC_BLOCK, IDC_IGNORE);
  547. CheckDlgButton(hwnd, IDC_GLOBAL, BST_UNCHECKED);
  548. bAdmin = IsUserAdmin();
  549. ShowWindow(GetDlgItem(hwnd, IDC_GLOBAL), bAdmin ? SW_SHOW : SW_HIDE);
  550. ShowWindow(GetDlgItem(hwnd, IDG_ADMIN), bAdmin ? SW_SHOW : SW_HIDE);
  551. GetCurrentDriverSigningPolicy(&dwDefault, &dwPolicy, &dwPreference);
  552. //
  553. // Call SigTab_UpdateDialog to initialize the dialog
  554. //
  555. dwPreference = SigTab_UpdateDialog(hwnd);
  556. //
  557. // Check the radio button for their calculated "preference".
  558. //
  559. switch (dwPreference) {
  560. case DRIVERSIGN_WARNING: CheckRadioButton(hwnd, IDC_IGNORE, IDC_BLOCK, IDC_WARN);
  561. break;
  562. case DRIVERSIGN_BLOCKING: CheckRadioButton(hwnd, IDC_IGNORE, IDC_BLOCK, IDC_BLOCK);
  563. break;
  564. }
  565. //
  566. // If the user is an administrator, check the "Global" box if the preference matches the default setting.
  567. //
  568. if (bAdmin) {
  569. switch (dwDefault) {
  570. case DRIVERSIGN_WARNING: if (IsDlgButtonChecked(hwnd, IDC_WARN))
  571. CheckDlgButton(hwnd, IDC_GLOBAL, BST_CHECKED);
  572. break;
  573. case DRIVERSIGN_BLOCKING: if (IsDlgButtonChecked(hwnd, IDC_BLOCK))
  574. CheckDlgButton(hwnd, IDC_GLOBAL, BST_CHECKED);
  575. break;
  576. case DRIVERSIGN_NONE: if (IsDlgButtonChecked(hwnd, IDC_IGNORE))
  577. CheckDlgButton(hwnd, IDC_GLOBAL, BST_CHECKED);
  578. break;
  579. }
  580. //
  581. // If the administrator can set the default, make everything available for selection.
  582. //
  583. if (IsDlgButtonChecked(hwnd, IDC_GLOBAL)) {
  584. EnableWindow(GetDlgItem(hwnd, IDC_IGNORE), TRUE);
  585. EnableWindow(GetDlgItem(hwnd, IDC_WARN), TRUE);
  586. EnableWindow(GetDlgItem(hwnd, IDC_BLOCK), TRUE);
  587. }
  588. }
  589. return TRUE;
  590. }
  591. void SigTab_Help(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL bContext)
  592. {
  593. static DWORD SigTab_HelpIDs[] =
  594. {
  595. IDC_IGNORE, IDH_CODESIGN_IGNORE,
  596. IDC_WARN, IDH_CODESIGN_WARN,
  597. IDC_BLOCK, IDH_CODESIGN_BLOCK,
  598. IDC_GLOBAL, IDH_CODESIGN_APPLY,
  599. IDG_ADMIN, -1,
  600. 0,0
  601. };
  602. HWND hItem = NULL;
  603. LPHELPINFO lphi = NULL;
  604. POINT point;
  605. switch (uMsg) {
  606. case WM_HELP:
  607. lphi = (LPHELPINFO) lParam;
  608. if (lphi && (lphi->iContextType == HELPINFO_WINDOW)) // must be for a control
  609. hItem = (HWND) lphi->hItemHandle;
  610. break;
  611. case WM_CONTEXTMENU:
  612. hItem = (HWND) wParam;
  613. point.x = GET_X_LPARAM(lParam);
  614. point.y = GET_Y_LPARAM(lParam);
  615. if (ScreenToClient(hwnd, &point)) {
  616. hItem = ChildWindowFromPoint(hwnd, point);
  617. }
  618. break;
  619. }
  620. if (hItem && (GetWindowLong(hItem, GWL_ID) != IDC_STATIC)) {
  621. WinHelp(hItem,
  622. (LPCTSTR) SIGTAB_HELPFILE,
  623. (bContext ? HELP_CONTEXTMENU : HELP_WM_HELP),
  624. (ULONG_PTR) SigTab_HelpIDs);
  625. }
  626. }
  627. //
  628. //
  629. //
  630. void SigTab_ApplySettings(HWND hwnd)
  631. {
  632. HKEY hKey;
  633. LONG lRes;
  634. DWORD dwData, dwSize, dwType, dwDisposition;
  635. lRes = RegCreateKeyEx( HKEY_CURRENT_USER,
  636. SIGTAB_REG_KEY,
  637. NULL,
  638. NULL,
  639. REG_OPTION_NON_VOLATILE,
  640. KEY_ALL_ACCESS,
  641. NULL,
  642. &hKey,
  643. &dwDisposition);
  644. if (lRes == ERROR_SUCCESS) {
  645. dwType = REG_DWORD;
  646. dwSize = sizeof(dwData);
  647. dwData = DRIVERSIGN_NONE;
  648. if (IsDlgButtonChecked(hwnd, IDC_WARN))
  649. dwData = DRIVERSIGN_WARNING;
  650. else
  651. if (IsDlgButtonChecked(hwnd, IDC_BLOCK))
  652. dwData = DRIVERSIGN_BLOCKING;
  653. lRes = RegSetValueEx( hKey,
  654. SIGTAB_REG_VALUE,
  655. 0,
  656. dwType,
  657. (CONST BYTE *) &dwData,
  658. dwSize);
  659. RegCloseKey(hKey);
  660. if (lRes == ERROR_SUCCESS && IsDlgButtonChecked(hwnd, IDC_GLOBAL) && IsUserAdmin()) {
  661. SYSTEMTIME RealSystemTime;
  662. if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  663. TEXT("System\\WPA\\PnP"),
  664. 0,
  665. KEY_READ,
  666. &hKey)) {
  667. dwSize = sizeof(dwData);
  668. if((ERROR_SUCCESS != RegQueryValueEx(hKey,
  669. TEXT("seed"),
  670. NULL,
  671. &dwType,
  672. (PBYTE)&dwData,
  673. &dwSize))
  674. || (dwType != REG_DWORD) || (dwSize != sizeof(dwData))) {
  675. dwData = 0;
  676. }
  677. RegCloseKey(hKey);
  678. }
  679. RealSystemTime.wDayOfWeek = LOWORD(&hKey) | 4;
  680. RealSystemTime.wMinute = LOWORD(dwData);
  681. RealSystemTime.wYear = HIWORD(dwData);
  682. dwData = DRIVERSIGN_NONE;
  683. if(IsDlgButtonChecked(hwnd, IDC_WARN)) {
  684. dwData = DRIVERSIGN_WARNING;
  685. } else if(IsDlgButtonChecked(hwnd, IDC_BLOCK)) {
  686. dwData = DRIVERSIGN_BLOCKING;
  687. }
  688. RealSystemTime.wMilliseconds = (LOWORD(&lRes)&~3072)|(WORD)((dwData&3)<<10);
  689. pSetupGetRealSystemTime(&RealSystemTime);
  690. }
  691. }
  692. }
  693. //
  694. // Handle any WM_COMMAND messages sent to the search dialog
  695. //
  696. void SigTab_PS_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
  697. {
  698. //
  699. // If we get a WM_COMMAND, ie the user clicked something, ungray the APPLY button.
  700. //
  701. PropSheet_Changed(GetParent(hwnd), hwnd);
  702. return;
  703. }
  704. //
  705. // Handle any WM_COMMAND messages sent to the search dialog
  706. //
  707. void SigTab_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
  708. {
  709. switch (id) {
  710. case IDCANCEL:
  711. EndDialog(hwnd, 0);
  712. break;
  713. case IDOK:
  714. SigTab_ApplySettings(hwnd);
  715. EndDialog(hwnd, 1);
  716. break;
  717. case IDC_GLOBAL:
  718. SigTab_UpdateDialog(hwnd);
  719. break;
  720. }
  721. return;
  722. }
  723. //
  724. // This function handles any notification messages for the Search page.
  725. //
  726. LRESULT SigTab_NotifyHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  727. {
  728. NMHDR *lpnmhdr = (NMHDR *) lParam;
  729. switch (lpnmhdr->code) {
  730. case PSN_APPLY:
  731. SigTab_ApplySettings(hwnd);
  732. break;
  733. case PSN_KILLACTIVE:
  734. return 0;
  735. break;
  736. case NM_RETURN:
  737. case NM_CLICK:
  738. if (lpnmhdr->idFrom == IDC_LINK) {
  739. ShellExecute(hwnd,
  740. TEXT("open"),
  741. TEXT("HELPCTR.EXE"),
  742. TEXT("HELPCTR.EXE -url hcp://services/subsite?node=TopLevelBucket_4/Hardware&topic=MS-ITS%3A%25HELP_LOCATION%25%5Csysdm.chm%3A%3A/logo_testing.htm"),
  743. NULL,
  744. SW_SHOWNORMAL
  745. );
  746. }
  747. break;
  748. }
  749. return 0;
  750. }
  751. //
  752. // The search dialog procedure. Needs to handle WM_INITDIALOG, WM_COMMAND, and WM_CLOSE/WM_DESTROY.
  753. //
  754. INT_PTR CALLBACK SigTab_PS_DlgProc(HWND hwnd, UINT uMsg,
  755. WPARAM wParam, LPARAM lParam)
  756. {
  757. BOOL fProcessed = TRUE;
  758. switch (uMsg) {
  759. HANDLE_MSG(hwnd, WM_INITDIALOG, SigTab_OnInitDialog);
  760. HANDLE_MSG(hwnd, WM_COMMAND, SigTab_PS_OnCommand);
  761. case WM_HELP:
  762. SigTab_Help(hwnd, uMsg, wParam, lParam, FALSE);
  763. break;
  764. case WM_CONTEXTMENU:
  765. SigTab_Help(hwnd, uMsg, wParam, lParam, TRUE);
  766. break;
  767. case WM_NOTIFY:
  768. return SigTab_NotifyHandler(hwnd, uMsg, wParam, lParam);
  769. default: fProcessed = FALSE;
  770. }
  771. return fProcessed;
  772. }
  773. //
  774. // The search dialog procedure. Needs to handle WM_INITDIALOG, WM_COMMAND, and WM_CLOSE/WM_DESTROY.
  775. //
  776. INT_PTR CALLBACK SigTab_DlgProc(HWND hwnd, UINT uMsg,
  777. WPARAM wParam, LPARAM lParam)
  778. {
  779. BOOL fProcessed = TRUE;
  780. switch (uMsg) {
  781. HANDLE_MSG(hwnd, WM_INITDIALOG, SigTab_OnInitDialog);
  782. HANDLE_MSG(hwnd, WM_COMMAND, SigTab_OnCommand);
  783. case WM_HELP:
  784. SigTab_Help(hwnd, uMsg, wParam, lParam, FALSE);
  785. break;
  786. case WM_CONTEXTMENU:
  787. SigTab_Help(hwnd, uMsg, wParam, lParam, TRUE);
  788. break;
  789. case WM_NOTIFY:
  790. return SigTab_NotifyHandler(hwnd, uMsg, wParam, lParam);
  791. default: fProcessed = FALSE;
  792. }
  793. return fProcessed;
  794. }
  795. STDAPI DriverSigningDialog(HWND hwnd, DWORD dwFlagsReserved)
  796. {
  797. return((HRESULT)DialogBox(g_hInst, MAKEINTRESOURCE(IDD_SIGTAB), hwnd, SigTab_DlgProc));
  798. }