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.

1155 lines
26 KiB

  1. ////////////////////////////////////////////////////////////////////////
  2. //
  3. // Module : Dynamic/dyanamicDelete.cpp
  4. //
  5. // Purpose : Dynamic Delete Implementation.
  6. //
  7. //
  8. // Developers Name : Bharat/Radhika
  9. //
  10. //
  11. // History :
  12. //
  13. // Date Author Comments
  14. // 9-13-2001 Radhika Initial Version. V1.0
  15. //
  16. ////////////////////////////////////////////////////////////////////////
  17. #include "nshipsec.h"
  18. extern HINSTANCE g_hModule;
  19. extern _TCHAR* g_szDynamicMachine;
  20. ///////////////////////////////////////////////////////////////////////////////////////////
  21. //
  22. //Function: DeleteMMPolicy
  23. //
  24. //Date of Creation: 9-3-2001
  25. //
  26. //Parameters: IN LPTSTR pszPolicyName
  27. //
  28. //Return: DWORD
  29. //
  30. //Description: This function deletes Mainmode Policy for the given name or
  31. // deletes all main mode policies if name is not given.
  32. //Revision History:
  33. //
  34. // Date Author Comments
  35. //
  36. //////////////////////////////////////////////////////////////////////////////////////////
  37. DWORD
  38. DeleteMMPolicy(
  39. IN LPTSTR pszPolicyName
  40. )
  41. {
  42. DWORD dwCount = 0; // counting objects here
  43. DWORD dwResumeHandle = 0;
  44. DWORD dwOldResumeHandle = 0; // handle for continuation calls
  45. DWORD dwVersion = 0;
  46. DWORD i=0, j=0;
  47. DWORD dwReturn = ERROR_SUCCESS; // assume success
  48. BOOL bNameFin = FALSE;
  49. BOOL bRemoved = FALSE;
  50. PIPSEC_MM_POLICY pIPSecMMP = NULL; // for MM policy calls
  51. for (i = 0; ;i+=dwCount)
  52. {
  53. bRemoved = FALSE;
  54. dwOldResumeHandle = dwResumeHandle;
  55. dwReturn = EnumMMPolicies(g_szDynamicMachine, dwVersion, NULL, 0, 0,
  56. &pIPSecMMP, &dwCount, &dwResumeHandle, NULL);
  57. //If there is no data Bail out.
  58. if (dwReturn == ERROR_NO_DATA || dwCount == 0)
  59. {
  60. dwReturn = ERROR_SUCCESS;
  61. BAIL_OUT;
  62. }
  63. if (dwReturn != ERROR_SUCCESS)
  64. {
  65. BAIL_OUT;
  66. }
  67. if(!(pIPSecMMP && dwCount > 0))
  68. {
  69. BAIL_OUT; // not required to continue.
  70. }
  71. // Policy name is not given, hence delete all policies
  72. if(pszPolicyName == NULL)
  73. {
  74. for (j = 0; j < dwCount; j++)
  75. {
  76. dwReturn = DeleteMMPolicy(g_szDynamicMachine, dwVersion, pIPSecMMP[j].pszPolicyName, NULL);
  77. if (dwReturn == ERROR_SUCCESS)
  78. {
  79. bRemoved = TRUE;
  80. }
  81. bNameFin = TRUE;
  82. }
  83. }
  84. // Delete policy with the given name
  85. else if(pszPolicyName)
  86. {
  87. for (j = 0; j < dwCount; j++)
  88. {
  89. if(_tcsicmp(pIPSecMMP[j].pszPolicyName,pszPolicyName) == 0)
  90. {
  91. dwReturn = DeleteMMPolicy(g_szDynamicMachine, dwVersion, pIPSecMMP[j].pszPolicyName, NULL);
  92. if (dwReturn == ERROR_SUCCESS)
  93. {
  94. bRemoved = TRUE;
  95. }
  96. bNameFin = TRUE;
  97. BAIL_OUT; // found the policy, come out from the loop
  98. }
  99. }
  100. }
  101. SPDApiBufferFree(pIPSecMMP);
  102. pIPSecMMP=NULL;
  103. if(bRemoved)
  104. {
  105. dwResumeHandle = dwOldResumeHandle; // need to restart enumeration for deleting all
  106. }
  107. if(dwReturn != ERROR_SUCCESS)
  108. {
  109. BAIL_OUT;
  110. }
  111. }
  112. error:
  113. //functionality errors are displayed here and ERROR_SUCCESS is passed to parent function.
  114. if(pszPolicyName && !bNameFin)
  115. {
  116. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_ADD_MMF_NO_MMPOLICY);
  117. dwReturn = ERROR_SUCCESS;
  118. }
  119. else if(!bNameFin)
  120. {
  121. //Error Message printed in parent function
  122. //as this is also called by delete all function
  123. //where the error message should not be displayed
  124. dwReturn = ERROR_NO_DISPLAY;
  125. }
  126. if(pIPSecMMP)
  127. {
  128. //error path clean up
  129. SPDApiBufferFree(pIPSecMMP);
  130. pIPSecMMP=NULL;
  131. }
  132. return dwReturn;
  133. }
  134. ///////////////////////////////////////////////////////////////////////////////////////////
  135. //
  136. //Function: DeleteQMPolicy
  137. //
  138. //Date of Creation: 9-3-2001
  139. //
  140. //Parameters: IN LPTSTR pszPolicyName
  141. //
  142. //Return: DWORD
  143. //
  144. //Description: This function deletes quickmode Policy for the given name
  145. // or deletes all the policies if the name is not given.
  146. //
  147. //Revision History:
  148. //
  149. // Date Author Comments
  150. //
  151. //////////////////////////////////////////////////////////////////////////////////////////
  152. DWORD
  153. DeleteQMPolicy(
  154. IN LPTSTR pszPolicyName
  155. )
  156. {
  157. DWORD dwCount = 0; // counting objects here
  158. DWORD dwResumeHandle = 0;
  159. DWORD dwOldResumeHandle = 0; // handle for continuation calls
  160. DWORD i=0, j=0;
  161. DWORD dwReturn = ERROR_SUCCESS; // assume success
  162. DWORD dwVersion = 0;
  163. BOOL bNameFin = FALSE;
  164. BOOL bRemoved = FALSE;
  165. PIPSEC_QM_POLICY pIPSecQMP = NULL; // for QM policy calls
  166. for (i = 0; ;i+=dwCount)
  167. {
  168. bRemoved = FALSE;
  169. dwOldResumeHandle = dwResumeHandle;
  170. dwReturn = EnumQMPolicies(g_szDynamicMachine, dwVersion, NULL, 0, 0,
  171. &pIPSecQMP, &dwCount, &dwResumeHandle, NULL);
  172. //If there is no data Bail out.
  173. if (dwReturn == ERROR_NO_DATA || dwCount == 0)
  174. {
  175. dwReturn = ERROR_SUCCESS;
  176. BAIL_OUT;
  177. }
  178. if (dwReturn != ERROR_SUCCESS)
  179. {
  180. BAIL_OUT;
  181. }
  182. if(!(pIPSecQMP && dwCount > 0))
  183. {
  184. BAIL_OUT; // not required to continue.
  185. }
  186. // Deletes all the policies
  187. if(pszPolicyName == NULL)
  188. {
  189. for (j = 0; j < dwCount; j++)
  190. {
  191. dwReturn = DeleteQMPolicy(g_szDynamicMachine, dwVersion, pIPSecQMP[j].pszPolicyName, NULL);
  192. if (dwReturn == ERROR_SUCCESS)
  193. {
  194. bRemoved = TRUE;
  195. }
  196. bNameFin = TRUE;
  197. }
  198. }
  199. // Deletes the policy for the given name
  200. else if(pszPolicyName)
  201. {
  202. for (j = 0; j < dwCount; j++)
  203. {
  204. if(_tcsicmp(pIPSecQMP[j].pszPolicyName,pszPolicyName) == 0)
  205. {
  206. dwReturn = DeleteQMPolicy(g_szDynamicMachine, dwVersion, pIPSecQMP[j].pszPolicyName, NULL);
  207. if (dwReturn == ERROR_SUCCESS)
  208. {
  209. bRemoved = TRUE;
  210. }
  211. bNameFin = TRUE;
  212. BAIL_OUT;
  213. }
  214. }
  215. }
  216. SPDApiBufferFree(pIPSecQMP);
  217. pIPSecQMP=NULL;
  218. if (bRemoved)
  219. {
  220. dwResumeHandle = dwOldResumeHandle; // need to restart enumeration!
  221. }
  222. if(dwReturn != ERROR_SUCCESS)
  223. {
  224. BAIL_OUT;
  225. }
  226. }
  227. error:
  228. //functionality errors are displayed here and ERROR_SUCCESS is passed to parent function.
  229. if(pszPolicyName && !bNameFin)
  230. {
  231. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_ADD_QMF_NO_QMPOLICY);
  232. dwReturn = ERROR_SUCCESS;
  233. }
  234. else if(!bNameFin)
  235. {
  236. //Error Message printed in parent function
  237. //as this is also called by delete all function
  238. //where the error message should not be displayed
  239. dwReturn = ERROR_NO_DISPLAY;
  240. }
  241. if(pIPSecQMP)
  242. {
  243. //error path clean up
  244. SPDApiBufferFree(pIPSecQMP);
  245. pIPSecQMP=NULL;
  246. }
  247. return dwReturn;
  248. }
  249. ///////////////////////////////////////////////////////////////////////////////////////////
  250. //
  251. //Function: DeleteMMFilters
  252. //
  253. //Date of Creation: 9-3-2001
  254. //
  255. //Parameters: VOID
  256. //
  257. //Return: DWORD
  258. //
  259. //Description: This function deletes all the mainmode filters and
  260. // corresponding authentication methods.
  261. //
  262. //Revision History:
  263. //
  264. // Date Author Comments
  265. //
  266. //////////////////////////////////////////////////////////////////////////////////////////
  267. DWORD
  268. DeleteMMFilters(
  269. VOID
  270. )
  271. {
  272. DWORD dwReturn = ERROR_SUCCESS;
  273. DWORD dwResumeHandle = 0;
  274. DWORD dwOldResumeHandle = 0; // handle for continuation calls
  275. DWORD dwCount = 0; // counting objects here
  276. DWORD dwMaxCount = 0; // Max objects count
  277. DWORD dwLocalCount = 0; // local total count
  278. DWORD dwVersion = 0;
  279. DWORD dwTmpCount1 = 0, dwTmpCount2 = 0;
  280. GUID gDefaultGUID = {0}; // NULL GUID value
  281. DWORD i=0, j=0;
  282. BOOL bRemoved = FALSE;
  283. PMM_FILTER pMMFilter = NULL;
  284. HANDLE hFilter = NULL;
  285. dwReturn = GetMaxCountMMFilters(dwMaxCount);
  286. if((dwReturn != ERROR_SUCCESS) || (dwMaxCount == 0))
  287. {
  288. BAIL_OUT;
  289. }
  290. for (i = 0; ;i+=dwCount)
  291. {
  292. bRemoved = FALSE;
  293. dwOldResumeHandle = dwResumeHandle;
  294. dwReturn = EnumMMFilters(g_szDynamicMachine, dwVersion, NULL, ENUM_GENERIC_FILTERS,
  295. gDefaultGUID, 0, &pMMFilter, &dwCount, &dwResumeHandle, NULL);
  296. //If there is no data Bail out.
  297. if (dwReturn == ERROR_NO_DATA || dwCount == 0)
  298. {
  299. dwReturn = ERROR_SUCCESS;
  300. BAIL_OUT;
  301. }
  302. if (dwReturn != ERROR_SUCCESS)
  303. {
  304. BAIL_OUT;
  305. }
  306. if(!(pMMFilter && dwCount > 0))
  307. {
  308. BAIL_OUT; // not required to continue.
  309. }
  310. dwReturn = GetMaxCountMMFilters(dwTmpCount1);
  311. if(dwReturn != ERROR_SUCCESS)
  312. {
  313. BAIL_OUT;
  314. }
  315. // Deletes all Main Mode filters and the corresponding authentication methods.
  316. for (j = 0; j < dwCount; j++)
  317. {
  318. dwReturn = OpenMMFilterHandle(g_szDynamicMachine, dwVersion, &(pMMFilter[j]), NULL, &hFilter);
  319. if (dwReturn != ERROR_SUCCESS)
  320. {
  321. BAIL_OUT;
  322. }
  323. dwReturn = DeleteMMFilter(hFilter);
  324. if(dwReturn == ERROR_SUCCESS)
  325. {
  326. dwReturn = DeleteMMAuthMethods(g_szDynamicMachine, dwVersion,
  327. pMMFilter[j].gMMAuthID, NULL);
  328. }
  329. else
  330. {
  331. dwReturn = CloseMMFilterHandle(hFilter);
  332. if(dwReturn != ERROR_SUCCESS)
  333. {
  334. BAIL_OUT;
  335. }
  336. }
  337. }
  338. SPDApiBufferFree(pMMFilter);
  339. pMMFilter = NULL;
  340. dwLocalCount += dwCount;
  341. if(dwLocalCount >= dwMaxCount)
  342. {
  343. break;
  344. }
  345. //
  346. //DeleteMMFilter api returns success for if try to delete Policyagent Objects,
  347. //even though those are not deleted.
  348. //This code mitigates by comparing current objects count with old objects count in SPD.
  349. //
  350. dwReturn = GetMaxCountMMFilters(dwTmpCount2);
  351. if(dwReturn != ERROR_SUCCESS)
  352. {
  353. BAIL_OUT;
  354. }
  355. if(dwTmpCount2 != dwTmpCount1)
  356. {
  357. bRemoved = TRUE;
  358. }
  359. else
  360. {
  361. bRemoved = FALSE;
  362. }
  363. if (bRemoved)
  364. {
  365. dwResumeHandle = dwOldResumeHandle; // need to restart enumeration to delete all the filters!
  366. }
  367. }
  368. dwReturn = GetMaxCountMMFilters(dwMaxCount);
  369. if(dwReturn != ERROR_SUCCESS)
  370. {
  371. BAIL_OUT;
  372. }
  373. if(dwMaxCount > 0)
  374. {
  375. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_DELETE_MMF_OBJ_NOTDEL, dwMaxCount);
  376. }
  377. error:
  378. //error path clean up
  379. if(pMMFilter)
  380. {
  381. SPDApiBufferFree(pMMFilter);
  382. pMMFilter = NULL;
  383. }
  384. return dwReturn;
  385. }
  386. ///////////////////////////////////////////////////////////////////////////////////////////
  387. //
  388. //Function: DeleteTransportFilters
  389. //
  390. //Date of Creation: 9-3-2001
  391. //
  392. //Parameters: VOID
  393. //
  394. //Return: DWORD
  395. //
  396. //Description: This function deletes all the quickmode Transport filters.
  397. //
  398. //
  399. //Revision History:
  400. //
  401. // Date Author Comments
  402. //
  403. //////////////////////////////////////////////////////////////////////////////////////////
  404. DWORD
  405. DeleteTransportFilters(
  406. VOID
  407. )
  408. {
  409. DWORD dwReturn = ERROR_SUCCESS;
  410. DWORD dwResumeHandle = 0;
  411. DWORD dwOldResumeHandle = 0; // handle for continuation calls
  412. DWORD dwCount = 0; // counting objects here
  413. DWORD dwMaxCount = 0; // Max objects count
  414. DWORD dwLocalCount = 0; // local total count
  415. GUID gDefaultGUID = {0}; // NULL GUID value
  416. DWORD i=0, j=0;
  417. DWORD dwVersion = 0;
  418. DWORD dwTmpCount1 = 0, dwTmpCount2 = 0;
  419. BOOL bRemoved = FALSE;
  420. PTRANSPORT_FILTER pTransF = NULL;
  421. HANDLE hFilter = NULL;
  422. dwReturn = GetMaxCountTransportFilters(dwMaxCount);
  423. if((dwReturn != ERROR_SUCCESS) || (dwMaxCount == 0))
  424. {
  425. BAIL_OUT;
  426. }
  427. for (i = 0; ;i+=dwCount)
  428. {
  429. bRemoved = FALSE;
  430. dwOldResumeHandle = dwResumeHandle;
  431. dwReturn = GetMaxCountTransportFilters(dwTmpCount1);
  432. if((dwReturn != ERROR_SUCCESS) || (dwTmpCount1 == 0))
  433. {
  434. BAIL_OUT;
  435. }
  436. dwReturn = EnumTransportFilters(g_szDynamicMachine, dwVersion, NULL, ENUM_GENERIC_FILTERS, gDefaultGUID, 0,
  437. &pTransF, &dwCount, &dwResumeHandle, NULL);
  438. //If there is no data Bail out.
  439. if (dwReturn == ERROR_NO_DATA || dwCount == 0)
  440. {
  441. dwReturn = ERROR_SUCCESS;
  442. BAIL_OUT;
  443. }
  444. if (dwReturn != ERROR_SUCCESS)
  445. {
  446. BAIL_OUT;
  447. }
  448. if(!(pTransF && dwCount > 0))
  449. {
  450. BAIL_OUT; // no need continue.
  451. }
  452. //GetMaxCountTransportFilters(dwTmpCount1);
  453. // Deletes all the Transport filters.
  454. for (j = 0; j < dwCount; j++)
  455. {
  456. dwReturn = OpenTransportFilterHandle(g_szDynamicMachine, dwVersion, &(pTransF[j]), NULL, &hFilter);
  457. if (dwReturn != ERROR_SUCCESS)
  458. {
  459. BAIL_OUT;
  460. }
  461. dwReturn = DeleteTransportFilter(hFilter);
  462. if (dwReturn != ERROR_SUCCESS)
  463. {
  464. dwReturn = CloseTransportFilterHandle(hFilter);
  465. if(dwReturn != ERROR_SUCCESS)
  466. {
  467. BAIL_OUT;
  468. }
  469. }
  470. }
  471. SPDApiBufferFree(pTransF);
  472. pTransF = NULL;
  473. dwLocalCount += dwCount;
  474. if(dwLocalCount >= dwMaxCount)
  475. {
  476. break;
  477. }
  478. //
  479. //DeleteTransportFilter api returns success for if try to delete Policyagent Objects,
  480. //even though those are not deleted.
  481. //This code mitigates by comparing current objects count with old objects count in SPD.
  482. //
  483. dwReturn = GetMaxCountTransportFilters(dwTmpCount2);
  484. if(dwReturn != ERROR_SUCCESS)
  485. {
  486. BAIL_OUT;
  487. }
  488. if(dwTmpCount1 != dwTmpCount2)
  489. {
  490. bRemoved = TRUE;
  491. }
  492. else
  493. {
  494. bRemoved = FALSE;
  495. }
  496. if (bRemoved)
  497. {
  498. dwResumeHandle = dwOldResumeHandle; // need to restart enumeration to delete all the filters!
  499. }
  500. }
  501. dwReturn = GetMaxCountTransportFilters(dwMaxCount);
  502. if(dwReturn != ERROR_SUCCESS)
  503. {
  504. BAIL_OUT;
  505. }
  506. if(dwMaxCount > 0)
  507. {
  508. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_DELETE_TRANSPORT_OBJ_NOTDEL, dwMaxCount);
  509. }
  510. error:
  511. if(pTransF)
  512. {
  513. //error path clean up
  514. SPDApiBufferFree(pTransF);
  515. pTransF = NULL;
  516. }
  517. return dwReturn;
  518. }
  519. ///////////////////////////////////////////////////////////////////////////////////////////
  520. //
  521. //Function: DeleteTunnelFilters
  522. //
  523. //Date of Creation: 9-3-2001
  524. //
  525. //Parameters: VOID
  526. //
  527. //Return: DWORD
  528. //
  529. //Description: This function deletes all the quickmode Tunnel filters.
  530. //
  531. //
  532. //Revision History:
  533. //
  534. // Date Author Comments
  535. //
  536. //////////////////////////////////////////////////////////////////////////////////////////
  537. DWORD
  538. DeleteTunnelFilters(
  539. VOID
  540. )
  541. {
  542. DWORD dwReturn = ERROR_SUCCESS;
  543. DWORD dwResumeHandle = 0;
  544. DWORD dwOldResumeHandle = 0; // handle for continuation calls
  545. DWORD dwCount = 0; // counting objects here
  546. DWORD dwMaxCount = 0; // Max objects count
  547. DWORD dwLocalCount = 0; // local total count
  548. DWORD dwTmpCount1 = 0, dwTmpCount2 = 0;
  549. GUID gDefaultGUID = {0}; // NULL GUID value
  550. DWORD i=0, j=0;
  551. DWORD dwVersion = 0;
  552. BOOL bRemoved = FALSE;
  553. HANDLE hFilter = NULL;
  554. PTUNNEL_FILTER pTunnelF = NULL;
  555. dwReturn = GetMaxCountTunnelFilters(dwMaxCount);
  556. if((dwReturn != ERROR_SUCCESS) || (dwMaxCount == 0))
  557. {
  558. BAIL_OUT;
  559. }
  560. for (i = 0; ;i+=dwCount)
  561. {
  562. bRemoved = FALSE;
  563. dwOldResumeHandle = dwResumeHandle;
  564. dwReturn = EnumTunnelFilters(g_szDynamicMachine, dwVersion, NULL, ENUM_GENERIC_FILTERS, gDefaultGUID, 0, &pTunnelF, &dwCount, &dwResumeHandle, NULL);
  565. //If there is no data Bail out.
  566. if (dwReturn == ERROR_NO_DATA || dwCount == 0)
  567. {
  568. dwReturn = ERROR_SUCCESS;
  569. BAIL_OUT;
  570. }
  571. if (dwReturn != ERROR_SUCCESS)
  572. {
  573. BAIL_OUT;
  574. }
  575. if(!(pTunnelF && dwCount > 0))
  576. {
  577. BAIL_OUT; // not required to continue.
  578. }
  579. dwReturn = GetMaxCountTunnelFilters(dwTmpCount1);
  580. if(dwReturn != ERROR_SUCCESS)
  581. {
  582. BAIL_OUT;
  583. }
  584. for (j = 0; j < dwCount; j++)
  585. {
  586. // Deletes all the Tunnel filters.
  587. dwReturn = OpenTunnelFilterHandle(g_szDynamicMachine, dwVersion, &(pTunnelF[j]), NULL, &hFilter);
  588. if (dwReturn != ERROR_SUCCESS)
  589. {
  590. BAIL_OUT;
  591. }
  592. dwReturn = DeleteTunnelFilter(hFilter);
  593. if (dwReturn == ERROR_SUCCESS)
  594. {
  595. }
  596. else
  597. {
  598. dwReturn = CloseTunnelFilterHandle(hFilter);
  599. if(dwReturn != ERROR_SUCCESS)
  600. {
  601. BAIL_OUT;
  602. }
  603. }
  604. }
  605. SPDApiBufferFree(pTunnelF);
  606. pTunnelF = NULL;
  607. dwLocalCount += dwCount;
  608. if(dwLocalCount >= dwMaxCount)
  609. {
  610. break;
  611. }
  612. //
  613. //DeleteTunnelFilter api returns success for if try to delete Policyagent Objects,
  614. //even though those are not deleted.
  615. //This code mitigates by comparing current objects count with old objects count in SPD.
  616. //
  617. dwReturn = GetMaxCountTunnelFilters(dwTmpCount2);
  618. if(dwReturn != ERROR_SUCCESS)
  619. {
  620. BAIL_OUT;
  621. }
  622. if(dwTmpCount2 != dwTmpCount1)
  623. {
  624. bRemoved = TRUE;
  625. }
  626. else
  627. {
  628. bRemoved = FALSE;
  629. }
  630. if (bRemoved)
  631. {
  632. dwResumeHandle = dwOldResumeHandle; // need to restart enumeration!
  633. }
  634. }
  635. dwReturn = GetMaxCountTunnelFilters(dwMaxCount);
  636. if(dwReturn != ERROR_SUCCESS)
  637. {
  638. BAIL_OUT;
  639. }
  640. if(dwMaxCount > 0)
  641. {
  642. PrintErrorMessage(IPSEC_ERR,0,ERRCODE_DELETE_TUNNEL_OBJ_NOTDEL, dwMaxCount);
  643. }
  644. error:
  645. //error path clean up
  646. if(pTunnelF)
  647. {
  648. SPDApiBufferFree(pTunnelF);
  649. pTunnelF = NULL;
  650. }
  651. return dwReturn;
  652. }
  653. ///////////////////////////////////////////////////////////////////////////////////////////
  654. //
  655. //Function: DeleteAuthMethods
  656. //
  657. //Date of Creation: 9-3-2001
  658. //
  659. //Parameters: VOID
  660. //
  661. //Return: DWORD
  662. //
  663. //Description: This function deletes all the remaining authentication methods.
  664. //
  665. //
  666. //Revision History:
  667. //
  668. // Date Author Comments
  669. //
  670. //////////////////////////////////////////////////////////////////////////////////////////
  671. DWORD
  672. DeleteAuthMethods(
  673. VOID
  674. )
  675. {
  676. DWORD dwReturn = ERROR_SUCCESS;
  677. DWORD dwAuthResumeHandle = 0;
  678. DWORD dwOldResumeHandle = 0; // handle for continuation calls
  679. DWORD dwCountAuth = 0; // counting Authentication objects here
  680. DWORD k=0, l=0;
  681. DWORD dwVersion = 0;
  682. BOOL bAuthRemoved = FALSE;
  683. PMM_AUTH_METHODS pAuthMeth = NULL;
  684. for (k = 0; ;k+=dwCountAuth)
  685. {
  686. bAuthRemoved = FALSE;
  687. dwOldResumeHandle = dwAuthResumeHandle;
  688. dwReturn = EnumMMAuthMethods(g_szDynamicMachine, dwVersion, NULL, 0, 0, &pAuthMeth, &dwCountAuth, &dwAuthResumeHandle, NULL);
  689. //If there is no data Bail out.
  690. if (dwReturn == ERROR_NO_DATA || dwCountAuth == 0)
  691. {
  692. dwReturn = ERROR_SUCCESS;
  693. BAIL_OUT;
  694. }
  695. if (dwReturn != ERROR_SUCCESS)
  696. {
  697. BAIL_OUT;
  698. }
  699. //Deletes all the auth methods. Called by delete all handle.
  700. for(l=0; l<dwCountAuth; l++)
  701. {
  702. dwReturn = DeleteMMAuthMethods(g_szDynamicMachine, dwVersion, pAuthMeth[l].gMMAuthID, NULL);
  703. if (dwReturn != ERROR_SUCCESS)
  704. {
  705. BAIL_OUT;
  706. }
  707. bAuthRemoved = TRUE;
  708. }
  709. SPDApiBufferFree(pAuthMeth);
  710. pAuthMeth = NULL;
  711. if (bAuthRemoved)
  712. {
  713. dwAuthResumeHandle = dwOldResumeHandle; // need to restart enumeration!
  714. }
  715. }
  716. error:
  717. //error path clean up
  718. if(pAuthMeth)
  719. {
  720. SPDApiBufferFree(pAuthMeth);
  721. pAuthMeth = NULL;
  722. }
  723. return dwReturn;
  724. }
  725. ///////////////////////////////////////////////////////////////////////////////////////////
  726. //
  727. //Function: DeleteMMFilterRule
  728. //
  729. //Date of Creation: 9-3-2001
  730. //
  731. //Parameters: MM_FILTER& MMFilter
  732. //
  733. //Return: DWORD
  734. //
  735. //Description: This function deletes the mmfilter for matched rule.
  736. //
  737. //
  738. //Revision History:
  739. //
  740. // Date Author Comments
  741. //
  742. //////////////////////////////////////////////////////////////////////////////////////////
  743. DWORD
  744. DeleteMMFilterRule(
  745. MM_FILTER& MMFilter
  746. )
  747. {
  748. DWORD dwReturn = ERROR_SUCCESS;
  749. DWORD dwVersion = 0;
  750. HANDLE hFilter = NULL;
  751. dwReturn = OpenMMFilterHandle(g_szDynamicMachine, dwVersion, &MMFilter, NULL, &hFilter);
  752. if (dwReturn != ERROR_SUCCESS)
  753. {
  754. BAIL_OUT;
  755. }
  756. //Delete the matched filter which is passed from the parent function
  757. dwReturn = DeleteMMFilter(hFilter);
  758. if(dwReturn != ERROR_SUCCESS)
  759. {
  760. PrintErrorMessage(WIN32_ERR, dwReturn, NULL);
  761. dwReturn = CloseMMFilterHandle(hFilter);
  762. BAIL_OUT;
  763. }
  764. dwReturn = DeleteMMAuthMethods(g_szDynamicMachine, dwVersion, MMFilter.gMMAuthID, NULL);
  765. error:
  766. return dwReturn;
  767. }
  768. ///////////////////////////////////////////////////////////////////////////////////////////
  769. //
  770. //Function: DeleteTransportRule
  771. //
  772. //Date of Creation: 9-3-2001
  773. //
  774. //Parameters: TRANSPORT_FILTER& TransportFilter
  775. //
  776. //Return: DWORD
  777. //
  778. //Description: This function deletes the Transport filter for matched rule.
  779. //
  780. //
  781. //Revision History:
  782. //
  783. // Date Author Comments
  784. //
  785. //////////////////////////////////////////////////////////////////////////////////////////
  786. DWORD
  787. DeleteTransportRule(
  788. TRANSPORT_FILTER& TransportFilter
  789. )
  790. {
  791. DWORD dwReturn = ERROR_SUCCESS;
  792. DWORD dwVersion = 0;
  793. HANDLE hFilter = NULL;
  794. dwReturn = OpenTransportFilterHandle(g_szDynamicMachine, dwVersion, &TransportFilter, NULL, &hFilter);
  795. if (dwReturn != ERROR_SUCCESS)
  796. {
  797. BAIL_OUT;
  798. }
  799. //Delete the matched filter which is passed from the parent function
  800. dwReturn = DeleteTransportFilter(hFilter);
  801. if(dwReturn != ERROR_SUCCESS)
  802. {
  803. PrintErrorMessage(WIN32_ERR, dwReturn, NULL);
  804. dwReturn = CloseTransportFilterHandle(hFilter);
  805. }
  806. error:
  807. return dwReturn;
  808. }
  809. ///////////////////////////////////////////////////////////////////////////////////////////
  810. //
  811. //Function: DeleteTunnelRule
  812. //
  813. //Date of Creation: 9-3-2001
  814. //
  815. //Parameters: TUNNEL_FILTER& TunnelFilter
  816. //
  817. //Return: DWORD
  818. //
  819. //Description: This function deletes the tunnel filter for matched rule.
  820. //
  821. //
  822. //Revision History:
  823. //
  824. // Date Author Comments
  825. //
  826. //////////////////////////////////////////////////////////////////////////////////////////
  827. DWORD
  828. DeleteTunnelRule(
  829. TUNNEL_FILTER& TunnelFilter
  830. )
  831. {
  832. DWORD dwReturn = ERROR_SUCCESS;
  833. DWORD dwVersion = 0;
  834. HANDLE hFilter = NULL;
  835. dwReturn = OpenTunnelFilterHandle(g_szDynamicMachine, dwVersion, &TunnelFilter, NULL, &hFilter);
  836. if (dwReturn != ERROR_SUCCESS)
  837. {
  838. BAIL_OUT;
  839. }
  840. //Delete the matched filter which is passed from the parent function
  841. dwReturn = DeleteTunnelFilter(hFilter);
  842. if(dwReturn != ERROR_SUCCESS)
  843. {
  844. PrintErrorMessage(WIN32_ERR, dwReturn, NULL);
  845. dwReturn = CloseTunnelFilterHandle(hFilter);
  846. }
  847. error:
  848. return dwReturn;
  849. }
  850. ///////////////////////////////////////////////////////////////////////////////////////////
  851. //
  852. //Function: GetMaxCountMMFilters
  853. //
  854. //Date of Creation: 1-31-2002
  855. //
  856. //Parameters: DWORD& dwMaxCount
  857. //
  858. //Return: DWORD
  859. //
  860. //Description: Gets the maximum MMFilters count.
  861. //
  862. //
  863. //Revision History:
  864. //
  865. // Date Author Comments
  866. //
  867. //////////////////////////////////////////////////////////////////////////////////////////
  868. DWORD
  869. GetMaxCountMMFilters(
  870. DWORD& dwMaxCount
  871. )
  872. {
  873. DWORD dwReturn = ERROR_SUCCESS;
  874. DWORD dwResumeHandle = 0;
  875. DWORD dwCount = 0; // counting objects here
  876. DWORD dwVersion = 0;
  877. GUID gDefaultGUID = {0}; // NULL GUID value
  878. DWORD i=0;
  879. PMM_FILTER pMMFilter = NULL;
  880. dwMaxCount = 0;
  881. for (i = 0; ;i+=dwCount)
  882. {
  883. dwReturn = EnumMMFilters(g_szDynamicMachine, dwVersion, NULL, ENUM_GENERIC_FILTERS,
  884. gDefaultGUID, 0, &pMMFilter, &dwCount, &dwResumeHandle, NULL);
  885. //If there is no data Bail out.
  886. if (dwReturn == ERROR_NO_DATA || dwCount == 0)
  887. {
  888. dwReturn = ERROR_SUCCESS;
  889. BAIL_OUT;
  890. }
  891. if (dwReturn != ERROR_SUCCESS)
  892. {
  893. BAIL_OUT;
  894. }
  895. if(!(pMMFilter && dwCount > 0))
  896. {
  897. BAIL_OUT; // not required to continue.
  898. }
  899. dwMaxCount += dwCount;
  900. SPDApiBufferFree(pMMFilter);
  901. pMMFilter = NULL;
  902. }
  903. error:
  904. if(pMMFilter)
  905. {
  906. SPDApiBufferFree(pMMFilter);
  907. pMMFilter = NULL;
  908. }
  909. return dwReturn;
  910. }
  911. ///////////////////////////////////////////////////////////////////////////////////////////
  912. //
  913. //Function: GetMaxCountTransportFilters
  914. //
  915. //Date of Creation: 1-31-2002
  916. //
  917. //Parameters: DWORD& dwMaxCount
  918. //
  919. //Return: DWORD
  920. //
  921. //Description: Gets the maximum TransportFilters count.
  922. //
  923. //
  924. //Revision History:
  925. //
  926. // Date Author Comments
  927. //
  928. //////////////////////////////////////////////////////////////////////////////////////////
  929. DWORD
  930. GetMaxCountTransportFilters(
  931. DWORD& dwMaxCount
  932. )
  933. {
  934. DWORD dwReturn = ERROR_SUCCESS;
  935. DWORD dwResumeHandle = 0;
  936. DWORD dwCount = 0; // counting objects here
  937. GUID gDefaultGUID = {0}; // NULL GUID value
  938. DWORD i=0;
  939. DWORD dwVersion = 0;
  940. PTRANSPORT_FILTER pTransF = NULL;
  941. dwMaxCount = 0;
  942. for (i = 0; ;i+=dwCount)
  943. {
  944. dwReturn = EnumTransportFilters(g_szDynamicMachine, dwVersion, NULL, ENUM_GENERIC_FILTERS, gDefaultGUID, 0,
  945. &pTransF, &dwCount, &dwResumeHandle, NULL);
  946. //If there is no data Bail out.
  947. if (dwReturn == ERROR_NO_DATA || dwCount == 0)
  948. {
  949. dwReturn = ERROR_SUCCESS;
  950. BAIL_OUT;
  951. }
  952. if (dwReturn != ERROR_SUCCESS)
  953. {
  954. BAIL_OUT;
  955. }
  956. if(!(pTransF && dwCount > 0))
  957. {
  958. BAIL_OUT; // no need continue.
  959. }
  960. dwMaxCount += dwCount;
  961. SPDApiBufferFree(pTransF);
  962. pTransF = NULL;
  963. }
  964. error:
  965. if(pTransF)
  966. {
  967. SPDApiBufferFree(pTransF);
  968. pTransF = NULL;
  969. }
  970. return dwReturn;
  971. }
  972. ///////////////////////////////////////////////////////////////////////////////////////////
  973. //
  974. //Function: GetMaxCountTunnelFilters
  975. //
  976. //Date of Creation: 1-31-2002
  977. //
  978. //Parameters: DWORD& dwMaxCount
  979. //
  980. //Return: DWORD
  981. //
  982. //Description: Gets the maximum TunnelFilters count.
  983. //
  984. //
  985. //Revision History:
  986. //
  987. // Date Author Comments
  988. //
  989. //////////////////////////////////////////////////////////////////////////////////////////
  990. DWORD
  991. GetMaxCountTunnelFilters(
  992. DWORD& dwMaxCount
  993. )
  994. {
  995. DWORD dwReturn = ERROR_SUCCESS;
  996. DWORD dwResumeHandle = 0;
  997. DWORD dwCount = 0; // counting objects here
  998. GUID gDefaultGUID = {0}; // NULL GUID value
  999. DWORD i=0;
  1000. DWORD dwVersion = 0;
  1001. PTUNNEL_FILTER pTunnelF = NULL;
  1002. dwMaxCount = 0;
  1003. for (i = 0; ;i+=dwCount)
  1004. {
  1005. dwReturn = EnumTunnelFilters(g_szDynamicMachine, dwVersion, NULL, ENUM_GENERIC_FILTERS, gDefaultGUID,
  1006. 0, &pTunnelF, &dwCount, &dwResumeHandle, NULL);
  1007. //If there is no data Bail out.
  1008. if (dwReturn == ERROR_NO_DATA || dwCount == 0)
  1009. {
  1010. dwReturn = ERROR_SUCCESS;
  1011. BAIL_OUT;
  1012. }
  1013. if (dwReturn != ERROR_SUCCESS)
  1014. {
  1015. BAIL_OUT;
  1016. }
  1017. if(!(pTunnelF && dwCount > 0))
  1018. {
  1019. BAIL_OUT; // not required to continue.
  1020. }
  1021. dwMaxCount += dwCount;
  1022. SPDApiBufferFree(pTunnelF);
  1023. pTunnelF = NULL;
  1024. }
  1025. error:
  1026. if(pTunnelF)
  1027. {
  1028. SPDApiBufferFree(pTunnelF);
  1029. pTunnelF = NULL;
  1030. }
  1031. return dwReturn;
  1032. }