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.

1051 lines
25 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000.
  5. //
  6. // File: refer-d.c
  7. //
  8. // Contents: Reference Management for directory.
  9. //
  10. //
  11. // History: KrishnaG
  12. // AbhishEV
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "precomp.h"
  16. DWORD
  17. DirAddNFAReferenceToPolicyObject(
  18. HLDAP hLdapBindHandle,
  19. LPWSTR pszIpsecPolicyName,
  20. LPWSTR pszIpsecNFAName
  21. )
  22. {
  23. DWORD dwError = ERROR_SUCCESS;
  24. DWORD dwNumAttributes = 1;
  25. DWORD i = 0;
  26. LDAPModW ** ppLDAPModW = NULL;
  27. LDAPModW * pLDAPModW = NULL;
  28. ppLDAPModW = (LDAPModW **) AllocPolMem(
  29. (dwNumAttributes+1) * sizeof(LDAPModW*)
  30. );
  31. if (!ppLDAPModW) {
  32. dwError = ERROR_OUTOFMEMORY;
  33. BAIL_ON_WIN32_ERROR(dwError);
  34. }
  35. pLDAPModW = (LDAPModW *) AllocPolMem(
  36. dwNumAttributes * sizeof(LDAPModW)
  37. );
  38. if (!pLDAPModW) {
  39. dwError = ERROR_OUTOFMEMORY;
  40. BAIL_ON_WIN32_ERROR(dwError);
  41. }
  42. ppLDAPModW[i] = pLDAPModW + i;
  43. dwError = AllocatePolString(
  44. L"ipsecNFAReference",
  45. &(pLDAPModW +i)->mod_type
  46. );
  47. BAIL_ON_WIN32_ERROR(dwError);
  48. dwError = AllocateLDAPStringValue(
  49. pszIpsecNFAName,
  50. (PLDAPOBJECT *)&(pLDAPModW +i)->mod_values
  51. );
  52. BAIL_ON_WIN32_ERROR(dwError);
  53. pLDAPModW[i].mod_op |= LDAP_MOD_ADD;
  54. dwError = LdapModifyS(
  55. hLdapBindHandle,
  56. pszIpsecPolicyName,
  57. ppLDAPModW
  58. );
  59. BAIL_ON_WIN32_ERROR(dwError);
  60. error:
  61. if (ppLDAPModW) {
  62. FreeLDAPModWs(
  63. ppLDAPModW
  64. );
  65. }
  66. return(dwError);
  67. }
  68. DWORD
  69. DirRemoveNFAReferenceFromPolicyObject(
  70. HLDAP hLdapBindHandle,
  71. LPWSTR pszIpsecPolicyName,
  72. LPWSTR pszIpsecNFAName
  73. )
  74. {
  75. DWORD dwError = ERROR_SUCCESS;
  76. DWORD dwNumAttributes = 1;
  77. DWORD i = 0;
  78. LDAPModW ** ppLDAPModW = NULL;
  79. LDAPModW * pLDAPModW = NULL;
  80. ppLDAPModW = (LDAPModW **) AllocPolMem(
  81. (dwNumAttributes+1) * sizeof(LDAPModW*)
  82. );
  83. if (!ppLDAPModW) {
  84. dwError = ERROR_OUTOFMEMORY;
  85. BAIL_ON_WIN32_ERROR(dwError);
  86. }
  87. pLDAPModW = (LDAPModW *) AllocPolMem(
  88. dwNumAttributes * sizeof(LDAPModW)
  89. );
  90. if (!pLDAPModW) {
  91. dwError = ERROR_OUTOFMEMORY;
  92. BAIL_ON_WIN32_ERROR(dwError);
  93. }
  94. ppLDAPModW[i] = pLDAPModW + i;
  95. dwError = AllocatePolString(
  96. L"ipsecNFAReference",
  97. &(pLDAPModW +i)->mod_type
  98. );
  99. BAIL_ON_WIN32_ERROR(dwError);
  100. dwError = AllocateLDAPStringValue(
  101. pszIpsecNFAName,
  102. (PLDAPOBJECT *)&(pLDAPModW +i)->mod_values
  103. );
  104. BAIL_ON_WIN32_ERROR(dwError);
  105. pLDAPModW[i].mod_op |= LDAP_MOD_DELETE;
  106. dwError = LdapModifyS(
  107. hLdapBindHandle,
  108. pszIpsecPolicyName,
  109. ppLDAPModW
  110. );
  111. BAIL_ON_WIN32_ERROR(dwError);
  112. error:
  113. if (ppLDAPModW) {
  114. FreeLDAPModWs(
  115. ppLDAPModW
  116. );
  117. }
  118. return(dwError);
  119. }
  120. DWORD
  121. DirAddPolicyReferenceToNFAObject(
  122. HLDAP hLdapBindHandle,
  123. LPWSTR pszIpsecNFAName,
  124. LPWSTR pszIpsecPolicyName
  125. )
  126. {
  127. DWORD dwError = ERROR_SUCCESS;
  128. DWORD dwNumAttributes = 1;
  129. DWORD i = 0;
  130. LDAPModW ** ppLDAPModW = NULL;
  131. LDAPModW * pLDAPModW = NULL;
  132. ppLDAPModW = (LDAPModW **) AllocPolMem(
  133. (dwNumAttributes+1) * sizeof(LDAPModW*)
  134. );
  135. if (!ppLDAPModW) {
  136. dwError = ERROR_OUTOFMEMORY;
  137. BAIL_ON_WIN32_ERROR(dwError);
  138. }
  139. pLDAPModW = (LDAPModW *) AllocPolMem(
  140. dwNumAttributes * sizeof(LDAPModW)
  141. );
  142. if (!pLDAPModW) {
  143. dwError = ERROR_OUTOFMEMORY;
  144. BAIL_ON_WIN32_ERROR(dwError);
  145. }
  146. ppLDAPModW[i] = pLDAPModW + i;
  147. dwError = AllocatePolString(
  148. L"ipsecOwnersReference",
  149. &(pLDAPModW +i)->mod_type
  150. );
  151. BAIL_ON_WIN32_ERROR(dwError);
  152. dwError = AllocateLDAPStringValue(
  153. pszIpsecPolicyName,
  154. (PLDAPOBJECT *)&(pLDAPModW +i)->mod_values
  155. );
  156. BAIL_ON_WIN32_ERROR(dwError);
  157. pLDAPModW[i].mod_op |= LDAP_MOD_ADD;
  158. dwError = LdapModifyS(
  159. hLdapBindHandle,
  160. pszIpsecNFAName,
  161. ppLDAPModW
  162. );
  163. BAIL_ON_WIN32_ERROR(dwError);
  164. error:
  165. if (ppLDAPModW) {
  166. FreeLDAPModWs(
  167. ppLDAPModW
  168. );
  169. }
  170. return(dwError);
  171. }
  172. DWORD
  173. DirAddNegPolReferenceToNFAObject(
  174. HLDAP hLdapBindHandle,
  175. LPWSTR pszIpsecNFAName,
  176. LPWSTR pszIpsecNegPolName
  177. )
  178. {
  179. DWORD dwError = ERROR_SUCCESS;
  180. DWORD dwNumAttributes = 1;
  181. DWORD i = 0;
  182. LDAPModW ** ppLDAPModW = NULL;
  183. LDAPModW * pLDAPModW = NULL;
  184. ppLDAPModW = (LDAPModW **) AllocPolMem(
  185. (dwNumAttributes+1) * sizeof(LDAPModW*)
  186. );
  187. if (!ppLDAPModW) {
  188. dwError = ERROR_OUTOFMEMORY;
  189. BAIL_ON_WIN32_ERROR(dwError);
  190. }
  191. pLDAPModW = (LDAPModW *) AllocPolMem(
  192. dwNumAttributes * sizeof(LDAPModW)
  193. );
  194. if (!pLDAPModW) {
  195. dwError = ERROR_OUTOFMEMORY;
  196. BAIL_ON_WIN32_ERROR(dwError);
  197. }
  198. ppLDAPModW[i] = pLDAPModW + i;
  199. dwError = AllocatePolString(
  200. L"ipsecNegotiationPolicyReference",
  201. &(pLDAPModW +i)->mod_type
  202. );
  203. BAIL_ON_WIN32_ERROR(dwError);
  204. dwError = AllocateLDAPStringValue(
  205. pszIpsecNegPolName,
  206. (PLDAPOBJECT *)&(pLDAPModW +i)->mod_values
  207. );
  208. BAIL_ON_WIN32_ERROR(dwError);
  209. pLDAPModW[i].mod_op |= LDAP_MOD_REPLACE;
  210. dwError = LdapModifyS(
  211. hLdapBindHandle,
  212. pszIpsecNFAName,
  213. ppLDAPModW
  214. );
  215. BAIL_ON_WIN32_ERROR(dwError);
  216. error:
  217. if (ppLDAPModW) {
  218. FreeLDAPModWs(
  219. ppLDAPModW
  220. );
  221. }
  222. return(dwError);
  223. }
  224. DWORD
  225. DirUpdateNegPolReferenceInNFAObject(
  226. HLDAP hLdapBindHandle,
  227. LPWSTR pszIpsecNFAName,
  228. LPWSTR pszOldIpsecNegPolName,
  229. LPWSTR pszNewIpsecNegPolName
  230. )
  231. {
  232. DWORD dwError = ERROR_SUCCESS;
  233. DWORD dwNumAttributes = 1;
  234. DWORD i = 0;
  235. LDAPModW ** ppLDAPModW = NULL;
  236. LDAPModW * pLDAPModW = NULL;
  237. ppLDAPModW = (LDAPModW **) AllocPolMem(
  238. (dwNumAttributes+1) * sizeof(LDAPModW*)
  239. );
  240. if (!ppLDAPModW) {
  241. dwError = ERROR_OUTOFMEMORY;
  242. BAIL_ON_WIN32_ERROR(dwError);
  243. }
  244. pLDAPModW = (LDAPModW *) AllocPolMem(
  245. dwNumAttributes * sizeof(LDAPModW)
  246. );
  247. if (!pLDAPModW) {
  248. dwError = ERROR_OUTOFMEMORY;
  249. BAIL_ON_WIN32_ERROR(dwError);
  250. }
  251. ppLDAPModW[i] = pLDAPModW + i;
  252. dwError = AllocatePolString(
  253. L"ipsecNegotiationPolicyReference",
  254. &(pLDAPModW +i)->mod_type
  255. );
  256. BAIL_ON_WIN32_ERROR(dwError);
  257. dwError = AllocateLDAPStringValue(
  258. pszNewIpsecNegPolName,
  259. (PLDAPOBJECT *)&(pLDAPModW +i)->mod_values
  260. );
  261. BAIL_ON_WIN32_ERROR(dwError);
  262. pLDAPModW[i].mod_op |= LDAP_MOD_REPLACE;
  263. dwError = LdapModifyS(
  264. hLdapBindHandle,
  265. pszIpsecNFAName,
  266. ppLDAPModW
  267. );
  268. BAIL_ON_WIN32_ERROR(dwError);
  269. error:
  270. if (ppLDAPModW) {
  271. FreeLDAPModWs(
  272. ppLDAPModW
  273. );
  274. }
  275. return(dwError);
  276. }
  277. DWORD
  278. DirAddFilterReferenceToNFAObject(
  279. HLDAP hLdapBindHandle,
  280. LPWSTR pszIpsecNFAName,
  281. LPWSTR pszIpsecFilterName
  282. )
  283. {
  284. DWORD dwError = ERROR_SUCCESS;
  285. DWORD dwNumAttributes = 1;
  286. DWORD i = 0;
  287. LDAPModW ** ppLDAPModW = NULL;
  288. LDAPModW * pLDAPModW = NULL;
  289. ppLDAPModW = (LDAPModW **) AllocPolMem(
  290. (dwNumAttributes+1) * sizeof(LDAPModW*)
  291. );
  292. if (!ppLDAPModW) {
  293. dwError = ERROR_OUTOFMEMORY;
  294. BAIL_ON_WIN32_ERROR(dwError);
  295. }
  296. pLDAPModW = (LDAPModW *) AllocPolMem(
  297. dwNumAttributes * sizeof(LDAPModW)
  298. );
  299. if (!pLDAPModW) {
  300. dwError = ERROR_OUTOFMEMORY;
  301. BAIL_ON_WIN32_ERROR(dwError);
  302. }
  303. ppLDAPModW[i] = pLDAPModW + i;
  304. dwError = AllocatePolString(
  305. L"ipsecFilterReference",
  306. &(pLDAPModW +i)->mod_type
  307. );
  308. BAIL_ON_WIN32_ERROR(dwError);
  309. dwError = AllocateLDAPStringValue(
  310. pszIpsecFilterName,
  311. (PLDAPOBJECT *)&(pLDAPModW +i)->mod_values
  312. );
  313. BAIL_ON_WIN32_ERROR(dwError);
  314. pLDAPModW[i].mod_op |= LDAP_MOD_REPLACE;
  315. dwError = LdapModifyS(
  316. hLdapBindHandle,
  317. pszIpsecNFAName,
  318. ppLDAPModW
  319. );
  320. BAIL_ON_WIN32_ERROR(dwError);
  321. error:
  322. if (ppLDAPModW) {
  323. FreeLDAPModWs(
  324. ppLDAPModW
  325. );
  326. }
  327. return(dwError);
  328. }
  329. DWORD
  330. DirUpdateFilterReferenceInNFAObject(
  331. HLDAP hLdapBindHandle,
  332. LPWSTR pszIpsecNFAName,
  333. LPWSTR pszOldIpsecFilterName,
  334. LPWSTR pszNewIpsecFilterName
  335. )
  336. {
  337. DWORD dwError = ERROR_SUCCESS;
  338. DWORD dwNumAttributes = 1;
  339. DWORD i = 0;
  340. LDAPModW ** ppLDAPModW = NULL;
  341. LDAPModW * pLDAPModW = NULL;
  342. ppLDAPModW = (LDAPModW **) AllocPolMem(
  343. (dwNumAttributes+1) * sizeof(LDAPModW*)
  344. );
  345. if (!ppLDAPModW) {
  346. dwError = ERROR_OUTOFMEMORY;
  347. BAIL_ON_WIN32_ERROR(dwError);
  348. }
  349. pLDAPModW = (LDAPModW *) AllocPolMem(
  350. dwNumAttributes * sizeof(LDAPModW)
  351. );
  352. if (!pLDAPModW) {
  353. dwError = ERROR_OUTOFMEMORY;
  354. BAIL_ON_WIN32_ERROR(dwError);
  355. }
  356. ppLDAPModW[i] = pLDAPModW + i;
  357. dwError = AllocatePolString(
  358. L"ipsecFilterReference",
  359. &(pLDAPModW +i)->mod_type
  360. );
  361. BAIL_ON_WIN32_ERROR(dwError);
  362. dwError = AllocateLDAPStringValue(
  363. pszNewIpsecFilterName,
  364. (PLDAPOBJECT *)&(pLDAPModW +i)->mod_values
  365. );
  366. BAIL_ON_WIN32_ERROR(dwError);
  367. pLDAPModW[i].mod_op |= LDAP_MOD_REPLACE;
  368. dwError = LdapModifyS(
  369. hLdapBindHandle,
  370. pszIpsecNFAName,
  371. ppLDAPModW
  372. );
  373. BAIL_ON_WIN32_ERROR(dwError);
  374. error:
  375. if (ppLDAPModW) {
  376. FreeLDAPModWs(
  377. ppLDAPModW
  378. );
  379. }
  380. return(dwError);
  381. }
  382. DWORD
  383. DirAddNFAReferenceToFilterObject(
  384. HLDAP hLdapBindHandle,
  385. LPWSTR pszIpsecFilterName,
  386. LPWSTR pszIpsecNFAName
  387. )
  388. {
  389. DWORD dwError = ERROR_SUCCESS;
  390. DWORD dwNumAttributes = 1;
  391. DWORD i = 0;
  392. LDAPModW ** ppLDAPModW = NULL;
  393. LDAPModW * pLDAPModW = NULL;
  394. ppLDAPModW = (LDAPModW **) AllocPolMem(
  395. (dwNumAttributes+1) * sizeof(LDAPModW*)
  396. );
  397. if (!ppLDAPModW) {
  398. dwError = ERROR_OUTOFMEMORY;
  399. BAIL_ON_WIN32_ERROR(dwError);
  400. }
  401. pLDAPModW = (LDAPModW *) AllocPolMem(
  402. dwNumAttributes * sizeof(LDAPModW)
  403. );
  404. if (!pLDAPModW) {
  405. dwError = ERROR_OUTOFMEMORY;
  406. BAIL_ON_WIN32_ERROR(dwError);
  407. }
  408. ppLDAPModW[i] = pLDAPModW + i;
  409. dwError = AllocatePolString(
  410. L"ipsecOwnersReference",
  411. &(pLDAPModW +i)->mod_type
  412. );
  413. BAIL_ON_WIN32_ERROR(dwError);
  414. dwError = AllocateLDAPStringValue(
  415. pszIpsecNFAName,
  416. (PLDAPOBJECT *)&(pLDAPModW +i)->mod_values
  417. );
  418. BAIL_ON_WIN32_ERROR(dwError);
  419. pLDAPModW[i].mod_op |= LDAP_MOD_ADD;
  420. dwError = LdapModifyS(
  421. hLdapBindHandle,
  422. pszIpsecFilterName,
  423. ppLDAPModW
  424. );
  425. BAIL_ON_WIN32_ERROR(dwError);
  426. error:
  427. if (ppLDAPModW) {
  428. FreeLDAPModWs(
  429. ppLDAPModW
  430. );
  431. }
  432. return(dwError);
  433. }
  434. DWORD
  435. DirDeleteNFAReferenceInFilterObject(
  436. HLDAP hLdapBindHandle,
  437. LPWSTR pszIpsecFilterName,
  438. LPWSTR pszIpsecNFAName
  439. )
  440. {
  441. DWORD dwError = ERROR_SUCCESS;
  442. DWORD dwNumAttributes = 1;
  443. DWORD i = 0;
  444. LDAPModW ** ppLDAPModW = NULL;
  445. LDAPModW * pLDAPModW = NULL;
  446. ppLDAPModW = (LDAPModW **) AllocPolMem(
  447. (dwNumAttributes+1) * sizeof(LDAPModW*)
  448. );
  449. if (!ppLDAPModW) {
  450. dwError = ERROR_OUTOFMEMORY;
  451. BAIL_ON_WIN32_ERROR(dwError);
  452. }
  453. pLDAPModW = (LDAPModW *) AllocPolMem(
  454. dwNumAttributes * sizeof(LDAPModW)
  455. );
  456. if (!pLDAPModW) {
  457. dwError = ERROR_OUTOFMEMORY;
  458. BAIL_ON_WIN32_ERROR(dwError);
  459. }
  460. ppLDAPModW[i] = pLDAPModW + i;
  461. dwError = AllocatePolString(
  462. L"ipsecOwnersReference",
  463. &(pLDAPModW +i)->mod_type
  464. );
  465. BAIL_ON_WIN32_ERROR(dwError);
  466. dwError = AllocateLDAPStringValue(
  467. pszIpsecNFAName,
  468. (PLDAPOBJECT *)&(pLDAPModW +i)->mod_values
  469. );
  470. BAIL_ON_WIN32_ERROR(dwError);
  471. pLDAPModW[i].mod_op |= LDAP_MOD_DELETE;
  472. dwError = LdapModifyS(
  473. hLdapBindHandle,
  474. pszIpsecFilterName,
  475. ppLDAPModW
  476. );
  477. BAIL_ON_WIN32_ERROR(dwError);
  478. error:
  479. if (ppLDAPModW) {
  480. FreeLDAPModWs(
  481. ppLDAPModW
  482. );
  483. }
  484. return(dwError);
  485. }
  486. DWORD
  487. DirAddNFAReferenceToNegPolObject(
  488. HLDAP hLdapBindHandle,
  489. LPWSTR pszIpsecNegPolName,
  490. LPWSTR pszIpsecNFAName
  491. )
  492. {
  493. DWORD dwError = ERROR_SUCCESS;
  494. DWORD dwNumAttributes = 1;
  495. DWORD i = 0;
  496. LDAPModW ** ppLDAPModW = NULL;
  497. LDAPModW * pLDAPModW = NULL;
  498. ppLDAPModW = (LDAPModW **) AllocPolMem(
  499. (dwNumAttributes+1) * sizeof(LDAPModW*)
  500. );
  501. if (!ppLDAPModW) {
  502. dwError = ERROR_OUTOFMEMORY;
  503. BAIL_ON_WIN32_ERROR(dwError);
  504. }
  505. pLDAPModW = (LDAPModW *) AllocPolMem(
  506. dwNumAttributes * sizeof(LDAPModW)
  507. );
  508. if (!pLDAPModW) {
  509. dwError = ERROR_OUTOFMEMORY;
  510. BAIL_ON_WIN32_ERROR(dwError);
  511. }
  512. ppLDAPModW[i] = pLDAPModW + i;
  513. dwError = AllocatePolString(
  514. L"ipsecOwnersReference",
  515. &(pLDAPModW +i)->mod_type
  516. );
  517. BAIL_ON_WIN32_ERROR(dwError);
  518. dwError = AllocateLDAPStringValue(
  519. pszIpsecNFAName,
  520. (PLDAPOBJECT *)&(pLDAPModW +i)->mod_values
  521. );
  522. BAIL_ON_WIN32_ERROR(dwError);
  523. pLDAPModW[i].mod_op |= LDAP_MOD_ADD;
  524. dwError = LdapModifyS(
  525. hLdapBindHandle,
  526. pszIpsecNegPolName,
  527. ppLDAPModW
  528. );
  529. BAIL_ON_WIN32_ERROR(dwError);
  530. error:
  531. if (ppLDAPModW) {
  532. FreeLDAPModWs(
  533. ppLDAPModW
  534. );
  535. }
  536. return(dwError);
  537. }
  538. DWORD
  539. DirDeleteNFAReferenceInNegPolObject(
  540. HLDAP hLdapBindHandle,
  541. LPWSTR pszIpsecNegPolName,
  542. LPWSTR pszIpsecNFAName
  543. )
  544. {
  545. DWORD dwError = ERROR_SUCCESS;
  546. DWORD dwNumAttributes = 1;
  547. DWORD i = 0;
  548. LDAPModW ** ppLDAPModW = NULL;
  549. LDAPModW * pLDAPModW = NULL;
  550. ppLDAPModW = (LDAPModW **) AllocPolMem(
  551. (dwNumAttributes+1) * sizeof(LDAPModW*)
  552. );
  553. if (!ppLDAPModW) {
  554. dwError = ERROR_OUTOFMEMORY;
  555. BAIL_ON_WIN32_ERROR(dwError);
  556. }
  557. pLDAPModW = (LDAPModW *) AllocPolMem(
  558. dwNumAttributes * sizeof(LDAPModW)
  559. );
  560. if (!pLDAPModW) {
  561. dwError = ERROR_OUTOFMEMORY;
  562. BAIL_ON_WIN32_ERROR(dwError);
  563. }
  564. ppLDAPModW[i] = pLDAPModW + i;
  565. dwError = AllocatePolString(
  566. L"ipsecOwnersReference",
  567. &(pLDAPModW +i)->mod_type
  568. );
  569. BAIL_ON_WIN32_ERROR(dwError);
  570. dwError = AllocateLDAPStringValue(
  571. pszIpsecNFAName,
  572. (PLDAPOBJECT *)&(pLDAPModW +i)->mod_values
  573. );
  574. BAIL_ON_WIN32_ERROR(dwError);
  575. pLDAPModW[i].mod_op |= LDAP_MOD_DELETE;
  576. dwError = LdapModifyS(
  577. hLdapBindHandle,
  578. pszIpsecNegPolName,
  579. ppLDAPModW
  580. );
  581. BAIL_ON_WIN32_ERROR(dwError);
  582. error:
  583. if (ppLDAPModW) {
  584. FreeLDAPModWs(
  585. ppLDAPModW
  586. );
  587. }
  588. return(dwError);
  589. }
  590. DWORD
  591. DirAddPolicyReferenceToISAKMPObject(
  592. HLDAP hLdapBindHandle,
  593. LPWSTR pszIpsecISAKMPName,
  594. LPWSTR pszIpsecPolicyName
  595. )
  596. {
  597. DWORD dwError = ERROR_SUCCESS;
  598. DWORD dwNumAttributes = 1;
  599. DWORD i = 0;
  600. LDAPModW ** ppLDAPModW = NULL;
  601. LDAPModW * pLDAPModW = NULL;
  602. ppLDAPModW = (LDAPModW **) AllocPolMem(
  603. (dwNumAttributes+1)*sizeof(LDAPModW*)
  604. );
  605. if (!ppLDAPModW) {
  606. dwError = ERROR_OUTOFMEMORY;
  607. BAIL_ON_WIN32_ERROR(dwError);
  608. }
  609. pLDAPModW = (LDAPModW *) AllocPolMem(
  610. dwNumAttributes*sizeof(LDAPModW)
  611. );
  612. if (!pLDAPModW) {
  613. dwError = ERROR_OUTOFMEMORY;
  614. BAIL_ON_WIN32_ERROR(dwError);
  615. }
  616. ppLDAPModW[i] = pLDAPModW + i;
  617. dwError = AllocatePolString(
  618. L"ipsecOwnersReference",
  619. &(pLDAPModW +i)->mod_type
  620. );
  621. BAIL_ON_WIN32_ERROR(dwError);
  622. dwError = AllocateLDAPStringValue(
  623. pszIpsecPolicyName,
  624. (PLDAPOBJECT *)&(pLDAPModW +i)->mod_values
  625. );
  626. BAIL_ON_WIN32_ERROR(dwError);
  627. pLDAPModW[i].mod_op |= LDAP_MOD_ADD;
  628. dwError = LdapModifyS(
  629. hLdapBindHandle,
  630. pszIpsecISAKMPName,
  631. ppLDAPModW
  632. );
  633. BAIL_ON_WIN32_ERROR(dwError);
  634. error:
  635. if (ppLDAPModW) {
  636. FreeLDAPModWs(
  637. ppLDAPModW
  638. );
  639. }
  640. return(dwError);
  641. }
  642. DWORD
  643. DirAddISAKMPReferenceToPolicyObject(
  644. HLDAP hLdapBindHandle,
  645. LPWSTR pszIpsecPolicyName,
  646. LPWSTR pszIpsecISAKMPName
  647. )
  648. {
  649. DWORD dwError = ERROR_SUCCESS;
  650. DWORD dwNumAttributes = 1;
  651. DWORD i = 0;
  652. LDAPModW ** ppLDAPModW = NULL;
  653. LDAPModW * pLDAPModW = NULL;
  654. ppLDAPModW = (LDAPModW **) AllocPolMem(
  655. (dwNumAttributes+1)*sizeof(LDAPModW*)
  656. );
  657. if (!ppLDAPModW) {
  658. dwError = ERROR_OUTOFMEMORY;
  659. BAIL_ON_WIN32_ERROR(dwError);
  660. }
  661. pLDAPModW = (LDAPModW *) AllocPolMem(
  662. dwNumAttributes*sizeof(LDAPModW)
  663. );
  664. if (!pLDAPModW) {
  665. dwError = ERROR_OUTOFMEMORY;
  666. BAIL_ON_WIN32_ERROR(dwError);
  667. }
  668. ppLDAPModW[i] = pLDAPModW + i;
  669. dwError = AllocatePolString(
  670. L"ipsecISAKMPReference",
  671. &(pLDAPModW +i)->mod_type
  672. );
  673. BAIL_ON_WIN32_ERROR(dwError);
  674. dwError = AllocateLDAPStringValue(
  675. pszIpsecISAKMPName,
  676. (PLDAPOBJECT *)&(pLDAPModW +i)->mod_values
  677. );
  678. BAIL_ON_WIN32_ERROR(dwError);
  679. pLDAPModW[i].mod_op |= LDAP_MOD_REPLACE;
  680. dwError = LdapModifyS(
  681. hLdapBindHandle,
  682. pszIpsecPolicyName,
  683. ppLDAPModW
  684. );
  685. BAIL_ON_WIN32_ERROR(dwError);
  686. error:
  687. if (ppLDAPModW) {
  688. FreeLDAPModWs(
  689. ppLDAPModW
  690. );
  691. }
  692. return(dwError);
  693. }
  694. DWORD
  695. DirRemovePolicyReferenceFromISAKMPObject(
  696. HLDAP hLdapBindHandle,
  697. LPWSTR pszIpsecISAKMPName,
  698. LPWSTR pszIpsecPolicyName
  699. )
  700. {
  701. DWORD dwError = 0;
  702. DWORD dwNumAttributes = 1;
  703. DWORD i = 0;
  704. LDAPModW ** ppLDAPModW = NULL;
  705. LDAPModW * pLDAPModW = NULL;
  706. ppLDAPModW = (LDAPModW **) AllocPolMem(
  707. (dwNumAttributes+1) * sizeof(LDAPModW*)
  708. );
  709. if (!ppLDAPModW) {
  710. dwError = ERROR_OUTOFMEMORY;
  711. BAIL_ON_WIN32_ERROR(dwError);
  712. }
  713. pLDAPModW = (LDAPModW *) AllocPolMem(
  714. dwNumAttributes * sizeof(LDAPModW)
  715. );
  716. if (!pLDAPModW) {
  717. dwError = ERROR_OUTOFMEMORY;
  718. BAIL_ON_WIN32_ERROR(dwError);
  719. }
  720. ppLDAPModW[i] = pLDAPModW + i;
  721. dwError = AllocatePolString(
  722. L"ipsecOwnersReference",
  723. &(pLDAPModW +i)->mod_type
  724. );
  725. BAIL_ON_WIN32_ERROR(dwError);
  726. dwError = AllocateLDAPStringValue(
  727. pszIpsecPolicyName,
  728. (PLDAPOBJECT *)&(pLDAPModW +i)->mod_values
  729. );
  730. BAIL_ON_WIN32_ERROR(dwError);
  731. pLDAPModW[i].mod_op |= LDAP_MOD_DELETE;
  732. dwError = LdapModifyS(
  733. hLdapBindHandle,
  734. pszIpsecISAKMPName,
  735. ppLDAPModW
  736. );
  737. //
  738. // ipsecOwnersReference may be empty for ISAKMP object.
  739. //
  740. if (dwError == ERROR_DS_NO_ATTRIBUTE_OR_VALUE) {
  741. dwError = 0;
  742. }
  743. BAIL_ON_WIN32_ERROR(dwError);
  744. error:
  745. if (ppLDAPModW) {
  746. FreeLDAPModWs(
  747. ppLDAPModW
  748. );
  749. }
  750. return(dwError);
  751. }
  752. DWORD
  753. DirUpdateISAKMPReferenceInPolicyObject(
  754. HLDAP hLdapBindHandle,
  755. LPWSTR pszIpsecPolicyName,
  756. LPWSTR pszOldIpsecISAKMPName,
  757. LPWSTR pszNewIpsecISAKMPName
  758. )
  759. {
  760. DWORD dwError = 0;
  761. DWORD dwNumAttributes = 1;
  762. DWORD i = 0;
  763. LDAPModW ** ppLDAPModW = NULL;
  764. LDAPModW * pLDAPModW = NULL;
  765. ppLDAPModW = (LDAPModW **) AllocPolMem(
  766. (dwNumAttributes+1) * sizeof(LDAPModW*)
  767. );
  768. if (!ppLDAPModW) {
  769. dwError = ERROR_OUTOFMEMORY;
  770. BAIL_ON_WIN32_ERROR(dwError);
  771. }
  772. pLDAPModW = (LDAPModW *) AllocPolMem(
  773. dwNumAttributes * sizeof(LDAPModW)
  774. );
  775. if (!pLDAPModW) {
  776. dwError = ERROR_OUTOFMEMORY;
  777. BAIL_ON_WIN32_ERROR(dwError);
  778. }
  779. ppLDAPModW[i] = pLDAPModW + i;
  780. dwError = AllocatePolString(
  781. L"ipsecISAKMPReference",
  782. &(pLDAPModW +i)->mod_type
  783. );
  784. BAIL_ON_WIN32_ERROR(dwError);
  785. dwError = AllocateLDAPStringValue(
  786. pszNewIpsecISAKMPName,
  787. (PLDAPOBJECT *)&(pLDAPModW +i)->mod_values
  788. );
  789. BAIL_ON_WIN32_ERROR(dwError);
  790. pLDAPModW[i].mod_op |= LDAP_MOD_REPLACE;
  791. dwError = LdapModifyS(
  792. hLdapBindHandle,
  793. pszIpsecPolicyName,
  794. ppLDAPModW
  795. );
  796. BAIL_ON_WIN32_ERROR(dwError);
  797. error:
  798. if (ppLDAPModW) {
  799. FreeLDAPModWs(
  800. ppLDAPModW
  801. );
  802. }
  803. return(dwError);
  804. }
  805. DWORD
  806. DirRemoveFilterReferenceInNFAObject(
  807. HLDAP hLdapBindHandle,
  808. LPWSTR pszIpsecNFAName
  809. )
  810. {
  811. DWORD dwError = ERROR_SUCCESS;
  812. DWORD dwNumAttributes = 1;
  813. DWORD i = 0;
  814. LDAPModW ** ppLDAPModW = NULL;
  815. LDAPModW * pLDAPModW = NULL;
  816. ppLDAPModW = (LDAPModW **) AllocPolMem(
  817. (dwNumAttributes+1) * sizeof(LDAPModW*)
  818. );
  819. if (!ppLDAPModW) {
  820. dwError = ERROR_OUTOFMEMORY;
  821. BAIL_ON_WIN32_ERROR(dwError);
  822. }
  823. pLDAPModW = (LDAPModW *) AllocPolMem(
  824. dwNumAttributes * sizeof(LDAPModW)
  825. );
  826. if (!pLDAPModW) {
  827. dwError = ERROR_OUTOFMEMORY;
  828. BAIL_ON_WIN32_ERROR(dwError);
  829. }
  830. ppLDAPModW[i] = pLDAPModW + i;
  831. dwError = AllocatePolString(
  832. L"ipsecFilterReference",
  833. &(pLDAPModW +i)->mod_type
  834. );
  835. BAIL_ON_WIN32_ERROR(dwError);
  836. (pLDAPModW +i)->mod_values = NULL;
  837. pLDAPModW[i].mod_op |= LDAP_MOD_DELETE;
  838. dwError = LdapModifyS(
  839. hLdapBindHandle,
  840. pszIpsecNFAName,
  841. ppLDAPModW
  842. );
  843. if (dwError == ERROR_DS_NO_ATTRIBUTE_OR_VALUE) {
  844. dwError = 0;
  845. }
  846. BAIL_ON_WIN32_ERROR(dwError);
  847. error:
  848. if (ppLDAPModW) {
  849. FreeLDAPModWs(
  850. ppLDAPModW
  851. );
  852. }
  853. return(dwError);
  854. }