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.

1337 lines
37 KiB

  1. /********************************************************************/
  2. /** Copyright(c) 1989 Microsoft Corporation. **/
  3. /********************************************************************/
  4. //***
  5. //
  6. // Filename: init.c
  7. //
  8. // Description: This module contains all the code to initialize the PPP
  9. // engine.
  10. //
  11. // History:
  12. // Nov 11,1993. NarenG Created original version.
  13. //
  14. #include <nt.h>
  15. #include <ntrtl.h>
  16. #include <nturtl.h> // needed for winbase.h
  17. #include <windows.h> // Win32 base API's
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include <time.h>
  21. #include <wchar.h>
  22. #include <raserror.h>
  23. #include <rasman.h>
  24. #include <rtutils.h>
  25. #include <mprlog.h>
  26. #include <lmcons.h>
  27. #include <rasppp.h>
  28. #include <pppcp.h>
  29. #include <lcp.h>
  30. #define _ALLOCATE_GLOBALS_
  31. #include <ppp.h>
  32. #include <timer.h>
  33. #include <util.h>
  34. #include <worker.h>
  35. #include <init.h>
  36. #include <rasauth.h>
  37. #include <bap.h>
  38. #include <raseapif.h>
  39. #define __NOT_INCLUDE_OpenRAS_IASProfileDlg__
  40. #include <dialinusr.h>
  41. #define ALLOC_BLTINCPS_GLOBALS
  42. #include <bltincps.h>
  43. // AFP Server Service registry parameter structure
  44. //
  45. typedef struct _PPP_REGISTRY_PARAMS {
  46. LPSTR pszValueName;
  47. DWORD * pValue;
  48. DWORD Max;
  49. DWORD dwDefValue;
  50. } PPP_REGISTRY_PARAMS, *PPPP_REGISTRY_PARAMS;
  51. PPP_REGISTRY_PARAMS PppRegParams[] =
  52. {
  53. RAS_VALUENAME_MAXTERMINATE,
  54. &(PppConfigInfo.MaxTerminate),
  55. 255,
  56. PPP_DEF_MAXTERMINATE,
  57. RAS_VALUENAME_MAXCONFIGURE,
  58. &(PppConfigInfo.MaxConfigure),
  59. 255,
  60. PPP_DEF_MAXCONFIGURE,
  61. RAS_VALUENAME_MAXFAILURE,
  62. &(PppConfigInfo.MaxFailure),
  63. 255,
  64. PPP_DEF_MAXFAILURE,
  65. RAS_VALUENAME_MAXREJECT,
  66. &(PppConfigInfo.MaxReject),
  67. 255,
  68. PPP_DEF_MAXREJECT,
  69. RAS_VALUENAME_RESTARTTIMER,
  70. &(PppConfigInfo.DefRestartTimer),
  71. 0xFFFFFFFF,
  72. PPP_DEF_RESTARTTIMER,
  73. RAS_VALUENAME_NEGOTIATETIME,
  74. &(PppConfigInfo.NegotiateTime),
  75. 0xFFFFFFFF,
  76. PPP_DEF_NEGOTIATETIME,
  77. RAS_VALUENAME_CALLBACKDELAY,
  78. &(PppConfigInfo.dwCallbackDelay),
  79. 255,
  80. PPP_DEF_CALLBACKDELAY,
  81. RAS_VALUENAME_PORTLIMIT,
  82. &(PppConfigInfo.dwDefaultPortLimit),
  83. 0xFFFFFFFF,
  84. PPP_DEF_PORTLIMIT,
  85. RAS_VALUENAME_SESSIONTIMEOUT,
  86. &(PppConfigInfo.dwDefaultSessionTimeout),
  87. 0xFFFFFFFF,
  88. PPP_DEF_SESSIONTIMEOUT,
  89. RAS_VALUENAME_IDLETIMEOUT,
  90. &(PppConfigInfo.dwDefaulIdleTimeout),
  91. 0xFFFFFFFF,
  92. PPP_DEF_IDLETIMEOUT,
  93. RAS_VALUENAME_BAPTHRESHOLD,
  94. &(PppConfigInfo.dwHangupExtraPercent),
  95. 100,
  96. RAS_DEF_BAPLINEDNLIMIT,
  97. RAS_VALUENAME_BAPTIME,
  98. &(PppConfigInfo.dwHangUpExtraSampleSeconds),
  99. 0xFFFFFFFF,
  100. RAS_DEF_BAPLINEDNTIME,
  101. RAS_VALUENAME_BAPLISTENTIME,
  102. &(PppConfigInfo.dwBapListenTimeoutSeconds),
  103. 0xFFFFFFFF,
  104. PPP_DEF_BAPLISTENTIME,
  105. RAS_VALUENAME_UNKNOWNPACKETTRACESIZE,
  106. &(PppConfigInfo.dwUnknownPacketTraceSize),
  107. 0xFFFFFFFF,
  108. PPP_DEF_UNKNOWNPACKETTRACESIZE,
  109. RAS_ECHO_REQUEST_INTERVAL,
  110. &(PppConfigInfo.dwLCPEchoTimeInterval),
  111. 0xFFFFFFFF,
  112. PPP_DEF_ECHO_REQUEST_INTERVAL, //Default of 60 seconds
  113. RAS_ECHO_REQUEST_IDLE,
  114. &(PppConfigInfo.dwIdleBeforeEcho),
  115. 0xFFFFFFFF,
  116. PPP_DEF_ECHO_REQUEST_IDLE, //Default of 300 seconds
  117. RAS_ECHO_NUM_MISSED_ECHOS,
  118. &(PppConfigInfo.dwNumMissedEchosBeforeDisconnect),
  119. 0xFFFFFFFF,
  120. PPP_DEF_ECHO_NUM_MISSED_ECHOS, //Default of 3 tries
  121. RAS_DONTNEGOTIATE_MULTILINKONSINGLELINK,
  122. &(PppConfigInfo.dwDontNegotiateMultiLinkOnSingleLink),
  123. 0xFFFFFFFF,
  124. 0,
  125. NULL, NULL, 0, 0
  126. };
  127. static DLL_ENTRY_POINTS * pCpDlls = (DLL_ENTRY_POINTS*)NULL;
  128. HANDLE HInstDLL;
  129. //**
  130. //
  131. // Call: LoadProtocolDlls
  132. //
  133. // Returns: NO_ERROR - Success
  134. // non-zero code - Failure
  135. //
  136. // Description: This procedure enumerates all the Subkeys under the PPP key
  137. // and loads each AP or CP and fills up the DLL_ENTRY_POINTS
  138. // structure with the required entry points. It also will return
  139. // the total number of protocols in all the Dlls. Note that each
  140. // DLL could have up to PPPCP_MAXCPSPERDLL protocols.
  141. //
  142. DWORD
  143. LoadProtocolDlls(
  144. IN DLL_ENTRY_POINTS * pCpDlls,
  145. IN DWORD cCpDlls,
  146. IN HKEY hKeyProtocols,
  147. OUT DWORD * pcTotalNumProtocols
  148. )
  149. {
  150. HKEY hKeyCp = (HKEY)NULL;
  151. LPSTR pCpDllPath = (LPSTR)NULL;
  152. LPSTR pCpDllExpandedPath = (LPSTR)NULL;
  153. DWORD dwKeyIndex;
  154. DWORD dwRetCode = ERROR_REGISTRY_CORRUPT;
  155. CHAR chSubKeyName[100];
  156. DWORD cbSubKeyName;
  157. DWORD dwNumSubKeys;
  158. DWORD dwMaxSubKeySize;
  159. DWORD dwNumValues;
  160. DWORD cbMaxValNameLen;
  161. DWORD cbMaxValueDataSize;
  162. DWORD dwSecDescLen;
  163. DWORD ProtocolIds[PPPCP_MAXCPSPERDLL];
  164. DWORD dwNumProtocolIds;
  165. FARPROC pRasCpEnumProtocolIds;
  166. FARPROC pRasCpGetInfo;
  167. DWORD cbSize;
  168. DWORD dwType;
  169. HINSTANCE hInstance;
  170. //
  171. // Read the registry to find out the various control protocols to load.
  172. //
  173. for ( dwKeyIndex = 0; dwKeyIndex < cCpDlls; dwKeyIndex++ )
  174. {
  175. cbSubKeyName = sizeof( chSubKeyName );
  176. dwRetCode = RegEnumKeyEx(
  177. hKeyProtocols,
  178. dwKeyIndex,
  179. chSubKeyName,
  180. &cbSubKeyName,
  181. NULL,
  182. NULL,
  183. NULL,
  184. NULL
  185. );
  186. if ( ( dwRetCode != NO_ERROR ) &&
  187. ( dwRetCode != ERROR_MORE_DATA ) &&
  188. ( dwRetCode != ERROR_NO_MORE_ITEMS ) )
  189. {
  190. PppLogErrorString(ROUTERLOG_CANT_ENUM_REGKEYVALUES,0,
  191. NULL,dwRetCode,0);
  192. break;
  193. }
  194. dwRetCode = RegOpenKeyEx(
  195. hKeyProtocols,
  196. chSubKeyName,
  197. 0,
  198. KEY_QUERY_VALUE,
  199. &hKeyCp );
  200. if ( dwRetCode != NO_ERROR )
  201. {
  202. PppLogErrorString(ROUTERLOG_CANT_OPEN_PPP_REGKEY,0,NULL,
  203. dwRetCode,0);
  204. break;
  205. }
  206. //
  207. // Find out the size of the path value.
  208. //
  209. dwRetCode = RegQueryInfoKey(
  210. hKeyCp,
  211. NULL,
  212. NULL,
  213. NULL,
  214. &dwNumSubKeys,
  215. &dwMaxSubKeySize,
  216. NULL,
  217. &dwNumValues,
  218. &cbMaxValNameLen,
  219. &cbMaxValueDataSize,
  220. NULL,
  221. NULL
  222. );
  223. if ( dwRetCode != NO_ERROR )
  224. {
  225. PppLogErrorString(ROUTERLOG_CANT_OPEN_PPP_REGKEY,0,NULL,
  226. dwRetCode,0);
  227. break;
  228. }
  229. //
  230. // Allocate space for path and add one for NULL terminator
  231. //
  232. pCpDllPath = (LPBYTE)LOCAL_ALLOC( LPTR, ++cbMaxValueDataSize );
  233. if ( pCpDllPath == (LPBYTE)NULL )
  234. {
  235. dwRetCode = GetLastError();
  236. PppLogError( ROUTERLOG_NOT_ENOUGH_MEMORY, 0, NULL, dwRetCode);
  237. break;
  238. }
  239. //
  240. // Read in the path
  241. //
  242. dwRetCode = RegQueryValueEx(
  243. hKeyCp,
  244. RAS_VALUENAME_PATH,
  245. NULL,
  246. &dwType,
  247. pCpDllPath,
  248. &cbMaxValueDataSize
  249. );
  250. if ( dwRetCode != NO_ERROR )
  251. {
  252. PppLogError(ROUTERLOG_CANT_GET_REGKEYVALUES, 0, NULL, dwRetCode );
  253. break;
  254. }
  255. if ( ( dwType != REG_EXPAND_SZ ) && ( dwType != REG_SZ ) )
  256. {
  257. dwRetCode = ERROR_REGISTRY_CORRUPT;
  258. PppLogError( ROUTERLOG_CANT_GET_REGKEYVALUES, 0, NULL, dwRetCode );
  259. break;
  260. }
  261. //
  262. // Replace the %SystemRoot% with the actual path.
  263. //
  264. cbSize = ExpandEnvironmentStrings( pCpDllPath, NULL, 0 );
  265. if ( cbSize == 0 )
  266. {
  267. dwRetCode = GetLastError();
  268. PppLogError( ROUTERLOG_CANT_GET_REGKEYVALUES, 0, NULL, dwRetCode );
  269. break;
  270. }
  271. pCpDllExpandedPath = (LPSTR)LOCAL_ALLOC( LPTR, ++cbSize );
  272. if ( pCpDllExpandedPath == (LPSTR)NULL )
  273. {
  274. dwRetCode = GetLastError();
  275. PppLogError( ROUTERLOG_NOT_ENOUGH_MEMORY, 0, NULL, dwRetCode);
  276. break;
  277. }
  278. cbSize = ExpandEnvironmentStrings(
  279. pCpDllPath,
  280. pCpDllExpandedPath,
  281. cbSize );
  282. if ( cbSize == 0 )
  283. {
  284. dwRetCode = GetLastError();
  285. PppLogError(ROUTERLOG_CANT_GET_REGKEYVALUES,0,NULL,dwRetCode);
  286. break;
  287. }
  288. hInstance = LoadLibrary( pCpDllExpandedPath );
  289. if ( hInstance == (HINSTANCE)NULL )
  290. {
  291. dwRetCode = GetLastError();
  292. PppLogErrorString( ROUTERLOG_PPP_CANT_LOAD_DLL,1,
  293. &pCpDllExpandedPath,dwRetCode, 1);
  294. break;
  295. }
  296. pRasCpEnumProtocolIds = GetProcAddress( hInstance,
  297. "RasCpEnumProtocolIds" );
  298. if ( pRasCpEnumProtocolIds == (FARPROC)NULL )
  299. {
  300. dwRetCode = GetLastError();
  301. PppLogErrorString( ROUTERLOG_PPPCP_DLL_ERROR, 1,
  302. &pCpDllExpandedPath, dwRetCode, 1);
  303. break;
  304. }
  305. pCpDlls[dwKeyIndex].pRasCpEnumProtocolIds = pRasCpEnumProtocolIds;
  306. dwRetCode = (DWORD) (*pRasCpEnumProtocolIds)( ProtocolIds, &dwNumProtocolIds );
  307. if ( dwRetCode != NO_ERROR )
  308. {
  309. PppLogErrorString(ROUTERLOG_PPPCP_DLL_ERROR, 1,
  310. &pCpDllExpandedPath, dwRetCode, 1);
  311. break;
  312. }
  313. (*pcTotalNumProtocols) += dwNumProtocolIds;
  314. pRasCpGetInfo = GetProcAddress( hInstance, "RasCpGetInfo" );
  315. if ( pRasCpGetInfo == (FARPROC)NULL )
  316. {
  317. dwRetCode = GetLastError();
  318. PppLogErrorString(ROUTERLOG_PPPCP_DLL_ERROR, 1,
  319. &pCpDllExpandedPath, dwRetCode, 1);
  320. break;
  321. }
  322. pCpDlls[dwKeyIndex].pRasCpGetInfo = pRasCpGetInfo;
  323. RegCloseKey( hKeyCp );
  324. hKeyCp = (HKEY)NULL;
  325. pCpDlls[dwKeyIndex].pszModuleName = pCpDllExpandedPath;
  326. pCpDlls[dwKeyIndex].hInstance = hInstance;
  327. if ( NULL != pCpDllPath )
  328. LOCAL_FREE( pCpDllPath );
  329. pCpDllPath = (LPSTR)NULL;
  330. }
  331. if ( hKeyCp != (HKEY)NULL )
  332. RegCloseKey( hKeyCp );
  333. if ( pCpDllPath != (LPSTR)NULL )
  334. LOCAL_FREE( pCpDllPath );
  335. return( dwRetCode );
  336. }
  337. //**
  338. //
  339. // Call: ReadPPPKeyValues
  340. //
  341. // Returns: NO_ERROR - Success
  342. // Non-zero - Failure
  343. //
  344. // Description: Will read in all the values in the PPP key.
  345. //
  346. DWORD
  347. ReadPPPKeyValues(
  348. IN HKEY hKeyPpp
  349. )
  350. {
  351. DWORD dwIndex;
  352. DWORD dwRetCode = ERROR_REGISTRY_CORRUPT;
  353. DWORD cbValueBuf;
  354. DWORD dwType;
  355. //
  356. // Run through and get all the PPP values
  357. //
  358. for ( dwIndex = 0; PppRegParams[dwIndex].pszValueName != NULL; dwIndex++ )
  359. {
  360. cbValueBuf = sizeof( DWORD );
  361. dwRetCode = RegQueryValueEx(
  362. hKeyPpp,
  363. PppRegParams[dwIndex].pszValueName,
  364. NULL,
  365. &dwType,
  366. (LPBYTE)(PppRegParams[dwIndex].pValue),
  367. &cbValueBuf
  368. );
  369. if ((dwRetCode != NO_ERROR) && (dwRetCode != ERROR_FILE_NOT_FOUND))
  370. {
  371. PppLogError(ROUTERLOG_CANT_GET_REGKEYVALUES,0,NULL,dwRetCode);
  372. break;
  373. }
  374. if ( dwRetCode == ERROR_FILE_NOT_FOUND )
  375. {
  376. *(PppRegParams[dwIndex].pValue) = PppRegParams[dwIndex].dwDefValue;
  377. dwRetCode = NO_ERROR;
  378. }
  379. else
  380. {
  381. if ( ( dwType != REG_DWORD ) ||
  382. ( *(PppRegParams[dwIndex].pValue) > PppRegParams[dwIndex].Max))
  383. {
  384. CHAR * pChar = PppRegParams[dwIndex].pszValueName;
  385. PppLogWarning(ROUTERLOG_REGVALUE_OVERIDDEN, 1,&pChar);
  386. *(PppRegParams[dwIndex].pValue)
  387. = PppRegParams[dwIndex].dwDefValue;
  388. }
  389. }
  390. }
  391. if ( dwRetCode != NO_ERROR )
  392. {
  393. return( ERROR_REGISTRY_CORRUPT );
  394. }
  395. //
  396. // If value is zero use defaults.
  397. //
  398. if ( PppConfigInfo.MaxTerminate == 0 )
  399. {
  400. PppConfigInfo.MaxTerminate = PPP_DEF_MAXTERMINATE;
  401. }
  402. if ( PppConfigInfo.MaxFailure == 0 )
  403. {
  404. PppConfigInfo.MaxFailure = PPP_DEF_MAXFAILURE;
  405. }
  406. if ( PppConfigInfo.MaxConfigure == 0 )
  407. {
  408. PppConfigInfo.MaxConfigure = PPP_DEF_MAXCONFIGURE;
  409. }
  410. if ( PppConfigInfo.MaxReject == 0 )
  411. {
  412. PppConfigInfo.MaxReject = PPP_DEF_MAXREJECT;
  413. }
  414. //
  415. // Really the number for request retries so subtract one.
  416. //
  417. PppConfigInfo.MaxTerminate--;
  418. PppConfigInfo.MaxConfigure--;
  419. return( NO_ERROR );
  420. }
  421. //**
  422. //
  423. // Call: ReadRegistryInfo
  424. //
  425. // Returns: NO_ERROR - Success
  426. // non-zero WIN32 error - failure
  427. //
  428. // Description: Will read all PPP information in the registry. Will load the
  429. // control and authentication protocol dlls and
  430. // initialze the CpTable with information about the protocols.
  431. //
  432. DWORD
  433. ReadRegistryInfo(
  434. OUT HKEY * phKeyPpp
  435. )
  436. {
  437. HKEY hKeyProtocols = (HKEY)NULL;
  438. DWORD dwNumSubKeys = 0;
  439. DWORD dwMaxSubKeySize;
  440. DWORD dwNumValues;
  441. DWORD cbMaxValNameLen;
  442. DWORD cbMaxValueDataSize;
  443. DWORD dwSecDescLen;
  444. FILETIME LastWrite;
  445. DWORD dwRetCode;
  446. DWORD ProtocolIds[PPPCP_MAXCPSPERDLL];
  447. DWORD dwNumProtocolIds;
  448. DWORD cTotalNumProtocols = 0;
  449. PPPCP_ENTRY CpEntry;
  450. DWORD dwIndex;
  451. DWORD cbValueBuf;
  452. DWORD dwType;
  453. DWORD dwValue;
  454. do
  455. {
  456. dwRetCode = RegOpenKeyEx(
  457. HKEY_LOCAL_MACHINE,
  458. RAS_KEYPATH_PPP,
  459. 0,
  460. KEY_READ,
  461. phKeyPpp );
  462. if ( dwRetCode != NO_ERROR)
  463. {
  464. PppLogErrorString(ROUTERLOG_CANT_OPEN_PPP_REGKEY,0,NULL,
  465. dwRetCode,0);
  466. break;
  467. }
  468. dwRetCode = RegOpenKeyEx(
  469. HKEY_LOCAL_MACHINE,
  470. RAS_KEYPATH_PROTOCOLS,
  471. 0,
  472. KEY_READ,
  473. &hKeyProtocols );
  474. if ( dwRetCode != NO_ERROR)
  475. {
  476. PppLogErrorString(ROUTERLOG_CANT_OPEN_PPP_REGKEY,0,NULL,
  477. dwRetCode,0);
  478. break;
  479. }
  480. //
  481. // Find out how many sub-keys or dlls there are
  482. //
  483. dwRetCode = RegQueryInfoKey(
  484. hKeyProtocols,
  485. NULL,
  486. NULL,
  487. NULL,
  488. &dwNumSubKeys,
  489. &dwMaxSubKeySize,
  490. NULL,
  491. &dwNumValues,
  492. &cbMaxValNameLen,
  493. &cbMaxValueDataSize,
  494. NULL,
  495. NULL
  496. );
  497. if ( dwRetCode != NO_ERROR )
  498. {
  499. PppLogErrorString(ROUTERLOG_CANT_OPEN_PPP_REGKEY,0,
  500. NULL,dwRetCode,0);
  501. break;
  502. }
  503. //
  504. // Cannot have no APs or NCPs
  505. //
  506. if ( dwNumSubKeys == 0 )
  507. {
  508. PppLogError( ROUTERLOG_NO_AUTHENTICATION_CPS, 0, NULL, 0 );
  509. dwRetCode = ERROR_REGISTRY_CORRUPT;
  510. break;
  511. }
  512. dwRetCode = ReadPPPKeyValues( *phKeyPpp );
  513. if ( dwRetCode != NO_ERROR )
  514. {
  515. break;
  516. }
  517. LoadParserDll( PppConfigInfo.hKeyPpp );
  518. //
  519. // Allocate space to hold entry points for all the CP dlls
  520. //
  521. pCpDlls = (DLL_ENTRY_POINTS*)LOCAL_ALLOC( LPTR,
  522. sizeof( DLL_ENTRY_POINTS )
  523. * (dwNumSubKeys + 1) );
  524. if ( pCpDlls == (DLL_ENTRY_POINTS*)NULL )
  525. {
  526. dwRetCode = GetLastError();
  527. PppLogError( ROUTERLOG_NOT_ENOUGH_MEMORY, 0, NULL, dwRetCode );
  528. break;
  529. }
  530. pCpDlls[dwNumSubKeys].hInstance = INVALID_HANDLE_VALUE;
  531. //
  532. // Load all the AP and CP dlls and get their entry points
  533. //
  534. dwRetCode = LoadProtocolDlls(
  535. pCpDlls,
  536. dwNumSubKeys,
  537. hKeyProtocols,
  538. &cTotalNumProtocols );
  539. if ( dwRetCode != NO_ERROR )
  540. break;
  541. //
  542. // We now know how big the CpTable structure has to be so allocate space
  543. // for it. Add one for LCP.
  544. //
  545. CpTable = (PPPCP_ENTRY *)LOCAL_ALLOC( LPTR, sizeof( PPPCP_ENTRY ) *
  546. ( cTotalNumProtocols + 1 ) );
  547. if ( CpTable == (PPPCP_ENTRY *)NULL)
  548. {
  549. dwRetCode = GetLastError();
  550. PppLogError( ROUTERLOG_NOT_ENOUGH_MEMORY, 0, NULL, dwRetCode );
  551. break;
  552. }
  553. //
  554. // Now fill up the table. First fill up information for LCP
  555. //
  556. dwRetCode = LcpGetInfo( PPP_LCP_PROTOCOL,
  557. &(CpTable[LCP_INDEX].CpInfo) );
  558. if ( dwRetCode != NO_ERROR )
  559. {
  560. CHAR * pChar = "LCP";
  561. PppLogErrorString(ROUTERLOG_PPPCP_DLL_ERROR, 1,
  562. &pChar, dwRetCode, 1);
  563. break;
  564. }
  565. PppConfigInfo.NumberOfCPs = 1;
  566. PppConfigInfo.NumberOfAPs = 0;
  567. //
  568. // Fill up the table with the loaded APs and CPs. The CPs start from
  569. // 1 and increase the APs start from cTotolNumProtocols and go down.
  570. //
  571. for ( dwIndex = 0; dwIndex < dwNumSubKeys; dwIndex++ )
  572. {
  573. dwRetCode = (DWORD)(pCpDlls[dwIndex].pRasCpEnumProtocolIds)(
  574. ProtocolIds,
  575. &dwNumProtocolIds );
  576. if ( dwRetCode != NO_ERROR )
  577. {
  578. PppLogErrorString(
  579. ROUTERLOG_PPPCP_DLL_ERROR,
  580. 1,
  581. &(pCpDlls[dwIndex].pszModuleName),
  582. dwRetCode,
  583. 1 );
  584. break;
  585. }
  586. if ( ( dwNumProtocolIds == 0 ) ||
  587. ( dwNumProtocolIds > PPPCP_MAXCPSPERDLL ) )
  588. {
  589. dwRetCode = ERROR_INVALID_PARAMETER;
  590. PppLogErrorString(
  591. ROUTERLOG_PPPCP_DLL_ERROR,
  592. 1,
  593. &(pCpDlls[dwIndex].pszModuleName),
  594. dwRetCode,
  595. 1 );
  596. break;
  597. }
  598. while( dwNumProtocolIds-- > 0 )
  599. {
  600. ZeroMemory( &CpEntry, sizeof( CpEntry ) );
  601. dwRetCode = (DWORD)(pCpDlls[dwIndex].pRasCpGetInfo)(
  602. ProtocolIds[dwNumProtocolIds],
  603. &CpEntry.CpInfo );
  604. if ( dwRetCode != NO_ERROR )
  605. {
  606. PppLogErrorString(
  607. ROUTERLOG_PPPCP_DLL_ERROR,
  608. 1,
  609. &(pCpDlls[dwIndex].pszModuleName),
  610. dwRetCode,
  611. 1 );
  612. break;
  613. }
  614. if ( CpEntry.CpInfo.Protocol == PPP_IPCP_PROTOCOL )
  615. {
  616. PppConfigInfo.RasIpcpDhcpInform =
  617. (DWORD(*)(VOID*, PPP_DHCP_INFORM*))
  618. IpcpDhcpInform;
  619. PppConfigInfo.RasIphlpDhcpCallback =
  620. (VOID(*)(ULONG))
  621. RasSrvrDhcpCallback;
  622. }
  623. if ( CpEntry.CpInfo.RasCpInit != NULL )
  624. {
  625. if ( (PPP_IPCP_PROTOCOL == CpEntry.CpInfo.Protocol)
  626. || (PPP_IPXCP_PROTOCOL == CpEntry.CpInfo.Protocol)
  627. || (PPP_NBFCP_PROTOCOL == CpEntry.CpInfo.Protocol)
  628. || (PPP_ATCP_PROTOCOL == CpEntry.CpInfo.Protocol)
  629. )
  630. {
  631. // Do not init the CP.
  632. }
  633. else
  634. {
  635. PppLog(1, "RasCpInit(%x, TRUE)", CpEntry.CpInfo.Protocol);
  636. dwRetCode = CpEntry.CpInfo.RasCpInit(
  637. TRUE/* fInitialize */);
  638. CpEntry.fFlags |= PPPCP_FLAG_INIT_CALLED;
  639. if ( dwRetCode != NO_ERROR )
  640. {
  641. CHAR* SubStringArray[2];
  642. SubStringArray[0] = CpEntry.CpInfo.SzProtocolName;
  643. SubStringArray[1] = pCpDlls[dwIndex].pszModuleName;
  644. PppLogErrorString(
  645. ROUTERLOG_PPPCP_INIT_ERROR,
  646. 2,
  647. SubStringArray,
  648. dwRetCode,
  649. 2 );
  650. break;
  651. }
  652. else
  653. {
  654. CpEntry.fFlags |= PPPCP_FLAG_AVAILABLE;
  655. }
  656. }
  657. }
  658. //
  659. // If this entry point is NULL we assume that this is a CP.
  660. //
  661. if ( CpEntry.CpInfo.RasApMakeMessage == NULL )
  662. {
  663. if ( ( CpEntry.CpInfo.RasCpBegin == NULL ) ||
  664. ( CpEntry.CpInfo.RasCpEnd == NULL ) ||
  665. ( CpEntry.CpInfo.RasCpReset == NULL ) ||
  666. ( CpEntry.CpInfo.RasCpMakeConfigRequest == NULL ) ||
  667. ( CpEntry.CpInfo.RasCpMakeConfigResult == NULL ) ||
  668. ( CpEntry.CpInfo.RasCpConfigAckReceived == NULL ) ||
  669. ( CpEntry.CpInfo.RasCpConfigNakReceived == NULL ) ||
  670. ( CpEntry.CpInfo.RasCpConfigRejReceived == NULL ) ||
  671. ( CpEntry.CpInfo.Recognize > ( DISCARD_REQ + 1) ) )
  672. {
  673. dwRetCode = ERROR_INVALID_PARAMETER;
  674. PppLogErrorString(
  675. ROUTERLOG_PPPCP_DLL_ERROR,
  676. 1,
  677. &(pCpDlls[dwIndex].pszModuleName),
  678. dwRetCode,
  679. 1 );
  680. break;
  681. }
  682. CpTable[PppConfigInfo.NumberOfCPs++] = CpEntry;
  683. }
  684. else
  685. {
  686. CpTable[cTotalNumProtocols-PppConfigInfo.NumberOfAPs]
  687. = CpEntry;
  688. PppConfigInfo.NumberOfAPs++;
  689. }
  690. }
  691. if ( dwRetCode != NO_ERROR )
  692. break;
  693. }
  694. if ( GetCpIndexFromProtocol( PPP_BACP_PROTOCOL ) == (DWORD)-1 )
  695. {
  696. PppConfigInfo.ServerConfigInfo.dwConfigMask &= ~PPPCFG_NegotiateBacp;
  697. }
  698. else if ( PppConfigInfo.ServerConfigInfo.dwConfigMask &
  699. PPPCFG_NegotiateBacp )
  700. {
  701. cbValueBuf = sizeof(DWORD);
  702. if (RegQueryValueEx(
  703. *phKeyPpp, RAS_VALUENAME_DOBAPONVPN,
  704. NULL, &dwType,
  705. (LPBYTE )&dwValue, &cbValueBuf ) == 0
  706. && dwType == REG_DWORD
  707. && cbValueBuf == sizeof(DWORD)
  708. && dwValue)
  709. {
  710. FDoBapOnVpn = TRUE;
  711. BapTrace( "Allowing BAP over VPN's" );
  712. }
  713. }
  714. } while( FALSE );
  715. if ( dwRetCode != NO_ERROR )
  716. {
  717. if ( CpTable != (PPPCP_ENTRY *)NULL )
  718. {
  719. LOCAL_FREE( CpTable );
  720. }
  721. }
  722. if ( hKeyProtocols != (HKEY)NULL )
  723. {
  724. RegCloseKey( hKeyProtocols );
  725. }
  726. if ( pCpDlls != (DLL_ENTRY_POINTS*)NULL )
  727. {
  728. for ( dwIndex = 0; dwIndex < dwNumSubKeys; dwIndex++ )
  729. {
  730. if ( pCpDlls[dwIndex].pszModuleName != (LPSTR)NULL )
  731. {
  732. LOCAL_FREE( pCpDlls[dwIndex].pszModuleName );
  733. }
  734. }
  735. if ( dwRetCode != NO_ERROR )
  736. {
  737. LOCAL_FREE( pCpDlls );
  738. pCpDlls = NULL;
  739. }
  740. }
  741. return( dwRetCode );
  742. }
  743. //**
  744. //
  745. // Call: InitializePPP
  746. //
  747. // Returns: NO_ERROR - Success
  748. // non-zero code - Failure
  749. //
  750. // Description: Will initialize all global data and load and initialize the
  751. // Control and Authentication protocol dll.s
  752. //
  753. DWORD
  754. InitializePPP(
  755. VOID
  756. )
  757. {
  758. DWORD dwIndex;
  759. DWORD dwTId;
  760. DWORD dwRetCode;
  761. HANDLE hThread;
  762. NT_PRODUCT_TYPE NtProductType;
  763. OSVERSIONINFOEX stOsVer;
  764. srand ( (unsigned int)time ( NULL ) );
  765. PppConfigInfo.dwTraceId = TraceRegisterA( "PPP" );
  766. DwBapTraceId = TraceRegisterA( "BAP" );
  767. // PrivateTraceId = TraceRegisterA( "Private" );
  768. PppConfigInfo.hLogEvents = RouterLogRegister( TEXT("RemoteAccess") );
  769. PppConfigInfo.RasIpcpDhcpInform = NULL;
  770. PppConfigInfo.RasIphlpDhcpCallback = NULL;
  771. PppConfigInfo.dwLoggingLevel = 3;
  772. WorkItemQ.pQHead = (PCB_WORK_ITEM*)NULL;
  773. WorkItemQ.pQTail = (PCB_WORK_ITEM*)NULL;
  774. InitializeCriticalSection( &(WorkItemQ.CriticalSection) );
  775. WorkItemQ.hEventNonEmpty = CreateEvent( NULL, TRUE, FALSE, NULL );
  776. if ( WorkItemQ.hEventNonEmpty == (HANDLE)NULL )
  777. {
  778. return( GetLastError() );
  779. }
  780. //
  781. // Create DDM private heap
  782. //
  783. PppConfigInfo.hHeap = HeapCreate( 0, PPP_HEAP_INITIAL_SIZE,
  784. PPP_HEAP_MAX_SIZE );
  785. if ( PppConfigInfo.hHeap == NULL )
  786. {
  787. return( GetLastError() );
  788. }
  789. if ( (dwRetCode = ReadRegistryInfo(&(PppConfigInfo.hKeyPpp))) != NO_ERROR )
  790. {
  791. return( dwRetCode );
  792. }
  793. dwRetCode = InitEndpointDiscriminator(PppConfigInfo.EndPointDiscriminator);
  794. if ( dwRetCode != NO_ERROR )
  795. {
  796. return( dwRetCode );
  797. }
  798. PppConfigInfo.PortUIDGenerator = 0;
  799. //
  800. // Initialize global data-structures
  801. //
  802. //
  803. // Allocate hash table for PCBs
  804. //
  805. PcbTable.PcbBuckets = LOCAL_ALLOC( LPTR,
  806. sizeof( PCB_BUCKET ) *
  807. PcbTable.NumPcbBuckets );
  808. if ( PcbTable.PcbBuckets == NULL )
  809. {
  810. return( GetLastError() );
  811. }
  812. //
  813. // Allocate hash table for BCBs
  814. //
  815. PcbTable.BcbBuckets = LOCAL_ALLOC( LPTR,
  816. sizeof( BCB_BUCKET ) *
  817. PcbTable.NumPcbBuckets );
  818. if ( PcbTable.BcbBuckets == NULL )
  819. {
  820. LOCAL_FREE( PcbTable.PcbBuckets );
  821. return( GetLastError() );
  822. }
  823. for( dwIndex = 0; dwIndex < PcbTable.NumPcbBuckets; dwIndex++ )
  824. {
  825. PcbTable.PcbBuckets[dwIndex].pPorts = (PCB *)NULL;
  826. PcbTable.BcbBuckets[dwIndex].pBundles = (BCB *)NULL;
  827. }
  828. TimerQ.hEventNonEmpty = CreateEvent( NULL, FALSE, FALSE, NULL );
  829. if ( TimerQ.hEventNonEmpty == (HANDLE)NULL )
  830. {
  831. return( GetLastError() );
  832. }
  833. PppConfigInfo.hEventChangeNotification = CreateEvent(NULL,FALSE,FALSE,NULL);
  834. if ( PppConfigInfo.hEventChangeNotification == (HANDLE)NULL )
  835. {
  836. return( GetLastError() );
  837. }
  838. RtlGetNtProductType( &NtProductType );
  839. if ( NtProductWinNt == NtProductType )
  840. {
  841. PppConfigInfo.fFlags |= PPPCONFIG_FLAG_WKSTA;
  842. }
  843. //
  844. //Check to see if this is a blade and if it is a blade then
  845. //behave like workstation.
  846. //
  847. ZeroMemory( &stOsVer, sizeof(stOsVer) );
  848. stOsVer.dwOSVersionInfoSize = sizeof(stOsVer);
  849. RtlGetVersion ( (PRTL_OSVERSIONINFOW)&stOsVer );
  850. if ( stOsVer.wSuiteMask & VER_SUITE_BLADE )
  851. {
  852. PppConfigInfo.fFlags |= PPPCONFIG_FLAG_WKSTA;
  853. }
  854. //
  855. // Create worker thread.
  856. //
  857. hThread = CreateThread( NULL, 0, WorkerThread, NULL, 0, &dwTId );
  858. if ( hThread == (HANDLE)NULL )
  859. {
  860. return( GetLastError() );
  861. }
  862. CloseHandle(hThread);
  863. return( NO_ERROR );
  864. }
  865. //**
  866. //
  867. // Call: PPPCleanUp
  868. //
  869. // Returns: NO_ERROR - Success
  870. // Non-zero returns - Failure
  871. //
  872. // Description: Will de-allocate all allocated memory, close all handles and
  873. // reset all the global structures to 0.
  874. //
  875. VOID
  876. PPPCleanUp(
  877. VOID
  878. )
  879. {
  880. DWORD dwIndex;
  881. DWORD dwError;
  882. DWORD cTotalNumProtocols;
  883. //
  884. // Unload DLLs.
  885. //
  886. cTotalNumProtocols = PppConfigInfo.NumberOfCPs + PppConfigInfo.NumberOfAPs;
  887. if ( pCpDlls != NULL )
  888. {
  889. for ( dwIndex = 0; dwIndex < cTotalNumProtocols; dwIndex++ )
  890. {
  891. if ( CpTable[dwIndex].fFlags & PPPCP_FLAG_INIT_CALLED )
  892. {
  893. PppLog( 1, "RasCpInit(%x, FALSE)",
  894. CpTable[dwIndex].CpInfo.Protocol );
  895. dwError = CpTable[dwIndex].CpInfo.RasCpInit(
  896. FALSE /* fInitialize */ );
  897. if ( NO_ERROR != dwError )
  898. {
  899. PppLog(
  900. 1,
  901. "RasCpInit(FALSE) for protocol 0x%x returned error %d",
  902. CpTable[dwIndex].CpInfo.Protocol,
  903. dwError );
  904. }
  905. CpTable[dwIndex].fFlags &= ~PPPCP_FLAG_INIT_CALLED;
  906. CpTable[dwIndex].fFlags &= ~PPPCP_FLAG_AVAILABLE;
  907. }
  908. }
  909. for ( dwIndex = 0;
  910. pCpDlls[dwIndex].hInstance != INVALID_HANDLE_VALUE;
  911. dwIndex++ )
  912. {
  913. if ( pCpDlls[dwIndex].hInstance != NULL )
  914. {
  915. FreeLibrary( pCpDlls[dwIndex].hInstance );
  916. }
  917. }
  918. if ( pCpDlls )
  919. LOCAL_FREE( pCpDlls );
  920. pCpDlls = NULL;
  921. }
  922. RouterLogDeregister( PppConfigInfo.hLogEvents );
  923. DeleteCriticalSection( &(WorkItemQ.CriticalSection) );
  924. if ( TimerQ.hEventNonEmpty != NULL )
  925. {
  926. CloseHandle( TimerQ.hEventNonEmpty );
  927. }
  928. if ( WorkItemQ.hEventNonEmpty != NULL )
  929. {
  930. CloseHandle( WorkItemQ.hEventNonEmpty );
  931. }
  932. if ( PppConfigInfo.hEventChangeNotification != NULL )
  933. {
  934. CloseHandle( PppConfigInfo.hEventChangeNotification );
  935. }
  936. //
  937. // Destroy private heap
  938. //
  939. if ( PppConfigInfo.hHeap != NULL )
  940. {
  941. HeapDestroy( PppConfigInfo.hHeap );
  942. }
  943. if ( PppConfigInfo.dwTraceId != INVALID_TRACEID )
  944. {
  945. TraceDeregisterA( PppConfigInfo.dwTraceId );
  946. }
  947. if ( PppConfigInfo.hKeyPpp != (HKEY)NULL )
  948. {
  949. RegCloseKey( PppConfigInfo.hKeyPpp );
  950. }
  951. if ( NULL != PppConfigInfo.hInstanceParserDll )
  952. {
  953. FreeLibrary( PppConfigInfo.hInstanceParserDll );
  954. }
  955. if (NULL != PppConfigInfo.pszParserDllPath)
  956. {
  957. LOCAL_FREE(PppConfigInfo.pszParserDllPath);
  958. }
  959. PppConfigInfo.pszParserDllPath = NULL;
  960. PppConfigInfo.PacketFromPeer = NULL;
  961. PppConfigInfo.PacketToPeer = NULL;
  962. PppConfigInfo.PacketFree = NULL;
  963. //
  964. // TraceDeregisterA can handle INVALID_TRACEID gracefully
  965. //
  966. TraceDeregisterA( DwBapTraceId );
  967. ZeroMemory( &PcbTable, sizeof( PcbTable ) );
  968. ZeroMemory( &WorkItemQ, sizeof( WorkItemQ ) );
  969. ZeroMemory( &PppConfigInfo, sizeof( PppConfigInfo ) );
  970. ZeroMemory( &TimerQ, sizeof( TimerQ ) );
  971. CpTable = NULL;
  972. }
  973. //**
  974. //
  975. // Call: DllEntryPoint
  976. //
  977. // Returns: TRUE - Success
  978. // FALSE - Failure
  979. //
  980. // Description:
  981. //
  982. BOOL
  983. DllEntryPoint(
  984. IN HANDLE hInstDLL,
  985. IN DWORD fdwReason,
  986. IN LPVOID lpvReserved
  987. )
  988. {
  989. switch (fdwReason)
  990. {
  991. case DLL_PROCESS_ATTACH:
  992. HInstDLL = hInstDLL;
  993. DisableThreadLibraryCalls(hInstDLL);
  994. break;
  995. }
  996. return(TRUE);
  997. }
  998. //**
  999. //
  1000. // Call: RasCpEnumProtocolIds
  1001. //
  1002. // Returns: NO_ERROR - Success
  1003. //
  1004. // Description: This entry point is called to enumerate the number and the
  1005. // control protocol Ids for the protocols contained in the module.
  1006. //
  1007. DWORD
  1008. RasCpEnumProtocolIds(
  1009. OUT DWORD * pdwProtocolIds,
  1010. IN OUT DWORD * pcProtocolIds
  1011. )
  1012. {
  1013. DWORD dwIndex;
  1014. HKEY hKey;
  1015. DWORD dwErr;
  1016. DWORD dwType;
  1017. DWORD dwValue;
  1018. DWORD dwSize;
  1019. PppLog(1, "RasCpEnumProtocolIds");
  1020. RTASSERT(NUM_BUILT_IN_CPS <= PPPCP_MAXCPSPERDLL);
  1021. *pcProtocolIds = 0;
  1022. dwErr = RegOpenKeyEx(HKEY_LOCAL_MACHINE, RAS_KEYPATH_BUILTIN, 0, KEY_READ,
  1023. &hKey);
  1024. if (ERROR_SUCCESS == dwErr)
  1025. {
  1026. for (dwIndex = 0; dwIndex < NUM_BUILT_IN_CPS; dwIndex++)
  1027. {
  1028. dwSize = sizeof(dwValue);
  1029. dwErr = RegQueryValueEx(hKey, BuiltInCps[dwIndex].szNegotiateCp,
  1030. NULL, &dwType, (BYTE*)&dwValue, &dwSize);
  1031. if ( ERROR_SUCCESS == dwErr
  1032. && REG_DWORD == dwType
  1033. && sizeof(DWORD) == dwSize
  1034. && !dwValue)
  1035. {
  1036. BuiltInCps[dwIndex].fLoad = FALSE;
  1037. PppLog(1, "%s is FALSE", BuiltInCps[dwIndex].szNegotiateCp);
  1038. }
  1039. }
  1040. RegCloseKey(hKey);
  1041. }
  1042. for (dwIndex = 0; dwIndex < NUM_BUILT_IN_CPS; dwIndex++)
  1043. {
  1044. if (BuiltInCps[dwIndex].fLoad)
  1045. {
  1046. pdwProtocolIds[*pcProtocolIds] = BuiltInCps[dwIndex].dwProtocolId;
  1047. PppLog(1, "Protocol %x", BuiltInCps[dwIndex].dwProtocolId);
  1048. *pcProtocolIds += 1;
  1049. }
  1050. }
  1051. return(NO_ERROR);
  1052. }
  1053. //**
  1054. //
  1055. // Call: RasCpGetInfo
  1056. //
  1057. // Returns: NO_ERROR - Success
  1058. // ERROR_INVALID_PARAMETER - Protocol id is unrecogized
  1059. //
  1060. // Description: This entry point is called for get all information for the
  1061. // control protocol in this module.
  1062. //
  1063. DWORD
  1064. RasCpGetInfo(
  1065. IN DWORD dwProtocolId,
  1066. OUT PPPCP_INFO* pCpInfo
  1067. )
  1068. {
  1069. DWORD dwIndex;
  1070. PppLog(1, "RasCpGetInfo %x", dwProtocolId);
  1071. for (dwIndex = 0; dwIndex < NUM_BUILT_IN_CPS; dwIndex++)
  1072. {
  1073. if ( (BuiltInCps[dwIndex].dwProtocolId == dwProtocolId)
  1074. && BuiltInCps[dwIndex].fLoad)
  1075. {
  1076. return((DWORD)BuiltInCps[dwIndex].pRasCpGetInfo(
  1077. dwProtocolId, pCpInfo));
  1078. }
  1079. }
  1080. return(ERROR_INVALID_PARAMETER);
  1081. }
  1082. VOID
  1083. PrivateTrace(
  1084. IN CHAR* Format,
  1085. ...
  1086. )
  1087. {
  1088. va_list arglist;
  1089. va_start(arglist, Format);
  1090. TraceVprintfEx(PrivateTraceId,
  1091. 0x00010000 | TRACE_USE_MASK | TRACE_USE_MSEC,
  1092. Format,
  1093. arglist);
  1094. va_end(arglist);
  1095. }