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.

1065 lines
23 KiB

  1. /*
  2. File rassrvui.c
  3. Entry point implementation for the connections dialup server ui dll.
  4. Paul Mayfield, 9/29/97
  5. Much code was borrowed from stevec's rasdlg.
  6. */
  7. #include "rassrv.h"
  8. //
  9. // Called to add property pages for the dialup server property sheet
  10. //
  11. DWORD
  12. RasSrvAddPropPage(
  13. IN LPPROPSHEETPAGE lpPage,
  14. IN RASSRV_PAGE_CONTEXT * pPageData)
  15. {
  16. DWORD dwErr = ERROR_UNKNOWN_PROPERTY;
  17. switch(pPageData->dwId)
  18. {
  19. case RASSRVUI_GENERAL_TAB:
  20. dwErr = GenTabGetPropertyPage (lpPage, (LPARAM)pPageData);
  21. break;
  22. case RASSRVUI_USER_TAB:
  23. dwErr = UserTabGetPropertyPage (lpPage, (LPARAM)pPageData);
  24. break;
  25. case RASSRVUI_ADVANCED_TAB:
  26. dwErr = NetTabGetPropertyPage (lpPage, (LPARAM)pPageData);
  27. break;
  28. case RASSRVUI_DEVICE_WIZ_TAB:
  29. dwErr = DeviceWizGetPropertyPage (lpPage, (LPARAM)pPageData);
  30. break;
  31. case RASSRVUI_VPN_WIZ_TAB:
  32. dwErr = VpnWizGetPropertyPage (lpPage, (LPARAM)pPageData);
  33. break;
  34. case RASSRVUI_USER_WIZ_TAB:
  35. dwErr = UserWizGetPropertyPage (lpPage, (LPARAM)pPageData);
  36. break;
  37. case RASSRVUI_PROT_WIZ_TAB:
  38. dwErr = ProtWizGetPropertyPage (lpPage, (LPARAM)pPageData);
  39. break;
  40. case RASSRVUI_DCC_DEVICE_WIZ_TAB:
  41. dwErr = DccdevWizGetPropertyPage (lpPage, (LPARAM)pPageData);
  42. break;
  43. case RASSRVUI_SWITCHMMC_WIZ_TAB:
  44. dwErr = SwitchMmcWizGetProptertyPage (lpPage, (LPARAM)pPageData);
  45. break;
  46. }
  47. return dwErr;
  48. }
  49. //
  50. // Helper function might make code easier to read.
  51. //
  52. DWORD
  53. AddPageHelper (
  54. IN DWORD dwPageId,
  55. IN DWORD dwType,
  56. IN PVOID pvContext,
  57. IN LPFNADDPROPSHEETPAGE pfnAddPage,
  58. IN LPARAM lParam)
  59. {
  60. DWORD dwErr;
  61. HPROPSHEETPAGE hPropPage;
  62. PROPSHEETPAGE PropPage;
  63. RASSRV_PAGE_CONTEXT * pPageCtx = NULL;
  64. // Initialize the page data to send. RassrvMessageFilter will
  65. // clean this stuff up.
  66. pPageCtx = RassrvAlloc(sizeof (RASSRV_PAGE_CONTEXT), TRUE);
  67. if (pPageCtx == NULL)
  68. {
  69. return ERROR_NOT_ENOUGH_MEMORY;
  70. }
  71. pPageCtx->dwId = dwPageId;
  72. pPageCtx->dwType = dwType;
  73. pPageCtx->pvContext = pvContext;
  74. // Create the tab and add it to the property sheet
  75. if ((dwErr = RasSrvAddPropPage(&PropPage, pPageCtx)) != NO_ERROR)
  76. {
  77. return dwErr;
  78. }
  79. if ((hPropPage = CreatePropertySheetPage(&PropPage)) == NULL)
  80. {
  81. return ERROR_CAN_NOT_COMPLETE;
  82. }
  83. if (! (*pfnAddPage)(hPropPage, lParam))
  84. {
  85. return ERROR_CAN_NOT_COMPLETE;
  86. }
  87. return NO_ERROR;
  88. }
  89. //
  90. // Helper function generates a connection name based on the data
  91. // returned from MprApi calls.
  92. //
  93. DWORD
  94. GenerateConnectionName(
  95. IN RAS_CONNECTION_2 * pConn,
  96. OUT PWCHAR pszNameBuffer)
  97. {
  98. NET_API_STATUS nStatus;
  99. USER_INFO_2 * pUserInfo;
  100. DWORD dwFullNameLength;
  101. // Get the full name
  102. nStatus = NetUserGetInfo(
  103. NULL,
  104. pConn->wszUserName,
  105. 2,
  106. (LPBYTE*)&pUserInfo);
  107. if (nStatus == NERR_Success)
  108. {
  109. dwFullNameLength = wcslen(pUserInfo->usri2_full_name);
  110. if (dwFullNameLength)
  111. {
  112. wsprintfW(
  113. pszNameBuffer,
  114. L"%s (%s)",
  115. pConn->wszUserName,
  116. pUserInfo->usri2_full_name);
  117. }
  118. else
  119. {
  120. lstrcpynW(
  121. pszNameBuffer,
  122. pConn->wszUserName,
  123. sizeof(pConn->wszUserName) / sizeof(WCHAR));
  124. }
  125. NetApiBufferFree((LPBYTE)pUserInfo);
  126. }
  127. else
  128. {
  129. lstrcpynW(
  130. pszNameBuffer,
  131. pConn->wszUserName,
  132. sizeof(pConn->wszUserName) / sizeof(WCHAR));
  133. }
  134. return NO_ERROR;
  135. }
  136. //
  137. // Generate the connection type and device name
  138. //
  139. DWORD
  140. GenerateConnectionDeviceInfo (
  141. RAS_CONNECTION_2 * pConn,
  142. LPDWORD lpdwType,
  143. PWCHAR pszDeviceName)
  144. {
  145. DWORD dwErr, dwRead, dwTot, dwType, dwClass;
  146. RAS_PORT_0 * pPort = NULL;
  147. RASMAN_INFO Info;
  148. // Initialize the variables
  149. *lpdwType = 0;
  150. *pszDeviceName = (WCHAR)0;
  151. gblConnectToRasServer();
  152. do
  153. {
  154. // Enumerate the ports
  155. //
  156. dwErr = MprAdminPortEnum(
  157. Globals.hRasServer,
  158. 0,
  159. pConn->hConnection,
  160. (LPBYTE*)&pPort,
  161. sizeof(RAS_PORT_0) * 2,
  162. &dwRead,
  163. &dwTot,
  164. NULL);
  165. if (dwErr != NO_ERROR)
  166. {
  167. break;
  168. }
  169. if (dwRead == 0)
  170. {
  171. dwErr = ERROR_CAN_NOT_COMPLETE;
  172. break;
  173. }
  174. // Get extended information about the first
  175. // port
  176. //
  177. dwErr = RasGetInfo(NULL, pPort->hPort, &Info);
  178. if (dwErr != NO_ERROR)
  179. {
  180. break;
  181. }
  182. dwClass = RAS_DEVICE_CLASS(Info.RI_rdtDeviceType);
  183. dwType = RAS_DEVICE_TYPE(Info.RI_rdtDeviceType);
  184. lstrcpynW(
  185. pszDeviceName,
  186. pPort[0].wszDeviceName,
  187. MAX_DEVICE_NAME + 1);
  188. if ((dwClass & RDT_Direct) || (dwClass & RDT_Null_Modem))
  189. {
  190. *lpdwType = RASSRVUI_DCC;
  191. }
  192. else if (dwClass & RDT_Tunnel)
  193. {
  194. *lpdwType = RASSRVUI_VPN;
  195. }
  196. else
  197. {
  198. *lpdwType = RASSRVUI_MODEM;
  199. }
  200. } while (FALSE);
  201. // Cleanup
  202. {
  203. if (pPort)
  204. {
  205. MprAdminBufferFree((LPBYTE)pPort);
  206. }
  207. }
  208. return dwErr;
  209. }
  210. //
  211. // Starts the remote access service and marks it as autostart
  212. //
  213. DWORD
  214. RasSrvInitializeService()
  215. {
  216. DWORD dwErr = NO_ERROR, dwTimeout = 60*2;
  217. HANDLE hDialupService, hData = NULL;
  218. BOOL bInitialized = FALSE;
  219. // Get a reference to the service
  220. if ((dwErr = SvcOpenRemoteAccess(&hDialupService)) != NO_ERROR)
  221. {
  222. return dwErr;
  223. }
  224. do
  225. {
  226. RasSrvShowServiceWait(
  227. Globals.hInstDll,
  228. GetActiveWindow(),
  229. &hData);
  230. // First, mark the service as autostart
  231. if ((dwErr = SvcMarkAutoStart(hDialupService)) != NO_ERROR)
  232. {
  233. break;
  234. }
  235. // Start it (with a 5 minute timeout)
  236. dwErr = SvcStart(hDialupService, 60*5);
  237. if (dwErr == ERROR_TIMEOUT)
  238. {
  239. dwErr = ERROR_CAN_NOT_COMPLETE;
  240. break;
  241. }
  242. // Wait for the service to complete initialization
  243. //
  244. while (dwTimeout)
  245. {
  246. bInitialized = MprAdminIsServiceRunning(NULL);
  247. if (bInitialized)
  248. {
  249. break;
  250. }
  251. Sleep(1000);
  252. dwTimeout--;
  253. }
  254. if (dwTimeout == 0)
  255. {
  256. dwErr = ERROR_CAN_NOT_COMPLETE;
  257. break;
  258. }
  259. } while (FALSE);
  260. // Cleanup
  261. //
  262. {
  263. RasSrvFinishServiceWait(hData);
  264. // Cleanup the reference to the dialup service
  265. SvcClose(hDialupService);
  266. }
  267. return dwErr;
  268. }
  269. //
  270. // Stops and marks the remote access service as disabled.
  271. //
  272. DWORD
  273. RasSrvCleanupService()
  274. {
  275. DWORD dwErr = NO_ERROR;
  276. HANDLE hDialupService, hData = NULL;
  277. BOOL fIcRunningBefore = FALSE;
  278. BOOL fIcRunningAfter = FALSE;
  279. RasSrvIsServiceRunning( &fIcRunningBefore );
  280. // Get a reference to the service
  281. if ((dwErr = SvcOpenRemoteAccess(&hDialupService)) != NO_ERROR)
  282. {
  283. return dwErr;
  284. }
  285. do
  286. {
  287. RasSrvShowServiceWait(
  288. Globals.hInstDll,
  289. GetActiveWindow(),
  290. &hData);
  291. // First, stop the service (with a 5 minute timeout)
  292. //
  293. dwErr = SvcStop(hDialupService, 60*5);
  294. if (dwErr == ERROR_TIMEOUT)
  295. {
  296. dwErr = ERROR_CAN_NOT_COMPLETE;
  297. break;
  298. }
  299. if (dwErr != NO_ERROR)
  300. {
  301. break;
  302. }
  303. // Mark it as disabled
  304. if ((dwErr = SvcMarkDisabled(hDialupService)) != NO_ERROR)
  305. {
  306. break;
  307. }
  308. } while (FALSE);
  309. // Cleanup
  310. //
  311. {
  312. RasSrvFinishServiceWait(hData);
  313. SvcClose(hDialupService);
  314. }
  315. //For whistler bug 123769
  316. //If the this connection to be deleted is Incoming connection
  317. //go to disable PortMapping
  318. if ( NO_ERROR == RasSrvIsServiceRunning( &fIcRunningAfter ) )
  319. {
  320. if ( fIcRunningBefore && !fIcRunningAfter )
  321. {
  322. dwErr = HnPMConfigureAllConnections( FALSE );
  323. //this is taken out because we decide not to delete the portmappings,
  324. //just disable them instead. I keep this just for future reference. gangz
  325. //
  326. // if (NO_ERROR == dwErr )
  327. // {
  328. // dwErr = HnPMDeletePortMapping();
  329. // }
  330. }
  331. }
  332. return dwErr;
  333. }
  334. //
  335. // Reports whether the dialup service is running
  336. //
  337. DWORD
  338. APIENTRY
  339. RasSrvIsServiceRunning (
  340. OUT BOOL* pfIsRunning)
  341. {
  342. DWORD dwErr = NO_ERROR;
  343. HANDLE hDialupService = NULL;
  344. // Get a reference to the service
  345. if ((dwErr = SvcOpenRemoteAccess(&hDialupService)) != NO_ERROR)
  346. {
  347. return dwErr;
  348. }
  349. do
  350. {
  351. // Get the current status. SvcIsStarted checks the validity
  352. // of the pfIsRunning parameter.
  353. dwErr = SvcIsStarted(hDialupService, pfIsRunning);
  354. if (dwErr != NO_ERROR)
  355. {
  356. break;
  357. }
  358. } while (FALSE);
  359. // Cleanup
  360. {
  361. // Cleanup the reference to the dialup service
  362. SvcClose(hDialupService);
  363. }
  364. return NO_ERROR;
  365. }
  366. //
  367. // Returns whether the conenctions wizard should be allowed to show.
  368. //
  369. DWORD
  370. APIENTRY
  371. RasSrvAllowConnectionsWizard (
  372. OUT BOOL* pfAllow)
  373. {
  374. DWORD dwErr = NO_ERROR, dwFlags = 0;
  375. if (!pfAllow)
  376. {
  377. return ERROR_INVALID_PARAMETER;
  378. }
  379. // Initialize the product type
  380. if ((dwErr = RasSrvGetMachineFlags (&dwFlags)) != NO_ERROR)
  381. {
  382. return dwErr;
  383. }
  384. // Member or domain servers are not allowed to be shown
  385. if ((dwFlags & RASSRVUI_MACHINE_F_Server) &&
  386. (dwFlags & RASSRVUI_MACHINE_F_Member))
  387. {
  388. *pfAllow = FALSE;
  389. }
  390. else
  391. {
  392. *pfAllow = TRUE;
  393. }
  394. return NO_ERROR;
  395. }
  396. //
  397. // On ntw or standalone nts, returns result of RasSrvIsServiceRunning.
  398. // Otherwise returns false.
  399. //
  400. DWORD
  401. APIENTRY
  402. RasSrvAllowConnectionsConfig (
  403. OUT BOOL* pfAllow)
  404. {
  405. BOOL bAllowWizard;
  406. DWORD dwErr;
  407. if ((dwErr = RasSrvAllowConnectionsWizard (&bAllowWizard)) != NO_ERROR)
  408. {
  409. return dwErr;
  410. }
  411. if (bAllowWizard)
  412. {
  413. return RasSrvIsServiceRunning(pfAllow);
  414. }
  415. *pfAllow = FALSE;
  416. return NO_ERROR;
  417. }
  418. //
  419. // Checks to see if remote access service is installed
  420. //
  421. BOOL
  422. RasSrvIsRemoteAccessInstalled ()
  423. {
  424. const WCHAR pszServiceKey[] =
  425. L"SYSTEM\\CurrentControlSet\\Services\\RemoteAccess";
  426. HKEY hkService = NULL;
  427. DWORD dwErr = NO_ERROR;
  428. // Attempt to open the service registry key
  429. dwErr = RegOpenKeyExW(
  430. HKEY_LOCAL_MACHINE,
  431. pszServiceKey,
  432. 0,
  433. KEY_READ | KEY_WRITE,
  434. &hkService);
  435. // If we opened the key ok, then we can assume
  436. // that the service is installed
  437. if (dwErr == ERROR_SUCCESS)
  438. {
  439. RegCloseKey(hkService);
  440. return TRUE;
  441. }
  442. return FALSE;
  443. }
  444. //
  445. // Adds the required tabs to the incoming connections property sheet.
  446. //
  447. DWORD
  448. APIENTRY
  449. RasSrvAddPropPages (
  450. IN HRASSRVCONN hRasSrvConn,
  451. IN HWND hwndParent,
  452. IN LPFNADDPROPSHEETPAGE pfnAddPage,
  453. IN LPARAM lParam,
  454. IN OUT PVOID * ppvContext)
  455. {
  456. DWORD dwErr;
  457. // Check parameters
  458. if (!pfnAddPage || !ppvContext)
  459. {
  460. return ERROR_INVALID_PARAMETER;
  461. }
  462. // Make sure remote access is installed
  463. if (!RasSrvIsRemoteAccessInstalled())
  464. {
  465. return ERROR_SERVICE_DEPENDENCY_FAIL;
  466. }
  467. // Create the context for this page
  468. if ((dwErr = RassrvCreatePageSetCtx(ppvContext)) != NO_ERROR)
  469. {
  470. return dwErr;
  471. }
  472. // Add the tabs
  473. AddPageHelper(RASSRVUI_GENERAL_TAB,
  474. RASWIZ_TYPE_INCOMING,
  475. *ppvContext,
  476. pfnAddPage,
  477. lParam);
  478. AddPageHelper(RASSRVUI_USER_TAB,
  479. RASWIZ_TYPE_INCOMING,
  480. *ppvContext,
  481. pfnAddPage,
  482. lParam);
  483. AddPageHelper(RASSRVUI_ADVANCED_TAB,
  484. RASWIZ_TYPE_INCOMING,
  485. *ppvContext,
  486. pfnAddPage,
  487. lParam);
  488. return NO_ERROR;
  489. }
  490. //
  491. // Adds the required tabs to the incoming connections wizard
  492. //
  493. DWORD
  494. APIENTRY
  495. RasSrvAddWizPages (
  496. IN LPFNADDPROPSHEETPAGE pfnAddPage,
  497. IN LPARAM lParam,
  498. IN OUT PVOID * ppvContext)
  499. {
  500. DWORD dwErr;
  501. BOOL bAllowWizard;
  502. // Check parameters
  503. if (!pfnAddPage || !ppvContext)
  504. {
  505. return ERROR_INVALID_PARAMETER;
  506. }
  507. // Make sure remote access is installed
  508. if (!RasSrvIsRemoteAccessInstalled())
  509. {
  510. return ERROR_SERVICE_DEPENDENCY_FAIL;
  511. }
  512. // Find out if configuration through connections is allowed
  513. dwErr = RasSrvAllowConnectionsWizard (&bAllowWizard);
  514. if (dwErr != NO_ERROR)
  515. {
  516. return dwErr;
  517. }
  518. // Create the context for this page
  519. if ((dwErr = RassrvCreatePageSetCtx(ppvContext)) != NO_ERROR)
  520. {
  521. return dwErr;
  522. }
  523. // If configuration is allowed, add the wizard pages as normal
  524. if (bAllowWizard)
  525. {
  526. // Add the tabs
  527. AddPageHelper(RASSRVUI_DEVICE_WIZ_TAB,
  528. RASWIZ_TYPE_INCOMING,
  529. *ppvContext,
  530. pfnAddPage,
  531. lParam);
  532. AddPageHelper(RASSRVUI_VPN_WIZ_TAB,
  533. RASWIZ_TYPE_INCOMING,
  534. *ppvContext,
  535. pfnAddPage,
  536. lParam);
  537. AddPageHelper(RASSRVUI_USER_WIZ_TAB,
  538. RASWIZ_TYPE_INCOMING,
  539. *ppvContext,
  540. pfnAddPage,
  541. lParam);
  542. AddPageHelper(RASSRVUI_PROT_WIZ_TAB,
  543. RASWIZ_TYPE_INCOMING,
  544. *ppvContext,
  545. pfnAddPage,
  546. lParam);
  547. }
  548. // Otherwise, add the bogus page that
  549. // switches to mmc.
  550. else
  551. {
  552. // Add the tabs
  553. AddPageHelper(RASSRVUI_SWITCHMMC_WIZ_TAB,
  554. RASWIZ_TYPE_INCOMING,
  555. *ppvContext,
  556. pfnAddPage,
  557. lParam);
  558. }
  559. return NO_ERROR;
  560. }
  561. //
  562. // Function adds the host-side direct connect wizard pages
  563. //
  564. DWORD
  565. APIENTRY
  566. RassrvAddDccWizPages(
  567. IN LPFNADDPROPSHEETPAGE pfnAddPage,
  568. IN LPARAM lParam,
  569. IN OUT PVOID * ppvContext)
  570. {
  571. DWORD dwErr;
  572. BOOL bAllowWizard;
  573. // Check parameters
  574. if (!pfnAddPage || !ppvContext)
  575. {
  576. return ERROR_INVALID_PARAMETER;
  577. }
  578. // Make sure remote access is installed
  579. if (!RasSrvIsRemoteAccessInstalled())
  580. {
  581. return ERROR_SERVICE_DEPENDENCY_FAIL;
  582. }
  583. // Find out if configuration through connections is allowed
  584. dwErr = RasSrvAllowConnectionsWizard (&bAllowWizard);
  585. if (dwErr != NO_ERROR)
  586. {
  587. return dwErr;
  588. }
  589. // Create the context for this page
  590. if ((dwErr = RassrvCreatePageSetCtx(ppvContext)) != NO_ERROR)
  591. {
  592. return dwErr;
  593. }
  594. if (bAllowWizard)
  595. {
  596. // Add the tabs
  597. AddPageHelper(RASSRVUI_DCC_DEVICE_WIZ_TAB,
  598. RASWIZ_TYPE_DIRECT,
  599. *ppvContext,
  600. pfnAddPage,
  601. lParam);
  602. AddPageHelper(RASSRVUI_USER_WIZ_TAB,
  603. RASWIZ_TYPE_DIRECT,
  604. *ppvContext,
  605. pfnAddPage,
  606. lParam);
  607. }
  608. // Otherwise, add the bogus page that
  609. // switches to mmc.
  610. else
  611. {
  612. // Add the tabs
  613. AddPageHelper(RASSRVUI_SWITCHMMC_WIZ_TAB,
  614. RASWIZ_TYPE_DIRECT,
  615. *ppvContext,
  616. pfnAddPage,
  617. lParam);
  618. }
  619. return NO_ERROR;
  620. }
  621. //
  622. // Function returns the suggested name for an incoming connection.
  623. //
  624. DWORD
  625. APIENTRY
  626. RassrvGetDefaultConnectionName (
  627. IN OUT PWCHAR pszBuffer,
  628. IN OUT LPDWORD lpdwBufSize)
  629. {
  630. PWCHAR pszName;
  631. DWORD dwLen;
  632. // Load the resource string
  633. pszName = (PWCHAR) PszLoadString(
  634. Globals.hInstDll,
  635. SID_DEFAULT_CONNECTION_NAME);
  636. // Calculate length
  637. dwLen = wcslen(pszName);
  638. if (dwLen > *lpdwBufSize)
  639. {
  640. *lpdwBufSize = dwLen;
  641. return ERROR_INSUFFICIENT_BUFFER;
  642. }
  643. // Return the result
  644. wcscpy(pszBuffer, pszName);
  645. *lpdwBufSize = dwLen;
  646. return NO_ERROR;
  647. }
  648. //
  649. // Function behaves anagolously to the WIN32 function RasEnumConnections
  650. // but for client connections instead of dialout connections.
  651. //
  652. DWORD
  653. RasSrvEnumConnections(
  654. IN LPRASSRVCONN pRasSrvCon,
  655. OUT LPDWORD lpcb,
  656. OUT LPDWORD lpcConnections)
  657. {
  658. DWORD dwErr = NO_ERROR, dwEntriesRead, dwTotal, dwFlags = 0;
  659. DWORD dwPrefMax = 1000000, i, dwSizeNeeded = 0;
  660. RAS_CONNECTION_2 * pConnList;
  661. BOOL bCopy = TRUE;
  662. // Sanity Check
  663. if (!pRasSrvCon || !lpcb || !lpcConnections)
  664. {
  665. return ERROR_INVALID_PARAMETER;
  666. }
  667. //
  668. // We do not allow IC ui for member servers
  669. //
  670. RasSrvGetMachineFlags(&dwFlags);
  671. if ((dwFlags & RASSRVUI_MACHINE_F_Server) &&
  672. (dwFlags & RASSRVUI_MACHINE_F_Member))
  673. {
  674. *lpcb = 0;
  675. *lpcConnections = 0;
  676. return NO_ERROR;
  677. }
  678. //
  679. // Get the MprAdmin handle
  680. //
  681. gblConnectToRasServer();
  682. do
  683. {
  684. // Enumerate the structures
  685. dwErr = MprAdminConnectionEnum (
  686. Globals.hRasServer,
  687. 2,
  688. (LPBYTE *)&pConnList,
  689. dwPrefMax,
  690. &dwEntriesRead,
  691. &dwTotal,
  692. NULL);
  693. if (dwErr != NO_ERROR)
  694. {
  695. DbgOutputTrace ("MprAdminEnum failed %x\n", dwErr);
  696. break;
  697. }
  698. // Reuse the dwTotal variable
  699. dwTotal = 0;
  700. dwSizeNeeded = 0;
  701. // Copy over the pertanent information
  702. for (i = 0; i < dwEntriesRead; i++)
  703. {
  704. if (pConnList[i].dwInterfaceType == ROUTER_IF_TYPE_CLIENT)
  705. {
  706. dwSizeNeeded += sizeof (RASSRVCONN);
  707. if (dwSizeNeeded > *lpcb)
  708. {
  709. bCopy = FALSE;
  710. }
  711. if (bCopy)
  712. {
  713. // Connection handle
  714. pRasSrvCon[dwTotal].hRasSrvConn =
  715. pConnList[i].hConnection;
  716. // Name
  717. dwErr = GenerateConnectionName(
  718. &pConnList[i],
  719. pRasSrvCon[dwTotal].szEntryName);
  720. if (dwErr != NO_ERROR)
  721. {
  722. continue;
  723. }
  724. // Type and Device Name
  725. dwErr = GenerateConnectionDeviceInfo(
  726. &pConnList[i],
  727. &(pRasSrvCon[dwTotal].dwType),
  728. pRasSrvCon[dwTotal].szDeviceName);
  729. if (dwErr != NO_ERROR)
  730. {
  731. continue;
  732. }
  733. // Guid
  734. pRasSrvCon[dwTotal].Guid = pConnList[i].guid;
  735. dwTotal++;
  736. }
  737. }
  738. }
  739. *lpcb = dwSizeNeeded;
  740. *lpcConnections = dwTotal;
  741. } while (FALSE);
  742. // Cleanup
  743. {
  744. MprAdminBufferFree((LPBYTE)pConnList);
  745. }
  746. if (!bCopy)
  747. {
  748. dwErr = ERROR_BUFFER_TOO_SMALL;
  749. }
  750. return dwErr;
  751. }
  752. //
  753. // Gets the status of a Ras Server Connection
  754. //
  755. DWORD
  756. APIENTRY
  757. RasSrvIsConnectionConnected (
  758. IN HRASSRVCONN hRasSrvConn,
  759. OUT BOOL* pfConnected)
  760. {
  761. RAS_CONNECTION_2 * pConn;
  762. DWORD dwErr;
  763. // Sanity check the parameters
  764. if (!pfConnected)
  765. {
  766. return ERROR_INVALID_PARAMETER;
  767. }
  768. gblConnectToRasServer();
  769. // Query rasman for the connection information
  770. dwErr = MprAdminConnectionGetInfo(
  771. Globals.hRasServer,
  772. 0,
  773. hRasSrvConn,
  774. (LPBYTE*)&pConn);
  775. if (dwErr != NO_ERROR)
  776. {
  777. *pfConnected = FALSE;
  778. }
  779. else
  780. {
  781. *pfConnected = TRUE;
  782. }
  783. if (pfConnected)
  784. {
  785. MprAdminBufferFree((LPBYTE)pConn);
  786. }
  787. return NO_ERROR;
  788. }
  789. //
  790. // Hangs up the given connection
  791. //
  792. DWORD
  793. RasSrvHangupConnection(
  794. IN HRASSRVCONN hRasSrvConn)
  795. {
  796. RAS_PORT_0 * pPorts;
  797. DWORD dwRead, dwTot, dwErr, i, dwRet = NO_ERROR;
  798. gblConnectToRasServer();
  799. // Enumerate all of the ports on this connection
  800. dwErr = MprAdminPortEnum(
  801. Globals.hRasServer,
  802. 0,
  803. hRasSrvConn,
  804. (LPBYTE*)&pPorts,
  805. 4096,
  806. &dwRead,
  807. &dwTot,
  808. NULL);
  809. if (dwErr != NO_ERROR)
  810. {
  811. return dwErr;
  812. }
  813. // Hang up each of the ports individually
  814. for (i = 0; i < dwRead; i++)
  815. {
  816. dwErr = MprAdminPortDisconnect(
  817. Globals.hRasServer,
  818. pPorts[i].hPort);
  819. if (dwErr != NO_ERROR)
  820. {
  821. dwRet = dwErr;
  822. }
  823. }
  824. MprAdminBufferFree((LPBYTE)pPorts);
  825. return dwRet;
  826. }
  827. //
  828. // Queries whether to show icons in the task bar.
  829. //
  830. DWORD
  831. APIENTRY
  832. RasSrvQueryShowIcon (
  833. OUT BOOL* pfShowIcon)
  834. {
  835. DWORD dwErr = NO_ERROR;
  836. HANDLE hMiscDatabase = NULL;
  837. if (!pfShowIcon)
  838. {
  839. return ERROR_INVALID_PARAMETER;
  840. }
  841. do
  842. {
  843. // Open a copy of the miscellaneous database
  844. dwErr = miscOpenDatabase(&hMiscDatabase);
  845. if (dwErr != NO_ERROR)
  846. {
  847. break;
  848. }
  849. // Return the status
  850. dwErr = miscGetIconEnable(hMiscDatabase, pfShowIcon);
  851. if (dwErr != NO_ERROR)
  852. {
  853. break;
  854. }
  855. } while (FALSE);
  856. // Cleanup
  857. {
  858. if (hMiscDatabase)
  859. {
  860. miscCloseDatabase(hMiscDatabase);
  861. }
  862. }
  863. return dwErr;
  864. }
  865. // ===================================
  866. // ===================================
  867. // Dll entry management
  868. // ===================================
  869. // ===================================
  870. //
  871. // Called when another process attaches to this dll
  872. //
  873. DWORD
  874. RassrvHandleProcessAttach(
  875. IN HINSTANCE hInstDll,
  876. IN LPVOID pReserved)
  877. {
  878. // Initialize global variables
  879. //
  880. return gblInit(hInstDll, &Globals);
  881. }
  882. //
  883. // Called when process detaches from this dll
  884. //
  885. DWORD
  886. RassrvHandleProcessDetach(
  887. IN HINSTANCE hInstDll,
  888. IN LPVOID pReserved)
  889. {
  890. // Cleanup global variables
  891. //
  892. return gblCleanup(&Globals);
  893. }
  894. //
  895. // Called when thread attaches to this dll
  896. //
  897. DWORD
  898. RassrvHandleThreadAttach(
  899. IN HINSTANCE hInstDll,
  900. IN LPVOID pReserved)
  901. {
  902. return NO_ERROR;
  903. }
  904. //
  905. // Called when thread detaches from this dll
  906. //
  907. DWORD
  908. RassrvHandleThreadDetach(
  909. IN HINSTANCE hInstDll,
  910. IN LPVOID pReserved)
  911. {
  912. return NO_ERROR;
  913. }