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.

689 lines
16 KiB

  1. #include "precomp.h"
  2. DWORD
  3. DirBackPropIncChangesForISAKMPToPolicy(
  4. HLDAP hLdapBindHandle,
  5. LPWSTR pszIpsecRootContainer,
  6. GUID ISAKMPIdentifier
  7. )
  8. {
  9. DWORD dwError = 0;
  10. LPWSTR * ppszIpsecPolicyReferences = NULL;
  11. DWORD dwNumReferences = 0;
  12. DWORD i = 0;
  13. LPWSTR pszIpsecPolicyReference = NULL;
  14. dwError = DirGetPolicyReferencesForISAKMP(
  15. hLdapBindHandle,
  16. pszIpsecRootContainer,
  17. ISAKMPIdentifier,
  18. &ppszIpsecPolicyReferences,
  19. &dwNumReferences
  20. );
  21. for (i = 0; i < dwNumReferences; i++) {
  22. pszIpsecPolicyReference = *(ppszIpsecPolicyReferences + i);
  23. dwError = DirUpdatePolicy(
  24. hLdapBindHandle,
  25. pszIpsecRootContainer,
  26. pszIpsecPolicyReference,
  27. 0x200
  28. );
  29. BAIL_ON_WIN32_ERROR(dwError);
  30. dwError = DirUpdatePolicy(
  31. hLdapBindHandle,
  32. pszIpsecRootContainer,
  33. pszIpsecPolicyReference,
  34. 0x100
  35. );
  36. BAIL_ON_WIN32_ERROR(dwError);
  37. }
  38. dwError = ERROR_SUCCESS;
  39. error:
  40. if (ppszIpsecPolicyReferences) {
  41. FreeNFAReferences(
  42. ppszIpsecPolicyReferences,
  43. dwNumReferences
  44. );
  45. }
  46. return (dwError);
  47. }
  48. DWORD
  49. DirBackPropIncChangesForFilterToNFA(
  50. HLDAP hLdapBindHandle,
  51. LPWSTR pszIpsecRootContainer,
  52. GUID FilterIdentifier
  53. )
  54. {
  55. DWORD dwError = 0;
  56. LPWSTR * ppszIpsecNFAReferences = NULL;
  57. DWORD dwNumReferences = 0;
  58. DWORD i = 0;
  59. LPWSTR pszIpsecNFAReference = NULL;
  60. dwError = DirGetNFAReferencesForFilter(
  61. hLdapBindHandle,
  62. pszIpsecRootContainer,
  63. FilterIdentifier,
  64. &ppszIpsecNFAReferences,
  65. &dwNumReferences
  66. );
  67. for (i = 0; i < dwNumReferences; i++) {
  68. pszIpsecNFAReference = *(ppszIpsecNFAReferences + i);
  69. dwError = DirUpdateNFA(
  70. hLdapBindHandle,
  71. pszIpsecRootContainer,
  72. pszIpsecNFAReference,
  73. 0x200
  74. );
  75. if (dwError) {
  76. continue;
  77. }
  78. dwError = DirUpdateNFA(
  79. hLdapBindHandle,
  80. pszIpsecRootContainer,
  81. pszIpsecNFAReference,
  82. 0x100
  83. );
  84. if (dwError) {
  85. continue;
  86. }
  87. dwError = DirBackPropIncChangesForNFAToPolicy(
  88. hLdapBindHandle,
  89. pszIpsecRootContainer,
  90. pszIpsecNFAReference
  91. );
  92. if (dwError) {
  93. continue;
  94. }
  95. }
  96. dwError = ERROR_SUCCESS;
  97. if (ppszIpsecNFAReferences) {
  98. FreeNFAReferences(
  99. ppszIpsecNFAReferences,
  100. dwNumReferences
  101. );
  102. }
  103. return (dwError);
  104. }
  105. DWORD
  106. DirBackPropIncChangesForNegPolToNFA(
  107. HLDAP hLdapBindHandle,
  108. LPWSTR pszIpsecRootContainer,
  109. GUID NegPolIdentifier
  110. )
  111. {
  112. DWORD dwError = 0;
  113. LPWSTR * ppszIpsecNFAReferences = NULL;
  114. DWORD dwNumReferences = 0;
  115. DWORD i = 0;
  116. LPWSTR pszIpsecNFAReference = NULL;
  117. dwError = DirGetNFAReferencesForNegPol(
  118. hLdapBindHandle,
  119. pszIpsecRootContainer,
  120. NegPolIdentifier,
  121. &ppszIpsecNFAReferences,
  122. &dwNumReferences
  123. );
  124. for (i = 0; i < dwNumReferences; i++) {
  125. pszIpsecNFAReference = *(ppszIpsecNFAReferences + i);
  126. dwError = DirUpdateNFA(
  127. hLdapBindHandle,
  128. pszIpsecRootContainer,
  129. pszIpsecNFAReference,
  130. 0x200
  131. );
  132. if (dwError) {
  133. continue;
  134. }
  135. dwError = DirUpdateNFA(
  136. hLdapBindHandle,
  137. pszIpsecRootContainer,
  138. pszIpsecNFAReference,
  139. 0x100
  140. );
  141. if (dwError) {
  142. continue;
  143. }
  144. dwError = DirBackPropIncChangesForNFAToPolicy(
  145. hLdapBindHandle,
  146. pszIpsecRootContainer,
  147. pszIpsecNFAReference
  148. );
  149. if (dwError) {
  150. continue;
  151. }
  152. }
  153. dwError = ERROR_SUCCESS;
  154. if (ppszIpsecNFAReferences) {
  155. FreeNFAReferences(
  156. ppszIpsecNFAReferences,
  157. dwNumReferences
  158. );
  159. }
  160. return (dwError);
  161. }
  162. DWORD
  163. DirBackPropIncChangesForNFAToPolicy(
  164. HLDAP hLdapBindHandle,
  165. LPWSTR pszIpsecRootContainer,
  166. LPWSTR pszNFADistinguishedName
  167. )
  168. {
  169. DWORD dwError = 0;
  170. LPWSTR * ppszIpsecPolicyReferences = NULL;
  171. DWORD dwNumReferences = 0;
  172. DWORD i = 0;
  173. LPWSTR pszIpsecPolicyReference = NULL;
  174. dwError = DirGetPolicyReferencesForNFA(
  175. hLdapBindHandle,
  176. pszIpsecRootContainer,
  177. pszNFADistinguishedName,
  178. &ppszIpsecPolicyReferences,
  179. &dwNumReferences
  180. );
  181. for (i = 0; i < dwNumReferences; i++) {
  182. pszIpsecPolicyReference = *(ppszIpsecPolicyReferences + i);
  183. dwError = DirUpdatePolicy(
  184. hLdapBindHandle,
  185. pszIpsecRootContainer,
  186. pszIpsecPolicyReference,
  187. 0x200
  188. );
  189. BAIL_ON_WIN32_ERROR(dwError);
  190. dwError = DirUpdatePolicy(
  191. hLdapBindHandle,
  192. pszIpsecRootContainer,
  193. pszIpsecPolicyReference,
  194. 0x100
  195. );
  196. BAIL_ON_WIN32_ERROR(dwError);
  197. }
  198. dwError = ERROR_SUCCESS;
  199. error:
  200. if (ppszIpsecPolicyReferences) {
  201. FreeNFAReferences(
  202. ppszIpsecPolicyReferences,
  203. dwNumReferences
  204. );
  205. }
  206. return (dwError);
  207. }
  208. DWORD
  209. DirGetPolicyReferencesForISAKMP(
  210. HLDAP hLdapBindHandle,
  211. LPWSTR pszIpsecRootContainer,
  212. GUID ISAKMPIdentifier,
  213. LPWSTR ** pppszIpsecPolicyReferences,
  214. PDWORD pdwNumReferences
  215. )
  216. {
  217. DWORD dwError = 0;
  218. PIPSEC_ISAKMP_OBJECT pIpsecISAKMPObject = NULL;
  219. LPWSTR * ppszIpsecPolicyReferences = NULL;
  220. DWORD dwNumReferences = 0;
  221. dwError = DirGetISAKMPObject(
  222. hLdapBindHandle,
  223. pszIpsecRootContainer,
  224. ISAKMPIdentifier,
  225. &pIpsecISAKMPObject
  226. );
  227. BAIL_ON_WIN32_ERROR(dwError);
  228. dwError = CopyReferences(
  229. pIpsecISAKMPObject->ppszIpsecNFAReferences,
  230. pIpsecISAKMPObject->dwNFACount,
  231. &ppszIpsecPolicyReferences,
  232. &dwNumReferences
  233. );
  234. BAIL_ON_WIN32_ERROR(dwError);
  235. *pppszIpsecPolicyReferences = ppszIpsecPolicyReferences;
  236. *pdwNumReferences = dwNumReferences;
  237. cleanup:
  238. if (pIpsecISAKMPObject) {
  239. FreeIpsecISAKMPObject(pIpsecISAKMPObject);
  240. }
  241. return (dwError);
  242. error:
  243. *pppszIpsecPolicyReferences = NULL;
  244. *pdwNumReferences = 0;
  245. goto cleanup;
  246. }
  247. DWORD
  248. DirUpdatePolicy(
  249. HLDAP hLdapBindHandle,
  250. LPWSTR pszIpsecRootContainer,
  251. LPWSTR pszIpsecPolicyReference,
  252. DWORD dwDataType
  253. )
  254. {
  255. DWORD dwError = 0;
  256. DWORD dwNumAttributes = 1;
  257. DWORD i = 0;
  258. LDAPModW ** ppLDAPModW = NULL;
  259. LDAPModW * pLDAPModW = NULL;
  260. WCHAR Buffer[64];
  261. DWORD dwIpsecDataType = dwDataType;
  262. Buffer[0] = L'\0';
  263. ppLDAPModW = (LDAPModW **) AllocPolMem(
  264. (dwNumAttributes+1) * sizeof(LDAPModW*)
  265. );
  266. if (!ppLDAPModW) {
  267. dwError = ERROR_OUTOFMEMORY;
  268. BAIL_ON_WIN32_ERROR(dwError);
  269. }
  270. pLDAPModW = (LDAPModW *) AllocPolMem(
  271. dwNumAttributes * sizeof(LDAPModW)
  272. );
  273. if (!pLDAPModW) {
  274. dwError = ERROR_OUTOFMEMORY;
  275. BAIL_ON_WIN32_ERROR(dwError);
  276. }
  277. ppLDAPModW[i] = pLDAPModW + i;
  278. dwError = AllocatePolString(
  279. L"ipsecDataType",
  280. &(pLDAPModW +i)->mod_type
  281. );
  282. BAIL_ON_WIN32_ERROR(dwError);
  283. _itow( dwIpsecDataType, Buffer, 10 );
  284. dwError = AllocateLDAPStringValue(
  285. Buffer,
  286. (PLDAPOBJECT *)&(pLDAPModW +i)->mod_values
  287. );
  288. BAIL_ON_WIN32_ERROR(dwError);
  289. (pLDAPModW + i)->mod_op |= LDAP_MOD_REPLACE;
  290. dwError = LdapModifyS(
  291. hLdapBindHandle,
  292. pszIpsecPolicyReference,
  293. ppLDAPModW
  294. );
  295. BAIL_ON_WIN32_ERROR(dwError);
  296. error:
  297. if (ppLDAPModW) {
  298. FreeLDAPModWs(
  299. ppLDAPModW
  300. );
  301. }
  302. return(dwError);
  303. }
  304. DWORD
  305. DirGetPolicyReferencesForNFA(
  306. HLDAP hLdapBindHandle,
  307. LPWSTR pszIpsecRootContainer,
  308. LPWSTR pszNFADistinguishedName,
  309. LPWSTR ** pppszIpsecPolicyReferences,
  310. PDWORD pdwNumReferences
  311. )
  312. {
  313. DWORD dwError = 0;
  314. LPWSTR pszIpsecID = NULL;
  315. GUID NFAIdentifier;
  316. PIPSEC_NFA_OBJECT pIpsecNFAObject = NULL;
  317. LPWSTR * ppszIpsecPolicyReferences = NULL;
  318. DWORD dwNumReferences = 0;
  319. pszIpsecID = wcschr(pszNFADistinguishedName, L'{');
  320. if (!pszIpsecID) {
  321. dwError = ERROR_INVALID_DATA;
  322. BAIL_ON_WIN32_ERROR(dwError);
  323. }
  324. wGUIDFromString(
  325. pszIpsecID,
  326. &NFAIdentifier
  327. );
  328. dwError = DirGetNFAObject(
  329. hLdapBindHandle,
  330. pszIpsecRootContainer,
  331. NFAIdentifier,
  332. &pIpsecNFAObject
  333. );
  334. BAIL_ON_WIN32_ERROR(dwError);
  335. dwError = CopyReferences(
  336. &(pIpsecNFAObject->pszIpsecOwnersReference),
  337. 1,
  338. &ppszIpsecPolicyReferences,
  339. &dwNumReferences
  340. );
  341. BAIL_ON_WIN32_ERROR(dwError);
  342. *pppszIpsecPolicyReferences = ppszIpsecPolicyReferences;
  343. *pdwNumReferences = dwNumReferences;
  344. cleanup:
  345. if (pIpsecNFAObject) {
  346. FreeIpsecNFAObject(pIpsecNFAObject);
  347. }
  348. return (dwError);
  349. error:
  350. *pppszIpsecPolicyReferences = NULL;
  351. *pdwNumReferences = 0;
  352. goto cleanup;
  353. }
  354. DWORD
  355. DirGetNFAReferencesForFilter(
  356. HLDAP hLdapBindHandle,
  357. LPWSTR pszIpsecRootContainer,
  358. GUID FilterIdentifier,
  359. LPWSTR ** pppszIpsecNFAReferences,
  360. PDWORD pdwNumReferences
  361. )
  362. {
  363. DWORD dwError = 0;
  364. PIPSEC_FILTER_OBJECT pIpsecFilterObject = NULL;
  365. LPWSTR * ppszIpsecNFAReferences = NULL;
  366. DWORD dwNumReferences = 0;
  367. dwError = DirGetFilterObject(
  368. hLdapBindHandle,
  369. pszIpsecRootContainer,
  370. FilterIdentifier,
  371. &pIpsecFilterObject
  372. );
  373. BAIL_ON_WIN32_ERROR(dwError);
  374. dwError = CopyReferences(
  375. pIpsecFilterObject->ppszIpsecNFAReferences,
  376. pIpsecFilterObject->dwNFACount,
  377. &ppszIpsecNFAReferences,
  378. &dwNumReferences
  379. );
  380. BAIL_ON_WIN32_ERROR(dwError);
  381. *pppszIpsecNFAReferences = ppszIpsecNFAReferences;
  382. *pdwNumReferences = dwNumReferences;
  383. cleanup:
  384. if (pIpsecFilterObject) {
  385. FreeIpsecFilterObject(pIpsecFilterObject);
  386. }
  387. return (dwError);
  388. error:
  389. *pppszIpsecNFAReferences = NULL;
  390. *pdwNumReferences = 0;
  391. goto cleanup;
  392. }
  393. DWORD
  394. DirUpdateNFA(
  395. HLDAP hLdapBindHandle,
  396. LPWSTR pszIpsecRootContainer,
  397. LPWSTR pszIpsecNFAReference,
  398. DWORD dwDataType
  399. )
  400. {
  401. DWORD dwError = 0;
  402. DWORD dwNumAttributes = 1;
  403. DWORD i = 0;
  404. LDAPModW ** ppLDAPModW = NULL;
  405. LDAPModW * pLDAPModW = NULL;
  406. WCHAR Buffer[64];
  407. DWORD dwIpsecDataType = dwDataType;
  408. Buffer[0] = L'\0';
  409. ppLDAPModW = (LDAPModW **) AllocPolMem(
  410. (dwNumAttributes+1) * sizeof(LDAPModW*)
  411. );
  412. if (!ppLDAPModW) {
  413. dwError = ERROR_OUTOFMEMORY;
  414. BAIL_ON_WIN32_ERROR(dwError);
  415. }
  416. pLDAPModW = (LDAPModW *) AllocPolMem(
  417. dwNumAttributes * sizeof(LDAPModW)
  418. );
  419. if (!pLDAPModW) {
  420. dwError = ERROR_OUTOFMEMORY;
  421. BAIL_ON_WIN32_ERROR(dwError);
  422. }
  423. ppLDAPModW[i] = pLDAPModW + i;
  424. dwError = AllocatePolString(
  425. L"ipsecDataType",
  426. &(pLDAPModW +i)->mod_type
  427. );
  428. BAIL_ON_WIN32_ERROR(dwError);
  429. _itow( dwIpsecDataType, Buffer, 10 );
  430. dwError = AllocateLDAPStringValue(
  431. Buffer,
  432. (PLDAPOBJECT *)&(pLDAPModW +i)->mod_values
  433. );
  434. BAIL_ON_WIN32_ERROR(dwError);
  435. (pLDAPModW + i)->mod_op |= LDAP_MOD_REPLACE;
  436. dwError = LdapModifyS(
  437. hLdapBindHandle,
  438. pszIpsecNFAReference,
  439. ppLDAPModW
  440. );
  441. BAIL_ON_WIN32_ERROR(dwError);
  442. error:
  443. if (ppLDAPModW) {
  444. FreeLDAPModWs(
  445. ppLDAPModW
  446. );
  447. }
  448. return(dwError);
  449. }
  450. DWORD
  451. DirGetNFAReferencesForNegPol(
  452. HLDAP hLdapBindHandle,
  453. LPWSTR pszIpsecRootContainer,
  454. GUID NegPolIdentifier,
  455. LPWSTR ** pppszIpsecNFAReferences,
  456. PDWORD pdwNumReferences
  457. )
  458. {
  459. DWORD dwError = 0;
  460. PIPSEC_NEGPOL_OBJECT pIpsecNegPolObject = NULL;
  461. LPWSTR * ppszIpsecNFAReferences = NULL;
  462. DWORD dwNumReferences = 0;
  463. dwError = DirGetNegPolObject(
  464. hLdapBindHandle,
  465. pszIpsecRootContainer,
  466. NegPolIdentifier,
  467. &pIpsecNegPolObject
  468. );
  469. BAIL_ON_WIN32_ERROR(dwError);
  470. dwError = CopyReferences(
  471. pIpsecNegPolObject->ppszIpsecNFAReferences,
  472. pIpsecNegPolObject->dwNFACount,
  473. &ppszIpsecNFAReferences,
  474. &dwNumReferences
  475. );
  476. BAIL_ON_WIN32_ERROR(dwError);
  477. *pppszIpsecNFAReferences = ppszIpsecNFAReferences;
  478. *pdwNumReferences = dwNumReferences;
  479. cleanup:
  480. if (pIpsecNegPolObject) {
  481. FreeIpsecNegPolObject(pIpsecNegPolObject);
  482. }
  483. return (dwError);
  484. error:
  485. *pppszIpsecNFAReferences = NULL;
  486. *pdwNumReferences = 0;
  487. goto cleanup;
  488. }
  489. DWORD
  490. CopyReferences(
  491. LPWSTR * ppszIpsecReferences,
  492. DWORD dwNumReferences,
  493. LPWSTR ** pppszNewIpsecReferences,
  494. PDWORD pdwNumNewReferences
  495. )
  496. {
  497. DWORD dwError = 0;
  498. LPWSTR * ppszNewIpsecReferences = NULL;
  499. DWORD i = 0;
  500. LPWSTR pszTemp = NULL;
  501. LPWSTR pszString = NULL;
  502. if (!dwNumReferences || !ppszIpsecReferences) {
  503. *pppszNewIpsecReferences = NULL;
  504. *pdwNumNewReferences = 0;
  505. return (dwError);
  506. }
  507. ppszNewIpsecReferences = (LPWSTR *) AllocPolMem(
  508. sizeof(LPWSTR) * dwNumReferences
  509. );
  510. if (!ppszNewIpsecReferences) {
  511. dwError = ERROR_OUTOFMEMORY;
  512. BAIL_ON_WIN32_ERROR(dwError);
  513. }
  514. for (i = 0; i < dwNumReferences; i++) {
  515. pszTemp = *(ppszIpsecReferences + i);
  516. pszString = AllocPolStr(pszTemp);
  517. if (!pszString) {
  518. dwError = ERROR_OUTOFMEMORY;
  519. BAIL_ON_WIN32_ERROR(dwError);
  520. }
  521. *(ppszNewIpsecReferences + i) = pszString;
  522. }
  523. *pppszNewIpsecReferences = ppszNewIpsecReferences;
  524. *pdwNumNewReferences = dwNumReferences;
  525. return (dwError);
  526. error:
  527. if (ppszNewIpsecReferences) {
  528. FreeNFAReferences(
  529. ppszNewIpsecReferences,
  530. i
  531. );
  532. }
  533. *pppszNewIpsecReferences = NULL;
  534. *pdwNumNewReferences = 0;
  535. return (dwError);
  536. }