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.

2710 lines
72 KiB

  1. /*****************************************************************************/
  2. /** Microsoft LAN Manager **/
  3. /** Copyright (C) Microsoft Corp., 1992 **/
  4. /*****************************************************************************/
  5. //***
  6. // File Name: util.c
  7. //
  8. // Function: miscellaneous supervisor support procedures
  9. //
  10. // History:
  11. //
  12. // 05/21/92 Stefan Solomon - Original Version 1.0
  13. //***
  14. #include "ddm.h"
  15. #include "util.h"
  16. #include "isdn.h"
  17. #include "objects.h"
  18. #include "rasmanif.h"
  19. #include "handlers.h"
  20. #include <ddmif.h>
  21. #include <timer.h>
  22. #include <ctype.h>
  23. #include <memory.h>
  24. #include <ddmparms.h>
  25. #define INCL_HOSTWIRE
  26. #include <ppputil.h>
  27. #include "rassrvr.h"
  28. #include "raserror.h"
  29. #include "winsock2.h"
  30. #define net_long(x) (((((unsigned long)(x))&0xffL)<<24) | \
  31. ((((unsigned long)(x))&0xff00L)<<8) | \
  32. ((((unsigned long)(x))&0xff0000L)>>8) | \
  33. ((((unsigned long)(x))&0xff000000L)>>24))
  34. //**
  35. //
  36. // Call: ConvertStringToIpxAddress
  37. //
  38. // Returns: None
  39. //
  40. // Description:
  41. //
  42. VOID
  43. ConvertStringToIpxAddress(
  44. IN WCHAR* pwchIpxAddress,
  45. OUT BYTE * bIpxAddress
  46. )
  47. {
  48. DWORD i;
  49. WCHAR wChar[3];
  50. for(i=0; i<4; i++)
  51. {
  52. wChar[0] = pwchIpxAddress[i*2];
  53. wChar[1] = pwchIpxAddress[(i*2)+1];
  54. wChar[2] = (WCHAR)NULL;
  55. bIpxAddress[i] = (BYTE)wcstol( wChar, NULL, 16 );
  56. }
  57. //
  58. // Skip over the .
  59. //
  60. for(i=4; i<10; i++)
  61. {
  62. wChar[0] = pwchIpxAddress[(i*2)+1];
  63. wChar[1] = pwchIpxAddress[(i*2)+2];
  64. wChar[2] = (WCHAR)NULL;
  65. bIpxAddress[i] = (BYTE)wcstol( wChar, NULL, 16 );
  66. }
  67. }
  68. //**
  69. //
  70. // Call: ConvertStringToIpAddress
  71. //
  72. // Returns: None
  73. //
  74. // Description: Convert caller's a.b.c.d IP address string to the
  75. // big-endian (Motorola format) numeric equivalent.
  76. //
  77. VOID
  78. ConvertStringToIpAddress(
  79. IN WCHAR * pwchIpAddress,
  80. OUT DWORD * lpdwIpAddress
  81. )
  82. {
  83. INT i;
  84. LONG lResult = 0;
  85. WCHAR* pwch = pwchIpAddress;
  86. *lpdwIpAddress = 0;
  87. for (i = 1; i <= 4; ++i)
  88. {
  89. LONG lField = _wtol( pwch );
  90. if (lField > 255)
  91. return;
  92. lResult = (lResult << 8) + lField;
  93. while (*pwch >= L'0' && *pwch <= L'9')
  94. pwch++;
  95. if (i < 4 && *pwch != L'.')
  96. return;
  97. pwch++;
  98. }
  99. *lpdwIpAddress = net_long(lResult);
  100. }
  101. //**
  102. //
  103. // Call: ConvertIpAddressToString
  104. //
  105. // Returns: None
  106. //
  107. // Description: Converts 'ipaddr' to a string in the a.b.c.d form and
  108. // returns same in caller's 'pwszIpAddress' buffer.
  109. // The buffer should be at least 16 wide characters long.
  110. //
  111. VOID
  112. ConvertIpAddressToString(
  113. IN DWORD dwIpAddress,
  114. IN LPWSTR pwszIpAddress
  115. )
  116. {
  117. WCHAR wszBuf[ 3 + 1 ];
  118. LONG lNetIpaddr = net_long( dwIpAddress );
  119. LONG lA = (lNetIpaddr & 0xFF000000) >> 24;
  120. LONG lB = (lNetIpaddr & 0x00FF0000) >> 16;
  121. LONG lC = (lNetIpaddr & 0x0000FF00) >> 8;
  122. LONG lD = (lNetIpaddr & 0x000000FF);
  123. _ltow( lA, wszBuf, 10 );
  124. wcscpy( pwszIpAddress, wszBuf );
  125. wcscat( pwszIpAddress, L"." );
  126. _ltow( lB, wszBuf, 10 );
  127. wcscat( pwszIpAddress, wszBuf );
  128. wcscat( pwszIpAddress, L"." );
  129. _ltow( lC, wszBuf, 10 );
  130. wcscat( pwszIpAddress, wszBuf );
  131. wcscat( pwszIpAddress, L"." );
  132. _ltow( lD, wszBuf, 10 );
  133. wcscat( pwszIpAddress, wszBuf );
  134. }
  135. //**
  136. //
  137. // Call: ConvertIpxAddressToString
  138. //
  139. // Returns: None
  140. //
  141. // Description:
  142. //
  143. VOID
  144. ConvertIpxAddressToString(
  145. IN PBYTE bIpxAddress,
  146. IN LPWSTR pwszIpxAddress
  147. )
  148. {
  149. wsprintf( pwszIpxAddress,
  150. TEXT("%2.2X%2.2X%2.2X%2.2X.%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X"),
  151. bIpxAddress[0],bIpxAddress[1],bIpxAddress[2],bIpxAddress[3],
  152. bIpxAddress[4],bIpxAddress[5],bIpxAddress[6],bIpxAddress[7],
  153. bIpxAddress[8],bIpxAddress[9] );
  154. }
  155. //**
  156. //
  157. // Call: ConvertAtAddressToString
  158. //
  159. // Returns: NO_ERROR - Success
  160. // Non-zero returns - Failure
  161. //
  162. // Description:
  163. //
  164. VOID
  165. ConvertAtAddressToString(
  166. IN DWORD dwAtAddress,
  167. IN LPWSTR pwszAtAddress
  168. )
  169. {
  170. WCHAR wszBuf[ 5 + 1 ];
  171. LONG lA = (dwAtAddress & 0xFFFF0000) >> 16;
  172. LONG lB = (dwAtAddress & 0x0000FFFF);
  173. _ltow( lA, wszBuf, 10 );
  174. wcscpy( pwszAtAddress, wszBuf );
  175. wcscat( pwszAtAddress, L"." );
  176. _ltow( lB, wszBuf, 10 );
  177. wcscat( pwszAtAddress, wszBuf );
  178. return;
  179. }
  180. //**
  181. //
  182. // Call: GetRasConnection0Data
  183. //
  184. // Returns: NO_ERROR - Success
  185. // Non-zero returns - Failure
  186. //
  187. // Description: Given a pointer to a CONNECTION_OBJECT structure will extract
  188. // all relevent information and insert it into a RAS_CONNECTION_0
  189. // structure.
  190. //
  191. DWORD
  192. GetRasiConnection0Data(
  193. IN PCONNECTION_OBJECT pConnObj,
  194. OUT PRASI_CONNECTION_0 pRasConnection0
  195. )
  196. {
  197. pRasConnection0->dwConnection = PtrToUlong(pConnObj->hConnection);
  198. pRasConnection0->dwInterface = PtrToUlong(pConnObj->hDIMInterface);
  199. pRasConnection0->dwInterfaceType = pConnObj->InterfaceType;
  200. wcscpy( pRasConnection0->wszInterfaceName, pConnObj->wchInterfaceName );
  201. wcscpy( pRasConnection0->wszUserName, pConnObj->wchUserName );
  202. wcscpy( pRasConnection0->wszLogonDomain, pConnObj->wchDomainName );
  203. MultiByteToWideChar( CP_ACP,
  204. 0,
  205. pConnObj->bComputerName,
  206. -1,
  207. pRasConnection0->wszRemoteComputer,
  208. NETBIOS_NAME_LEN+1 );
  209. pRasConnection0->dwConnectDuration =
  210. GetActiveTimeInSeconds( &(pConnObj->qwActiveTime) );
  211. pRasConnection0->dwConnectionFlags =
  212. ( pConnObj->fFlags & CONN_OBJ_MESSENGER_PRESENT )
  213. ? RAS_FLAGS_MESSENGER_PRESENT : 0;
  214. if ( pConnObj->fFlags & CONN_OBJ_IS_PPP )
  215. {
  216. pRasConnection0->dwConnectionFlags |= RAS_FLAGS_PPP_CONNECTION;
  217. }
  218. return( NO_ERROR );
  219. }
  220. //**
  221. //
  222. // Call: GetRasConnection1Data
  223. //
  224. // Returns: NO_ERROR - Success
  225. // Non-zero returns - Failure
  226. //
  227. // Description: Given a pointer to a CONNECTION_OBJECT structure will extract
  228. // all relevent information and insert it into a RAS_CONNECTION_1
  229. // structure.
  230. //
  231. DWORD
  232. GetRasiConnection1Data(
  233. IN PCONNECTION_OBJECT pConnObj,
  234. OUT PRASI_CONNECTION_1 pRasConnection1
  235. )
  236. {
  237. BYTE buffer[sizeof(RAS_STATISTICS) + (MAX_STATISTICS_EX * sizeof (ULONG))];
  238. RAS_STATISTICS *pStats = (RAS_STATISTICS *)buffer;
  239. DWORD dwSize = sizeof (buffer);
  240. DWORD dwRetCode;
  241. pRasConnection1->dwConnection = PtrToUlong(pConnObj->hConnection);
  242. pRasConnection1->dwInterface = PtrToUlong(pConnObj->hDIMInterface);
  243. dwRetCode = RasBundleGetStatisticsEx(NULL, (HPORT)pConnObj->hPort,
  244. (PBYTE)pStats, &dwSize );
  245. if ( dwRetCode != NO_ERROR )
  246. {
  247. return( dwRetCode );
  248. }
  249. pRasConnection1->PppInfo.nbf.dwError =
  250. pConnObj->PppProjectionResult.nbf.dwError;
  251. if ( pRasConnection1->PppInfo.nbf.dwError == NO_ERROR )
  252. {
  253. wcscpy( pRasConnection1->PppInfo.nbf.wszWksta,
  254. pConnObj->PppProjectionResult.nbf.wszWksta );
  255. }
  256. else
  257. {
  258. pRasConnection1->PppInfo.nbf.wszWksta[0] = (WCHAR)NULL;
  259. }
  260. pRasConnection1->PppInfo.ip.dwError =
  261. pConnObj->PppProjectionResult.ip.dwError;
  262. if ( pRasConnection1->PppInfo.ip.dwError == NO_ERROR )
  263. {
  264. ConvertIpAddressToString(
  265. pConnObj->PppProjectionResult.ip.dwLocalAddress,
  266. pRasConnection1->PppInfo.ip.wszAddress );
  267. ConvertIpAddressToString(
  268. pConnObj->PppProjectionResult.ip.dwRemoteAddress,
  269. pRasConnection1->PppInfo.ip.wszRemoteAddress );
  270. }
  271. else
  272. {
  273. pRasConnection1->PppInfo.ip.wszAddress[0] = (WCHAR)NULL;
  274. pRasConnection1->PppInfo.ip.wszRemoteAddress[0] = (WCHAR)NULL;
  275. }
  276. pRasConnection1->PppInfo.ipx.dwError =
  277. pConnObj->PppProjectionResult.ipx.dwError;
  278. if ( pRasConnection1->PppInfo.ipx.dwError == NO_ERROR )
  279. {
  280. ConvertIpxAddressToString(
  281. ( pConnObj->InterfaceType == ROUTER_IF_TYPE_CLIENT )
  282. ? pConnObj->PppProjectionResult.ipx.bRemoteAddress
  283. : pConnObj->PppProjectionResult.ipx.bLocalAddress,
  284. pRasConnection1->PppInfo.ipx.wszAddress );
  285. }
  286. else
  287. {
  288. pRasConnection1->PppInfo.ipx.wszAddress[0] = (WCHAR)NULL;
  289. }
  290. pRasConnection1->PppInfo.at.dwError =
  291. pConnObj->PppProjectionResult.at.dwError;
  292. if ( pRasConnection1->PppInfo.at.dwError == NO_ERROR )
  293. {
  294. ConvertAtAddressToString(
  295. ( pConnObj->InterfaceType == ROUTER_IF_TYPE_CLIENT )
  296. ? pConnObj->PppProjectionResult.at.dwRemoteAddress
  297. : pConnObj->PppProjectionResult.at.dwLocalAddress,
  298. pRasConnection1->PppInfo.at.wszAddress );
  299. }
  300. else
  301. {
  302. pRasConnection1->PppInfo.at.wszAddress[0] = (WCHAR)NULL;
  303. }
  304. pRasConnection1->dwBytesXmited = pStats->S_Statistics[BYTES_XMITED];
  305. pRasConnection1->dwBytesRcved = pStats->S_Statistics[BYTES_RCVED];
  306. pRasConnection1->dwFramesXmited = pStats->S_Statistics[FRAMES_XMITED];
  307. pRasConnection1->dwFramesRcved = pStats->S_Statistics[FRAMES_RCVED];
  308. pRasConnection1->dwCrcErr = pStats->S_Statistics[CRC_ERR];
  309. pRasConnection1->dwTimeoutErr = pStats->S_Statistics[TIMEOUT_ERR];
  310. pRasConnection1->dwAlignmentErr = pStats->S_Statistics[ALIGNMENT_ERR];
  311. pRasConnection1->dwFramingErr = pStats->S_Statistics[FRAMING_ERR];
  312. pRasConnection1->dwHardwareOverrunErr
  313. = pStats->S_Statistics[HARDWARE_OVERRUN_ERR];
  314. pRasConnection1->dwBufferOverrunErr
  315. = pStats->S_Statistics[BUFFER_OVERRUN_ERR];
  316. pRasConnection1->dwCompressionRatioIn
  317. = pStats->S_Statistics[COMPRESSION_RATIO_IN];
  318. pRasConnection1->dwCompressionRatioOut
  319. = pStats->S_Statistics[COMPRESSION_RATIO_OUT];
  320. return( NO_ERROR );
  321. }
  322. //**
  323. //
  324. // Call: GetRasConnection2Data
  325. //
  326. // Returns: NO_ERROR - Success
  327. // Non-zero returns - Failure
  328. //
  329. // Description: Given a pointer to a CONNECTION_OBJECT structure will extract
  330. // all relevent information and insert it into a RAS_CONNECTION_2
  331. // structure.
  332. //
  333. DWORD
  334. GetRasiConnection2Data(
  335. IN PCONNECTION_OBJECT pConnObj,
  336. OUT PRASI_CONNECTION_2 pRasConnection2
  337. )
  338. {
  339. pRasConnection2->dwConnection = PtrToUlong(pConnObj->hConnection);
  340. pRasConnection2->guid = pConnObj->guid;
  341. pRasConnection2->dwInterfaceType = pConnObj->InterfaceType;
  342. wcscpy( pRasConnection2->wszUserName, pConnObj->wchUserName );
  343. pRasConnection2->PppInfo2.nbf.dwError =
  344. pConnObj->PppProjectionResult.nbf.dwError;
  345. if ( pRasConnection2->PppInfo2.nbf.dwError == NO_ERROR )
  346. {
  347. wcscpy( pRasConnection2->PppInfo2.nbf.wszWksta,
  348. pConnObj->PppProjectionResult.nbf.wszWksta );
  349. }
  350. else
  351. {
  352. pRasConnection2->PppInfo2.nbf.wszWksta[0] = (WCHAR)NULL;
  353. }
  354. pRasConnection2->PppInfo2.ip.dwError =
  355. pConnObj->PppProjectionResult.ip.dwError;
  356. if ( pRasConnection2->PppInfo2.ip.dwError == NO_ERROR )
  357. {
  358. ConvertIpAddressToString(
  359. pConnObj->PppProjectionResult.ip.dwLocalAddress,
  360. pRasConnection2->PppInfo2.ip.wszAddress );
  361. ConvertIpAddressToString(
  362. pConnObj->PppProjectionResult.ip.dwRemoteAddress,
  363. pRasConnection2->PppInfo2.ip.wszRemoteAddress );
  364. pRasConnection2->PppInfo2.ip.dwOptions = 0;
  365. pRasConnection2->PppInfo2.ip.dwRemoteOptions = 0;
  366. if ( pConnObj->PppProjectionResult.ip.fSendVJHCompression )
  367. {
  368. pRasConnection2->PppInfo2.ip.dwOptions |= PPP_IPCP_VJ;
  369. }
  370. if ( pConnObj->PppProjectionResult.ip.fReceiveVJHCompression )
  371. {
  372. pRasConnection2->PppInfo2.ip.dwRemoteOptions |= PPP_IPCP_VJ;
  373. }
  374. }
  375. else
  376. {
  377. pRasConnection2->PppInfo2.ip.wszAddress[0] = (WCHAR)NULL;
  378. pRasConnection2->PppInfo2.ip.wszRemoteAddress[0] = (WCHAR)NULL;
  379. }
  380. pRasConnection2->PppInfo2.ipx.dwError =
  381. pConnObj->PppProjectionResult.ipx.dwError;
  382. if ( pRasConnection2->PppInfo2.ipx.dwError == NO_ERROR )
  383. {
  384. ConvertIpxAddressToString(
  385. ( pConnObj->InterfaceType == ROUTER_IF_TYPE_CLIENT )
  386. ? pConnObj->PppProjectionResult.ipx.bRemoteAddress
  387. : pConnObj->PppProjectionResult.ipx.bLocalAddress,
  388. pRasConnection2->PppInfo2.ipx.wszAddress );
  389. }
  390. else
  391. {
  392. pRasConnection2->PppInfo2.ipx.wszAddress[0] = (WCHAR)NULL;
  393. }
  394. pRasConnection2->PppInfo2.at.dwError =
  395. pConnObj->PppProjectionResult.at.dwError;
  396. if ( pRasConnection2->PppInfo2.at.dwError == NO_ERROR )
  397. {
  398. ConvertAtAddressToString(
  399. ( pConnObj->InterfaceType == ROUTER_IF_TYPE_CLIENT )
  400. ? pConnObj->PppProjectionResult.at.dwRemoteAddress
  401. : pConnObj->PppProjectionResult.at.dwLocalAddress,
  402. pRasConnection2->PppInfo2.at.wszAddress );
  403. }
  404. else
  405. {
  406. pRasConnection2->PppInfo2.at.wszAddress[0] = (WCHAR)NULL;
  407. }
  408. pRasConnection2->PppInfo2.ccp.dwError =
  409. pConnObj->PppProjectionResult.ccp.dwError;
  410. if ( pRasConnection2->PppInfo2.ccp.dwError == NO_ERROR )
  411. {
  412. pRasConnection2->PppInfo2.ccp.dwCompressionAlgorithm = 0;
  413. if ( pConnObj->PppProjectionResult.ccp.dwSendProtocol == 0x12 )
  414. {
  415. pRasConnection2->PppInfo2.ccp.dwCompressionAlgorithm = RASCCPCA_MPPC;
  416. }
  417. pRasConnection2->PppInfo2.ccp.dwOptions =
  418. pConnObj->PppProjectionResult.ccp.dwSendProtocolData;
  419. pRasConnection2->PppInfo2.ccp.dwRemoteCompressionAlgorithm = 0;
  420. if ( pConnObj->PppProjectionResult.ccp.dwReceiveProtocol == 0x12 )
  421. {
  422. pRasConnection2->PppInfo2.ccp.dwRemoteCompressionAlgorithm = RASCCPCA_MPPC;
  423. }
  424. pRasConnection2->PppInfo2.ccp.dwRemoteOptions =
  425. pConnObj->PppProjectionResult.ccp.dwReceiveProtocolData;
  426. }
  427. pRasConnection2->PppInfo2.lcp.dwError = NO_ERROR;
  428. pRasConnection2->PppInfo2.lcp.dwAuthenticationProtocol =
  429. pConnObj->PppProjectionResult.lcp.dwLocalAuthProtocol;
  430. pRasConnection2->PppInfo2.lcp.dwAuthenticationData =
  431. pConnObj->PppProjectionResult.lcp.dwLocalAuthProtocolData;
  432. pRasConnection2->PppInfo2.lcp.dwEapTypeId =
  433. pConnObj->PppProjectionResult.lcp.dwLocalEapTypeId;
  434. pRasConnection2->PppInfo2.lcp.dwTerminateReason = NO_ERROR;
  435. pRasConnection2->PppInfo2.lcp.dwOptions = 0;
  436. if ( pConnObj->PppProjectionResult.lcp.dwLocalFramingType & PPP_MULTILINK_FRAMING )
  437. {
  438. pRasConnection2->PppInfo2.lcp.dwOptions |= PPP_LCP_MULTILINK_FRAMING;
  439. }
  440. if ( pConnObj->PppProjectionResult.lcp.dwLocalOptions & PPPLCPO_PFC )
  441. {
  442. pRasConnection2->PppInfo2.lcp.dwOptions |= PPP_LCP_PFC;
  443. }
  444. if ( pConnObj->PppProjectionResult.lcp.dwLocalOptions & PPPLCPO_ACFC )
  445. {
  446. pRasConnection2->PppInfo2.lcp.dwOptions |= PPP_LCP_ACFC;
  447. }
  448. if ( pConnObj->PppProjectionResult.lcp.dwLocalOptions & PPPLCPO_SSHF )
  449. {
  450. pRasConnection2->PppInfo2.lcp.dwOptions |= PPP_LCP_SSHF;
  451. }
  452. if ( pConnObj->PppProjectionResult.lcp.dwLocalOptions & PPPLCPO_DES_56 )
  453. {
  454. pRasConnection2->PppInfo2.lcp.dwOptions |= PPP_LCP_DES_56;
  455. }
  456. if ( pConnObj->PppProjectionResult.lcp.dwLocalOptions & PPPLCPO_3_DES )
  457. {
  458. pRasConnection2->PppInfo2.lcp.dwOptions |= PPP_LCP_3_DES;
  459. }
  460. pRasConnection2->PppInfo2.lcp.dwRemoteAuthenticationProtocol =
  461. pConnObj->PppProjectionResult.lcp.dwRemoteAuthProtocol;
  462. pRasConnection2->PppInfo2.lcp.dwRemoteAuthenticationData =
  463. pConnObj->PppProjectionResult.lcp.dwRemoteAuthProtocolData;
  464. pRasConnection2->PppInfo2.lcp.dwRemoteEapTypeId =
  465. pConnObj->PppProjectionResult.lcp.dwRemoteEapTypeId;
  466. pRasConnection2->PppInfo2.lcp.dwRemoteTerminateReason = NO_ERROR;
  467. pRasConnection2->PppInfo2.lcp.dwRemoteOptions = 0;
  468. if ( pConnObj->PppProjectionResult.lcp.dwRemoteFramingType & PPP_MULTILINK_FRAMING )
  469. {
  470. pRasConnection2->PppInfo2.lcp.dwRemoteOptions |= PPP_LCP_MULTILINK_FRAMING;
  471. }
  472. if ( pConnObj->PppProjectionResult.lcp.dwRemoteOptions & PPPLCPO_PFC )
  473. {
  474. pRasConnection2->PppInfo2.lcp.dwRemoteOptions |= PPP_LCP_PFC;
  475. }
  476. if ( pConnObj->PppProjectionResult.lcp.dwRemoteOptions & PPPLCPO_ACFC )
  477. {
  478. pRasConnection2->PppInfo2.lcp.dwRemoteOptions |= PPP_LCP_ACFC;
  479. }
  480. if ( pConnObj->PppProjectionResult.lcp.dwRemoteOptions & PPPLCPO_SSHF )
  481. {
  482. pRasConnection2->PppInfo2.lcp.dwRemoteOptions |= PPP_LCP_SSHF;
  483. }
  484. if ( pConnObj->PppProjectionResult.lcp.dwRemoteOptions & PPPLCPO_DES_56 )
  485. {
  486. pRasConnection2->PppInfo2.lcp.dwRemoteOptions |= PPP_LCP_DES_56;
  487. }
  488. if ( pConnObj->PppProjectionResult.lcp.dwRemoteOptions & PPPLCPO_3_DES )
  489. {
  490. pRasConnection2->PppInfo2.lcp.dwRemoteOptions |= PPP_LCP_3_DES;
  491. }
  492. return( NO_ERROR );
  493. }
  494. DWORD
  495. GetRasConnection0Data(
  496. IN PCONNECTION_OBJECT pConnObj,
  497. OUT PRAS_CONNECTION_0 pRasConn0
  498. )
  499. {
  500. #ifdef _WIN64
  501. DWORD dwErr;
  502. RASI_CONNECTION_0 RasiConn0;
  503. dwErr = GetRasiConnection0Data(pConnObj, &RasiConn0);
  504. if (dwErr == NO_ERROR)
  505. {
  506. pRasConn0->hConnection = UlongToPtr(RasiConn0.dwConnection);
  507. pRasConn0->hInterface = UlongToPtr(RasiConn0.dwInterface);
  508. pRasConn0->dwConnectDuration = RasiConn0.dwConnectDuration;
  509. pRasConn0->dwInterfaceType = RasiConn0.dwInterfaceType;
  510. pRasConn0->dwConnectionFlags = RasiConn0.dwConnectionFlags;
  511. wcscpy(pRasConn0->wszInterfaceName, RasiConn0.wszInterfaceName);
  512. wcscpy(pRasConn0->wszUserName, RasiConn0.wszUserName);
  513. wcscpy(pRasConn0->wszLogonDomain, RasiConn0.wszLogonDomain);
  514. wcscpy(pRasConn0->wszRemoteComputer,RasiConn0.wszRemoteComputer);
  515. }
  516. return dwErr;
  517. #else
  518. return GetRasiConnection0Data(pConnObj, (PRASI_CONNECTION_0)pRasConn0);
  519. #endif
  520. }
  521. DWORD
  522. GetRasConnection1Data(
  523. IN PCONNECTION_OBJECT pConnObj,
  524. OUT PRAS_CONNECTION_1 pRasConn1
  525. )
  526. {
  527. #ifdef _WIN64
  528. DWORD dwErr;
  529. RASI_CONNECTION_1 RasiConn1;
  530. dwErr = GetRasiConnection1Data(pConnObj, &RasiConn1);
  531. if (dwErr == NO_ERROR)
  532. {
  533. pRasConn1->hConnection = UlongToPtr(RasiConn1.dwConnection);
  534. pRasConn1->hInterface = UlongToPtr(RasiConn1.dwInterface);
  535. pRasConn1->PppInfo = RasiConn1.PppInfo;
  536. pRasConn1->dwBytesXmited = RasiConn1.dwBytesXmited;
  537. pRasConn1->dwBytesRcved = RasiConn1.dwBytesRcved;
  538. pRasConn1->dwFramesXmited = RasiConn1.dwFramesXmited;
  539. pRasConn1->dwFramesRcved = RasiConn1.dwFramesRcved;
  540. pRasConn1->dwCrcErr = RasiConn1.dwCrcErr;
  541. pRasConn1->dwTimeoutErr = RasiConn1.dwTimeoutErr;
  542. pRasConn1->dwAlignmentErr = RasiConn1.dwAlignmentErr;
  543. pRasConn1->dwHardwareOverrunErr = RasiConn1.dwHardwareOverrunErr;
  544. pRasConn1->dwFramingErr = RasiConn1.dwFramingErr;
  545. pRasConn1->dwBufferOverrunErr = RasiConn1.dwBufferOverrunErr;
  546. pRasConn1->dwCompressionRatioIn = RasiConn1.dwCompressionRatioIn;
  547. pRasConn1->dwCompressionRatioOut= RasiConn1.dwCompressionRatioOut;
  548. }
  549. return dwErr;
  550. #else
  551. return GetRasiConnection1Data(pConnObj, (PRASI_CONNECTION_1)pRasConn1);
  552. #endif
  553. }
  554. DWORD
  555. GetRasConnection2Data(
  556. IN PCONNECTION_OBJECT pConnObj,
  557. OUT PRAS_CONNECTION_2 pRasConn2
  558. )
  559. {
  560. #ifdef _WIN64
  561. DWORD dwErr;
  562. RASI_CONNECTION_2 RasiConn2;
  563. dwErr = GetRasiConnection2Data(pConnObj, &RasiConn2);
  564. if (dwErr == NO_ERROR)
  565. {
  566. pRasConn2->hConnection = UlongToPtr(RasiConn2.dwConnection);
  567. pRasConn2->dwInterfaceType = RasiConn2.dwInterfaceType;
  568. pRasConn2->guid = RasiConn2.guid;
  569. pRasConn2->PppInfo2 = RasiConn2.PppInfo2;
  570. wcscpy(pRasConn2->wszUserName, RasiConn2.wszUserName);
  571. }
  572. return dwErr;
  573. #else
  574. return GetRasiConnection2Data(pConnObj, (PRASI_CONNECTION_2)pRasConn2);
  575. #endif
  576. }
  577. //**
  578. //
  579. // Call: GetRasiPort0Data
  580. //
  581. // Returns: NO_ERROR - Success
  582. // Non-zero returns - Failure
  583. //
  584. // Description: Given a pointer to a DEVICE_OBJECT structure will extract all
  585. // relevent information and insert it into a RAS_PORT_0 structure.
  586. //
  587. DWORD
  588. GetRasiPort0Data(
  589. IN PDEVICE_OBJECT pDevObj,
  590. OUT PRASI_PORT_0 pRasPort0
  591. )
  592. {
  593. pRasPort0->dwPort = PtrToUlong(pDevObj->hPort);
  594. pRasPort0->dwConnection = PtrToUlong(pDevObj->hConnection);
  595. pRasPort0->dwTotalNumberOfCalls = pDevObj->dwTotalNumberOfCalls;
  596. pRasPort0->dwConnectDuration = 0;
  597. wcscpy( pRasPort0->wszPortName, pDevObj->wchPortName );
  598. wcscpy( pRasPort0->wszMediaName, pDevObj->wchMediaName );
  599. wcscpy( pRasPort0->wszDeviceName, pDevObj->wchDeviceName );
  600. wcscpy( pRasPort0->wszDeviceType, pDevObj->wchDeviceType );
  601. if ( pDevObj->fFlags & DEV_OBJ_OPENED_FOR_DIALOUT )
  602. {
  603. RASCONNSTATUS ConnectionStatus;
  604. ConnectionStatus.dwSize = sizeof( RASCONNSTATUS );
  605. if ( RasGetConnectStatus( pDevObj->hRasConn, &ConnectionStatus ) )
  606. {
  607. //
  608. // On any error we assume the port is disconnected and closed.
  609. //
  610. pRasPort0->dwPortCondition = RAS_PORT_LISTENING;
  611. return( NO_ERROR );
  612. }
  613. switch( ConnectionStatus.rasconnstate )
  614. {
  615. case RASCS_OpenPort:
  616. case RASCS_PortOpened:
  617. case RASCS_ConnectDevice:
  618. case RASCS_DeviceConnected:
  619. case RASCS_AllDevicesConnected:
  620. case RASCS_Authenticate:
  621. case RASCS_AuthNotify:
  622. case RASCS_AuthRetry:
  623. case RASCS_AuthChangePassword:
  624. case RASCS_AuthLinkSpeed:
  625. case RASCS_AuthAck:
  626. case RASCS_ReAuthenticate:
  627. case RASCS_AuthProject:
  628. case RASCS_StartAuthentication:
  629. case RASCS_LogonNetwork:
  630. case RASCS_RetryAuthentication:
  631. case RASCS_CallbackComplete:
  632. case RASCS_PasswordExpired:
  633. pRasPort0->dwPortCondition = RAS_PORT_AUTHENTICATING;
  634. break;
  635. case RASCS_CallbackSetByCaller:
  636. case RASCS_AuthCallback:
  637. case RASCS_PrepareForCallback:
  638. case RASCS_WaitForModemReset:
  639. case RASCS_WaitForCallback:
  640. pRasPort0->dwPortCondition = RAS_PORT_LISTENING;
  641. break;
  642. case RASCS_Projected:
  643. case RASCS_Authenticated:
  644. pRasPort0->dwPortCondition = RAS_PORT_AUTHENTICATED;
  645. break;
  646. case RASCS_SubEntryConnected:
  647. case RASCS_Connected:
  648. pRasPort0->dwPortCondition = RAS_PORT_AUTHENTICATED;
  649. pRasPort0->dwConnectDuration =
  650. GetActiveTimeInSeconds( &(pDevObj->qwActiveTime) );
  651. break;
  652. case RASCS_Disconnected:
  653. case RASCS_SubEntryDisconnected:
  654. pRasPort0->dwPortCondition = RAS_PORT_DISCONNECTED;
  655. break;
  656. case RASCS_Interactive:
  657. default:
  658. pRasPort0->dwPortCondition = RAS_PORT_DISCONNECTED;
  659. break;
  660. }
  661. return( NO_ERROR );
  662. }
  663. switch( pDevObj->DeviceState )
  664. {
  665. case DEV_OBJ_LISTENING:
  666. pRasPort0->dwPortCondition = RAS_PORT_LISTENING;
  667. break;
  668. case DEV_OBJ_HW_FAILURE:
  669. pRasPort0->dwPortCondition = RAS_PORT_NON_OPERATIONAL;
  670. break;
  671. case DEV_OBJ_RECEIVING_FRAME:
  672. case DEV_OBJ_LISTEN_COMPLETE:
  673. case DEV_OBJ_AUTH_IS_ACTIVE:
  674. pRasPort0->dwPortCondition = RAS_PORT_AUTHENTICATING;
  675. break;
  676. case DEV_OBJ_ACTIVE:
  677. pRasPort0->dwPortCondition = RAS_PORT_AUTHENTICATED;
  678. pRasPort0->dwConnectDuration =
  679. GetActiveTimeInSeconds( &(pDevObj->qwActiveTime) );
  680. break;
  681. case DEV_OBJ_CALLBACK_DISCONNECTING:
  682. case DEV_OBJ_CALLBACK_DISCONNECTED:
  683. case DEV_OBJ_CALLBACK_CONNECTING:
  684. pRasPort0->dwPortCondition = RAS_PORT_CALLING_BACK;
  685. break;
  686. case DEV_OBJ_CLOSED:
  687. case DEV_OBJ_CLOSING:
  688. pRasPort0->dwPortCondition = RAS_PORT_DISCONNECTED;
  689. break;
  690. default:
  691. ASSERT( FALSE );
  692. }
  693. return( NO_ERROR );
  694. }
  695. //**
  696. //
  697. // Call: GetRasiPort1Data
  698. //
  699. // Returns: NO_ERROR - Success
  700. // Non-zero returns - Failure
  701. //
  702. // Description: Given a pointer to a DEVICE_OBJECT structure will extract all
  703. // relevent information and insert it into a RAS_PORT_0 structure.
  704. //
  705. DWORD
  706. GetRasiPort1Data(
  707. IN PDEVICE_OBJECT pDevObj,
  708. OUT PRASI_PORT_1 pRasPort1
  709. )
  710. {
  711. BYTE buffer[sizeof(RAS_STATISTICS) + (MAX_STATISTICS * sizeof (ULONG))];
  712. RAS_STATISTICS *pStats = (RAS_STATISTICS *)buffer;
  713. DWORD dwSize = sizeof (buffer);
  714. DWORD dwRetCode;
  715. RASMAN_INFO RasManInfo;
  716. pRasPort1->dwPort = PtrToUlong(pDevObj->hPort);
  717. pRasPort1->dwConnection = PtrToUlong(pDevObj->hConnection);
  718. pRasPort1->dwHardwareCondition =
  719. ( pDevObj->DeviceState == DEV_OBJ_HW_FAILURE )
  720. ? RAS_HARDWARE_FAILURE
  721. : RAS_HARDWARE_OPERATIONAL;
  722. dwRetCode = RasGetInfo( NULL, (HPORT)pDevObj->hPort, &RasManInfo );
  723. if ( dwRetCode != NO_ERROR )
  724. {
  725. return( dwRetCode );
  726. }
  727. pRasPort1->dwLineSpeed = RasManInfo.RI_LinkSpeed;
  728. dwRetCode = RasPortGetStatisticsEx(NULL, (HPORT)pDevObj->hPort,
  729. (PBYTE)pStats, &dwSize );
  730. if ( dwRetCode != NO_ERROR )
  731. {
  732. return( dwRetCode );
  733. }
  734. pRasPort1->dwLineSpeed = RasManInfo.RI_LinkSpeed;
  735. pRasPort1->dwBytesXmited = pStats->S_Statistics[BYTES_XMITED];
  736. pRasPort1->dwBytesRcved = pStats->S_Statistics[BYTES_RCVED];
  737. pRasPort1->dwFramesXmited = pStats->S_Statistics[FRAMES_XMITED];
  738. pRasPort1->dwFramesRcved = pStats->S_Statistics[FRAMES_RCVED];
  739. pRasPort1->dwCrcErr = pStats->S_Statistics[CRC_ERR];
  740. pRasPort1->dwTimeoutErr = pStats->S_Statistics[TIMEOUT_ERR];
  741. pRasPort1->dwAlignmentErr = pStats->S_Statistics[ALIGNMENT_ERR];
  742. pRasPort1->dwFramingErr = pStats->S_Statistics[FRAMING_ERR];
  743. pRasPort1->dwHardwareOverrunErr
  744. = pStats->S_Statistics[HARDWARE_OVERRUN_ERR];
  745. pRasPort1->dwBufferOverrunErr
  746. = pStats->S_Statistics[BUFFER_OVERRUN_ERR];
  747. pRasPort1->dwCompressionRatioIn
  748. = pStats->S_Statistics[ COMPRESSION_RATIO_IN ];
  749. pRasPort1->dwCompressionRatioOut
  750. = pStats->S_Statistics[ COMPRESSION_RATIO_OUT ];
  751. return( NO_ERROR );
  752. }
  753. DWORD
  754. GetRasPort0Data(
  755. IN PDEVICE_OBJECT pDevObj,
  756. OUT PRAS_PORT_0 pRasPort0
  757. )
  758. {
  759. #ifdef _WIN64
  760. DWORD dwErr;
  761. RASI_PORT_0 RasiPort0;
  762. dwErr = GetRasiPort0Data(pDevObj, &RasiPort0);
  763. if (dwErr == NO_ERROR)
  764. {
  765. pRasPort0->hPort = UlongToPtr(RasiPort0.dwPort);
  766. pRasPort0->hConnection = UlongToPtr(RasiPort0.dwConnection);
  767. pRasPort0->dwPortCondition = RasiPort0.dwPortCondition;
  768. pRasPort0->dwTotalNumberOfCalls = RasiPort0.dwTotalNumberOfCalls;
  769. pRasPort0->dwConnectDuration = RasiPort0.dwConnectDuration;
  770. wcscpy(pRasPort0->wszPortName, RasiPort0.wszPortName);
  771. wcscpy(pRasPort0->wszMediaName, RasiPort0.wszMediaName);
  772. wcscpy(pRasPort0->wszDeviceName, RasiPort0.wszDeviceName);
  773. wcscpy(pRasPort0->wszDeviceType, RasiPort0.wszDeviceType);
  774. }
  775. return dwErr;
  776. #else
  777. return GetRasiPort0Data(pDevObj, (PRASI_PORT_0)pRasPort0);
  778. #endif
  779. }
  780. DWORD
  781. GetRasPort1Data(
  782. IN PDEVICE_OBJECT pDevObj,
  783. OUT PRAS_PORT_1 pRasPort1
  784. )
  785. {
  786. #ifdef _WIN64
  787. DWORD dwErr;
  788. RASI_PORT_1 RasiPort1;
  789. dwErr = GetRasiPort1Data(pDevObj, &RasiPort1);
  790. if (dwErr == NO_ERROR)
  791. {
  792. pRasPort1->hPort = UlongToPtr(RasiPort1.dwPort);
  793. pRasPort1->hConnection = UlongToPtr(RasiPort1.dwConnection);
  794. pRasPort1->dwHardwareCondition = RasiPort1.dwHardwareCondition;
  795. pRasPort1->dwLineSpeed = RasiPort1.dwLineSpeed;
  796. pRasPort1->dwBytesXmited = RasiPort1.dwBytesXmited;
  797. pRasPort1->dwBytesRcved = RasiPort1.dwBytesRcved;
  798. pRasPort1->dwFramesXmited = RasiPort1.dwFramesXmited;
  799. pRasPort1->dwFramesRcved = RasiPort1.dwFramesRcved;
  800. pRasPort1->dwCrcErr = RasiPort1.dwCrcErr;
  801. pRasPort1->dwTimeoutErr = RasiPort1.dwTimeoutErr;
  802. pRasPort1->dwAlignmentErr = RasiPort1.dwAlignmentErr;
  803. pRasPort1->dwHardwareOverrunErr = RasiPort1.dwHardwareOverrunErr;
  804. pRasPort1->dwFramingErr = RasiPort1.dwFramingErr;
  805. pRasPort1->dwBufferOverrunErr = RasiPort1.dwBufferOverrunErr;
  806. pRasPort1->dwCompressionRatioIn = RasiPort1.dwCompressionRatioIn;
  807. pRasPort1->dwCompressionRatioOut= RasiPort1.dwCompressionRatioOut;
  808. }
  809. return dwErr;
  810. #else
  811. return GetRasiPort1Data(pDevObj, (PRASI_PORT_1)pRasPort1);
  812. #endif
  813. }
  814. //***
  815. //
  816. // Function: SignalHwError
  817. //
  818. // Descr:
  819. //
  820. //***
  821. VOID
  822. SignalHwError(
  823. IN PDEVICE_OBJECT pDeviceObj
  824. )
  825. {
  826. LPWSTR portnamep;
  827. DDM_PRINT( gblDDMConfigInfo.dwTraceId, TRACE_FSM, "SignalHwErr: Entered");
  828. portnamep = pDeviceObj->wchPortName;
  829. DDMLogError( ROUTERLOG_DEV_HW_ERROR, 1, &portnamep, 0 );
  830. }
  831. DWORD
  832. MapAuthCodeToLogId(
  833. IN WORD Code
  834. )
  835. {
  836. switch (Code)
  837. {
  838. case AUTH_ALL_PROJECTIONS_FAILED:
  839. return (ROUTERLOG_AUTH_NO_PROJECTIONS);
  840. case AUTH_PASSWORD_EXPIRED:
  841. return(ROUTERLOG_PASSWORD_EXPIRED);
  842. case AUTH_ACCT_EXPIRED:
  843. return(ROUTERLOG_ACCT_EXPIRED);
  844. case AUTH_NO_DIALIN_PRIVILEGE:
  845. return(ROUTERLOG_NO_DIALIN_PRIVILEGE);
  846. case AUTH_UNSUPPORTED_VERSION:
  847. return(ROUTERLOG_UNSUPPORTED_VERSION);
  848. case AUTH_ENCRYPTION_REQUIRED:
  849. return(ROUTERLOG_ENCRYPTION_REQUIRED);
  850. }
  851. return(0);
  852. }
  853. BOOL
  854. IsPortOwned(
  855. IN PDEVICE_OBJECT pDeviceObj
  856. )
  857. {
  858. RASMAN_INFO rasinfo;
  859. //
  860. // get the current port state
  861. //
  862. if ( RasGetInfo( NULL, pDeviceObj->hPort, &rasinfo ) != NO_ERROR )
  863. {
  864. return( FALSE );
  865. }
  866. return( rasinfo.RI_OwnershipFlag );
  867. }
  868. VOID
  869. GetLoggingInfo(
  870. IN PDEVICE_OBJECT pDeviceObj,
  871. OUT PDWORD BaudRate,
  872. OUT PDWORD BytesSent,
  873. OUT PDWORD BytesRecv,
  874. OUT RASMAN_DISCONNECT_REASON *Reason,
  875. OUT SYSTEMTIME *Time
  876. )
  877. {
  878. RASMAN_INFO RasmanInfo;
  879. BYTE buffer[sizeof(RAS_STATISTICS) + (MAX_STATISTICS * sizeof (ULONG))];
  880. RAS_STATISTICS *PortStats = (RAS_STATISTICS *)buffer;
  881. DWORD PortStatsSize = sizeof (buffer);
  882. *Reason = 3L;
  883. //
  884. // Time is a piece of cake
  885. //
  886. GetLocalTime(Time);
  887. //
  888. // Now the statistics
  889. //
  890. *BytesSent = 0L;
  891. *BytesRecv = 0L;
  892. if (RasPortGetStatisticsEx( NULL,
  893. pDeviceObj->hPort,
  894. (PBYTE)PortStats,
  895. &PortStatsSize))
  896. {
  897. return;
  898. }
  899. *BytesRecv = PortStats->S_Statistics[BYTES_RCVED];
  900. *BytesSent = PortStats->S_Statistics[BYTES_XMITED];
  901. //
  902. // And finally the disconnect reason (local or remote) and baud rate
  903. //
  904. if (RasGetInfo(NULL, pDeviceObj->hPort, &RasmanInfo))
  905. {
  906. return;
  907. }
  908. *Reason = RasmanInfo.RI_DisconnectReason;
  909. *BaudRate = GetLineSpeed(pDeviceObj->hPort);
  910. return;
  911. }
  912. DWORD
  913. GetLineSpeed(
  914. IN HPORT hPort
  915. )
  916. {
  917. RASMAN_INFO RasManInfo;
  918. if (RasGetInfo(NULL, hPort, &RasManInfo))
  919. {
  920. return 0;
  921. }
  922. return (RasManInfo.RI_LinkSpeed);
  923. }
  924. VOID
  925. LogConnectionEvent(
  926. IN PCONNECTION_OBJECT pConnObj,
  927. IN PDEVICE_OBJECT pDeviceObj
  928. )
  929. {
  930. DWORD BaudRate = 0;
  931. DWORD BytesSent;
  932. DWORD BytesRecv;
  933. RASMAN_DISCONNECT_REASON Reason;
  934. SYSTEMTIME DiscTime;
  935. LPWSTR auditstrp[12];
  936. WCHAR *ReasonStr;
  937. WCHAR BytesRecvStr[20];
  938. WCHAR BytesSentStr[20];
  939. WCHAR BaudRateStr[20];
  940. WCHAR DateConnected[64];
  941. WCHAR DateDisconnected[64];
  942. WCHAR TimeConnected[64];
  943. WCHAR TimeDisconnected[64];
  944. DWORD active_time;
  945. WCHAR minutes[20];
  946. WCHAR seconds[4];
  947. WCHAR wchFullUserName[UNLEN+DNLEN+2];
  948. WCHAR *DiscReasons[] =
  949. {
  950. gblpszAdminRequest,
  951. gblpszUserRequest,
  952. gblpszHardwareFailure,
  953. gblpszUnknownReason
  954. };
  955. GetLoggingInfo( pDeviceObj, &BaudRate, &BytesSent,
  956. &BytesRecv, &Reason, &DiscTime);
  957. wcscpy(TimeConnected, L"");
  958. wcscpy(DateConnected, L"");
  959. wcscpy(TimeDisconnected, L"");
  960. wcscpy(DateDisconnected, L"");
  961. GetTimeFormat(
  962. LOCALE_SYSTEM_DEFAULT,
  963. TIME_NOSECONDS,
  964. &pDeviceObj->ConnectionTime,
  965. NULL,
  966. TimeConnected,
  967. sizeof(TimeConnected)/sizeof(WCHAR));
  968. GetDateFormat(
  969. LOCALE_SYSTEM_DEFAULT,
  970. DATE_SHORTDATE,
  971. &pDeviceObj->ConnectionTime,
  972. NULL,
  973. DateConnected,
  974. sizeof(DateConnected)/sizeof(WCHAR));
  975. GetTimeFormat(
  976. LOCALE_SYSTEM_DEFAULT,
  977. TIME_NOSECONDS,
  978. &DiscTime,
  979. NULL,
  980. TimeDisconnected,
  981. sizeof(TimeDisconnected)/sizeof(WCHAR));
  982. GetDateFormat(
  983. LOCALE_SYSTEM_DEFAULT,
  984. DATE_SHORTDATE,
  985. &DiscTime,
  986. NULL,
  987. DateDisconnected,
  988. sizeof(DateDisconnected)/sizeof(WCHAR));
  989. active_time = GetActiveTimeInSeconds( &(pDeviceObj->qwActiveTime) );
  990. DDM_PRINT( gblDDMConfigInfo.dwTraceId, TRACE_FSM,
  991. "CLIENT ACTIVE FOR %li SECONDS", active_time);
  992. _itow(active_time / 60, minutes, 10);
  993. _itow(active_time % 60, seconds, 10);
  994. wsprintf(BytesSentStr, TEXT("%u"), BytesSent);
  995. wsprintf(BytesRecvStr, TEXT("%u"), BytesRecv);
  996. wsprintf(BaudRateStr, TEXT("%i"), BaudRate);
  997. ReasonStr = DiscReasons[Reason];
  998. if ( pConnObj->wchDomainName[0] != TEXT('\0') )
  999. {
  1000. wcscpy( wchFullUserName, pConnObj->wchDomainName );
  1001. wcscat( wchFullUserName, TEXT("\\") );
  1002. wcscat( wchFullUserName, pConnObj->wchUserName );
  1003. }
  1004. else
  1005. {
  1006. wcscpy( wchFullUserName, pConnObj->wchUserName );
  1007. }
  1008. auditstrp[0] = wchFullUserName;
  1009. auditstrp[1] = pDeviceObj->wchPortName;
  1010. auditstrp[2] = DateConnected;
  1011. auditstrp[3] = TimeConnected;
  1012. auditstrp[4] = DateDisconnected;
  1013. auditstrp[5] = TimeDisconnected;
  1014. auditstrp[6] = minutes;
  1015. auditstrp[7] = seconds;
  1016. auditstrp[8] = BytesSentStr;
  1017. auditstrp[9] = BytesRecvStr;
  1018. if(RAS_DEVICE_CLASS(pDeviceObj->dwDeviceType) == RDT_Tunnel)
  1019. {
  1020. auditstrp[10] = DiscReasons[Reason];
  1021. auditstrp[11] = NULL;
  1022. DDMLogInformation( ROUTERLOG_USER_ACTIVE_TIME_VPN, 11, auditstrp );
  1023. }
  1024. else
  1025. {
  1026. auditstrp[10] = BaudRateStr;
  1027. auditstrp[11] = DiscReasons[Reason];
  1028. DDMLogInformation( ROUTERLOG_USER_ACTIVE_TIME, 12, auditstrp );
  1029. }
  1030. if(pConnObj->PppProjectionResult.ip.dwError == NO_ERROR)
  1031. {
  1032. WCHAR *pszAddress = GetIpAddress(
  1033. pConnObj->PppProjectionResult.ip.dwRemoteAddress);
  1034. auditstrp[0] = pszAddress;
  1035. DDMLogInformation( ROUTERLOG_IP_USER_DISCONNECTED, 1, auditstrp);
  1036. LocalFree(pszAddress);
  1037. }
  1038. }
  1039. //**
  1040. //
  1041. // Call: GetTransportIndex
  1042. //
  1043. // Returns: Index of the tansport entry in the interface object
  1044. //
  1045. // Description: Given the id of a protocol return an index.
  1046. //
  1047. DWORD
  1048. GetTransportIndex(
  1049. IN DWORD dwProtocolId
  1050. )
  1051. {
  1052. DWORD dwTransportIndex;
  1053. for ( dwTransportIndex = 0;
  1054. dwTransportIndex < gblDDMConfigInfo.dwNumRouterManagers;
  1055. dwTransportIndex++ )
  1056. {
  1057. if ( gblRouterManagers[dwTransportIndex].DdmRouterIf.dwProtocolId
  1058. == dwProtocolId )
  1059. {
  1060. return( dwTransportIndex );
  1061. }
  1062. }
  1063. return( (DWORD)-1 );
  1064. }
  1065. //**
  1066. //
  1067. // Call: DDMCleanUp
  1068. //
  1069. // Returns: None
  1070. //
  1071. // Description: Will clean up all DDM allocations
  1072. //
  1073. VOID
  1074. DDMCleanUp(
  1075. VOID
  1076. )
  1077. {
  1078. DWORD dwIndex;
  1079. if(gblDDMConfigInfo.dwServerFlags & PPPCFG_AudioAccelerator)
  1080. {
  1081. //
  1082. // Cleanup rasaudio stuff.
  1083. //
  1084. (void) RasEnableRasAudio(NULL, FALSE);
  1085. }
  1086. if ( gblDDMConfigInfo.hIpHlpApi != NULL )
  1087. {
  1088. FreeLibrary( gblDDMConfigInfo.hIpHlpApi );
  1089. gblDDMConfigInfo.hIpHlpApi = NULL;
  1090. gblDDMConfigInfo.lpfnAllocateAndGetIfTableFromStack = NULL;
  1091. gblDDMConfigInfo.lpfnAllocateAndGetIpAddrTableFromStack = NULL;
  1092. }
  1093. if ( gblDDMConfigInfo.fRasSrvrInitialized )
  1094. {
  1095. RasSrvrUninitialize();
  1096. gblDDMConfigInfo.fRasSrvrInitialized = FALSE;
  1097. }
  1098. PppDdmDeInit();
  1099. if ( gblDDMConfigInfo.hinstAcctModule != NULL )
  1100. {
  1101. DWORD dwRetCode;
  1102. HKEY hKeyAccounting;
  1103. if ( gblDDMConfigInfo.lpfnRasAcctProviderTerminate != NULL )
  1104. {
  1105. gblDDMConfigInfo.lpfnRasAcctProviderTerminate();
  1106. }
  1107. //
  1108. // Write back the AccntSessionId value
  1109. //
  1110. dwRetCode = RegOpenKeyEx(
  1111. HKEY_LOCAL_MACHINE,
  1112. RAS_KEYPATH_ACCOUNTING,
  1113. 0,
  1114. KEY_READ | KEY_WRITE,
  1115. &hKeyAccounting );
  1116. if ( dwRetCode == NO_ERROR )
  1117. {
  1118. RegSetValueEx(
  1119. hKeyAccounting,
  1120. RAS_VALNAME_ACCTSESSIONID,
  1121. 0,
  1122. REG_DWORD,
  1123. (BYTE *)(&gblDDMConfigInfo.dwAccountingSessionId),
  1124. 4 );
  1125. RegCloseKey( hKeyAccounting );
  1126. }
  1127. FreeLibrary( gblDDMConfigInfo.hinstAcctModule );
  1128. gblDDMConfigInfo.hinstAcctModule = NULL;
  1129. }
  1130. DeleteCriticalSection( &(gblDDMConfigInfo.CSAccountingSessionId) );
  1131. if ( gblDDMConfigInfo.hinstAuthModule != NULL )
  1132. {
  1133. if ( gblDDMConfigInfo.lpfnRasAuthProviderTerminate != NULL )
  1134. {
  1135. gblDDMConfigInfo.lpfnRasAuthProviderTerminate();
  1136. }
  1137. FreeLibrary( gblDDMConfigInfo.hinstAuthModule );
  1138. gblDDMConfigInfo.hinstAuthModule = NULL;
  1139. }
  1140. if ( gblDDMConfigInfo.hkeyParameters != NULL )
  1141. {
  1142. RegCloseKey( gblDDMConfigInfo.hkeyParameters );
  1143. gblDDMConfigInfo.hkeyParameters = NULL;
  1144. }
  1145. if ( gblDDMConfigInfo.hkeyAccounting != NULL )
  1146. {
  1147. RegCloseKey( gblDDMConfigInfo.hkeyParameters );
  1148. gblDDMConfigInfo.hkeyParameters = NULL;
  1149. }
  1150. if ( gblDDMConfigInfo.hkeyAuthentication != NULL )
  1151. {
  1152. RegCloseKey( gblDDMConfigInfo.hkeyParameters );
  1153. gblDDMConfigInfo.hkeyParameters = NULL;
  1154. }
  1155. if ( gblDDMConfigInfo.hInstAdminModule != NULL )
  1156. {
  1157. if ( gblDDMConfigInfo.lpfnRasAdminTerminateDll != NULL )
  1158. {
  1159. DWORD (*TerminateAdminDll)() =
  1160. (DWORD(*)(VOID))gblDDMConfigInfo.lpfnRasAdminTerminateDll;
  1161. TerminateAdminDll();
  1162. }
  1163. FreeLibrary( gblDDMConfigInfo.hInstAdminModule );
  1164. }
  1165. if ( gblDDMConfigInfo.hInstSecurityModule != NULL )
  1166. {
  1167. FreeLibrary( gblDDMConfigInfo.hInstSecurityModule );
  1168. }
  1169. if ( gblpRouterPhoneBook != NULL )
  1170. {
  1171. LOCAL_FREE( gblpRouterPhoneBook );
  1172. }
  1173. if ( gblpszAdminRequest != NULL )
  1174. {
  1175. LOCAL_FREE( gblpszAdminRequest );
  1176. }
  1177. if ( gblpszUserRequest != NULL )
  1178. {
  1179. LOCAL_FREE( gblpszUserRequest );
  1180. }
  1181. if ( gblpszHardwareFailure != NULL )
  1182. {
  1183. LOCAL_FREE( gblpszHardwareFailure );
  1184. }
  1185. if ( gblpszUnknownReason != NULL )
  1186. {
  1187. LOCAL_FREE( gblpszUnknownReason );
  1188. }
  1189. if ( gblpszPm != NULL )
  1190. {
  1191. LOCAL_FREE( gblpszPm );
  1192. }
  1193. if ( gblpszAm != NULL )
  1194. {
  1195. LOCAL_FREE( gblpszAm );
  1196. }
  1197. if( gblDDMConfigInfo.apAnalogIPAddresses != NULL )
  1198. {
  1199. LocalFree( gblDDMConfigInfo.apAnalogIPAddresses[0] );
  1200. LocalFree( gblDDMConfigInfo.apAnalogIPAddresses );
  1201. gblDDMConfigInfo.apAnalogIPAddresses = NULL;
  1202. gblDDMConfigInfo.cAnalogIPAddresses = 0;
  1203. }
  1204. if( gblDDMConfigInfo.apDigitalIPAddresses != NULL )
  1205. {
  1206. LocalFree( gblDDMConfigInfo.apDigitalIPAddresses[0] );
  1207. LocalFree( gblDDMConfigInfo.apDigitalIPAddresses );
  1208. gblDDMConfigInfo.apDigitalIPAddresses = NULL;
  1209. gblDDMConfigInfo.cDigitalIPAddresses = 0;
  1210. }
  1211. gblDDMConfigInfo.dwIndex = 0;
  1212. if ( gblDeviceTable.DeviceBucket != NULL )
  1213. {
  1214. //
  1215. // close all opened devices
  1216. //
  1217. DeviceObjIterator( DeviceObjClose, FALSE, NULL );
  1218. }
  1219. if(gblDDMConfigInfo.fRasmanReferenced)
  1220. {
  1221. //
  1222. // Decerement rasman's refrence count. This does not happen
  1223. // automatically since we are in the same process as rasman.
  1224. //
  1225. RasReferenceRasman( FALSE );
  1226. }
  1227. if ( gblSupervisorEvents != (HANDLE *)NULL )
  1228. {
  1229. DeleteMessageQs();
  1230. for ( dwIndex = 0;
  1231. dwIndex < NUM_DDM_EVENTS +
  1232. gblDeviceTable.NumDeviceBuckets +
  1233. gblDeviceTable.NumConnectionBuckets;
  1234. dwIndex ++ )
  1235. {
  1236. if ( gblSupervisorEvents[dwIndex] != NULL )
  1237. {
  1238. switch( dwIndex )
  1239. {
  1240. case DDM_EVENT_SVC_TERMINATED:
  1241. case DDM_EVENT_SVC:
  1242. break;
  1243. default:
  1244. CloseHandle( gblSupervisorEvents[dwIndex] );
  1245. break;
  1246. }
  1247. gblSupervisorEvents[dwIndex] = NULL;
  1248. }
  1249. }
  1250. }
  1251. //
  1252. // Wait for this to be released
  1253. //
  1254. EnterCriticalSection( &(gblDeviceTable.CriticalSection) );
  1255. DeleteCriticalSection( &(gblDeviceTable.CriticalSection) );
  1256. TimerQDelete();
  1257. //
  1258. // Release all notification events
  1259. //
  1260. if ( gblDDMConfigInfo.NotificationEventListHead.Flink != NULL )
  1261. {
  1262. while( !IsListEmpty( &(gblDDMConfigInfo.NotificationEventListHead ) ) )
  1263. {
  1264. NOTIFICATION_EVENT * pNotificationEvent = (NOTIFICATION_EVENT *)
  1265. RemoveHeadList( &(gblDDMConfigInfo.NotificationEventListHead) );
  1266. CloseHandle( pNotificationEvent->hEventClient );
  1267. CloseHandle( pNotificationEvent->hEventRouter );
  1268. LOCAL_FREE( pNotificationEvent );
  1269. }
  1270. }
  1271. MediaObjFreeTable();
  1272. //
  1273. // Destroy private heap
  1274. //
  1275. if ( gblDDMConfigInfo.hHeap != NULL )
  1276. {
  1277. HeapDestroy( gblDDMConfigInfo.hHeap );
  1278. }
  1279. //
  1280. // Zero out globals
  1281. //
  1282. ZeroMemory( &gblDeviceTable, sizeof( gblDeviceTable ) );
  1283. ZeroMemory( &gblMediaTable, sizeof( gblMediaTable ) );
  1284. ZeroMemory( gblEventHandlerTable, sizeof( gblEventHandlerTable ) );
  1285. //ZeroMemory( &gblDDMConfigInfo, sizeof( gblDDMConfigInfo ) );
  1286. gblRouterManagers = NULL;
  1287. gblpInterfaceTable = NULL;
  1288. gblSupervisorEvents = NULL;
  1289. gblphEventDDMServiceState = NULL;
  1290. gblpRouterPhoneBook = NULL;
  1291. gblpszAdminRequest = NULL;
  1292. gblpszUserRequest = NULL;
  1293. gblpszHardwareFailure = NULL;
  1294. gblpszUnknownReason = NULL;
  1295. gblpszPm = NULL;
  1296. gblpszAm = NULL;
  1297. }
  1298. //**
  1299. //
  1300. // Call: GetRouterPhoneBook
  1301. //
  1302. // Returns: NO_ERROR - Success
  1303. // Non-zero returns - Failure
  1304. //
  1305. // Description: Will set the gblpRouterPhoneBook global to point to the
  1306. // full path of the router phonebook.
  1307. //
  1308. DWORD
  1309. GetRouterPhoneBook(
  1310. VOID
  1311. )
  1312. {
  1313. DWORD dwSize;
  1314. DWORD cchDir = GetWindowsDirectory( NULL, 0 );
  1315. if ( cchDir == 0 )
  1316. {
  1317. return( GetLastError() );
  1318. }
  1319. dwSize=(cchDir+wcslen(TEXT("\\SYSTEM32\\RAS\\ROUTER.PBK"))+1)*sizeof(WCHAR);
  1320. if ( ( gblpRouterPhoneBook = LOCAL_ALLOC( LPTR, dwSize ) ) == NULL )
  1321. {
  1322. return( GetLastError() );
  1323. }
  1324. if ( GetWindowsDirectory( gblpRouterPhoneBook, cchDir ) == 0 )
  1325. {
  1326. return( GetLastError() );
  1327. }
  1328. if ( gblpRouterPhoneBook[cchDir-1] != TEXT('\\') )
  1329. {
  1330. wcscat( gblpRouterPhoneBook, TEXT("\\") );
  1331. }
  1332. wcscat( gblpRouterPhoneBook, TEXT("SYSTEM32\\RAS\\ROUTER.PBK") );
  1333. return( NO_ERROR );
  1334. }
  1335. //**
  1336. //
  1337. // Call: LoadStrings
  1338. //
  1339. // Returns: NO_ERROR - Success
  1340. // Non-zero returns - Failure
  1341. //
  1342. // Description: Loads all localizable strings from the resource table
  1343. //
  1344. DWORD
  1345. LoadStrings(
  1346. VOID
  1347. )
  1348. {
  1349. #define MAX_XLATE_STRING 40
  1350. LPWSTR lpwsModuleName = TEXT("MPRDDM.DLL");
  1351. //
  1352. // Load strings from resource file
  1353. //
  1354. gblpszAdminRequest = LOCAL_ALLOC( LPTR, MAX_XLATE_STRING*sizeof(WCHAR));
  1355. gblpszUserRequest = LOCAL_ALLOC( LPTR, MAX_XLATE_STRING*sizeof(WCHAR));
  1356. gblpszHardwareFailure = LOCAL_ALLOC( LPTR, MAX_XLATE_STRING*sizeof(WCHAR));
  1357. gblpszUnknownReason = LOCAL_ALLOC( LPTR, MAX_XLATE_STRING*sizeof(WCHAR));
  1358. gblpszPm = LOCAL_ALLOC( LPTR, MAX_XLATE_STRING*sizeof(WCHAR));
  1359. gblpszAm = LOCAL_ALLOC( LPTR, MAX_XLATE_STRING*sizeof(WCHAR));
  1360. gblpszUnknown = LOCAL_ALLOC( LPTR, MAX_XLATE_STRING*sizeof(WCHAR));
  1361. if ( ( gblpszAdminRequest == NULL ) ||
  1362. ( gblpszUserRequest == NULL ) ||
  1363. ( gblpszHardwareFailure == NULL ) ||
  1364. ( gblpszUnknownReason == NULL ) ||
  1365. ( gblpszUnknown == NULL ) ||
  1366. ( gblpszPm == NULL ) ||
  1367. ( gblpszAm == NULL ) )
  1368. {
  1369. return( GetLastError() );
  1370. }
  1371. if (( !LoadString( GetModuleHandle( lpwsModuleName ), 1,
  1372. gblpszAdminRequest, MAX_XLATE_STRING ))
  1373. ||
  1374. ( !LoadString( GetModuleHandle( lpwsModuleName ), 2,
  1375. gblpszUserRequest, MAX_XLATE_STRING ))
  1376. ||
  1377. ( !LoadString( GetModuleHandle( lpwsModuleName ), 3,
  1378. gblpszHardwareFailure, MAX_XLATE_STRING ))
  1379. ||
  1380. ( !LoadString( GetModuleHandle( lpwsModuleName ), 4,
  1381. gblpszUnknownReason, MAX_XLATE_STRING ))
  1382. ||
  1383. ( !LoadString( GetModuleHandle( lpwsModuleName) , 5,
  1384. gblpszAm, MAX_XLATE_STRING ))
  1385. ||
  1386. ( !LoadString( GetModuleHandle( lpwsModuleName ), 6,
  1387. gblpszPm, MAX_XLATE_STRING ))
  1388. ||
  1389. ( !LoadString( GetModuleHandle( lpwsModuleName) , 7,
  1390. gblpszUnknown, MAX_XLATE_STRING )))
  1391. {
  1392. return( GetLastError() );
  1393. }
  1394. return( NO_ERROR );
  1395. }
  1396. //**
  1397. //
  1398. // Call: AcceptNewLink
  1399. //
  1400. // Returns: TRUE - Continue with link processing
  1401. // FALSE - Abort link processing
  1402. //
  1403. // Description:
  1404. //
  1405. BOOL
  1406. AcceptNewLink(
  1407. IN DEVICE_OBJECT * pDeviceObj,
  1408. IN CONNECTION_OBJECT * pConnObj
  1409. )
  1410. {
  1411. //
  1412. // If admin module is loaded, notify it of a new link
  1413. //
  1414. if ( gblDDMConfigInfo.lpfnRasAdminAcceptNewLink != NULL )
  1415. {
  1416. RAS_PORT_0 RasPort0;
  1417. RAS_PORT_1 RasPort1;
  1418. BOOL (*MprAdminAcceptNewLink)( RAS_PORT_0 *, RAS_PORT_1 * );
  1419. if ((GetRasPort0Data(pDeviceObj,&RasPort0) != NO_ERROR)
  1420. ||
  1421. (GetRasPort1Data(pDeviceObj,&RasPort1) != NO_ERROR))
  1422. {
  1423. DevStartClosing( pDeviceObj );
  1424. return( FALSE );
  1425. }
  1426. pDeviceObj->fFlags &= (~DEV_OBJ_NOTIFY_OF_DISCONNECTION);
  1427. MprAdminAcceptNewLink =
  1428. (BOOL (*)( RAS_PORT_0 *, RAS_PORT_1 * ))
  1429. gblDDMConfigInfo.lpfnRasAdminAcceptNewLink;
  1430. if ( !MprAdminAcceptNewLink( &RasPort0, &RasPort1 ) )
  1431. {
  1432. DevStartClosing( pDeviceObj );
  1433. return( FALSE );
  1434. }
  1435. pDeviceObj->fFlags |= DEV_OBJ_NOTIFY_OF_DISCONNECTION;
  1436. }
  1437. return( TRUE );
  1438. }
  1439. //**
  1440. //
  1441. // Call: AcceptNewConnection
  1442. //
  1443. // Returns: TRUE - Continue with connection processing
  1444. // FALSE - Abort connection processing
  1445. //
  1446. // Description:
  1447. //
  1448. BOOL
  1449. AcceptNewConnection(
  1450. IN DEVICE_OBJECT * pDeviceObj,
  1451. IN CONNECTION_OBJECT * pConnObj
  1452. )
  1453. {
  1454. //
  1455. // If admin module is loaded, notify it of a new connection
  1456. //
  1457. if ( ( gblDDMConfigInfo.lpfnRasAdminAcceptNewConnection != NULL ) ||
  1458. ( gblDDMConfigInfo.lpfnRasAdminAcceptNewConnection2 != NULL ) )
  1459. {
  1460. RAS_CONNECTION_0 RasConnection0;
  1461. RAS_CONNECTION_1 RasConnection1;
  1462. RAS_CONNECTION_2 RasConnection2;
  1463. if ((GetRasConnection0Data(pConnObj,&RasConnection0) != NO_ERROR)
  1464. ||
  1465. (GetRasConnection1Data(pConnObj,&RasConnection1) != NO_ERROR)
  1466. ||
  1467. (GetRasConnection2Data(pConnObj,&RasConnection2) != NO_ERROR))
  1468. {
  1469. ConnObjDisconnect( pConnObj );
  1470. return( FALSE );
  1471. }
  1472. //
  1473. // Let callout DLL know that we do not have a username for this user
  1474. //
  1475. if ( _wcsicmp( RasConnection0.wszUserName, gblpszUnknown ) == 0 )
  1476. {
  1477. RasConnection0.wszUserName[0] = (WCHAR)NULL;
  1478. }
  1479. pConnObj->fFlags &= (~CONN_OBJ_NOTIFY_OF_DISCONNECTION);
  1480. if ( gblDDMConfigInfo.lpfnRasAdminAcceptNewConnection2 != NULL )
  1481. {
  1482. BOOL (*MprAdminAcceptNewConnection2)(
  1483. RAS_CONNECTION_0 *,
  1484. RAS_CONNECTION_1 *,
  1485. RAS_CONNECTION_2 * );
  1486. MprAdminAcceptNewConnection2 =
  1487. (BOOL (*)(
  1488. RAS_CONNECTION_0 *,
  1489. RAS_CONNECTION_1 * ,
  1490. RAS_CONNECTION_2 * ))
  1491. gblDDMConfigInfo.lpfnRasAdminAcceptNewConnection2;
  1492. if ( !MprAdminAcceptNewConnection2( &RasConnection0,
  1493. &RasConnection1,
  1494. &RasConnection2 ) )
  1495. {
  1496. ConnObjDisconnect( pConnObj );
  1497. return( FALSE );
  1498. }
  1499. }
  1500. else
  1501. {
  1502. BOOL (*MprAdminAcceptNewConnection)(
  1503. RAS_CONNECTION_0 *,
  1504. RAS_CONNECTION_1 * );
  1505. MprAdminAcceptNewConnection =
  1506. (BOOL (*)(
  1507. RAS_CONNECTION_0 *,
  1508. RAS_CONNECTION_1 * ))
  1509. gblDDMConfigInfo.lpfnRasAdminAcceptNewConnection;
  1510. if ( !MprAdminAcceptNewConnection( &RasConnection0,
  1511. &RasConnection1 ) )
  1512. {
  1513. ConnObjDisconnect( pConnObj );
  1514. return( FALSE );
  1515. }
  1516. }
  1517. pConnObj->fFlags |= CONN_OBJ_NOTIFY_OF_DISCONNECTION;
  1518. }
  1519. return( TRUE );
  1520. }
  1521. //**
  1522. //
  1523. // Call: ConnectionHangupNotification
  1524. //
  1525. // Returns: NO_ERROR - Success
  1526. // Non-zero returns - Failure
  1527. //
  1528. // Description:
  1529. //
  1530. VOID
  1531. ConnectionHangupNotification(
  1532. IN CONNECTION_OBJECT * pConnObj
  1533. )
  1534. {
  1535. RAS_CONNECTION_0 RasConnection0;
  1536. RAS_CONNECTION_1 RasConnection1;
  1537. RAS_CONNECTION_2 RasConnection2;
  1538. if ((GetRasConnection0Data(pConnObj,&RasConnection0) == NO_ERROR) &&
  1539. (GetRasConnection1Data(pConnObj,&RasConnection1) == NO_ERROR) &&
  1540. (GetRasConnection2Data(pConnObj,&RasConnection2) == NO_ERROR))
  1541. {
  1542. if ( gblDDMConfigInfo.lpfnRasAdminConnectionHangupNotification2 != NULL)
  1543. {
  1544. VOID (*MprAdminConnectionHangupNotification2)( RAS_CONNECTION_0 *,
  1545. RAS_CONNECTION_1 *,
  1546. RAS_CONNECTION_2 * );
  1547. MprAdminConnectionHangupNotification2 =
  1548. (VOID (*)( RAS_CONNECTION_0 *,
  1549. RAS_CONNECTION_1 *,
  1550. RAS_CONNECTION_2 * ))
  1551. gblDDMConfigInfo.lpfnRasAdminConnectionHangupNotification2;
  1552. MprAdminConnectionHangupNotification2( &RasConnection0,
  1553. &RasConnection1,
  1554. &RasConnection2 );
  1555. }
  1556. else
  1557. {
  1558. VOID (*MprAdminConnectionHangupNotification)( RAS_CONNECTION_0 *,
  1559. RAS_CONNECTION_1 * );
  1560. MprAdminConnectionHangupNotification =
  1561. (VOID (*)( RAS_CONNECTION_0 *,
  1562. RAS_CONNECTION_1 * ))
  1563. gblDDMConfigInfo.lpfnRasAdminConnectionHangupNotification;
  1564. MprAdminConnectionHangupNotification( &RasConnection0,
  1565. &RasConnection1 );
  1566. }
  1567. }
  1568. }
  1569. //**
  1570. //
  1571. // Call: GetActiveTimeInSeconds
  1572. //
  1573. // Returns: NO_ERROR - Success
  1574. // Non-zero returns - Failure
  1575. //
  1576. // Description: Will return the difference, in seconds, between then time the
  1577. // current time and the time represented by the argument passed in.
  1578. //
  1579. DWORD
  1580. GetActiveTimeInSeconds(
  1581. IN ULARGE_INTEGER * pqwActiveTime
  1582. )
  1583. {
  1584. ULARGE_INTEGER qwCurrentTime;
  1585. ULARGE_INTEGER qwUpTime;
  1586. DWORD dwRemainder;
  1587. if ( pqwActiveTime->QuadPart == 0 )
  1588. {
  1589. return( 0 );
  1590. }
  1591. GetSystemTimeAsFileTime( (FILETIME*)&qwCurrentTime );
  1592. if ( pqwActiveTime->QuadPart > qwCurrentTime.QuadPart )
  1593. {
  1594. return( 0 );
  1595. }
  1596. qwUpTime.QuadPart = qwCurrentTime.QuadPart - pqwActiveTime->QuadPart;
  1597. return( RtlEnlargedUnsignedDivide(qwUpTime,(DWORD)10000000,&dwRemainder));
  1598. }
  1599. //**
  1600. //
  1601. // Call: DDMRecognizeFrame
  1602. //
  1603. // Returns: TRUE - Recognized
  1604. // FALSE - Unrecognized
  1605. //
  1606. // Description: Returns whether a received packet has a recognized format
  1607. // by the RAS server (i.e. is in the format of a data-link layer
  1608. // protocol that is supported by RAS).
  1609. //
  1610. // Up though Windows 2000, this api would return true for AMB
  1611. // or PPP packets.
  1612. //
  1613. // Now, only PPP packets are supported.
  1614. //
  1615. BOOL
  1616. DDMRecognizeFrame(
  1617. IN PVOID pvFrameBuf, // pointer to the frame
  1618. IN WORD wFrameLen, // Length in bytes of the frame
  1619. OUT DWORD *pProtocol // xport id - valid only if recognized
  1620. )
  1621. {
  1622. PBYTE pb;
  1623. WORD FrameType;
  1624. if ( wFrameLen < 16 )
  1625. {
  1626. DDMTRACE( "Initial frame length is less than 16, frame not recognized");
  1627. //ASSERT( FALSE );
  1628. return( FALSE );
  1629. }
  1630. //
  1631. // Check PPP
  1632. //
  1633. pb = ((PBYTE) pvFrameBuf) + 12;
  1634. GET_USHORT(&FrameType, pb);
  1635. switch( FrameType )
  1636. {
  1637. case PPP_LCP_PROTOCOL:
  1638. case PPP_PAP_PROTOCOL:
  1639. case PPP_CBCP_PROTOCOL:
  1640. case PPP_BACP_PROTOCOL:
  1641. case PPP_BAP_PROTOCOL:
  1642. case PPP_CHAP_PROTOCOL:
  1643. case PPP_IPCP_PROTOCOL:
  1644. case PPP_ATCP_PROTOCOL:
  1645. case PPP_IPXCP_PROTOCOL:
  1646. case PPP_CCP_PROTOCOL:
  1647. case PPP_SPAP_NEW_PROTOCOL:
  1648. case PPP_EAP_PROTOCOL:
  1649. *pProtocol = PPP_LCP_PROTOCOL;
  1650. return( TRUE );
  1651. default:
  1652. DDMTRACE1("Initial frame has unknown header %x, frame unrecognized",
  1653. FrameType );
  1654. //ASSERT( FALSE );
  1655. break;
  1656. }
  1657. return( FALSE );
  1658. }
  1659. //**
  1660. //
  1661. // Call: DDMGetIdentityAttributes
  1662. //
  1663. // Returns: NO_ERROR - Success
  1664. // Non-zero returns - Failure
  1665. //
  1666. // Description: Will gather all identity attributes and return them to
  1667. // DIM to be plumbed into the DS
  1668. //
  1669. DWORD
  1670. DDMGetIdentityAttributes(
  1671. IN OUT ROUTER_IDENTITY_ATTRIBUTE * pRouterIdAttributes
  1672. )
  1673. {
  1674. DWORD dwIndex;
  1675. //
  1676. // Get all media types used
  1677. //
  1678. DeviceObjIterator( DeviceObjGetType, FALSE, pRouterIdAttributes );
  1679. for( dwIndex = 0;
  1680. pRouterIdAttributes[dwIndex].dwVendorId != (DWORD)-1;
  1681. dwIndex++ );
  1682. //
  1683. // Find out the authentication/accounting providers
  1684. //
  1685. if ( gblDDMConfigInfo.fFlags & DDM_USING_NT_AUTHENTICATION )
  1686. {
  1687. pRouterIdAttributes[dwIndex].dwVendorId = 311;
  1688. pRouterIdAttributes[dwIndex].dwType = 6;
  1689. pRouterIdAttributes[dwIndex].dwValue = 801;
  1690. dwIndex++;
  1691. }
  1692. else if ( gblDDMConfigInfo.fFlags & DDM_USING_RADIUS_AUTHENTICATION )
  1693. {
  1694. pRouterIdAttributes[dwIndex].dwVendorId = 311;
  1695. pRouterIdAttributes[dwIndex].dwType = 6;
  1696. pRouterIdAttributes[dwIndex].dwValue = 802;
  1697. dwIndex++;
  1698. }
  1699. if ( gblDDMConfigInfo.fFlags & DDM_USING_RADIUS_ACCOUNTING )
  1700. {
  1701. pRouterIdAttributes[dwIndex].dwVendorId = 311;
  1702. pRouterIdAttributes[dwIndex].dwType = 6;
  1703. pRouterIdAttributes[dwIndex].dwValue = 803;
  1704. dwIndex++;
  1705. }
  1706. if ( gblDDMConfigInfo.fArapAllowed )
  1707. {
  1708. // AppleTalkRAS(ATCP): Vendor= MS, TypeMajor= 6, TypeMinor= 504
  1709. //
  1710. pRouterIdAttributes[dwIndex].dwVendorId = 311;
  1711. pRouterIdAttributes[dwIndex].dwType = 6;
  1712. pRouterIdAttributes[dwIndex].dwValue = 504;
  1713. dwIndex++;
  1714. }
  1715. //
  1716. // Terminate the array
  1717. //
  1718. pRouterIdAttributes[dwIndex].dwVendorId = (DWORD)-1;
  1719. pRouterIdAttributes[dwIndex].dwType = (DWORD)-1;
  1720. pRouterIdAttributes[dwIndex].dwValue = (DWORD)-1;
  1721. return( NO_ERROR );
  1722. }
  1723. //**
  1724. //
  1725. // Call: GetNextAccountingSessionId
  1726. //
  1727. // Returns: Next Accounting session Id to use
  1728. //
  1729. // Description: Called by PPP to get the next accounting session ID
  1730. // to use the next accouting request sent to the accounting
  1731. // provider.
  1732. //
  1733. DWORD
  1734. GetNextAccountingSessionId(
  1735. VOID
  1736. )
  1737. {
  1738. DWORD dwAccountingSessionId;
  1739. EnterCriticalSection( &(gblDDMConfigInfo.CSAccountingSessionId) );
  1740. dwAccountingSessionId = (gblDDMConfigInfo.dwAccountingSessionId++);
  1741. LeaveCriticalSection( &(gblDDMConfigInfo.CSAccountingSessionId) );
  1742. return( dwAccountingSessionId );
  1743. }
  1744. //**
  1745. //
  1746. // Call: LoadIpHlpApiDll
  1747. //
  1748. // Returns: NO_ERROR - Success
  1749. // Non-zero returns - Failure
  1750. //
  1751. // Description: Loads iphlpapi.dll and gets the proc addresses of
  1752. // AllocateAndGetIfTableFromStack and
  1753. // AllocateAndGetIpAddrTableFromStack. These values are stored in
  1754. // gblDDMConfigInfo. If anything fails, the variables in
  1755. // gblDDMConfigInfo remain NULL, and no cleanup is necessary.
  1756. //
  1757. DWORD
  1758. LoadIpHlpApiDll(
  1759. VOID
  1760. )
  1761. {
  1762. DWORD dwResult = NO_ERROR;
  1763. if ( gblDDMConfigInfo.hIpHlpApi != NULL )
  1764. {
  1765. RTASSERT( gblDDMConfigInfo.lpfnAllocateAndGetIfTableFromStack != NULL );
  1766. RTASSERT( gblDDMConfigInfo.lpfnAllocateAndGetIpAddrTableFromStack !=
  1767. NULL );
  1768. return ( NO_ERROR );
  1769. }
  1770. do
  1771. {
  1772. gblDDMConfigInfo.hIpHlpApi = LoadLibrary(TEXT("iphlpapi.dll"));
  1773. if ( gblDDMConfigInfo.hIpHlpApi == NULL )
  1774. {
  1775. dwResult = GetLastError();
  1776. DDM_PRINT( gblDDMConfigInfo.dwTraceId, TRACE_FSM,
  1777. "LoadLibrary(iphlpapi.dll) failed: %d", dwResult);
  1778. break;
  1779. }
  1780. gblDDMConfigInfo.lpfnAllocateAndGetIfTableFromStack =
  1781. (ALLOCATEANDGETIFTABLEFROMSTACK)
  1782. GetProcAddress( gblDDMConfigInfo.hIpHlpApi,
  1783. "AllocateAndGetIfTableFromStack" );
  1784. if ( gblDDMConfigInfo.lpfnAllocateAndGetIfTableFromStack == NULL )
  1785. {
  1786. dwResult = GetLastError();
  1787. DDM_PRINT( gblDDMConfigInfo.dwTraceId, TRACE_FSM,
  1788. "GetProcAddress( AllocateAndGetIfTableFromStack ) "
  1789. "failed: %d", dwResult);
  1790. break;
  1791. }
  1792. gblDDMConfigInfo.lpfnAllocateAndGetIpAddrTableFromStack =
  1793. (ALLOCATEANDGETIPADDRTABLEFROMSTACK)
  1794. GetProcAddress( gblDDMConfigInfo.hIpHlpApi,
  1795. "AllocateAndGetIpAddrTableFromStack" );
  1796. if ( gblDDMConfigInfo.lpfnAllocateAndGetIpAddrTableFromStack == NULL )
  1797. {
  1798. dwResult = GetLastError();
  1799. DDM_PRINT( gblDDMConfigInfo.dwTraceId, TRACE_FSM,
  1800. "GetProcAddress( AllocateAndGetIpAddrTableFromStack ) "
  1801. "failed: %d", dwResult);
  1802. break;
  1803. }
  1804. }
  1805. while ( FALSE );
  1806. if ( dwResult != NO_ERROR )
  1807. {
  1808. gblDDMConfigInfo.lpfnAllocateAndGetIfTableFromStack = NULL;
  1809. gblDDMConfigInfo.lpfnAllocateAndGetIpAddrTableFromStack = NULL;
  1810. if ( gblDDMConfigInfo.hIpHlpApi != NULL )
  1811. {
  1812. FreeLibrary( gblDDMConfigInfo.hIpHlpApi );
  1813. gblDDMConfigInfo.hIpHlpApi = NULL;
  1814. }
  1815. }
  1816. return( dwResult );
  1817. }
  1818. //**
  1819. //
  1820. // Call: LogUnreachabilityEvent
  1821. //
  1822. // Returns: NO_ERROR - Success
  1823. // Non-zero returns - Failure
  1824. //
  1825. // Description:
  1826. //
  1827. VOID
  1828. LogUnreachabilityEvent(
  1829. IN DWORD dwReason,
  1830. IN LPWSTR lpwsInterfaceName
  1831. )
  1832. {
  1833. DWORD dwEventLogId = 0;
  1834. switch( dwReason )
  1835. {
  1836. case INTERFACE_OUT_OF_RESOURCES:
  1837. dwEventLogId = ROUTERLOG_IF_UNREACHABLE_REASON1;
  1838. break;
  1839. case INTERFACE_CONNECTION_FAILURE:
  1840. dwEventLogId = ROUTERLOG_IF_UNREACHABLE_REASON2;
  1841. break;
  1842. case INTERFACE_DISABLED:
  1843. dwEventLogId = ROUTERLOG_IF_UNREACHABLE_REASON3;
  1844. break;
  1845. case INTERFACE_SERVICE_IS_PAUSED:
  1846. dwEventLogId = ROUTERLOG_IF_UNREACHABLE_REASON4;
  1847. break;
  1848. case INTERFACE_DIALOUT_HOURS_RESTRICTION:
  1849. dwEventLogId = ROUTERLOG_IF_UNREACHABLE_REASON5;
  1850. break;
  1851. case INTERFACE_NO_MEDIA_SENSE:
  1852. dwEventLogId = ROUTERLOG_IF_UNREACHABLE_REASON6;
  1853. break;
  1854. case INTERFACE_NO_DEVICE:
  1855. dwEventLogId = ROUTERLOG_IF_UNREACHABLE_REASON7;
  1856. break;
  1857. default:
  1858. dwEventLogId = 0;
  1859. break;
  1860. }
  1861. if ( dwEventLogId != 0 )
  1862. {
  1863. DDMLogInformation( dwEventLogId, 1, &lpwsInterfaceName );
  1864. }
  1865. }
  1866. //**
  1867. //
  1868. // Call: GetLocalNASIpAddress
  1869. //
  1870. // Returns: IP address of Local Machine - Success
  1871. // 0 - Failure
  1872. //
  1873. // Description: Will get the IP address of this NAS to be sent to the back-end
  1874. // authentication module, if IP is installed on the local machine,
  1875. // otherwise it will
  1876. //
  1877. DWORD
  1878. GetLocalNASIpAddress(
  1879. VOID
  1880. )
  1881. {
  1882. DWORD dwResult, i, j, dwSize;
  1883. DWORD dwIpAddress;
  1884. PMIB_IFTABLE pIfTable;
  1885. PMIB_IPADDRTABLE pIpAddrTable;
  1886. dwResult = LoadIpHlpApiDll();
  1887. if ( dwResult != NO_ERROR )
  1888. {
  1889. return( 0 );
  1890. }
  1891. dwSize = 0;
  1892. dwResult = gblDDMConfigInfo.lpfnAllocateAndGetIfTableFromStack(
  1893. &pIfTable,
  1894. FALSE,
  1895. GetProcessHeap(),
  1896. HEAP_ZERO_MEMORY,
  1897. TRUE);
  1898. if ( dwResult != NO_ERROR )
  1899. {
  1900. return( 0 );
  1901. }
  1902. if( pIfTable->dwNumEntries == 0 )
  1903. {
  1904. LocalFree( pIfTable );
  1905. return( 0 );
  1906. }
  1907. //
  1908. // Ok so now we have the IF Table, get the corresponding IP Address table
  1909. //
  1910. dwResult = gblDDMConfigInfo.lpfnAllocateAndGetIpAddrTableFromStack(
  1911. &pIpAddrTable,
  1912. FALSE,
  1913. GetProcessHeap(),
  1914. HEAP_ZERO_MEMORY);
  1915. if ( dwResult != NO_ERROR )
  1916. {
  1917. LocalFree( pIfTable );
  1918. return( 0 );
  1919. }
  1920. if ( pIpAddrTable->dwNumEntries == 0 )
  1921. {
  1922. LocalFree( pIfTable );
  1923. LocalFree( pIpAddrTable );
  1924. return( 0 );
  1925. }
  1926. for ( i = 0; i < pIfTable->dwNumEntries; i++ )
  1927. {
  1928. //
  1929. // Go through the interface trying to find a good one
  1930. //
  1931. if((pIfTable->table[i].dwType == MIB_IF_TYPE_PPP) ||
  1932. (pIfTable->table[i].dwType == MIB_IF_TYPE_SLIP) ||
  1933. (pIfTable->table[i].dwType == MIB_IF_TYPE_LOOPBACK))
  1934. {
  1935. //
  1936. // Dont want any of these
  1937. //
  1938. continue;
  1939. }
  1940. for ( j = 0; j < pIpAddrTable->dwNumEntries; j++ )
  1941. {
  1942. if( pIpAddrTable->table[j].dwIndex == pIfTable->table[i].dwIndex )
  1943. {
  1944. if( pIpAddrTable->table[j].dwAddr == 0x00000000 )
  1945. {
  1946. //
  1947. // An invalid address
  1948. //
  1949. continue;
  1950. }
  1951. LocalFree( pIfTable );
  1952. dwIpAddress = WireToHostFormat32(
  1953. (CHAR*)&(pIpAddrTable->table[j].dwAddr));
  1954. LocalFree( pIpAddrTable );
  1955. return( dwIpAddress );
  1956. }
  1957. }
  1958. }
  1959. LocalFree( pIfTable );
  1960. LocalFree( pIpAddrTable );
  1961. return( 0 );
  1962. }
  1963. DWORD
  1964. ModifyDefPolicyToForceEncryption(
  1965. IN BOOL bStrong)
  1966. {
  1967. HANDLE hServer = NULL;
  1968. DWORD dwErr = NO_ERROR, dwType, dwSize, dwFlags = 0;
  1969. HKEY hkFlags = NULL;
  1970. do
  1971. {
  1972. dwErr = MprAdminUserServerConnect(NULL, TRUE, &hServer);
  1973. if (dwErr != NO_ERROR)
  1974. {
  1975. break;
  1976. }
  1977. dwErr = MprAdminUserWriteProfFlags(
  1978. hServer,
  1979. (bStrong) ? MPR_USER_PROF_FLAG_FORCE_STRONG_ENCRYPTION
  1980. : MPR_USER_PROF_FLAG_FORCE_ENCRYPTION);
  1981. // DISP_E_MEMBERNOTFOUND returned from MprAdminUserWriteProfFlags means that
  1982. // there is no default policy either because there are no policies or because
  1983. // there are more than one.
  1984. //
  1985. // If there is no default policy, then we should continue on this function
  1986. // to clear the bits.
  1987. //
  1988. if ((dwErr != DISP_E_MEMBERNOTFOUND) && (dwErr != NO_ERROR))
  1989. {
  1990. break;
  1991. }
  1992. dwErr = RegOpenKeyExW(
  1993. HKEY_LOCAL_MACHINE,
  1994. L"SYSTEM\\CurrentControlSet\\Services\\RemoteAccess\\Parameters",
  1995. 0,
  1996. KEY_READ | KEY_WRITE,
  1997. &hkFlags);
  1998. if (dwErr != ERROR_SUCCESS)
  1999. {
  2000. break;
  2001. }
  2002. dwType = REG_DWORD;
  2003. dwSize = sizeof(DWORD);
  2004. dwErr = RegQueryValueExW(
  2005. hkFlags,
  2006. L"ServerFlags",
  2007. NULL,
  2008. &dwType,
  2009. (LPBYTE)&dwFlags,
  2010. &dwSize);
  2011. if (dwErr != ERROR_SUCCESS)
  2012. {
  2013. break;
  2014. }
  2015. dwFlags &= ~PPPCFG_RequireEncryption;
  2016. dwFlags &= ~PPPCFG_RequireStrongEncryption;
  2017. dwErr = RegSetValueExW(
  2018. hkFlags,
  2019. L"ServerFlags",
  2020. 0,
  2021. dwType,
  2022. (CONST BYTE*)&dwFlags,
  2023. dwSize);
  2024. if (dwErr != ERROR_SUCCESS)
  2025. {
  2026. break;
  2027. }
  2028. } while (FALSE);
  2029. // Cleanup
  2030. {
  2031. if (hServer)
  2032. {
  2033. MprAdminUserServerDisconnect(hServer);
  2034. }
  2035. if (hkFlags)
  2036. {
  2037. RegCloseKey(hkFlags);
  2038. }
  2039. }
  2040. return dwErr;
  2041. }
  2042. DWORD
  2043. MungePhoneNumber(
  2044. char *cbphno,
  2045. DWORD dwIndex,
  2046. DWORD *pdwSizeofMungedPhNo,
  2047. char **ppszMungedPhNo
  2048. )
  2049. {
  2050. DWORD dwErr = ERROR_SUCCESS;
  2051. BOOL fDigital = FALSE;
  2052. WCHAR *pwszAddress;
  2053. char *pszMungedPhNo;
  2054. DWORD dwSizeofMungedPhNo;
  2055. *ppszMungedPhNo = cbphno;
  2056. *pdwSizeofMungedPhNo = strlen(cbphno);
  2057. do
  2058. {
  2059. if( (NULL == cbphno)
  2060. || ('\0' == cbphno[0])
  2061. || ('\0' == cbphno[1]))
  2062. {
  2063. break;
  2064. }
  2065. //
  2066. // find out if the cbphno is digital or analog
  2067. //
  2068. if( ( ('D' == cbphno[0])
  2069. || ('d' == cbphno[0]))
  2070. && (':' == cbphno[1]))
  2071. {
  2072. fDigital = TRUE;
  2073. }
  2074. if(fDigital)
  2075. {
  2076. if(0 == gblDDMConfigInfo.cDigitalIPAddresses)
  2077. {
  2078. break;
  2079. }
  2080. dwIndex = (dwIndex % gblDDMConfigInfo.cDigitalIPAddresses);
  2081. pwszAddress = gblDDMConfigInfo.apDigitalIPAddresses[dwIndex];
  2082. }
  2083. else
  2084. {
  2085. if(0 == gblDDMConfigInfo.cAnalogIPAddresses)
  2086. {
  2087. break;
  2088. }
  2089. dwIndex = (dwIndex % gblDDMConfigInfo.cAnalogIPAddresses);
  2090. pwszAddress = gblDDMConfigInfo.apAnalogIPAddresses[dwIndex];
  2091. }
  2092. dwSizeofMungedPhNo = strlen(cbphno)
  2093. + wcslen(pwszAddress)
  2094. + 2; // +2 is for a space and terminating NULL;
  2095. pszMungedPhNo = LocalAlloc(
  2096. LPTR,
  2097. dwSizeofMungedPhNo);
  2098. if(NULL == pszMungedPhNo)
  2099. {
  2100. dwErr = GetLastError();
  2101. break;
  2102. }
  2103. sprintf(pszMungedPhNo, "%ws %s", pwszAddress, cbphno);
  2104. *ppszMungedPhNo = pszMungedPhNo;
  2105. *pdwSizeofMungedPhNo = dwSizeofMungedPhNo;
  2106. } while (FALSE);
  2107. return dwErr;
  2108. }
  2109. WCHAR *
  2110. GetIpAddress(DWORD dwIpAddress)
  2111. {
  2112. struct in_addr ipaddr;
  2113. CHAR *pszaddr;
  2114. WCHAR *pwszaddr = NULL;
  2115. ipaddr.s_addr = dwIpAddress;
  2116. pszaddr = inet_ntoa(ipaddr);
  2117. if(NULL != pszaddr)
  2118. {
  2119. DWORD cb;
  2120. cb = MultiByteToWideChar(
  2121. CP_ACP, 0, pszaddr, -1, NULL, 0);
  2122. pwszaddr = LocalAlloc(LPTR, cb * sizeof(WCHAR));
  2123. if (pwszaddr == NULL)
  2124. {
  2125. return NULL;
  2126. }
  2127. cb = MultiByteToWideChar(
  2128. CP_ACP, 0, pszaddr, -1, pwszaddr, cb);
  2129. if (!cb)
  2130. {
  2131. LocalFree(pwszaddr);
  2132. return NULL;
  2133. }
  2134. }
  2135. return pwszaddr;
  2136. }
  2137. #ifdef MEM_LEAK_CHECK
  2138. //**
  2139. //
  2140. // Call: DebugAlloc
  2141. //
  2142. // Returns: return from HeapAlloc
  2143. //
  2144. // Description: Will use the memory table to store the pointer returned by
  2145. // LocalAlloc
  2146. //
  2147. LPVOID
  2148. DebugAlloc(
  2149. IN DWORD Flags,
  2150. IN DWORD dwSize
  2151. )
  2152. {
  2153. DWORD Index;
  2154. LPBYTE pMem = (LPBYTE)HeapAlloc( gblDDMConfigInfo.hHeap,
  2155. HEAP_ZERO_MEMORY,dwSize+8);
  2156. if ( pMem == NULL )
  2157. return( pMem );
  2158. for( Index=0; Index < DDM_MEM_TABLE_SIZE; Index++ )
  2159. {
  2160. if ( DdmMemTable[Index] == NULL )
  2161. {
  2162. DdmMemTable[Index] = pMem;
  2163. break;
  2164. }
  2165. }
  2166. *((LPDWORD)pMem) = dwSize;
  2167. pMem += 4;
  2168. //
  2169. // Our signature
  2170. //
  2171. *(pMem+dwSize) = 0x0F;
  2172. *(pMem+dwSize+1) = 0x0E;
  2173. *(pMem+dwSize+2) = 0x0A;
  2174. *(pMem+dwSize+3) = 0x0B;
  2175. RTASSERT( Index != DDM_MEM_TABLE_SIZE );
  2176. return( (LPVOID)pMem );
  2177. }
  2178. //**
  2179. //
  2180. // Call: DebugFree
  2181. //
  2182. // Returns: return from HeapFree
  2183. //
  2184. // Description: Will remove the pointer from the memory table before freeing
  2185. // the memory block
  2186. //
  2187. BOOL
  2188. DebugFree(
  2189. IN LPVOID pMem
  2190. )
  2191. {
  2192. DWORD Index;
  2193. pMem = ((LPBYTE)pMem) - 4;
  2194. for( Index=0; Index < DDM_MEM_TABLE_SIZE; Index++ )
  2195. {
  2196. if ( DdmMemTable[Index] == pMem )
  2197. {
  2198. DdmMemTable[Index] = NULL;
  2199. break;
  2200. }
  2201. }
  2202. RTASSERT( Index != DDM_MEM_TABLE_SIZE );
  2203. return( HeapFree( gblDDMConfigInfo.hHeap, 0, pMem ) );
  2204. }
  2205. //**
  2206. //
  2207. // Call: DebugReAlloc
  2208. //
  2209. // Returns: return from HeapReAlloc
  2210. //
  2211. // Description: Will change the value of the realloced pointer.
  2212. //
  2213. LPVOID
  2214. DebugReAlloc( PVOID pMem, DWORD dwSize )
  2215. {
  2216. DWORD Index;
  2217. if ( pMem == NULL )
  2218. {
  2219. RTASSERT(FALSE);
  2220. }
  2221. for( Index=0; Index < DDM_MEM_TABLE_SIZE; Index++ )
  2222. {
  2223. if ( DdmMemTable[Index] == pMem )
  2224. {
  2225. DdmMemTable[Index] = HeapReAlloc( gblDDMConfigInfo.hHeap,
  2226. HEAP_ZERO_MEMORY,
  2227. pMem, dwSize+8 );
  2228. pMem = DdmMemTable[Index];
  2229. *((LPDWORD)pMem) = dwSize;
  2230. ((LPBYTE)pMem) += 4;
  2231. //
  2232. // Our signature
  2233. //
  2234. *(((LPBYTE)pMem)+dwSize) = 0x0F;
  2235. *(((LPBYTE)pMem)+dwSize+1) = 0x0E;
  2236. *(((LPBYTE)pMem)+dwSize+2) = 0x0A;
  2237. *(((LPBYTE)pMem)+dwSize+3) = 0x0B;
  2238. break;
  2239. }
  2240. }
  2241. RTASSERT( Index != DDM_MEM_TABLE_SIZE );
  2242. return( (LPVOID)pMem );
  2243. }
  2244. #endif