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.

954 lines
24 KiB

  1. //#--------------------------------------------------------------
  2. //
  3. // File: packetreceiver.cpp
  4. //
  5. // Synopsis: Implementation of CPacketReceiver class methods
  6. //
  7. //
  8. // History: 9/23/97 MKarki Created
  9. //
  10. // Copyright (C) 1997-98 Microsoft Corporation
  11. // All rights reserved.
  12. //
  13. //----------------------------------------------------------------
  14. #include "radcommon.h"
  15. #include "packetreceiver.h"
  16. #include <new>
  17. #include <iastlutl.h>
  18. #include <iasutil.h>
  19. //
  20. // this is the time we allow the worker thread to sleep
  21. //
  22. const DWORD MAX_SLEEP_TIME = 1000; //1000 milli-seconds
  23. extern LONG g_lPacketCount;
  24. extern LONG g_lThreadCount;
  25. ///////////////////////////////////////////////////////////////////////////////
  26. //
  27. // Retrieve the Auto-Reject User-Name pattern from the registry.
  28. //
  29. ///////////////////////////////////////////////////////////////////////////////
  30. BSTR
  31. WINAPI
  32. IASRadiusGetPingUserName( VOID )
  33. {
  34. LONG status;
  35. HKEY hKey;
  36. status = RegOpenKeyW(
  37. HKEY_LOCAL_MACHINE,
  38. L"SYSTEM\\CurrentControlSet\\Services\\IAS\\Parameters",
  39. &hKey
  40. );
  41. if (status != NO_ERROR) { return NULL; }
  42. BSTR val = NULL;
  43. DWORD cbData, type;
  44. status = RegQueryValueExW(
  45. hKey,
  46. L"Ping User-Name",
  47. NULL,
  48. &type,
  49. NULL,
  50. &cbData
  51. );
  52. if (status == NO_ERROR && type == REG_SZ)
  53. {
  54. PWSTR buf = (PWSTR)_alloca(cbData);
  55. status = RegQueryValueExW(
  56. hKey,
  57. L"Ping User-Name",
  58. NULL,
  59. &type,
  60. (PBYTE)buf,
  61. &cbData
  62. );
  63. if (status == NO_ERROR && type == REG_SZ)
  64. {
  65. val = SysAllocString(buf);
  66. }
  67. }
  68. RegCloseKey(hKey);
  69. return val;
  70. }
  71. ///////////////////////////////////////////////////////////////////////////////
  72. //
  73. // Handle ping packets.
  74. //
  75. ///////////////////////////////////////////////////////////////////////////////
  76. BOOL
  77. WINAPI
  78. IASRadiusIsPing(
  79. CPacketRadius& pkt,
  80. const RegularExpression& regexp
  81. ) throw ()
  82. {
  83. // Determine the ping response.
  84. PACKETTYPE outCode;
  85. switch (pkt.GetInCode())
  86. {
  87. case ACCESS_REQUEST:
  88. outCode = ACCESS_REJECT;
  89. break;
  90. case ACCOUNTING_REQUEST:
  91. outCode = ACCOUNTING_RESPONSE;
  92. break;
  93. default:
  94. return FALSE;
  95. }
  96. // Get the User-Name.
  97. PATTRIBUTE username = pkt.GetUserName();
  98. if (!username) { return FALSE; }
  99. // Convert to UNICODE and test against the pattern.
  100. IAS_OCTET_STRING oct = { username->byLength - 2, username->ValueStart };
  101. if (!regexp.testString(IAS_OCT2WIDE(oct))) { return FALSE; }
  102. // Build the empty out packet.
  103. HRESULT hr = pkt.BuildOutPacket(outCode, NULL, 0);
  104. if (SUCCEEDED(hr))
  105. {
  106. // Compute the Response-Authenticator.
  107. pkt.GenerateOutAuthenticator();
  108. // Get the packet ...
  109. PBYTE buf = pkt.GetOutPacket();
  110. WORD buflen = pkt.GetOutLength();
  111. // ... and address.
  112. SOCKADDR_IN sin;
  113. sin.sin_family = AF_INET;
  114. sin.sin_port = htons(pkt.GetOutPort());
  115. sin.sin_addr.s_addr = htonl(pkt.GetOutAddress());
  116. // Send the ping response.
  117. sendto(
  118. pkt.GetSocket(),
  119. (const char*)buf,
  120. buflen,
  121. 0,
  122. (PSOCKADDR)&sin,
  123. sizeof(sin)
  124. );
  125. }
  126. // This packet has been processed.
  127. InterlockedDecrement(&g_lPacketCount);
  128. return TRUE;
  129. }
  130. //+++-------------------------------------------------------------
  131. //
  132. // Function: CPacketReceiver
  133. //
  134. // Synopsis: This is the constructor of the CPacketReceiver class
  135. //
  136. // Arguments: NONE
  137. //
  138. // Returns: NONE
  139. //
  140. //
  141. // History: MKarki Created 9/26/97
  142. //
  143. //----------------------------------------------------------------
  144. CPacketReceiver::CPacketReceiver(
  145. VOID
  146. )
  147. : pingPattern(NULL),
  148. m_pCDictionary (NULL),
  149. m_pCPreValidator (NULL),
  150. m_pCHashMD5 (NULL),
  151. m_pCHashHmacMD5 (NULL),
  152. m_pCClients (NULL),
  153. m_pCReportEvent (NULL)
  154. {
  155. } // end of CPacketReceiver constructor
  156. //+++-------------------------------------------------------------
  157. //
  158. // Function: ~CPacketReceiver
  159. //
  160. // Synopsis: This is the destructor of the CPacketReceiver class
  161. //
  162. // Arguments: NONE
  163. //
  164. // Returns: NONE
  165. //
  166. // History: MKarki Created 9/23/97
  167. //
  168. //----------------------------------------------------------------
  169. CPacketReceiver::~CPacketReceiver(
  170. VOID
  171. )
  172. {
  173. SysFreeString(pingPattern);
  174. } // end of CPacketReceiver destructor
  175. //+++-------------------------------------------------------------
  176. //
  177. // Function: Init
  178. //
  179. // Synopsis: This is the method which initializes the
  180. // CPacketReceiver class object
  181. //
  182. // Arguments:
  183. // [in] CDictionary*
  184. // [in] CPreValidator*
  185. // [in] CHashMD5*
  186. // [in] CHashHmacMD5*
  187. // [in] CReportEvent*
  188. //
  189. // Returns: BOOL - status
  190. //
  191. //
  192. // History: MKarki Created 9/29/97
  193. //
  194. // Called By: CContoller class method
  195. //
  196. //----------------------------------------------------------------
  197. BOOL CPacketReceiver::Init(
  198. CDictionary *pCDictionary,
  199. CPreValidator *pCPreValidator,
  200. CHashMD5 *pCHashMD5,
  201. CHashHmacMD5 *pCHashHmacMD5,
  202. CClients *pCClients,
  203. CReportEvent *pCReportEvent
  204. )
  205. {
  206. _ASSERT (
  207. (NULL != pCDictionary) &&
  208. (NULL != pCPreValidator) &&
  209. (NULL != pCHashMD5) &&
  210. (NULL != pCHashHmacMD5) &&
  211. (NULL != pCClients) &&
  212. (NULL != pCReportEvent)
  213. );
  214. // Initialize the Auto-Reject pattern.
  215. if (pingPattern = IASRadiusGetPingUserName())
  216. {
  217. regexp.setGlobal(TRUE);
  218. regexp.setIgnoreCase(TRUE);
  219. regexp.setPattern(pingPattern);
  220. }
  221. m_pCDictionary = pCDictionary;
  222. m_pCPreValidator = pCPreValidator;
  223. m_pCHashMD5 = pCHashMD5;
  224. m_pCHashHmacMD5 = pCHashHmacMD5;
  225. m_pCClients = pCClients;
  226. m_pCReportEvent = pCReportEvent;
  227. if (m_AuthEvent.initialize() || m_AcctEvent.initialize())
  228. {
  229. return FALSE;
  230. }
  231. return (TRUE);
  232. } // end of CPacketReceiver::Init method
  233. //+++-------------------------------------------------------------
  234. //
  235. // Function: StartProcessing
  236. //
  237. // Synopsis: This is the method to start receiving inbound
  238. // data
  239. //
  240. // Arguments:
  241. // [in] fd_set - Authentication socket set
  242. // [in] fd_set - Accounting socket set
  243. //
  244. // Returns: BOOL - status
  245. //
  246. // History: MKarki Created 11/19/97
  247. //
  248. // Called By: CContoller::InternalInit method
  249. //
  250. //----------------------------------------------------------------
  251. BOOL
  252. CPacketReceiver::StartProcessing (
  253. /*[in]*/ fd_set& AuthSet,
  254. /*[in]*/ fd_set& AcctSet
  255. )
  256. {
  257. BOOL bStatus = FALSE;
  258. __try
  259. {
  260. //
  261. // enable
  262. //
  263. EnableProcessing ();
  264. m_AuthSet = AuthSet;
  265. m_AcctSet = AcctSet;
  266. // Make sure the events are clear ...
  267. m_AuthEvent.reset();
  268. m_AcctEvent.reset();
  269. // ... and add the to the fd_set.
  270. FD_SET (m_AuthEvent, &m_AuthSet);
  271. FD_SET (m_AcctEvent, &m_AcctSet);
  272. //
  273. // start a new thread to process authentication requests
  274. //
  275. bStatus = StartThreadIfNeeded (AUTH_PORTTYPE);
  276. if (FALSE == bStatus) { __leave; }
  277. //
  278. // start a new thread to process accounting requests
  279. //
  280. bStatus = StartThreadIfNeeded (ACCT_PORTTYPE);
  281. if (FALSE == bStatus) { __leave; }
  282. //
  283. // success
  284. //
  285. }
  286. __finally
  287. {
  288. if (FALSE == bStatus) { DisableProcessing (); }
  289. }
  290. return (bStatus);
  291. } // end of CPacketReceiver::StartProcessing method
  292. //+++-------------------------------------------------------------
  293. //
  294. // Function: StopProcessing
  295. //
  296. // Synopsis: This is the method to stop receiving inbound
  297. // data
  298. //
  299. // Arguments: none
  300. //
  301. // Returns: BOOL - status
  302. //
  303. //
  304. // History: MKarki Created 11/19/97
  305. //
  306. // Called By: CContoller::Suspend method
  307. //
  308. //----------------------------------------------------------------
  309. BOOL
  310. CPacketReceiver::StopProcessing (
  311. VOID
  312. )
  313. {
  314. DisableProcessing ();
  315. // Signal the SocketEvents to wake up the worker threads.
  316. m_AuthEvent.set();
  317. m_AcctEvent.set();
  318. return (TRUE);
  319. } // end of CPacketReceiver::StopProcessing method
  320. //+++-------------------------------------------------------------
  321. //
  322. // Function: ReceivePacket
  323. //
  324. // Synopsis: This is the method which receives the UDP packet
  325. // buffer and starts processing it.
  326. //
  327. // Arguments:
  328. // [in] PBYTE - in packet buffer
  329. // [in] DWORD - size of the packet
  330. // [in] DWORD - Client's IP address
  331. // [in] WORD - Client's UDP port
  332. //
  333. // Returns: HRESULT - status
  334. //
  335. // Called By: CPacketReceiver::WorkerRoutine private method
  336. //
  337. // History: MKarki Created 9/23/97
  338. //
  339. //----------------------------------------------------------------
  340. HRESULT
  341. CPacketReceiver::ReceivePacket(
  342. PBYTE pInBuffer,
  343. DWORD dwSize,
  344. DWORD dwIPaddress,
  345. WORD wPort,
  346. SOCKET sock,
  347. PORTTYPE portType
  348. )
  349. {
  350. BOOL bStatus = FALSE;
  351. HRESULT hr = S_OK;
  352. CPacketRadius *pCPacketRadius = NULL;
  353. CComPtr <IIasClient> pIIasClient;
  354. _ASSERT (pInBuffer);
  355. //
  356. // get client information for this RADIUS packet
  357. //
  358. bStatus = m_pCClients->FindObject (
  359. dwIPaddress,
  360. &pIIasClient
  361. );
  362. if (FALSE == bStatus)
  363. {
  364. //
  365. // free the allocated in buffer
  366. //
  367. ::CoTaskMemFree (pInBuffer);
  368. //
  369. // log error and generate audit event
  370. //
  371. WCHAR srcAddr[16];
  372. ias_inet_htow(dwIPaddress, srcAddr);
  373. IASTracePrintf (
  374. "No client with IP-Address:%S registered with server", srcAddr
  375. );
  376. PCWSTR strings[] = { srcAddr };
  377. IASReportEvent(
  378. RADIUS_E_INVALID_CLIENT,
  379. 1,
  380. 0,
  381. strings,
  382. NULL
  383. );
  384. //
  385. // generate an Audit Log
  386. //
  387. m_pCReportEvent->Process (
  388. RADIUS_INVALID_CLIENT,
  389. (AUTH_PORTTYPE == portType)?ACCESS_REQUEST:ACCOUNTING_REQUEST,
  390. dwSize,
  391. dwIPaddress,
  392. NULL,
  393. static_cast <LPVOID> (pInBuffer)
  394. );
  395. hr = RADIUS_E_ERRORS_OCCURRED;
  396. goto Cleanup;
  397. }
  398. //
  399. // create packet radius object
  400. //
  401. pCPacketRadius = new (std::nothrow) CPacketRadius (
  402. m_pCHashMD5,
  403. m_pCHashHmacMD5,
  404. pIIasClient,
  405. m_pCReportEvent,
  406. pInBuffer,
  407. dwSize,
  408. dwIPaddress,
  409. wPort,
  410. sock,
  411. portType
  412. );
  413. if (NULL == pCPacketRadius)
  414. {
  415. //
  416. // free the allocated in buffer
  417. //
  418. ::CoTaskMemFree (pInBuffer);
  419. IASTracePrintf (
  420. "Unable to create Packet-Radius object during packet processing"
  421. );
  422. hr = E_OUTOFMEMORY;
  423. goto Cleanup;
  424. }
  425. //
  426. // now do the preliminary verification of the packet received
  427. //
  428. hr = pCPacketRadius->PrelimVerification (
  429. m_pCDictionary,
  430. dwSize
  431. );
  432. if (FAILED (hr)) { goto Cleanup; }
  433. // If the Ping User-Name pattern has been set, then we must test
  434. // this packet.
  435. if (pingPattern && IASRadiusIsPing(*pCPacketRadius, regexp))
  436. {
  437. // It was a ping packet, so we're done.
  438. delete pCPacketRadius;
  439. return S_OK;
  440. }
  441. //
  442. // now pass on this packet to the PreValidator
  443. //
  444. hr = m_pCPreValidator->StartInValidation (pCPacketRadius);
  445. if (FAILED (hr)) { goto Cleanup; }
  446. Cleanup:
  447. //
  448. // cleanup on error
  449. //
  450. if (FAILED (hr))
  451. {
  452. if (hr != RADIUS_E_ERRORS_OCCURRED)
  453. {
  454. IASReportEvent(
  455. RADIUS_E_INTERNAL_ERROR,
  456. 0,
  457. sizeof(hr),
  458. NULL,
  459. &hr
  460. );
  461. }
  462. //
  463. // also inform that the packet is being discarded
  464. //
  465. in_addr sin;
  466. sin.s_addr = htonl (dwIPaddress);
  467. IASTracePrintf (
  468. "Silently discarding packet received from:%s",
  469. inet_ntoa (sin)
  470. );
  471. //
  472. // inform that packet is being discarded
  473. //
  474. m_pCReportEvent->Process (
  475. RADIUS_DROPPED_PACKET,
  476. (AUTH_PORTTYPE == portType)?ACCESS_REQUEST:ACCOUNTING_REQUEST,
  477. dwSize,
  478. dwIPaddress,
  479. NULL,
  480. static_cast <LPVOID> (pInBuffer)
  481. );
  482. //
  483. // free the memory
  484. //
  485. if (pCPacketRadius) { delete pCPacketRadius; }
  486. }
  487. return (hr);
  488. } // end of CPacketReceiver::ReceivePacket method
  489. //+++-------------------------------------------------------------
  490. //
  491. // Function: WorkerRoutine
  492. //
  493. // Synopsis: This is the routing in which the worker thread
  494. // that carries out the actual data reception
  495. //
  496. // Arguments: [in] DWORD
  497. //
  498. // Returns: none
  499. //
  500. // History: MKarki Created 11/19/97
  501. //
  502. // Called By: New Worker Thread
  503. //
  504. //----------------------------------------------------------------
  505. VOID
  506. CPacketReceiver::WorkerRoutine (
  507. DWORD dwInfo
  508. )
  509. {
  510. BOOL bStatus = FALSE;
  511. BOOL bRetVal = FALSE;
  512. BOOL bDataReceived = FALSE;
  513. DWORD dwPeerAddress = 0;
  514. WORD wPeerPort = 0;
  515. CPacketRadius *pCPacketRadius = NULL;
  516. PBYTE pBuffer = NULL;
  517. PBYTE pReAllocatedBuffer = NULL;
  518. DWORD dwSize = MAX_PACKET_SIZE;
  519. fd_set socketSet;
  520. SOCKET sock = INVALID_SOCKET;
  521. __try
  522. {
  523. if (AUTH_PORTTYPE == (PORTTYPE)dwInfo)
  524. {
  525. socketSet = m_AuthSet;
  526. }
  527. else
  528. {
  529. socketSet = m_AcctSet;
  530. }
  531. StartAgain:
  532. //
  533. // check if the processing is still going on
  534. //
  535. if (FALSE == IsProcessingEnabled ())
  536. {
  537. IASTracePrintf (
  538. "Worker Thread exiting as packet processing is not enabled"
  539. );
  540. __leave;
  541. }
  542. //
  543. // allocate a new inbound packet buffer
  544. //
  545. pBuffer = reinterpret_cast <PBYTE> (m_InBufferPool.allocate ());
  546. if (NULL == pBuffer)
  547. {
  548. IASTracePrintf (
  549. "unable to allocate memory from buffer pool for in-bound packet"
  550. );
  551. //
  552. // Sleep for a second, and try again
  553. // Fix for Bug #159140 - MKarki - 4/29/98
  554. //
  555. Sleep (MAX_SLEEP_TIME);
  556. //
  557. // we will have to check whether processing is still
  558. // enabled
  559. //
  560. goto StartAgain;
  561. }
  562. //
  563. // wait now on select
  564. //
  565. INT iRetVal = select (0, &socketSet, NULL, NULL, NULL);
  566. if (SOCKET_ERROR == iRetVal)
  567. {
  568. IASTracePrintf (
  569. "Worker Thread failed on select call with error:%d",
  570. ::WSAGetLastError ()
  571. );
  572. __leave;
  573. }
  574. //
  575. // check if the processing is still going on
  576. //
  577. if (FALSE == IsProcessingEnabled ())
  578. {
  579. IASTracePrintf (
  580. "Worker Thread exiting as packet processing is not enabled"
  581. );
  582. __leave;
  583. }
  584. //
  585. // get a socket to recv data on
  586. //
  587. static size_t nextSocket;
  588. sock = socketSet.fd_array[++nextSocket % iRetVal];
  589. //
  590. // recv data now
  591. //
  592. SOCKADDR_IN sin;
  593. DWORD dwAddrSize = sizeof (SOCKADDR);
  594. dwSize = ::recvfrom (
  595. sock,
  596. (PCHAR)pBuffer,
  597. (INT)dwSize,
  598. (INT)0,
  599. (PSOCKADDR)&sin,
  600. (INT*)&dwAddrSize
  601. );
  602. //
  603. // Request a new thread now
  604. //
  605. StartThreadIfNeeded (dwInfo);
  606. //
  607. // if failed to receive data, quit processing
  608. // MKarki 3/13/98 - Fix for Bug #147266
  609. // Fix Summary: check for dwSize == 0 too
  610. //
  611. if ( 0 == dwSize )
  612. {
  613. __leave;
  614. }
  615. wPeerPort = ntohs (sin.sin_port);
  616. dwPeerAddress = ntohl (sin.sin_addr.s_addr);
  617. if ( dwSize == SOCKET_ERROR )
  618. {
  619. int error = WSAGetLastError();
  620. switch (error)
  621. {
  622. case WSAEMSGSIZE:
  623. {
  624. ProcessInvalidPacketSize(dwInfo, pBuffer, dwPeerAddress);
  625. __leave;
  626. }
  627. default:
  628. __leave;
  629. }
  630. }
  631. //
  632. // reallocate buffer to size
  633. //
  634. pReAllocatedBuffer = reinterpret_cast <PBYTE>
  635. (::CoTaskMemAlloc (dwSize));
  636. if (NULL == pReAllocatedBuffer)
  637. {
  638. IASTracePrintf (
  639. "Unable to allocate memory for received Radius packet "
  640. "from Process Heap"
  641. );
  642. __leave;
  643. }
  644. //
  645. // copy the information into this buffer
  646. //
  647. CopyMemory (pReAllocatedBuffer, pBuffer, dwSize);
  648. //
  649. // free the memory from the pool
  650. //
  651. m_InBufferPool.deallocate (pBuffer);
  652. pBuffer = NULL;
  653. //
  654. // success
  655. //
  656. bRetVal = TRUE;
  657. }
  658. __finally
  659. {
  660. if (FALSE == bRetVal)
  661. {
  662. //
  663. // do Cleanup
  664. //
  665. if (pBuffer) { m_InBufferPool.deallocate (pBuffer); }
  666. }
  667. else
  668. {
  669. //
  670. // Increment the packet count here
  671. //
  672. InterlockedIncrement (&g_lPacketCount);
  673. //
  674. // start processing data
  675. //
  676. HRESULT hr = ReceivePacket (
  677. pReAllocatedBuffer,
  678. dwSize,
  679. dwPeerAddress,
  680. wPeerPort,
  681. sock,
  682. (PORTTYPE)dwInfo
  683. );
  684. if (FAILED (hr))
  685. {
  686. //
  687. // Decrement the packet count here
  688. //
  689. InterlockedDecrement (&g_lPacketCount);
  690. bRetVal = FALSE;
  691. }
  692. }
  693. //
  694. // decrement the global worker thread count
  695. //
  696. InterlockedDecrement (&g_lThreadCount);
  697. }
  698. } // end of CPacketReceiver::WorkerRoutine method
  699. //+++-------------------------------------------------------------
  700. //
  701. // Function: StartThreadIfNeeded
  702. //
  703. // Synopsis: This is the routine which starts a new
  704. // worker thread if there is a need to do this
  705. // this also increment the outstanding thread
  706. // count
  707. //
  708. // Arguments: [in] DWORD - info to give to thread
  709. //
  710. // Returns: BOOL - status
  711. //
  712. // History: MKarki Created 06/02/98
  713. //
  714. // Called By:
  715. //
  716. //----------------------------------------------------------------
  717. BOOL
  718. CPacketReceiver::StartThreadIfNeeded (
  719. DWORD dwInfo
  720. )
  721. {
  722. BOOL bStatus = TRUE;
  723. //
  724. // check if the processing is still going on
  725. //
  726. if (TRUE == IsProcessingEnabled ())
  727. {
  728. InterlockedIncrement (&g_lThreadCount);
  729. //
  730. // Request a new thread now
  731. //
  732. bStatus = ::IASRequestThread (MakeBoundCallback (
  733. this,
  734. &CPacketReceiver::WorkerRoutine,
  735. dwInfo
  736. )
  737. );
  738. if (FALSE == bStatus)
  739. {
  740. IASTracePrintf (
  741. "Request for a new worker thread failed in Radius component"
  742. );
  743. InterlockedDecrement (&g_lThreadCount);
  744. }
  745. }
  746. return (bStatus);
  747. } // end of CPacketReceiver::StartThreadIfNeeded method
  748. //+++-------------------------------------------------------------
  749. //
  750. // Function: ProcessInvalidPacketSize
  751. //
  752. // Synopsis: Process the UDP packets received when the size of the packet
  753. // is bigger than MAX_PACKET_SIZE (4096)
  754. // Log the error.
  755. //
  756. // Arguments: [in] DWORD - info to give to thread
  757. // (comes from WorkerRoutine)
  758. //
  759. // [in] const void* pBuffer - contains the 4096 first bytes
  760. // of the packet received
  761. // [in] DWORD address - source address (host order)
  762. //
  763. //
  764. // Called By: CPacketReceiver::WorkerRoutine
  765. //
  766. //----------------------------------------------------------------
  767. void CPacketReceiver::ProcessInvalidPacketSize(
  768. /*in*/ DWORD dwInfo,
  769. /*in*/ const void* pBuffer,
  770. /*in*/ DWORD address
  771. )
  772. {
  773. //
  774. // packet received bigger than max size.
  775. // log error and generate audit event
  776. //
  777. // extract the IP address
  778. WCHAR srcAddr[16];
  779. ias_inet_htow(address, srcAddr);
  780. IASTracePrintf(
  781. "Incorrect received packet from %S, size: greater than %d",
  782. srcAddr, MAX_PACKET_SIZE
  783. );
  784. //
  785. // get client information for this RADIUS packet
  786. //
  787. BOOL bStatus = m_pCClients->FindObject(address);
  788. if ( bStatus == FALSE )
  789. {
  790. //
  791. // Invalid Client
  792. // log error and generate audit event
  793. //
  794. IASTracePrintf(
  795. "No client with IP-Address:%S registered with server",
  796. srcAddr
  797. );
  798. PCWSTR strings[] = { srcAddr };
  799. IASReportEvent(
  800. RADIUS_E_INVALID_CLIENT,
  801. 1,
  802. 0,
  803. strings,
  804. NULL
  805. );
  806. //
  807. // generate an Audit Log
  808. //
  809. m_pCReportEvent->Process(
  810. RADIUS_INVALID_CLIENT,
  811. (AUTH_PORTTYPE == (PORTTYPE)dwInfo)?ACCESS_REQUEST:ACCOUNTING_REQUEST,
  812. MAX_PACKET_SIZE,
  813. address,
  814. NULL,
  815. const_cast<void*> (pBuffer)
  816. );
  817. }
  818. else
  819. {
  820. //
  821. // Valid client but packet received bigger than max size.
  822. // log error and generate audit event
  823. //
  824. PCWSTR strings[] = {srcAddr};
  825. IASReportEvent(
  826. RADIUS_E_MALFORMED_PACKET,
  827. 1,
  828. MAX_PACKET_SIZE,
  829. strings,
  830. const_cast<void*> (pBuffer)
  831. );
  832. //
  833. // generate an Audit Log
  834. //
  835. m_pCReportEvent->Process(
  836. RADIUS_MALFORMED_PACKET,
  837. (AUTH_PORTTYPE == (PORTTYPE)dwInfo)?ACCESS_REQUEST:ACCOUNTING_REQUEST,
  838. MAX_PACKET_SIZE,
  839. address,
  840. NULL,
  841. const_cast<void*> (pBuffer)
  842. );
  843. }
  844. }