Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1707 lines
48 KiB

  1. /*******************************************************************/
  2. /* Copyright(c) 1992 Microsoft Corporation */
  3. /*******************************************************************/
  4. //***
  5. //
  6. // Filename: registry.c
  7. //
  8. // Description: This module contains the code for DDM parameters
  9. // initialization and loading from the registry.
  10. //
  11. // Author: Stefan Solomon (stefans) May 18, 1992.
  12. //
  13. //***
  14. #include "ddm.h"
  15. #include <string.h>
  16. #include <stdlib.h>
  17. #include <ddmparms.h>
  18. #include <rasauth.h>
  19. #include <util.h>
  20. typedef struct _DDM_REGISTRY_PARAMS
  21. {
  22. LPWSTR pszValueName;
  23. DWORD * pValue;
  24. DWORD dwDefValue;
  25. DWORD Min;
  26. DWORD Max;
  27. } DDM_REGISTRY_PARAMS, *PDDM_REGISTRY_PARAMS;
  28. //
  29. // DDM parameter descriptor table
  30. //
  31. DDM_REGISTRY_PARAMS DDMRegParams[] =
  32. {
  33. // authenticateretries
  34. DDM_VALNAME_AUTHENTICATERETRIES,
  35. &gblDDMConfigInfo.dwAuthenticateRetries,
  36. DEF_AUTHENTICATERETRIES,
  37. MIN_AUTHENTICATERETRIES,
  38. MAX_AUTHENTICATERETRIES,
  39. // authenticatetime
  40. DDM_VALNAME_AUTHENTICATETIME,
  41. &gblDDMConfigInfo.dwAuthenticateTime,
  42. DEF_AUTHENTICATETIME,
  43. MIN_AUTHENTICATETIME,
  44. MAX_AUTHENTICATETIME,
  45. // callbacktime
  46. DDM_VALNAME_CALLBACKTIME,
  47. &gblDDMConfigInfo.dwCallbackTime,
  48. DEF_CALLBACKTIME,
  49. MIN_CALLBACKTIME,
  50. MAX_CALLBACKTIME,
  51. // Autodisconnect Time
  52. DDM_VALNAME_AUTODISCONNECTTIME,
  53. &gblDDMConfigInfo.dwAutoDisconnectTime,
  54. DEF_AUTODISCONNECTTIME,
  55. MIN_AUTODISCONNECTTIME,
  56. MAX_AUTODISCONNECTTIME,
  57. // Clients per process
  58. DDM_VALNAME_CLIENTSPERPROC,
  59. &gblDDMConfigInfo.dwClientsPerProc,
  60. DEF_CLIENTSPERPROC,
  61. MIN_CLIENTSPERPROC,
  62. MAX_CLIENTSPERPROC,
  63. // Time for 3rd party security DLL to complete
  64. DDM_VALNAME_SECURITYTIME,
  65. &gblDDMConfigInfo.dwSecurityTime,
  66. DEF_SECURITYTIME,
  67. MIN_SECURITYTIME,
  68. MAX_SECURITYTIME,
  69. // Logging level
  70. DDM_VALNAME_LOGGING_LEVEL,
  71. &gblDDMConfigInfo.dwLoggingLevel,
  72. DEF_LOGGINGLEVEL,
  73. MIN_LOGGINGLEVEL,
  74. MAX_LOGGINGLEVEL,
  75. // Number of callback retries
  76. DDM_VALNAME_NUM_CALLBACK_RETRIES,
  77. &gblDDMConfigInfo.dwCallbackRetries,
  78. DEF_NUMCALLBACKRETRIES,
  79. MIN_NUMCALLBACKRETRIES,
  80. MAX_NUMCALLBACKRETRIES,
  81. DDM_VALNAME_SERVERFLAGS,
  82. &gblDDMConfigInfo.dwServerFlags,
  83. DEF_SERVERFLAGS,
  84. 0,
  85. 0xFFFFFFFF,
  86. // End
  87. NULL, NULL, 0, 0, 0
  88. };
  89. //***
  90. //
  91. // Function: GetKeyMax
  92. //
  93. // Descr: returns the nr of values in this key and the maximum
  94. // size of the value data.
  95. //
  96. //***
  97. DWORD
  98. GetKeyMax(
  99. IN HKEY hKey,
  100. OUT LPDWORD MaxValNameSize_ptr, // longest valuename
  101. OUT LPDWORD NumValues_ptr, // nr of values
  102. OUT LPDWORD MaxValueDataSize_ptr // max size of data
  103. )
  104. {
  105. DWORD NumSubKeys;
  106. DWORD MaxSubKeySize;
  107. DWORD dwRetCode;
  108. dwRetCode = RegQueryInfoKey( hKey, NULL, NULL, NULL, &NumSubKeys,
  109. &MaxSubKeySize, NULL, NumValues_ptr,
  110. MaxValNameSize_ptr, MaxValueDataSize_ptr,
  111. NULL, NULL );
  112. (*MaxValNameSize_ptr)++;
  113. return( dwRetCode );
  114. }
  115. //***
  116. //
  117. // Function: LoadDDMParameters
  118. //
  119. // Descr: Opens the registry, reads and sets specified supervisor
  120. // parameters. If fatal error reading parameters writes the
  121. // error log.
  122. //
  123. // Returns: NO_ERROR - success
  124. // else - fatal error.
  125. //
  126. //***
  127. DWORD
  128. LoadDDMParameters(
  129. IN HKEY hkeyParameters,
  130. OUT BOOL* pfIpAllowed
  131. )
  132. {
  133. DWORD dwIndex;
  134. DWORD dwRetCode;
  135. DWORD cbValueBuf;
  136. DWORD dwType;
  137. DWORD fIpxAllowed;
  138. //
  139. // Initialize Global values
  140. //
  141. gblDDMConfigInfo.fRemoteListen = TRUE;
  142. gblDDMConfigInfo.dwAnnouncePresenceTimer = ANNOUNCE_PRESENCE_TIMEOUT;
  143. //
  144. // Let us not allow any protocol if DdmFindBoundProtocols fails.
  145. //
  146. gblDDMConfigInfo.dwServerFlags &=
  147. ~( PPPCFG_ProjectNbf |
  148. PPPCFG_ProjectIp |
  149. PPPCFG_ProjectIpx |
  150. PPPCFG_ProjectAt );
  151. dwRetCode = DdmFindBoundProtocols( pfIpAllowed,
  152. &fIpxAllowed,
  153. &gblDDMConfigInfo.fArapAllowed );
  154. if ( dwRetCode != NO_ERROR )
  155. {
  156. return( dwRetCode );
  157. }
  158. if ( !*pfIpAllowed && !fIpxAllowed && !gblDDMConfigInfo.fArapAllowed )
  159. {
  160. DDMLogError( ROUTERLOG_NO_PROTOCOLS_CONFIGURED, 0, NULL, 0 );
  161. return( dwRetCode );
  162. }
  163. //
  164. // Run through and get all the DDM values
  165. //
  166. for ( dwIndex = 0; DDMRegParams[dwIndex].pszValueName != NULL; dwIndex++ )
  167. {
  168. cbValueBuf = sizeof( DWORD );
  169. dwRetCode = RegQueryValueEx(
  170. hkeyParameters,
  171. DDMRegParams[dwIndex].pszValueName,
  172. NULL,
  173. &dwType,
  174. (LPBYTE)(DDMRegParams[dwIndex].pValue),
  175. &cbValueBuf
  176. );
  177. if ((dwRetCode != NO_ERROR) && (dwRetCode != ERROR_FILE_NOT_FOUND))
  178. {
  179. DDMLogError( ROUTERLOG_CANT_GET_REGKEYVALUES, 0, NULL, dwRetCode );
  180. break;
  181. }
  182. if ( dwRetCode == ERROR_FILE_NOT_FOUND )
  183. {
  184. *(DDMRegParams[dwIndex].pValue) = DDMRegParams[dwIndex].dwDefValue;
  185. dwRetCode = NO_ERROR;
  186. }
  187. else
  188. {
  189. if ( ( dwType != REG_DWORD )
  190. ||(*(DDMRegParams[dwIndex].pValue) > DDMRegParams[dwIndex].Max)
  191. ||( *(DDMRegParams[dwIndex].pValue)<DDMRegParams[dwIndex].Min))
  192. {
  193. WCHAR * pChar = DDMRegParams[dwIndex].pszValueName;
  194. DDMLogWarning( ROUTERLOG_REGVALUE_OVERIDDEN,1,&pChar);
  195. *(DDMRegParams[dwIndex].pValue) =
  196. DDMRegParams[dwIndex].dwDefValue;
  197. }
  198. }
  199. }
  200. if ( dwRetCode != NO_ERROR )
  201. {
  202. return( dwRetCode );
  203. }
  204. else
  205. {
  206. //
  207. // Insert allowed protocols in the ServerFlags which will be sent to
  208. // PPP engine
  209. //
  210. if ( *pfIpAllowed )
  211. {
  212. gblDDMConfigInfo.dwServerFlags |= PPPCFG_ProjectIp;
  213. }
  214. if ( fIpxAllowed )
  215. {
  216. gblDDMConfigInfo.dwServerFlags |= PPPCFG_ProjectIpx;
  217. }
  218. if ( gblDDMConfigInfo.fArapAllowed )
  219. {
  220. gblDDMConfigInfo.dwServerFlags |= PPPCFG_ProjectAt;
  221. }
  222. if ( gblDDMConfigInfo.dwServerFlags & PPPCFG_RequireStrongEncryption )
  223. {
  224. ModifyDefPolicyToForceEncryption( TRUE );
  225. }
  226. else if ( gblDDMConfigInfo.dwServerFlags & PPPCFG_RequireEncryption )
  227. {
  228. ModifyDefPolicyToForceEncryption( FALSE );
  229. }
  230. gblDDMConfigInfo.dwServerFlags &= ~PPPCFG_RequireStrongEncryption;
  231. gblDDMConfigInfo.dwServerFlags &= ~PPPCFG_RequireEncryption;
  232. }
  233. return( NO_ERROR );
  234. }
  235. //***
  236. //
  237. // Function: LoadSecurityModule
  238. //
  239. // Descr: Opens the registry, reads and sets specified supervisor
  240. // parameters for the secuirity module. If fatal error reading
  241. // parameters writes the error log.
  242. //
  243. // Returns: NO_ERROR - success
  244. // otherwise - fatal error.
  245. //
  246. //***
  247. DWORD
  248. LoadSecurityModule(
  249. VOID
  250. )
  251. {
  252. HKEY hKey;
  253. DWORD dwRetCode = NO_ERROR;
  254. DWORD MaxValueDataSize;
  255. DWORD MaxValNameSize;
  256. DWORD NumValues;
  257. DWORD dwType;
  258. WCHAR * pDllPath = NULL;
  259. WCHAR * pDllExpandedPath = NULL;
  260. DWORD cbSize;
  261. //
  262. // get handle to the RAS key
  263. //
  264. dwRetCode = RegOpenKey( HKEY_LOCAL_MACHINE, DDM_SEC_KEY_PATH, &hKey);
  265. if ( dwRetCode == ERROR_FILE_NOT_FOUND )
  266. {
  267. return( NO_ERROR );
  268. }
  269. else if ( dwRetCode != NO_ERROR )
  270. {
  271. DDMLogErrorString( ROUTERLOG_CANT_OPEN_SECMODULE_KEY, 0,
  272. NULL, dwRetCode, 0);
  273. return ( dwRetCode );
  274. }
  275. do
  276. {
  277. //
  278. // get the length of the path.
  279. //
  280. if (( dwRetCode = GetKeyMax( hKey,
  281. &MaxValNameSize,
  282. &NumValues,
  283. &MaxValueDataSize)))
  284. {
  285. DDMLogError(ROUTERLOG_CANT_GET_REGKEYVALUES, 0, NULL, dwRetCode);
  286. break;
  287. }
  288. if ((pDllPath = LOCAL_ALLOC(LPTR,MaxValueDataSize+sizeof(WCHAR)))==NULL)
  289. {
  290. dwRetCode = GetLastError();
  291. DDMLogError( ROUTERLOG_NOT_ENOUGH_MEMORY, 0, NULL, dwRetCode);
  292. break;
  293. }
  294. //
  295. // Read in the path
  296. //
  297. dwRetCode = RegQueryValueEx(
  298. hKey,
  299. DDM_VALNAME_DLLPATH,
  300. NULL,
  301. &dwType,
  302. (LPBYTE)pDllPath,
  303. &MaxValueDataSize );
  304. if ( dwRetCode != NO_ERROR )
  305. {
  306. DDMLogError(ROUTERLOG_CANT_GET_REGKEYVALUES, 0, NULL, dwRetCode);
  307. break;
  308. }
  309. if ( ( dwType != REG_EXPAND_SZ ) && ( dwType != REG_SZ ) )
  310. {
  311. dwRetCode = ERROR_REGISTRY_CORRUPT;
  312. DDMLogError( ROUTERLOG_CANT_GET_REGKEYVALUES, 0, NULL, dwRetCode );
  313. break;
  314. }
  315. //
  316. // Replace the %SystemRoot% with the actual path.
  317. //
  318. cbSize = ExpandEnvironmentStrings( pDllPath, NULL, 0 );
  319. if ( cbSize == 0 )
  320. {
  321. dwRetCode = GetLastError();
  322. DDMLogError( ROUTERLOG_CANT_GET_REGKEYVALUES, 0, NULL, dwRetCode );
  323. break;
  324. }
  325. pDllExpandedPath = (LPWSTR)LOCAL_ALLOC( LPTR, cbSize*sizeof(WCHAR) );
  326. if ( pDllExpandedPath == (LPWSTR)NULL )
  327. {
  328. dwRetCode = GetLastError();
  329. DDMLogError( ROUTERLOG_NOT_ENOUGH_MEMORY, 0, NULL, dwRetCode );
  330. break;
  331. }
  332. cbSize = ExpandEnvironmentStrings(
  333. pDllPath,
  334. pDllExpandedPath,
  335. cbSize );
  336. if ( cbSize == 0 )
  337. {
  338. dwRetCode = GetLastError();
  339. DDMLogError( ROUTERLOG_CANT_GET_REGKEYVALUES, 0, NULL, dwRetCode );
  340. break;
  341. }
  342. gblDDMConfigInfo.hInstSecurityModule = LoadLibrary( pDllExpandedPath );
  343. if ( gblDDMConfigInfo.hInstSecurityModule == (HINSTANCE)NULL )
  344. {
  345. dwRetCode = GetLastError();
  346. DDMLogErrorString(ROUTERLOG_CANT_LOAD_SECDLL, 0, NULL, dwRetCode,0);
  347. break;
  348. }
  349. gblDDMConfigInfo.lpfnRasBeginSecurityDialog =
  350. (PVOID)GetProcAddress(
  351. gblDDMConfigInfo.hInstSecurityModule,
  352. "RasSecurityDialogBegin" );
  353. if ( gblDDMConfigInfo.lpfnRasBeginSecurityDialog == NULL )
  354. {
  355. dwRetCode = GetLastError();
  356. DDMLogErrorString(ROUTERLOG_CANT_LOAD_SECDLL,0,NULL,dwRetCode,0);
  357. break;
  358. }
  359. gblDDMConfigInfo.lpfnRasEndSecurityDialog =
  360. (PVOID)GetProcAddress(
  361. gblDDMConfigInfo.hInstSecurityModule,
  362. "RasSecurityDialogEnd" );
  363. if ( gblDDMConfigInfo.lpfnRasEndSecurityDialog == NULL )
  364. {
  365. dwRetCode = GetLastError();
  366. DDMLogErrorString(ROUTERLOG_CANT_LOAD_SECDLL,0,NULL,dwRetCode,0);
  367. break;
  368. }
  369. }while(FALSE);
  370. if ( pDllPath != NULL )
  371. {
  372. LOCAL_FREE( pDllPath );
  373. }
  374. if ( pDllExpandedPath != NULL )
  375. {
  376. LOCAL_FREE( pDllExpandedPath );
  377. }
  378. RegCloseKey( hKey );
  379. return( dwRetCode );
  380. }
  381. //***
  382. //
  383. // Function: LoadAdminModule
  384. //
  385. // Descr: Opens the registry, reads and sets specified supervisor
  386. // parameters for the admin module. If fatal error reading
  387. // parameters writes the error log.
  388. //
  389. // Returns: NO_ERROR - success
  390. // otherwise - fatal error.
  391. //
  392. //***
  393. DWORD
  394. LoadAdminModule(
  395. VOID
  396. )
  397. {
  398. DWORD RetCode = NO_ERROR;
  399. DWORD MaxValueDataSize;
  400. DWORD MaxValNameSize;
  401. DWORD NumValues;
  402. DWORD dwType;
  403. WCHAR * pDllPath = NULL;
  404. WCHAR * pDllExpandedPath = NULL;
  405. DWORD cbSize;
  406. HKEY hKey;
  407. DWORD (*lpfnRasAdminInitializeDll)();
  408. // get handle to the RAS key
  409. RetCode = RegOpenKey( HKEY_LOCAL_MACHINE, DDM_ADMIN_KEY_PATH, &hKey);
  410. if ( RetCode == ERROR_FILE_NOT_FOUND )
  411. {
  412. return( NO_ERROR );
  413. }
  414. else if ( RetCode != NO_ERROR )
  415. {
  416. DDMLogErrorString(ROUTERLOG_CANT_OPEN_ADMINMODULE_KEY,0,NULL,RetCode,0);
  417. return ( RetCode );
  418. }
  419. do {
  420. // get the length of the path.
  421. if (( RetCode = GetKeyMax(hKey,
  422. &MaxValNameSize,
  423. &NumValues,
  424. &MaxValueDataSize)))
  425. {
  426. DDMLogError(ROUTERLOG_CANT_GET_REGKEYVALUES, 0, NULL, RetCode);
  427. break;
  428. }
  429. if (( pDllPath = LOCAL_ALLOC(LPTR,MaxValueDataSize+sizeof(WCHAR)))
  430. == NULL)
  431. {
  432. DDMLogError(ROUTERLOG_NOT_ENOUGH_MEMORY, 0, NULL, 0);
  433. break;
  434. }
  435. //
  436. // Read in the path
  437. //
  438. RetCode = RegQueryValueEx( hKey,
  439. DDM_VALNAME_DLLPATH,
  440. NULL,
  441. &dwType,
  442. (LPBYTE)pDllPath,
  443. &MaxValueDataSize );
  444. if ( RetCode != NO_ERROR )
  445. {
  446. DDMLogError(ROUTERLOG_CANT_GET_REGKEYVALUES, 0, NULL, RetCode);
  447. break;
  448. }
  449. if ( ( dwType != REG_EXPAND_SZ ) && ( dwType != REG_SZ ) )
  450. {
  451. RetCode = ERROR_REGISTRY_CORRUPT;
  452. DDMLogError( ROUTERLOG_CANT_GET_REGKEYVALUES, 0, NULL, RetCode );
  453. break;
  454. }
  455. //
  456. // Replace the %SystemRoot% with the actual path.
  457. //
  458. cbSize = ExpandEnvironmentStrings( pDllPath, NULL, 0 );
  459. if ( cbSize == 0 )
  460. {
  461. RetCode = GetLastError();
  462. DDMLogError( ROUTERLOG_CANT_GET_REGKEYVALUES, 0, NULL, RetCode );
  463. break;
  464. }
  465. pDllExpandedPath = (LPWSTR)LOCAL_ALLOC( LPTR, cbSize*sizeof(WCHAR) );
  466. if ( pDllExpandedPath == (LPWSTR)NULL )
  467. {
  468. RetCode = GetLastError();
  469. DDMLogError( ROUTERLOG_NOT_ENOUGH_MEMORY, 0, NULL, RetCode );
  470. break;
  471. }
  472. cbSize = ExpandEnvironmentStrings(
  473. pDllPath,
  474. pDllExpandedPath,
  475. cbSize );
  476. if ( cbSize == 0 )
  477. {
  478. RetCode = GetLastError();
  479. DDMLogError( ROUTERLOG_CANT_GET_REGKEYVALUES, 0, NULL, RetCode );
  480. break;
  481. }
  482. gblDDMConfigInfo.hInstAdminModule = LoadLibrary( pDllExpandedPath );
  483. if ( gblDDMConfigInfo.hInstAdminModule == (HINSTANCE)NULL )
  484. {
  485. RetCode = GetLastError();
  486. DDMLogErrorString(ROUTERLOG_CANT_LOAD_ADMINDLL,0,NULL,RetCode,0);
  487. break;
  488. }
  489. lpfnRasAdminInitializeDll = (DWORD(*)(VOID))GetProcAddress(
  490. gblDDMConfigInfo.hInstAdminModule,
  491. "MprAdminInitializeDll" );
  492. if ( lpfnRasAdminInitializeDll != NULL )
  493. {
  494. RetCode = (*lpfnRasAdminInitializeDll)();
  495. if(ERROR_SUCCESS != RetCode)
  496. {
  497. DDMLogErrorString(ROUTERLOG_CANT_LOAD_ADMINDLL,
  498. 0,NULL,RetCode,0);
  499. break;
  500. }
  501. }
  502. gblDDMConfigInfo.lpfnRasAdminTerminateDll =
  503. (PVOID)GetProcAddress(
  504. gblDDMConfigInfo.hInstAdminModule,
  505. "MprAdminTerminateDll" );
  506. gblDDMConfigInfo.lpfnRasAdminAcceptNewConnection =
  507. (PVOID)GetProcAddress(
  508. gblDDMConfigInfo.hInstAdminModule,
  509. "MprAdminAcceptNewConnection" );
  510. gblDDMConfigInfo.lpfnRasAdminAcceptNewConnection2 =
  511. (PVOID)GetProcAddress(
  512. gblDDMConfigInfo.hInstAdminModule,
  513. "MprAdminAcceptNewConnection2" );
  514. //
  515. // At least one of these 2 must be available
  516. //
  517. if ( ( gblDDMConfigInfo.lpfnRasAdminAcceptNewConnection == NULL ) &&
  518. ( gblDDMConfigInfo.lpfnRasAdminAcceptNewConnection2 == NULL ) )
  519. {
  520. RetCode = GetLastError();
  521. DDMLogErrorString(ROUTERLOG_CANT_LOAD_ADMINDLL,0,NULL,RetCode,0);
  522. break;
  523. }
  524. gblDDMConfigInfo.lpfnRasAdminAcceptNewLink =
  525. (PVOID)GetProcAddress(
  526. gblDDMConfigInfo.hInstAdminModule,
  527. "MprAdminAcceptNewLink" );
  528. if ( gblDDMConfigInfo.lpfnRasAdminAcceptNewLink == NULL )
  529. {
  530. RetCode = GetLastError();
  531. DDMLogErrorString(ROUTERLOG_CANT_LOAD_ADMINDLL,0,NULL,RetCode,0);
  532. break;
  533. }
  534. gblDDMConfigInfo.lpfnRasAdminConnectionHangupNotification =
  535. (PVOID)GetProcAddress(
  536. gblDDMConfigInfo.hInstAdminModule,
  537. "MprAdminConnectionHangupNotification" );
  538. gblDDMConfigInfo.lpfnRasAdminConnectionHangupNotification2 =
  539. (PVOID)GetProcAddress(
  540. gblDDMConfigInfo.hInstAdminModule,
  541. "MprAdminConnectionHangupNotification2" );
  542. //
  543. // At least one of these 2 entrypoints must be available
  544. //
  545. if ( (gblDDMConfigInfo.lpfnRasAdminConnectionHangupNotification==NULL)
  546. &&
  547. (gblDDMConfigInfo.lpfnRasAdminConnectionHangupNotification2==NULL))
  548. {
  549. RetCode = GetLastError();
  550. DDMLogErrorString(ROUTERLOG_CANT_LOAD_ADMINDLL,0,NULL,RetCode,0);
  551. break;
  552. }
  553. gblDDMConfigInfo.lpfnRasAdminLinkHangupNotification =
  554. (PVOID)GetProcAddress(
  555. gblDDMConfigInfo.hInstAdminModule,
  556. "MprAdminLinkHangupNotification" );
  557. if ( gblDDMConfigInfo.lpfnRasAdminLinkHangupNotification == NULL )
  558. {
  559. RetCode = GetLastError();
  560. DDMLogErrorString(ROUTERLOG_CANT_LOAD_ADMINDLL,0,NULL,RetCode,0);
  561. break;
  562. }
  563. gblDDMConfigInfo.lpfnMprAdminGetIpAddressForUser =
  564. (PVOID)GetProcAddress(
  565. gblDDMConfigInfo.hInstAdminModule,
  566. "MprAdminGetIpAddressForUser" );
  567. if ( gblDDMConfigInfo.lpfnMprAdminGetIpAddressForUser == NULL )
  568. {
  569. RetCode = GetLastError();
  570. DDMLogErrorString(ROUTERLOG_CANT_LOAD_ADMINDLL,0,NULL,RetCode,0);
  571. break;
  572. }
  573. gblDDMConfigInfo.lpfnMprAdminReleaseIpAddress =
  574. (PVOID)GetProcAddress(
  575. gblDDMConfigInfo.hInstAdminModule,
  576. "MprAdminReleaseIpAddress" );
  577. if ( gblDDMConfigInfo.lpfnMprAdminReleaseIpAddress == NULL )
  578. {
  579. RetCode = GetLastError();
  580. DDMLogErrorString(ROUTERLOG_CANT_LOAD_ADMINDLL,0,NULL,RetCode,0);
  581. break;
  582. }
  583. }while(FALSE);
  584. if ( pDllPath != NULL )
  585. {
  586. LOCAL_FREE( pDllPath );
  587. }
  588. if ( pDllExpandedPath != NULL )
  589. {
  590. LOCAL_FREE( pDllExpandedPath );
  591. }
  592. RegCloseKey( hKey );
  593. return( RetCode );
  594. }
  595. //**
  596. //
  597. // Call: LoadAndInitAuthOrAcctProvider
  598. //
  599. // Returns: NO_ERROR - Success
  600. // Non-zero returns - Failure
  601. //
  602. // Description:
  603. //
  604. DWORD
  605. LoadAndInitAuthOrAcctProvider(
  606. IN BOOL fAuthenticationProvider,
  607. IN DWORD dwNASIpAddress,
  608. OUT DWORD * lpdwStartAccountingSessionId,
  609. OUT LPVOID * plpfnRasAuthProviderAuthenticateUser,
  610. OUT LPVOID * plpfnRasAuthProviderFreeAttributes,
  611. OUT LPVOID * plpfnRasAuthConfigChangeNotification,
  612. OUT LPVOID * plpfnRasAcctProviderStartAccounting,
  613. OUT LPVOID * plpfnRasAcctProviderInterimAccounting,
  614. OUT LPVOID * plpfnRasAcctProviderStopAccounting,
  615. OUT LPVOID * plpfnRasAcctProviderFreeAttributes,
  616. OUT LPVOID * plpfnRasAcctConfigChangeNotification
  617. )
  618. {
  619. HKEY hKeyProviders = NULL;
  620. HKEY hKeyCurrentProvider = NULL;
  621. LPWSTR pDllPath = (LPWSTR)NULL;
  622. LPWSTR pDllExpandedPath = (LPWSTR)NULL;
  623. LPWSTR pProviderName = (LPWSTR)NULL;
  624. HINSTANCE hinstProviderModule = NULL;
  625. DWORD dwRetCode;
  626. WCHAR chSubKeyName[100];
  627. DWORD cbSubKeyName;
  628. DWORD dwNumSubKeys;
  629. DWORD dwMaxSubKeySize;
  630. DWORD dwNumValues;
  631. DWORD cbMaxValNameLen;
  632. DWORD cbMaxValueDataSize;
  633. DWORD cbSize;
  634. DWORD dwType;
  635. CHAR chComputerName[MAX_COMPUTERNAME_LENGTH + 1];
  636. RAS_AUTH_ATTRIBUTE ServerAttributes[2];
  637. CHAR szAcctSessionId[20];
  638. do
  639. {
  640. dwRetCode = RegOpenKeyEx(
  641. HKEY_LOCAL_MACHINE,
  642. fAuthenticationProvider
  643. ? RAS_AUTHPROVIDER_REGISTRY_LOCATION
  644. : RAS_ACCTPROVIDER_REGISTRY_LOCATION,
  645. 0,
  646. KEY_READ,
  647. &hKeyProviders );
  648. if ( dwRetCode != NO_ERROR )
  649. {
  650. LPWSTR lpStr = fAuthenticationProvider
  651. ? RAS_AUTHPROVIDER_REGISTRY_LOCATION
  652. : RAS_ACCTPROVIDER_REGISTRY_LOCATION;
  653. DDMLogError( ROUTERLOG_CANT_OPEN_REGKEY, 1, &lpStr, dwRetCode );
  654. break;
  655. }
  656. //
  657. // Find out the size of the provider value
  658. //
  659. dwRetCode = RegQueryInfoKey(
  660. hKeyProviders,
  661. NULL,
  662. NULL,
  663. NULL,
  664. &dwNumSubKeys,
  665. &dwMaxSubKeySize,
  666. NULL,
  667. &dwNumValues,
  668. &cbMaxValNameLen,
  669. &cbMaxValueDataSize,
  670. NULL,
  671. NULL
  672. );
  673. if ( dwRetCode != NO_ERROR )
  674. {
  675. DDMLogError(ROUTERLOG_CANT_GET_REGKEYVALUES, 0, NULL, dwRetCode );
  676. break;
  677. }
  678. //
  679. // One extra for the NULL terminator
  680. //
  681. cbMaxValueDataSize += sizeof(WCHAR);
  682. pProviderName = (LPWSTR)LOCAL_ALLOC( LPTR, cbMaxValueDataSize );
  683. if ( pProviderName == NULL )
  684. {
  685. dwRetCode = GetLastError();
  686. break;
  687. }
  688. //
  689. // Find out the provider to use
  690. //
  691. dwRetCode = RegQueryValueEx(
  692. hKeyProviders,
  693. RAS_VALNAME_ACTIVEPROVIDER,
  694. NULL,
  695. &dwType,
  696. (BYTE*)pProviderName,
  697. &cbMaxValueDataSize
  698. );
  699. if ( dwRetCode != NO_ERROR )
  700. {
  701. DDMLogError( ROUTERLOG_CANT_GET_REGKEYVALUES, 0, NULL, dwRetCode );
  702. break;
  703. }
  704. if ( dwType != REG_SZ )
  705. {
  706. dwRetCode = ERROR_REGISTRY_CORRUPT;
  707. DDMLogError( ROUTERLOG_CANT_GET_REGKEYVALUES, 0, NULL, dwRetCode );
  708. break;
  709. }
  710. if ( wcslen( pProviderName ) == 0 )
  711. {
  712. dwRetCode = fAuthenticationProvider
  713. ? ERROR_REGISTRY_CORRUPT : NO_ERROR;
  714. break;
  715. }
  716. else
  717. {
  718. if ( !fAuthenticationProvider )
  719. {
  720. HKEY hKeyAccounting;
  721. dwRetCode = RegOpenKeyEx(
  722. HKEY_LOCAL_MACHINE,
  723. RAS_KEYPATH_ACCOUNTING,
  724. 0,
  725. KEY_READ,
  726. &hKeyAccounting );
  727. if ( dwRetCode == NO_ERROR )
  728. {
  729. cbMaxValueDataSize = sizeof( DWORD );
  730. dwRetCode =
  731. RegQueryValueEx(
  732. hKeyAccounting,
  733. RAS_VALNAME_ACCTSESSIONID,
  734. NULL,
  735. &dwType,
  736. (BYTE*)lpdwStartAccountingSessionId,
  737. &cbMaxValueDataSize );
  738. if ( ( dwRetCode != NO_ERROR ) || ( dwType != REG_DWORD ) )
  739. {
  740. *lpdwStartAccountingSessionId = 0;
  741. }
  742. RegCloseKey( hKeyAccounting );
  743. }
  744. if ( wcscmp( pProviderName,
  745. TEXT("{1AA7F840-C7F5-11D0-A376-00C04FC9DA04}") )
  746. == 0 )
  747. {
  748. gblDDMConfigInfo.fFlags |= DDM_USING_RADIUS_ACCOUNTING;
  749. }
  750. }
  751. else
  752. {
  753. if ( wcscmp( pProviderName,
  754. TEXT("{1AA7F83F-C7F5-11D0-A376-00C04FC9DA04}") )
  755. == 0 )
  756. {
  757. gblDDMConfigInfo.fFlags |= DDM_USING_RADIUS_AUTHENTICATION;
  758. }
  759. else if ( wcscmp(
  760. pProviderName,
  761. TEXT("{1AA7F841-C7F5-11D0-A376-00C04FC9DA04}") )
  762. == 0 )
  763. {
  764. gblDDMConfigInfo.fFlags |= DDM_USING_NT_AUTHENTICATION;
  765. }
  766. }
  767. }
  768. dwRetCode = RegOpenKeyEx(
  769. hKeyProviders,
  770. pProviderName,
  771. 0,
  772. KEY_READ,
  773. &hKeyCurrentProvider );
  774. if ( dwRetCode != NO_ERROR )
  775. {
  776. LPWSTR lpStr = RAS_ACCTPROVIDER_REGISTRY_LOCATION;
  777. DDMLogError( ROUTERLOG_CANT_OPEN_REGKEY, 1, &lpStr, dwRetCode );
  778. break;
  779. }
  780. //
  781. // Find out the size of the path value.
  782. //
  783. dwRetCode = RegQueryInfoKey(
  784. hKeyCurrentProvider,
  785. NULL,
  786. NULL,
  787. NULL,
  788. &dwNumSubKeys,
  789. &dwMaxSubKeySize,
  790. NULL,
  791. &dwNumValues,
  792. &cbMaxValNameLen,
  793. &cbMaxValueDataSize,
  794. NULL,
  795. NULL
  796. );
  797. if ( dwRetCode != NO_ERROR )
  798. {
  799. DDMLogError(ROUTERLOG_CANT_GET_REGKEYVALUES, 0, NULL, dwRetCode );
  800. break;
  801. }
  802. //
  803. // Allocate space for path and add one for NULL terminator
  804. //
  805. cbMaxValueDataSize += sizeof(WCHAR);
  806. pDllPath = (LPWSTR)LOCAL_ALLOC( LPTR, cbMaxValueDataSize );
  807. if ( pDllPath == (LPWSTR)NULL )
  808. {
  809. dwRetCode = GetLastError();
  810. DDMLogError( ROUTERLOG_NOT_ENOUGH_MEMORY, 0, NULL, dwRetCode);
  811. break;
  812. }
  813. //
  814. // Read in the path
  815. //
  816. dwRetCode = RegQueryValueEx(
  817. hKeyCurrentProvider,
  818. RAS_PROVIDER_VALUENAME_PATH,
  819. NULL,
  820. &dwType,
  821. (PBYTE)pDllPath,
  822. &cbMaxValueDataSize
  823. );
  824. if ( dwRetCode != NO_ERROR )
  825. {
  826. DDMLogError(ROUTERLOG_CANT_GET_REGKEYVALUES, 0, NULL, dwRetCode );
  827. break;
  828. }
  829. if ( ( dwType != REG_EXPAND_SZ ) && ( dwType != REG_SZ ) )
  830. {
  831. dwRetCode = ERROR_REGISTRY_CORRUPT;
  832. DDMLogError( ROUTERLOG_CANT_GET_REGKEYVALUES, 0, NULL, dwRetCode );
  833. break;
  834. }
  835. //
  836. // Replace the %SystemRoot% with the actual path.
  837. //
  838. cbSize = ExpandEnvironmentStrings( pDllPath, NULL, 0 );
  839. if ( cbSize == 0 )
  840. {
  841. dwRetCode = GetLastError();
  842. DDMLogError( ROUTERLOG_CANT_GET_REGKEYVALUES, 0, NULL, dwRetCode );
  843. break;
  844. }
  845. cbSize *= sizeof( WCHAR );
  846. pDllExpandedPath = (LPWSTR)LOCAL_ALLOC( LPTR, cbSize );
  847. if ( pDllExpandedPath == (LPWSTR)NULL )
  848. {
  849. dwRetCode = GetLastError();
  850. DDMLogError( ROUTERLOG_NOT_ENOUGH_MEMORY, 0, NULL, dwRetCode);
  851. break;
  852. }
  853. cbSize = ExpandEnvironmentStrings(
  854. pDllPath,
  855. pDllExpandedPath,
  856. cbSize );
  857. if ( cbSize == 0 )
  858. {
  859. dwRetCode = GetLastError();
  860. DDMLogError(ROUTERLOG_CANT_GET_REGKEYVALUES,0,NULL,dwRetCode);
  861. break;
  862. }
  863. hinstProviderModule = LoadLibrary( pDllExpandedPath );
  864. if ( hinstProviderModule == (HINSTANCE)NULL )
  865. {
  866. dwRetCode = GetLastError();
  867. break;
  868. }
  869. //
  870. // Get server attributes that will be used to initialize authentication
  871. // and accounting providers
  872. //
  873. if ( dwNASIpAddress == 0 )
  874. {
  875. DWORD dwComputerNameLen = sizeof( chComputerName);
  876. //
  877. // Failed to get the LOCAL IP address, use computer name instead.
  878. //
  879. if ( !GetComputerNameA( chComputerName, &dwComputerNameLen ) )
  880. {
  881. dwRetCode = GetLastError();
  882. break;
  883. }
  884. ServerAttributes[0].raaType = raatNASIdentifier;
  885. ServerAttributes[0].dwLength = strlen(chComputerName);
  886. ServerAttributes[0].Value = chComputerName;
  887. }
  888. else
  889. {
  890. ServerAttributes[0].raaType = raatNASIPAddress;
  891. ServerAttributes[0].dwLength = 4;
  892. ServerAttributes[0].Value = UlongToPtr(dwNASIpAddress);
  893. }
  894. if ( !fAuthenticationProvider )
  895. {
  896. ZeroMemory( szAcctSessionId, sizeof( szAcctSessionId ) );
  897. _itoa( (*lpdwStartAccountingSessionId)++, szAcctSessionId, 10 );
  898. ServerAttributes[1].raaType = raatAcctSessionId;
  899. ServerAttributes[1].dwLength = strlen( szAcctSessionId );
  900. ServerAttributes[1].Value = (PVOID)szAcctSessionId;
  901. ServerAttributes[2].raaType = raatMinimum;
  902. ServerAttributes[2].dwLength = 0;
  903. ServerAttributes[2].Value = NULL;
  904. }
  905. else
  906. {
  907. ServerAttributes[1].raaType = raatMinimum;
  908. ServerAttributes[1].dwLength = 0;
  909. ServerAttributes[1].Value = NULL;
  910. }
  911. if ( fAuthenticationProvider )
  912. {
  913. DWORD (*RasAuthProviderInitialize)( RAS_AUTH_ATTRIBUTE *, HANDLE, DWORD );
  914. gblDDMConfigInfo.hinstAuthModule = hinstProviderModule;
  915. RasAuthProviderInitialize =
  916. (DWORD(*)(RAS_AUTH_ATTRIBUTE*, HANDLE, DWORD))
  917. GetProcAddress(
  918. hinstProviderModule,
  919. "RasAuthProviderInitialize" );
  920. if ( RasAuthProviderInitialize == NULL )
  921. {
  922. dwRetCode = GetLastError();
  923. break;
  924. }
  925. dwRetCode = RasAuthProviderInitialize(
  926. (RAS_AUTH_ATTRIBUTE *)&ServerAttributes,
  927. gblDDMConfigInfo.hLogEvents,
  928. gblDDMConfigInfo.dwLoggingLevel );
  929. if ( dwRetCode != NO_ERROR )
  930. {
  931. break;
  932. }
  933. gblDDMConfigInfo.lpfnRasAuthProviderTerminate = (DWORD(*)(VOID))
  934. GetProcAddress(
  935. hinstProviderModule,
  936. "RasAuthProviderTerminate" );
  937. if ( gblDDMConfigInfo.lpfnRasAuthProviderTerminate == NULL )
  938. {
  939. dwRetCode = GetLastError();
  940. break;
  941. }
  942. *plpfnRasAuthProviderAuthenticateUser =
  943. GetProcAddress(
  944. hinstProviderModule,
  945. "RasAuthProviderAuthenticateUser" );
  946. if ( *plpfnRasAuthProviderAuthenticateUser == NULL )
  947. {
  948. dwRetCode = GetLastError();
  949. break;
  950. }
  951. *plpfnRasAuthProviderFreeAttributes =
  952. GetProcAddress(
  953. hinstProviderModule,
  954. "RasAuthProviderFreeAttributes" );
  955. if ( *plpfnRasAuthProviderFreeAttributes == NULL )
  956. {
  957. dwRetCode = GetLastError();
  958. break;
  959. }
  960. *plpfnRasAuthConfigChangeNotification =
  961. GetProcAddress(
  962. hinstProviderModule,
  963. "RasAuthConfigChangeNotification" );
  964. if ( *plpfnRasAuthConfigChangeNotification == NULL )
  965. {
  966. dwRetCode = GetLastError();
  967. break;
  968. }
  969. }
  970. else
  971. {
  972. DWORD (*RasAcctProviderInitialize)( RAS_AUTH_ATTRIBUTE *, HANDLE, DWORD );
  973. gblDDMConfigInfo.hinstAcctModule = hinstProviderModule;
  974. RasAcctProviderInitialize =
  975. (DWORD(*)(RAS_AUTH_ATTRIBUTE*, HANDLE, DWORD))
  976. GetProcAddress(
  977. hinstProviderModule,
  978. "RasAcctProviderInitialize" );
  979. if ( RasAcctProviderInitialize == NULL )
  980. {
  981. dwRetCode = GetLastError();
  982. break;
  983. }
  984. dwRetCode = RasAcctProviderInitialize(
  985. (RAS_AUTH_ATTRIBUTE *)&ServerAttributes,
  986. gblDDMConfigInfo.hLogEvents,
  987. gblDDMConfigInfo.dwLoggingLevel );
  988. if ( dwRetCode != NO_ERROR )
  989. {
  990. break;
  991. }
  992. gblDDMConfigInfo.lpfnRasAcctProviderTerminate = (DWORD(*)(VOID))
  993. GetProcAddress(
  994. hinstProviderModule,
  995. "RasAcctProviderTerminate" );
  996. if ( gblDDMConfigInfo.lpfnRasAcctProviderTerminate == NULL )
  997. {
  998. dwRetCode = GetLastError();
  999. break;
  1000. }
  1001. *plpfnRasAcctProviderStartAccounting =
  1002. GetProcAddress(
  1003. hinstProviderModule,
  1004. "RasAcctProviderStartAccounting" );
  1005. if ( *plpfnRasAcctProviderStartAccounting == NULL )
  1006. {
  1007. dwRetCode = GetLastError();
  1008. break;
  1009. }
  1010. *plpfnRasAcctProviderStopAccounting =
  1011. GetProcAddress(
  1012. hinstProviderModule,
  1013. "RasAcctProviderStopAccounting" );
  1014. if ( *plpfnRasAcctProviderStopAccounting == NULL )
  1015. {
  1016. dwRetCode = GetLastError();
  1017. break;
  1018. }
  1019. *plpfnRasAcctProviderInterimAccounting =
  1020. GetProcAddress(
  1021. hinstProviderModule,
  1022. "RasAcctProviderInterimAccounting");
  1023. if ( *plpfnRasAcctProviderInterimAccounting == NULL )
  1024. {
  1025. dwRetCode = GetLastError();
  1026. break;
  1027. }
  1028. *plpfnRasAcctProviderFreeAttributes =
  1029. GetProcAddress(
  1030. hinstProviderModule,
  1031. "RasAcctProviderFreeAttributes" );
  1032. if ( *plpfnRasAcctProviderFreeAttributes == NULL )
  1033. {
  1034. dwRetCode = GetLastError();
  1035. break;
  1036. }
  1037. *plpfnRasAcctConfigChangeNotification =
  1038. GetProcAddress(
  1039. hinstProviderModule,
  1040. "RasAcctConfigChangeNotification" );
  1041. if ( *plpfnRasAcctConfigChangeNotification == NULL )
  1042. {
  1043. dwRetCode = GetLastError();
  1044. break;
  1045. }
  1046. }
  1047. }while( FALSE );
  1048. if ( hKeyProviders != NULL )
  1049. {
  1050. RegCloseKey( hKeyProviders );
  1051. }
  1052. if ( hKeyCurrentProvider != NULL )
  1053. {
  1054. RegCloseKey( hKeyCurrentProvider );
  1055. }
  1056. if ( pDllPath != NULL )
  1057. {
  1058. LOCAL_FREE( pDllPath );
  1059. }
  1060. if ( pDllExpandedPath != NULL )
  1061. {
  1062. LOCAL_FREE( pDllExpandedPath );
  1063. }
  1064. if ( pProviderName != NULL )
  1065. {
  1066. LOCAL_FREE( pProviderName );
  1067. }
  1068. return( dwRetCode );
  1069. }
  1070. LONG
  1071. RegQueryDword (HKEY hkey, LPCTSTR szValueName, LPDWORD pdwValue)
  1072. {
  1073. // Get the value.
  1074. //
  1075. DWORD dwType;
  1076. DWORD cbData = sizeof(DWORD);
  1077. LONG lr = RegQueryValueEx (hkey, szValueName, NULL, &dwType,
  1078. (LPBYTE)pdwValue, &cbData);
  1079. // It's type should be REG_DWORD. (duh).
  1080. //
  1081. if ((ERROR_SUCCESS == lr) && (REG_DWORD != dwType))
  1082. {
  1083. lr = ERROR_INVALID_DATATYPE;
  1084. }
  1085. // Make sure we initialize the output value on error.
  1086. // (We don't know for sure that RegQueryValueEx does this.)
  1087. //
  1088. if (ERROR_SUCCESS != lr)
  1089. {
  1090. *pdwValue = 0;
  1091. }
  1092. return lr;
  1093. }
  1094. DWORD
  1095. lProtocolEnabled(
  1096. IN HKEY hKey,
  1097. IN DWORD dwPid,
  1098. IN BOOL fRasSrv,
  1099. IN BOOL fRouter,
  1100. IN BOOL * pfEnabled
  1101. )
  1102. {
  1103. static const TCHAR c_szRegValEnableIn[] = TEXT("EnableIn");
  1104. static const TCHAR c_szRegValEnableRoute[] = TEXT("EnableRoute");
  1105. static const TCHAR c_szRegSubkeyIp[] = TEXT("Ip");
  1106. static const TCHAR c_szRegSubkeyIpx[] = TEXT("Ipx");
  1107. static const TCHAR c_szRegSubkeyATalk[] = TEXT("AppleTalk");
  1108. DWORD dwValue;
  1109. DWORD lr;
  1110. HKEY hkeyProtocol = NULL;
  1111. const TCHAR * pszSubkey;
  1112. switch ( dwPid )
  1113. {
  1114. case PID_IP:
  1115. pszSubkey = c_szRegSubkeyIp;
  1116. break;
  1117. case PID_IPX:
  1118. pszSubkey = c_szRegSubkeyIpx;
  1119. break;
  1120. case PID_ATALK:
  1121. pszSubkey = c_szRegSubkeyATalk;
  1122. break;
  1123. default:
  1124. return( FALSE );
  1125. }
  1126. *pfEnabled = FALSE;
  1127. lr = RegOpenKey( hKey, pszSubkey, &hkeyProtocol );
  1128. if ( 0 != lr )
  1129. {
  1130. goto done;
  1131. }
  1132. if (fRasSrv)
  1133. {
  1134. lr = RegQueryDword(hkeyProtocol, c_szRegValEnableIn, &dwValue);
  1135. if ( (ERROR_FILE_NOT_FOUND == lr)
  1136. || ((ERROR_SUCCESS == lr) && (dwValue != 0)))
  1137. {
  1138. lr = ERROR_SUCCESS;
  1139. *pfEnabled = TRUE;
  1140. goto done;
  1141. }
  1142. }
  1143. if (fRouter)
  1144. {
  1145. lr = RegQueryDword(hkeyProtocol, c_szRegValEnableRoute, &dwValue);
  1146. if ( (ERROR_FILE_NOT_FOUND == lr)
  1147. || ((ERROR_SUCCESS == lr) && (dwValue != 0)))
  1148. {
  1149. lr = ERROR_SUCCESS;
  1150. *pfEnabled = TRUE;
  1151. goto done;
  1152. }
  1153. }
  1154. done:
  1155. if(NULL != hkeyProtocol)
  1156. {
  1157. RegCloseKey ( hkeyProtocol );
  1158. }
  1159. return lr;
  1160. }
  1161. DWORD
  1162. DdmFindBoundProtocols(
  1163. OUT BOOL * pfBoundToIp,
  1164. OUT BOOL * pfBoundToIpx,
  1165. OUT BOOL * pfBoundToATalk
  1166. )
  1167. {
  1168. static const TCHAR c_szRegKeyRemoteAccessParams[]
  1169. = TEXT("SYSTEM\\CurrentControlSet\\Services\\RemoteAccess\\Parameters");
  1170. RASMAN_GET_PROTOCOL_INFO InstalledProtocols;
  1171. LONG lResult = 0;
  1172. HKEY hKey = NULL;
  1173. DWORD i;
  1174. *pfBoundToIp = FALSE;
  1175. *pfBoundToIpx = FALSE;
  1176. *pfBoundToATalk = FALSE;
  1177. lResult = RasGetProtocolInfo( NULL, &InstalledProtocols );
  1178. if ( lResult != NO_ERROR )
  1179. {
  1180. goto done;
  1181. }
  1182. lResult = RegOpenKey( HKEY_LOCAL_MACHINE, c_szRegKeyRemoteAccessParams, &hKey );
  1183. if ( 0 != lResult )
  1184. {
  1185. goto done;
  1186. }
  1187. for ( i = 0; i < InstalledProtocols.ulNumProtocols; i++ )
  1188. {
  1189. switch( InstalledProtocols.ProtocolInfo[i].ProtocolType )
  1190. {
  1191. case IPX:
  1192. lResult=lProtocolEnabled( hKey,
  1193. PID_IPX,
  1194. TRUE,
  1195. FALSE,
  1196. pfBoundToIpx);
  1197. break;
  1198. case IP:
  1199. lResult=lProtocolEnabled( hKey,
  1200. PID_IP,
  1201. TRUE,
  1202. FALSE,
  1203. pfBoundToIp );
  1204. break;
  1205. case APPLETALK:
  1206. lResult=lProtocolEnabled( hKey,
  1207. PID_ATALK,
  1208. TRUE,
  1209. FALSE,
  1210. pfBoundToATalk);
  1211. break;
  1212. default:
  1213. break;
  1214. }
  1215. }
  1216. RegCloseKey( hKey );
  1217. done:
  1218. return ( DWORD ) lResult;
  1219. }
  1220. DWORD
  1221. GetArrayOfIpAddresses(PWSTR pwszIpAddresses,
  1222. DWORD *pcNumValues,
  1223. PWSTR **papwstrValues)
  1224. {
  1225. DWORD cValues = 0;
  1226. PWSTR psz = pwszIpAddresses;
  1227. DWORD dwErr = ERROR_SUCCESS;
  1228. DWORD i;
  1229. PWSTR *apwstrValues = NULL;
  1230. do
  1231. {
  1232. for(; TEXT('\0') != *psz; cValues++)
  1233. {
  1234. psz += (wcslen(psz) + 1);
  1235. }
  1236. apwstrValues = LocalAlloc(LPTR, cValues * sizeof(PWSTR));
  1237. if(NULL == apwstrValues)
  1238. {
  1239. dwErr = GetLastError();
  1240. break;
  1241. }
  1242. psz = pwszIpAddresses;
  1243. for(i = 0; TEXT('\0') != *psz; i++)
  1244. {
  1245. apwstrValues[i] = psz;
  1246. psz += (wcslen(psz) + 1);
  1247. }
  1248. } while (FALSE);
  1249. *pcNumValues = cValues;
  1250. *papwstrValues = apwstrValues;
  1251. return dwErr;
  1252. }
  1253. DWORD
  1254. GetIPAddressPoolFromRegistry(
  1255. HKEY hkey,
  1256. PWSTR pszValueName,
  1257. DWORD *pcNumValues,
  1258. PWSTR **papwstrValues
  1259. )
  1260. {
  1261. DWORD dwErr = ERROR_SUCCESS;
  1262. DWORD dwType;
  1263. DWORD dwSize = 0;
  1264. PWSTR pwszIpAddresses = NULL;
  1265. do
  1266. {
  1267. if( (NULL == papwstrValues)
  1268. || (NULL == pcNumValues)
  1269. || (NULL == pszValueName)
  1270. || (NULL == hkey))
  1271. {
  1272. dwErr = ERROR_INVALID_HANDLE;
  1273. break;
  1274. }
  1275. *pcNumValues = 0;
  1276. *papwstrValues = NULL;
  1277. //
  1278. // Find the size of the MULTI_SZ
  1279. //
  1280. dwErr = RegQueryValueEx(
  1281. hkey,
  1282. pszValueName,
  1283. NULL,
  1284. &dwType,
  1285. NULL,
  1286. &dwSize);
  1287. if( (ERROR_SUCCESS != dwErr)
  1288. || (REG_MULTI_SZ != dwType)
  1289. || (0 == dwSize))
  1290. {
  1291. //
  1292. // Trace out that failed to read the information
  1293. // and bail.
  1294. //
  1295. break;
  1296. }
  1297. //
  1298. // Allocate the bufffer
  1299. //
  1300. pwszIpAddresses = LocalAlloc(LPTR, dwSize);
  1301. if(NULL == pwszIpAddresses)
  1302. {
  1303. dwErr = GetLastError();
  1304. break;
  1305. }
  1306. //
  1307. // Get the strings
  1308. //
  1309. dwErr = RegQueryValueEx(
  1310. hkey,
  1311. pszValueName,
  1312. NULL,
  1313. &dwType,
  1314. (LPBYTE) pwszIpAddresses,
  1315. &dwSize);
  1316. if(ERROR_SUCCESS != dwErr)
  1317. {
  1318. //
  1319. // Trace
  1320. //
  1321. break;
  1322. }
  1323. //
  1324. // Construct the array of IPAddresses
  1325. //
  1326. dwErr = GetArrayOfIpAddresses(pwszIpAddresses,
  1327. pcNumValues,
  1328. papwstrValues);
  1329. } while (FALSE);
  1330. return dwErr;
  1331. }
  1332. DWORD
  1333. AddressPoolInit(
  1334. VOID
  1335. )
  1336. {
  1337. HKEY hkey = NULL;
  1338. DWORD dwErr = ERROR_SUCCESS;
  1339. gblDDMConfigInfo.cAnalogIPAddresses = 0;
  1340. gblDDMConfigInfo.apAnalogIPAddresses = NULL;
  1341. gblDDMConfigInfo.cDigitalIPAddresses = 0;
  1342. gblDDMConfigInfo.apDigitalIPAddresses = NULL;
  1343. do
  1344. {
  1345. dwErr = RegOpenKeyEx(
  1346. HKEY_LOCAL_MACHINE,
  1347. TEXT("System\\CurrentControlSet\\Services\\PptpProtocol\\Parameters"),
  1348. 0,
  1349. KEY_READ,
  1350. &hkey);
  1351. if(ERROR_SUCCESS != dwErr)
  1352. {
  1353. break;
  1354. }
  1355. //
  1356. // Get Analog IP Address Pool
  1357. //
  1358. dwErr = GetIPAddressPoolFromRegistry(
  1359. hkey,
  1360. TEXT("AnalogIPAddressPool"),
  1361. &gblDDMConfigInfo.cAnalogIPAddresses,
  1362. &gblDDMConfigInfo.apAnalogIPAddresses);
  1363. //
  1364. // Trace out the errors here
  1365. //
  1366. //
  1367. // Get Digital IP Address Pool
  1368. //
  1369. dwErr = GetIPAddressPoolFromRegistry(
  1370. hkey,
  1371. TEXT("DigitalIPAddressPool"),
  1372. &gblDDMConfigInfo.cDigitalIPAddresses,
  1373. &gblDDMConfigInfo.apDigitalIPAddresses);
  1374. //
  1375. // Trace out the errors here
  1376. //
  1377. } while(FALSE);
  1378. if(NULL != hkey)
  1379. {
  1380. RegCloseKey(hkey);
  1381. }
  1382. if(ERROR_FILE_NOT_FOUND == dwErr)
  1383. {
  1384. dwErr = ERROR_SUCCESS;
  1385. }
  1386. return dwErr;
  1387. }