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.

1085 lines
25 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. // For whistler 480871
  304. // Mark the registry if IC is deleted
  305. RassrvSetICConfig( 0 );
  306. // Mark it as disabled
  307. if ((dwErr = SvcMarkDisabled(hDialupService)) != NO_ERROR)
  308. {
  309. break;
  310. }
  311. } while (FALSE);
  312. // Cleanup
  313. //
  314. {
  315. RasSrvFinishServiceWait(hData);
  316. SvcClose(hDialupService);
  317. }
  318. //For whistler bug 123769
  319. //If the this connection to be deleted is Incoming connection
  320. //go to disable PortMapping
  321. if ( NO_ERROR == RasSrvIsServiceRunning( &fIcRunningAfter ) )
  322. {
  323. if ( fIcRunningBefore && !fIcRunningAfter )
  324. {
  325. dwErr = HnPMConfigureAllConnections( FALSE );
  326. //this is taken out because we decide not to delete the portmappings,
  327. //just disable them instead. I keep this just for future reference. gangz
  328. //
  329. // if (NO_ERROR == dwErr )
  330. // {
  331. // dwErr = HnPMDeletePortMapping();
  332. // }
  333. }
  334. }
  335. return dwErr;
  336. }
  337. //
  338. // Reports whether the dialup service is running
  339. //
  340. DWORD
  341. APIENTRY
  342. RasSrvIsServiceRunning (
  343. OUT BOOL* pfIsRunning)
  344. {
  345. DWORD dwErr = NO_ERROR;
  346. HANDLE hDialupService = NULL;
  347. // Get a reference to the service
  348. if ((dwErr = SvcOpenRemoteAccess(&hDialupService)) != NO_ERROR)
  349. {
  350. return dwErr;
  351. }
  352. do
  353. {
  354. // Get the current status. SvcIsStarted checks the validity
  355. // of the pfIsRunning parameter.
  356. dwErr = SvcIsStarted(hDialupService, pfIsRunning);
  357. if (dwErr != NO_ERROR)
  358. {
  359. break;
  360. }
  361. } while (FALSE);
  362. // Cleanup
  363. {
  364. // Cleanup the reference to the dialup service
  365. SvcClose(hDialupService);
  366. }
  367. return NO_ERROR;
  368. }
  369. //
  370. // Returns whether the conenctions wizard should be allowed to show.
  371. //
  372. DWORD
  373. APIENTRY
  374. RasSrvAllowConnectionsWizard (
  375. OUT BOOL* pfAllow)
  376. {
  377. DWORD dwErr = NO_ERROR, dwFlags = 0;
  378. BOOL fConfig = FALSE;
  379. if (!pfAllow)
  380. {
  381. return ERROR_INVALID_PARAMETER;
  382. }
  383. // Initialize the product type
  384. if ((dwErr = RasSrvGetMachineFlags (&dwFlags)) != NO_ERROR)
  385. {
  386. return dwErr;
  387. }
  388. if( NO_ERROR != RasSrvIsRRASConfigured( & fConfig ) )
  389. {
  390. *pfAllow = TRUE;
  391. }
  392. else
  393. {
  394. *pfAllow = fConfig ? FALSE : TRUE ;
  395. }
  396. return NO_ERROR;
  397. }
  398. //
  399. // On ntw or standalone nts, returns result of RasSrvIsServiceRunning.
  400. // Otherwise returns false.
  401. //
  402. DWORD
  403. APIENTRY
  404. RasSrvAllowConnectionsConfig (
  405. OUT BOOL* pfAllow)
  406. {
  407. BOOL bAllowWizard;
  408. DWORD dwErr;
  409. if ((dwErr = RasSrvAllowConnectionsWizard (&bAllowWizard)) != NO_ERROR)
  410. {
  411. return dwErr;
  412. }
  413. if (bAllowWizard)
  414. {
  415. return RasSrvIsServiceRunning(pfAllow);
  416. }
  417. *pfAllow = FALSE;
  418. return NO_ERROR;
  419. }
  420. //
  421. // Checks to see if remote access service is installed
  422. //
  423. BOOL
  424. RasSrvIsRemoteAccessInstalled ()
  425. {
  426. const WCHAR pszServiceKey[] =
  427. L"SYSTEM\\CurrentControlSet\\Services\\RemoteAccess";
  428. HKEY hkService = NULL;
  429. DWORD dwErr = NO_ERROR;
  430. // Attempt to open the service registry key
  431. dwErr = RegOpenKeyExW(
  432. HKEY_LOCAL_MACHINE,
  433. pszServiceKey,
  434. 0,
  435. KEY_READ | KEY_WRITE,
  436. &hkService);
  437. // If we opened the key ok, then we can assume
  438. // that the service is installed
  439. if (dwErr == ERROR_SUCCESS)
  440. {
  441. RegCloseKey(hkService);
  442. return TRUE;
  443. }
  444. return FALSE;
  445. }
  446. //
  447. // Adds the required tabs to the incoming connections property sheet.
  448. //
  449. DWORD
  450. APIENTRY
  451. RasSrvAddPropPages (
  452. IN HRASSRVCONN hRasSrvConn,
  453. IN HWND hwndParent,
  454. IN LPFNADDPROPSHEETPAGE pfnAddPage,
  455. IN LPARAM lParam,
  456. IN OUT PVOID * ppvContext)
  457. {
  458. DWORD dwErr;
  459. // Check parameters
  460. if (!pfnAddPage || !ppvContext)
  461. {
  462. return ERROR_INVALID_PARAMETER;
  463. }
  464. // Make sure remote access is installed
  465. if (!RasSrvIsRemoteAccessInstalled())
  466. {
  467. return ERROR_SERVICE_DEPENDENCY_FAIL;
  468. }
  469. // Create the context for this page
  470. if ((dwErr = RassrvCreatePageSetCtx(ppvContext)) != NO_ERROR)
  471. {
  472. return dwErr;
  473. }
  474. // Add the tabs
  475. AddPageHelper(RASSRVUI_GENERAL_TAB,
  476. RASWIZ_TYPE_INCOMING,
  477. *ppvContext,
  478. pfnAddPage,
  479. lParam);
  480. AddPageHelper(RASSRVUI_USER_TAB,
  481. RASWIZ_TYPE_INCOMING,
  482. *ppvContext,
  483. pfnAddPage,
  484. lParam);
  485. AddPageHelper(RASSRVUI_ADVANCED_TAB,
  486. RASWIZ_TYPE_INCOMING,
  487. *ppvContext,
  488. pfnAddPage,
  489. lParam);
  490. return NO_ERROR;
  491. }
  492. //
  493. // Adds the required tabs to the incoming connections wizard
  494. //
  495. DWORD
  496. APIENTRY
  497. RasSrvAddWizPages (
  498. IN LPFNADDPROPSHEETPAGE pfnAddPage,
  499. IN LPARAM lParam,
  500. IN OUT PVOID * ppvContext)
  501. {
  502. DWORD dwErr;
  503. BOOL bAllowWizard;
  504. // Check parameters
  505. if (!pfnAddPage || !ppvContext)
  506. {
  507. return ERROR_INVALID_PARAMETER;
  508. }
  509. // Make sure remote access is installed
  510. if (!RasSrvIsRemoteAccessInstalled())
  511. {
  512. return ERROR_SERVICE_DEPENDENCY_FAIL;
  513. }
  514. // Find out if configuration through connections is allowed
  515. dwErr = RasSrvAllowConnectionsWizard (&bAllowWizard);
  516. if (dwErr != NO_ERROR)
  517. {
  518. return dwErr;
  519. }
  520. // Create the context for this page
  521. if ((dwErr = RassrvCreatePageSetCtx(ppvContext)) != NO_ERROR)
  522. {
  523. return dwErr;
  524. }
  525. // If configuration is allowed, add the wizard pages as normal
  526. if (bAllowWizard)
  527. {
  528. // Add the tabs
  529. AddPageHelper(RASSRVUI_DEVICE_WIZ_TAB,
  530. RASWIZ_TYPE_INCOMING,
  531. *ppvContext,
  532. pfnAddPage,
  533. lParam);
  534. AddPageHelper(RASSRVUI_VPN_WIZ_TAB,
  535. RASWIZ_TYPE_INCOMING,
  536. *ppvContext,
  537. pfnAddPage,
  538. lParam);
  539. AddPageHelper(RASSRVUI_USER_WIZ_TAB,
  540. RASWIZ_TYPE_INCOMING,
  541. *ppvContext,
  542. pfnAddPage,
  543. lParam);
  544. AddPageHelper(RASSRVUI_PROT_WIZ_TAB,
  545. RASWIZ_TYPE_INCOMING,
  546. *ppvContext,
  547. pfnAddPage,
  548. lParam);
  549. }
  550. // Otherwise, add the bogus page that
  551. // switches to mmc.
  552. else
  553. {
  554. // Add the tabs
  555. AddPageHelper(RASSRVUI_SWITCHMMC_WIZ_TAB,
  556. RASWIZ_TYPE_INCOMING,
  557. *ppvContext,
  558. pfnAddPage,
  559. lParam);
  560. }
  561. return NO_ERROR;
  562. }
  563. //
  564. // Function adds the host-side direct connect wizard pages
  565. //
  566. DWORD
  567. APIENTRY
  568. RassrvAddDccWizPages(
  569. IN LPFNADDPROPSHEETPAGE pfnAddPage,
  570. IN LPARAM lParam,
  571. IN OUT PVOID * ppvContext)
  572. {
  573. DWORD dwErr;
  574. BOOL bAllowWizard;
  575. // Check parameters
  576. if (!pfnAddPage || !ppvContext)
  577. {
  578. return ERROR_INVALID_PARAMETER;
  579. }
  580. // Make sure remote access is installed
  581. if (!RasSrvIsRemoteAccessInstalled())
  582. {
  583. return ERROR_SERVICE_DEPENDENCY_FAIL;
  584. }
  585. // Find out if configuration through connections is allowed
  586. dwErr = RasSrvAllowConnectionsWizard (&bAllowWizard);
  587. if (dwErr != NO_ERROR)
  588. {
  589. return dwErr;
  590. }
  591. // Create the context for this page
  592. if ((dwErr = RassrvCreatePageSetCtx(ppvContext)) != NO_ERROR)
  593. {
  594. return dwErr;
  595. }
  596. if (bAllowWizard)
  597. {
  598. // Add the tabs
  599. AddPageHelper(RASSRVUI_DCC_DEVICE_WIZ_TAB,
  600. RASWIZ_TYPE_DIRECT,
  601. *ppvContext,
  602. pfnAddPage,
  603. lParam);
  604. AddPageHelper(RASSRVUI_USER_WIZ_TAB,
  605. RASWIZ_TYPE_DIRECT,
  606. *ppvContext,
  607. pfnAddPage,
  608. lParam);
  609. }
  610. // Otherwise, add the bogus page that
  611. // switches to mmc.
  612. else
  613. {
  614. // Add the tabs
  615. AddPageHelper(RASSRVUI_SWITCHMMC_WIZ_TAB,
  616. RASWIZ_TYPE_DIRECT,
  617. *ppvContext,
  618. pfnAddPage,
  619. lParam);
  620. }
  621. return NO_ERROR;
  622. }
  623. //
  624. // Function returns the suggested name for an incoming connection.
  625. //
  626. DWORD
  627. APIENTRY
  628. RassrvGetDefaultConnectionName (
  629. IN OUT PWCHAR pszBuffer,
  630. IN OUT LPDWORD lpdwBufSize)
  631. {
  632. PWCHAR pszName;
  633. DWORD dwLen;
  634. // Load the resource string
  635. pszName = (PWCHAR) PszLoadString(
  636. Globals.hInstDll,
  637. SID_DEFAULT_CONNECTION_NAME);
  638. // Calculate length
  639. dwLen = wcslen(pszName);
  640. if (dwLen > *lpdwBufSize)
  641. {
  642. *lpdwBufSize = dwLen;
  643. return ERROR_INSUFFICIENT_BUFFER;
  644. }
  645. // Return the result
  646. wcscpy(pszBuffer, pszName);
  647. *lpdwBufSize = dwLen;
  648. return NO_ERROR;
  649. }
  650. //
  651. // Function behaves anagolously to the WIN32 function RasEnumConnections
  652. // but for client connections instead of dialout connections.
  653. //
  654. DWORD
  655. RasSrvEnumConnections(
  656. IN LPRASSRVCONN pRasSrvCon,
  657. OUT LPDWORD lpcb,
  658. OUT LPDWORD lpcConnections)
  659. {
  660. DWORD dwErr = NO_ERROR, dwEntriesRead, dwTotal, dwFlags = 0;
  661. DWORD dwPrefMax = 1000000, i, dwSizeNeeded = 0;
  662. RAS_CONNECTION_2 * pConnList = NULL;
  663. BOOL bCopy = TRUE, fConfig = FALSE, fAllow = FALSE;
  664. // Sanity Check
  665. if (!pRasSrvCon || !lpcb || !lpcConnections)
  666. {
  667. return ERROR_INVALID_PARAMETER;
  668. }
  669. // For .Net 690392
  670. if( NO_ERROR == RasSrvIsRRASConfigured( & fConfig ) )
  671. {
  672. fAllow = fConfig ? FALSE : TRUE;
  673. }
  674. //
  675. // We do not allow IC ui for member servers when rras is configured
  676. //
  677. RasSrvGetMachineFlags(&dwFlags);
  678. if ((dwFlags & RASSRVUI_MACHINE_F_Server) &&
  679. (dwFlags & RASSRVUI_MACHINE_F_Member) &&
  680. (!fAllow)
  681. )
  682. {
  683. *lpcb = 0;
  684. *lpcConnections = 0;
  685. return NO_ERROR;
  686. }
  687. //
  688. // Get the MprAdmin handle
  689. //
  690. do
  691. {
  692. // for .Net 606857
  693. dwErr = gblConnectToRasServer();
  694. if (dwErr != NO_ERROR)
  695. {
  696. DbgOutputTrace ("gblConnectToRasServer failed %x\n", dwErr);
  697. break;
  698. }
  699. // Enumerate the structures
  700. dwErr = MprAdminConnectionEnum (
  701. Globals.hRasServer,
  702. 2,
  703. (LPBYTE *)&pConnList,
  704. dwPrefMax,
  705. &dwEntriesRead,
  706. &dwTotal,
  707. NULL);
  708. if (dwErr != NO_ERROR)
  709. {
  710. pConnList = NULL;
  711. DbgOutputTrace ("MprAdminEnum failed %x\n", dwErr);
  712. break;
  713. }
  714. // Reuse the dwTotal variable
  715. dwTotal = 0;
  716. dwSizeNeeded = 0;
  717. // Copy over the pertanent information
  718. for (i = 0; i < dwEntriesRead; i++)
  719. {
  720. if (pConnList[i].dwInterfaceType == ROUTER_IF_TYPE_CLIENT)
  721. {
  722. dwSizeNeeded += sizeof (RASSRVCONN);
  723. if (dwSizeNeeded > *lpcb)
  724. {
  725. bCopy = FALSE;
  726. }
  727. if (bCopy)
  728. {
  729. // Connection handle
  730. pRasSrvCon[dwTotal].hRasSrvConn =
  731. pConnList[i].hConnection;
  732. // Name
  733. dwErr = GenerateConnectionName(
  734. &pConnList[i],
  735. pRasSrvCon[dwTotal].szEntryName);
  736. if (dwErr != NO_ERROR)
  737. {
  738. continue;
  739. }
  740. // Type and Device Name
  741. dwErr = GenerateConnectionDeviceInfo(
  742. &pConnList[i],
  743. &(pRasSrvCon[dwTotal].dwType),
  744. pRasSrvCon[dwTotal].szDeviceName);
  745. if (dwErr != NO_ERROR)
  746. {
  747. continue;
  748. }
  749. // Guid
  750. pRasSrvCon[dwTotal].Guid = pConnList[i].guid;
  751. dwTotal++;
  752. }
  753. }
  754. }
  755. *lpcb = dwSizeNeeded;
  756. *lpcConnections = dwTotal;
  757. } while (FALSE);
  758. // Cleanup
  759. if(pConnList)
  760. {
  761. MprAdminBufferFree((LPBYTE)pConnList);
  762. }
  763. if (!bCopy)
  764. {
  765. dwErr = ERROR_BUFFER_TOO_SMALL;
  766. }
  767. return dwErr;
  768. }
  769. //
  770. // Gets the status of a Ras Server Connection
  771. //
  772. DWORD
  773. APIENTRY
  774. RasSrvIsConnectionConnected (
  775. IN HRASSRVCONN hRasSrvConn,
  776. OUT BOOL* pfConnected)
  777. {
  778. RAS_CONNECTION_2 * pConn;
  779. DWORD dwErr;
  780. // Sanity check the parameters
  781. if (!pfConnected)
  782. {
  783. return ERROR_INVALID_PARAMETER;
  784. }
  785. gblConnectToRasServer();
  786. // Query rasman for the connection information
  787. dwErr = MprAdminConnectionGetInfo(
  788. Globals.hRasServer,
  789. 0,
  790. hRasSrvConn,
  791. (LPBYTE*)&pConn);
  792. if (dwErr != NO_ERROR)
  793. {
  794. *pfConnected = FALSE;
  795. }
  796. else
  797. {
  798. *pfConnected = TRUE;
  799. }
  800. if (pfConnected)
  801. {
  802. MprAdminBufferFree((LPBYTE)pConn);
  803. }
  804. return NO_ERROR;
  805. }
  806. //
  807. // Hangs up the given connection
  808. //
  809. DWORD
  810. RasSrvHangupConnection(
  811. IN HRASSRVCONN hRasSrvConn)
  812. {
  813. RAS_PORT_0 * pPorts;
  814. DWORD dwRead, dwTot, dwErr, i, dwRet = NO_ERROR;
  815. gblConnectToRasServer();
  816. // Enumerate all of the ports on this connection
  817. dwErr = MprAdminPortEnum(
  818. Globals.hRasServer,
  819. 0,
  820. hRasSrvConn,
  821. (LPBYTE*)&pPorts,
  822. 4096,
  823. &dwRead,
  824. &dwTot,
  825. NULL);
  826. if (dwErr != NO_ERROR)
  827. {
  828. return dwErr;
  829. }
  830. // Hang up each of the ports individually
  831. for (i = 0; i < dwRead; i++)
  832. {
  833. dwErr = MprAdminPortDisconnect(
  834. Globals.hRasServer,
  835. pPorts[i].hPort);
  836. if (dwErr != NO_ERROR)
  837. {
  838. dwRet = dwErr;
  839. }
  840. }
  841. MprAdminBufferFree((LPBYTE)pPorts);
  842. return dwRet;
  843. }
  844. //
  845. // Queries whether to show icons in the task bar.
  846. //
  847. DWORD
  848. APIENTRY
  849. RasSrvQueryShowIcon (
  850. OUT BOOL* pfShowIcon)
  851. {
  852. DWORD dwErr = NO_ERROR;
  853. HANDLE hMiscDatabase = NULL;
  854. if (!pfShowIcon)
  855. {
  856. return ERROR_INVALID_PARAMETER;
  857. }
  858. do
  859. {
  860. // Open a copy of the miscellaneous database
  861. dwErr = miscOpenDatabase(&hMiscDatabase);
  862. if (dwErr != NO_ERROR)
  863. {
  864. break;
  865. }
  866. // Return the status
  867. dwErr = miscGetIconEnable(hMiscDatabase, pfShowIcon);
  868. if (dwErr != NO_ERROR)
  869. {
  870. break;
  871. }
  872. } while (FALSE);
  873. // Cleanup
  874. {
  875. if (hMiscDatabase)
  876. {
  877. miscCloseDatabase(hMiscDatabase);
  878. }
  879. }
  880. return dwErr;
  881. }
  882. // ===================================
  883. // ===================================
  884. // Dll entry management
  885. // ===================================
  886. // ===================================
  887. //
  888. // Called when another process attaches to this dll
  889. //
  890. DWORD
  891. RassrvHandleProcessAttach(
  892. IN HINSTANCE hInstDll,
  893. IN LPVOID pReserved)
  894. {
  895. // Initialize global variables
  896. //
  897. return gblInit(hInstDll, &Globals);
  898. }
  899. //
  900. // Called when process detaches from this dll
  901. //
  902. DWORD
  903. RassrvHandleProcessDetach(
  904. IN HINSTANCE hInstDll,
  905. IN LPVOID pReserved)
  906. {
  907. // Cleanup global variables
  908. //
  909. return gblCleanup(&Globals);
  910. }
  911. //
  912. // Called when thread attaches to this dll
  913. //
  914. DWORD
  915. RassrvHandleThreadAttach(
  916. IN HINSTANCE hInstDll,
  917. IN LPVOID pReserved)
  918. {
  919. return NO_ERROR;
  920. }
  921. //
  922. // Called when thread detaches from this dll
  923. //
  924. DWORD
  925. RassrvHandleThreadDetach(
  926. IN HINSTANCE hInstDll,
  927. IN LPVOID pReserved)
  928. {
  929. return NO_ERROR;
  930. }