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.

5545 lines
116 KiB

  1. /*++
  2. Copyright (C) 1992-98 Microsft Corporation. All rights reserved.
  3. Module Name:
  4. apis.c
  5. Abstract:
  6. This file contains all entry points for the RASMAN.DLL of
  7. RAS Manager Component.
  8. Author:
  9. Gurdeep Singh Pall (gurdeep) 06-Jun-1997
  10. Revision History:
  11. Miscellaneous Modifications - raos 31-Dec-1997
  12. --*/
  13. #include <nt.h>
  14. #include <ntrtl.h>
  15. #include <nturtl.h>
  16. #include <rasman.h>
  17. #include <wanpub.h>
  18. #include <media.h>
  19. #include <stdio.h>
  20. #include <raserror.h>
  21. #include <rasppp.h>
  22. #include <stdarg.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include <sechost.h>
  26. #include <winsock.h>
  27. #include "defs.h"
  28. #include "structs.h"
  29. #include <sechost.h>
  30. #include "globals.h"
  31. #include "rasmxs.h"
  32. #include "protos.h"
  33. #include "nouiutil.h"
  34. #include "loaddlls.h"
  35. #include "rpc.h"
  36. #include "process.h"
  37. extern CRITICAL_SECTION g_csRequestBuffer;
  38. extern RPC_BINDING_HANDLE g_hBinding;
  39. BOOL g_fRasInitialized = FALSE;
  40. BOOL g_fWinsockInitialized = FALSE;
  41. BOOL g_fRasAutoStarted = FALSE;
  42. DWORD g_dwEventCount = 0;
  43. #define SECS_WaitTimeOut 500
  44. #define NET_SVCS_GROUP "-k netsvcs"
  45. DWORD
  46. DwRasGetHostByName(CHAR *pszHostName, DWORD **pdwAddress, DWORD *pcAddresses);
  47. /*++
  48. Routine Description:
  49. This function is called to check if a port handle
  50. supplied to the the API is valid.
  51. Arguments:
  52. Return Value:
  53. TRUE (if valid)
  54. FALSE
  55. --*/
  56. BOOL
  57. ValidatePortHandle (HPORT porthandle)
  58. {
  59. if ((porthandle >= 0))
  60. {
  61. return TRUE ;
  62. }
  63. return FALSE ;
  64. }
  65. BOOL
  66. ValidateConnectionHandle(HANDLE hConnection)
  67. {
  68. RAS_RPC *pRasRpcConnection = (RAS_RPC *) hConnection;
  69. if( NULL != pRasRpcConnection
  70. && NULL == pRasRpcConnection->hRpcBinding)
  71. {
  72. return FALSE;
  73. }
  74. return TRUE;
  75. }
  76. BOOL
  77. IsRasmanProcess()
  78. {
  79. CHAR *pszCmdLine = NULL;
  80. BOOL fRet = FALSE;
  81. pszCmdLine = GetCommandLine();
  82. RasmanOutputDebug("IsRasmanProcess: CmdLine=%s\n",
  83. (NULL == pszCmdLine)
  84. ? "NULL"
  85. : pszCmdLine);
  86. if( (NULL != pszCmdLine)
  87. && (strstr(pszCmdLine, NET_SVCS_GROUP)))
  88. {
  89. fRet = TRUE;
  90. }
  91. RasmanOutputDebug("IsRasmanProcess: returning %d\n",
  92. fRet);
  93. return fRet;
  94. }
  95. BOOL
  96. IsKnownDll(WCHAR *pwszCustomDialerName)
  97. {
  98. BOOL fRet = FALSE;
  99. WCHAR *pwszDialerName, *pwsz;
  100. if(NULL == pwszCustomDialerName)
  101. {
  102. goto done;
  103. }
  104. pwsz = pwszCustomDialerName + wcslen(pwszCustomDialerName);
  105. while( (L'\\' != *pwsz)
  106. && (pwsz != pwszCustomDialerName))
  107. {
  108. pwsz--;
  109. }
  110. if(L'\\' == *pwsz)
  111. {
  112. pwsz++;
  113. }
  114. if(0 == _wcsicmp(pwsz, L"cmdial32.dll"))
  115. {
  116. fRet = TRUE;
  117. }
  118. done:
  119. return fRet;
  120. }
  121. /*++
  122. Routine Description:
  123. Used for detecting processes attaching and detaching
  124. to the DLL.
  125. Arguments:
  126. Return Value:
  127. --*/
  128. BOOL
  129. InitRasmanDLL (HANDLE hInst, DWORD ul_reason_being_called, LPVOID lpReserved)
  130. {
  131. WSADATA wsaData;
  132. switch (ul_reason_being_called)
  133. {
  134. case DLL_PROCESS_ATTACH:
  135. DisableThreadLibraryCalls(hInst);
  136. //
  137. // Before we proceed initialize this cs. This will
  138. // be used to synchronize threads in the client
  139. // process that sends requests to rasmans.
  140. //
  141. InitializeCriticalSection( &g_csRequestBuffer );
  142. break ;
  143. case DLL_PROCESS_DETACH:
  144. //
  145. // If this is the rasman process detaching -
  146. // don't do anything, else check if rasman
  147. // service should be stopped and then stop
  148. // it.
  149. //
  150. if (!IsRasmanProcess())
  151. {
  152. DWORD dwAttachedCount;
  153. BOOL fPortsOpen;
  154. //
  155. // Dereference rasman only if Ras was initialized in
  156. // this process
  157. //
  158. if (!g_fRasInitialized)
  159. {
  160. DeleteCriticalSection(&g_csRequestBuffer);
  161. break;
  162. }
  163. RasGetAttachedCount (&dwAttachedCount);
  164. SubmitRequest(NULL, REQTYPE_CLOSEPROCESSPORTS);
  165. fPortsOpen = SubmitRequest(NULL, REQTYPE_NUMPORTOPEN);
  166. RasReferenceRasman (FALSE);
  167. if ( !fPortsOpen
  168. && 1 == dwAttachedCount)
  169. {
  170. WaitForRasmanServiceStop () ;
  171. }
  172. //
  173. // Disconnect from rasmans
  174. //
  175. if (g_hBinding)
  176. {
  177. DWORD dwErr;
  178. dwErr = RasRpcDisconnect (&g_hBinding);
  179. }
  180. }
  181. else
  182. {
  183. //
  184. // Free rasmans dll if we loaded it i.e when in
  185. // mprouter process
  186. //
  187. if (hInstRasmans)
  188. {
  189. FreeLibrary (hInstRasmans);
  190. }
  191. hInstRasmans = NULL;
  192. }
  193. if(NULL != lpReserved)
  194. {
  195. DeleteCriticalSection(&g_csRequestBuffer);
  196. break;
  197. }
  198. //
  199. // Terminate winsock.
  200. //
  201. if(g_fWinsockInitialized)
  202. {
  203. WSACleanup();
  204. g_fWinsockInitialized = FALSE;
  205. }
  206. //
  207. // This has to be the very last thing to do.
  208. //
  209. DeleteCriticalSection(&g_csRequestBuffer);
  210. break ;
  211. }
  212. return 1;
  213. }
  214. /*++
  215. Routine Description:
  216. Returns the product type and sku
  217. Arguments:
  218. ppt - Address to receive the product type
  219. pps - Address to receive the sku
  220. Return Value:
  221. ERROR_SUCCESS if successful
  222. Registry apis errors
  223. --*/
  224. LONG
  225. GetProductTypeAndSku(
  226. PRODUCT_TYPE *ppt,
  227. PRODUCT_SKU *pps OPTIONAL
  228. )
  229. {
  230. LONG lr = ERROR_SUCCESS;
  231. CHAR szProductType[128] = {0};
  232. CHAR szProductSku[128] = {0};
  233. HKEY hkey = NULL;
  234. DWORD dwsize;
  235. DWORD dwtype;
  236. CHAR *pszProductType = "ProductType";
  237. CHAR *pszProductSku = "ProductSuite";
  238. CHAR *pszProductOptions =
  239. "System\\CurrentControlSet\\Control\\ProductOptions";
  240. CHAR *pszServerNT = "ServerNT";
  241. CHAR *pszWinNT = "WinNT";
  242. CHAR *pszPersonal = "Personal";
  243. //
  244. // default to workstation
  245. //
  246. *ppt = PT_WORKSTATION;
  247. if (pps)
  248. {
  249. *pps = 0;
  250. }
  251. //
  252. // Open the ProductOptions key
  253. //
  254. if (ERROR_SUCCESS != (lr = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  255. pszProductOptions,
  256. 0, KEY_READ,
  257. &hkey)))
  258. {
  259. goto done;
  260. }
  261. //
  262. // Query the product type
  263. //
  264. dwsize = sizeof(szProductType);
  265. if(ERROR_SUCCESS != (lr = RegQueryValueEx(
  266. hkey,
  267. pszProductType,
  268. NULL,
  269. &dwtype,
  270. (LPBYTE) szProductType,
  271. &dwsize)))
  272. {
  273. goto done;
  274. }
  275. if(0 == _stricmp(szProductType,
  276. pszServerNT))
  277. {
  278. *ppt = PT_SERVER;
  279. }
  280. else if(0 == _stricmp(szProductType,
  281. pszWinNT))
  282. {
  283. *ppt = PT_WORKSTATION;
  284. }
  285. //
  286. // Query the product sku as appropriate
  287. //
  288. if (*ppt == PT_WORKSTATION && pps)
  289. {
  290. dwsize = sizeof(szProductSku);
  291. if(ERROR_SUCCESS != (lr = RegQueryValueEx(
  292. hkey,
  293. pszProductSku,
  294. NULL,
  295. &dwtype,
  296. (LPBYTE) szProductSku,
  297. &dwsize)))
  298. {
  299. goto done;
  300. }
  301. if (0 == _stricmp(szProductSku, pszPersonal))
  302. {
  303. *pps = PS_PERSONAL;
  304. }
  305. else
  306. {
  307. *pps = PS_PROFESSIONAL;
  308. }
  309. }
  310. done:
  311. if(hkey)
  312. {
  313. RegCloseKey(hkey);
  314. }
  315. RasmanOutputDebug("GetProductType returning 0x%x\n", lr);
  316. return lr;
  317. }
  318. /*++
  319. Routine Description:
  320. Returns the product type
  321. Arguments:
  322. ppt - Address to receive the product type
  323. Return Value:
  324. ERROR_SUCCESS if successful
  325. Registry apis errors
  326. --*/
  327. LONG
  328. GetProductType(PRODUCT_TYPE *ppt)
  329. {
  330. return GetProductTypeAndSku(ppt, NULL);
  331. }
  332. DWORD
  333. RasStartRasAutoIfRequired()
  334. {
  335. SC_HANDLE schandle = NULL;
  336. SC_HANDLE svchandle = NULL;
  337. SERVICE_STATUS status;
  338. DWORD dwErr = SUCCESS;
  339. BOOL fServiceStarted = FALSE;
  340. BOOL fConsumer = FALSE;
  341. if(g_fRasAutoStarted)
  342. {
  343. RasmanOutputDebug(
  344. "StartRasAuto: RasAuto already started. pid=%d\n", _getpid());
  345. goto done;
  346. }
  347. //
  348. // Check to see if this is a consumer platform
  349. // Return if not.
  350. //
  351. fConsumer = IsConsumerPlatform();
  352. if(! fConsumer)
  353. {
  354. RasmanOutputDebug(
  355. "StartRasAuto: not a consumer platform. pid=%d\n", _getpid());
  356. goto done;
  357. }
  358. else
  359. {
  360. RasmanOutputDebug(
  361. "StartRasAuto: is consumer platform. pid=%d\n", _getpid());
  362. }
  363. if( !(schandle = OpenSCManager(NULL,
  364. NULL,
  365. SC_MANAGER_CONNECT))
  366. || !(svchandle = OpenService(schandle,
  367. TEXT("RasAuto"),
  368. SERVICE_START |
  369. SERVICE_QUERY_STATUS)))
  370. {
  371. dwErr = GetLastError();
  372. RasmanOutputDebug("StartRasAuto: Failed to open SCM/Service. dwErr=%d\n",
  373. dwErr);
  374. goto done;
  375. }
  376. while (TRUE)
  377. {
  378. //
  379. // Check if service is already starting:
  380. //
  381. if (QueryServiceStatus(svchandle, &status) == FALSE)
  382. {
  383. dwErr = GetLastError();
  384. goto done;
  385. }
  386. RasmanOutputDebug("StartRasAuto: ServiceStatus=%d\n",
  387. status.dwCurrentState);
  388. switch (status.dwCurrentState)
  389. {
  390. case SERVICE_STOPPED:
  391. {
  392. //
  393. // If we had previously tried to start the service
  394. // and failed. Quit
  395. //
  396. if (fServiceStarted)
  397. {
  398. RasmanOutputDebug("StartRasAuto: failed to start rasauto\n");
  399. dwErr = ERROR_RASAUTO_CANNOT_INITIALIZE;
  400. goto done;
  401. }
  402. RasmanOutputDebug("StartRasAuto: Starting RasAuto...\n");
  403. if (StartService (svchandle, 0, NULL) == FALSE)
  404. {
  405. dwErr = GetLastError() ;
  406. RasmanOutputDebug("StartRasAuto: StartService failed. rc=0x%x",
  407. dwErr);
  408. if(ERROR_SERVICE_ALREADY_RUNNING == dwErr)
  409. {
  410. dwErr = SUCCESS;
  411. }
  412. else if(SUCCESS != dwErr)
  413. {
  414. dwErr = ERROR_RASAUTO_CANNOT_INITIALIZE;
  415. goto done;
  416. }
  417. }
  418. fServiceStarted = TRUE;
  419. break;
  420. }
  421. case SERVICE_START_PENDING:
  422. {
  423. Sleep (500L) ;
  424. break ;
  425. }
  426. case SERVICE_RUNNING:
  427. {
  428. g_fRasAutoStarted = TRUE;
  429. goto done;
  430. }
  431. default:
  432. {
  433. dwErr = ERROR_RASAUTO_CANNOT_INITIALIZE;
  434. goto done;
  435. }
  436. }
  437. }
  438. done:
  439. if(NULL != schandle)
  440. {
  441. CloseServiceHandle(schandle);
  442. }
  443. if(NULL != svchandle)
  444. {
  445. CloseServiceHandle(svchandle);
  446. }
  447. RasmanOutputDebug("StartRasAuto: returning 0x%x\n",
  448. dwErr);
  449. return dwErr;
  450. }
  451. DWORD
  452. RasmanUninitialize()
  453. {
  454. DWORD dwRetcode = ERROR_SUCCESS;
  455. if (!IsRasmanProcess())
  456. {
  457. #if 0
  458. DbgPrint("RasmanUninitialize: Uninitializing rasman. pid=%d\n",
  459. GetCurrentProcessId());
  460. #endif
  461. //
  462. // Dereference rasman only if Ras was initialized in
  463. // this process
  464. //
  465. if (!g_fRasInitialized)
  466. {
  467. // DeleteCriticalSection(&g_csRequestBuffer);
  468. goto done;
  469. }
  470. RasReferenceRasman (FALSE);
  471. //
  472. // Disconnect from rasmans
  473. //
  474. if (g_hBinding)
  475. {
  476. DWORD dwErr;
  477. dwErr = RasRpcDisconnect (&g_hBinding);
  478. g_hBinding = NULL;
  479. }
  480. }
  481. else
  482. {
  483. //
  484. // Free rasmans dll if we loaded it i.e when in
  485. // mprouter process
  486. //
  487. if (hInstRasmans)
  488. {
  489. FreeLibrary (hInstRasmans);
  490. }
  491. hInstRasmans = NULL;
  492. }
  493. //
  494. // Terminate winsock.
  495. //
  496. if(g_fWinsockInitialized)
  497. {
  498. WSACleanup();
  499. g_fWinsockInitialized = FALSE;
  500. }
  501. g_fRasInitialized = FALSE;
  502. done:
  503. #if 0
  504. DbgPrint("\nRasmanUninitialize: uninitialized rasman\n");
  505. #endif
  506. return dwRetcode;
  507. }
  508. DWORD
  509. RasInitializeNoWait ()
  510. {
  511. hInstRasmans = NULL;
  512. g_fnServiceRequest = NULL;
  513. // GetStartupInfo(&startupinfo) ;
  514. if (IsRasmanProcess())
  515. {
  516. //
  517. // Load rasmans dll and initialize "ServiceRequest"
  518. // fn pointer
  519. //
  520. hInstRasmans = LoadLibrary ("rasmans.dll");
  521. if (NULL == hInstRasmans)
  522. {
  523. RasmanOutputDebug("RasIntializeNoWait: hInstRasmans==NULL!\n");
  524. return ERROR_RASMAN_CANNOT_INITIALIZE;
  525. }
  526. g_fnServiceRequest = GetProcAddress (hInstRasmans,
  527. TEXT("ServiceRequest"));
  528. if (NULL == g_fnServiceRequest)
  529. {
  530. FreeLibrary (hInstRasmans);
  531. RasmanOutputDebug("RasInitializeNoWait: g_fnServiceRequest==NULL!\n");
  532. return ERROR_RASMAN_CANNOT_INITIALIZE;
  533. }
  534. return SUCCESS;
  535. }
  536. //
  537. // Initialize winsock if we haven't done so already
  538. //
  539. if (!g_fWinsockInitialized)
  540. {
  541. int status = 0;
  542. WSADATA wsaData;
  543. status = WSAStartup(MAKEWORD(2,0), &wsaData);
  544. if(0 != status)
  545. {
  546. return WSAGetLastError();
  547. }
  548. g_fWinsockInitialized = TRUE;
  549. }
  550. return SUCCESS ;
  551. }
  552. /*++
  553. Routine Description:
  554. Called to map the shared space into the attaching process.
  555. Arguments:
  556. Return Value:
  557. SUCCESS
  558. --*/
  559. DWORD
  560. RasInitialize ()
  561. {
  562. SC_HANDLE schandle = NULL;
  563. SC_HANDLE svchandle = NULL;
  564. SERVICE_STATUS status ;
  565. BOOL fRasmanStarted = FALSE;
  566. DWORD dwErr = ERROR_SUCCESS;
  567. dwErr = RasInitializeNoWait ();
  568. if (dwErr)
  569. {
  570. goto done;
  571. }
  572. //
  573. // Get handles to check status of service and
  574. // (if it is not started -) to start it.
  575. //
  576. if ( !(schandle = OpenSCManager(NULL,
  577. NULL,
  578. SC_MANAGER_CONNECT))
  579. || !(svchandle = OpenService(schandle,
  580. RASMAN_SERVICE_NAME,SERVICE_START
  581. |SERVICE_QUERY_STATUS)))
  582. {
  583. dwErr = GetLastError();
  584. goto done;
  585. }
  586. while (TRUE)
  587. {
  588. //
  589. // Check if service is already starting:
  590. //
  591. if (QueryServiceStatus(svchandle,&status) == FALSE)
  592. {
  593. dwErr = GetLastError();
  594. goto done;
  595. }
  596. switch (status.dwCurrentState)
  597. {
  598. case SERVICE_STOPPED:
  599. //
  600. // If we had previously tried to start rasman
  601. // and failed. Quit
  602. //
  603. if (fRasmanStarted)
  604. {
  605. RasmanOutputDebug("RasInitialize: SERVICE_STOPPED!\n");
  606. dwErr = ERROR_RASMAN_CANNOT_INITIALIZE;
  607. goto done;
  608. }
  609. if (StartService (svchandle, 0, NULL) == FALSE)
  610. {
  611. GlobalError = GetLastError() ;
  612. RasmanOutputDebug("RasInitialize: StartService returned 0x%x\n",
  613. GlobalError);
  614. if(ERROR_SERVICE_ALREADY_RUNNING == GlobalError)
  615. {
  616. GlobalError = SUCCESS;
  617. }
  618. else if(SUCCESS != dwErr)
  619. {
  620. dwErr = ERROR_RASMAN_CANNOT_INITIALIZE;
  621. goto done;
  622. }
  623. }
  624. fRasmanStarted = TRUE;
  625. break;
  626. case SERVICE_START_PENDING:
  627. Sleep (500L) ;
  628. break ;
  629. case SERVICE_RUNNING:
  630. {
  631. BOOL fRasmanProcess = IsRasmanProcess();
  632. //
  633. // This means that local rpc server is already running
  634. // We should be able to connect to it if we haven't
  635. // already
  636. //
  637. if ( !fRasmanProcess
  638. && (NULL != g_hBinding))
  639. {
  640. goto done;
  641. }
  642. if(!fRasmanProcess)
  643. {
  644. #if 0
  645. DbgPrint("RasInitialize: Initializing rasman. pid %d\n",
  646. GetCurrentProcessId());
  647. #endif
  648. if (dwErr = RasRpcConnect (NULL, &g_hBinding))
  649. {
  650. RasmanOutputDebug ("RasInitialize: Failed to "
  651. "connect to local server. %d\n",
  652. dwErr);
  653. dwErr = ERROR_RASMAN_CANNOT_INITIALIZE;
  654. goto done;
  655. }
  656. }
  657. //
  658. // Reference rasman only if this is not running in
  659. // svchost.exe. Otherwise the service calling
  660. // RasInitialize explicitly references rasman.
  661. // Change this to be done in a more graceful
  662. // way.
  663. //
  664. // GetStartupInfo(&startupinfo) ;
  665. if (!fRasmanProcess)
  666. {
  667. if (dwErr = RasReferenceRasman(TRUE))
  668. {
  669. RasmanOutputDebug("RasInitialize: failed to "
  670. "reference rasman. %d\n",
  671. dwErr );
  672. dwErr = ERROR_RASMAN_CANNOT_INITIALIZE;
  673. goto done;
  674. }
  675. }
  676. g_fRasInitialized = TRUE;
  677. goto done;
  678. }
  679. default:
  680. RasmanOutputDebug("RasInitialize: Invalid service.status=%d\n",
  681. status.dwCurrentState);
  682. dwErr = ERROR_RASMAN_CANNOT_INITIALIZE;
  683. break;
  684. }
  685. }
  686. done:
  687. if(NULL != schandle)
  688. {
  689. CloseServiceHandle(schandle);
  690. }
  691. if(NULL != svchandle)
  692. {
  693. CloseServiceHandle(svchandle);
  694. }
  695. return dwErr ;
  696. }
  697. /*++
  698. Routine Description:
  699. Opens Port for which name is specified.
  700. Arguments:
  701. Return Value:
  702. SUCCESS
  703. ERROR_PORT_ALREADY_OPEN
  704. ERROR_PORT_NOT_FOUND
  705. --*/
  706. DWORD APIENTRY
  707. RasPortOpen ( PCHAR portname,
  708. HPORT* porthandle,
  709. HANDLE notifier)
  710. {
  711. DWORD pid ;
  712. pid = GetCurrentProcessId() ;
  713. return SubmitRequest( NULL,
  714. REQTYPE_PORTOPEN,
  715. portname,
  716. notifier,
  717. pid,
  718. TRUE,
  719. porthandle);
  720. }
  721. DWORD APIENTRY
  722. RasPortOpenEx(CHAR *pszDeviceName,
  723. DWORD dwDeviceLineCounter,
  724. HPORT *phport,
  725. HANDLE hnotifier,
  726. DWORD *pdwUsageFlags)
  727. {
  728. DWORD retcode =
  729. SubmitRequest(NULL,
  730. REQTYPE_PORTOPENEX,
  731. pszDeviceName,
  732. dwDeviceLineCounter,
  733. hnotifier,
  734. TRUE,
  735. pdwUsageFlags,
  736. phport);
  737. //
  738. // If user name is not NULL and password is
  739. // NULL and this is not the svchost process,
  740. // get the user sid and save it in the ports
  741. // user data
  742. //
  743. if( (ERROR_SUCCESS == retcode)
  744. && (!IsRasmanProcess()))
  745. {
  746. DWORD dwErr;
  747. PWCHAR pszSid = LocalAlloc(LPTR, 5000);
  748. if(NULL != pszSid)
  749. {
  750. dwErr = GetUserSid(pszSid, 5000);
  751. if(ERROR_SUCCESS == dwErr)
  752. {
  753. dwErr = RasSetPortUserData(
  754. *phport,
  755. PORT_USERSID_INDEX,
  756. (PBYTE) pszSid,
  757. 5000);
  758. }
  759. LocalFree(pszSid);
  760. }
  761. else
  762. {
  763. RasmanOutputDebug("RASMAN: RasPppStart: failed to allocate sid\n");
  764. }
  765. }
  766. return retcode;
  767. }
  768. /*++
  769. Routine Description:
  770. Opens Port for which name is specified.
  771. Arguments:
  772. Return Value:
  773. SUCCESS
  774. ERROR_PORT_ALREADY_OPEN
  775. ERROR_PORT_NOT_FOUND
  776. --*/
  777. DWORD APIENTRY
  778. RasPortReserve (PCHAR portname, HPORT* porthandle)
  779. {
  780. DWORD pid ;
  781. pid = GetCurrentProcessId() ;
  782. return SubmitRequest( NULL,
  783. REQTYPE_PORTOPEN,
  784. portname,
  785. NULL,
  786. pid,
  787. FALSE,
  788. porthandle) ;
  789. }
  790. /*++
  791. Routine Description:
  792. Opens Port for which name is specified.
  793. Arguments:
  794. Return Value:
  795. SUCCESS
  796. ERROR_PORT_ALREADY_OPEN
  797. ERROR_PORT_NOT_FOUND
  798. --*/
  799. DWORD APIENTRY
  800. RasPortFree (HPORT porthandle)
  801. {
  802. DWORD pid ;
  803. pid = GetCurrentProcessId() ;
  804. if (ValidatePortHandle (porthandle) == FALSE)
  805. {
  806. return ERROR_INVALID_PORT_HANDLE ;
  807. }
  808. return SubmitRequest ( NULL,
  809. REQTYPE_PORTCLOSE,
  810. porthandle,
  811. pid,
  812. FALSE) ;
  813. }
  814. /*++
  815. Routine Description:
  816. Closes the Port for which the handle is specified.
  817. Arguments:
  818. Return Value:
  819. SUCCESS
  820. ERROR_INVALID_PORT_HANDLE
  821. --*/
  822. DWORD APIENTRY
  823. RasPortClose (HPORT porthandle)
  824. {
  825. DWORD pid ;
  826. pid = GetCurrentProcessId() ;
  827. if (ValidatePortHandle (porthandle) == FALSE)
  828. {
  829. return ERROR_INVALID_PORT_HANDLE ;
  830. }
  831. return SubmitRequest ( NULL,
  832. REQTYPE_PORTCLOSE,
  833. porthandle,
  834. pid,
  835. TRUE) ;
  836. }
  837. /*++
  838. Routine Description:
  839. Enumerates all the Ports configured for RAS.
  840. Arguments:
  841. Return Value:
  842. SUCCESS
  843. ERROR_BUFFER_TOO_SMALL
  844. --*/
  845. DWORD APIENTRY
  846. RasPortEnum (HANDLE hConnection,
  847. PBYTE buffer,
  848. PDWORD size,
  849. PDWORD entries)
  850. {
  851. DWORD dwError = SUCCESS;
  852. RAS_RPC *pRasRpcConnection = (RAS_RPC *) hConnection;
  853. PBYTE buffer40 = NULL;
  854. PBYTE buffer32 = NULL;
  855. DWORD dwSize32 = 0;
  856. DWORD dwsize40 = 0;
  857. if(!ValidateConnectionHandle(hConnection))
  858. {
  859. dwError = E_INVALIDARG;
  860. goto done;
  861. }
  862. //
  863. // If the request is for a remote server and the server
  864. // version is 4.0 - steelhead, then defer to the old way
  865. // of getting this information since rasman has become
  866. // a rpc server only in version 50.
  867. //
  868. if( NULL != pRasRpcConnection
  869. && VERSION_40 == pRasRpcConnection->dwVersion)
  870. {
  871. //
  872. // Allocate 40 buffer
  873. //
  874. if(buffer != NULL)
  875. {
  876. dwsize40 = sizeof(RASMAN_PORT_400)
  877. * ((*size)/sizeof(RASMAN_PORT));
  878. buffer40 = LocalAlloc(LPTR, dwsize40);
  879. if(NULL == buffer40)
  880. {
  881. dwError = GetLastError();
  882. goto done;
  883. }
  884. }
  885. dwError = RemoteRasPortEnum(hConnection,
  886. buffer40,
  887. &dwsize40,
  888. entries);
  889. if(ERROR_SUCCESS == dwError)
  890. {
  891. DWORD i;
  892. RASMAN_PORT *pPort = (RASMAN_PORT *) buffer;
  893. RASMAN_PORT_400 *pPort400 = (RASMAN_PORT_400 *) buffer40;
  894. //
  895. // Copy over the information from the 40 buffer
  896. // to 50 buffer
  897. //
  898. for(i = 0; i < *entries; i++)
  899. {
  900. pPort[i].P_Handle = pPort400[i].P_Handle;
  901. strcpy(pPort[i].P_PortName,
  902. pPort400[i].P_PortName);
  903. pPort[i].P_Status = pPort400[i].P_Status;
  904. pPort[i].P_ConfiguredUsage =
  905. pPort400[i].P_ConfiguredUsage;
  906. pPort[i].P_CurrentUsage = pPort400[i].P_CurrentUsage;
  907. strcpy(pPort[i].P_MediaName,
  908. pPort400[i].P_MediaName);
  909. strcpy(pPort[i].P_DeviceType,
  910. pPort400[i].P_DeviceType);
  911. strcpy(pPort[i].P_DeviceName,
  912. pPort400[i].P_DeviceName);
  913. pPort[i].P_LineDeviceId = pPort400[i].P_LineDeviceId;
  914. pPort[i].P_AddressId = pPort400[i].P_AddressId;
  915. if(0 == _stricmp(pPort400[i].P_DeviceType,
  916. "modem"))
  917. {
  918. pPort->P_rdtDeviceType = RDT_Modem;
  919. }
  920. else if(0 == _stricmp(pPort400[i].P_DeviceType,
  921. "isdn"))
  922. {
  923. pPort->P_rdtDeviceType = RDT_Isdn;
  924. }
  925. else if(0 == _stricmp(pPort400[i].P_DeviceType,
  926. "x25"))
  927. {
  928. pPort->P_rdtDeviceType = RDT_X25;
  929. }
  930. else if(0 == _stricmp(pPort400[i].P_DeviceType,
  931. "vpn"))
  932. {
  933. pPort->P_rdtDeviceType = RDT_Tunnel_Pptp | RDT_Tunnel;
  934. }
  935. else
  936. {
  937. pPort->P_rdtDeviceType = RDT_Other;
  938. }
  939. }
  940. }
  941. else if(ERROR_BUFFER_TOO_SMALL == dwError)
  942. {
  943. *size = sizeof(RASMAN_PORT)
  944. * (dwsize40/sizeof(RASMAN_PORT_400));
  945. }
  946. }
  947. else
  948. {
  949. //
  950. // Thunk the ports structure
  951. //
  952. if(NULL == size)
  953. {
  954. dwError = E_INVALIDARG;
  955. goto done;
  956. }
  957. dwSize32 = (*size/sizeof(RASMAN_PORT)) * sizeof(RASMAN_PORT_32);
  958. if(0 != dwSize32)
  959. {
  960. buffer32 = LocalAlloc(LPTR, dwSize32);
  961. if(NULL == buffer32)
  962. {
  963. dwError = E_OUTOFMEMORY;
  964. goto done;
  965. }
  966. }
  967. dwError = SubmitRequest(hConnection,
  968. REQTYPE_PORTENUM,
  969. &dwSize32, //size,
  970. buffer32, //buffer,
  971. entries) ;
  972. if( (dwError != ERROR_SUCCESS)
  973. && (dwError != ERROR_BUFFER_TOO_SMALL))
  974. {
  975. goto done;
  976. }
  977. if(*size < (dwSize32/sizeof(RASMAN_PORT_32)) * sizeof(RASMAN_PORT))
  978. {
  979. dwError = ERROR_BUFFER_TOO_SMALL;
  980. }
  981. *size = (dwSize32/sizeof(RASMAN_PORT_32)) * sizeof(RASMAN_PORT);
  982. if(ERROR_SUCCESS == dwError)
  983. {
  984. DWORD i;
  985. RASMAN_PORT *pPort;
  986. RASMAN_PORT_32 *pPort32;
  987. #if defined (_WIN64)
  988. //
  989. // Thunk the rasman port structures
  990. //
  991. for(i = 0; i < *entries; i++)
  992. {
  993. pPort = &((RASMAN_PORT *) buffer)[i];
  994. pPort32 = &((RASMAN_PORT_32 *) buffer32 )[i];
  995. //
  996. // Copy handle
  997. //
  998. pPort->P_Handle = UlongToHandle(pPort32->P_Port);
  999. //
  1000. // Copy rest of the structure - this should be the
  1001. // same for all platforms
  1002. //
  1003. CopyMemory(
  1004. (PBYTE) pPort + FIELD_OFFSET(RASMAN_PORT, P_PortName),
  1005. (PBYTE) pPort32 + FIELD_OFFSET(RASMAN_PORT_32, P_PortName),
  1006. sizeof(RASMAN_PORT_32) - sizeof(DWORD));
  1007. }
  1008. #else
  1009. if(NULL != buffer32)
  1010. CopyMemory(buffer, buffer32, *size);
  1011. #endif
  1012. }
  1013. }
  1014. done:
  1015. if(NULL != buffer40)
  1016. {
  1017. LocalFree(buffer40);
  1018. }
  1019. if(NULL != buffer32)
  1020. {
  1021. LocalFree(buffer32);
  1022. }
  1023. return dwError;
  1024. }
  1025. /*++
  1026. Routine Description:
  1027. Gets parameters (info) for the Port for which handle
  1028. is supplied
  1029. Arguments:
  1030. Return Value:
  1031. SUCCESS
  1032. ERROR_BUFFER_TOO_SMALL
  1033. ERROR_INVALID_PORT_HANDLE
  1034. --*/
  1035. DWORD APIENTRY
  1036. RasPortGetInfo ( HANDLE hConnection,
  1037. HPORT porthandle,
  1038. PBYTE buffer,
  1039. PDWORD size)
  1040. {
  1041. DWORD dwError = SUCCESS;
  1042. RAS_RPC *pRasRpcConnection = (RAS_RPC *) hConnection;
  1043. if (ValidatePortHandle (porthandle) == FALSE)
  1044. {
  1045. dwError = ERROR_INVALID_PORT_HANDLE;
  1046. goto done;
  1047. }
  1048. if(!ValidateConnectionHandle(hConnection))
  1049. {
  1050. dwError = E_INVALIDARG;
  1051. goto done;
  1052. }
  1053. //
  1054. // If the request is for a remote server and the server
  1055. // version is 4.0 - steelhead, then defer to the old way
  1056. // of getting this information since rasman has become
  1057. // a rpc server only in version 50.
  1058. //
  1059. if( NULL != pRasRpcConnection
  1060. && VERSION_40 == pRasRpcConnection->dwVersion)
  1061. {
  1062. dwError = RemoteRasPortGetInfo(hConnection,
  1063. porthandle,
  1064. buffer,
  1065. size);
  1066. }
  1067. else
  1068. {
  1069. dwError = SubmitRequest(hConnection,
  1070. REQTYPE_PORTGETINFO,
  1071. porthandle,
  1072. buffer,
  1073. size);
  1074. }
  1075. done:
  1076. return dwError;
  1077. }
  1078. /*++
  1079. Routine Description:
  1080. Sets parameters (info) for the Port for which handle
  1081. is supplied
  1082. Arguments:
  1083. Return Value:
  1084. SUCCESS
  1085. ERROR_CANNOT_SET_PORT_INFO
  1086. ERROR_WRONG_INFO_SPECIFIED
  1087. ERROR_INVALID_PORT_HANDLE
  1088. --*/
  1089. DWORD APIENTRY
  1090. RasPortSetInfo (HPORT porthandle,
  1091. RASMAN_PORTINFO* info)
  1092. {
  1093. DWORD size=info->PI_NumOfParams*sizeof(RAS_PARAMS) ;
  1094. if (ValidatePortHandle (porthandle) == FALSE)
  1095. {
  1096. return ERROR_INVALID_PORT_HANDLE ;
  1097. }
  1098. return SubmitRequest ( NULL,
  1099. REQTYPE_PORTSETINFO,
  1100. porthandle,
  1101. info) ;
  1102. }
  1103. /*++
  1104. Routine Description:
  1105. Disconnects the port for which handle is supplied.
  1106. Arguments:
  1107. Return Value:
  1108. PENDING
  1109. ERROR_NOT_CONNECTED
  1110. ERROR_EVENT_INVALID
  1111. ERROR_INVALID_PORT_HANDLE
  1112. anything GetLastError returns from CreateEvent calls
  1113. --*/
  1114. DWORD APIENTRY
  1115. RasPortDisconnect (HPORT porthandle,
  1116. HANDLE winevent)
  1117. {
  1118. DWORD pid ;
  1119. HANDLE hEvent;
  1120. DWORD dwError;
  1121. BOOL fCreateEvent = FALSE;
  1122. if (ValidatePortHandle (porthandle) == FALSE)
  1123. {
  1124. dwError = ERROR_INVALID_PORT_HANDLE ;
  1125. goto done;
  1126. }
  1127. fCreateEvent = !!(INVALID_HANDLE_VALUE == winevent);
  1128. if (fCreateEvent)
  1129. {
  1130. hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
  1131. if (NULL == hEvent)
  1132. {
  1133. fCreateEvent = FALSE;
  1134. dwError = GetLastError();
  1135. goto done;
  1136. }
  1137. }
  1138. else
  1139. {
  1140. hEvent = winevent;
  1141. }
  1142. pid = GetCurrentProcessId () ;
  1143. dwError = SubmitRequest( NULL,
  1144. REQTYPE_PORTDISCONNECT,
  1145. porthandle,
  1146. hEvent,
  1147. pid);
  1148. if ( fCreateEvent
  1149. && PENDING == dwError)
  1150. {
  1151. //
  1152. // Wait till the pending operation
  1153. // is done. We are making this call synchronous.
  1154. //
  1155. WaitForSingleObject(hEvent, INFINITE);
  1156. //
  1157. //clear the pending error
  1158. //
  1159. dwError = SUCCESS;
  1160. }
  1161. if (ERROR_ALREADY_DISCONNECTING == dwError)
  1162. {
  1163. //
  1164. // hit the rare case where there is already
  1165. // a disconnect pending on this port and the
  1166. // event handle was thrown away. Sleep for
  1167. // 5s. before proceeding. The actual disconnect
  1168. // should have happened by then. The disconnect
  1169. // timeout is 10s in rasman.
  1170. //
  1171. Sleep(5000);
  1172. dwError = ERROR_SUCCESS;
  1173. }
  1174. done:
  1175. if (fCreateEvent)
  1176. {
  1177. CloseHandle(hEvent);
  1178. }
  1179. return dwError;
  1180. }
  1181. /*++
  1182. Routine Description:
  1183. Sends supplied buffer. If connected writes to RASHUB.
  1184. Else it writes to the port directly.
  1185. Arguments:
  1186. Return Value:
  1187. SUCCESS
  1188. ERROR_BUFFER_INVALID
  1189. ERROR_EVENT_INVALID
  1190. ERROR_INVALID_PORT_HANDLE
  1191. --*/
  1192. DWORD APIENTRY
  1193. RasPortSend ( HPORT porthandle,
  1194. PBYTE buffer,
  1195. DWORD size)
  1196. {
  1197. NDISWAN_IO_PACKET *pPacket;
  1198. SendRcvBuffer *pSendRcvBuffer;
  1199. if (ValidatePortHandle (porthandle) == FALSE)
  1200. {
  1201. return ERROR_INVALID_PORT_HANDLE ;
  1202. }
  1203. //
  1204. // Get Pointer to ndiswan io data
  1205. //
  1206. pPacket = CONTAINING_RECORD (buffer, NDISWAN_IO_PACKET, PacketData);
  1207. //
  1208. // Get Pointer to SendRcvBuffer
  1209. //
  1210. pSendRcvBuffer = CONTAINING_RECORD (pPacket, SendRcvBuffer, SRB_Packet);
  1211. return SubmitRequest( NULL,
  1212. REQTYPE_PORTSEND,
  1213. porthandle,
  1214. pSendRcvBuffer,
  1215. size );
  1216. }
  1217. /*++
  1218. Routine Description:
  1219. Receives in supplied buffer. If connected reads through
  1220. RASHUB. Else, it writes to the port directly.
  1221. Arguments:
  1222. Return Value:
  1223. PENDING
  1224. ERROR_BUFFER_INVALID
  1225. ERROR_EVENT_INVALID
  1226. ERROR_INVALID_PORT_HANDLE
  1227. --*/
  1228. DWORD APIENTRY
  1229. RasPortReceive ( HPORT porthandle,
  1230. PBYTE buffer,
  1231. PDWORD size,
  1232. DWORD timeout,
  1233. HANDLE winevent)
  1234. {
  1235. DWORD pid ;
  1236. NDISWAN_IO_PACKET *pPacket;
  1237. SendRcvBuffer *pSendRcvBuffer;
  1238. if (ValidatePortHandle (porthandle) == FALSE)
  1239. {
  1240. return ERROR_INVALID_PORT_HANDLE ;
  1241. }
  1242. pid = GetCurrentProcessId () ;
  1243. //
  1244. // Get Pointer to ndiswan io data
  1245. //
  1246. pPacket = CONTAINING_RECORD ( buffer, NDISWAN_IO_PACKET, PacketData );
  1247. //
  1248. // Get Pointer to SendRcvBuffer
  1249. //
  1250. pSendRcvBuffer = CONTAINING_RECORD ( pPacket, SendRcvBuffer, SRB_Packet );
  1251. return SubmitRequest ( NULL,
  1252. REQTYPE_PORTRECEIVE,
  1253. porthandle,
  1254. pSendRcvBuffer,
  1255. size,
  1256. timeout,
  1257. winevent,
  1258. pid) ;
  1259. }
  1260. DWORD APIENTRY
  1261. RasPortReceiveEx ( HPORT porthandle,
  1262. PBYTE buffer,
  1263. PDWORD size )
  1264. {
  1265. if (ValidatePortHandle (porthandle) == FALSE)
  1266. {
  1267. return ERROR_INVALID_PORT_HANDLE;
  1268. }
  1269. return SubmitRequest ( NULL,
  1270. REQTYPE_PORTRECEIVEEX,
  1271. porthandle,
  1272. buffer,
  1273. size);
  1274. }
  1275. /*++
  1276. Routine Description:
  1277. Cancels a previously pending receive
  1278. Arguments:
  1279. Return Value:
  1280. SUCCESS
  1281. ERROR_INVALID_PORT_HANDLE
  1282. --*/
  1283. DWORD APIENTRY
  1284. RasPortCancelReceive (HPORT porthandle)
  1285. {
  1286. if (ValidatePortHandle (porthandle) == FALSE)
  1287. {
  1288. return ERROR_INVALID_PORT_HANDLE ;
  1289. }
  1290. return SubmitRequest (NULL,
  1291. REQTYPE_CANCELRECEIVE,
  1292. porthandle) ;
  1293. }
  1294. /*++
  1295. Routine Description:
  1296. Posts a listen on the device connected to the port.
  1297. Arguments:
  1298. Return Value:
  1299. PENDING
  1300. ERROR_EVENT_INVALID
  1301. ERROR_INVALID_PORT_HANDLE
  1302. --*/
  1303. DWORD APIENTRY
  1304. RasPortListen( HPORT porthandle,
  1305. ULONG timeout,
  1306. HANDLE winevent)
  1307. {
  1308. DWORD pid ;
  1309. if (ValidatePortHandle (porthandle) == FALSE)
  1310. {
  1311. return ERROR_INVALID_PORT_HANDLE ;
  1312. }
  1313. pid = GetCurrentProcessId () ;
  1314. return SubmitRequest ( NULL,
  1315. REQTYPE_PORTLISTEN,
  1316. porthandle,
  1317. timeout,
  1318. winevent,
  1319. pid) ;
  1320. }
  1321. /*++
  1322. Routine Description:
  1323. Changes state of port to CONNECTED and does other
  1324. necessary switching.
  1325. Arguments:
  1326. Return Value:
  1327. SUCCESS
  1328. ERROR_INVALID_PORT_HANDLE
  1329. --*/
  1330. DWORD APIENTRY
  1331. RasPortConnectComplete (HPORT porthandle)
  1332. {
  1333. if (ValidatePortHandle (porthandle) == FALSE)
  1334. {
  1335. return ERROR_INVALID_PORT_HANDLE ;
  1336. }
  1337. return SubmitRequest ( NULL,
  1338. REQTYPE_PORTCONNECTCOMPLETE,
  1339. porthandle) ;
  1340. }
  1341. /*++
  1342. Routine Description:
  1343. Fetches statistics for the port for which the handle
  1344. is supplied
  1345. Arguments:
  1346. Return Value:
  1347. SUCCESS
  1348. ERROR_INVALID_PORT_HANDLE
  1349. --*/
  1350. DWORD APIENTRY
  1351. RasPortGetStatistics ( HANDLE hConnection,
  1352. HPORT porthandle,
  1353. PBYTE statbuffer,
  1354. PDWORD size)
  1355. {
  1356. DWORD dwError = SUCCESS;
  1357. if (ValidatePortHandle (porthandle) == FALSE)
  1358. {
  1359. dwError = ERROR_INVALID_PORT_HANDLE;
  1360. goto done;
  1361. }
  1362. if(!ValidateConnectionHandle(hConnection))
  1363. {
  1364. dwError = ERROR_INVALID_PORT_HANDLE;
  1365. goto done;
  1366. }
  1367. dwError = SubmitRequest ( hConnection,
  1368. REQTYPE_PORTGETSTATISTICS,
  1369. porthandle,
  1370. statbuffer,
  1371. size) ;
  1372. done:
  1373. return dwError;
  1374. }
  1375. /*++
  1376. Routine Description:
  1377. Fetches statistics for the bundle for which the handle
  1378. is supplied
  1379. Arguments:
  1380. Return Value:
  1381. SUCCESS
  1382. ERROR_INVALID_PORT_HANDLE
  1383. --*/
  1384. DWORD APIENTRY
  1385. RasBundleGetStatistics ( HANDLE hConnection,
  1386. HPORT porthandle,
  1387. PBYTE statbuffer,
  1388. PDWORD size)
  1389. {
  1390. DWORD dwError = SUCCESS;
  1391. if (ValidatePortHandle (porthandle) == FALSE)
  1392. {
  1393. dwError = ERROR_INVALID_PORT_HANDLE;
  1394. goto done;
  1395. }
  1396. if(!ValidateConnectionHandle(hConnection))
  1397. {
  1398. dwError = E_INVALIDARG;
  1399. goto done;
  1400. }
  1401. dwError = SubmitRequest (hConnection,
  1402. REQTYPE_BUNDLEGETSTATISTICS,
  1403. porthandle,
  1404. statbuffer,
  1405. size) ;
  1406. done:
  1407. return dwError;
  1408. }
  1409. DWORD APIENTRY
  1410. RasPortGetStatisticsEx ( HANDLE hConnection,
  1411. HPORT porthandle,
  1412. PBYTE statBuffer,
  1413. PDWORD size)
  1414. {
  1415. DWORD dwError = SUCCESS;
  1416. if (ValidatePortHandle (porthandle) == FALSE)
  1417. {
  1418. dwError = ERROR_INVALID_HANDLE;
  1419. goto done;
  1420. }
  1421. if(!ValidateConnectionHandle(hConnection))
  1422. {
  1423. dwError = E_INVALIDARG;
  1424. goto done;
  1425. }
  1426. dwError = SubmitRequest(hConnection,
  1427. REQTYPE_PORTGETSTATISTICSEX,
  1428. porthandle,
  1429. statBuffer,
  1430. size);
  1431. done:
  1432. return dwError;
  1433. }
  1434. DWORD APIENTRY
  1435. RasBundleGetStatisticsEx ( HANDLE hConnection,
  1436. HPORT portHandle,
  1437. PBYTE statbuffer,
  1438. PDWORD size)
  1439. {
  1440. DWORD dwError = SUCCESS;
  1441. if (ValidatePortHandle (portHandle) == FALSE)
  1442. {
  1443. dwError = ERROR_INVALID_PORT_HANDLE;
  1444. goto done;
  1445. }
  1446. if(!ValidateConnectionHandle(hConnection))
  1447. {
  1448. dwError = E_INVALIDARG;
  1449. goto done;
  1450. }
  1451. dwError = SubmitRequest ( hConnection,
  1452. REQTYPE_BUNDLEGETSTATISTICSEX,
  1453. portHandle,
  1454. statbuffer,
  1455. size);
  1456. done:
  1457. return dwError;
  1458. }
  1459. /*++
  1460. Routine Description:
  1461. Clears statistics for the port for which the handle
  1462. is supplied
  1463. Arguments:
  1464. Return Value:
  1465. SUCCESS
  1466. ERROR_INVALID_PORT_HANDLE
  1467. --*/
  1468. DWORD APIENTRY RasPortClearStatistics (HANDLE hConnection,
  1469. HPORT porthandle)
  1470. {
  1471. DWORD dwError = SUCCESS;
  1472. if (ValidatePortHandle (porthandle) == FALSE)
  1473. {
  1474. dwError = ERROR_INVALID_PORT_HANDLE;
  1475. goto done;
  1476. }
  1477. if(!ValidateConnectionHandle(hConnection))
  1478. {
  1479. dwError = E_INVALIDARG;
  1480. goto done;
  1481. }
  1482. dwError = SubmitRequest ( hConnection,
  1483. REQTYPE_PORTCLEARSTATISTICS,
  1484. porthandle) ;
  1485. done:
  1486. return dwError;
  1487. }
  1488. /*++
  1489. Routine Description:
  1490. Clears statistics for the bundle for which the
  1491. handle is supplied
  1492. Arguments:
  1493. Return Value:
  1494. SUCCESS
  1495. ERROR_INVALID_PORT_HANDLE
  1496. --*/
  1497. DWORD APIENTRY RasBundleClearStatistics(HANDLE hConnection,
  1498. HPORT porthandle)
  1499. {
  1500. DWORD dwError = SUCCESS;
  1501. if (ValidatePortHandle (porthandle) == FALSE)
  1502. {
  1503. dwError = ERROR_INVALID_PORT_HANDLE;
  1504. goto done;
  1505. }
  1506. if(!ValidateConnectionHandle(hConnection))
  1507. {
  1508. dwError = E_INVALIDARG;
  1509. goto done;
  1510. }
  1511. dwError = SubmitRequest ( hConnection,
  1512. REQTYPE_BUNDLECLEARSTATISTICS,
  1513. porthandle) ;
  1514. done:
  1515. return dwError;
  1516. }
  1517. DWORD APIENTRY RasBundleClearStatisticsEx(HANDLE hConnection,
  1518. HCONN hconn)
  1519. {
  1520. DWORD dwErr;
  1521. HPORT hPort;
  1522. dwErr = RasBundleGetPort(hConnection,
  1523. (HBUNDLE) hconn,
  1524. &hPort);
  1525. if (dwErr)
  1526. {
  1527. goto done;
  1528. }
  1529. dwErr = SubmitRequest ( hConnection,
  1530. REQTYPE_BUNDLECLEARSTATISTICS,
  1531. hPort);
  1532. done:
  1533. return dwErr;
  1534. }
  1535. /*++
  1536. Routine Description:
  1537. Enumerates all the devices of a device type.
  1538. Arguments:
  1539. Return Value:
  1540. SUCCESS
  1541. ERROR_DEVICE_DOES_NOT_EXIST
  1542. ERROR_BUFFER_TOO_SMALL
  1543. --*/
  1544. DWORD APIENTRY
  1545. RasDeviceEnum (HANDLE hConnection,
  1546. PCHAR devicetype,
  1547. PBYTE buffer,
  1548. PDWORD size,
  1549. PDWORD entries)
  1550. {
  1551. DWORD dwError = SUCCESS;
  1552. RAS_RPC *pRasRpcConnection = (RAS_RPC *) hConnection;
  1553. if(!ValidateConnectionHandle(hConnection))
  1554. {
  1555. dwError = E_INVALIDARG;
  1556. goto done;
  1557. }
  1558. //
  1559. // If the request is for a remote server and the server
  1560. // version is 4.0 - steelhead, then defer to the old way
  1561. // of getting this information since rasman has become
  1562. // a rpc server only in version 50.
  1563. //
  1564. if( pRasRpcConnection
  1565. && VERSION_40 == pRasRpcConnection->dwVersion)
  1566. {
  1567. dwError = RemoteRasDeviceEnum(hConnection,
  1568. devicetype,
  1569. buffer,
  1570. size,
  1571. entries);
  1572. }
  1573. else
  1574. {
  1575. dwError = SubmitRequest ( hConnection,
  1576. REQTYPE_DEVICEENUM,
  1577. devicetype,
  1578. size,
  1579. buffer,
  1580. entries
  1581. );
  1582. }
  1583. done:
  1584. return dwError;
  1585. }
  1586. /*++
  1587. Routine Description:
  1588. Gets info for the specified device.
  1589. Arguments:
  1590. Return Value:
  1591. SUCCESS
  1592. ERROR_INVALID_PORT_HANDLE
  1593. ERROR_DEVICETYPE_DOES_NOT_EXIST
  1594. ERROR_DEVICE_DOES_NOT_EXIST
  1595. ERROR_BUFFER_TOO_SMALL
  1596. --*/
  1597. DWORD APIENTRY
  1598. RasDeviceGetInfo ( HANDLE hConnection,
  1599. HPORT porthandle,
  1600. PCHAR devicetype,
  1601. PCHAR devicename,
  1602. PBYTE buffer,
  1603. PDWORD size)
  1604. {
  1605. DWORD dwError = SUCCESS;
  1606. if (ValidatePortHandle (porthandle) == FALSE)
  1607. {
  1608. dwError = ERROR_INVALID_PORT_HANDLE;
  1609. goto done;
  1610. }
  1611. if(!ValidateConnectionHandle(hConnection))
  1612. {
  1613. dwError = E_INVALIDARG;
  1614. goto done;
  1615. }
  1616. dwError = SubmitRequest ( hConnection,
  1617. REQTYPE_DEVICEGETINFO,
  1618. porthandle,
  1619. devicetype,
  1620. devicename,
  1621. buffer,
  1622. size) ;
  1623. done:
  1624. return dwError;
  1625. }
  1626. /*++
  1627. Routine Description:
  1628. Sets info for the specified device.
  1629. Arguments:
  1630. Return Value:
  1631. SUCCESS
  1632. ERROR_INVALID_PORT_HANDLE
  1633. ERROR_DEVICETYPE_DOES_NOT_EXIST
  1634. ERROR_DEVICE_DOES_NOT_EXIST
  1635. ERROR_INVALID_INFO_SPECIFIED
  1636. --*/
  1637. DWORD APIENTRY
  1638. RasDeviceSetInfo (HPORT porthandle,
  1639. PCHAR devicetype,
  1640. PCHAR devicename,
  1641. RASMAN_DEVICEINFO* info)
  1642. {
  1643. DWORD i,
  1644. dwOldIndex,
  1645. dwcbOldString = 0,
  1646. retcode;
  1647. PCHAR szOldString = NULL;
  1648. BOOL fVpn = FALSE;
  1649. RASMAN_INFO ri;
  1650. if (ValidatePortHandle (porthandle) == FALSE)
  1651. {
  1652. return ERROR_INVALID_PORT_HANDLE ;
  1653. }
  1654. retcode = RasGetInfo(NULL,
  1655. porthandle,
  1656. &ri);
  1657. if(ERROR_SUCCESS == retcode)
  1658. {
  1659. if(0 == _stricmp(ri.RI_szDeviceType,
  1660. "vpn"))
  1661. {
  1662. fVpn = TRUE;
  1663. }
  1664. }
  1665. if (fVpn)
  1666. {
  1667. for (i = 0; i < info->DI_NumOfParams; i++)
  1668. {
  1669. //
  1670. // We're only looking for the
  1671. // MXS_PHONENUMBER_KEY key.
  1672. //
  1673. if ( info->DI_Params[i].P_Type != String
  1674. || _stricmp(info->DI_Params[i].P_Key,
  1675. MXS_PHONENUMBER_KEY))
  1676. {
  1677. continue;
  1678. }
  1679. //
  1680. // We found it. If the phone number is a
  1681. // DNS address, convert it to an IP address.
  1682. //
  1683. if (inet_addr(info->DI_Params[i].P_Value.String.Data)
  1684. == -1L)
  1685. {
  1686. struct hostent *hostp;
  1687. DWORD dwErr;
  1688. DWORD *pdwAddress;
  1689. DWORD cAddresses;
  1690. DWORD dwAddress;
  1691. dwErr = DwRasGetHostByName(
  1692. info->DI_Params[i].P_Value.String.Data,
  1693. &pdwAddress,
  1694. &cAddresses);
  1695. //
  1696. // If gethostbyname() succeeds, then replace
  1697. // the DNS address with the IP address.
  1698. //
  1699. /*
  1700. hostp = gethostbyname(
  1701. info->DI_Params[i].P_Value.String.Data
  1702. );
  1703. */
  1704. if ( (SUCCESS == dwErr)
  1705. && (0 != cAddresses)
  1706. && (0 != (dwAddress = *pdwAddress)))
  1707. {
  1708. struct in_addr in;
  1709. in.s_addr = dwAddress;
  1710. //
  1711. // We save the old string value away,
  1712. // and set the new value. The old
  1713. // value will be restored after the
  1714. // call to SubmitRequest(). This works
  1715. // because SubmitRequest() has to copy
  1716. // the user's params anyway.
  1717. //
  1718. szOldString =
  1719. info->DI_Params[i].P_Value.String.Data;
  1720. dwcbOldString =
  1721. info->DI_Params[i].P_Value.String.Length;
  1722. info->DI_Params[i].P_Value.String.Data =
  1723. inet_ntoa(in);
  1724. info->DI_Params[i].P_Value.String.Length =
  1725. strlen(info->DI_Params[i].P_Value.String.Data);
  1726. dwOldIndex = i;
  1727. }
  1728. if(NULL != pdwAddress)
  1729. {
  1730. LocalFree(pdwAddress);
  1731. }
  1732. }
  1733. }
  1734. }
  1735. retcode = SubmitRequest ( NULL,
  1736. REQTYPE_DEVICESETINFO,
  1737. porthandle,
  1738. devicetype,
  1739. devicename,
  1740. info) ;
  1741. if (dwcbOldString)
  1742. {
  1743. info->DI_Params[dwOldIndex].P_Value.String.Data =
  1744. szOldString;
  1745. info->DI_Params[dwOldIndex].P_Value.String.Length =
  1746. dwcbOldString;
  1747. }
  1748. return retcode;
  1749. }
  1750. /*++
  1751. Routine Description:
  1752. Connects through the device specified.
  1753. Arguments:
  1754. Return Value:
  1755. PENDING
  1756. ERROR_INVALID_PORT_HANDLE
  1757. ERROR_DEVICETYPE_DOES_NOT_EXIST
  1758. ERROR_DEVICE_DOES_NOT_EXIST
  1759. ERROR_INVALID_INFO_SPECIFIED
  1760. --*/
  1761. DWORD APIENTRY
  1762. RasDeviceConnect ( HPORT porthandle,
  1763. PCHAR devicetype,
  1764. PCHAR devicename,
  1765. ULONG timeout,
  1766. HANDLE winevent)
  1767. {
  1768. DWORD pid ;
  1769. if (ValidatePortHandle (porthandle) == FALSE)
  1770. {
  1771. return ERROR_INVALID_PORT_HANDLE ;
  1772. }
  1773. pid = GetCurrentProcessId () ;
  1774. return SubmitRequest ( NULL,
  1775. REQTYPE_DEVICECONNECT,
  1776. porthandle,
  1777. devicetype,
  1778. devicename,
  1779. timeout,
  1780. winevent,
  1781. pid) ;
  1782. }
  1783. /*++
  1784. Routine Description:
  1785. Gets general info for the port for which handle is
  1786. supplied.
  1787. Arguments:
  1788. Return Value:
  1789. SUCCESS
  1790. ERROR_INVALID_PORT_HANDLE
  1791. --*/
  1792. DWORD APIENTRY
  1793. RasGetInfo (HANDLE hConnection,
  1794. HPORT porthandle,
  1795. RASMAN_INFO* info)
  1796. {
  1797. DWORD dwError = SUCCESS;
  1798. if (ValidatePortHandle (porthandle) == FALSE)
  1799. {
  1800. dwError = ERROR_INVALID_PORT_HANDLE;
  1801. goto done;
  1802. }
  1803. if(!ValidateConnectionHandle(hConnection))
  1804. {
  1805. dwError = E_INVALIDARG;
  1806. goto done;
  1807. }
  1808. dwError = SubmitRequest ( hConnection,
  1809. REQTYPE_GETINFO,
  1810. porthandle,
  1811. info) ;
  1812. done:
  1813. return dwError;
  1814. }
  1815. /*++
  1816. Routine Description:
  1817. Gets general info for all the ports.
  1818. Arguments:
  1819. Return Value:
  1820. SUCCESS
  1821. --*/
  1822. DWORD APIENTRY
  1823. RasGetInfoEx (HANDLE hConnection,
  1824. RASMAN_INFO* info,
  1825. PWORD entries)
  1826. {
  1827. return ERROR_NOT_SUPPORTED;
  1828. #if 0
  1829. DWORD dwError = SUCCESS;
  1830. if (info == NULL)
  1831. {
  1832. dwError = ERROR_BUFFER_TOO_SMALL;
  1833. goto done;
  1834. }
  1835. if(!ValidateConnectionHandle(hConnection))
  1836. {
  1837. dwError = E_INVALIDARG;
  1838. goto done;
  1839. }
  1840. dwError = SubmitRequest (hConnection,
  1841. REQTYPE_GETINFOEX,
  1842. info) ;
  1843. done:
  1844. return dwError;
  1845. #endif
  1846. }
  1847. /*++
  1848. Routine Description:
  1849. Gets a buffer to be used with send and receive.
  1850. Arguments:
  1851. Return Value:
  1852. SUCCESS
  1853. ERROR_OUT_OF_BUFFERS
  1854. --*/
  1855. DWORD APIENTRY
  1856. RasGetBuffer (PBYTE* buffer, PDWORD size)
  1857. {
  1858. HANDLE handle = NULL;
  1859. DWORD retcode = SUCCESS;
  1860. SendRcvBuffer *pSendRcvBuffer = NULL;
  1861. handle = OpenNamedMutexHandle ( SENDRCVMUTEXOBJECT );
  1862. if (NULL == handle)
  1863. {
  1864. retcode = GetLastError();
  1865. RasmanOutputDebug ("RASMAN: RasGetBuffer Failed to open"
  1866. " mutex. %d\n",
  1867. retcode);
  1868. goto done;
  1869. }
  1870. WaitForSingleObject (handle, INFINITE);
  1871. //
  1872. // Alloc a buffer
  1873. //
  1874. pSendRcvBuffer = LocalAlloc (LPTR,
  1875. sizeof (SendRcvBuffer));
  1876. if (NULL == pSendRcvBuffer)
  1877. {
  1878. retcode = GetLastError();
  1879. RasmanOutputDebug ("RASMAN: RasGetBuffer Failed to "
  1880. "allocate. %d\n",
  1881. retcode);
  1882. goto done;
  1883. }
  1884. pSendRcvBuffer->SRB_Pid = GetCurrentProcessId();
  1885. *size = (*size < MAX_SENDRCVBUFFER_SIZE)
  1886. ? *size
  1887. : MAX_SENDRCVBUFFER_SIZE;
  1888. *buffer = pSendRcvBuffer->SRB_Packet.PacketData;
  1889. done:
  1890. if (handle)
  1891. {
  1892. ReleaseMutex (handle);
  1893. CloseHandle (handle);
  1894. }
  1895. return retcode ;
  1896. }
  1897. /*++
  1898. Routine Description:
  1899. Frees a buffer gotten earlier with RasGetBuffer()
  1900. Arguments:
  1901. Return Value:
  1902. SUCCESS
  1903. ERROR_BUFFER_INVALID
  1904. --*/
  1905. DWORD APIENTRY
  1906. RasFreeBuffer (PBYTE buffer)
  1907. {
  1908. HANDLE handle;
  1909. DWORD retcode = SUCCESS;
  1910. SendRcvBuffer *pSendRcvBuffer;
  1911. NDISWAN_IO_PACKET *pPacket;
  1912. handle = OpenNamedMutexHandle (SENDRCVMUTEXOBJECT);
  1913. if (NULL == handle)
  1914. {
  1915. retcode = GetLastError();
  1916. RasmanOutputDebug ("RASMAN: RasFreeBuffer Failed to"
  1917. " OpenMutex. %d\n", retcode);
  1918. goto done;
  1919. }
  1920. WaitForSingleObject (handle, INFINITE);
  1921. //
  1922. // Get Pointer to ndiswan io data
  1923. //
  1924. pPacket = CONTAINING_RECORD(buffer, NDISWAN_IO_PACKET, PacketData);
  1925. //
  1926. // Get Pointer to SendRcvBuffer
  1927. //
  1928. pSendRcvBuffer = CONTAINING_RECORD(pPacket, SendRcvBuffer, SRB_Packet);
  1929. LocalFree (pSendRcvBuffer);
  1930. ReleaseMutex(handle);
  1931. CloseHandle(handle);
  1932. done:
  1933. return retcode ;
  1934. }
  1935. /*++
  1936. Routine Description:
  1937. Retrieves information about protocols configured
  1938. in the system.
  1939. Arguments:
  1940. Return Value:
  1941. SUCCESS
  1942. ERROR_BUFFER_TOO_SMALL
  1943. --*/
  1944. DWORD APIENTRY
  1945. RasProtocolEnum ( PBYTE buffer,
  1946. PDWORD size,
  1947. PDWORD entries)
  1948. {
  1949. return SubmitRequest ( NULL,
  1950. REQTYPE_PROTOCOLENUM,
  1951. size,
  1952. buffer,
  1953. entries) ;
  1954. }
  1955. /*++
  1956. Routine Description:
  1957. Allocates a route (binding) without actually activating it.
  1958. Arguments:
  1959. Return Value:
  1960. SUCCESS
  1961. ERROR_INVALID_PORT_HANDLE
  1962. ERROR_ROUTE_NOT_AVAILABLE
  1963. --*/
  1964. DWORD APIENTRY
  1965. RasAllocateRoute ( HPORT porthandle,
  1966. RAS_PROTOCOLTYPE type,
  1967. BOOL wrknet,
  1968. RASMAN_ROUTEINFO* info)
  1969. {
  1970. if (ValidatePortHandle (porthandle) == FALSE)
  1971. {
  1972. return ERROR_INVALID_PORT_HANDLE ;
  1973. }
  1974. //
  1975. // Even though this can be done by this process - we pass
  1976. // this on to the requestor thread since we get the
  1977. // serialization for free.
  1978. //
  1979. return SubmitRequest ( NULL,
  1980. REQTYPE_ALLOCATEROUTE,
  1981. porthandle,
  1982. type,
  1983. wrknet,
  1984. info) ;
  1985. }
  1986. /*++
  1987. Routine Description:
  1988. Activates a previously allocated route (binding).
  1989. Arguments:
  1990. Return Value:
  1991. SUCCESS
  1992. ERROR_INVALID_PORT_HANDLE
  1993. ERROR_ROUTE_NOT_AVAILABLE
  1994. --*/
  1995. DWORD APIENTRY
  1996. RasActivateRoute ( HPORT porthandle,
  1997. RAS_PROTOCOLTYPE type,
  1998. RASMAN_ROUTEINFO* info,
  1999. PROTOCOL_CONFIG_INFO *config)
  2000. {
  2001. if (ValidatePortHandle (porthandle) == FALSE)
  2002. {
  2003. return ERROR_INVALID_PORT_HANDLE ;
  2004. }
  2005. return SubmitRequest ( NULL,
  2006. REQTYPE_ACTIVATEROUTE,
  2007. porthandle,
  2008. type,
  2009. config,
  2010. info) ;
  2011. }
  2012. /*++
  2013. Routine Description:
  2014. Activates a previously allocated route (binding).
  2015. Allows you to set the max frame size as well
  2016. Arguments:
  2017. Return Value:
  2018. SUCCESS
  2019. ERROR_INVALID_PORT_HANDLE
  2020. ERROR_ROUTE_NOT_AVAILABLE
  2021. --*/
  2022. DWORD APIENTRY
  2023. RasActivateRouteEx ( HPORT porthandle,
  2024. RAS_PROTOCOLTYPE type,
  2025. DWORD framesize,
  2026. RASMAN_ROUTEINFO* info,
  2027. PROTOCOL_CONFIG_INFO *config)
  2028. {
  2029. if (ValidatePortHandle (porthandle) == FALSE)
  2030. {
  2031. return ERROR_INVALID_PORT_HANDLE ;
  2032. }
  2033. return SubmitRequest ( NULL,
  2034. REQTYPE_ACTIVATEROUTEEX,
  2035. porthandle,
  2036. type,
  2037. framesize,
  2038. config,
  2039. info) ;
  2040. }
  2041. /*++
  2042. Routine Description:
  2043. DeAllocates a route (binding) that was previously
  2044. activated.
  2045. Arguments:
  2046. Return Value:
  2047. SUCCESS
  2048. ERROR_INVALID_PORT_HANDLE
  2049. ERROR_ROUTE_NOT_ALLOCATED
  2050. --*/
  2051. DWORD APIENTRY
  2052. RasDeAllocateRoute ( HBUNDLE hbundle,
  2053. RAS_PROTOCOLTYPE type)
  2054. {
  2055. return SubmitRequest ( NULL,
  2056. REQTYPE_DEALLOCATEROUTE,
  2057. hbundle,
  2058. type) ;
  2059. }
  2060. /*++
  2061. Routine Description:
  2062. Gets compression information for the port.
  2063. Arguments:
  2064. Return Value:
  2065. SUCCESS
  2066. ERROR_INVALID_PORT_HANDLE
  2067. --*/
  2068. DWORD APIENTRY
  2069. RasCompressionGetInfo ( HPORT porthandle,
  2070. RAS_COMPRESSION_INFO *send,
  2071. RAS_COMPRESSION_INFO *recv)
  2072. {
  2073. if (ValidatePortHandle (porthandle) == FALSE)
  2074. {
  2075. return ERROR_INVALID_PORT_HANDLE ;
  2076. }
  2077. return SubmitRequest ( NULL,
  2078. REQTYPE_COMPRESSIONGETINFO,
  2079. porthandle,
  2080. send,
  2081. recv ) ;
  2082. }
  2083. /*++
  2084. Routine Description:
  2085. Sets compression information for the port.
  2086. Arguments:
  2087. Return Value:
  2088. SUCCESS
  2089. ERROR_INVALID_PORT_HANDLE
  2090. ERROR_INVALID_COMPRESSION_SPECIFIED
  2091. --*/
  2092. DWORD APIENTRY
  2093. RasCompressionSetInfo ( HPORT porthandle,
  2094. RAS_COMPRESSION_INFO *send,
  2095. RAS_COMPRESSION_INFO *recv)
  2096. {
  2097. if (ValidatePortHandle (porthandle) == FALSE)
  2098. {
  2099. return ERROR_INVALID_PORT_HANDLE ;
  2100. }
  2101. return SubmitRequest( NULL,
  2102. REQTYPE_COMPRESSIONSETINFO,
  2103. porthandle,
  2104. send,
  2105. recv) ;
  2106. }
  2107. /*++
  2108. Routine Description:
  2109. Gets user credentials (username, password) from LSA.
  2110. Arguments:
  2111. Return Value:
  2112. SUCCESS
  2113. Non zero (failure)
  2114. --*/
  2115. DWORD APIENTRY
  2116. RasGetUserCredentials(
  2117. PBYTE pChallenge,
  2118. PLUID LogonId,
  2119. PWCHAR UserName,
  2120. PBYTE CaseSensitiveChallengeResponse,
  2121. PBYTE CaseInsensitiveChallengeResponse,
  2122. PBYTE LMSessionKey,
  2123. PBYTE UserSessionKey
  2124. )
  2125. {
  2126. return SubmitRequest (
  2127. NULL,
  2128. REQTYPE_GETUSERCREDENTIALS,
  2129. pChallenge,
  2130. LogonId,
  2131. UserName,
  2132. CaseSensitiveChallengeResponse,
  2133. CaseInsensitiveChallengeResponse,
  2134. LMSessionKey,
  2135. UserSessionKey) ;
  2136. }
  2137. /*++
  2138. Routine Description:
  2139. Changes user's cached credentials with LSA.
  2140. Arguments:
  2141. Return Value:
  2142. SUCCESS
  2143. Non zero (failure)
  2144. --*/
  2145. DWORD APIENTRY
  2146. RasSetCachedCredentials(
  2147. PCHAR Account,
  2148. PCHAR Domain,
  2149. PCHAR NewPassword )
  2150. {
  2151. return
  2152. SubmitRequest(
  2153. NULL,
  2154. REQTYPE_SETCACHEDCREDENTIALS,
  2155. Account,
  2156. Domain,
  2157. NewPassword );
  2158. }
  2159. /*++
  2160. Routine Description:
  2161. A request event is assocaited with a port for signalling
  2162. Arguments:
  2163. Return Value:
  2164. SUCCESS
  2165. ERROR_EVENT_INVALID
  2166. ERROR_INVALID_PORT_HANDLE
  2167. --*/
  2168. DWORD APIENTRY
  2169. RasRequestNotification (HPORT porthandle, HANDLE winevent)
  2170. {
  2171. DWORD pid ;
  2172. if (ValidatePortHandle (porthandle) == FALSE)
  2173. {
  2174. return ERROR_INVALID_PORT_HANDLE ;
  2175. }
  2176. pid = GetCurrentProcessId () ;
  2177. return SubmitRequest ( NULL,
  2178. REQTYPE_REQUESTNOTIFICATION,
  2179. porthandle,
  2180. winevent,
  2181. pid) ;
  2182. }
  2183. /*++
  2184. Routine Description:
  2185. Gets the lan nets lana numbers read from the
  2186. registry by Rasman
  2187. Arguments:
  2188. Return Value:
  2189. SUCCESS
  2190. --*/
  2191. DWORD APIENTRY
  2192. RasEnumLanNets ( DWORD *count,
  2193. UCHAR* lanas)
  2194. {
  2195. return SubmitRequest ( NULL,
  2196. REQTYPE_ENUMLANNETS,
  2197. count,
  2198. lanas) ;
  2199. }
  2200. /*++
  2201. Routine Description:
  2202. Gets the lan nets lana numbers read from the
  2203. registry by Rasman
  2204. Arguments:
  2205. Return Value:
  2206. SUCCESS
  2207. --*/
  2208. DWORD APIENTRY
  2209. RasPortEnumProtocols ( HANDLE hConnection,
  2210. HPORT porthandle,
  2211. RAS_PROTOCOLS* protocols,
  2212. PDWORD count)
  2213. {
  2214. DWORD dwError = SUCCESS;
  2215. if (ValidatePortHandle (porthandle) == FALSE)
  2216. {
  2217. dwError = ERROR_INVALID_PORT_HANDLE;
  2218. goto done;
  2219. }
  2220. if(!ValidateConnectionHandle(hConnection))
  2221. {
  2222. dwError = E_INVALIDARG;
  2223. goto done;
  2224. }
  2225. dwError = SubmitRequest (hConnection,
  2226. REQTYPE_PORTENUMPROTOCOLS,
  2227. porthandle,
  2228. protocols,
  2229. count) ;
  2230. done:
  2231. return dwError;
  2232. }
  2233. /*++
  2234. Routine Description:
  2235. Sets the framing type once the port is connected
  2236. Arguments:
  2237. Return Value:
  2238. SUCCESS
  2239. --*/
  2240. DWORD APIENTRY
  2241. RasPortSetFraming ( HPORT porthandle,
  2242. RAS_FRAMING type,
  2243. RASMAN_PPPFEATURES *Send,
  2244. RASMAN_PPPFEATURES *Recv)
  2245. {
  2246. DWORD sendfeatures = 0 ;
  2247. DWORD recvfeatures = 0 ;
  2248. DWORD sendbits = 0 ;
  2249. DWORD recvbits = 0 ;
  2250. if (ValidatePortHandle (porthandle) == FALSE)
  2251. {
  2252. return ERROR_INVALID_PORT_HANDLE ;
  2253. }
  2254. if (type == PPP)
  2255. {
  2256. sendfeatures = PPP_FRAMING ;
  2257. if (Send)
  2258. {
  2259. sendfeatures |= (Send->ACFC
  2260. ? PPP_COMPRESS_ADDRESS_CONTROL
  2261. : 0) ;
  2262. sendbits = Send->ACCM ;
  2263. }
  2264. recvfeatures = PPP_FRAMING ;
  2265. if (Recv)
  2266. {
  2267. recvfeatures |= (Recv->ACFC
  2268. ? PPP_COMPRESS_ADDRESS_CONTROL
  2269. : 0) ;
  2270. recvbits = Recv->ACCM ;
  2271. }
  2272. }
  2273. else if (type == SLIP)
  2274. {
  2275. sendfeatures = recvfeatures = SLIP_FRAMING ;
  2276. }
  2277. else if (type == SLIPCOMP)
  2278. {
  2279. sendfeatures = recvfeatures = SLIP_FRAMING
  2280. | SLIP_VJ_COMPRESSION ;
  2281. }
  2282. else if (type == SLIPCOMPAUTO)
  2283. {
  2284. sendfeatures = recvfeatures = SLIP_FRAMING
  2285. | SLIP_VJ_AUTODETECT ;
  2286. }
  2287. else if (type == RAS)
  2288. {
  2289. sendfeatures = recvfeatures = OLD_RAS_FRAMING ;
  2290. }
  2291. else if (type == AUTODETECT)
  2292. {
  2293. }
  2294. return SubmitRequest ( NULL,
  2295. REQTYPE_SETFRAMING,
  2296. porthandle,
  2297. sendfeatures,
  2298. recvfeatures,
  2299. sendbits,
  2300. recvbits) ;
  2301. }
  2302. DWORD APIENTRY
  2303. RasPortStoreUserData ( HPORT porthandle,
  2304. PBYTE data,
  2305. DWORD size)
  2306. {
  2307. if (ValidatePortHandle (porthandle) == FALSE)
  2308. return ERROR_INVALID_PORT_HANDLE ;
  2309. return SubmitRequest ( NULL,
  2310. REQTYPE_STOREUSERDATA,
  2311. porthandle,
  2312. data,
  2313. size) ;
  2314. }
  2315. DWORD APIENTRY
  2316. RasPortRetrieveUserData ( HPORT porthandle,
  2317. PBYTE data,
  2318. DWORD *size)
  2319. {
  2320. if (ValidatePortHandle (porthandle) == FALSE)
  2321. return ERROR_INVALID_PORT_HANDLE ;
  2322. return SubmitRequest ( NULL,
  2323. REQTYPE_RETRIEVEUSERDATA,
  2324. porthandle,
  2325. data,
  2326. size) ;
  2327. }
  2328. /*++
  2329. Routine Description:
  2330. A generic scheme for apps to attach disconnect
  2331. action that must be performed when the link drops.
  2332. Arguments:
  2333. Return Value:
  2334. SUCCESS
  2335. ERROR_INVALID_PORT_HANDLE
  2336. ERROR_PORT_NOT_OPEN
  2337. --*/
  2338. DWORD APIENTRY
  2339. RasPortRegisterSlip (HPORT porthandle,
  2340. DWORD ipaddr,
  2341. DWORD dwFrameSize,
  2342. BOOL priority,
  2343. WCHAR *pszDNSAddress,
  2344. WCHAR *pszDNS2Address,
  2345. WCHAR *pszWINSAddress,
  2346. WCHAR *pszWINS2Address)
  2347. {
  2348. if (ValidatePortHandle (porthandle) == FALSE)
  2349. {
  2350. return ERROR_INVALID_PORT_HANDLE ;
  2351. }
  2352. return SubmitRequest (NULL,
  2353. REQTYPE_REGISTERSLIP,
  2354. porthandle,
  2355. ipaddr,
  2356. dwFrameSize,
  2357. priority,
  2358. pszDNSAddress,
  2359. pszDNS2Address,
  2360. pszWINSAddress,
  2361. pszWINS2Address);
  2362. }
  2363. /*++
  2364. Routine Description:
  2365. Sets the framing info once the port is connected
  2366. Arguments:
  2367. Return Value:
  2368. SUCCESS
  2369. --*/
  2370. DWORD APIENTRY
  2371. RasPortSetFramingEx ( HPORT porthandle,
  2372. RAS_FRAMING_INFO *info)
  2373. {
  2374. if (ValidatePortHandle (porthandle) == FALSE)
  2375. {
  2376. return ERROR_INVALID_PORT_HANDLE ;
  2377. }
  2378. return SubmitRequest ( NULL,
  2379. REQTYPE_SETFRAMINGEX,
  2380. porthandle,
  2381. info) ;
  2382. }
  2383. /*++
  2384. Routine Description:
  2385. Gets the framing info once the port is connected
  2386. Arguments:
  2387. Return Value:
  2388. SUCCESS
  2389. --*/
  2390. DWORD APIENTRY
  2391. RasPortGetFramingEx ( HANDLE hConnection,
  2392. HPORT porthandle,
  2393. RAS_FRAMING_INFO *info)
  2394. {
  2395. DWORD dwError = SUCCESS;
  2396. if (ValidatePortHandle (porthandle) == FALSE)
  2397. {
  2398. dwError = ERROR_INVALID_PORT_HANDLE;
  2399. goto done;
  2400. }
  2401. if(!ValidateConnectionHandle(hConnection))
  2402. {
  2403. dwError = E_INVALIDARG;
  2404. goto done;
  2405. }
  2406. dwError = SubmitRequest ( hConnection,
  2407. REQTYPE_GETFRAMINGEX,
  2408. porthandle,
  2409. info) ;
  2410. done:
  2411. return dwError;
  2412. }
  2413. /*++
  2414. Routine Description:
  2415. Gets the protocol compression attributes for the port
  2416. Arguments:
  2417. Return Value:
  2418. SUCCESS
  2419. --*/
  2420. DWORD APIENTRY
  2421. RasPortGetProtocolCompression (HPORT porthandle,
  2422. RAS_PROTOCOLTYPE type,
  2423. RAS_PROTOCOLCOMPRESSION *send,
  2424. RAS_PROTOCOLCOMPRESSION *recv)
  2425. {
  2426. if (ValidatePortHandle (porthandle) == FALSE)
  2427. {
  2428. return ERROR_INVALID_PORT_HANDLE ;
  2429. }
  2430. return SubmitRequest (NULL,
  2431. REQTYPE_GETPROTOCOLCOMPRESSION,
  2432. porthandle,
  2433. type,
  2434. send,
  2435. recv) ;
  2436. }
  2437. /*++
  2438. Routine Description:
  2439. Gets the protocol compression attributes for the port
  2440. Arguments:
  2441. Return Value:
  2442. SUCCESS
  2443. --*/
  2444. DWORD APIENTRY
  2445. RasPortSetProtocolCompression (HPORT porthandle,
  2446. RAS_PROTOCOLTYPE type,
  2447. RAS_PROTOCOLCOMPRESSION *send,
  2448. RAS_PROTOCOLCOMPRESSION *recv)
  2449. {
  2450. if (ValidatePortHandle (porthandle) == FALSE)
  2451. {
  2452. return ERROR_INVALID_PORT_HANDLE ;
  2453. }
  2454. return SubmitRequest (NULL,
  2455. REQTYPE_SETPROTOCOLCOMPRESSION,
  2456. porthandle,
  2457. type,
  2458. send,
  2459. recv) ;
  2460. }
  2461. /*++
  2462. Routine Description:
  2463. Gets the framing capabilities for the
  2464. port from the mac
  2465. Arguments:
  2466. Return Value:
  2467. SUCCESS
  2468. --*/
  2469. DWORD APIENTRY
  2470. RasGetFramingCapabilities ( HPORT porthandle,
  2471. RAS_FRAMING_CAPABILITIES* caps)
  2472. {
  2473. if (ValidatePortHandle (porthandle) == FALSE)
  2474. {
  2475. return ERROR_INVALID_PORT_HANDLE ;
  2476. }
  2477. return SubmitRequest ( NULL,
  2478. REQTYPE_GETFRAMINGCAPABILITIES,
  2479. porthandle,
  2480. caps) ;
  2481. }
  2482. /*++
  2483. Routine Description:
  2484. Exported call for third party security send
  2485. Arguments:
  2486. Return Value:
  2487. returns from RasPortSend.
  2488. --*/
  2489. DWORD APIENTRY
  2490. RasSecurityDialogSend(
  2491. IN HPORT hPort,
  2492. IN PBYTE pBuffer,
  2493. IN WORD BufferLength
  2494. )
  2495. {
  2496. RASMAN_INFO RasInfo;
  2497. DWORD dwRetCode = RasGetInfo( NULL, hPort, &RasInfo );
  2498. if ( RasInfo.RI_ConnState != LISTENCOMPLETED )
  2499. {
  2500. return( ERROR_PORT_DISCONNECTED );
  2501. }
  2502. return( RasPortSend( hPort, pBuffer, ( DWORD ) BufferLength ) );
  2503. }
  2504. /*++
  2505. Routine Description:
  2506. Exported call for third party security send
  2507. Arguments:
  2508. Return Value:
  2509. returns from RasPortSend.
  2510. --*/
  2511. DWORD APIENTRY
  2512. RasSecurityDialogReceive(
  2513. IN HPORT hPort,
  2514. IN PBYTE pBuffer,
  2515. IN PWORD pBufferLength,
  2516. IN DWORD Timeout,
  2517. IN HANDLE hEvent
  2518. )
  2519. {
  2520. RASMAN_INFO RasInfo;
  2521. DWORD dwRetCode = RasGetInfo( NULL, hPort, &RasInfo );
  2522. DWORD dwBufLength;
  2523. if(ERROR_SUCCESS != dwRetCode)
  2524. {
  2525. return dwRetCode;
  2526. }
  2527. if ( RasInfo.RI_ConnState != LISTENCOMPLETED )
  2528. {
  2529. return( ERROR_PORT_DISCONNECTED );
  2530. }
  2531. dwBufLength = ( DWORD ) *pBufferLength;
  2532. dwRetCode = RasPortReceive( hPort,
  2533. pBuffer,
  2534. &dwBufLength,
  2535. Timeout,
  2536. hEvent );
  2537. return dwRetCode;
  2538. }
  2539. /*++
  2540. Routine Description:
  2541. Gets parameters (info) for the
  2542. Port for which handle is supplied
  2543. Arguments:
  2544. Return Value:
  2545. returns from RasPortGetInfo
  2546. --*/
  2547. DWORD APIENTRY
  2548. RasSecurityDialogGetInfo(
  2549. IN HPORT hPort,
  2550. IN RAS_SECURITY_INFO* pBuffer
  2551. )
  2552. {
  2553. RASMAN_INFO RasInfo;
  2554. DWORD dwRetCode = RasGetInfo( NULL, hPort, &RasInfo );
  2555. if ( dwRetCode != NO_ERROR )
  2556. {
  2557. return( dwRetCode );
  2558. }
  2559. memcpy( pBuffer->DeviceName,
  2560. RasInfo.RI_DeviceConnecting,
  2561. MAX_DEVICE_NAME + 1);
  2562. pBuffer->BytesReceived = RasInfo.RI_BytesReceived;
  2563. pBuffer->LastError = RasInfo.RI_LastError;
  2564. return( NO_ERROR );
  2565. }
  2566. /*++
  2567. Routine Description:
  2568. Sets second HPORT to be multilinked
  2569. (bundled) with the first HPORT
  2570. Arguments:
  2571. Return Value:
  2572. SUCCESS
  2573. --*/
  2574. DWORD APIENTRY
  2575. RasPortBundle (HPORT firstporthandle, HPORT secondporthandle)
  2576. {
  2577. if (ValidatePortHandle (firstporthandle) == FALSE)
  2578. {
  2579. return ERROR_INVALID_PORT_HANDLE ;
  2580. }
  2581. if (ValidatePortHandle (secondporthandle) == FALSE)
  2582. return ERROR_INVALID_PORT_HANDLE ;
  2583. return SubmitRequest ( NULL,
  2584. REQTYPE_PORTBUNDLE,
  2585. firstporthandle,
  2586. secondporthandle) ;
  2587. }
  2588. /*++
  2589. Routine Description:
  2590. Given a port this API returns a connected
  2591. port handle from the same bundle this port
  2592. is or was (if not connected) part of.
  2593. Arguments:
  2594. Return Value:
  2595. SUCCESS
  2596. --*/
  2597. DWORD APIENTRY
  2598. RasPortGetBundledPort (HPORT oldport, HPORT *pnewport)
  2599. {
  2600. if (ValidatePortHandle (oldport) == FALSE)
  2601. {
  2602. return ERROR_INVALID_PORT_HANDLE ;
  2603. }
  2604. return SubmitRequest (NULL,
  2605. REQTYPE_GETBUNDLEDPORT,
  2606. oldport,
  2607. pnewport) ;
  2608. }
  2609. /*++
  2610. Routine Description:
  2611. Given a port this API returns handle to a bundle
  2612. Arguments:
  2613. Return Value:
  2614. SUCCESS
  2615. ERROR_PORT_DISCONNECTED
  2616. --*/
  2617. DWORD APIENTRY
  2618. RasPortGetBundle (HANDLE hConnection,
  2619. HPORT hport,
  2620. HBUNDLE *phbundle)
  2621. {
  2622. DWORD dwError = SUCCESS;
  2623. if (ValidatePortHandle (hport) == FALSE)
  2624. {
  2625. dwError = ERROR_INVALID_PORT_HANDLE;
  2626. goto done;
  2627. }
  2628. if(!ValidateConnectionHandle(hConnection))
  2629. {
  2630. dwError = E_INVALIDARG;
  2631. goto done;
  2632. }
  2633. dwError = SubmitRequest (hConnection,
  2634. REQTYPE_PORTGETBUNDLE,
  2635. hport,
  2636. phbundle) ;
  2637. done:
  2638. return dwError;
  2639. }
  2640. /*++
  2641. Routine Description:
  2642. Given a bundle this API returns a connected
  2643. port handle part of the bundle.
  2644. Arguments:
  2645. Return Value:
  2646. SUCCESS
  2647. ERROR_INVALID_PORT_HANDLE
  2648. --*/
  2649. DWORD APIENTRY
  2650. RasBundleGetPort (HANDLE hConnection,
  2651. HBUNDLE hbundle,
  2652. HPORT *phport)
  2653. {
  2654. DWORD dwError = SUCCESS;
  2655. if(!ValidateConnectionHandle(hConnection))
  2656. {
  2657. dwError = E_INVALIDARG;
  2658. goto done;
  2659. }
  2660. dwError = SubmitRequest (hConnection,
  2661. REQTYPE_BUNDLEGETPORT,
  2662. hbundle,
  2663. phport) ;
  2664. done:
  2665. return dwError;
  2666. }
  2667. /*++
  2668. Routine Description:
  2669. Increment/decrement the shared buffer attach count for
  2670. use with other services inside the rasman.exe process.
  2671. Arguments:
  2672. Return Value:
  2673. SUCCESS
  2674. --*/
  2675. DWORD APIENTRY
  2676. RasReferenceRasman (BOOL fAttach)
  2677. {
  2678. return SubmitRequest (NULL,
  2679. REQTYPE_SETATTACHCOUNT,
  2680. fAttach);
  2681. }
  2682. /*++
  2683. Routine Description:
  2684. Retrieve the stored dial parameters for an entry UID.
  2685. Arguments:
  2686. Return Value:
  2687. SUCCESS
  2688. --*/
  2689. DWORD APIENTRY
  2690. RasGetDialParams(
  2691. DWORD dwUID,
  2692. LPDWORD pdwMask,
  2693. PRAS_DIALPARAMS pDialParams
  2694. )
  2695. {
  2696. return SubmitRequest ( NULL,
  2697. REQTYPE_GETDIALPARAMS,
  2698. dwUID,
  2699. pdwMask,
  2700. pDialParams);
  2701. }
  2702. /*++
  2703. Routine Description:
  2704. Store new dial parameters for an entry UID.
  2705. Arguments:
  2706. Return Value:
  2707. SUCCESS
  2708. --*/
  2709. DWORD APIENTRY
  2710. RasSetDialParams(
  2711. DWORD dwUID,
  2712. DWORD dwMask,
  2713. PRAS_DIALPARAMS pDialParams,
  2714. BOOL fDelete
  2715. )
  2716. {
  2717. return SubmitRequest ( NULL,
  2718. REQTYPE_SETDIALPARAMS,
  2719. dwUID,
  2720. dwMask,
  2721. pDialParams,
  2722. fDelete);
  2723. }
  2724. /*++
  2725. Routine Description:
  2726. Create a rasapi32 connection.
  2727. Arguments:
  2728. Return Value:
  2729. SUCCESS
  2730. --*/
  2731. DWORD APIENTRY
  2732. RasCreateConnection(
  2733. HCONN *lphconn,
  2734. DWORD dwSubEntries,
  2735. DWORD *lpdwEntryAlreadyConnected,
  2736. DWORD *lpdwSubEntryInfo,
  2737. DWORD dwDialMode,
  2738. GUID *pGuidEntry,
  2739. CHAR *lpszPhonebookPath,
  2740. CHAR *lpszEntryName,
  2741. CHAR *lpszRefPbkPath,
  2742. CHAR *lpszRefEntryName
  2743. )
  2744. {
  2745. return SubmitRequest ( NULL,
  2746. REQTYPE_CREATECONNECTION,
  2747. GetCurrentProcessId(),
  2748. dwSubEntries,
  2749. dwDialMode,
  2750. pGuidEntry,
  2751. lpszPhonebookPath,
  2752. lpszEntryName,
  2753. lpszRefPbkPath,
  2754. lpszRefEntryName,
  2755. lphconn,
  2756. lpdwEntryAlreadyConnected,
  2757. lpdwSubEntryInfo);
  2758. }
  2759. /*++
  2760. Routine Description:
  2761. Return a list of active HCONNs
  2762. Arguments:
  2763. Return Value:
  2764. SUCCESS
  2765. --*/
  2766. DWORD APIENTRY
  2767. RasConnectionEnum(
  2768. HANDLE hConnection,
  2769. HCONN *lphconn,
  2770. LPDWORD lpdwcbConnections,
  2771. LPDWORD lpdwcConnections
  2772. )
  2773. {
  2774. DWORD dwError = SUCCESS;
  2775. if(!ValidateConnectionHandle(hConnection))
  2776. {
  2777. dwError = E_INVALIDARG;
  2778. goto done;
  2779. }
  2780. dwError = SubmitRequest (hConnection,
  2781. REQTYPE_ENUMCONNECTION,
  2782. lpdwcbConnections,
  2783. lphconn,
  2784. lpdwcConnections);
  2785. done:
  2786. return dwError;
  2787. }
  2788. /*++
  2789. Routine Description:
  2790. Associate a rasapi32 connection with a port
  2791. Arguments:
  2792. Return Value:
  2793. SUCCESS
  2794. --*/
  2795. DWORD APIENTRY
  2796. RasAddConnectionPort(
  2797. HCONN hconn,
  2798. HPORT hport,
  2799. DWORD dwSubEntry
  2800. )
  2801. {
  2802. return SubmitRequest ( NULL,
  2803. REQTYPE_ADDCONNECTIONPORT,
  2804. hconn,
  2805. hport,
  2806. dwSubEntry);
  2807. }
  2808. /*++
  2809. Routine Description:
  2810. Enumerate all ports in a connection
  2811. Arguments:
  2812. Return Value:
  2813. SUCCESS
  2814. --*/
  2815. DWORD APIENTRY
  2816. RasEnumConnectionPorts(
  2817. HANDLE hConnection,
  2818. HCONN hconn,
  2819. RASMAN_PORT *lpPorts,
  2820. LPDWORD lpdwcbPorts,
  2821. LPDWORD lpdwcPorts
  2822. )
  2823. {
  2824. DWORD dwError = SUCCESS;
  2825. if(!ValidateConnectionHandle(hConnection))
  2826. {
  2827. dwError = E_INVALIDARG;
  2828. goto done;
  2829. }
  2830. dwError = SubmitRequest (hConnection,
  2831. REQTYPE_ENUMCONNECTIONPORTS,
  2832. hconn,
  2833. lpdwcbPorts,
  2834. lpPorts,
  2835. lpdwcPorts);
  2836. done:
  2837. return dwError;
  2838. }
  2839. /*++
  2840. Routine Description:
  2841. Destroy a rasapi32 connection.
  2842. Arguments:
  2843. Return Value:
  2844. SUCCESS
  2845. ERROR_NOT_ENOUGH_MEMORY
  2846. ERROR_ACCESS_DENIED
  2847. whatever RasEnumConnectionPorts returns
  2848. --*/
  2849. DWORD APIENTRY
  2850. RasDestroyConnection(
  2851. HCONN hconn
  2852. )
  2853. {
  2854. RASMAN_PORT *lpPorts = NULL;
  2855. DWORD dwPort;
  2856. DWORD dwcbPorts;
  2857. DWORD dwcPorts;
  2858. DWORD dwError = SUCCESS;
  2859. DWORD dwLastError = SUCCESS;
  2860. //
  2861. // allocate buffer for 2 ports up front
  2862. // We don't have to make more than one
  2863. // rasman call in base cases.
  2864. //
  2865. lpPorts = LocalAlloc(LPTR,
  2866. 2 * sizeof(RASMAN_PORT));
  2867. if (NULL == lpPorts)
  2868. {
  2869. dwError = ERROR_NOT_ENOUGH_MEMORY;
  2870. goto done;
  2871. }
  2872. dwcbPorts = 2 * sizeof(RASMAN_PORT);
  2873. do {
  2874. //
  2875. // enumerate the ports in this connection
  2876. //
  2877. dwError = RasEnumConnectionPorts(NULL,
  2878. hconn,
  2879. lpPorts,
  2880. &dwcbPorts,
  2881. &dwcPorts);
  2882. if (ERROR_BUFFER_TOO_SMALL == dwError)
  2883. {
  2884. LocalFree(lpPorts);
  2885. lpPorts = NULL;
  2886. //
  2887. // allocate a larger buffer and call the api again
  2888. //
  2889. lpPorts = LocalAlloc(LPTR, dwcbPorts);
  2890. if (NULL == lpPorts)
  2891. {
  2892. dwError = ERROR_NOT_ENOUGH_MEMORY;
  2893. }
  2894. }
  2895. } while (ERROR_BUFFER_TOO_SMALL == dwError);
  2896. if (SUCCESS != dwError)
  2897. {
  2898. goto done;
  2899. }
  2900. for (dwPort = 0; dwPort < dwcPorts; dwPort++)
  2901. {
  2902. //
  2903. //disconnect the port
  2904. //
  2905. dwError = RasPortDisconnect( lpPorts[dwPort].P_Handle,
  2906. INVALID_HANDLE_VALUE);
  2907. if(ERROR_SUCCESS != dwError)
  2908. {
  2909. dwLastError = dwError;
  2910. }
  2911. //
  2912. // close the port
  2913. //
  2914. dwError = RasPortClose( lpPorts[dwPort].P_Handle );
  2915. if(ERROR_SUCCESS != dwError)
  2916. {
  2917. dwLastError = dwError;
  2918. }
  2919. }
  2920. done:
  2921. if (lpPorts)
  2922. {
  2923. LocalFree(lpPorts);
  2924. }
  2925. if( (ERROR_SUCCESS == dwError)
  2926. && (ERROR_SUCCESS != dwLastError))
  2927. {
  2928. dwError = dwLastError;
  2929. }
  2930. return dwError;
  2931. }
  2932. /*++
  2933. Routine Description:
  2934. Retrieve rasapi32 bandwidth-on-demand, idle disconnect,
  2935. and redial-on-link-failure parameters for a bundle
  2936. Arguments:
  2937. Return Value:
  2938. SUCCESS
  2939. --*/
  2940. DWORD APIENTRY
  2941. RasGetConnectionParams(
  2942. HCONN hconn,
  2943. PRAS_CONNECTIONPARAMS pConnectionParams
  2944. )
  2945. {
  2946. return SubmitRequest ( NULL,
  2947. REQTYPE_GETCONNECTIONPARAMS,
  2948. hconn,
  2949. pConnectionParams);
  2950. }
  2951. /*++
  2952. Routine Description:
  2953. Store rasapi32 bandwidth-on-demand, idle disconnect,
  2954. and redial-on-link-failure parameters for a bundle
  2955. Arguments:
  2956. Return Value:
  2957. SUCCESS
  2958. --*/
  2959. DWORD APIENTRY
  2960. RasSetConnectionParams(
  2961. HCONN hconn,
  2962. PRAS_CONNECTIONPARAMS pConnectionParams
  2963. )
  2964. {
  2965. return SubmitRequest ( NULL,
  2966. REQTYPE_SETCONNECTIONPARAMS,
  2967. hconn,
  2968. pConnectionParams);
  2969. }
  2970. /*++
  2971. Routine Description:
  2972. Retrieve tagged user data for a connection
  2973. Arguments:
  2974. Return Value:
  2975. SUCCESS
  2976. --*/
  2977. DWORD APIENTRY
  2978. RasGetConnectionUserData(
  2979. HCONN hconn,
  2980. DWORD dwTag,
  2981. PBYTE pBuf,
  2982. LPDWORD lpdwcbBuf
  2983. )
  2984. {
  2985. return SubmitRequest ( NULL,
  2986. REQTYPE_GETCONNECTIONUSERDATA,
  2987. hconn,
  2988. dwTag,
  2989. pBuf,
  2990. lpdwcbBuf);
  2991. }
  2992. /*++
  2993. Routine Description:
  2994. Store tagged user data for a connection
  2995. Arguments:
  2996. Return Value:
  2997. SUCCESS
  2998. --*/
  2999. DWORD APIENTRY
  3000. RasSetConnectionUserData(
  3001. HCONN hconn,
  3002. DWORD dwTag,
  3003. PBYTE pBuf,
  3004. DWORD dwcbBuf
  3005. )
  3006. {
  3007. return SubmitRequest ( NULL,
  3008. REQTYPE_SETCONNECTIONUSERDATA,
  3009. hconn,
  3010. dwTag,
  3011. pBuf,
  3012. dwcbBuf);
  3013. }
  3014. /*++
  3015. Routine Description:
  3016. Retrieve tagged user data for a port
  3017. Arguments:
  3018. Return Value:
  3019. SUCCESS
  3020. --*/
  3021. DWORD APIENTRY
  3022. RasGetPortUserData(
  3023. HPORT hport,
  3024. DWORD dwTag,
  3025. PBYTE pBuf,
  3026. LPDWORD lpdwcbBuf
  3027. )
  3028. {
  3029. return SubmitRequest ( NULL,
  3030. REQTYPE_GETPORTUSERDATA,
  3031. hport,
  3032. dwTag,
  3033. pBuf,
  3034. lpdwcbBuf);
  3035. }
  3036. /*++
  3037. Routine Description:
  3038. Store tagged user data for a port
  3039. Arguments:
  3040. Return Value:
  3041. SUCCESS
  3042. --*/
  3043. DWORD APIENTRY
  3044. RasSetPortUserData(
  3045. HPORT hport,
  3046. DWORD dwTag,
  3047. PBYTE pBuf,
  3048. DWORD dwcbBuf
  3049. )
  3050. {
  3051. return SubmitRequest ( NULL,
  3052. REQTYPE_SETPORTUSERDATA,
  3053. hport,
  3054. dwTag,
  3055. pBuf,
  3056. dwcbBuf);
  3057. }
  3058. /*++
  3059. Routine Description:
  3060. Sends message to rasman.
  3061. Arguments:
  3062. Return Value:
  3063. SUCCESS
  3064. Non-zero returns - Failure
  3065. --*/
  3066. DWORD APIENTRY
  3067. RasSendPppMessageToRasman (
  3068. IN HPORT hPort,
  3069. LPBYTE lpPppMessage
  3070. )
  3071. {
  3072. return SubmitRequest ( NULL,
  3073. REQTYPE_SENDPPPMESSAGETORASMAN,
  3074. hPort,
  3075. lpPppMessage);
  3076. }
  3077. /*++
  3078. Routine Description:
  3079. Stops PPP on 'hPort'.
  3080. Arguments:
  3081. Return Value:
  3082. SUCCESS
  3083. Non-zero returns - Failure
  3084. --*/
  3085. DWORD APIENTRY
  3086. RasPppStop(
  3087. IN HPORT hPort
  3088. )
  3089. {
  3090. if (ValidatePortHandle (hPort) == FALSE)
  3091. {
  3092. return ERROR_INVALID_PORT_HANDLE ;
  3093. }
  3094. return SubmitRequest( NULL,
  3095. REQTYPE_PPPSTOP,
  3096. hPort );
  3097. }
  3098. /*++
  3099. Routine Description:
  3100. Called in response to a "CallbackRequest" notification to
  3101. set the callback number (or not) for the "set-by-caller"
  3102. user.
  3103. Arguments:
  3104. Return Value:
  3105. SUCCESS
  3106. Non-zero returns - Failure
  3107. --*/
  3108. DWORD APIENTRY
  3109. RasPppCallback(
  3110. IN HPORT hPort,
  3111. IN CHAR* pszCallbackNumber
  3112. )
  3113. {
  3114. if (ValidatePortHandle (hPort) == FALSE)
  3115. return ERROR_INVALID_PORT_HANDLE ;
  3116. return SubmitRequest ( NULL,
  3117. REQTYPE_PPPCALLBACK,
  3118. hPort,
  3119. pszCallbackNumber );
  3120. }
  3121. /*++
  3122. Routine Description:
  3123. Called in response to a "ChangePwRequest" notification
  3124. to set a new password (replacing the one that has expired)
  3125. of 'pszNewPassword'. The username and old password are
  3126. specified because in the auto-logon case they have not
  3127. yet been specified in change password useable form.
  3128. Arguments:
  3129. Return Value:
  3130. SUCCESS
  3131. Non-zero returns - Failure
  3132. --*/
  3133. DWORD APIENTRY
  3134. RasPppChangePassword(
  3135. IN HPORT hPort,
  3136. IN CHAR* pszUserName,
  3137. IN CHAR* pszOldPassword,
  3138. IN CHAR* pszNewPassword )
  3139. {
  3140. if (ValidatePortHandle (hPort) == FALSE)
  3141. {
  3142. return ERROR_INVALID_PORT_HANDLE ;
  3143. }
  3144. return SubmitRequest( NULL,
  3145. REQTYPE_PPPCHANGEPWD,
  3146. hPort,
  3147. pszUserName,
  3148. pszOldPassword,
  3149. pszNewPassword );
  3150. }
  3151. /*++
  3152. Routine Description:
  3153. Called when the PPP event is set to retrieve the latest PPP
  3154. ** notification info which is loaded into caller's 'pMsg'
  3155. buffer.
  3156. Arguments:
  3157. Return Value:
  3158. SUCCESS
  3159. Non-zero returns - Failure
  3160. --*/
  3161. DWORD APIENTRY
  3162. RasPppGetInfo(
  3163. IN HPORT hPort,
  3164. OUT PPP_MESSAGE* pMsg
  3165. )
  3166. {
  3167. if (ValidatePortHandle (hPort) == FALSE)
  3168. {
  3169. return ERROR_INVALID_PORT_HANDLE ;
  3170. }
  3171. return SubmitRequest( NULL,
  3172. REQTYPE_PPPGETINFO,
  3173. hPort,
  3174. pMsg );
  3175. }
  3176. /*++
  3177. Routine Description:
  3178. Called in response to an "AuthRetry" notification to retry
  3179. authentication with the new credentials, 'pszUserName',
  3180. 'pszPassword', and 'pszDomain'.
  3181. Arguments:
  3182. Return Value:
  3183. SUCCESS
  3184. Non-zero returns - Failure
  3185. --*/
  3186. DWORD APIENTRY
  3187. RasPppRetry(
  3188. IN HPORT hPort,
  3189. IN CHAR* pszUserName,
  3190. IN CHAR* pszPassword,
  3191. IN CHAR* pszDomain
  3192. )
  3193. {
  3194. if (ValidatePortHandle (hPort) == FALSE)
  3195. {
  3196. return ERROR_INVALID_PORT_HANDLE ;
  3197. }
  3198. return SubmitRequest( NULL,
  3199. REQTYPE_PPPRETRY,
  3200. hPort,
  3201. pszUserName,
  3202. pszPassword,
  3203. pszDomain );
  3204. }
  3205. /*++
  3206. Routine Description:
  3207. Starts PPP on open and connected RAS Manager port 'hPort'.
  3208. If successful, 'hEvent' (a manual-reset event) is thereafter
  3209. set whenever a PPP notification is available (via RasPppGetInfo).
  3210. 'pszUserName', 'pszPassword', and 'pszDomain' specify the
  3211. credentials to be authenticated during authentication phase.
  3212. 'pConfigInfo' specifies further configuration info such as
  3213. which CPs to request, callback and compression parameters,
  3214. etc. 'pszzParameters' is a buffer of length PARAMETERBUFLEN
  3215. containing a string of NUL-terminated key=value strings,
  3216. all terminated by a double-NUL.
  3217. Arguments:
  3218. Return Value:
  3219. SUCCESS
  3220. Non-zero returns - Failure
  3221. --*/
  3222. DWORD APIENTRY
  3223. RasPppStart(
  3224. IN HPORT hPort,
  3225. IN CHAR* pszPortName,
  3226. IN CHAR* pszUserName,
  3227. IN CHAR* pszPassword,
  3228. IN CHAR* pszDomain,
  3229. IN LUID* pLuid,
  3230. IN PPP_CONFIG_INFO* pConfigInfo,
  3231. IN LPVOID pInterfaceInfo,
  3232. IN CHAR* pszzParameters,
  3233. IN BOOL fThisIsACallback,
  3234. IN HANDLE hEvent,
  3235. IN DWORD dwAutoDisconnectTime,
  3236. IN BOOL fRedialOnLinkFailure,
  3237. IN PPP_BAPPARAMS* pBapParams,
  3238. IN BOOL fNonInteractive,
  3239. IN DWORD dwEapTypeId,
  3240. IN DWORD dwFlags
  3241. )
  3242. {
  3243. PPP_INTERFACE_INFO * pPppInterfaceInfo = pInterfaceInfo;
  3244. if (ValidatePortHandle (hPort) == FALSE)
  3245. {
  3246. return ERROR_INVALID_PORT_HANDLE ;
  3247. }
  3248. //
  3249. // If user name is not NULL and password is
  3250. // NULL and this is not the svchost process,
  3251. // get the user sid and save it in the ports
  3252. // user data
  3253. //
  3254. if(!IsRasmanProcess())
  3255. {
  3256. DWORD dwErr;
  3257. PWCHAR pszSid = LocalAlloc(LPTR, 5000);
  3258. if(NULL != pszSid)
  3259. {
  3260. dwErr = GetUserSid(pszSid, 5000);
  3261. if(ERROR_SUCCESS == dwErr)
  3262. {
  3263. dwErr = RasSetPortUserData(
  3264. hPort,
  3265. PORT_USERSID_INDEX,
  3266. (PBYTE) pszSid,
  3267. 5000);
  3268. }
  3269. LocalFree(pszSid);
  3270. }
  3271. else
  3272. {
  3273. RasmanOutputDebug("RASMAN: RasPppStart: failed to allocate sid\n");
  3274. }
  3275. }
  3276. return SubmitRequest( NULL,
  3277. REQTYPE_PPPSTART,
  3278. hPort,
  3279. pszPortName,
  3280. pszUserName,
  3281. pszPassword,
  3282. pszDomain,
  3283. pLuid,
  3284. pConfigInfo,
  3285. pPppInterfaceInfo,
  3286. pszzParameters,
  3287. fThisIsACallback,
  3288. hEvent,
  3289. GetCurrentProcessId(),
  3290. dwAutoDisconnectTime,
  3291. fRedialOnLinkFailure,
  3292. pBapParams,
  3293. fNonInteractive,
  3294. dwEapTypeId,
  3295. dwFlags);
  3296. }
  3297. /*++
  3298. Routine Description:
  3299. Adds an event to be signalled on disconnect
  3300. state for either an existing connection, or an
  3301. existing port.
  3302. Arguments:
  3303. Return Value:
  3304. SUCCESS
  3305. Non-zero returns - Failure
  3306. --*/
  3307. DWORD APIENTRY
  3308. RasAddNotification(
  3309. IN HCONN hconn,
  3310. IN HANDLE hevent,
  3311. IN DWORD dwfFlags
  3312. )
  3313. {
  3314. DWORD pid = GetCurrentProcessId();
  3315. return SubmitRequest ( NULL,
  3316. REQTYPE_ADDNOTIFICATION,
  3317. pid,
  3318. hconn,
  3319. hevent,
  3320. dwfFlags );
  3321. }
  3322. /*++
  3323. Routine Description:
  3324. Allows rasapi32 to notify rasman when a new connection
  3325. is ready to have data sent over it.
  3326. Arguments:
  3327. Return Value:
  3328. SUCCESS
  3329. Non-zero returns - Failure
  3330. --*/
  3331. DWORD APIENTRY
  3332. RasSignalNewConnection(
  3333. IN HCONN hconn
  3334. )
  3335. {
  3336. return SubmitRequest( NULL,
  3337. REQTYPE_SIGNALCONNECTION,
  3338. hconn );
  3339. }
  3340. /*++
  3341. Routine Description:
  3342. Allows apps to set dev config that is specific to the device.
  3343. This is passed on to the approp. media dll
  3344. Arguments:
  3345. Return Value:
  3346. SUCCESS
  3347. Non-zero returns - Failure
  3348. --*/
  3349. DWORD APIENTRY
  3350. RasSetDevConfig( IN HPORT hport,
  3351. IN CHAR *devicetype,
  3352. IN PBYTE config,
  3353. IN DWORD size)
  3354. {
  3355. if (ValidatePortHandle (hport) == FALSE)
  3356. {
  3357. return ERROR_INVALID_PORT_HANDLE ;
  3358. }
  3359. return SubmitRequest ( NULL,
  3360. REQTYPE_SETDEVCONFIG,
  3361. hport,
  3362. devicetype,
  3363. config,
  3364. size);
  3365. }
  3366. /*++
  3367. Routine Description:
  3368. Allows apps to get dev config that is specific to the device.
  3369. Arguments:
  3370. Return Value:
  3371. SUCCESS
  3372. Non-zero returns - Failure
  3373. --*/
  3374. DWORD APIENTRY
  3375. RasGetDevConfig ( IN HANDLE hConnection,
  3376. IN HPORT hport,
  3377. IN CHAR *devicetype,
  3378. IN PBYTE config,
  3379. IN OUT DWORD *size)
  3380. {
  3381. DWORD dwError = SUCCESS;
  3382. RAS_RPC *pRasRpcConnection = (RAS_RPC *) hConnection;
  3383. if (ValidatePortHandle (hport) == FALSE)
  3384. {
  3385. dwError = ERROR_INVALID_PORT_HANDLE;
  3386. goto done;
  3387. }
  3388. if(!ValidateConnectionHandle(hConnection))
  3389. {
  3390. dwError = E_INVALIDARG;
  3391. goto done;
  3392. }
  3393. //
  3394. // If the request is for a remote server and the server
  3395. // version is 4.0 - steelhead, then defer to the old way
  3396. // of getting this information since rasman has become
  3397. // a rpc server only in version 50.
  3398. //
  3399. if( NULL != pRasRpcConnection
  3400. && VERSION_40 == pRasRpcConnection->dwVersion)
  3401. {
  3402. DWORD dwSizeRequired = *size;
  3403. dwError = RemoteRasGetDevConfig(hConnection,
  3404. hport,
  3405. devicetype,
  3406. config,
  3407. &dwSizeRequired);
  3408. //
  3409. // Since this is a buffer returned from a 4.0
  3410. // server, we need to change this to a format
  3411. // that nt 5.0 understands.
  3412. //
  3413. if( (SUCCESS == dwError)
  3414. && (dwSizeRequired > 0)
  3415. && (*size >= (dwSizeRequired + sizeof(RAS_DEVCONFIG))))
  3416. {
  3417. RAS_DEVCONFIG *pDevConfig = (RAS_DEVCONFIG *) config;
  3418. MoveMemory((PBYTE) pDevConfig->abInfo,
  3419. config,
  3420. dwSizeRequired);
  3421. pDevConfig->dwOffsetofModemSettings =
  3422. FIELD_OFFSET(RAS_DEVCONFIG, abInfo);
  3423. pDevConfig->dwSizeofModemSettings = dwSizeRequired;
  3424. pDevConfig->dwSizeofExtendedCaps = 0;
  3425. pDevConfig->dwOffsetofExtendedCaps = 0;
  3426. }
  3427. else if ( (dwSizeRequired > 0)
  3428. && (*size < (dwSizeRequired + sizeof(RAS_DEVCONFIG))))
  3429. {
  3430. dwError = ERROR_BUFFER_TOO_SMALL;
  3431. }
  3432. else if (dwSizeRequired > 0)
  3433. {
  3434. *size = dwSizeRequired + sizeof(RAS_DEVCONFIG);
  3435. }
  3436. else
  3437. {
  3438. *size = dwSizeRequired;
  3439. }
  3440. }
  3441. else
  3442. {
  3443. dwError = SubmitRequest (hConnection,
  3444. REQTYPE_GETDEVCONFIG,
  3445. hport,
  3446. devicetype,
  3447. config,
  3448. size);
  3449. }
  3450. done:
  3451. return dwError;
  3452. }
  3453. /*++
  3454. Routine Description:
  3455. Gets time in seconds from NDISWAN since the last activity on
  3456. this port
  3457. Arguments:
  3458. Return Value:
  3459. SUCCESS
  3460. Non-zero returns - Failure
  3461. --*/
  3462. DWORD APIENTRY
  3463. RasGetTimeSinceLastActivity(
  3464. IN HPORT hport,
  3465. OUT LPDWORD lpdwTimeSinceLastActivity
  3466. )
  3467. {
  3468. if (ValidatePortHandle (hport) == FALSE)
  3469. {
  3470. return( ERROR_INVALID_PORT_HANDLE );
  3471. }
  3472. return SubmitRequest( NULL,
  3473. REQTYPE_GETTIMESINCELASTACTIVITY,
  3474. hport,
  3475. lpdwTimeSinceLastActivity );
  3476. }
  3477. /*++
  3478. Routine Description:
  3479. Debug routine to test PnP operations
  3480. Arguments:
  3481. Return Value:
  3482. SUCCESS
  3483. Non-zero returns - Failure
  3484. --*/
  3485. DWORD APIENTRY
  3486. RasPnPControl(
  3487. IN DWORD dwOp,
  3488. IN HPORT hport
  3489. )
  3490. {
  3491. return SubmitRequest( NULL,
  3492. REQTYPE_PNPCONTROL,
  3493. dwOp,
  3494. hport );
  3495. }
  3496. /*++
  3497. Routine Description:
  3498. Set the I/O Completion Port associated with a port.
  3499. Arguments:
  3500. Return Value:
  3501. SUCCESS
  3502. Non-zero returns - Failure
  3503. --*/
  3504. DWORD APIENTRY
  3505. RasSetIoCompletionPort(
  3506. IN HPORT hport,
  3507. IN HANDLE hIoCompletionPort,
  3508. IN PRAS_OVERLAPPED lpOvDrop,
  3509. IN PRAS_OVERLAPPED lpOvStateChange,
  3510. IN PRAS_OVERLAPPED lpOvPpp,
  3511. IN PRAS_OVERLAPPED lpOvLast
  3512. )
  3513. {
  3514. return SubmitRequest(
  3515. NULL,
  3516. REQTYPE_SETIOCOMPLETIONPORT,
  3517. hport,
  3518. hIoCompletionPort,
  3519. lpOvDrop,
  3520. lpOvStateChange,
  3521. lpOvPpp,
  3522. lpOvLast);
  3523. }
  3524. /*++
  3525. Routine Description:
  3526. Set the I/O Completion Port associated with a port.
  3527. Arguments:
  3528. Return Value:
  3529. SUCCESS
  3530. Non-zero returns - Failure
  3531. --*/
  3532. DWORD APIENTRY
  3533. RasSetRouterUsage(
  3534. IN HPORT hport,
  3535. IN BOOL fRouter
  3536. )
  3537. {
  3538. return SubmitRequest(
  3539. NULL,
  3540. REQTYPE_SETROUTERUSAGE,
  3541. hport,
  3542. fRouter);
  3543. }
  3544. /*++
  3545. Routine Description:
  3546. Close the server's side of a port.
  3547. Arguments:
  3548. Return Value:
  3549. SUCCESS
  3550. Non-zero returns - Failure
  3551. --*/
  3552. DWORD APIENTRY
  3553. RasServerPortClose(
  3554. IN HPORT hport
  3555. )
  3556. {
  3557. DWORD pid = GetCurrentProcessId();
  3558. if (!ValidatePortHandle (hport))
  3559. {
  3560. return ERROR_INVALID_PORT_HANDLE ;
  3561. }
  3562. return SubmitRequest ( NULL,
  3563. REQTYPE_SERVERPORTCLOSE,
  3564. hport,
  3565. pid,
  3566. TRUE) ;
  3567. }
  3568. DWORD APIENTRY
  3569. RasSetRasdialInfo (
  3570. IN HPORT hport,
  3571. IN CHAR *pszPhonebookPath,
  3572. IN CHAR *pszEntryName,
  3573. IN CHAR *pszPhoneNumber,
  3574. IN DWORD cbCustomAuthData,
  3575. IN PBYTE pbCustomAuthData)
  3576. {
  3577. if (!ValidatePortHandle (hport))
  3578. {
  3579. return ERROR_INVALID_PORT_HANDLE;
  3580. }
  3581. return SubmitRequest ( NULL,
  3582. REQTYPE_SETRASDIALINFO,
  3583. hport,
  3584. pszPhonebookPath,
  3585. pszEntryName,
  3586. pszPhoneNumber,
  3587. cbCustomAuthData,
  3588. pbCustomAuthData);
  3589. }
  3590. DWORD
  3591. RasRegisterPnPCommon ( PVOID pvNotifier,
  3592. HANDLE hAlertableThread,
  3593. DWORD dwFlags,
  3594. BOOL fRegister)
  3595. {
  3596. DWORD dwErr;
  3597. DWORD pid = GetCurrentProcessId();
  3598. HANDLE hThreadHandle = NULL;
  3599. if ( NULL == pvNotifier
  3600. || ( 0 == ( dwFlags & PNP_NOTIFEVENT )
  3601. && 0 == ( dwFlags & PNP_NOTIFCALLBACK )))
  3602. {
  3603. dwErr = ERROR_INVALID_PARAMETER;
  3604. goto done;
  3605. }
  3606. if ( dwFlags & PNP_NOTIFCALLBACK )
  3607. {
  3608. if (fRegister )
  3609. {
  3610. if(NULL == hAlertableThread )
  3611. {
  3612. RasmanOutputDebug ("RasRegisterPnPCommon: "
  3613. "hAlertableThread == NULL\n");
  3614. dwErr = ERROR_INVALID_PARAMETER;
  3615. goto done;
  3616. }
  3617. if ( !DuplicateHandle( GetCurrentProcess(),
  3618. hAlertableThread,
  3619. GetCurrentProcess(),
  3620. &hThreadHandle,
  3621. 0,
  3622. FALSE,
  3623. DUPLICATE_SAME_ACCESS ) )
  3624. {
  3625. RasmanOutputDebug("RasRegisterPnPCommon: Failed to"
  3626. " duplicate handle\n");
  3627. dwErr = GetLastError();
  3628. goto done;
  3629. }
  3630. }
  3631. }
  3632. dwErr = SubmitRequest ( NULL,
  3633. REQTYPE_REGISTERPNPNOTIF,
  3634. pvNotifier,
  3635. dwFlags,
  3636. pid,
  3637. hThreadHandle,
  3638. fRegister);
  3639. done:
  3640. return dwErr;
  3641. }
  3642. DWORD APIENTRY
  3643. RasRegisterPnPEvent ( HANDLE hEvent, BOOL fRegister )
  3644. {
  3645. DWORD pid = GetCurrentProcessId ();
  3646. return RasRegisterPnPCommon ( (PVOID) hEvent,
  3647. NULL,
  3648. PNP_NOTIFEVENT,
  3649. fRegister);
  3650. }
  3651. DWORD APIENTRY
  3652. RasRegisterPnPHandler(PAPCFUNC pfnPnPHandler,
  3653. HANDLE hAlertableThread,
  3654. BOOL fRegister)
  3655. {
  3656. return RasRegisterPnPCommon ( (PVOID) pfnPnPHandler,
  3657. hAlertableThread,
  3658. PNP_NOTIFCALLBACK,
  3659. fRegister);
  3660. }
  3661. DWORD APIENTRY
  3662. RasGetAttachedCount ( DWORD *pdwAttachedCount )
  3663. {
  3664. return SubmitRequest ( NULL,
  3665. REQTYPE_GETATTACHEDCOUNT,
  3666. pdwAttachedCount );
  3667. }
  3668. DWORD APIENTRY
  3669. RasGetNumPortOpen (void)
  3670. {
  3671. return SubmitRequest ( NULL,
  3672. REQTYPE_NUMPORTOPEN );
  3673. }
  3674. DWORD APIENTRY
  3675. RasSetBapPolicy ( HCONN hConn,
  3676. DWORD dwLowThreshold,
  3677. DWORD dwLowSamplePeriod,
  3678. DWORD dwHighThreshold,
  3679. DWORD dwHighSamplePeriod)
  3680. {
  3681. return SubmitRequest ( NULL,
  3682. REQTYPE_SETBAPPOLICY,
  3683. hConn,
  3684. dwLowThreshold,
  3685. dwLowSamplePeriod,
  3686. dwHighThreshold,
  3687. dwHighSamplePeriod );
  3688. }
  3689. DWORD APIENTRY
  3690. RasPppStarted ( HPORT hPort )
  3691. {
  3692. return SubmitRequest ( NULL,
  3693. REQTYPE_PPPSTARTED,
  3694. hPort );
  3695. }
  3696. DWORD APIENTRY
  3697. RasRefConnection( HCONN hConn,
  3698. BOOL fAddref,
  3699. DWORD *pdwRefCount )
  3700. {
  3701. return SubmitRequest ( NULL,
  3702. REQTYPE_REFCONNECTION,
  3703. hConn,
  3704. fAddref,
  3705. pdwRefCount );
  3706. }
  3707. DWORD APIENTRY
  3708. RasPppGetEapInfo( HCONN hConn,
  3709. DWORD dwSubEntry,
  3710. DWORD *pdwContextId,
  3711. DWORD *pdwEapTypeId,
  3712. DWORD *pdwSizeOfUIData,
  3713. PBYTE pbdata )
  3714. {
  3715. return SubmitRequest( NULL,
  3716. REQTYPE_GETEAPINFO,
  3717. hConn,
  3718. dwSubEntry,
  3719. pdwSizeOfUIData,
  3720. pbdata,
  3721. pdwContextId,
  3722. pdwEapTypeId);
  3723. }
  3724. DWORD APIENTRY
  3725. RasPppSetEapInfo( HPORT hPort,
  3726. DWORD dwContextId,
  3727. DWORD dwSizeOfEapUIData,
  3728. PBYTE pbdata)
  3729. {
  3730. return SubmitRequest( NULL,
  3731. REQTYPE_SETEAPINFO,
  3732. hPort,
  3733. dwContextId,
  3734. dwSizeOfEapUIData,
  3735. pbdata);
  3736. }
  3737. DWORD APIENTRY
  3738. RasSetDeviceConfigInfo( HANDLE hConnection,
  3739. DWORD cEntries,
  3740. DWORD cbBuffer,
  3741. BYTE *pbBuffer
  3742. )
  3743. {
  3744. DWORD dwError = SUCCESS;
  3745. if(!ValidateConnectionHandle(hConnection))
  3746. {
  3747. dwError = E_INVALIDARG;
  3748. goto done;
  3749. }
  3750. dwError = SubmitRequest( hConnection,
  3751. REQTYPE_SETDEVICECONFIGINFO,
  3752. cEntries,
  3753. cbBuffer,
  3754. pbBuffer);
  3755. done:
  3756. return dwError;
  3757. }
  3758. DWORD APIENTRY
  3759. RasGetDeviceConfigInfo( HANDLE hConnection,
  3760. DWORD *pdwVersion,
  3761. DWORD *pcEntries,
  3762. DWORD *pcbdata,
  3763. BYTE *pbBuffer)
  3764. {
  3765. DWORD dwError = SUCCESS;
  3766. if(!ValidateConnectionHandle(hConnection))
  3767. {
  3768. dwError = E_INVALIDARG;
  3769. goto done;
  3770. }
  3771. dwError = SubmitRequest( hConnection,
  3772. REQTYPE_GETDEVICECONFIGINFO,
  3773. pdwVersion,
  3774. pcbdata,
  3775. pbBuffer,
  3776. pcEntries);
  3777. done:
  3778. return dwError;
  3779. }
  3780. DWORD APIENTRY
  3781. RasFindPrerequisiteEntry( HCONN hConn,
  3782. HCONN *phConnPrerequisiteEntry)
  3783. {
  3784. return SubmitRequest( NULL,
  3785. REQTYPE_FINDPREREQUISITEENTRY,
  3786. hConn,
  3787. phConnPrerequisiteEntry);
  3788. }
  3789. DWORD APIENTRY
  3790. RasLinkGetStatistics( HANDLE hConnection,
  3791. HCONN hConn,
  3792. DWORD dwSubEntry,
  3793. PBYTE pbStats)
  3794. {
  3795. DWORD dwError = SUCCESS;
  3796. if(!ValidateConnectionHandle(hConnection))
  3797. {
  3798. dwError = E_INVALIDARG;
  3799. goto done;
  3800. }
  3801. dwError = SubmitRequest( hConnection,
  3802. REQTYPE_GETLINKSTATS,
  3803. hConn,
  3804. dwSubEntry,
  3805. pbStats);
  3806. done:
  3807. return dwError;
  3808. }
  3809. DWORD APIENTRY
  3810. RasConnectionGetStatistics(HANDLE hConnection,
  3811. HCONN hConn,
  3812. PBYTE pbStats)
  3813. {
  3814. DWORD dwError = SUCCESS;
  3815. if(!ValidateConnectionHandle(hConnection))
  3816. {
  3817. dwError = E_INVALIDARG;
  3818. goto done;
  3819. }
  3820. dwError = SubmitRequest( hConnection,
  3821. REQTYPE_GETCONNECTIONSTATS,
  3822. hConn,
  3823. pbStats);
  3824. done:
  3825. return dwError;
  3826. }
  3827. DWORD APIENTRY
  3828. RasGetHportFromConnection(HANDLE hConnection,
  3829. HCONN hConn,
  3830. HPORT *phport)
  3831. {
  3832. DWORD dwError = SUCCESS;
  3833. if(!ValidateConnectionHandle(hConnection))
  3834. {
  3835. dwError = E_INVALIDARG;
  3836. goto done;
  3837. }
  3838. dwError = SubmitRequest(hConnection,
  3839. REQTYPE_GETHPORTFROMCONNECTION,
  3840. hConn,
  3841. phport);
  3842. done:
  3843. return dwError;
  3844. }
  3845. DWORD APIENTRY
  3846. RasReferenceCustomCount(HCONN hConn,
  3847. BOOL fAddref,
  3848. CHAR* pszPhonebookPath,
  3849. CHAR* pszEntryName,
  3850. DWORD* pdwCount)
  3851. {
  3852. return SubmitRequest(NULL,
  3853. REQTYPE_REFERENCECUSTOMCOUNT,
  3854. hConn,
  3855. fAddref,
  3856. pszPhonebookPath,
  3857. pszEntryName,
  3858. pdwCount);
  3859. }
  3860. DWORD APIENTRY
  3861. RasGetHConnFromEntry(HCONN *phConn,
  3862. CHAR *pszPhonebookPath,
  3863. CHAR *pszEntryName)
  3864. {
  3865. return SubmitRequest(NULL,
  3866. REQTYPE_GETHCONNFROMENTRY,
  3867. pszPhonebookPath,
  3868. pszEntryName,
  3869. phConn);
  3870. }
  3871. DWORD APIENTRY
  3872. RasGetConnectInfo(HPORT hPort,
  3873. DWORD *pdwSize,
  3874. RAS_CONNECT_INFO *pConnectInfo)
  3875. {
  3876. if(NULL == pdwSize)
  3877. {
  3878. return E_INVALIDARG;
  3879. }
  3880. return SubmitRequest(NULL,
  3881. REQTYPE_GETCONNECTINFO,
  3882. hPort,
  3883. pdwSize,
  3884. pConnectInfo);
  3885. }
  3886. DWORD APIENTRY
  3887. RasGetDeviceName(RASDEVICETYPE eDeviceType,
  3888. CHAR *pszDeviceName)
  3889. {
  3890. if(NULL == pszDeviceName)
  3891. {
  3892. return E_INVALIDARG;
  3893. }
  3894. return SubmitRequest(NULL,
  3895. REQTYPE_GETDEVICENAME,
  3896. eDeviceType,
  3897. pszDeviceName);
  3898. }
  3899. DWORD APIENTRY
  3900. RasGetCalledIdInfo(HANDLE hConnection,
  3901. RAS_DEVICE_INFO *pDeviceInfo,
  3902. DWORD *pdwSize,
  3903. RAS_CALLEDID_INFO *pCalledIdInfo)
  3904. {
  3905. if( (NULL == pDeviceInfo)
  3906. || (NULL == pdwSize))
  3907. {
  3908. return E_INVALIDARG;
  3909. }
  3910. return SubmitRequest(hConnection,
  3911. REQTYPE_GETCALLEDID,
  3912. pDeviceInfo,
  3913. pdwSize,
  3914. pCalledIdInfo);
  3915. }
  3916. DWORD APIENTRY
  3917. RasSetCalledIdInfo(HANDLE hConnection,
  3918. RAS_DEVICE_INFO *pDeviceInfo,
  3919. RAS_CALLEDID_INFO *pCalledIdInfo,
  3920. BOOL fWrite)
  3921. {
  3922. if( (NULL == pDeviceInfo)
  3923. || (NULL == pCalledIdInfo))
  3924. {
  3925. return E_INVALIDARG;
  3926. }
  3927. return SubmitRequest(hConnection,
  3928. REQTYPE_SETCALLEDID,
  3929. pDeviceInfo,
  3930. pCalledIdInfo,
  3931. fWrite);
  3932. }
  3933. DWORD APIENTRY
  3934. RasEnableIpSec(HPORT hPort,
  3935. BOOL fEnable,
  3936. BOOL fServer,
  3937. RAS_L2TP_ENCRYPTION eEncryption)
  3938. {
  3939. DWORD retcode = ERROR_SUCCESS;
  3940. retcode = SubmitRequest(NULL,
  3941. REQTYPE_ENABLEIPSEC,
  3942. hPort,
  3943. fEnable,
  3944. fServer,
  3945. eEncryption);
  3946. if( (ERROR_SUCCESS != retcode)
  3947. && (ERROR_CERT_FOR_ENCRYPTION_NOT_FOUND != retcode)
  3948. && (ERROR_NO_CERTIFICATE != retcode))
  3949. {
  3950. if(!fServer)
  3951. {
  3952. return ERROR_FAILED_TO_ENCRYPT;
  3953. }
  3954. }
  3955. return retcode;
  3956. }
  3957. DWORD APIENTRY
  3958. RasIsIpSecEnabled(HPORT hPort,
  3959. BOOL *pfIsIpSecEnabled)
  3960. {
  3961. if(NULL == pfIsIpSecEnabled)
  3962. {
  3963. return E_INVALIDARG;
  3964. }
  3965. return SubmitRequest(NULL,
  3966. REQTYPE_ISIPSECENABLED,
  3967. hPort,
  3968. pfIsIpSecEnabled);
  3969. }
  3970. DWORD APIENTRY
  3971. RasGetEapUserInfo(HANDLE hToken,
  3972. PBYTE pbEapInfo,
  3973. DWORD *pdwInfoSize,
  3974. GUID *pGuid,
  3975. BOOL fRouter,
  3976. DWORD dwEapTypeId)
  3977. {
  3978. return DwGetEapUserInfo(hToken,
  3979. pbEapInfo,
  3980. pdwInfoSize,
  3981. pGuid,
  3982. fRouter,
  3983. dwEapTypeId);
  3984. }
  3985. DWORD APIENTRY
  3986. RasSetEapUserInfo(HANDLE hToken,
  3987. GUID *pGuid,
  3988. PBYTE pbUserInfo,
  3989. DWORD dwInfoSize,
  3990. BOOL fClear,
  3991. BOOL fRouter,
  3992. DWORD dwEapTypeId)
  3993. {
  3994. return DwSetEapUserInfo(hToken,
  3995. pGuid,
  3996. pbUserInfo,
  3997. dwInfoSize,
  3998. fClear,
  3999. fRouter,
  4000. dwEapTypeId);
  4001. }
  4002. DWORD APIENTRY
  4003. RasSetEapLogonInfo(HPORT hPort,
  4004. BOOL fLogon,
  4005. RASEAPINFO *pEapInfo)
  4006. {
  4007. ASSERT(NULL != pEapInfo);
  4008. return SubmitRequest(NULL,
  4009. REQTYPE_SETEAPLOGONINFO,
  4010. hPort,
  4011. fLogon,
  4012. pEapInfo);
  4013. }
  4014. DWORD APIENTRY
  4015. RasSendNotification(RASEVENT *pRasEvent)
  4016. {
  4017. ASSERT(NULL != pRasEvent);
  4018. return SubmitRequest(NULL,
  4019. REQTYPE_SENDNOTIFICATION,
  4020. pRasEvent);
  4021. }
  4022. DWORD APIENTRY RasGetNdiswanDriverCaps(
  4023. HANDLE hConnection,
  4024. RAS_NDISWAN_DRIVER_INFO *pInfo)
  4025. {
  4026. if(NULL == pInfo)
  4027. {
  4028. return E_INVALIDARG;
  4029. }
  4030. return SubmitRequest(hConnection,
  4031. REQTYPE_GETNDISWANDRIVERCAPS,
  4032. pInfo);
  4033. }
  4034. DWORD APIENTRY RasGetBandwidthUtilization(
  4035. HPORT hPort,
  4036. RAS_GET_BANDWIDTH_UTILIZATION *pUtilization)
  4037. {
  4038. if(NULL == pUtilization)
  4039. {
  4040. return E_INVALIDARG;
  4041. }
  4042. return SubmitRequest(NULL,
  4043. REQTYPE_GETBANDWIDTHUTILIZATION,
  4044. hPort,
  4045. pUtilization);
  4046. }
  4047. /*++
  4048. Routine Description:
  4049. This function allows rasauto.dll to provide
  4050. a callback procedure that gets invoked when
  4051. a connection is terminated due to hardware
  4052. failure on its remaining link.
  4053. Arguments:
  4054. Return Value:
  4055. --*/
  4056. VOID
  4057. RasRegisterRedialCallback(
  4058. LPVOID func
  4059. )
  4060. {
  4061. if(NULL == g_fnServiceRequest)
  4062. {
  4063. goto done;
  4064. }
  4065. (void) SubmitRequest(NULL,
  4066. REQTYPE_REGISTERREDIALCALLBACK,
  4067. func);
  4068. done:
  4069. return;
  4070. }
  4071. DWORD APIENTRY RasGetProtocolInfo(
  4072. HANDLE hConnection,
  4073. RASMAN_GET_PROTOCOL_INFO *pInfo)
  4074. {
  4075. if(NULL == pInfo)
  4076. {
  4077. return E_INVALIDARG;
  4078. }
  4079. return SubmitRequest(NULL,
  4080. REQTYPE_GETPROTOCOLINFO,
  4081. pInfo);
  4082. }
  4083. DWORD APIENTRY RasGetCustomScriptDll(
  4084. CHAR *pszCustomDll)
  4085. {
  4086. if(NULL == pszCustomDll)
  4087. {
  4088. return E_INVALIDARG;
  4089. }
  4090. return SubmitRequest(
  4091. NULL,
  4092. REQTYPE_GETCUSTOMSCRIPTDLL,
  4093. pszCustomDll);
  4094. }
  4095. DWORD APIENTRY RasIsTrustedCustomDll(
  4096. HANDLE hConnection,
  4097. WCHAR *pwszCustomDll,
  4098. BOOL *pfTrusted)
  4099. {
  4100. if( (NULL == pwszCustomDll)
  4101. || (wcslen(pwszCustomDll) > MAX_PATH)
  4102. || (NULL == pfTrusted))
  4103. {
  4104. return E_INVALIDARG;
  4105. }
  4106. *pfTrusted = FALSE;
  4107. if(IsKnownDll(pwszCustomDll))
  4108. {
  4109. *pfTrusted = TRUE;
  4110. return SUCCESS;
  4111. }
  4112. return SubmitRequest(
  4113. NULL,
  4114. REQTYPE_ISTRUSTEDCUSTOMDLL,
  4115. pwszCustomDll,
  4116. pfTrusted);
  4117. }
  4118. DWORD APIENTRY RasDoIke(
  4119. HANDLE hConnection,
  4120. HPORT hPort,
  4121. DWORD *pdwStatus)
  4122. {
  4123. DWORD retcode = ERROR_SUCCESS;
  4124. HANDLE hEvent = NULL;
  4125. ASSERT(NULL != pdwStatus);
  4126. /*
  4127. sprintf(szEventName,
  4128. "Global\\RASIKEEVENT%d-%d",
  4129. g_dwEventCount,
  4130. GetCurrentProcessId());
  4131. g_dwEventCount += 1;
  4132. */
  4133. if(NULL == (hEvent = CreateEvent(
  4134. NULL,
  4135. FALSE,
  4136. FALSE,
  4137. NULL)))
  4138. {
  4139. retcode = GetLastError();
  4140. goto done;
  4141. }
  4142. retcode = SubmitRequest(
  4143. NULL,
  4144. REQTYPE_DOIKE,
  4145. hPort,
  4146. hEvent);
  4147. if(SUCCESS == retcode)
  4148. {
  4149. DWORD dwRet;
  4150. for(;;)
  4151. {
  4152. //
  4153. // go into wait and keep checking to see
  4154. // if the port has been disconnected.
  4155. //
  4156. dwRet = WaitForSingleObject(hEvent, SECS_WaitTimeOut);
  4157. if(WAIT_TIMEOUT == dwRet)
  4158. {
  4159. RASMAN_INFO ri;
  4160. retcode = SubmitRequest(
  4161. NULL,
  4162. REQTYPE_GETINFO,
  4163. hPort,
  4164. &ri);
  4165. if( (ERROR_SUCCESS == retcode)
  4166. && (CLOSED != ri.RI_PortStatus)
  4167. && (LISTENING != ri.RI_ConnState))
  4168. {
  4169. continue;
  4170. }
  4171. else
  4172. {
  4173. break;
  4174. }
  4175. }
  4176. else
  4177. {
  4178. if (WAIT_OBJECT_0 == dwRet)
  4179. {
  4180. retcode = SubmitRequest(
  4181. NULL,
  4182. REQTYPE_QUERYIKESTATUS,
  4183. hPort,
  4184. pdwStatus);
  4185. }
  4186. break;
  4187. }
  4188. }
  4189. }
  4190. if(E_ABORT == retcode)
  4191. {
  4192. retcode = SUCCESS;
  4193. }
  4194. done:
  4195. if(NULL != hEvent)
  4196. {
  4197. CloseHandle(hEvent);
  4198. }
  4199. return retcode;
  4200. }
  4201. DWORD APIENTRY RasSetCommSettings(
  4202. HPORT hPort,
  4203. RASCOMMSETTINGS *pRasCommSettings,
  4204. PVOID pv)
  4205. {
  4206. UNREFERENCED_PARAMETER(pv);
  4207. if(NULL == pRasCommSettings)
  4208. {
  4209. E_INVALIDARG;
  4210. }
  4211. if( (sizeof(RASCOMMSETTINGS) != pRasCommSettings->dwSize)
  4212. || sizeof(RASMANCOMMSETTINGS) != sizeof(RASCOMMSETTINGS))
  4213. {
  4214. ASSERT(FALSE);
  4215. return ERROR_INVALID_SIZE;
  4216. }
  4217. return SubmitRequest(
  4218. NULL,
  4219. REQTYPE_SETRASCOMMSETTINGS,
  4220. hPort,
  4221. pRasCommSettings);
  4222. }
  4223. DWORD
  4224. RasEnableRasAudio(
  4225. HANDLE hConnection,
  4226. BOOL fEnable)
  4227. {
  4228. return SubmitRequest(
  4229. hConnection,
  4230. REQTYPE_ENABLERASAUDIO,
  4231. fEnable);
  4232. }
  4233. DWORD
  4234. RasSetKey(
  4235. HANDLE hConnection,
  4236. GUID *pGuid,
  4237. DWORD dwMask,
  4238. DWORD cbkey,
  4239. PBYTE pbkey)
  4240. {
  4241. return SubmitRequest(
  4242. hConnection,
  4243. REQTYPE_SETKEY,
  4244. pGuid,
  4245. dwMask,
  4246. cbkey,
  4247. pbkey);
  4248. }
  4249. DWORD
  4250. RasGetKey(
  4251. HANDLE hConnection,
  4252. GUID *pGuid,
  4253. DWORD dwMask,
  4254. DWORD *pcbkey,
  4255. PBYTE pbkey)
  4256. {
  4257. return SubmitRequest(
  4258. hConnection,
  4259. REQTYPE_GETKEY,
  4260. pGuid,
  4261. dwMask,
  4262. pcbkey,
  4263. pbkey);
  4264. }
  4265. DWORD
  4266. RasSetAddressDisable(
  4267. WCHAR *pszAddress,
  4268. BOOL fDisable)
  4269. {
  4270. return SubmitRequest(
  4271. NULL,
  4272. REQTYPE_ADDRESSDISABLE,
  4273. pszAddress,
  4274. fDisable);
  4275. }
  4276. DWORD APIENTRY
  4277. RasGetDevConfigEx ( IN HANDLE hConnection,
  4278. IN HPORT hport,
  4279. IN CHAR *devicetype,
  4280. IN PBYTE config,
  4281. IN OUT DWORD *size)
  4282. {
  4283. return SubmitRequest(
  4284. hConnection,
  4285. REQTYPE_GETDEVCONFIGEX,
  4286. hport,
  4287. devicetype,
  4288. config,
  4289. size
  4290. );
  4291. }
  4292. DWORD APIENTRY
  4293. RasSendCreds(IN HPORT hport,
  4294. IN CHAR controlchar)
  4295. {
  4296. return SubmitRequest(
  4297. NULL,
  4298. REQTYPE_SENDCREDS,
  4299. hport,
  4300. controlchar);
  4301. }
  4302. DWORD APIENTRY
  4303. RasGetUnicodeDeviceName(IN HPORT hport,
  4304. IN WCHAR *wszDeviceName)
  4305. {
  4306. return SubmitRequest(
  4307. NULL,
  4308. REQTYPE_GETUNICODEDEVICENAME,
  4309. hport,
  4310. wszDeviceName);
  4311. }
  4312. DWORD APIENTRY
  4313. RasGetDeviceNameW(RASDEVICETYPE eDeviceType,
  4314. WCHAR *pszDeviceName)
  4315. {
  4316. if(NULL == pszDeviceName)
  4317. {
  4318. return E_INVALIDARG;
  4319. }
  4320. return SubmitRequest(NULL,
  4321. REQTYPE_GETDEVICENAMEW,
  4322. eDeviceType,
  4323. pszDeviceName);
  4324. }