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.

1394 lines
34 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2001.
  5. //
  6. // File: policy-d.c
  7. //
  8. // Contents: Policy management for directory.
  9. //
  10. //
  11. // History: TaroonM (10/30/01)
  12. // AbhisheV (05/11/00)
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "precomp.h"
  16. extern LPWSTR PolicyDNAttributes[];
  17. DWORD
  18. DirEnumWirelessPolicyData(
  19. HLDAP hLdapBindHandle,
  20. LPWSTR pszWirelessRootContainer,
  21. PWIRELESS_POLICY_DATA ** pppWirelessPolicyData,
  22. PDWORD pdwNumPolicyObjects
  23. )
  24. {
  25. DWORD dwError = 0;
  26. PWIRELESS_POLICY_OBJECT * ppWirelessPolicyObjects = NULL;
  27. PWIRELESS_POLICY_DATA pWirelessPolicyData = NULL;
  28. PWIRELESS_POLICY_DATA * ppWirelessPolicyData = NULL;
  29. DWORD dwNumPolicyObjects = 0;
  30. DWORD i = 0;
  31. DWORD j = 0;
  32. dwError = DirEnumPolicyObjects(
  33. hLdapBindHandle,
  34. pszWirelessRootContainer,
  35. &ppWirelessPolicyObjects,
  36. &dwNumPolicyObjects
  37. );
  38. BAIL_ON_WIN32_ERROR(dwError);
  39. if (dwNumPolicyObjects) {
  40. ppWirelessPolicyData = (PWIRELESS_POLICY_DATA *) AllocPolMem(
  41. dwNumPolicyObjects*sizeof(PWIRELESS_POLICY_DATA));
  42. if (!ppWirelessPolicyData) {
  43. dwError = ERROR_OUTOFMEMORY;
  44. BAIL_ON_WIN32_ERROR(dwError);
  45. }
  46. }
  47. for (i = 0; i < dwNumPolicyObjects; i++) {
  48. dwError = DirUnmarshallWirelessPolicyData(
  49. *(ppWirelessPolicyObjects + i),
  50. &pWirelessPolicyData
  51. );
  52. if (!dwError) {
  53. *(ppWirelessPolicyData + j) = pWirelessPolicyData;
  54. j++;
  55. }
  56. }
  57. if (j == 0) {
  58. if (ppWirelessPolicyData) {
  59. FreePolMem(ppWirelessPolicyData);
  60. ppWirelessPolicyData = NULL;
  61. }
  62. }
  63. *pppWirelessPolicyData = ppWirelessPolicyData;
  64. *pdwNumPolicyObjects = j;
  65. dwError = ERROR_SUCCESS;
  66. cleanup:
  67. if (ppWirelessPolicyObjects) {
  68. FreeWirelessPolicyObjects(
  69. ppWirelessPolicyObjects,
  70. dwNumPolicyObjects
  71. );
  72. }
  73. return(dwError);
  74. error:
  75. if (ppWirelessPolicyData) {
  76. FreeMulWirelessPolicyData(
  77. ppWirelessPolicyData,
  78. i
  79. );
  80. }
  81. *pppWirelessPolicyData = NULL;
  82. *pdwNumPolicyObjects = 0;
  83. goto cleanup;
  84. }
  85. DWORD
  86. DirEnumPolicyObjects(
  87. HLDAP hLdapBindHandle,
  88. LPWSTR pszWirelessRootContainer,
  89. PWIRELESS_POLICY_OBJECT ** pppWirelessPolicyObjects,
  90. PDWORD pdwNumPolicyObjects
  91. )
  92. {
  93. LDAPMessage *res = NULL;
  94. LDAPMessage *e = NULL;
  95. DWORD dwError = 0;
  96. LPWSTR pszPolicyString = NULL;
  97. DWORD i = 0;
  98. DWORD dwCount = 0;
  99. PWIRELESS_POLICY_OBJECT pWirelessPolicyObject = NULL;
  100. PWIRELESS_POLICY_OBJECT * ppWirelessPolicyObjects = NULL;
  101. DWORD dwNumPolicyObjectsReturned = 0;
  102. dwError = GenerateAllPolicyQuery(
  103. &pszPolicyString
  104. );
  105. BAIL_ON_WIN32_ERROR(dwError);
  106. dwError = LdapSearchST(
  107. hLdapBindHandle,
  108. pszWirelessRootContainer,
  109. LDAP_SCOPE_ONELEVEL,
  110. pszPolicyString,
  111. PolicyDNAttributes,
  112. 0,
  113. NULL,
  114. &res
  115. );
  116. BAIL_ON_WIN32_ERROR(dwError);
  117. dwCount = LdapCountEntries(
  118. hLdapBindHandle,
  119. res
  120. );
  121. if (!dwCount) {
  122. dwError = ERROR_DS_NO_ATTRIBUTE_OR_VALUE;
  123. BAIL_ON_WIN32_ERROR(dwError);
  124. }
  125. ppWirelessPolicyObjects = (PWIRELESS_POLICY_OBJECT *)AllocPolMem(
  126. sizeof(PWIRELESS_POLICY_OBJECT)*dwCount
  127. );
  128. if (!ppWirelessPolicyObjects) {
  129. dwError = ERROR_OUTOFMEMORY;
  130. BAIL_ON_WIN32_ERROR(dwError);
  131. }
  132. for (i = 0; i < dwCount; i++) {
  133. if (i == 0) {
  134. dwError = LdapFirstEntry(
  135. hLdapBindHandle,
  136. res,
  137. &e
  138. );
  139. BAIL_ON_WIN32_ERROR(dwError);
  140. } else {
  141. dwError = LdapNextEntry(
  142. hLdapBindHandle,
  143. e,
  144. &e
  145. );
  146. BAIL_ON_WIN32_ERROR(dwError);
  147. }
  148. dwError = UnMarshallPolicyObject2(
  149. hLdapBindHandle,
  150. e,
  151. &pWirelessPolicyObject
  152. );
  153. if (dwError == ERROR_SUCCESS) {
  154. *(ppWirelessPolicyObjects + dwNumPolicyObjectsReturned) = pWirelessPolicyObject;
  155. dwNumPolicyObjectsReturned++;
  156. }
  157. }
  158. *pppWirelessPolicyObjects = ppWirelessPolicyObjects;
  159. *pdwNumPolicyObjects = dwNumPolicyObjectsReturned;
  160. dwError = ERROR_SUCCESS;
  161. cleanup:
  162. if (pszPolicyString) {
  163. FreePolMem(pszPolicyString);
  164. }
  165. if (res) {
  166. LdapMsgFree(res);
  167. }
  168. return(dwError);
  169. error:
  170. if (ppWirelessPolicyObjects) {
  171. FreeWirelessPolicyObjects(
  172. ppWirelessPolicyObjects,
  173. dwNumPolicyObjectsReturned
  174. );
  175. }
  176. *pppWirelessPolicyObjects = NULL;
  177. *pdwNumPolicyObjects = 0;
  178. goto cleanup;
  179. }
  180. DWORD
  181. GenerateAllPolicyQuery(
  182. LPWSTR * ppszPolicyString
  183. )
  184. {
  185. DWORD dwError = 0;
  186. DWORD dwLength = 0;
  187. LPWSTR pszPolicyString = NULL;
  188. //
  189. // Compute Length of Buffer to be allocated
  190. //
  191. dwLength = wcslen(L"(objectclass=msieee80211-Policy)");
  192. pszPolicyString = (LPWSTR) AllocPolMem((dwLength + 1)*sizeof(WCHAR));
  193. if (!pszPolicyString) {
  194. dwError = ERROR_OUTOFMEMORY;
  195. BAIL_ON_WIN32_ERROR(dwError);
  196. }
  197. //
  198. // Now fill in the buffer
  199. //
  200. wcscpy(pszPolicyString, L"(objectclass=msieee80211-Policy)");
  201. *ppszPolicyString = pszPolicyString;
  202. return(0);
  203. error:
  204. if (pszPolicyString) {
  205. FreePolMem(pszPolicyString);
  206. }
  207. *ppszPolicyString = NULL;
  208. return(dwError);
  209. }
  210. DWORD
  211. UnMarshallPolicyObject2(
  212. HLDAP hLdapBindHandle,
  213. LDAPMessage *e,
  214. PWIRELESS_POLICY_OBJECT * ppWirelessPolicyObject
  215. )
  216. {
  217. PWIRELESS_POLICY_OBJECT pWirelessPolicyObject = NULL;
  218. DWORD dwCount = 0;
  219. DWORD dwLen = 0;
  220. LPBYTE pBuffer = NULL;
  221. DWORD i = 0;
  222. DWORD dwError = 0;
  223. WCHAR **strvalues = NULL;
  224. struct berval ** bvalues = NULL;
  225. LPWSTR * ppszTemp = NULL;
  226. pWirelessPolicyObject = (PWIRELESS_POLICY_OBJECT)AllocPolMem(
  227. sizeof(WIRELESS_POLICY_OBJECT)
  228. );
  229. if (!pWirelessPolicyObject) {
  230. dwError = ERROR_OUTOFMEMORY;
  231. BAIL_ON_WIN32_ERROR(dwError);
  232. }
  233. strvalues = NULL;
  234. dwError = LdapGetValues(
  235. hLdapBindHandle,
  236. e,
  237. L"distinguishedName",
  238. (WCHAR ***)&strvalues,
  239. (int *)&dwCount
  240. );
  241. BAIL_ON_WIN32_ERROR(dwError);
  242. pWirelessPolicyObject->pszWirelessOwnersReference = AllocPolStr(
  243. LDAPOBJECT_STRING((PLDAPOBJECT)strvalues)
  244. );
  245. if (!pWirelessPolicyObject->pszWirelessOwnersReference) {
  246. dwError = ERROR_OUTOFMEMORY;
  247. BAIL_ON_WIN32_ERROR(dwError);
  248. }
  249. LdapValueFree(strvalues);
  250. strvalues = NULL;
  251. dwError = LdapGetValues(
  252. hLdapBindHandle,
  253. e,
  254. L"cn",
  255. (WCHAR ***)&strvalues,
  256. (int *)&dwCount
  257. );
  258. BAIL_ON_WIN32_ERROR(dwError);
  259. pWirelessPolicyObject->pszWirelessName = AllocPolStr(
  260. LDAPOBJECT_STRING((PLDAPOBJECT)strvalues)
  261. );
  262. if (!pWirelessPolicyObject->pszWirelessName) {
  263. dwError = ERROR_OUTOFMEMORY;
  264. BAIL_ON_WIN32_ERROR(dwError);
  265. }
  266. LdapValueFree(strvalues);
  267. strvalues = NULL;
  268. dwError = LdapGetValues(
  269. hLdapBindHandle,
  270. e,
  271. L"description",
  272. (WCHAR ***)&strvalues,
  273. (int *)&dwCount
  274. );
  275. // BAIL_ON_WIN32_ERROR(dwError);
  276. if (strvalues && LDAPOBJECT_STRING((PLDAPOBJECT)strvalues)) {
  277. pWirelessPolicyObject->pszDescription = AllocPolStr(
  278. LDAPOBJECT_STRING((PLDAPOBJECT)strvalues)
  279. );
  280. if (!pWirelessPolicyObject->pszDescription) {
  281. dwError = ERROR_OUTOFMEMORY;
  282. BAIL_ON_WIN32_ERROR(dwError);
  283. }
  284. LdapValueFree(strvalues);
  285. } else {
  286. pWirelessPolicyObject->pszDescription = NULL;
  287. }
  288. strvalues = NULL;
  289. dwError = LdapGetValues(
  290. hLdapBindHandle,
  291. e,
  292. L"msieee80211-ID",
  293. (WCHAR ***)&strvalues,
  294. (int *)&dwCount
  295. );
  296. BAIL_ON_WIN32_ERROR(dwError);
  297. pWirelessPolicyObject->pszWirelessID = AllocPolStr(
  298. LDAPOBJECT_STRING((PLDAPOBJECT)strvalues)
  299. );
  300. if (!pWirelessPolicyObject->pszWirelessID) {
  301. dwError = ERROR_OUTOFMEMORY;
  302. BAIL_ON_WIN32_ERROR(dwError);
  303. }
  304. LdapValueFree(strvalues);
  305. strvalues = NULL;
  306. dwError = LdapGetValues(
  307. hLdapBindHandle,
  308. e,
  309. L"msieee80211-DataType",
  310. (WCHAR ***)&strvalues,
  311. (int *)&dwCount
  312. );
  313. BAIL_ON_WIN32_ERROR(dwError);
  314. pWirelessPolicyObject->dwWirelessDataType = _wtol(LDAPOBJECT_STRING((PLDAPOBJECT)strvalues));
  315. LdapValueFree(strvalues);
  316. strvalues = NULL;
  317. dwError = LdapGetValues(
  318. hLdapBindHandle,
  319. e,
  320. L"whenChanged",
  321. (WCHAR ***)&strvalues,
  322. (int *)&dwCount
  323. );
  324. BAIL_ON_WIN32_ERROR(dwError);
  325. pWirelessPolicyObject->dwWhenChanged = _wtol(LDAPOBJECT_STRING((PLDAPOBJECT)strvalues));
  326. LdapValueFree(strvalues);
  327. //
  328. // unmarshall the msieee80211-Data blob
  329. //
  330. dwError = LdapGetValuesLen(
  331. hLdapBindHandle,
  332. e,
  333. L"msieee80211-Data",
  334. (struct berval ***)&bvalues,
  335. (int *)&dwCount
  336. );
  337. BAIL_ON_WIN32_ERROR(dwError);
  338. dwLen = LDAPOBJECT_BERVAL_LEN((PLDAPOBJECT)bvalues);
  339. pBuffer = (LPBYTE)AllocPolMem(dwLen);
  340. if (!pBuffer) {
  341. dwError = ERROR_OUTOFMEMORY;
  342. BAIL_ON_WIN32_ERROR(dwError);
  343. }
  344. memcpy( pBuffer, LDAPOBJECT_BERVAL_VAL((PLDAPOBJECT)bvalues), dwLen );
  345. pWirelessPolicyObject->pWirelessData = pBuffer;
  346. pWirelessPolicyObject->dwWirelessDataLen = dwLen;
  347. LdapValueFreeLen(bvalues);
  348. *ppWirelessPolicyObject = pWirelessPolicyObject;
  349. return(dwError);
  350. error:
  351. if (pWirelessPolicyObject) {
  352. FreeWirelessPolicyObject(pWirelessPolicyObject);
  353. }
  354. *ppWirelessPolicyObject = NULL;
  355. return(dwError);
  356. }
  357. DWORD
  358. DirUnmarshallWirelessPolicyData(
  359. PWIRELESS_POLICY_OBJECT pWirelessPolicyObject,
  360. PWIRELESS_POLICY_DATA * ppWirelessPolicyData
  361. )
  362. {
  363. DWORD dwError = 0;
  364. dwError = UnmarshallWirelessPolicyObject(
  365. pWirelessPolicyObject,
  366. WIRELESS_DIRECTORY_PROVIDER,
  367. ppWirelessPolicyData
  368. );
  369. return(dwError);
  370. }
  371. DWORD
  372. DirCreateWirelessPolicyData(
  373. HLDAP hLdapBindHandle,
  374. LPWSTR pszWirelessRootContainer,
  375. PWIRELESS_POLICY_DATA pWirelessPolicyData
  376. )
  377. {
  378. DWORD dwError = 0;
  379. PWIRELESS_POLICY_OBJECT pWirelessPolicyObject = NULL;
  380. dwError = DirMarshallWirelessPolicyObject(
  381. pWirelessPolicyData,
  382. pszWirelessRootContainer,
  383. &pWirelessPolicyObject
  384. );
  385. BAIL_ON_WIN32_ERROR(dwError);
  386. dwError = DirCreatePolicyObject(
  387. hLdapBindHandle,
  388. pszWirelessRootContainer,
  389. pWirelessPolicyObject
  390. );
  391. BAIL_ON_WIN32_ERROR(dwError);
  392. error:
  393. if (pWirelessPolicyObject) {
  394. FreeWirelessPolicyObject(
  395. pWirelessPolicyObject
  396. );
  397. }
  398. return(dwError);
  399. }
  400. DWORD
  401. DirMarshallWirelessPolicyObject(
  402. PWIRELESS_POLICY_DATA pWirelessPolicyData,
  403. LPWSTR pszWirelessRootContainer,
  404. PWIRELESS_POLICY_OBJECT * ppWirelessPolicyObject
  405. )
  406. {
  407. DWORD dwError = 0;
  408. PWIRELESS_POLICY_OBJECT pWirelessPolicyObject = NULL;
  409. WCHAR szGuid[MAX_PATH];
  410. LPWSTR pszDistinguishedName = NULL;
  411. LPBYTE pBuffer = NULL;
  412. DWORD dwBufferLen = 0;
  413. LPWSTR pszStringUuid = NULL;
  414. DWORD dwCNLen = 0;
  415. DWORD dwContainerLen = 0;
  416. DWORD dwTotalLen = 0;
  417. LPWSTR pszWirelessOwnersReference = NULL;
  418. LPWSTR pszOldWirelessOwnersReference = NULL;
  419. szGuid[0] = L'\0';
  420. pWirelessPolicyObject = (PWIRELESS_POLICY_OBJECT)AllocPolMem(
  421. sizeof(WIRELESS_POLICY_OBJECT)
  422. );
  423. if (!pWirelessPolicyObject) {
  424. dwError = ERROR_OUTOFMEMORY;
  425. BAIL_ON_WIN32_ERROR(dwError);
  426. }
  427. pWirelessPolicyObject->pszOldWirelessOwnersReferenceName = NULL;
  428. dwError = UuidToString(
  429. &pWirelessPolicyData->PolicyIdentifier,
  430. &pszStringUuid
  431. );
  432. BAIL_ON_WIN32_ERROR(dwError);
  433. wcscpy(szGuid, L"{");
  434. wcscat(szGuid, pszStringUuid);
  435. wcscat(szGuid, L"}");
  436. //
  437. // Fill in the distinguishedName
  438. //
  439. dwCNLen = wcslen(L"CN=") + wcslen(pWirelessPolicyData->pszWirelessName) + wcslen(L",");
  440. dwContainerLen = wcslen(pszWirelessRootContainer);
  441. dwTotalLen = dwCNLen + dwContainerLen;
  442. pszWirelessOwnersReference = AllocPolMem(
  443. (dwTotalLen + 1) * sizeof(WCHAR)
  444. );
  445. if (!pszWirelessOwnersReference) {
  446. dwError = ERROR_OUTOFMEMORY;
  447. BAIL_ON_WIN32_ERROR(dwError);
  448. }
  449. wcsncpy(pszWirelessOwnersReference, L"CN=", wcslen(L"CN="));
  450. wcscat(pszWirelessOwnersReference,pWirelessPolicyData->pszWirelessName);
  451. wcscat(pszWirelessOwnersReference, L",");
  452. wcscat(pszWirelessOwnersReference, pszWirelessRootContainer);
  453. pszWirelessOwnersReference[dwTotalLen] = L'\0';
  454. pWirelessPolicyObject->pszWirelessOwnersReference = pszWirelessOwnersReference;
  455. if (pWirelessPolicyData->pszOldWirelessName) {
  456. dwCNLen = wcslen(L"CN=") + wcslen(pWirelessPolicyData->pszOldWirelessName) + wcslen(L",");
  457. // we already have the container len;
  458. dwTotalLen = dwCNLen + dwContainerLen;
  459. pszOldWirelessOwnersReference = (LPWSTR) AllocPolMem(
  460. (dwTotalLen +1) * sizeof(WCHAR)
  461. );
  462. if (!pszOldWirelessOwnersReference) {
  463. dwError = ERROR_OUTOFMEMORY;
  464. }
  465. BAIL_ON_WIN32_ERROR(dwError);
  466. wcsncpy(pszOldWirelessOwnersReference,L"CN=", wcslen(L"CN="));
  467. wcscat(pszOldWirelessOwnersReference, pWirelessPolicyData->pszOldWirelessName);
  468. wcscat(pszOldWirelessOwnersReference, L",");
  469. wcscat(pszOldWirelessOwnersReference, pszWirelessRootContainer);
  470. pszOldWirelessOwnersReference[dwTotalLen] = L'\0';
  471. pWirelessPolicyObject->pszOldWirelessOwnersReferenceName =
  472. pszOldWirelessOwnersReference;
  473. }
  474. //
  475. // Fill in the msieee80211-Name
  476. //
  477. if (pWirelessPolicyData->pszWirelessName &&
  478. *pWirelessPolicyData->pszWirelessName) {
  479. pWirelessPolicyObject->pszWirelessName = AllocPolStr(
  480. pWirelessPolicyData->pszWirelessName
  481. );
  482. if (!pWirelessPolicyObject->pszWirelessName) {
  483. dwError = ERROR_OUTOFMEMORY;
  484. BAIL_ON_WIN32_ERROR(dwError);
  485. }
  486. }
  487. if (pWirelessPolicyData->pszDescription &&
  488. *pWirelessPolicyData->pszDescription) {
  489. pWirelessPolicyObject->pszDescription = AllocPolStr(
  490. pWirelessPolicyData->pszDescription
  491. );
  492. if (!pWirelessPolicyObject->pszDescription) {
  493. dwError = ERROR_OUTOFMEMORY;
  494. BAIL_ON_WIN32_ERROR(dwError);
  495. }
  496. }
  497. //
  498. // Fill in the msieee80211-ID
  499. //
  500. pWirelessPolicyObject->pszWirelessID = AllocPolStr(
  501. szGuid
  502. );
  503. if (!pWirelessPolicyObject->pszWirelessID) {
  504. dwError = ERROR_OUTOFMEMORY;
  505. BAIL_ON_WIN32_ERROR(dwError);
  506. }
  507. //
  508. // Fill in the msieee80211-DataType
  509. //
  510. pWirelessPolicyObject->dwWirelessDataType = 0x100;
  511. //
  512. // Marshall the pWirelessDataBuffer and the Length
  513. //
  514. dwError = MarshallWirelessPolicyBuffer(
  515. pWirelessPolicyData,
  516. &pBuffer,
  517. &dwBufferLen
  518. );
  519. BAIL_ON_WIN32_ERROR(dwError);
  520. pWirelessPolicyObject->pWirelessData = pBuffer;
  521. pWirelessPolicyObject->dwWirelessDataLen = dwBufferLen;
  522. pWirelessPolicyObject->dwWhenChanged = 0;
  523. *ppWirelessPolicyObject = pWirelessPolicyObject;
  524. cleanup:
  525. if (pszStringUuid) {
  526. RpcStringFree(
  527. &pszStringUuid
  528. );
  529. }
  530. return(dwError);
  531. error:
  532. if (pWirelessPolicyObject) {
  533. FreeWirelessPolicyObject(
  534. pWirelessPolicyObject
  535. );
  536. }
  537. *ppWirelessPolicyObject = NULL;
  538. goto cleanup;
  539. }
  540. DWORD
  541. DirCreatePolicyObject(
  542. HLDAP hLdapBindHandle,
  543. LPWSTR pszWirelessRootContainer,
  544. PWIRELESS_POLICY_OBJECT pWirelessPolicyObject
  545. )
  546. {
  547. DWORD dwError = 0;
  548. LDAPModW ** ppLDAPModW = NULL;
  549. dwError = DirMarshallAddPolicyObject(
  550. hLdapBindHandle,
  551. pszWirelessRootContainer,
  552. pWirelessPolicyObject,
  553. &ppLDAPModW
  554. );
  555. BAIL_ON_WIN32_ERROR(dwError);
  556. dwError = LdapAddS(
  557. hLdapBindHandle,
  558. pWirelessPolicyObject->pszWirelessOwnersReference,
  559. ppLDAPModW
  560. );
  561. BAIL_ON_WIN32_ERROR(dwError);
  562. error:
  563. //
  564. // Free the amods structures.
  565. //
  566. if (ppLDAPModW) {
  567. FreeLDAPModWs(
  568. ppLDAPModW
  569. );
  570. }
  571. return(dwError);
  572. }
  573. DWORD
  574. DirMarshallAddPolicyObject(
  575. HLDAP hLdapBindHandle,
  576. LPWSTR pszWirelessRootContainer,
  577. PWIRELESS_POLICY_OBJECT pWirelessPolicyObject,
  578. LDAPModW *** pppLDAPModW
  579. )
  580. {
  581. DWORD i = 0;
  582. LDAPModW ** ppLDAPModW = NULL;
  583. LDAPModW * pLDAPModW = NULL;
  584. DWORD dwNumAttributes = 5;
  585. DWORD dwError = 0;
  586. WCHAR Buffer[64];
  587. if (!pWirelessPolicyObject->pszWirelessName ||
  588. !*pWirelessPolicyObject->pszWirelessName) {
  589. dwNumAttributes--;
  590. }
  591. if (!pWirelessPolicyObject->pszDescription ||
  592. !*pWirelessPolicyObject->pszDescription) {
  593. dwNumAttributes--;
  594. }
  595. ppLDAPModW = (LDAPModW **) AllocPolMem(
  596. (dwNumAttributes+1) * sizeof(LDAPModW*)
  597. );
  598. if (!ppLDAPModW) {
  599. dwError = ERROR_OUTOFMEMORY;
  600. BAIL_ON_WIN32_ERROR(dwError);
  601. }
  602. pLDAPModW = (LDAPModW *) AllocPolMem(
  603. dwNumAttributes * sizeof(LDAPModW)
  604. );
  605. if (!pLDAPModW) {
  606. dwError = ERROR_OUTOFMEMORY;
  607. BAIL_ON_WIN32_ERROR(dwError);
  608. }
  609. //
  610. // 0. objectClass
  611. //
  612. ppLDAPModW[i] = pLDAPModW + i;
  613. dwError = AllocatePolString(
  614. L"objectClass",
  615. &(pLDAPModW +i)->mod_type
  616. );
  617. BAIL_ON_WIN32_ERROR(dwError);
  618. dwError = AllocateLDAPStringValue(
  619. L"msieee80211-Policy",
  620. (PLDAPOBJECT *)&(pLDAPModW +i)->mod_values
  621. );
  622. BAIL_ON_WIN32_ERROR(dwError);
  623. (pLDAPModW + i)->mod_op |= LDAP_MOD_REPLACE;
  624. i++;
  625. //
  626. // 2. msieee80211-ID
  627. //
  628. ppLDAPModW[i] = pLDAPModW + i;
  629. dwError = AllocatePolString(
  630. L"msieee80211-ID",
  631. &(pLDAPModW +i)->mod_type
  632. );
  633. BAIL_ON_WIN32_ERROR(dwError);
  634. dwError = AllocateLDAPStringValue(
  635. pWirelessPolicyObject->pszWirelessID,
  636. (PLDAPOBJECT *)&(pLDAPModW +i)->mod_values
  637. );
  638. BAIL_ON_WIN32_ERROR(dwError);
  639. (pLDAPModW + i)->mod_op |= LDAP_MOD_REPLACE;
  640. i++;
  641. //
  642. // 3. msieee80211-DataType
  643. //
  644. ppLDAPModW[i] = pLDAPModW + i;
  645. dwError = AllocatePolString(
  646. L"msieee80211-DataType",
  647. &(pLDAPModW +i)->mod_type
  648. );
  649. BAIL_ON_WIN32_ERROR(dwError);
  650. _itow( pWirelessPolicyObject->dwWirelessDataType, Buffer, 10 );
  651. dwError = AllocateLDAPStringValue(
  652. Buffer,
  653. (PLDAPOBJECT *)&(pLDAPModW +i)->mod_values
  654. );
  655. BAIL_ON_WIN32_ERROR(dwError);
  656. (pLDAPModW + i)->mod_op |= LDAP_MOD_REPLACE;
  657. i++;
  658. //
  659. // 4. msieee80211-Data
  660. //
  661. ppLDAPModW[i] = pLDAPModW + i;
  662. dwError = AllocatePolString(
  663. L"msieee80211-Data",
  664. &(pLDAPModW +i)->mod_type
  665. );
  666. BAIL_ON_WIN32_ERROR(dwError);
  667. dwError = AllocateLDAPBinaryValue(
  668. pWirelessPolicyObject->pWirelessData,
  669. pWirelessPolicyObject->dwWirelessDataLen,
  670. (PLDAPOBJECT *)&(pLDAPModW +i)->mod_values
  671. );
  672. BAIL_ON_WIN32_ERROR(dwError);
  673. (pLDAPModW+i)->mod_op = LDAP_MOD_REPLACE | LDAP_MOD_BVALUES;
  674. i++;
  675. //
  676. // 5. description
  677. //
  678. if (pWirelessPolicyObject->pszDescription &&
  679. *pWirelessPolicyObject->pszDescription) {
  680. ppLDAPModW[i] = pLDAPModW + i;
  681. dwError = AllocatePolString(
  682. L"description",
  683. &(pLDAPModW +i)->mod_type
  684. );
  685. BAIL_ON_WIN32_ERROR(dwError);
  686. dwError = AllocateLDAPStringValue(
  687. pWirelessPolicyObject->pszDescription,
  688. (PLDAPOBJECT *)&(pLDAPModW +i)->mod_values
  689. );
  690. BAIL_ON_WIN32_ERROR(dwError);
  691. (pLDAPModW + i)->mod_op |= LDAP_MOD_REPLACE;
  692. i++;
  693. }
  694. *pppLDAPModW = ppLDAPModW;
  695. return(dwError);
  696. error:
  697. if (ppLDAPModW) {
  698. FreeLDAPModWs(
  699. ppLDAPModW
  700. );
  701. }
  702. *pppLDAPModW = NULL;
  703. return(dwError);
  704. }
  705. DWORD
  706. DirSetWirelessPolicyData(
  707. HLDAP hLdapBindHandle,
  708. LPWSTR pszWirelessRootContainer,
  709. PWIRELESS_POLICY_DATA pWirelessPolicyData
  710. )
  711. {
  712. DWORD dwError = 0;
  713. PWIRELESS_POLICY_OBJECT pWirelessPolicyObject = NULL;
  714. dwError = DirMarshallWirelessPolicyObject(
  715. pWirelessPolicyData,
  716. pszWirelessRootContainer,
  717. &pWirelessPolicyObject
  718. );
  719. BAIL_ON_WIN32_ERROR(dwError);
  720. dwError = DirSetPolicyObject(
  721. hLdapBindHandle,
  722. pszWirelessRootContainer,
  723. pWirelessPolicyObject
  724. );
  725. BAIL_ON_WIN32_ERROR(dwError);
  726. error:
  727. if (pWirelessPolicyObject) {
  728. FreeWirelessPolicyObject(pWirelessPolicyObject);
  729. }
  730. return(dwError);
  731. }
  732. DWORD
  733. DirSetPolicyObject(
  734. HLDAP hLdapBindHandle,
  735. LPWSTR pszWirelessRootContainer,
  736. PWIRELESS_POLICY_OBJECT pWirelessPolicyObject
  737. )
  738. {
  739. DWORD dwError = 0;
  740. LDAPModW ** ppLDAPModW = NULL;
  741. dwError = DirMarshallSetPolicyObject(
  742. hLdapBindHandle,
  743. pszWirelessRootContainer,
  744. pWirelessPolicyObject,
  745. &ppLDAPModW
  746. );
  747. BAIL_ON_WIN32_ERROR(dwError);
  748. if (pWirelessPolicyObject->pszOldWirelessOwnersReferenceName) {
  749. dwError = LdapRename(hLdapBindHandle,
  750. pWirelessPolicyObject->pszOldWirelessOwnersReferenceName,
  751. pWirelessPolicyObject->pszWirelessOwnersReference
  752. );
  753. BAIL_ON_WIN32_ERROR(dwError);
  754. }
  755. dwError = LdapModifyS(
  756. hLdapBindHandle,
  757. pWirelessPolicyObject->pszWirelessOwnersReference,
  758. ppLDAPModW
  759. );
  760. BAIL_ON_WIN32_ERROR(dwError);
  761. error:
  762. //
  763. // Free the amods structures.
  764. //
  765. if (ppLDAPModW) {
  766. FreeLDAPModWs(
  767. ppLDAPModW
  768. );
  769. }
  770. return(dwError);
  771. }
  772. DWORD
  773. DirMarshallSetPolicyObject(
  774. HLDAP hLdapBindHandle,
  775. LPWSTR pszWirelessRootContainer,
  776. PWIRELESS_POLICY_OBJECT pWirelessPolicyObject,
  777. LDAPModW *** pppLDAPModW
  778. )
  779. {
  780. DWORD i = 0;
  781. LDAPModW ** ppLDAPModW = NULL;
  782. LDAPModW * pLDAPModW = NULL;
  783. DWORD dwNumAttributes = 4;
  784. DWORD dwError = 0;
  785. WCHAR Buffer[64];
  786. if (!pWirelessPolicyObject->pszWirelessName ||
  787. !*pWirelessPolicyObject->pszWirelessName) {
  788. dwNumAttributes--;
  789. }
  790. if (!pWirelessPolicyObject->pszDescription ||
  791. !*pWirelessPolicyObject->pszDescription) {
  792. dwNumAttributes--;
  793. }
  794. ppLDAPModW = (LDAPModW **) AllocPolMem(
  795. (dwNumAttributes+1) * sizeof(LDAPModW*)
  796. );
  797. if (!ppLDAPModW) {
  798. dwError = ERROR_OUTOFMEMORY;
  799. BAIL_ON_WIN32_ERROR(dwError);
  800. }
  801. pLDAPModW = (LDAPModW *) AllocPolMem(
  802. dwNumAttributes * sizeof(LDAPModW)
  803. );
  804. if (!pLDAPModW) {
  805. dwError = ERROR_OUTOFMEMORY;
  806. BAIL_ON_WIN32_ERROR(dwError);
  807. }
  808. //
  809. // 2. msieee80211-ID
  810. //
  811. ppLDAPModW[i] = pLDAPModW + i;
  812. dwError = AllocatePolString(
  813. L"msieee80211-ID",
  814. &(pLDAPModW +i)->mod_type
  815. );
  816. BAIL_ON_WIN32_ERROR(dwError);
  817. dwError = AllocateLDAPStringValue(
  818. pWirelessPolicyObject->pszWirelessID,
  819. (PLDAPOBJECT *)&(pLDAPModW +i)->mod_values
  820. );
  821. BAIL_ON_WIN32_ERROR(dwError);
  822. (pLDAPModW + i)->mod_op |= LDAP_MOD_REPLACE;
  823. i++;
  824. //
  825. // 3. msieee80211-DataType
  826. //
  827. ppLDAPModW[i] = pLDAPModW + i;
  828. dwError = AllocatePolString(
  829. L"msieee80211-DataType",
  830. &(pLDAPModW +i)->mod_type
  831. );
  832. BAIL_ON_WIN32_ERROR(dwError);
  833. _itow( pWirelessPolicyObject->dwWirelessDataType, Buffer, 10 );
  834. dwError = AllocateLDAPStringValue(
  835. Buffer,
  836. (PLDAPOBJECT *)&(pLDAPModW +i)->mod_values
  837. );
  838. BAIL_ON_WIN32_ERROR(dwError);
  839. (pLDAPModW + i)->mod_op |= LDAP_MOD_REPLACE;
  840. i++;
  841. //
  842. // 4. msieee80211-Data
  843. //
  844. ppLDAPModW[i] = pLDAPModW + i;
  845. dwError = AllocatePolString(
  846. L"msieee80211-Data",
  847. &(pLDAPModW +i)->mod_type
  848. );
  849. BAIL_ON_WIN32_ERROR(dwError);
  850. dwError = AllocateLDAPBinaryValue(
  851. pWirelessPolicyObject->pWirelessData,
  852. pWirelessPolicyObject->dwWirelessDataLen,
  853. (PLDAPOBJECT *)&(pLDAPModW +i)->mod_values
  854. );
  855. BAIL_ON_WIN32_ERROR(dwError);
  856. (pLDAPModW+i)->mod_op = LDAP_MOD_REPLACE | LDAP_MOD_BVALUES;
  857. i++;
  858. //
  859. // 5. description
  860. //
  861. if (pWirelessPolicyObject->pszDescription &&
  862. *pWirelessPolicyObject->pszDescription) {
  863. ppLDAPModW[i] = pLDAPModW + i;
  864. dwError = AllocatePolString(
  865. L"description",
  866. &(pLDAPModW +i)->mod_type
  867. );
  868. BAIL_ON_WIN32_ERROR(dwError);
  869. dwError = AllocateLDAPStringValue(
  870. pWirelessPolicyObject->pszDescription,
  871. (PLDAPOBJECT *)&(pLDAPModW +i)->mod_values
  872. );
  873. BAIL_ON_WIN32_ERROR(dwError);
  874. (pLDAPModW + i)->mod_op |= LDAP_MOD_REPLACE;
  875. i++;
  876. }
  877. *pppLDAPModW = ppLDAPModW;
  878. return(dwError);
  879. error:
  880. if (ppLDAPModW) {
  881. FreeLDAPModWs(
  882. ppLDAPModW
  883. );
  884. }
  885. *pppLDAPModW = NULL;
  886. return(dwError);
  887. }
  888. DWORD
  889. GenerateSpecificPolicyQuery(
  890. GUID PolicyIdentifier,
  891. LPWSTR * ppszPolicyString
  892. )
  893. {
  894. DWORD dwError = ERROR_SUCCESS;
  895. WCHAR szGuid[MAX_PATH];
  896. WCHAR szCommonName[MAX_PATH];
  897. LPWSTR pszStringUuid = NULL;
  898. DWORD dwLength = 0;
  899. LPWSTR pszPolicyString = NULL;
  900. szGuid[0] = L'\0';
  901. szCommonName[0] = L'\0';
  902. dwError = UuidToString(
  903. &PolicyIdentifier,
  904. &pszStringUuid
  905. );
  906. BAIL_ON_WIN32_ERROR(dwError);
  907. wcscpy(szGuid, L"{");
  908. wcscat(szGuid, pszStringUuid);
  909. wcscat(szGuid, L"}");
  910. wcscpy(szCommonName, L"cn=msieee80211-Policy");
  911. wcscat(szCommonName, szGuid);
  912. //
  913. // Compute Length of Buffer to be allocated
  914. //
  915. dwLength = wcslen(L"(&(objectclass=msieee80211-Policy)");
  916. dwLength += wcslen(L"(");
  917. dwLength += wcslen(szCommonName);
  918. dwLength += wcslen(L"))");
  919. pszPolicyString = (LPWSTR) AllocPolMem((dwLength + 1)*sizeof(WCHAR));
  920. if (!pszPolicyString) {
  921. dwError = ERROR_OUTOFMEMORY;
  922. BAIL_ON_WIN32_ERROR(dwError);
  923. }
  924. wcscpy(pszPolicyString, L"(&(objectclass=msieee80211-Policy)");
  925. wcscat(pszPolicyString, L"(");
  926. wcscat(pszPolicyString, szCommonName);
  927. wcscat(pszPolicyString, L"))");
  928. *ppszPolicyString = pszPolicyString;
  929. cleanup:
  930. if (pszStringUuid) {
  931. RpcStringFree(&pszStringUuid);
  932. }
  933. return(dwError);
  934. error:
  935. if (pszPolicyString) {
  936. FreePolMem(pszPolicyString);
  937. }
  938. *ppszPolicyString = NULL;
  939. goto cleanup;
  940. }
  941. DWORD
  942. DirDeleteWirelessPolicyData(
  943. HLDAP hLdapBindHandle,
  944. LPWSTR pszWirelessRootContainer,
  945. PWIRELESS_POLICY_DATA pWirelessPolicyData
  946. )
  947. {
  948. DWORD dwError = 0;
  949. PWIRELESS_POLICY_OBJECT pWirelessPolicyObject = NULL;
  950. dwError = DirMarshallWirelessPolicyObject(
  951. pWirelessPolicyData,
  952. pszWirelessRootContainer,
  953. &pWirelessPolicyObject
  954. );
  955. BAIL_ON_WIN32_ERROR(dwError);
  956. dwError = LdapDeleteS(
  957. hLdapBindHandle,
  958. pWirelessPolicyObject->pszWirelessOwnersReference
  959. );
  960. BAIL_ON_WIN32_ERROR(dwError);
  961. error:
  962. if (pWirelessPolicyObject) {
  963. FreeWirelessPolicyObject(pWirelessPolicyObject);
  964. }
  965. return(dwError);
  966. }
  967. DWORD
  968. ConvertGuidToDirPolicyString(
  969. GUID PolicyIdentifier,
  970. LPWSTR pszWirelessRootContainer,
  971. LPWSTR * ppszWirelessPolicyReference
  972. )
  973. {
  974. DWORD dwError = 0;
  975. LPWSTR pszStringUuid = NULL;
  976. WCHAR szGuidString[MAX_PATH];
  977. WCHAR szPolicyReference[MAX_PATH];
  978. LPWSTR pszWirelessPolicyReference = NULL;
  979. dwError = UuidToString(
  980. &PolicyIdentifier,
  981. &pszStringUuid
  982. );
  983. BAIL_ON_WIN32_ERROR(dwError);
  984. szGuidString[0] = L'\0';
  985. wcscpy(szGuidString, L"{");
  986. wcscat(szGuidString, pszStringUuid);
  987. wcscat(szGuidString, L"}");
  988. szPolicyReference[0] = L'\0';
  989. wcscpy(szPolicyReference,L"CN=msieee80211-Policy");
  990. wcscat(szPolicyReference, szGuidString);
  991. wcscat(szPolicyReference, L",");
  992. wcscat(szPolicyReference, pszWirelessRootContainer);
  993. pszWirelessPolicyReference = AllocPolStr(
  994. szPolicyReference
  995. );
  996. if (!pszWirelessPolicyReference) {
  997. dwError = ERROR_OUTOFMEMORY;
  998. BAIL_ON_WIN32_ERROR(dwError);
  999. }
  1000. *ppszWirelessPolicyReference = pszWirelessPolicyReference;
  1001. cleanup:
  1002. if (pszStringUuid) {
  1003. RpcStringFree(&pszStringUuid);
  1004. }
  1005. return(dwError);
  1006. error:
  1007. *ppszWirelessPolicyReference = NULL;
  1008. goto cleanup;
  1009. }
  1010. DWORD
  1011. DirGetWirelessPolicyData(
  1012. HLDAP hLdapBindHandle,
  1013. LPWSTR pszWirelessRootContainer,
  1014. GUID PolicyIdentifier,
  1015. PWIRELESS_POLICY_DATA * ppWirelessPolicyData
  1016. )
  1017. {
  1018. DWORD dwError = 0;
  1019. LPWSTR pszPolicyString = NULL;
  1020. LDAPMessage * res = NULL;
  1021. DWORD dwCount = 0;
  1022. LDAPMessage * e = NULL;
  1023. PWIRELESS_POLICY_OBJECT pWirelessPolicyObject = NULL;
  1024. *ppWirelessPolicyData = NULL;
  1025. dwError = GenerateSpecificPolicyQuery(
  1026. PolicyIdentifier,
  1027. &pszPolicyString
  1028. );
  1029. BAIL_ON_WIN32_ERROR(dwError);
  1030. dwError = LdapSearchST(
  1031. hLdapBindHandle,
  1032. pszWirelessRootContainer,
  1033. LDAP_SCOPE_ONELEVEL,
  1034. pszPolicyString,
  1035. PolicyDNAttributes,
  1036. 0,
  1037. NULL,
  1038. &res
  1039. );
  1040. BAIL_ON_WIN32_ERROR(dwError);
  1041. dwCount = LdapCountEntries(
  1042. hLdapBindHandle,
  1043. res
  1044. );
  1045. if (!dwCount) {
  1046. dwError = ERROR_DS_NO_ATTRIBUTE_OR_VALUE;
  1047. BAIL_ON_WIN32_ERROR(dwError);
  1048. }
  1049. dwError = LdapFirstEntry(
  1050. hLdapBindHandle,
  1051. res,
  1052. &e
  1053. );
  1054. BAIL_ON_WIN32_ERROR(dwError);
  1055. dwError = UnMarshallPolicyObject2(
  1056. hLdapBindHandle,
  1057. e,
  1058. &pWirelessPolicyObject
  1059. );
  1060. BAIL_ON_WIN32_ERROR(dwError);
  1061. dwError = DirUnmarshallWirelessPolicyData(
  1062. pWirelessPolicyObject,
  1063. ppWirelessPolicyData
  1064. );
  1065. BAIL_ON_WIN32_ERROR(dwError);
  1066. error:
  1067. if (pszPolicyString) {
  1068. FreePolStr(pszPolicyString);
  1069. }
  1070. if (res) {
  1071. LdapMsgFree(res);
  1072. }
  1073. if (pWirelessPolicyObject) {
  1074. FreeWirelessPolicyObject(pWirelessPolicyObject);
  1075. }
  1076. return (dwError);
  1077. }