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.

1634 lines
39 KiB

  1. //////////////////////////////////////////////////////////////////////
  2. //Module: Static/StaticSetUtils.cpp
  3. // Purpose: Static Set auxiliary functions Implementation.
  4. // Developers Name: Surya
  5. // History:
  6. // Date Author Comments
  7. // 10-8-2001 Bharat Initial Version. SCM Base line 1.0
  8. // <creation> <author>
  9. // <modification> <author> <comments, references to code sections,
  10. // in case of bug fixes>
  11. //////////////////////////////////////////////////////////////////////
  12. #include "nshipsec.h"
  13. //////////////////////////////////////////////////////////////////////
  14. //Function: IsDSAvailable()
  15. //Date of Creation: 21st Aug 2001
  16. //Parameters:
  17. // OUT LPTSTR * pszPath
  18. //Return: BOOL
  19. //Description:
  20. // This function checks whether DS exists
  21. //Revision History:
  22. //<Version number, Change request number, Date of modification,
  23. // Author, Nature of change>
  24. //////////////////////////////////////////////////////////////////////
  25. BOOL
  26. IsDSAvailable(
  27. OUT LPTSTR * pszPath
  28. )
  29. {
  30. HRESULT hr = S_OK;
  31. IADs * pintIADs = NULL;
  32. VARIANT var;
  33. BSTR bstrName = NULL;
  34. DWORD dwReturn = ERROR_SUCCESS , dwStrLenAlloc = 0,dwStrLenCpy = 0;
  35. BOOL bDSAvailable = FALSE ;
  36. hr = ADsGetObject(_TEXT("LDAP://rootDSE"), IID_IADs, (void **)&pintIADs);
  37. if ( SUCCEEDED(hr) )
  38. {
  39. if ( pszPath )
  40. {
  41. dwReturn = AllocBSTRMem(_TEXT("defaultNamingContext"),bstrName);
  42. if(dwReturn == ERROR_OUTOFMEMORY)
  43. {
  44. PrintErrorMessage(WIN32_ERR,ERROR_OUTOFMEMORY,NULL);
  45. BAIL_OUT;
  46. }
  47. pintIADs->Get(bstrName, &var);
  48. SysFreeString(bstrName);
  49. if ( SUCCEEDED(hr) )
  50. {
  51. dwStrLenAlloc = wcslen(var.bstrVal) + wcslen(_TEXT("LDAP://"));
  52. *pszPath = (LPTSTR)
  53. ::CoTaskMemAlloc(sizeof(OLECHAR) *
  54. (dwStrLenAlloc+1));
  55. if (*pszPath == NULL)
  56. {
  57. PrintErrorMessage(WIN32_ERR,ERROR_OUTOFMEMORY,NULL);
  58. BAIL_OUT;
  59. }
  60. wcsncpy(*pszPath, _TEXT("LDAP://"),dwStrLenAlloc+1);
  61. dwStrLenCpy = wcslen(*pszPath);
  62. wcsncat(*pszPath, var.bstrVal,dwStrLenAlloc-dwStrLenCpy+1);
  63. }
  64. }
  65. bDSAvailable = TRUE;
  66. }
  67. if ( pintIADs )
  68. {
  69. pintIADs->Release();
  70. }
  71. error:
  72. return bDSAvailable;
  73. }
  74. //////////////////////////////////////////////////////////////////////
  75. //
  76. // Function: FindObject
  77. //
  78. // Date of Creation: 21st Aug 2001
  79. //
  80. //
  81. // Pre-conditions:
  82. //
  83. // Runs on a machine that is part of an NT5 domain
  84. //
  85. // Parameters:
  86. //
  87. // IN szName the friendly name to find
  88. // IN cls the class of the object
  89. // OUT szPath ADS path returned on success
  90. // Or the ADS path to the domain on failure
  91. //
  92. // Return :
  93. //
  94. // E_FAIL if object not found
  95. // anything from GetGC
  96. // S_OK for success
  97. //
  98. // Description:
  99. // Finds particular object in the DS. The objects supported
  100. // right now are any in the objectClass enum type
  101. // Revision History:
  102. // <Version number, Change request number, Date of modification,
  103. // Author, Nature of change>
  104. //////////////////////////////////////////////////////////////////////
  105. HRESULT
  106. FindObject(
  107. IN LPTSTR szName,
  108. IN objectClass cls,
  109. OUT LPTSTR & szPath
  110. )
  111. {
  112. _TCHAR szFilter[IDS_MAX_FILTLEN] = {0}; // the search filter we'll use
  113. _TCHAR szSearchBase[IDS_MAX_FILTLEN] = {0}; // the root to search from
  114. LPTSTR pszAttr[] = {_TEXT("distinguishedName")};
  115. DWORD dwAttrCount = 1 , dwStrLen = 0;
  116. HRESULT hrStatus = S_OK;
  117. IDirectorySearch * pintSearch = NULL;
  118. szPath = NULL;
  119. if ( !IsDSAvailable(&szPath) )
  120. {
  121. return E_IDS_NO_DS;
  122. }
  123. else if ( !szName )
  124. {
  125. return E_INVALIDARG;
  126. }
  127. // determine what we're looking for
  128. // and set up the filter
  129. _tcsncpy(szSearchBase, _TEXT("LDAP://"),IDS_MAX_FILTLEN-1);
  130. switch (cls)
  131. {
  132. case OBJCLS_OU:
  133. _tcsncpy(szFilter, _TEXT("(&(objectClass=organizationalUnit)(name="),IDS_MAX_FILTLEN-1);
  134. break;
  135. case OBJCLS_GPO:
  136. _tcsncpy(szFilter, _TEXT("(&(objectClass=groupPolicyContainer)(displayName="),IDS_MAX_FILTLEN-1);
  137. dwStrLen = _tcslen(szSearchBase);
  138. _tcsncat(szSearchBase, _TEXT("CN=Policies,CN=System,"),IDS_MAX_FILTLEN-dwStrLen-1);
  139. break;
  140. case OBJCLS_IPSEC_POLICY:
  141. _tcsncpy(szFilter, _TEXT("(&(objectClass=ipsecPolicy)(ipsecName="),IDS_MAX_FILTLEN-1);
  142. dwStrLen = _tcslen(szSearchBase);
  143. _tcsncat(szSearchBase, _TEXT("CN=IP Security,CN=System,"),IDS_MAX_FILTLEN-dwStrLen-1);
  144. break;
  145. case OBJCLS_CONTAINER:
  146. _tcsncpy(szFilter, _TEXT("(&(objectClass=container)(cn="),IDS_MAX_FILTLEN-1);
  147. break;
  148. case OBJCLS_COMPUTER:
  149. _tcsncpy(szFilter, _TEXT("(&(objectClass=computer)(cn="),IDS_MAX_FILTLEN-1);
  150. break;
  151. default:
  152. return CO_E_NOT_SUPPORTED;
  153. }
  154. dwStrLen = _tcslen(szFilter);
  155. _tcsncat(szFilter, szName,IDS_MAX_FILTLEN-dwStrLen-1);
  156. dwStrLen = _tcslen(szFilter);
  157. _tcsncat(szFilter, TEXT("))"),IDS_MAX_FILTLEN-dwStrLen-1);
  158. dwStrLen = _tcslen(szSearchBase);
  159. _tcsncat(szSearchBase, szPath + 7,IDS_MAX_FILTLEN-dwStrLen-1); // get's past the LDAP://
  160. // the filter and search base are set up now
  161. // we need to get the IDirectorySearch interface
  162. // from the root of the domain
  163. hrStatus = ADsGetObject(szSearchBase, IID_IDirectorySearch,
  164. (void **)&pintSearch);
  165. if ( SUCCEEDED(hrStatus) )
  166. {
  167. ADS_SEARCH_HANDLE hSearch = NULL;
  168. hrStatus = pintSearch->ExecuteSearch(szFilter, pszAttr,
  169. dwAttrCount, &hSearch);
  170. if ( SUCCEEDED(hrStatus) )
  171. {
  172. hrStatus = pintSearch->GetFirstRow(hSearch);
  173. // at this point, if we have a row, we have found the
  174. // object.
  175. if ( S_ADS_NOMORE_ROWS == hrStatus )
  176. {
  177. hrStatus = E_FAIL;
  178. }
  179. else if ( SUCCEEDED(hrStatus) )
  180. {
  181. ADS_SEARCH_COLUMN adsCol = {0};
  182. hrStatus = pintSearch->GetColumn(hSearch, pszAttr[0], &adsCol);
  183. if ( SUCCEEDED(hrStatus) &&
  184. adsCol.pADsValues->dwType == ADSTYPE_DN_STRING )
  185. {
  186. if ( szPath )
  187. CoTaskMemFree(szPath);
  188. dwStrLen = _tcslen(adsCol.pADsValues->DNString) + _tcslen(TEXT("LDAP://"));
  189. szPath = (LPTSTR)::CoTaskMemAlloc((dwStrLen +1) * sizeof(_TCHAR));
  190. if (szPath == NULL)
  191. {
  192. hrStatus=HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY);
  193. BAIL_OUT;
  194. }
  195. memset(szPath ,0 ,(dwStrLen+1)*sizeof(TCHAR));
  196. _tcsncpy(szPath, _TEXT("LDAP://"),dwStrLen+1);
  197. _tcsncat(szPath, adsCol.pADsValues->DNString,dwStrLen- (_tcslen(szPath))+1);
  198. }
  199. else
  200. {
  201. hrStatus = E_IDS_NODNSTRING;
  202. }
  203. pintSearch->FreeColumn( &adsCol );
  204. }
  205. pintSearch->CloseSearchHandle(hSearch);
  206. }
  207. }
  208. if ( pintSearch )
  209. {
  210. pintSearch->Release();
  211. }
  212. error:
  213. return hrStatus;
  214. }
  215. //////////////////////////////////////////////////////////////////////////////
  216. // Function: AssignIPSecPolicyToGPO
  217. //
  218. // Purpose:
  219. //
  220. // Assigns (or unassigns) IPSec pol to GPO
  221. //
  222. // Pre-conditions: None
  223. //
  224. // Parameters:
  225. //
  226. // IN szPolicyName ADsPath or name of ipsec pol
  227. // IN szGPO ADsPath or name of GPO
  228. // IN BOOL bAssign
  229. //
  230. // Returns:
  231. //
  232. // ADSI errors
  233. // S_OK on success
  234. //
  235. //Revision History:
  236. //<Version number, Change request number, Date of modification,
  237. // Author, Nature of change>
  238. //////////////////////////////////////////////////////////////////////////////
  239. HRESULT
  240. AssignIPSecPolicyToGPO(
  241. IN LPTSTR szPolicyName,
  242. IN LPTSTR szGPO,
  243. IN BOOL bAssign
  244. )
  245. {
  246. HRESULT hr = S_OK;
  247. LPTSTR szIPSecPolPath = NULL,
  248. szGPOPath = NULL;
  249. _TCHAR szMachinePath[IDS_MAX_PATHLEN] = {0};
  250. IGroupPolicyObject * pintGPO = NULL;
  251. GUID guidClientExt = CLSID_IPSECClientEx;
  252. GUID guidSnapin = CLSID_Snapin;
  253. hr = CoInitialize(NULL);
  254. if (FAILED(hr))
  255. {
  256. BAIL_OUT;
  257. }
  258. if ( !szGPO )
  259. {
  260. return E_INVALIDARG;
  261. }
  262. //
  263. // First, get the ipsec policy object
  264. // and get the GPO objects
  265. //
  266. if ( szPolicyName && !IsADsPath(szPolicyName) )
  267. {
  268. hr = FindObject(szPolicyName, OBJCLS_IPSEC_POLICY, szIPSecPolPath);
  269. }
  270. else
  271. {
  272. szIPSecPolPath = szPolicyName;
  273. }
  274. // now get the GPO
  275. if ( SUCCEEDED(hr) )
  276. {
  277. if ( !IsADsPath(szGPO) )
  278. {
  279. hr = FindObject(szGPO, OBJCLS_GPO, szGPOPath);
  280. }
  281. else
  282. {
  283. szGPOPath = szGPO;
  284. }
  285. hr = CoCreateInstance(CLSID_GroupPolicyObject, NULL, CLSCTX_ALL,
  286. IID_IGroupPolicyObject, (void **)&pintGPO);
  287. if ( SUCCEEDED(hr) )
  288. {
  289. //
  290. // we need to hand off the domain path name
  291. // FindObject returned it in szPath
  292. //
  293. hr = pintGPO->OpenDSGPO(szGPOPath, FALSE);
  294. if ( SUCCEEDED(hr) )
  295. {
  296. //
  297. // We want to get the path to the GPO's machine container
  298. //
  299. hr = pintGPO->GetDSPath(GPO_SECTION_MACHINE, szMachinePath,
  300. IDS_MAX_PATHLEN);
  301. }
  302. }
  303. }
  304. if ( SUCCEEDED(hr) )
  305. {
  306. LPTSTR szName = NULL,
  307. szDescription = NULL;
  308. if ( szIPSecPolPath )
  309. {
  310. if(bAssign)
  311. {
  312. //
  313. // Assignment
  314. hr = GetIPSecPolicyInfo(szIPSecPolPath, szName, szDescription);
  315. if ( SUCCEEDED(hr) )
  316. {
  317. // if description is NULL, pass blank str to make ADSI happy
  318. //
  319. hr = AddPolicyInformationToGPO(szMachinePath,
  320. szName,
  321. (szDescription) ? szDescription : TEXT(" "),
  322. szIPSecPolPath);
  323. // Need to write the changes to the GPO
  324. if ( SUCCEEDED(hr) )
  325. {
  326. hr = pintGPO->Save(TRUE, TRUE, &guidClientExt,
  327. &guidSnapin);
  328. }
  329. }
  330. if ( szName )
  331. CoTaskMemFree(szName);
  332. if ( szDescription )
  333. CoTaskMemFree(szDescription);
  334. }
  335. else
  336. {
  337. // Unassignment
  338. hr = DeletePolicyInformationFromGPO(szMachinePath);
  339. // Need to write the changes to the GPO
  340. if ( SUCCEEDED(hr) )
  341. {
  342. pintGPO->Save(TRUE, FALSE, &guidClientExt,
  343. &guidSnapin);
  344. }
  345. }
  346. }
  347. }
  348. if ( pintGPO )
  349. pintGPO->Release();
  350. error:
  351. return hr;
  352. }
  353. //////////////////////////////////////////////////////////////////////////////
  354. //
  355. // Function: GetIPSecPolicyInfo
  356. //
  357. // Purpose:
  358. //
  359. // Gets the name and description of an ipsec policy
  360. // given an ADs path to the policy
  361. //
  362. // Pre-conditions: None
  363. //
  364. // Parameters:
  365. // IN szPath ADsPath to policy
  366. // OUT szName, szDescription
  367. // NOTE: caller MUST free with CoTaskMemFree
  368. //
  369. // Returns:
  370. // anything from ADsGetObject
  371. // E_FAIL if Name not found
  372. //
  373. //Revision History:
  374. //<Version number, Change request number, Date of modification,
  375. // Author, Nature of change>
  376. //////////////////////////////////////////////////////////////////////////////
  377. HRESULT
  378. GetIPSecPolicyInfo(
  379. IN LPTSTR szPath,
  380. OUT LPTSTR & szName,
  381. OUT LPTSTR & szDescription
  382. )
  383. {
  384. HRESULT hr = S_OK;
  385. DWORD dwNumAttr = 2,
  386. dwNumRecvd = 0,
  387. dwStrLen = 0;
  388. LPTSTR pszAttr[] = {TEXT("ipsecName"), TEXT("description")};
  389. ADS_ATTR_INFO * pattrInfo = NULL;
  390. IDirectoryObject * pintDirObj = NULL;
  391. //
  392. // init these to NULL, if the attr's not found, they will stay NULL
  393. //
  394. szName = szDescription = NULL;
  395. hr = ADsGetObject(szPath, IID_IDirectoryObject, (void **)&pintDirObj);
  396. BAIL_ON_FAILURE(hr);
  397. hr = pintDirObj->GetObjectAttributes(pszAttr, dwNumAttr, &pattrInfo, &dwNumRecvd);
  398. BAIL_ON_FAILURE(hr);
  399. for ( DWORD i = 0; i < dwNumRecvd; ++i )
  400. {
  401. if ( !_tcscmp(pattrInfo[i].pszAttrName, TEXT("ipsecName")) )
  402. {
  403. dwStrLen = _tcslen(pattrInfo[i].pADsValues->DNString);
  404. szName = (LPTSTR)CoTaskMemAlloc((dwStrLen + 1)
  405. * sizeof (_TCHAR));
  406. if (szName == NULL)
  407. {
  408. hr=HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY);
  409. BAIL_OUT;
  410. }
  411. _tcsncpy(szName, pattrInfo[i].pADsValues->DNString,dwStrLen + 1);
  412. }
  413. else if ( !_tcscmp(pattrInfo[i].pszAttrName, TEXT("description")) )
  414. {
  415. dwStrLen = _tcslen(pattrInfo[i].pADsValues->DNString);
  416. szDescription = (LPTSTR)CoTaskMemAlloc((dwStrLen + 1)
  417. * sizeof (_TCHAR));
  418. if (szDescription == NULL)
  419. {
  420. hr=HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY);
  421. BAIL_OUT;
  422. }
  423. _tcsncpy(szDescription, pattrInfo[i].pADsValues->DNString,dwStrLen + 1);
  424. }
  425. }
  426. pintDirObj->Release();
  427. FreeADsMem(pattrInfo);
  428. //
  429. // if szName is NULL, it wasn't found and it is an error
  430. // description CAN be NULL
  431. //
  432. if ( !szName )
  433. {
  434. hr = E_FAIL;
  435. }
  436. error:
  437. return hr;
  438. }
  439. ///////////////////////////////////////////////////////////////////////////
  440. //Function: CreateDirectoryAndBindToObject()
  441. //Date of Creation: 21st Aug 2001
  442. //Parameters:
  443. // IDirectoryObject * pParentContainer,
  444. // LPWSTR pszCommonName,
  445. // LPWSTR pszObjectClass,
  446. // IDirectoryObject ** ppDirectoryObject
  447. //Return: HRESULT
  448. //Description:
  449. // This function created a AD object
  450. //Revision History:
  451. //<Version number, Change request number, Date of modification,
  452. // Author, Nature of change>
  453. ///////////////////////////////////////////////////////////////////////////
  454. HRESULT
  455. CreateDirectoryAndBindToObject(
  456. IDirectoryObject * pParentContainer,
  457. LPWSTR pszCommonName,
  458. LPWSTR pszObjectClass,
  459. IDirectoryObject ** ppDirectoryObject
  460. )
  461. {
  462. ADS_ATTR_INFO AttrInfo[2];
  463. ADSVALUE classValue;
  464. HRESULT hr = S_OK;
  465. IADsContainer * pADsContainer = NULL;
  466. IDispatch * pDispatch = NULL;
  467. BSTR bstrObjectClass = NULL, bstrCommonName = NULL;
  468. DWORD dwReturn = ERROR_SUCCESS;
  469. //
  470. // Populate ADS_ATTR_INFO structure for new object
  471. //
  472. classValue.dwType = ADSTYPE_CASE_IGNORE_STRING;
  473. classValue.CaseIgnoreString = pszObjectClass;
  474. AttrInfo[0].pszAttrName = _TEXT("objectClass");
  475. AttrInfo[0].dwControlCode = ADS_ATTR_UPDATE;
  476. AttrInfo[0].dwADsType = ADSTYPE_CASE_IGNORE_STRING;
  477. AttrInfo[0].pADsValues = &classValue;
  478. AttrInfo[0].dwNumValues = 1;
  479. hr = pParentContainer->CreateDSObject(
  480. pszCommonName,
  481. AttrInfo,
  482. 1,
  483. &pDispatch
  484. );
  485. if ((FAILED(hr) && (hr == E_ADS_OBJECT_EXISTS)) ||
  486. (FAILED(hr) && (hr == HRESULT_FROM_WIN32(ERROR_OBJECT_ALREADY_EXISTS)))){
  487. hr = pParentContainer->QueryInterface(
  488. IID_IADsContainer,
  489. (void **)&pADsContainer
  490. );
  491. BAIL_ON_FAILURE(hr);
  492. dwReturn = AllocBSTRMem(pszObjectClass,bstrObjectClass);
  493. hr = HRESULT_FROM_WIN32(dwReturn);
  494. BAIL_ON_WIN32_ERROR(dwReturn);
  495. dwReturn = AllocBSTRMem(pszCommonName,bstrCommonName);
  496. hr = HRESULT_FROM_WIN32(dwReturn);
  497. BAIL_ON_WIN32_ERROR(dwReturn);
  498. hr = pADsContainer->GetObject(
  499. bstrObjectClass,
  500. bstrCommonName,
  501. &pDispatch
  502. );
  503. SysFreeString(bstrObjectClass);
  504. SysFreeString(bstrCommonName);
  505. BAIL_ON_FAILURE(hr);
  506. }
  507. hr = pDispatch->QueryInterface(
  508. IID_IDirectoryObject,
  509. (void **)ppDirectoryObject
  510. );
  511. error:
  512. if (pADsContainer) {
  513. pADsContainer->Release();
  514. }
  515. if (pDispatch) {
  516. pDispatch->Release();
  517. }
  518. return(hr);
  519. }
  520. ///////////////////////////////////////////////////////////////////////////
  521. //Function: CreateChildPath()
  522. //Date of Creation: 21st Aug 2001
  523. //Parameters:
  524. // IN LPWSTR pszParentPath,
  525. // IN LPWSTR pszChildComponent,
  526. // OUT BSTR * ppszChildPath
  527. //Return: HRESULT
  528. //Description:
  529. // This function creates the required path in the AD
  530. //Revision History:
  531. //<Version number, Change request number, Date of modification,
  532. // Author, Nature of change>
  533. ///////////////////////////////////////////////////////////////////////////
  534. HRESULT
  535. CreateChildPath(
  536. IN LPWSTR pszParentPath,
  537. IN LPWSTR pszChildComponent,
  538. OUT BSTR * ppszChildPath
  539. )
  540. {
  541. HRESULT hr = S_OK;
  542. IADsPathname *pPathname = NULL;
  543. BSTR bstrParentPath = NULL,bstrChildComponent=NULL;
  544. DWORD dwReturn = ERROR_SUCCESS;
  545. hr = CoCreateInstance(
  546. CLSID_Pathname,
  547. NULL,
  548. CLSCTX_ALL,
  549. IID_IADsPathname,
  550. (void**)&pPathname
  551. );
  552. if (FAILED(hr))
  553. {
  554. BAIL_OUT;
  555. }
  556. dwReturn = AllocBSTRMem(pszParentPath,bstrParentPath);
  557. hr = HRESULT_FROM_WIN32(dwReturn);
  558. BAIL_ON_WIN32_ERROR(dwReturn);
  559. hr = pPathname->Set(bstrParentPath, ADS_SETTYPE_FULL);
  560. SysFreeString(bstrParentPath);
  561. BAIL_ON_FAILURE(hr);
  562. dwReturn = AllocBSTRMem(pszChildComponent,bstrChildComponent);
  563. hr = HRESULT_FROM_WIN32(dwReturn);
  564. BAIL_ON_WIN32_ERROR(dwReturn);
  565. hr = pPathname->AddLeafElement(bstrChildComponent);
  566. SysFreeString(bstrChildComponent);
  567. BAIL_ON_FAILURE(hr);
  568. hr = pPathname->Retrieve(ADS_FORMAT_X500, ppszChildPath);
  569. BAIL_ON_FAILURE(hr);
  570. error:
  571. if (pPathname) {
  572. pPathname->Release();
  573. }
  574. return(hr);
  575. }
  576. ///////////////////////////////////////////////////////////////////////////
  577. //Function: ConvertADsPathToDN()
  578. //Date of Creation: 21st Aug 2001
  579. //Parameters:
  580. // IN LPWSTR pszPathName,
  581. // OUT BSTR * ppszPolicyDN
  582. //Return: HRESULT
  583. //Description:
  584. // This function converts ADs path to DN path
  585. //Revision History:
  586. //<Version number, Change request number, Date of modification,
  587. // Author, Nature of change>
  588. ///////////////////////////////////////////////////////////////////////////
  589. HRESULT
  590. ConvertADsPathToDN(
  591. IN LPWSTR pszPathName,
  592. OUT BSTR * ppszPolicyDN
  593. )
  594. {
  595. HRESULT hr = S_OK;
  596. IADsPathname *pPathname = NULL;
  597. BSTR bstrPathName =NULL;
  598. DWORD dwReturn = ERROR_SUCCESS;
  599. hr = CoCreateInstance(
  600. CLSID_Pathname,
  601. NULL,
  602. CLSCTX_ALL,
  603. IID_IADsPathname,
  604. (void**)&pPathname
  605. );
  606. if (FAILED(hr))
  607. {
  608. BAIL_OUT;
  609. }
  610. dwReturn = AllocBSTRMem(pszPathName,bstrPathName);
  611. hr = HRESULT_FROM_WIN32(dwReturn);
  612. BAIL_ON_WIN32_ERROR(dwReturn);
  613. hr = pPathname->Set(bstrPathName, ADS_SETTYPE_FULL);
  614. SysFreeString(bstrPathName);
  615. BAIL_ON_FAILURE(hr);
  616. hr = pPathname->Retrieve(ADS_FORMAT_X500_DN, ppszPolicyDN);
  617. BAIL_ON_FAILURE(hr);
  618. error:
  619. if (pPathname) {
  620. pPathname->Release();
  621. }
  622. return(hr);
  623. }
  624. ///////////////////////////////////////////////////////////////////////////
  625. //Function: AddPolicyInformationToGPO()
  626. //Date of Creation: 21st Aug 2001
  627. //Parameters:
  628. // IN LPWSTR pszMachinePath,
  629. // IN LPWSTR pszName,
  630. // IN LPWSTR pszDescription,
  631. // IN LPWSTR pszPathName
  632. //Return: HRESULT
  633. //Description:
  634. // This function assigns the policy info to the specified GPO.
  635. //Revision History:
  636. //<Version number, Change request number, Date of modification,
  637. // Author, Nature of change>
  638. ///////////////////////////////////////////////////////////////////////////
  639. HRESULT
  640. AddPolicyInformationToGPO(
  641. IN LPWSTR pszMachinePath,
  642. IN LPWSTR pszName,
  643. IN LPWSTR pszDescription,
  644. IN LPWSTR pszPathName
  645. )
  646. {
  647. HRESULT hr = S_OK;
  648. IDirectoryObject * pMachineContainer = NULL;
  649. IDirectoryObject * pIpsecObject = NULL;
  650. IDirectoryObject * pWindowsContainer = NULL;
  651. IDirectoryObject * pMicrosoftContainer = NULL;
  652. BSTR pszMicrosoftPath = NULL;
  653. BSTR pszIpsecPath = NULL;
  654. BSTR pszWindowsPath = NULL;
  655. BSTR pszPolicyDN = NULL;
  656. ADS_ATTR_INFO AttrInfo[4];
  657. ADSVALUE PolicyPathValue;
  658. ADSVALUE PolicyNameValue;
  659. ADSVALUE PolicyDescriptionValue;
  660. memset((LPBYTE)AttrInfo, 0, sizeof(ADS_ATTR_INFO)*4);
  661. memset((LPBYTE)&PolicyPathValue, 0, sizeof(ADSVALUE));
  662. memset((LPBYTE)&PolicyNameValue, 0, sizeof(ADSVALUE));
  663. memset((LPBYTE)&PolicyDescriptionValue, 0, sizeof(ADSVALUE));
  664. DWORD dwNumModified = 0;
  665. hr = ADsGetObject(
  666. pszMachinePath,
  667. IID_IDirectoryObject,
  668. (void **)&pMachineContainer
  669. );
  670. BAIL_ON_FAILURE(hr);
  671. // Build the fully qualified ADsPath for my object
  672. hr = CreateChildPath(
  673. pszMachinePath,
  674. _TEXT("cn=Microsoft"),
  675. &pszMicrosoftPath
  676. );
  677. BAIL_ON_FAILURE(hr);
  678. hr = CreateChildPath(
  679. pszMicrosoftPath,
  680. _TEXT("cn=Windows"),
  681. &pszWindowsPath
  682. );
  683. BAIL_ON_FAILURE(hr);
  684. hr = CreateChildPath(
  685. pszWindowsPath,
  686. _TEXT("cn=ipsec"),
  687. &pszIpsecPath
  688. );
  689. BAIL_ON_FAILURE(hr);
  690. hr = ADsGetObject(
  691. pszIpsecPath,
  692. IID_IDirectoryObject,
  693. (void **)&pIpsecObject
  694. );
  695. if (FAILED(hr)) {
  696. //
  697. // Bind to the Machine Container
  698. //
  699. hr = CreateDirectoryAndBindToObject(
  700. pMachineContainer,
  701. _TEXT("cn=Microsoft"),
  702. _TEXT("container"),
  703. &pMicrosoftContainer
  704. );
  705. BAIL_ON_FAILURE(hr);
  706. hr = CreateDirectoryAndBindToObject(
  707. pMicrosoftContainer,
  708. _TEXT("cn=Windows"),
  709. _TEXT("container"),
  710. &pWindowsContainer
  711. );
  712. BAIL_ON_FAILURE(hr);
  713. hr = CreateDirectoryAndBindToObject(
  714. pWindowsContainer,
  715. _TEXT("cn=IPSEC"),
  716. _TEXT("ipsecPolicy"),
  717. &pIpsecObject
  718. );
  719. BAIL_ON_FAILURE(hr);
  720. }
  721. //
  722. // Input pszPathName is an ADsPathName
  723. // We need to reduce it to a DN and store it
  724. // in the ipsecOwnersReference (a multi-valued DN attribute)
  725. //
  726. hr = ConvertADsPathToDN(
  727. pszPathName,
  728. &pszPolicyDN
  729. );
  730. BAIL_ON_FAILURE(hr);
  731. //
  732. // Populate ADS_ATTR_INFO structure for new object
  733. //
  734. PolicyPathValue.dwType = ADSTYPE_CASE_IGNORE_STRING;
  735. PolicyPathValue.CaseIgnoreString = pszPolicyDN;
  736. AttrInfo[0].pszAttrName = _TEXT("ipsecOwnersReference");
  737. AttrInfo[0].dwControlCode = ADS_ATTR_UPDATE;
  738. AttrInfo[0].dwADsType = ADSTYPE_CASE_IGNORE_STRING;
  739. AttrInfo[0].pADsValues = &PolicyPathValue;
  740. AttrInfo[0].dwNumValues = 1;
  741. //
  742. // Populate ADS_ATTR_INFO structure for new object
  743. //
  744. PolicyNameValue.dwType = ADSTYPE_CASE_IGNORE_STRING;
  745. PolicyNameValue.CaseIgnoreString = pszName;
  746. AttrInfo[1].pszAttrName = _TEXT("ipsecName");
  747. AttrInfo[1].dwControlCode = ADS_ATTR_UPDATE;
  748. AttrInfo[1].dwADsType = ADSTYPE_CASE_IGNORE_STRING;
  749. AttrInfo[1].pADsValues = &PolicyNameValue;
  750. AttrInfo[1].dwNumValues = 1;
  751. //
  752. // Populate ADS_ATTR_INFO structure for new object
  753. //
  754. PolicyDescriptionValue.dwType = ADSTYPE_CASE_IGNORE_STRING;
  755. PolicyDescriptionValue.CaseIgnoreString = pszDescription;
  756. AttrInfo[2].pszAttrName = _TEXT("description");
  757. AttrInfo[2].dwControlCode = ADS_ATTR_UPDATE;
  758. AttrInfo[2].dwADsType = ADSTYPE_CASE_IGNORE_STRING;
  759. AttrInfo[2].pADsValues = &PolicyDescriptionValue;
  760. AttrInfo[2].dwNumValues = 1;
  761. //
  762. // Now populate our object with our data.
  763. //
  764. hr = pIpsecObject->SetObjectAttributes(
  765. AttrInfo,
  766. 3,
  767. &dwNumModified
  768. );
  769. error:
  770. if (pIpsecObject) {
  771. pIpsecObject->Release();
  772. }
  773. if (pMicrosoftContainer) {
  774. pMicrosoftContainer->Release();
  775. }
  776. if (pWindowsContainer) {
  777. pWindowsContainer->Release();
  778. }
  779. if (pMachineContainer) {
  780. pMachineContainer->Release();
  781. }
  782. if (pszMicrosoftPath) {
  783. SysFreeString(pszMicrosoftPath);
  784. }
  785. if (pszPolicyDN) {
  786. SysFreeString(pszPolicyDN);
  787. }
  788. if (pszWindowsPath) {
  789. SysFreeString(pszWindowsPath);
  790. }
  791. if (pszIpsecPath) {
  792. SysFreeString(pszIpsecPath);
  793. }
  794. return(hr);
  795. }
  796. ///////////////////////////////////////////////////////////////////////////
  797. //Function: DeletePolicyInformationFromGPO()
  798. //Date of Creation: 21st Aug 2001
  799. //Parameters:
  800. // IN LPWSTR pszMachinePath,
  801. //Return: HRESULT
  802. //Description:
  803. // This function unassigns the policy info to the specified GPO.
  804. //Revision History:
  805. //<Version number, Change request number, Date of modification,
  806. // Author, Nature of change>
  807. ///////////////////////////////////////////////////////////////////////////
  808. HRESULT
  809. DeletePolicyInformationFromGPO(
  810. IN LPWSTR pszMachinePath
  811. )
  812. {
  813. HRESULT hr = S_OK;
  814. IDirectoryObject * pIpsecObject = NULL;
  815. IDirectoryObject * pWindowsContainer = NULL;
  816. BSTR pszMicrosoftPath = NULL;
  817. BSTR pszIpsecPath = NULL;
  818. BSTR pszWindowsPath = NULL;
  819. // Build the fully qualified ADsPath for my object
  820. hr = CreateChildPath(
  821. pszMachinePath,
  822. _TEXT("cn=Microsoft"),
  823. &pszMicrosoftPath
  824. );
  825. BAIL_ON_FAILURE(hr);
  826. hr = CreateChildPath(
  827. pszMicrosoftPath,
  828. _TEXT("cn=Windows"),
  829. &pszWindowsPath
  830. );
  831. BAIL_ON_FAILURE(hr);
  832. hr = CreateChildPath(
  833. pszWindowsPath,
  834. _TEXT("cn=ipsec"),
  835. &pszIpsecPath
  836. );
  837. BAIL_ON_FAILURE(hr);
  838. hr = ADsGetObject(
  839. pszIpsecPath,
  840. IID_IDirectoryObject,
  841. (void **)&pIpsecObject
  842. );
  843. if (FAILED(hr)) {
  844. //
  845. // This means there is no object, need to
  846. // test that it is because the object does
  847. // not exist.
  848. //
  849. hr = S_OK;
  850. goto error;
  851. }
  852. if (SUCCEEDED(hr)) {
  853. pIpsecObject->Release();
  854. pIpsecObject = NULL;
  855. hr = ADsGetObject(
  856. pszWindowsPath,
  857. IID_IDirectoryObject,
  858. (void **)&pWindowsContainer
  859. );
  860. BAIL_ON_FAILURE(hr);
  861. hr = pWindowsContainer->DeleteDSObject(
  862. _TEXT("cn=ipsec")
  863. );
  864. }
  865. error:
  866. if (pIpsecObject) {
  867. pIpsecObject->Release();
  868. }
  869. if (pWindowsContainer) {
  870. pWindowsContainer->Release();
  871. }
  872. if (pszMicrosoftPath) {
  873. SysFreeString(pszMicrosoftPath);
  874. }
  875. if (pszWindowsPath) {
  876. SysFreeString(pszWindowsPath);
  877. }
  878. if (pszIpsecPath) {
  879. SysFreeString(pszIpsecPath);
  880. }
  881. return(hr);
  882. }
  883. ///////////////////////////////////////////////////////////////////////////
  884. //Function: IsADsPath()
  885. //Date of Creation: 21st Aug 2001
  886. //Parameters:
  887. // IN LPTSTR szPath
  888. //Return: BOOL
  889. //Description:
  890. // This function checks whether the specified string is valid ADs path
  891. //Revision History:
  892. //<Version number, Change request number, Date of modification,
  893. // Author, Nature of change>
  894. ///////////////////////////////////////////////////////////////////////////
  895. BOOL
  896. IsADsPath(
  897. IN LPTSTR szPath
  898. )
  899. {
  900. return !_tcsncmp(szPath, _TEXT("LDAP://"), 7);
  901. }
  902. ///////////////////////////////////////////////////////////////////////
  903. //Function: StripGUIDBraces()
  904. //Date of Creation: 21st Aug 2001
  905. //Parameters:
  906. // IN OUT LPTSTR & pszStr
  907. //Return: VOID
  908. //Description:
  909. // This function strips the end braces from the GUID string
  910. //Revision History:
  911. //<Version number, Change request number, Date of modification,
  912. // Author, Nature of change>
  913. ///////////////////////////////////////////////////////////////////////
  914. VOID
  915. StripGUIDBraces(
  916. IN OUT LPTSTR & pszGUIDStr
  917. )
  918. {
  919. LPTSTR pszLocalStr=NULL;
  920. if(!pszGUIDStr)
  921. {
  922. BAIL_OUT;
  923. }
  924. pszLocalStr = _tcschr(pszGUIDStr,CLOSE_GUID_BRACE);
  925. if(pszLocalStr)
  926. *pszLocalStr = _T('\0');
  927. pszLocalStr = _tcschr(pszGUIDStr,OPEN_GUID_BRACE);
  928. if(pszLocalStr)
  929. {
  930. pszLocalStr++;
  931. memmove(pszGUIDStr,(const void *)pszLocalStr,sizeof(TCHAR)*(_tcslen(pszLocalStr)+1));
  932. }
  933. error:
  934. return;
  935. }
  936. ///////////////////////////////////////////////////////////////////////
  937. //Function: AllocBSTRMem()
  938. //Date of Creation: 21st Aug 2001
  939. //Parameters:
  940. // IN LPTSTR pszStr,
  941. // IN OUT BSTR & pbsStr
  942. //Return: DWORD
  943. //Description:
  944. // This function strips the end braces from the GUID string
  945. //Revision History:
  946. //<Version number, Change request number, Date of modification,
  947. // Author, Nature of change>
  948. ///////////////////////////////////////////////////////////////////////
  949. DWORD
  950. AllocBSTRMem(
  951. IN LPTSTR pszStr,
  952. IN OUT BSTR & pbsStr
  953. )
  954. {
  955. DWORD dwReturnCode=ERROR_SUCCESS;
  956. if(!pszStr)
  957. {
  958. dwReturnCode=ERROR_INVALID_DATA;
  959. BAIL_OUT;
  960. }
  961. pbsStr = SysAllocString(pszStr);
  962. if(!pbsStr)
  963. {
  964. if (*pszStr)
  965. {
  966. dwReturnCode=ERROR_OUTOFMEMORY;
  967. }
  968. else
  969. {
  970. dwReturnCode=ERROR_INVALID_DATA;
  971. }
  972. }
  973. error:
  974. return dwReturnCode;
  975. }
  976. ///////////////////////////////////////////////////////////////////////
  977. //Function: CleanUpAuthInfo()
  978. //Date of Creation: 21st Aug 2001
  979. //Parameters:
  980. // PIPSEC_NFA_DATA &pRule
  981. //Return: VOID
  982. //Description:
  983. // This function cleans up the auth info memory of rule
  984. //Revision History:
  985. //<Version number, Change request number, Date of modification,
  986. // Author, Nature of change>
  987. ///////////////////////////////////////////////////////////////////////
  988. VOID
  989. CleanUpAuthInfo(
  990. PIPSEC_NFA_DATA &pRule
  991. )
  992. {
  993. DWORD i=0;
  994. if(pRule->ppAuthMethods)
  995. {
  996. for (i = 0; i < pRule->dwAuthMethodCount; i++)
  997. {
  998. if(pRule->ppAuthMethods[i])
  999. {
  1000. if(pRule->ppAuthMethods[i]->pAltAuthMethod!=NULL)
  1001. {
  1002. IPSecFreePolMem(pRule->ppAuthMethods[i]->pAltAuthMethod);
  1003. }
  1004. IPSecFreePolMem(pRule->ppAuthMethods[i]);
  1005. }
  1006. }
  1007. IPSecFreePolMem(pRule->ppAuthMethods);
  1008. }
  1009. }
  1010. ///////////////////////////////////////////////////////////////////////
  1011. //Function: CleanUpPolicy()
  1012. //Date of Creation: 21st Aug 2001
  1013. //Parameters:
  1014. // PIPSEC_POLICY_DATA &pPolicy
  1015. //Return: VOID
  1016. //Description:
  1017. // This function cleans up the policy info
  1018. //Revision History:
  1019. //<Version number, Change request number, Date of modification,
  1020. // Author, Nature of change>
  1021. ///////////////////////////////////////////////////////////////////////
  1022. VOID
  1023. CleanUpPolicy(
  1024. PIPSEC_POLICY_DATA &pPolicy
  1025. )
  1026. {
  1027. if(pPolicy)
  1028. {
  1029. if(pPolicy->pIpsecISAKMPData)
  1030. {
  1031. if(pPolicy->pIpsecISAKMPData->pSecurityMethods)
  1032. {
  1033. IPSecFreePolMem(pPolicy->pIpsecISAKMPData->pSecurityMethods);
  1034. }
  1035. IPSecFreePolMem(pPolicy->pIpsecISAKMPData);
  1036. }
  1037. IPSecFreePolMem(pPolicy);
  1038. pPolicy=NULL;
  1039. }
  1040. }
  1041. ///////////////////////////////////////////////////////////////////////
  1042. //Function: CleanUpLocalRuleDataStructure()
  1043. //Date of Creation: 21st Aug 2001
  1044. //Parameters:
  1045. // PRULEDATA &pRuleData
  1046. //Return: VOID
  1047. //Description:
  1048. // This function cleans up the local Rule Structure
  1049. //Revision History:
  1050. //<Version number, Change request number, Date of modification,
  1051. // Author, Nature of change>
  1052. ///////////////////////////////////////////////////////////////////////
  1053. VOID
  1054. CleanUpLocalRuleDataStructure(
  1055. PRULEDATA &pRuleData
  1056. )
  1057. {
  1058. DWORD j=0;
  1059. if (pRuleData)
  1060. {
  1061. if (pRuleData->pszRuleName)
  1062. {
  1063. delete [] pRuleData->pszRuleName;
  1064. }
  1065. if (pRuleData->pszNewRuleName)
  1066. {
  1067. delete [] pRuleData->pszNewRuleName;
  1068. }
  1069. if (pRuleData->pszRuleDescription)
  1070. {
  1071. delete [] pRuleData->pszRuleDescription;
  1072. }
  1073. if (pRuleData->pszPolicyName)
  1074. {
  1075. delete [] pRuleData->pszPolicyName;
  1076. }
  1077. if (pRuleData->pszFLName)
  1078. {
  1079. delete [] pRuleData->pszFLName;
  1080. }
  1081. if (pRuleData->pszFAName)
  1082. {
  1083. delete [] pRuleData->pszFAName;
  1084. }
  1085. for (j=0;j<pRuleData->AuthInfos.dwNumAuthInfos;j++)
  1086. {
  1087. if (pRuleData->AuthInfos.pAuthMethodInfo[j].pAuthenticationInfo)
  1088. {
  1089. if (pRuleData->AuthInfos.pAuthMethodInfo[j].pAuthenticationInfo->AuthMethod == IKE_RSA_SIGNATURE &&
  1090. pRuleData->AuthInfos.pAuthMethodInfo[j].pAuthenticationInfo->pAuthInfo
  1091. )
  1092. {
  1093. delete [] pRuleData->AuthInfos.pAuthMethodInfo[j].pAuthenticationInfo->pAuthInfo;
  1094. }
  1095. delete pRuleData->AuthInfos.pAuthMethodInfo[j].pAuthenticationInfo;
  1096. }
  1097. }
  1098. if (pRuleData->AuthInfos.pAuthMethodInfo)
  1099. {
  1100. delete [] pRuleData->AuthInfos.pAuthMethodInfo;
  1101. }
  1102. delete pRuleData;
  1103. pRuleData = NULL;
  1104. }
  1105. }
  1106. ///////////////////////////////////////////////////////////////////////
  1107. //Function: CleanUpLocalPolicyDataStructure()
  1108. //Date of Creation: 21st Aug 2001
  1109. //Parameters:
  1110. // PPOLICYDATA &pPolicyData
  1111. //Return: VOID
  1112. //Description:
  1113. // This function cleans up the local policy Structure
  1114. //Revision History:
  1115. //<Version number, Change request number, Date of modification,
  1116. // Author, Nature of change>
  1117. ///////////////////////////////////////////////////////////////////////
  1118. VOID
  1119. CleanUpLocalPolicyDataStructure(
  1120. PPOLICYDATA &pPolicyData
  1121. )
  1122. {
  1123. if(pPolicyData)
  1124. {
  1125. if (pPolicyData->pszPolicyName)
  1126. {
  1127. delete [] pPolicyData->pszPolicyName;
  1128. }
  1129. if (pPolicyData->pszNewPolicyName)
  1130. {
  1131. delete [] pPolicyData->pszNewPolicyName;
  1132. }
  1133. if (pPolicyData->pszDescription)
  1134. {
  1135. delete [] pPolicyData->pszDescription;
  1136. }
  1137. if (pPolicyData->pszGPOName)
  1138. {
  1139. delete [] pPolicyData->pszGPOName;
  1140. }
  1141. if (pPolicyData->pIpSecMMOffer)
  1142. {
  1143. delete [] pPolicyData->pIpSecMMOffer;
  1144. }
  1145. delete pPolicyData;
  1146. pPolicyData = NULL;
  1147. }
  1148. }
  1149. ///////////////////////////////////////////////////////////////////////
  1150. //Function: CleanUpLocalFilterActionDataStructure()
  1151. //Date of Creation: 21st Aug 2001
  1152. //Parameters:
  1153. // PFILTERACTION &pFilterAction
  1154. //Return: VOID
  1155. //Description:
  1156. // This function cleans up the local filteraction Structure
  1157. //Revision History:
  1158. //<Version number, Change request number, Date of modification,
  1159. // Author, Nature of change>
  1160. ///////////////////////////////////////////////////////////////////////
  1161. VOID
  1162. CleanUpLocalFilterActionDataStructure(
  1163. PFILTERACTION &pFilterAction
  1164. )
  1165. {
  1166. if(pFilterAction)
  1167. {
  1168. if(pFilterAction->pszFAName)
  1169. {
  1170. delete [] pFilterAction->pszFAName;
  1171. }
  1172. if(pFilterAction->pszNewFAName)
  1173. {
  1174. delete [] pFilterAction->pszNewFAName;
  1175. }
  1176. if(pFilterAction->pszFADescription)
  1177. {
  1178. delete [] pFilterAction->pszFADescription;
  1179. }
  1180. if(pFilterAction->pszGUIDStr)
  1181. {
  1182. delete [] pFilterAction->pszGUIDStr;
  1183. }
  1184. if(pFilterAction->pIpsecSecMethods)
  1185. {
  1186. delete [] pFilterAction->pIpsecSecMethods;
  1187. }
  1188. delete pFilterAction;
  1189. pFilterAction=NULL;
  1190. }
  1191. }
  1192. ///////////////////////////////////////////////////////////////////////
  1193. //Function: CleanUpLocalFilterDataStructure()
  1194. //Date of Creation: 21st Aug 2001
  1195. //Parameters:
  1196. // PFILTERDATA &pFilter
  1197. //Return: VOID
  1198. //Description:
  1199. // This function cleans up the local filter Structure
  1200. //Revision History:
  1201. //<Version number, Change request number, Date of modification,
  1202. // Author, Nature of change>
  1203. ///////////////////////////////////////////////////////////////////////
  1204. VOID
  1205. CleanUpLocalFilterDataStructure(
  1206. PFILTERDATA &pFilter
  1207. )
  1208. {
  1209. if(pFilter)
  1210. {
  1211. if(pFilter->pszFLName)
  1212. {
  1213. delete [] pFilter->pszFLName;
  1214. }
  1215. if(pFilter->pszDescription)
  1216. {
  1217. delete [] pFilter->pszDescription;
  1218. }
  1219. if(pFilter->SourceAddr.pszDomainName)
  1220. {
  1221. delete [] pFilter->SourceAddr.pszDomainName;
  1222. }
  1223. if(pFilter->DestnAddr.pszDomainName)
  1224. {
  1225. delete [] pFilter->DestnAddr.pszDomainName;
  1226. }
  1227. if(pFilter->SourceAddr.puIpAddr)
  1228. {
  1229. delete [] pFilter->SourceAddr.puIpAddr;
  1230. }
  1231. if(pFilter->DestnAddr.puIpAddr)
  1232. {
  1233. delete [] pFilter->DestnAddr.puIpAddr;
  1234. }
  1235. delete pFilter;
  1236. pFilter = NULL;
  1237. }
  1238. }
  1239. ///////////////////////////////////////////////////////////////////////
  1240. //Function: CleanUpLocalDelFilterDataStructure()
  1241. //Date of Creation: 21st Aug 2001
  1242. //Parameters:
  1243. // PFILTERDATA &pFilter
  1244. //Return: VOID
  1245. //Description:
  1246. // This function cleans up the local filter Structure
  1247. //Revision History:
  1248. //<Version number, Change request number, Date of modification,
  1249. // Author, Nature of change>
  1250. ///////////////////////////////////////////////////////////////////////
  1251. VOID
  1252. CleanUpLocalDelFilterDataStructure(
  1253. PDELFILTERDATA &pFilter
  1254. )
  1255. {
  1256. if(pFilter)
  1257. {
  1258. if(pFilter->pszFLName)
  1259. {
  1260. delete [] pFilter->pszFLName;
  1261. }
  1262. if(pFilter->SourceAddr.pszDomainName)
  1263. {
  1264. delete [] pFilter->SourceAddr.pszDomainName;
  1265. }
  1266. if(pFilter->DestnAddr.pszDomainName)
  1267. {
  1268. delete [] pFilter->DestnAddr.pszDomainName;
  1269. }
  1270. if(pFilter->SourceAddr.puIpAddr)
  1271. {
  1272. delete [] pFilter->SourceAddr.puIpAddr;
  1273. }
  1274. if(pFilter->DestnAddr.puIpAddr)
  1275. {
  1276. delete [] pFilter->DestnAddr.puIpAddr;
  1277. }
  1278. delete pFilter;
  1279. pFilter = NULL;
  1280. }
  1281. }
  1282. ///////////////////////////////////////////////////////////////////////
  1283. //Function: CleanUpLocalDefRuleDataStructure()
  1284. //Date of Creation: 21st Aug 2001
  1285. //Parameters:
  1286. // PDEFAULTRULE &pRuleData
  1287. //Return: VOID
  1288. //Description:
  1289. // This function cleans up the local default rule Structure
  1290. //Revision History:
  1291. //<Version number, Change request number, Date of modification,
  1292. // Author, Nature of change>
  1293. ///////////////////////////////////////////////////////////////////////
  1294. VOID
  1295. CleanUpLocalDefRuleDataStructure(
  1296. PDEFAULTRULE &pDefRuleData
  1297. )
  1298. {
  1299. if(pDefRuleData)
  1300. {
  1301. if(pDefRuleData->pszPolicyName) delete [] pDefRuleData->pszPolicyName;
  1302. for(DWORD j=0;j<pDefRuleData->AuthInfos.dwNumAuthInfos;j++)
  1303. {
  1304. if(&(pDefRuleData->AuthInfos.pAuthMethodInfo[j]) &&
  1305. pDefRuleData->AuthInfos.pAuthMethodInfo[j].pAuthenticationInfo)
  1306. {
  1307. if(pDefRuleData->AuthInfos.pAuthMethodInfo[j].pAuthenticationInfo->pAuthInfo)
  1308. {
  1309. delete pDefRuleData->AuthInfos.pAuthMethodInfo[j].pAuthenticationInfo->pAuthInfo;
  1310. pDefRuleData->AuthInfos.pAuthMethodInfo[j].pAuthenticationInfo->pAuthInfo = NULL;
  1311. }
  1312. delete pDefRuleData->AuthInfos.pAuthMethodInfo[j].pAuthenticationInfo;
  1313. pDefRuleData->AuthInfos.pAuthMethodInfo[j].pAuthenticationInfo = NULL;
  1314. }
  1315. }
  1316. if(pDefRuleData->AuthInfos.pAuthMethodInfo)
  1317. {
  1318. delete [] pDefRuleData->AuthInfos.pAuthMethodInfo;
  1319. }
  1320. if(pDefRuleData->pIpsecSecMethods)
  1321. {
  1322. delete [] pDefRuleData->pIpsecSecMethods;
  1323. }
  1324. delete pDefRuleData;
  1325. pDefRuleData = NULL;
  1326. }
  1327. }