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.

5356 lines
148 KiB

  1. //Copyright (c) 1998 - 1999 Microsoft Corporation
  2. #include"stdafx.h"
  3. #include"tsprsht.h"
  4. #include"resource.h"
  5. #include"tarray.h"
  6. #include<tscfgex.h>
  7. #include<shellapi.h>
  8. #include <shlobj.h>
  9. #include <shlobjp.h>
  10. #include "regapi.h"
  11. void ErrMessage( HWND hwndOwner , INT_PTR iResourceID );
  12. void TscAccessDeniedMsg( HWND hwnd );
  13. void TscGeneralErrMsg( HWND hwnd );
  14. void xxxErrMessage( HWND , INT_PTR , INT_PTR , UINT );
  15. void ReportStatusError( HWND hwnd , DWORD dwStatus );
  16. DWORD xxxLegacyLogoffCleanup( PSECURITY_DESCRIPTOR *ppSD , PBOOL );
  17. //extern BOOL g_bEditMode = FALSE;
  18. //
  19. INT_PTR APIENTRY CustomSecurityDlgProc( HWND, UINT, WPARAM, LPARAM );
  20. extern void EnableGroup( HWND hParent , LPINT rgID , BOOL bEnable );
  21. //-----------------------------------------------------------------------------
  22. typedef enum _AcluiApiIndex
  23. {
  24. ACLUI_CREATE_PAGE = 0,
  25. ACLUI_EDIT_SECURITY
  26. };
  27. //-----------------------------------------------------------------------------
  28. typedef struct _DLL_FUNCTIONS
  29. {
  30. LPCSTR pcstrFunctionName;
  31. LPVOID lpfnFunction;
  32. HINSTANCE hInst;
  33. } DLL_FUNCTIONS;
  34. //-----------------------------------------------------------------------------
  35. // not subject to localization
  36. //-----------------------------------------------------------------------------
  37. static DLL_FUNCTIONS g_aAclFunctions[] =
  38. {
  39. "CreateSecurityPage", NULL, NULL ,
  40. NULL , NULL , NULL
  41. };
  42. //-----------------------------------------------------------------------------
  43. CPropsheet::CPropsheet( )
  44. {
  45. m_cref = 0;
  46. m_hNotify = 0;
  47. m_pResNode = NULL;
  48. m_bGotUC = FALSE;
  49. m_puc = NULL;
  50. m_bPropertiesChange = FALSE;
  51. m_hMMCWindow = NULL;
  52. }
  53. //-----------------------------------------------------------------------------
  54. int CPropsheet::AddRef( )
  55. {
  56. DBGMSG( L"Propsheet Refcount at %d\n", ( m_cref + 1 ) );
  57. return InterlockedIncrement( ( LPLONG )&m_cref );
  58. }
  59. //-----------------------------------------------------------------------------
  60. // called before the destructor
  61. //-----------------------------------------------------------------------------
  62. void CPropsheet::PreDestruct( )
  63. {
  64. ICfgComp *pCfgcomp = NULL;
  65. if( m_bPropertiesChange )
  66. {
  67. // check to see if any users are logged on
  68. LONG lCount;
  69. if( m_pResNode->GetServer( &pCfgcomp ) > 0 )
  70. {
  71. if( SUCCEEDED( pCfgcomp->QueryLoggedOnCount( m_pResNode->GetConName( ) , &lCount ) ) )
  72. {
  73. TCHAR tchTitle[ 80 ];
  74. TCHAR tchMessage[ 256 ];
  75. TCHAR tchBuffer[ 336 ];
  76. UINT nFlags = MB_OK | MB_ICONINFORMATION;
  77. VERIFY_E( 0 , LoadString( _Module.GetResourceInstance( ) , IDS_TERMSERPROP , tchTitle , SIZE_OF_BUFFER( tchTitle ) ) );
  78. if( lCount > 0 )
  79. {
  80. // Notify user that settings will not affect connected users
  81. if( lCount == 1 )
  82. {
  83. VERIFY_E( 0 , LoadString( _Module.GetResourceInstance( ) , IDS_PROPCHANGE_WRN , tchMessage , SIZE_OF_BUFFER( tchMessage ) ) );
  84. }
  85. else if( lCount > 1 )
  86. {
  87. VERIFY_E( 0 , LoadString( _Module.GetResourceInstance( ) , IDS_PROPCHANGE_WRN_2, tchMessage , SIZE_OF_BUFFER( tchMessage ) ) );
  88. wsprintf( tchBuffer , tchMessage , m_pResNode->GetConName( ) );
  89. }
  90. wsprintf( tchBuffer , tchMessage , m_pResNode->GetConName( ) );
  91. if( m_hMMCWindow == NULL )
  92. {
  93. nFlags |= MB_TASKMODAL;
  94. }
  95. MessageBox( m_hMMCWindow , tchBuffer , tchTitle , MB_OK | MB_ICONINFORMATION );
  96. }
  97. }
  98. pCfgcomp->Release( );
  99. }
  100. }
  101. if( m_puc != NULL )
  102. {
  103. CoTaskMemFree( m_puc );
  104. }
  105. // FreeStrings( );
  106. g_aAclFunctions[ ACLUI_CREATE_PAGE ].lpfnFunction = NULL;
  107. for( INT x = 0; x < NUM_OF_PRSHT ; ++x )
  108. {
  109. if( m_pDlg[ x ] != NULL )
  110. {
  111. delete[] m_pDlg[x];
  112. }
  113. }
  114. m_pResNode->m_bEditMode = FALSE;
  115. }
  116. //-----------------------------------------------------------------------------
  117. int CPropsheet::Release( )
  118. {
  119. if( InterlockedDecrement( ( LPLONG )&m_cref ) == 0 )
  120. {
  121. MMCFreeNotifyHandle( m_hNotify );
  122. ODS( L"Propsheet Released\n" );
  123. PreDestruct( );
  124. delete this;
  125. return 0;
  126. }
  127. DBGMSG( L"Propsheet Refcount at %d\n", m_cref );
  128. return m_cref;
  129. }
  130. //-----------------------------------------------------------------------------
  131. HRESULT CPropsheet::InitDialogs( HWND hMMC , LPPROPERTYSHEETCALLBACK pPsc , CResultNode *pResNode , LONG_PTR lNotifyHandle )
  132. {
  133. PROPSHEETPAGE psp;
  134. if( pPsc == NULL || pResNode == NULL )
  135. {
  136. return E_INVALIDARG;
  137. }
  138. m_pResNode = pResNode;
  139. m_hNotify = lNotifyHandle;
  140. BOOL bAlloc = FALSE;
  141. m_hMMCWindow = hMMC;
  142. m_pResNode->m_bEditMode = TRUE;
  143. // init array
  144. for( int x = 0; x < NUM_OF_PRSHT; x++ )
  145. {
  146. m_pDlg[ x ] = NULL;
  147. }
  148. do
  149. {
  150. m_pDlg[ 0 ] = ( CDialogPropBase * )new CGeneral( this );
  151. if( m_pDlg[ 0 ] == NULL )
  152. {
  153. ODS( L"CGeneral object allocation failed @ CPropsheet::InitDialogs\n" );
  154. break;
  155. }
  156. m_pDlg[ 1 ] = ( CDialogPropBase * )new CLogonSetting( this );
  157. if( m_pDlg[ 1 ] == NULL )
  158. {
  159. ODS( L"CLogonSetting object allocation failed @ CPropsheet::InitDialogs\n" );
  160. break;
  161. }
  162. m_pDlg[ 2 ] = ( CDialogPropBase * )new CTimeSetting( this );
  163. if( m_pDlg[ 2 ] == NULL )
  164. {
  165. ODS( L"CTimeSetting object allocation failed @ CPropsheet::InitDialogs\n" );
  166. break;
  167. }
  168. // m_pDlg[ 3 ] = ( CDialogPropBase * )new CPerm( this );
  169. m_pDlg[ 3 ] = ( CDialogPropBase * )new CEnviro( this );
  170. if( m_pDlg[ 3 ] == NULL )
  171. {
  172. ODS( L"CEnviro object allocation failed @ CPropsheet::InitDialogs\n" );
  173. break;
  174. }
  175. m_pDlg[ 4 ] = ( CDialogPropBase * )new CRemote( this );
  176. if( m_pDlg[ 4 ] == NULL )
  177. {
  178. ODS( L"CRemote object allocation failed @ CPropsheet::InitDialogs\n" );
  179. break;
  180. }
  181. m_pDlg[ 5 ] = ( CDialogPropBase * )new CClient( this );
  182. if( m_pDlg[ 5 ] == NULL )
  183. {
  184. ODS( L"CClient object allocation failed @ CPropsheet::InitDialogs\n" );
  185. break;
  186. }
  187. m_pDlg[ 6 ] = ( CDialogPropBase * )new CTransNetwork( this );
  188. if( m_pDlg[ 6 ] == NULL )
  189. {
  190. ODS( L"CTransNetwork object allocation failed @ CPropsheet::InitDialogs\n" );
  191. break;
  192. }
  193. m_pDlg[ 7 ] = ( CDialogPropBase * )new CTransAsync( this );
  194. if( m_pDlg[ 7 ] == NULL )
  195. {
  196. ODS( L"CTransAsync object allocation failed @ CPropsheet::InitDialogs\n" );
  197. break;
  198. }
  199. bAlloc = TRUE;
  200. }while( 0 );
  201. if( !bAlloc )
  202. {
  203. // try cleaning up before leaving
  204. for( x = 0; x < NUM_OF_PRSHT ; ++x )
  205. {
  206. if( m_pDlg[ x ] != NULL )
  207. {
  208. delete[] m_pDlg[x];
  209. }
  210. }
  211. return E_OUTOFMEMORY;
  212. }
  213. for( int idx = 0; idx < 5; ++idx )
  214. {
  215. if( m_pDlg[ idx ] != NULL )
  216. {
  217. if( !m_pDlg[ idx ]->GetPropertySheetPage( psp ) )
  218. {
  219. return E_UNEXPECTED;
  220. }
  221. if( FAILED( pPsc->AddPage( CreatePropertySheetPage( &psp ) ) ) )
  222. {
  223. return E_FAIL;
  224. }
  225. }
  226. }
  227. HRESULT hr = E_FAIL;
  228. if( m_pResNode != NULL )
  229. {
  230. ICfgComp *pCfgcomp = NULL;
  231. PWS pWinsta = NULL;
  232. // don't fail here third party vendor may want to use their own page
  233. if( m_pResNode->GetServer( &pCfgcomp ) > 0 )
  234. {
  235. LONG cbSize;
  236. hr = pCfgcomp->GetWSInfo( m_pResNode->GetConName( ) , &cbSize , &pWinsta );
  237. if( SUCCEEDED( hr ) )
  238. {
  239. CDialogPropBase *pDlg = NULL;
  240. CDialogPropBase *pDlgClientSettings = m_pDlg[ 5 ]; // client settings
  241. if( pWinsta->PdClass == SdNetwork )
  242. {
  243. pDlg = m_pDlg[ 6 ];
  244. }
  245. else if( pWinsta->PdClass == SdAsync )
  246. {
  247. pDlg = m_pDlg[ 7 ];
  248. }
  249. if( pDlg != NULL )
  250. {
  251. if( !pDlgClientSettings->GetPropertySheetPage( psp ) )
  252. {
  253. ODS( L"Client settings page failed to load\n" );
  254. hr = E_UNEXPECTED;
  255. }
  256. if( SUCCEEDED( hr ) )
  257. {
  258. hr = pPsc->AddPage( CreatePropertySheetPage( &psp ) );
  259. }
  260. if( SUCCEEDED( hr ) )
  261. {
  262. if( !pDlg->GetPropertySheetPage( psp ) )
  263. {
  264. ODS( L"Transport page failed to load\n" );
  265. hr = E_UNEXPECTED;
  266. }
  267. }
  268. if( SUCCEEDED( hr ) )
  269. {
  270. hr = pPsc->AddPage( CreatePropertySheetPage( &psp ) );
  271. }
  272. }
  273. CoTaskMemFree( pWinsta );
  274. }
  275. pCfgcomp->Release();
  276. }
  277. }
  278. if( SUCCEEDED( hr ) )
  279. {
  280. hr = pPsc->AddPage( GetSecurityPropertyPage( this ) );
  281. }
  282. return hr;
  283. }
  284. //The UC structure will contain data from a merger between the TSCC data and the machine policy data. We
  285. //don't want all that written to the TSCC data though. If there's a machine policy for a given field, we
  286. //want to replace its data with the data that currently exists in the TSCC section of the registry
  287. BOOL CPropsheet::ExcludeMachinePolicySettings(USERCONFIG& uc)
  288. {
  289. POLICY_TS_MACHINE p;
  290. RegGetMachinePolicy(&p);
  291. USERCONFIG origUC;
  292. //The default is to call GetUserConfig with a TRUE merge
  293. //parameter, so we have to do that before we can call
  294. //GetCurrentUserConfig which just returns the cached USERCONFIG structure
  295. if (!GetUserConfig(FALSE))
  296. return FALSE;
  297. if (!GetCurrentUserConfig(origUC, FALSE))
  298. return FALSE;
  299. //We have to do this so that the cached USERCONFIG structure
  300. //will again have the expected (merged) data
  301. if (!GetUserConfig(TRUE))
  302. return FALSE;
  303. //CRemote fields
  304. if (p.fPolicyShadow)
  305. {
  306. uc.fInheritShadow = origUC.fInheritShadow;
  307. uc.Shadow = origUC.Shadow;
  308. }
  309. //CEnviro fields
  310. if (p.fPolicyInitialProgram)
  311. {
  312. uc.fInheritInitialProgram = origUC.fInheritInitialProgram;
  313. wcscpy(uc.InitialProgram, origUC.InitialProgram);
  314. wcscpy(uc.WorkDirectory, origUC.WorkDirectory);
  315. }
  316. //CClient fields
  317. if (p.fPolicyColorDepth)
  318. {
  319. uc.fInheritColorDepth = origUC.fInheritColorDepth;
  320. uc.ColorDepth = origUC.ColorDepth;
  321. }
  322. if (p.fPolicyForceClientLptDef)
  323. uc.fForceClientLptDef = origUC.fForceClientLptDef;
  324. if (p.fPolicyDisableCdm)
  325. uc.fDisableCdm = origUC.fDisableCdm;
  326. if (p.fPolicyDisableCpm)
  327. uc.fDisableCpm = origUC.fDisableCpm;
  328. if (p.fPolicyDisableLPT)
  329. uc.fDisableLPT = origUC.fDisableLPT;
  330. if (p.fPolicyDisableCcm)
  331. uc.fDisableCcm = origUC.fDisableCcm;
  332. if (p.fPolicyDisableClip)
  333. uc.fDisableClip = origUC.fDisableClip;
  334. if (p.fPolicyDisableCam)
  335. uc.fDisableCam = origUC.fDisableCam;
  336. //CLogonSetting fields
  337. if (p.fPolicyPromptForPassword)
  338. uc.fPromptForPassword = origUC.fPromptForPassword;
  339. //CGeneral fields
  340. if (p.fPolicyMinEncryptionLevel)
  341. uc.MinEncryptionLevel = origUC.MinEncryptionLevel;
  342. //CTimeSetting fields
  343. if (p.fPolicyMaxSessionTime)
  344. uc.MaxConnectionTime = origUC.MaxConnectionTime;
  345. if (p.fPolicyMaxDisconnectionTime)
  346. uc.MaxDisconnectionTime = origUC.MaxDisconnectionTime;
  347. if (p.fPolicyMaxIdleTime)
  348. uc.MaxIdleTime = origUC.MaxIdleTime;
  349. if (p.fPolicyResetBroken)
  350. uc.fResetBroken = origUC.fResetBroken;
  351. if (p.fPolicyReconnectSame)
  352. uc.fReconnectSame = origUC.fReconnectSame;
  353. if (p.fPolicyMaxSessionTime || p.fPolicyMaxDisconnectionTime || p.fPolicyMaxIdleTime)
  354. uc.fInheritMaxSessionTime = origUC.fInheritMaxSessionTime;
  355. if (p.fPolicyResetBroken)
  356. uc.fInheritResetBroken = origUC.fInheritResetBroken;
  357. if (p.fPolicyReconnectSame)
  358. uc.fInheritReconnectSame = origUC.fInheritReconnectSame;
  359. return TRUE;
  360. }
  361. //-------------------------------------------------------------------------------
  362. // Use custom interface to persist uc to winstation
  363. //-------------------------------------------------------------------------------
  364. HRESULT CPropsheet::SetUserConfig( USERCONFIG& uc , PDWORD pdwStatus )
  365. {
  366. ICfgComp *pCfgcomp;
  367. *pdwStatus = ERROR_INVALID_PARAMETER;
  368. if( m_pResNode == NULL )
  369. return E_FAIL;
  370. if( m_pResNode->GetServer( &pCfgcomp ) == 0 )
  371. return E_FAIL;
  372. if (!ExcludeMachinePolicySettings(uc))
  373. return E_FAIL;
  374. HRESULT hr = pCfgcomp->SetUserConfig( m_pResNode->GetConName( ) , sizeof( USERCONFIG ) , &uc , pdwStatus );
  375. if( SUCCEEDED( hr ) )
  376. {
  377. m_bGotUC = FALSE;
  378. }
  379. pCfgcomp->Release( );
  380. return hr;
  381. }
  382. //-------------------------------------------------------------------------------
  383. // Use custom interface to obtain the winstation userconfig
  384. // store it in m_puc -- and return t | f
  385. //-------------------------------------------------------------------------------
  386. BOOL CPropsheet::GetUserConfig(BOOLEAN bPerformMerger)
  387. {
  388. ICfgComp *pCfgcomp;
  389. if( m_pResNode == NULL )
  390. {
  391. return FALSE;
  392. }
  393. if( m_pResNode->GetServer( &pCfgcomp ) == 0 )
  394. {
  395. return FALSE;
  396. }
  397. LONG lSzReqd;
  398. if( m_puc != NULL )
  399. {
  400. CoTaskMemFree( m_puc );
  401. m_puc = NULL;
  402. }
  403. HRESULT hr = pCfgcomp->GetUserConfig( m_pResNode->GetConName( ) , &lSzReqd , &m_puc, bPerformMerger );
  404. if( FAILED( hr ) )
  405. {
  406. hr = pCfgcomp->GetDefaultUserConfig( m_pResNode->GetConName( ) , &lSzReqd , &m_puc );
  407. }
  408. pCfgcomp->Release( );
  409. return ( FAILED( hr ) ? FALSE: TRUE );
  410. }
  411. //-------------------------------------------------------------------------------
  412. // Cache the uc
  413. //-------------------------------------------------------------------------------
  414. BOOL CPropsheet::GetCurrentUserConfig( USERCONFIG& uc, BOOLEAN bPerformMerger )
  415. {
  416. if( !m_bGotUC )
  417. {
  418. m_bGotUC = GetUserConfig(bPerformMerger);
  419. }
  420. if( m_puc != NULL )
  421. {
  422. uc = *m_puc;
  423. }
  424. return m_bGotUC;
  425. }
  426. //*******************************************************************************
  427. //-------------------------------------------------------------------------------
  428. // OnNotify - base class method
  429. //-------------------------------------------------------------------------------
  430. BOOL CDialogPropBase::OnNotify( int idCtrl , LPNMHDR pnmh , HWND hDlg )
  431. {
  432. UNREFERENCED_PARAMETER( idCtrl );
  433. if( pnmh->code == PSN_APPLY )
  434. {
  435. if( !m_bPersisted )
  436. {
  437. m_bPersisted = PersistSettings( hDlg );
  438. }
  439. }
  440. else if( pnmh->code == PSN_KILLACTIVE )
  441. {
  442. if( !m_bPersisted )
  443. {
  444. if( !IsValidSettings( hDlg ) )
  445. {
  446. SetWindowLongPtr( hDlg , DWLP_MSGRESULT , PSNRET_INVALID_NOCHANGEPAGE );
  447. return TRUE;
  448. }
  449. }
  450. }
  451. return FALSE;
  452. }
  453. //-------------------------------------------------------------------------------
  454. // OnCOntextMenu -- base class operation
  455. //-------------------------------------------------------------------------------
  456. BOOL CDialogPropBase::OnContextMenu( HWND hwnd , POINT& pt )
  457. {
  458. UNREFERENCED_PARAMETER( pt );
  459. TCHAR tchHelpFile[ MAX_PATH ];
  460. ODS( L"CDialogPropBase::OnContextMenu\n" );
  461. if( m_hWnd == GetParent( hwnd ) )
  462. {
  463. //
  464. // Make sure its not a dummy window
  465. //
  466. if( GetDlgCtrlID( hwnd ) <= ( int )-1 )
  467. {
  468. return FALSE;
  469. }
  470. ULONG_PTR rgdw[ 2 ];
  471. rgdw[ 0 ] = GetDlgCtrlID( hwnd );
  472. rgdw[ 1 ] = GetWindowContextHelpId( hwnd );
  473. LoadString( _Module.GetModuleInstance( ) , IDS_HELPFILE , tchHelpFile , SIZE_OF_BUFFER( tchHelpFile ) );
  474. WinHelp( hwnd , tchHelpFile , HELP_CONTEXTMENU , ( ULONG_PTR )&rgdw );
  475. }
  476. return TRUE;
  477. }
  478. //-------------------------------------------------------------------------------
  479. // Each control has a helpid assign to them. Some controls share the same topic
  480. // check for these.
  481. //-------------------------------------------------------------------------------
  482. BOOL CDialogPropBase::OnHelp( HWND hwnd , LPHELPINFO lphi )
  483. {
  484. UNREFERENCED_PARAMETER( hwnd );
  485. TCHAR tchHelpFile[ MAX_PATH ];
  486. //
  487. // For the information to winhelp api
  488. //
  489. if( IsBadReadPtr( lphi , sizeof( HELPINFO ) ) )
  490. {
  491. return FALSE;
  492. }
  493. if( lphi->iCtrlId <= -1 )
  494. {
  495. return FALSE;
  496. }
  497. LoadString( _Module.GetModuleInstance( ) , IDS_HELPFILE , tchHelpFile , SIZE_OF_BUFFER( tchHelpFile ) );
  498. ULONG_PTR rgdw[ 2 ];
  499. rgdw[ 0 ] = ( ULONG_PTR )lphi->iCtrlId;
  500. rgdw[ 1 ] = ( ULONG_PTR )lphi->dwContextId;
  501. WinHelp( ( HWND )lphi->hItemHandle , tchHelpFile , HELP_WM_HELP , ( ULONG_PTR )&rgdw );//lphi->dwContextId );
  502. return TRUE;
  503. }
  504. //*****************************************************************************
  505. // General dialog
  506. CGeneral::CGeneral( CPropsheet *pSheet )
  507. {
  508. m_pParent = pSheet;
  509. m_pEncrypt = NULL;
  510. m_DefaultEncryptionLevelIndex = 0;
  511. m_nOldSel = ( INT_PTR )-1;
  512. }
  513. //-----------------------------------------------------------------------------
  514. BOOL CGeneral::OnInitDialog( HWND hDlg , WPARAM wp , LPARAM lp )
  515. {
  516. if( m_pParent == NULL )
  517. {
  518. ODS( L"CGeneral::OnInitDialog - PropertySheet: Parent object lost!!!\n" );
  519. return FALSE;
  520. }
  521. m_pParent->AddRef( );
  522. USERCONFIG uc;
  523. ZeroMemory( &uc , sizeof( USERCONFIG ) );
  524. if( !m_pParent->GetCurrentUserConfig( uc, TRUE ) )
  525. {
  526. ODS( L"CGeneral::OnInitDialog - PropertySheet: GetCurrentUserConfig failed!!!\n" );
  527. return FALSE;
  528. }
  529. // Security
  530. SendMessage( GetDlgItem( hDlg , IDC_CHECK_GEN_AUTHEN ) , BM_SETCHECK , ( WPARAM )uc.fUseDefaultGina , 0 );
  531. // Network Transport
  532. if( m_pParent->m_pResNode == NULL )
  533. {
  534. return FALSE;
  535. }
  536. ICfgComp *pCfgcomp;
  537. ULONG cbSize = 0;
  538. ULONG ulItems = 0;
  539. do
  540. {
  541. if( m_pParent->m_pResNode->GetServer( &pCfgcomp ) == 0 )
  542. {
  543. break;
  544. }
  545. // Set Connection name
  546. SetWindowText( GetDlgItem( hDlg , IDC_STATIC_CONNAME ) , m_pParent->m_pResNode->GetConName( ) );
  547. PWS pWinSta = NULL;
  548. if( SUCCEEDED( pCfgcomp->GetWSInfo( m_pParent->m_pResNode->GetConName( ) , ( PLONG )&cbSize , &pWinSta ) ) )
  549. {
  550. SendMessage( GetDlgItem( hDlg , IDC_EDIT_GEN_COMMENT ) , EM_SETLIMITTEXT , ( WPARAM )WINSTATIONCOMMENT_LENGTH , 0 );
  551. SetWindowText( GetDlgItem( hDlg , IDC_EDIT_GEN_COMMENT ) , pWinSta->Comment );
  552. //m_pParent->m_pResNode->GetComment( ) );
  553. SetWindowText( GetDlgItem( hDlg , IDC_STATIC_GEN_TYPE ) , m_pParent->m_pResNode->GetTypeName( ) );
  554. SetWindowText( GetDlgItem( hDlg , IDC_EDIT_GENERAL_TRANSPORT ) , pWinSta->pdName );
  555. // security
  556. // Encryption *pEncrypt;
  557. if( SUCCEEDED( pCfgcomp->GetEncryptionLevels( m_pParent->m_pResNode->GetConName( ) , WsName , &ulItems , &m_pEncrypt ) ) )
  558. {
  559. BOOL bSet = FALSE;
  560. for( ULONG i = 0; i < ulItems; ++i )
  561. {
  562. SendMessage( GetDlgItem( hDlg , IDC_COMBO_GEN_ENCRYPT ) , CB_ADDSTRING , 0 , ( LPARAM )m_pEncrypt[ i ].szLevel );
  563. if(m_pEncrypt[ i ].Flags & ELF_DEFAULT)
  564. {
  565. m_DefaultEncryptionLevelIndex = i;
  566. }
  567. if( uc.MinEncryptionLevel == m_pEncrypt[ i ].RegistryValue )
  568. {
  569. SendMessage( GetDlgItem( hDlg , IDC_COMBO_GEN_ENCRYPT ) , CB_SETCURSEL , ( WPARAM )i , 0);
  570. bSet = TRUE;
  571. }
  572. }
  573. POLICY_TS_MACHINE p;
  574. RegGetMachinePolicy(&p);
  575. EnableWindow(GetDlgItem(hDlg, IDC_COMBO_GEN_ENCRYPT), !p.fPolicyMinEncryptionLevel);
  576. if(!bSet)
  577. {
  578. uc.MinEncryptionLevel = (UCHAR)(m_pEncrypt[m_DefaultEncryptionLevelIndex].RegistryValue);
  579. SendMessage( GetDlgItem( hDlg , IDC_COMBO_GEN_ENCRYPT ) , CB_SETCURSEL , ( WPARAM )m_DefaultEncryptionLevelIndex, 0 );
  580. }
  581. OnCommand( CBN_SELCHANGE , IDC_COMBO_GEN_ENCRYPT , GetDlgItem( hDlg , IDC_COMBO_GEN_ENCRYPT ) );
  582. if( !IsWindowEnabled( GetDlgItem( hDlg , IDC_STATIC_GEN_DESCR ) ) )
  583. {
  584. RECT rc;
  585. RECT rc2;
  586. GetWindowRect( GetDlgItem( hDlg , IDC_STATIC_CONGRP ) , &rc );
  587. GetWindowRect( GetDlgItem( hDlg , IDC_STATIC_GEN_DESCR ) , &rc2 );
  588. rc.bottom = rc2.top;
  589. MapWindowPoints( NULL , hDlg , ( LPPOINT )&rc , 2 );
  590. SetWindowPos( GetDlgItem( hDlg , IDC_STATIC_CONGRP ) , 0 , 0 , 0 , rc.right - rc.left , rc.bottom - rc.top , SWP_NOMOVE | SWP_SHOWWINDOW );
  591. //resize window
  592. }
  593. }
  594. else
  595. {
  596. // no encryption info insert value to none and grey out the control
  597. TCHAR tchNone[ 80 ];
  598. LoadString( _Module.GetResourceInstance( ) , IDS_NONE , tchNone , SIZE_OF_BUFFER( tchNone ) );
  599. SendMessage( GetDlgItem( hDlg , IDC_COMBO_GEN_ENCRYPT ) , CB_ADDSTRING , 0 , ( LPARAM )tchNone );
  600. SendMessage( GetDlgItem( hDlg , IDC_COMBO_GEN_ENCRYPT ) , CB_SETCURSEL , 0 , 0 );
  601. EnableWindow( GetDlgItem( hDlg , IDC_COMBO_GEN_ENCRYPT ) , FALSE );
  602. EnableWindow( GetDlgItem( hDlg , IDC_STATIC_CONGRP ) , FALSE );
  603. }
  604. CoTaskMemFree( pWinSta );
  605. }
  606. // check to see if session is readonly
  607. BOOL bReadOnly;
  608. if( SUCCEEDED( pCfgcomp->IsSessionReadOnly( &bReadOnly ) ) )
  609. {
  610. if( bReadOnly )
  611. {
  612. // make edit controls read-only
  613. SendMessage( GetDlgItem( hDlg , IDC_EDIT_GEN_COMMENT ) , EM_SETREADONLY , ( WPARAM )TRUE , 0 );
  614. // disable the remaining controls
  615. INT rgIds[] = { IDC_CHECK_GEN_AUTHEN , IDC_STATIC_CONGRP, IDC_COMBO_GEN_ENCRYPT , -1 };
  616. EnableGroup( hDlg , &rgIds[ 0 ] , FALSE );
  617. }
  618. }
  619. pCfgcomp->Release( );
  620. }while( 0 );
  621. m_bPersisted = TRUE;
  622. return CDialogPropBase::OnInitDialog( hDlg , wp , lp );
  623. }
  624. //-----------------------------------------------------------------------------
  625. INT_PTR CALLBACK CGeneral::DlgProc( HWND hwnd , UINT msg , WPARAM wp , LPARAM lp )
  626. {
  627. CGeneral *pDlg;
  628. if( msg == WM_INITDIALOG )
  629. {
  630. CGeneral *pDlg = ( CGeneral * )( ( PROPSHEETPAGE *)lp )->lParam ;
  631. SetWindowLongPtr( hwnd , DWLP_USER , ( LONG_PTR )pDlg );
  632. if( !IsBadReadPtr( pDlg , sizeof( CGeneral ) ) )
  633. {
  634. pDlg->OnInitDialog( hwnd , wp , lp );
  635. }
  636. return 0;
  637. }
  638. else
  639. {
  640. pDlg = ( CGeneral * )GetWindowLongPtr( hwnd , DWLP_USER );
  641. if( IsBadReadPtr( pDlg , sizeof( CGeneral ) ) )
  642. {
  643. return FALSE;
  644. }
  645. }
  646. switch( msg )
  647. {
  648. case WM_NCDESTROY:
  649. pDlg->OnDestroy( );
  650. break;
  651. case WM_COMMAND:
  652. pDlg->OnCommand( HIWORD( wp ) , LOWORD( wp ) , ( HWND )lp );
  653. break;
  654. case WM_CONTEXTMENU:
  655. {
  656. POINT pt;
  657. pt.x = LOWORD( lp );
  658. pt.y = HIWORD( lp );
  659. pDlg->OnContextMenu( ( HWND )wp , pt );
  660. }
  661. break;
  662. case WM_HELP:
  663. pDlg->OnHelp( hwnd , ( LPHELPINFO )lp );
  664. break;
  665. case WM_NOTIFY:
  666. return pDlg->OnNotify( ( int )wp , ( LPNMHDR )lp , hwnd );
  667. }
  668. return FALSE;
  669. }
  670. //-----------------------------------------------------------------------------
  671. BOOL CGeneral::OnCommand( WORD wNotifyCode , WORD wID , HWND hwndCtrl )
  672. {
  673. if( wNotifyCode == BN_CLICKED || wNotifyCode == EN_CHANGE )
  674. {
  675. m_bPersisted = FALSE;
  676. }
  677. else if( wNotifyCode == CBN_SELCHANGE && wID == IDC_COMBO_GEN_ENCRYPT )
  678. {
  679. if( SendMessage( hwndCtrl , CB_GETDROPPEDSTATE , 0 , 0 ) == FALSE )
  680. {
  681. INT_PTR nSel = SendMessage( hwndCtrl , CB_GETCURSEL , 0 , 0 );
  682. if( nSel != CB_ERR )
  683. {
  684. if( nSel != m_nOldSel && m_pEncrypt != NULL )
  685. {
  686. if( m_pEncrypt[ nSel ].szDescr[ 0 ] == 0 )
  687. {
  688. EnableWindow( GetDlgItem( GetParent( hwndCtrl ) , IDC_STATIC_GEN_DESCRTITLE ) , FALSE );
  689. EnableWindow( GetDlgItem( GetParent( hwndCtrl ) , IDC_STATIC_GEN_DESCR ) , FALSE );
  690. ShowWindow( GetDlgItem( GetParent( hwndCtrl ) , IDC_STATIC_GEN_DESCRTITLE ) , SW_HIDE );
  691. ShowWindow( GetDlgItem( GetParent( hwndCtrl ) , IDC_STATIC_GEN_DESCR ) , SW_HIDE );
  692. }
  693. else
  694. {
  695. ShowWindow( GetDlgItem( GetParent( hwndCtrl ) , IDC_STATIC_GEN_DESCRTITLE ) , SW_SHOW );
  696. ShowWindow( GetDlgItem( GetParent( hwndCtrl ) , IDC_STATIC_GEN_DESCR ) , SW_SHOW );
  697. EnableWindow( GetDlgItem( GetParent( hwndCtrl ) , IDC_STATIC_GEN_DESCR ) , TRUE );
  698. EnableWindow( GetDlgItem( GetParent( hwndCtrl ) , IDC_STATIC_GEN_DESCRTITLE ) , TRUE );
  699. SetWindowText( GetDlgItem( GetParent( hwndCtrl ) , IDC_STATIC_GEN_DESCR ) , m_pEncrypt[ nSel ].szDescr );
  700. }
  701. m_bPersisted = FALSE;
  702. m_nOldSel = nSel;
  703. }
  704. }
  705. }
  706. }
  707. else if( wNotifyCode == ALN_APPLY )
  708. {
  709. SendMessage( GetParent( hwndCtrl ) , PSM_CANCELTOCLOSE , 0 , 0 );
  710. return FALSE;
  711. }
  712. if( !m_bPersisted )
  713. {
  714. SendMessage( GetParent( GetParent( hwndCtrl ) ) , PSM_CHANGED , ( WPARAM )GetParent( hwndCtrl ) , 0 );
  715. }
  716. return FALSE;
  717. }
  718. //-----------------------------------------------------------------------------
  719. BOOL CGeneral::GetPropertySheetPage( PROPSHEETPAGE& psp )
  720. {
  721. ZeroMemory( &psp , sizeof( PROPSHEETPAGE ) );
  722. psp.dwSize = sizeof( PROPSHEETPAGE );
  723. psp.dwFlags = PSP_DEFAULT;
  724. psp.hInstance = _Module.GetResourceInstance( );
  725. psp.pszTemplate = MAKEINTRESOURCE( IDD_GENERAL );
  726. psp.lParam = ( LPARAM )this;
  727. psp.pfnDlgProc = CGeneral::DlgProc;
  728. return TRUE;
  729. }
  730. //-----------------------------------------------------------------------------
  731. BOOL CGeneral::PersistSettings( HWND hDlg )
  732. {
  733. HRESULT hr;
  734. if( IsValidSettings( hDlg ) )
  735. {
  736. ICfgComp *pCfgcomp;
  737. if( m_pParent->m_pResNode->GetServer( &pCfgcomp ) == 0 )
  738. {
  739. return FALSE;
  740. }
  741. WS *pWinsta = NULL;
  742. LONG lSize = 0;
  743. hr = pCfgcomp->GetWSInfo( m_pParent->m_pResNode->GetConName( ) , &lSize , &pWinsta );
  744. if( SUCCEEDED( hr ) )
  745. {
  746. GetWindowText( GetDlgItem( hDlg , IDC_EDIT_GEN_COMMENT ) , pWinsta->Comment , WINSTATIONCOMMENT_LENGTH + 1 );
  747. m_pParent->m_pResNode->SetComment( pWinsta->Comment , lstrlen( pWinsta->Comment ) );
  748. DWORD dwStatus;
  749. hr = pCfgcomp->UpDateWS( pWinsta , UPDATE_COMMENT , &dwStatus, FALSE );
  750. if( FAILED( hr ) )
  751. {
  752. // report error
  753. ReportStatusError( GetDlgItem( hDlg , IDC_EDIT_GEN_COMMENT ) , dwStatus );
  754. }
  755. CoTaskMemFree( pWinsta );
  756. }
  757. if( SUCCEEDED( hr ) )
  758. {
  759. USERCONFIG uc;
  760. if( m_pParent->GetCurrentUserConfig( uc, TRUE ) )
  761. {
  762. if( m_pEncrypt != NULL )
  763. {
  764. UINT index = ( UCHAR )SendMessage( GetDlgItem( hDlg , IDC_COMBO_GEN_ENCRYPT ) , CB_GETCURSEL , 0 , 0 );
  765. if(index == CB_ERR )
  766. {
  767. uc.MinEncryptionLevel =(UCHAR) m_pEncrypt[m_DefaultEncryptionLevelIndex].RegistryValue;
  768. }
  769. else
  770. {
  771. uc.MinEncryptionLevel = (UCHAR) m_pEncrypt[index].RegistryValue;
  772. }
  773. }
  774. else
  775. {
  776. uc.MinEncryptionLevel = 0;
  777. }
  778. uc.fUseDefaultGina = SendMessage( GetDlgItem( hDlg , IDC_CHECK_GEN_AUTHEN ) , BM_GETCHECK , 0 , 0 ) == BST_CHECKED;
  779. DWORD dwStatus = 0;
  780. hr = m_pParent->SetUserConfig( uc , &dwStatus );
  781. if( FAILED( hr ) )
  782. {
  783. // report error
  784. ReportStatusError( hDlg , dwStatus );
  785. }
  786. }
  787. }
  788. if( SUCCEEDED( hr ) )
  789. {
  790. ODS( L"TSCC : Forcing reg update on General Page\n" );
  791. VERIFY_S( S_OK , pCfgcomp->ForceUpdate( ) );
  792. VERIFY_S( S_OK , pCfgcomp->Refresh( ) );
  793. // global flag can only be set to true
  794. m_pParent->m_bPropertiesChange = TRUE;
  795. PostMessage( hDlg , WM_COMMAND , MAKELPARAM( 0 , ALN_APPLY ) , ( LPARAM )hDlg );
  796. SendMessage( GetParent( hDlg ) , PSM_UNCHANGED , ( WPARAM )hDlg , 0 );
  797. return TRUE;
  798. }
  799. pCfgcomp->Release( );
  800. }
  801. return FALSE;
  802. }
  803. //-----------------------------------------------------------------------------
  804. BOOL CGeneral::OnDestroy( )
  805. {
  806. if( m_pEncrypt != NULL )
  807. {
  808. CoTaskMemFree( m_pEncrypt );
  809. m_pEncrypt = NULL;
  810. }
  811. m_pParent->Release( );
  812. return CDialogPropBase::OnDestroy( );
  813. }
  814. //*****************************************************************************
  815. CTransNetwork::CTransNetwork( CPropsheet *pSheet )
  816. {
  817. ASSERT( pSheet != NULL );
  818. m_pParent = pSheet;
  819. // this now behaves as the last combx selection
  820. m_ulOldLanAdapter = ( ULONG )-1;
  821. m_oldID = ( WORD )-1;
  822. m_uMaxInstOld = ( ULONG )-1;
  823. }
  824. //-----------------------------------------------------------------------------
  825. INT_PTR CALLBACK CTransNetwork::DlgProc( HWND hwnd , UINT msg , WPARAM wp , LPARAM lp )
  826. {
  827. CTransNetwork *pDlg;
  828. if( msg == WM_INITDIALOG )
  829. {
  830. CTransNetwork *pDlg = ( CTransNetwork * )( ( PROPSHEETPAGE *)lp )->lParam ;
  831. SetWindowLongPtr( hwnd , DWLP_USER , ( LONG_PTR )pDlg );
  832. if( !IsBadReadPtr( pDlg , sizeof( CTransNetwork ) ) )
  833. {
  834. pDlg->OnInitDialog( hwnd , wp , lp );
  835. }
  836. return 0;
  837. }
  838. else
  839. {
  840. pDlg = ( CTransNetwork * )GetWindowLongPtr( hwnd , DWLP_USER );
  841. if( IsBadReadPtr( pDlg , sizeof( CTransNetwork ) ) )
  842. {
  843. return FALSE;
  844. }
  845. }
  846. switch( msg )
  847. {
  848. case WM_NCDESTROY:
  849. pDlg->OnDestroy( );
  850. break;
  851. case WM_COMMAND:
  852. pDlg->OnCommand( HIWORD( wp ) , LOWORD( wp ) , ( HWND )lp );
  853. break;
  854. case WM_CONTEXTMENU:
  855. {
  856. POINT pt;
  857. pt.x = LOWORD( lp );
  858. pt.y = HIWORD( lp );
  859. pDlg->OnContextMenu( ( HWND )wp , pt );
  860. }
  861. break;
  862. case WM_HELP:
  863. pDlg->OnHelp( hwnd , ( LPHELPINFO )lp );
  864. break;
  865. case WM_NOTIFY:
  866. return pDlg->OnNotify( ( int )wp , ( LPNMHDR )lp , hwnd );
  867. }
  868. return FALSE;
  869. }
  870. //-----------------------------------------------------------------------------
  871. BOOL CTransNetwork::OnInitDialog( HWND hDlg , WPARAM wp , LPARAM lp )
  872. {
  873. BOOL bReadOnly;
  874. HICON hIcon;
  875. m_pParent->AddRef( );
  876. SendMessage( GetDlgItem( hDlg , IDC_SPINCTR_GEN ) , UDM_SETRANGE32 , 0 , ( LPARAM )999999 );
  877. if( m_pParent->m_pResNode == NULL )
  878. {
  879. return FALSE;
  880. }
  881. ICfgComp *pCfgcomp = NULL;
  882. ULONG cbSize = 0;
  883. ULONG ulItems = 0;
  884. PGUIDTBL pGuidtbl = NULL;
  885. m_bPersisted = TRUE;
  886. do
  887. {
  888. if( m_pParent->m_pResNode->GetServer( &pCfgcomp ) == 0 )
  889. {
  890. ODS( L"CTransNetwork::OnInitDialog - GetServer failed\n" );
  891. break;
  892. }
  893. WS *pWinSta = NULL;
  894. if( FAILED( pCfgcomp->GetWSInfo( m_pParent->m_pResNode->GetConName( ) , ( PLONG )&cbSize , &pWinSta ) ) )
  895. {
  896. ODS( L"TSCC: GetWSInfo failed in TransNetwork::OnInitDialog\n" );
  897. break;
  898. }
  899. ISettingsComp* pISettingComp = NULL;
  900. HRESULT hr;
  901. DWORD dwStatus;
  902. DWORD nVal;
  903. hr = pCfgcomp->QueryInterface( IID_ISettingsComp, (void **) &pISettingComp );
  904. //
  905. // Assume we are not remote admin if anything go wrong
  906. //
  907. m_RemoteAdminMode = FALSE;
  908. if( SUCCEEDED(hr) && NULL != pISettingComp )
  909. {
  910. hr = pISettingComp->GetTermSrvMode( &nVal, &dwStatus );
  911. if( SUCCEEDED(hr) && nVal == 0 )
  912. {
  913. // we are in RA mode
  914. m_RemoteAdminMode = TRUE;
  915. }
  916. pISettingComp->Release();
  917. }
  918. if( FAILED(hr) )
  919. {
  920. //
  921. // QueryInterface() or GetTermSrvMode() failed
  922. // bring up a error message
  923. //
  924. TCHAR tchMessage[ 256 ];
  925. TCHAR tchWarn[ 40 ];
  926. VERIFY_E( 0 , LoadString( _Module.GetResourceInstance( ) , IDS_ERR_TERMSRVMODE , tchMessage , SIZE_OF_BUFFER( tchMessage ) ) );
  927. VERIFY_E( 0 , LoadString( _Module.GetResourceInstance( ) , IDS_WARN_TITLE , tchWarn , SIZE_OF_BUFFER( tchWarn ) ) );
  928. MessageBox( hDlg , tchMessage , tchWarn , MB_ICONWARNING | MB_OK );
  929. }
  930. // certain operations cannot be performed if the user is not part of the admin group
  931. pCfgcomp->IsSessionReadOnly( &bReadOnly );
  932. // Set Connection name
  933. SetWindowText( GetDlgItem( hDlg , IDC_STATIC_CONNAME ) , m_pParent->m_pResNode->GetConName( ) );
  934. // List all supported lan adapters for transport type
  935. ULONG idx;
  936. if( SUCCEEDED( pCfgcomp->GetLanAdapterList2( m_pParent->m_pResNode->GetTTName() , &ulItems , &pGuidtbl ) ) )
  937. {
  938. // verify table is valid
  939. BOOL bFound = FALSE;
  940. for( idx = 0 ; idx < ulItems ; ++idx )
  941. {
  942. if( pGuidtbl[ idx ].dwStatus != ERROR_SUCCESS && !bReadOnly )
  943. {
  944. pCfgcomp->BuildGuidTable( &pGuidtbl , ulItems , m_pParent->m_pResNode->GetTTName() );
  945. break;
  946. }
  947. }
  948. for( idx = 0 ; idx < ulItems ; ++idx )
  949. {
  950. if( pGuidtbl[ idx ].dwLana == pWinSta->LanAdapter )
  951. {
  952. bFound = TRUE;
  953. break;
  954. }
  955. }
  956. if( !bFound )
  957. {
  958. if( !bReadOnly )
  959. {
  960. // Notify user we must rebuild guid table
  961. TCHAR tchMessage[ 256 ];
  962. TCHAR tchTitle[ 80 ];
  963. VERIFY_E( 0 , LoadString( _Module.GetResourceInstance( ) , IDS_INVALNETWORK , tchMessage , SIZE_OF_BUFFER( tchMessage ) ) );
  964. VERIFY_E( 0 , LoadString( _Module.GetResourceInstance( ) , IDS_TSCERRTITLE , tchTitle , SIZE_OF_BUFFER( tchTitle ) ) );
  965. MessageBox( hDlg , tchMessage , tchTitle , MB_OK | MB_ICONINFORMATION );
  966. m_bPersisted = FALSE;
  967. SendMessage( GetParent( hDlg ) , PSM_CHANGED , ( WPARAM )hDlg , 0 );
  968. }
  969. // reset lana index
  970. pWinSta->LanAdapter = ( DWORD )-1;
  971. }
  972. for( idx = 0 ; idx < ulItems; ++idx )
  973. {
  974. if( pGuidtbl[ idx ].dwLana == pWinSta->LanAdapter )
  975. {
  976. // make sure we only set this once
  977. // invalid entries will have dwLana set to zero
  978. if( m_ulOldLanAdapter == ( DWORD )-1 )
  979. {
  980. m_ulOldLanAdapter = idx;
  981. }
  982. }
  983. SendMessage( GetDlgItem( hDlg , IDC_COMBO_GEN_LANADAPTER ) , CB_ADDSTRING , 0 , ( LPARAM )pGuidtbl[ idx ].DispName );
  984. SendMessage( GetDlgItem( hDlg , IDC_COMBO_GEN_LANADAPTER ) , CB_SETITEMDATA , idx , ( LPARAM )pGuidtbl[ idx ].dwLana );
  985. }
  986. CoTaskMemFree( pGuidtbl );
  987. }
  988. SendMessage( GetDlgItem( hDlg , IDC_COMBO_GEN_LANADAPTER ) , CB_SETCURSEL , ( WPARAM )m_ulOldLanAdapter , 0 );
  989. if( !m_bPersisted )
  990. {
  991. // force IsValidSettings to confirm on the lana uniqueness
  992. m_ulOldLanAdapter = ( DWORD )-1;
  993. }
  994. /*
  995. if( SUCCEEDED( pCfgcomp->GetLanAdapterList( m_pParent->m_pResNode->GetTTName() , &ulItems , &cbSize , ( WCHAR ** )&pdnw ) ) )
  996. {
  997. for( ULONG i = 0 ; i < ulItems ; i++ )
  998. {
  999. SendMessage( GetDlgItem( hDlg , IDC_COMBO_GEN_LANADAPTER ) , CB_ADDSTRING , 0 , ( LPARAM )pdnw[ i ] );
  1000. }
  1001. CoTaskMemFree( pdnw );
  1002. }
  1003. */
  1004. // SendMessage( GetDlgItem( hDlg , IDC_COMBO_GEN_LANADAPTER ) , CB_SETCURSEL , ( WPARAM )pWinSta->LanAdapter , 0 );
  1005. // m_ulOldLanAdapter = pWinSta->LanAdapter;
  1006. // unlimited connections
  1007. TCHAR tchBuf[ 6 ]; // max digits
  1008. m_uMaxInstOld = pWinSta->uMaxInstanceCount;
  1009. SendMessage( GetDlgItem( hDlg , IDC_EDIT_GEN_MAXCONS ) , EM_SETLIMITTEXT , SIZE_OF_BUFFER( tchBuf ) , 0 );
  1010. if( TRUE == m_RemoteAdminMode )
  1011. {
  1012. hIcon = LoadIcon( _Module.GetModuleInstance( ) , MAKEINTRESOURCE( IDI_ICON_WARNING ) );
  1013. hIcon = ( HICON )LoadImage( _Module.GetModuleInstance( ) ,
  1014. MAKEINTRESOURCE( IDI_ICON_WARNING ) ,
  1015. IMAGE_ICON,
  1016. 0,
  1017. 0,
  1018. 0 );
  1019. SendMessage( GetDlgItem( hDlg , IDC_USERPERM_ICON ) , STM_SETICON , ( WPARAM )hIcon , 0 );
  1020. ShowWindow( GetDlgItem( hDlg , IDC_USERPERM_ICON ), SW_SHOW );
  1021. ShowWindow( GetDlgItem( hDlg , IDC_TSMSTATIC_RA ), SW_SHOW );
  1022. wsprintf(
  1023. tchBuf ,
  1024. L"%d" ,
  1025. (pWinSta->uMaxInstanceCount > 2 || pWinSta->uMaxInstanceCount == (ULONG) -1) ? 2 : pWinSta->uMaxInstanceCount
  1026. );
  1027. SetWindowText( GetDlgItem( hDlg , IDC_EDIT_GEN_MAXCONS ) , tchBuf );
  1028. SendMessage( GetDlgItem( hDlg , IDC_CHECK_GEN_UNLIMITED ) , BM_SETCHECK , ( WPARAM )FALSE , 0 );
  1029. SendMessage( GetDlgItem( hDlg , IDC_RADIO_MAXPROP) , BM_SETCHECK , ( WPARAM )TRUE , 0 );
  1030. SendMessage( GetDlgItem( hDlg , IDC_SPINCTR_GEN ) , UDM_SETRANGE32 , 0 , ( LPARAM )2 );
  1031. }
  1032. else
  1033. {
  1034. BOOL bUnlimitedConnections = (pWinSta->uMaxInstanceCount == (ULONG)-1);
  1035. SendMessage(GetDlgItem(hDlg, IDC_CHECK_GEN_UNLIMITED), BM_SETCHECK,
  1036. (WPARAM)(bUnlimitedConnections), 0);
  1037. SendMessage(GetDlgItem(hDlg, IDC_RADIO_MAXPROP), BM_SETCHECK,
  1038. (WPARAM)(!bUnlimitedConnections), 0);
  1039. POLICY_TS_MACHINE p;
  1040. RegGetMachinePolicy(&p);
  1041. EnableWindow(GetDlgItem(hDlg, IDC_CHECK_GEN_UNLIMITED), !p.fPolicyMaxInstanceCount);
  1042. EnableWindow(GetDlgItem(hDlg, IDC_RADIO_MAXPROP), !p.fPolicyMaxInstanceCount);
  1043. EnableWindow(GetDlgItem(hDlg, IDC_EDIT_GEN_MAXCONS), !bUnlimitedConnections && !p.fPolicyMaxInstanceCount);
  1044. EnableWindow(GetDlgItem(hDlg, IDC_SPINCTR_GEN), !bUnlimitedConnections && !p.fPolicyMaxInstanceCount);
  1045. if (!bUnlimitedConnections)
  1046. {
  1047. wsprintf(tchBuf, L"%d", pWinSta->uMaxInstanceCount);
  1048. SetWindowText(GetDlgItem(hDlg, IDC_EDIT_GEN_MAXCONS), tchBuf);
  1049. m_oldID = IDC_RADIO_MAXPROP;
  1050. }
  1051. else
  1052. m_oldID = IDC_CHECK_GEN_UNLIMITED;
  1053. }
  1054. CoTaskMemFree( pWinSta );
  1055. if( bReadOnly || m_RemoteAdminMode )
  1056. {
  1057. // disable the remaining controls
  1058. // Disable Unlimited connections
  1059. EnableWindow( GetDlgItem( hDlg, IDC_CHECK_GEN_UNLIMITED ), FALSE );
  1060. // purely cosmetic, on m_RemoteAdminMode, we enable this control
  1061. EnableWindow( GetDlgItem( hDlg, IDC_RADIO_MAXPROP ), !bReadOnly );
  1062. //
  1063. // if we are read only, disable the window, in remote admin mode, we still let
  1064. // user pick a NIC card, if this is read onlu (user not in admin group), bReadOnly
  1065. // will be TRUE which will disable static text and combo box.
  1066. //
  1067. EnableWindow( GetDlgItem( hDlg, IDC_STATIC_NA ), !bReadOnly );
  1068. EnableWindow( GetDlgItem( hDlg, IDC_COMBO_GEN_LANADAPTER ), !bReadOnly );
  1069. // if user have only read access, disable MAX connection and its associated spin control
  1070. EnableWindow( GetDlgItem( hDlg, IDC_EDIT_GEN_MAXCONS ), !bReadOnly );
  1071. EnableWindow( GetDlgItem( hDlg, IDC_SPINCTR_GEN ), !bReadOnly );
  1072. }
  1073. pCfgcomp->Release( );
  1074. }while( 0 );
  1075. return CDialogPropBase::OnInitDialog( hDlg , wp , lp );
  1076. }
  1077. //-----------------------------------------------------------------------------
  1078. BOOL CTransNetwork::GetPropertySheetPage( PROPSHEETPAGE& psp )
  1079. {
  1080. ZeroMemory( &psp , sizeof( PROPSHEETPAGE ) );
  1081. psp.dwSize = sizeof( PROPSHEETPAGE );
  1082. psp.dwFlags = PSP_DEFAULT;
  1083. psp.hInstance = _Module.GetResourceInstance( );
  1084. psp.pszTemplate = MAKEINTRESOURCE( IDD_NETWORK_FACE );
  1085. psp.lParam = ( LPARAM )this;
  1086. psp.pfnDlgProc = CTransNetwork::DlgProc;
  1087. return TRUE;
  1088. }
  1089. //-----------------------------------------------------------------------------
  1090. BOOL CTransNetwork::OnDestroy( )
  1091. {
  1092. m_pParent->Release( );
  1093. return CDialogPropBase::OnDestroy( );
  1094. }
  1095. //-----------------------------------------------------------------------------
  1096. BOOL CTransNetwork::OnCommand( WORD wNotifyCode , WORD wID , HWND hwndCtrl )
  1097. {
  1098. if( wNotifyCode == BN_CLICKED || wNotifyCode == EN_CHANGE )// || wNotifyCode == CBN_SELCHANGE )
  1099. {
  1100. if( wID == IDC_CHECK_GEN_UNLIMITED )
  1101. {
  1102. EnableWindow( GetDlgItem( GetParent( hwndCtrl ) , IDC_EDIT_GEN_MAXCONS ) ,
  1103. SendMessage( hwndCtrl , BM_GETCHECK , 0 , 0 ) == BST_UNCHECKED );
  1104. EnableWindow( GetDlgItem( GetParent( hwndCtrl ) , IDC_SPINCTR_GEN ) ,
  1105. SendMessage( hwndCtrl , BM_GETCHECK , 0 , 0 ) == BST_UNCHECKED );
  1106. SendMessage(GetDlgItem(GetParent(hwndCtrl), IDC_RADIO_MAXPROP),BM_SETCHECK,(WPARAM)BST_UNCHECKED,0);
  1107. }
  1108. else if(wID == IDC_RADIO_MAXPROP)
  1109. {
  1110. EnableWindow( GetDlgItem( GetParent( hwndCtrl ) , IDC_EDIT_GEN_MAXCONS ) ,
  1111. SendMessage( hwndCtrl , BM_GETCHECK , 0 , 0 ) == BST_CHECKED );
  1112. EnableWindow( GetDlgItem( GetParent( hwndCtrl ) , IDC_SPINCTR_GEN ) ,
  1113. SendMessage( hwndCtrl , BM_GETCHECK , 0 , 0 ) == BST_CHECKED );
  1114. SendMessage(GetDlgItem(GetParent(hwndCtrl), IDC_CHECK_GEN_UNLIMITED),BM_SETCHECK,(WPARAM)BST_UNCHECKED,0);
  1115. SetFocus( GetDlgItem( GetParent( hwndCtrl ) , IDC_EDIT_GEN_MAXCONS ) );
  1116. SendMessage( GetDlgItem( GetParent( hwndCtrl ) , IDC_EDIT_GEN_MAXCONS ) , EM_SETSEL , ( WPARAM )0 , ( LPARAM )-1 );
  1117. }
  1118. if( wID != m_oldID )
  1119. {
  1120. m_bPersisted = FALSE;
  1121. // this could come from EN_CHANGE -- so don't save the current control id
  1122. if( wID != IDC_EDIT_GEN_MAXCONS )
  1123. {
  1124. m_oldID = wID;
  1125. }
  1126. }
  1127. }
  1128. else if( wNotifyCode == CBN_SELCHANGE )
  1129. {
  1130. INT_PTR iSel = SendMessage( hwndCtrl , CB_GETCURSEL , 0 , 0 );
  1131. if( iSel != ( INT_PTR )m_ulOldLanAdapter )
  1132. {
  1133. m_bPersisted = FALSE;
  1134. }
  1135. }
  1136. else if( wNotifyCode == ALN_APPLY )
  1137. {
  1138. SendMessage( GetParent( hwndCtrl ) , PSM_CANCELTOCLOSE , 0 , 0 );
  1139. return FALSE;
  1140. }
  1141. if( !m_bPersisted )
  1142. {
  1143. SendMessage( GetParent( GetParent( hwndCtrl ) ) , PSM_CHANGED , ( WPARAM )GetParent( hwndCtrl ) , 0 );
  1144. }
  1145. return FALSE;
  1146. }
  1147. //-----------------------------------------------------------------------------
  1148. BOOL CTransNetwork::PersistSettings( HWND hDlg )
  1149. {
  1150. BOOL bOk = FALSE;
  1151. if( IsValidSettings( hDlg ) )
  1152. {
  1153. ICfgComp *pCfgcomp;
  1154. bOk = TRUE;
  1155. if( m_pParent->m_pResNode->GetServer( &pCfgcomp ) == 0 )
  1156. {
  1157. return FALSE;
  1158. }
  1159. WS winsta;
  1160. ZeroMemory( &winsta , sizeof( WS ) );
  1161. // winsta.LanAdapter = ( ULONG )SendMessage( GetDlgItem( hDlg , IDC_COMBO_GEN_LANADAPTER ) , CB_GETCURSEL , 0 , 0 );
  1162. //If a group policy exists, its data will be in the winsta structure. We don't want to write that to
  1163. //the TSCC registry, so read the TSCC data by getting the User Config without merging the machine policy
  1164. POLICY_TS_MACHINE p;
  1165. RegGetMachinePolicy(&p);
  1166. if (p.fPolicyMaxInstanceCount)
  1167. {
  1168. POLICY_TS_MACHINE pTemp;
  1169. ULONG Length = 0;
  1170. WINSTATIONCONFIG2W WSConfig;
  1171. memset(&pTemp, 0, sizeof(POLICY_TS_MACHINE));
  1172. if((ERROR_SUCCESS != RegWinStationQueryEx(NULL,&pTemp,m_pParent->m_pResNode->GetConName( ),&WSConfig,sizeof(WINSTATIONCONFIG2W),&Length,FALSE)))
  1173. return FALSE;
  1174. winsta.uMaxInstanceCount = WSConfig.Create.MaxInstanceCount;
  1175. }
  1176. else
  1177. {
  1178. if( SendMessage( GetDlgItem( hDlg , IDC_CHECK_GEN_UNLIMITED ), BM_GETCHECK , 0 , 0 ) == BST_CHECKED )
  1179. winsta.uMaxInstanceCount = ( ULONG )-1;
  1180. else
  1181. winsta.uMaxInstanceCount = GetDlgItemInt( hDlg , IDC_EDIT_GEN_MAXCONS , &bOk , FALSE );
  1182. }
  1183. INT_PTR iSel = SendMessage( GetDlgItem( hDlg , IDC_COMBO_GEN_LANADAPTER ) , CB_GETCURSEL , 0 , 0 );
  1184. winsta.LanAdapter = ( ULONG )SendMessage(
  1185. GetDlgItem( hDlg , IDC_COMBO_GEN_LANADAPTER ) ,
  1186. CB_GETITEMDATA ,
  1187. ( WPARAM )iSel ,
  1188. 0 );
  1189. if( iSel != CB_ERR )
  1190. {
  1191. if( iSel != ( INT_PTR )m_ulOldLanAdapter )
  1192. {
  1193. LONG lCount;
  1194. pCfgcomp->QueryLoggedOnCount( m_pParent->m_pResNode->GetConName( ) , &lCount );
  1195. if( lCount > 0 )
  1196. {
  1197. // Warn user, changing an active lan adapter will cause all connections to disconnect
  1198. TCHAR tchMessage[ 256 ];
  1199. TCHAR tchWarn[ 40 ];
  1200. VERIFY_E( 0 , LoadString( _Module.GetResourceInstance( ) , IDS_ERR_LANCHANGE , tchMessage , SIZE_OF_BUFFER( tchMessage ) ) );
  1201. VERIFY_E( 0 , LoadString( _Module.GetResourceInstance( ) , IDS_WARN_TITLE , tchWarn , SIZE_OF_BUFFER( tchWarn ) ) );
  1202. if( MessageBox( hDlg , tchMessage , tchWarn , MB_ICONWARNING | MB_YESNO ) == IDNO )
  1203. {
  1204. bOk = FALSE;
  1205. }
  1206. }
  1207. }
  1208. }
  1209. if( bOk && iSel != CB_ERR ) //winsta.LanAdapter != CB_ERR )
  1210. {
  1211. lstrcpyn( winsta.Name , m_pParent->m_pResNode->GetConName( ) , SIZE_OF_BUFFER( winsta.Name ) - 1 );
  1212. DWORD dwStatus;
  1213. if( FAILED( pCfgcomp->UpDateWS( &winsta , UPDATE_LANADAPTER | UPDATE_MAXINSTANCECOUNT , &dwStatus, FALSE ) ) )
  1214. {
  1215. // report error and get out
  1216. ReportStatusError( hDlg , dwStatus );
  1217. pCfgcomp->Release( );
  1218. }
  1219. else
  1220. {
  1221. ODS( L"Connection LANA persisted\n" );
  1222. m_ulOldLanAdapter = ( ULONG )iSel;
  1223. ODS( L"TSCC : Forcing reg update - CTransNetwork\n" );
  1224. VERIFY_S( S_OK , pCfgcomp->ForceUpdate( ) );
  1225. VERIFY_S( S_OK , pCfgcomp->Refresh( ) );
  1226. // global flag can only be set to true
  1227. m_pParent->m_bPropertiesChange = TRUE;
  1228. PostMessage( hDlg , WM_COMMAND , MAKELPARAM( 0 , ALN_APPLY ) , ( LPARAM )hDlg );
  1229. SendMessage( GetParent( hDlg ) , PSM_UNCHANGED , ( WPARAM )hDlg , 0 );
  1230. }
  1231. }
  1232. pCfgcomp->Release( );
  1233. }
  1234. return bOk;
  1235. }
  1236. //-----------------------------------------------------------------------------
  1237. BOOL CTransNetwork::IsValidSettings( HWND hDlg )
  1238. {
  1239. BOOL ret = TRUE;
  1240. ICfgComp *pCfgcomp;
  1241. TCHAR tchMessage[ 256 ];
  1242. TCHAR tchWarn[ 40 ];
  1243. if( SendMessage( GetDlgItem( hDlg , IDC_CHECK_GEN_UNLIMITED ), BM_GETCHECK , 0 , 0 ) == BST_UNCHECKED )
  1244. {
  1245. UINT uMax;
  1246. BOOL bOK = FALSE;
  1247. uMax = GetDlgItemInt( hDlg , IDC_EDIT_GEN_MAXCONS , &bOK , FALSE );
  1248. if( !bOK )
  1249. {
  1250. ErrMessage( hDlg , IDS_ERR_CONREADFAIL );
  1251. SetFocus( GetDlgItem( hDlg , IDC_EDIT_GEN_MAXCONS ) );
  1252. SendMessage( GetDlgItem( hDlg , IDC_EDIT_GEN_MAXCONS ) , EM_SETSEL , ( WPARAM )0 , ( LPARAM )-1 );
  1253. return FALSE;
  1254. }
  1255. if( uMax > 999999UL )
  1256. {
  1257. ErrMessage( hDlg , IDS_ERR_CONMAX );
  1258. SetFocus( GetDlgItem( hDlg , IDC_EDIT_GEN_MAXCONS ) );
  1259. SendMessage( GetDlgItem( hDlg , IDC_EDIT_GEN_MAXCONS ) , EM_SETSEL , ( WPARAM )0 , ( LPARAM )-1 );
  1260. return FALSE;
  1261. }
  1262. }
  1263. if( m_pParent != NULL && m_pParent->m_pResNode != NULL )
  1264. {
  1265. if( m_pParent->m_pResNode->GetServer( &pCfgcomp ) == 0 )
  1266. {
  1267. return FALSE;
  1268. }
  1269. // PDNAMEW pName;
  1270. PWS pWinSta;
  1271. LONG cbSize;
  1272. if( SUCCEEDED( pCfgcomp->GetWSInfo( m_pParent->m_pResNode->GetConName( ) , ( PLONG )&cbSize , &pWinSta ) ) )
  1273. {
  1274. INT_PTR iSel = SendMessage( GetDlgItem( hDlg , IDC_COMBO_GEN_LANADAPTER ) , CB_GETCURSEL , 0 , 0 );
  1275. BOOL bUnique = TRUE;
  1276. if( iSel != CB_ERR )
  1277. {
  1278. if( iSel != ( int )m_ulOldLanAdapter )
  1279. {
  1280. ULONG nStations;
  1281. VERIFY_S( S_OK , pCfgcomp->GetNumofWinStations(pWinSta->wdName,pWinSta->pdName,&nStations ) );
  1282. DBGMSG( L"TSCC: Number of winstations equals = %d\n" , nStations );
  1283. if( nStations > 1 )
  1284. {
  1285. ODS( L"TSCC: We have more than one winstation verify unique lana settings\n" );
  1286. ULONG ulLana = ( ULONG )SendMessage( GetDlgItem( hDlg , IDC_COMBO_GEN_LANADAPTER ) , CB_GETITEMDATA , ( WPARAM )iSel , 0 );
  1287. VERIFY_S( S_OK , pCfgcomp->IsNetWorkConnectionUnique( m_pParent->m_pResNode->GetTypeName( ) , pWinSta->pdName , ulLana , &bUnique ) );
  1288. }
  1289. if( !bUnique )
  1290. {
  1291. //ErrMessage( hDlg , IDS_ERR_UNIQUECON );
  1292. VERIFY_E( 0 , LoadString( _Module.GetResourceInstance( ) , IDS_ERR_UNIQUECON , tchMessage , SIZE_OF_BUFFER( tchMessage ) ) );
  1293. VERIFY_E( 0 , LoadString( _Module.GetResourceInstance( ) , IDS_WARN_TITLE , tchWarn , SIZE_OF_BUFFER( tchWarn ) ) );
  1294. MessageBox( hDlg , tchMessage , tchWarn , MB_ICONINFORMATION | MB_OK );
  1295. ret = FALSE;
  1296. }
  1297. else
  1298. {
  1299. LONG lCount;
  1300. pCfgcomp->QueryLoggedOnCount( m_pParent->m_pResNode->GetConName( ) , &lCount );
  1301. if( lCount > 0 )
  1302. {
  1303. // Warn user, changing an active lan adapter will cause all connections to disconnect
  1304. TCHAR tchMessage[ 256 ];
  1305. TCHAR tchWarn[ 40 ];
  1306. VERIFY_E( 0 , LoadString( _Module.GetResourceInstance( ) , IDS_ERR_LANCHANGE , tchMessage , SIZE_OF_BUFFER( tchMessage ) ) );
  1307. VERIFY_E( 0 , LoadString( _Module.GetResourceInstance( ) , IDS_WARN_TITLE , tchWarn , SIZE_OF_BUFFER( tchWarn ) ) );
  1308. if( MessageBox( hDlg , tchMessage , tchWarn , MB_ICONWARNING | MB_YESNO ) == IDNO )
  1309. {
  1310. ret = FALSE;
  1311. }
  1312. }
  1313. }
  1314. if( ret )
  1315. {
  1316. m_ulOldLanAdapter = (ULONG)iSel;
  1317. }
  1318. }
  1319. }
  1320. CoTaskMemFree( pWinSta );
  1321. }
  1322. pCfgcomp->Release( );
  1323. }
  1324. if( !ret )
  1325. {
  1326. if( m_uMaxInstOld == ( ULONG )-1 )
  1327. {
  1328. EnableWindow( GetDlgItem( hDlg , IDC_EDIT_GEN_MAXCONS ) , FALSE );
  1329. EnableWindow( GetDlgItem( hDlg , IDC_SPINCTR_GEN ) , FALSE );
  1330. SendMessage( GetDlgItem( hDlg , IDC_CHECK_GEN_UNLIMITED ) , BM_CLICK , 0 , 0 );
  1331. m_oldID = IDC_CHECK_GEN_UNLIMITED;
  1332. }
  1333. else
  1334. {
  1335. TCHAR tchBuf[ 16 ];
  1336. EnableWindow( GetDlgItem( hDlg , IDC_EDIT_GEN_MAXCONS ) , TRUE );
  1337. EnableWindow( GetDlgItem( hDlg , IDC_SPINCTR_GEN ) , TRUE );
  1338. wsprintf( tchBuf , L"%d" , m_uMaxInstOld );
  1339. SetWindowText( GetDlgItem( hDlg , IDC_EDIT_GEN_MAXCONS ) , tchBuf );
  1340. SendMessage( GetDlgItem( hDlg , IDC_RADIO_MAXPROP) , BM_CLICK , 0 , 0 );
  1341. m_oldID = IDC_RADIO_MAXPROP;
  1342. }
  1343. SendMessage( GetDlgItem( hDlg , IDC_COMBO_GEN_LANADAPTER ) , CB_SETCURSEL , ( WPARAM )m_ulOldLanAdapter , 0 );
  1344. SendMessage( GetParent( hDlg ) , PSM_UNCHANGED , ( WPARAM )hDlg , 0 );
  1345. m_bPersisted = TRUE;
  1346. }
  1347. return ret;
  1348. }
  1349. //*****************************************************************************
  1350. CTransAsync::CTransAsync( CPropsheet * pSheet )
  1351. {
  1352. m_pParent = pSheet;
  1353. }
  1354. //-----------------------------------------------------------------------------
  1355. BOOL CTransAsync::OnInitDialog( HWND hwnd , WPARAM wp , LPARAM lp )
  1356. {
  1357. ICfgComp *pCfgcomp = NULL;
  1358. m_pParent->AddRef( );
  1359. if( m_pParent->m_pResNode->GetServer( &pCfgcomp ) == 0 )
  1360. {
  1361. ODS( L"Cound not obtain backend interface @ CTransAsync::OnInitDialog\n" );
  1362. return FALSE;
  1363. }
  1364. VERIFY_S( TRUE , m_pParent->GetCurrentUserConfig( m_uc, TRUE ) );
  1365. pCfgcomp->GetAsyncConfig( m_pParent->m_pResNode->GetConName() , WsName , &m_ac );
  1366. VERIFY_S( TRUE , CAsyncDlg::OnInitDialog( hwnd , m_pParent->m_pResNode->GetTypeName( ) , m_pParent->m_pResNode->GetConName( ) , pCfgcomp ) ) ;
  1367. BOOL bReadOnly;
  1368. if( SUCCEEDED( pCfgcomp->IsSessionReadOnly( &bReadOnly ) ) )
  1369. {
  1370. if( bReadOnly )
  1371. {
  1372. // disable the remaining controls
  1373. INT rgIds[] = {
  1374. IDC_ASYNC_DEVICENAME,
  1375. IDC_ASYNC_CONNECT,
  1376. IDC_ASYNC_BAUDRATE,
  1377. IDC_ASYNC_MODEMCALLBACK_PHONENUMBER,
  1378. IDC_ASYNC_MODEMCALLBACK_PHONENUMBER_INHERIT,
  1379. IDC_ASYNC_MODEMCALLBACK,
  1380. IDC_ASYNC_MODEMCALLBACK_INHERIT,
  1381. IDC_MODEM_PROP_PROP,
  1382. IDC_ASYNC_DEFAULTS,
  1383. IDC_ASYNC_ADVANCED,
  1384. IDC_ASYNC_TEST, -1
  1385. };
  1386. EnableGroup( hwnd , &rgIds[ 0 ] , FALSE );
  1387. }
  1388. }
  1389. pCfgcomp->Release( );
  1390. m_bPersisted = TRUE;
  1391. return CDialogPropBase::OnInitDialog( hwnd , wp , lp );
  1392. }
  1393. //-----------------------------------------------------------------------------
  1394. INT_PTR CALLBACK CTransAsync::DlgProc( HWND hwnd , UINT msg , WPARAM wp , LPARAM lp )
  1395. {
  1396. CTransAsync *pDlg;
  1397. if( msg == WM_INITDIALOG )
  1398. {
  1399. CTransAsync *pDlg = ( CTransAsync * )( ( PROPSHEETPAGE *)lp )->lParam ;
  1400. SetWindowLongPtr( hwnd , DWLP_USER , ( LONG_PTR )pDlg );
  1401. if( !IsBadReadPtr( pDlg , sizeof( CTransAsync ) ) )
  1402. {
  1403. pDlg->OnInitDialog( hwnd , wp , lp );
  1404. }
  1405. return 0;
  1406. }
  1407. else
  1408. {
  1409. pDlg = ( CTransAsync * )GetWindowLongPtr( hwnd , DWLP_USER );
  1410. if( IsBadReadPtr( pDlg , sizeof( CTransAsync ) ) )
  1411. {
  1412. return FALSE;
  1413. }
  1414. }
  1415. switch( msg )
  1416. {
  1417. case WM_NCDESTROY:
  1418. pDlg->OnDestroy( );
  1419. break;
  1420. case WM_COMMAND:
  1421. pDlg->OnCommand( HIWORD( wp ) , LOWORD( wp ) , ( HWND )lp );
  1422. break;
  1423. case WM_CONTEXTMENU:
  1424. {
  1425. POINT pt;
  1426. pt.x = LOWORD( lp );
  1427. pt.y = HIWORD( lp );
  1428. pDlg->OnContextMenu( ( HWND )wp , pt );
  1429. }
  1430. break;
  1431. case WM_HELP:
  1432. pDlg->OnHelp( hwnd , ( LPHELPINFO )lp );
  1433. break;
  1434. case WM_NOTIFY:
  1435. return pDlg->OnNotify( ( int )wp , ( LPNMHDR )lp , hwnd );
  1436. }
  1437. return FALSE;
  1438. }
  1439. //-----------------------------------------------------------------------------
  1440. BOOL CTransAsync::GetPropertySheetPage( PROPSHEETPAGE& psp )
  1441. {
  1442. ZeroMemory( &psp , sizeof( PROPSHEETPAGE ) );
  1443. psp.dwSize = sizeof( PROPSHEETPAGE );
  1444. psp.dwFlags = PSP_DEFAULT;
  1445. psp.hInstance = _Module.GetResourceInstance( );
  1446. psp.pszTemplate = MAKEINTRESOURCE( IDD_ASYNC_FACE );
  1447. psp.lParam = ( LPARAM )this;
  1448. psp.pfnDlgProc = CTransAsync::DlgProc;
  1449. return TRUE;
  1450. }
  1451. //-----------------------------------------------------------------------------
  1452. BOOL CTransAsync::OnDestroy( )
  1453. {
  1454. AsyncRelease( );
  1455. m_pParent->Release( );
  1456. return CDialogPropBase::OnDestroy( );
  1457. }
  1458. //-----------------------------------------------------------------------------
  1459. BOOL CTransAsync::OnCommand( WORD wNotifyCode , WORD wID , HWND hwndCtrl )
  1460. {
  1461. CAsyncDlg::OnCommand( wNotifyCode , wID , hwndCtrl , &m_bPersisted );
  1462. if( wNotifyCode == ALN_APPLY )
  1463. {
  1464. SendMessage( GetParent( hwndCtrl ) , PSM_CANCELTOCLOSE , 0 , 0 );
  1465. return FALSE;
  1466. }
  1467. if( !m_bPersisted )
  1468. {
  1469. SendMessage( GetParent( GetParent( hwndCtrl ) ) , PSM_CHANGED , ( WPARAM )GetParent( hwndCtrl ) , 0 );
  1470. }
  1471. return FALSE;
  1472. }
  1473. //-----------------------------------------------------------------------------
  1474. BOOL CTransAsync::PersistSettings( HWND hDlg )
  1475. {
  1476. if( !IsValidSettings( hDlg ) )
  1477. {
  1478. return FALSE;
  1479. }
  1480. ICfgComp * pCfgcomp = NULL;
  1481. if( m_pParent->m_pResNode->GetServer( &pCfgcomp ) == 0 )
  1482. {
  1483. ODS( L"Cound not obtain backend interface @ CTransAsync::OnInitDialog\n" );
  1484. return FALSE;
  1485. }
  1486. DWORD dwStatus;
  1487. HRESULT hr = pCfgcomp->SetAsyncConfig( m_pParent->m_pResNode->GetConName() , WsName , &m_ac , &dwStatus );
  1488. if( FAILED( hr ) )
  1489. {
  1490. ReportStatusError( hDlg , dwStatus );
  1491. }
  1492. if( SUCCEEDED( hr ) )
  1493. {
  1494. DWORD dwStatus;
  1495. hr = m_pParent->SetUserConfig( m_uc , &dwStatus );
  1496. if( FAILED( hr ) )
  1497. {
  1498. ReportStatusError( hDlg , dwStatus );
  1499. }
  1500. }
  1501. if( SUCCEEDED( hr ) )
  1502. {
  1503. ODS( L"TSCC : Forcing reg update - CTransAsync\n" );
  1504. VERIFY_S( S_OK , pCfgcomp->ForceUpdate( ) );
  1505. VERIFY_S( S_OK , pCfgcomp->Refresh( ) );
  1506. // global flag can only be set to true
  1507. m_pParent->m_bPropertiesChange = TRUE;
  1508. PostMessage( hDlg , WM_COMMAND , MAKELPARAM( 0 , ALN_APPLY ) , ( LPARAM )hDlg );
  1509. SendMessage( GetParent( hDlg ) , PSM_UNCHANGED , ( WPARAM )hDlg , 0 );
  1510. }
  1511. pCfgcomp->Release( );
  1512. return SUCCEEDED( hr ) ? TRUE : FALSE;
  1513. }
  1514. BOOL CTransAsync::IsValidSettings(HWND hDlg)
  1515. {
  1516. UNREFERENCED_PARAMETER( hDlg );
  1517. // all async connections are checked for usage
  1518. // thus no two connections can use the same port
  1519. return TRUE;
  1520. }
  1521. //*****************************************************************************
  1522. // Logon settings dialog
  1523. CLogonSetting::CLogonSetting( CPropsheet *pSheet )
  1524. {
  1525. m_pParent = pSheet;
  1526. m_wOldId = ( WORD )-1;
  1527. }
  1528. //-----------------------------------------------------------------------------
  1529. BOOL CLogonSetting::OnInitDialog( HWND hDlg , WPARAM wp , LPARAM lp )
  1530. {
  1531. if( !IsBadReadPtr( m_pParent , sizeof( CPropsheet ) ) )
  1532. {
  1533. m_pParent->AddRef( );
  1534. }
  1535. USERCONFIG uc;
  1536. if( !m_pParent->GetCurrentUserConfig( uc, TRUE ) )
  1537. {
  1538. ODS( L"CLogonSetting::OnInitDialog - GetCurrentUserConfig failed!!!\n" );
  1539. return FALSE;
  1540. }
  1541. /*
  1542. SendMessage( GetDlgItem( hDlg , IDC_CHECK_LOGON_INHERIT ) , BM_SETCHECK ,
  1543. uc.fInheritAutoLogon ? BST_CHECKED : BST_UNCHECKED , 0 );*/
  1544. if( uc.fInheritAutoLogon == BST_CHECKED )
  1545. {
  1546. CheckRadioButton( hDlg , IDC_CHECK_LOGON_INHERIT , IDC_RADIO_LOGON , IDC_CHECK_LOGON_INHERIT );
  1547. m_wOldId = IDC_CHECK_LOGON_INHERIT;
  1548. }
  1549. else
  1550. {
  1551. CheckRadioButton( hDlg , IDC_CHECK_LOGON_INHERIT , IDC_RADIO_LOGON , IDC_RADIO_LOGON );
  1552. m_wOldId = IDC_RADIO_LOGON;
  1553. }
  1554. SendMessage( GetDlgItem( hDlg , IDC_CHECK_LOGON_PROMPTPASSWD ), BM_SETCHECK ,
  1555. uc.fPromptForPassword ? BST_CHECKED : BST_UNCHECKED , 0 );
  1556. POLICY_TS_MACHINE p;
  1557. RegGetMachinePolicy(&p);
  1558. EnableWindow( GetDlgItem( hDlg, IDC_CHECK_LOGON_PROMPTPASSWD ), !p.fPolicyPromptForPassword);
  1559. //int rgID[] = { IDC_EDIT_LOGON_USRNAME , IDC_EDIT_LOGON_DOMAIN , IDC_EDIT_LOGON_PASSWD , IDC_EDIT_LOGON_CONFIRMPASSWD , -1 };
  1560. SendMessage( GetDlgItem( hDlg , IDC_EDIT_LOGON_USRNAME ) , EM_SETLIMITTEXT , ( WPARAM )USERNAME_LENGTH , 0 );
  1561. SendMessage( GetDlgItem( hDlg , IDC_EDIT_LOGON_DOMAIN ) , EM_SETLIMITTEXT , ( WPARAM )DOMAIN_LENGTH , 0 );
  1562. SendMessage( GetDlgItem( hDlg , IDC_EDIT_LOGON_PASSWD ) , EM_SETLIMITTEXT , ( WPARAM )PASSWORD_LENGTH , 0 );
  1563. SendMessage( GetDlgItem( hDlg , IDC_EDIT_LOGON_CONFIRMPASSWD ) , EM_SETLIMITTEXT , ( WPARAM )PASSWORD_LENGTH , 0 );
  1564. if( !uc.fInheritAutoLogon )
  1565. {
  1566. SetWindowText( GetDlgItem( hDlg , IDC_EDIT_LOGON_USRNAME ) , ( LPTSTR )uc.UserName );
  1567. SetWindowText( GetDlgItem( hDlg , IDC_EDIT_LOGON_DOMAIN ) , ( LPTSTR )uc.Domain );
  1568. }
  1569. if( !uc.fPromptForPassword )
  1570. {
  1571. SetWindowText( GetDlgItem( hDlg , IDC_EDIT_LOGON_PASSWD ) , ( LPTSTR )uc.Password );
  1572. SetWindowText( GetDlgItem( hDlg , IDC_EDIT_LOGON_CONFIRMPASSWD ) , ( LPTSTR )uc.Password );
  1573. }
  1574. int rgID[] = { IDC_EDIT_LOGON_USRNAME , IDC_STATIC_LSUSR , IDC_EDIT_LOGON_DOMAIN , IDC_STATIC_LSDOMAIN , IDC_EDIT_LOGON_PASSWD , IDC_STATIC_LSPWD , IDC_EDIT_LOGON_CONFIRMPASSWD , IDC_STATIC_LSCONPWD , -1 };
  1575. EnableGroup( hDlg , &rgID[0] , !uc.fInheritAutoLogon );
  1576. if( !uc.fInheritAutoLogon )
  1577. {
  1578. EnableGroup( hDlg , &rgID[4] , !uc.fPromptForPassword );
  1579. }
  1580. ICfgComp *pCfgcomp = NULL;
  1581. if( m_pParent->m_pResNode->GetServer( &pCfgcomp ) != 0 )
  1582. {
  1583. BOOL bReadOnly;
  1584. if( SUCCEEDED( pCfgcomp->IsSessionReadOnly( &bReadOnly ) ) )
  1585. {
  1586. if( bReadOnly )
  1587. {
  1588. // make edit controls read-only
  1589. SendMessage( GetDlgItem( hDlg , IDC_EDIT_LOGON_USRNAME ) , EM_SETREADONLY , ( WPARAM )TRUE , 0 );
  1590. SendMessage( GetDlgItem( hDlg , IDC_EDIT_LOGON_DOMAIN ) , EM_SETREADONLY , ( WPARAM )TRUE , 0 );
  1591. // disable the remaining controls
  1592. INT rgIds[] = {
  1593. IDC_EDIT_LOGON_PASSWD,
  1594. IDC_EDIT_LOGON_CONFIRMPASSWD,
  1595. IDC_CHECK_LOGON_PROMPTPASSWD,
  1596. IDC_CHECK_LOGON_INHERIT,
  1597. IDC_RADIO_LOGON,
  1598. -1
  1599. };
  1600. EnableGroup( hDlg , &rgIds[ 0 ] , FALSE );
  1601. }
  1602. }
  1603. pCfgcomp->Release( );
  1604. }
  1605. m_bPersisted = TRUE;
  1606. return CDialogPropBase::OnInitDialog( hDlg , wp , lp );
  1607. }
  1608. //-----------------------------------------------------------------------------
  1609. INT_PTR CALLBACK CLogonSetting::DlgProc( HWND hwnd , UINT msg , WPARAM wp , LPARAM lp )
  1610. {
  1611. CLogonSetting *pDlg;
  1612. if( msg == WM_INITDIALOG )
  1613. {
  1614. CLogonSetting *pDlg = ( CLogonSetting * )( ( PROPSHEETPAGE *)lp )->lParam ;
  1615. SetWindowLongPtr( hwnd , DWLP_USER , ( LONG_PTR )pDlg );
  1616. if( !IsBadReadPtr( pDlg , sizeof( CLogonSetting ) ) )
  1617. {
  1618. pDlg->OnInitDialog( hwnd , wp , lp );
  1619. }
  1620. return 0;
  1621. }
  1622. else
  1623. {
  1624. pDlg = ( CLogonSetting * )GetWindowLongPtr( hwnd , DWLP_USER );
  1625. if( IsBadReadPtr( pDlg , sizeof( CLogonSetting ) ) )
  1626. {
  1627. return FALSE;
  1628. }
  1629. }
  1630. switch( msg )
  1631. {
  1632. case WM_NCDESTROY:
  1633. pDlg->OnDestroy( );
  1634. break;
  1635. case WM_COMMAND:
  1636. pDlg->OnCommand( HIWORD( wp ) , LOWORD( wp ) , ( HWND )lp );
  1637. break;
  1638. case WM_CONTEXTMENU:
  1639. {
  1640. POINT pt;
  1641. pt.x = LOWORD( lp );
  1642. pt.y = HIWORD( lp );
  1643. pDlg->OnContextMenu( ( HWND )wp , pt );
  1644. }
  1645. break;
  1646. case WM_HELP:
  1647. pDlg->OnHelp( hwnd , ( LPHELPINFO )lp );
  1648. break;
  1649. case WM_NOTIFY:
  1650. return pDlg->OnNotify( ( int )wp , ( LPNMHDR )lp , hwnd );
  1651. }
  1652. return 0;
  1653. }
  1654. //-----------------------------------------------------------------------------
  1655. BOOL CLogonSetting::GetPropertySheetPage( PROPSHEETPAGE& psp )
  1656. {
  1657. ZeroMemory( &psp , sizeof( PROPSHEETPAGE ) );
  1658. psp.dwSize = sizeof( PROPSHEETPAGE );
  1659. psp.dwFlags = PSP_DEFAULT;
  1660. psp.hInstance = _Module.GetResourceInstance( );
  1661. psp.pszTemplate = MAKEINTRESOURCE( IDD_LOGONSETTINGS );
  1662. psp.lParam = ( LPARAM )this;
  1663. psp.pfnDlgProc = CLogonSetting::DlgProc;
  1664. return TRUE;
  1665. }
  1666. //---------------------------------------------------------------------------
  1667. BOOL CLogonSetting::OnCommand( WORD wNotifyCode , WORD wID , HWND hwndCtrl )
  1668. {
  1669. if( wNotifyCode == BN_CLICKED )
  1670. {
  1671. int rgID[] = { IDC_EDIT_LOGON_USRNAME , IDC_STATIC_LSUSR , IDC_EDIT_LOGON_DOMAIN , IDC_STATIC_LSDOMAIN , IDC_EDIT_LOGON_PASSWD , IDC_STATIC_LSPWD , IDC_EDIT_LOGON_CONFIRMPASSWD , IDC_STATIC_LSCONPWD , -1 };
  1672. BOOL bEnable = ( BOOL )SendMessage( GetDlgItem( GetParent( hwndCtrl ) , IDC_CHECK_LOGON_INHERIT ) , BM_GETCHECK , 0 , 0 ) == BST_UNCHECKED;
  1673. if( wID == IDC_CHECK_LOGON_INHERIT )
  1674. {
  1675. EnableGroup( GetParent( hwndCtrl ) , &rgID[ 0 ] , bEnable );
  1676. if( bEnable )
  1677. {
  1678. EnableGroup( GetParent( hwndCtrl ) , &rgID[ 4 ] , SendMessage( GetDlgItem( GetParent( hwndCtrl ) , IDC_CHECK_LOGON_PROMPTPASSWD ) , BM_GETCHECK , 0 , 0 ) == BST_UNCHECKED );
  1679. SendMessage(GetDlgItem(GetParent(hwndCtrl), IDC_RADIO_LOGON),BM_SETCHECK,(WPARAM)BST_CHECKED,0);
  1680. }
  1681. else
  1682. {
  1683. SendMessage(GetDlgItem(GetParent(hwndCtrl), IDC_RADIO_LOGON),BM_SETCHECK,(WPARAM)BST_UNCHECKED,0);
  1684. }
  1685. }
  1686. else if( wID == IDC_CHECK_LOGON_PROMPTPASSWD )
  1687. {
  1688. if( bEnable )
  1689. {
  1690. EnableGroup( GetParent( hwndCtrl ) , &rgID[ 4 ] , SendMessage( hwndCtrl , BM_GETCHECK , 0 , 0 ) == BST_UNCHECKED );
  1691. }
  1692. // make sure apply button becomes enabled when user checks this box
  1693. m_bPersisted = FALSE;
  1694. }
  1695. else if( wID == IDC_RADIO_LOGON )
  1696. {
  1697. BOOL bChecked = SendMessage( hwndCtrl , BM_GETCHECK , 0 , 0 ) == BST_CHECKED ;
  1698. if(bChecked)
  1699. {
  1700. //SendMessage(GetDlgItem(GetParent(hwndCtrl), IDC_CHECK_LOGON_INHERIT),BM_SETCHECK,(WPARAM)BST_UNCHECKED,0);
  1701. EnableGroup( GetParent( hwndCtrl ) , &rgID[ 0 ] , TRUE );
  1702. EnableGroup( GetParent( hwndCtrl ) , &rgID[ 4 ] , !( SendMessage( GetDlgItem( GetParent( hwndCtrl ) , IDC_CHECK_LOGON_PROMPTPASSWD ) , BM_GETCHECK , 0 , 0 ) == BST_CHECKED ) );
  1703. }
  1704. else
  1705. {
  1706. SendMessage(GetDlgItem(GetParent(hwndCtrl), IDC_CHECK_LOGON_INHERIT),BM_SETCHECK,(WPARAM)BST_CHECKED,0);
  1707. }
  1708. //SendMessage(GetDlgItem(GetParent(hwndCtrl), IDC_CHECK_ICCP_WZ),BM_CLICK,0,0);
  1709. }
  1710. // if radio button from the last is different enabled the apply button
  1711. if( m_wOldId != wID )
  1712. {
  1713. m_wOldId = wID;
  1714. m_bPersisted = FALSE;
  1715. }
  1716. }
  1717. else if( wNotifyCode == EN_CHANGE )
  1718. {
  1719. m_bPersisted = FALSE;
  1720. }
  1721. else if( wNotifyCode == ALN_APPLY )
  1722. {
  1723. SendMessage( GetParent( hwndCtrl ) , PSM_CANCELTOCLOSE , 0 , 0 );
  1724. return FALSE;
  1725. }
  1726. if( !m_bPersisted )
  1727. {
  1728. SendMessage( GetParent( GetParent( hwndCtrl ) ) , PSM_CHANGED , ( WPARAM )GetParent( hwndCtrl ) , 0 );
  1729. }
  1730. return FALSE;
  1731. }
  1732. //-----------------------------------------------------------------------------
  1733. BOOL CLogonSetting::OnDestroy( )
  1734. {
  1735. m_pParent->Release( );
  1736. return CDialogPropBase::OnDestroy( );
  1737. }
  1738. //-----------------------------------------------------------------------------
  1739. BOOL CLogonSetting::PersistSettings( HWND hDlg )
  1740. {
  1741. if( m_pParent != NULL )
  1742. {
  1743. USERCONFIG uc;
  1744. m_pParent->GetCurrentUserConfig( uc, TRUE );
  1745. uc.fPromptForPassword = SendMessage( GetDlgItem( hDlg , IDC_CHECK_LOGON_PROMPTPASSWD ) , BM_GETCHECK , 0 , 0 ) == BST_CHECKED ? TRUE : FALSE;
  1746. if( !uc.fPromptForPassword )
  1747. {
  1748. if( !ConfirmPassWd( hDlg ) )
  1749. {
  1750. return FALSE;
  1751. }
  1752. }
  1753. else
  1754. {
  1755. ZeroMemory( ( PVOID )uc.Password , sizeof( uc.Password ) );
  1756. }
  1757. if( SendMessage( GetDlgItem( hDlg , IDC_CHECK_LOGON_INHERIT ) , BM_GETCHECK , 0 , 0 ) == BST_CHECKED )
  1758. {
  1759. uc.fInheritAutoLogon = TRUE;
  1760. ZeroMemory( ( PVOID )uc.UserName , sizeof( uc.UserName ) );
  1761. ZeroMemory( ( PVOID )uc.Domain , sizeof( uc.Domain ) );
  1762. ZeroMemory( ( PVOID )uc.Password , sizeof( uc.Password ) );
  1763. }
  1764. else
  1765. {
  1766. uc.fInheritAutoLogon = FALSE;
  1767. GetWindowText( GetDlgItem( hDlg , IDC_EDIT_LOGON_USRNAME ) , uc.UserName , USERNAME_LENGTH + 1 );
  1768. GetWindowText( GetDlgItem( hDlg , IDC_EDIT_LOGON_DOMAIN ) , uc.Domain , DOMAIN_LENGTH + 1 );
  1769. GetWindowText( GetDlgItem( hDlg , IDC_EDIT_LOGON_PASSWD ) , uc.Password , PASSWORD_LENGTH + 1 );
  1770. }
  1771. DWORD dwStatus;
  1772. if( FAILED( m_pParent->SetUserConfig( uc , &dwStatus ) ) )
  1773. {
  1774. ReportStatusError( hDlg , dwStatus );
  1775. return FALSE;
  1776. }
  1777. ICfgComp *pCfgcomp = NULL;
  1778. if( m_pParent->m_pResNode->GetServer( &pCfgcomp ) > 0 )
  1779. {
  1780. VERIFY_S( S_OK , pCfgcomp->ForceUpdate( ) );
  1781. VERIFY_S( S_OK , pCfgcomp->Refresh( ) );
  1782. // global flag can only be set to true
  1783. m_pParent->m_bPropertiesChange = TRUE;
  1784. pCfgcomp->Release( );
  1785. }
  1786. PostMessage( hDlg , WM_COMMAND , MAKELPARAM( 0 , ALN_APPLY ) , ( LPARAM )hDlg );
  1787. SendMessage( GetParent( hDlg ) , PSM_UNCHANGED , ( WPARAM )hDlg , 0 );
  1788. return TRUE;
  1789. }
  1790. return FALSE;
  1791. }
  1792. //-----------------------------------------------------------------------------
  1793. BOOL CLogonSetting::IsValidSettings( HWND hDlg )
  1794. {
  1795. if( SendMessage( GetDlgItem( hDlg , IDC_CHECK_LOGON_PROMPTPASSWD ) , BM_GETCHECK , 0 , 0 ) == BST_UNCHECKED )
  1796. {
  1797. return ConfirmPassWd( hDlg );
  1798. }
  1799. return TRUE;
  1800. }
  1801. //-----------------------------------------------------------------------------
  1802. BOOL CLogonSetting::ConfirmPassWd( HWND hDlg )
  1803. {
  1804. TCHAR tchPzWd[ PASSWORD_LENGTH + 1];
  1805. TCHAR tchConfirm[ PASSWORD_LENGTH + 1];
  1806. if( SendMessage( GetDlgItem( hDlg , IDC_CHECK_LOGON_INHERIT ) , BM_GETCHECK , 0 , 0 ) == BST_CHECKED )
  1807. {
  1808. return TRUE;
  1809. }
  1810. int iSz = GetWindowText( GetDlgItem( hDlg , IDC_EDIT_LOGON_PASSWD ) , tchPzWd , PASSWORD_LENGTH + 1 );
  1811. // warn on the minimum and maximum sizes
  1812. if( iSz > PASSWORD_LENGTH ) //if( iSz > 0 && ( iSz < 6 || iSz > PASSWORD_LENGTH ) )
  1813. {
  1814. ErrMessage( hDlg , IDS_ERR_PASSWD );
  1815. // set focus back on password and erase the confirm entry
  1816. SetFocus( GetDlgItem( hDlg , IDC_EDIT_LOGON_PASSWD ) );
  1817. SendMessage( GetDlgItem( hDlg , IDC_EDIT_LOGON_PASSWD ) , EM_SETSEL , ( WPARAM )0 , ( LPARAM )-1 );
  1818. SetWindowText( GetDlgItem( hDlg , IDC_EDIT_LOGON_CONFIRMPASSWD ) , L"" );
  1819. return FALSE;
  1820. }
  1821. int iSz2 = GetWindowText( GetDlgItem( hDlg , IDC_EDIT_LOGON_CONFIRMPASSWD ) , tchConfirm , PASSWORD_LENGTH + 1 );
  1822. if( iSz == iSz2 )
  1823. {
  1824. if( iSz == 0 )
  1825. {
  1826. return TRUE;
  1827. }
  1828. if( lstrcmp( tchPzWd , tchConfirm ) == 0 )
  1829. {
  1830. return TRUE;
  1831. }
  1832. }
  1833. ErrMessage( hDlg , IDS_ERR_PASSCONFIRM );
  1834. SetFocus( GetDlgItem( hDlg , IDC_EDIT_LOGON_CONFIRMPASSWD ) );
  1835. SetWindowText( GetDlgItem( hDlg , IDC_EDIT_LOGON_CONFIRMPASSWD ) , L"" );
  1836. return FALSE;
  1837. }
  1838. //*****************************************************************************
  1839. // Time out settings dialog
  1840. CTimeSetting::CTimeSetting( CPropsheet *pSheet )
  1841. {
  1842. m_pParent = pSheet;
  1843. m_wOldAction = ( WORD )-1;
  1844. m_wOldCon = ( WORD )-1;
  1845. m_bPrevClient = FALSE;
  1846. }
  1847. //-----------------------------------------------------------------------------
  1848. BOOL CTimeSetting::OnInitDialog( HWND hwnd , WPARAM wp , LPARAM lp )
  1849. {
  1850. TCHAR tchBuffer[ 80 ];
  1851. if( m_pParent == NULL )
  1852. {
  1853. ODS( L"CTimeSetting::OnInitDialog - PropertySheet: We've lost our parent node!!!\n" );
  1854. return FALSE;
  1855. }
  1856. m_pParent->AddRef( );
  1857. USERCONFIG uc;
  1858. HWND hCombo[ 3 ] =
  1859. {
  1860. GetDlgItem( hwnd , IDC_COMBO_TIMEOUTS_CON_PS ),
  1861. GetDlgItem( hwnd , IDC_COMBO_TIMEOUTS_DISCON_PS ),
  1862. GetDlgItem( hwnd , IDC_COMBO_TIMEOUTS_IDLE_PS )
  1863. };
  1864. DWORD rgdwTime[] = { 0 , 1 , 5 , 10 , 15 , 30 , 60 , 120 , 180 , 1440 , 2880 , ( DWORD )-1 };
  1865. for( int idx = 0; rgdwTime[ idx ] != ( DWORD)-1; ++idx )
  1866. {
  1867. if( rgdwTime[ idx ] == 0 )
  1868. {
  1869. LoadString( _Module.GetResourceInstance( ) , IDS_NOTIMEOUT , tchBuffer , SIZE_OF_BUFFER( tchBuffer ) );
  1870. }
  1871. else
  1872. {
  1873. ConvertToDuration( rgdwTime[ idx ] , tchBuffer );
  1874. }
  1875. for( int inner = 0 ; inner < 3 ; ++inner )
  1876. {
  1877. SendMessage( hCombo[ inner ] , CB_ADDSTRING , 0 , ( LPARAM )&tchBuffer[0] );
  1878. SendMessage( hCombo[ inner ] , CB_SETITEMDATA , idx , rgdwTime[ idx ] );
  1879. }
  1880. }
  1881. if( !m_pParent->GetCurrentUserConfig( uc, TRUE ) )
  1882. {
  1883. ODS( L"CTimeSetting::OnInitDialog - PropertySheet: Could not get current USERCONFIG\n" );
  1884. return FALSE;
  1885. }
  1886. ULONG ulTime;
  1887. if( uc.MaxConnectionTime > 0 )
  1888. {
  1889. ulTime = uc.MaxConnectionTime / kMilliMinute;
  1890. InsertSortedAndSetCurSel( hCombo[ 0 ] , ulTime );
  1891. }
  1892. else
  1893. {
  1894. SendMessage( hCombo[ 0 ] , CB_SETCURSEL , 0 , 0 );
  1895. }
  1896. CTimeOutDlg::InitControl( hCombo[ 0 ] );
  1897. //
  1898. // Set the current or default disconnection timeout
  1899. //
  1900. if( uc.MaxDisconnectionTime > 0 )
  1901. {
  1902. ulTime = uc.MaxDisconnectionTime / kMilliMinute;
  1903. InsertSortedAndSetCurSel( hCombo[ 1 ] , ulTime );
  1904. }
  1905. else
  1906. {
  1907. SendMessage( hCombo[ 1] , CB_SETCURSEL , 0 , 0 );
  1908. }
  1909. CTimeOutDlg::InitControl( hCombo[ 1 ] );
  1910. //
  1911. // Set the current or default idle timeout
  1912. //
  1913. if( uc.MaxIdleTime > 0 )
  1914. {
  1915. ulTime = uc.MaxIdleTime / kMilliMinute;
  1916. InsertSortedAndSetCurSel( hCombo[ 2 ] , ulTime );
  1917. }
  1918. else
  1919. {
  1920. SendMessage( hCombo[ 2 ] , CB_SETCURSEL , 0 , 0 );
  1921. }
  1922. CTimeOutDlg::InitControl( hCombo[ 2 ] );
  1923. //
  1924. // all the timeout settings will have the same inherit status (NOT!)
  1925. //
  1926. // GP made all these settings orthogonal. When we write son of TSCC
  1927. // in Blackcomb, we should allow individual settings.
  1928. //
  1929. // ASSERT( ( BOOL )uc.fInheritMaxSessionTime == ( BOOL )uc.fInheritMaxDisconnectionTime );
  1930. // ASSERT( ( BOOL )uc.fInheritMaxSessionTime == ( BOOL )uc.fInheritMaxIdleTime );
  1931. DBGMSG( L"uc.fInheritMaxSessionTime %d\n" , uc.fInheritMaxSessionTime );
  1932. DBGMSG( L"uc.fInheritMaxDisconnectionTime %d\n" , uc.fInheritMaxDisconnectionTime );
  1933. DBGMSG( L"uc.fInheritMaxIdleTime %d\n" , uc.fInheritMaxIdleTime );
  1934. SendMessage( GetDlgItem( hwnd , IDC_CHECK_INHERITTIMEOUT_PS ) , BM_SETCHECK , ( WPARAM )( BOOL )!uc.fInheritMaxSessionTime , 0 );
  1935. SetTimeoutControls(hwnd);
  1936. SendMessage( GetDlgItem( hwnd , IDC_CHECK_TIMEOUTS_INHERITBKCON_PS ) , BM_SETCHECK , ( WPARAM )!uc.fInheritResetBroken , 0 );
  1937. if( uc.fResetBroken ) //BST_CHECKED : BST_UNCHECKED
  1938. {
  1939. CheckDlgButton( hwnd , IDC_RADIO_TIMEOUTS_RESET_PS , BST_CHECKED );
  1940. m_wOldAction = IDC_RADIO_TIMEOUTS_RESET_PS;
  1941. }
  1942. else
  1943. {
  1944. CheckDlgButton( hwnd , IDC_RADIO_TIMEOUTS_DISCON_PS , BST_CHECKED );
  1945. m_wOldAction = IDC_RADIO_TIMEOUTS_DISCON_PS;
  1946. }
  1947. /*
  1948. if( uc.fReconnectSame )
  1949. {
  1950. CheckDlgButton( hwnd , IDC_RADIO_TIMEOUTS_PREVCLNT_PS , BST_CHECKED );
  1951. m_wOldCon = IDC_RADIO_TIMEOUTS_PREVCLNT_PS;
  1952. }
  1953. else
  1954. {
  1955. CheckDlgButton( hwnd , IDC_RADIO_TIMEOUTS_ANYCLIENT_PS , BST_CHECKED );
  1956. m_wOldCon = IDC_RADIO_TIMEOUTS_ANYCLIENT_PS;
  1957. }
  1958. */
  1959. SetBkResetControls(hwnd);
  1960. SendMessage( GetDlgItem( hwnd , IDC_CHECK_TIMEOUTS_INHERITRECON_PS ) , BM_SETCHECK , ( WPARAM )!uc.fInheritReconnectSame , 0 );
  1961. //SetReconControls( hwnd , !uc.fInheritReconnectSame );
  1962. LoadAbbreviates( );
  1963. ICfgComp *pCfgcomp = NULL;
  1964. if( m_pParent->m_pResNode->GetServer( &pCfgcomp ) != 0 )
  1965. {
  1966. BOOL bReadOnly = FALSE;
  1967. if( SUCCEEDED( pCfgcomp->IsSessionReadOnly( &bReadOnly ) ) )
  1968. {
  1969. if( bReadOnly )
  1970. {
  1971. // disable the remaining controls
  1972. int rgID[] = {
  1973. IDC_COMBO_TIMEOUTS_CON_PS ,
  1974. IDC_COMBO_TIMEOUTS_DISCON_PS ,
  1975. IDC_COMBO_TIMEOUTS_IDLE_PS ,
  1976. IDC_RADIO_TIMEOUTS_DISCON_PS ,
  1977. IDC_RADIO_TIMEOUTS_RESET_PS ,
  1978. IDC_RADIO_TIMEOUTS_ANYCLIENT_PS ,
  1979. IDC_RADIO_TIMEOUTS_PREVCLNT_PS ,
  1980. IDC_CHECK_INHERITTIMEOUT_PS,
  1981. IDC_CHECK_TIMEOUTS_INHERITBKCON_PS,
  1982. IDC_CHECK_TIMEOUTS_INHERITRECON_PS,
  1983. -1
  1984. };
  1985. EnableGroup( hwnd , &rgID[ 0 ] , FALSE );
  1986. }
  1987. }
  1988. if( !bReadOnly )
  1989. {
  1990. ULONG mask = 0;
  1991. if( SUCCEEDED( pCfgcomp->GetCaps( m_pParent->m_pResNode->GetTypeName( ) , &mask ) ) )
  1992. {
  1993. // citrix only flag
  1994. m_bPrevClient = mask & WDC_RECONNECT_PREVCLIENT;
  1995. if( !m_bPrevClient )
  1996. {
  1997. EnableWindow( GetDlgItem( hwnd , IDC_CHECK_TIMEOUTS_INHERITRECON_PS ) , FALSE );
  1998. }
  1999. SetReconControls(hwnd);
  2000. }
  2001. }
  2002. pCfgcomp->Release( );
  2003. }
  2004. if( uc.fReconnectSame )
  2005. {
  2006. CheckDlgButton( hwnd , IDC_RADIO_TIMEOUTS_PREVCLNT_PS , BST_CHECKED );
  2007. m_wOldCon = IDC_RADIO_TIMEOUTS_PREVCLNT_PS;
  2008. }
  2009. else
  2010. {
  2011. CheckDlgButton( hwnd , IDC_RADIO_TIMEOUTS_ANYCLIENT_PS , BST_CHECKED );
  2012. m_wOldCon = IDC_RADIO_TIMEOUTS_ANYCLIENT_PS;
  2013. }
  2014. m_bPersisted = TRUE;
  2015. return CDialogPropBase::OnInitDialog( hwnd , wp , lp );
  2016. }
  2017. //-----------------------------------------------------------------------------
  2018. // the next set of functions manage the enabling and disabling of the controls
  2019. //-----------------------------------------------------------------------------
  2020. void CTimeSetting::SetTimeoutControls(HWND hDlg)
  2021. {
  2022. POLICY_TS_MACHINE p;
  2023. RegGetMachinePolicy(&p);
  2024. BOOL bOverride =
  2025. (SendMessage(GetDlgItem(hDlg, IDC_CHECK_INHERITTIMEOUT_PS), BM_GETCHECK, 0, 0) == BST_CHECKED);
  2026. EnableWindow(GetDlgItem(hDlg, IDC_COMBO_TIMEOUTS_CON_PS), (bOverride && !p.fPolicyMaxSessionTime));
  2027. EnableWindow(GetDlgItem(hDlg, IDC_STATIC_TIMCON), (bOverride && !p.fPolicyMaxSessionTime));
  2028. EnableWindow(GetDlgItem(hDlg, IDC_COMBO_TIMEOUTS_DISCON_PS), (bOverride && !p.fPolicyMaxDisconnectionTime));
  2029. EnableWindow(GetDlgItem(hDlg, IDC_STATIC_TIMDISCON), (bOverride && !p.fPolicyMaxDisconnectionTime));
  2030. EnableWindow(GetDlgItem(hDlg, IDC_COMBO_TIMEOUTS_IDLE_PS), (bOverride && !p.fPolicyMaxIdleTime));
  2031. EnableWindow(GetDlgItem(hDlg, IDC_STATIC_TIMIDLE), (bOverride && !p.fPolicyMaxIdleTime));
  2032. EnableWindow(GetDlgItem(hDlg, IDC_CHECK_INHERITTIMEOUT_PS),
  2033. !(p.fPolicyMaxSessionTime && p.fPolicyMaxDisconnectionTime && p.fPolicyMaxIdleTime));
  2034. }
  2035. void CTimeSetting::SetBkResetControls(HWND hDlg)
  2036. {
  2037. POLICY_TS_MACHINE p;
  2038. RegGetMachinePolicy(&p);
  2039. BOOL bOverride =
  2040. (SendMessage(GetDlgItem(hDlg, IDC_CHECK_TIMEOUTS_INHERITBKCON_PS), BM_GETCHECK, 0, 0) == BST_CHECKED);
  2041. EnableWindow(GetDlgItem(hDlg, IDC_RADIO_TIMEOUTS_DISCON_PS), bOverride && !p.fPolicyResetBroken);
  2042. EnableWindow(GetDlgItem(hDlg, IDC_RADIO_TIMEOUTS_RESET_PS), bOverride && !p.fPolicyResetBroken);
  2043. EnableWindow(GetDlgItem(hDlg, IDC_CHECK_TIMEOUTS_INHERITBKCON_PS), !p.fPolicyResetBroken);
  2044. }
  2045. void CTimeSetting::SetReconControls(HWND hDlg)
  2046. {
  2047. POLICY_TS_MACHINE p;
  2048. RegGetMachinePolicy(&p);
  2049. BOOL bOverride =
  2050. (SendMessage(GetDlgItem(hDlg, IDC_CHECK_TIMEOUTS_INHERITRECON_PS), BM_GETCHECK, 0, 0) == BST_CHECKED);
  2051. if( !m_bPrevClient )
  2052. {
  2053. EnableWindow(GetDlgItem(hDlg, IDC_RADIO_TIMEOUTS_ANYCLIENT_PS), FALSE);
  2054. EnableWindow(GetDlgItem(hDlg, IDC_RADIO_TIMEOUTS_PREVCLNT_PS), FALSE);
  2055. EnableWindow(GetDlgItem(hDlg, IDC_CHECK_TIMEOUTS_INHERITRECON_PS), FALSE);
  2056. }
  2057. else
  2058. {
  2059. EnableWindow(GetDlgItem(hDlg, IDC_RADIO_TIMEOUTS_ANYCLIENT_PS), bOverride && !p.fPolicyReconnectSame);
  2060. EnableWindow(GetDlgItem(hDlg, IDC_RADIO_TIMEOUTS_PREVCLNT_PS), bOverride && !p.fPolicyReconnectSame);
  2061. EnableWindow(GetDlgItem(hDlg, IDC_CHECK_TIMEOUTS_INHERITRECON_PS), !p.fPolicyReconnectSame);
  2062. }
  2063. }
  2064. //-----------------------------------------------------------------------------
  2065. INT_PTR CALLBACK CTimeSetting::DlgProc( HWND hwnd , UINT msg , WPARAM wp , LPARAM lp )
  2066. {
  2067. CTimeSetting *pDlg;
  2068. if( msg == WM_INITDIALOG )
  2069. {
  2070. CTimeSetting *pDlg = ( CTimeSetting * )( ( PROPSHEETPAGE *)lp )->lParam ;
  2071. SetWindowLongPtr( hwnd , DWLP_USER , ( LONG_PTR )pDlg );
  2072. if( !IsBadReadPtr( pDlg , sizeof( CTimeSetting ) ) )
  2073. {
  2074. pDlg->OnInitDialog( hwnd , wp , lp );
  2075. }
  2076. return 0;
  2077. }
  2078. else
  2079. {
  2080. pDlg = ( CTimeSetting * )GetWindowLongPtr( hwnd , DWLP_USER );
  2081. if( IsBadReadPtr( pDlg , sizeof( CTimeSetting ) ) )
  2082. {
  2083. return FALSE;
  2084. }
  2085. }
  2086. switch( msg )
  2087. {
  2088. case WM_NCDESTROY:
  2089. pDlg->OnDestroy( );
  2090. break;
  2091. case WM_COMMAND:
  2092. pDlg->OnCommand( HIWORD( wp ) , LOWORD( wp ) , ( HWND )lp );
  2093. break;
  2094. case WM_CONTEXTMENU:
  2095. {
  2096. POINT pt;
  2097. pt.x = LOWORD( lp );
  2098. pt.y = HIWORD( lp );
  2099. pDlg->OnContextMenu( ( HWND )wp , pt );
  2100. }
  2101. break;
  2102. case WM_HELP:
  2103. pDlg->OnHelp( hwnd , ( LPHELPINFO )lp );
  2104. break;
  2105. case WM_NOTIFY:
  2106. return pDlg->OnNotify( ( int )wp , ( LPNMHDR )lp , hwnd );
  2107. }
  2108. return 0;
  2109. }
  2110. //-----------------------------------------------------------------------------
  2111. BOOL CTimeSetting::GetPropertySheetPage( PROPSHEETPAGE& psp )
  2112. {
  2113. ZeroMemory( &psp , sizeof( PROPSHEETPAGE ) );
  2114. psp.dwSize = sizeof( PROPSHEETPAGE );
  2115. psp.dwFlags = PSP_DEFAULT;
  2116. psp.hInstance = _Module.GetResourceInstance( );
  2117. psp.pszTemplate = MAKEINTRESOURCE( IDD_TIMEOUTS_PS );
  2118. psp.lParam = ( LPARAM )this;
  2119. psp.pfnDlgProc = CTimeSetting::DlgProc;
  2120. return TRUE;
  2121. }
  2122. //-----------------------------------------------------------------------------
  2123. BOOL CTimeSetting::OnCommand( WORD wNotifyCode , WORD wID , HWND hwndCtrl )
  2124. {
  2125. if( wNotifyCode == BN_CLICKED )
  2126. {
  2127. if( wID == IDC_CHECK_INHERITTIMEOUT_PS )
  2128. {
  2129. SetTimeoutControls(GetParent(hwndCtrl));
  2130. m_bPersisted = FALSE;
  2131. }
  2132. else if( wID == IDC_CHECK_TIMEOUTS_INHERITBKCON_PS )
  2133. {
  2134. SetBkResetControls(GetParent(hwndCtrl));
  2135. m_bPersisted = FALSE;
  2136. }
  2137. else if( wID == IDC_CHECK_TIMEOUTS_INHERITRECON_PS )
  2138. {
  2139. SetReconControls(GetParent(hwndCtrl));
  2140. m_bPersisted = FALSE;
  2141. }
  2142. else if( wID == IDC_RADIO_TIMEOUTS_DISCON_PS || wID == IDC_RADIO_TIMEOUTS_RESET_PS )
  2143. {
  2144. if( wID != m_wOldAction )
  2145. {
  2146. m_wOldAction = wID;
  2147. m_bPersisted = FALSE;
  2148. }
  2149. }
  2150. else if( wID == IDC_RADIO_TIMEOUTS_ANYCLIENT_PS || wID == IDC_RADIO_TIMEOUTS_PREVCLNT_PS )
  2151. {
  2152. if( wID != m_wOldCon )
  2153. {
  2154. m_wOldCon = wID;
  2155. m_bPersisted = FALSE;
  2156. }
  2157. }
  2158. }
  2159. else if( wNotifyCode == ALN_APPLY )
  2160. {
  2161. SendMessage( GetParent( hwndCtrl ) , PSM_CANCELTOCLOSE , 0 , 0 );
  2162. return FALSE;
  2163. }
  2164. else
  2165. {
  2166. CTimeOutDlg::OnCommand( wNotifyCode , wID , hwndCtrl , &m_bPersisted );
  2167. }
  2168. if( !m_bPersisted )
  2169. {
  2170. SendMessage( GetParent( GetParent( hwndCtrl ) ) , PSM_CHANGED , ( WPARAM )GetParent( hwndCtrl ) , 0 );
  2171. }
  2172. return FALSE;
  2173. }
  2174. //-----------------------------------------------------------------------------
  2175. int CTimeSetting::GetCBXSTATEindex( HWND hCombo )
  2176. {
  2177. int idx = -1;
  2178. switch( GetDlgCtrlID( hCombo ) )
  2179. {
  2180. case IDC_COMBO_TIMEOUTS_CON_PS:
  2181. idx = 0;
  2182. break;
  2183. case IDC_COMBO_TIMEOUTS_DISCON_PS:
  2184. idx = 1;
  2185. break;
  2186. case IDC_COMBO_TIMEOUTS_IDLE_PS:
  2187. idx = 2;
  2188. break;
  2189. }
  2190. return idx;
  2191. }
  2192. //-------------------------------------------------------------------------------
  2193. // PersistSettings
  2194. //-------------------------------------------------------------------------------
  2195. BOOL CTimeSetting::PersistSettings( HWND hDlg )
  2196. {
  2197. if( m_pParent == NULL )
  2198. {
  2199. return FALSE;
  2200. }
  2201. USERCONFIG uc;
  2202. if( !m_pParent->GetCurrentUserConfig( uc, TRUE ) )
  2203. {
  2204. return FALSE;
  2205. }
  2206. if( SendMessage( GetDlgItem( hDlg , IDC_CHECK_INHERITTIMEOUT_PS ) , BM_GETCHECK , 0 , 0 ) == BST_UNCHECKED )
  2207. {
  2208. uc.fInheritMaxSessionTime = 1;
  2209. uc.fInheritMaxDisconnectionTime = 1;
  2210. uc.fInheritMaxIdleTime = 1;
  2211. // reset timeout values to no timeout
  2212. uc.MaxConnectionTime = 0;
  2213. uc.MaxDisconnectionTime = 0;
  2214. uc.MaxIdleTime = 0;
  2215. }
  2216. else
  2217. {
  2218. uc.fInheritMaxSessionTime = 0;
  2219. uc.fInheritMaxDisconnectionTime = 0;
  2220. uc.fInheritMaxIdleTime = 0;
  2221. if( !ConvertToMinutes( GetDlgItem( hDlg , IDC_COMBO_TIMEOUTS_CON_PS ) , &uc.MaxConnectionTime ) )
  2222. {
  2223. return FALSE;
  2224. }
  2225. if( !ConvertToMinutes( GetDlgItem( hDlg , IDC_COMBO_TIMEOUTS_DISCON_PS ) , &uc.MaxDisconnectionTime ) )
  2226. {
  2227. return FALSE;
  2228. }
  2229. if( !ConvertToMinutes( GetDlgItem( hDlg , IDC_COMBO_TIMEOUTS_IDLE_PS ) , &uc.MaxIdleTime ) )
  2230. {
  2231. return FALSE;
  2232. }
  2233. }
  2234. if( SendMessage( GetDlgItem( hDlg , IDC_CHECK_TIMEOUTS_INHERITBKCON_PS ) , BM_GETCHECK , 0 , 0 ) == BST_UNCHECKED )
  2235. {
  2236. uc.fInheritResetBroken = 1;
  2237. }
  2238. else
  2239. {
  2240. uc.fInheritResetBroken = 0;
  2241. uc.fResetBroken = SendMessage( GetDlgItem( hDlg , IDC_RADIO_TIMEOUTS_RESET_PS ) , BM_GETCHECK , 0 , 0 ) == BST_CHECKED ? TRUE : FALSE;
  2242. }
  2243. if( SendMessage( GetDlgItem( hDlg , IDC_CHECK_TIMEOUTS_INHERITRECON_PS ) , BM_GETCHECK , 0 , 0 ) == BST_UNCHECKED )
  2244. {
  2245. uc.fInheritReconnectSame = 1;
  2246. }
  2247. else
  2248. {
  2249. uc.fInheritReconnectSame = 0;
  2250. uc.fReconnectSame = ( ULONG )SendMessage( GetDlgItem( hDlg , IDC_RADIO_TIMEOUTS_PREVCLNT_PS ) , BM_GETCHECK , 0 , 0 ) == BST_CHECKED ? TRUE : FALSE;
  2251. }
  2252. DWORD dwStatus;
  2253. if( FAILED( m_pParent->SetUserConfig( uc , &dwStatus ) ) )
  2254. {
  2255. ReportStatusError( hDlg , dwStatus );
  2256. return FALSE;
  2257. }
  2258. ICfgComp *pCfgcomp = NULL;
  2259. if( m_pParent->m_pResNode->GetServer( &pCfgcomp ) > 0 )
  2260. {
  2261. VERIFY_S( S_OK , pCfgcomp->ForceUpdate( ) );
  2262. VERIFY_S( S_OK , pCfgcomp->Refresh( ) );
  2263. // global flag can only be set to true
  2264. m_pParent->m_bPropertiesChange = TRUE;
  2265. pCfgcomp->Release( );
  2266. }
  2267. PostMessage( hDlg , WM_COMMAND , MAKELPARAM( 0 , ALN_APPLY ) , ( LPARAM )hDlg );
  2268. SendMessage( GetParent( hDlg ) , PSM_UNCHANGED , ( WPARAM )hDlg , 0 );
  2269. return TRUE;
  2270. }
  2271. //-------------------------------------------------------------------------------
  2272. // Making sure the user has entered valid info
  2273. //-------------------------------------------------------------------------------
  2274. BOOL CTimeSetting::IsValidSettings( HWND hDlg )
  2275. {
  2276. if( m_pParent == NULL )
  2277. {
  2278. return FALSE;
  2279. }
  2280. USERCONFIG uc;
  2281. if( !m_pParent->GetCurrentUserConfig( uc, TRUE ) )
  2282. {
  2283. return FALSE;
  2284. }
  2285. if( SendMessage( GetDlgItem( hDlg , IDC_CHECK_INHERITTIMEOUT_PS ) , BM_GETCHECK , 0 , 0 ) == BST_CHECKED )
  2286. {
  2287. if( !ConvertToMinutes( GetDlgItem( hDlg , IDC_COMBO_TIMEOUTS_CON_PS ) , &uc.MaxConnectionTime ) )
  2288. {
  2289. return FALSE;
  2290. }
  2291. if( !ConvertToMinutes( GetDlgItem( hDlg , IDC_COMBO_TIMEOUTS_DISCON_PS ) , &uc.MaxDisconnectionTime ) )
  2292. {
  2293. return FALSE;
  2294. }
  2295. if( !ConvertToMinutes( GetDlgItem( hDlg , IDC_COMBO_TIMEOUTS_IDLE_PS ) , &uc.MaxIdleTime ) )
  2296. {
  2297. return FALSE;
  2298. }
  2299. }
  2300. return TRUE;
  2301. }
  2302. //-----------------------------------------------------------------------------
  2303. BOOL CTimeSetting::OnDestroy( )
  2304. {
  2305. m_pParent->Release( );
  2306. ReleaseAbbreviates( );
  2307. return CDialogPropBase::OnDestroy( );
  2308. }
  2309. //*****************************************************************************
  2310. // Environment dialog
  2311. CEnviro::CEnviro( CPropsheet *pSheet )
  2312. {
  2313. m_pParent = pSheet;
  2314. }
  2315. //-----------------------------------------------------------------------------
  2316. BOOL CEnviro::OnInitDialog( HWND hwnd , WPARAM wp , LPARAM lp )
  2317. {
  2318. if( m_pParent == NULL )
  2319. {
  2320. ODS( L"CEnviro::OnInitDialog - PropertySheet: Parent object is lost!!!\n" );
  2321. return FALSE;
  2322. }
  2323. m_pParent->AddRef( );
  2324. USERCONFIG uc;
  2325. if( !m_pParent->GetCurrentUserConfig( uc, TRUE ) )
  2326. {
  2327. ODS( L"CEnviro::OnInitDialog - PropertySheet: Failed to obtain USERCONFIG\n" );
  2328. return FALSE;
  2329. }
  2330. SendMessage( GetDlgItem( hwnd , IDC_EDIT_ENVIRO_CMDLINE ) , EM_SETLIMITTEXT , ( WPARAM )INITIALPROGRAM_LENGTH , 0 );
  2331. SendMessage( GetDlgItem( hwnd , IDC_EDIT_ENVIRO_WD ) , EM_SETLIMITTEXT , ( WPARAM )DIRECTORY_LENGTH , 0 );
  2332. if(uc.fInheritInitialProgram)
  2333. {
  2334. SendMessage( GetDlgItem( hwnd , IDC_CHECK_ENVIRO_INHERIT ) , BM_SETCHECK , ( WPARAM )BST_UNCHECKED , 0 );
  2335. }
  2336. else
  2337. {
  2338. SendMessage( GetDlgItem( hwnd , IDC_CHECK_ENVIRO_INHERIT ) , BM_SETCHECK , ( WPARAM )BST_CHECKED, 0 );
  2339. }
  2340. if(uc.fInheritInitialProgram)
  2341. {
  2342. SetControls( hwnd , FALSE );
  2343. }
  2344. else
  2345. {
  2346. SetWindowText( GetDlgItem( hwnd , IDC_EDIT_ENVIRO_CMDLINE ) , ( LPCTSTR )uc.InitialProgram );
  2347. SetWindowText( GetDlgItem( hwnd , IDC_EDIT_ENVIRO_WD ) , ( LPCTSTR )uc.WorkDirectory );
  2348. }
  2349. // SendMessage( GetDlgItem( hwnd , IDC_CHECK_ENVIRO_DISABLEWALL ) , BM_SETCHECK , ( WPARAM )uc.fWallPaperDisabled , 0 );
  2350. ICfgComp *pCfgcomp = NULL;
  2351. if( m_pParent->m_pResNode->GetServer( &pCfgcomp ) != 0 )
  2352. {
  2353. BOOL bReadOnly;
  2354. if( SUCCEEDED( pCfgcomp->IsSessionReadOnly( &bReadOnly ) ) )
  2355. {
  2356. if( bReadOnly )
  2357. {
  2358. // make edit controls read-only
  2359. SendMessage( GetDlgItem( hwnd , IDC_EDIT_ENVIRO_CMDLINE ) , EM_SETREADONLY , ( WPARAM )TRUE , 0 );
  2360. SendMessage( GetDlgItem( hwnd , IDC_EDIT_ENVIRO_WD ) , EM_SETREADONLY , ( WPARAM )TRUE , 0 );
  2361. // disable the remaining controls
  2362. int rgID[] = {
  2363. IDC_CHECK_ENVIRO_INHERIT ,
  2364. // IDC_CHECK_ENVIRO_DISABLEWALL,
  2365. -1
  2366. };
  2367. EnableGroup( hwnd , &rgID[ 0 ] , FALSE );
  2368. }
  2369. }
  2370. pCfgcomp->Release( );
  2371. }
  2372. POLICY_TS_MACHINE p;
  2373. RegGetMachinePolicy(&p);
  2374. if (p.fPolicyInitialProgram)
  2375. {
  2376. int rgID[] =
  2377. {
  2378. IDC_CHECK_ENVIRO_INHERIT,
  2379. IDC_EDIT_ENVIRO_CMDLINE,
  2380. IDC_EDIT_ENVIRO_WD, -1
  2381. };
  2382. EnableGroup(hwnd, &rgID[0], FALSE);
  2383. }
  2384. m_bPersisted = TRUE;
  2385. return CDialogPropBase::OnInitDialog( hwnd , wp , lp );
  2386. }
  2387. //-----------------------------------------------------------------------------
  2388. INT_PTR CALLBACK CEnviro::DlgProc( HWND hwnd , UINT msg , WPARAM wp , LPARAM lp )
  2389. {
  2390. CEnviro *pDlg;
  2391. if( msg == WM_INITDIALOG )
  2392. {
  2393. CEnviro *pDlg = ( CEnviro * )( ( PROPSHEETPAGE *)lp )->lParam ;
  2394. SetWindowLongPtr( hwnd , DWLP_USER , ( LONG_PTR )pDlg );
  2395. if( !IsBadReadPtr( pDlg , sizeof( CEnviro ) ) )
  2396. {
  2397. pDlg->OnInitDialog( hwnd , wp , lp );
  2398. }
  2399. return 0;
  2400. }
  2401. else
  2402. {
  2403. pDlg = ( CEnviro * )GetWindowLongPtr( hwnd , DWLP_USER );
  2404. if( IsBadReadPtr( pDlg , sizeof( CEnviro ) ) )
  2405. {
  2406. return 0;
  2407. }
  2408. }
  2409. switch( msg )
  2410. {
  2411. case WM_NCDESTROY:
  2412. pDlg->OnDestroy( );
  2413. break;
  2414. case WM_COMMAND:
  2415. pDlg->OnCommand( HIWORD( wp ) , LOWORD( wp ) , ( HWND )lp );
  2416. break;
  2417. case WM_CONTEXTMENU:
  2418. {
  2419. POINT pt;
  2420. pt.x = LOWORD( lp );
  2421. pt.y = HIWORD( lp );
  2422. pDlg->OnContextMenu( ( HWND )wp , pt );
  2423. }
  2424. break;
  2425. case WM_HELP:
  2426. pDlg->OnHelp( hwnd , ( LPHELPINFO )lp );
  2427. break;
  2428. case WM_NOTIFY:
  2429. return pDlg->OnNotify( ( int )wp , ( LPNMHDR )lp , hwnd );
  2430. }
  2431. return 0;
  2432. }
  2433. //-----------------------------------------------------------------------------
  2434. BOOL CEnviro::GetPropertySheetPage( PROPSHEETPAGE& psp )
  2435. {
  2436. ZeroMemory( &psp , sizeof( PROPSHEETPAGE ) );
  2437. psp.dwSize = sizeof( PROPSHEETPAGE );
  2438. psp.dwFlags = PSP_DEFAULT;
  2439. psp.hInstance = _Module.GetResourceInstance( );
  2440. psp.pszTemplate = MAKEINTRESOURCE( IDD_ENVIRONMENT );
  2441. psp.lParam = ( LPARAM )this;
  2442. psp.pfnDlgProc = CEnviro::DlgProc;
  2443. return TRUE;
  2444. }
  2445. //-----------------------------------------------------------------------------
  2446. BOOL CEnviro::OnCommand( WORD wNotifyCode , WORD wID , HWND hwndCtrl )
  2447. {
  2448. if( wNotifyCode == BN_CLICKED )
  2449. {
  2450. if( wID == IDC_CHECK_ENVIRO_INHERIT )
  2451. {
  2452. SetControls( GetParent( hwndCtrl ) , SendMessage( hwndCtrl , BM_GETCHECK , 0 , 0 ) == BST_CHECKED );
  2453. }
  2454. m_bPersisted = FALSE;
  2455. }
  2456. else if( wNotifyCode == EN_CHANGE )
  2457. {
  2458. m_bPersisted = FALSE;
  2459. }
  2460. else if( wNotifyCode == ALN_APPLY )
  2461. {
  2462. SendMessage( GetParent( hwndCtrl ) , PSM_CANCELTOCLOSE , 0 , 0 );
  2463. return FALSE;
  2464. }
  2465. if( !m_bPersisted )
  2466. {
  2467. SendMessage( GetParent( GetParent( hwndCtrl ) ) , PSM_CHANGED , ( WPARAM )GetParent( hwndCtrl ) , 0 );
  2468. }
  2469. return FALSE;
  2470. }
  2471. //-----------------------------------------------------------------------------
  2472. void CEnviro::SetControls( HWND hDlg , BOOL bEnable )
  2473. {
  2474. int rgID[] = { IDC_EDIT_ENVIRO_CMDLINE , IDC_STATIC_ENCL , IDC_EDIT_ENVIRO_WD , IDC_STATIC_WD ,-1 };
  2475. EnableGroup( hDlg , &rgID[ 0 ] , bEnable );
  2476. }
  2477. //-----------------------------------------------------------------------------
  2478. BOOL CEnviro::PersistSettings( HWND hDlg )
  2479. {
  2480. if( m_pParent == NULL )
  2481. {
  2482. return FALSE;
  2483. }
  2484. USERCONFIG uc;
  2485. if( !m_pParent->GetCurrentUserConfig( uc, TRUE ) )
  2486. {
  2487. return FALSE;
  2488. }
  2489. uc.fInheritInitialProgram = (( ULONG )SendMessage( GetDlgItem( hDlg , IDC_CHECK_ENVIRO_INHERIT ) , BM_GETCHECK , 0 , 0 )) == BST_UNCHECKED;
  2490. if( !uc.fInheritInitialProgram )
  2491. {
  2492. GetWindowText( GetDlgItem( hDlg , IDC_EDIT_ENVIRO_CMDLINE ) , uc.InitialProgram , INITIALPROGRAM_LENGTH + 1);
  2493. GetWindowText( GetDlgItem( hDlg , IDC_EDIT_ENVIRO_WD ) , uc.WorkDirectory , DIRECTORY_LENGTH + 1 );
  2494. }
  2495. else
  2496. {
  2497. ZeroMemory( ( PVOID )uc.InitialProgram , sizeof( uc.InitialProgram ) );
  2498. ZeroMemory( ( PVOID )uc.WorkDirectory , sizeof( uc.WorkDirectory ) );
  2499. }
  2500. // uc.fWallPaperDisabled = ( ULONG )SendMessage( GetDlgItem( hDlg , IDC_CHECK_ENVIRO_DISABLEWALL ) , BM_GETCHECK , 0 , 0 );
  2501. DWORD dwStatus;
  2502. if( FAILED( m_pParent->SetUserConfig( uc , &dwStatus ) ) )
  2503. {
  2504. ReportStatusError( hDlg , dwStatus );
  2505. return FALSE;
  2506. }
  2507. ICfgComp *pCfgcomp = NULL;
  2508. if( m_pParent->m_pResNode->GetServer( &pCfgcomp ) > 0 )
  2509. {
  2510. VERIFY_S( S_OK , pCfgcomp->ForceUpdate( ) );
  2511. VERIFY_S( S_OK , pCfgcomp->Refresh( ) );
  2512. // global flag can only be set to true
  2513. m_pParent->m_bPropertiesChange = TRUE;
  2514. pCfgcomp->Release( );
  2515. }
  2516. PostMessage( hDlg , WM_COMMAND , MAKELPARAM( 0 , ALN_APPLY ) , ( LPARAM )hDlg );
  2517. SendMessage( GetParent( hDlg ) , PSM_UNCHANGED , ( WPARAM )hDlg , 0 );
  2518. return TRUE;
  2519. }
  2520. //-----------------------------------------------------------------------------
  2521. BOOL CEnviro::OnDestroy( )
  2522. {
  2523. m_pParent->Release( );
  2524. return CDialogPropBase::OnDestroy( );
  2525. }
  2526. //*****************************************************************************
  2527. // Shadow dialog
  2528. CRemote::CRemote( CPropsheet *pSheet )
  2529. {
  2530. m_pParent = pSheet;
  2531. m_wOldRadioID = ( WORD )-1;
  2532. m_wOldSel = ( WORD )-1;
  2533. }
  2534. //-----------------------------------------------------------------------------
  2535. BOOL CRemote::OnInitDialog( HWND hwnd , WPARAM wp , LPARAM lp )
  2536. {
  2537. if( m_pParent == NULL )
  2538. {
  2539. ODS( L"CRemote::OnInitDialog - PropertySheet: Parent object lost!!\n" );
  2540. return FALSE;
  2541. }
  2542. m_pParent->AddRef( );
  2543. USERCONFIG uc;
  2544. if( !m_pParent->GetCurrentUserConfig( uc, TRUE ) )
  2545. {
  2546. ODS( L"CRemote::OnInitDialog - PropertySheet: GetCurrentUserConfig failed!!\n" );
  2547. return FALSE;
  2548. }
  2549. if( uc.fInheritShadow || uc.Shadow == Shadow_Disable )
  2550. {
  2551. // setup some default values
  2552. SendMessage( GetDlgItem( hwnd , IDC_CHECK_NOTIFY ) , BM_SETCHECK , ( WPARAM )TRUE , 0 );
  2553. SendMessage( GetDlgItem( hwnd , IDC_RADIO_WATCH ) , BM_SETCHECK , ( WPARAM )TRUE , 0 );
  2554. m_wOldSel = IDC_RADIO_WATCH;
  2555. if( uc.fInheritShadow )
  2556. {
  2557. SendMessage( GetDlgItem( hwnd , IDC_RADIO_REMOTE_INHERIT ) , BM_SETCHECK , ( WPARAM )uc.fInheritShadow , 0 );
  2558. }
  2559. else
  2560. {
  2561. SendMessage( GetDlgItem( hwnd , IDC_RADIO_NOREMOTE ) , BM_SETCHECK , ( WPARAM )TRUE , 0 );
  2562. }
  2563. m_wOldRadioID = ( WORD )( uc.fInheritShadow ? IDC_RADIO_REMOTE_INHERIT : IDC_RADIO_NOREMOTE );
  2564. SetControls( hwnd , FALSE );
  2565. }
  2566. else
  2567. {
  2568. // Controls are initially enabled, set current status
  2569. SendMessage( GetDlgItem( hwnd , IDC_RADIO_ENABLE_REMOTE ) , BM_SETCHECK , ( WPARAM )TRUE , 0 );
  2570. m_wOldRadioID = IDC_RADIO_ENABLE_REMOTE;
  2571. switch( uc.Shadow )
  2572. {
  2573. case Shadow_EnableInputNotify:
  2574. SendMessage( GetDlgItem( hwnd , IDC_CHECK_NOTIFY ) , BM_SETCHECK , ( WPARAM )TRUE , 0 );
  2575. SendMessage( GetDlgItem( hwnd , IDC_RADIO_CONTROL ) , BM_SETCHECK , ( WPARAM )TRUE , 0 );
  2576. break;
  2577. case Shadow_EnableInputNoNotify:
  2578. SendMessage( GetDlgItem( hwnd , IDC_CHECK_NOTIFY ) , BM_SETCHECK , ( WPARAM )FALSE , 0 );
  2579. SendMessage( GetDlgItem( hwnd , IDC_RADIO_CONTROL ) , BM_SETCHECK , ( WPARAM )TRUE , 0 );
  2580. break;
  2581. case Shadow_EnableNoInputNotify:
  2582. SendMessage( GetDlgItem( hwnd , IDC_CHECK_NOTIFY ) , BM_SETCHECK , ( WPARAM )TRUE , 0 );
  2583. SendMessage( GetDlgItem( hwnd , IDC_RADIO_WATCH ) , BM_SETCHECK , ( WPARAM )TRUE , 0 );
  2584. break;
  2585. case Shadow_EnableNoInputNoNotify:
  2586. SendMessage( GetDlgItem( hwnd , IDC_CHECK_NOTIFY ) , BM_SETCHECK , ( WPARAM )FALSE , 0 );
  2587. SendMessage( GetDlgItem( hwnd , IDC_RADIO_WATCH ) , BM_SETCHECK , ( WPARAM )TRUE , 0 );
  2588. break;
  2589. }
  2590. if( IsDlgButtonChecked( hwnd , IDC_RADIO_WATCH ) == BST_CHECKED )
  2591. {
  2592. m_wOldSel = IDC_RADIO_WATCH;
  2593. }
  2594. else
  2595. {
  2596. m_wOldSel = IDC_RADIO_CONTROL;
  2597. }
  2598. }
  2599. ICfgComp *pCfgcomp = NULL;
  2600. if( m_pParent->m_pResNode->GetServer( &pCfgcomp ) != 0 )
  2601. {
  2602. BOOL bReadOnly;
  2603. if( SUCCEEDED( pCfgcomp->IsSessionReadOnly( &bReadOnly ) ) )
  2604. {
  2605. if( bReadOnly )
  2606. {
  2607. // disable the remaining controls
  2608. int rgID[] = {
  2609. IDC_RADIO_ENABLE_REMOTE ,
  2610. IDC_RADIO_NOREMOTE,
  2611. IDC_RADIO_CONTROL,
  2612. IDC_RADIO_REMOTE_INHERIT,
  2613. IDC_RADIO_WATCH,
  2614. IDC_CHECK_NOTIFY,
  2615. -1
  2616. };
  2617. EnableGroup( hwnd , &rgID[ 0 ] , FALSE );
  2618. }
  2619. }
  2620. pCfgcomp->Release( );
  2621. }
  2622. //Disable all the controls if there is a group policy set
  2623. POLICY_TS_MACHINE p;
  2624. RegGetMachinePolicy(&p);
  2625. if (p.fPolicyShadow)
  2626. {
  2627. int rgID[] =
  2628. {
  2629. IDC_RADIO_ENABLE_REMOTE ,
  2630. IDC_RADIO_NOREMOTE,
  2631. IDC_RADIO_CONTROL,
  2632. IDC_RADIO_REMOTE_INHERIT,
  2633. IDC_RADIO_WATCH,
  2634. IDC_CHECK_NOTIFY,
  2635. -1
  2636. };
  2637. EnableGroup( hwnd , &rgID[ 0 ] , FALSE );
  2638. }
  2639. m_bPersisted = TRUE;
  2640. return CDialogPropBase::OnInitDialog( hwnd , wp , lp );
  2641. }
  2642. //-----------------------------------------------------------------------------
  2643. void CRemote::SetControls( HWND hDlg , BOOL bEnable )
  2644. {
  2645. int rgID[] = { IDC_RADIO_WATCH , IDC_RADIO_CONTROL , IDC_CHECK_NOTIFY , IDC_STATIC_LEVELOFCTRL , -1 };
  2646. EnableGroup( hDlg , &rgID[ 0 ] , bEnable );
  2647. }
  2648. //-----------------------------------------------------------------------------
  2649. INT_PTR CALLBACK CRemote::DlgProc( HWND hwnd , UINT msg , WPARAM wp , LPARAM lp )
  2650. {
  2651. CRemote *pDlg;
  2652. if( msg == WM_INITDIALOG )
  2653. {
  2654. CRemote *pDlg = ( CRemote * )( ( PROPSHEETPAGE *)lp )->lParam ;
  2655. SetWindowLongPtr( hwnd , DWLP_USER , ( LONG_PTR )pDlg );
  2656. if( !IsBadReadPtr( pDlg , sizeof( CRemote ) ) )
  2657. {
  2658. pDlg->OnInitDialog( hwnd , wp , lp );
  2659. }
  2660. return 0;
  2661. }
  2662. else
  2663. {
  2664. pDlg = ( CRemote * )GetWindowLongPtr( hwnd , DWLP_USER );
  2665. if( IsBadReadPtr( pDlg , sizeof( CRemote ) ) )
  2666. {
  2667. return 0;
  2668. }
  2669. }
  2670. switch( msg )
  2671. {
  2672. case WM_NCDESTROY:
  2673. pDlg->OnDestroy( );
  2674. break;
  2675. case WM_COMMAND:
  2676. pDlg->OnCommand( HIWORD( wp ) , LOWORD( wp ) , ( HWND )lp );
  2677. break;
  2678. case WM_CONTEXTMENU:
  2679. {
  2680. POINT pt;
  2681. pt.x = LOWORD( lp );
  2682. pt.y = HIWORD( lp );
  2683. pDlg->OnContextMenu( ( HWND )wp , pt );
  2684. }
  2685. break;
  2686. case WM_HELP:
  2687. pDlg->OnHelp( hwnd , ( LPHELPINFO )lp );
  2688. break;
  2689. case WM_NOTIFY:
  2690. return pDlg->OnNotify( ( int )wp , ( LPNMHDR )lp , hwnd );
  2691. }
  2692. return 0;
  2693. }
  2694. //-----------------------------------------------------------------------------
  2695. BOOL CRemote::GetPropertySheetPage( PROPSHEETPAGE& psp )
  2696. {
  2697. ZeroMemory( &psp , sizeof( PROPSHEETPAGE ) );
  2698. psp.dwSize = sizeof( PROPSHEETPAGE );
  2699. psp.dwFlags = PSP_DEFAULT;
  2700. psp.hInstance = _Module.GetResourceInstance( );
  2701. psp.pszTemplate = MAKEINTRESOURCE( IDD_PAGE_SHADOW );
  2702. psp.lParam = ( LPARAM )this;
  2703. psp.pfnDlgProc = CRemote::DlgProc;
  2704. return TRUE;
  2705. }
  2706. //-----------------------------------------------------------------------------
  2707. BOOL CRemote::OnCommand( WORD wNotifyCode , WORD wID , HWND hwndCtrl )
  2708. {
  2709. if( wNotifyCode == BN_CLICKED )
  2710. {
  2711. if( wID == IDC_CHECK_NOTIFY )
  2712. {
  2713. m_bPersisted = FALSE;
  2714. }
  2715. else if( wID == IDC_RADIO_REMOTE_INHERIT || wID == IDC_RADIO_NOREMOTE || wID == IDC_RADIO_ENABLE_REMOTE )
  2716. {
  2717. if( m_wOldRadioID != wID )
  2718. {
  2719. if( wID == IDC_RADIO_REMOTE_INHERIT || wID == IDC_RADIO_NOREMOTE )
  2720. {
  2721. SetControls( GetParent( hwndCtrl ) , FALSE );
  2722. }
  2723. else if( wID == IDC_RADIO_ENABLE_REMOTE )
  2724. {
  2725. SetControls( GetParent( hwndCtrl ) , TRUE );
  2726. }
  2727. m_wOldRadioID = wID;
  2728. m_bPersisted = FALSE;
  2729. }
  2730. }
  2731. else if( wID == IDC_RADIO_CONTROL || wID == IDC_RADIO_WATCH )
  2732. {
  2733. if( wID != m_wOldSel )
  2734. {
  2735. m_wOldSel = wID;
  2736. m_bPersisted = FALSE;
  2737. }
  2738. }
  2739. }
  2740. else if( wNotifyCode == ALN_APPLY )
  2741. {
  2742. SendMessage( GetParent( hwndCtrl ) , PSM_CANCELTOCLOSE , 0 , 0 );
  2743. return FALSE;
  2744. }
  2745. if( !m_bPersisted )
  2746. {
  2747. SendMessage( GetParent( GetParent( hwndCtrl ) ) , PSM_CHANGED , ( WPARAM )GetParent( hwndCtrl ) , 0 );
  2748. }
  2749. return FALSE;
  2750. }
  2751. //-----------------------------------------------------------------------------
  2752. BOOL CRemote::OnDestroy( )
  2753. {
  2754. m_pParent->Release( );
  2755. return CDialogPropBase::OnDestroy( );
  2756. }
  2757. //-----------------------------------------------------------------------------
  2758. // The nesting may appear scary but its has a nice logic flow to a weird
  2759. // datatype called shadow
  2760. //-----------------------------------------------------------------------------
  2761. BOOL CRemote::PersistSettings( HWND hDlg )
  2762. {
  2763. if( m_pParent != NULL )
  2764. {
  2765. USERCONFIG uc;
  2766. m_pParent->GetCurrentUserConfig( uc, TRUE );
  2767. if( SendMessage( GetDlgItem( hDlg , IDC_RADIO_REMOTE_INHERIT ) , BM_GETCHECK , 0 , 0 ) == BST_UNCHECKED )
  2768. {
  2769. uc.fInheritShadow = FALSE;
  2770. if( SendMessage( GetDlgItem( hDlg , IDC_RADIO_NOREMOTE ) , BM_GETCHECK , 0 , 0 ) == BST_UNCHECKED )
  2771. {
  2772. BOOL bCheckNotify = ( BOOL )SendMessage( GetDlgItem( hDlg , IDC_CHECK_NOTIFY ) , BM_GETCHECK , 0 , 0 );
  2773. BOOL bRadioControl = ( BOOL )SendMessage( GetDlgItem( hDlg , IDC_RADIO_CONTROL ) , BM_GETCHECK , 0 , 0 );
  2774. if( bCheckNotify )
  2775. {
  2776. if( bRadioControl )
  2777. {
  2778. uc.Shadow = Shadow_EnableInputNotify;
  2779. }
  2780. else
  2781. {
  2782. uc.Shadow = Shadow_EnableNoInputNotify;
  2783. }
  2784. }
  2785. else
  2786. {
  2787. if( bRadioControl )
  2788. {
  2789. uc.Shadow = Shadow_EnableInputNoNotify;
  2790. }
  2791. else
  2792. {
  2793. uc.Shadow = Shadow_EnableNoInputNoNotify;
  2794. }
  2795. }
  2796. }
  2797. else
  2798. {
  2799. uc.Shadow = Shadow_Disable;
  2800. }
  2801. }
  2802. else
  2803. {
  2804. uc.fInheritShadow = TRUE;
  2805. }
  2806. DWORD dwStatus;
  2807. if( FAILED( m_pParent->SetUserConfig( uc , &dwStatus ) ) )
  2808. {
  2809. ReportStatusError( hDlg , dwStatus );
  2810. return FALSE;
  2811. }
  2812. ICfgComp *pCfgcomp = NULL;
  2813. if( m_pParent->m_pResNode->GetServer( &pCfgcomp ) > 0 )
  2814. {
  2815. VERIFY_S( S_OK , pCfgcomp->ForceUpdate( ) );
  2816. VERIFY_S( S_OK , pCfgcomp->Refresh( ) );
  2817. // global flag can only be set to true
  2818. m_pParent->m_bPropertiesChange = TRUE;
  2819. pCfgcomp->Release( );
  2820. }
  2821. PostMessage( hDlg , WM_COMMAND , MAKELPARAM( 0 , ALN_APPLY ) , ( LPARAM )hDlg );
  2822. SendMessage( GetParent( hDlg ) , PSM_UNCHANGED , ( WPARAM )hDlg , 0 );
  2823. return TRUE;
  2824. }
  2825. return FALSE;
  2826. }
  2827. //*****************************************************************************
  2828. // Client settings dialog
  2829. CClient::CClient( CPropsheet *pSheet )
  2830. {
  2831. m_pParent = pSheet;
  2832. m_nColorDepth = TS_8BPP_SUPPORT;
  2833. }
  2834. //-----------------------------------------------------------------------------
  2835. BOOL CClient::OnInitDialog( HWND hDlg , WPARAM wp , LPARAM lp )
  2836. {
  2837. if( m_pParent == NULL )
  2838. {
  2839. ODS( L"CClient::OnInitDialog - PropertySheet: Parent object lost!!\n" );
  2840. return FALSE;
  2841. }
  2842. m_pParent->AddRef( );
  2843. USERCONFIG uc;
  2844. if( !m_pParent->GetCurrentUserConfig( uc, TRUE ) )
  2845. {
  2846. ODS( L"CClient::OnInitDialog - PropertySheet: GetCurrentUserConfig failed!!\n" );
  2847. return FALSE;
  2848. }
  2849. // Obtain capabilities mask
  2850. ICfgComp *pCfgcomp = NULL;
  2851. if( m_pParent->m_pResNode->GetServer( &pCfgcomp ) == 0 )
  2852. {
  2853. ODS( L"CClient::OnInitDialog GetServer failed\n" );
  2854. return FALSE;
  2855. }
  2856. SendMessage( GetDlgItem( hDlg , IDC_CHECK_CONCLIENT_INHERIT ) , BM_SETCHECK , ( WPARAM )uc.fInheritAutoClient , 0 );
  2857. SendMessage( GetDlgItem( hDlg , IDC_CHECK_CCDL_PS ) , BM_SETCHECK , ( WPARAM )uc.fAutoClientDrives , 0 );
  2858. SendMessage( GetDlgItem( hDlg , IDC_CHECK_CCPL_PS ) , BM_SETCHECK , ( WPARAM )uc.fAutoClientLpts , 0 );
  2859. SendMessage( GetDlgItem( hDlg , IDC_CHECK_DMCP_PS ) , BM_SETCHECK , ( WPARAM )uc.fForceClientLptDef , 0 );
  2860. //NA 2/23/01
  2861. TCHAR tchBuffer[80];
  2862. int nColorDepthIndex = 0;
  2863. LoadString( _Module.GetResourceInstance( ) , IDS_COLORDEPTH_24 , tchBuffer , SIZE_OF_BUFFER( tchBuffer ) );
  2864. SendMessage( GetDlgItem( hDlg, IDC_COLORDEPTH_OVERRIDE ), CB_ADDSTRING , 0 , ( LPARAM )&tchBuffer[0] );
  2865. SendMessage( GetDlgItem( hDlg, IDC_COLORDEPTH_OVERRIDE ), CB_SETITEMDATA , nColorDepthIndex++ , TS_24BPP_SUPPORT );
  2866. LoadString( _Module.GetResourceInstance( ) , IDS_COLORDEPTH_16 , tchBuffer , SIZE_OF_BUFFER( tchBuffer ) );
  2867. SendMessage( GetDlgItem( hDlg, IDC_COLORDEPTH_OVERRIDE ), CB_ADDSTRING , 0 , ( LPARAM )&tchBuffer[0] );
  2868. SendMessage( GetDlgItem( hDlg, IDC_COLORDEPTH_OVERRIDE ), CB_SETITEMDATA , nColorDepthIndex++ , TS_16BPP_SUPPORT );
  2869. LoadString( _Module.GetResourceInstance( ) , IDS_COLORDEPTH_15 , tchBuffer , SIZE_OF_BUFFER( tchBuffer ) );
  2870. SendMessage( GetDlgItem( hDlg, IDC_COLORDEPTH_OVERRIDE ), CB_ADDSTRING , 0 , ( LPARAM )&tchBuffer[0] );
  2871. SendMessage( GetDlgItem( hDlg, IDC_COLORDEPTH_OVERRIDE ), CB_SETITEMDATA , nColorDepthIndex++ , TS_15BPP_SUPPORT );
  2872. LoadString( _Module.GetResourceInstance( ) , IDS_COLORDEPTH_8 , tchBuffer , SIZE_OF_BUFFER( tchBuffer ) );
  2873. SendMessage( GetDlgItem( hDlg, IDC_COLORDEPTH_OVERRIDE ), CB_ADDSTRING , 0 , ( LPARAM )&tchBuffer[0] );
  2874. SendMessage( GetDlgItem( hDlg, IDC_COLORDEPTH_OVERRIDE ), CB_SETITEMDATA , nColorDepthIndex++ , TS_8BPP_SUPPORT );
  2875. if(uc.fInheritColorDepth)
  2876. SendMessage( GetDlgItem( hDlg , IDC_CHECK_COLORDEPTH_OVERRIDE ) , BM_SETCHECK , ( WPARAM )BST_UNCHECKED , 0 );
  2877. else
  2878. SendMessage( GetDlgItem( hDlg , IDC_CHECK_COLORDEPTH_OVERRIDE ) , BM_SETCHECK , ( WPARAM )BST_CHECKED, 0 );
  2879. if (uc.ColorDepth < TS_8BPP_SUPPORT)
  2880. m_nColorDepth = TS_8BPP_SUPPORT;
  2881. else if (uc.ColorDepth > TS_24BPP_SUPPORT)
  2882. m_nColorDepth = TS_24BPP_SUPPORT;
  2883. else
  2884. m_nColorDepth = (int)uc.ColorDepth;
  2885. //Mapping fields
  2886. ULONG mask = 0;
  2887. VERIFY_S(S_OK, pCfgcomp->GetCaps(m_pParent->m_pResNode->GetTypeName(), &mask));
  2888. EnableWindow(GetDlgItem(hDlg, IDC_CHECK_DCDM_PS), mask & WDC_CLIENT_DRIVE_MAPPING);
  2889. EnableWindow(GetDlgItem(hDlg, IDC_CHECK_DWCPM_PS), mask & WDC_WIN_CLIENT_PRINTER_MAPPING);
  2890. EnableWindow(GetDlgItem(hDlg, IDC_CHECK_DCLPM_PS), mask & WDC_CLIENT_LPT_PORT_MAPPING);
  2891. EnableWindow(GetDlgItem(hDlg, IDC_CHECK_DCCPM_PS), mask & WDC_CLIENT_COM_PORT_MAPPING);
  2892. EnableWindow(GetDlgItem(hDlg, IDC_CHECK_DCCM_PS), mask & WDC_CLIENT_CLIPBOARD_MAPPING);
  2893. EnableWindow(GetDlgItem(hDlg, IDC_CHECK_DCAM_PS), mask & WDC_CLIENT_AUDIO_MAPPING);
  2894. if (!(mask & WDC_CLIENT_DRIVE_MAPPING))
  2895. SendMessage(GetDlgItem(hDlg, IDC_CHECK_DCDM_PS), BM_SETCHECK, (WPARAM)TRUE, 0);
  2896. else
  2897. SendMessage(GetDlgItem(hDlg, IDC_CHECK_DCDM_PS), BM_SETCHECK, (WPARAM)uc.fDisableCdm, 0);
  2898. if(!(mask & WDC_WIN_CLIENT_PRINTER_MAPPING))
  2899. SendMessage(GetDlgItem(hDlg, IDC_CHECK_DWCPM_PS), BM_SETCHECK, (WPARAM)TRUE, 0 );
  2900. else
  2901. SendMessage(GetDlgItem(hDlg, IDC_CHECK_DWCPM_PS), BM_SETCHECK, (WPARAM)uc.fDisableCpm, 0);
  2902. if(!(mask & WDC_CLIENT_LPT_PORT_MAPPING))
  2903. SendMessage(GetDlgItem(hDlg, IDC_CHECK_DCLPM_PS), BM_SETCHECK, (WPARAM)TRUE, 0);
  2904. else
  2905. SendMessage(GetDlgItem(hDlg, IDC_CHECK_DCLPM_PS), BM_SETCHECK, (WPARAM)uc.fDisableLPT, 0);
  2906. SendMessage( GetDlgItem( hDlg , IDC_CHECK_DCCPM_PS ) , BM_SETCHECK , ( WPARAM )uc.fDisableCcm , 0 );
  2907. SendMessage( GetDlgItem( hDlg , IDC_CHECK_DCCM_PS ) , BM_SETCHECK , ( WPARAM )uc.fDisableClip , 0 );
  2908. SendMessage( GetDlgItem( hDlg , IDC_CHECK_DCAM_PS ) , BM_SETCHECK , ( WPARAM )uc.fDisableCam , 0 );
  2909. DetermineFieldEnabling(hDlg);
  2910. SetColorDepthEntry(hDlg);
  2911. BOOL bReadOnly;
  2912. if (SUCCEEDED(pCfgcomp->IsSessionReadOnly(&bReadOnly)))
  2913. {
  2914. if(bReadOnly)
  2915. {
  2916. // disable the remaining controls
  2917. int rgID[] =
  2918. {
  2919. IDC_CHECK_DCDM_PS ,
  2920. IDC_CHECK_DWCPM_PS ,
  2921. IDC_CHECK_DCLPM_PS ,
  2922. IDC_CHECK_DCCPM_PS ,
  2923. IDC_CHECK_DCCM_PS ,
  2924. IDC_CHECK_DCAM_PS ,
  2925. IDC_CHECK_CCDL_PS ,
  2926. IDC_CHECK_CCPL_PS ,
  2927. IDC_CHECK_DMCP_PS ,
  2928. IDC_CHECK_CONCLIENT_INHERIT,
  2929. IDC_CHECK_COLORDEPTH_OVERRIDE,
  2930. IDC_COLORDEPTH_OVERRIDE,
  2931. -1
  2932. };
  2933. EnableGroup( hDlg , &rgID[ 0 ] , FALSE );
  2934. }
  2935. }
  2936. pCfgcomp->Release( );
  2937. m_bPersisted = TRUE;
  2938. return CDialogPropBase::OnInitDialog( hDlg , wp , lp );
  2939. }
  2940. //-----------------------------------------------------------------------------
  2941. //Disable fields if a group policy is set
  2942. void CClient::DetermineFieldEnabling(HWND hDlg)
  2943. {
  2944. POLICY_TS_MACHINE p;
  2945. RegGetMachinePolicy(&p);
  2946. //Mapping fields
  2947. //EnableWindow(GetDlgItem(hDlg, IDC_CHECK_DMCP_PS), !p.fPolicyForceClientLptDef); //Done below since it depends on 2 things
  2948. EnableWindow(GetDlgItem(hDlg, IDC_CHECK_DCDM_PS), !p.fPolicyDisableCdm);
  2949. EnableWindow(GetDlgItem(hDlg, IDC_CHECK_DWCPM_PS), !p.fPolicyDisableCpm);
  2950. EnableWindow(GetDlgItem(hDlg, IDC_CHECK_DCLPM_PS), !p.fPolicyDisableLPT);
  2951. EnableWindow(GetDlgItem(hDlg, IDC_CHECK_DCCPM_PS), !p.fPolicyDisableCcm);
  2952. EnableWindow(GetDlgItem(hDlg, IDC_CHECK_DCCM_PS), !p.fPolicyDisableClip);
  2953. EnableWindow(GetDlgItem(hDlg, IDC_CHECK_DCAM_PS), !p.fPolicyDisableCam);
  2954. //Connection fields
  2955. BOOL bEnableConnectionSettings = (SendMessage(GetDlgItem(hDlg, IDC_CHECK_CONCLIENT_INHERIT), BM_GETCHECK, 0, 0) != BST_CHECKED);
  2956. // check to see if client drive mapping is selected if so disable
  2957. EnableWindow(GetDlgItem(hDlg, IDC_CHECK_CCDL_PS), bEnableConnectionSettings &&
  2958. (SendMessage(GetDlgItem(hDlg, IDC_CHECK_DCDM_PS), BM_GETCHECK, 0, 0) != BST_CHECKED));
  2959. EnableWindow( GetDlgItem( hDlg , IDC_CHECK_CCPL_PS ) , bEnableConnectionSettings );
  2960. EnableWindow( GetDlgItem( hDlg , IDC_CHECK_DMCP_PS ) , bEnableConnectionSettings && !p.fPolicyForceClientLptDef);
  2961. //Color Depth fields
  2962. EnableWindow(GetDlgItem(hDlg, IDC_CHECK_COLORDEPTH_OVERRIDE), (!p.fPolicyColorDepth));
  2963. BOOL bEnableColorDepthSetting = SendMessage( GetDlgItem( hDlg , IDC_CHECK_COLORDEPTH_OVERRIDE ) , BM_GETCHECK , 0 , 0 ) == BST_CHECKED;
  2964. EnableWindow(GetDlgItem(hDlg, IDC_COLORDEPTH_OVERRIDE), (bEnableColorDepthSetting && !p.fPolicyColorDepth));
  2965. }
  2966. //-----------------------------------------------------------------------------
  2967. void CClient::SetColorDepthEntry(HWND hwnd)
  2968. {
  2969. //NA 2/23/01
  2970. BOOL bEnableColorDepthSetting = TRUE;
  2971. // check to see if override Color Depth setting is checked
  2972. bEnableColorDepthSetting = SendMessage( GetDlgItem( hwnd , IDC_CHECK_COLORDEPTH_OVERRIDE ) , BM_GETCHECK , 0 , 0 ) == BST_CHECKED;
  2973. //Select the correct combo box entry
  2974. if (bEnableColorDepthSetting)
  2975. {
  2976. //Select the correct value in the combo box based on the current value
  2977. INT_PTR iColorDepthListCount = 0;
  2978. iColorDepthListCount = SendMessage( GetDlgItem( hwnd, IDC_COLORDEPTH_OVERRIDE ), CB_GETCOUNT , 0 , 0 );
  2979. //Traverse the list looking an entry with value equal to m_nColorDepth
  2980. for (int iColorDepthListIndex = 0; iColorDepthListIndex < iColorDepthListCount; iColorDepthListIndex++)
  2981. {
  2982. INT_PTR iMatchingColorDepthValue = 0;
  2983. iMatchingColorDepthValue = SendMessage( GetDlgItem( hwnd, IDC_COLORDEPTH_OVERRIDE ), CB_GETITEMDATA , iColorDepthListIndex , 0 ) ;
  2984. if (iMatchingColorDepthValue == m_nColorDepth )
  2985. {
  2986. //Value found, set the combo box selection to the correct index
  2987. SendMessage( GetDlgItem( hwnd, IDC_COLORDEPTH_OVERRIDE ), CB_SETCURSEL , iColorDepthListIndex , 0 );
  2988. break;
  2989. }
  2990. }
  2991. //Make sure something's been selected - if not, just select the first value in the list
  2992. INT_PTR iSelection = SendMessage ( GetDlgItem( hwnd, IDC_COLORDEPTH_OVERRIDE ), CB_GETCURSEL, 0, 0 );
  2993. if (iSelection == CB_ERR)
  2994. SendMessage( GetDlgItem( hwnd, IDC_COLORDEPTH_OVERRIDE ), CB_SETCURSEL , 0 , 0 );
  2995. }
  2996. else
  2997. {
  2998. //Clear the contents of the combo box window if the color depth isn't editable
  2999. SendMessage( GetDlgItem( hwnd, IDC_COLORDEPTH_OVERRIDE ), CB_SETCURSEL , (WPARAM)CB_ERR , 0 );
  3000. }
  3001. }
  3002. //-----------------------------------------------------------------------------
  3003. BOOL CClient::PersistSettings( HWND hDlg )
  3004. {
  3005. if( m_pParent == NULL )
  3006. {
  3007. return FALSE;
  3008. }
  3009. USERCONFIG uc;
  3010. if( !m_pParent->GetCurrentUserConfig( uc, TRUE ) )
  3011. {
  3012. return FALSE;
  3013. }
  3014. uc.fInheritAutoClient = SendMessage( GetDlgItem( hDlg , IDC_CHECK_CONCLIENT_INHERIT ) , BM_GETCHECK , 0 , 0 );
  3015. if( !uc.fInheritAutoClient )
  3016. {
  3017. uc.fAutoClientDrives = SendMessage( GetDlgItem( hDlg , IDC_CHECK_CCDL_PS ) , BM_GETCHECK , 0 , 0 );
  3018. uc.fAutoClientLpts = SendMessage( GetDlgItem( hDlg , IDC_CHECK_CCPL_PS ) , BM_GETCHECK , 0 , 0 );
  3019. uc.fForceClientLptDef = SendMessage( GetDlgItem( hDlg , IDC_CHECK_DMCP_PS ) , BM_GETCHECK , 0 , 0 );
  3020. }
  3021. uc.fDisableCdm = SendMessage( GetDlgItem( hDlg , IDC_CHECK_DCDM_PS ) , BM_GETCHECK , 0 , 0 );
  3022. uc.fDisableCpm = SendMessage( GetDlgItem( hDlg , IDC_CHECK_DWCPM_PS ) , BM_GETCHECK , 0 , 0 );
  3023. uc.fDisableLPT = SendMessage( GetDlgItem( hDlg , IDC_CHECK_DCLPM_PS ) , BM_GETCHECK , 0 , 0 );
  3024. uc.fDisableCcm = SendMessage( GetDlgItem( hDlg , IDC_CHECK_DCCPM_PS ) , BM_GETCHECK , 0 , 0 );
  3025. uc.fDisableClip = SendMessage( GetDlgItem( hDlg , IDC_CHECK_DCCM_PS ) , BM_GETCHECK , 0 , 0 );
  3026. uc.fDisableCam = SendMessage( GetDlgItem( hDlg , IDC_CHECK_DCAM_PS ) , BM_GETCHECK , 0 , 0 );
  3027. //NA 2/23/01
  3028. uc.fInheritColorDepth = (( ULONG )SendMessage( GetDlgItem( hDlg , IDC_CHECK_COLORDEPTH_OVERRIDE ) , BM_GETCHECK , 0 , 0 )) == BST_UNCHECKED;
  3029. if( !uc.fInheritColorDepth )
  3030. {
  3031. INT_PTR iColorDepthSel = CB_ERR;
  3032. iColorDepthSel = SendMessage( GetDlgItem( hDlg , IDC_COLORDEPTH_OVERRIDE ) , CB_GETCURSEL, 0 , 0 );
  3033. INT_PTR iColorDepthValue = 0;
  3034. iColorDepthValue = SendMessage( GetDlgItem( hDlg , IDC_COLORDEPTH_OVERRIDE ) , CB_GETITEMDATA , iColorDepthSel , 0 );
  3035. uc.ColorDepth = iColorDepthValue;
  3036. }
  3037. else
  3038. {
  3039. uc.ColorDepth = TS_24BPP_SUPPORT;
  3040. }
  3041. DWORD dwStatus;
  3042. if( FAILED( m_pParent->SetUserConfig( uc , &dwStatus ) ) )
  3043. {
  3044. ReportStatusError( hDlg , dwStatus );
  3045. return FALSE;
  3046. }
  3047. ICfgComp *pCfgcomp = NULL;
  3048. if( m_pParent->m_pResNode->GetServer( &pCfgcomp ) > 0 )
  3049. {
  3050. VERIFY_S( S_OK , pCfgcomp->ForceUpdate( ) );
  3051. VERIFY_S( S_OK , pCfgcomp->Refresh( ) );
  3052. // global flag can only be set to true
  3053. m_pParent->m_bPropertiesChange = TRUE;
  3054. pCfgcomp->Release( );
  3055. }
  3056. PostMessage( hDlg , WM_COMMAND , MAKELPARAM( 0 , ALN_APPLY ) , ( LPARAM )hDlg );
  3057. SendMessage( GetParent( hDlg ) , PSM_UNCHANGED , ( WPARAM )hDlg , 0 );
  3058. return TRUE;
  3059. }
  3060. //-----------------------------------------------------------------------------
  3061. INT_PTR CALLBACK CClient::DlgProc( HWND hwnd , UINT msg , WPARAM wp , LPARAM lp )
  3062. {
  3063. CClient *pDlg;
  3064. if( msg == WM_INITDIALOG )
  3065. {
  3066. CClient *pDlg = ( CClient * )( ( PROPSHEETPAGE *)lp )->lParam ;
  3067. SetWindowLongPtr( hwnd , DWLP_USER , ( LONG_PTR )pDlg );
  3068. if( !IsBadReadPtr( pDlg , sizeof( CClient ) ) )
  3069. {
  3070. pDlg->OnInitDialog( hwnd , wp , lp );
  3071. }
  3072. return 0;
  3073. }
  3074. else
  3075. {
  3076. pDlg = ( CClient * )GetWindowLongPtr( hwnd , DWLP_USER );
  3077. if( IsBadReadPtr( pDlg , sizeof( CClient ) ) )
  3078. {
  3079. return FALSE;
  3080. }
  3081. }
  3082. switch( msg )
  3083. {
  3084. case WM_NCDESTROY:
  3085. pDlg->OnDestroy( );
  3086. break;
  3087. case WM_COMMAND:
  3088. pDlg->OnCommand( HIWORD( wp ) , LOWORD( wp ) , ( HWND )lp );
  3089. break;
  3090. case WM_CONTEXTMENU:
  3091. {
  3092. POINT pt;
  3093. pt.x = LOWORD( lp );
  3094. pt.y = HIWORD( lp );
  3095. pDlg->OnContextMenu( ( HWND )wp , pt );
  3096. }
  3097. break;
  3098. case WM_HELP:
  3099. pDlg->OnHelp( hwnd , ( LPHELPINFO )lp );
  3100. break;
  3101. case WM_NOTIFY:
  3102. return pDlg->OnNotify( ( int )wp , ( LPNMHDR )lp , hwnd );
  3103. break;
  3104. }
  3105. return FALSE;
  3106. }
  3107. //-----------------------------------------------------------------------------
  3108. BOOL CClient::GetPropertySheetPage( PROPSHEETPAGE& psp )
  3109. {
  3110. ZeroMemory( &psp , sizeof( PROPSHEETPAGE ) );
  3111. psp.dwSize = sizeof( PROPSHEETPAGE );
  3112. psp.dwFlags = PSP_DEFAULT;
  3113. psp.hInstance = _Module.GetResourceInstance( );
  3114. psp.pszTemplate = MAKEINTRESOURCE( IDD_TSCC_CLIENT );
  3115. psp.lParam = ( LPARAM )this;
  3116. psp.pfnDlgProc = CClient::DlgProc;
  3117. return TRUE;
  3118. }
  3119. //-----------------------------------------------------------------------------
  3120. BOOL CClient::OnCommand( WORD wNotifyCode , WORD wID , HWND hwndCtrl )
  3121. {
  3122. if( wNotifyCode == BN_CLICKED )
  3123. {
  3124. if ((wID == IDC_CHECK_CONCLIENT_INHERIT) || (wID == IDC_CHECK_COLORDEPTH_OVERRIDE) ||
  3125. (wID == IDC_CHECK_DWCPM_PS ) || (wID == IDC_CHECK_DCDM_PS))
  3126. {
  3127. DetermineFieldEnabling(GetParent(hwndCtrl));
  3128. }
  3129. if (wID == IDC_CHECK_COLORDEPTH_OVERRIDE)
  3130. SetColorDepthEntry(GetParent(hwndCtrl));
  3131. }
  3132. else if( wNotifyCode == ALN_APPLY )
  3133. {
  3134. SendMessage( GetParent( hwndCtrl ) , PSM_CANCELTOCLOSE , 0 , 0 );
  3135. return FALSE;
  3136. }
  3137. m_bPersisted = FALSE;
  3138. SendMessage( GetParent( GetParent( hwndCtrl ) ) , PSM_CHANGED , ( WPARAM )GetParent( hwndCtrl ) , 0 );
  3139. return FALSE;
  3140. }
  3141. //-----------------------------------------------------------------------------
  3142. BOOL CClient::OnDestroy( )
  3143. {
  3144. m_pParent->Release( );
  3145. return TRUE;
  3146. }
  3147. /*************************************************************************************************************************/
  3148. /*EXTERN_C const GUID IID_ISecurityInformation =
  3149. { 0x965fc360, 0x16ff, 0x11d0, 0x91, 0xcb, 0x0, 0xaa, 0x0, 0xbb, 0xb7, 0x23 };
  3150. */
  3151. //
  3152. // WinStation General Permissions
  3153. //
  3154. /*
  3155. SI_ACCESS siWinStationAccesses[] =
  3156. {
  3157. { &GUID_NULL , WINSTATION_QUERY , NULL ,SI_ACCESS_SPECIFIC },
  3158. { &GUID_NULL , WINSTATION_SET , NULL ,SI_ACCESS_SPECIFIC },
  3159. { &GUID_NULL , WINSTATION_RESET , NULL ,SI_ACCESS_SPECIFIC },
  3160. { &GUID_NULL , WINSTATION_SHADOW , NULL ,SI_ACCESS_SPECIFIC },
  3161. { &GUID_NULL , WINSTATION_LOGON , NULL ,SI_ACCESS_SPECIFIC },
  3162. { &GUID_NULL , WINSTATION_LOGOFF , NULL ,SI_ACCESS_SPECIFIC },
  3163. { &GUID_NULL , WINSTATION_MSG , NULL ,SI_ACCESS_SPECIFIC },
  3164. { &GUID_NULL , WINSTATION_CONNECT , NULL ,SI_ACCESS_SPECIFIC },
  3165. { &GUID_NULL , WINSTATION_DISCONNECT , NULL , SI_ACCESS_SPECIFIC},
  3166. { &GUID_NULL , WINSTATION_VIRTUAL | STANDARD_RIGHTS_REQUIRED, NULL , SI_ACCESS_SPECIFIC},
  3167. { &GUID_NULL , WINSTATION_ALL_ACCESS , NULL , SI_ACCESS_GENERAL },
  3168. { &GUID_NULL , WINSTATION_USER_ACCESS , NULL , SI_ACCESS_GENERAL },
  3169. { &GUID_NULL , WINSTATION_GUEST_ACCESS , NULL , SI_ACCESS_GENERAL }
  3170. };
  3171. */
  3172. SI_ACCESS siWinStationAccesses[] =
  3173. {
  3174. { &GUID_NULL , WINSTATION_QUERY , MAKEINTRESOURCE ( IDS_PERMS_SPECIAL_QUERY ),SI_ACCESS_SPECIFIC },
  3175. { &GUID_NULL , WINSTATION_SET , MAKEINTRESOURCE ( IDS_PERMS_SPECIAL_SET ) ,SI_ACCESS_SPECIFIC },
  3176. //{ &GUID_NULL , WINSTATION_RESET , MAKEINTRESOURCE ( IDS_PERMS_SPECIAL_RESET ) ,SI_ACCESS_SPECIFIC },
  3177. { &GUID_NULL , WINSTATION_SHADOW , MAKEINTRESOURCE ( IDS_PERMS_SPECIAL_SHADOW ) ,SI_ACCESS_SPECIFIC },
  3178. { &GUID_NULL , WINSTATION_LOGON , MAKEINTRESOURCE ( IDS_PERMS_SPECIAL_LOGON ) ,SI_ACCESS_SPECIFIC },
  3179. { &GUID_NULL , WINSTATION_RESET , MAKEINTRESOURCE ( IDS_PERMS_SPECIAL_LOGOFF ) ,SI_ACCESS_SPECIFIC },
  3180. { &GUID_NULL , WINSTATION_MSG , MAKEINTRESOURCE ( IDS_PERMS_SPECIAL_MSG ) ,SI_ACCESS_SPECIFIC },
  3181. { &GUID_NULL , WINSTATION_CONNECT , MAKEINTRESOURCE ( IDS_PERMS_SPECIAL_CONNECT ) ,SI_ACCESS_SPECIFIC },
  3182. { &GUID_NULL , WINSTATION_DISCONNECT , MAKEINTRESOURCE ( IDS_PERMS_SPECIAL_DISCONNECT ) , SI_ACCESS_SPECIFIC},
  3183. { &GUID_NULL , WINSTATION_VIRTUAL | STANDARD_RIGHTS_REQUIRED, MAKEINTRESOURCE ( IDS_PERMS_SPECIAL_DELETE ) , SI_ACCESS_SPECIFIC},
  3184. { &GUID_NULL , WINSTATION_ALL_ACCESS , MAKEINTRESOURCE ( IDS_PERMS_RESOURCE_ADMIN ) , SI_ACCESS_GENERAL },
  3185. { &GUID_NULL , WINSTATION_USER_ACCESS , MAKEINTRESOURCE ( IDS_PERMS_RESOURCE_USER ) , SI_ACCESS_GENERAL },
  3186. { &GUID_NULL , WINSTATION_GUEST_ACCESS , MAKEINTRESOURCE ( IDS_PERMS_RESOURCE_GUEST ) , SI_ACCESS_GENERAL }
  3187. };
  3188. #define MAX_PERM 12
  3189. #define iWinStationDefAccess 11 // index of value in array siWinStationAccesses
  3190. //-----------------------------------------------------------------------------
  3191. STDMETHODIMP CSecurityPage::GetAccessRights(
  3192. const GUID *pguidObjectType,
  3193. DWORD dwFlags,
  3194. PSI_ACCESS *ppAccess,
  3195. PULONG pcAccesses,
  3196. PULONG piDefaultAccess
  3197. )
  3198. {
  3199. UNREFERENCED_PARAMETER( dwFlags );
  3200. UNREFERENCED_PARAMETER( pguidObjectType );
  3201. ASSERT( ppAccess != NULL );
  3202. ASSERT( pcAccesses != NULL );
  3203. ASSERT( piDefaultAccess != NULL );
  3204. *ppAccess = siWinStationAccesses;
  3205. *pcAccesses = MAX_PERM;
  3206. *piDefaultAccess = iWinStationDefAccess;
  3207. return S_OK;
  3208. }
  3209. //-----------------------------------------------------------------------------
  3210. // This is consistent with the termsrv code
  3211. //-----------------------------------------------------------------------------
  3212. GENERIC_MAPPING WinStationMap =
  3213. {
  3214. WINSTATION_QUERY , /* GenericRead */
  3215. WINSTATION_USER_ACCESS, /* GenericWrite */
  3216. WINSTATION_USER_ACCESS, /* GenericExecute */
  3217. WINSTATION_ALL_ACCESS /* GenericAll */
  3218. };
  3219. //-----------------------------------------------------------------------------
  3220. void CSecurityPage::SetParent( CPropsheet *pParent )
  3221. {
  3222. m_pParent = pParent;
  3223. }
  3224. //-----------------------------------------------------------------------------
  3225. STDMETHODIMP CSecurityPage::MapGeneric( const GUID *pguidObjectType , PUCHAR pAceFlags , ACCESS_MASK *pMask )
  3226. {
  3227. UNREFERENCED_PARAMETER( pguidObjectType );
  3228. UNREFERENCED_PARAMETER( pAceFlags );
  3229. ASSERT( pMask != NULL );
  3230. MapGenericMask( pMask , &WinStationMap );
  3231. return S_OK;
  3232. }
  3233. //-----------------------------------------------------------------------------
  3234. STDMETHODIMP CSecurityPage::GetInheritTypes( PSI_INHERIT_TYPE *ppInheritTypes , PULONG pcInheritTypes )
  3235. {
  3236. UNREFERENCED_PARAMETER( ppInheritTypes );
  3237. UNREFERENCED_PARAMETER( pcInheritTypes );
  3238. return E_NOTIMPL;
  3239. }
  3240. //-----------------------------------------------------------------------------
  3241. STDMETHODIMP CSecurityPage::PropertySheetPageCallback( HWND hwnd , UINT uMsg , SI_PAGE_TYPE uPage )
  3242. {
  3243. UNREFERENCED_PARAMETER( hwnd );
  3244. UNREFERENCED_PARAMETER( uPage );
  3245. if( uMsg == PSPCB_SI_INITDIALOG )
  3246. {
  3247. ODS( L"CSecurityPage::PropertySheetPageCallback -- Init\n" );
  3248. if (!m_WritablePermissionsTab )
  3249. {
  3250. LinkWindow_RegisterClass();
  3251. DialogBox( _Module.GetResourceInstance( ), MAKEINTRESOURCE(IDD_CUSTOM_SECURITY),
  3252. hwnd, CustomSecurityDlgProc);
  3253. LinkWindow_UnregisterClass(_Module.GetModuleInstance( ));
  3254. }
  3255. }
  3256. else if( uMsg == PSPCB_RELEASE )
  3257. {
  3258. ODS( L"CSecurityPage::PropertySheetPageCallback -- Release\n" );
  3259. }
  3260. return S_FALSE; //Be sure to return S_FALSE, This supresses other popups.
  3261. }
  3262. /*
  3263. Change to TSCC's permissions TAB such that the default state is READ-ONLY unless
  3264. group policy is used to override it.
  3265. If TRUE, permissions TAB can be edited by local Adimn.
  3266. if FALSE, the local Admin should not edit permissions TAB, it is read only
  3267. */
  3268. BOOLEAN QueryWriteAccess()
  3269. {
  3270. DWORD ValueType;
  3271. DWORD ValueSize = sizeof(DWORD);
  3272. DWORD valueData ;
  3273. LONG errorCode;
  3274. HKEY hTSControlKey = NULL;
  3275. //
  3276. // first check the policy tree,
  3277. //
  3278. POLICY_TS_MACHINE p;
  3279. RegGetMachinePolicy(&p);
  3280. if ( p.fPolicyWritableTSCCPermissionsTAB )
  3281. {
  3282. return (BOOLEAN)( p.fWritableTSCCPermissionsTAB ? TRUE : FALSE );
  3283. }
  3284. // if we got this far, then no policy was set. Check the local machine now.
  3285. errorCode = RegOpenKeyEx( HKEY_LOCAL_MACHINE, REG_CONTROL_TSERVER, 0,
  3286. KEY_READ, &hTSControlKey );
  3287. if ( ( errorCode == ERROR_SUCCESS ) && hTSControlKey )
  3288. {
  3289. errorCode = RegQueryValueEx( hTSControlKey,
  3290. POLICY_TS_TSCC_PERM_TAB_WRITABLE , NULL, &ValueType,
  3291. (LPBYTE) &valueData, &ValueSize );
  3292. RegCloseKey(hTSControlKey);
  3293. if (errorCode == ERROR_SUCCESS )
  3294. {
  3295. return (BOOLEAN)( valueData ? TRUE : FALSE ) ;
  3296. }
  3297. }
  3298. // if no localKey, gee... the registry is missing data... return FALSE to be on the secure side
  3299. return FALSE;
  3300. }
  3301. /*-----------------------------------------------------------------------------
  3302. JeffreyS 1/24/97:
  3303. If you don't set the SI_RESET flag in
  3304. ISecurityInformation::GetObjectInformation, then fDefault should never be TRUE
  3305. so you can ignore it. Returning E_NOTIMPL in this case is OK too.
  3306. If you want the user to be able to reset the ACL to some default state
  3307. (defined by you) then turn on SI_RESET and return your default ACL
  3308. when fDefault is TRUE. This happens if/when the user pushes a button
  3309. that is only visible when SI_RESET is on.
  3310. -----------------------------------------------------------------------------*/
  3311. STDMETHODIMP CSecurityPage::GetObjectInformation( PSI_OBJECT_INFO pObjectInfo )
  3312. {
  3313. ASSERT( pObjectInfo != NULL && !IsBadWritePtr(pObjectInfo, sizeof(*pObjectInfo ) ) );
  3314. pObjectInfo->dwFlags = SI_OWNER_READONLY | SI_EDIT_PERMS | SI_NO_ACL_PROTECT | SI_PAGE_TITLE | SI_EDIT_AUDITS | SI_ADVANCED | SI_RESET;
  3315. m_WritablePermissionsTab = QueryWriteAccess() ;
  3316. if( ! m_WritablePermissionsTab ) {
  3317. pObjectInfo->dwFlags |= SI_READONLY;
  3318. }
  3319. pObjectInfo->hInstance = _Module.GetResourceInstance( );
  3320. pObjectInfo->pszServerName = NULL;
  3321. pObjectInfo->pszObjectName = m_pParent->m_pResNode->GetConName();
  3322. VERIFY_E( 0 , LoadString( _Module.GetResourceInstance( ) , IDS_SECURPAGENAME , m_szPageName , SIZE_OF_BUFFER( m_szPageName ) ) );
  3323. pObjectInfo->pszPageTitle = m_szPageName;
  3324. return S_OK;
  3325. }
  3326. //-----------------------------------------------------------------------------
  3327. STDMETHODIMP CSecurityPage::GetSecurity( SECURITY_INFORMATION RequestedInformation , PSECURITY_DESCRIPTOR *ppSecurityDescriptor , BOOL bDefault )
  3328. {
  3329. #ifdef DBG
  3330. if( RequestedInformation & OWNER_SECURITY_INFORMATION )
  3331. {
  3332. ODS( L"CSecurityPage::GetSecurity - OWNER_SECURITY_INFORMATION\n");
  3333. }
  3334. if( RequestedInformation & GROUP_SECURITY_INFORMATION )
  3335. {
  3336. ODS( L"CSecurityPage::GetSecurity - GROUP_SECURITY_INFORMATION\n");
  3337. }
  3338. if( RequestedInformation & DACL_SECURITY_INFORMATION )
  3339. {
  3340. ODS( L"CSecurityPage::GetSecurity - DACL_SECURITY_INFORMATION\n");
  3341. }
  3342. if( RequestedInformation & SACL_SECURITY_INFORMATION )
  3343. {
  3344. ODS( L"CSecurityPage::GetSecurity - SACL_SECURITY_INFORMATION\n");
  3345. }
  3346. #endif
  3347. if( 0 == RequestedInformation || NULL == ppSecurityDescriptor )
  3348. {
  3349. ASSERT( FALSE );
  3350. return E_INVALIDARG;
  3351. }
  3352. ICfgComp *pCfgcomp = NULL;
  3353. if( m_pParent->m_pResNode->GetServer( &pCfgcomp ) == 0 )
  3354. {
  3355. return FALSE;
  3356. }
  3357. LONG lSDsize;
  3358. HRESULT hr;
  3359. PSECURITY_DESCRIPTOR pSD = NULL;
  3360. if( bDefault )
  3361. {
  3362. hr = pCfgcomp->GetDefaultSecurityDescriptor( &lSDsize , &pSD );
  3363. *ppSecurityDescriptor = pSD;
  3364. }
  3365. else
  3366. {
  3367. BOOL bChanged = FALSE;
  3368. hr = pCfgcomp->GetSecurityDescriptor( m_pParent->m_pResNode->GetConName( ) , &lSDsize , &pSD );
  3369. // check for legacy "denied logoff" ace and remove.
  3370. if( xxxLegacyLogoffCleanup( &pSD , &bChanged ) != ERROR_SUCCESS )
  3371. {
  3372. hr = pCfgcomp->GetDefaultSecurityDescriptor( &lSDsize , &pSD );
  3373. }
  3374. *ppSecurityDescriptor = pSD;
  3375. }
  3376. pCfgcomp->Release( );
  3377. return hr;
  3378. }
  3379. //-----------------------------------------------------------------------------
  3380. STDMETHODIMP CSecurityPage::SetSecurity( SECURITY_INFORMATION SecurityInformation ,PSECURITY_DESCRIPTOR pSecurityDescriptor )
  3381. {
  3382. HRESULT hr = S_OK;
  3383. ICfgComp *pCfgcomp = NULL;
  3384. PSECURITY_DESCRIPTOR pSD1;
  3385. if( m_pParent == NULL || m_pParent->m_pResNode == NULL )
  3386. {
  3387. hr = E_UNEXPECTED;
  3388. }
  3389. else if( m_pParent->m_pResNode->GetServer( &pCfgcomp ) != 0 )
  3390. {
  3391. long lSDsize;
  3392. hr = pCfgcomp->GetSecurityDescriptor( m_pParent->m_pResNode->GetConName( ) , &lSDsize , &pSD1 );
  3393. if( FAILED( hr ) )
  3394. {
  3395. pCfgcomp->Release( );
  3396. return hr;
  3397. }
  3398. SECURITY_DESCRIPTOR_CONTROL sdc;
  3399. DWORD dwREV;
  3400. PACL pDacl = NULL;
  3401. PACL pSacl = NULL;
  3402. SECURITY_DESCRIPTOR absSD;
  3403. BOOL bSaclPresent = FALSE;
  3404. BOOL bSaclDefaulted = FALSE;
  3405. BOOL bDaclPresent = FALSE;
  3406. BOOL bDaclDefaulted = FALSE;
  3407. //
  3408. // Convert SelfRel to Absolute
  3409. // ignore owner and group
  3410. //
  3411. GetSecurityDescriptorControl( pSD1 , &sdc , &dwREV );
  3412. if( !InitializeSecurityDescriptor( &absSD , dwREV ) )
  3413. {
  3414. DBGMSG( L"TSCC!CSecurityPage_SetSecurity InitializeSecurityDescriptor failed with 0x%x\n" , GetLastError( ) );
  3415. return E_FAIL;
  3416. }
  3417. GetSecurityDescriptorDacl( pSD1 , &bDaclPresent , &pDacl , &bDaclDefaulted );
  3418. SetSecurityDescriptorDacl( &absSD , bDaclPresent , pDacl , bDaclDefaulted );
  3419. GetSecurityDescriptorSacl( pSD1 , &bSaclPresent , &pSacl , &bSaclDefaulted );
  3420. SetSecurityDescriptorSacl( &absSD , bSaclPresent , pSacl , bSaclDefaulted );
  3421. // now call SetDACL or SACL depending on SecurityInformation
  3422. if( SecurityInformation & OWNER_SECURITY_INFORMATION )
  3423. {
  3424. ODS( L"CSecurityPage::SetSecurity - OWNER_SECURITY_INFORMATION ( default value set )\n");
  3425. }
  3426. if( SecurityInformation & GROUP_SECURITY_INFORMATION )
  3427. {
  3428. ODS( L"CSecurityPage::SetSecurity - GROUP_SECURITY_INFORMATION ( default value set )\n");
  3429. }
  3430. if( SecurityInformation & DACL_SECURITY_INFORMATION )
  3431. {
  3432. ODS( L"CSecurityPage::SetSecurity - DACL_SECURITY_INFORMATION\n");
  3433. GetSecurityDescriptorDacl( pSecurityDescriptor , &bDaclPresent , &pDacl , &bDaclDefaulted );
  3434. SetSecurityDescriptorDacl( &absSD , bDaclPresent , pDacl , bDaclDefaulted );
  3435. }
  3436. if( SecurityInformation & SACL_SECURITY_INFORMATION )
  3437. {
  3438. ODS( L"CSecurityPage::SetSecurity - SACL_SECURITY_INFORMATION\n");
  3439. GetSecurityDescriptorSacl( pSecurityDescriptor , &bSaclPresent , &pSacl , &bSaclDefaulted );
  3440. SetSecurityDescriptorSacl( &absSD , bSaclPresent , pSacl , bSaclDefaulted );
  3441. }
  3442. PSID SystemSid = NULL;
  3443. SID_IDENTIFIER_AUTHORITY NtSidAuthority = SECURITY_NT_AUTHORITY;
  3444. hr = E_OUTOFMEMORY;
  3445. if( AllocateAndInitializeSid( &NtSidAuthority,
  3446. 1,
  3447. SECURITY_LOCAL_SYSTEM_RID,
  3448. 0, 0, 0, 0, 0, 0, 0,
  3449. &SystemSid ) )
  3450. {
  3451. if( SystemSid != NULL )
  3452. {
  3453. hr = S_OK;
  3454. }
  3455. }
  3456. PSECURITY_DESCRIPTOR pSD = NULL;
  3457. DWORD dwSDLen;
  3458. if( SUCCEEDED( hr ) )
  3459. {
  3460. VERIFY_S( TRUE , SetSecurityDescriptorOwner( &absSD , SystemSid , FALSE ) );
  3461. VERIFY_S( TRUE, SetSecurityDescriptorGroup( &absSD , SystemSid , FALSE ) );
  3462. dwSDLen = 0;
  3463. MakeSelfRelativeSD( &absSD, pSD, &dwSDLen);
  3464. if (dwSDLen != 0)
  3465. {
  3466. pSD = ( LPBYTE )new BYTE[ dwSDLen ];
  3467. }
  3468. }
  3469. if( pSD == NULL )
  3470. {
  3471. ODS( L"TSCC!CSecurityPage::SetSecurity - SD allocation failed\n" );
  3472. hr = E_OUTOFMEMORY;
  3473. }
  3474. if( SUCCEEDED( hr ) )
  3475. {
  3476. if( !MakeSelfRelativeSD( &absSD , pSD , &dwSDLen ) )
  3477. {
  3478. hr = E_UNEXPECTED;
  3479. DBGMSG( L"MakeSelfRelativeSD - failed in CSecurityPage::SetSecurity With error %x\n" , GetLastError( ) );
  3480. }
  3481. if( SUCCEEDED( hr ) )
  3482. {
  3483. hr = pCfgcomp->SetSecurityDescriptor( m_pParent->m_pResNode->GetConName( ) , dwSDLen , pSD );
  3484. }
  3485. if( SUCCEEDED( hr ) )
  3486. {
  3487. ODS( L"TSCC : Update SD for TERMSRV\n" );
  3488. hr = pCfgcomp->ForceUpdate( );
  3489. // global flag can only be set to true
  3490. m_pParent->m_bPropertiesChange = TRUE;
  3491. }
  3492. delete[] pSD;
  3493. }
  3494. if( SystemSid != NULL )
  3495. {
  3496. FreeSid( SystemSid );
  3497. }
  3498. // free originally stored SD.
  3499. LocalFree( pSD1 );
  3500. pCfgcomp->Release( );
  3501. }
  3502. return hr;
  3503. }
  3504. typedef HPROPSHEETPAGE (*CREATEPAGE_PROC) (LPSECURITYINFO);
  3505. //-----------------------------------------------------------------------------
  3506. HPROPSHEETPAGE GetSecurityPropertyPage( CPropsheet *pParent )
  3507. {
  3508. LPVOID *pvFunction = &g_aAclFunctions[ ACLUI_CREATE_PAGE ].lpfnFunction;
  3509. if( *pvFunction == NULL )
  3510. {
  3511. g_aAclFunctions[ ACLUI_CREATE_PAGE ].hInst = LoadLibrary( TEXT("ACLUI.DLL") );
  3512. ASSERT( g_aAclFunctions[ ACLUI_CREATE_PAGE ].hInst != NULL );
  3513. if( g_aAclFunctions[ ACLUI_CREATE_PAGE ].hInst == NULL )
  3514. {
  3515. return NULL;
  3516. }
  3517. *pvFunction = ( LPVOID )GetProcAddress( g_aAclFunctions[ ACLUI_CREATE_PAGE ].hInst , g_aAclFunctions[ ACLUI_CREATE_PAGE ].pcstrFunctionName );
  3518. ASSERT( *pvFunction != NULL );
  3519. if( *pvFunction == NULL )
  3520. {
  3521. return NULL;
  3522. }
  3523. CComObject< CSecurityPage > *psecinfo = NULL;
  3524. HRESULT hRes = CComObject< CSecurityPage >::CreateInstance( &psecinfo );
  3525. if( SUCCEEDED( hRes ) )
  3526. {
  3527. // InitStrings();
  3528. psecinfo->SetParent( pParent );
  3529. return ( ( CREATEPAGE_PROC )*pvFunction )( psecinfo );
  3530. }
  3531. }
  3532. return NULL;
  3533. }
  3534. //-----------------------------------------------------------------------------
  3535. // Error messag boxes
  3536. //
  3537. void ErrMessage( HWND hwndOwner , INT_PTR iResourceID )
  3538. {
  3539. xxxErrMessage( hwndOwner , iResourceID , IDS_ERROR_TITLE , MB_OK | MB_ICONERROR );
  3540. }
  3541. //-----------------------------------------------------------------------------
  3542. void TscAccessDeniedMsg( HWND hwnd )
  3543. {
  3544. xxxErrMessage( hwnd , IDS_TSCACCESSDENIED , IDS_TSCERRTITLE , MB_OK | MB_ICONERROR );
  3545. }
  3546. //-----------------------------------------------------------------------------
  3547. void TscGeneralErrMsg( HWND hwnd )
  3548. {
  3549. xxxErrMessage( hwnd , IDS_TSCERRGENERAL , IDS_TSCERRTITLE , MB_OK | MB_ICONERROR );
  3550. }
  3551. //-----------------------------------------------------------------------------
  3552. void xxxErrMessage( HWND hwnd , INT_PTR nResMessageId , INT_PTR nResTitleId , UINT nFlags )
  3553. {
  3554. TCHAR tchErrMsg[ 256 ];
  3555. TCHAR tchErrTitle[ 80 ];
  3556. VERIFY_E( 0 , LoadString( _Module.GetResourceInstance( ) , ( UINT )nResMessageId , tchErrMsg , SIZE_OF_BUFFER( tchErrMsg ) ) );
  3557. VERIFY_E( 0 , LoadString( _Module.GetResourceInstance( ) , ( UINT )nResTitleId , tchErrTitle , SIZE_OF_BUFFER( tchErrTitle ) ) );
  3558. if( hwnd == NULL )
  3559. {
  3560. nFlags |= MB_TASKMODAL;
  3561. }
  3562. MessageBox( hwnd , tchErrMsg , tchErrTitle , nFlags ) ; //MB_OK|MB_ICONERROR );
  3563. }
  3564. //-----------------------------------------------------------------------------
  3565. void ReportStatusError( HWND hwnd , DWORD dwStatus )
  3566. {
  3567. LPTSTR pBuffer = NULL;
  3568. TCHAR tchTitle[ 80 ];
  3569. TCHAR tchBuffer[ 256 ];
  3570. TCHAR tchErr[ 256 ];
  3571. if( dwStatus != 0 )
  3572. {
  3573. VERIFY_E( 0 , LoadString( _Module.GetResourceInstance( ) , IDS_TSCERRTITLE , tchTitle , SIZE_OF_BUFFER( tchTitle ) ) );
  3574. VERIFY_E( 0 , LoadString( _Module.GetResourceInstance( ) , IDS_REPORTERROR , tchBuffer , SIZE_OF_BUFFER( tchBuffer ) ) );
  3575. FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER |
  3576. FORMAT_MESSAGE_FROM_SYSTEM,
  3577. NULL, //ignored
  3578. dwStatus , //message ID
  3579. MAKELANGID( LANG_NEUTRAL, SUBLANG_NEUTRAL ), //message language
  3580. (LPTSTR)&pBuffer, //address of buffer pointer
  3581. 0, //minimum buffer size
  3582. NULL); //no other arguments
  3583. wsprintf( tchErr , tchBuffer , pBuffer );
  3584. ::MessageBox( hwnd , tchErr , tchTitle , MB_OK | MB_ICONERROR );
  3585. if( pBuffer != NULL )
  3586. {
  3587. LocalFree( pBuffer );
  3588. }
  3589. }
  3590. }
  3591. //=------------------------------------------------------------------------------------------------
  3592. // xxxLegacDenyCleanup -- checked for the old LOGOFF bit
  3593. //=------------------------------------------------------------------------------------------------
  3594. DWORD xxxLegacyLogoffCleanup( PSECURITY_DESCRIPTOR *ppSD , PBOOL pfDaclChanged )
  3595. {
  3596. ACL_SIZE_INFORMATION asi;
  3597. BOOL bDaclPresent;
  3598. BOOL bDaclDefaulted;
  3599. PACL pDacl = NULL;
  3600. SECURITY_DESCRIPTOR_CONTROL sdc;
  3601. DWORD dwREV;
  3602. SECURITY_DESCRIPTOR absSD;
  3603. BOOL bSaclPresent;
  3604. BOOL bSaclDefaulted;
  3605. BOOL bOwnerDefaulted;
  3606. PSID psidOwner = NULL;
  3607. PVOID pAce = NULL;
  3608. PACL pSacl = NULL;
  3609. PSECURITY_DESCRIPTOR pOldSD = NULL;
  3610. DWORD dwStatus = ERROR_SUCCESS;
  3611. ZeroMemory( &asi , sizeof( ACL_SIZE_INFORMATION ) );
  3612. if( !GetSecurityDescriptorDacl( *ppSD ,
  3613. &bDaclPresent ,
  3614. &pDacl,
  3615. &bDaclDefaulted ) )
  3616. {
  3617. dwStatus = GetLastError();
  3618. DBGMSG( L"xxxLegacyLogoffCleanup@GetSecurityDescriptorDacl returned 0x%x\n" , dwStatus );
  3619. return dwStatus;
  3620. }
  3621. do
  3622. {
  3623. *pfDaclChanged = FALSE;
  3624. if( !GetAclInformation( pDacl , &asi , sizeof( asi ) , AclSizeInformation ) )
  3625. {
  3626. dwStatus = GetLastError( );
  3627. DBGMSG( L"xxxLegacyLogoffCleanup@GetAclInformation returned 0x%x\n" , dwStatus );
  3628. break;
  3629. }
  3630. // killed denied logoff.
  3631. BYTE bAceType;
  3632. for( int i = 0 ; i < ( int )asi.AceCount ; ++i )
  3633. {
  3634. if( !GetAce( pDacl , i , &pAce ) )
  3635. {
  3636. dwStatus = GetLastError( );
  3637. DBGMSG( L"xxxLegacyLogoffCleanup@GetAce returned 0x%x\n" , dwStatus );
  3638. break;
  3639. }
  3640. bAceType = ( ( PACE_HEADER )pAce )->AceType;
  3641. if( bAceType == ACCESS_DENIED_ACE_TYPE || bAceType == ACCESS_ALLOWED_ACE_TYPE )
  3642. {
  3643. // if the denied ace represents a single bit get rid of it
  3644. if( ( ( ACCESS_DENIED_ACE * )pAce )->Mask == WINSTATION_LOGOFF )
  3645. {
  3646. if( DeleteAce( pDacl , i ) )
  3647. {
  3648. // pDacl should have been reallocated to we need to re-obtain the acl info
  3649. GetAclInformation( pDacl , &asi , sizeof( asi ) , AclSizeInformation );
  3650. // reset the loop to point to the first ace
  3651. i=-1;
  3652. *pfDaclChanged = TRUE;
  3653. }
  3654. }
  3655. else if( ( ( ACCESS_DENIED_ACE * )pAce )->Mask & WINSTATION_LOGOFF )
  3656. {
  3657. // if the denied ace is a collection of bits with one as logoff turn the bit off
  3658. ( ( ACCESS_DENIED_ACE * )pAce )->Mask ^= WINSTATION_LOGOFF;
  3659. *pfDaclChanged = TRUE;
  3660. }
  3661. }
  3662. }
  3663. if( dwStatus == ERROR_SUCCESS && *pfDaclChanged )
  3664. {
  3665. //
  3666. // Convert SelfRel to Absolute
  3667. //
  3668. DWORD dwSDLen = 0;
  3669. pOldSD = *ppSD;
  3670. GetSecurityDescriptorControl( *ppSD , &sdc , &dwREV );
  3671. InitializeSecurityDescriptor( &absSD , dwREV );
  3672. SetSecurityDescriptorDacl( &absSD , bDaclPresent , pDacl , bDaclDefaulted );
  3673. GetSecurityDescriptorSacl( *ppSD , &bSaclPresent , &pSacl , &bSaclDefaulted );
  3674. SetSecurityDescriptorSacl( &absSD , bSaclPresent , pSacl , bSaclDefaulted );
  3675. GetSecurityDescriptorOwner( *ppSD , &psidOwner , &bOwnerDefaulted );
  3676. SetSecurityDescriptorOwner( &absSD , psidOwner , FALSE );
  3677. SetSecurityDescriptorGroup( &absSD , psidOwner , FALSE );
  3678. *ppSD = NULL;
  3679. if( !MakeSelfRelativeSD( &absSD , *ppSD , &dwSDLen ) )
  3680. {
  3681. ODS( L"xxxLegacyLogoffCleanup -- MakeSelfRelativeSD failed as expected\n" );
  3682. *ppSD = ( PSECURITY_DESCRIPTOR )LocalAlloc( LMEM_FIXED , dwSDLen );
  3683. if( *ppSD == NULL )
  3684. {
  3685. dwStatus = ERROR_NOT_ENOUGH_MEMORY;
  3686. DBGMSG( L"xxxLegacyLogoffCleanup -- LocalAlloc failed 0x%x\n" , dwStatus );
  3687. break;
  3688. }
  3689. if( !MakeSelfRelativeSD( &absSD , *ppSD , &dwSDLen ) )
  3690. {
  3691. dwStatus = GetLastError( );
  3692. DBGMSG( L"xxxLegacyLogoffCleanup -- MakeSelfRelativeSD failed 0x%x\n" , dwStatus );
  3693. break;
  3694. }
  3695. }
  3696. }
  3697. }while( 0 );
  3698. if( pOldSD != NULL )
  3699. {
  3700. LocalFree( pOldSD );
  3701. }
  3702. return dwStatus;
  3703. }
  3704. //
  3705. INT_PTR APIENTRY
  3706. CustomSecurityDlgProc (
  3707. HWND hDlg,
  3708. UINT uMsg,
  3709. WPARAM wParam,
  3710. LPARAM lParam)
  3711. {
  3712. UNREFERENCED_PARAMETER( hDlg );
  3713. switch (uMsg)
  3714. {
  3715. case WM_INITDIALOG:
  3716. // This may seem that it does nothin, but it casues this function to return TRUE
  3717. // otherwise, you won't get this dialog!
  3718. break;
  3719. case WM_NOTIFY:
  3720. switch (((NMHDR FAR*)lParam)->code)
  3721. {
  3722. case NM_CLICK:
  3723. case NM_RETURN:
  3724. if(wParam == IDC_GP_LINK)
  3725. {
  3726. ShellExecute(NULL,TEXT("open"),TEXT("gpedit.msc"),NULL,NULL,SW_SHOW);
  3727. break;
  3728. }
  3729. else
  3730. {
  3731. return FALSE;
  3732. }
  3733. default:
  3734. return FALSE;
  3735. }
  3736. break;
  3737. case WM_COMMAND:
  3738. switch(LOWORD(wParam))
  3739. {
  3740. case IDOK:
  3741. case IDCANCEL:
  3742. EndDialog(hDlg,0);
  3743. break;
  3744. default:
  3745. return FALSE;
  3746. }
  3747. default:
  3748. return FALSE;
  3749. }
  3750. return TRUE;
  3751. }