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.

2506 lines
66 KiB

  1. ////////////////////////////////////////////////////////////////////
  2. // Module: Static/StaticShow.cpp
  3. //
  4. // Purpose: Static Module Implementation.
  5. //
  6. // Developers Name: Surya
  7. //
  8. // History:
  9. //
  10. // Date Author Comments
  11. // 10-8-2001 Surya Initial Version. SCM Base line 1.0
  12. //
  13. //
  14. ////////////////////////////////////////////////////////////////////
  15. #include "nshipsec.h"
  16. extern HINSTANCE g_hModule;
  17. extern STORAGELOCATION g_StorageLocation;
  18. ////////////////////////////////////////////////////////////////////
  19. //Function: PrintPolicyTable()
  20. //
  21. //Date of Creation: 21st Aug 2001
  22. //
  23. //Parameters:
  24. // IN PIPSEC_POLICY_DATA pPolicy,
  25. // IN BOOL bVerb,
  26. // IN BOOL bAssigned,
  27. // IN BOOL bWide
  28. //
  29. //Return: VOID
  30. //
  31. //Description:
  32. // This function prints out the Policy information.
  33. //
  34. //Revision History:
  35. //
  36. // Date Author Comments
  37. //
  38. ////////////////////////////////////////////////////////////////////
  39. VOID
  40. PrintPolicyTable(
  41. IN PIPSEC_POLICY_DATA pPolicy,
  42. IN BOOL bVerb,
  43. IN BOOL bAssigned,
  44. IN BOOL bWide
  45. )
  46. {
  47. _TCHAR pszGUIDStr[BUFFER_SIZE]={0};
  48. _TCHAR pszStrTime[BUFFER_SIZE]={0};
  49. _TCHAR pszStrTruncated[BUFFER_SIZE]={0};
  50. DWORD i =0,k=0;
  51. BOOL bDsPolAssigned = FALSE;
  52. if (bVerb)
  53. {
  54. PrintMessageFromModule(g_hModule,SHW_STATIC_PRTFSPEC_NEWLINE);
  55. // print policy name
  56. if(pPolicy->pszIpsecName)
  57. {
  58. TruncateString(pPolicy->pszIpsecName,pszStrTruncated,POL_TRUNC_LEN_TABLE_VER,bWide);
  59. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTPOLICY_POL_NAME_STR,pszStrTruncated);
  60. }
  61. // print policy desc
  62. if(pPolicy->pszDescription)
  63. {
  64. TruncateString(pPolicy->pszDescription,pszStrTruncated,POL_TRUNC_LEN_TABLE_VER,bWide);
  65. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTPOLICY_POL_DESC_STR,pszStrTruncated);
  66. }
  67. else
  68. {
  69. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTPOLICY_POL_DESC_NONE);
  70. }
  71. //print storage info
  72. PrintStorageInfoTable();
  73. //last modified time
  74. FormatTime((time_t)pPolicy->dwWhenChanged, pszStrTime);
  75. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTFILTERDATA_FL_LASTMOD_STR,pszStrTime);
  76. //print GUID
  77. i=StringFromGUID2(pPolicy->PolicyIdentifier,pszGUIDStr,BUFFER_SIZE);
  78. if(i>0 && (_tcscmp(pszGUIDStr,_TEXT(""))!=0))
  79. {
  80. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTFILTERDATA_FL_GUID_STR,pszGUIDStr);
  81. }
  82. if(g_StorageLocation.dwLocation !=IPSEC_DIRECTORY_PROVIDER)
  83. {
  84. if(bAssigned)
  85. {
  86. if (
  87. ERROR_SUCCESS == IPSecIsDomainPolicyAssigned(&bDsPolAssigned) &&
  88. g_StorageLocation.dwLocation != IPSEC_PERSISTENT_PROVIDER &&
  89. bDsPolAssigned
  90. )
  91. {
  92. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTPOLICY_ASSIGNED_AD);
  93. }
  94. else
  95. {
  96. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTPOLICY_ASSIGNED_YES);
  97. }
  98. }
  99. else
  100. {
  101. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTPOLICY_ASSIGNED_NO);
  102. }
  103. }
  104. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTPOLICY_POLL_MIN, (pPolicy->dwPollingInterval)/60);
  105. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTISAKMP_MM_LIFE_FORMAT,(pPolicy->pIpsecISAKMPData->pSecurityMethods[0].Lifetime.Seconds)/60 ,pPolicy->pIpsecISAKMPData->pSecurityMethods[0].QuickModeLimit);
  106. if(pPolicy->pIpsecISAKMPData->ISAKMPPolicy.PfsIdentityRequired)
  107. {
  108. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTPOLICY_MMPFS_YES);
  109. }
  110. else
  111. {
  112. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTPOLICY_MMPFS_NO);
  113. }
  114. //print ISAKMP data structure
  115. if(pPolicy->pIpsecISAKMPData)
  116. {
  117. PrintISAKMPDataTable(pPolicy->pIpsecISAKMPData);
  118. }
  119. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTPOLICY_RULE_COUNT, pPolicy->dwNumNFACount);
  120. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTPOLICY_RULE_TITLE);
  121. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTPOLICY_RULE_UNDERLINE);
  122. //print NFA structure in verbose mode
  123. for (DWORD j=0;j<pPolicy->dwNumNFACount;j++)
  124. {
  125. if(pPolicy->ppIpsecNFAData[j])
  126. {
  127. k=StringFromGUID2(pPolicy->ppIpsecNFAData[j]->NFAIdentifier,pszGUIDStr,BUFFER_SIZE);
  128. if(k>0 && (_tcscmp(pszGUIDStr,_TEXT(""))!=0))
  129. {
  130. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_RULE_ID_GUID,j+1,pszGUIDStr);
  131. }
  132. PrintRuleTable(pPolicy->ppIpsecNFAData[j],bVerb,bWide);
  133. }
  134. }
  135. }
  136. else
  137. {
  138. if(pPolicy->pszIpsecName)
  139. {
  140. TruncateString(pPolicy->pszIpsecName,pszStrTruncated,POL_TRUNC_LEN_TABLE_NVER,bWide);
  141. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTPOLICY_FORMAT32S,pszStrTruncated);
  142. }
  143. else
  144. {
  145. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTFSPEC_NONE_STR);
  146. }
  147. // NFA count
  148. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTFILTER_IP_FORMAT_TAB,pPolicy->dwNumNFACount);
  149. //last modified time
  150. FormatTime((time_t)pPolicy->dwWhenChanged, pszStrTime);
  151. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_RULE_FORMAT23S,pszStrTime);
  152. if(g_StorageLocation.dwLocation != IPSEC_DIRECTORY_PROVIDER)
  153. {
  154. if(bAssigned)
  155. {
  156. if (ERROR_SUCCESS == IPSecIsDomainPolicyAssigned(&bDsPolAssigned) && bDsPolAssigned)
  157. {
  158. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTPOLICY_AD_POL_OVERRIDES);
  159. }
  160. else
  161. {
  162. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTPOLICY_YES_STR);
  163. }
  164. }
  165. else
  166. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTPOLICY_NO_STR);
  167. }
  168. else
  169. {
  170. PrintMessageFromModule(g_hModule,SHW_STATIC_PRTFSPEC_NEWLINE);
  171. }
  172. }
  173. }
  174. ////////////////////////////////////////////////////////////////////
  175. //
  176. //Function: IsAssigned()
  177. //
  178. //Date of Creation: 21st Aug 2001
  179. //
  180. //Parameters:
  181. // IN PIPSEC_POLICY_DATA pPolicy,
  182. // IN HANDLE hStorageHandle
  183. // IN OUT BOOL &bAssigned
  184. //
  185. //Return: DWORD
  186. //
  187. //Description:
  188. // This function checks out whether the specified policy is assigned.
  189. //
  190. //Revision History:
  191. //
  192. // Date Author Comments
  193. //
  194. ////////////////////////////////////////////////////////////////////
  195. DWORD
  196. IsAssigned(
  197. IN PIPSEC_POLICY_DATA pPolicy,
  198. IN HANDLE hStorageHandle,
  199. IN OUT BOOL &bAssigned
  200. )
  201. {
  202. PIPSEC_POLICY_DATA pActive=NULL;
  203. DWORD dwReturnCode = IPSecGetAssignedPolicyData(hStorageHandle, &pActive);
  204. if ((dwReturnCode == ERROR_SUCCESS)&&(pActive!=NULL))
  205. {
  206. if (IsEqualGUID(pPolicy->PolicyIdentifier, pActive->PolicyIdentifier))
  207. {
  208. bAssigned=TRUE;
  209. }
  210. if (pActive)
  211. {
  212. IPSecFreePolicyData(pActive);
  213. }
  214. }
  215. return dwReturnCode;
  216. }
  217. ////////////////////////////////////////////////////////////////////
  218. //
  219. //Function: PrintRuleTable()
  220. //
  221. //Date of Creation: 21st Aug 2001
  222. //
  223. //Parameters:
  224. // IN PIPSEC_NFA_DATA pIpsecNFAData,
  225. // IN BOOL bVerb,
  226. // IN BOOL bWide
  227. //
  228. //Return: VOID
  229. //
  230. //Description:
  231. // This function prints out the Rule information.
  232. //
  233. //Revision History:
  234. //
  235. // Date Author Comments
  236. //
  237. ////////////////////////////////////////////////////////////////////
  238. VOID
  239. PrintRuleTable(
  240. IN PIPSEC_NFA_DATA pIpsecNFAData,
  241. IN BOOL bVerb,
  242. IN BOOL bWide
  243. )
  244. {
  245. _TCHAR pszStrTime[BUFFER_SIZE]={0};
  246. _TCHAR pszStrTruncated[BUFFER_SIZE]={0};
  247. if(!bVerb)
  248. {
  249. if(pIpsecNFAData->dwTunnelIpAddr==0)
  250. {
  251. //whether the rule is activated
  252. if(pIpsecNFAData->dwActiveFlag)
  253. {
  254. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTRULE_YES_STR);
  255. }
  256. else
  257. {
  258. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTRULE_NO_STR);
  259. }
  260. if(pIpsecNFAData->pIpsecFilterData && pIpsecNFAData->pIpsecFilterData->pszIpsecName)
  261. {
  262. TruncateString(pIpsecNFAData->pIpsecFilterData->pszIpsecName,pszStrTruncated,RUL_TRUNC_LEN_TABLE_NVER,bWide);
  263. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTNEGPOL_FORMAT23STAB,pszStrTruncated);
  264. }
  265. else
  266. {
  267. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTRULE_NONE_STR);
  268. }
  269. if(pIpsecNFAData->pIpsecNegPolData && pIpsecNFAData->pIpsecNegPolData->pszIpsecName)
  270. {
  271. TruncateString(pIpsecNFAData->pIpsecNegPolData->pszIpsecName,pszStrTruncated,RUL_TRUNC_LEN_TABLE_NVER,bWide);
  272. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTNEGPOL_FORMAT23STAB,pszStrTruncated);
  273. }
  274. else
  275. {
  276. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTRULE_NONE_STR);
  277. }
  278. // print auth
  279. for (DWORD j=0;j<(pIpsecNFAData->dwAuthMethodCount);j++)
  280. {
  281. if(pIpsecNFAData->ppAuthMethods[j])
  282. {
  283. if(pIpsecNFAData->ppAuthMethods[j]->dwAuthType==IKE_SSPI)
  284. {
  285. //kerb
  286. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTRULE_KERB);
  287. }
  288. else if(pIpsecNFAData->ppAuthMethods[j]->dwAuthType==IKE_RSA_SIGNATURE)
  289. {
  290. //cert
  291. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTRULE_CERT);
  292. }
  293. else if (pIpsecNFAData->ppAuthMethods[j]->dwAuthType==IKE_PRESHARED_KEY)
  294. {
  295. //preshared
  296. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTRULE_PRE);
  297. }
  298. else
  299. {
  300. //none
  301. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTRULE_NONE_STR);
  302. }
  303. }
  304. if(j< (pIpsecNFAData->dwAuthMethodCount-1))
  305. {
  306. PrintMessageFromModule(g_hModule,SHW_STATIC_PRTFSPEC_COMMA);
  307. }
  308. if(!bWide && j==2 && (pIpsecNFAData->dwAuthMethodCount-1)>2 )
  309. {
  310. PrintMessageFromModule(g_hModule,SHW_STATIC_PRTFSPEC_EXTENSION);
  311. break;
  312. }
  313. }
  314. }
  315. else
  316. {
  317. if(pIpsecNFAData->dwActiveFlag)
  318. {
  319. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTRULE_YES_STR);
  320. }
  321. else
  322. {
  323. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTRULE_NO_STR);
  324. }
  325. if(pIpsecNFAData->pIpsecFilterData && pIpsecNFAData->pIpsecFilterData->pszIpsecName)
  326. {
  327. TruncateString(pIpsecNFAData->pIpsecFilterData->pszIpsecName,pszStrTruncated,RUL_TRUNC_LEN_TABLE_NVER,bWide);
  328. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTNEGPOL_FORMAT23STAB,pszStrTruncated);
  329. }
  330. else
  331. {
  332. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTRULE_NONE_STR);
  333. }
  334. if(pIpsecNFAData->pIpsecNegPolData && pIpsecNFAData->pIpsecNegPolData->pszIpsecName)
  335. {
  336. TruncateString(pIpsecNFAData->pIpsecNegPolData->pszIpsecName,pszStrTruncated,RUL_TRUNC_LEN_TABLE_NVER,bWide);
  337. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTNEGPOL_FORMAT23STAB,pszStrTruncated);
  338. }
  339. else
  340. {
  341. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTRULE_NONE_STR);
  342. }
  343. //tunnel address
  344. PrintIPAddrTable(pIpsecNFAData->dwTunnelIpAddr);
  345. }
  346. }
  347. else
  348. {
  349. if(pIpsecNFAData->pszIpsecName)
  350. {
  351. TruncateString(pIpsecNFAData->pszIpsecName,pszStrTruncated,POL_TRUNC_LEN_TABLE_VER,bWide);
  352. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTRULE_RULE_NAME_STR,pszStrTruncated);
  353. }
  354. else if(pIpsecNFAData->pIpsecNegPolData->NegPolType == GUID_NEGOTIATION_TYPE_DEFAULT)
  355. {
  356. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTRULE_RULE_NAME_NONE_STR);
  357. }
  358. else
  359. {
  360. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTRULE_RULE_NAME_NONE);
  361. }
  362. // rule desc
  363. if(pIpsecNFAData->pszDescription)
  364. {
  365. TruncateString(pIpsecNFAData->pszDescription,pszStrTruncated,POL_TRUNC_LEN_TABLE_VER,bWide);
  366. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTPOLICY_POL_DESC_STR,pszStrTruncated);
  367. }
  368. else
  369. {
  370. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTPOLICY_POL_DESC_NONE);
  371. }
  372. //last modified time
  373. FormatTime((time_t)pIpsecNFAData->dwWhenChanged, pszStrTime);
  374. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTFILTERDATA_FL_LASTMOD_STR,pszStrTime);
  375. if(pIpsecNFAData->dwActiveFlag)
  376. {
  377. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTRULE_ACTIVATED_YES);
  378. }
  379. else
  380. {
  381. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTRULE_ACTIVATED_NO);
  382. }
  383. //tunnel address
  384. if(pIpsecNFAData->pIpsecNegPolData->NegPolType != GUID_NEGOTIATION_TYPE_DEFAULT)
  385. {
  386. if(pIpsecNFAData->dwTunnelIpAddr==0)
  387. {
  388. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTRULE_TUNNEL_NONE);
  389. }
  390. else
  391. {
  392. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTRULE_TUNNEL_IP);
  393. PrintIPAddrTable(pIpsecNFAData->dwTunnelIpAddr);
  394. PrintMessageFromModule(g_hModule,SHW_STATIC_PRTFSPEC_NEWLINE);
  395. }
  396. }
  397. //interface type
  398. if(pIpsecNFAData->dwInterfaceType==(DWORD)PAS_INTERFACE_TYPE_ALL)
  399. {
  400. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTRULE_CONN_TYPE_ALL);
  401. }
  402. else if(pIpsecNFAData->dwInterfaceType==(DWORD)PAS_INTERFACE_TYPE_LAN)
  403. {
  404. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTRULE_CONN_TYPE_LAN);
  405. }
  406. else if(pIpsecNFAData->dwInterfaceType==(DWORD)PAS_INTERFACE_TYPE_DIALUP)
  407. {
  408. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTRULE_CONN_TYPE_DIALUP);
  409. }
  410. else
  411. {
  412. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTRULE_CONN_TYPE_UNKNOWN);
  413. }
  414. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTRULE_AUTH_TITLE,pIpsecNFAData->dwAuthMethodCount);
  415. //print auth
  416. for (DWORD j=0;j<(pIpsecNFAData->dwAuthMethodCount);j++)
  417. {
  418. if(pIpsecNFAData->ppAuthMethods[j])
  419. {
  420. PrintAuthMethodsTable(pIpsecNFAData->ppAuthMethods[j]);
  421. }
  422. }
  423. //print filter data structure
  424. if (pIpsecNFAData->pIpsecFilterData)
  425. {
  426. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTRULE_FILTERLIST_TITLE);
  427. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTRULE_FILTERLIST_UNDERLINE);
  428. if(pIpsecNFAData->pIpsecFilterData)
  429. {
  430. PrintFilterDataTable(pIpsecNFAData->pIpsecFilterData,bVerb,bWide);
  431. }
  432. }
  433. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTRULE_FILTERACTION_TITLE);
  434. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTRULE_FILTERACTION_UNDERLINE);
  435. //print filter action data structure
  436. if(pIpsecNFAData->pIpsecNegPolData)
  437. {
  438. PrintNegPolDataTable(pIpsecNFAData->pIpsecNegPolData,bVerb,bWide);
  439. }
  440. }
  441. }
  442. ////////////////////////////////////////////////////////////////////
  443. //
  444. //Function: PrintNegPolData()
  445. //
  446. //Date of Creation: 21st Aug 2001
  447. //
  448. //Parameters:
  449. // IN PIPSEC_NEGPOL_DATA pIpsecNegPolData,
  450. // IN BOOL bVerb,
  451. // IN BOOL bWide
  452. //
  453. //Return: VOID
  454. //
  455. //Description:
  456. // This function prints out the Negotiation Policy information.
  457. //
  458. //Revision History:
  459. //
  460. // Date Author Comments
  461. //
  462. ////////////////////////////////////////////////////////////////////
  463. VOID
  464. PrintNegPolDataTable(
  465. IN PIPSEC_NEGPOL_DATA pIpsecNegPolData,
  466. IN BOOL bVerb,
  467. IN BOOL bWide
  468. )
  469. {
  470. BOOL bSoft=FALSE;
  471. _TCHAR pszGUIDStr[BUFFER_SIZE]={0};
  472. _TCHAR pszStrTruncated[BUFFER_SIZE]={0};
  473. _TCHAR pszStrTime[BUFFER_SIZE]={0};
  474. DWORD i=0;
  475. if(pIpsecNegPolData)
  476. {
  477. if (bVerb)
  478. {
  479. PrintMessageFromModule(g_hModule,SHW_STATIC_PRTFSPEC_NEWLINE);
  480. //filteraction name
  481. if(pIpsecNegPolData->pszIpsecName)
  482. {
  483. TruncateString(pIpsecNegPolData->pszIpsecName,pszStrTruncated,POL_TRUNC_LEN_TABLE_VER,bWide);
  484. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTNEGPOL_FA_NAME_STR,pszStrTruncated);
  485. }
  486. else
  487. {
  488. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTNEGPOL_FA_NAME_NONE);
  489. }
  490. //filteraction desc
  491. if(pIpsecNegPolData->pszDescription)
  492. {
  493. TruncateString(pIpsecNegPolData->pszDescription,pszStrTruncated,POL_TRUNC_LEN_TABLE_VER,bWide);
  494. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTPOLICY_POL_DESC_STR,pszStrTruncated);
  495. }
  496. else
  497. {
  498. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTPOLICY_POL_DESC_NONE);
  499. }
  500. PrintStorageInfoTable();
  501. //negpol action
  502. if (!(pIpsecNegPolData->NegPolType==GUID_NEGOTIATION_TYPE_DEFAULT))
  503. {
  504. if(pIpsecNegPolData->NegPolAction==GUID_NEGOTIATION_ACTION_NO_IPSEC)
  505. {
  506. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTNEGPOL_ACTION_PERMIT);
  507. }
  508. else if(pIpsecNegPolData->NegPolAction==GUID_NEGOTIATION_ACTION_BLOCK)
  509. {
  510. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTNEGPOL_ACTION_BLOCK);
  511. }
  512. else
  513. {
  514. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTNEGPOL_ACTION_NEGOTIATE);
  515. }
  516. }
  517. //secmethods
  518. if(pIpsecNegPolData->pIpsecSecurityMethods)
  519. {
  520. for (DWORD cnt=0;cnt<pIpsecNegPolData->dwSecurityMethodCount;cnt++)
  521. if (CheckSoft(pIpsecNegPolData->pIpsecSecurityMethods[cnt]))
  522. {
  523. bSoft=TRUE;
  524. break;
  525. }
  526. }
  527. //inpass
  528. if(pIpsecNegPolData->NegPolAction==GUID_NEGOTIATION_ACTION_INBOUND_PASSTHRU)
  529. {
  530. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTNEGPOL_INPASS_YES);
  531. }
  532. else
  533. {
  534. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTNEGPOL_INPASS_NO);
  535. }
  536. //soft
  537. if(bSoft)
  538. {
  539. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTNEGPOL_SOFT_YES);
  540. }
  541. else
  542. {
  543. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTNEGPOL_SOFT_NO);
  544. }
  545. if (pIpsecNegPolData->dwSecurityMethodCount )
  546. {
  547. if(pIpsecNegPolData->pIpsecSecurityMethods && pIpsecNegPolData->pIpsecSecurityMethods[0].PfsQMRequired)
  548. {
  549. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTNEGPOL_QMPFS_YES);
  550. }
  551. else
  552. {
  553. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTNEGPOL_QMPFS_NO);
  554. }
  555. }
  556. //lastmodified time
  557. FormatTime((time_t)pIpsecNegPolData->dwWhenChanged, pszStrTime);
  558. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTFILTERDATA_FL_LASTMOD_STR,pszStrTime);
  559. //guid
  560. i=StringFromGUID2(pIpsecNegPolData->NegPolIdentifier,pszGUIDStr,BUFFER_SIZE);
  561. if(i>0 && (_tcscmp(pszGUIDStr,_TEXT(""))!=0))
  562. {
  563. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTFILTERDATA_FL_GUID_STR,pszGUIDStr);
  564. }
  565. if (pIpsecNegPolData->dwSecurityMethodCount)
  566. {
  567. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTNEGPOL_SEC_MTHD_TITLE);
  568. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTNEGPOL_ALGO_TITLE);
  569. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTNEGPOL_ALGO_UNDERLINE);
  570. }
  571. for (DWORD cnt=0;cnt<pIpsecNegPolData->dwSecurityMethodCount;cnt++)
  572. {
  573. //sec methods
  574. if(pIpsecNegPolData->pIpsecSecurityMethods)
  575. {
  576. PrintSecurityMethodsTable(pIpsecNegPolData->pIpsecSecurityMethods[cnt]);
  577. }
  578. }
  579. }
  580. else
  581. {
  582. if(pIpsecNegPolData->pszIpsecName)
  583. {
  584. TruncateString(pIpsecNegPolData->pszIpsecName,pszStrTruncated,FA_TRUNC_LEN_TABLE_NVER,bWide);
  585. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTNEGPOL_FORMAT38S,pszStrTruncated);
  586. }
  587. else
  588. {
  589. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTNEGPOL_NONE_STR);
  590. }
  591. //negpol action
  592. if (!(pIpsecNegPolData->NegPolType==GUID_NEGOTIATION_TYPE_DEFAULT))
  593. {
  594. if(pIpsecNegPolData->NegPolAction==GUID_NEGOTIATION_ACTION_NO_IPSEC)
  595. {
  596. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTNEGPOL_PERMIT_STR);
  597. }
  598. else if(pIpsecNegPolData->NegPolAction==GUID_NEGOTIATION_ACTION_BLOCK)
  599. {
  600. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTNEGPOL_BLOCK_STR);
  601. }
  602. else
  603. {
  604. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTNEGPOL_NEGOTIATE_STR);
  605. }
  606. }
  607. else
  608. {
  609. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTNEGPOL_ACTION_NONE_STR);
  610. }
  611. //last modified
  612. FormatTime((time_t)pIpsecNegPolData->dwWhenChanged, pszStrTime);
  613. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTNEGPOL_FORMAT23SNEWLINE,pszStrTime);
  614. }
  615. }
  616. }
  617. ////////////////////////////////////////////////////////////////////
  618. //
  619. //Function: PrintSecurityMethodsTable()
  620. //
  621. //Date of Creation: 21st Aug 2001
  622. //
  623. //Parameters:
  624. // IN IPSEC_SECURITY_METHOD IpsecSecurityMethods,
  625. //
  626. //Return: VOID
  627. //
  628. //Description:
  629. // This function prints out the the Security Methods information.
  630. //
  631. //Revision History:
  632. //
  633. // Date Author Comments
  634. //
  635. ////////////////////////////////////////////////////////////////////
  636. VOID
  637. PrintSecurityMethodsTable(
  638. IN IPSEC_SECURITY_METHOD IpsecSecurityMethods
  639. )
  640. {
  641. if (!CheckSoft(IpsecSecurityMethods))
  642. {
  643. if(IpsecSecurityMethods.Algos)
  644. {
  645. //print algo
  646. PrintAlgoInfoTable(IpsecSecurityMethods.Algos,IpsecSecurityMethods.Count);
  647. }
  648. //print life
  649. PrintLifeTimeTable(IpsecSecurityMethods.Lifetime);
  650. }
  651. }
  652. /////////////////////////////////////////////////////////////////
  653. //
  654. //Function: PrintAlgoInfo()
  655. //
  656. //Date of Creation: 21st Aug 2001
  657. //
  658. //Parameters:
  659. // IN PIPSEC_ALGO_INFO Algos,
  660. // IN DWORD dwNumAlgos
  661. //
  662. //Return: VOID
  663. //
  664. //Description:
  665. // This function prints out the the Algorithm information.
  666. //
  667. //Revision History:
  668. //
  669. // Date Author Comments
  670. //
  671. /////////////////////////////////////////////////////////////////
  672. VOID
  673. PrintAlgoInfoTable(
  674. IN PIPSEC_ALGO_INFO Algos,
  675. IN DWORD dwNumAlgos
  676. )
  677. {
  678. if(dwNumAlgos==1) //if only auth or encrpt specified
  679. {
  680. //print authentication
  681. if (Algos[0].operation==AUTHENTICATION)
  682. {
  683. if(Algos[0].algoIdentifier==AUTH_ALGO_MD5)
  684. {
  685. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTALGO_MD5);
  686. }
  687. else if(Algos[0].algoIdentifier==AUTH_ALGO_SHA1)
  688. {
  689. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTALGO_SHA1);
  690. }
  691. else
  692. {
  693. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTALGO_NONE);
  694. }
  695. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTALGO_NONE_NONE);
  696. }
  697. else if (Algos[0].operation==ENCRYPTION)
  698. {
  699. //print encription
  700. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTALGO_NONE);
  701. if(Algos[0].secondaryAlgoIdentifier==HMAC_AUTH_ALGO_MD5)
  702. {
  703. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTALGO_MD5_COMMA);
  704. }
  705. else if(Algos[0].secondaryAlgoIdentifier==HMAC_AUTH_ALGO_SHA1)
  706. {
  707. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTALGO_SHA1_COMMA);
  708. }
  709. else
  710. {
  711. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTALGO_NONE_COMMA);
  712. }
  713. if(Algos[0].algoIdentifier==CONF_ALGO_DES)
  714. {
  715. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTALGO_DES_TAB);
  716. }
  717. else if(Algos[0].algoIdentifier==CONF_ALGO_3_DES)
  718. {
  719. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTALGO_3DES_TAB);
  720. }
  721. else
  722. {
  723. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTALGO_NONE_TAB);
  724. }
  725. }
  726. }
  727. else if(dwNumAlgos==2) //if both auth and encrpt specified
  728. {
  729. //encryption
  730. if (Algos[0].operation==ENCRYPTION)
  731. {
  732. if (Algos[1].operation==AUTHENTICATION)
  733. {
  734. if(Algos[1].algoIdentifier==AUTH_ALGO_MD5)
  735. {
  736. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTALGO_MD5);
  737. }
  738. else
  739. {
  740. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTALGO_SHA1);
  741. }
  742. }
  743. else
  744. {
  745. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTALGO_NONE);
  746. }
  747. if(Algos[0].secondaryAlgoIdentifier==HMAC_AUTH_ALGO_MD5)
  748. {
  749. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTALGO_MD5_COMMA);
  750. }
  751. else if(Algos[0].secondaryAlgoIdentifier==HMAC_AUTH_ALGO_SHA1)
  752. {
  753. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTALGO_SHA1_COMMA);
  754. }
  755. else
  756. {
  757. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTALGO_NONE_COMMA);
  758. }
  759. if(Algos[0].algoIdentifier==CONF_ALGO_DES)
  760. {
  761. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTALGO_DES_TAB);
  762. }
  763. else if(Algos[0].algoIdentifier==CONF_ALGO_3_DES)
  764. {
  765. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTALGO_3DES_TAB);
  766. }
  767. else
  768. {
  769. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTALGO_NONE_TAB);
  770. }
  771. }
  772. else //authentication
  773. {
  774. if (Algos[0].operation==AUTHENTICATION)
  775. {
  776. if(Algos[0].algoIdentifier==AUTH_ALGO_MD5)
  777. {
  778. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTALGO_MD5);
  779. }
  780. else
  781. {
  782. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTALGO_SHA1);
  783. }
  784. }
  785. else
  786. {
  787. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTALGO_NONE);
  788. }
  789. if(Algos[1].secondaryAlgoIdentifier==HMAC_AUTH_ALGO_MD5)
  790. {
  791. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTALGO_MD5_COMMA);
  792. }
  793. else if(Algos[1].secondaryAlgoIdentifier==HMAC_AUTH_ALGO_SHA1)
  794. {
  795. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTALGO_SHA1_COMMA);
  796. }
  797. else
  798. {
  799. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTALGO_NONE_COMMA);
  800. }
  801. if(Algos[1].algoIdentifier==CONF_ALGO_DES)
  802. {
  803. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTALGO_DES_TAB);
  804. }
  805. else if(Algos[1].algoIdentifier==CONF_ALGO_3_DES)
  806. {
  807. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTALGO_3DES_TAB);
  808. }
  809. else
  810. {
  811. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTALGO_NONE_TAB);
  812. }
  813. }
  814. }
  815. }
  816. /////////////////////////////////////////////////////////////////
  817. //
  818. //Function: PrintLifeTimeTable()
  819. //
  820. //Date of Creation: 21st Aug 2001
  821. //
  822. //Parameters:
  823. // IN LIFETIME LifeTime
  824. //
  825. //Return: VOID
  826. //
  827. //Description:
  828. // This function prints out the Life Time details.
  829. //
  830. //Revision History:
  831. //
  832. // Date Author Comments
  833. //
  834. /////////////////////////////////////////////////////////////////
  835. VOID
  836. PrintLifeTimeTable(
  837. IN LIFETIME LifeTime
  838. )
  839. {
  840. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTLIFE_FORMAT,LifeTime.KeyExpirationTime,LifeTime.KeyExpirationBytes);
  841. }
  842. /////////////////////////////////////////////////////////////////
  843. //
  844. //Function: CheckSoft()
  845. //
  846. //Date of Creation: 21st Aug 2001
  847. //
  848. //Parameters:
  849. // IN IPSEC_SECURITY_METHOD IpsecSecurityMethods
  850. //
  851. //Return: BOOL
  852. //
  853. //Description:
  854. // This function checks whether soft association exists.
  855. //
  856. //Revision History:
  857. //
  858. // Date Author Comments
  859. //
  860. ///////////////////////////////////////////////////////////////////
  861. BOOL
  862. CheckSoft(
  863. IN IPSEC_SECURITY_METHOD IpsecSecurityMethods
  864. )
  865. {
  866. BOOL bSoft=FALSE;
  867. if (IpsecSecurityMethods.Count==0)
  868. {
  869. bSoft=TRUE;
  870. }
  871. return bSoft;
  872. }
  873. /////////////////////////////////////////////////////////////////
  874. //
  875. //Function: PrintAuthMethodsTable()
  876. //
  877. //Date of Creation: 21st Aug 2001
  878. //
  879. //Parameters:
  880. // IN PIPSEC_AUTH_METHOD pIpsecAuthData
  881. //
  882. //Return: VOID
  883. //
  884. //Description:
  885. // This function prints out Authentication details.
  886. //
  887. //Revision History:
  888. //
  889. // Date Author Comments
  890. //
  891. /////////////////////////////////////////////////////////////////
  892. VOID
  893. PrintAuthMethodsTable(
  894. IN PIPSEC_AUTH_METHOD pIpsecAuthData
  895. )
  896. {
  897. if(pIpsecAuthData)
  898. {
  899. PrintMessageFromModule(g_hModule,SHW_STATIC_PRTFSPEC_NEWLINE);
  900. if(pIpsecAuthData->dwAuthType==IKE_SSPI) //kerb
  901. {
  902. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTAUTH_KERB);
  903. }
  904. else if(pIpsecAuthData->dwAuthType==IKE_RSA_SIGNATURE && pIpsecAuthData->pszAuthMethod)
  905. {
  906. //cert
  907. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTAUTH_ROOTCA_FORMAT,pIpsecAuthData->pszAuthMethod);
  908. //cert mapping flag
  909. if((g_StorageLocation.dwLocation != IPSEC_DIRECTORY_PROVIDER && IsDomainMember(g_StorageLocation.pszMachineName))||(g_StorageLocation.dwLocation == IPSEC_DIRECTORY_PROVIDER))
  910. {
  911. if(pIpsecAuthData->dwAuthFlags & IPSEC_MM_CERT_AUTH_ENABLE_ACCOUNT_MAP)
  912. {
  913. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_POLICY_CERT_MAP_YES);
  914. }
  915. else
  916. {
  917. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_POLICY_CERT_MAP_NO);
  918. }
  919. }
  920. if (pIpsecAuthData->dwAuthFlags & IPSEC_MM_CERT_AUTH_DISABLE_CERT_REQUEST)
  921. {
  922. PrintMessageFromModule(g_hModule, SHW_AUTH_EXCLUDE_CA_NAME_YES_STR);
  923. }
  924. else
  925. {
  926. PrintMessageFromModule(g_hModule, SHW_AUTH_EXCLUDE_CA_NAME_NO_STR);
  927. }
  928. }
  929. else if (pIpsecAuthData->dwAuthType==IKE_PRESHARED_KEY && pIpsecAuthData->pszAuthMethod)
  930. {
  931. //preshared key
  932. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTAUTH_PRE_FORMAT,pIpsecAuthData->pszAuthMethod);
  933. }
  934. else
  935. {
  936. //none
  937. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTAUTH_NONE_AUTH_STR);
  938. }
  939. }
  940. }
  941. /////////////////////////////////////////////////////////////////
  942. //
  943. //Function: PrintFilterDataTable()
  944. //
  945. //Date of Creation: 21st Aug 2001
  946. //
  947. //Parameters:
  948. // IN PIPSEC_FILTER_DATA pIpsecFilterData,
  949. // IN BOOL bVerb,
  950. // IN BOOL bWide
  951. //
  952. //Return: VOID
  953. //
  954. //Description:
  955. // This function prints out Filter list details.
  956. //
  957. //Revision History:
  958. //
  959. // Date Author Comments
  960. //
  961. /////////////////////////////////////////////////////////////////
  962. DWORD
  963. PrintFilterDataTable(
  964. IN PIPSEC_FILTER_DATA pIpsecFilterData,
  965. IN BOOL bVerb,
  966. IN BOOL bWide
  967. )
  968. {
  969. BOOL bTitlePrinted=FALSE;
  970. _TCHAR pszGUIDStr[BUFFER_SIZE]={0};
  971. _TCHAR pszStrTime[BUFFER_SIZE]={0};
  972. _TCHAR pszStrTruncated[BUFFER_SIZE]={0};
  973. DWORD i=0,dwReturn = ERROR_SUCCESS;
  974. if (pIpsecFilterData)
  975. {
  976. if(bVerb)
  977. {
  978. //filterlist name
  979. if(pIpsecFilterData->pszIpsecName)
  980. {
  981. TruncateString(pIpsecFilterData->pszIpsecName,pszStrTruncated,POL_TRUNC_LEN_TABLE_VER,bWide);
  982. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTFILTERDATA_FL_NAME_STR,pszStrTruncated);
  983. }
  984. else
  985. {
  986. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTFILTERDATA_FL_NAME_NONE);
  987. }
  988. //filterlist desc
  989. if(pIpsecFilterData->pszDescription)
  990. {
  991. TruncateString(pIpsecFilterData->pszDescription,pszStrTruncated,POL_TRUNC_LEN_TABLE_VER,bWide);
  992. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTPOLICY_POL_DESC_STR,pszStrTruncated);
  993. }
  994. else
  995. {
  996. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTPOLICY_POL_DESC_NONE);
  997. }
  998. PrintStorageInfoTable();
  999. //last modified
  1000. FormatTime((time_t)pIpsecFilterData->dwWhenChanged, pszStrTime);
  1001. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTFILTERDATA_FL_LASTMOD_STR,pszStrTime);
  1002. //guid
  1003. i=StringFromGUID2(pIpsecFilterData->FilterIdentifier,pszGUIDStr,BUFFER_SIZE);
  1004. if(i>0 && (_tcscmp(pszGUIDStr,_TEXT(""))!=0))
  1005. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTFILTERDATA_FL_GUID_STR,pszGUIDStr);
  1006. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTFILTERDATA_FILTER_COUNT,pIpsecFilterData->dwNumFilterSpecs);
  1007. for (DWORD k=0;k<pIpsecFilterData->dwNumFilterSpecs;k++)
  1008. {
  1009. //print filter specs
  1010. if(!bTitlePrinted)
  1011. {
  1012. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTFILTERDATA_FILTERS_TITLE);
  1013. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTFSPEC_FILTER_TITLE);
  1014. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTFSPEC_FILTER_UNDERLINE);
  1015. bTitlePrinted=TRUE;
  1016. }
  1017. PrintFilterSpecTable(pIpsecFilterData->ppFilterSpecs[k]);
  1018. }
  1019. }
  1020. else
  1021. {
  1022. if(pIpsecFilterData->pszIpsecName)
  1023. {
  1024. TruncateString(pIpsecFilterData->pszIpsecName,pszStrTruncated,FL_TRUNC_LEN_TABLE_NVER,bWide);
  1025. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTFSPEC_FORMAT45S,pszStrTruncated);
  1026. }
  1027. else
  1028. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTFSPEC_NONE_TAB);
  1029. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTFSPEC_FORMAT5D,pIpsecFilterData->dwNumFilterSpecs);
  1030. //last modified
  1031. FormatTime((time_t)pIpsecFilterData->dwWhenChanged, pszStrTime);
  1032. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTFSPEC_FORMATS,pszStrTime);
  1033. }
  1034. }
  1035. return dwReturn;
  1036. }
  1037. //////////////////////////////////////////////////////////////////////////
  1038. //Function: PrintIPAddrTable()
  1039. //
  1040. //Date of Creation: 21st Aug 2001
  1041. //
  1042. //Parameters:
  1043. // IN DWORD dwAddr
  1044. //
  1045. ///Return: VOID
  1046. //
  1047. //Description:
  1048. // This function prints out IP Address.
  1049. //
  1050. //Revision History:
  1051. //
  1052. // Date Author Comments
  1053. //
  1054. //////////////////////////////////////////////////////////////////////////
  1055. VOID
  1056. PrintIPAddrTable(
  1057. IN DWORD dwAddr
  1058. )
  1059. {
  1060. _TCHAR szIPAddr[20]= {0};
  1061. // not necessary to change to bounded printf
  1062. _stprintf(szIPAddr,_T("%d.%d.%d.%d"), (dwAddr & 0x000000FFL),((dwAddr & 0x0000FF00L) >> 8),((dwAddr & 0x00FF0000L) >> 16),((dwAddr & 0xFF000000L) >> 24) );
  1063. PrintMessageFromModule(g_hModule,SHW_STATIC_PRTFSPEC_FORMAT15S,szIPAddr);
  1064. }
  1065. //////////////////////////////////////////////////////////////////////////
  1066. //
  1067. //Function: GetFilterDNSDetails()
  1068. //
  1069. //Date of Creation: 21st Aug 2001
  1070. //
  1071. //Parameters:
  1072. // IN PIPSEC_FILTER_SPEC pFilterData,
  1073. // IN OUT PFILTERDNS pFilterDNS
  1074. //
  1075. //Return: VOID
  1076. //
  1077. //Description:
  1078. // This function gets the details of DNS information.
  1079. //
  1080. //Revision History:
  1081. //
  1082. // Date Author Comments
  1083. //
  1084. //////////////////////////////////////////////////////////////////////////
  1085. VOID
  1086. GetFilterDNSDetails(
  1087. IN PIPSEC_FILTER_SPEC pFilterData,
  1088. IN OUT PFILTERDNS pFilterDNS
  1089. )
  1090. {
  1091. if ((pFilterData->Filter.SrcAddr == 0) && (pFilterData->Filter.SrcMask == MASK_ME) && (WcsCmp0(pFilterData->pszSrcDNSName,_TEXT("")) == 0))
  1092. {
  1093. pFilterDNS->FilterSrcNameID=FILTER_MYADDRESS;
  1094. }
  1095. else
  1096. {
  1097. if (WcsCmp0(pFilterData->pszSrcDNSName,_TEXT("")) != 0)
  1098. {
  1099. pFilterDNS->FilterSrcNameID=FILTER_DNSADDRESS; //DNS name
  1100. }
  1101. else if ((pFilterData->Filter.SrcAddr == 0) && (pFilterData->Filter.SrcMask == 0))
  1102. {
  1103. pFilterDNS->FilterSrcNameID=FILTER_ANYADDRESS; //any
  1104. }
  1105. else if ((pFilterData->Filter.SrcAddr != 0) && (pFilterData->Filter.SrcMask == MASK_ME))
  1106. {
  1107. pFilterDNS->FilterSrcNameID=FILTER_IPADDRESS; //a specific IP
  1108. }
  1109. else if ((pFilterData->Filter.SrcAddr != 0) && (pFilterData->Filter.SrcMask != 0))
  1110. {
  1111. pFilterDNS->FilterSrcNameID=FILTER_IPSUBNET; //a specific IP subnet
  1112. }
  1113. else
  1114. {
  1115. pFilterDNS->FilterSrcNameID=FILTER_ANYADDRESS; //any
  1116. }
  1117. }
  1118. if ((pFilterData->Filter.DestAddr == 0) && (pFilterData->Filter.DestMask == 0) && ((WcsCmp0(pFilterData->pszDestDNSName,_TEXT("")) == 0) == 0))
  1119. {
  1120. pFilterDNS->FilterDestNameID= FILTER_ANYADDRESS; //any
  1121. }
  1122. else
  1123. {
  1124. if (WcsCmp0(pFilterData->pszDestDNSName,_TEXT("")) != 0)
  1125. {
  1126. pFilterDNS->FilterDestNameID = FILTER_DNSADDRESS; //DNA name
  1127. }
  1128. else if ((pFilterData->Filter.DestAddr == 0) && (pFilterData->Filter.DestMask == MASK_ME))
  1129. {
  1130. pFilterDNS->FilterDestNameID = FILTER_MYADDRESS; //me
  1131. }
  1132. else if ((pFilterData->Filter.DestAddr != 0) && (pFilterData->Filter.DestMask == MASK_ME))
  1133. {
  1134. pFilterDNS->FilterDestNameID = FILTER_IPADDRESS; //a specifiec IP
  1135. }
  1136. else if ((pFilterData->Filter.DestAddr != 0) && (pFilterData->Filter.DestMask != 0))
  1137. {
  1138. pFilterDNS->FilterDestNameID =FILTER_IPSUBNET; //a specific subnet
  1139. }
  1140. else
  1141. {
  1142. pFilterDNS->FilterDestNameID = FILTER_ANYADDRESS; //any
  1143. }
  1144. }
  1145. }
  1146. //////////////////////////////////////////////////////////////////////////
  1147. //
  1148. //Function: PrintFilterSpecTable()
  1149. //
  1150. //Date of Creation: 21st Aug 2001
  1151. //
  1152. //Parameters:
  1153. // IN PIPSEC_FILTER_SPEC pIpsecFilterSpec
  1154. //
  1155. //Return: DWORD
  1156. //
  1157. //Description:
  1158. //
  1159. // This function prints the Filter Spec details
  1160. //
  1161. //Revision History:
  1162. //
  1163. // Date Author Comments
  1164. //
  1165. //////////////////////////////////////////////////////////////////////////
  1166. DWORD
  1167. PrintFilterSpecTable(
  1168. IN PIPSEC_FILTER_SPEC pIpsecFilterSpec
  1169. )
  1170. {
  1171. DWORD dwReturn = ERROR_SUCCESS;
  1172. PFILTERDNS pFilterDNS= new FILTERDNS;
  1173. if(pFilterDNS == NULL)
  1174. {
  1175. dwReturn = ERROR_OUTOFMEMORY;
  1176. BAIL_OUT;
  1177. }
  1178. GetFilterDNSDetails(pIpsecFilterSpec, pFilterDNS);
  1179. if(pIpsecFilterSpec->dwMirrorFlag)
  1180. {
  1181. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTFSPEC_YES_STR_TAB);
  1182. }
  1183. else
  1184. {
  1185. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTFSPEC_NO_STR_TAB);
  1186. }
  1187. // print the filter details
  1188. PrintFilterTable(pIpsecFilterSpec->Filter,pFilterDNS);
  1189. error:
  1190. return dwReturn;
  1191. }
  1192. /////////////////////////////////////////////////////////////////////////
  1193. //
  1194. //Function: PrintFilterTable()
  1195. //
  1196. //Date of Creation: 21st Aug 2001
  1197. //
  1198. //Parameters:
  1199. // IN IPSEC_FILTER Filter,
  1200. // IN PFILTERDNS pFilterDNS
  1201. //
  1202. //Return: VOID
  1203. //
  1204. //Description:
  1205. // This function prints the Filter details
  1206. //
  1207. //Revision History:
  1208. //
  1209. // Date Author Comments
  1210. //
  1211. /////////////////////////////////////////////////////////////////////////
  1212. VOID
  1213. PrintFilterTable(
  1214. IN IPSEC_FILTER Filter,
  1215. IN PFILTERDNS pFilterDNS
  1216. )
  1217. {
  1218. //Source details
  1219. if ((pFilterDNS->FilterSrcNameID==FILTER_MYADDRESS)&&(Filter.SrcAddr==0))
  1220. {
  1221. if((Filter.ExType == EXT_NORMAL)||((Filter.ExType & EXT_DEST)== EXT_DEST))
  1222. {
  1223. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTFILTER_MY_IP_ADDR); // my IP
  1224. }
  1225. else if((Filter.ExType & EXT_DEST) != EXT_DEST) //special servers
  1226. {
  1227. if((Filter.ExType & EXT_DEFAULT_GATEWAY) == EXT_DEFAULT_GATEWAY)
  1228. {
  1229. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTFILTER_DEFGATE_TAB);
  1230. }
  1231. else if((Filter.ExType & EXT_DHCP_SERVER) == EXT_DHCP_SERVER)
  1232. {
  1233. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTFILTER_DHCP_TAB);
  1234. }
  1235. else if((Filter.ExType & EXT_WINS_SERVER) == EXT_WINS_SERVER)
  1236. {
  1237. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTFILTER_WINS_TAB);
  1238. }
  1239. else if((Filter.ExType & EXT_DNS_SERVER) == EXT_DNS_SERVER)
  1240. {
  1241. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTFILTER_DNS_TAB);
  1242. }
  1243. }
  1244. }
  1245. else if ((pFilterDNS->FilterSrcNameID==FILTER_ANYADDRESS)&&(Filter.SrcAddr==0))
  1246. {
  1247. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTFILTER_ANY_IP_ADDR); //any IP address
  1248. }
  1249. else
  1250. {
  1251. PrintIPAddrTable(Filter.SrcAddr); //print specific IP addr
  1252. }
  1253. PrintIPAddrTable(Filter.SrcMask); //mask
  1254. //Destination details
  1255. if ((pFilterDNS->FilterDestNameID==FILTER_MYADDRESS)&&(Filter.DestAddr==0))
  1256. {
  1257. if((Filter.ExType == EXT_NORMAL)||((Filter.ExType & EXT_DEST) != EXT_DEST)) //my ip addr
  1258. {
  1259. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTFILTER_MY_IP_ADDR);
  1260. }
  1261. else if((Filter.ExType & EXT_DEST) == EXT_DEST) // special servers
  1262. {
  1263. if((Filter.ExType & EXT_DEFAULT_GATEWAY) == EXT_DEFAULT_GATEWAY)
  1264. {
  1265. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTFILTER_DEFGATE_TAB);
  1266. }
  1267. else if((Filter.ExType & EXT_DHCP_SERVER) == EXT_DHCP_SERVER)
  1268. {
  1269. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTFILTER_DHCP_TAB);
  1270. }
  1271. else if((Filter.ExType & EXT_WINS_SERVER) == EXT_WINS_SERVER)
  1272. {
  1273. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTFILTER_WINS_TAB);
  1274. }
  1275. else if((Filter.ExType & EXT_DNS_SERVER) == EXT_DNS_SERVER)
  1276. {
  1277. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTFILTER_DNS_TAB);
  1278. }
  1279. }
  1280. }
  1281. else if ((pFilterDNS->FilterDestNameID==FILTER_ANYADDRESS)&&(Filter.DestAddr==0))
  1282. {
  1283. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTFILTER_ANY_IP_ADDR); //any
  1284. }
  1285. else
  1286. {
  1287. PrintIPAddrTable(Filter.DestAddr); //print specific addr
  1288. }
  1289. PrintIPAddrTable(Filter.DestMask); //mask
  1290. PrintProtocolNameTable(Filter.Protocol);
  1291. if(Filter.SrcPort)
  1292. {
  1293. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTFILTER_IP_FORMAT_TAB,Filter.SrcPort);
  1294. }
  1295. else
  1296. {
  1297. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTFILTER_ANY_STR_TAB);
  1298. }
  1299. if(Filter.DestPort)
  1300. {
  1301. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTFILTER_IP_FORMAT_NEWLINE,Filter.DestPort);
  1302. }
  1303. else
  1304. {
  1305. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTFILTER_ANY_STR_NEWLINE);
  1306. }
  1307. }
  1308. /////////////////////////////////////////////////////////////////////////
  1309. //
  1310. //Function: PrintProtocolName()
  1311. //
  1312. //Date of Creation: 21st Aug 2001
  1313. //
  1314. //Parameters:
  1315. // DWORD dwProtocol
  1316. //
  1317. //Return: VOID
  1318. //
  1319. //Description:
  1320. // This function prints protocol name corresponding to protocoll ID.
  1321. //
  1322. //Revision History:
  1323. //
  1324. // Date Author Comments
  1325. //
  1326. /////////////////////////////////////////////////////////////////////////
  1327. VOID
  1328. PrintProtocolNameTable(
  1329. DWORD dwProtocol
  1330. )
  1331. {
  1332. switch(dwProtocol)
  1333. {
  1334. case PROT_ID_ICMP :
  1335. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTPROTOCOL_ICMP_TAB);
  1336. break;
  1337. case PROT_ID_TCP :
  1338. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTPROTOCOL_TCP_TAB);
  1339. break;
  1340. case PROT_ID_UDP :
  1341. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTPROTOCOL_UDP_TAB);
  1342. break;
  1343. case PROT_ID_RAW :
  1344. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTPROTOCOL_RAW_TAB);
  1345. break;
  1346. case PROT_ID_ANY :
  1347. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTPROTOCOL_ANY_TAB);
  1348. break;
  1349. default:
  1350. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTPROTOCOL_OTHER_TAB);
  1351. break;
  1352. };
  1353. }
  1354. /////////////////////////////////////////////////////////////////////////
  1355. //
  1356. //Function: PrintISAKMPDataTable()
  1357. //
  1358. //Date of Creation: 21st Aug 2001
  1359. //
  1360. //Parameters:
  1361. // IN PIPSEC_ISAKMP_DATA pIpsecISAKMPData,
  1362. //
  1363. //Return: VOID
  1364. //
  1365. //Description:
  1366. // This function prints out the ISAKMP details.
  1367. //
  1368. //Revision History:
  1369. //
  1370. // Date Author Comments
  1371. //
  1372. /////////////////////////////////////////////////////////////////////////
  1373. VOID
  1374. PrintISAKMPDataTable(
  1375. IN PIPSEC_ISAKMP_DATA pIpsecISAKMPData
  1376. )
  1377. {
  1378. if(pIpsecISAKMPData)
  1379. {
  1380. //ISAKMP details
  1381. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTISAKMP_MMSEC_TITLE);
  1382. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTISAKMP_MMSEC_MTD_TILE);
  1383. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTISAKMP_MMSEC_MTD_UNDERLINE);
  1384. for (DWORD Loop=0;Loop<pIpsecISAKMPData->dwNumISAKMPSecurityMethods;Loop++)
  1385. {
  1386. if(pIpsecISAKMPData->pSecurityMethods)
  1387. {
  1388. PrintISAKAMPSecurityMethodsTable(pIpsecISAKMPData->pSecurityMethods[Loop]);
  1389. }
  1390. }
  1391. }
  1392. }
  1393. /////////////////////////////////////////////////////////////////////////
  1394. //
  1395. //Function: PrintISAKAMPSecurityMethodsTable()
  1396. //
  1397. //Date of Creation: 21st Aug 2001
  1398. //
  1399. //Parameters:
  1400. // IN CRYPTO_BUNDLE SecurityMethods,
  1401. //
  1402. //Return: VOID
  1403. //
  1404. //Description:
  1405. // This function prints out the ISAKMP SecurityMethods details.
  1406. //
  1407. //Revision History:
  1408. //
  1409. // Date Author Comments
  1410. //
  1411. /////////////////////////////////////////////////////////////////////////
  1412. VOID
  1413. PrintISAKAMPSecurityMethodsTable(
  1414. IN CRYPTO_BUNDLE SecurityMethods
  1415. )
  1416. {
  1417. // encription
  1418. if(SecurityMethods.EncryptionAlgorithm.AlgorithmIdentifier==CONF_ALGO_DES)
  1419. {
  1420. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTISAKMPSEC_DES_TAB);
  1421. }
  1422. else
  1423. {
  1424. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTISAKMPSEC_3DES_TAB);
  1425. }
  1426. //hash algo
  1427. if(SecurityMethods.HashAlgorithm.AlgorithmIdentifier==AUTH_ALGO_SHA1)
  1428. {
  1429. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTISAKMPSEC_SHA1_TAB);
  1430. }
  1431. else
  1432. {
  1433. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTISAKMPSEC_MD5_TAB);
  1434. }
  1435. //DH group
  1436. if(SecurityMethods.OakleyGroup==POTF_OAKLEY_GROUP1)
  1437. {
  1438. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTISAKMPSEC_DH_LOW);
  1439. }
  1440. else if (SecurityMethods.OakleyGroup==POTF_OAKLEY_GROUP2)
  1441. {
  1442. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTISAKMPSEC_DH_MEDIUM);
  1443. }
  1444. else
  1445. {
  1446. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTISAKMPSEC_DH_2048);
  1447. }
  1448. }
  1449. /////////////////////////////////////////////////////////////////////////
  1450. //
  1451. //Function: PrintStandAloneFAData()
  1452. //
  1453. //Date of Creation: 21st Aug 2001
  1454. //
  1455. //Parameters:
  1456. // IN HANDLE hPolicyStorage,
  1457. // IN BOOL bVerbose,
  1458. // IN BOOL bTable,
  1459. // IN BOOL bWide
  1460. //
  1461. //Return: DWORD
  1462. //
  1463. //Description:
  1464. // This function prints out the Filter actions details ,unattached to any of the policies.
  1465. //
  1466. //Revision History:
  1467. //
  1468. // Date Author Comments
  1469. //
  1470. /////////////////////////////////////////////////////////////////////////
  1471. DWORD
  1472. PrintStandAloneFAData(
  1473. IN HANDLE hPolicyStorage,
  1474. IN BOOL bVerbose,
  1475. IN BOOL bTable,
  1476. IN BOOL bWide
  1477. )
  1478. {
  1479. DWORD dwReturnCode = S_OK;
  1480. BOOL bTitlePrinted=FALSE, bStandAlone=TRUE;
  1481. PIPSEC_NEGPOL_DATA *ppNegPolEnum = NULL,pNegPol=NULL;
  1482. DWORD dwNumNegPol=0;
  1483. DWORD cnt=0,num=1;
  1484. dwReturnCode = IPSecEnumNegPolData(hPolicyStorage, &ppNegPolEnum, &dwNumNegPol);
  1485. if (!(dwReturnCode == ERROR_SUCCESS && dwNumNegPol > 0 && ppNegPolEnum != NULL))
  1486. {
  1487. BAIL_OUT; // if no FA , bail out of the function
  1488. }
  1489. for(cnt=0; cnt < dwNumNegPol;cnt++)
  1490. {
  1491. bStandAlone=TRUE;
  1492. dwReturnCode = IPSecCopyNegPolData(ppNegPolEnum[cnt], &pNegPol);
  1493. if ((dwReturnCode == ERROR_SUCCESS) && (pNegPol != NULL)&&(pNegPol->NegPolType!=GUID_NEGOTIATION_TYPE_DEFAULT))
  1494. {
  1495. //check whether it is stand alone
  1496. dwReturnCode= IsStandAloneFA(pNegPol,hPolicyStorage,bStandAlone);
  1497. if (dwReturnCode == ERROR_SUCCESS)
  1498. {
  1499. if(bStandAlone) // if standalone print the details of it
  1500. {
  1501. if(!bTitlePrinted)
  1502. {
  1503. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTSAFA_STAND_ALONE_FA_TITLE);
  1504. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTSAFA_STAND_ALONE_FA_UNDERLINE);
  1505. }
  1506. num++;
  1507. if(bTable)
  1508. PrintNegPolDataTable(pNegPol,bVerbose,bWide);
  1509. else
  1510. PrintNegPolDataList(pNegPol,bVerbose,bWide);
  1511. bTitlePrinted=TRUE;
  1512. }
  1513. }
  1514. if(pNegPol) IPSecFreeNegPolData(pNegPol);
  1515. }
  1516. if (dwReturnCode != ERROR_SUCCESS) break;
  1517. }
  1518. // clean up
  1519. if (dwNumNegPol > 0 && ppNegPolEnum != NULL)
  1520. {
  1521. IPSecFreeMulNegPolData( ppNegPolEnum,dwNumNegPol);
  1522. }
  1523. if(num-1)
  1524. {
  1525. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTSAFA_STAND_ALONE_FA_COUNT,num-1);
  1526. }
  1527. error:
  1528. return dwReturnCode;
  1529. }
  1530. /////////////////////////////////////////////////////////////////////////
  1531. //
  1532. //Function: IsStandAloneFA()
  1533. //
  1534. //Date of Creation: 21st Aug 2001
  1535. //
  1536. //Parameters:
  1537. // IN PIPSEC_NEGPOL_DATA pNegPol,
  1538. // IN HANDLE hPolicyStorage
  1539. //
  1540. //Return: VOID
  1541. //
  1542. //Description:
  1543. // This function checks whether the specified Filter Action is unattached to any of the policies.
  1544. //
  1545. //Revision History:
  1546. //
  1547. // Date Author Comments
  1548. //
  1549. /////////////////////////////////////////////////////////////////////////
  1550. DWORD
  1551. IsStandAloneFA(
  1552. IN PIPSEC_NEGPOL_DATA pNegPol,
  1553. IN HANDLE hPolicyStorage,
  1554. IN OUT BOOL &bStandAlone
  1555. )
  1556. {
  1557. PIPSEC_POLICY_DATA *ppPolicyEnum = NULL,pPolicy=NULL;
  1558. DWORD dwNumPolicies = 0 , i = 0;
  1559. RPC_STATUS RpcStat;
  1560. DWORD dwReturnCode = S_OK;
  1561. dwReturnCode = IPSecEnumPolicyData(hPolicyStorage, &ppPolicyEnum, &dwNumPolicies);
  1562. if (!(dwReturnCode == ERROR_SUCCESS && dwNumPolicies > 0 && ppPolicyEnum != NULL))
  1563. {
  1564. dwReturnCode = ERROR_SUCCESS;
  1565. BAIL_OUT; // if nothing exists , bail out
  1566. }
  1567. for (i = 0; i < dwNumPolicies; i++)
  1568. {
  1569. dwReturnCode = IPSecCopyPolicyData(ppPolicyEnum[i], &pPolicy);
  1570. if (dwReturnCode == ERROR_SUCCESS)
  1571. {
  1572. //enum rules
  1573. dwReturnCode = IPSecEnumNFAData(hPolicyStorage, pPolicy->PolicyIdentifier, &(pPolicy->ppIpsecNFAData), &(pPolicy->dwNumNFACount));
  1574. if (dwReturnCode == ERROR_SUCCESS)
  1575. {
  1576. DWORD j;
  1577. for (j = 0; j < pPolicy->dwNumNFACount; j++)
  1578. {
  1579. if (!UuidIsNil(&(pPolicy->ppIpsecNFAData[j]->NegPolIdentifier), &RpcStat))
  1580. {
  1581. dwReturnCode=IPSecGetNegPolData(hPolicyStorage, pPolicy->ppIpsecNFAData[j]->NegPolIdentifier,&(pPolicy->ppIpsecNFAData[j]->pIpsecNegPolData));
  1582. if(dwReturnCode != ERROR_SUCCESS)
  1583. {
  1584. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_SHW_STATIC_TAB_POLICY_3,pPolicy->pszIpsecName);
  1585. }
  1586. }
  1587. if (dwReturnCode != ERROR_SUCCESS) break;
  1588. }
  1589. }
  1590. if(dwReturnCode == ERROR_SUCCESS)
  1591. {
  1592. for (DWORD n = 0; n < pPolicy->dwNumNFACount; n++)
  1593. {
  1594. //check whether standalone filteraction
  1595. if (UuidCompare(&(pPolicy->ppIpsecNFAData[n]->pIpsecNegPolData->NegPolIdentifier), &(pNegPol->NegPolIdentifier), &RpcStat) == 0 && RpcStat == RPC_S_OK || (pNegPol->NegPolType==GUID_NEGOTIATION_TYPE_DEFAULT))
  1596. {
  1597. bStandAlone=FALSE;
  1598. break;
  1599. }
  1600. }
  1601. }
  1602. if (pPolicy)
  1603. IPSecFreePolicyData(pPolicy);
  1604. }
  1605. if ((!bStandAlone)||(dwReturnCode != ERROR_SUCCESS)) break;
  1606. }
  1607. //clean up
  1608. if (dwNumPolicies > 0 && ppPolicyEnum != NULL)
  1609. {
  1610. IPSecFreeMulPolicyData(ppPolicyEnum, dwNumPolicies);
  1611. }
  1612. error:
  1613. return dwReturnCode;
  1614. }
  1615. /////////////////////////////////////////////////////////////////////////
  1616. //
  1617. //Function: PrintStandAloneFLData()
  1618. //
  1619. //Date of Creation: 21st Aug 2001
  1620. //
  1621. //Parameters:
  1622. // IN HANDLE hPolicyStorage,
  1623. // IN BOOL bVerbose
  1624. // IN BOOL bTable,
  1625. // IN BOOL bWide
  1626. //
  1627. //Return: VOID
  1628. //
  1629. //Description:
  1630. // This function prints out the Filter Lists details ,unattached to any of the policies.
  1631. //
  1632. //Revision History:
  1633. //
  1634. // Date Author Comments
  1635. //
  1636. /////////////////////////////////////////////////////////////////////////
  1637. DWORD
  1638. PrintStandAloneFLData(
  1639. IN HANDLE hPolicyStorage,
  1640. IN BOOL bVerbose,
  1641. IN BOOL bTable,
  1642. IN BOOL bWide
  1643. )
  1644. {
  1645. DWORD dwReturnCode = S_OK;
  1646. BOOL bTitlePrinted=FALSE,bStandAlone=TRUE;
  1647. PIPSEC_FILTER_DATA *ppFilterEnum = NULL,pFilter=NULL;
  1648. DWORD dwNumFilter=0;
  1649. DWORD cnt=0,num=1;
  1650. dwReturnCode = IPSecEnumFilterData(hPolicyStorage, &ppFilterEnum, &dwNumFilter);
  1651. if (!(dwReturnCode == ERROR_SUCCESS && dwNumFilter > 0 && ppFilterEnum != NULL))
  1652. {
  1653. BAIL_OUT; // if nothing available, bail out od the function
  1654. }
  1655. for(cnt=0; cnt < dwNumFilter;cnt++)
  1656. {
  1657. bStandAlone=TRUE;
  1658. dwReturnCode = IPSecCopyFilterData(ppFilterEnum[cnt], &pFilter);
  1659. if ((dwReturnCode == ERROR_SUCCESS) && (pFilter != NULL))
  1660. {
  1661. dwReturnCode= IsStandAloneFL(pFilter,hPolicyStorage,bStandAlone);
  1662. if (dwReturnCode == ERROR_SUCCESS)
  1663. {
  1664. if(bStandAlone) // print the details, if it is standalone
  1665. {
  1666. if(!bTitlePrinted)
  1667. {
  1668. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTSAFL_STAND_ALONE_FL_TITLE);
  1669. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTSAFL_STAND_ALONE_FL_UNDERLINE);
  1670. }
  1671. num++;
  1672. // print in required format
  1673. if(bTable)
  1674. {
  1675. PrintFilterDataTable(pFilter,bVerbose,bWide);
  1676. }
  1677. else
  1678. {
  1679. dwReturnCode = PrintFilterDataList(pFilter,bVerbose,FALSE,bWide);
  1680. BAIL_ON_WIN32_ERROR(dwReturnCode);
  1681. }
  1682. bTitlePrinted=TRUE; // this is to print the title only once
  1683. }
  1684. }
  1685. if(pFilter) IPSecFreeFilterData(pFilter);
  1686. }
  1687. if (dwReturnCode != ERROR_SUCCESS) break;
  1688. }
  1689. if(ppFilterEnum && dwNumFilter > 0)
  1690. {
  1691. IPSecFreeMulFilterData( ppFilterEnum,dwNumFilter);
  1692. }
  1693. if(num-1)
  1694. {
  1695. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTSAFL_STAND_ALONE_FL_COUNT,num-1);
  1696. }
  1697. error:
  1698. return dwReturnCode;
  1699. }
  1700. /////////////////////////////////////////////////////////////////////////
  1701. //
  1702. //Function: IsStandAloneFL()
  1703. //
  1704. //Date of Creation: 21st Aug 2001
  1705. //
  1706. //Parameters:
  1707. // IN PIPSEC_FILTER_DATA pFilter,
  1708. // IN HANDLE hPolicyStorage
  1709. // IN OUT BOOL & bStandAlone
  1710. //
  1711. //Return: VOID
  1712. //
  1713. //Description:
  1714. // This function checks whether the specified Filter List is unattached to any of the policies.
  1715. //
  1716. //Revision History:
  1717. //
  1718. // Date Author Comments
  1719. //
  1720. /////////////////////////////////////////////////////////////////////////
  1721. DWORD
  1722. IsStandAloneFL(
  1723. IN PIPSEC_FILTER_DATA pFilter,
  1724. IN HANDLE hPolicyStorage,
  1725. IN OUT BOOL & bStandAlone
  1726. )
  1727. {
  1728. PIPSEC_POLICY_DATA *ppPolicyEnum = NULL,pPolicy=NULL;
  1729. DWORD dwNumPolicies = 0 , i =0;
  1730. RPC_STATUS RpcStat=RPC_S_OK;
  1731. DWORD dwReturnCode = S_OK;
  1732. dwReturnCode = IPSecEnumPolicyData(hPolicyStorage, &ppPolicyEnum, &dwNumPolicies);
  1733. if (!(dwReturnCode == ERROR_SUCCESS && dwNumPolicies > 0 && ppPolicyEnum != NULL))
  1734. {
  1735. dwReturnCode = ERROR_SUCCESS;
  1736. BAIL_OUT; // if nothing found, bail out of the function
  1737. }
  1738. for (i = 0; i < dwNumPolicies; i++)
  1739. {
  1740. dwReturnCode = IPSecCopyPolicyData(ppPolicyEnum[i], &pPolicy);
  1741. if (dwReturnCode == ERROR_SUCCESS)
  1742. {
  1743. dwReturnCode = IPSecEnumNFAData(hPolicyStorage, pPolicy->PolicyIdentifier, &(pPolicy->ppIpsecNFAData), &(pPolicy->dwNumNFACount));
  1744. if (dwReturnCode == ERROR_SUCCESS)
  1745. {
  1746. DWORD j;
  1747. for (j = 0; j < pPolicy->dwNumNFACount; j++)
  1748. {
  1749. if (!UuidIsNil(&(pPolicy->ppIpsecNFAData[j]->FilterIdentifier), &RpcStat))
  1750. {
  1751. dwReturnCode=IPSecGetFilterData(hPolicyStorage, pPolicy->ppIpsecNFAData[j]->FilterIdentifier,&(pPolicy->ppIpsecNFAData[j]->pIpsecFilterData));
  1752. if(dwReturnCode != ERROR_SUCCESS)
  1753. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_SHW_STATIC_TAB_POLICY_4,pPolicy->pszIpsecName);
  1754. }
  1755. if (dwReturnCode != ERROR_SUCCESS)
  1756. {
  1757. bStandAlone=FALSE;
  1758. break;
  1759. }
  1760. }
  1761. }
  1762. if(dwReturnCode == ERROR_SUCCESS)
  1763. {
  1764. for (DWORD n = 0; n < pPolicy->dwNumNFACount; n++)
  1765. {
  1766. if (UuidCompare(&(pPolicy->ppIpsecNFAData[n]->pIpsecFilterData->FilterIdentifier), &(pFilter->FilterIdentifier), &RpcStat) == 0 && RpcStat == RPC_S_OK )
  1767. {
  1768. // check whether it is stand alone or used some where
  1769. bStandAlone=FALSE;
  1770. break;
  1771. }
  1772. }
  1773. }
  1774. if (pPolicy) IPSecFreePolicyData(pPolicy);
  1775. }
  1776. if ((!bStandAlone)||(dwReturnCode != ERROR_SUCCESS)) break;
  1777. }
  1778. //clean up
  1779. if (dwNumPolicies > 0 && ppPolicyEnum != NULL)
  1780. {
  1781. IPSecFreeMulPolicyData(ppPolicyEnum, dwNumPolicies);
  1782. }
  1783. error:
  1784. return dwReturnCode;
  1785. }
  1786. //////////////////////////////////////////////////////////////////////////
  1787. //
  1788. //Function: PrintAllFilterData()
  1789. //
  1790. //Date of Creation: 21st Aug 2001
  1791. //
  1792. //Parameters:
  1793. // IN HANDLE hPolicyStorage,
  1794. // IN LPTSTR pszFlistName,
  1795. // IN BOOL bVerbose,
  1796. // IN BOOL bTable,
  1797. // IN BOOL bResolveDNS,
  1798. // IN BOOL bWide
  1799. //
  1800. //Return: DWORD
  1801. //
  1802. //Description:
  1803. // This function prints out all the filter data
  1804. //
  1805. //Revision History:
  1806. //
  1807. // Date Author Comments
  1808. //
  1809. //////////////////////////////////////////////////////////////////////////
  1810. DWORD
  1811. PrintAllFilterData(
  1812. IN HANDLE hPolicyStorage,
  1813. IN LPTSTR pszFlistName,
  1814. IN BOOL bVerbose,
  1815. IN BOOL bTable,
  1816. IN BOOL bResolveDNS,
  1817. IN BOOL bWide
  1818. )
  1819. {
  1820. DWORD dwReturnCode = S_OK;
  1821. BOOL bNoFilter=TRUE, bAll=TRUE;
  1822. PIPSEC_FILTER_DATA *ppFilterEnum = NULL,pFilter=NULL;
  1823. DWORD dwNumFilters=0;
  1824. DWORD cnt=0;
  1825. BOOL bTitlePrinted=FALSE;
  1826. if (pszFlistName) bAll=FALSE;
  1827. dwReturnCode = IPSecEnumFilterData(hPolicyStorage, &ppFilterEnum, &dwNumFilters);
  1828. if (!(dwReturnCode == ERROR_SUCCESS && dwNumFilters > 0 && ppFilterEnum != NULL))
  1829. {
  1830. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_SHW_STATIC_TAB_PRTALLFL_2);
  1831. BAIL_OUT; // if nothing exists, bail out of the function
  1832. }
  1833. for(cnt=0; cnt < dwNumFilters;cnt++)
  1834. {
  1835. dwReturnCode = IPSecCopyFilterData(ppFilterEnum[cnt], &pFilter);
  1836. if ((dwReturnCode == ERROR_SUCCESS) && (pFilter != NULL))
  1837. {
  1838. //if exists , print the details
  1839. if(bAll||((pFilter->pszIpsecName!=NULL)&&(pszFlistName!=NULL)&&(_tcscmp(pFilter->pszIpsecName,pszFlistName)==0)))
  1840. {
  1841. if(bTable) // print as per the requested format
  1842. {
  1843. if(!bVerbose && !bTitlePrinted)
  1844. {
  1845. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTFILTERDATA_NONVERB_TITLE);
  1846. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTFILTERDATA_NONVERB_UNDERLINE);
  1847. bTitlePrinted=TRUE;
  1848. }
  1849. PrintFilterDataTable(pFilter,bVerbose,bWide);
  1850. }
  1851. else
  1852. {
  1853. dwReturnCode = PrintFilterDataList(pFilter,bVerbose,bResolveDNS,bWide);
  1854. BAIL_ON_WIN32_ERROR(dwReturnCode);
  1855. }
  1856. bNoFilter=FALSE;
  1857. }
  1858. if(pFilter) IPSecFreeFilterData(pFilter);
  1859. }
  1860. if (dwReturnCode != ERROR_SUCCESS) break;
  1861. }
  1862. if (bAll) // if all is specified, print the count
  1863. {
  1864. if(bTable)
  1865. {
  1866. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTALLFL_FL_COUNT_TAB,dwNumFilters);
  1867. }
  1868. else
  1869. {
  1870. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTALLFL_FL_COUNT_LIST,dwNumFilters);
  1871. }
  1872. }
  1873. //error message
  1874. if (bNoFilter && pszFlistName && (dwReturnCode == ERROR_SUCCESS))
  1875. {
  1876. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_SHW_STATIC_TAB_PRTALLFL_3,pszFlistName);
  1877. }
  1878. //clean up
  1879. if(ppFilterEnum && dwNumFilters>0)
  1880. {
  1881. IPSecFreeMulFilterData( ppFilterEnum,dwNumFilters);
  1882. }
  1883. error:
  1884. return dwReturnCode;
  1885. }
  1886. //////////////////////////////////////////////////////////////////////////
  1887. //
  1888. //Function: PrintAllFilterActionData()
  1889. //
  1890. //Date of Creation: 21st Aug 2001
  1891. //
  1892. //Parameters:
  1893. // IN HANDLE hPolicyStorage,
  1894. // IN LPTSTR pszFactName,
  1895. // IN BOOL bVerbose,
  1896. // IN BOOL bTable,
  1897. // IN BOOL bWide
  1898. //
  1899. //Return: VOID
  1900. //
  1901. //Description:
  1902. // This function prints out all the filter action data
  1903. //
  1904. //Revision History:
  1905. //
  1906. // Date Author Comments
  1907. //
  1908. //////////////////////////////////////////////////////////////////////////
  1909. DWORD
  1910. PrintAllFilterActionData(
  1911. IN HANDLE hPolicyStorage,
  1912. IN LPTSTR pszFactName,
  1913. IN BOOL bVerbose,
  1914. IN BOOL bTable,
  1915. IN BOOL bWide
  1916. )
  1917. {
  1918. DWORD dwReturnCode = S_OK;
  1919. PIPSEC_NEGPOL_DATA *ppNegPolEnum = NULL,pNegPol=NULL;
  1920. DWORD dwNumNegPol=0,dwNegPol=0;
  1921. DWORD cnt=0;
  1922. BOOL bAll=TRUE,bNoFilterAct=TRUE,bTitlePrinted=FALSE;
  1923. if (pszFactName) bAll=FALSE;
  1924. dwReturnCode = IPSecEnumNegPolData(hPolicyStorage, &ppNegPolEnum, &dwNumNegPol);
  1925. if (!(dwReturnCode == ERROR_SUCCESS && dwNumNegPol > 0 && ppNegPolEnum != NULL))
  1926. {
  1927. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_SHW_STATIC_TAB_PRTALLFA_6);
  1928. BAIL_OUT; // if nothing found, bail out
  1929. }
  1930. if (bAll)
  1931. {
  1932. for (DWORD Loop=0;Loop< dwNumNegPol;Loop++)
  1933. {
  1934. if(IsEqualGUID(ppNegPolEnum[Loop]->NegPolType,GUID_NEGOTIATION_TYPE_DEFAULT)) continue;
  1935. dwNegPol++; // ignore default filteractions
  1936. }
  1937. }
  1938. for(cnt=0; cnt < dwNumNegPol ;cnt++)
  1939. {
  1940. dwReturnCode = IPSecCopyNegPolData(ppNegPolEnum[cnt], &pNegPol);
  1941. if ((dwReturnCode == ERROR_SUCCESS) && (pNegPol != NULL))
  1942. {
  1943. //if something found, print them in requested format
  1944. if((bAll&&(pNegPol->NegPolType!=GUID_NEGOTIATION_TYPE_DEFAULT))||((pNegPol->pszIpsecName!=NULL)&&(pszFactName!=NULL)&&(_tcscmp(pNegPol->pszIpsecName,pszFactName)==0)))
  1945. {
  1946. if(bTable)
  1947. {
  1948. if(!bVerbose && !bTitlePrinted)
  1949. {
  1950. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTNEGPOL_NONVERB_TITLE);
  1951. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTNEGPOL_NONVERB_UNDERLINE);
  1952. bTitlePrinted=TRUE;
  1953. }
  1954. PrintNegPolDataTable(pNegPol,bVerbose,bWide); //table format
  1955. }
  1956. else
  1957. PrintNegPolDataList(pNegPol,bVerbose,bWide); // list format
  1958. bNoFilterAct=FALSE;
  1959. }
  1960. if(pNegPol) IPSecFreeNegPolData(pNegPol);
  1961. }
  1962. if (dwReturnCode != ERROR_SUCCESS) break;
  1963. }
  1964. //error messages
  1965. if (bAll&& (dwNegPol==0) && (dwReturnCode == ERROR_SUCCESS))
  1966. {
  1967. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_SHW_STATIC_TAB_PRTALLFA_6);
  1968. }
  1969. else if (bNoFilterAct&&pszFactName && (dwReturnCode == ERROR_SUCCESS))
  1970. {
  1971. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_SHW_STATIC_TAB_PRTALLFA_FA_COUNT_LIST,pszFactName);
  1972. }
  1973. if(dwNegPol> 0) // negpol count printing
  1974. {
  1975. if(bTable)
  1976. {
  1977. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTALLFA_FA_COUNT_TAB,dwNegPol);
  1978. }
  1979. else
  1980. {
  1981. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_PRTALLFA_FA_COUNT_LIST,dwNegPol);
  1982. }
  1983. }
  1984. //clean up
  1985. if (dwNumNegPol > 0 && ppNegPolEnum != NULL)
  1986. {
  1987. IPSecFreeMulNegPolData( ppNegPolEnum,dwNumNegPol);
  1988. }
  1989. error:
  1990. return dwReturnCode;
  1991. }
  1992. //////////////////////////////////////////////////////////////////////////
  1993. //
  1994. //Function: GetPolicyInfoFromDomain()
  1995. //
  1996. //Date of Creation: 21st Aug 2001
  1997. //
  1998. //Parameters:
  1999. // IN LPTSTR pszDirectoryName,
  2000. // IN LPTSTR szPolicyDN
  2001. //
  2002. //Return: DWORD
  2003. //
  2004. //Description:
  2005. // This function prints the details of GPO assigned policy from domain.
  2006. //
  2007. //Revision History:
  2008. //
  2009. // Date Author Comments
  2010. //
  2011. //////////////////////////////////////////////////////////////////////////
  2012. DWORD
  2013. GetPolicyInfoFromDomain(
  2014. IN LPTSTR pszDirectoryName,
  2015. IN LPTSTR szPolicyDN,
  2016. IN OUT PGPO pGPO
  2017. )
  2018. {
  2019. DWORD dwReturnCode=ERROR_SUCCESS , dwStrLength = 0;
  2020. LPTSTR pszDomainName=NULL;
  2021. DWORD dwLocation=IPSEC_DIRECTORY_PROVIDER;
  2022. _TCHAR szPathName[MAX_PATH] ={0};
  2023. DWORD dwNumPolicies = 0, i =0;
  2024. PIPSEC_POLICY_DATA *ppPolicyEnum = NULL ;
  2025. HANDLE hPolicyStorage = NULL;
  2026. LPWSTR pszPolicyIdentifier= new _TCHAR[POLICYGUID_STR_SIZE];
  2027. if(pszPolicyIdentifier==NULL)
  2028. {
  2029. dwReturnCode=ERROR_OUTOFMEMORY;
  2030. BAIL_OUT;
  2031. }
  2032. PDOMAIN_CONTROLLER_INFO pDomainControllerInfo = NULL;
  2033. DWORD Flags = DS_DIRECTORY_SERVICE_REQUIRED | DS_RETURN_DNS_NAME | DS_FORCE_REDISCOVERY;
  2034. //get domain and DC name
  2035. DWORD hr = DsGetDcName(NULL,
  2036. NULL,
  2037. NULL,
  2038. NULL,
  2039. Flags,
  2040. &pDomainControllerInfo
  2041. ) ;
  2042. if(hr==NO_ERROR && pDomainControllerInfo)
  2043. {
  2044. if(pDomainControllerInfo->DomainName)
  2045. {
  2046. dwStrLength = _tcslen(pDomainControllerInfo->DomainName);
  2047. pGPO->pszDomainName= new _TCHAR[dwStrLength+1];
  2048. if(pGPO->pszDomainName==NULL)
  2049. {
  2050. dwReturnCode=ERROR_OUTOFMEMORY;
  2051. BAIL_OUT;
  2052. }
  2053. _tcsncpy(pGPO->pszDomainName,pDomainControllerInfo->DomainName,dwStrLength+1);
  2054. }
  2055. if(pDomainControllerInfo->DomainControllerName)
  2056. {
  2057. dwStrLength = _tcslen(pDomainControllerInfo->DomainControllerName);
  2058. pGPO->pszDCName= new _TCHAR[dwStrLength+1];
  2059. if(pGPO->pszDCName==NULL)
  2060. {
  2061. dwReturnCode=ERROR_OUTOFMEMORY;
  2062. BAIL_OUT;
  2063. }
  2064. _tcsncpy(pGPO->pszDCName,pDomainControllerInfo->DomainControllerName,dwStrLength+1);
  2065. }
  2066. NetApiBufferFree(pDomainControllerInfo); //free it after used
  2067. }
  2068. dwReturnCode = OpenPolicyStore(&hPolicyStorage);
  2069. if (dwReturnCode != ERROR_SUCCESS)
  2070. {
  2071. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_FAILED_POLSTORE_OPEN);
  2072. dwReturnCode=ERROR_SUCCESS;
  2073. BAIL_OUT;
  2074. }
  2075. dwReturnCode = IPSecEnumPolicyData(hPolicyStorage, &ppPolicyEnum, &dwNumPolicies);
  2076. if (!(dwReturnCode == ERROR_SUCCESS && dwNumPolicies > 0 && ppPolicyEnum != NULL))
  2077. {
  2078. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_NO_POLICY);
  2079. dwReturnCode= ERROR_SUCCESS;
  2080. BAIL_OUT;
  2081. }
  2082. //check for any domain policy which is assigned
  2083. // if yes, copy the name and other details to local structure
  2084. for (i = 0; i < dwNumPolicies; i++)
  2085. {
  2086. DWORD dwReturn = StringFromGUID2(ppPolicyEnum[i]->PolicyIdentifier, pszPolicyIdentifier, POLICYGUID_STR_SIZE);
  2087. if(dwReturn == 0)
  2088. {
  2089. dwReturnCode = ERROR_INVALID_DATA;
  2090. BAIL_OUT;
  2091. }
  2092. ComputePolicyDN(pszDirectoryName, pszPolicyIdentifier, szPathName);
  2093. if ( szPathName[0] && szPolicyDN[0] && !_tcsicmp(szPolicyDN, szPathName))
  2094. {
  2095. pGPO->bActive=TRUE;
  2096. if(ppPolicyEnum[i]->pszIpsecName)
  2097. {
  2098. dwStrLength = _tcslen(ppPolicyEnum[i]->pszIpsecName);
  2099. pGPO->pszPolicyName = new _TCHAR[dwStrLength+1];
  2100. if(pGPO->pszPolicyName==NULL)
  2101. {
  2102. dwReturnCode=ERROR_OUTOFMEMORY;
  2103. BAIL_OUT;
  2104. }
  2105. _tcsncpy(pGPO->pszPolicyName,ppPolicyEnum[i]->pszIpsecName,dwStrLength+1);
  2106. }
  2107. dwStrLength = _tcslen(szPolicyDN);
  2108. pGPO->pszPolicyDNName=new _TCHAR[dwStrLength+1];
  2109. if(pGPO->pszPolicyDNName==NULL)
  2110. {
  2111. dwReturnCode=ERROR_OUTOFMEMORY;
  2112. BAIL_OUT;
  2113. }
  2114. _tcsncpy(pGPO->pszPolicyDNName,szPolicyDN,dwStrLength+1);
  2115. }
  2116. }
  2117. // clean up
  2118. if (dwNumPolicies > 0 && ppPolicyEnum != NULL)
  2119. {
  2120. IPSecFreeMulPolicyData(ppPolicyEnum, dwNumPolicies);
  2121. }
  2122. if(dwReturnCode == ERROR_FILE_NOT_FOUND)
  2123. dwReturnCode=ERROR_SUCCESS;
  2124. ClosePolicyStore(hPolicyStorage);
  2125. error:
  2126. if(pszPolicyIdentifier) delete []pszPolicyIdentifier;
  2127. if(pszDomainName) delete []pszDomainName;
  2128. return dwReturnCode;
  2129. }
  2130. //////////////////////////////////////////////////////////////////////////
  2131. //
  2132. //Function: PrintStorageInfoTable()
  2133. //
  2134. //Date of Creation: 21st Aug 2001
  2135. //
  2136. //Parameters:
  2137. // VOID
  2138. //
  2139. //
  2140. //Return: DWORD
  2141. //
  2142. //Description:
  2143. // This function prints out the the Security Methods information.
  2144. //
  2145. //Revision History:
  2146. //
  2147. // Date Author Comments
  2148. //
  2149. //////////////////////////////////////////////////////////////////////////
  2150. DWORD
  2151. PrintStorageInfoTable(
  2152. VOID
  2153. )
  2154. {
  2155. DWORD dwReturn = ERROR_SUCCESS , dwStrLength = 0, dwStoreId = 0;
  2156. if(g_StorageLocation.dwLocation!=IPSEC_DIRECTORY_PROVIDER)
  2157. {
  2158. if(_tcscmp(g_StorageLocation.pszMachineName,_TEXT(""))!=0) // if name exists in global variable, print
  2159. {
  2160. if (g_StorageLocation.dwLocation == IPSEC_REGISTRY_PROVIDER)
  2161. {
  2162. dwStoreId = SHW_STATIC_TAB_POLICY_STORE_RM_NAME;
  2163. }
  2164. else
  2165. {
  2166. dwStoreId = SHW_STATIC_TAB_POLICY_STORE_RM_NAMEP;
  2167. }
  2168. PrintMessageFromModule(g_hModule,dwStoreId,g_StorageLocation.pszMachineName);
  2169. }
  2170. else // if no name exists in global variable, get it and print
  2171. {
  2172. _TCHAR pszLocalMachineName[MAXSTRLEN] = {0};
  2173. DWORD MaxStringLen=MAXSTRLEN;
  2174. GetComputerName(pszLocalMachineName,&MaxStringLen); // to get the computer name
  2175. if(_tcscmp(pszLocalMachineName,_TEXT(""))!=0)
  2176. {
  2177. if (g_StorageLocation.dwLocation == IPSEC_REGISTRY_PROVIDER)
  2178. {
  2179. dwStoreId = SHW_STATIC_TAB_POLICY_STORE_LM_NAME;
  2180. }
  2181. else
  2182. {
  2183. dwStoreId = SHW_STATIC_TAB_POLICY_STORE_LM_NAMEP;
  2184. }
  2185. PrintMessageFromModule(g_hModule,dwStoreId,pszLocalMachineName);
  2186. }
  2187. else
  2188. {
  2189. if (g_StorageLocation.dwLocation == IPSEC_REGISTRY_PROVIDER)
  2190. {
  2191. dwStoreId = SHW_STATIC_TAB_POLICY_STORE_LM;
  2192. }
  2193. else
  2194. {
  2195. dwStoreId = SHW_STATIC_TAB_POLICY_STORE_LP;
  2196. }
  2197. PrintMessageFromModule(g_hModule,dwStoreId);
  2198. }
  2199. }
  2200. }
  2201. else if(g_StorageLocation.dwLocation==IPSEC_DIRECTORY_PROVIDER)
  2202. {
  2203. if(_tcscmp(g_StorageLocation.pszDomainName,_TEXT(""))!=0)
  2204. {
  2205. // if name exists in global variable, print
  2206. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_POLICY_STORE_RD_NAME,g_StorageLocation.pszDomainName);
  2207. }
  2208. else
  2209. {
  2210. // if no name exists in global variable, get it and print
  2211. PDOMAIN_CONTROLLER_INFO pDomainControllerInfo = NULL;
  2212. LPTSTR pszDomainName = NULL;
  2213. DWORD Flags = DS_DIRECTORY_SERVICE_REQUIRED | DS_RETURN_DNS_NAME | DS_FORCE_REDISCOVERY;
  2214. // to get the DOMAIN name
  2215. DWORD hr = DsGetDcName(NULL,
  2216. NULL,
  2217. NULL,
  2218. NULL,
  2219. Flags,
  2220. &pDomainControllerInfo
  2221. ) ;
  2222. if(hr==NO_ERROR && pDomainControllerInfo && pDomainControllerInfo->DomainName)
  2223. {
  2224. dwStrLength = _tcslen(pDomainControllerInfo->DomainName);
  2225. pszDomainName= new _TCHAR[dwStrLength+1];
  2226. if(pszDomainName == NULL)
  2227. {
  2228. dwReturn = ERROR_OUTOFMEMORY;
  2229. BAIL_OUT;
  2230. }
  2231. _tcsncpy(pszDomainName,pDomainControllerInfo->DomainName,dwStrLength+1);
  2232. }
  2233. if (pDomainControllerInfo)
  2234. {
  2235. NetApiBufferFree(pDomainControllerInfo);
  2236. }
  2237. if(pszDomainName)
  2238. {
  2239. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_POLICY_STORE_LD_NAME,pszDomainName);
  2240. }
  2241. else
  2242. {
  2243. PrintMessageFromModule(g_hModule,SHW_STATIC_TAB_POLICY_STORE_LD);
  2244. }
  2245. if(pszDomainName) delete [] pszDomainName;
  2246. }
  2247. }
  2248. error:
  2249. return dwReturn;
  2250. }
  2251. //////////////////////////////////////////////////////////////////////////
  2252. //
  2253. //Function: TruncateString()
  2254. //
  2255. //Date of Creation: 21st Aug 2001
  2256. //
  2257. //Parameters:
  2258. // IN LPTSTR pszOriginalString,
  2259. // IN OUT LPTSTR &pszReturnString,
  2260. // IN DWORD dwTruncLen,
  2261. // IN BOOL bWide
  2262. //
  2263. //
  2264. //Return: VOID
  2265. //
  2266. //Description:
  2267. // This function prints out the the Security Methods information.
  2268. //
  2269. //Revision History:
  2270. //
  2271. // Date Author Comments
  2272. //
  2273. //////////////////////////////////////////////////////////////////////////
  2274. VOID
  2275. TruncateString(
  2276. IN LPTSTR pszOriginalString,
  2277. IN OUT LPOLESTR pszReturnString,
  2278. IN DWORD dwTruncLen,
  2279. IN BOOL bWide
  2280. )
  2281. {
  2282. //this truncates the string to the requested extent
  2283. _tcsncpy(pszReturnString,pszOriginalString,BUFFER_SIZE-1);
  2284. if(!bWide && (DWORD)_tcslen(pszOriginalString)> dwTruncLen)
  2285. {
  2286. pszReturnString[dwTruncLen]= _TEXT('\0');
  2287. pszReturnString[dwTruncLen-1]= _TEXT('.');
  2288. pszReturnString[dwTruncLen-2]= _TEXT('.');
  2289. pszReturnString[dwTruncLen-3]= _TEXT('.');
  2290. }
  2291. }