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.

1067 lines
30 KiB

  1. // configdlg.cpp : implements TSConfigDlg dialog.
  2. //
  3. #include "stdafx.h"
  4. #include "resource.h"
  5. #include "configdlg.h"
  6. const CONNECTION_TIME_DIGIT_MAX = 5; // 5 digits max
  7. const CONNECTION_TIME_DEFAULT = 120; // 120 minutes
  8. const CONNECTION_TIME_MIN = 1; // 1 minute
  9. const CONNECTION_TIME_MAX = 71582; // 71582 minutes (max msec for ULONG)
  10. const DISCONNECTION_TIME_DIGIT_MAX = 5; // 5 digits max
  11. const DISCONNECTION_TIME_DEFAULT = 10; // 10 minutes
  12. const DISCONNECTION_TIME_MIN = 1; // 1 minute
  13. const DISCONNECTION_TIME_MAX = 71582; // 71582 minutes (max msec for ULONG)
  14. const IDLE_TIME_DIGIT_MAX = 5; // 5 digits max
  15. const IDLE_TIME_DEFAULT = 10; // 10 minutes
  16. const IDLE_TIME_MIN = 1; // 1 minute
  17. const IDLE_TIME_MAX = 71582; // 71582 minutes (max msec for ULONG)
  18. const TIME_RESOLUTION = 60000; // stored as msec-seen as minutes
  19. // forword declard.
  20. DWORD wchar2TCHAR(TCHAR *dest, const WCHAR *src);
  21. extern HINSTANCE GetInstance();
  22. BOOL TSConfigDlg::m_sbWindowLogSet = FALSE;
  23. // property page dialog procedure : handles dialog messages.
  24. BOOL CALLBACK TSConfigDlg::PropertyPageDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  25. {
  26. if (uMsg == WM_INITDIALOG)
  27. {
  28. // LPARAM points to the property sheet page.
  29. // this will give us this pointer to access the class.
  30. TSConfigDlg *pDlg = reinterpret_cast<TSConfigDlg*>(LPPROPSHEETPAGE(lParam)->lParam);
  31. ASSERT(NULL != pDlg);
  32. ASSERT(pDlg->AssertClass());
  33. SetWindowLong(hwndDlg, DWL_USER, long(pDlg));
  34. // ok now hereafter we can access the class pointer.
  35. // maks_done: check mfc implementation, how do they do it ?
  36. // what mfc does is - its hooks into the wnd creation process
  37. // and keeps a map of hwnd vs objects.
  38. m_sbWindowLogSet = TRUE;
  39. return pDlg->OnInitDialog(hwndDlg, wParam, lParam);
  40. }
  41. // now we have set DWL_USER as class pointer during INIT DIALOG.
  42. if (m_sbWindowLogSet)
  43. {
  44. TSConfigDlg *pDlg = reinterpret_cast<TSConfigDlg*>(GetWindowLong(hwndDlg, DWL_USER));
  45. ASSERT(NULL != pDlg);
  46. ASSERT(pDlg->AssertClass());
  47. if (uMsg == WM_COMMAND)
  48. return pDlg->OnCommand(wParam, lParam);
  49. if (uMsg == WM_NOTIFY)
  50. {
  51. LOGMESSAGE3(_T("Received WM_NOTIFY:hwnddlg =%ul,wParam=%u,lParam=%ul"), hwndDlg, wParam, lParam);
  52. return pDlg->OnNotify(wParam, lParam);
  53. }
  54. }
  55. return 0;
  56. }
  57. // Property Sheet Procedure : gets notified about CREATE, RELEASE events
  58. UINT CALLBACK TSConfigDlg::PropSheetPageProc (
  59. HWND /* hWnd */, // [in] Window handle - always null
  60. UINT uMsg, // [in,out] Either the create or delete message
  61. LPPROPSHEETPAGE pPsp // [in,out] Pointer to the property sheet struct
  62. )
  63. {
  64. ASSERT( NULL != pPsp );
  65. // We need to recover a pointer to the current instance. We can't just use
  66. // "this" because we are in a static function
  67. TSConfigDlg* pMe = reinterpret_cast<TSConfigDlg*>(pPsp->lParam);
  68. ASSERT( NULL != pMe );
  69. ASSERT(pMe->AssertClass());
  70. switch( uMsg )
  71. {
  72. case PSPCB_CREATE:
  73. break;
  74. case PSPCB_RELEASE:
  75. // this variable makes dialog proc setwindowlong on dialog handle.
  76. m_sbWindowLogSet = FALSE;
  77. delete pMe;
  78. return 1; //(pfnOrig)(hWnd, uMsg, pPsp);
  79. }
  80. return 1;
  81. } // end PropSheetPageProc()
  82. TSConfigDlg::TSConfigDlg (LPWSTR wMachineName, LPWSTR wUserName)
  83. {
  84. ASSERT(wMachineName);
  85. ASSERT(wUserName);
  86. ASSERT(wcslen(wMachineName) < SIZE_MAX_SERVERNAME);
  87. ASSERT(wcslen(wUserName) < SIZE_MAX_USERNAME);
  88. VERIFY( wchar2TCHAR(m_Username, wUserName) < SIZE_MAX_USERNAME);
  89. VERIFY( wchar2TCHAR(m_Servername, wMachineName) < SIZE_MAX_SERVERNAME);
  90. LOGMESSAGE0(_T("TSConfigDlg::TSConfigDlg ()"));
  91. m_tPropSheetPage.dwSize = sizeof (PROPSHEETPAGE);
  92. m_tPropSheetPage.hInstance = GetInstance ();
  93. m_tPropSheetPage.pszTemplate = MAKEINTRESOURCE(IDD);
  94. m_tPropSheetPage.dwFlags = PSP_USECALLBACK;
  95. m_tPropSheetPage.pfnDlgProc = PropertyPageDlgProc;
  96. m_tPropSheetPage.pfnCallback = PropSheetPageProc;
  97. m_tPropSheetPage.lParam = long(this);
  98. m_sbWindowLogSet = FALSE;
  99. m_id = IDD_TS_USER_CONFIG_EDIT;
  100. }
  101. BOOL TSConfigDlg::AssertClass() const
  102. {
  103. return m_id == IDD_TS_USER_CONFIG_EDIT;
  104. }
  105. TSConfigDlg::~TSConfigDlg ()
  106. {
  107. LOGMESSAGE0(_T("TSConfigDlg::~TSConfigDlg ()"));
  108. }
  109. BOOL TSConfigDlg::OnInitDialog(
  110. HWND hwndDlg,
  111. WPARAM /* wParam */,
  112. LPARAM /* lParam */
  113. )
  114. {
  115. m_hDlg = hwndDlg;
  116. // get the user info and initialize dialog class members with it.
  117. GetUserInfo();
  118. // initializes the controls.
  119. InitControls();
  120. return 1; // non zero since we are not calling setfocus
  121. }
  122. APIERR TSConfigDlg::SetUserInfo ()
  123. {
  124. APIERR err;
  125. USERCONFIG UserConfig;
  126. /* If the object is not 'dirty', no need to save info.
  127. */
  128. // if ( !_fDirty )
  129. // return NERR_Success;
  130. /* Zero-initialize USERCONFIG structure and copy member variable
  131. * contents there.
  132. */
  133. ZeroMemory( &UserConfig, sizeof(USERCONFIG) );
  134. MembersToUCStruct( &UserConfig );
  135. /*
  136. * Save user's configuration.
  137. */
  138. err = RegUserConfigSet(
  139. GetServername(), // servername
  140. GetUsername(), // username
  141. &UserConfig,
  142. sizeof(UserConfig)
  143. );
  144. // Don't reset 'dirty' flag to behave properly with new RegUserConfig APIs
  145. // (we might get called twice, just like the UsrMgr objects to, so we want
  146. // to happily write our our data twice, just like they do)
  147. // _fDirty = FALSE;
  148. //
  149. // By not setting _fDirty = FALSE here we try to check the validity of the RemoteWFHomeDir whenever OK is pressed
  150. // This is because MS used 2 structures to hold its HomeDir, and could compare the two. We only have one and rely
  151. // on this dirty flag. This flag is used in USERPROP_DLG::I_PerformOne_Write(...) and is set in the
  152. // USER_CONFIG::GetInfo and USER_CONFIG::GetDefaults and USERPROF_DLG_NT::PerformOne()
  153. //
  154. tDialogData._fWFHomeDirDirty = FALSE;
  155. return err;
  156. }
  157. APIERR TSConfigDlg::GetUserInfo ()
  158. {
  159. APIERR err;
  160. ULONG Length;
  161. USERCONFIG UserConfig;
  162. // calll regapi function for getting user configuration
  163. err = RegUserConfigQuery (
  164. GetServername(), // servername
  165. GetUsername(), // username
  166. &UserConfig, // address for userconfig buffer
  167. sizeof(UserConfig), // size of buffer
  168. &Length // returned size
  169. );
  170. if ( err == NERR_Success )
  171. {
  172. ASSERT(Length == sizeof(UserConfig));
  173. }
  174. else
  175. {
  176. LOGMESSAGE3(_T("RegUserConfigQuery failed for %s\\%s. Error = %ul"), GetServername(), GetUsername(), err);
  177. LOGMESSAGE0(_T("Getting Deafult user config"));
  178. err = RegDefaultUserConfigQuery(
  179. GetServername(), // servername
  180. &UserConfig, // address for userconfig buffer
  181. sizeof(UserConfig), // size of buffer
  182. &Length // returned length
  183. );
  184. if (err != NERR_Success)
  185. {
  186. LOGMESSAGE3(_T("RegDefaultUserConfigQuery failed for %s\\%s. Error = %ul"), GetServername(), GetUsername(), err);
  187. // maks_todo: must initialize defaults known to us over here.
  188. return err;
  189. }
  190. }
  191. UCStructToMembers( &UserConfig );
  192. tDialogData._fWFHomeDirDirty = FALSE;
  193. tDialogData._fDirty = FALSE;
  194. return err;
  195. }
  196. /*******************************************************************
  197. NAME: USER_CONFIG::UCStructToMembers
  198. SYNOPSIS: Copies a given USERCONFIG structure elements into
  199. corresponding member variables.
  200. ENTRY: pUCStruct - pointer to USERCONFIG structure.
  201. ********************************************************************/
  202. void TSConfigDlg::UCStructToMembers( PUSERCONFIG pUCStruct )
  203. {
  204. ASSERT(pUCStruct);
  205. tDialogData._fAllowLogon = (BOOL)!pUCStruct->fLogonDisabled;
  206. tDialogData._ulConnection = pUCStruct->MaxConnectionTime;
  207. tDialogData._ulDisconnection = pUCStruct->MaxDisconnectionTime;
  208. tDialogData._ulIdle = pUCStruct->MaxIdleTime;
  209. _tcscpy(tDialogData._nlsInitialProgram, pUCStruct->InitialProgram);
  210. _tcscpy(tDialogData._nlsWorkingDirectory, pUCStruct->WorkDirectory );
  211. tDialogData._fClientSpecified = pUCStruct->fInheritInitialProgram;
  212. tDialogData._fAutoClientDrives = pUCStruct->fAutoClientDrives;
  213. tDialogData._fAutoClientLpts = pUCStruct->fAutoClientLpts;
  214. tDialogData._fForceClientLptDef = pUCStruct->fForceClientLptDef;
  215. tDialogData._iEncryption = (INT)pUCStruct->MinEncryptionLevel;
  216. tDialogData._fDisableEncryption = pUCStruct->fDisableEncryption;
  217. tDialogData._fHomeDirectoryMapRoot = pUCStruct->fHomeDirectoryMapRoot;
  218. tDialogData._iBroken = (INT)pUCStruct->fResetBroken;
  219. tDialogData._iReconnect = (INT)pUCStruct->fReconnectSame;
  220. tDialogData._iCallback = (INT)pUCStruct->Callback;
  221. _tcscpy(tDialogData._nlsPhoneNumber, pUCStruct->CallbackNumber );
  222. tDialogData._iShadow = (INT)pUCStruct->Shadow;
  223. _tcscpy(tDialogData._nlsNWLogonServer, pUCStruct->NWLogonServer );
  224. _tcscpy(tDialogData._nlsWFProfilePath, pUCStruct->WFProfilePath );
  225. _tcscpy(tDialogData._nlsWFHomeDir, pUCStruct->WFHomeDir );
  226. _tcscpy(tDialogData._nlsWFHomeDirDrive, pUCStruct->WFHomeDirDrive);
  227. }
  228. /*******************************************************************
  229. NAME: USER_CONFIG::MembersToUCStruct
  230. SYNOPSIS: Copies member variables into a given USERCONFIG
  231. structure elements.
  232. ENTRY: pUCStruct - pointer to USERCONFIG structure.
  233. ********************************************************************/
  234. void TSConfigDlg::MembersToUCStruct( PUSERCONFIG pUCStruct ) const
  235. {
  236. ASSERT(pUCStruct);
  237. pUCStruct->fLogonDisabled = !tDialogData._fAllowLogon;
  238. pUCStruct->MaxConnectionTime = tDialogData._ulConnection;
  239. pUCStruct->MaxDisconnectionTime = tDialogData._ulDisconnection;
  240. pUCStruct->MaxIdleTime = tDialogData._ulIdle;
  241. _tcscpy( pUCStruct->InitialProgram, tDialogData._nlsInitialProgram);
  242. _tcscpy( pUCStruct->WorkDirectory, tDialogData._nlsWorkingDirectory);
  243. pUCStruct->fInheritInitialProgram = tDialogData._fClientSpecified;
  244. pUCStruct->fAutoClientDrives = tDialogData._fAutoClientDrives;
  245. pUCStruct->fAutoClientLpts = tDialogData._fAutoClientLpts;
  246. pUCStruct->fForceClientLptDef = tDialogData._fForceClientLptDef;
  247. pUCStruct->MinEncryptionLevel = (BYTE)tDialogData._iEncryption;
  248. pUCStruct->fDisableEncryption = tDialogData._fDisableEncryption;
  249. pUCStruct->fHomeDirectoryMapRoot = tDialogData._fHomeDirectoryMapRoot;
  250. pUCStruct->fResetBroken = tDialogData._iBroken;
  251. pUCStruct->fReconnectSame = tDialogData._iReconnect;
  252. pUCStruct->Callback = (CALLBACKCLASS)tDialogData._iCallback;
  253. _tcscpy( pUCStruct->CallbackNumber, tDialogData._nlsPhoneNumber);
  254. pUCStruct->Shadow = (SHADOWCLASS)tDialogData._iShadow;
  255. _tcscpy( pUCStruct->NWLogonServer, tDialogData._nlsNWLogonServer);
  256. _tcscpy( pUCStruct->WFProfilePath, tDialogData._nlsWFProfilePath);
  257. _tcscpy( pUCStruct->WFHomeDir, tDialogData._nlsWFHomeDir);
  258. _tcscpy( pUCStruct->WFHomeDirDrive, tDialogData._nlsWFHomeDirDrive);
  259. }
  260. BOOL TSConfigDlg::OnNotify (WPARAM wParam, LPARAM lParam)
  261. {
  262. int idCtrl = (int) wParam;
  263. NMHDR *pnmh = (LPNMHDR) lParam;
  264. // typedef struct tagNMHDR {
  265. // HWND hwndFrom;
  266. // UINT idFrom;
  267. // UINT code;
  268. // } NMHDR;
  269. ASSERT(pnmh);
  270. switch(pnmh->code)
  271. {
  272. case PSN_KILLACTIVE:
  273. LOGMESSAGE0(_T("Its KillActive Notification"));
  274. if (VerifyChanges())
  275. // verify passed, allow the page to lose the activation
  276. SetWindowLong(GetDlgHandle(), DWL_MSGRESULT, FALSE);
  277. else
  278. // no verify failed, prevent the page from losing the activation
  279. SetWindowLong(GetDlgHandle(), DWL_MSGRESULT, TRUE);;
  280. break;
  281. case PSN_APPLY:
  282. LOGMESSAGE0(_T("Its Apply Notification"));
  283. ApplyChanges();
  284. break;
  285. case PSN_RESET:
  286. // cancel changes.
  287. LOGMESSAGE0(_T("Its Apply Reset"));
  288. break;
  289. default:
  290. break;
  291. }
  292. return 1;
  293. }
  294. BOOL TSConfigDlg::OnCommand(WPARAM wParam, LPARAM lParam)
  295. {
  296. WORD wNotifyCode = HIWORD(wParam); // notification code
  297. WORD wID = LOWORD(wParam); // item, control, or accelerator identifier
  298. HWND hwndCtl = (HWND) lParam; // handle of control
  299. //if (wNotifyCode == 0 || wNotifyCode == 1)
  300. // return 1;
  301. // dispatch the command messages accordingly.
  302. switch(wID)
  303. {
  304. case IDC_UCE_ALLOWLOGON:
  305. ALLOWLOGONEvent(wNotifyCode);
  306. break;
  307. case IDC_UCE_CONNECTION_NONE:
  308. CONNECTION_NONEEvent(wNotifyCode);
  309. break;
  310. case IDC_UCE_DISCONNECTION_NONE:
  311. DISCONNECTION_NONEEvent(wNotifyCode);
  312. break;
  313. case IDC_UCE_IDLE_NONE:
  314. IDLE_NONEEvent(wNotifyCode);
  315. break;
  316. case IDC_UCE_INITIALPROGRAM_INHERIT:
  317. INITIALPROGRAM_INHERITEvent(wNotifyCode);
  318. break;
  319. case IDC_UCE_SECURITY_DISABLEAFTERLOGON:
  320. SECURITY_DISABLEAFTERLOGONEvent(wNotifyCode);
  321. break;
  322. default:
  323. break;
  324. }
  325. return 1; // since we do not process message.
  326. }
  327. BOOL TSConfigDlg::InitControls ()
  328. {
  329. TCHAR str[SIZE_SMALL_STRING_BUFFER];
  330. struct
  331. {
  332. UINT uiControlID;
  333. UINT uiNoOfStrings;
  334. UINT auiStringList[7];
  335. } atListControls[] =
  336. {
  337. {
  338. IDC_UCE_SECURITY_ENCRYPT,
  339. 2,
  340. {
  341. IDS_UCE_ENCRYPT_NONE,
  342. IDS_UCE_ENCRYPT_LEVEL1,
  343. }
  344. },
  345. {
  346. IDC_UCE_BROKEN,
  347. 2,
  348. {
  349. IDS_UCE_BROKEN_DISCONNECT,
  350. IDS_UCE_BROKEN_RESET,
  351. }
  352. },
  353. {
  354. IDC_UCE_RECONNECT,
  355. 2,
  356. {
  357. IDS_UCE_RECONNECT_ANY,
  358. IDS_UCE_RECONNECT_PREVIOUS,
  359. }
  360. },
  361. {
  362. IDC_UCE_CALLBACK,
  363. 3,
  364. {
  365. IDS_UCE_CALLBACK_DISABLE,
  366. IDS_UCE_CALLBACK_ROVING,
  367. IDS_UCE_CALLBACK_FIXED,
  368. }
  369. },
  370. {
  371. IDC_UCE_SHADOW,
  372. 5,
  373. {
  374. IDS_UCE_SHADOW_DISABLE,
  375. IDS_UCE_SHADOW_INPUT_NOTIFY,
  376. IDS_UCE_SHADOW_INPUT_NONOTIFY,
  377. IDS_UCE_SHADOW_NOINPUT_NOTIFY,
  378. IDS_UCE_SHADOW_NOINPUT_NONOTIFY,
  379. }
  380. }
  381. };
  382. // for each list/combo box control
  383. for (int j = 0; j < sizeof(atListControls)/sizeof(atListControls[0]); j++)
  384. {
  385. // add all the strings specified for the control
  386. for (UINT i = 0; i < atListControls[j].uiNoOfStrings; i++)
  387. {
  388. DWORD dwSize = LoadString(
  389. GetInstance (),
  390. atListControls[j].auiStringList[i],
  391. str,
  392. SIZE_SMALL_STRING_BUFFER);
  393. ASSERT(dwSize != 0 && dwSize <= SIZE_SMALL_STRING_BUFFER - 1);
  394. SendDlgItemMessage(
  395. GetDlgHandle(),
  396. atListControls[j].uiControlID,
  397. CB_ADDSTRING,
  398. 0,
  399. LPARAM(str));
  400. }
  401. }
  402. // we dont want tristate buttons for now
  403. // as we are not supporting multipal users
  404. // lets make all the controls no tristate.
  405. int aCheckBoxes[] =
  406. {
  407. IDC_UCE_ALLOWLOGON,
  408. IDC_UCE_CONNECTION_NONE,
  409. IDC_UCE_DISCONNECTION_NONE,
  410. IDC_UCE_IDLE_NONE,
  411. IDC_UCE_INITIALPROGRAM_INHERIT,
  412. IDC_UCE_SECURITY_DISABLEAFTERLOGON
  413. };
  414. for (int i = 0; i < sizeof(aCheckBoxes)/sizeof(aCheckBoxes[0]); i++)
  415. {
  416. HWND hControlWnd = GetDlgItem(GetDlgHandle(), aCheckBoxes[i]);
  417. ASSERT(hControlWnd);
  418. //DWORD dwStyle = GetWindowLong(hControlWnd, GWL_STYLE);
  419. //dwStyle = dwStyle & ~BS_3STATE;
  420. SendMessage (hControlWnd, BM_SETSTYLE, LOWORD(BS_AUTOCHECKBOX), MAKELPARAM(0, 0));
  421. }
  422. // set text limit for the edit boxes.
  423. // EM_SETLIMITTEXT
  424. // wParam = (WPARAM) cbMax; // new text limits, in bytes
  425. // lParam = 0; // not used, must be zero
  426. struct
  427. {
  428. UINT uiEditControlid;
  429. UINT uiLimitText;
  430. } atTextLimits[] =
  431. {
  432. {IDC_UCE_CONNECTION, CONNECTION_TIME_DIGIT_MAX},
  433. {IDC_UCE_DISCONNECTION, DISCONNECTION_TIME_DIGIT_MAX},
  434. {IDC_UCE_IDLE, IDLE_TIME_DIGIT_MAX},
  435. {IDC_UCE_INITIALPROGRAM_COMMANDLINE, MAX_INIT_PROGRAM_SIZE},
  436. {IDC_UCE_INITIALPROGRAM_WORKINGDIRECTORY, MAX_INIT_DIR_SIZE}
  437. };
  438. for (i = 0; i < sizeof(atTextLimits)/sizeof(atTextLimits[0]); i++)
  439. {
  440. HWND hControlWnd = GetDlgItem(GetDlgHandle(), atTextLimits[i].uiEditControlid);
  441. ASSERT(hControlWnd);
  442. //DWORD dwStyle = GetWindowLong(hControlWnd, GWL_STYLE);
  443. //dwStyle = dwStyle & ~BS_3STATE;
  444. SendMessage (hControlWnd, EM_SETLIMITTEXT, atTextLimits[i].uiLimitText, MAKELPARAM(0, 0));
  445. }
  446. return MembersToControls();
  447. }
  448. BOOL TSConfigDlg::VerifyChanges ()
  449. {
  450. // do the necessary varification here.
  451. // if data entered is good return TRUE
  452. // otherwise display message and return FALSE
  453. TDialogData tTemp;
  454. return ControlsToMembers(&tTemp);
  455. }
  456. BOOL TSConfigDlg::ApplyChanges ()
  457. {
  458. ASSERT(VerifyChanges());
  459. // control to members fails if the data is controls is bad.
  460. // but since we have varified the changes before getting call to apply changes
  461. // it must pass.
  462. VERIFY( ControlsToMembers(&tDialogData) );
  463. SetUserInfo();
  464. return TRUE;
  465. }
  466. BOOL TSConfigDlg::MembersToControls ()
  467. {
  468. VERIFY( SetAllowLogon ( tDialogData._fAllowLogon ));
  469. VERIFY( SetConnectionTimeOut( tDialogData._ulConnection ));
  470. VERIFY( SetDisConnectionTimeOut( tDialogData._ulDisconnection ));
  471. VERIFY( SetIdleTimeOut( tDialogData._ulIdle ));
  472. VERIFY( SetCommandLineAndWorkingDirectory(tDialogData._fClientSpecified, tDialogData._nlsWorkingDirectory, tDialogData._nlsInitialProgram));
  473. VERIFY( SetSecurity(tDialogData._iEncryption, tDialogData._fDisableEncryption));
  474. VERIFY( SetBrokenConnectionOption(tDialogData._iBroken));
  475. VERIFY( SetReconnectDisconnection(tDialogData._iReconnect));
  476. VERIFY( SetCallBackOptonAndPhoneNumber(tDialogData._iCallback, tDialogData._nlsPhoneNumber));
  477. VERIFY( SetShadowing(tDialogData._iShadow));
  478. return TRUE;
  479. }
  480. BOOL TSConfigDlg::ControlsToMembers (TDialogData *pDlgData)
  481. {
  482. ASSERT(pDlgData);
  483. if ( !GetAllowLogon (&pDlgData->_fAllowLogon))
  484. return FALSE;
  485. if ( !GetConnectionTimeOut(&pDlgData->_ulConnection))
  486. return FALSE;
  487. if ( !GetDisConnectionTimeOut(&pDlgData->_ulDisconnection))
  488. return FALSE;
  489. if ( !GetIdleTimeOut(&pDlgData->_ulIdle))
  490. return FALSE;
  491. if ( !GetCommandLineAndWorkingDirectory(&pDlgData->_fClientSpecified, pDlgData->_nlsWorkingDirectory, pDlgData->_nlsInitialProgram))
  492. return FALSE;
  493. if ( !GetSecurity(&pDlgData->_iEncryption, &pDlgData->_fDisableEncryption))
  494. return FALSE;
  495. if ( !GetBrokenConnectionOption(&pDlgData->_iBroken))
  496. return FALSE;
  497. if ( !GetReconnectDisconnection(&pDlgData->_iReconnect))
  498. return FALSE;
  499. if ( !GetCallBackOptonAndPhoneNumber(&pDlgData->_iCallback, pDlgData->_nlsPhoneNumber))
  500. return FALSE;
  501. if ( !GetShadowing(&pDlgData->_iShadow))
  502. return FALSE;
  503. return TRUE;
  504. }
  505. BOOL TSConfigDlg::GetAllowLogon (BOOL *pbAllowLogon)
  506. {
  507. ASSERT(pbAllowLogon);
  508. *pbAllowLogon = IsChecked(IDC_UCE_ALLOWLOGON);
  509. return TRUE;
  510. }
  511. BOOL TSConfigDlg::SetAllowLogon (BOOL bAllowLogon)
  512. {
  513. SetCheck(IDC_UCE_ALLOWLOGON, bAllowLogon);
  514. return TRUE;
  515. }
  516. BOOL TSConfigDlg::GetConnectionTimeOut(ULONG *pValue)
  517. {
  518. ASSERT(pValue);
  519. BOOL bResult = FALSE;
  520. if (IsChecked(IDC_UCE_CONNECTION_NONE))
  521. {
  522. // maks_todo: assert that edit control is disabled.
  523. // maks_todo : assert that edit control has value == 0
  524. *pValue = 0;
  525. bResult = TRUE;
  526. }
  527. else
  528. {
  529. // last parameter tells if the value is signed or unsigned.
  530. // we ask it not to look for - sign.
  531. // maks_todo:BUT WE MAY WANT TO CHNAGE THIS
  532. *pValue = GetDlgItemInt(GetDlgHandle(), IDC_UCE_CONNECTION, &bResult, FALSE);
  533. if (!bResult || *pValue == 0 || *pValue > 71582)
  534. {
  535. MessageBox(GetDlgHandle(), _T("The Connection Timeout value must 1 to 71582 minutes. Check the 'No Timeout' if you wish to specify no connection timeout"), _T("Termainl Server Properties"), MB_OK);
  536. bResult = FALSE;
  537. }
  538. }
  539. // users talk in terms of mins.
  540. // we talk about msecs.
  541. *pValue = *pValue * TIME_RESOLUTION;
  542. return bResult;
  543. }
  544. BOOL TSConfigDlg::SetConnectionTimeOut(ULONG iValue)
  545. {
  546. // users talk in terms of mins.
  547. // we talk about msecs.
  548. iValue = iValue / TIME_RESOLUTION;
  549. SetCheck(IDC_UCE_CONNECTION_NONE, iValue == 0);
  550. EnableControl(IDC_UCE_CONNECTION, iValue != 0);
  551. SetDlgItemInt(GetDlgHandle(), IDC_UCE_CONNECTION, iValue, TRUE); // maks_todo : look into last param.
  552. return TRUE;
  553. }
  554. BOOL TSConfigDlg::GetDisConnectionTimeOut(ULONG *pValue)
  555. {
  556. ASSERT(pValue);
  557. BOOL bResult = FALSE;
  558. if (IsChecked(IDC_UCE_DISCONNECTION_NONE))
  559. {
  560. // maks_todo: assert that edit control is disabled.
  561. // maks_todo : assert that edit control has value == 0
  562. *pValue = 0;
  563. bResult = TRUE;
  564. }
  565. else
  566. {
  567. // last parameter tells if the value is signed or unsigned.
  568. // we ask it not to look for - sign.
  569. // maks_todo:BUT WE MAY WANT TO CHNAGE THIS
  570. *pValue = GetDlgItemInt(GetDlgHandle(), IDC_UCE_DISCONNECTION, &bResult, FALSE);
  571. if (!bResult || *pValue == 0 || *pValue > 71582)
  572. {
  573. MessageBox(GetDlgHandle(), _T("The Disconnection Timeout value must 1 to 71582 minutes. Check the 'No Timeout' if you wish to specify no Disconnection timeout"), _T("Termainl Server Properties"), MB_OK);
  574. bResult = FALSE;
  575. }
  576. }
  577. *pValue = *pValue * TIME_RESOLUTION;
  578. return bResult;
  579. }
  580. BOOL TSConfigDlg::SetDisConnectionTimeOut(ULONG iValue)
  581. {
  582. // users talk in terms of mins.
  583. // we talk about msecs.
  584. iValue = iValue / TIME_RESOLUTION;
  585. SetCheck(IDC_UCE_DISCONNECTION_NONE, iValue == 0);
  586. EnableControl(IDC_UCE_DISCONNECTION, iValue != 0);
  587. SetDlgItemInt(GetDlgHandle(), IDC_UCE_DISCONNECTION, iValue, TRUE); // maks_todo : look into last param.
  588. return TRUE;
  589. }
  590. BOOL TSConfigDlg::GetIdleTimeOut(ULONG *pValue)
  591. {
  592. ASSERT(pValue);
  593. BOOL bResult = FALSE;
  594. if (IsChecked(IDC_UCE_IDLE_NONE))
  595. {
  596. // maks_todo: assert that edit control is disabled.
  597. // maks_todo : assert that edit control has value == 0
  598. *pValue = 0;
  599. bResult = TRUE;
  600. }
  601. else
  602. {
  603. // last parameter tells if the value is signed or unsigned.
  604. // we ask it not to look for - sign.
  605. // maks_todo:BUT WE MAY WANT TO CHNAGE THIS
  606. *pValue = GetDlgItemInt(GetDlgHandle(), IDC_UCE_IDLE, &bResult, FALSE);
  607. if (!bResult || *pValue == 0 || *pValue > 71582)
  608. {
  609. MessageBox(GetDlgHandle(), _T("The Idle Timeout value must 1 to 71582 minutes. Check the 'No Timeout' if you wish to specify no Idle timeout"), _T("Termainl Server Properties"), MB_OK);
  610. bResult = FALSE;
  611. }
  612. }
  613. *pValue = *pValue * TIME_RESOLUTION;
  614. return bResult;
  615. }
  616. BOOL TSConfigDlg::SetIdleTimeOut(ULONG iValue)
  617. {
  618. // users talk in terms of mins.
  619. // we talk about msecs.
  620. iValue = iValue / TIME_RESOLUTION;
  621. SetCheck(IDC_UCE_IDLE_NONE, iValue == 0);
  622. EnableControl(IDC_UCE_IDLE, iValue != 0);
  623. SetDlgItemInt(GetDlgHandle(), IDC_UCE_IDLE, iValue, TRUE); // maks_todo : look into last param.
  624. return TRUE;
  625. }
  626. BOOL TSConfigDlg::SetCommandLineAndWorkingDirectory(BOOL bUserInherited, LPCTSTR dir, LPCTSTR cmd)
  627. {
  628. ASSERT(dir);
  629. ASSERT(cmd);
  630. if (bUserInherited)
  631. SetCheck(IDC_UCE_INITIALPROGRAM_INHERIT, bUserInherited);
  632. // enable/disable edits according to check box status.
  633. EnableControl(IDL_UCE_INITIALPROGRAM_COMMANDLINE1, !bUserInherited);
  634. EnableControl(IDL_UCE_INITIALPROGRAM_WORKINGDIRECTORY1, !bUserInherited);
  635. EnableControl(IDC_UCE_INITIALPROGRAM_COMMANDLINE, !bUserInherited);
  636. EnableControl(IDC_UCE_INITIALPROGRAM_WORKINGDIRECTORY, !bUserInherited);
  637. // set the text into edits.
  638. SetDlgItemText(GetDlgHandle(), IDC_UCE_INITIALPROGRAM_COMMANDLINE, cmd);
  639. SetDlgItemText(GetDlgHandle(), IDC_UCE_INITIALPROGRAM_WORKINGDIRECTORY, dir);
  640. return TRUE;
  641. }
  642. BOOL TSConfigDlg::GetCommandLineAndWorkingDirectory(BOOL *pbUserInherited, LPTSTR dir, LPTSTR cmd)
  643. {
  644. ASSERT(dir);
  645. ASSERT(cmd);
  646. *pbUserInherited = IsChecked(IDC_UCE_INITIALPROGRAM_INHERIT);
  647. // set the text into edits.
  648. GetDlgItemText(GetDlgHandle(), IDC_UCE_INITIALPROGRAM_COMMANDLINE, cmd, MAX_INIT_PROGRAM_SIZE);
  649. GetDlgItemText(GetDlgHandle(), IDC_UCE_INITIALPROGRAM_WORKINGDIRECTORY, dir, MAX_INIT_DIR_SIZE);
  650. return TRUE;
  651. }
  652. BOOL TSConfigDlg::SetSecurity(int iLevel, BOOL bDisableAfterLogon)
  653. {
  654. SetComboCurrentSel(IDC_UCE_SECURITY_ENCRYPT, iLevel);
  655. SetCheck(IDC_UCE_SECURITY_DISABLEAFTERLOGON, bDisableAfterLogon);
  656. return TRUE;
  657. }
  658. BOOL TSConfigDlg::GetSecurity(int *piLevel, BOOL *pbDisableAfterLogon)
  659. {
  660. ASSERT(piLevel);
  661. ASSERT(pbDisableAfterLogon);
  662. *piLevel = GetComboCurrentSel(IDC_UCE_SECURITY_ENCRYPT);
  663. *pbDisableAfterLogon = IsChecked(IDC_UCE_SECURITY_DISABLEAFTERLOGON);
  664. return TRUE;
  665. }
  666. BOOL TSConfigDlg::SetBrokenConnectionOption(int iLevel)
  667. {
  668. SetComboCurrentSel(IDC_UCE_BROKEN, iLevel);
  669. return TRUE;
  670. }
  671. BOOL TSConfigDlg::GetBrokenConnectionOption(int *piLevel)
  672. {
  673. *piLevel = GetComboCurrentSel(IDC_UCE_BROKEN);
  674. return TRUE;
  675. }
  676. BOOL TSConfigDlg::SetReconnectDisconnection(int iLevel)
  677. {
  678. SetComboCurrentSel(IDC_UCE_RECONNECT, iLevel);
  679. return TRUE;
  680. }
  681. BOOL TSConfigDlg::GetReconnectDisconnection(int *piLevel)
  682. {
  683. *piLevel = GetComboCurrentSel(IDC_UCE_RECONNECT);
  684. return TRUE;
  685. }
  686. BOOL TSConfigDlg::SetCallBackOptonAndPhoneNumber(int iCallBack, LPCTSTR PhoneNo)
  687. {
  688. SetComboCurrentSel(IDC_UCE_CALLBACK, iCallBack);
  689. SetDlgItemText(GetDlgHandle(), IDC_UCE_PHONENUMBER, PhoneNo);
  690. // enable/disable phone # accordingly.
  691. EnableControl(IDL_UCE_PHONENUMBER, iCallBack != 0);
  692. EnableControl(IDC_UCE_PHONENUMBER, iCallBack != 0);
  693. return TRUE;
  694. }
  695. BOOL TSConfigDlg::GetCallBackOptonAndPhoneNumber(int *piCallBack, LPTSTR PhoneNo)
  696. {
  697. *piCallBack = GetComboCurrentSel(IDC_UCE_CALLBACK);
  698. GetDlgItemText(GetDlgHandle(), IDC_UCE_PHONENUMBER, PhoneNo, MAX_PHONENO_SIZE);
  699. return TRUE;
  700. }
  701. BOOL TSConfigDlg::SetShadowing(int iLevel)
  702. {
  703. SetComboCurrentSel(IDC_UCE_SHADOW, iLevel);
  704. return TRUE;
  705. }
  706. BOOL TSConfigDlg::GetShadowing(int *piLevel)
  707. {
  708. *piLevel = GetComboCurrentSel(IDC_UCE_SHADOW);
  709. return TRUE;
  710. }
  711. // Utility function.
  712. DWORD wchar2TCHAR(TCHAR *dest, const WCHAR *src)
  713. {
  714. ASSERT(dest && src);
  715. #ifdef UNICODE
  716. _tcscpy(dest, src);
  717. #else
  718. DWORD count;
  719. count = WideCharToMultiByte(CP_ACP,
  720. 0,
  721. src,
  722. -1,
  723. NULL,
  724. 0,
  725. NULL,
  726. NULL);
  727. return WideCharToMultiByte(CP_ACP,
  728. 0,
  729. src,
  730. -1,
  731. dest,
  732. count,
  733. NULL,
  734. NULL);
  735. #endif
  736. return _tcslen(dest);
  737. }
  738. BOOL TSConfigDlg::ALLOWLOGONEvent(WORD wNotifyCode)
  739. {
  740. switch(wNotifyCode)
  741. {
  742. case BN_CLICKED:
  743. break;
  744. default:
  745. break;
  746. }
  747. return TRUE;
  748. }
  749. BOOL TSConfigDlg::CONNECTION_NONEEvent(WORD wNotifyCode)
  750. {
  751. switch(wNotifyCode)
  752. {
  753. case BN_CLICKED:
  754. EnableControl(IDC_UCE_CONNECTION, !IsChecked(IDC_UCE_CONNECTION_NONE));
  755. //EnableControl(IDC_UCE_CONNECTION, iValue != 0);
  756. break;
  757. default:
  758. break;
  759. }
  760. return TRUE;
  761. }
  762. BOOL TSConfigDlg::DISCONNECTION_NONEEvent(WORD wNotifyCode)
  763. {
  764. switch(wNotifyCode)
  765. {
  766. case BN_CLICKED:
  767. EnableControl(IDC_UCE_DISCONNECTION, !IsChecked(IDC_UCE_DISCONNECTION_NONE));
  768. break;
  769. default:
  770. break;
  771. }
  772. return TRUE;
  773. }
  774. BOOL TSConfigDlg::IDLE_NONEEvent(WORD wNotifyCode)
  775. {
  776. switch(wNotifyCode)
  777. {
  778. case BN_CLICKED:
  779. EnableControl(IDC_UCE_IDLE, !IsChecked(IDC_UCE_IDLE_NONE));
  780. break;
  781. default:
  782. break;
  783. }
  784. return TRUE;
  785. }
  786. BOOL TSConfigDlg::INITIALPROGRAM_INHERITEvent(WORD wNotifyCode)
  787. {
  788. switch(wNotifyCode)
  789. {
  790. case BN_CLICKED:
  791. EnableControl(IDL_UCE_INITIALPROGRAM_COMMANDLINE1,
  792. !IsChecked(IDC_UCE_INITIALPROGRAM_INHERIT));
  793. EnableControl(IDL_UCE_INITIALPROGRAM_WORKINGDIRECTORY1,
  794. !IsChecked(IDC_UCE_INITIALPROGRAM_INHERIT));
  795. EnableControl(IDC_UCE_INITIALPROGRAM_COMMANDLINE,
  796. !IsChecked(IDC_UCE_INITIALPROGRAM_INHERIT));
  797. EnableControl(IDC_UCE_INITIALPROGRAM_WORKINGDIRECTORY,
  798. !IsChecked(IDC_UCE_INITIALPROGRAM_INHERIT));
  799. break;
  800. default:
  801. break;
  802. }
  803. return TRUE;
  804. }
  805. BOOL TSConfigDlg::SECURITY_DISABLEAFTERLOGONEvent(WORD /* wNotifyCode */ )
  806. {
  807. return TRUE;
  808. }
  809. BOOL TSConfigDlg::IsChecked(UINT controlId)
  810. {
  811. ASSERT(GetDlgItem(GetDlgHandle(), controlId));
  812. return BST_CHECKED == SendDlgItemMessage(GetDlgHandle(), controlId, BM_GETCHECK, 0, 0);
  813. }
  814. void TSConfigDlg::SetCheck(UINT controlId, BOOL bCheck)
  815. {
  816. ASSERT(GetDlgItem(GetDlgHandle(), controlId));
  817. SendDlgItemMessage(GetDlgHandle(), controlId, BM_SETCHECK, bCheck ? BST_CHECKED : BST_UNCHECKED, 0);
  818. }
  819. void TSConfigDlg::EnableControl(UINT controlId, BOOL bEnable)
  820. {
  821. ASSERT(GetDlgItem(GetDlgHandle(), controlId));
  822. EnableWindow(GetDlgItem(GetDlgHandle(), controlId), bEnable);
  823. }
  824. int TSConfigDlg::GetComboCurrentSel(UINT controlId)
  825. {
  826. ASSERT(GetDlgItem(GetDlgHandle(), controlId));
  827. return SendDlgItemMessage(GetDlgHandle(), controlId, CB_GETCURSEL, 0, 0);
  828. }
  829. void TSConfigDlg::SetComboCurrentSel(UINT controlId, int iSel)
  830. {
  831. ASSERT(GetDlgItem(GetDlgHandle(), controlId));
  832. SendDlgItemMessage(GetDlgHandle(), controlId, CB_SETCURSEL, iSel, 0);
  833. }