Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1004 lines
27 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. spddb.h
  7. FILE HISTORY:
  8. */
  9. #ifndef _SPDDB_H
  10. #define _SPDDB_H
  11. #ifndef _HARRAY_H
  12. #include "harray.h"
  13. #endif
  14. #include "ipsec.h"
  15. #include "winipsec.h"
  16. #include "spdutil.h"
  17. #include "wincrypt.h"
  18. interface ISpdInfo;
  19. template <class T>
  20. void
  21. FreeItemsAndEmptyArray (
  22. T& array);
  23. DWORD IsAdmin(LPCTSTR szMachineName, LPCTSTR szAccount, LPCTSTR szPassword, BOOL * pfIsAdmin);
  24. typedef enum _IPSECMON_INFO_TYPE {MON_MM_FILTER=0x1,MON_MM_POLICY=0x2,MON_MM_SA=0x4,MON_MM_SP_FILTER=0x8,
  25. MON_QM_FILTER=0x10, MON_QM_SP_FILTER=0x20,
  26. MON_QM_POLICY=0x40,MON_QM_SA=0x80,MON_STATS=0x100,
  27. MON_MM_AUTH=0x200, MON_INIT=0x400} IPSECMON_INFO_TYPE;
  28. class CFilterInfo
  29. {
  30. public:
  31. FILTER_TYPE m_FilterType;
  32. GUID m_guidFltr;
  33. CString m_stName;
  34. IF_TYPE m_InterfaceType;
  35. BOOL m_bCreateMirror;
  36. ADDR m_SrcAddr;
  37. ADDR m_DesAddr;
  38. ADDR m_MyTnlAddr; //only valid for tunnel filters
  39. ADDR m_PeerTnlAddr; //only valid for tunnel filters
  40. PROTOCOL m_Protocol;
  41. PORT m_SrcPort;
  42. PORT m_DesPort;
  43. FILTER_FLAG m_InboundFilterFlag;
  44. FILTER_FLAG m_OutboundFilterFlag;
  45. DWORD m_dwDirection;
  46. DWORD m_dwWeight;
  47. GUID m_guidPolicyID;
  48. CString m_stPolicyName;
  49. public:
  50. CFilterInfo() { m_FilterType = FILTER_TYPE_ANY; };
  51. CFilterInfo& operator=(const TRANSPORT_FILTER TransFltr)
  52. {
  53. m_FilterType = FILTER_TYPE_TRANSPORT;
  54. m_guidFltr = TransFltr.gFilterID;
  55. m_stName = TransFltr.pszFilterName;
  56. m_InterfaceType = TransFltr.InterfaceType;
  57. m_bCreateMirror = TransFltr.bCreateMirror;
  58. m_SrcAddr = TransFltr.SrcAddr;
  59. m_DesAddr = TransFltr.DesAddr;
  60. m_Protocol = TransFltr.Protocol;
  61. m_SrcPort = TransFltr.SrcPort;
  62. m_DesPort = TransFltr.DesPort;
  63. m_InboundFilterFlag = TransFltr.InboundFilterFlag;
  64. m_OutboundFilterFlag = TransFltr.OutboundFilterFlag;
  65. m_dwDirection = TransFltr.dwDirection;
  66. m_dwWeight = TransFltr.dwWeight;
  67. m_guidPolicyID = TransFltr.gPolicyID;
  68. m_stPolicyName = _T("");
  69. ZeroMemory(&m_MyTnlAddr, sizeof(m_MyTnlAddr));
  70. ZeroMemory(&m_PeerTnlAddr, sizeof(m_PeerTnlAddr));
  71. return *this;
  72. };
  73. CFilterInfo& operator=(const TUNNEL_FILTER Fltr)
  74. {
  75. m_FilterType = FILTER_TYPE_TUNNEL;
  76. m_guidFltr = Fltr.gFilterID;
  77. m_stName = Fltr.pszFilterName;
  78. m_InterfaceType = Fltr.InterfaceType;
  79. m_bCreateMirror = Fltr.bCreateMirror;
  80. m_SrcAddr = Fltr.SrcAddr;
  81. m_DesAddr = Fltr.DesAddr;
  82. m_Protocol = Fltr.Protocol;
  83. m_SrcPort = Fltr.SrcPort;
  84. m_DesPort = Fltr.DesPort;
  85. m_InboundFilterFlag = Fltr.InboundFilterFlag;
  86. m_OutboundFilterFlag = Fltr.OutboundFilterFlag;
  87. m_dwDirection = Fltr.dwDirection;
  88. m_dwWeight = Fltr.dwWeight;
  89. m_guidPolicyID = Fltr.gPolicyID;
  90. m_stPolicyName = _T("");
  91. m_MyTnlAddr = Fltr.SrcTunnelAddr;
  92. m_PeerTnlAddr = Fltr.DesTunnelAddr;
  93. return *this;
  94. }
  95. };
  96. class CMmFilterInfo
  97. {
  98. public:
  99. GUID m_guidFltr;
  100. CString m_stName;
  101. IF_TYPE m_InterfaceType;
  102. BOOL m_bCreateMirror;
  103. ADDR m_SrcAddr;
  104. ADDR m_DesAddr;
  105. DWORD m_dwDirection;
  106. DWORD m_dwWeight;
  107. GUID m_guidPolicyID;
  108. GUID m_guidAuthID;
  109. CString m_stPolicyName;
  110. CString m_stAuthDescription;
  111. public:
  112. CMmFilterInfo() {};
  113. CMmFilterInfo& operator=(const MM_FILTER Fltr)
  114. {
  115. m_guidFltr = Fltr.gFilterID;
  116. m_stName = Fltr.pszFilterName;
  117. m_InterfaceType = Fltr.InterfaceType;
  118. m_bCreateMirror = Fltr.bCreateMirror;
  119. m_SrcAddr = Fltr.SrcAddr;
  120. m_DesAddr = Fltr.DesAddr;
  121. m_dwDirection = Fltr.dwDirection;
  122. m_dwWeight = Fltr.dwWeight;
  123. m_guidPolicyID = Fltr.gPolicyID;
  124. m_guidAuthID = Fltr.gMMAuthID;
  125. m_stPolicyName.Empty();
  126. m_stAuthDescription.Empty();
  127. return *this;
  128. };
  129. };
  130. typedef CArray<CMmFilterInfo *, CMmFilterInfo *> CMmFilterInfoArray;
  131. class CMmAuthInfo
  132. {
  133. public:
  134. MM_AUTH_ENUM m_AuthMethod;
  135. DWORD m_dwAuthInfoSize;
  136. LPBYTE m_pAuthInfo;
  137. public:
  138. CMmAuthInfo()
  139. {
  140. m_dwAuthInfoSize = 0;
  141. m_pAuthInfo = NULL;
  142. };
  143. CMmAuthInfo(const CMmAuthInfo& info)
  144. {
  145. m_AuthMethod = info.m_AuthMethod;
  146. m_dwAuthInfoSize = info.m_dwAuthInfoSize;
  147. m_pAuthInfo = new BYTE[m_dwAuthInfoSize];
  148. Assert(info.m_pAuthInfo);
  149. if (m_pAuthInfo)
  150. {
  151. memcpy(m_pAuthInfo, info.m_pAuthInfo, m_dwAuthInfoSize);
  152. }
  153. };
  154. CMmAuthInfo& operator=(const IPSEC_MM_AUTH_INFO AuthInfo)
  155. {
  156. if (m_pAuthInfo)
  157. {
  158. delete [] m_pAuthInfo;
  159. m_pAuthInfo = NULL;
  160. }
  161. m_AuthMethod = AuthInfo.AuthMethod;
  162. if (0 != AuthInfo.dwAuthInfoSize && NULL != AuthInfo.pAuthInfo) {
  163. if (m_AuthMethod != IKE_RSA_SIGNATURE) {
  164. m_dwAuthInfoSize = AuthInfo.dwAuthInfoSize + 2; //To append the _T('\0') at the end
  165. m_pAuthInfo = new BYTE[m_dwAuthInfoSize];
  166. if (m_pAuthInfo)
  167. {
  168. ZeroMemory(m_pAuthInfo, m_dwAuthInfoSize * sizeof(BYTE));
  169. memcpy(m_pAuthInfo, AuthInfo.pAuthInfo, AuthInfo.dwAuthInfoSize);
  170. }
  171. } else {
  172. DWORD dwNameSize=0;
  173. CRYPT_DATA_BLOB NameBlob;
  174. m_pAuthInfo=NULL;
  175. NameBlob.pbData=AuthInfo.pAuthInfo;
  176. NameBlob.cbData=AuthInfo.dwAuthInfoSize;
  177. dwNameSize = CertNameToStr(
  178. X509_ASN_ENCODING,
  179. &NameBlob,
  180. CERT_X500_NAME_STR,
  181. (LPWSTR)m_pAuthInfo,
  182. dwNameSize);
  183. if (dwNameSize >= 1) {
  184. m_pAuthInfo=new BYTE[dwNameSize * sizeof(wchar_t)];
  185. if (m_pAuthInfo) {
  186. dwNameSize=CertNameToStr(
  187. X509_ASN_ENCODING,
  188. &NameBlob,
  189. CERT_X500_NAME_STR,
  190. (LPWSTR)m_pAuthInfo,
  191. dwNameSize);
  192. }
  193. m_dwAuthInfoSize=dwNameSize;
  194. }
  195. }
  196. }
  197. else
  198. {
  199. m_dwAuthInfoSize = 0;
  200. }
  201. return *this;
  202. };
  203. CMmAuthInfo& operator=(const CMmAuthInfo& info)
  204. {
  205. if (this == &info)
  206. return *this;
  207. if (m_pAuthInfo)
  208. {
  209. delete [] m_pAuthInfo;
  210. }
  211. m_AuthMethod = info.m_AuthMethod;
  212. m_dwAuthInfoSize = info.m_dwAuthInfoSize;
  213. if (0 != info.m_dwAuthInfoSize && NULL != info.m_pAuthInfo)
  214. {
  215. m_pAuthInfo = new BYTE[m_dwAuthInfoSize];
  216. if (m_pAuthInfo)
  217. {
  218. memcpy(m_pAuthInfo, info.m_pAuthInfo, m_dwAuthInfoSize);
  219. }
  220. }
  221. return *this;
  222. };
  223. ~CMmAuthInfo()
  224. {
  225. if (m_pAuthInfo)
  226. {
  227. delete [] m_pAuthInfo;
  228. }
  229. };
  230. };
  231. typedef CArray<CMmAuthInfo *, CMmAuthInfo *> CMmAuthInfoArray;
  232. class CMmAuthMethods
  233. {
  234. public:
  235. GUID m_guidID;
  236. CMmAuthInfoArray m_arrAuthInfo;
  237. CString m_stDescription;
  238. CMmAuthMethods() {}
  239. CMmAuthMethods(const CMmAuthMethods & methods)
  240. {
  241. m_guidID = methods.m_guidID;
  242. FreeItemsAndEmptyArray (m_arrAuthInfo);
  243. m_arrAuthInfo.SetSize(methods.m_arrAuthInfo.GetSize());
  244. for (int i = 0; i < methods.m_arrAuthInfo.GetSize(); i++)
  245. {
  246. CMmAuthInfo * pAuth = new CMmAuthInfo;
  247. *pAuth = *(methods.m_arrAuthInfo[i]);
  248. m_arrAuthInfo[i] = pAuth;
  249. }
  250. m_stDescription = methods.m_stDescription;
  251. }
  252. CMmAuthMethods& operator=(const CMmAuthMethods & methods)
  253. {
  254. if (&methods == this)
  255. return *this;
  256. m_guidID = methods.m_guidID;
  257. FreeItemsAndEmptyArray (m_arrAuthInfo);
  258. m_arrAuthInfo.SetSize(methods.m_arrAuthInfo.GetSize());
  259. for (int i = 0; i < methods.m_arrAuthInfo.GetSize(); i++)
  260. {
  261. CMmAuthInfo * pAuth = new CMmAuthInfo;
  262. *pAuth = *(methods.m_arrAuthInfo[i]);
  263. m_arrAuthInfo[i] = pAuth;
  264. }
  265. m_stDescription = methods.m_stDescription;
  266. return *this;
  267. }
  268. CMmAuthMethods& operator=(const MM_AUTH_METHODS & methods)
  269. {
  270. m_guidID = methods.gMMAuthID;
  271. FreeItemsAndEmptyArray (m_arrAuthInfo);
  272. m_arrAuthInfo.SetSize(methods.dwNumAuthInfos);
  273. for (int i = 0; i < (int)methods.dwNumAuthInfos; i++)
  274. {
  275. CMmAuthInfo * pAuth = new CMmAuthInfo;
  276. *pAuth = methods.pAuthenticationInfo[i];
  277. m_arrAuthInfo[i] = pAuth;
  278. }
  279. //construct the description
  280. m_stDescription.Empty();
  281. CString st;
  282. for (i = 0; i < m_arrAuthInfo.GetSize(); i++)
  283. {
  284. if (0 != i)
  285. {
  286. m_stDescription += _T(", ");
  287. }
  288. MmAuthToString(m_arrAuthInfo[i]->m_AuthMethod, &st);
  289. m_stDescription += st;
  290. }
  291. return *this;
  292. }
  293. ~CMmAuthMethods() { FreeItemsAndEmptyArray (m_arrAuthInfo); }
  294. };
  295. typedef CArray<CMmAuthMethods *, CMmAuthMethods *> CMmAuthMethodsArray;
  296. class CMmOffer
  297. {
  298. public:
  299. KEY_LIFETIME m_Lifetime;
  300. DWORD m_dwFlags;
  301. DWORD m_dwQuickModeLimit;
  302. DWORD m_dwDHGroup;
  303. IPSEC_MM_ALGO m_EncryptionAlgorithm;
  304. IPSEC_MM_ALGO m_HashingAlgorithm;
  305. public:
  306. CMmOffer() {};
  307. CMmOffer(const CMmOffer & offer)
  308. {
  309. m_Lifetime = offer.m_Lifetime;
  310. m_dwFlags = offer.m_dwFlags;
  311. m_dwQuickModeLimit = offer.m_dwQuickModeLimit;
  312. m_dwDHGroup = offer.m_dwDHGroup;
  313. m_EncryptionAlgorithm = offer.m_EncryptionAlgorithm;
  314. m_HashingAlgorithm = offer.m_HashingAlgorithm;
  315. };
  316. CMmOffer& operator=(const CMmOffer& offer)
  317. {
  318. if (this == &offer)
  319. return *this;
  320. m_Lifetime = offer.m_Lifetime;
  321. m_dwFlags = offer.m_dwFlags;
  322. m_dwQuickModeLimit = offer.m_dwQuickModeLimit;
  323. m_dwDHGroup = offer.m_dwDHGroup;
  324. m_EncryptionAlgorithm = offer.m_EncryptionAlgorithm;
  325. m_HashingAlgorithm = offer.m_HashingAlgorithm;
  326. return *this;
  327. };
  328. CMmOffer& operator=(const IPSEC_MM_OFFER MmOffer)
  329. {
  330. m_Lifetime = MmOffer.Lifetime;
  331. m_dwFlags = MmOffer.dwFlags;
  332. m_dwQuickModeLimit = MmOffer.dwQuickModeLimit;
  333. m_dwDHGroup = MmOffer.dwDHGroup;
  334. m_EncryptionAlgorithm = MmOffer.EncryptionAlgorithm;
  335. m_HashingAlgorithm = MmOffer.HashingAlgorithm;
  336. return *this;
  337. };
  338. ~CMmOffer() {}
  339. };
  340. typedef CArray<CMmOffer *, CMmOffer *> CMmOfferArray;
  341. class CMmPolicyInfo
  342. {
  343. public:
  344. GUID m_guidID;
  345. CString m_stName;
  346. DWORD m_dwFlags;
  347. DWORD m_dwOfferCount;
  348. CMmOfferArray m_arrOffers;
  349. public:
  350. CMmPolicyInfo() {};
  351. CMmPolicyInfo(const CMmPolicyInfo &info)
  352. {
  353. m_guidID = info.m_guidID;
  354. m_stName = info.m_stName;
  355. m_dwFlags = info.m_dwFlags;
  356. m_dwOfferCount = info.m_dwOfferCount;
  357. FreeItemsAndEmptyArray (m_arrOffers);
  358. m_arrOffers.SetSize(m_dwOfferCount);
  359. for (DWORD i = 0; i < m_dwOfferCount; i++)
  360. {
  361. CMmOffer * pOffer = new CMmOffer;
  362. *pOffer = *info.m_arrOffers[i];
  363. m_arrOffers[i] = pOffer;
  364. }
  365. };
  366. CMmPolicyInfo& operator=(const CMmPolicyInfo &info)
  367. {
  368. if (&info == this)
  369. return *this;
  370. m_guidID = info.m_guidID;
  371. m_stName = info.m_stName;
  372. m_dwFlags = info.m_dwFlags;
  373. m_dwOfferCount = info.m_dwOfferCount;
  374. FreeItemsAndEmptyArray (m_arrOffers);
  375. m_arrOffers.SetSize(m_dwOfferCount);
  376. for (DWORD i = 0; i < m_dwOfferCount; i++)
  377. {
  378. CMmOffer * pOffer = new CMmOffer;
  379. *pOffer = *info.m_arrOffers[i];
  380. m_arrOffers[i] = pOffer;
  381. }
  382. return *this;
  383. };
  384. CMmPolicyInfo& operator=(const IPSEC_MM_POLICY MmPol)
  385. {
  386. m_guidID = MmPol.gPolicyID;
  387. m_stName = MmPol.pszPolicyName;
  388. m_dwFlags = MmPol.dwFlags;
  389. m_dwOfferCount = MmPol.dwOfferCount;
  390. FreeItemsAndEmptyArray (m_arrOffers);
  391. m_arrOffers.SetSize(m_dwOfferCount);
  392. for (DWORD i = 0; i < m_dwOfferCount; i++)
  393. {
  394. CMmOffer * pOffer = new CMmOffer;
  395. *pOffer = MmPol.pOffers[i];
  396. m_arrOffers[i] = (pOffer);
  397. }
  398. return *this;
  399. };
  400. ~CMmPolicyInfo() { FreeItemsAndEmptyArray (m_arrOffers); }
  401. };
  402. class CMmSA
  403. {
  404. public:
  405. GUID m_guidPolicy;
  406. CMmOffer m_SelectedOffer;
  407. MM_AUTH_ENUM m_Auth;
  408. IKE_COOKIE_PAIR m_MMSpi;
  409. ADDR m_MeAddr;
  410. ADDR m_PeerAddr;
  411. CString m_stMyId;
  412. CString m_stMyCertChain;
  413. CString m_stPeerId;
  414. CString m_stPeerCertChain;
  415. CString m_stPolicyName;
  416. DWORD m_dwFlags;
  417. public:
  418. CMmSA() {};
  419. CMmSA& operator=(const IPSEC_MM_SA sa)
  420. {
  421. m_guidPolicy = sa.gMMPolicyID;
  422. m_SelectedOffer = sa.SelectedMMOffer;
  423. m_Auth = sa.MMAuthEnum;
  424. m_MMSpi = sa.MMSpi;
  425. m_MeAddr = sa.Me;
  426. m_PeerAddr = sa.Peer;
  427. IpsecByteBlobToString(sa.MyId, &m_stMyId);
  428. IpsecByteBlobToString(sa.MyCertificateChain, &m_stMyCertChain);
  429. IpsecByteBlobToString(sa.PeerId, &m_stPeerId);
  430. IpsecByteBlobToString(sa.PeerCertificateChain, &m_stPeerCertChain);
  431. m_dwFlags = sa.dwFlags;
  432. m_stPolicyName.Empty(); //Should set the name in LoadMiscMmSAInfo
  433. return *this;
  434. };
  435. };
  436. typedef CArray<CMmSA *, CMmSA *> CMmSAArray;
  437. class CQmAlgo
  438. {
  439. public:
  440. IPSEC_OPERATION m_Operation;
  441. ULONG m_ulAlgo;
  442. HMAC_AH_ALGO m_SecAlgo;
  443. ULONG m_ulKeyLen;
  444. ULONG m_ulRounds;
  445. public:
  446. CQmAlgo() {};
  447. CQmAlgo& operator=(const IPSEC_QM_ALGO algo)
  448. {
  449. m_Operation = algo.Operation;
  450. m_ulAlgo = algo.uAlgoIdentifier;
  451. m_SecAlgo= algo.uSecAlgoIdentifier;
  452. m_ulKeyLen = algo.uAlgoKeyLen;
  453. m_ulRounds = algo.uAlgoRounds;
  454. return *this;
  455. };
  456. };
  457. typedef CArray<CQmAlgo *, CQmAlgo *> CQmAlgoArray;
  458. class CQmOffer
  459. {
  460. public:
  461. KEY_LIFETIME m_Lifetime;
  462. DWORD m_dwFlags;
  463. BOOL m_fPFSRequired;
  464. DWORD m_dwPFSGroup;
  465. DWORD m_dwNumAlgos;
  466. CQmAlgo m_arrAlgos[QM_MAX_ALGOS];
  467. public:
  468. CQmOffer() {};
  469. CQmOffer& operator=(const IPSEC_QM_OFFER offer)
  470. {
  471. m_Lifetime = offer.Lifetime;
  472. m_dwFlags = offer.dwFlags;
  473. m_fPFSRequired = offer.bPFSRequired;
  474. m_dwPFSGroup = offer.dwPFSGroup;
  475. m_dwNumAlgos = offer.dwNumAlgos;
  476. for (DWORD i = 0; i < m_dwNumAlgos; i++)
  477. {
  478. m_arrAlgos[i] = offer.Algos[i];
  479. }
  480. return *this;
  481. };
  482. };
  483. typedef CArray<CQmOffer *, CQmOffer *> CQmOfferArray;
  484. class CQmPolicyInfo
  485. {
  486. public:
  487. GUID m_guidID;
  488. CString m_stName;
  489. DWORD m_dwFlags;
  490. CQmOfferArray m_arrOffers;
  491. public:
  492. CQmPolicyInfo() {};
  493. ~CQmPolicyInfo() { FreeItemsAndEmptyArray(m_arrOffers); }
  494. CQmPolicyInfo(const CQmPolicyInfo& pol)
  495. {
  496. m_guidID = pol.m_guidID;
  497. m_stName = pol.m_stName;
  498. m_dwFlags = pol.m_dwFlags;
  499. int nSize = (int)pol.m_arrOffers.GetSize();
  500. m_arrOffers.SetSize(nSize);
  501. for(int i = 0; i < nSize; i++)
  502. {
  503. CQmOffer * pOffer = new CQmOffer;
  504. *pOffer = *pol.m_arrOffers[i];
  505. m_arrOffers[i] = pOffer;
  506. }
  507. };
  508. CQmPolicyInfo& operator=(const CQmPolicyInfo& pol)
  509. {
  510. if (&pol == this)
  511. return *this;
  512. m_guidID = pol.m_guidID;
  513. m_stName = pol.m_stName;
  514. m_dwFlags = pol.m_dwFlags;
  515. int nSize = (int)pol.m_arrOffers.GetSize();
  516. FreeItemsAndEmptyArray(m_arrOffers);
  517. m_arrOffers.SetSize(nSize);
  518. for(int i = 0; i < nSize; i++)
  519. {
  520. CQmOffer * pOffer = new CQmOffer;
  521. *pOffer = *pol.m_arrOffers[i];
  522. m_arrOffers[i] = pOffer;
  523. }
  524. return *this;
  525. };
  526. CQmPolicyInfo& operator=(const IPSEC_QM_POLICY& pol)
  527. {
  528. m_guidID = pol.gPolicyID;
  529. m_stName = pol.pszPolicyName;
  530. m_dwFlags = pol.dwFlags;
  531. int nSize = pol.dwOfferCount;
  532. FreeItemsAndEmptyArray(m_arrOffers);
  533. m_arrOffers.SetSize(nSize);
  534. for(int i = 0; i < nSize; i++)
  535. {
  536. CQmOffer * pOffer = new CQmOffer;
  537. *pOffer = pol.pOffers[i];
  538. m_arrOffers[i] = pOffer;
  539. }
  540. return *this;
  541. };
  542. };
  543. //The filter setting used by the driver, corresponding to IPSEC_QM_FILTER
  544. class CQmDriverFilter
  545. {
  546. public:
  547. QM_FILTER_TYPE m_Type;
  548. ADDR m_SrcAddr;
  549. ADDR m_DesAddr;
  550. PROTOCOL m_Protocol;
  551. PORT m_SrcPort;
  552. PORT m_DesPort;
  553. ADDR m_MyTunnelEndpt;
  554. ADDR m_PeerTunnelEndpt;
  555. DWORD m_dwFlags;
  556. CQmDriverFilter& operator=(const IPSEC_QM_FILTER fltr)
  557. {
  558. m_Type = fltr.QMFilterType;
  559. m_SrcAddr = fltr.SrcAddr;
  560. m_DesAddr = fltr.DesAddr;
  561. m_Protocol = fltr.Protocol;
  562. m_DesPort = fltr.DesPort;
  563. m_SrcPort = fltr.SrcPort;
  564. m_MyTunnelEndpt = fltr.MyTunnelEndpt;
  565. m_PeerTunnelEndpt = fltr.PeerTunnelEndpt;
  566. m_dwFlags = fltr.dwFlags;
  567. return *this;
  568. }
  569. };
  570. class CQmSA
  571. {
  572. public:
  573. GUID m_guidPolicy;
  574. GUID m_guidFilter;
  575. CQmOffer m_SelectedOffer;
  576. CQmDriverFilter m_QmDriverFilter;
  577. IKE_COOKIE_PAIR m_MMSpi;
  578. CString m_stPolicyName;
  579. CQmSA& operator=(const IPSEC_QM_SA sa)
  580. {
  581. m_guidPolicy = sa.gQMPolicyID;
  582. m_guidFilter = sa.gQMFilterID;
  583. m_SelectedOffer = sa.SelectedQMOffer;
  584. m_QmDriverFilter = sa.IpsecQMFilter;
  585. m_MMSpi = sa.MMSpi;
  586. //Need LoadMiscQmSAInfo to set the policy name
  587. m_stPolicyName.Empty();
  588. return *this;
  589. }
  590. };
  591. typedef CArray<CQmSA *, CQmSA *> CQmSAArray;
  592. class CIkeStatistics
  593. {
  594. public:
  595. DWORD m_dwActiveAcquire;
  596. DWORD m_dwActiveReceive;
  597. DWORD m_dwAcquireFail;
  598. DWORD m_dwReceiveFail;
  599. DWORD m_dwSendFail;
  600. DWORD m_dwAcquireHeapSize;
  601. DWORD m_dwReceiveHeapSize;
  602. DWORD m_dwNegotiationFailures;
  603. DWORD m_dwAuthenticationFailures;
  604. DWORD m_dwInvalidCookiesReceived;
  605. DWORD m_dwTotalAcquire;
  606. DWORD m_dwTotalGetSpi;
  607. DWORD m_dwTotalKeyAdd;
  608. DWORD m_dwTotalKeyUpdate;
  609. DWORD m_dwGetSpiFail;
  610. DWORD m_dwKeyAddFail;
  611. DWORD m_dwKeyUpdateFail;
  612. DWORD m_dwIsadbListSize;
  613. DWORD m_dwConnListSize;
  614. DWORD m_dwOakleyMainModes;
  615. DWORD m_dwOakleyQuickModes;
  616. DWORD m_dwSoftAssociations;
  617. DWORD m_dwInvalidPacketsReceived;
  618. CIkeStatistics & operator=(const IKE_STATISTICS stats)
  619. {
  620. m_dwActiveAcquire = stats.dwActiveAcquire;
  621. m_dwActiveReceive = stats.dwActiveReceive;
  622. m_dwAcquireFail = stats.dwAcquireFail;
  623. m_dwReceiveFail = stats.dwReceiveFail;
  624. m_dwSendFail = stats.dwSendFail;
  625. m_dwAcquireHeapSize = stats.dwAcquireHeapSize;
  626. m_dwReceiveHeapSize = stats.dwReceiveHeapSize;
  627. m_dwNegotiationFailures = stats.dwNegotiationFailures;
  628. m_dwAuthenticationFailures = stats.dwAuthenticationFailures;
  629. m_dwInvalidCookiesReceived = stats.dwInvalidCookiesReceived;
  630. m_dwTotalAcquire = stats.dwTotalAcquire;
  631. m_dwTotalGetSpi = stats.dwTotalGetSpi;
  632. m_dwTotalKeyAdd = stats.dwTotalKeyAdd;
  633. m_dwTotalKeyUpdate = stats.dwTotalKeyUpdate;
  634. m_dwGetSpiFail = stats.dwGetSpiFail;
  635. m_dwKeyAddFail = stats.dwKeyAddFail;
  636. m_dwKeyUpdateFail = stats.dwKeyUpdateFail;
  637. m_dwIsadbListSize = stats.dwIsadbListSize;
  638. m_dwConnListSize = stats.dwConnListSize;
  639. m_dwOakleyMainModes = stats.dwOakleyMainModes;
  640. m_dwOakleyQuickModes = stats.dwOakleyQuickModes;
  641. m_dwSoftAssociations = stats.dwSoftAssociations;
  642. m_dwInvalidPacketsReceived = stats.dwInvalidPacketsReceived;
  643. return *this;
  644. }
  645. };
  646. class CIpsecStatistics
  647. {
  648. public:
  649. DWORD m_dwNumActiveAssociations;
  650. DWORD m_dwNumOffloadedSAs;
  651. DWORD m_dwNumPendingKeyOps;
  652. DWORD m_dwNumKeyAdditions;
  653. DWORD m_dwNumKeyDeletions;
  654. DWORD m_dwNumReKeys;
  655. DWORD m_dwNumActiveTunnels;
  656. DWORD m_dwNumBadSPIPackets;
  657. DWORD m_dwNumPacketsNotDecrypted;
  658. DWORD m_dwNumPacketsNotAuthenticated;
  659. DWORD m_dwNumPacketsWithReplayDetection;
  660. ULARGE_INTEGER m_uConfidentialBytesSent;
  661. ULARGE_INTEGER m_uConfidentialBytesReceived;
  662. ULARGE_INTEGER m_uAuthenticatedBytesSent;
  663. ULARGE_INTEGER m_uAuthenticatedBytesReceived;
  664. ULARGE_INTEGER m_uTransportBytesSent;
  665. ULARGE_INTEGER m_uTransportBytesReceived;
  666. ULARGE_INTEGER m_uBytesSentInTunnels;
  667. ULARGE_INTEGER m_uBytesReceivedInTunnels;
  668. ULARGE_INTEGER m_uOffloadedBytesSent;
  669. ULARGE_INTEGER m_uOffloadedBytesReceived;
  670. CIpsecStatistics & operator=(const IPSEC_STATISTICS stats)
  671. {
  672. m_dwNumActiveAssociations = stats.dwNumActiveAssociations;
  673. m_dwNumOffloadedSAs = stats.dwNumOffloadedSAs;
  674. m_dwNumPendingKeyOps = stats.dwNumPendingKeyOps;
  675. m_dwNumKeyAdditions = stats.dwNumKeyAdditions;
  676. m_dwNumKeyDeletions = stats.dwNumKeyDeletions;
  677. m_dwNumReKeys = stats.dwNumReKeys;
  678. m_dwNumActiveTunnels = stats.dwNumActiveTunnels;
  679. m_dwNumBadSPIPackets = stats.dwNumBadSPIPackets;
  680. m_dwNumPacketsNotDecrypted = stats.dwNumPacketsNotDecrypted;
  681. m_dwNumPacketsNotAuthenticated = stats.dwNumPacketsNotAuthenticated;
  682. m_dwNumPacketsWithReplayDetection = stats.dwNumPacketsWithReplayDetection;
  683. m_uConfidentialBytesSent = stats.uConfidentialBytesSent;
  684. m_uConfidentialBytesReceived = stats.uConfidentialBytesReceived;
  685. m_uAuthenticatedBytesSent = stats.uAuthenticatedBytesSent;
  686. m_uAuthenticatedBytesReceived = stats.uAuthenticatedBytesReceived;
  687. m_uBytesSentInTunnels = stats.uBytesSentInTunnels;
  688. m_uTransportBytesSent = stats.uTransportBytesSent;
  689. m_uTransportBytesReceived = stats.uTransportBytesReceived;
  690. m_uBytesReceivedInTunnels = stats.uBytesReceivedInTunnels;
  691. m_uOffloadedBytesSent = stats.uOffloadedBytesSent;
  692. m_uOffloadedBytesReceived = stats.uOffloadedBytesReceived;
  693. return *this;
  694. }
  695. };
  696. typedef CArray<CQmPolicyInfo *, CQmPolicyInfo *> CQmPolicyInfoArray;
  697. typedef CArray<CMmPolicyInfo *, CMmPolicyInfo *> CMmPolicyInfoArray;
  698. typedef CArray<CFilterInfo *, CFilterInfo *> CFilterInfoArray;
  699. struct SA_ENTRY
  700. {
  701. IPSEC_SA_INFO * psaInfo;
  702. CString stPolicyName;
  703. CString stFilterName;
  704. };
  705. // for our interface
  706. #define DeclareISpdInfoMembers(IPURE) \
  707. STDMETHOD(Destroy) (THIS) IPURE; \
  708. STDMETHOD(SetComputerName) (THIS_ LPTSTR pszName) IPURE; \
  709. STDMETHOD(GetComputerName) (THIS_ CString * pstName) IPURE; \
  710. STDMETHOD(EnumQmFilters) (THIS) IPURE; \
  711. STDMETHOD(EnumMmPolicies) (THIS) IPURE; \
  712. STDMETHOD(EnumMmFilters) (THIS) IPURE; \
  713. STDMETHOD(EnumQmPolicies) (THIS) IPURE; \
  714. STDMETHOD(EnumSpecificFilters) (THIS_ GUID * pTransFilterGuid, CFilterInfoArray * parraySpecificFilters, FILTER_TYPE fltrType) IPURE; \
  715. STDMETHOD(EnumMmSpecificFilters) (THIS_ GUID * pGenFilterGuid, CMmFilterInfoArray * parraySpecificFilters) IPURE; \
  716. STDMETHOD(EnumQmSAsFromMmSA) (THIS_ const CMmSA & MmSA, CQmSAArray * parrayQmSAs) IPURE; \
  717. STDMETHOD(EnumMmAuthMethods) (THIS) IPURE; \
  718. STDMETHOD(EnumMmSAs) (THIS) IPURE; \
  719. STDMETHOD(EnumQmSAs) (THIS) IPURE; \
  720. STDMETHOD(GetFilterInfo) (THIS_ int iIndex, CFilterInfo * pTransFltr) IPURE; \
  721. STDMETHOD(GetSpecificFilterInfo) (THIS_ int iIndex, CFilterInfo * pTransFltr) IPURE; \
  722. STDMETHOD(GetMmPolicyInfo) (THIS_ int iIndex, CMmPolicyInfo * pMmPolicy) IPURE; \
  723. STDMETHOD(GetMmFilterInfo) (THIS_ int iIndex, CMmFilterInfo * pMmPolicy) IPURE; \
  724. STDMETHOD(GetMmSpecificFilterInfo) (THIS_ int iIndex, CMmFilterInfo * pMmPolicy) IPURE; \
  725. STDMETHOD(GetQmPolicyInfo) (THIS_ int iIndex, CQmPolicyInfo * pMmPolicy) IPURE; \
  726. STDMETHOD(GetQmPolicyNameByGuid) (THIS_ GUID Guid, CString * pst) IPURE; \
  727. STDMETHOD(GetMmAuthMethodsInfo) (THIS_ int iIndex, CMmAuthMethods * pMmAuth) IPURE; \
  728. STDMETHOD(GetMmSAInfo) (THIS_ int iIndex, CMmSA * pSA) IPURE; \
  729. STDMETHOD(GetQmSAInfo) (THIS_ int iIndex, CQmSA * pSA) IPURE; \
  730. STDMETHOD(GetMmAuthMethodsInfoByGuid) (THIS_ GUID guid, CMmAuthMethods * pMmAuth) IPURE; \
  731. STDMETHOD(GetMmPolicyNameByGuid) (THIS_ GUID Guid, CString * pst) IPURE; \
  732. STDMETHOD_(DWORD, GetQmFilterCountOfCurrentViewType) (THIS) IPURE; \
  733. STDMETHOD_(DWORD, GetQmSpFilterCountOfCurrentViewType) (THIS) IPURE; \
  734. STDMETHOD_(DWORD, GetMmFilterCount) (THIS) IPURE; \
  735. STDMETHOD_(DWORD, GetMmSpecificFilterCount) (THIS) IPURE; \
  736. STDMETHOD_(DWORD, GetMmPolicyCount) (THIS) IPURE; \
  737. STDMETHOD_(DWORD, GetMmAuthMethodsCount) (THIS) IPURE; \
  738. STDMETHOD_(DWORD, GetMmSACount) (THIS) IPURE; \
  739. STDMETHOD_(DWORD, GetQmSACount) (THIS) IPURE; \
  740. STDMETHOD_(DWORD, GetQmPolicyCount) (THIS) IPURE; \
  741. STDMETHOD(GetMatchFilters) (THIS_ CFilterInfo * pfltrSearchCondition, DWORD dwPreferredNum, CFilterInfoArray * parrFilters) IPURE; \
  742. STDMETHOD(GetMatchMMFilters) (THIS_ CMmFilterInfo * pfltrSearchCondition, DWORD dwPreferredNum, CMmFilterInfoArray * parrFilters) IPURE; \
  743. STDMETHOD(SortFilters) (THIS_ DWORD dwIndexType, DWORD dwSortOptions) IPURE; \
  744. STDMETHOD(SortSpecificFilters) (THIS_ DWORD dwIndexType, DWORD dwSortOptions) IPURE; \
  745. STDMETHOD(SortMmFilters) (DWORD dwIndexType, DWORD dwSortOptions) IPURE; \
  746. STDMETHOD(SortMmSpecificFilters) (DWORD dwIndexType, DWORD dwSortOptions) IPURE; \
  747. STDMETHOD(SortMmPolicies) (DWORD dwIndexType, DWORD dwSortOptions) IPURE; \
  748. STDMETHOD(SortQmPolicies) (DWORD dwIndexType, DWORD dwSortOptions) IPURE; \
  749. STDMETHOD(SortMmSAs) (DWORD dwIndexType, DWORD dwSortOptions) IPURE; \
  750. STDMETHOD(SortQmSAs) (DWORD dwIndexType, DWORD dwSortOptions) IPURE; \
  751. STDMETHOD(LoadStatistics) (THIS) IPURE; \
  752. STDMETHOD_(void, GetLoadedStatistics) (CIkeStatistics * pIkeStats, CIpsecStatistics * pIpsecStats) IPURE; \
  753. STDMETHOD_(void, ChangeQmFilterViewType) (FILTER_TYPE FltrType) IPURE; \
  754. STDMETHOD_(void, ChangeQmSpFilterViewType) (FILTER_TYPE FltrType) IPURE; \
  755. STDMETHOD_(DWORD, GetInitInfo) (THIS) IPURE; \
  756. STDMETHOD_(void, SetInitInfo) (THIS_ DWORD dwInitInfo) IPURE; \
  757. STDMETHOD_(DWORD, GetActiveInfo) (THIS) IPURE; \
  758. STDMETHOD_(void, SetActiveInfo) (THIS_ DWORD dwActiveInfo) IPURE; \
  759. #undef INTERFACE
  760. #define INTERFACE ISpdInfo
  761. DECLARE_INTERFACE_(ISpdInfo, IUnknown)
  762. {
  763. public:
  764. DeclareIUnknownMembers(PURE)
  765. DeclareISpdInfoMembers(PURE)
  766. };
  767. typedef ComSmartPointer<ISpdInfo, &IID_ISpdInfo> SPISpdInfo;
  768. class CSpdInfo : public ISpdInfo
  769. {
  770. public:
  771. CSpdInfo();
  772. ~CSpdInfo();
  773. DeclareIUnknownMembers(IMPL);
  774. DeclareISpdInfoMembers(IMPL);
  775. private:
  776. CFilterInfoArray m_arrayFilters; //for generic filters
  777. CIndexMgrFilter m_IndexMgrFilters;
  778. CFilterInfoArray m_arraySpecificFilters; //for specific filters
  779. CIndexMgrFilter m_IndexMgrSpecificFilters;
  780. CMmFilterInfoArray m_arrayMmFilters;
  781. CIndexMgrMmFilter m_IndexMgrMmFilters;
  782. CMmFilterInfoArray m_arrayMmSpecificFilters;
  783. CIndexMgrMmFilter m_IndexMgrMmSpecificFilters;
  784. CMmPolicyInfoArray m_arrayMmPolicies;
  785. CIndexMgrMmPolicy m_IndexMgrMmPolicies;
  786. CMmSAArray m_arrayMmSAs;
  787. CIndexMgrMmSA m_IndexMgrMmSAs;
  788. CQmSAArray m_arrayQmSAs;
  789. CIndexMgrQmSA m_IndexMgrQmSAs;
  790. CQmPolicyInfoArray m_arrayQmPolicies;
  791. CIndexMgrQmPolicy m_IndexMgrQmPolicies;
  792. CMmAuthMethodsArray m_arrMmAuthMethods;
  793. CIkeStatistics m_IkeStats;
  794. CIpsecStatistics m_IpsecStats;
  795. CCriticalSection m_csData;
  796. CString m_stMachineName;
  797. LONG m_cRef;
  798. DWORD m_Init;
  799. DWORD m_Active;
  800. private:
  801. void ConvertToExternalFilterData(CFilterInfo * pfltrIn, TRANSPORT_FILTER * pfltrOut);
  802. void CSpdInfo::ConvertToExternalMMFilterData (
  803. CMmFilterInfo * pfltrIn,
  804. MM_FILTER * pfltrOut);
  805. HRESULT LoadMiscMmFilterInfo(CMmFilterInfo * pFltr);
  806. HRESULT LoadMiscFilterInfo(CFilterInfo * pFilter);
  807. HRESULT LoadMiscMmSAInfo(CMmSA * pSA);
  808. HRESULT LoadMiscQmSAInfo(CQmSA * pSA);
  809. HRESULT InternalEnumMmFilters(
  810. DWORD dwLevel,
  811. GUID guid,
  812. CMmFilterInfoArray * pArray,
  813. DWORD dwPreferredNum = 0 /*by default get all entries*/);
  814. HRESULT InternalEnumTransportFilters(
  815. DWORD dwLevel,
  816. GUID guid,
  817. CFilterInfoArray * pArray,
  818. DWORD dwPreferredNum = 0 /*by default get all entries*/);
  819. HRESULT InternalEnumTunnelFilters(
  820. DWORD dwLevel,
  821. GUID guid,
  822. CFilterInfoArray * pArray,
  823. DWORD dwPreferredNum = 0 /*by default get all entries*/);
  824. HRESULT InternalEnumMmPolicies(
  825. CMmPolicyInfoArray * pArray,
  826. DWORD dwPreferredNum = 0 /*by default get all entries*/);
  827. HRESULT InternalEnumQmPolicies(
  828. CQmPolicyInfoArray * pArray,
  829. DWORD dwPreferredNum = 0 /*by default get all entries*/);
  830. HRESULT InternalEnumMmAuthMethods(
  831. CMmAuthMethodsArray * pArray,
  832. DWORD dwPreferredNum = 0 /*by default get all entries*/);
  833. HRESULT InternalEnumMmSAs(CMmSAArray * pArray);
  834. HRESULT InternalEnumQmSAs(CQmSAArray * pArray);
  835. void FreeIpsecSAList();
  836. HRESULT CallPA();
  837. };
  838. HRESULT CreateSpdInfo(ISpdInfo **ppSpdInfo);
  839. #endif