Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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