Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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