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.

1027 lines
26 KiB

  1. /********************************************************************/
  2. /** Copyright(c) 1995 Microsoft Corporation. **/
  3. /********************************************************************/
  4. //***
  5. //
  6. // Filename: attrib.c
  7. //
  8. // Description: Contains code to manipulate RAS_AUTH_ATTRIBUTE structures
  9. //
  10. // History: Feb 11,1997 NarenG Created original version.
  11. //
  12. #define UNICODE
  13. #include <nt.h>
  14. #include <ntrtl.h>
  15. #include <nturtl.h>
  16. #include <windows.h>
  17. #include <rtutils.h>
  18. #include <lmcons.h>
  19. #include <rasauth.h>
  20. #include <string.h>
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #define INCL_RASAUTHATTRIBUTES
  24. #define INCL_HOSTWIRE
  25. #include "ppputil.h"
  26. //**
  27. //
  28. // Call: RasAuthAttributeCreate
  29. //
  30. // Returns: NO_ERROR - Success
  31. // Non-zero returns - Failure
  32. //
  33. // Description: Will create an array of attributes plus one for the terminator
  34. //
  35. RAS_AUTH_ATTRIBUTE *
  36. RasAuthAttributeCreate(
  37. IN DWORD dwNumAttributes
  38. )
  39. {
  40. RAS_AUTH_ATTRIBUTE * pAttributes;
  41. DWORD dwIndex;
  42. pAttributes = (RAS_AUTH_ATTRIBUTE * )
  43. LocalAlloc(LPTR,
  44. sizeof( RAS_AUTH_ATTRIBUTE )*(1+dwNumAttributes));
  45. if ( pAttributes == NULL )
  46. {
  47. return( NULL );
  48. }
  49. //
  50. // Initialize
  51. //
  52. for( dwIndex = 0; dwIndex < dwNumAttributes; dwIndex++ )
  53. {
  54. pAttributes[dwIndex].raaType = raatReserved;
  55. pAttributes[dwIndex].dwLength = 0;
  56. pAttributes[dwIndex].Value = NULL;
  57. }
  58. //
  59. // Terminate
  60. //
  61. pAttributes[dwNumAttributes].raaType = raatMinimum;
  62. pAttributes[dwNumAttributes].dwLength = 0;
  63. pAttributes[dwNumAttributes].Value = NULL;
  64. return( pAttributes );
  65. }
  66. //**
  67. //
  68. // Call: RasAuthAttributeDestroy
  69. //
  70. // Returns: NO_ERROR - Success
  71. // Non-zero returns - Failure
  72. //
  73. // Description: Will free up all allocated memory occupied by the attributes
  74. // structure
  75. //
  76. VOID
  77. RasAuthAttributeDestroy(
  78. IN RAS_AUTH_ATTRIBUTE * pAttributes
  79. )
  80. {
  81. DWORD dwIndex;
  82. if ( NULL == pAttributes )
  83. {
  84. return;
  85. }
  86. for( dwIndex = 0; pAttributes[dwIndex].raaType != raatMinimum; dwIndex++ )
  87. {
  88. switch( pAttributes[dwIndex].raaType )
  89. {
  90. case raatUserName:
  91. case raatUserPassword:
  92. case raatMD5CHAPPassword:
  93. case raatFilterId:
  94. case raatReplyMessage:
  95. case raatCallbackNumber:
  96. case raatCallbackId:
  97. case raatFramedRoute:
  98. case raatState:
  99. case raatClass:
  100. case raatVendorSpecific:
  101. case raatCalledStationId:
  102. case raatCallingStationId:
  103. case raatNASIdentifier:
  104. case raatProxyState:
  105. case raatLoginLATService:
  106. case raatLoginLATNode:
  107. case raatLoginLATGroup:
  108. case raatFramedAppleTalkZone:
  109. case raatAcctSessionId:
  110. case raatAcctMultiSessionId:
  111. case raatMD5CHAPChallenge:
  112. case raatLoginLATPort:
  113. case raatTunnelClientEndpoint:
  114. case raatTunnelServerEndpoint:
  115. case raatARAPPassword:
  116. case raatARAPFeatures:
  117. case raatARAPSecurityData:
  118. case raatConnectInfo:
  119. case raatConfigurationToken:
  120. case raatEAPMessage:
  121. case raatSignature:
  122. case raatARAPChallengeResponse:
  123. case raatCertificateOID:
  124. //
  125. // Allocated memory here so free it
  126. //
  127. if ( pAttributes[dwIndex].Value != NULL )
  128. {
  129. ZeroMemory( pAttributes[dwIndex].Value,
  130. pAttributes[dwIndex].dwLength);
  131. LocalFree( pAttributes[dwIndex].Value );
  132. }
  133. break;
  134. case raatReserved:
  135. //
  136. // Do nothing to uninitialized values
  137. //
  138. case raatPEAPFastRoamedSession:
  139. case raatPEAPEmbeddedEAPTypeId:
  140. //
  141. // Same as Default case here. fall thru'
  142. //
  143. default:
  144. //
  145. // DWORDs, USHORTs or BYTEs so do nothing
  146. //
  147. break;
  148. }
  149. }
  150. LocalFree( pAttributes );
  151. }
  152. //**
  153. //
  154. // Call: RasAuthAttributeGet
  155. //
  156. // Returns: NO_ERROR - Success
  157. // Non-zero returns - Failure
  158. //
  159. // Description:
  160. //
  161. RAS_AUTH_ATTRIBUTE *
  162. RasAuthAttributeGet(
  163. IN RAS_AUTH_ATTRIBUTE_TYPE raaType,
  164. IN RAS_AUTH_ATTRIBUTE * pAttributes
  165. )
  166. {
  167. DWORD dwIndex;
  168. if ( pAttributes == NULL )
  169. {
  170. return( NULL );
  171. }
  172. for( dwIndex = 0; pAttributes[dwIndex].raaType != raatMinimum; dwIndex++ )
  173. {
  174. if ( pAttributes[dwIndex].raaType == raaType )
  175. {
  176. return( &(pAttributes[dwIndex]) );
  177. }
  178. }
  179. return( NULL );
  180. }
  181. //**
  182. //
  183. // Call: RasAuthAttributeGetFirst
  184. //
  185. // Returns: NO_ERROR - Success
  186. // Non-zero returns - Failure
  187. //
  188. // Description:
  189. //
  190. RAS_AUTH_ATTRIBUTE *
  191. RasAuthAttributeGetFirst(
  192. IN RAS_AUTH_ATTRIBUTE_TYPE raaType,
  193. IN RAS_AUTH_ATTRIBUTE * pAttributes,
  194. OUT HANDLE * phAttribute
  195. )
  196. {
  197. DWORD dwIndex;
  198. RAS_AUTH_ATTRIBUTE * pRequiredAttribute;
  199. pRequiredAttribute = RasAuthAttributeGet( raaType, pAttributes );
  200. if ( pRequiredAttribute == NULL )
  201. {
  202. *phAttribute = NULL;
  203. return( NULL );
  204. }
  205. *phAttribute = pRequiredAttribute;
  206. return( pRequiredAttribute );
  207. }
  208. //**
  209. //
  210. // Call: RasAuthAttributeGetNext
  211. //
  212. // Returns: NO_ERROR - Success
  213. // Non-zero returns - Failure
  214. //
  215. // Description:
  216. //
  217. RAS_AUTH_ATTRIBUTE *
  218. RasAuthAttributeGetNext(
  219. IN OUT HANDLE * phAttribute,
  220. IN RAS_AUTH_ATTRIBUTE_TYPE raaType
  221. )
  222. {
  223. DWORD dwIndex;
  224. RAS_AUTH_ATTRIBUTE * pAttributes = (RAS_AUTH_ATTRIBUTE *)*phAttribute;
  225. if ( pAttributes == NULL )
  226. {
  227. return( NULL );
  228. }
  229. pAttributes++;
  230. while( pAttributes->raaType != raatMinimum )
  231. {
  232. if ( pAttributes->raaType == raaType )
  233. {
  234. *phAttribute = pAttributes;
  235. return( pAttributes );
  236. }
  237. pAttributes++;
  238. }
  239. *phAttribute = NULL;
  240. return( NULL );
  241. }
  242. //**
  243. //
  244. // Call: RasAuthAttributesPrint
  245. //
  246. // Returns: VOID
  247. //
  248. // Description: Will print all the attributes in pAttributes
  249. //
  250. VOID
  251. RasAuthAttributesPrint(
  252. IN DWORD dwTraceID,
  253. IN DWORD dwFlags,
  254. IN RAS_AUTH_ATTRIBUTE * pAttributes
  255. )
  256. {
  257. DWORD dwIndex;
  258. if ( NULL == pAttributes )
  259. {
  260. return;
  261. }
  262. for ( dwIndex = 0;
  263. pAttributes[dwIndex].raaType != raatMinimum;
  264. dwIndex++)
  265. {
  266. switch( pAttributes[dwIndex].raaType )
  267. {
  268. case raatUserName:
  269. case raatUserPassword:
  270. case raatMD5CHAPPassword:
  271. case raatFilterId:
  272. case raatReplyMessage:
  273. case raatCallbackNumber:
  274. case raatCallbackId:
  275. case raatFramedRoute:
  276. case raatState:
  277. case raatClass:
  278. case raatVendorSpecific:
  279. case raatCalledStationId:
  280. case raatCallingStationId:
  281. case raatNASIdentifier:
  282. case raatProxyState:
  283. case raatLoginLATService:
  284. case raatLoginLATNode:
  285. case raatLoginLATGroup:
  286. case raatFramedAppleTalkZone:
  287. case raatAcctSessionId:
  288. case raatAcctMultiSessionId:
  289. case raatMD5CHAPChallenge:
  290. case raatLoginLATPort:
  291. case raatTunnelClientEndpoint:
  292. case raatTunnelServerEndpoint:
  293. case raatARAPPassword:
  294. case raatARAPFeatures:
  295. case raatARAPSecurityData:
  296. case raatConnectInfo:
  297. case raatConfigurationToken:
  298. case raatEAPMessage:
  299. case raatSignature:
  300. case raatARAPChallengeResponse:
  301. case raatCertificateOID:
  302. TracePrintfExA(
  303. dwTraceID, dwFlags,
  304. "Type=%d, Length=%d, Value=",
  305. pAttributes[dwIndex].raaType,
  306. pAttributes[dwIndex].dwLength );
  307. if ( ( pAttributes[dwIndex].raaType == raatVendorSpecific )
  308. && ( pAttributes[dwIndex].dwLength >= 5 )
  309. && ( WireToHostFormat32( pAttributes[dwIndex].Value ) == 311 ) )
  310. {
  311. DWORD dwVendorType;
  312. dwVendorType = ((BYTE*)(pAttributes[dwIndex].Value))[4];
  313. //
  314. // Do not print MS-CHAP-MPPE-Keys, MS-MPPE-Send-Key and
  315. // MS-MPPE-Recv-Key
  316. //
  317. if ( ( dwVendorType == 12 )
  318. || ( dwVendorType == 16 )
  319. || ( dwVendorType == 17 ) )
  320. {
  321. TracePrintfExA(
  322. dwTraceID, dwFlags,
  323. "MS vendor specific %d", dwVendorType );
  324. break;
  325. }
  326. }
  327. //
  328. // Do not print the password
  329. //
  330. if(pAttributes[dwIndex].raaType == raatUserPassword)
  331. {
  332. TracePrintfExA(
  333. dwTraceID, dwFlags,
  334. "raatUserPassword");
  335. break;
  336. }
  337. TraceDumpExA(
  338. dwTraceID, dwFlags,
  339. pAttributes[dwIndex].Value,
  340. pAttributes[dwIndex].dwLength,
  341. 1, FALSE, "" );
  342. break;
  343. case raatPEAPFastRoamedSession:
  344. case raatPEAPEmbeddedEAPTypeId:
  345. //
  346. // Same as Default case here. fall thru'
  347. //
  348. default:
  349. TracePrintfExA(
  350. dwTraceID, dwFlags,
  351. "Type=%d, Length=%d, Value=0x%x",
  352. pAttributes[dwIndex].raaType,
  353. pAttributes[dwIndex].dwLength,
  354. pAttributes[dwIndex].Value );
  355. break;
  356. }
  357. }
  358. }
  359. //**
  360. //
  361. // Call: RasAuthAttributeInsert
  362. //
  363. // Returns: NO_ERROR - Success
  364. // Non-zero returns - Failure
  365. //
  366. // Description:
  367. //
  368. DWORD
  369. RasAuthAttributeInsert(
  370. IN DWORD dwIndex,
  371. IN RAS_AUTH_ATTRIBUTE * pAttributes,
  372. IN RAS_AUTH_ATTRIBUTE_TYPE raaType,
  373. IN BOOL fConvertToMultiByte,
  374. IN DWORD dwLength,
  375. IN PVOID pValue
  376. )
  377. {
  378. DWORD dwErr;
  379. if ( raatMinimum == pAttributes[dwIndex].raaType )
  380. {
  381. return( ERROR_NOT_ENOUGH_MEMORY );
  382. }
  383. switch( raaType )
  384. {
  385. case raatUserName:
  386. case raatUserPassword:
  387. case raatMD5CHAPPassword:
  388. case raatFilterId:
  389. case raatReplyMessage:
  390. case raatCallbackNumber:
  391. case raatCallbackId:
  392. case raatFramedRoute:
  393. case raatState:
  394. case raatClass:
  395. case raatVendorSpecific:
  396. case raatCalledStationId:
  397. case raatCallingStationId:
  398. case raatNASIdentifier:
  399. case raatProxyState:
  400. case raatLoginLATService:
  401. case raatLoginLATNode:
  402. case raatLoginLATGroup:
  403. case raatFramedAppleTalkZone:
  404. case raatAcctSessionId:
  405. case raatAcctMultiSessionId:
  406. case raatMD5CHAPChallenge:
  407. case raatLoginLATPort:
  408. case raatTunnelClientEndpoint:
  409. case raatTunnelServerEndpoint:
  410. case raatARAPPassword:
  411. case raatARAPFeatures:
  412. case raatARAPSecurityData:
  413. case raatConnectInfo:
  414. case raatConfigurationToken:
  415. case raatEAPMessage:
  416. case raatSignature:
  417. case raatARAPChallengeResponse:
  418. case raatCertificateOID:
  419. // If you add a new attribute here, update RasAuthAttributesPrint also.
  420. if ( pValue != NULL )
  421. {
  422. pAttributes[dwIndex].Value = LocalAlloc( LPTR, dwLength+1 );
  423. if ( pAttributes[dwIndex].Value == NULL )
  424. {
  425. return( GetLastError() );
  426. }
  427. if ( fConvertToMultiByte )
  428. {
  429. if (0 == WideCharToMultiByte(
  430. CP_ACP,
  431. 0,
  432. (WCHAR*)pValue,
  433. dwLength + 1,
  434. pAttributes[dwIndex].Value,
  435. dwLength + 1,
  436. NULL,
  437. NULL ) )
  438. {
  439. dwErr = GetLastError();
  440. LocalFree( pAttributes[dwIndex].Value );
  441. return( dwErr );
  442. }
  443. }
  444. else
  445. {
  446. CopyMemory( pAttributes[dwIndex].Value, pValue, dwLength );
  447. }
  448. }
  449. else
  450. {
  451. pAttributes[dwIndex].Value = NULL;
  452. }
  453. break;
  454. case raatPEAPFastRoamedSession:
  455. case raatPEAPEmbeddedEAPTypeId:
  456. default:
  457. pAttributes[dwIndex].Value = pValue;
  458. break;
  459. }
  460. pAttributes[dwIndex].dwLength = dwLength;
  461. pAttributes[dwIndex].raaType = raaType;
  462. return( NO_ERROR );
  463. }
  464. //**
  465. //
  466. // Call: RasAuthAttributeInsertVSA
  467. //
  468. // Returns: NO_ERROR - Success
  469. // Non-zero returns - Failure
  470. //
  471. // Description:
  472. //
  473. DWORD
  474. RasAuthAttributeInsertVSA(
  475. IN DWORD dwIndex,
  476. IN RAS_AUTH_ATTRIBUTE * pAttributes,
  477. IN DWORD dwVendorId,
  478. IN DWORD dwLength,
  479. IN PVOID pValue
  480. )
  481. {
  482. if ( pValue != NULL )
  483. {
  484. pAttributes[dwIndex].Value = LocalAlloc( LPTR, dwLength+1+4 );
  485. if ( pAttributes[dwIndex].Value == NULL )
  486. {
  487. return( GetLastError() );
  488. }
  489. HostToWireFormat32( dwVendorId, (PBYTE)(pAttributes[dwIndex].Value) );
  490. CopyMemory( ((PBYTE)pAttributes[dwIndex].Value)+4,
  491. (PBYTE)pValue,
  492. dwLength );
  493. pAttributes[dwIndex].dwLength = dwLength+4;
  494. }
  495. else
  496. {
  497. pAttributes[dwIndex].Value = NULL;
  498. pAttributes[dwIndex].dwLength = 0;
  499. }
  500. pAttributes[dwIndex].raaType = raatVendorSpecific;
  501. return( NO_ERROR );
  502. }
  503. //**
  504. //
  505. // Call: RasAuthAttributeCopy
  506. //
  507. // Returns: Pointer to copy of attributes - Success
  508. // NULL - Failure
  509. //
  510. // Description:
  511. //
  512. RAS_AUTH_ATTRIBUTE *
  513. RasAuthAttributeCopy(
  514. IN RAS_AUTH_ATTRIBUTE * pAttributes
  515. )
  516. {
  517. RAS_AUTH_ATTRIBUTE * pAttributesCopy;
  518. DWORD dwAttributesCount = 0;
  519. DWORD dwIndex;
  520. DWORD dwRetCode;
  521. //
  522. // Find out how many attributes there are
  523. //
  524. if ( pAttributes == NULL )
  525. {
  526. return( NULL );
  527. }
  528. for( dwIndex = 0; pAttributes[dwIndex].raaType != raatMinimum; dwIndex++ );
  529. if ( ( pAttributesCopy = RasAuthAttributeCreate( dwIndex ) ) == NULL )
  530. {
  531. return( NULL );
  532. }
  533. for( dwIndex = 0; pAttributes[dwIndex].raaType != raatMinimum; dwIndex++ )
  534. {
  535. dwRetCode = RasAuthAttributeInsert( dwIndex,
  536. pAttributesCopy,
  537. pAttributes[dwIndex].raaType,
  538. FALSE,
  539. pAttributes[dwIndex].dwLength,
  540. pAttributes[dwIndex].Value );
  541. if ( dwRetCode != NO_ERROR )
  542. {
  543. RasAuthAttributeDestroy( pAttributesCopy );
  544. SetLastError( dwRetCode );
  545. return( NULL );
  546. }
  547. }
  548. return( pAttributesCopy );
  549. }
  550. //**
  551. //
  552. // Call: RasAuthAttributeCopyWithAlloc
  553. //
  554. // Returns: Pointer to copy of attributes - Success
  555. // NULL - Failure
  556. //
  557. // Description: Copies the attribute list and allocs dwNumExtraAttributes
  558. // extra blank attributes in the beginning. pAttributes can
  559. // be NULL.
  560. //
  561. RAS_AUTH_ATTRIBUTE *
  562. RasAuthAttributeCopyWithAlloc(
  563. IN RAS_AUTH_ATTRIBUTE * pAttributes,
  564. IN DWORD dwNumExtraAttributes
  565. )
  566. {
  567. RAS_AUTH_ATTRIBUTE * pAttributesCopy;
  568. DWORD dwAttributesCount = 0;
  569. DWORD dwIndex;
  570. DWORD dwRetCode;
  571. if ( pAttributes == NULL )
  572. {
  573. pAttributesCopy = RasAuthAttributeCreate( dwNumExtraAttributes );
  574. if ( pAttributesCopy == NULL )
  575. {
  576. return( NULL );
  577. }
  578. }
  579. else
  580. {
  581. //
  582. // Find out how many attributes there are
  583. //
  584. for( dwIndex = 0;
  585. pAttributes[dwIndex].raaType != raatMinimum;
  586. dwIndex++ );
  587. dwIndex += dwNumExtraAttributes;
  588. if ( ( pAttributesCopy = RasAuthAttributeCreate( dwIndex ) ) == NULL )
  589. {
  590. return( NULL );
  591. }
  592. for( dwIndex = 0;
  593. pAttributes[dwIndex].raaType != raatMinimum;
  594. dwIndex++ )
  595. {
  596. dwRetCode = RasAuthAttributeInsert( dwIndex + dwNumExtraAttributes,
  597. pAttributesCopy,
  598. pAttributes[dwIndex].raaType,
  599. FALSE,
  600. pAttributes[dwIndex].dwLength,
  601. pAttributes[dwIndex].Value );
  602. if ( dwRetCode != NO_ERROR )
  603. {
  604. RasAuthAttributeDestroy( pAttributesCopy );
  605. SetLastError( dwRetCode );
  606. return( NULL );
  607. }
  608. }
  609. }
  610. return( pAttributesCopy );
  611. }
  612. //**
  613. //
  614. // Call: RasAuthAttributeGetVendorSpecific
  615. //
  616. // Returns: Pointer to attribute
  617. // NULL if it couldn't find it
  618. //
  619. // Description:
  620. //
  621. RAS_AUTH_ATTRIBUTE *
  622. RasAuthAttributeGetVendorSpecific(
  623. IN DWORD dwVendorId,
  624. IN DWORD dwVendorType,
  625. IN RAS_AUTH_ATTRIBUTE * pAttributes
  626. )
  627. {
  628. HANDLE hAttribute;
  629. RAS_AUTH_ATTRIBUTE * pAttribute;
  630. //
  631. // First search for the vendor specific attribute
  632. //
  633. pAttribute = RasAuthAttributeGetFirst( raatVendorSpecific,
  634. pAttributes,
  635. &hAttribute );
  636. while ( pAttribute != NULL )
  637. {
  638. //
  639. // If this attribute is of at least size to hold vendor Id/Type
  640. //
  641. if ( pAttribute->dwLength >= 8 )
  642. {
  643. //
  644. // Does this have the correct VendorId
  645. //
  646. if (WireToHostFormat32( (PBYTE)(pAttribute->Value) ) == dwVendorId)
  647. {
  648. //
  649. // Does this have the correct Vendor Type
  650. //
  651. if ( *(((PBYTE)(pAttribute->Value))+4) == dwVendorType )
  652. {
  653. return( pAttribute );
  654. }
  655. }
  656. }
  657. pAttribute = RasAuthAttributeGetNext( &hAttribute,
  658. raatVendorSpecific );
  659. }
  660. return( NULL );
  661. }
  662. //**
  663. //
  664. // Call: RasAuthAttributeReAlloc
  665. //
  666. // Returns: NO_ERROR - Success
  667. // Non-zero returns - Failure
  668. //
  669. // Description: Will create an array of attributes plus one for the terminator
  670. //
  671. RAS_AUTH_ATTRIBUTE *
  672. RasAuthAttributeReAlloc(
  673. IN RAS_AUTH_ATTRIBUTE * pAttributes,
  674. IN DWORD dwNumAttributes
  675. )
  676. {
  677. DWORD dwIndex;
  678. RAS_AUTH_ATTRIBUTE * pOutAttributes;
  679. pOutAttributes = (RAS_AUTH_ATTRIBUTE *)
  680. LocalReAlloc(
  681. pAttributes,
  682. sizeof( RAS_AUTH_ATTRIBUTE )*(1+dwNumAttributes),
  683. LMEM_ZEROINIT );
  684. if ( pOutAttributes == NULL )
  685. {
  686. return( NULL );
  687. }
  688. //
  689. // Initialize the rest of the array.
  690. //
  691. for( dwIndex = 0; dwIndex < dwNumAttributes; dwIndex++ )
  692. {
  693. if ( pOutAttributes[dwIndex].raaType == raatMinimum )
  694. {
  695. while( dwIndex < dwNumAttributes )
  696. {
  697. pOutAttributes[dwIndex].raaType = raatReserved;
  698. pOutAttributes[dwIndex].dwLength = 0;
  699. pOutAttributes[dwIndex].Value = NULL;
  700. dwIndex++;
  701. }
  702. break;
  703. }
  704. }
  705. //
  706. // Terminate the new array.
  707. //
  708. pOutAttributes[dwNumAttributes].raaType = raatMinimum;
  709. pOutAttributes[dwNumAttributes].dwLength = 0;
  710. pOutAttributes[dwNumAttributes].Value = NULL;
  711. return( pOutAttributes );
  712. }
  713. //**
  714. //
  715. // Call: RasAuthAttributeGetConcatString
  716. //
  717. // Returns: pointer to a LocalAlloc'ed string
  718. //
  719. // Description: Looks for attributes of type raaType in pAttributes. Combines
  720. // them all into one string and returns the string. The string
  721. // must be LocalFree'd. *pdwStringLength will contain the number
  722. // of characters in the string.
  723. //
  724. CHAR *
  725. RasAuthAttributeGetConcatString(
  726. IN RAS_AUTH_ATTRIBUTE_TYPE raaType,
  727. IN RAS_AUTH_ATTRIBUTE * pAttributes,
  728. IN OUT DWORD * pdwStringLength
  729. )
  730. {
  731. #define MAX_STR_LENGTH 1500
  732. HANDLE hAttribute;
  733. CHAR * pszReplyMessage = NULL;
  734. RAS_AUTH_ATTRIBUTE * pAttribute;
  735. DWORD dwBytesRemaining;
  736. DWORD dwBytesToCopy;
  737. do
  738. {
  739. *pdwStringLength = 0;
  740. pAttribute = RasAuthAttributeGetFirst( raaType, pAttributes,
  741. &hAttribute );
  742. if ( NULL == pAttribute )
  743. {
  744. break;
  745. }
  746. pszReplyMessage = LocalAlloc( LPTR, MAX_STR_LENGTH + 1 );
  747. if ( NULL == pszReplyMessage )
  748. {
  749. break;
  750. }
  751. //
  752. // Bytes remaining, excluding terminating NULL
  753. //
  754. dwBytesRemaining = MAX_STR_LENGTH;
  755. while ( ( dwBytesRemaining > 0 )
  756. && ( NULL != pAttribute ) )
  757. {
  758. //
  759. // This does not include the terminating NULL
  760. //
  761. dwBytesToCopy = pAttribute->dwLength;
  762. if ( dwBytesToCopy > dwBytesRemaining )
  763. {
  764. dwBytesToCopy = dwBytesRemaining;
  765. }
  766. CopyMemory( pszReplyMessage + MAX_STR_LENGTH - dwBytesRemaining,
  767. pAttribute->Value,
  768. dwBytesToCopy );
  769. dwBytesRemaining -= dwBytesToCopy;
  770. pAttribute = RasAuthAttributeGetNext( &hAttribute,
  771. raaType );
  772. }
  773. *pdwStringLength = MAX_STR_LENGTH - dwBytesRemaining;
  774. }
  775. while ( FALSE );
  776. return( pszReplyMessage );
  777. }
  778. //**
  779. //
  780. // Call: RasAuthAttributeGetConcatVendorSpecific
  781. //
  782. // Returns: Pointer to a chunk of bytes
  783. // NULL if it couldn't find it
  784. //
  785. // Description: Looks for attributes of type dwVendorType in pAttributes.
  786. // Combines them all into the return value. The Value must be
  787. // LocalFree'd.
  788. //
  789. BYTE *
  790. RasAuthAttributeGetConcatVendorSpecific(
  791. IN DWORD dwVendorId,
  792. IN DWORD dwVendorType,
  793. IN RAS_AUTH_ATTRIBUTE * pAttributes
  794. )
  795. {
  796. DWORD dwMAX_ATTR_LENGTH = 1024;
  797. HANDLE hAttribute;
  798. RAS_AUTH_ATTRIBUTE * pAttribute;
  799. BYTE* pbValue = NULL;
  800. DWORD dwIndex = 0;
  801. DWORD dwLength;
  802. BOOL fFound = FALSE;
  803. pbValue = LocalAlloc( LPTR, dwMAX_ATTR_LENGTH );
  804. if ( NULL == pbValue )
  805. {
  806. return( NULL );
  807. }
  808. //
  809. // First search for the vendor specific attribute
  810. //
  811. pAttribute = RasAuthAttributeGetFirst( raatVendorSpecific,
  812. pAttributes,
  813. &hAttribute );
  814. while ( pAttribute != NULL )
  815. {
  816. //
  817. // If this attribute is of at least size to hold vendor Id/Type
  818. //
  819. if ( pAttribute->dwLength >= 8 )
  820. {
  821. //
  822. // Does this have the correct VendorId
  823. //
  824. if (WireToHostFormat32( (PBYTE)(pAttribute->Value) ) == dwVendorId)
  825. {
  826. //
  827. // Does this have the correct Vendor Type
  828. //
  829. if ( *(((PBYTE)(pAttribute->Value))+4) == dwVendorType )
  830. {
  831. //
  832. // Exclude Vendor-Type and Vendor-Length from the length
  833. //
  834. dwLength = *(((PBYTE)(pAttribute->Value))+5) - 2;
  835. // If we overrun the buffer, we should increase it
  836. if ( dwMAX_ATTR_LENGTH - dwIndex < dwLength )
  837. {
  838. BYTE *pbNewValue;
  839. dwMAX_ATTR_LENGTH += 1024;
  840. pbNewValue = LocalReAlloc(pbValue, dwMAX_ATTR_LENGTH, LMEM_ZEROINIT|LMEM_MOVEABLE);
  841. // Bail if we can't get more memory
  842. if( pbNewValue == NULL )
  843. {
  844. LocalFree( pbValue );
  845. return( NULL );
  846. }
  847. pbValue = pbNewValue;
  848. }
  849. CopyMemory(
  850. pbValue + dwIndex,
  851. ((PBYTE)(pAttribute->Value))+6,
  852. dwLength );
  853. dwIndex += dwLength;
  854. fFound = TRUE;
  855. }
  856. }
  857. }
  858. pAttribute = RasAuthAttributeGetNext( &hAttribute,
  859. raatVendorSpecific );
  860. }
  861. if ( fFound )
  862. {
  863. return( pbValue );
  864. }
  865. else
  866. {
  867. LocalFree( pbValue );
  868. return( NULL );
  869. }
  870. }