Leaked source code of windows server 2003
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.

1080 lines
29 KiB

  1. /*
  2. File wizard.c
  3. Implementation of the incoming connections wizard.
  4. Paul Mayfield, 10/30/97
  5. */
  6. #include "rassrv.h"
  7. #include <tapi.h>
  8. // Help maps
  9. static const DWORD phmWizardDccdev[] =
  10. {
  11. CID_Wizard_Dccdev_LB_Devices, IDH_Wizard_Dccdev_LB_Devices,
  12. 0, 0
  13. };
  14. static const DWORD phmWizardVpn[] =
  15. {
  16. 0, 0
  17. };
  18. #define RASSRV_WIZTITLE_SIZE 256
  19. #define RASSRV_WIZSUBTITLE_SIZE 256
  20. // This structure let's us remember information needed
  21. // to keep our device data page in sync
  22. typedef struct _DCCDEV_DATA
  23. {
  24. HANDLE hDevice;
  25. BOOL bEnabled;
  26. } DCCDEV_DATA;
  27. //
  28. // This dialog proc implements the vpn tab on the incoming connections
  29. // wizard.
  30. //
  31. INT_PTR
  32. CALLBACK
  33. VpnWizDialogProc(
  34. HWND hwndDlg,
  35. UINT uMsg,
  36. WPARAM wParam,
  37. LPARAM lParam);
  38. //
  39. // Dialog procedure that handles the host dcc wizard device page
  40. //
  41. INT_PTR
  42. CALLBACK
  43. DccdevWizDialogProc(
  44. HWND hwndDlg,
  45. UINT uMsg,
  46. WPARAM wParam,
  47. LPARAM lParam);
  48. //
  49. // This dialog procedure responds to messages sent to the
  50. // switch to mmc wizard tab.
  51. //
  52. INT_PTR
  53. CALLBACK
  54. SwitchMmcWizDialogProc (
  55. HWND hwndDlg,
  56. UINT uMsg,
  57. WPARAM wParam,
  58. LPARAM lParam);
  59. //
  60. // Fills in the property sheet structure with the information required to
  61. // display the device tab in the incoming connections wizard.
  62. //
  63. DWORD
  64. DeviceWizGetPropertyPage(
  65. IN LPPROPSHEETPAGE ppage,
  66. IN LPARAM lpUserData)
  67. {
  68. LPCTSTR pszHeader, pszSubHeader;
  69. // Initialize
  70. ZeroMemory(ppage, sizeof(PROPSHEETPAGE));
  71. // Load the string resources
  72. pszHeader = PszLoadString(
  73. Globals.hInstDll,
  74. SID_WIZDEVICETITLE);
  75. pszSubHeader = PszLoadString(
  76. Globals.hInstDll,
  77. SID_WIZDEVICESUBTITLE);
  78. // The General Properties dialog procedure also implements the device
  79. // tab in the incoming connections wizard
  80. ppage->pfnDlgProc = GenTabDialogProc;
  81. // Fill in the values
  82. ppage->dwSize = sizeof(PROPSHEETPAGE);
  83. ppage->hInstance = Globals.hInstDll;
  84. ppage->pszTemplate = MAKEINTRESOURCE(PID_Wizard_GenTab);
  85. ppage->pfnCallback = RasSrvInitDestroyPropSheetCb;
  86. ppage->pszHeaderTitle = (PWCHAR)pszHeader;
  87. ppage->pszHeaderSubTitle = (PWCHAR)pszSubHeader;
  88. ppage->lParam = lpUserData;
  89. ppage->dwFlags = PSP_USEHEADERSUBTITLE |
  90. PSP_USEHEADERTITLE |
  91. PSP_USECALLBACK;
  92. return NO_ERROR;
  93. }
  94. //
  95. // Fills in the property sheet structure with the information required
  96. // to display the vpn tab in the incoming connections wizard.
  97. //
  98. DWORD
  99. VpnWizGetPropertyPage(
  100. IN LPPROPSHEETPAGE ppage,
  101. IN LPARAM lpUserData)
  102. {
  103. LPCTSTR pszHeader, pszSubHeader;
  104. // Initialize
  105. ZeroMemory(ppage, sizeof(PROPSHEETPAGE));
  106. // Load the string resources
  107. pszHeader = PszLoadString(
  108. Globals.hInstDll,
  109. SID_WIZVPNTITLE);
  110. pszSubHeader = PszLoadString(
  111. Globals.hInstDll,
  112. SID_WIZVPNSUBTITLE);
  113. // I could have used the general tab dialog procedure to implement the
  114. // vpn tab. The only problem is that the general tab has a single
  115. // check to enable vpn while the vpn tab in the wizard has a yes/no
  116. // radio check group. For this reason, I made the vpn tab its very
  117. // own dialog proc.
  118. ppage->pfnDlgProc = VpnWizDialogProc;
  119. // Fill in the values
  120. ppage->dwSize = sizeof(PROPSHEETPAGE);
  121. ppage->hInstance = Globals.hInstDll;
  122. ppage->pszTemplate = MAKEINTRESOURCE(PID_Wizard_Vpn);
  123. ppage->pfnCallback = RasSrvInitDestroyPropSheetCb;
  124. ppage->pszHeaderTitle = (PWCHAR)pszHeader;
  125. ppage->pszHeaderSubTitle = (PWCHAR)pszSubHeader;
  126. ppage->lParam = lpUserData;
  127. ppage->dwFlags = PSP_USEHEADERSUBTITLE |
  128. PSP_USEHEADERTITLE |
  129. PSP_USECALLBACK;
  130. return NO_ERROR;
  131. }
  132. //
  133. // Function fills in the given lpPage structure with the information needed
  134. // to run the user tab in the incoming connections wizard.
  135. //
  136. DWORD
  137. UserWizGetPropertyPage(
  138. IN LPPROPSHEETPAGE ppage,
  139. IN LPARAM lpUserData)
  140. {
  141. LPCTSTR pszHeader, pszSubHeader;
  142. // Initialize
  143. ZeroMemory(ppage, sizeof(PROPSHEETPAGE));
  144. // Load the string resources
  145. pszHeader = PszLoadString(Globals.hInstDll, SID_WIZUSERTITLE);
  146. pszSubHeader = PszLoadString(Globals.hInstDll, SID_WIZUSERSUBTITLE);
  147. // The User Properties dialog procedure also implements the user tab
  148. // in the incoming connections wizard
  149. ppage->pfnDlgProc = UserTabDialogProc;
  150. // Fill in the values
  151. ppage->dwSize = sizeof(PROPSHEETPAGE);
  152. ppage->hInstance = Globals.hInstDll;
  153. ppage->pszTemplate = MAKEINTRESOURCE(PID_Wizard_UserTab);
  154. ppage->pfnCallback = RasSrvInitDestroyPropSheetCb;
  155. ppage->pszHeaderTitle = (PWCHAR)pszHeader;
  156. ppage->pszHeaderSubTitle = (PWCHAR)pszSubHeader;
  157. ppage->lParam = lpUserData;
  158. ppage->dwFlags = PSP_USEHEADERSUBTITLE |
  159. PSP_USEHEADERTITLE |
  160. PSP_USECALLBACK;
  161. return NO_ERROR;
  162. }
  163. //
  164. // Fills a LPPROPSHEETPAGE structure with the information
  165. // needed to display the protocol tab in the incoming connections wizard.
  166. //
  167. DWORD
  168. ProtWizGetPropertyPage(
  169. IN LPPROPSHEETPAGE ppage,
  170. IN LPARAM lpUserData)
  171. {
  172. LPCTSTR pszHeader, pszSubHeader;
  173. // Initialize
  174. ZeroMemory(ppage, sizeof(PROPSHEETPAGE));
  175. // Load the string resources
  176. pszHeader = PszLoadString(Globals.hInstDll, SID_WIZPROTTITLE);
  177. pszSubHeader = PszLoadString(Globals.hInstDll, SID_WIZPROTSUBTITLE);
  178. // The Advanced Properties dialog procedure also implements the net tab
  179. // in the incoming connections wizard
  180. ppage->pfnDlgProc = NetTabDialogProc;
  181. // Fill in the values
  182. ppage->dwSize = sizeof(PROPSHEETPAGE);
  183. ppage->hInstance = Globals.hInstDll;
  184. ppage->pszTemplate = MAKEINTRESOURCE(PID_Wizard_NetTab);
  185. ppage->pfnCallback = RasSrvInitDestroyPropSheetCb;
  186. ppage->pszHeaderTitle = (PWCHAR)pszHeader;
  187. ppage->pszHeaderSubTitle = (PWCHAR)pszSubHeader;
  188. ppage->lParam = lpUserData;
  189. ppage->dwFlags = PSP_USEHEADERSUBTITLE |
  190. PSP_USEHEADERTITLE |
  191. PSP_USECALLBACK;
  192. return NO_ERROR;
  193. }
  194. //
  195. // Function fills in the given LPPROPSHEETPAGE structure with the info
  196. // needed to run the dcc device tab in the incoming connections wizard.
  197. //
  198. DWORD
  199. DccdevWizGetPropertyPage(
  200. IN LPPROPSHEETPAGE ppage,
  201. IN LPARAM lpUserData)
  202. {
  203. LPCTSTR pszHeader, pszSubHeader;
  204. // Initialize
  205. ZeroMemory(ppage, sizeof(PROPSHEETPAGE));
  206. // Load the string resources
  207. pszHeader = PszLoadString(Globals.hInstDll, SID_WIZDCCDEVTITLE);
  208. pszSubHeader = PszLoadString(Globals.hInstDll, SID_WIZDCCDEVSUBTITLE);
  209. // The Advanced Properties dialog procedure also implements the protocol
  210. // tab in the incoming connections wizard
  211. ppage->pfnDlgProc = DccdevWizDialogProc;
  212. // Fill in the values
  213. ppage->dwSize = sizeof(PROPSHEETPAGE);
  214. ppage->hInstance = Globals.hInstDll;
  215. ppage->pszTemplate = MAKEINTRESOURCE(PID_Wizard_Dccdev);
  216. ppage->pfnCallback = RasSrvInitDestroyPropSheetCb;
  217. ppage->pszHeaderTitle = (PWCHAR)pszHeader;
  218. ppage->pszHeaderSubTitle = (PWCHAR)pszSubHeader;
  219. ppage->lParam = lpUserData;
  220. ppage->dwFlags = PSP_USEHEADERSUBTITLE |
  221. PSP_USEHEADERTITLE |
  222. PSP_USECALLBACK;
  223. return NO_ERROR;
  224. }
  225. //
  226. // Function fills in the given LPPROPSHEETPAGE structure with the
  227. // information needed to run the dummy wizard page that switches to mmc.
  228. //
  229. DWORD
  230. SwitchMmcWizGetProptertyPage (
  231. IN LPPROPSHEETPAGE ppage,
  232. IN LPARAM lpUserData)
  233. {
  234. // Initialize
  235. ZeroMemory(ppage, sizeof(PROPSHEETPAGE));
  236. // The Advanced Properties dialog procedure also implements
  237. // the protocol tab in the incoming connections wizard
  238. ppage->pfnDlgProc = SwitchMmcWizDialogProc;
  239. // Fill in the values
  240. ppage->dwSize = sizeof(PROPSHEETPAGE);
  241. ppage->hInstance = Globals.hInstDll;
  242. ppage->pszTemplate = MAKEINTRESOURCE(PID_Wizard_SwitchMmc);
  243. ppage->pfnCallback = RasSrvInitDestroyPropSheetCb;
  244. ppage->lParam = lpUserData;
  245. ppage->dwFlags = PSP_USEHEADERSUBTITLE |
  246. PSP_USEHEADERTITLE |
  247. PSP_USECALLBACK;
  248. return NO_ERROR;
  249. }
  250. //
  251. // Initializes the vpn wizard tab.
  252. //
  253. DWORD
  254. VpnWizInitializeDialog(
  255. IN HWND hwndDlg,
  256. IN WPARAM wParam)
  257. {
  258. DWORD dwErr;
  259. BOOL bFlag;
  260. HANDLE hDevDatabase = NULL;
  261. // Get handles to the databases we're interested in
  262. RasSrvGetDatabaseHandle(hwndDlg, ID_DEVICE_DATABASE, &hDevDatabase);
  263. // Initialize the vpn check
  264. dwErr = devGetVpnEnable(hDevDatabase, &bFlag);
  265. if (dwErr != NO_ERROR)
  266. {
  267. ErrDisplayError(
  268. hwndDlg,
  269. ERR_DEVICE_DATABASE_CORRUPT,
  270. ERR_GENERALTAB_CATAGORY,
  271. 0,
  272. Globals.dwErrorData);
  273. return dwErr;
  274. }
  275. SendMessage(GetDlgItem(hwndDlg, CID_Wizard_Vpn_RB_Yes),
  276. BM_SETCHECK,
  277. (bFlag) ? BST_CHECKED : BST_UNCHECKED,
  278. 0);
  279. SendMessage(GetDlgItem(hwndDlg, CID_Wizard_Vpn_RB_No),
  280. BM_SETCHECK,
  281. (!bFlag) ? BST_CHECKED : BST_UNCHECKED,
  282. 0);
  283. return NO_ERROR;
  284. }
  285. //
  286. // Handles cancel button being pressed for the vpn wizard page
  287. //
  288. DWORD
  289. VpnWizCancelEdit(
  290. IN HWND hwndDlg,
  291. IN NMHDR* pNotifyData)
  292. {
  293. HANDLE hDevDatabase = NULL;
  294. DWORD dwErr;
  295. DbgOutputTrace("Rolling back vpn wizard tab.");
  296. // Cancel flush of database
  297. RasSrvGetDatabaseHandle(hwndDlg, ID_DEVICE_DATABASE, &hDevDatabase);
  298. dwErr = devRollbackDatabase(hDevDatabase);
  299. if (dwErr != NO_ERROR)
  300. {
  301. ErrDisplayError(
  302. hwndDlg,
  303. ERR_GENERAL_CANT_ROLLBACK_CHANGES,
  304. ERR_GENERALTAB_CATAGORY,
  305. 0,
  306. Globals.dwErrorData);
  307. }
  308. return NO_ERROR;
  309. }
  310. //
  311. // Handles having the vpn wizard come active
  312. //
  313. DWORD
  314. VpnWizSetActive (
  315. IN HWND hwndDlg,
  316. IN WPARAM wParam,
  317. IN LPARAM lParam)
  318. {
  319. PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_NEXT | PSWIZB_BACK);
  320. return NO_ERROR;
  321. }
  322. //
  323. // Handles vpn loose activation messages
  324. //
  325. DWORD
  326. VpnWizKillActive (
  327. IN HWND hwndDlg,
  328. IN WPARAM wParam,
  329. IN LPARAM lParam)
  330. {
  331. HANDLE hDevDatabase = NULL;
  332. BOOL bEnable;
  333. //For Whistler bug#123769
  334. //In order to let the SetPortMapping commit
  335. //when creating a new IC connection, we set
  336. //the fVpnEnabledOrig to be different from
  337. // the fVpnEnable
  338. //
  339. RasSrvGetDatabaseHandle(hwndDlg, ID_DEVICE_DATABASE, &hDevDatabase);
  340. bEnable = IsDlgButtonChecked( hwndDlg, CID_Wizard_Vpn_RB_Yes );
  341. devSetVpnOrigEnable(hDevDatabase, !bEnable);
  342. return NO_ERROR;
  343. }
  344. //
  345. // Processes command messages for the vpn wizard page
  346. //
  347. DWORD
  348. VpnWizCommand(
  349. IN HWND hwndDlg,
  350. IN WPARAM wParam,
  351. IN LPARAM lParam)
  352. {
  353. HANDLE hDevDatabase = NULL;
  354. BOOL bEnable;
  355. RasSrvGetDatabaseHandle(hwndDlg, ID_DEVICE_DATABASE, &hDevDatabase);
  356. if (wParam == CID_Wizard_Vpn_RB_Yes || wParam == CID_Wizard_Vpn_RB_No)
  357. {
  358. HWND hwndVPNRB = GetDlgItem(hwndDlg, CID_Wizard_Vpn_RB_Yes);
  359. if (hwndVPNRB)
  360. {
  361. bEnable = (BOOL) SendMessage(
  362. hwndVPNRB,
  363. BM_GETCHECK,
  364. 0,
  365. 0);
  366. }
  367. devSetVpnEnable(hDevDatabase, bEnable);
  368. }
  369. return NO_ERROR;
  370. }
  371. //
  372. // This dialog procedure responds to messages sent to the
  373. // vpn wizard tab.
  374. //
  375. INT_PTR CALLBACK
  376. VpnWizDialogProc(
  377. IN HWND hwndDlg,
  378. IN UINT uMsg,
  379. IN WPARAM wParam,
  380. IN LPARAM lParam)
  381. {
  382. // Filter the customized ras server ui page messages. By filtering
  383. // messages through here, we are able to call RasSrvGetDatabaseHandle
  384. // below
  385. if (RasSrvMessageFilter(hwndDlg, uMsg, wParam, lParam))
  386. return TRUE;
  387. // Process other messages as normal
  388. switch (uMsg)
  389. {
  390. case WM_INITDIALOG:
  391. // For whislter bug 417039 gangz
  392. // Firewall is taken out of 64bit build or server build
  393. //
  394. if( !IsFirewallAvailablePlatform() )
  395. {
  396. ShowWindow(GetDlgItem(hwndDlg,CID_Wizard_Vpn_ST_Firewall),
  397. SW_HIDE);
  398. }
  399. return FALSE;
  400. break;
  401. case WM_NOTIFY:
  402. switch (((NMHDR*)lParam)->code)
  403. {
  404. case PSN_RESET:
  405. VpnWizCancelEdit(hwndDlg, (NMHDR*)lParam);
  406. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, FALSE);
  407. break;
  408. case PSN_SETACTIVE:
  409. if (! GetWindowLongPtr(hwndDlg, GWLP_USERDATA))
  410. {
  411. VpnWizInitializeDialog(hwndDlg, wParam);
  412. SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 1);
  413. }
  414. VpnWizSetActive (hwndDlg, wParam, lParam);
  415. break;
  416. case PSN_KILLACTIVE:
  417. VpnWizKillActive (hwndDlg, wParam, lParam);
  418. break;
  419. }
  420. case WM_COMMAND:
  421. VpnWizCommand(hwndDlg, wParam, lParam);
  422. break;
  423. }
  424. return FALSE;
  425. }
  426. // Fill the device combo box
  427. DWORD
  428. DccdevFillDeviceList(
  429. IN HWND hwndDlg,
  430. IN HANDLE hDevDatabase,
  431. IN HANDLE hDevSelect)
  432. {
  433. HWND hwndCb = GetDlgItem(hwndDlg, CID_Wizard_Dccdev_LB_Devices);
  434. DWORD dwCount, dwIndex, dwErr, i, j=0, dwSelect = 0;
  435. HANDLE hDevice;
  436. PWCHAR pszName = NULL;
  437. if (hwndCb)
  438. {
  439. // Delete anything that was in the combo box
  440. SendMessage(hwndCb, CB_RESETCONTENT, 0, 0);
  441. }
  442. // Get the count of devices
  443. if ((dwErr = devGetDeviceCount(hDevDatabase, &dwCount)) != NO_ERROR)
  444. {
  445. return dwErr;
  446. }
  447. // Add them to the device combo box
  448. for (i = 0; i < dwCount; i++)
  449. {
  450. // If the device wasn't filtered out, add it to the combo
  451. // box and remember its handle
  452. dwErr = devGetDeviceHandle(hDevDatabase, i, &hDevice);
  453. if (dwErr == NO_ERROR)
  454. {
  455. // For .Net 499405
  456. // If the device is already enabled, disable it first,
  457. // this device was not disabled when deleting the Incoming Connection
  458. //
  459. BOOL fEnabled = FALSE;
  460. dwErr = devGetDeviceEnable( hDevice, &fEnabled );
  461. if( NO_ERROR == dwErr )
  462. {
  463. if( fEnabled )
  464. {
  465. devSetDeviceEnable( hDevice, FALSE);
  466. }
  467. }
  468. devGetDeviceName (hDevice, &pszName);
  469. dwIndex = (DWORD) SendMessage (
  470. hwndCb,
  471. CB_ADDSTRING,
  472. 0,
  473. (LPARAM)pszName);
  474. SendMessage (
  475. hwndCb,
  476. CB_SETITEMDATA,
  477. dwIndex,
  478. (LPARAM)hDevice);
  479. // If this is the device to select, remember that fact
  480. if (hDevice == hDevSelect)
  481. {
  482. dwSelect = j;
  483. }
  484. j++;
  485. }
  486. }
  487. ComboBox_SetCurSel(hwndCb, dwSelect);
  488. return NO_ERROR;
  489. }
  490. //
  491. // Initializes the dcc device wizard tab.
  492. //
  493. DWORD
  494. DccdevWizInitializeDialog(
  495. IN HWND hwndDlg,
  496. IN WPARAM wParam)
  497. {
  498. HANDLE hDevDatabase = NULL, hDevice = NULL;
  499. DWORD dwStatus, dwErr, dwCount, i;
  500. BOOL bEnabled;
  501. DCCDEV_DATA * pDcData;
  502. // Whenever the dcc device page is left, the currently selected device
  503. // is remembered and its original enabling is recorded. Then this device
  504. // is set to enabled. Whenever the page is activated, the remembered
  505. // device is restored to its original enabling state if it is still
  506. // enabled.
  507. //
  508. // This whole process is a little confusing, but it ensures that the dcc
  509. // device page will interact correctly when the user goes down the dcc
  510. // path and then the incoming path and back and forth.
  511. //
  512. if ((pDcData = RassrvAlloc (sizeof(DCCDEV_DATA), TRUE)) == NULL)
  513. {
  514. return ERROR_NOT_ENOUGH_MEMORY;
  515. }
  516. // Get handles to the databases we're interested in
  517. RasSrvGetDatabaseHandle(hwndDlg, ID_DEVICE_DATABASE, &hDevDatabase);
  518. // Add the com ports as devices and filter out all non dcc
  519. // devices from the device database
  520. devFilterDevices(hDevDatabase, INCOMING_TYPE_DIRECT);
  521. devAddComPorts(hDevDatabase);
  522. // Get the count of devices
  523. if ((dwErr = devGetDeviceCount(hDevDatabase, &dwCount)) != NO_ERROR)
  524. {
  525. return dwErr;
  526. }
  527. // Get the handle to the first device if any
  528. for (i = 0; i < dwCount; i++)
  529. {
  530. if (devGetDeviceHandle (hDevDatabase, i, &hDevice) == NO_ERROR)
  531. {
  532. break;
  533. }
  534. }
  535. // Record the device's enabling -- index is 0 (default)
  536. if (hDevice)
  537. {
  538. dwErr = devGetDeviceEnable (hDevice, &(pDcData->bEnabled));
  539. if (dwErr != NO_ERROR)
  540. {
  541. return dwErr;
  542. }
  543. pDcData->hDevice = hDevice;
  544. }
  545. // Record the status bits
  546. SetWindowLongPtr (hwndDlg, GWLP_USERDATA, (LONG_PTR)pDcData);
  547. return NO_ERROR;
  548. }
  549. //
  550. // Cleans up the dcc device wizard
  551. //
  552. DWORD
  553. DccdevWizCleanupDialog(
  554. IN HWND hwndDlg,
  555. IN WPARAM wParam,
  556. IN LPARAM lParam)
  557. {
  558. DCCDEV_DATA * pDcData =
  559. (DCCDEV_DATA *) GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
  560. if (pDcData)
  561. {
  562. RassrvFree (pDcData);
  563. }
  564. return NO_ERROR;
  565. }
  566. //
  567. // Called to do any processing when the dcc wizard device page is
  568. // gaining focus
  569. //
  570. DWORD
  571. DccdevWizSetActive (
  572. IN HWND hwndDlg,
  573. IN WPARAM wParam,
  574. IN LPARAM lParam)
  575. {
  576. HANDLE hDevDatabase = NULL;
  577. BOOL bEnabled;
  578. DCCDEV_DATA * pDcData;
  579. // Whenever the page is activated, the remembered device
  580. // is restored to its original enabling state if it is still enabled.
  581. pDcData = (DCCDEV_DATA*) GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
  582. if (pDcData && pDcData->hDevice)
  583. {
  584. if (devGetDeviceEnable (pDcData->hDevice, &bEnabled) == NO_ERROR)
  585. {
  586. if (bEnabled)
  587. {
  588. devSetDeviceEnable (pDcData->hDevice, pDcData->bEnabled);
  589. }
  590. }
  591. }
  592. // Get handles to the databases we're interested in
  593. RasSrvGetDatabaseHandle (hwndDlg, ID_DEVICE_DATABASE, &hDevDatabase);
  594. // Fill the device combo box
  595. DccdevFillDeviceList (
  596. hwndDlg,
  597. hDevDatabase,
  598. (pDcData) ? pDcData->hDevice : NULL);
  599. PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_NEXT | PSWIZB_BACK);
  600. return NO_ERROR;
  601. }
  602. //
  603. // Called to do any processing when the dcc wizard device
  604. // page is loosing focus
  605. //
  606. DWORD
  607. DccdevWizKillActive (
  608. IN HWND hwndDlg,
  609. IN WPARAM wParam,
  610. IN LPARAM lParam)
  611. {
  612. HANDLE hDevDatabase = NULL, hDevice = NULL;
  613. DCCDEV_DATA * pDcData;
  614. INT iCurSel = -1;
  615. HWND hwndCb = GetDlgItem (hwndDlg, CID_Wizard_Dccdev_LB_Devices);
  616. DWORD dwErr;
  617. // Whenever the dcc device page is left, the currently selected
  618. // device is remembered and its original enabling is recorded.
  619. // Then this device is set to enabled.
  620. pDcData = (DCCDEV_DATA*) GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
  621. if (pDcData)
  622. {
  623. if (hwndCb)
  624. {
  625. iCurSel = ComboBox_GetCurSel(hwndCb);
  626. }
  627. if (iCurSel != -1)
  628. {
  629. if (hwndCb)
  630. {
  631. hDevice = (HANDLE) ComboBox_GetItemData(hwndCb, iCurSel);
  632. }
  633. dwErr = devGetDeviceEnable (hDevice, &(pDcData->bEnabled));
  634. if (dwErr == NO_ERROR)
  635. {
  636. pDcData->hDevice = hDevice;
  637. devSetDeviceEnable (hDevice, TRUE);
  638. }
  639. }
  640. else
  641. {
  642. pDcData->hDevice = NULL;
  643. }
  644. }
  645. // Get handles to the databases we're interested in
  646. RasSrvGetDatabaseHandle(
  647. hwndDlg,
  648. ID_DEVICE_DATABASE,
  649. &hDevDatabase);
  650. // Undo the filter so that other pages aren't affected
  651. //devFilterDevices(
  652. // hDevDatabase,
  653. // 0xffffffff);
  654. return NO_ERROR;
  655. }
  656. //
  657. // Called to cancel the edit operation on the dcc host
  658. // device wizard tab.
  659. //
  660. DWORD
  661. DccdevWizCancelEdit(
  662. IN HWND hwndDlg,
  663. IN NMHDR* pNotifyData)
  664. {
  665. HANDLE hDevDatabase = NULL;
  666. DWORD dwErr;
  667. DbgOutputTrace("Rolling back dcc device wizard tab.");
  668. // Cancel the commit on the device database
  669. RasSrvGetDatabaseHandle(
  670. hwndDlg,
  671. ID_DEVICE_DATABASE,
  672. &hDevDatabase);
  673. dwErr = devRollbackDatabase(hDevDatabase);
  674. if (dwErr != NO_ERROR)
  675. {
  676. ErrDisplayError(
  677. hwndDlg,
  678. ERR_GENERAL_CANT_ROLLBACK_CHANGES,
  679. ERR_GENERALTAB_CATAGORY,
  680. 0,
  681. Globals.dwErrorData);
  682. }
  683. return NO_ERROR;
  684. }
  685. //
  686. // Raises properties for a component
  687. //
  688. DWORD
  689. DccdevWizRaiseProperties (
  690. IN HWND hwndDlg,
  691. IN HWND hwndLb,
  692. IN INT iItem)
  693. {
  694. HANDLE hDevice;
  695. DWORD dwErr = NO_ERROR, dwId;
  696. MSGARGS MsgArgs;
  697. BOOL bIsComPort = FALSE;
  698. // Get a handle to the device
  699. hDevice = (HANDLE) ComboBox_GetItemData(hwndLb, iItem);
  700. if (hDevice == NULL)
  701. {
  702. return ERROR_CAN_NOT_COMPLETE;
  703. }
  704. // Find out if the device is a com port which has not yet had a
  705. // null modem installed.
  706. //
  707. dwErr = devDeviceIsComPort(hDevice, &bIsComPort);
  708. if (dwErr != NO_ERROR)
  709. {
  710. return ERROR_CAN_NOT_COMPLETE;
  711. }
  712. // If so, popup info to the user explaining
  713. // the situation.
  714. //
  715. if (bIsComPort)
  716. {
  717. ZeroMemory(&MsgArgs, sizeof(MsgArgs));
  718. MsgArgs.dwFlags = MB_OK | MB_ICONINFORMATION;
  719. MsgDlgUtil(
  720. hwndDlg,
  721. SID_COM_PORT_NOT_ENABLED,
  722. &MsgArgs,
  723. Globals.hInstDll,
  724. SID_DEFAULT_MSG_TITLE);
  725. return NO_ERROR;
  726. }
  727. // Get the tapi id of the device
  728. if (devGetDeviceId(hDevice, &dwId) != NO_ERROR)
  729. {
  730. return ERROR_CAN_NOT_COMPLETE;
  731. }
  732. // Launch the device properties dialog
  733. dwErr = lineConfigDialogW(dwId, hwndDlg, NULL);
  734. if (dwErr == LINEERR_OPERATIONUNAVAIL)
  735. {
  736. ErrDisplayError(
  737. hwndDlg,
  738. ERR_DEVICE_HAS_NO_CONFIG,
  739. ERR_GENERALTAB_CATAGORY,
  740. 0,
  741. Globals.dwErrorData);
  742. dwErr = NO_ERROR;
  743. }
  744. return dwErr;
  745. }
  746. //
  747. // Called when "iItem" is being selected to enable or disable the
  748. // properties button.
  749. //
  750. DWORD
  751. DccdevWizEnableDisableProperties(
  752. IN HWND hwndDlg,
  753. IN HWND hwndLb,
  754. IN INT iItem)
  755. {
  756. return NO_ERROR;
  757. }
  758. //
  759. // Called to cancel the edit operation on the dcc host
  760. // device wizard tab.
  761. //
  762. DWORD
  763. DccdevWizCommand(
  764. HWND hwndDlg,
  765. WPARAM wParam,
  766. LPARAM lParam)
  767. {
  768. switch (LOWORD(wParam))
  769. {
  770. case CID_Dccdev_PB_Properties:
  771. {
  772. HWND hwndLb;
  773. hwndLb = GetDlgItem(hwndDlg, CID_Wizard_Dccdev_LB_Devices);
  774. if (hwndLb)
  775. {
  776. DccdevWizRaiseProperties(
  777. hwndDlg,
  778. hwndLb,
  779. ComboBox_GetCurSel(hwndLb));
  780. }
  781. }
  782. break;
  783. case CID_Wizard_Dccdev_LB_Devices:
  784. {
  785. if (HIWORD(wParam) == CBN_SELCHANGE)
  786. {
  787. DccdevWizEnableDisableProperties(
  788. hwndDlg,
  789. (HWND)lParam,
  790. ComboBox_GetCurSel((HWND)lParam));
  791. }
  792. }
  793. break;
  794. }
  795. return NO_ERROR;
  796. }
  797. INT_PTR
  798. CALLBACK
  799. DccdevWizDialogProc(
  800. IN HWND hwndDlg,
  801. IN UINT uMsg,
  802. IN WPARAM wParam,
  803. IN LPARAM lParam)
  804. {
  805. // Filter the customized ras server ui page
  806. // messages. By filtering messages through
  807. // here, we are able to call RasSrvGetDatabaseHandle
  808. // below
  809. if (RasSrvMessageFilter(hwndDlg, uMsg, wParam, lParam))
  810. return TRUE;
  811. // Process other messages as normal
  812. switch (uMsg)
  813. {
  814. case WM_INITDIALOG:
  815. return FALSE;
  816. case WM_NOTIFY:
  817. switch (((NMHDR*)lParam)->code)
  818. {
  819. case PSN_RESET:
  820. DccdevWizCancelEdit(hwndDlg, (NMHDR*)lParam);
  821. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, FALSE);
  822. break;
  823. case PSN_SETACTIVE:
  824. {
  825. DWORD dwErr;
  826. if (! GetWindowLongPtr(hwndDlg, GWLP_USERDATA))
  827. {
  828. DccdevWizInitializeDialog(hwndDlg, wParam);
  829. }
  830. dwErr = DccdevWizSetActive (
  831. hwndDlg,
  832. wParam,
  833. lParam);
  834. if (dwErr != NO_ERROR)
  835. {
  836. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, -1);
  837. }
  838. }
  839. break;
  840. case PSN_KILLACTIVE:
  841. DccdevWizKillActive (hwndDlg, wParam, lParam);
  842. break;
  843. }
  844. break;//for bug 187918
  845. case WM_COMMAND:
  846. DccdevWizCommand(hwndDlg, wParam, lParam);
  847. break;
  848. case WM_DESTROY:
  849. DccdevWizCleanupDialog(hwndDlg, wParam, lParam);
  850. break;
  851. }
  852. return FALSE;
  853. }
  854. //
  855. // Handles the activation of the switch to mmc wizard page.
  856. //
  857. DWORD
  858. SwitchMmcWizSetActive (
  859. IN HWND hwndDlg,
  860. IN WPARAM wParam,
  861. IN LPARAM lParam)
  862. {
  863. PWCHAR pszTitle;
  864. PWCHAR pszMessage;
  865. INT iRet;
  866. // Load the messages to display
  867. pszTitle = (PWCHAR)
  868. PszLoadString(Globals.hInstDll, WRN_WIZARD_NOT_ALLOWED_TITLE);
  869. pszMessage = (PWCHAR)
  870. PszLoadString(Globals.hInstDll, WRN_WIZARD_NOT_ALLOWED_MSG);
  871. iRet = MessageBox (
  872. hwndDlg,
  873. pszMessage,
  874. pszTitle,
  875. MB_YESNO | MB_ICONINFORMATION);
  876. if (iRet == 0)
  877. {
  878. return ERROR_NOT_ENOUGH_MEMORY;
  879. }
  880. // If yes was pressed, switch to mpradmin snapin.
  881. if (iRet == IDYES)
  882. {
  883. RasSrvLeaveServiceRunning (hwndDlg);
  884. PropSheet_PressButton (GetParent (hwndDlg), PSBTN_CANCEL);
  885. RassrvLaunchMMC (RASSRVUI_MPRCONSOLE);
  886. }
  887. // Otherwise, display the welcome page
  888. else if (iRet == IDNO)
  889. {
  890. PropSheet_PressButton (GetParent (hwndDlg), PSBTN_BACK);
  891. }
  892. // No matter what, don't accept activation
  893. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, -1);
  894. return NO_ERROR;
  895. }
  896. // This dialog procedure responds to messages sent to the
  897. // switch to mmc wizard tab.
  898. INT_PTR
  899. CALLBACK
  900. SwitchMmcWizDialogProc (
  901. HWND hwndDlg,
  902. UINT uMsg,
  903. WPARAM wParam,
  904. LPARAM lParam)
  905. {
  906. // Filter the customized ras server ui page messages. By filtering
  907. // messages through here, we are able to call RasSrvGetDatabaseHandle
  908. // below
  909. if (RasSrvMessageFilter(hwndDlg, uMsg, wParam, lParam))
  910. return TRUE;
  911. // Process other messages as normal
  912. switch (uMsg)
  913. {
  914. case WM_NOTIFY:
  915. switch (((NMHDR*)lParam)->code)
  916. {
  917. case PSN_SETACTIVE:
  918. return SwitchMmcWizSetActive (hwndDlg, wParam, lParam);
  919. break;
  920. }
  921. break;
  922. }
  923. return FALSE;
  924. }