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.

6340 lines
162 KiB

  1. ////////////////////////////////////////////////////////////////////////
  2. //
  3. // Module : Dynamic/DyanamicShow.cpp
  4. //
  5. // Purpose : Dynamic Show commands Implementation.
  6. //
  7. //
  8. // Developers Name : Bharat/Radhika
  9. //
  10. // History :
  11. //
  12. // Date Author Comments
  13. // 9-23-2001 Bharat Initial Version. V1.0
  14. // 11-21-2001 Bharat Version. V1.1
  15. //
  16. ////////////////////////////////////////////////////////////////////////
  17. #include "nshipsec.h"
  18. #include "staticshowutils.h"
  19. extern HINSTANCE g_hModule;
  20. extern HKEY g_hGlobalRegistryKey;
  21. extern _TCHAR* g_szDynamicMachine;
  22. extern STORAGELOCATION g_StorageLocation;
  23. UINT QMPFSDHGroup(DWORD dwPFSGroup);
  24. ///////////////////////////////////////////////////////////////////////////////////////////
  25. //
  26. // Function : ShowMMPolicy
  27. //
  28. // Date of Creation: 9-3-2001
  29. //
  30. // Parameters : IN LPTSTR pszShowPolicyName
  31. //
  32. // Return : DWORD
  33. //
  34. // Description : This function prepares data to display Mainmode Policies.
  35. //
  36. // History :
  37. //
  38. // Date Author Comments
  39. //
  40. //////////////////////////////////////////////////////////////////////////////////////////
  41. DWORD
  42. ShowMMPolicy(
  43. IN LPTSTR pszShowPolicyName
  44. )
  45. {
  46. DWORD dwCount = 0; // counting objects here
  47. DWORD dwResumeHandle = 0; // handle for continuation calls
  48. DWORD i=0, j=0;
  49. DWORD dwReturn = ERROR_SUCCESS; // assume success
  50. DWORD dwVersion = 0;
  51. BOOL bNameFin = FALSE;
  52. PIPSEC_MM_POLICY pIPSecMMP = NULL; // for MM policy calls
  53. for(i = 0; ;i+=dwCount)
  54. {
  55. dwReturn = EnumMMPolicies(g_szDynamicMachine, dwVersion, NULL, 0, 0, &pIPSecMMP, &dwCount, &dwResumeHandle, NULL);
  56. //If there is no data Bail out.
  57. if (dwReturn == ERROR_NO_DATA || dwCount == 0)
  58. {
  59. if (i == 0)
  60. {
  61. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_NEWLINE);
  62. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_SHOW_MMP_6);
  63. //This is to avoid one more error message show up!!
  64. bNameFin = TRUE;
  65. }
  66. dwReturn = ERROR_SUCCESS;
  67. BAIL_OUT;
  68. }
  69. if (dwReturn != ERROR_SUCCESS)
  70. {
  71. BAIL_OUT;
  72. }
  73. if(!(pIPSecMMP && dwCount > 0))
  74. {
  75. // not required to continue.
  76. BAIL_OUT;
  77. }
  78. // Show all the main mode policies
  79. if(!pszShowPolicyName)
  80. {
  81. for (j = 0; j < dwCount; j++)
  82. {
  83. PrintMMPolicy(pIPSecMMP[j]);
  84. }
  85. }
  86. // Show main mode policy for the given policy name.
  87. else if(pszShowPolicyName)
  88. {
  89. for (j = 0; j < dwCount; j++)
  90. {
  91. if(_tcsicmp(pIPSecMMP[j].pszPolicyName,pszShowPolicyName) == 0)
  92. {
  93. PrintMMPolicy(pIPSecMMP[j]);
  94. bNameFin = TRUE;
  95. BAIL_OUT;
  96. }
  97. }
  98. }
  99. SPDApiBufferFree(pIPSecMMP);
  100. pIPSecMMP=NULL;
  101. }
  102. error:
  103. if(pszShowPolicyName && !bNameFin)
  104. {
  105. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_NEWLINE);
  106. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_SHOW_MMP_5);
  107. dwReturn = ERROR_SUCCESS;
  108. }
  109. if(pIPSecMMP)
  110. {
  111. //error path clean up
  112. SPDApiBufferFree(pIPSecMMP);
  113. pIPSecMMP=NULL;
  114. }
  115. return dwReturn;
  116. }
  117. ///////////////////////////////////////////////////////////////////////////////////////////
  118. //
  119. // Function : PrintMMPolicy
  120. //
  121. // Date of Creation: 9-3-2001
  122. //
  123. // Parameters : IN IPSEC_MM_POLICY MMPolicy
  124. //
  125. // Return : DWORD
  126. //
  127. // Description : This function displays headings and policy name for Mainmode Policy.
  128. //
  129. // History :
  130. //
  131. // Date Author Comments
  132. //
  133. //////////////////////////////////////////////////////////////////////////////////////////
  134. VOID
  135. PrintMMPolicy(
  136. IN IPSEC_MM_POLICY MMPolicy
  137. )
  138. {
  139. DWORD i = 0;
  140. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_NEWLINE);
  141. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_POLNAME, MMPolicy.pszPolicyName );
  142. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_SOFTSA, MMPolicy.uSoftExpirationTime);
  143. if(MMPolicy.dwOfferCount>0) //offers are greater than 0, print the header for it
  144. {
  145. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_NEWLINE);
  146. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMP_COLUMN_HEADING);
  147. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMP_COLUMN_HEADING_UNDERLINE);
  148. }
  149. for (i = 0; i < MMPolicy.dwOfferCount; i++)
  150. {
  151. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_NEWLINE);
  152. PrintMMOffer(MMPolicy.pOffers[i]);
  153. }
  154. }
  155. ///////////////////////////////////////////////////////////////////////////////////////////
  156. //
  157. //Function: PrintMMOffer
  158. //
  159. //Date of Creation: 9-3-2001
  160. //
  161. //Parameters: IN IPSEC_MM_OFFER MMOffer
  162. //
  163. //Return: VOID
  164. //
  165. //Description: This function displays offer details for each Mainmode Policy.
  166. //
  167. // History :
  168. //
  169. // Date Author Comments
  170. //
  171. //////////////////////////////////////////////////////////////////////////////////////////
  172. VOID
  173. PrintMMOffer(
  174. IN IPSEC_MM_OFFER MMOffer
  175. )
  176. {
  177. //This is to display DH2048 as 3
  178. if(MMOffer.dwDHGroup == DH_GROUP_2048)
  179. {
  180. MMOffer.dwDHGroup = 2048;
  181. }
  182. //Display of Encryption algorithm
  183. switch(MMOffer.EncryptionAlgorithm.uAlgoIdentifier)
  184. {
  185. case 1:
  186. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMP_ESP_DES_ALGO);
  187. break;
  188. case 2:
  189. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMP_ESP_UNKNOWN_ALGO);
  190. break;
  191. case 3:
  192. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMP_ESP_3DES_ALGO);
  193. break;
  194. case 0:
  195. default:
  196. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMP_ESP_NONE_ALGO);
  197. break;
  198. }
  199. //Display of Hash algorithm
  200. switch(MMOffer.HashingAlgorithm.uAlgoIdentifier)
  201. {
  202. case 1:
  203. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMP_AH_MD5_ALGO);
  204. break;
  205. case 2:
  206. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMP_AH_SHA1_ALGO);
  207. break;
  208. case 0:
  209. default:
  210. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMP_AH_NONE_ALGO);
  211. break;
  212. }
  213. //IF QMPERMM is 1 then 1 (MMPFS) is displayed.
  214. if(MMOffer.dwQuickModeLimit != 1)
  215. {
  216. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMP_DH_LIFE_QMLIMIT,MMOffer.dwDHGroup, MMOffer.Lifetime.uKeyExpirationKBytes, MMOffer.Lifetime.uKeyExpirationTime, MMOffer.dwQuickModeLimit );
  217. }
  218. else
  219. {
  220. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMP_DH_LIFE_QMLIMIT_MMPFS,MMOffer.dwDHGroup, MMOffer.Lifetime.uKeyExpirationKBytes, MMOffer.Lifetime.uKeyExpirationTime);
  221. }
  222. }
  223. ///////////////////////////////////////////////////////////////////////////////////////////
  224. //
  225. //Function: ShowQMPolicy
  226. //
  227. //Date of Creation: 9-3-2001
  228. //
  229. //Parameters: IN LPTSTR pszShowPolicyName
  230. //
  231. //Return: DWORD
  232. //
  233. //Description: This function prepares data to display quickmode Policy.
  234. //
  235. // History :
  236. //
  237. // Date Author Comments
  238. //
  239. //////////////////////////////////////////////////////////////////////////////////////////
  240. DWORD
  241. ShowQMPolicy(
  242. IN LPTSTR pszShowPolicyName
  243. )
  244. {
  245. DWORD dwCount = 0; // counting objects here
  246. DWORD dwResumeHandle = 0; // handle for continuation calls
  247. DWORD i=0, j=0;
  248. DWORD dwReturn = ERROR_SUCCESS; // assume success
  249. DWORD dwVersion = 0;
  250. BOOL bNameFin = FALSE;
  251. PIPSEC_QM_POLICY pIPSecQMP = NULL; // for QM policy calls
  252. for (i = 0; ;i+=dwCount)
  253. {
  254. dwReturn = EnumQMPolicies(g_szDynamicMachine, dwVersion, NULL, 0, 0, &pIPSecQMP, &dwCount, &dwResumeHandle, NULL);
  255. //If there is no data Bail out.
  256. if (dwReturn == ERROR_NO_DATA || dwCount == 0)
  257. {
  258. if (i == 0)
  259. {
  260. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_NEWLINE);
  261. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_SHOW_QMP_6);
  262. //This is to avoid one more error message show up!!
  263. bNameFin = TRUE;
  264. }
  265. dwReturn = ERROR_SUCCESS;
  266. BAIL_OUT;
  267. }
  268. if (dwReturn != ERROR_SUCCESS)
  269. {
  270. BAIL_OUT;
  271. }
  272. if(!(pIPSecQMP && dwCount > 0))
  273. {
  274. BAIL_OUT; // not required to continue.
  275. }
  276. //Show all QMPolicies
  277. if(!pszShowPolicyName)
  278. {
  279. for (j = 0; j < dwCount; j++)
  280. {
  281. PrintFilterAction(pIPSecQMP[j]);
  282. }
  283. }
  284. //Show QMPolicy for the given name
  285. else if(pszShowPolicyName)
  286. {
  287. for (j = 0; j < dwCount; j++)
  288. {
  289. if(_tcsicmp(pIPSecQMP[j].pszPolicyName,pszShowPolicyName) == 0)
  290. {
  291. PrintFilterAction(pIPSecQMP[j]);
  292. bNameFin = TRUE;
  293. BAIL_OUT;
  294. }
  295. }
  296. }
  297. SPDApiBufferFree(pIPSecQMP);
  298. pIPSecQMP=NULL;
  299. }
  300. error:
  301. if(pszShowPolicyName && !bNameFin)
  302. {
  303. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_NEWLINE);
  304. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_SHOW_QMP_5);
  305. dwReturn = ERROR_SUCCESS;
  306. }
  307. if(pIPSecQMP)
  308. {
  309. //error path cleanup
  310. SPDApiBufferFree(pIPSecQMP);
  311. pIPSecQMP=NULL;
  312. }
  313. return dwReturn;
  314. }
  315. ///////////////////////////////////////////////////////////////////////////////////////////
  316. //
  317. //Function: PrintFilterAction
  318. //
  319. //Date of Creation: 9-3-2001
  320. //
  321. //Parameters: IN IPSEC_QM_POLICY QMPolicy
  322. //
  323. //Return: VOID
  324. //
  325. //Description: This function displays quickmode Policy name and headers.
  326. //
  327. // History :
  328. //
  329. // Date Author Comments
  330. //
  331. //////////////////////////////////////////////////////////////////////////////////////////
  332. VOID
  333. PrintFilterAction(
  334. IN IPSEC_QM_POLICY QMPolicy
  335. )
  336. {
  337. DWORD i = 0;
  338. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_NEWLINE);
  339. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_NEGOTIATION_NAME, QMPolicy.pszPolicyName);
  340. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_NEWLINE);
  341. if(QMPolicy.dwOfferCount>0)
  342. {
  343. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_COLUMN_HEADING);
  344. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_COLUMN_HEADING_UNDERLINE);
  345. }
  346. for (i = 0; i < QMPolicy.dwOfferCount; i++)
  347. {
  348. PrintQMOffer(QMPolicy.pOffers[i]);
  349. }
  350. }
  351. ///////////////////////////////////////////////////////////////////////////////////////////
  352. //
  353. //Function: PrintQMOffer
  354. //
  355. //Date of Creation: 9-3-2001
  356. //
  357. //Parameters: IN IPSEC_QM_OFFER QMOffer
  358. //
  359. //Return: VOID
  360. //
  361. //Description: This function displays quickmode Policy offers.
  362. //
  363. // History :
  364. //
  365. // Date Author Comments
  366. //
  367. //////////////////////////////////////////////////////////////////////////////////////////
  368. VOID
  369. PrintQMOffer(
  370. IN IPSEC_QM_OFFER QMOffer
  371. )
  372. {
  373. DWORD i=0;
  374. DWORD dwFlag = 0;
  375. if(QMOffer.dwNumAlgos > 0)
  376. {
  377. for (i = 0; i < QMOffer.dwNumAlgos; i++)
  378. {
  379. //If the number algos is exactly one (either Authentication or encryption)
  380. //print the Pfs group and lifetime after the algo is printed
  381. if(QMOffer.dwNumAlgos == 1)
  382. dwFlag = 2;
  383. // '+' is required to be printed if both encryption and
  384. // authentication algo are present in an offer
  385. if(dwFlag == 1 )
  386. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_PLUS);
  387. if(QMOffer.Algos[i].Operation == AUTHENTICATION)
  388. {
  389. switch(QMOffer.Algos[i].uAlgoIdentifier)
  390. {
  391. case 1:
  392. if(QMOffer.dwNumAlgos == 1)
  393. {
  394. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_AH_MD5_ALGO);
  395. }
  396. else if(QMOffer.dwNumAlgos == 2)
  397. {
  398. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_AH_MD5);
  399. //Increment the flag for printing lifetime and pfs group
  400. dwFlag++;
  401. }
  402. break;
  403. case 2:
  404. if(QMOffer.dwNumAlgos == 1)
  405. {
  406. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_AH_SHA1_ALGO);
  407. }
  408. else if(QMOffer.dwNumAlgos == 2)
  409. {
  410. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_AH_SHA1);
  411. dwFlag++;
  412. }
  413. break;
  414. case 0:
  415. if(QMOffer.dwNumAlgos == 1)
  416. {
  417. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_AH_NONE_ALGO);
  418. }
  419. else if(QMOffer.dwNumAlgos == 2)
  420. {
  421. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_AH_NONE);
  422. dwFlag++;
  423. }
  424. break;
  425. default:
  426. if(QMOffer.dwNumAlgos == 1)
  427. {
  428. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_AH_ERR_SPACE);
  429. }
  430. else if(QMOffer.dwNumAlgos == 2)
  431. {
  432. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_AH_ERR);
  433. dwFlag++;
  434. }
  435. break;
  436. }
  437. }
  438. else if(QMOffer.Algos[i].Operation == ENCRYPTION)
  439. {
  440. switch(QMOffer.Algos[i].uAlgoIdentifier)
  441. {
  442. case 1:
  443. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_ESP_DES_ALGO);
  444. break;
  445. case 2:
  446. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_ESP_ERR_ALGO);
  447. break;
  448. case 3:
  449. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_ESP_3DES_ALGO);
  450. break;
  451. case 0:
  452. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_ESP_NONE_ALGO);
  453. break;
  454. default:
  455. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_ESP_ERR_ALGO);
  456. break;
  457. }
  458. switch(QMOffer.Algos[i].uSecAlgoIdentifier)
  459. {
  460. case 1:
  461. if(QMOffer.dwNumAlgos == 1)
  462. {
  463. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_MD5_ALGO);
  464. }
  465. else if(QMOffer.dwNumAlgos == 2)
  466. {
  467. //Increment the flag for printing lifetime and pfs group
  468. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_MD5);
  469. dwFlag++;
  470. }
  471. break;
  472. case 2:
  473. if(QMOffer.dwNumAlgos == 1)
  474. {
  475. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_SHA1_ALGO);
  476. }
  477. else if(QMOffer.dwNumAlgos == 2)
  478. {
  479. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_SHA1);
  480. dwFlag++;
  481. }
  482. break;
  483. case 0:
  484. if(QMOffer.dwNumAlgos == 1)
  485. {
  486. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_NONE_ALGO);
  487. }
  488. else if(QMOffer.dwNumAlgos == 2)
  489. {
  490. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_NONE);
  491. dwFlag++;
  492. }
  493. break;
  494. default:
  495. if(QMOffer.dwNumAlgos == 1)
  496. {
  497. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_ERR_SPACE);
  498. }
  499. else if(QMOffer.dwNumAlgos == 2)
  500. {
  501. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_ERR);
  502. dwFlag++;
  503. }
  504. break;
  505. }
  506. }
  507. else
  508. {
  509. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_ERROR_ALGO);
  510. }
  511. //Print lifetime and pfsgroup only if all the 2 algos are printed with a plus sign
  512. // or printed only if one algo is present in the qmoffer.
  513. if(dwFlag == 2)
  514. {
  515. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_LIFETIME, QMOffer.Lifetime.uKeyExpirationKBytes, QMOffer.Lifetime.uKeyExpirationTime);
  516. if(QMOffer.bPFSRequired)
  517. {
  518. PrintMessageFromModule(g_hModule, QMPFSDHGroup(QMOffer.dwPFSGroup));
  519. }
  520. else
  521. {
  522. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_PFS_NONE);
  523. }
  524. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_NEWLINE);
  525. }
  526. }
  527. }
  528. }
  529. ///////////////////////////////////////////////////////////////////////////////////////////
  530. //
  531. //Function: ShowMMFilters
  532. //
  533. //Date of Creation: 9-3-2001
  534. //
  535. //Parameters: IN LPTSTR pszShowFilterName,
  536. // IN LPTSTR pszShowPolicyName
  537. //
  538. //Return: DWORD
  539. //
  540. //Description: This function displays both generic and specific mainmode filters.
  541. //
  542. // History :
  543. //
  544. // Date Author Comments
  545. //
  546. //////////////////////////////////////////////////////////////////////////////////////////
  547. DWORD
  548. ShowMMFilters(
  549. IN LPTSTR pszShowFilterName,
  550. IN BOOL bType,
  551. IN ADDR SrcAddr,
  552. IN ADDR DstAddr,
  553. IN NshHashTable& addressHash,
  554. IN BOOL bResolveDNS,
  555. IN BOOL bSrcMask,
  556. IN BOOL bDstMask
  557. )
  558. {
  559. DWORD dwReturn = ERROR_SUCCESS;
  560. DWORD dwResumeHandle = 0;
  561. DWORD dwSpecificResumeHandle = 0; // handle for continuation calls
  562. DWORD dwCount = 0; // counting objects here
  563. DWORD dwSpecificCount = 0; // counting objects here
  564. DWORD dwVersion = 0;
  565. GUID gDefaultGUID = {0}; // NULL GUID value
  566. DWORD i=0, j=0, l=0;
  567. DWORD dwTempCnt = 0;
  568. BOOL bNameFin=FALSE;
  569. BOOL bPrint = FALSE;
  570. BOOL bPrintIN = FALSE;
  571. PIPSEC_MM_POLICY pMMPolicy = NULL;
  572. PMM_FILTER pMMFilter = NULL;
  573. PMM_FILTER pSpecificMMFilter = NULL;
  574. //Print generic filters
  575. if(bType)
  576. {
  577. for (i = 0; ;i+=dwCount)
  578. {
  579. dwReturn = EnumMMFilters(g_szDynamicMachine, dwVersion, NULL, ENUM_GENERIC_FILTERS, gDefaultGUID, 0, &pMMFilter, &dwCount, &dwResumeHandle, NULL);
  580. if (dwReturn == ERROR_NO_DATA || dwCount == 0)
  581. {
  582. dwReturn = ERROR_SUCCESS;
  583. break;
  584. }
  585. if (dwReturn != ERROR_SUCCESS)
  586. {
  587. BAIL_OUT;
  588. }
  589. if(!(pMMFilter && dwCount > 0))
  590. {
  591. BAIL_OUT; // not required to continue.
  592. }
  593. for (j = 0; j < dwCount; j++)
  594. {
  595. //Get the corresponding MMPolicy associated with the filter.
  596. dwReturn = GetMMPolicyByID(g_szDynamicMachine, dwVersion, pMMFilter[j].gPolicyID, &pMMPolicy, NULL);
  597. if(dwReturn != ERROR_SUCCESS)
  598. {
  599. BAIL_OUT;
  600. }
  601. //Check for the user given parameters. If exists prints the corresponding record
  602. //otherwise continues for next iteration
  603. dwReturn = CheckMMFilter(pMMFilter[j], SrcAddr, DstAddr, bDstMask, bSrcMask, pszShowFilterName);
  604. if(dwReturn == ERROR_SUCCESS)
  605. {
  606. if(!bPrint)
  607. {
  608. //If it is first time print the header.
  609. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_SUB_HEADING);
  610. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_GENERIC_HEADING);
  611. bPrint = TRUE;
  612. }
  613. //Print the filter data.
  614. dwReturn = PrintMainmodeFilter(pMMFilter[j], pMMPolicy[0], addressHash, bResolveDNS, bType);
  615. dwTempCnt++;
  616. bNameFin = TRUE;
  617. }
  618. SPDApiBufferFree(pMMPolicy);
  619. pMMPolicy = NULL;
  620. }
  621. SPDApiBufferFree(pMMFilter);
  622. pMMFilter = NULL;
  623. }
  624. if(dwTempCnt > 0)
  625. {
  626. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_NO_OF_GENERIC_FILTERS, dwTempCnt);
  627. }
  628. }
  629. //Print specific filters
  630. else if(!bType)
  631. {
  632. for (i = 0; ;i+=dwSpecificCount)
  633. {
  634. dwReturn = EnumMMFilters(g_szDynamicMachine, dwVersion, NULL, ENUM_SPECIFIC_FILTERS, gDefaultGUID, 0, &pSpecificMMFilter, &dwSpecificCount, &dwSpecificResumeHandle, NULL);
  635. if (dwReturn == ERROR_NO_DATA || dwSpecificCount == 0)
  636. {
  637. dwReturn = ERROR_SUCCESS;
  638. break;
  639. }
  640. if (dwReturn != ERROR_SUCCESS)
  641. {
  642. BAIL_OUT;
  643. }
  644. if(!(pSpecificMMFilter && dwSpecificCount > 0))
  645. {
  646. BAIL_OUT; // not required to continue.
  647. }
  648. for (l = 0; l < dwSpecificCount; l++)
  649. {
  650. //Get the corresponding MMPolicy associated with the filter.
  651. dwReturn = GetMMPolicyByID(g_szDynamicMachine, dwVersion, pSpecificMMFilter[l].gPolicyID, &pMMPolicy, NULL);
  652. if(dwReturn!=ERROR_SUCCESS)
  653. {
  654. BAIL_OUT;
  655. }
  656. //First print all specific outbound filters.
  657. if(pSpecificMMFilter[l].dwDirection == FILTER_DIRECTION_OUTBOUND)
  658. {
  659. //Check for the user given parameters. If exists prints the corresponding record
  660. //otherwise continues for next iteration
  661. dwReturn = CheckMMFilter(pSpecificMMFilter[l], SrcAddr, DstAddr, bDstMask, bSrcMask, pszShowFilterName);
  662. if(dwReturn == ERROR_SUCCESS)
  663. {
  664. if(!bPrint)
  665. {
  666. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_SUB_HEADING);
  667. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_SPECIFIC_HEADING);
  668. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_OUTBOUND_HEADING);
  669. bPrint = TRUE;
  670. }
  671. //Print the filter data.
  672. dwReturn = PrintMainmodeFilter(pSpecificMMFilter[l], pMMPolicy[0], addressHash, bResolveDNS, bType);
  673. dwTempCnt++;
  674. bNameFin = TRUE;
  675. }
  676. SPDApiBufferFree(pMMPolicy);
  677. pMMPolicy = NULL;
  678. }
  679. }
  680. SPDApiBufferFree(pSpecificMMFilter);
  681. pSpecificMMFilter = NULL;
  682. }
  683. if(dwTempCnt > 0)
  684. {
  685. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_NO_OF_SPECIFIC_OUTBOUND, dwTempCnt);
  686. }
  687. dwSpecificCount = 0;
  688. dwSpecificResumeHandle = 0;
  689. pSpecificMMFilter = NULL;
  690. dwTempCnt = 0;
  691. for (i = 0; ;i+=dwSpecificCount)
  692. {
  693. dwReturn = EnumMMFilters(g_szDynamicMachine, dwVersion, NULL, ENUM_SPECIFIC_FILTERS, gDefaultGUID, 0, &pSpecificMMFilter, &dwSpecificCount, &dwSpecificResumeHandle, NULL);
  694. if (dwReturn == ERROR_NO_DATA || dwSpecificCount == 0)
  695. {
  696. dwReturn = ERROR_SUCCESS;
  697. break;
  698. }
  699. if (dwReturn != ERROR_SUCCESS)
  700. {
  701. BAIL_OUT;
  702. }
  703. if(!(pSpecificMMFilter && dwSpecificCount > 0))
  704. {
  705. BAIL_OUT; // not required to continue.
  706. }
  707. for (l = 0; l < dwSpecificCount; l++)
  708. {
  709. //Get the corresponding MMPolicy associated with the filter.
  710. dwReturn = GetMMPolicyByID(g_szDynamicMachine, dwVersion, pSpecificMMFilter[l].gPolicyID, &pMMPolicy, NULL);
  711. if(dwReturn!=ERROR_SUCCESS)
  712. {
  713. BAIL_OUT;
  714. }
  715. //Then print all the specific inbound filters
  716. if(pSpecificMMFilter[l].dwDirection == FILTER_DIRECTION_INBOUND)
  717. {
  718. //Check for the user given parameters. If exists prints the corresponding record
  719. //otherwise continues for next iteration
  720. dwReturn = CheckMMFilter(pSpecificMMFilter[l],SrcAddr, DstAddr, bDstMask, bSrcMask, pszShowFilterName);
  721. if(dwReturn == ERROR_SUCCESS)
  722. {
  723. if(!bPrintIN)
  724. {
  725. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_NEWLINE);
  726. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_NEWLINE);
  727. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_SUB_HEADING);
  728. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_SPECIFIC_HEADING);
  729. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_INBOUND_HEADING);
  730. bPrintIN = TRUE;
  731. }
  732. //Print the filter data.
  733. dwReturn = PrintMainmodeFilter(pSpecificMMFilter[l], pMMPolicy[0], addressHash, bResolveDNS, bType);
  734. dwTempCnt++;
  735. bNameFin = TRUE;
  736. }
  737. SPDApiBufferFree(pMMPolicy);
  738. pMMPolicy = NULL;
  739. }
  740. }
  741. SPDApiBufferFree(pSpecificMMFilter);
  742. pSpecificMMFilter = NULL;
  743. }
  744. //print number of filters
  745. if(dwTempCnt > 0)
  746. {
  747. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_NO_OF_SPECIFIC_INBOUND, dwTempCnt);
  748. }
  749. }
  750. error:
  751. if(!bNameFin)
  752. {
  753. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_NEWLINE);
  754. if(pszShowFilterName)
  755. {
  756. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_SHOW_MMF_8);
  757. }
  758. else
  759. {
  760. if(bType)
  761. {
  762. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_SHOW_MMF_6);
  763. }
  764. else
  765. {
  766. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_SHOW_MMF_7);
  767. }
  768. }
  769. dwReturn = ERROR_SUCCESS;
  770. }
  771. // error path clean up
  772. if(pMMPolicy)
  773. {
  774. SPDApiBufferFree(pMMPolicy);
  775. pMMPolicy = NULL;
  776. }
  777. if(pMMFilter)
  778. {
  779. SPDApiBufferFree(pMMFilter);
  780. pMMFilter = NULL;
  781. }
  782. if(pSpecificMMFilter)
  783. {
  784. SPDApiBufferFree(pSpecificMMFilter);
  785. pSpecificMMFilter = NULL;
  786. }
  787. return dwReturn;
  788. }
  789. ///////////////////////////////////////////////////////////////////////////////////////////
  790. //
  791. //Function: CheckMMFilter
  792. //
  793. //Date of Creation: 11-21-2001
  794. //
  795. //Parameters: IN MM_FILTER MMFltr,
  796. // IN ADDR SrcAddr,
  797. // IN ADDR DstAddr,
  798. // IN BOOL bDstMask,
  799. // IN BOOL bSrcMask,
  800. // IN LPWSTR pszShowFilterName
  801. //
  802. //Return: DWORD
  803. //
  804. //Description: This function prepares data for displaying mainmode filter
  805. // and validates the input.
  806. //
  807. //
  808. // History :
  809. //
  810. // Date Author Comments
  811. //
  812. //////////////////////////////////////////////////////////////////////////////////////////
  813. DWORD
  814. CheckMMFilter(
  815. IN MM_FILTER MMFltr,
  816. IN ADDR SrcAddr,
  817. IN ADDR DstAddr,
  818. IN BOOL bDstMask,
  819. IN BOOL bSrcMask,
  820. IN LPWSTR pszShowFilterName)
  821. {
  822. DWORD dwReturn = ERROR_SUCCESS;
  823. while(1)
  824. {
  825. //Validates user given input for Source address
  826. switch(SrcAddr.AddrType)
  827. {
  828. case IP_ADDR_WINS_SERVER:
  829. case IP_ADDR_DHCP_SERVER:
  830. case IP_ADDR_DNS_SERVER:
  831. case IP_ADDR_DEFAULT_GATEWAY:
  832. if(MMFltr.SrcAddr.AddrType != SrcAddr.AddrType)
  833. {
  834. dwReturn = ERROR_NO_DISPLAY;
  835. BAIL_OUT;
  836. }
  837. break;
  838. default:
  839. if(SrcAddr.uIpAddr != 0xFFFFFFFF)
  840. {
  841. if(MMFltr.SrcAddr.uIpAddr != SrcAddr.uIpAddr)
  842. {
  843. dwReturn = ERROR_NO_DISPLAY;
  844. BAIL_OUT;
  845. }
  846. }
  847. break;
  848. }
  849. //Validates user given input for Destination address
  850. switch(DstAddr.AddrType)
  851. {
  852. case IP_ADDR_WINS_SERVER:
  853. case IP_ADDR_DHCP_SERVER:
  854. case IP_ADDR_DNS_SERVER:
  855. case IP_ADDR_DEFAULT_GATEWAY:
  856. if(MMFltr.DesAddr.AddrType != DstAddr.AddrType)
  857. {
  858. dwReturn = ERROR_NO_DISPLAY;
  859. BAIL_OUT;
  860. }
  861. break;
  862. default:
  863. if(DstAddr.uIpAddr != 0xFFFFFFFF)
  864. {
  865. if(MMFltr.DesAddr.uIpAddr != DstAddr.uIpAddr)
  866. {
  867. dwReturn = ERROR_NO_DISPLAY;
  868. BAIL_OUT;
  869. }
  870. }
  871. break;
  872. }
  873. //Validates user given input for Destination mask
  874. if(bDstMask)
  875. {
  876. if(MMFltr.DesAddr.uSubNetMask != DstAddr.uSubNetMask)
  877. {
  878. dwReturn = ERROR_NO_DISPLAY;
  879. BAIL_OUT;
  880. }
  881. }
  882. //Validates user given input for Source mask
  883. if(bSrcMask)
  884. {
  885. if(MMFltr.SrcAddr.uSubNetMask != SrcAddr.uSubNetMask)
  886. {
  887. dwReturn = ERROR_NO_DISPLAY;
  888. BAIL_OUT;
  889. }
  890. }
  891. //Validates user given input for Filter name
  892. if(pszShowFilterName!=NULL)
  893. {
  894. if(_tcsicmp(MMFltr.pszFilterName, pszShowFilterName) != 0)
  895. {
  896. dwReturn = ERROR_NO_DISPLAY;
  897. BAIL_OUT;
  898. }
  899. }
  900. //everything fine... all matched
  901. BAIL_OUT;
  902. }
  903. error:
  904. return dwReturn;
  905. }
  906. ///////////////////////////////////////////////////////////////////////////////////////////
  907. //
  908. //Function: PrintMainmodeFilter
  909. //
  910. //Date of Creation: 9-3-2001
  911. //
  912. //Parameters: IN MM_FILTER MMFltr
  913. // IN NshHashTable& addressHash
  914. //
  915. //Return: DWORD
  916. //
  917. //Description: This function displays quickmode Policy in verbose.
  918. //
  919. //
  920. // History :
  921. //
  922. // Date Author Comments
  923. //
  924. //////////////////////////////////////////////////////////////////////////////////////////
  925. DWORD
  926. PrintMainmodeFilter(
  927. IN MM_FILTER MMFltr,
  928. IN IPSEC_MM_POLICY MMPol,
  929. IN NshHashTable& addressHash,
  930. IN BOOL bResolveDNS,
  931. IN BOOL bType
  932. )
  933. {
  934. DWORD dwReturn = ERROR_SUCCESS;
  935. DWORD i = 0;
  936. DWORD dwVersion = 0;
  937. LPTSTR pszCertStr = NULL;
  938. PINT_MM_AUTH_METHODS pIntMMAuth = NULL;
  939. PMM_AUTH_METHODS pMMAM = NULL;
  940. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_NEWLINE);
  941. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_UNDERLINE);
  942. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_NAME, MMFltr.pszFilterName);
  943. //Print Weight
  944. if(!bType)
  945. {
  946. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_FILTER_WEIGHT, MMFltr.dwWeight);
  947. }
  948. //Print Connection Type
  949. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_CONN_HEADING);
  950. switch(MMFltr.InterfaceType)
  951. {
  952. case INTERFACE_TYPE_ALL:
  953. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_CONN_ALL);
  954. break;
  955. case INTERFACE_TYPE_LAN:
  956. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_CONN_LAN);
  957. break;
  958. case INTERFACE_TYPE_DIALUP:
  959. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_CONN_DIALUP);
  960. break;
  961. default:
  962. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_CONN_UNKNOWN);
  963. break;
  964. }
  965. //Print Source Address
  966. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_SRC_ADDR_HEADING);
  967. PrintAddr(MMFltr.SrcAddr, addressHash, bResolveDNS);
  968. if(!bResolveDNS)
  969. {
  970. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMSAS_LEFTBRACKET);
  971. PrintMask(MMFltr.SrcAddr);
  972. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMSAS_RIGHTBRACKET);
  973. }
  974. //Print Destination Address
  975. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_DST_ADDR_HEADING);
  976. PrintAddr(MMFltr.DesAddr, addressHash, bResolveDNS);
  977. if(!bResolveDNS)
  978. {
  979. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMSAS_LEFTBRACKET);
  980. PrintMask(MMFltr.DesAddr);
  981. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMSAS_RIGHTBRACKET);
  982. }
  983. //Print Authentication Methods.
  984. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_AUTH_HEADING);
  985. dwReturn = GetMMAuthMethods(g_szDynamicMachine, dwVersion, MMFltr.gMMAuthID, &pMMAM, NULL);
  986. if (dwReturn != ERROR_SUCCESS)
  987. {
  988. BAIL_OUT;
  989. }
  990. //This is conversion from old structure to the new structure.
  991. dwReturn = ConvertExtMMAuthToInt(pMMAM, &pIntMMAuth);
  992. if (dwReturn != ERROR_SUCCESS)
  993. {
  994. BAIL_OUT;
  995. }
  996. for (i = 0; i < pIntMMAuth[0].dwNumAuthInfos; i++)
  997. {
  998. switch(pIntMMAuth[0].pAuthenticationInfo[i].AuthMethod)
  999. {
  1000. case IKE_PRESHARED_KEY:
  1001. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_PRE_KEY_HEADING);
  1002. break;
  1003. case IKE_DSS_SIGNATURE:
  1004. case IKE_RSA_SIGNATURE:
  1005. case IKE_RSA_ENCRYPTION:
  1006. dwReturn = DecodeCertificateName(pIntMMAuth[0].pAuthenticationInfo[i].pAuthInfo, pIntMMAuth[0].pAuthenticationInfo[i].dwAuthInfoSize, &pszCertStr);
  1007. if (dwReturn != ERROR_SUCCESS)
  1008. {
  1009. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_UNKNOWN_CERT);
  1010. }
  1011. else
  1012. {
  1013. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_NEWLINE_TAB);
  1014. if (pszCertStr)
  1015. {
  1016. DisplayCertInfo(pszCertStr, pIntMMAuth->pAuthenticationInfo[i].dwAuthFlags);
  1017. delete [] pszCertStr;
  1018. pszCertStr = NULL;
  1019. }
  1020. }
  1021. break;
  1022. case IKE_SSPI:
  1023. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_KERB);
  1024. break;
  1025. default:
  1026. break;
  1027. }
  1028. }
  1029. error:
  1030. //Print Security Methods
  1031. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_SEC_METHOD_HEADING);
  1032. // Count
  1033. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_OFFER_CNT,MMPol.dwOfferCount);
  1034. if(IsDefaultMMOffers(MMPol))
  1035. {
  1036. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_DEFAULT_OFFER);
  1037. }
  1038. for (i = 0; i < MMPol.dwOfferCount; i++)
  1039. {
  1040. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_NEWLINE);
  1041. PrintMMFilterOffer(MMPol.pOffers[i]);
  1042. }
  1043. //error path clean up
  1044. if(pMMAM)
  1045. {
  1046. SPDApiBufferFree(pMMAM);
  1047. pMMAM = NULL;
  1048. }
  1049. if(pIntMMAuth)
  1050. {
  1051. SPDApiBufferFree(pIntMMAuth);
  1052. pIntMMAuth = NULL;
  1053. }
  1054. return dwReturn;
  1055. }
  1056. ///////////////////////////////////////////////////////////////////////////////////////////
  1057. //
  1058. //Function: IsDefaultMMOffers
  1059. //
  1060. //Date of Creation: 11-21-2001
  1061. //
  1062. //Parameters: IN IPSEC_MM_POLICY MMPol
  1063. //
  1064. //Return: BOOL
  1065. //
  1066. //Description: This function checks for default MM offers
  1067. //
  1068. // Date Author Comments
  1069. //
  1070. //////////////////////////////////////////////////////////////////////////////////////////
  1071. BOOL
  1072. IsDefaultMMOffers(
  1073. IN IPSEC_MM_POLICY MMPol
  1074. )
  1075. {
  1076. BOOL bDefaultOffer = FALSE;
  1077. if(MMPol.dwOfferCount == 3)
  1078. {
  1079. if((MMPol.pOffers[0].EncryptionAlgorithm.uAlgoIdentifier == CONF_ALGO_3_DES)
  1080. &&(MMPol.pOffers[0].HashingAlgorithm.uAlgoIdentifier == AUTH_ALGO_SHA1)
  1081. &&(MMPol.pOffers[0].dwDHGroup == POTF_OAKLEY_GROUP2)
  1082. &&(MMPol.pOffers[1].EncryptionAlgorithm.uAlgoIdentifier == CONF_ALGO_3_DES)
  1083. &&(MMPol.pOffers[1].HashingAlgorithm.uAlgoIdentifier == AUTH_ALGO_MD5)
  1084. &&(MMPol.pOffers[1].dwDHGroup == POTF_OAKLEY_GROUP2)
  1085. &&(MMPol.pOffers[2].EncryptionAlgorithm.uAlgoIdentifier == CONF_ALGO_3_DES)
  1086. &&(MMPol.pOffers[2].HashingAlgorithm.uAlgoIdentifier == AUTH_ALGO_SHA1)
  1087. &&(MMPol.pOffers[2].dwDHGroup == POTF_OAKLEY_GROUP2048))
  1088. {
  1089. bDefaultOffer=TRUE;
  1090. }
  1091. }
  1092. return bDefaultOffer;
  1093. }
  1094. ///////////////////////////////////////////////////////////////////////////////////////////
  1095. //
  1096. //Function: PrintMMFilterOffer
  1097. //
  1098. //Date of Creation: 11-21-2001
  1099. //
  1100. //Parameters: IN IPSEC_MM_OFFER MMOffer
  1101. //
  1102. //Return: VOID
  1103. //
  1104. //Description: This function prints MM offers
  1105. //
  1106. // Date Author Comments
  1107. //
  1108. //////////////////////////////////////////////////////////////////////////////////////////
  1109. VOID
  1110. PrintMMFilterOffer(
  1111. IN IPSEC_MM_OFFER MMOffer
  1112. )
  1113. {
  1114. //This is to display DH2048 as 3
  1115. if(MMOffer.dwDHGroup == DH_GROUP_2048)
  1116. {
  1117. MMOffer.dwDHGroup = 3;
  1118. }
  1119. //Print Encryption algorithm
  1120. switch(MMOffer.EncryptionAlgorithm.uAlgoIdentifier)
  1121. {
  1122. case 1:
  1123. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_OFFER_DES_ALGO);
  1124. break;
  1125. case 2:
  1126. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_OFFER_UNKNOWN_ALGO);
  1127. break;
  1128. case 3:
  1129. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_OFFER_3DES_ALGO);
  1130. break;
  1131. case 0:
  1132. default:
  1133. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_OFFER_NONE_ALGO);
  1134. break;
  1135. }
  1136. //Print Hash algorithm
  1137. switch(MMOffer.HashingAlgorithm.uAlgoIdentifier)
  1138. {
  1139. case 1:
  1140. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_OFFER_MD5_ALGO);
  1141. break;
  1142. case 2:
  1143. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_OFFER_SHA1_ALGO);
  1144. break;
  1145. case 0:
  1146. default:
  1147. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_OFFER_AH_NONE_ALGO);
  1148. break;
  1149. }
  1150. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_DH_QMLIMIT,MMOffer.dwDHGroup, MMOffer.Lifetime.uKeyExpirationTime, MMOffer.dwQuickModeLimit );
  1151. }
  1152. ///////////////////////////////////////////////////////////////////////////////////////////
  1153. //
  1154. //Function: ShowQMFilters
  1155. //
  1156. //Date of Creation: 11-21-2001
  1157. //
  1158. //Parameters: IN LPTSTR pszShowFilterName,
  1159. // IN LPTSTR pszShowPolicyName
  1160. //
  1161. //Return: DWORD
  1162. //
  1163. //Description: This function prepares data for displaying quick mode filters.
  1164. //
  1165. // Date Author Comments
  1166. //
  1167. //////////////////////////////////////////////////////////////////////////////////////////
  1168. DWORD
  1169. ShowQMFilters(
  1170. IN LPTSTR pszShowFilterName,
  1171. IN BOOL bType,
  1172. IN ADDR SrcAddr,
  1173. IN ADDR DstAddr,
  1174. IN NshHashTable& addressHash,
  1175. IN BOOL bResolveDNS,
  1176. IN BOOL bSrcMask,
  1177. IN BOOL bDstMask,
  1178. IN QM_FILTER_VALUE_BOOL QMBoolValue
  1179. )
  1180. {
  1181. DWORD dwReturn = ERROR_SUCCESS;
  1182. DWORD dwResumeHandle = 0; // handle for continuation calls
  1183. DWORD dwSpecificResumeHandle = 0; // handle for continuation calls
  1184. DWORD dwCount = 0; // counting objects here
  1185. DWORD dwSpecificCount = 0;
  1186. DWORD dwActionFlag = 0;
  1187. GUID gDefaultGUID = {0}; // NULL GUID value
  1188. DWORD i=0, j=0, l=0;
  1189. DWORD dwVersion = 0;
  1190. BOOL bNameFin = FALSE;
  1191. DWORD dwTempCnt = 0;
  1192. LPWSTR pszQMName = NULL;
  1193. BOOL bPrint = FALSE;
  1194. BOOL bPrintIN = FALSE;
  1195. PIPSEC_QM_POLICY pQMPolicy = NULL;
  1196. PTRANSPORT_FILTER pTransF = NULL;
  1197. PTRANSPORT_FILTER pSpecificTransF = NULL;
  1198. //Print generic filters
  1199. if(bType)
  1200. {
  1201. for (i = 0; ;i+=dwCount)
  1202. {
  1203. dwReturn = EnumTransportFilters(g_szDynamicMachine, dwVersion, NULL, ENUM_GENERIC_FILTERS,
  1204. gDefaultGUID, 0, &pTransF, &dwCount, &dwResumeHandle, NULL);
  1205. if (dwReturn == ERROR_NO_DATA || dwCount == 0)
  1206. {
  1207. dwReturn = ERROR_SUCCESS;
  1208. break;
  1209. }
  1210. if (dwReturn != ERROR_SUCCESS)
  1211. {
  1212. BAIL_OUT;
  1213. }
  1214. if(!(pTransF && dwCount > 0))
  1215. {
  1216. BAIL_OUT; // not required to continue.
  1217. }
  1218. for (j = 0; j < dwCount; j++)
  1219. {
  1220. //Get the corresponding QMPolicy for the Transport filter
  1221. dwReturn = GetQMPolicyByID(g_szDynamicMachine, dwVersion, pTransF[j].gPolicyID, 0, &pQMPolicy, NULL);
  1222. if(dwReturn == ERROR_SUCCESS)
  1223. {
  1224. pszQMName = pQMPolicy[0].pszPolicyName;
  1225. }
  1226. else
  1227. {
  1228. //If there is no corresponding filter NULL is passed to the function,
  1229. //so that it is not printed.
  1230. pszQMName = NULL;
  1231. dwReturn = ERROR_SUCCESS;
  1232. }
  1233. //To print inbound and outbound action
  1234. dwActionFlag = 0;
  1235. //Check for the user given parameters. If exists prints the corresponding record
  1236. //otherwise continues for next iteration
  1237. dwReturn = CheckQMFilter(pTransF[j], SrcAddr, DstAddr,
  1238. bDstMask, bSrcMask, QMBoolValue,
  1239. pszShowFilterName);
  1240. if(dwReturn == ERROR_SUCCESS )
  1241. {
  1242. if(!bPrint)
  1243. {
  1244. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_TRANSPORT_HEADING);
  1245. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_GENERIC_HEADING);
  1246. bPrint = TRUE;
  1247. }
  1248. bNameFin = TRUE;
  1249. dwTempCnt++;
  1250. //Print the transport filter
  1251. dwReturn = PrintQuickmodeFilter(pTransF[j], pszQMName, addressHash, bResolveDNS, bType, dwActionFlag);
  1252. }
  1253. if(pQMPolicy)
  1254. {
  1255. SPDApiBufferFree(pQMPolicy);
  1256. pQMPolicy = NULL;
  1257. }
  1258. }
  1259. SPDApiBufferFree(pTransF);
  1260. pTransF = NULL;
  1261. }
  1262. if(dwTempCnt > 0)
  1263. {
  1264. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_NO_OF_GENERIC_FILTERS, dwTempCnt);
  1265. }
  1266. }
  1267. //Print specific filters
  1268. else if(!bType)
  1269. {
  1270. for (i = 0; ;i+=dwSpecificCount)
  1271. {
  1272. dwReturn = EnumTransportFilters(g_szDynamicMachine, dwVersion, NULL, ENUM_SPECIFIC_FILTERS,
  1273. gDefaultGUID, 0, &pSpecificTransF, &dwSpecificCount, &dwSpecificResumeHandle, NULL);
  1274. if (dwReturn == ERROR_NO_DATA || dwSpecificCount == 0)
  1275. {
  1276. dwReturn = ERROR_SUCCESS;
  1277. break;
  1278. }
  1279. if (dwReturn != ERROR_SUCCESS)
  1280. {
  1281. BAIL_OUT;
  1282. }
  1283. if(!(pSpecificTransF && dwSpecificCount > 0))
  1284. {
  1285. BAIL_OUT; // not required to continue.
  1286. }
  1287. for (l = 0; l < dwSpecificCount; l++)
  1288. {
  1289. //get the corresponding QMPolicy
  1290. dwReturn = GetQMPolicyByID(g_szDynamicMachine, dwVersion, pSpecificTransF[l].gPolicyID, 0, &pQMPolicy, NULL);
  1291. if(dwReturn==ERROR_SUCCESS)
  1292. {
  1293. pszQMName = pQMPolicy[0].pszPolicyName;
  1294. }
  1295. else
  1296. {
  1297. //If there is no corresponding policy pass NULL, so that it is not displayed.
  1298. pszQMName = NULL;
  1299. dwReturn = ERROR_SUCCESS;
  1300. }
  1301. //print outbound filters
  1302. if(pSpecificTransF[l].dwDirection == FILTER_DIRECTION_OUTBOUND)
  1303. {
  1304. dwActionFlag = 1;
  1305. //validate user input parameters.
  1306. dwReturn = CheckQMFilter(pSpecificTransF[l], SrcAddr, DstAddr,
  1307. bDstMask, bSrcMask,QMBoolValue,
  1308. pszShowFilterName);
  1309. if(dwReturn==ERROR_SUCCESS)
  1310. {
  1311. if(!bPrint)
  1312. {
  1313. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_TRANSPORT_HEADING);
  1314. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_SPECIFIC_HEADING);
  1315. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_OUTBOUND_HEADING);
  1316. bPrint = TRUE;
  1317. }
  1318. dwTempCnt++;
  1319. bNameFin = TRUE;
  1320. //print specific filters
  1321. dwReturn = PrintQuickmodeFilter(pSpecificTransF[l], pszQMName, addressHash, bResolveDNS, bType, dwActionFlag);
  1322. }
  1323. if(pQMPolicy)
  1324. {
  1325. SPDApiBufferFree(pQMPolicy);
  1326. pQMPolicy = NULL;
  1327. }
  1328. }
  1329. }
  1330. SPDApiBufferFree(pSpecificTransF);
  1331. pSpecificTransF = NULL;
  1332. }
  1333. //print number of filters
  1334. if(dwTempCnt > 0)
  1335. {
  1336. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_NO_OF_SPECIFIC_OUTBOUND, dwTempCnt);
  1337. }
  1338. dwTempCnt = 0;
  1339. dwSpecificCount = 0;
  1340. dwSpecificResumeHandle = 0;
  1341. pSpecificTransF = NULL;
  1342. for (i = 0; ;i+=dwSpecificCount)
  1343. {
  1344. dwReturn = EnumTransportFilters(g_szDynamicMachine, dwVersion, NULL, ENUM_SPECIFIC_FILTERS, gDefaultGUID, 0, &pSpecificTransF, &dwSpecificCount, &dwSpecificResumeHandle, NULL);
  1345. if (dwReturn == ERROR_NO_DATA || dwSpecificCount == 0)
  1346. {
  1347. dwReturn = ERROR_SUCCESS;
  1348. break;
  1349. }
  1350. if (dwReturn != ERROR_SUCCESS)
  1351. {
  1352. BAIL_OUT;
  1353. }
  1354. if(!(pSpecificTransF && dwSpecificCount > 0))
  1355. {
  1356. BAIL_OUT; // not required to continue.
  1357. }
  1358. for (l = 0; l < dwSpecificCount; l++)
  1359. {
  1360. //get the corresponding QMPolicy
  1361. dwReturn = GetQMPolicyByID(g_szDynamicMachine, dwVersion, pSpecificTransF[l].gPolicyID, 0, &pQMPolicy, NULL);
  1362. if(dwReturn==ERROR_SUCCESS)
  1363. {
  1364. pszQMName = pQMPolicy[0].pszPolicyName;
  1365. }
  1366. else
  1367. {
  1368. //if there is no corresponding policy pass NULL, so that it is not printed.
  1369. pszQMName = NULL;
  1370. dwReturn = ERROR_SUCCESS;
  1371. }
  1372. //Print inbound filters
  1373. if(pSpecificTransF[l].dwDirection == FILTER_DIRECTION_INBOUND)
  1374. {
  1375. //To print inbound and outbound filteraction
  1376. dwActionFlag = 2;
  1377. //validate user input data
  1378. dwReturn = CheckQMFilter(pSpecificTransF[l], SrcAddr, DstAddr,
  1379. bDstMask, bSrcMask,QMBoolValue,
  1380. pszShowFilterName);
  1381. if(dwReturn==ERROR_SUCCESS)
  1382. {
  1383. if(!bPrintIN)
  1384. {
  1385. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_NEWLINE);
  1386. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_NEWLINE);
  1387. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_TRANSPORT_HEADING);
  1388. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_SPECIFIC_HEADING);
  1389. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_INBOUND_HEADING);
  1390. bPrintIN = TRUE;
  1391. }
  1392. dwTempCnt++;
  1393. bNameFin = TRUE;
  1394. //print specific filter data
  1395. dwReturn = PrintQuickmodeFilter(pSpecificTransF[l], pszQMName, addressHash, bResolveDNS, bType, dwActionFlag);
  1396. }
  1397. if(pQMPolicy)
  1398. {
  1399. SPDApiBufferFree(pQMPolicy);
  1400. pQMPolicy = NULL;
  1401. }
  1402. }
  1403. }
  1404. SPDApiBufferFree(pSpecificTransF);
  1405. pSpecificTransF = NULL;
  1406. }
  1407. //print number of filters
  1408. if(dwTempCnt > 0)
  1409. {
  1410. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_NO_OF_SPECIFIC_INBOUND, dwTempCnt);
  1411. }
  1412. }
  1413. error:
  1414. //even if there is no transport filters, tunnel can be shown
  1415. dwReturn = ShowTunnelFilters(pszShowFilterName, bType, SrcAddr, DstAddr, addressHash,
  1416. bResolveDNS, bSrcMask, bDstMask, QMBoolValue, bNameFin);
  1417. if(!bNameFin)
  1418. {
  1419. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_NEWLINE);
  1420. if(pszShowFilterName)
  1421. {
  1422. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_SHOW_QMF_8);
  1423. }
  1424. else
  1425. {
  1426. if(bType)
  1427. {
  1428. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_SHOW_QMF_6);
  1429. }
  1430. else
  1431. {
  1432. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_SHOW_QMF_7);
  1433. }
  1434. }
  1435. dwReturn = ERROR_SUCCESS;
  1436. }
  1437. //error path clean up
  1438. if(pQMPolicy)
  1439. {
  1440. SPDApiBufferFree(pQMPolicy);
  1441. pQMPolicy = NULL;
  1442. }
  1443. if(pTransF)
  1444. {
  1445. SPDApiBufferFree(pTransF);
  1446. pTransF = NULL;
  1447. }
  1448. if(pSpecificTransF)
  1449. {
  1450. SPDApiBufferFree(pSpecificTransF);
  1451. pSpecificTransF = NULL;
  1452. }
  1453. return dwReturn;
  1454. }
  1455. ///////////////////////////////////////////////////////////////////////////////////////////
  1456. //
  1457. //Function: ShowTunnelFilters
  1458. //
  1459. //Date of Creation: 11-21-2001
  1460. //
  1461. //Parameters: IN LPTSTR pszShowFilterName,
  1462. // IN BOOL bType,
  1463. // IN ADDR SrcAddr,
  1464. // IN ADDR DstAddr,
  1465. // IN NshHashTable& addressHash,
  1466. // IN BOOL bResolveDNS,
  1467. // IN BOOL bSrcMask,
  1468. // IN BOOL bDstMask,
  1469. // IN QM_FILTER_VALUE_BOOL QMBoolValue,
  1470. // IN OUT BOOL& bNameFin
  1471. //
  1472. //
  1473. //Return: DWORD
  1474. //
  1475. //Description: This function prepares data for displaying Tunnel filters.
  1476. //
  1477. // Date Author Comments
  1478. //
  1479. //////////////////////////////////////////////////////////////////////////////////////////
  1480. DWORD
  1481. ShowTunnelFilters(
  1482. IN LPTSTR pszShowFilterName,
  1483. IN BOOL bType,
  1484. IN ADDR SrcAddr,
  1485. IN ADDR DstAddr,
  1486. IN NshHashTable& addressHash,
  1487. IN BOOL bResolveDNS,
  1488. IN BOOL bSrcMask,
  1489. IN BOOL bDstMask,
  1490. IN QM_FILTER_VALUE_BOOL QMBoolValue,
  1491. IN OUT BOOL& bNameFin
  1492. )
  1493. {
  1494. DWORD dwReturn = ERROR_SUCCESS;
  1495. DWORD dwResumeHandle = 0; // handle for continuation calls
  1496. DWORD dwSpecificResumeHandle = 0; // handle for continuation calls
  1497. DWORD dwCount = 0; // counting objects here
  1498. DWORD dwSpecificCount = 0;
  1499. GUID gDefaultGUID = {0}; // NULL GUID value
  1500. DWORD i=0, j=0, l=0;
  1501. DWORD dwVersion = 0;
  1502. DWORD dwTempCnt = 0;
  1503. LPWSTR pszQMName = NULL;
  1504. BOOL bPrint = FALSE;
  1505. BOOL bPrintIN = FALSE;
  1506. PIPSEC_QM_POLICY pQMPolicy = NULL;
  1507. PTUNNEL_FILTER pTunnelF = NULL;
  1508. PTUNNEL_FILTER pSpecificTunnelF = NULL;
  1509. DWORD dwActionFlag = 0;
  1510. //print generic filters
  1511. if(bType)
  1512. {
  1513. for (i = 0; ;i+=dwCount)
  1514. {
  1515. dwReturn = EnumTunnelFilters(g_szDynamicMachine, dwVersion, NULL, ENUM_GENERIC_FILTERS, gDefaultGUID, 0, &pTunnelF, &dwCount, &dwResumeHandle, NULL);
  1516. if (dwReturn == ERROR_NO_DATA || dwCount == 0)
  1517. {
  1518. dwReturn = ERROR_SUCCESS;
  1519. break;
  1520. }
  1521. if (dwReturn != ERROR_SUCCESS)
  1522. {
  1523. BAIL_OUT;
  1524. }
  1525. if(!(pTunnelF && dwCount > 0))
  1526. {
  1527. BAIL_OUT; // not required to continue.
  1528. }
  1529. for (j = 0; j < dwCount; j++)
  1530. {
  1531. //get the corresponding QMPolicy
  1532. dwReturn = GetQMPolicyByID(g_szDynamicMachine, dwVersion, pTunnelF[j].gPolicyID, 0, &pQMPolicy, NULL);
  1533. if(dwReturn == ERROR_SUCCESS)
  1534. {
  1535. pszQMName = pQMPolicy[0].pszPolicyName;
  1536. }
  1537. else
  1538. {
  1539. //if there is no policy pass NULL, for not printing the policy
  1540. pszQMName = NULL;
  1541. dwReturn = ERROR_SUCCESS;
  1542. }
  1543. dwActionFlag = 0;
  1544. //validate the user input data.
  1545. dwReturn = CheckQMFilter(pTunnelF[j], SrcAddr, DstAddr,
  1546. bDstMask, bSrcMask, QMBoolValue,
  1547. pszShowFilterName);
  1548. if(dwReturn == ERROR_SUCCESS )
  1549. {
  1550. if(!bPrint)
  1551. {
  1552. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_TUNNEL_HEADING);
  1553. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_GENERIC_HEADING);
  1554. bPrint = TRUE;
  1555. }
  1556. bNameFin = TRUE;
  1557. dwTempCnt++;
  1558. //print the filter data
  1559. dwReturn = PrintQuickmodeFilter(pTunnelF[j], pszQMName, addressHash, bResolveDNS, bType, dwActionFlag);
  1560. }
  1561. if(pQMPolicy)
  1562. {
  1563. SPDApiBufferFree(pQMPolicy);
  1564. pQMPolicy = NULL;
  1565. }
  1566. }
  1567. SPDApiBufferFree(pTunnelF);
  1568. pTunnelF = NULL;
  1569. }
  1570. //print the number of filters.
  1571. if(dwTempCnt > 0)
  1572. {
  1573. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_NO_OF_GENERIC_FILTERS, dwTempCnt);
  1574. }
  1575. }
  1576. //print for Specific filters
  1577. else if(!bType)
  1578. {
  1579. for (i = 0; ;i+=dwSpecificCount)
  1580. {
  1581. dwReturn = EnumTunnelFilters(g_szDynamicMachine, dwVersion, NULL, ENUM_SPECIFIC_FILTERS, gDefaultGUID, 0, &pSpecificTunnelF, &dwSpecificCount, &dwSpecificResumeHandle, NULL);
  1582. if (dwReturn == ERROR_NO_DATA || dwSpecificCount == 0)
  1583. {
  1584. dwReturn = ERROR_SUCCESS;
  1585. break; //Still more to show up, break from the loop...
  1586. }
  1587. if (dwReturn != ERROR_SUCCESS)
  1588. {
  1589. BAIL_OUT;
  1590. }
  1591. if(!(pSpecificTunnelF && dwSpecificCount > 0))
  1592. {
  1593. BAIL_OUT; // not required to continue.
  1594. }
  1595. for (l = 0; l < dwSpecificCount; l++)
  1596. {
  1597. //get the corresponding QMPolicy
  1598. dwReturn = GetQMPolicyByID(g_szDynamicMachine, dwVersion, pSpecificTunnelF[l].gPolicyID, 0, &pQMPolicy, NULL);
  1599. if(dwReturn==ERROR_SUCCESS)
  1600. {
  1601. pszQMName = pQMPolicy[0].pszPolicyName;
  1602. }
  1603. else
  1604. {
  1605. //If there is no corresponding policy is not there,
  1606. //pass NULL so that policy is not printed.
  1607. pszQMName = NULL;
  1608. dwReturn = ERROR_SUCCESS;
  1609. }
  1610. //First print outbound filters
  1611. if(pSpecificTunnelF[l].dwDirection == FILTER_DIRECTION_OUTBOUND)
  1612. {
  1613. dwActionFlag = 1;
  1614. //Validate user input data.
  1615. dwReturn = CheckQMFilter(pSpecificTunnelF[l], SrcAddr, DstAddr,
  1616. bDstMask, bSrcMask, QMBoolValue,
  1617. pszShowFilterName);
  1618. if(dwReturn==ERROR_SUCCESS)
  1619. {
  1620. if(!bPrint)
  1621. {
  1622. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_TUNNEL_HEADING);
  1623. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_SPECIFIC_HEADING);
  1624. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_OUTBOUND_HEADING);
  1625. bPrint = TRUE;
  1626. }
  1627. dwTempCnt++;
  1628. bNameFin = TRUE;
  1629. //print specific filter data.
  1630. dwReturn = PrintQuickmodeFilter(pSpecificTunnelF[l], pszQMName, addressHash, bResolveDNS, bType, dwActionFlag);
  1631. }
  1632. if(pQMPolicy == NULL)
  1633. {
  1634. SPDApiBufferFree(pQMPolicy);
  1635. pQMPolicy = NULL;
  1636. }
  1637. }
  1638. }
  1639. SPDApiBufferFree(pSpecificTunnelF);
  1640. pSpecificTunnelF = NULL;
  1641. }
  1642. if(dwTempCnt > 0)
  1643. {
  1644. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_NO_OF_SPECIFIC_OUTBOUND, dwTempCnt);
  1645. }
  1646. dwTempCnt = 0;
  1647. dwSpecificCount = 0;
  1648. dwSpecificResumeHandle = 0;
  1649. pSpecificTunnelF = NULL;
  1650. for (i = 0; ;i+=dwSpecificCount)
  1651. {
  1652. dwReturn = EnumTunnelFilters(g_szDynamicMachine, dwVersion, NULL, ENUM_SPECIFIC_FILTERS, gDefaultGUID, 0, &pSpecificTunnelF, &dwSpecificCount, &dwSpecificResumeHandle, NULL);
  1653. if (dwReturn == ERROR_NO_DATA || dwSpecificCount == 0)
  1654. {
  1655. dwReturn = ERROR_SUCCESS;
  1656. break;
  1657. }
  1658. if (dwReturn != ERROR_SUCCESS)
  1659. {
  1660. BAIL_OUT;
  1661. }
  1662. if(!(pSpecificTunnelF && dwSpecificCount > 0))
  1663. {
  1664. BAIL_OUT; // not required to continue.
  1665. }
  1666. for (l = 0; l < dwSpecificCount; l++)
  1667. {
  1668. //get the corresponding QMPolicy for the filter
  1669. dwReturn = GetQMPolicyByID(g_szDynamicMachine, dwVersion, pSpecificTunnelF[l].gPolicyID, 0, &pQMPolicy, NULL);
  1670. if(dwReturn==ERROR_SUCCESS)
  1671. {
  1672. pszQMName = pQMPolicy[0].pszPolicyName;
  1673. }
  1674. else
  1675. {
  1676. //if the corresponding filter name is not present, pass NULL so that it is not printed.
  1677. pszQMName = NULL;
  1678. dwReturn = ERROR_SUCCESS;
  1679. }
  1680. // then print all inbound filters
  1681. if(pSpecificTunnelF[l].dwDirection == FILTER_DIRECTION_INBOUND)
  1682. {
  1683. dwActionFlag = 2;
  1684. //validate user input
  1685. dwReturn = CheckQMFilter(pSpecificTunnelF[l], SrcAddr, DstAddr,
  1686. bDstMask, bSrcMask, QMBoolValue,
  1687. pszShowFilterName);
  1688. if(dwReturn==ERROR_SUCCESS)
  1689. {
  1690. if(!bPrintIN)
  1691. {
  1692. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_NEWLINE);
  1693. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_NEWLINE);
  1694. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_TUNNEL_HEADING);
  1695. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_SPECIFIC_HEADING);
  1696. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_INBOUND_HEADING);
  1697. bPrintIN = TRUE;
  1698. }
  1699. dwTempCnt++;
  1700. bNameFin = TRUE;
  1701. //print tunnel specific filter data
  1702. dwReturn = PrintQuickmodeFilter(pSpecificTunnelF[l], pszQMName, addressHash, bResolveDNS, bType, dwActionFlag);
  1703. }
  1704. if(pQMPolicy)
  1705. {
  1706. SPDApiBufferFree(pQMPolicy);
  1707. pQMPolicy = NULL;
  1708. }
  1709. }
  1710. }
  1711. SPDApiBufferFree(pSpecificTunnelF);
  1712. pSpecificTunnelF = NULL;
  1713. }
  1714. //print number of filters
  1715. if(dwTempCnt > 0)
  1716. {
  1717. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_NO_OF_SPECIFIC_INBOUND, dwTempCnt);
  1718. }
  1719. }
  1720. error:
  1721. if(pQMPolicy)
  1722. {
  1723. SPDApiBufferFree(pQMPolicy);
  1724. pQMPolicy = NULL;
  1725. }
  1726. //error path clean up
  1727. if(pTunnelF)
  1728. {
  1729. SPDApiBufferFree(pTunnelF);
  1730. pTunnelF = NULL;
  1731. }
  1732. if(pSpecificTunnelF)
  1733. {
  1734. SPDApiBufferFree(pSpecificTunnelF);
  1735. pSpecificTunnelF = NULL;
  1736. }
  1737. return dwReturn;
  1738. }
  1739. ///////////////////////////////////////////////////////////////////////////////////////////
  1740. //
  1741. //Function: CheckQMFilter
  1742. //
  1743. //Date of Creation: 11-21-2001
  1744. //
  1745. //Parameters: IN TRANSPORT_FILTER TransF,
  1746. // IN ADDR SrcAddr,
  1747. // IN ADDR DstAddr,
  1748. // IN BOOL bDstMask,
  1749. // IN BOOL bSrcMask,
  1750. // IN QM_FILTER_VALUE_BOOL QMBoolValue,
  1751. // IN LPWSTR pszShowFilterName
  1752. //
  1753. //
  1754. //Return: DWORD
  1755. //
  1756. //Description: This function prepares data for QM Transport Filter and validates the input
  1757. //
  1758. // Date Author Comments
  1759. //
  1760. //////////////////////////////////////////////////////////////////////////////////////////
  1761. DWORD
  1762. CheckQMFilter(
  1763. IN TRANSPORT_FILTER TransF,
  1764. IN ADDR SrcAddr,
  1765. IN ADDR DstAddr,
  1766. IN BOOL bDstMask,
  1767. IN BOOL bSrcMask,
  1768. IN QM_FILTER_VALUE_BOOL QMBoolValue,
  1769. IN LPWSTR pszShowFilterName
  1770. )
  1771. {
  1772. DWORD dwReturn = ERROR_SUCCESS;
  1773. while(1)
  1774. {
  1775. //Validates user given input for Source address
  1776. switch(SrcAddr.AddrType)
  1777. {
  1778. case IP_ADDR_WINS_SERVER:
  1779. case IP_ADDR_DHCP_SERVER:
  1780. case IP_ADDR_DNS_SERVER:
  1781. case IP_ADDR_DEFAULT_GATEWAY:
  1782. if(TransF.SrcAddr.AddrType != SrcAddr.AddrType)
  1783. {
  1784. dwReturn = ERROR_NO_DISPLAY;
  1785. BAIL_OUT;
  1786. }
  1787. break;
  1788. default:
  1789. if(SrcAddr.uIpAddr != 0xFFFFFFFF)
  1790. {
  1791. if(TransF.SrcAddr.uIpAddr != SrcAddr.uIpAddr)
  1792. {
  1793. dwReturn = ERROR_NO_DISPLAY;
  1794. BAIL_OUT;
  1795. }
  1796. }
  1797. break;
  1798. }
  1799. //Validates user given input for Destination address
  1800. switch(DstAddr.AddrType)
  1801. {
  1802. case IP_ADDR_WINS_SERVER:
  1803. case IP_ADDR_DHCP_SERVER:
  1804. case IP_ADDR_DNS_SERVER:
  1805. case IP_ADDR_DEFAULT_GATEWAY:
  1806. if(TransF.DesAddr.AddrType != DstAddr.AddrType)
  1807. {
  1808. dwReturn = ERROR_NO_DISPLAY;
  1809. BAIL_OUT;
  1810. }
  1811. break;
  1812. default:
  1813. if(DstAddr.uIpAddr != 0xFFFFFFFF)
  1814. {
  1815. if(TransF.DesAddr.uIpAddr != DstAddr.uIpAddr)
  1816. {
  1817. dwReturn = ERROR_NO_DISPLAY;
  1818. BAIL_OUT;
  1819. }
  1820. }
  1821. break;
  1822. }
  1823. //Validates user given input for Source port
  1824. if(QMBoolValue.bSrcPort)
  1825. {
  1826. if(TransF.SrcPort.wPort != (WORD)QMBoolValue.dwSrcPort)
  1827. {
  1828. dwReturn = ERROR_NO_DISPLAY;
  1829. BAIL_OUT;
  1830. }
  1831. }
  1832. //Validates user given input for Destination port
  1833. if(QMBoolValue.bDstPort)
  1834. {
  1835. if(TransF.DesPort.wPort != (WORD)QMBoolValue.dwDstPort)
  1836. {
  1837. dwReturn = ERROR_NO_DISPLAY;
  1838. BAIL_OUT;
  1839. }
  1840. }
  1841. //Validates user given input for Protocol
  1842. if(QMBoolValue.bProtocol)
  1843. {
  1844. if(TransF.Protocol.dwProtocol != QMBoolValue.dwProtocol)
  1845. {
  1846. dwReturn = ERROR_NO_DISPLAY;
  1847. BAIL_OUT;
  1848. }
  1849. }
  1850. //Validates user given input for Inbound action
  1851. if(QMBoolValue.bActionInbound)
  1852. {
  1853. if(TransF.InboundFilterAction != (FILTER_ACTION)QMBoolValue.dwActionInbound)
  1854. {
  1855. dwReturn = ERROR_NO_DISPLAY;
  1856. BAIL_OUT;
  1857. }
  1858. }
  1859. //Validates user given input for Outbound action
  1860. if(QMBoolValue.bActionOutbound)
  1861. {
  1862. if(TransF.OutboundFilterAction != (FILTER_ACTION)QMBoolValue.dwActionOutbound)
  1863. {
  1864. dwReturn = ERROR_NO_DISPLAY;
  1865. BAIL_OUT;
  1866. }
  1867. }
  1868. //Validates user given input for Source Mask
  1869. if(bSrcMask)
  1870. {
  1871. if(TransF.SrcAddr.uSubNetMask != SrcAddr.uSubNetMask)
  1872. {
  1873. dwReturn = ERROR_NO_DISPLAY;
  1874. BAIL_OUT;
  1875. }
  1876. }
  1877. //Validates user given input for Destination address
  1878. if(bDstMask)
  1879. {
  1880. if(TransF.DesAddr.uSubNetMask != DstAddr.uSubNetMask)
  1881. {
  1882. dwReturn = ERROR_NO_DISPLAY;
  1883. BAIL_OUT;
  1884. }
  1885. }
  1886. //Validates user given input for Filtername
  1887. if(pszShowFilterName!=NULL)
  1888. {
  1889. if(_tcsicmp(TransF.pszFilterName, pszShowFilterName) != 0)
  1890. {
  1891. dwReturn = ERROR_NO_DISPLAY;
  1892. BAIL_OUT;
  1893. }
  1894. }
  1895. //Every thing fine... All matched
  1896. BAIL_OUT;
  1897. }
  1898. error:
  1899. return dwReturn;
  1900. }
  1901. ///////////////////////////////////////////////////////////////////////////////////////////
  1902. //
  1903. //Function: CheckQMFilter
  1904. //
  1905. //Date of Creation: 11-21-2001
  1906. //
  1907. //Parameters: IN TUNNEL_FILTER TunnelF,
  1908. // IN ADDR SrcAddr,
  1909. // IN ADDR DstAddr,
  1910. // IN BOOL bDstMask,
  1911. // IN BOOL bSrcMask,
  1912. // IN QM_FILTER_VALUE_BOOL QMBoolValue,
  1913. // IN LPWSTR pszShowFilterName
  1914. //Return: DWORD
  1915. //
  1916. //Description: This function prepares data for QM Tunnel Filter and validates the input
  1917. //
  1918. // Date Author Comments
  1919. //
  1920. //////////////////////////////////////////////////////////////////////////////////////////
  1921. DWORD
  1922. CheckQMFilter(
  1923. IN TUNNEL_FILTER TunnelF,
  1924. IN ADDR SrcAddr,
  1925. IN ADDR DstAddr,
  1926. IN BOOL bDstMask,
  1927. IN BOOL bSrcMask,
  1928. IN QM_FILTER_VALUE_BOOL QMBoolValue,
  1929. IN LPWSTR pszShowFilterName
  1930. )
  1931. {
  1932. DWORD dwReturn = ERROR_SUCCESS;
  1933. while(1)
  1934. {
  1935. //Validates user given input for Source address
  1936. switch(SrcAddr.AddrType)
  1937. {
  1938. case IP_ADDR_WINS_SERVER:
  1939. case IP_ADDR_DHCP_SERVER:
  1940. case IP_ADDR_DNS_SERVER:
  1941. case IP_ADDR_DEFAULT_GATEWAY:
  1942. if(TunnelF.SrcAddr.AddrType != SrcAddr.AddrType)
  1943. {
  1944. dwReturn = ERROR_NO_DISPLAY;
  1945. BAIL_OUT;
  1946. }
  1947. break;
  1948. default:
  1949. if(SrcAddr.uIpAddr != 0xFFFFFFFF)
  1950. {
  1951. if(TunnelF.SrcAddr.uIpAddr != SrcAddr.uIpAddr)
  1952. {
  1953. dwReturn = ERROR_NO_DISPLAY;
  1954. BAIL_OUT;
  1955. }
  1956. }
  1957. break;
  1958. }
  1959. //Validates user given input for Destination address
  1960. switch(DstAddr.AddrType)
  1961. {
  1962. case IP_ADDR_WINS_SERVER:
  1963. case IP_ADDR_DHCP_SERVER:
  1964. case IP_ADDR_DNS_SERVER:
  1965. case IP_ADDR_DEFAULT_GATEWAY:
  1966. if(TunnelF.DesAddr.AddrType != DstAddr.AddrType)
  1967. {
  1968. dwReturn = ERROR_NO_DISPLAY;
  1969. BAIL_OUT;
  1970. }
  1971. break;
  1972. default:
  1973. if(DstAddr.uIpAddr != 0xFFFFFFFF)
  1974. {
  1975. if(TunnelF.DesAddr.uIpAddr != DstAddr.uIpAddr)
  1976. {
  1977. dwReturn = ERROR_NO_DISPLAY;
  1978. BAIL_OUT;
  1979. }
  1980. }
  1981. break;
  1982. }
  1983. //Validates user given input for Source port
  1984. if(QMBoolValue.bSrcPort)
  1985. {
  1986. if(TunnelF.SrcPort.wPort != (WORD)QMBoolValue.dwSrcPort)
  1987. {
  1988. dwReturn = ERROR_NO_DISPLAY;
  1989. BAIL_OUT;
  1990. }
  1991. }
  1992. //Validates user given input for Destination port
  1993. if(QMBoolValue.bDstPort)
  1994. {
  1995. if(TunnelF.DesPort.wPort != (WORD)QMBoolValue.dwDstPort)
  1996. {
  1997. dwReturn = ERROR_NO_DISPLAY;
  1998. BAIL_OUT;
  1999. }
  2000. }
  2001. //Validates user given input for protocol
  2002. if(QMBoolValue.bProtocol)
  2003. {
  2004. if(TunnelF.Protocol.dwProtocol != QMBoolValue.dwProtocol)
  2005. {
  2006. dwReturn = ERROR_NO_DISPLAY;
  2007. BAIL_OUT;
  2008. }
  2009. }
  2010. //Validates user given input for Inbound action
  2011. if(QMBoolValue.bActionInbound)
  2012. {
  2013. if(TunnelF.InboundFilterAction != (FILTER_ACTION)QMBoolValue.dwActionInbound)
  2014. {
  2015. dwReturn = ERROR_NO_DISPLAY;
  2016. BAIL_OUT;
  2017. }
  2018. }
  2019. //Validates user given input for outbound action
  2020. if(QMBoolValue.bActionOutbound)
  2021. {
  2022. if(TunnelF.OutboundFilterAction != (FILTER_ACTION)QMBoolValue.dwActionOutbound)
  2023. {
  2024. dwReturn = ERROR_NO_DISPLAY;
  2025. BAIL_OUT;
  2026. }
  2027. }
  2028. //Validates user given input for Source Mask
  2029. if(bSrcMask)
  2030. {
  2031. if(TunnelF.SrcAddr.uSubNetMask != SrcAddr.uSubNetMask)
  2032. {
  2033. dwReturn = ERROR_NO_DISPLAY;
  2034. BAIL_OUT;
  2035. }
  2036. }
  2037. //Validates user given input for Destination mask
  2038. if(bDstMask)
  2039. {
  2040. if(TunnelF.DesAddr.uSubNetMask != DstAddr.uSubNetMask)
  2041. {
  2042. dwReturn = ERROR_NO_DISPLAY;
  2043. BAIL_OUT;
  2044. }
  2045. }
  2046. //Validates user given input for filter name
  2047. if(pszShowFilterName!=NULL)
  2048. {
  2049. if(_tcsicmp(TunnelF.pszFilterName, pszShowFilterName) != 0)
  2050. {
  2051. dwReturn = ERROR_NO_DISPLAY;
  2052. BAIL_OUT;
  2053. }
  2054. }
  2055. //Every thing fine... All matched
  2056. BAIL_OUT;
  2057. }
  2058. error:
  2059. return dwReturn;
  2060. }
  2061. ///////////////////////////////////////////////////////////////////////////////////////////
  2062. //
  2063. //Function: PrintQuickmodeFilter
  2064. //
  2065. //Date of Creation: 11-21-2001
  2066. //
  2067. //Parameters:
  2068. // IN TRANSPORT_FILTER TransF,
  2069. // IN LPWSTR pszQMName,
  2070. // IN NshHashTable& addressHash
  2071. // IN BOOL bResolveDNS,
  2072. // IN BOOL bType,
  2073. // IN DWORD dwActionFlag
  2074. //
  2075. //Return: DWORD
  2076. //
  2077. //Description: This function prints Transport filter details
  2078. //
  2079. // Date Author Comments
  2080. //
  2081. //////////////////////////////////////////////////////////////////////////////////////////
  2082. DWORD
  2083. PrintQuickmodeFilter(
  2084. IN TRANSPORT_FILTER TransF,
  2085. IN LPWSTR pszQMName,
  2086. IN NshHashTable& addressHash,
  2087. IN BOOL bResolveDNS,
  2088. IN BOOL bType,
  2089. IN DWORD dwActionFlag
  2090. )
  2091. {
  2092. DWORD dwReturn = ERROR_SUCCESS;
  2093. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_NEWLINE);
  2094. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_UNDERLINE);
  2095. //Print FilterName
  2096. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_NAME, TransF.pszFilterName);
  2097. //Print Connection Type
  2098. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_CONN_HEADING);
  2099. switch(TransF.InterfaceType)
  2100. {
  2101. case INTERFACE_TYPE_ALL:
  2102. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_CONN_ALL);
  2103. break;
  2104. case INTERFACE_TYPE_LAN:
  2105. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_CONN_LAN);
  2106. break;
  2107. case INTERFACE_TYPE_DIALUP:
  2108. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_CONN_DIALUP);
  2109. break;
  2110. default:
  2111. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_CONN_UNKNOWN);
  2112. break;
  2113. }
  2114. //Print Weight
  2115. if(!bType)
  2116. {
  2117. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_FILTER_WEIGHT, TransF.dwWeight);
  2118. }
  2119. //Print Source Address
  2120. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_SRC_ADDR_HEADING);
  2121. PrintAddr(TransF.SrcAddr, addressHash, bResolveDNS);
  2122. if(!bResolveDNS)
  2123. {
  2124. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMSAS_LEFTBRACKET);
  2125. PrintMask(TransF.SrcAddr);
  2126. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMSAS_RIGHTBRACKET);
  2127. }
  2128. //Print Destination Address
  2129. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_DST_ADDR_HEADING);
  2130. PrintAddr(TransF.DesAddr, addressHash, bResolveDNS);
  2131. if(!bResolveDNS)
  2132. {
  2133. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMSAS_LEFTBRACKET);
  2134. PrintMask(TransF.DesAddr);
  2135. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMSAS_RIGHTBRACKET);
  2136. }
  2137. //Print Protocol
  2138. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_PROTO_HEADING);
  2139. switch(TransF.Protocol.dwProtocol)
  2140. {
  2141. case PROT_ID_ICMP:
  2142. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_ICMP);
  2143. break;
  2144. case PROT_ID_TCP:
  2145. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_TCP);
  2146. break;
  2147. case PROT_ID_UDP:
  2148. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_UDP);
  2149. break;
  2150. case PROT_ID_RAW:
  2151. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_RAW);
  2152. break;
  2153. case PROT_ID_ANY:
  2154. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_ANY);
  2155. break;
  2156. default:
  2157. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_DEFAULT_PROTOCOL, TransF.Protocol.dwProtocol);
  2158. break;
  2159. }
  2160. //Print Src, Des Port
  2161. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_SRC_DST_PORT,TransF.SrcPort.wPort,TransF.DesPort.wPort);
  2162. //Print Mirror
  2163. if(TransF.bCreateMirror)
  2164. {
  2165. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MIRR_YES);
  2166. }
  2167. else
  2168. {
  2169. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MIRR_NO);
  2170. }
  2171. // Print Qm Policy Name
  2172. if(pszQMName != NULL)
  2173. {
  2174. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_NAME,pszQMName);
  2175. }
  2176. //Print Action Flag
  2177. if(dwActionFlag == 0 || dwActionFlag == 2)
  2178. {
  2179. switch(TransF.InboundFilterAction)
  2180. {
  2181. case PASS_THRU:
  2182. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_INBOUND_PASSTHRU);
  2183. break;
  2184. case NEGOTIATE_SECURITY:
  2185. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_INBOUND_NEGOTIATE);
  2186. break;
  2187. case BLOCKING:
  2188. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_INBOUND_BLOCK);
  2189. break;
  2190. default:
  2191. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_INBOUND_UNKNOWN);
  2192. break;
  2193. }
  2194. }
  2195. if(dwActionFlag == 0 || dwActionFlag == 1)
  2196. {
  2197. switch(TransF.OutboundFilterAction)
  2198. {
  2199. case PASS_THRU:
  2200. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_OUTBOUND_PASSTHRU);
  2201. break;
  2202. case NEGOTIATE_SECURITY:
  2203. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_OUTBOUND_NEGOTIATE);
  2204. break;
  2205. case BLOCKING:
  2206. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_OUTBOUND_BLOCK);
  2207. break;
  2208. default:
  2209. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_OUTBOUND_UNKNOWN);
  2210. break;
  2211. }
  2212. }
  2213. return dwReturn;
  2214. }
  2215. ///////////////////////////////////////////////////////////////////////////////////////////
  2216. //
  2217. //Function: PrintQuickmodeFilter
  2218. //
  2219. //Date of Creation: 11-21-2001
  2220. //
  2221. //Parameters:
  2222. // IN TUNNEL_FILTER TunnelF,
  2223. // IN LPWSTR pszQMName,
  2224. // IN NshHashTable& addressHash
  2225. // IN BOOL bResolveDNS,
  2226. // IN BOOL bType,
  2227. // IN DWORD dwActionFlag
  2228. //
  2229. //Return: DWORD
  2230. //
  2231. //Description: This function prints Tunnel filter details
  2232. //
  2233. // Date Author Comments
  2234. //
  2235. //////////////////////////////////////////////////////////////////////////////////////////
  2236. DWORD
  2237. PrintQuickmodeFilter(
  2238. IN TUNNEL_FILTER TunnelF,
  2239. IN LPWSTR pszQMName,
  2240. IN NshHashTable& addressHash,
  2241. IN BOOL bResolveDNS,
  2242. IN BOOL bType,
  2243. IN DWORD dwActionFlag
  2244. )
  2245. {
  2246. DWORD dwReturn = ERROR_SUCCESS;
  2247. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_NEWLINE);
  2248. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_UNDERLINE);
  2249. //Print FilterName
  2250. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_NAME, TunnelF.pszFilterName);
  2251. //Print Connection Type
  2252. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_CONN_HEADING);
  2253. switch(TunnelF.InterfaceType)
  2254. {
  2255. case INTERFACE_TYPE_ALL:
  2256. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_CONN_ALL);
  2257. break;
  2258. case INTERFACE_TYPE_LAN:
  2259. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_CONN_LAN);
  2260. break;
  2261. case INTERFACE_TYPE_DIALUP:
  2262. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_CONN_DIALUP);
  2263. break;
  2264. default:
  2265. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_CONN_UNKNOWN);
  2266. break;
  2267. }
  2268. //Print Weight
  2269. if(!bType)
  2270. {
  2271. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_FILTER_WEIGHT, TunnelF.dwWeight);
  2272. }
  2273. //Print Source Address
  2274. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_SRC_ADDR_HEADING);
  2275. PrintAddr(TunnelF.SrcAddr, addressHash, bResolveDNS);
  2276. if(!bResolveDNS)
  2277. {
  2278. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMSAS_LEFTBRACKET);
  2279. PrintMask(TunnelF.SrcAddr);
  2280. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMSAS_RIGHTBRACKET);
  2281. }
  2282. //Print Destination Address
  2283. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_DST_ADDR_HEADING);
  2284. PrintAddr(TunnelF.DesAddr, addressHash, bResolveDNS);
  2285. if(!bResolveDNS)
  2286. {
  2287. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMSAS_LEFTBRACKET);
  2288. PrintMask(TunnelF.DesAddr);
  2289. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMSAS_RIGHTBRACKET);
  2290. }
  2291. //Print Tunnel Src
  2292. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_TUNNEL_SRC);
  2293. PrintAddr(TunnelF.SrcTunnelAddr, addressHash, bResolveDNS);
  2294. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_TUNNEL_DST);
  2295. PrintAddr(TunnelF.DesTunnelAddr, addressHash, bResolveDNS);
  2296. //Print Protocol
  2297. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_PROTO_HEADING);
  2298. switch(TunnelF.Protocol.dwProtocol)
  2299. {
  2300. case PROT_ID_ICMP: //1
  2301. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_ICMP);
  2302. break;
  2303. case PROT_ID_TCP: //6
  2304. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_TCP);
  2305. break;
  2306. case PROT_ID_UDP: //17
  2307. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_UDP);
  2308. break;
  2309. case PROT_ID_RAW: //255
  2310. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_RAW);
  2311. break;
  2312. case PROT_ID_ANY: //0
  2313. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_ANY);
  2314. break;
  2315. default:
  2316. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_DEFAULT_PROTOCOL, TunnelF.Protocol.dwProtocol);
  2317. break;
  2318. }
  2319. //Print Src, Des Port
  2320. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_SRC_DST_PORT,TunnelF.SrcPort.wPort,TunnelF.DesPort.wPort);
  2321. //Print Mirror
  2322. if(TunnelF.bCreateMirror)
  2323. {
  2324. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MIRR_YES);
  2325. }
  2326. else
  2327. {
  2328. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MIRR_NO);
  2329. }
  2330. // Print Qm Policy Name
  2331. if(pszQMName != NULL)
  2332. {
  2333. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_NAME,pszQMName);
  2334. }
  2335. //Print Action Flag
  2336. if(dwActionFlag == 0 || dwActionFlag == 2)
  2337. {
  2338. switch(TunnelF.InboundFilterAction)
  2339. {
  2340. case PASS_THRU:
  2341. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_INBOUND_PASSTHRU);
  2342. break;
  2343. case NEGOTIATE_SECURITY:
  2344. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_INBOUND_NEGOTIATE);
  2345. break;
  2346. case BLOCKING:
  2347. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_INBOUND_BLOCK);
  2348. break;
  2349. default:
  2350. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_INBOUND_UNKNOWN);
  2351. break;
  2352. }
  2353. }
  2354. if(dwActionFlag == 0 || dwActionFlag == 1)
  2355. {
  2356. switch(TunnelF.OutboundFilterAction)
  2357. {
  2358. case PASS_THRU:
  2359. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_OUTBOUND_PASSTHRU);
  2360. break;
  2361. case NEGOTIATE_SECURITY:
  2362. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_OUTBOUND_NEGOTIATE);
  2363. break;
  2364. case BLOCKING:
  2365. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_OUTBOUND_BLOCK);
  2366. break;
  2367. default:
  2368. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_OUTBOUND_UNKNOWN);
  2369. break;
  2370. }
  2371. }
  2372. return dwReturn;
  2373. }
  2374. ///////////////////////////////////////////////////////////////////////////////////////////
  2375. //
  2376. //Function: ShowRule
  2377. //
  2378. //Date of Creation: 9-3-2001
  2379. //
  2380. //Parameters:
  2381. // IN DWORD dwType,
  2382. // IN ADDR SrcAddr,
  2383. // IN ADDR DstAddr,
  2384. // IN NshHashTable& addressHash,
  2385. // IN BOOL bResolveDNS,
  2386. // IN BOOL bSrcMask,
  2387. // IN BOOL bDstMask,
  2388. // IN QM_FILTER_VALUE_BOOL QMBoolValue
  2389. //
  2390. //Return: DWORD
  2391. //
  2392. //Description: This function prepares data for displaying quick mode filters.
  2393. //
  2394. // Date Author Comments
  2395. //
  2396. //////////////////////////////////////////////////////////////////////////////////////////
  2397. DWORD
  2398. ShowRule(
  2399. IN DWORD dwType,
  2400. IN ADDR SrcAddr,
  2401. IN ADDR DstAddr,
  2402. IN NshHashTable& addressHash,
  2403. IN BOOL bResolveDNS,
  2404. IN BOOL bSrcMask,
  2405. IN BOOL bDstMask,
  2406. IN QM_FILTER_VALUE_BOOL QMBoolValue
  2407. )
  2408. {
  2409. DWORD dwReturn = ERROR_SUCCESS;
  2410. DWORD dwResumeHandle = 0; // handle for continuation calls
  2411. DWORD dwCount = 0; // counting objects here
  2412. DWORD dwQMResumeHandle = 0; // handle for continuation calls
  2413. DWORD dwQMCount = 0; // counting objects here
  2414. GUID gDefaultGUID = {0}; // NULL GUID value
  2415. DWORD i=0, j=0, k=0, l=0;
  2416. DWORD dwVersion = 0;
  2417. DWORD dwTempCnt = 0;
  2418. DWORD dwActionFlag = 0;
  2419. LPWSTR pszQMName = NULL;
  2420. BOOL bPrint = FALSE;
  2421. BOOL bMMFound = FALSE;
  2422. BOOL bNameFin = FALSE;
  2423. PIPSEC_QM_POLICY pQMPolicy = NULL;
  2424. PTRANSPORT_FILTER pTransF = NULL;
  2425. PIPSEC_MM_POLICY pMMPolicy = NULL;
  2426. PMM_FILTER pMMFilter = NULL;
  2427. if(dwType == 1 || dwType == 0)//either transport or all
  2428. {
  2429. for (k = 0; ;k+=dwQMCount)
  2430. {
  2431. dwReturn = EnumTransportFilters(g_szDynamicMachine, dwVersion, NULL, ENUM_GENERIC_FILTERS, gDefaultGUID, 0,
  2432. &pTransF, &dwQMCount, &dwQMResumeHandle, NULL);
  2433. if (dwReturn == ERROR_NO_DATA || dwQMCount == 0)
  2434. {
  2435. dwReturn = ERROR_SUCCESS;
  2436. BAIL_OUT;
  2437. }
  2438. if (dwReturn != ERROR_SUCCESS)
  2439. {
  2440. BAIL_OUT;
  2441. }
  2442. if(!(pTransF && dwQMCount > 0))
  2443. {
  2444. BAIL_OUT; // not required to continue.
  2445. }
  2446. for (l = 0; l < dwQMCount; l++)
  2447. {
  2448. dwResumeHandle = 0;
  2449. pMMFilter = 0;
  2450. dwCount = 0;
  2451. dwReturn = CheckQMFilter(pTransF[l], SrcAddr, DstAddr, bDstMask, bSrcMask,QMBoolValue, NULL);
  2452. if(dwReturn != ERROR_SUCCESS)
  2453. {
  2454. //Though not matched check for other filters
  2455. dwReturn = ERROR_SUCCESS;
  2456. continue;
  2457. }
  2458. for (i = 0; ;i+=dwCount)
  2459. {
  2460. dwReturn = EnumMMFilters(g_szDynamicMachine, dwVersion, NULL, ENUM_GENERIC_FILTERS, gDefaultGUID, 0,
  2461. &pMMFilter, &dwCount, &dwResumeHandle, NULL);
  2462. if (dwReturn == ERROR_NO_DATA || dwCount == 0)
  2463. {
  2464. dwReturn = ERROR_SUCCESS;
  2465. break;
  2466. }
  2467. if (dwReturn != ERROR_SUCCESS)
  2468. {
  2469. break;
  2470. }
  2471. if(!(pMMFilter && dwCount > 0))
  2472. {
  2473. break; // not required to continue.
  2474. }
  2475. for (j = 0; j < dwCount; j++)
  2476. {
  2477. //Match QMfilter data with MMFilter data to get the corresponding MMFilter details to print
  2478. if((pTransF[l].SrcAddr.AddrType == pMMFilter[j].SrcAddr.AddrType) &&
  2479. (pTransF[l].SrcAddr.uIpAddr == pMMFilter[j].SrcAddr.uIpAddr) &&
  2480. (pTransF[l].DesAddr.AddrType == pMMFilter[j].DesAddr.AddrType) &&
  2481. (pTransF[l].DesAddr.uIpAddr == pMMFilter[j].DesAddr.uIpAddr) &&
  2482. (pTransF[l].SrcAddr.uSubNetMask == pMMFilter[j].SrcAddr.uSubNetMask) &&
  2483. (pTransF[l].DesAddr.uSubNetMask == pMMFilter[j].DesAddr.uSubNetMask) &&
  2484. (pTransF[l].InterfaceType == pMMFilter[j].InterfaceType) &&
  2485. (pTransF[l].bCreateMirror == pMMFilter[j].bCreateMirror)
  2486. )
  2487. {
  2488. //Get the corresponding MMPolicy details
  2489. pMMPolicy = NULL;
  2490. dwReturn = GetMMPolicyByID(g_szDynamicMachine, dwVersion, pMMFilter[j].gPolicyID,
  2491. &pMMPolicy, NULL);
  2492. if(dwReturn != ERROR_SUCCESS)
  2493. {
  2494. BAIL_OUT;
  2495. }
  2496. //Get the corresponding QMPolicy details
  2497. dwReturn = GetQMPolicyByID(g_szDynamicMachine, dwVersion, pTransF[l].gPolicyID, 0, &pQMPolicy, NULL);
  2498. if(dwReturn == ERROR_SUCCESS)
  2499. {
  2500. pszQMName = pQMPolicy[0].pszPolicyName;
  2501. }
  2502. else
  2503. {
  2504. //If there is no corresponding policy pass NULL, so it is not printed
  2505. pszQMName = NULL;
  2506. dwReturn = ERROR_SUCCESS;
  2507. }
  2508. dwActionFlag = 0;
  2509. if(!bPrint)
  2510. {
  2511. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_TRANSPORT_RULE_HEADING);
  2512. bPrint = TRUE;
  2513. }
  2514. dwTempCnt++;
  2515. //print Transport Rule details
  2516. dwReturn = PrintTransportRuleFilter(&pMMFilter[j], &pMMPolicy[0], pTransF[l], pszQMName, addressHash, bResolveDNS);
  2517. bNameFin = TRUE;
  2518. bMMFound = TRUE;
  2519. if(pQMPolicy)
  2520. {
  2521. SPDApiBufferFree(pQMPolicy);
  2522. pQMPolicy = NULL;
  2523. }
  2524. if(pMMPolicy)
  2525. {
  2526. SPDApiBufferFree(pMMPolicy);
  2527. pMMPolicy = NULL;
  2528. }
  2529. }
  2530. }
  2531. if(pMMFilter)
  2532. {
  2533. SPDApiBufferFree(pMMFilter);
  2534. pMMFilter = NULL;
  2535. }
  2536. }
  2537. }
  2538. SPDApiBufferFree(pTransF);
  2539. pTransF = NULL;
  2540. }
  2541. }
  2542. error:
  2543. //print the number of transport rules
  2544. if(dwTempCnt > 0)
  2545. {
  2546. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_NO_OF_TRANSPORT_FILTERS, dwTempCnt);
  2547. }
  2548. //Then print tunnel filters
  2549. dwReturn = ShowTunnelRule(dwType, SrcAddr, DstAddr, addressHash, bResolveDNS, bSrcMask, bDstMask, QMBoolValue, bNameFin);
  2550. if(!bNameFin)
  2551. {
  2552. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_NEWLINE);
  2553. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_SHOW_QMF_17);
  2554. dwReturn = ERROR_SUCCESS;
  2555. }
  2556. //error path clean up
  2557. if(pQMPolicy)
  2558. {
  2559. SPDApiBufferFree(pQMPolicy);
  2560. pQMPolicy = NULL;
  2561. }
  2562. if(pMMPolicy)
  2563. {
  2564. SPDApiBufferFree(pMMPolicy);
  2565. pMMPolicy = NULL;
  2566. }
  2567. if(pMMFilter)
  2568. {
  2569. SPDApiBufferFree(pMMFilter);
  2570. pMMFilter = NULL;
  2571. }
  2572. if(pTransF)
  2573. {
  2574. SPDApiBufferFree(pTransF);
  2575. pTransF = NULL;
  2576. }
  2577. return dwReturn;
  2578. }
  2579. ///////////////////////////////////////////////////////////////////////////////////////////
  2580. //
  2581. // Function : ShowTunnelRule
  2582. //
  2583. // Date of Creation: 9-3-2001
  2584. //
  2585. // Parameters :
  2586. // IN DWORD dwType,
  2587. // IN ADDR SrcAddr,
  2588. // IN ADDR DstAddr,
  2589. // IN NshHashTable& addressHash,
  2590. // IN BOOL bResolveDNS,
  2591. // IN BOOL bSrcMask,
  2592. // IN BOOL bDstMask,
  2593. // IN QM_FILTER_VALUE_BOOL QMBoolValue
  2594. // IN OUT BOOL& bNameFin
  2595. //
  2596. // Return : DWORD
  2597. //
  2598. // Description : This function prepares data for displaying quick mode filters.
  2599. //
  2600. // Date Author Comments
  2601. //
  2602. //////////////////////////////////////////////////////////////////////////////////////////
  2603. DWORD
  2604. ShowTunnelRule(
  2605. IN DWORD dwType,
  2606. IN ADDR SrcAddr,
  2607. IN ADDR DstAddr,
  2608. IN NshHashTable& addressHash,
  2609. IN BOOL bResolveDNS,
  2610. IN BOOL bSrcMask,
  2611. IN BOOL bDstMask,
  2612. IN QM_FILTER_VALUE_BOOL QMBoolValue,
  2613. IN OUT BOOL& bNameFin
  2614. )
  2615. {
  2616. DWORD dwReturn = ERROR_SUCCESS;
  2617. DWORD dwResumeHandle = 0; // handle for continuation calls
  2618. DWORD dwCount = 0; // counting objects here
  2619. DWORD dwQMResumeHandle = 0; // handle for continuation calls
  2620. DWORD dwQMCount = 0; // counting objects here
  2621. GUID gDefaultGUID = {0}; // NULL GUID value
  2622. DWORD i=0, j=0, k=0, l=0;
  2623. DWORD dwVersion = 0;
  2624. DWORD dwTempCnt = 0;
  2625. DWORD dwActionFlag = 0;
  2626. LPWSTR pszQMName = NULL;
  2627. BOOL bPrint = FALSE;
  2628. BOOL bMMFound = FALSE;
  2629. PIPSEC_QM_POLICY pQMPolicy = NULL;
  2630. PTUNNEL_FILTER pTunnelF = NULL;
  2631. PIPSEC_MM_POLICY pMMPolicy = NULL;
  2632. PMM_FILTER pMMFilter = NULL;
  2633. if(dwType == 2 || dwType == 0)//either tunnel or all
  2634. {
  2635. for (k = 0; ;k+=dwQMCount)
  2636. {
  2637. dwReturn = EnumTunnelFilters(g_szDynamicMachine, dwVersion, NULL, ENUM_GENERIC_FILTERS, gDefaultGUID, 0, &pTunnelF, &dwQMCount, &dwQMResumeHandle, NULL);
  2638. if (dwReturn == ERROR_NO_DATA || dwQMCount == 0)
  2639. {
  2640. dwReturn = ERROR_SUCCESS;
  2641. BAIL_OUT;
  2642. }
  2643. if (dwReturn != ERROR_SUCCESS)
  2644. {
  2645. BAIL_OUT;
  2646. }
  2647. if(!(pTunnelF && dwQMCount > 0))
  2648. {
  2649. BAIL_OUT; // not required to continue.
  2650. }
  2651. for (l = 0; l < dwQMCount; l++)
  2652. {
  2653. dwResumeHandle = 0;
  2654. pMMFilter = 0;
  2655. dwCount = 0;
  2656. //Validate user input data.
  2657. dwReturn = CheckQMFilter(pTunnelF[l], SrcAddr, DstAddr, bDstMask, bSrcMask,QMBoolValue, NULL);
  2658. if(dwReturn != ERROR_SUCCESS)
  2659. {
  2660. //Though not matched continue for other filters
  2661. dwReturn = ERROR_SUCCESS;
  2662. continue;
  2663. }
  2664. for (i = 0; ;i+=dwCount)
  2665. {
  2666. dwReturn = EnumMMFilters(g_szDynamicMachine, dwVersion, NULL, ENUM_GENERIC_FILTERS, gDefaultGUID, 0, &pMMFilter, &dwCount, &dwResumeHandle, NULL);
  2667. if (dwReturn == ERROR_NO_DATA || dwCount == 0)
  2668. {
  2669. dwReturn = ERROR_SUCCESS;
  2670. break;
  2671. }
  2672. if (dwReturn != ERROR_SUCCESS)
  2673. {
  2674. break;
  2675. }
  2676. if(!(pMMFilter && dwCount > 0))
  2677. {
  2678. break; // not required to continue.
  2679. }
  2680. for (j = 0; j < dwCount; j++)
  2681. {
  2682. //Match QMfilter data with MMFilter data to get the corresponding MMFilter details to print
  2683. if((pTunnelF[l].DesTunnelAddr.AddrType == pMMFilter[j].DesAddr.AddrType) &&
  2684. (pTunnelF[l].DesTunnelAddr.uIpAddr == pMMFilter[j].DesAddr.uIpAddr) &&
  2685. (pTunnelF[l].InterfaceType == pMMFilter[j].InterfaceType)
  2686. )
  2687. {
  2688. //get the corresponding MMpolicy
  2689. pMMPolicy = NULL;
  2690. dwReturn = GetMMPolicyByID(g_szDynamicMachine, dwVersion, pMMFilter[j].gPolicyID, &pMMPolicy, NULL);
  2691. if(dwReturn != ERROR_SUCCESS)
  2692. {
  2693. BAIL_OUT;
  2694. }
  2695. //get the corresponding QMpolicy
  2696. dwReturn = GetQMPolicyByID(g_szDynamicMachine, dwVersion, pTunnelF[l].gPolicyID, 0, &pQMPolicy, NULL);
  2697. if(dwReturn == ERROR_SUCCESS)
  2698. {
  2699. pszQMName = pQMPolicy[0].pszPolicyName;
  2700. }
  2701. else
  2702. {
  2703. //If the corresponding policy is not found, pass NULL so that it is not printed.
  2704. pszQMName = NULL;
  2705. dwReturn = ERROR_SUCCESS;
  2706. }
  2707. dwActionFlag = 0;
  2708. if(!bPrint)
  2709. {
  2710. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_TUNNEL_RULE_HEADING);
  2711. bPrint = TRUE;
  2712. }
  2713. dwTempCnt++;
  2714. //print tunnel rule details
  2715. dwReturn = PrintTunnelRuleFilter(&pMMFilter[j], &pMMPolicy[0], pTunnelF[l], pszQMName, addressHash, bResolveDNS);
  2716. bNameFin = TRUE;
  2717. bMMFound = TRUE;
  2718. if(pQMPolicy == NULL)
  2719. {
  2720. SPDApiBufferFree(pQMPolicy);
  2721. pQMPolicy = NULL;
  2722. }
  2723. if(pMMPolicy)
  2724. {
  2725. SPDApiBufferFree(pMMPolicy);
  2726. pMMPolicy = NULL;
  2727. }
  2728. }
  2729. }
  2730. if(pMMFilter)
  2731. {
  2732. SPDApiBufferFree(pMMFilter);
  2733. pMMFilter = NULL;
  2734. }
  2735. }
  2736. }
  2737. SPDApiBufferFree(pTunnelF);
  2738. pTunnelF = NULL;
  2739. }
  2740. }
  2741. error:
  2742. if(dwTempCnt > 0)
  2743. {
  2744. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_NO_OF_TUNNEL_FILTERS, dwTempCnt);
  2745. }
  2746. // error path clean up
  2747. if(pTunnelF)
  2748. {
  2749. SPDApiBufferFree(pTunnelF);
  2750. pTunnelF = NULL;
  2751. }
  2752. if(pQMPolicy == NULL)
  2753. {
  2754. SPDApiBufferFree(pQMPolicy);
  2755. pQMPolicy = NULL;
  2756. }
  2757. if(pMMFilter)
  2758. {
  2759. SPDApiBufferFree(pMMFilter);
  2760. pMMFilter = NULL;
  2761. }
  2762. if(pMMPolicy)
  2763. {
  2764. SPDApiBufferFree(pMMPolicy);
  2765. pMMPolicy = NULL;
  2766. }
  2767. return dwReturn;
  2768. }
  2769. ///////////////////////////////////////////////////////////////////////////////////////////
  2770. //
  2771. // Function : PrintTunnelRuleFilter
  2772. //
  2773. // Date of Creation: 11-21-2001
  2774. //
  2775. // Parameters :
  2776. // IN PMM_FILTER pMMFltr,
  2777. // IN PIPSEC_MM_POLICY pMMPol,
  2778. // IN TUNNEL_FILTER TunnelF,
  2779. // IN LPWSTR pszQMName,
  2780. // IN NshHashTable& addressHash
  2781. // IN BOOL bResolveDNS
  2782. //
  2783. // Return : DWORD
  2784. //
  2785. // Description : This function prints Tunnel filter details
  2786. //
  2787. // Date Author Comments
  2788. //
  2789. //////////////////////////////////////////////////////////////////////////////////////////
  2790. DWORD
  2791. PrintTunnelRuleFilter(
  2792. IN PMM_FILTER pMMFltr,
  2793. IN PIPSEC_MM_POLICY pMMPol,
  2794. IN TUNNEL_FILTER TunnelF,
  2795. IN LPWSTR pszQMName,
  2796. IN NshHashTable& addressHash,
  2797. IN BOOL bResolveDNS
  2798. )
  2799. {
  2800. DWORD dwReturn = ERROR_SUCCESS;
  2801. DWORD i = 0;
  2802. DWORD dwVersion = 0;
  2803. LPTSTR pszCertStr = NULL;
  2804. PINT_MM_AUTH_METHODS pIntMMAuth = NULL;
  2805. PMM_AUTH_METHODS pMMAM = NULL;
  2806. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_NEWLINE);
  2807. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_UNDERLINE);
  2808. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_NEWLINE);
  2809. //Print MMMFilter name
  2810. if(pMMFltr)
  2811. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMFILTER_NAME, pMMFltr->pszFilterName);
  2812. //Print Tunnel FilterName
  2813. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMF_NAME, TunnelF.pszFilterName);
  2814. //Print Connection Type
  2815. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_CONN_HEADING);
  2816. switch(TunnelF.InterfaceType)
  2817. {
  2818. case INTERFACE_TYPE_ALL:
  2819. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_CONN_ALL);
  2820. break;
  2821. case INTERFACE_TYPE_LAN:
  2822. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_CONN_LAN);
  2823. break;
  2824. case INTERFACE_TYPE_DIALUP:
  2825. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_CONN_DIALUP);
  2826. break;
  2827. default:
  2828. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_CONN_UNKNOWN);
  2829. break;
  2830. }
  2831. //Print Source Address
  2832. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_SRC_ADDR_HEADING);
  2833. PrintAddr(TunnelF.SrcAddr, addressHash, bResolveDNS);
  2834. if(!bResolveDNS)
  2835. {
  2836. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMSAS_LEFTBRACKET);
  2837. PrintMask(TunnelF.SrcAddr);
  2838. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMSAS_RIGHTBRACKET);
  2839. }
  2840. //Print Destination Address
  2841. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_DST_ADDR_HEADING);
  2842. PrintAddr(TunnelF.DesAddr, addressHash, bResolveDNS);
  2843. if(!bResolveDNS)
  2844. {
  2845. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMSAS_LEFTBRACKET);
  2846. PrintMask(TunnelF.DesAddr);
  2847. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMSAS_RIGHTBRACKET);
  2848. }
  2849. //Print Tunnel Src
  2850. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_TUNNEL_SRC);
  2851. PrintAddr(TunnelF.SrcTunnelAddr, addressHash, bResolveDNS);
  2852. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_TUNNEL_DST);
  2853. PrintAddr(TunnelF.DesTunnelAddr, addressHash, bResolveDNS);
  2854. //Print Protocol
  2855. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_PROTO_HEADING);
  2856. switch(TunnelF.Protocol.dwProtocol)
  2857. {
  2858. case PROT_ID_ICMP:
  2859. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_ICMP);
  2860. break;
  2861. case PROT_ID_TCP:
  2862. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_TCP);
  2863. break;
  2864. case PROT_ID_UDP:
  2865. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_UDP);
  2866. break;
  2867. case PROT_ID_RAW:
  2868. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_RAW);
  2869. break;
  2870. case PROT_ID_ANY:
  2871. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_ANY);
  2872. break;
  2873. default:
  2874. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_DEFAULT_PROTOCOL, TunnelF.Protocol.dwProtocol);
  2875. break;
  2876. }
  2877. //Print Src, Des Port
  2878. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_SRC_DST_PORT,TunnelF.SrcPort.wPort,TunnelF.DesPort.wPort);
  2879. //Print Mirror
  2880. if(TunnelF.bCreateMirror)
  2881. {
  2882. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MIRR_YES);
  2883. }
  2884. else
  2885. {
  2886. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MIRR_NO);
  2887. }
  2888. if(pMMPol)
  2889. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMP_NAME,pMMPol->pszPolicyName);
  2890. //Print Authentication Methods.
  2891. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_AUTH_HEADING);
  2892. if(pMMFltr)
  2893. {
  2894. dwReturn = GetMMAuthMethods(g_szDynamicMachine, dwVersion, pMMFltr->gMMAuthID, &pMMAM, NULL);
  2895. if (dwReturn != ERROR_SUCCESS)
  2896. {
  2897. BAIL_OUT;
  2898. }
  2899. dwReturn = ConvertExtMMAuthToInt(pMMAM, &pIntMMAuth);
  2900. if (dwReturn != ERROR_SUCCESS)
  2901. {
  2902. BAIL_OUT;
  2903. }
  2904. for (i = 0; i < pIntMMAuth[0].dwNumAuthInfos; i++)
  2905. {
  2906. switch(pIntMMAuth[0].pAuthenticationInfo[i].AuthMethod)
  2907. {
  2908. case IKE_PRESHARED_KEY:
  2909. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_PRE_KEY_HEADING);
  2910. break;
  2911. case IKE_DSS_SIGNATURE:
  2912. case IKE_RSA_SIGNATURE:
  2913. case IKE_RSA_ENCRYPTION:
  2914. dwReturn = DecodeCertificateName(pIntMMAuth[0].pAuthenticationInfo[i].pAuthInfo, pIntMMAuth[0].pAuthenticationInfo[i].dwAuthInfoSize, &pszCertStr);
  2915. if (dwReturn != ERROR_SUCCESS)
  2916. {
  2917. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_UNKNOWN_CERT);
  2918. }
  2919. else
  2920. {
  2921. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_NEWLINE_TAB);
  2922. if (pszCertStr)
  2923. {
  2924. DisplayCertInfo(pszCertStr, pIntMMAuth->pAuthenticationInfo[i].dwAuthFlags);
  2925. delete [] pszCertStr;
  2926. pszCertStr = NULL;
  2927. }
  2928. }
  2929. break;
  2930. case IKE_SSPI:
  2931. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_KERB);
  2932. break;
  2933. default:
  2934. break;
  2935. }
  2936. }
  2937. }
  2938. error:
  2939. //Print Security Methods
  2940. if(pMMPol)
  2941. {
  2942. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_SEC_METHOD_HEADING);
  2943. // Count
  2944. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_OFFER_CNT,pMMPol->dwOfferCount);
  2945. if(IsDefaultMMOffers(*pMMPol))
  2946. {
  2947. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_DEFAULT_OFFER);
  2948. }
  2949. for (i = 0; i < pMMPol->dwOfferCount; i++)
  2950. {
  2951. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_NEWLINE);
  2952. PrintMMFilterOffer(pMMPol->pOffers[i]);
  2953. }
  2954. }
  2955. // Print Qm Policy Name
  2956. if(pszQMName != NULL)
  2957. {
  2958. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_NAME,pszQMName);
  2959. }
  2960. //Print Action Flag
  2961. switch(TunnelF.InboundFilterAction)
  2962. {
  2963. case PASS_THRU:
  2964. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_INBOUND_PASSTHRU);
  2965. break;
  2966. case NEGOTIATE_SECURITY:
  2967. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_INBOUND_NEGOTIATE);
  2968. break;
  2969. case BLOCKING:
  2970. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_INBOUND_BLOCK);
  2971. break;
  2972. default:
  2973. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_INBOUND_UNKNOWN);
  2974. break;
  2975. }
  2976. switch(TunnelF.OutboundFilterAction)
  2977. {
  2978. case PASS_THRU:
  2979. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_OUTBOUND_PASSTHRU);
  2980. break;
  2981. case NEGOTIATE_SECURITY:
  2982. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_OUTBOUND_NEGOTIATE);
  2983. break;
  2984. case BLOCKING:
  2985. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_OUTBOUND_BLOCK);
  2986. break;
  2987. default:
  2988. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_OUTBOUND_UNKNOWN);
  2989. break;
  2990. }
  2991. if(pIntMMAuth)
  2992. {
  2993. FreeIntMMAuthMethods(pIntMMAuth);
  2994. pIntMMAuth = NULL;
  2995. }
  2996. if(pMMAM)
  2997. {
  2998. SPDApiBufferFree(pMMAM);
  2999. pMMAM = NULL;
  3000. }
  3001. return dwReturn;
  3002. }
  3003. ///////////////////////////////////////////////////////////////////////////////////////////
  3004. //
  3005. // Function : PrintTransportRuleFilter
  3006. //
  3007. // Date of Creation: 11-21-2001
  3008. //
  3009. // Parameters :
  3010. // IN PMM_FILTER pMMFltr,
  3011. // IN PIPSEC_MM_POLICY pMMPol,
  3012. // IN TRANSPORT_FILTER TransF,
  3013. // IN LPWSTR pszQMName,
  3014. // IN NshHashTable& addressHash
  3015. // IN BOOL bResolveDNS
  3016. //
  3017. // Return : DWORD
  3018. //
  3019. // Description : This function prints Transport filter details
  3020. //
  3021. // Date Author Comments
  3022. //
  3023. //////////////////////////////////////////////////////////////////////////////////////////
  3024. DWORD
  3025. PrintTransportRuleFilter(
  3026. IN PMM_FILTER pMMFltr,
  3027. IN PIPSEC_MM_POLICY pMMPol,
  3028. IN TRANSPORT_FILTER TransF,
  3029. IN LPWSTR pszQMName,
  3030. IN NshHashTable& addressHash,
  3031. IN BOOL bResolveDNS
  3032. )
  3033. {
  3034. DWORD dwReturn = ERROR_SUCCESS;
  3035. DWORD i = 0;
  3036. DWORD dwVersion = 0;
  3037. LPTSTR pszCertStr = NULL;
  3038. PINT_MM_AUTH_METHODS pIntMMAuth = NULL;
  3039. PMM_AUTH_METHODS pMMAM = NULL;
  3040. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_NEWLINE);
  3041. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_UNDERLINE);
  3042. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_NEWLINE);
  3043. //Print Mmfilter name
  3044. if(pMMFltr)
  3045. {
  3046. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMFILTER_NAME, pMMFltr->pszFilterName);
  3047. }
  3048. //Print Tunnel FilterName
  3049. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMF_NAME, TransF.pszFilterName);
  3050. //Print Connection Type
  3051. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_CONN_HEADING);
  3052. switch(TransF.InterfaceType)
  3053. {
  3054. case INTERFACE_TYPE_ALL:
  3055. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_CONN_ALL);
  3056. break;
  3057. case INTERFACE_TYPE_LAN:
  3058. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_CONN_LAN);
  3059. break;
  3060. case INTERFACE_TYPE_DIALUP:
  3061. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_CONN_DIALUP);
  3062. break;
  3063. default:
  3064. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_CONN_UNKNOWN);
  3065. break;
  3066. }
  3067. //Print Source Address
  3068. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_SRC_ADDR_HEADING);
  3069. PrintAddr(TransF.SrcAddr, addressHash, bResolveDNS);
  3070. if(!bResolveDNS)
  3071. {
  3072. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMSAS_LEFTBRACKET);
  3073. PrintMask(TransF.SrcAddr);
  3074. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMSAS_RIGHTBRACKET);
  3075. }
  3076. //Print Destination Address
  3077. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_DST_ADDR_HEADING);
  3078. PrintAddr(TransF.DesAddr, addressHash, bResolveDNS);
  3079. if(!bResolveDNS)
  3080. {
  3081. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMSAS_LEFTBRACKET);
  3082. PrintMask(TransF.DesAddr);
  3083. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMSAS_RIGHTBRACKET);
  3084. }
  3085. //Print Protocol
  3086. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_PROTO_HEADING);
  3087. switch(TransF.Protocol.dwProtocol)
  3088. {
  3089. case PROT_ID_ICMP:
  3090. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_ICMP);
  3091. break;
  3092. case PROT_ID_TCP:
  3093. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_TCP);
  3094. break;
  3095. case PROT_ID_UDP:
  3096. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_UDP);
  3097. break;
  3098. case PROT_ID_RAW:
  3099. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_RAW);
  3100. break;
  3101. case PROT_ID_ANY:
  3102. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_ANY);
  3103. break;
  3104. default:
  3105. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_DEFAULT_PROTOCOL, TransF.Protocol.dwProtocol);
  3106. break;
  3107. }
  3108. //Print Src, Des Port
  3109. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_SRC_DST_PORT,TransF.SrcPort.wPort,TransF.DesPort.wPort);
  3110. //Print Mirror
  3111. if(TransF.bCreateMirror)
  3112. {
  3113. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MIRR_YES);
  3114. }
  3115. else
  3116. {
  3117. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MIRR_NO);
  3118. }
  3119. if(pMMPol)
  3120. {
  3121. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMP_NAME,pMMPol->pszPolicyName);
  3122. }
  3123. //Print Authentication Methods.
  3124. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_AUTH_HEADING);
  3125. if(pMMFltr)
  3126. {
  3127. dwReturn = GetMMAuthMethods(g_szDynamicMachine, dwVersion, pMMFltr->gMMAuthID, &pMMAM, NULL);
  3128. if (dwReturn != ERROR_SUCCESS)
  3129. {
  3130. BAIL_OUT;
  3131. }
  3132. dwReturn = ConvertExtMMAuthToInt(pMMAM, &pIntMMAuth);
  3133. if (dwReturn != ERROR_SUCCESS)
  3134. {
  3135. BAIL_OUT;
  3136. }
  3137. for (i = 0; i < pIntMMAuth[0].dwNumAuthInfos; i++)
  3138. {
  3139. switch(pIntMMAuth[0].pAuthenticationInfo[i].AuthMethod)
  3140. {
  3141. case IKE_PRESHARED_KEY:
  3142. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_PRE_KEY_HEADING);
  3143. break;
  3144. case IKE_DSS_SIGNATURE:
  3145. case IKE_RSA_SIGNATURE:
  3146. case IKE_RSA_ENCRYPTION:
  3147. dwReturn = DecodeCertificateName(pIntMMAuth[0].pAuthenticationInfo[i].pAuthInfo, pIntMMAuth[0].pAuthenticationInfo[i].dwAuthInfoSize, &pszCertStr);
  3148. if (dwReturn != ERROR_SUCCESS)
  3149. {
  3150. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_UNKNOWN_CERT);
  3151. }
  3152. else
  3153. {
  3154. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_NEWLINE_TAB);
  3155. if (pszCertStr)
  3156. {
  3157. DisplayCertInfo(pszCertStr, pIntMMAuth->pAuthenticationInfo[i].dwAuthFlags);
  3158. delete [] pszCertStr;
  3159. pszCertStr = NULL;
  3160. }
  3161. }
  3162. break;
  3163. case IKE_SSPI:
  3164. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_KERB);
  3165. break;
  3166. default:
  3167. break;
  3168. }
  3169. }
  3170. }
  3171. error:
  3172. // Print Security Methods
  3173. // Count
  3174. if(pMMPol)
  3175. {
  3176. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_SEC_METHOD_HEADING);
  3177. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_OFFER_CNT,pMMPol->dwOfferCount);
  3178. if(IsDefaultMMOffers(*pMMPol))
  3179. {
  3180. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_DEFAULT_OFFER);
  3181. }
  3182. for (i = 0; i < pMMPol->dwOfferCount; i++)
  3183. {
  3184. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_NEWLINE);
  3185. PrintMMFilterOffer(pMMPol->pOffers[i]);
  3186. }
  3187. }
  3188. // Print Qm Policy Name
  3189. if(pszQMName != NULL)
  3190. {
  3191. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_NAME,pszQMName);
  3192. }
  3193. //Print Action Flag
  3194. switch(TransF.InboundFilterAction)
  3195. {
  3196. case PASS_THRU:
  3197. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_INBOUND_PASSTHRU);
  3198. break;
  3199. case NEGOTIATE_SECURITY:
  3200. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_INBOUND_NEGOTIATE);
  3201. break;
  3202. case BLOCKING:
  3203. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_INBOUND_BLOCK);
  3204. break;
  3205. default:
  3206. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_INBOUND_UNKNOWN);
  3207. break;
  3208. }
  3209. switch(TransF.OutboundFilterAction)
  3210. {
  3211. case PASS_THRU:
  3212. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_OUTBOUND_PASSTHRU);
  3213. break;
  3214. case NEGOTIATE_SECURITY:
  3215. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_OUTBOUND_NEGOTIATE);
  3216. break;
  3217. case BLOCKING:
  3218. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_OUTBOUND_BLOCK);
  3219. break;
  3220. default:
  3221. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_OUTBOUND_UNKNOWN);
  3222. break;
  3223. }
  3224. if(pIntMMAuth)
  3225. {
  3226. FreeIntMMAuthMethods(pIntMMAuth);
  3227. pIntMMAuth = NULL;
  3228. }
  3229. if(pMMAM)
  3230. {
  3231. SPDApiBufferFree(pMMAM);
  3232. pMMAM = NULL;
  3233. }
  3234. return dwReturn;
  3235. }
  3236. ///////////////////////////////////////////////////////////////////////////////////////////
  3237. //
  3238. // Function : ShowStats
  3239. //
  3240. // Date of Creation: 9-3-2001
  3241. //
  3242. // Parameters : IN DWORD dwShow
  3243. //
  3244. // Return : DWORD
  3245. //
  3246. // Description : This function calls appropriate IKE and IPSEC statistics display.
  3247. //
  3248. // Date Author Comments
  3249. //
  3250. //////////////////////////////////////////////////////////////////////////////////////////
  3251. DWORD
  3252. ShowStats(
  3253. IN DWORD dwShow
  3254. )
  3255. {
  3256. DWORD dwReturn = ERROR_SUCCESS; // assume success
  3257. if(dwShow != STATS_IPSEC) //is the show is for IKE or all
  3258. {
  3259. dwReturn = PrintIkeStats();
  3260. if(dwReturn != ERROR_SUCCESS)
  3261. {
  3262. BAIL_OUT;
  3263. }
  3264. }
  3265. if(dwShow != STATS_IKE) //is the show is for IPSEC or all
  3266. {
  3267. dwReturn = PrintIpsecStats();
  3268. }
  3269. error:
  3270. return dwReturn;
  3271. }
  3272. ///////////////////////////////////////////////////////////////////////////////////////////
  3273. //
  3274. //Function: PrintIkeStats
  3275. //
  3276. //Date of Creation: 28-1-2002
  3277. //
  3278. //Parameters:
  3279. //
  3280. //Return: DWORD
  3281. //
  3282. //Description: This function Prints IkeStatistics
  3283. //
  3284. // Date Author Comments
  3285. //
  3286. //////////////////////////////////////////////////////////////////////////////////////////
  3287. DWORD
  3288. PrintIkeStats(
  3289. VOID
  3290. )
  3291. {
  3292. DWORD dwReturn = ERROR_SUCCESS; // assume success
  3293. DWORD dwVersion = 0;
  3294. LPSTR pszLLString = NULL;
  3295. IKE_STATISTICS IKEStats;
  3296. //Query IKE Statistics
  3297. dwReturn = QueryIKEStatistics(g_szDynamicMachine,dwVersion, &IKEStats, NULL);
  3298. if (dwReturn != ERROR_SUCCESS)
  3299. {
  3300. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_NOT_FOUND_MSG);
  3301. BAIL_OUT;
  3302. }
  3303. //Heading
  3304. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_HEADING);
  3305. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_IKE_HEADING_UNDERLINE);
  3306. //Print IKE statistics
  3307. pszLLString = LongLongToString(0, IKEStats.dwOakleyMainModes, 1);
  3308. if(pszLLString)
  3309. {
  3310. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_MAIN_MODE, pszLLString);
  3311. free(pszLLString);
  3312. pszLLString = NULL;
  3313. }
  3314. else
  3315. {
  3316. dwReturn = ERROR_OUTOFMEMORY;
  3317. BAIL_OUT;
  3318. }
  3319. pszLLString = LongLongToString(0, IKEStats.dwOakleyQuickModes, 1);
  3320. if(pszLLString)
  3321. {
  3322. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_QUICK_MODE, pszLLString);
  3323. free(pszLLString);
  3324. pszLLString = NULL;
  3325. }
  3326. else
  3327. {
  3328. dwReturn = ERROR_OUTOFMEMORY;
  3329. BAIL_OUT;
  3330. }
  3331. pszLLString = LongLongToString(0, IKEStats.dwSoftAssociations, 1);
  3332. if(pszLLString)
  3333. {
  3334. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_SOFT_SA, pszLLString);
  3335. free(pszLLString);
  3336. pszLLString = NULL;
  3337. }
  3338. else
  3339. {
  3340. dwReturn = ERROR_OUTOFMEMORY;
  3341. BAIL_OUT;
  3342. }
  3343. pszLLString = LongLongToString(0, IKEStats.dwAuthenticationFailures, 1);
  3344. if(pszLLString)
  3345. {
  3346. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_AUTH_FAIL, pszLLString);
  3347. free(pszLLString);
  3348. pszLLString = NULL;
  3349. }
  3350. else
  3351. {
  3352. dwReturn = ERROR_OUTOFMEMORY;
  3353. BAIL_OUT;
  3354. }
  3355. pszLLString = LongLongToString(0, IKEStats.dwActiveAcquire, 1);
  3356. if(pszLLString)
  3357. {
  3358. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_ACTIVE_ACQUIRE, pszLLString);
  3359. free(pszLLString);
  3360. pszLLString = NULL;
  3361. }
  3362. else
  3363. {
  3364. dwReturn = ERROR_OUTOFMEMORY;
  3365. BAIL_OUT;
  3366. }
  3367. pszLLString = LongLongToString(0, IKEStats.dwActiveReceive, 1);
  3368. if(pszLLString)
  3369. {
  3370. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_ACTIVE_RECEIVE, pszLLString);
  3371. free(pszLLString);
  3372. pszLLString = NULL;
  3373. }
  3374. else
  3375. {
  3376. dwReturn = ERROR_OUTOFMEMORY;
  3377. BAIL_OUT;
  3378. }
  3379. pszLLString = LongLongToString(0, IKEStats.dwAcquireFail, 1);
  3380. if(pszLLString)
  3381. {
  3382. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_ACQUIRE_FAIL, pszLLString);
  3383. free(pszLLString);
  3384. pszLLString = NULL;
  3385. }
  3386. else
  3387. {
  3388. dwReturn = ERROR_OUTOFMEMORY;
  3389. BAIL_OUT;
  3390. }
  3391. pszLLString = LongLongToString(0, IKEStats.dwReceiveFail, 1);
  3392. if(pszLLString)
  3393. {
  3394. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_RECEIVE_FAIL, pszLLString);
  3395. free(pszLLString);
  3396. pszLLString = NULL;
  3397. }
  3398. else
  3399. {
  3400. dwReturn = ERROR_OUTOFMEMORY;
  3401. BAIL_OUT;
  3402. }
  3403. pszLLString = LongLongToString(0, IKEStats.dwSendFail, 1);
  3404. if(pszLLString)
  3405. {
  3406. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_SEND_FAIL, pszLLString);
  3407. free(pszLLString);
  3408. pszLLString = NULL;
  3409. }
  3410. else
  3411. {
  3412. dwReturn = ERROR_OUTOFMEMORY;
  3413. BAIL_OUT;
  3414. }
  3415. pszLLString = LongLongToString(0, IKEStats.dwAcquireHeapSize, 1);
  3416. if(pszLLString)
  3417. {
  3418. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_ACQ_HEAP_SIZE, pszLLString);
  3419. free(pszLLString);
  3420. pszLLString = NULL;
  3421. }
  3422. else
  3423. {
  3424. dwReturn = ERROR_OUTOFMEMORY;
  3425. BAIL_OUT;
  3426. }
  3427. pszLLString = LongLongToString(0, IKEStats.dwReceiveHeapSize, 1);
  3428. if(pszLLString)
  3429. {
  3430. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_RECEIVE_HEAP_SIZE, pszLLString);
  3431. free(pszLLString);
  3432. pszLLString = NULL;
  3433. }
  3434. else
  3435. {
  3436. dwReturn = ERROR_OUTOFMEMORY;
  3437. BAIL_OUT;
  3438. }
  3439. pszLLString = LongLongToString(0, IKEStats.dwNegotiationFailures, 1);
  3440. if(pszLLString)
  3441. {
  3442. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_NEG_FAIL, pszLLString);
  3443. free(pszLLString);
  3444. pszLLString = NULL;
  3445. }
  3446. else
  3447. {
  3448. dwReturn = ERROR_OUTOFMEMORY;
  3449. BAIL_OUT;
  3450. }
  3451. pszLLString = LongLongToString(0, IKEStats.dwInvalidCookiesReceived, 1);
  3452. if(pszLLString)
  3453. {
  3454. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_INVALID_COOKIE, pszLLString);
  3455. free(pszLLString);
  3456. pszLLString = NULL;
  3457. }
  3458. else
  3459. {
  3460. dwReturn = ERROR_OUTOFMEMORY;
  3461. BAIL_OUT;
  3462. }
  3463. pszLLString = LongLongToString(0, IKEStats.dwTotalAcquire, 1);
  3464. if(pszLLString)
  3465. {
  3466. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_TOTAL_ACQUIRE, pszLLString);
  3467. free(pszLLString);
  3468. pszLLString = NULL;
  3469. }
  3470. else
  3471. {
  3472. dwReturn = ERROR_OUTOFMEMORY;
  3473. BAIL_OUT;
  3474. }
  3475. pszLLString = LongLongToString(0, IKEStats.dwTotalGetSpi, 1);
  3476. if(pszLLString)
  3477. {
  3478. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_TOT_GET_SPI, pszLLString);
  3479. free(pszLLString);
  3480. pszLLString = NULL;
  3481. }
  3482. else
  3483. {
  3484. dwReturn = ERROR_OUTOFMEMORY;
  3485. BAIL_OUT;
  3486. }
  3487. pszLLString = LongLongToString(0, IKEStats.dwTotalKeyAdd, 1);
  3488. if(pszLLString)
  3489. {
  3490. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_TOT_KEY_ADD, pszLLString);
  3491. free(pszLLString);
  3492. pszLLString = NULL;
  3493. }
  3494. else
  3495. {
  3496. dwReturn = ERROR_OUTOFMEMORY;
  3497. BAIL_OUT;
  3498. }
  3499. pszLLString = LongLongToString(0, IKEStats.dwTotalKeyUpdate, 1);
  3500. if(pszLLString)
  3501. {
  3502. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_TOT_KEY_UPDATE, pszLLString);
  3503. free(pszLLString);
  3504. pszLLString = NULL;
  3505. }
  3506. else
  3507. {
  3508. dwReturn = ERROR_OUTOFMEMORY;
  3509. BAIL_OUT;
  3510. }
  3511. pszLLString = LongLongToString(0, IKEStats.dwGetSpiFail, 1);
  3512. if(pszLLString)
  3513. {
  3514. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_GET_SPI_FAIL, pszLLString);
  3515. free(pszLLString);
  3516. pszLLString = NULL;
  3517. }
  3518. else
  3519. {
  3520. dwReturn = ERROR_OUTOFMEMORY;
  3521. BAIL_OUT;
  3522. }
  3523. pszLLString = LongLongToString(0, IKEStats.dwKeyAddFail, 1);
  3524. if(pszLLString)
  3525. {
  3526. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_KEY_ADD_FAIL, pszLLString);
  3527. free(pszLLString);
  3528. pszLLString = NULL;
  3529. }
  3530. else
  3531. {
  3532. dwReturn = ERROR_OUTOFMEMORY;
  3533. BAIL_OUT;
  3534. }
  3535. pszLLString = LongLongToString(0, IKEStats.dwKeyUpdateFail, 1);
  3536. if(pszLLString)
  3537. {
  3538. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_KEY_UPDATE_FAIL, pszLLString);
  3539. free(pszLLString);
  3540. pszLLString = NULL;
  3541. }
  3542. else
  3543. {
  3544. dwReturn = ERROR_OUTOFMEMORY;
  3545. BAIL_OUT;
  3546. }
  3547. pszLLString = LongLongToString(0, IKEStats.dwIsadbListSize, 1);
  3548. if(pszLLString)
  3549. {
  3550. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_DB_LIST, pszLLString);
  3551. free(pszLLString);
  3552. pszLLString = NULL;
  3553. }
  3554. else
  3555. {
  3556. dwReturn = ERROR_OUTOFMEMORY;
  3557. BAIL_OUT;
  3558. }
  3559. pszLLString = LongLongToString(0, IKEStats.dwConnListSize, 1);
  3560. if(pszLLString)
  3561. {
  3562. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_CONN_LIST_SIZE, pszLLString);
  3563. free(pszLLString);
  3564. pszLLString = NULL;
  3565. }
  3566. else
  3567. {
  3568. dwReturn = ERROR_OUTOFMEMORY;
  3569. BAIL_OUT;
  3570. }
  3571. pszLLString = LongLongToString(0, IKEStats.dwInvalidPacketsReceived, 1);
  3572. if(pszLLString)
  3573. {
  3574. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_INVLD_PKTS, pszLLString);
  3575. free(pszLLString);
  3576. pszLLString = NULL;
  3577. }
  3578. else
  3579. {
  3580. dwReturn = ERROR_OUTOFMEMORY;
  3581. BAIL_OUT;
  3582. }
  3583. error:
  3584. return dwReturn;
  3585. }
  3586. ///////////////////////////////////////////////////////////////////////////////////////////
  3587. //
  3588. //Function: PrintIpsecStats
  3589. //
  3590. //Date of Creation: 28-1-2002
  3591. //
  3592. //Parameters:
  3593. //
  3594. //Return: DWORD
  3595. //
  3596. //Description: This function Prints IpsecStatistics
  3597. //
  3598. // Date Author Comments
  3599. //
  3600. //////////////////////////////////////////////////////////////////////////////////////////
  3601. DWORD
  3602. PrintIpsecStats(
  3603. VOID
  3604. )
  3605. {
  3606. DWORD dwReturn = ERROR_SUCCESS; // assume success
  3607. DWORD dwVersion = 0;
  3608. LPSTR pszLLString = NULL;
  3609. PIPSEC_STATISTICS pIPSecStats = NULL;
  3610. dwReturn = QueryIPSecStatistics(g_szDynamicMachine, dwVersion, &pIPSecStats, NULL);
  3611. //Query IPSec Statistics
  3612. if (dwReturn != ERROR_SUCCESS)
  3613. {
  3614. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_IPSEC_NOT_FOUND);
  3615. BAIL_OUT;
  3616. }
  3617. //Heading
  3618. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_IPSEC_HEADING);
  3619. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_IPSEC_HEADING_UNDERLINE);
  3620. //Print IPSec statistics.
  3621. pszLLString = LongLongToString(0, pIPSecStats->dwNumActiveAssociations, 1);
  3622. if(pszLLString)
  3623. {
  3624. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_ACTIVE_ASSOC, pszLLString);
  3625. free(pszLLString);
  3626. pszLLString = NULL;
  3627. }
  3628. else
  3629. {
  3630. dwReturn = ERROR_OUTOFMEMORY;
  3631. BAIL_OUT;
  3632. }
  3633. pszLLString = LongLongToString(0, pIPSecStats->dwNumOffloadedSAs, 1);
  3634. if(pszLLString)
  3635. {
  3636. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_OFFLOAD_SAS, pszLLString);
  3637. free(pszLLString);
  3638. pszLLString = NULL;
  3639. }
  3640. else
  3641. {
  3642. dwReturn = ERROR_OUTOFMEMORY;
  3643. BAIL_OUT;
  3644. }
  3645. pszLLString = LongLongToString(0, pIPSecStats->dwNumPendingKeyOps, 1);
  3646. if(pszLLString)
  3647. {
  3648. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_PEND_KEY, pszLLString);
  3649. free(pszLLString);
  3650. pszLLString = NULL;
  3651. }
  3652. else
  3653. {
  3654. dwReturn = ERROR_OUTOFMEMORY;
  3655. BAIL_OUT;
  3656. }
  3657. pszLLString = LongLongToString(0, pIPSecStats->dwNumKeyAdditions, 1);
  3658. if(pszLLString)
  3659. {
  3660. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_KEY_ADDS, pszLLString);
  3661. free(pszLLString);
  3662. pszLLString = NULL;
  3663. }
  3664. else
  3665. {
  3666. dwReturn = ERROR_OUTOFMEMORY;
  3667. BAIL_OUT;
  3668. }
  3669. pszLLString = LongLongToString(0, pIPSecStats->dwNumKeyDeletions, 1);
  3670. if(pszLLString)
  3671. {
  3672. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_KEY_DELETES, pszLLString);
  3673. free(pszLLString);
  3674. pszLLString = NULL;
  3675. }
  3676. else
  3677. {
  3678. dwReturn = ERROR_OUTOFMEMORY;
  3679. BAIL_OUT;
  3680. }
  3681. pszLLString = LongLongToString(0, pIPSecStats->dwNumReKeys, 1);
  3682. if(pszLLString)
  3683. {
  3684. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_REKEYS, pszLLString);
  3685. free(pszLLString);
  3686. pszLLString = NULL;
  3687. }
  3688. else
  3689. {
  3690. dwReturn = ERROR_OUTOFMEMORY;
  3691. BAIL_OUT;
  3692. }
  3693. pszLLString = LongLongToString(0, pIPSecStats->dwNumActiveTunnels, 1);
  3694. if(pszLLString)
  3695. {
  3696. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_ACT_TUNNEL, pszLLString);
  3697. free(pszLLString);
  3698. pszLLString = NULL;
  3699. }
  3700. else
  3701. {
  3702. dwReturn = ERROR_OUTOFMEMORY;
  3703. BAIL_OUT;
  3704. }
  3705. pszLLString = LongLongToString(0, pIPSecStats->dwNumBadSPIPackets, 1);
  3706. if(pszLLString)
  3707. {
  3708. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_BAD_SPI, pszLLString);
  3709. free(pszLLString);
  3710. pszLLString = NULL;
  3711. }
  3712. else
  3713. {
  3714. dwReturn = ERROR_OUTOFMEMORY;
  3715. BAIL_OUT;
  3716. }
  3717. pszLLString = LongLongToString(0, pIPSecStats->dwNumPacketsNotDecrypted, 1);
  3718. if(pszLLString)
  3719. {
  3720. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_NOT_DECRYPT, pszLLString);
  3721. free(pszLLString);
  3722. pszLLString = NULL;
  3723. }
  3724. else
  3725. {
  3726. dwReturn = ERROR_OUTOFMEMORY;
  3727. BAIL_OUT;
  3728. }
  3729. pszLLString = LongLongToString(0, pIPSecStats->dwNumPacketsNotAuthenticated, 1);
  3730. if(pszLLString)
  3731. {
  3732. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_NOT_AUTH, pszLLString);
  3733. free(pszLLString);
  3734. pszLLString = NULL;
  3735. }
  3736. else
  3737. {
  3738. dwReturn = ERROR_OUTOFMEMORY;
  3739. BAIL_OUT;
  3740. }
  3741. pszLLString = LongLongToString(0, pIPSecStats->dwNumPacketsWithReplayDetection, 1);
  3742. if(pszLLString)
  3743. {
  3744. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_REPLAY, pszLLString);
  3745. free(pszLLString);
  3746. pszLLString = NULL;
  3747. }
  3748. else
  3749. {
  3750. dwReturn = ERROR_OUTOFMEMORY;
  3751. BAIL_OUT;
  3752. }
  3753. pszLLString = LongLongToString(pIPSecStats->uConfidentialBytesSent.HighPart,pIPSecStats->uConfidentialBytesSent.LowPart, 1);
  3754. if(pszLLString)
  3755. {
  3756. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_CONF_BYTES_SENT, pszLLString);
  3757. free(pszLLString);
  3758. pszLLString = NULL;
  3759. }
  3760. else
  3761. {
  3762. dwReturn = ERROR_OUTOFMEMORY;
  3763. BAIL_OUT;
  3764. }
  3765. pszLLString = LongLongToString(pIPSecStats->uConfidentialBytesReceived.HighPart,pIPSecStats->uConfidentialBytesReceived.LowPart, 1);
  3766. if(pszLLString)
  3767. {
  3768. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_CONF_BYTES_RECV, pszLLString);
  3769. free(pszLLString);
  3770. pszLLString = NULL;
  3771. }
  3772. else
  3773. {
  3774. dwReturn = ERROR_OUTOFMEMORY;
  3775. BAIL_OUT;
  3776. }
  3777. pszLLString = LongLongToString(pIPSecStats->uAuthenticatedBytesSent.HighPart,pIPSecStats->uAuthenticatedBytesSent.LowPart, 1);
  3778. if(pszLLString)
  3779. {
  3780. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_AUTH_BYTES_SENT, pszLLString);
  3781. free(pszLLString);
  3782. pszLLString = NULL;
  3783. }
  3784. else
  3785. {
  3786. dwReturn = ERROR_OUTOFMEMORY;
  3787. BAIL_OUT;
  3788. }
  3789. pszLLString = LongLongToString(pIPSecStats->uAuthenticatedBytesReceived.HighPart,pIPSecStats->uAuthenticatedBytesReceived.LowPart, 1);
  3790. if(pszLLString)
  3791. {
  3792. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_AUTH_BYTE_RECV, pszLLString);
  3793. free(pszLLString);
  3794. pszLLString = NULL;
  3795. }
  3796. else
  3797. {
  3798. dwReturn = ERROR_OUTOFMEMORY;
  3799. BAIL_OUT;
  3800. }
  3801. pszLLString = LongLongToString(pIPSecStats->uTransportBytesSent.HighPart,pIPSecStats->uTransportBytesSent.LowPart, 1);
  3802. if(pszLLString)
  3803. {
  3804. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_TRANSPORT_BYTES_SENT, pszLLString);
  3805. free(pszLLString);
  3806. pszLLString = NULL;
  3807. }
  3808. else
  3809. {
  3810. dwReturn = ERROR_OUTOFMEMORY;
  3811. BAIL_OUT;
  3812. }
  3813. pszLLString = LongLongToString(pIPSecStats->uTransportBytesReceived.HighPart,pIPSecStats->uTransportBytesReceived.LowPart, 1);
  3814. if(pszLLString)
  3815. {
  3816. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_TRANSPORT_BYTES_RCVD, pszLLString);
  3817. free(pszLLString);
  3818. pszLLString = NULL;
  3819. }
  3820. else
  3821. {
  3822. dwReturn = ERROR_OUTOFMEMORY;
  3823. BAIL_OUT;
  3824. }
  3825. pszLLString = LongLongToString(pIPSecStats->uBytesSentInTunnels.HighPart,pIPSecStats->uBytesSentInTunnels.LowPart, 1);
  3826. if(pszLLString)
  3827. {
  3828. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_BYTES_SENT_TUNNEL, pszLLString);
  3829. free(pszLLString);
  3830. pszLLString = NULL;
  3831. }
  3832. else
  3833. {
  3834. dwReturn = ERROR_OUTOFMEMORY;
  3835. BAIL_OUT;
  3836. }
  3837. pszLLString = LongLongToString(pIPSecStats->uBytesReceivedInTunnels.HighPart,pIPSecStats->uBytesReceivedInTunnels.LowPart, 1);
  3838. if(pszLLString)
  3839. {
  3840. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_BYTES_RECV_TUNNEL, pszLLString);
  3841. free(pszLLString);
  3842. pszLLString = NULL;
  3843. }
  3844. else
  3845. {
  3846. dwReturn = ERROR_OUTOFMEMORY;
  3847. BAIL_OUT;
  3848. }
  3849. pszLLString = LongLongToString(pIPSecStats->uOffloadedBytesSent.HighPart,pIPSecStats->uOffloadedBytesSent.LowPart, 1);
  3850. if(pszLLString)
  3851. {
  3852. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_OFFLOAD_BYTES_SENT, pszLLString);
  3853. free(pszLLString);
  3854. pszLLString = NULL;
  3855. }
  3856. else
  3857. {
  3858. dwReturn = ERROR_OUTOFMEMORY;
  3859. BAIL_OUT;
  3860. }
  3861. pszLLString = LongLongToString(pIPSecStats->uOffloadedBytesReceived.HighPart,pIPSecStats->uOffloadedBytesReceived.LowPart, 1);
  3862. if(pszLLString)
  3863. {
  3864. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_STATS_OFFLOAD_BYTES_RECV, pszLLString);
  3865. free(pszLLString);
  3866. pszLLString = NULL;
  3867. }
  3868. else
  3869. {
  3870. dwReturn = ERROR_OUTOFMEMORY;
  3871. BAIL_OUT;
  3872. }
  3873. error:
  3874. if(pIPSecStats)
  3875. {
  3876. SPDApiBufferFree(pIPSecStats);
  3877. pIPSecStats = NULL;
  3878. }
  3879. return dwReturn;
  3880. }
  3881. ///////////////////////////////////////////////////////////////////////////////////////////
  3882. //
  3883. //Function: ShowMMSas
  3884. //
  3885. //Date of Creation: 9-3-2001
  3886. //
  3887. //Parameters:
  3888. // IN ADDR Source,
  3889. // IN ADDR Destination,
  3890. // IN BOOL bFormat
  3891. // IN NshHashTable& addressHash,
  3892. // IN BOOL bResolveDNS
  3893. //
  3894. //Return: DWORD
  3895. //
  3896. //Description: This function prepares data for MMsas
  3897. //
  3898. // Date Author Comments
  3899. //
  3900. //////////////////////////////////////////////////////////////////////////////////////////
  3901. DWORD
  3902. ShowMMSas(
  3903. IN ADDR Source,
  3904. IN ADDR Destination,
  3905. IN BOOL bFormat,
  3906. IN NshHashTable& addressHash,
  3907. IN BOOL bResolveDNS
  3908. )
  3909. {
  3910. DWORD dwReturn = ERROR_SUCCESS; // success by default
  3911. int i=0, j=0;
  3912. DWORD dwResumeHandle = 0; // handle for continuation calls
  3913. DWORD dwCount = 2; // counting objects here min 2 required
  3914. // for MM SA calls
  3915. DWORD dwReserved = 0; // reserved container
  3916. DWORD dwVersion = 0;
  3917. BOOL bHeader = FALSE;
  3918. BOOL bFound = FALSE;
  3919. _TCHAR szTime[BUFFER_SIZE] = {0};
  3920. PIPSEC_MM_SA pIPSecMMSA=NULL;
  3921. IPSEC_MM_SA mmsaTemplate;
  3922. memset(&mmsaTemplate, 0, sizeof(IPSEC_MM_SA));
  3923. // Display main mode SAs
  3924. time_t Time;
  3925. time(&Time);
  3926. FormatTime(Time,szTime);
  3927. // make the call(s)
  3928. for (i = 0; ;i+=dwCount)
  3929. {
  3930. dwReturn = EnumMMSAs(g_szDynamicMachine, dwVersion, &mmsaTemplate, 0, 0, &pIPSecMMSA, &dwCount, &dwReserved, &dwResumeHandle, NULL);
  3931. if (dwReturn == ERROR_NO_DATA || dwCount == 0)
  3932. {
  3933. if (i == 0)
  3934. {
  3935. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_NEWLINE);
  3936. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_SHOW_MMSAS_3);
  3937. bHeader = TRUE; //To Block other error message
  3938. }
  3939. dwReturn = ERROR_SUCCESS;
  3940. BAIL_OUT;
  3941. }
  3942. if (dwReturn != ERROR_SUCCESS)
  3943. {
  3944. BAIL_OUT;
  3945. }
  3946. for (j = 0; j < (int) dwCount; j++)
  3947. {
  3948. bHeader = FALSE;
  3949. //Enumerate all MMSAs
  3950. if((Source.AddrType == IP_ADDR_UNIQUE) && (Destination.AddrType == IP_ADDR_UNIQUE) &&
  3951. (Source.uIpAddr == 0xFFFFFFFF ) && (Destination.uIpAddr == 0xFFFFFFFF))
  3952. {
  3953. bFound = TRUE;
  3954. }
  3955. //Enumerate me/any as source
  3956. else if((Source.AddrType != IP_ADDR_UNIQUE) && (Destination.AddrType == IP_ADDR_UNIQUE) &&
  3957. (Source.uIpAddr != 0xFFFFFFFF ) && (Destination.uIpAddr == 0xFFFFFFFF))
  3958. {
  3959. if((pIPSecMMSA[j].Me.AddrType == Source.AddrType) &&
  3960. (pIPSecMMSA[j].Me.uIpAddr == Source.uIpAddr) && (pIPSecMMSA[j].Me.uSubNetMask == Source.uSubNetMask))
  3961. {
  3962. bFound = TRUE;
  3963. }
  3964. }
  3965. //Enumerate me/any as dst
  3966. else if((Source.AddrType == IP_ADDR_UNIQUE) && (Destination.AddrType != IP_ADDR_UNIQUE) &&
  3967. (Source.uIpAddr == 0xFFFFFFFF ) && (Destination.uIpAddr != 0xFFFFFFFF))
  3968. {
  3969. if( (pIPSecMMSA[j].Peer.AddrType == Destination.AddrType)
  3970. && (pIPSecMMSA[j].Peer.uIpAddr == Destination.uIpAddr)
  3971. && (pIPSecMMSA[j].Peer.uSubNetMask == Destination.uSubNetMask))
  3972. {
  3973. bFound = TRUE;
  3974. }
  3975. }
  3976. //Enumerate me/any as source/dst
  3977. else if((Source.AddrType != IP_ADDR_UNIQUE) && (Destination.AddrType != IP_ADDR_UNIQUE) &&
  3978. (Source.uIpAddr != 0xFFFFFFFF ) && (Destination.uIpAddr != 0xFFFFFFFF))
  3979. {
  3980. if((pIPSecMMSA[j].Me.AddrType == Source.AddrType)
  3981. && (pIPSecMMSA[j].Me.uIpAddr == Source.uIpAddr)
  3982. && (pIPSecMMSA[j].Me.uSubNetMask == Source.uSubNetMask)
  3983. && (pIPSecMMSA[j].Peer.AddrType == Destination.AddrType)
  3984. && (pIPSecMMSA[j].Peer.uIpAddr == Destination.uIpAddr)
  3985. && (pIPSecMMSA[j].Peer.uSubNetMask == Destination.uSubNetMask))
  3986. {
  3987. bFound = TRUE;
  3988. }
  3989. }
  3990. //Enumerate Only given source SPL_SRVR MMSAs
  3991. else if((Source.AddrType != IP_ADDR_UNIQUE) && (Destination.AddrType == IP_ADDR_UNIQUE) &&
  3992. (Source.uIpAddr == 0xFFFFFFFF ) && (Destination.uIpAddr == 0xFFFFFFFF))
  3993. {
  3994. if(pIPSecMMSA[j].Me.AddrType == Source.AddrType)
  3995. {
  3996. bFound = TRUE;
  3997. }
  3998. }
  3999. //Enumerate Only given dst SPL_SRVR MMSAs
  4000. else if((Source.AddrType == IP_ADDR_UNIQUE) && (Destination.AddrType != IP_ADDR_UNIQUE) &&
  4001. (Source.uIpAddr == 0xFFFFFFFF ) && (Destination.uIpAddr == 0xFFFFFFFF))
  4002. {
  4003. if(pIPSecMMSA[j].Peer.AddrType == Destination.AddrType)
  4004. {
  4005. bFound = TRUE;
  4006. }
  4007. }
  4008. //Enumerate Only given src&dst MMSAs
  4009. else if((Source.uIpAddr != 0xFFFFFFFF) && (Destination.uIpAddr != 0xFFFFFFFF))
  4010. {
  4011. if((pIPSecMMSA[j].Me.uIpAddr == Source.uIpAddr) && (pIPSecMMSA[j].Peer.uIpAddr == Destination.uIpAddr))
  4012. {
  4013. bFound = TRUE;
  4014. }
  4015. }
  4016. //Enumerate Only given source MMSAs
  4017. else if((Source.uIpAddr != 0xFFFFFFFF) && (Destination.uIpAddr == 0xFFFFFFFF))
  4018. {
  4019. if(pIPSecMMSA[j].Me.uIpAddr == Source.uIpAddr)
  4020. {
  4021. bFound = TRUE;
  4022. }
  4023. }
  4024. //Enumerate Only given dst MMSAs
  4025. else if((Source.uIpAddr == 0xFFFFFFFF) && (Destination.uIpAddr != 0xFFFFFFFF))
  4026. {
  4027. if(pIPSecMMSA[j].Peer.uIpAddr == Destination.uIpAddr)
  4028. {
  4029. bFound = TRUE;
  4030. }
  4031. }
  4032. //Finally print it is found...
  4033. if(bFound)
  4034. {
  4035. if(!bHeader)
  4036. {
  4037. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_IKE_SA_HEADING,szTime);
  4038. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMF_UNDERLINE);
  4039. if(bFormat)
  4040. {
  4041. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_DST_SEC_HEADING);
  4042. //This is place holder for date and time created...
  4043. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_UNDERLINE);
  4044. }
  4045. bHeader = TRUE;
  4046. }
  4047. PrintMMSas(pIPSecMMSA[j], bFormat, addressHash, bResolveDNS);
  4048. }
  4049. }
  4050. SPDApiBufferFree(pIPSecMMSA);
  4051. pIPSecMMSA=NULL;
  4052. if(dwReserved == 0) //this is API requirement
  4053. {
  4054. BAIL_OUT;
  4055. }
  4056. }
  4057. error:
  4058. if(pIPSecMMSA)
  4059. {
  4060. SPDApiBufferFree(pIPSecMMSA);
  4061. pIPSecMMSA=NULL;
  4062. }
  4063. if(bHeader == FALSE)
  4064. {
  4065. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_NEWLINE);
  4066. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_SHOW_MMSAS_6);
  4067. }
  4068. return dwReturn;
  4069. }
  4070. ///////////////////////////////////////////////////////////////////////////////////////////
  4071. //
  4072. //Function: PrintMMSas
  4073. //
  4074. //Date of Creation: 9-3-2001
  4075. //
  4076. //Parameters:
  4077. //
  4078. // IN IPSEC_MM_SA MMsas,
  4079. // IN BOOL bFormat
  4080. // IN NshHashTable& addressHash
  4081. // IN BOOL bResolveDNS
  4082. //
  4083. //Return: VOID
  4084. //
  4085. //Description: This function prints data for MMsas
  4086. //
  4087. // Date Author Comments
  4088. //
  4089. //////////////////////////////////////////////////////////////////////////////////////////
  4090. VOID
  4091. PrintMMSas(
  4092. IN IPSEC_MM_SA MMsas,
  4093. IN BOOL bFormat,
  4094. IN NshHashTable& addressHash,
  4095. IN BOOL bResolveDNS
  4096. )
  4097. {
  4098. DWORD i = 0;
  4099. BYTE* pbData = NULL;
  4100. DWORD dwLenth = 0;
  4101. if(!bFormat)//List
  4102. {
  4103. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_COOKIE_PAIR);
  4104. pbData = (BYTE*)&(MMsas.MMSpi.Initiator);
  4105. dwLenth = sizeof(IKE_COOKIE);
  4106. for(i=0; i<dwLenth; i++)
  4107. {
  4108. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_COOKIE,pbData[i]);
  4109. }
  4110. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_COLON);
  4111. pbData = (BYTE*)&(MMsas.MMSpi.Responder);
  4112. for(i=0; i<dwLenth; i++)
  4113. {
  4114. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_COOKIE,pbData[i]);
  4115. }
  4116. //Created time required clarification
  4117. //Security Methods
  4118. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_SEC_METHOD_HEADING);
  4119. switch(MMsas.SelectedMMOffer.EncryptionAlgorithm.uAlgoIdentifier)
  4120. {
  4121. case CONF_ALGO_NONE:
  4122. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_NONE_ALGO);
  4123. break;
  4124. case CONF_ALGO_DES:
  4125. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_DES_ALGO);
  4126. break;
  4127. case CONF_ALGO_3_DES:
  4128. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_NO_SA_FOUND_MSGDES_ALGO);
  4129. break;
  4130. default:
  4131. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_UNKNOWN_ALGO);
  4132. break;
  4133. }
  4134. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_SLASH);
  4135. switch(MMsas.SelectedMMOffer.HashingAlgorithm.uAlgoIdentifier)
  4136. {
  4137. case AUTH_ALGO_NONE:
  4138. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_NONE_ALGO);
  4139. break;
  4140. case AUTH_ALGO_MD5:
  4141. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_MD5_ALGO);
  4142. break;
  4143. case AUTH_ALGO_SHA1:
  4144. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_SHA1_ALGO);
  4145. break;
  4146. default:
  4147. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_UNKNOWN_ALGO);
  4148. break;
  4149. }
  4150. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_DH_LIFETIME,MMsas.SelectedMMOffer.dwDHGroup, MMsas.SelectedMMOffer.Lifetime.uKeyExpirationTime);
  4151. //Authentication Mode
  4152. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_AUTH_MODE_HEADING);
  4153. switch(MMsas.MMAuthEnum)
  4154. {
  4155. case IKE_PRESHARED_KEY:
  4156. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_PRE_KEY);
  4157. break;
  4158. case IKE_DSS_SIGNATURE:
  4159. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_DSS_SIGN);
  4160. break;
  4161. case IKE_RSA_SIGNATURE:
  4162. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_RSA_SIGN);
  4163. break;
  4164. case IKE_RSA_ENCRYPTION:
  4165. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_RSA_ENCRYPT);
  4166. break;
  4167. case IKE_SSPI:
  4168. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_KERBEROS);
  4169. break;
  4170. default:
  4171. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_UNKNOWN_ALGO);
  4172. break;
  4173. }
  4174. //Source address:
  4175. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_SRC_HEADING);
  4176. PrintAddr(MMsas.Me, addressHash, false);
  4177. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_PORT,MMsas.UdpEncapContext.wSrcEncapPort);
  4178. if(bResolveDNS)
  4179. {
  4180. PrintAddrStr(&(MMsas.Me), addressHash);
  4181. }
  4182. switch(MMsas.MMAuthEnum)
  4183. {
  4184. case IKE_PRESHARED_KEY:
  4185. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_ID_HEADING);
  4186. PrintAddr(MMsas.Me, addressHash, bResolveDNS);
  4187. break;
  4188. case IKE_DSS_SIGNATURE:
  4189. case IKE_RSA_SIGNATURE:
  4190. case IKE_RSA_ENCRYPTION:
  4191. if(MMsas.MyCertificateChain.pBlob) {
  4192. PrintSACertInfo(MMsas);
  4193. }
  4194. else if(MMsas.MyId.pBlob){
  4195. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_ID_VALUE,(LPTSTR)(MMsas.MyId.pBlob));
  4196. }
  4197. break;
  4198. case IKE_SSPI:
  4199. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_ID_VALUE,(LPTSTR)(MMsas.MyId.pBlob));
  4200. break;
  4201. default:
  4202. break;
  4203. }
  4204. //Destination address:
  4205. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_DST_HEADING);
  4206. PrintAddr(MMsas.Peer, addressHash, false);
  4207. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_PORT,MMsas.UdpEncapContext.wDesEncapPort);
  4208. if(bResolveDNS)
  4209. {
  4210. PrintAddrStr(&(MMsas.Peer), addressHash);
  4211. }
  4212. switch(MMsas.MMAuthEnum)
  4213. {
  4214. case IKE_PRESHARED_KEY:
  4215. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_ID_HEADING);
  4216. PrintAddr(MMsas.Peer, addressHash, bResolveDNS);
  4217. break;
  4218. case IKE_DSS_SIGNATURE:
  4219. case IKE_RSA_SIGNATURE:
  4220. case IKE_RSA_ENCRYPTION:
  4221. if(MMsas.PeerCertificateChain.pBlob) {
  4222. PrintSACertInfo(MMsas);
  4223. }
  4224. else if(MMsas.PeerId.pBlob){
  4225. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_ID_VALUE,(LPTSTR)(MMsas.PeerId.pBlob));
  4226. }
  4227. break;
  4228. case IKE_SSPI:
  4229. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_ID_VALUE,(LPTSTR)(MMsas.PeerId.pBlob));
  4230. break;
  4231. default:
  4232. break;
  4233. }
  4234. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_NEWLINE);
  4235. }
  4236. else // Table output
  4237. {
  4238. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_NEWLINE);
  4239. PrintAddr(MMsas.Me, addressHash, bResolveDNS);
  4240. switch(MMsas.MMAuthEnum)
  4241. {
  4242. case IKE_PRESHARED_KEY:
  4243. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_SPACE_ADJ);
  4244. break;
  4245. case IKE_DSS_SIGNATURE:
  4246. case IKE_RSA_SIGNATURE:
  4247. case IKE_RSA_ENCRYPTION:
  4248. //This is a place holder for id
  4249. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_SPACE_ADJ);
  4250. break;
  4251. case IKE_SSPI:
  4252. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_KERB_ID, (LPTSTR)(MMsas.MyId.pBlob));
  4253. break;
  4254. default:
  4255. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_SPACE_ADJ);
  4256. break;
  4257. }
  4258. //Security Methods
  4259. switch(MMsas.SelectedMMOffer.EncryptionAlgorithm.uAlgoIdentifier)
  4260. {
  4261. case CONF_ALGO_NONE:
  4262. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_NONE_ALGO);
  4263. break;
  4264. case CONF_ALGO_DES:
  4265. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_DES_ALGO);
  4266. break;
  4267. case CONF_ALGO_3_DES:
  4268. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_NO_SA_FOUND_MSGDES_ALGO);
  4269. break;
  4270. default:
  4271. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_UNKNOWN_ALGO);
  4272. break;
  4273. }
  4274. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_SLASH);
  4275. switch(MMsas.SelectedMMOffer.HashingAlgorithm.uAlgoIdentifier)
  4276. {
  4277. case AUTH_ALGO_NONE:
  4278. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_NONE_ALGO);
  4279. break;
  4280. case AUTH_ALGO_MD5:
  4281. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_MD5_ALGO);
  4282. break;
  4283. case AUTH_ALGO_SHA1:
  4284. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_SHA1_ALGO);
  4285. break;
  4286. default:
  4287. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_UNKNOWN_ALGO);
  4288. break;
  4289. }
  4290. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_DH_LIFETIME,MMsas.SelectedMMOffer.dwDHGroup, MMsas.SelectedMMOffer.Lifetime.uKeyExpirationTime);
  4291. if(bResolveDNS)
  4292. {
  4293. PrintAddrStr(&(MMsas.Me), addressHash, DYNAMIC_SHOW_MMSAS_DNS);
  4294. }
  4295. //One set over next set starts
  4296. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_NEWLINE);
  4297. PrintAddr(MMsas.Peer, addressHash, bResolveDNS);
  4298. switch(MMsas.MMAuthEnum)
  4299. {
  4300. case IKE_PRESHARED_KEY:
  4301. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_SPACE_ADJ);
  4302. //" "
  4303. break;
  4304. case IKE_DSS_SIGNATURE:
  4305. case IKE_RSA_SIGNATURE:
  4306. case IKE_RSA_ENCRYPTION:
  4307. //This is a place holder for id
  4308. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_SPACE_ADJ);
  4309. break;
  4310. case IKE_SSPI:
  4311. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_KERB_PEER_ID, (LPTSTR)(MMsas.PeerId.pBlob));
  4312. break;
  4313. default:
  4314. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_SPACE_ADJ);
  4315. break;
  4316. }
  4317. //Sec Methods
  4318. switch(MMsas.SelectedMMOffer.EncryptionAlgorithm.uAlgoIdentifier)
  4319. {
  4320. case CONF_ALGO_NONE:
  4321. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_NONE_ALGO);
  4322. break;
  4323. case CONF_ALGO_DES:
  4324. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_DES_ALGO);
  4325. break;
  4326. case CONF_ALGO_3_DES:
  4327. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_NO_SA_FOUND_MSGDES_ALGO);
  4328. break;
  4329. default:
  4330. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_UNKNOWN_ALGO);
  4331. break;
  4332. }
  4333. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_SLASH);
  4334. switch(MMsas.SelectedMMOffer.HashingAlgorithm.uAlgoIdentifier)
  4335. {
  4336. case AUTH_ALGO_NONE:
  4337. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_NONE_ALGO);
  4338. break;
  4339. case AUTH_ALGO_MD5:
  4340. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_MD5_ALGO);
  4341. break;
  4342. case AUTH_ALGO_SHA1:
  4343. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_SHA1_ALGO);
  4344. break;
  4345. default:
  4346. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_UNKNOWN_ALGO);
  4347. break;
  4348. }
  4349. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_DH_LIFETIME,MMsas.SelectedMMOffer.dwDHGroup, MMsas.SelectedMMOffer.Lifetime.uKeyExpirationTime);
  4350. if(bResolveDNS)
  4351. {
  4352. PrintAddrStr(&(MMsas.Peer), addressHash, DYNAMIC_SHOW_MMSAS_DNS);
  4353. }
  4354. }
  4355. }
  4356. ///////////////////////////////////////////////////////////////////////////////////////////
  4357. //
  4358. //Function: PrintSACertInfo
  4359. //
  4360. //Date of Creation: 9-3-2001
  4361. //
  4362. //Parameters: IN IPSEC_MM_SA& MMsas
  4363. //
  4364. //Return: VOID
  4365. //
  4366. //Description:
  4367. //
  4368. // Date Author Comments
  4369. //
  4370. //////////////////////////////////////////////////////////////////////////////////////////
  4371. VOID
  4372. PrintSACertInfo(
  4373. IN IPSEC_MM_SA& MMsas
  4374. )
  4375. {
  4376. CRYPT_DATA_BLOB pkcsMsg;
  4377. HANDLE hCertStore = NULL;
  4378. PCCERT_CONTEXT pPrevCertContext = NULL;
  4379. PCCERT_CONTEXT pCertContext = NULL;
  4380. _TCHAR pszSubjectName[MAX_STR_LEN] = {0};
  4381. char szThumbPrint[MAX_STR_LEN] = {0};
  4382. BOOL bPrintID = FALSE;
  4383. BOOL bLastCert = FALSE;
  4384. BOOL pCertPrinted = TRUE;
  4385. pkcsMsg.pbData=MMsas.MyCertificateChain.pBlob;
  4386. pkcsMsg.cbData=MMsas.MyCertificateChain.dwSize;
  4387. hCertStore = CertOpenStore( CERT_STORE_PROV_PKCS7,
  4388. MY_ENCODING_TYPE | PKCS_7_ASN_ENCODING,
  4389. NULL,
  4390. CERT_STORE_READONLY_FLAG,
  4391. &pkcsMsg);
  4392. if ( NULL == hCertStore )
  4393. {
  4394. BAIL_OUT;
  4395. }
  4396. while(TRUE)
  4397. {
  4398. pCertContext = CertEnumCertificatesInStore( hCertStore,
  4399. pPrevCertContext);
  4400. if ( NULL == pCertContext )
  4401. {
  4402. bLastCert = TRUE;
  4403. }
  4404. if ( !pCertPrinted )
  4405. {
  4406. //print the certificate
  4407. if ( !bPrintID )
  4408. {
  4409. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_ID_VALUE,(LPTSTR)(pszSubjectName));
  4410. bPrintID = TRUE;
  4411. }
  4412. if ( !bLastCert )
  4413. {
  4414. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_ISSUE_CA, (LPTSTR) pszSubjectName );
  4415. }
  4416. else
  4417. {
  4418. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_ROOTCA , (LPTSTR) pszSubjectName );
  4419. }
  4420. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_THUMB_PRINT);
  4421. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_THUMBPRINT , szThumbPrint);
  4422. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_HASH_OPEN_BRACKET );
  4423. switch(MMsas.SelectedMMOffer.HashingAlgorithm.uAlgoIdentifier)
  4424. {
  4425. case AUTH_ALGO_NONE:
  4426. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_NONE_ALGO);
  4427. break;
  4428. case AUTH_ALGO_MD5:
  4429. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_MD5_ALGO);
  4430. break;
  4431. case AUTH_ALGO_SHA1:
  4432. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_SHA1_ALGO);
  4433. break;
  4434. default:
  4435. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_UNKNOWN_ALGO);
  4436. break;
  4437. }
  4438. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_MMSAS_HASH_CLOSE_BRACKET);
  4439. pCertPrinted = TRUE;
  4440. }
  4441. if ( bLastCert )
  4442. {
  4443. BAIL_OUT;
  4444. }
  4445. GetSubjectAndThumbprint(pCertContext, pszSubjectName, szThumbPrint);
  4446. pPrevCertContext = pCertContext;
  4447. pCertPrinted = FALSE;
  4448. }
  4449. error:
  4450. if ( hCertStore )
  4451. {
  4452. CertCloseStore(hCertStore, 0 );
  4453. }
  4454. }
  4455. ///////////////////////////////////////////////////////////////////////////////////////////
  4456. //
  4457. //Function: GetNameAudit
  4458. //
  4459. //Date of Creation: 1-3-2002
  4460. //
  4461. //Parameters:
  4462. //
  4463. // IN CRYPT_DATA_BLOB *NameBlob,
  4464. // IN OUT LPTSTR Name,
  4465. // IN DWORD NameBufferSize
  4466. //
  4467. //Return: VOID
  4468. //
  4469. //Description: Translates encoded Name into Unicode string.
  4470. // Buffer already allocated.
  4471. //
  4472. // Date Author Comments
  4473. //
  4474. //////////////////////////////////////////////////////////////////////////////////////////
  4475. DWORD
  4476. GetNameAudit(
  4477. IN CRYPT_DATA_BLOB *NameBlob,
  4478. IN OUT LPTSTR Name,
  4479. IN DWORD NameBufferSize
  4480. )
  4481. {
  4482. DWORD dwCount=0;
  4483. DWORD dwSize = 0;
  4484. dwSize = CertNameToStr(
  4485. MY_ENCODING_TYPE, // Encoding type
  4486. NameBlob, // CRYPT_DATA_BLOB
  4487. CERT_X500_NAME_STR, // Type
  4488. Name, // Place to return string
  4489. NameBufferSize); // Size of string (chars)
  4490. if(dwSize <= 1)
  4491. {
  4492. dwCount = _tcslen(_TEXT(""))+1;
  4493. _tcsncpy(Name, _TEXT(""), dwCount);
  4494. }
  4495. return ERROR_SUCCESS;
  4496. }
  4497. ///////////////////////////////////////////////////////////////////////////////////////////
  4498. //
  4499. // Function : CertGetSHAHash
  4500. //
  4501. // Date of Creation: 1-3-2002
  4502. //
  4503. // Parameters :
  4504. //
  4505. // IN PCCERT_CONTEXT pCertContext,
  4506. // IN OUT BYTE* OutHash
  4507. //
  4508. // Return : DWORD
  4509. //
  4510. // Description : Gets certificate context property
  4511. //
  4512. // Date Author Comments
  4513. //
  4514. //////////////////////////////////////////////////////////////////////////////////////////
  4515. DWORD
  4516. CertGetSHAHash(
  4517. IN PCCERT_CONTEXT pCertContext,
  4518. IN OUT BYTE* OutHash
  4519. )
  4520. {
  4521. DWORD HashSize = SHA_LENGTH - 1;//one less for null termination
  4522. DWORD dwReturn = ERROR_SUCCESS;
  4523. if (!CertGetCertificateContextProperty(pCertContext,
  4524. CERT_SHA1_HASH_PROP_ID,
  4525. (VOID*)OutHash,
  4526. &HashSize))
  4527. {
  4528. dwReturn = GetLastError();
  4529. }
  4530. return dwReturn;
  4531. }
  4532. ///////////////////////////////////////////////////////////////////////////////////////////
  4533. //
  4534. // Function : print_vpi
  4535. //
  4536. // Date of Creation: 1-3-2002
  4537. //
  4538. // Parameters :
  4539. // IN unsigned char *vpi,
  4540. // IN int vpi_len,
  4541. // IN OUT char *msg
  4542. //
  4543. // Return : VOID
  4544. //
  4545. // Description : Prepare string for Cookie
  4546. //
  4547. // Date Author Comments
  4548. //
  4549. //////////////////////////////////////////////////////////////////////////////////////////
  4550. VOID
  4551. print_vpi(
  4552. IN unsigned char *vpi,
  4553. IN int vpi_len,
  4554. IN OUT char *msg
  4555. )
  4556. {
  4557. int i;
  4558. char *p = msg;
  4559. if ((vpi != NULL) && (p != NULL))
  4560. {
  4561. for (i=0; i<vpi_len; i++)
  4562. {
  4563. p += _snprintf(p,1,"%x",vpi[i]);
  4564. }
  4565. *p = 0;
  4566. }
  4567. }
  4568. ///////////////////////////////////////////////////////////////////////////////////////////
  4569. //
  4570. // Function : GetSubjectAndThumbprint
  4571. //
  4572. // Date of Creation: 1-3-2002
  4573. //
  4574. // Parameters :
  4575. // IN PCCERT_CONTEXT pCertContext,
  4576. // IN LPTSTR pszSubjectName,
  4577. // IN LPSTR pszThumbPrint
  4578. //
  4579. // Return : VOID
  4580. //
  4581. // Description : Drills CA and prints thumbprint and Issuing CAs.
  4582. //
  4583. // Date Author Comments
  4584. //
  4585. //////////////////////////////////////////////////////////////////////////////////////////
  4586. VOID
  4587. GetSubjectAndThumbprint(
  4588. IN PCCERT_CONTEXT pCertContext,
  4589. IN LPTSTR pszSubjectName,
  4590. IN LPSTR pszThumbPrint
  4591. )
  4592. {
  4593. DWORD dwReturn = ERROR_SUCCESS;
  4594. CRYPT_DATA_BLOB NameBlob;
  4595. BYTE CertHash[SHA_LENGTH] = {0};
  4596. NameBlob = pCertContext->pCertInfo->Subject;
  4597. dwReturn = GetNameAudit(&NameBlob,pszSubjectName,MAX_STR_LEN);
  4598. if(dwReturn == ERROR_SUCCESS)
  4599. {
  4600. dwReturn = CertGetSHAHash(pCertContext,CertHash);
  4601. }
  4602. if(dwReturn == ERROR_SUCCESS)
  4603. {
  4604. print_vpi(CertHash, SHA_LENGTH, pszThumbPrint);
  4605. }
  4606. }
  4607. ///////////////////////////////////////////////////////////////////////////////////////////
  4608. //
  4609. // Function : ShowQMSas
  4610. //
  4611. // Date of Creation: 9-3-2001
  4612. //
  4613. // Parameters : IN IPAddr source,
  4614. // IN IPAddr destination,
  4615. // IN DWORD dwProtocol
  4616. // IN NshHashTable& addressHash
  4617. // IN BOOL bResolveDNS
  4618. //
  4619. // Return : DWORD
  4620. //
  4621. // Description : This function prepares data for QMsas
  4622. //
  4623. // Date Author Comments
  4624. //
  4625. //////////////////////////////////////////////////////////////////////////////////////////
  4626. DWORD
  4627. ShowQMSas(
  4628. IN ADDR Source,
  4629. IN ADDR Destination,
  4630. IN DWORD dwProtocol,
  4631. IN NshHashTable& addressHash,
  4632. IN BOOL bResolveDNS
  4633. )
  4634. {
  4635. DWORD dwReturn = ERROR_SUCCESS; // success by default
  4636. DWORD i=0, j=0;
  4637. DWORD dwResumeHandle = 0; // handle for continuation calls
  4638. DWORD dwCount =2; // counting objects here min 2 required
  4639. PIPSEC_QM_SA pIPSecQMSA = NULL; // for QM SA calls
  4640. DWORD dwReserved =0; // reserved container
  4641. DWORD dwVersion = 0;
  4642. BOOL bFound = FALSE;
  4643. BOOL bHeader = FALSE;
  4644. BOOL bContinue = TRUE;
  4645. // make the call(s)
  4646. for (i = 0; ;i+=dwCount)
  4647. {
  4648. dwReturn = EnumQMSAs(g_szDynamicMachine, dwVersion , NULL, 0, 0, &pIPSecQMSA, &dwCount, &dwReserved, &dwResumeHandle, NULL);
  4649. if (dwReturn == ERROR_NO_DATA || dwCount == 0)
  4650. {
  4651. if (i == 0)
  4652. {
  4653. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_NEWLINE);
  4654. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_SHOW_QMSAS_3);
  4655. bHeader = TRUE; //To Block other error message
  4656. }
  4657. dwReturn = ERROR_SUCCESS;
  4658. BAIL_OUT;
  4659. }
  4660. if (dwReturn != ERROR_SUCCESS)
  4661. {
  4662. BAIL_OUT;
  4663. }
  4664. for (j = 0; j < dwCount; j++)
  4665. {
  4666. bFound = FALSE;
  4667. bContinue = TRUE;
  4668. //Source is a SPL_SERVER
  4669. if((Source.AddrType != IP_ADDR_UNIQUE) && bContinue)
  4670. {
  4671. if(pIPSecQMSA[j].IpsecQMFilter.SrcAddr.AddrType == Source.AddrType)
  4672. {
  4673. bFound = TRUE;
  4674. }
  4675. else
  4676. {
  4677. bFound = FALSE;
  4678. bContinue= FALSE;
  4679. }
  4680. }
  4681. //Destination is a SPL_SERVER
  4682. if((Destination.AddrType != IP_ADDR_UNIQUE)&& bContinue)
  4683. {
  4684. if(pIPSecQMSA[j].IpsecQMFilter.DesAddr.AddrType == Destination.AddrType)
  4685. {
  4686. bFound = TRUE;
  4687. }
  4688. else
  4689. {
  4690. bFound = FALSE;
  4691. bContinue= FALSE;
  4692. }
  4693. }
  4694. //Source Addr specie
  4695. if((Source.uIpAddr != 0xFFFFFFFF)&& bContinue)
  4696. {
  4697. if(pIPSecQMSA[j].IpsecQMFilter.SrcAddr.uIpAddr == Source.uIpAddr)
  4698. {
  4699. bFound = TRUE;
  4700. }
  4701. else
  4702. {
  4703. bFound = FALSE;
  4704. bContinue= FALSE;
  4705. }
  4706. }
  4707. // Check for me/any
  4708. // 0x55555555 is an invalid mask. In parent function mask is initialized with this value.
  4709. // If user gives the input then this will be overwritten.
  4710. if((Source.uSubNetMask != 0x55555555)&& bContinue)
  4711. {
  4712. if(pIPSecQMSA[j].IpsecQMFilter.SrcAddr.uSubNetMask == Source.uSubNetMask)
  4713. {
  4714. bFound = TRUE;
  4715. }
  4716. else
  4717. {
  4718. bFound = FALSE;
  4719. bContinue= FALSE;
  4720. }
  4721. }
  4722. //Dst Addr
  4723. if((Destination.uIpAddr != 0xFFFFFFFF)&& bContinue)
  4724. {
  4725. if(pIPSecQMSA[j].IpsecQMFilter.DesAddr.uIpAddr == Destination.uIpAddr)
  4726. {
  4727. bFound = TRUE;
  4728. }
  4729. else
  4730. {
  4731. bFound = FALSE;
  4732. bContinue= FALSE;
  4733. }
  4734. }
  4735. //
  4736. // Check for me/any
  4737. // 0x55555555 is an invalid mask. In parent function mask is initialized with this value.
  4738. // If user gives the input then this will be overwritten.
  4739. //
  4740. if((Destination.uSubNetMask != 0x55555555)&& bContinue)
  4741. {
  4742. if(pIPSecQMSA[j].IpsecQMFilter.DesAddr.uSubNetMask == Destination.uSubNetMask)
  4743. {
  4744. bFound = TRUE;
  4745. }
  4746. else
  4747. {
  4748. bFound = FALSE;
  4749. bContinue= FALSE;
  4750. }
  4751. }
  4752. //Protocol specified
  4753. if((dwProtocol != 0xFFFFFFFF)&& bContinue)
  4754. {
  4755. if(pIPSecQMSA[j].IpsecQMFilter.Protocol.dwProtocol == dwProtocol)
  4756. {
  4757. bFound = TRUE;
  4758. }
  4759. else
  4760. {
  4761. bFound = FALSE;
  4762. bContinue= FALSE;
  4763. }
  4764. }
  4765. //
  4766. // AllQmsas
  4767. //
  4768. if((Source.uIpAddr == 0xFFFFFFFF ) && (Destination.uIpAddr == 0xFFFFFFFF) &&
  4769. (Source.AddrType == IP_ADDR_UNIQUE) && (Destination.AddrType == IP_ADDR_UNIQUE) &&
  4770. (dwProtocol == 0xFFFFFFFF))
  4771. {
  4772. bFound = TRUE;
  4773. }
  4774. if(bFound)
  4775. {
  4776. if(!bHeader)
  4777. {
  4778. //
  4779. // Display main mode SAs
  4780. //
  4781. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMSAS_HEADING);
  4782. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMSAS_UNDERLINE);
  4783. bHeader = TRUE;
  4784. }
  4785. PrintQMSAFilter(pIPSecQMSA[j], addressHash, bResolveDNS);
  4786. }
  4787. }
  4788. if(dwReserved == 0)
  4789. {
  4790. //
  4791. // This API requirement
  4792. //
  4793. BAIL_OUT;
  4794. }
  4795. SPDApiBufferFree(pIPSecQMSA);
  4796. pIPSecQMSA=NULL;
  4797. }
  4798. error:
  4799. //error path clean up
  4800. if(pIPSecQMSA)
  4801. {
  4802. SPDApiBufferFree(pIPSecQMSA);
  4803. }
  4804. if(bHeader == FALSE)
  4805. {
  4806. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_NEWLINE);
  4807. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_SHOW_QMSAS_4);
  4808. }
  4809. return dwReturn;
  4810. }
  4811. ///////////////////////////////////////////////////////////////////////////////////////////
  4812. //
  4813. // Function : PrintQMSas
  4814. //
  4815. // Date of Creation: 9-3-2001
  4816. //
  4817. // Parameters : IN IPSEC_MM_SA QMOffer
  4818. //
  4819. // Return : VOID
  4820. //
  4821. // Description : This function displays quickmode offer details for security associations.
  4822. //
  4823. // Date Author Comments
  4824. //
  4825. //////////////////////////////////////////////////////////////////////////////////////////
  4826. VOID
  4827. PrintQMSas(
  4828. IN IPSEC_QM_OFFER QMOffer
  4829. )
  4830. {
  4831. DWORD i = 0;
  4832. if(QMOffer.dwNumAlgos >0)
  4833. {
  4834. for (i = 0; i < QMOffer.dwNumAlgos; i++)
  4835. {
  4836. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_NEWLINE);
  4837. //print Authentication algorithms
  4838. if(QMOffer.Algos[i].Operation == AUTHENTICATION)
  4839. {
  4840. switch(QMOffer.Algos[i].uAlgoIdentifier)
  4841. {
  4842. case 1:
  4843. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_SAS_MD5_NONE_NONE_ALGO, QMOffer.Algos[i].uAlgoKeyLen, QMOffer.Algos[i].uAlgoRounds);
  4844. break;
  4845. case 2:
  4846. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_SAS_SHA1_NONE_NONE_ALGO, QMOffer.Algos[i].uAlgoKeyLen, QMOffer.Algos[i].uAlgoRounds);
  4847. break;
  4848. case 0:
  4849. default:
  4850. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_SAS_NONE_NONE_NONE_ALGO);
  4851. break;
  4852. }
  4853. }
  4854. else if(QMOffer.Algos[i].Operation == ENCRYPTION)
  4855. {
  4856. //print Hash algorithms
  4857. switch(QMOffer.Algos[i].uAlgoIdentifier)
  4858. {
  4859. case 1:
  4860. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_SAS_NONE_DES_ALGO, QMOffer.Algos[i].uAlgoKeyLen, QMOffer.Algos[i].uAlgoRounds);
  4861. break;
  4862. case 2:
  4863. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_SAS_NONE_UNKNOWN_ALGO);
  4864. break;
  4865. case 3:
  4866. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_SAS_NONE_3DES_ALGO, QMOffer.Algos[i].uAlgoKeyLen, QMOffer.Algos[i].uAlgoRounds);
  4867. break;
  4868. case 0:
  4869. default:
  4870. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_SAS_NONE_NONE_ALGO);
  4871. break;
  4872. }
  4873. if (QMOffer.Algos[i].uSecAlgoIdentifier != HMAC_AUTH_ALGO_NONE)
  4874. switch(QMOffer.Algos[i].uSecAlgoIdentifier)
  4875. {
  4876. case 1:
  4877. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_SAS_MD5_ALGO);
  4878. break;
  4879. case 2:
  4880. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_SAS_SHA1_ALGO);
  4881. break;
  4882. case 0:
  4883. default:
  4884. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_SAS_NONE_ALGO);
  4885. break;
  4886. }
  4887. else
  4888. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_SAS_NONE_SPACE_ALGO);
  4889. }
  4890. else
  4891. {
  4892. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMP_SAS_NONE_NONE_NONE_ALGO);
  4893. }
  4894. PrintMessageFromModule(g_hModule, QMPFSDHGroup(QMOffer.dwPFSGroup));
  4895. }
  4896. }
  4897. }
  4898. ///////////////////////////////////////////////////////////////////////////////////////////
  4899. //
  4900. // Function : PrintQMSAFilter
  4901. //
  4902. // Date of Creation: 9-3-2001
  4903. //
  4904. // Parameters : IN IPSEC_QM_SA QMsa
  4905. // IN NshHashTable& addressHash
  4906. // IN BOOL bResolveDNS
  4907. //
  4908. // Return : DWORD
  4909. //
  4910. // Description : This function displays quickmode filter details for Security associations.
  4911. //
  4912. // Date Author Comments
  4913. //
  4914. //////////////////////////////////////////////////////////////////////////////////////////
  4915. DWORD
  4916. PrintQMSAFilter(
  4917. IN IPSEC_QM_SA QMsa,
  4918. IN NshHashTable& addressHash,
  4919. IN BOOL bResolveDNS
  4920. )
  4921. {
  4922. DWORD dwReturn = 0;
  4923. DWORD dwVersion = 0;
  4924. PIPSEC_QM_POLICY pIPSecQMP = NULL;
  4925. //Print Tunnel or Transport type
  4926. switch(QMsa.IpsecQMFilter.QMFilterType)
  4927. {
  4928. case QM_TRANSPORT_FILTER:
  4929. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_TRANSPORT_FILTER_HEADING);
  4930. break;
  4931. case QM_TUNNEL_FILTER:
  4932. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_TUNNEL_FILTER_HEADING);
  4933. break;
  4934. default:
  4935. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_UNKNOWN);
  4936. break;
  4937. }
  4938. //print qmpolicy name
  4939. dwReturn = GetQMPolicyByID(g_szDynamicMachine, dwVersion, QMsa.gQMPolicyID, 0, &pIPSecQMP, NULL);
  4940. if(dwReturn == ERROR_SUCCESS)
  4941. {
  4942. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_POL_NAME_HEADING, pIPSecQMP[0].pszPolicyName);
  4943. }
  4944. //Print source and destination point.
  4945. if (QMsa.IpsecQMFilter.QMFilterType == QM_TUNNEL_FILTER)
  4946. {
  4947. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_TUNNEL_SRC);
  4948. PrintAddr(QMsa.IpsecQMFilter.MyTunnelEndpt, addressHash, bResolveDNS);
  4949. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_TUNNEL_DST);
  4950. PrintAddr(QMsa.IpsecQMFilter.PeerTunnelEndpt, addressHash, bResolveDNS);
  4951. }
  4952. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_SRC_ADDR_HEADING);
  4953. PrintAddr(QMsa.IpsecQMFilter.SrcAddr, addressHash, bResolveDNS);
  4954. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_DST_ADDR_HEADING);
  4955. PrintAddr(QMsa.IpsecQMFilter.DesAddr, addressHash, bResolveDNS);
  4956. //Print protocol
  4957. switch(QMsa.IpsecQMFilter.Protocol.dwProtocol)
  4958. {
  4959. case PROT_ID_ICMP:
  4960. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_PROTO_ICMP);
  4961. break;
  4962. case PROT_ID_TCP:
  4963. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_PROTO_TCP);
  4964. break;
  4965. case PROT_ID_UDP:
  4966. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_PROTO_UDP);
  4967. break;
  4968. case PROT_ID_RAW:
  4969. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_PROTO_RAW);
  4970. break;
  4971. case PROT_ID_ANY:
  4972. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_PROTO_ANY);
  4973. break;
  4974. default:
  4975. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_PROTO_HEADING, QMsa.IpsecQMFilter.Protocol.dwProtocol);
  4976. break;
  4977. }
  4978. //print source and destination port
  4979. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_SRC_PORT, QMsa.IpsecQMFilter.SrcPort.wPort);
  4980. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_DST_PORT, QMsa.IpsecQMFilter.DesPort.wPort);
  4981. //print Inbound and outbound filteractions
  4982. switch(QMsa.IpsecQMFilter.dwFlags)
  4983. {
  4984. case FILTER_DIRECTION_INBOUND:
  4985. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_DIRECTION_INBOUND);
  4986. break;
  4987. case FILTER_DIRECTION_OUTBOUND:
  4988. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_DIRECTION_OUTBOUND);
  4989. break;
  4990. default:
  4991. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_DIRECTION_ERR);
  4992. break;
  4993. }
  4994. //print encapsulation details
  4995. if (QMsa.EncapInfo.SAEncapType != SA_UDP_ENCAP_TYPE_NONE)
  4996. {
  4997. if(QMsa.EncapInfo.SAEncapType == SA_UDP_ENCAP_TYPE_IKE)
  4998. {
  4999. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMSAS_ENCAP_IKE);
  5000. }
  5001. else
  5002. {
  5003. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMSAS_ENCAP_OTHER);
  5004. }
  5005. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMSAS_SRC_UDP_PORT, QMsa.EncapInfo.UdpEncapContext.wSrcEncapPort);
  5006. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMSAS_DST_UDP_PORT, QMsa.EncapInfo.UdpEncapContext.wDesEncapPort);
  5007. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMSAS_PEER_ADDR);
  5008. PrintAddr(QMsa.EncapInfo.PeerPrivateAddr, addressHash, bResolveDNS);
  5009. }
  5010. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_OFFER);
  5011. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMSAS_COLUMN_HEADING);
  5012. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_QMSAS_COLUMN_UNDERLINE);
  5013. PrintQMSas(QMsa.SelectedQMOffer);
  5014. return dwReturn;
  5015. }
  5016. ///////////////////////////////////////////////////////////////////////////////////////////
  5017. //
  5018. // Function : ShowRegKeys
  5019. //
  5020. // Date of Creation: 9-3-2001
  5021. //
  5022. // Parameters : VOID
  5023. //
  5024. // Return : DWORD
  5025. //
  5026. // Description : This function displays ipsec configuration keys.
  5027. //
  5028. // Date Author Comments
  5029. //
  5030. //////////////////////////////////////////////////////////////////////////////////////////
  5031. DWORD
  5032. ShowRegKeys(
  5033. VOID
  5034. )
  5035. {
  5036. DWORD dwReturn = ERROR_SUCCESS;
  5037. DWORD dwKeyDataSize = sizeof(DWORD);
  5038. DWORD dwKeyDataType = REG_DWORD;
  5039. DWORD dwKeyData = 0;
  5040. IKE_CONFIG IKEConfig;
  5041. HKEY hRegistryKey = NULL;
  5042. LPTSTR lpBootMode;
  5043. PIPSEC_EXEMPT_ENTRY pAllEntries = NULL;
  5044. ZeroMemory( &IKEConfig, sizeof(IKE_CONFIG) );
  5045. dwReturn = RegOpenKeyEx(g_hGlobalRegistryKey, REGKEY_GLOBAL, 0, KEY_QUERY_VALUE, &hRegistryKey);
  5046. if(dwReturn != ERROR_SUCCESS)
  5047. {
  5048. BAIL_OUT;
  5049. }
  5050. dwReturn = GetConfigurationVariables(g_szDynamicMachine, &IKEConfig);
  5051. if(dwReturn != ERROR_SUCCESS)
  5052. {
  5053. //Print default values
  5054. IKEConfig.dwEnableLogging = IKE_LOG_DEFAULT;
  5055. IKEConfig.dwStrongCRLCheck = STRONG_CRL_DEFAULT;
  5056. dwReturn = ERROR_SUCCESS;
  5057. }
  5058. //print registry key headings
  5059. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_REG_HEADING);
  5060. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_REG_HEADING_UNDERLINE);
  5061. dwKeyData = IPSEC_DIAG_DEFAULT;
  5062. dwReturn = RegQueryValueEx(hRegistryKey, ENABLE_DIAG, 0, &dwKeyDataType, (BYTE*)&dwKeyData, &dwKeyDataSize);
  5063. if ((dwReturn != ERROR_SUCCESS) && (dwReturn != ERROR_FILE_NOT_FOUND))
  5064. {
  5065. BAIL_OUT;
  5066. }
  5067. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_REG_IPSEC_DIAG, dwKeyData);
  5068. //Print GetConfig values
  5069. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_REG_IKE_LOG, IKEConfig.dwEnableLogging);
  5070. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_REG_STRONG_CRL, IKEConfig.dwStrongCRLCheck);
  5071. dwKeyData = 0;
  5072. dwKeyData = ENABLE_LOGINT_DEFAULT;
  5073. dwReturn = RegQueryValueEx(hRegistryKey, ENABLE_LOGINT, 0, &dwKeyDataType, (BYTE*)&dwKeyData, &dwKeyDataSize);
  5074. if ((dwReturn != ERROR_SUCCESS) && (dwReturn != ERROR_FILE_NOT_FOUND))
  5075. {
  5076. BAIL_OUT;
  5077. }
  5078. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_REG_IPSEC_LOG, dwKeyData);
  5079. dwKeyData = 0;
  5080. dwKeyData = ENABLE_EXEMPT_DEFAULT;
  5081. dwReturn = RegQueryValueEx(hRegistryKey, ENABLE_EXEMPT, 0, &dwKeyDataType, (BYTE*)&dwKeyData, &dwKeyDataSize);
  5082. if ((dwReturn != ERROR_SUCCESS) && (dwReturn != ERROR_FILE_NOT_FOUND))
  5083. {
  5084. BAIL_OUT;
  5085. }
  5086. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_REG_IPSEC_EXEMPT, dwKeyData);
  5087. dwKeyData = BOOTMODE_DEFAULT;
  5088. dwReturn = RegQueryValueEx(hRegistryKey, BOOTMODEKEY, 0, &dwKeyDataType, (BYTE*)&dwKeyData, &dwKeyDataSize);
  5089. if ((dwReturn != ERROR_SUCCESS) && (dwReturn != ERROR_FILE_NOT_FOUND))
  5090. {
  5091. BAIL_OUT;
  5092. }
  5093. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_REG_IPSEC_BOOTMODE);
  5094. switch (dwKeyData)
  5095. {
  5096. case VALUE_STATEFUL:
  5097. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_REG_IPSEC_BOOTMODE_STATEFUL);
  5098. break;
  5099. case VALUE_BLOCK:
  5100. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_REG_IPSEC_BOOTMODE_BLOCK);
  5101. break;
  5102. case VALUE_PERMIT:
  5103. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_REG_IPSEC_BOOTMODE_PERMIT);
  5104. break;
  5105. default:
  5106. dwReturn = ERROR_INVALID_DATA;
  5107. break;
  5108. }
  5109. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_NEWLINE);
  5110. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_BOOTMODE_EXEMPTIONS_HEADER_1);
  5111. dwKeyDataSize = 0;
  5112. dwReturn = RegQueryValueEx(hRegistryKey, BOOTEXEMPTKEY, 0, 0, NULL, &dwKeyDataSize);
  5113. if (dwReturn == ERROR_FILE_NOT_FOUND)
  5114. {
  5115. dwReturn = ERROR_SUCCESS;
  5116. }
  5117. else if (dwReturn != ERROR_SUCCESS)
  5118. {
  5119. BAIL_OUT;
  5120. }
  5121. if (dwKeyDataSize == 0)
  5122. {
  5123. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_BOOTMODE_EXEMPTIONS_NO_EXEMPTIONS);
  5124. }
  5125. else if ((dwKeyDataSize % sizeof(IPSEC_EXEMPT_ENTRY)) != 0)
  5126. {
  5127. dwReturn = ERROR_INVALID_DATA;
  5128. BAIL_OUT;
  5129. }
  5130. else
  5131. {
  5132. size_t uiNumEntries = dwKeyDataSize / sizeof(IPSEC_EXEMPT_ENTRY);
  5133. pAllEntries = new IPSEC_EXEMPT_ENTRY[uiNumEntries];
  5134. if (pAllEntries == NULL)
  5135. {
  5136. dwReturn = ERROR_NOT_ENOUGH_MEMORY;
  5137. BAIL_OUT;
  5138. }
  5139. dwReturn = RegQueryValueEx(hRegistryKey, BOOTEXEMPTKEY, 0, 0, (BYTE*)pAllEntries, &dwKeyDataSize);
  5140. if (dwReturn != ERROR_SUCCESS)
  5141. {
  5142. BAIL_OUT;
  5143. }
  5144. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_NEWLINE);
  5145. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_BOOTMODE_EXEMPTIONS_HEADER_2);
  5146. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_BOOTMODE_EXEMPTIONS_HEADER_3);
  5147. for (size_t i = 0; i < uiNumEntries; ++i)
  5148. {
  5149. PIPSEC_EXEMPT_ENTRY pEntry = pAllEntries + i;
  5150. switch (pEntry->Protocol)
  5151. {
  5152. case PROT_ID_TCP:
  5153. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_REG_IPSEC_BOOTMODE_TCP);
  5154. break;
  5155. case PROT_ID_UDP:
  5156. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_REG_IPSEC_BOOTMODE_UDP);
  5157. break;
  5158. case PROT_ID_ICMP:
  5159. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_REG_IPSEC_BOOTMODE_ICMP);
  5160. break;
  5161. case PROT_ID_RAW:
  5162. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_REG_IPSEC_BOOTMODE_RAW);
  5163. break;
  5164. case PROT_ID_ANY:
  5165. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_REG_IPSEC_BOOTMODE_ANY);
  5166. break;
  5167. default:
  5168. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_BOOTMODE_EXEMPT_INTEGER, (int)pEntry->Protocol);
  5169. break;
  5170. }
  5171. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_BOOTMODE_EXEMPT_PORT, (int)pEntry->SrcPort);
  5172. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_BOOTMODE_EXEMPT_PORT, (int)pEntry->DestPort);
  5173. switch (pEntry->Direction)
  5174. {
  5175. case (EXEMPT_DIRECTION_INBOUND):
  5176. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_BOOTMODE_EXEMPT_DIRECTION_IN);
  5177. break;
  5178. case (EXEMPT_DIRECTION_OUTBOUND):
  5179. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_BOOTMODE_EXEMPT_DIRECTION_OUT);
  5180. break;
  5181. default:
  5182. dwReturn = ERROR_INVALID_DATA;
  5183. BAIL_OUT;
  5184. }
  5185. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_NEWLINE);
  5186. }
  5187. }
  5188. error:
  5189. if (pAllEntries)
  5190. {
  5191. delete [] pAllEntries;
  5192. }
  5193. if (hRegistryKey)
  5194. {
  5195. RegCloseKey(hRegistryKey);
  5196. }
  5197. return dwReturn;
  5198. }
  5199. ///////////////////////////////////////////////////////////////////////////////////////////
  5200. //
  5201. // Function : PrintAddr
  5202. //
  5203. // Date of Creation: 9-3-2001
  5204. //
  5205. // Parameters : IN ADDR addr
  5206. // IN NshHashTable& addressHash
  5207. // IN BOOL bResolveDNS
  5208. //
  5209. // Return : VOID
  5210. //
  5211. // Description : This function displays ip address in xxx.xxx.xxx.xxx format.
  5212. //
  5213. // Date Author Comments
  5214. //
  5215. ////////////////////////////////////////////////////////////////////////////////////////////
  5216. VOID
  5217. PrintAddr(
  5218. IN ADDR addr,
  5219. IN NshHashTable& addressHash,
  5220. IN BOOL bResolveDNS
  5221. )
  5222. {
  5223. struct in_addr inAddr;
  5224. LPSTR pszAddr = NULL;
  5225. LPTSTR pszWPAddr = NULL;
  5226. pszWPAddr = new _TCHAR[STR_ADDRLEN];
  5227. if(pszWPAddr == NULL)
  5228. {
  5229. PrintErrorMessage(WIN32_ERR, ERROR_OUTOFMEMORY, NULL);
  5230. BAIL_OUT;
  5231. }
  5232. ZeroMemory(pszWPAddr, STR_ADDRLEN * sizeof(_TCHAR));
  5233. if(addr.AddrType == IP_ADDR_WINS_SERVER)
  5234. {
  5235. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_WINS);
  5236. }
  5237. else if(addr.AddrType == IP_ADDR_DHCP_SERVER)
  5238. {
  5239. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_DHCP);
  5240. }
  5241. else if(addr.AddrType == IP_ADDR_DNS_SERVER)
  5242. {
  5243. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_DNS);
  5244. }
  5245. else if(addr.AddrType == IP_ADDR_DEFAULT_GATEWAY)
  5246. {
  5247. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_GATEWAY);
  5248. }
  5249. else if (addr.AddrType == IP_ADDR_UNIQUE && addr.uIpAddr == IP_ADDRESS_ME && addr.uSubNetMask == IP_ADDRESS_MASK_NONE)
  5250. {
  5251. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_PMYADD);
  5252. }
  5253. else if (addr.AddrType == IP_ADDR_SUBNET && addr.uIpAddr == SUBNET_ADDRESS_ANY && addr.uSubNetMask == SUBNET_MASK_ANY)
  5254. {
  5255. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_PANYADD);
  5256. }
  5257. else
  5258. {
  5259. inAddr.s_addr = addr.uIpAddr;
  5260. pszAddr = inet_ntoa(inAddr);
  5261. if(pszAddr == NULL)
  5262. {
  5263. _tcsncpy(pszWPAddr, _TEXT(" "), _tcslen(_TEXT(" "))+1);//if inet_ntoa fails 16 spaces
  5264. }
  5265. else
  5266. {
  5267. _sntprintf(pszWPAddr, STR_ADDRLEN-1, _TEXT("%-16S"), pszAddr);
  5268. }
  5269. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_PADD, pszWPAddr);
  5270. }
  5271. if (bResolveDNS)
  5272. {
  5273. PrintAddrStr(&addr, addressHash);
  5274. }
  5275. if (pszWPAddr)
  5276. {
  5277. delete [] pszWPAddr;
  5278. }
  5279. error:
  5280. return;
  5281. }
  5282. ///////////////////////////////////////////////////////////////////////////////////////////
  5283. //
  5284. //Function : PrintMask
  5285. //
  5286. //Date of Creation : 9-3-2001
  5287. //
  5288. //Parameters : IN ADDR addr
  5289. //
  5290. //Return : VOID
  5291. //
  5292. //Description : This function displays ip address in xxx.xxx.xxx.xxx format.
  5293. //
  5294. // Date Author Comments
  5295. //
  5296. //////////////////////////////////////////////////////////////////////////////////////////
  5297. VOID
  5298. PrintMask(
  5299. IN ADDR addr
  5300. )
  5301. {
  5302. struct in_addr inAddr;
  5303. LPSTR pszAddr = NULL;
  5304. LPTSTR pszWPAddr = NULL;
  5305. pszWPAddr = new _TCHAR[STR_ADDRLEN];
  5306. if(pszWPAddr == NULL)
  5307. {
  5308. PrintErrorMessage(WIN32_ERR, ERROR_OUTOFMEMORY, NULL);
  5309. BAIL_OUT;
  5310. }
  5311. ZeroMemory(pszWPAddr, STR_ADDRLEN * sizeof(_TCHAR));
  5312. inAddr.s_addr = addr.uSubNetMask;
  5313. pszAddr = inet_ntoa(inAddr);
  5314. if(pszAddr == NULL)
  5315. {
  5316. _tcsncpy(pszWPAddr, _TEXT(" "), _tcslen(_TEXT(" "))+1);//if inet_ntoa fails 15 spaces
  5317. }
  5318. else
  5319. {
  5320. _sntprintf(pszWPAddr, STR_ADDRLEN-1, _TEXT("%-15S"), pszAddr);
  5321. }
  5322. PrintMessageFromModule(g_hModule, DYNAMIC_SHOW_PADD, pszWPAddr);
  5323. if (pszWPAddr)
  5324. {
  5325. delete [] pszWPAddr;
  5326. }
  5327. error:
  5328. return;
  5329. }
  5330. ///////////////////////////////////////////////////////////////////////////////////////////
  5331. //
  5332. // Function : LongLongToString
  5333. //
  5334. // Date of Creation: 9-3-2001
  5335. //
  5336. // Parameters :
  5337. // IN DWORD dwHigh,
  5338. // IN DWORD dwLow,
  5339. // IN int iPrintCommas
  5340. //
  5341. // Return : LPTSTR
  5342. //
  5343. // Description: This routine will make a pretty string to match an input long-long,
  5344. // and return it. If iPrintCommas is set, it will put in commas.
  5345. //
  5346. // Date Author Comments
  5347. //
  5348. //////////////////////////////////////////////////////////////////////////////////////////
  5349. LPSTR
  5350. LongLongToString(
  5351. IN DWORD dwHigh,
  5352. IN DWORD dwLow,
  5353. IN int iPrintCommas
  5354. )
  5355. {
  5356. char cFourGig[]="4294967296"; // "four gigabytes"
  5357. char cBuf[POTF_MAX_STRLEN]={0};
  5358. char cRes[POTF_MAX_STRLEN]={0}, cFullRes[POTF_MAX_STRLEN]={0}, *cRet = NULL;
  5359. DWORD dwPos= 0, dwPosRes =0, dwThreeCount =0;
  5360. // First, multiply the high dword by decimal 2^32 to
  5361. // get the right decimal value for it.
  5362. _snprintf(cBuf,POTF_MAX_STRLEN, "%u",dwHigh);
  5363. cBuf[POTF_MAX_STRLEN -1] = 0;
  5364. AscMultUint(cRes,cBuf,cFourGig);
  5365. // next, add in the low DWORD (fine as it is)
  5366. // to the previous product
  5367. _snprintf(cBuf,POTF_MAX_STRLEN, "%u",dwLow);
  5368. cBuf[POTF_MAX_STRLEN -1] = 0;
  5369. AscAddUint(cFullRes, cRes, cBuf);
  5370. // Finally, copy the buffer with commas.
  5371. dwPos = 0;
  5372. dwPosRes = 0;
  5373. dwThreeCount = strlen(cFullRes)%3;
  5374. while(cFullRes[dwPosRes] != '\0')
  5375. {
  5376. cBuf[dwPos++] = cFullRes[dwPosRes++];
  5377. dwThreeCount +=2; // Same as subtracting one for modulo math
  5378. if ((!(dwThreeCount%3))&&(cFullRes[dwPosRes] != '\0')&&(iPrintCommas))
  5379. {
  5380. cBuf[dwPos++]=',';
  5381. }
  5382. if(dwPos == 254)
  5383. break;
  5384. }
  5385. cBuf[dwPos] = '\0';
  5386. cRet = (LPSTR)malloc(255);
  5387. if(cRet) //Allocation failure is checked in parent function
  5388. {
  5389. memset(cRet, 0, 255);
  5390. strncpy(cRet, cBuf, 255);
  5391. cRet[254] = 0;
  5392. }
  5393. return(cRet);
  5394. }
  5395. ///////////////////////////////////////////////////////////////////////////////////////////
  5396. //
  5397. // Function : AscMultUint
  5398. //
  5399. // Date of Creation: 9-3-2001
  5400. //
  5401. // Parameters : IN LPSTR cProduct,
  5402. // IN LPSTR cA,
  5403. // IN LPSTR cB
  5404. //
  5405. // Return : DWORD (0 on success, else failure code.)
  5406. //
  5407. // Description : This routine will add two arbitrarily long ascii strings. It makes several
  5408. // assumptions about them.
  5409. // 1) the string is null terminated.
  5410. // 2) The LSB is the last char of the string. "1000000" is a million
  5411. // 3) There are no signs or decimal points.
  5412. // 4) The cProduct buffer is large enough to store the result
  5413. // 5) The product will require 254 bytes or less.
  5414. //
  5415. //Revision History :
  5416. //
  5417. // Date Author Comments
  5418. //
  5419. //////////////////////////////////////////////////////////////////////////////////////////
  5420. DWORD
  5421. AscMultUint(
  5422. IN LPSTR cProduct,
  5423. IN LPSTR cA,
  5424. IN LPSTR cB
  5425. )
  5426. {
  5427. int iALen =0, iBLen =0;
  5428. int i=0,j=0,k=0, iCarry=0;
  5429. char cTmp[POTF_MAX_STRLEN]={0};
  5430. // Verify parameters
  5431. if ((cA == NULL) || (cB == NULL) || (cProduct == NULL))
  5432. {
  5433. return((DWORD)-1);
  5434. }
  5435. iALen = strlen(cA);
  5436. iBLen = strlen(cB);
  5437. // We will multiply the traditional longhand way: for each digit in
  5438. // cA, we will multiply it against cB and add the incremental result
  5439. // into our temporary product.
  5440. // for each digit of the first multiplicand
  5441. for (i=0; i < iALen; i++)
  5442. {
  5443. iCarry = 0;
  5444. // for each digit of the second multiplicand
  5445. for(j=0; j < iBLen; j++)
  5446. {
  5447. // calculate this digit's value
  5448. k = ((int) cA[iALen-i-1]-'0') * ((int) cB[iBLen-j-1]-'0');
  5449. k += iCarry;
  5450. // Add it in to the appropriate place in the result
  5451. if (cTmp[i+j] != '\0')
  5452. {
  5453. k += (int) cTmp[i+j] - '0';
  5454. }
  5455. cTmp[i+j] = '0' + (char)(k % 10);
  5456. iCarry = k/10;
  5457. }
  5458. // Take care of the straggler carry. If the higher
  5459. // digits happen to be '9999' then this can require
  5460. // a loop.
  5461. while (iCarry)
  5462. {
  5463. if (cTmp[i+j] != '\0')
  5464. {
  5465. iCarry += cTmp[i+j] - '0';
  5466. }
  5467. cTmp[i+j] = '0' + (char)(iCarry%10);
  5468. iCarry /= 10;
  5469. j++;
  5470. }
  5471. }
  5472. // Now that we've got the entire number, reverse it and put it back in the dest.
  5473. // Skip leading 0's.
  5474. i = strlen(cTmp) - 1;
  5475. while ((i > 0)&&(cTmp[i] == '0'))
  5476. {
  5477. i--;
  5478. }
  5479. // Copy the product.
  5480. j = 0;
  5481. while (i >= 0)
  5482. {
  5483. cProduct[j++] = cTmp[i--];
  5484. }
  5485. cProduct[j] = '\0';
  5486. // We're done. Return 0 for success!
  5487. return(0);
  5488. }
  5489. ///////////////////////////////////////////////////////////////////////////////////////////
  5490. //
  5491. // Function : AscAddUint
  5492. //
  5493. // Date of Creation: 9-3-2001
  5494. //
  5495. // Parameters : IN LPSTR cSum,
  5496. // IN LPSTR cA,
  5497. // IN LPSTR cB
  5498. //
  5499. // Return : DWORD(0 on success, else failure code.)
  5500. //
  5501. // Description : This routine will add two arbitrarily long ascii strings. It makes several
  5502. // assumptions about them.
  5503. //
  5504. // 1) the string is null terminated.
  5505. // 2) The LSB is the last char of the string. "1000000" is a million
  5506. // 3) There are no signs or decimal points.
  5507. // 4) The cSum buffer is large enough to store the result
  5508. // 5) The sum will require 254 bytes or less.
  5509. //
  5510. // Revision History:
  5511. //
  5512. // Date Author Comments
  5513. //
  5514. //////////////////////////////////////////////////////////////////////////////////////////
  5515. DWORD
  5516. AscAddUint(
  5517. IN LPSTR cSum,
  5518. IN LPSTR cA,
  5519. IN LPSTR cB
  5520. )
  5521. {
  5522. int iALen=0, iBLen=0, iBiggerLen=0;
  5523. int i=0,j=0,k=0, iCarry=0;
  5524. char cTmp[POTF_MAX_STRLEN]={0}, *cBigger=NULL;
  5525. // Verify parameters
  5526. if ((cA == NULL) || (cB == NULL) || (cSum == NULL))
  5527. {
  5528. return((DWORD)-1);
  5529. }
  5530. iALen = strlen(cA);
  5531. iBLen = strlen(cB);
  5532. iCarry = 0;
  5533. // Loop through, adding the values. Our result string will be
  5534. // backwards, we'll straighten it out when we copy it to the
  5535. // cSum buffer.
  5536. for (i=0; (i < iALen) && (i < iBLen); i++)
  5537. {
  5538. // Figure out the actual decimal value of the add.
  5539. k = (int) (cA[iALen-i-1] + cB[iBLen-i-1] + iCarry);
  5540. k -= 2 * '0';
  5541. // Set the carry as appropriate
  5542. iCarry = k/10;
  5543. // Set the current digit's value.
  5544. cTmp[i] = '0' + (char)(k%10);
  5545. }
  5546. // At this point, all digits present in both strings have been added.
  5547. // In other words, "12345" + "678901", "12345" has been added to "78901"
  5548. // The next step is to account for the high-order digits of the larger number.
  5549. if (iALen > iBLen)
  5550. {
  5551. cBigger = cA;
  5552. iBiggerLen = iALen;
  5553. }
  5554. else
  5555. {
  5556. cBigger = cB;
  5557. iBiggerLen = iBLen;
  5558. }
  5559. while (i < iBiggerLen)
  5560. {
  5561. k = cBigger[iBiggerLen - i - 1] + iCarry - '0';
  5562. // Set the carry as appropriate
  5563. iCarry = k/10;
  5564. // Set the current digit's value.
  5565. cTmp[i] = '0' + (char)(k%10);
  5566. i++;
  5567. }
  5568. // Finally, we might still have a set carry to put in the next
  5569. // digit.
  5570. if (iCarry)
  5571. {
  5572. cTmp[i++] = '0' + (char)iCarry;
  5573. }
  5574. // Now that we've got the entire number, reverse it and put it back in the dest.
  5575. // Skip leading 0's.
  5576. i = strlen(cTmp) - 1;
  5577. while ((i > 0)&&(cTmp[i] == '0'))
  5578. {
  5579. i--;
  5580. }
  5581. // and copy the number.
  5582. j = 0;
  5583. while (i >= 0)
  5584. {
  5585. cSum[j++] = cTmp[i--];
  5586. }
  5587. cSum[j] = '\0';
  5588. // We're done. Return 0 for success!
  5589. return(0);
  5590. }
  5591. ///////////////////////////////////////////////////////////////////////////////////////////
  5592. //
  5593. // Function : PrintAddrStr
  5594. //
  5595. // Date of Creation: 9-3-2001
  5596. //
  5597. // Parameters : IN PADDR ResolveAddress
  5598. // IN NshHashTable& addressHash
  5599. //
  5600. // Return : VOID
  5601. //
  5602. // Description : Resolves IP address number to char string.
  5603. //
  5604. // Revision History:
  5605. //
  5606. // Date Author Comments
  5607. //
  5608. //////////////////////////////////////////////////////////////////////////////////////////
  5609. VOID
  5610. PrintAddrStr(
  5611. IN PADDR pResolveAddress,
  5612. IN NshHashTable& addressHash,
  5613. IN UINT uiFormat
  5614. )
  5615. {
  5616. switch(pResolveAddress->AddrType)
  5617. {
  5618. case IP_ADDR_WINS_SERVER:
  5619. case IP_ADDR_DHCP_SERVER:
  5620. case IP_ADDR_DNS_SERVER:
  5621. case IP_ADDR_DEFAULT_GATEWAY:
  5622. case IP_ADDR_SUBNET:
  5623. //no resolve required for them... They are self explanatory...
  5624. break;
  5625. default:
  5626. ULONG uIpAddr = pResolveAddress->uIpAddr;
  5627. const char* name = addressHash.Find(uIpAddr);
  5628. if (name == 0)
  5629. {
  5630. HOSTENT* pHostEnt = gethostbyaddr((char *)&uIpAddr, 4, pResolveAddress->AddrType);
  5631. if (pHostEnt)
  5632. {
  5633. name = pHostEnt->h_name;
  5634. }
  5635. else
  5636. {
  5637. name = " ";
  5638. }
  5639. addressHash.Insert(uIpAddr, name);
  5640. }
  5641. PrintMessageFromModule(g_hModule, uiFormat, name);
  5642. break;
  5643. }
  5644. }
  5645. UINT QMPFSDHGroup(DWORD dwPFSGroup)
  5646. {
  5647. UINT PFSGroup;
  5648. switch (dwPFSGroup)
  5649. {
  5650. case PFS_GROUP_MM:
  5651. PFSGroup = DYNAMIC_SHOW_QMP_MM_DH_GROUP;
  5652. break;
  5653. case PFS_GROUP_1:
  5654. PFSGroup = DYNAMIC_SHOW_QMP_DH_GROUP_LOW;
  5655. break;
  5656. case PFS_GROUP_2:
  5657. PFSGroup = DYNAMIC_SHOW_QMP_DH_GROUP_MEDIUM;
  5658. break;
  5659. case PFS_GROUP_2048:
  5660. PFSGroup = DYNAMIC_SHOW_QMP_DH_GROUP_HIGH;
  5661. break;
  5662. default:
  5663. PFSGroup = DYNAMIC_SHOW_QMP_PFS_NONE;
  5664. break;
  5665. }
  5666. return PFSGroup;
  5667. }
  5668. // NshHashTable implementation
  5669. NshHashTable::NshHashTable() throw ()
  5670. {
  5671. for(size_t i = 0; i < NSHHASHTABLESIZE; ++i)
  5672. {
  5673. NsuListInitialize(&table[i]);;
  5674. }
  5675. }
  5676. NshHashTable::~NshHashTable() throw ()
  5677. {
  5678. Clear();
  5679. }
  5680. DWORD NshHashTable::Insert(UINT uiNewKey, const char* szNewData) throw ()
  5681. {
  5682. size_t hash = Hash(uiNewKey);
  5683. if (Find(uiNewKey, hash) != 0)
  5684. {
  5685. return ERROR_DUPLICATE_TAG;
  5686. }
  5687. HashEntry* entry = new HashEntry(&table[hash], uiNewKey, szNewData);
  5688. if (entry == 0)
  5689. {
  5690. delete entry;
  5691. return ERROR_NOT_ENOUGH_MEMORY;
  5692. }
  5693. return ERROR_SUCCESS;
  5694. }
  5695. void NshHashTable::Clear() throw ()
  5696. {
  5697. for (size_t i = 0; i < NSHHASHTABLESIZE; ++i)
  5698. {
  5699. PNSU_LIST_ENTRY pListEntry = NsuListRemoveFront(&table[i]);
  5700. while (pListEntry)
  5701. {
  5702. NsuListEntryRemove(pListEntry);
  5703. const HashEntry* pEntry = HashEntry::Get(pListEntry);
  5704. delete(pEntry);
  5705. pListEntry = NsuListRemoveFront(&table[i]);
  5706. }
  5707. }
  5708. }
  5709. const char* NshHashTable::Find(UINT uiKey) const throw ()
  5710. {
  5711. return Find(uiKey, Hash(uiKey));
  5712. }
  5713. const char* NshHashTable::Find(UINT uiKey, size_t hash) const throw ()
  5714. {
  5715. const HashEntry* entry = FindEntry(uiKey, hash);
  5716. return (entry == 0) ? NULL : entry->Data();
  5717. }
  5718. size_t NshHashTable::Hash(UINT uiKey) const throw ()
  5719. {
  5720. return uiKey % NSHHASHTABLESIZE;
  5721. }
  5722. const NshHashTable::HashEntry* NshHashTable::FindEntry(
  5723. UINT uiKey,
  5724. size_t hash
  5725. ) const throw ()
  5726. {
  5727. NSU_LIST_ITERATOR iterator;
  5728. NsuListIteratorInitialize(&iterator, (PNSU_LIST)&table[hash], 0);
  5729. while (!NsuListIteratorAtEnd(&iterator))
  5730. {
  5731. PNSU_LIST_ENTRY pListEntry = NsuListIteratorCurrent(&iterator);
  5732. const HashEntry* pEntry = HashEntry::Get(pListEntry);
  5733. if (pEntry->Key() == uiKey)
  5734. {
  5735. return pEntry;
  5736. }
  5737. NsuListIteratorNext(&iterator);
  5738. }
  5739. return 0;
  5740. }
  5741. NshHashTable::HashEntry::HashEntry(
  5742. PNSU_LIST pList,
  5743. UINT uiNewKey,
  5744. const char* szNewData
  5745. ) throw ()
  5746. : listEntry(),
  5747. key(uiNewKey)
  5748. {
  5749. NsuListInsertFront(pList, &listEntry);
  5750. char* szTempData;
  5751. NsuStringDupA(&szTempData, 1024, szNewData);
  5752. data = szTempData;
  5753. }
  5754. NshHashTable::HashEntry::~HashEntry() throw ()
  5755. {
  5756. NsuFree(reinterpret_cast<void**>(const_cast<char**>(&data)));
  5757. }
  5758. const NshHashTable::HashEntry* NshHashTable::HashEntry::Get(PNSU_LIST_ENTRY pEntry) throw ()
  5759. {
  5760. return NsuListEntryGetData(pEntry, HashEntry, HashEntry::listEntry);
  5761. }
  5762. UINT NshHashTable::HashEntry::Key() const throw ()
  5763. {
  5764. return key;
  5765. }
  5766. const char* NshHashTable::HashEntry::Data() const throw ()
  5767. {
  5768. return data;
  5769. }