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.

646 lines
15 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000-2001 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // CheckingAccessPage.cpp
  7. //
  8. // Maintained By:
  9. // David Potter (DavidP) 22-MAR-2001
  10. // Geoffrey Pease (GPease) 17-MAY-2000
  11. //
  12. //////////////////////////////////////////////////////////////////////////////
  13. #include "Pch.h"
  14. #include "CheckingAccessPage.h"
  15. DEFINE_THISCLASS("CCheckingAccessPage");
  16. //////////////////////////////////////////////////////////////////////////////
  17. //++
  18. //
  19. // CCheckingAccessPage::CCheckingAccessPage(
  20. // IServiceProvider * pspIn,
  21. // BSTR * pbstrClusterNameIn,
  22. // BOOL * pfShowCredentialsPageIn
  23. // )
  24. //
  25. //--
  26. //////////////////////////////////////////////////////////////////////////////
  27. CCheckingAccessPage::CCheckingAccessPage(
  28. IServiceProvider * pspIn,
  29. BSTR * pbstrClusterNameIn,
  30. BOOL * pfShowCredentialsPageIn
  31. )
  32. {
  33. TraceFunc( "" );
  34. // m_hwnd
  35. THR( pspIn->TypeSafeQI( IServiceProvider, &m_psp ) );
  36. m_pfShowCredentialsPage = pfShowCredentialsPageIn;
  37. m_pbstrClusterName = pbstrClusterNameIn;
  38. m_fNext = FALSE;
  39. m_cRef = 0;
  40. m_ptld = NULL;
  41. m_hEvent = NULL;
  42. // m_hrResult
  43. Assert( m_pfShowCredentialsPage != NULL );
  44. *pfShowCredentialsPageIn = FALSE;
  45. Assert( m_pbstrClusterName != NULL );
  46. TraceFuncExit();
  47. } //*** CCheckingAccessPage::CCheckingAccessPage()
  48. //////////////////////////////////////////////////////////////////////////////
  49. //++
  50. //
  51. // CCheckingAccessPage::~CCheckingAccessPage( void )
  52. //
  53. //--
  54. //////////////////////////////////////////////////////////////////////////////
  55. CCheckingAccessPage::~CCheckingAccessPage( void )
  56. {
  57. TraceFunc( "" );
  58. KillTimer( m_hwnd, 0 );
  59. if ( m_psp != NULL )
  60. {
  61. m_psp->Release();
  62. }
  63. if ( m_hEvent != NULL )
  64. {
  65. CloseHandle( m_hEvent );
  66. }
  67. if ( m_ptld != NULL )
  68. {
  69. THR( m_ptld->SetCallback( NULL ) );
  70. m_ptld->Release();
  71. }
  72. Assert( m_cRef == 0 );
  73. TraceFuncExit();
  74. } //*** CCheckingAccessPage::~CCheckingAccessPage()
  75. //////////////////////////////////////////////////////////////////////////////
  76. //++
  77. //
  78. // LRESULT
  79. // CCheckingAccessPage::OnInitDialog( void )
  80. //
  81. //--
  82. //////////////////////////////////////////////////////////////////////////////
  83. LRESULT
  84. CCheckingAccessPage::OnInitDialog( void )
  85. {
  86. TraceFunc( "" );
  87. LRESULT lr = FALSE; // didn't set focus
  88. m_hEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
  89. Assert( m_hEvent != NULL );
  90. SendDlgItemMessage( m_hwnd, IDC_CHECKINGACCESS_PRG_STATUS, PBM_SETRANGE, 0, MAKELPARAM( 0, 100 ) );
  91. RETURN( lr );
  92. } //*** CCheckingAccessPage::OnInitDialog()
  93. //////////////////////////////////////////////////////////////////////////////
  94. //++
  95. //
  96. // LRESULT
  97. // CCheckingAccessPage::OnNotifySetActive( void )
  98. //
  99. //--
  100. //////////////////////////////////////////////////////////////////////////////
  101. LRESULT
  102. CCheckingAccessPage::OnNotifySetActive( void )
  103. {
  104. TraceFunc( "" );
  105. HRESULT hr;
  106. BOOL bRet;
  107. UINT_PTR iTimer;
  108. LPWSTR pszDomain;
  109. LRESULT lr = TRUE;
  110. BSTR bstrDomain = NULL;
  111. IUnknown * punk = NULL;
  112. ITaskManager * ptm = NULL;
  113. //
  114. // Only cancel available.
  115. //
  116. PropSheet_SetWizButtons( GetParent( m_hwnd ), PSWIZB_BACK );
  117. //
  118. // Reset progress bar.
  119. //
  120. SendDlgItemMessage( m_hwnd, IDC_CHECKINGACCESS_PRG_STATUS, PBM_SETPOS, 0, 0 );
  121. //
  122. // If m_fNext is TRUE, then that means we are coming into this
  123. // page because someone is back-pedalling through the wizard.
  124. //
  125. if ( m_fNext && !(*m_pfShowCredentialsPage) )
  126. {
  127. //
  128. // Don't show us on the way back.
  129. //
  130. SetWindowLongPtr( m_hwnd, DWLP_MSGRESULT, -1 );
  131. m_fNext = FALSE;
  132. }
  133. else
  134. {
  135. //
  136. // Start the timer.
  137. //
  138. if ( m_hEvent != NULL )
  139. {
  140. hr = THR( m_psp->TypeSafeQS( CLSID_TaskManager,
  141. ITaskManager,
  142. &ptm
  143. ) );
  144. if ( FAILED( hr ) )
  145. goto Error;
  146. if ( m_ptld != NULL )
  147. {
  148. THR( m_ptld->SetCallback( NULL ) );
  149. m_ptld->Release();
  150. }
  151. hr = THR( ptm->CreateTask( TASK_LoginDomain,
  152. &punk
  153. ) );
  154. if ( FAILED( hr ) )
  155. goto Error;
  156. hr = THR( punk->TypeSafeQI( ITaskLoginDomain, &m_ptld ) );
  157. if ( FAILED( hr ) )
  158. goto Error;
  159. bRet = ResetEvent( m_hEvent );
  160. Assert( bRet );
  161. iTimer = SetTimer( m_hwnd, 0, 500, NULL );
  162. Assert( iTimer != 0 );
  163. pszDomain = wcschr( *m_pbstrClusterName, L'.' );
  164. Assert( pszDomain != NULL );
  165. pszDomain++; // move past the dot.
  166. bstrDomain = TraceSysAllocString( pszDomain );
  167. if ( bstrDomain == NULL )
  168. goto OutOfMemory;
  169. hr = THR( m_ptld->SetDomain( bstrDomain ) );
  170. if ( FAILED( hr ) )
  171. goto Error;
  172. hr = THR( m_ptld->SetCallback( static_cast< ITaskLoginDomainCallback * >( this ) ) );
  173. if ( FAILED( hr ) )
  174. goto Error;
  175. hr = THR( ptm->SubmitTask( m_ptld ) );
  176. if ( FAILED( hr ) )
  177. goto Error;
  178. }
  179. }
  180. Cleanup:
  181. if ( ptm != NULL )
  182. {
  183. ptm->Release();
  184. }
  185. if ( bstrDomain != NULL )
  186. {
  187. TraceSysFreeString( bstrDomain );
  188. }
  189. if ( punk != NULL )
  190. {
  191. punk->Release();
  192. }
  193. RETURN( lr );
  194. Error:
  195. //
  196. // On error, we can't block on the event because it'll never get
  197. // set. So we'll just assume that everything would go ok and skip
  198. // the login test.
  199. //
  200. if ( m_hEvent != NULL )
  201. {
  202. bRet = SetEvent( m_hEvent );
  203. Assert( bRet );
  204. }
  205. goto Cleanup;
  206. OutOfMemory:
  207. goto Error;
  208. } //*** CCheckingAccessPage::OnNotifySetActive()
  209. //////////////////////////////////////////////////////////////////////////////
  210. //++
  211. //
  212. // LRESULT
  213. // CCheckingAccessPage::OnNotifyQueryCancel( void )
  214. //
  215. //--
  216. //////////////////////////////////////////////////////////////////////////////
  217. LRESULT
  218. CCheckingAccessPage::OnNotifyQueryCancel( void )
  219. {
  220. TraceFunc( "" );
  221. LRESULT lr = TRUE;
  222. int iRet;
  223. iRet = MessageBoxFromStrings( m_hwnd,
  224. IDS_QUERY_CANCEL_TITLE,
  225. IDS_QUERY_CANCEL_TEXT,
  226. MB_YESNO
  227. );
  228. if ( iRet == IDNO )
  229. {
  230. SetWindowLongPtr( m_hwnd, DWLP_MSGRESULT, -1 );
  231. }
  232. else
  233. {
  234. KillTimer( m_hwnd, 0 );
  235. }
  236. RETURN( lr );
  237. } //*** CCheckingAccessPage::OnNotifyQueryCancel()
  238. //////////////////////////////////////////////////////////////////////////////
  239. //++
  240. //
  241. // LRESULT
  242. // CCheckingAccessPage::OnNotifyWizNext( void )
  243. //
  244. //--
  245. //////////////////////////////////////////////////////////////////////////////
  246. LRESULT
  247. CCheckingAccessPage::OnNotifyWizNext( void )
  248. {
  249. TraceFunc( "" );
  250. LRESULT lr = TRUE;
  251. m_fNext = TRUE;
  252. RETURN( lr );
  253. } //*** CCheckingAccessPage::OnNotifyWizNext()
  254. //////////////////////////////////////////////////////////////////////////////
  255. //++
  256. //
  257. // LRESULT
  258. // CCheckingAccessPage::OnNotifyWizBack( void )
  259. //
  260. //--
  261. //////////////////////////////////////////////////////////////////////////////
  262. LRESULT
  263. CCheckingAccessPage::OnNotifyWizBack()
  264. {
  265. TraceFunc( "" );
  266. BOOL bRet;
  267. LRESULT lr = TRUE;
  268. m_fNext = FALSE;
  269. KillTimer( m_hwnd, 0 );
  270. RETURN( lr );
  271. } //*** CCheckingAccessPage::OnNotifyWizBack()
  272. //////////////////////////////////////////////////////////////////////////////
  273. //++
  274. //
  275. // LRESULT
  276. // CCheckingAccessPage::OnNotify(
  277. // WPARAM idCtrlIn,
  278. // LPNMHDR pnmhdrIn
  279. // )
  280. //
  281. //--
  282. //////////////////////////////////////////////////////////////////////////////
  283. LRESULT
  284. CCheckingAccessPage::OnNotify(
  285. WPARAM idCtrlIn,
  286. LPNMHDR pnmhdrIn
  287. )
  288. {
  289. TraceFunc( "" );
  290. LRESULT lr = TRUE;
  291. SetWindowLongPtr( m_hwnd, DWLP_MSGRESULT, 0 );
  292. switch( pnmhdrIn->code )
  293. {
  294. case PSN_SETACTIVE:
  295. lr = OnNotifySetActive();
  296. break;
  297. case PSN_WIZNEXT:
  298. lr = OnNotifyWizNext();
  299. break;
  300. case PSN_WIZBACK:
  301. lr = OnNotifyWizBack();
  302. break;
  303. case PSN_QUERYCANCEL:
  304. lr = OnNotifyQueryCancel();
  305. break;
  306. }
  307. RETURN( lr );
  308. } //*** CCheckingAccessPage::OnNotify()
  309. //////////////////////////////////////////////////////////////////////////////
  310. //++
  311. //
  312. // LRESULT
  313. // CCheckingAccessPage::OnTimer( void )
  314. //
  315. //--
  316. //////////////////////////////////////////////////////////////////////////////
  317. LRESULT
  318. CCheckingAccessPage::OnTimer( void )
  319. {
  320. TraceFunc( "" );
  321. LRESULT lr = 0;
  322. SendDlgItemMessage( m_hwnd, IDC_CHECKINGACCESS_PRG_STATUS, PBM_DELTAPOS, 1, 0 );
  323. if ( m_hEvent == NULL
  324. || WaitForSingleObject( m_hEvent, 0 ) == WAIT_OBJECT_0
  325. )
  326. {
  327. BOOL bRet;
  328. bRet = KillTimer( m_hwnd, 0 );
  329. Assert( bRet );
  330. if ( m_hrResult == S_OK )
  331. {
  332. //
  333. // Done. Fake the button push. Don't show the login page.
  334. //
  335. PropSheet_PressButton( GetParent( m_hwnd ), PSBTN_NEXT );
  336. *m_pfShowCredentialsPage = FALSE;
  337. }
  338. else if ( m_hrResult == HRESULT_FROM_WIN32( ERROR_ACCESS_DENIED ) )
  339. {
  340. //
  341. // Found the domain, but we don't have access.
  342. // Move to the credentials pages.
  343. //
  344. PropSheet_PressButton( GetParent( m_hwnd ), PSBTN_NEXT );
  345. *m_pfShowCredentialsPage = TRUE;
  346. }
  347. else
  348. {
  349. MessageBoxFromStrings( m_hwnd,
  350. IDS_ERR_NO_SUCH_DOMAIN_TITLE,
  351. IDS_ERR_NO_SUCH_DOMAIN_TEXT,
  352. MB_OK
  353. );
  354. PropSheet_PressButton( GetParent( m_hwnd ), PSBTN_BACK );
  355. }
  356. }
  357. RETURN( lr );
  358. } //*** CCheckingAccessPage::OnTimer()
  359. //////////////////////////////////////////////////////////////////////////////
  360. //++
  361. //
  362. // INT_PTR
  363. // CALLBACK
  364. // CCheckingAccessPage::S_DlgProc(
  365. // HWND hDlgIn,
  366. // UINT MsgIn,
  367. // WPARAM wParam,
  368. // LPARAM lParam
  369. // )
  370. //
  371. //--
  372. //////////////////////////////////////////////////////////////////////////////
  373. INT_PTR
  374. CALLBACK
  375. CCheckingAccessPage::S_DlgProc(
  376. HWND hDlgIn,
  377. UINT MsgIn,
  378. WPARAM wParam,
  379. LPARAM lParam
  380. )
  381. {
  382. // Don't do TraceFunc because every mouse movement
  383. // will cause this function to be called.
  384. WndMsg( hDlgIn, MsgIn, wParam, lParam );
  385. LRESULT lr = FALSE;
  386. CCheckingAccessPage * pPage = reinterpret_cast< CCheckingAccessPage *> ( GetWindowLongPtr( hDlgIn, GWLP_USERDATA ) );
  387. if ( MsgIn == WM_INITDIALOG )
  388. {
  389. PROPSHEETPAGE * ppage = reinterpret_cast< PROPSHEETPAGE * >( lParam );
  390. SetWindowLongPtr( hDlgIn, GWLP_USERDATA, (LPARAM) ppage->lParam );
  391. pPage = reinterpret_cast< CCheckingAccessPage * >( ppage->lParam );
  392. pPage->m_hwnd = hDlgIn;
  393. }
  394. if ( pPage != NULL )
  395. {
  396. Assert( hDlgIn == pPage->m_hwnd );
  397. switch( MsgIn )
  398. {
  399. case WM_INITDIALOG:
  400. lr = pPage->OnInitDialog();
  401. break;
  402. case WM_NOTIFY:
  403. lr = pPage->OnNotify( wParam, reinterpret_cast< LPNMHDR >( lParam ) );
  404. break;
  405. case WM_TIMER:
  406. lr = pPage->OnTimer();
  407. break;
  408. // no default clause needed
  409. }
  410. }
  411. return lr;
  412. } //*** CCheckingAccessPage::S_DlgProc()
  413. // ************************************************************************
  414. //
  415. // IUnknown
  416. //
  417. // ************************************************************************
  418. //////////////////////////////////////////////////////////////////////////////
  419. //++
  420. //
  421. // STDMETHODIMP
  422. // CCheckingAccessPage::QueryInterface(
  423. // REFIID riidIn,
  424. // LPVOID * ppvOut
  425. // )
  426. //
  427. //--
  428. //////////////////////////////////////////////////////////////////////////////
  429. STDMETHODIMP
  430. CCheckingAccessPage::QueryInterface(
  431. REFIID riidIn,
  432. LPVOID * ppvOut
  433. )
  434. {
  435. TraceQIFunc( riidIn, ppvOut );
  436. HRESULT hr = E_NOINTERFACE;
  437. if ( IsEqualIID( riidIn, IID_IUnknown ) )
  438. {
  439. *ppvOut = static_cast< ITaskLoginDomainCallback * >( this );
  440. hr = S_OK;
  441. } // if: IUnknown
  442. else if ( IsEqualIID( riidIn, IID_ITaskLoginDomainCallback ) )
  443. {
  444. *ppvOut = TraceInterface( __THISCLASS__, ITaskLoginDomainCallback , this, 0 );
  445. hr = S_OK;
  446. } // else if: ITaskLoginDomainCallback
  447. if ( SUCCEEDED( hr ) )
  448. {
  449. ((IUnknown*) *ppvOut)->AddRef();
  450. } // if: success
  451. QIRETURN_IGNORESTDMARSHALLING( hr, riidIn );
  452. } //*** CCheckingAccessPage::QueryInterface()
  453. //////////////////////////////////////////////////////////////////////////////
  454. //++
  455. //
  456. // STDMETHODIMP_( ULONG )
  457. // CCheckingAccessPage::AddRef( void )
  458. //
  459. //--
  460. //////////////////////////////////////////////////////////////////////////////
  461. STDMETHODIMP_( ULONG )
  462. CCheckingAccessPage::AddRef( void )
  463. {
  464. TraceFunc( "[IUnknown]" );
  465. InterlockedIncrement( &m_cRef );
  466. RETURN( m_cRef );
  467. } //*** CCheckingAccessPage::AddRef()
  468. //////////////////////////////////////////////////////////////////////////////
  469. //++
  470. //
  471. // STDMETHODIMP_( ULONG )
  472. // CCheckingAccessPage::Release( void )
  473. //
  474. //--
  475. //////////////////////////////////////////////////////////////////////////////
  476. STDMETHODIMP_( ULONG )
  477. CCheckingAccessPage::Release( void )
  478. {
  479. TraceFunc( "[IUnknown]" );
  480. LONG cRef;
  481. cRef = InterlockedDecrement( &m_cRef );
  482. if ( cRef == 0 )
  483. {
  484. // do nothing -- COM interface does not control object lifetime
  485. }
  486. RETURN( cRef );
  487. } //*** CCheckingAccessPage::Release()
  488. //****************************************************************************
  489. //
  490. // ITaskLoginDomainCallback
  491. //
  492. //****************************************************************************
  493. //////////////////////////////////////////////////////////////////////////////
  494. //++
  495. //
  496. // STDMETHODIMP
  497. // CCheckingAccessPage::ReceiveLoginResult(
  498. // HRESULT hrIn
  499. // )
  500. //
  501. //--
  502. //////////////////////////////////////////////////////////////////////////////
  503. STDMETHODIMP
  504. CCheckingAccessPage::ReceiveLoginResult(
  505. HRESULT hrIn
  506. )
  507. {
  508. TraceFunc( "[ITaskLoginDomainCallback]" );
  509. HRESULT hr = S_OK;
  510. BOOL bRet;
  511. m_hrResult = hrIn;
  512. if ( m_hEvent != NULL )
  513. {
  514. bRet = SetEvent( m_hEvent );
  515. Assert( bRet );
  516. }
  517. HRETURN( hr );
  518. } //*** CCheckingAccessPage::ReceiveResult()