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.

1934 lines
44 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: adscopy.cxx
  7. //
  8. // Contents: NDS Object to Variant Copy Routines
  9. //
  10. // Functions:
  11. //
  12. // History: 25-Apr-96 KrishnaG Created.
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "oleds.hxx"
  16. HRESULT
  17. AdsClear(
  18. PADSVALUE lpAdsValue
  19. )
  20. {
  21. HRESULT hr = S_OK;
  22. switch (lpAdsValue->dwType){
  23. case ADSTYPE_DN_STRING:
  24. FreeADsStr(lpAdsValue->DNString);
  25. break;
  26. case ADSTYPE_CASE_EXACT_STRING:
  27. FreeADsStr(lpAdsValue->CaseExactString);
  28. break;
  29. case ADSTYPE_CASE_IGNORE_STRING:
  30. FreeADsStr(lpAdsValue->CaseIgnoreString);
  31. break;
  32. case ADSTYPE_PRINTABLE_STRING:
  33. FreeADsStr(lpAdsValue->PrintableString);
  34. break;
  35. case ADSTYPE_NUMERIC_STRING:
  36. FreeADsStr(lpAdsValue->NumericString);
  37. break;
  38. case ADSTYPE_BOOLEAN:
  39. break;
  40. case ADSTYPE_INTEGER:
  41. break;
  42. case ADSTYPE_OCTET_STRING:
  43. if (lpAdsValue->OctetString.lpValue) {
  44. FreeADsMem(lpAdsValue->OctetString.lpValue);
  45. }
  46. break;
  47. case ADSTYPE_PROV_SPECIFIC:
  48. if (lpAdsValue->ProviderSpecific.lpValue) {
  49. FreeADsMem(lpAdsValue->ProviderSpecific.lpValue);
  50. }
  51. break;
  52. case ADSTYPE_UTC_TIME:
  53. break;
  54. case ADSTYPE_CASEIGNORE_LIST:
  55. {
  56. PADS_CASEIGNORE_LIST pCurrent = NULL;
  57. PADS_CASEIGNORE_LIST pNext = NULL;
  58. pNext = lpAdsValue->pCaseIgnoreList;
  59. while (pNext) {
  60. pCurrent = pNext;
  61. pNext = pCurrent->Next;
  62. if (pCurrent->String) {
  63. FreeADsStr(pCurrent->String);
  64. }
  65. FreeADsMem(pCurrent);
  66. }
  67. break;
  68. }
  69. case ADSTYPE_FAXNUMBER:
  70. if (lpAdsValue->pFaxNumber) {
  71. if (lpAdsValue->pFaxNumber->Parameters) {
  72. FreeADsMem(lpAdsValue->pFaxNumber->Parameters);
  73. }
  74. if (lpAdsValue->pFaxNumber->TelephoneNumber) {
  75. FreeADsMem(lpAdsValue->pFaxNumber->TelephoneNumber);
  76. }
  77. FreeADsMem(lpAdsValue->pFaxNumber);
  78. }
  79. break;
  80. case ADSTYPE_NETADDRESS:
  81. if (lpAdsValue->pNetAddress) {
  82. if (lpAdsValue->pNetAddress->Address) {
  83. FreeADsMem(lpAdsValue->pNetAddress->Address);
  84. }
  85. FreeADsMem(lpAdsValue->pNetAddress);
  86. }
  87. break;
  88. case ADSTYPE_OCTET_LIST:
  89. {
  90. PADS_OCTET_LIST pCurrent = NULL;
  91. PADS_OCTET_LIST pNext = NULL;
  92. pNext = lpAdsValue->pOctetList;
  93. while (pNext) {
  94. pCurrent = pNext;
  95. pNext = pCurrent->Next;
  96. if (pCurrent->Data) {
  97. FreeADsMem(pCurrent->Data);
  98. }
  99. FreeADsMem(pCurrent);
  100. }
  101. break;
  102. }
  103. case ADSTYPE_EMAIL:
  104. if (lpAdsValue->Email.Address) {
  105. FreeADsStr(lpAdsValue->Email.Address);
  106. }
  107. break;
  108. case ADSTYPE_PATH:
  109. if (lpAdsValue->pPath) {
  110. if (lpAdsValue->pPath->VolumeName) {
  111. FreeADsStr(lpAdsValue->pPath->VolumeName);
  112. }
  113. if (lpAdsValue->pPath->Path) {
  114. FreeADsStr(lpAdsValue->pPath->Path);
  115. }
  116. FreeADsMem(lpAdsValue->pPath);
  117. }
  118. break;
  119. case ADSTYPE_REPLICAPOINTER:
  120. if (lpAdsValue->pReplicaPointer) {
  121. if (lpAdsValue->pReplicaPointer->ServerName) {
  122. FreeADsStr(lpAdsValue->pReplicaPointer->ServerName );
  123. }
  124. if (lpAdsValue->pReplicaPointer->ReplicaAddressHints->Address) {
  125. FreeADsMem(lpAdsValue->pReplicaPointer->ReplicaAddressHints->Address);
  126. }
  127. FreeADsMem(lpAdsValue->pReplicaPointer);
  128. }
  129. break;
  130. case ADSTYPE_TIMESTAMP:
  131. break;
  132. case ADSTYPE_POSTALADDRESS:
  133. {
  134. long i;
  135. if (lpAdsValue->pPostalAddress) {
  136. for (i=0;i<6;i++) {
  137. if (lpAdsValue->pPostalAddress->PostalAddress[i]) {
  138. FreeADsStr(lpAdsValue->pPostalAddress->PostalAddress[i]);
  139. }
  140. }
  141. FreeADsMem(lpAdsValue->pPostalAddress);
  142. }
  143. break;
  144. }
  145. case ADSTYPE_BACKLINK:
  146. if (lpAdsValue->BackLink.ObjectName) {
  147. FreeADsStr(lpAdsValue->BackLink.ObjectName);
  148. }
  149. break;
  150. case ADSTYPE_TYPEDNAME:
  151. if (lpAdsValue->pTypedName) {
  152. if (lpAdsValue->pTypedName->ObjectName) {
  153. FreeADsStr(lpAdsValue->pTypedName->ObjectName);
  154. }
  155. FreeADsMem(lpAdsValue->pTypedName);
  156. }
  157. break;
  158. case ADSTYPE_HOLD:
  159. if (lpAdsValue->Hold.ObjectName) {
  160. FreeADsStr(lpAdsValue->Hold.ObjectName);
  161. }
  162. break;
  163. case ADSTYPE_NT_SECURITY_DESCRIPTOR:
  164. if (lpAdsValue->SecurityDescriptor.lpValue) {
  165. FreeADsMem(lpAdsValue->SecurityDescriptor.lpValue);
  166. }
  167. break;
  168. case ADSTYPE_OBJECT_CLASS:
  169. FreeADsStr(lpAdsValue->ClassName);
  170. break;
  171. case ADSTYPE_DN_WITH_BINARY:
  172. if (lpAdsValue->pDNWithBinary) {
  173. if (lpAdsValue->pDNWithBinary->lpBinaryValue) {
  174. FreeADsMem(lpAdsValue->pDNWithBinary->lpBinaryValue);
  175. }
  176. if (lpAdsValue->pDNWithBinary->pszDNString) {
  177. FreeADsStr(lpAdsValue->pDNWithBinary->pszDNString);
  178. }
  179. FreeADsMem(lpAdsValue->pDNWithBinary);
  180. }
  181. break;
  182. case ADSTYPE_DN_WITH_STRING:
  183. if (lpAdsValue->pDNWithString) {
  184. if (lpAdsValue->pDNWithString->pszStringValue) {
  185. FreeADsMem(lpAdsValue->pDNWithString->pszStringValue);
  186. }
  187. if (lpAdsValue->pDNWithString->pszDNString) {
  188. FreeADsStr(lpAdsValue->pDNWithString->pszDNString);
  189. }
  190. FreeADsMem(lpAdsValue->pDNWithString);
  191. }
  192. break;
  193. default:
  194. break;
  195. }
  196. memset(lpAdsValue, 0, sizeof(ADSVALUE));
  197. RRETURN(S_OK);
  198. }
  199. HRESULT
  200. AdsCopyDNString(
  201. PADSVALUE lpAdsSrcValue,
  202. PADSVALUE lpAdsDestValue
  203. )
  204. {
  205. HRESULT hr = S_OK;
  206. if(lpAdsSrcValue->dwType != ADSTYPE_DN_STRING){
  207. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  208. }
  209. lpAdsDestValue->dwType = ADSTYPE_DN_STRING;
  210. lpAdsDestValue->DNString =
  211. AllocADsStr(
  212. lpAdsSrcValue->DNString
  213. );
  214. if (lpAdsSrcValue->DNString
  215. && !lpAdsDestValue->DNString) {
  216. hr = E_OUTOFMEMORY;
  217. }
  218. RRETURN(hr);
  219. }
  220. HRESULT
  221. AdsCopyCaseExactString(
  222. PADSVALUE lpAdsSrcValue,
  223. PADSVALUE lpAdsDestValue
  224. )
  225. {
  226. HRESULT hr = S_OK;
  227. if(lpAdsSrcValue->dwType != ADSTYPE_CASE_EXACT_STRING){
  228. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  229. }
  230. lpAdsDestValue->dwType = ADSTYPE_CASE_EXACT_STRING;
  231. lpAdsDestValue->CaseExactString =
  232. AllocADsStr(
  233. lpAdsSrcValue->CaseExactString
  234. );
  235. if (lpAdsSrcValue->CaseExactString
  236. && !lpAdsDestValue->CaseExactString) {
  237. hr = E_OUTOFMEMORY;
  238. }
  239. RRETURN(hr);
  240. }
  241. HRESULT
  242. AdsCopyCaseIgnoreString(
  243. PADSVALUE lpAdsSrcValue,
  244. PADSVALUE lpAdsDestValue
  245. )
  246. {
  247. HRESULT hr = S_OK;
  248. if(lpAdsSrcValue->dwType != ADSTYPE_CASE_IGNORE_STRING){
  249. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  250. }
  251. lpAdsDestValue->dwType = ADSTYPE_CASE_IGNORE_STRING;
  252. lpAdsDestValue->CaseIgnoreString =
  253. AllocADsStr(
  254. lpAdsSrcValue->CaseIgnoreString
  255. );
  256. if (lpAdsSrcValue->CaseIgnoreString
  257. && !lpAdsDestValue->CaseIgnoreString) {
  258. hr = E_OUTOFMEMORY;
  259. }
  260. RRETURN(hr);
  261. }
  262. HRESULT
  263. AdsCopyPrintableString(
  264. PADSVALUE lpAdsSrcValue,
  265. PADSVALUE lpAdsDestValue
  266. )
  267. {
  268. HRESULT hr = S_OK;
  269. if(lpAdsSrcValue->dwType != ADSTYPE_PRINTABLE_STRING){
  270. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  271. }
  272. lpAdsDestValue->dwType = ADSTYPE_PRINTABLE_STRING;
  273. lpAdsDestValue->PrintableString =
  274. AllocADsStr(
  275. lpAdsSrcValue->PrintableString
  276. );
  277. if (lpAdsSrcValue->PrintableString
  278. && !lpAdsDestValue->PrintableString) {
  279. hr = E_OUTOFMEMORY;
  280. }
  281. RRETURN(hr);
  282. }
  283. HRESULT
  284. AdsCopyNumericString(
  285. PADSVALUE lpAdsSrcValue,
  286. PADSVALUE lpAdsDestValue
  287. )
  288. {
  289. HRESULT hr = S_OK;
  290. if(lpAdsSrcValue->dwType != ADSTYPE_NUMERIC_STRING){
  291. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  292. }
  293. lpAdsDestValue->dwType = ADSTYPE_NUMERIC_STRING;
  294. lpAdsDestValue->NumericString =
  295. AllocADsStr(
  296. lpAdsSrcValue->NumericString
  297. );
  298. if (lpAdsSrcValue->NumericString
  299. && !lpAdsDestValue->NumericString) {
  300. hr = E_OUTOFMEMORY;
  301. }
  302. RRETURN(hr);
  303. }
  304. HRESULT
  305. AdsCopyBoolean(
  306. PADSVALUE lpAdsSrcValue,
  307. PADSVALUE lpAdsDestValue
  308. )
  309. {
  310. HRESULT hr = S_OK;
  311. if(lpAdsSrcValue->dwType != ADSTYPE_BOOLEAN){
  312. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  313. }
  314. lpAdsDestValue->dwType = ADSTYPE_BOOLEAN;
  315. lpAdsDestValue->Boolean =
  316. lpAdsSrcValue->Boolean;
  317. RRETURN(hr);
  318. }
  319. HRESULT
  320. AdsCopyInteger(
  321. PADSVALUE lpAdsSrcValue,
  322. PADSVALUE lpAdsDestValue
  323. )
  324. {
  325. HRESULT hr = S_OK;
  326. if(lpAdsSrcValue->dwType != ADSTYPE_INTEGER){
  327. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  328. }
  329. lpAdsDestValue->dwType = ADSTYPE_INTEGER;
  330. lpAdsDestValue->Integer =
  331. lpAdsSrcValue->Integer;
  332. RRETURN(hr);
  333. }
  334. HRESULT
  335. AdsCopyLargeInteger(
  336. PADSVALUE lpAdsSrcValue,
  337. PADSVALUE lpAdsDestValue
  338. )
  339. {
  340. HRESULT hr = S_OK;
  341. if(lpAdsSrcValue->dwType != ADSTYPE_LARGE_INTEGER){
  342. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  343. }
  344. lpAdsDestValue->dwType = ADSTYPE_LARGE_INTEGER;
  345. lpAdsDestValue->LargeInteger =
  346. lpAdsSrcValue->LargeInteger;
  347. RRETURN(hr);
  348. }
  349. HRESULT
  350. AdsCopyOctetString(
  351. PADSVALUE lpAdsSrcValue,
  352. PADSVALUE lpAdsDestValue
  353. )
  354. {
  355. LPBYTE lpByteStream = NULL;
  356. DWORD dwNumBytes = 0;
  357. HRESULT hr = S_OK;
  358. if(lpAdsSrcValue->dwType != ADSTYPE_OCTET_STRING){
  359. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  360. }
  361. lpAdsDestValue->dwType = ADSTYPE_OCTET_STRING;
  362. dwNumBytes = lpAdsSrcValue->OctetString.dwLength;
  363. lpByteStream = (LPBYTE)AllocADsMem(dwNumBytes);
  364. if (dwNumBytes && !lpByteStream) {
  365. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  366. }
  367. memcpy(
  368. lpByteStream,
  369. lpAdsSrcValue->OctetString.lpValue,
  370. dwNumBytes
  371. );
  372. lpAdsDestValue->OctetString.dwLength = dwNumBytes;
  373. lpAdsDestValue->OctetString.lpValue = lpByteStream;
  374. error :
  375. RRETURN(hr);
  376. }
  377. HRESULT
  378. AdsCopyProvSpecific(
  379. PADSVALUE lpAdsSrcValue,
  380. PADSVALUE lpAdsDestValue
  381. )
  382. {
  383. LPBYTE lpByteStream = NULL;
  384. DWORD dwNumBytes = 0;
  385. HRESULT hr = S_OK;
  386. if(lpAdsSrcValue->dwType != ADSTYPE_PROV_SPECIFIC){
  387. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  388. }
  389. lpAdsDestValue->dwType = ADSTYPE_PROV_SPECIFIC;
  390. dwNumBytes = lpAdsSrcValue->ProviderSpecific.dwLength;
  391. lpByteStream = (LPBYTE)AllocADsMem(dwNumBytes);
  392. if (!lpByteStream) {
  393. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  394. }
  395. memcpy(
  396. lpByteStream,
  397. lpAdsSrcValue->ProviderSpecific.lpValue,
  398. dwNumBytes
  399. );
  400. lpAdsDestValue->ProviderSpecific.dwLength = dwNumBytes;
  401. lpAdsDestValue->ProviderSpecific.lpValue = lpByteStream;
  402. RRETURN(hr);
  403. error:
  404. RRETURN(hr);
  405. }
  406. //
  407. // Was overloaded to handle IDispatch.
  408. // Removed overloading during code cleanup.
  409. //
  410. HRESULT
  411. AdsCopyNTSecurityDescriptor(
  412. PADSVALUE lpAdsSrcValue,
  413. CPropertyValue * lpPropValue,
  414. LPWSTR pszServerName,
  415. CCredentials& Credentials,
  416. BOOL fNTDSType
  417. )
  418. {
  419. LPBYTE lpByteStream = NULL;
  420. DWORD dwNumBytes = 0;
  421. HRESULT hr = S_OK;
  422. PADSVALUE lpAdsDestValue = lpPropValue->getADsValue();
  423. VARIANT vVarSec;
  424. VariantInit(&vVarSec);
  425. if(lpAdsSrcValue->dwType != ADSTYPE_NT_SECURITY_DESCRIPTOR){
  426. VariantClear(&vVarSec);
  427. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  428. }
  429. lpAdsDestValue->dwType = ADSTYPE_NT_SECURITY_DESCRIPTOR;
  430. dwNumBytes = lpAdsSrcValue->OctetString.dwLength;
  431. lpByteStream = (LPBYTE)AllocADsMem(dwNumBytes);
  432. if (!lpByteStream) {
  433. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  434. }
  435. memcpy(
  436. lpByteStream,
  437. lpAdsSrcValue->OctetString.lpValue,
  438. dwNumBytes
  439. );
  440. lpAdsDestValue->OctetString.dwLength = dwNumBytes;
  441. lpAdsDestValue->OctetString.lpValue = lpByteStream;
  442. //
  443. // Now attempt to conver to security descriptor
  444. //
  445. hr = ConvertSecDescriptorToVariant(
  446. pszServerName,
  447. Credentials,
  448. lpAdsSrcValue->OctetString.lpValue,
  449. &vVarSec,
  450. fNTDSType
  451. );
  452. BAIL_ON_FAILURE(hr);
  453. hr = lpPropValue->put_SecurityDescriptor(V_DISPATCH(&vVarSec));
  454. BAIL_ON_FAILURE(hr);
  455. VariantClear(&vVarSec);
  456. RRETURN(hr);
  457. error:
  458. if(lpByteStream){
  459. FreeADsMem(lpByteStream);
  460. }
  461. VariantClear(&vVarSec);
  462. RRETURN(hr);
  463. }
  464. HRESULT
  465. AdsCopyTime(
  466. PADSVALUE lpAdsSrcValue,
  467. PADSVALUE lpAdsDestValue
  468. )
  469. {
  470. HRESULT hr = S_OK;
  471. if(lpAdsSrcValue->dwType != ADSTYPE_UTC_TIME){
  472. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  473. }
  474. lpAdsDestValue->dwType = ADSTYPE_UTC_TIME;
  475. lpAdsDestValue->UTCTime = lpAdsSrcValue->UTCTime;
  476. RRETURN(hr);
  477. }
  478. HRESULT
  479. AdsCopyEmail(
  480. PADSVALUE lpAdsSrcValue,
  481. PADSVALUE lpAdsDestValue
  482. )
  483. {
  484. HRESULT hr = S_OK;
  485. if(lpAdsSrcValue->dwType != ADSTYPE_EMAIL){
  486. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  487. }
  488. lpAdsDestValue->dwType = ADSTYPE_EMAIL;
  489. lpAdsDestValue->Email.Type = lpAdsSrcValue->Email.Type;
  490. lpAdsDestValue->Email.Address = AllocADsStr(lpAdsSrcValue->Email.Address);
  491. if (!lpAdsDestValue->Email.Address) {
  492. hr = E_OUTOFMEMORY;
  493. BAIL_ON_FAILURE(hr);
  494. }
  495. error:
  496. RRETURN(hr);
  497. }
  498. HRESULT
  499. AdsCopyNetAddress(
  500. PADSVALUE lpAdsSrcValue,
  501. PADSVALUE lpAdsDestValue
  502. )
  503. {
  504. HRESULT hr = S_OK;
  505. LPBYTE lpByteStream = NULL;
  506. DWORD dwNumBytes = 0;
  507. if(lpAdsSrcValue->dwType != ADSTYPE_NETADDRESS){
  508. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  509. }
  510. if (!lpAdsSrcValue->pNetAddress) {
  511. RRETURN(hr = E_FAIL);
  512. }
  513. lpAdsDestValue->dwType = ADSTYPE_NETADDRESS;
  514. lpAdsDestValue->pNetAddress = (PADS_NETADDRESS)AllocADsMem(sizeof(ADS_NETADDRESS));
  515. if (!lpAdsDestValue->pNetAddress) {
  516. hr = E_OUTOFMEMORY;
  517. BAIL_ON_FAILURE(hr);
  518. }
  519. lpAdsDestValue->pNetAddress->AddressType = lpAdsSrcValue->pNetAddress->AddressType;
  520. dwNumBytes = lpAdsSrcValue->pNetAddress->AddressLength;
  521. lpByteStream = (LPBYTE)AllocADsMem(dwNumBytes);
  522. if (!lpByteStream) {
  523. hr = E_OUTOFMEMORY;
  524. BAIL_ON_FAILURE(hr);
  525. }
  526. memcpy(
  527. lpByteStream,
  528. lpAdsSrcValue->pNetAddress->Address,
  529. dwNumBytes
  530. );
  531. lpAdsDestValue->pNetAddress->AddressLength = dwNumBytes;
  532. lpAdsDestValue->pNetAddress->Address = lpByteStream;
  533. RRETURN(hr);
  534. error:
  535. if(lpAdsDestValue->pNetAddress) {
  536. FreeADsMem(lpAdsDestValue->pNetAddress);
  537. }
  538. RRETURN(hr);
  539. }
  540. HRESULT
  541. AdsCopyOctetList(
  542. PADSVALUE lpAdsSrcValue,
  543. PADSVALUE lpAdsDestValue
  544. )
  545. {
  546. HRESULT hr = S_OK;
  547. PADS_OCTET_LIST pCurrent = NULL;
  548. PADS_OCTET_LIST pResult = NULL;
  549. PADS_OCTET_LIST pNext = NULL;
  550. if(lpAdsSrcValue->dwType != ADSTYPE_OCTET_LIST){
  551. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  552. }
  553. if (!lpAdsSrcValue->pOctetList) {
  554. RRETURN(hr = E_FAIL);
  555. }
  556. lpAdsDestValue->dwType = ADSTYPE_OCTET_LIST;
  557. lpAdsDestValue->pOctetList = (PADS_OCTET_LIST)AllocADsMem(sizeof(ADS_OCTET_LIST));
  558. if (!lpAdsDestValue->pOctetList) {
  559. hr = E_OUTOFMEMORY;
  560. BAIL_ON_FAILURE(hr);
  561. }
  562. pCurrent = lpAdsSrcValue->pOctetList;
  563. pResult = lpAdsDestValue->pOctetList;
  564. hr = CopyOctetString(
  565. pCurrent->Length,
  566. pCurrent->Data,
  567. &pResult->Length,
  568. &pResult->Data);
  569. BAIL_ON_FAILURE(hr);
  570. while (pCurrent->Next) {
  571. pResult->Next = (PADS_OCTET_LIST)AllocADsMem(
  572. sizeof(ADS_OCTET_LIST));
  573. if (!pResult->Next) {
  574. hr = E_OUTOFMEMORY;
  575. BAIL_ON_FAILURE(hr);
  576. }
  577. pResult = pResult->Next;
  578. pCurrent = pCurrent->Next;
  579. hr = CopyOctetString(
  580. pCurrent->Length,
  581. pCurrent->Data,
  582. &pResult->Length,
  583. &pResult->Data);
  584. BAIL_ON_FAILURE(hr);
  585. }
  586. pResult->Next = NULL;
  587. RRETURN(hr);
  588. error:
  589. pResult = lpAdsDestValue->pOctetList;
  590. while ( pResult) {
  591. pNext = pResult->Next;
  592. FreeADsMem(pResult);
  593. pResult = pNext;
  594. }
  595. RRETURN(hr);
  596. }
  597. HRESULT
  598. AdsCopyCaseIgnoreList(
  599. PADSVALUE lpAdsSrcValue,
  600. PADSVALUE lpAdsDestValue
  601. )
  602. {
  603. HRESULT hr = S_OK;
  604. PADS_CASEIGNORE_LIST pCurrent = NULL;
  605. PADS_CASEIGNORE_LIST pResult = NULL;
  606. PADS_CASEIGNORE_LIST pNext = NULL;
  607. if(lpAdsSrcValue->dwType != ADSTYPE_CASEIGNORE_LIST){
  608. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  609. }
  610. if (!lpAdsSrcValue->pCaseIgnoreList) {
  611. RRETURN(hr = E_FAIL);
  612. }
  613. lpAdsDestValue->pCaseIgnoreList = (PADS_CASEIGNORE_LIST)AllocADsMem(sizeof(ADS_CASEIGNORE_LIST));
  614. if (!lpAdsDestValue->pCaseIgnoreList) {
  615. hr = E_OUTOFMEMORY;
  616. BAIL_ON_FAILURE(hr);
  617. }
  618. lpAdsDestValue->dwType = ADSTYPE_CASEIGNORE_LIST;
  619. pCurrent = lpAdsSrcValue->pCaseIgnoreList;
  620. pResult = lpAdsDestValue->pCaseIgnoreList;
  621. pResult->String = AllocADsStr(pCurrent->String);
  622. if (!pResult->String) {
  623. hr = E_OUTOFMEMORY;
  624. BAIL_ON_FAILURE(hr);
  625. }
  626. while (pCurrent->Next) {
  627. pResult->Next = (PADS_CASEIGNORE_LIST)AllocADsMem(
  628. sizeof(ADS_CASEIGNORE_LIST));
  629. if (!pResult->Next) {
  630. hr = E_OUTOFMEMORY;
  631. BAIL_ON_FAILURE(hr);
  632. }
  633. pResult = pResult->Next;
  634. pCurrent = pCurrent->Next;
  635. pResult->String = AllocADsStr(pCurrent->String);
  636. if (!pResult->String) {
  637. hr = E_OUTOFMEMORY;
  638. BAIL_ON_FAILURE(hr);
  639. }
  640. }
  641. pResult->Next = NULL;
  642. RRETURN(hr);
  643. error:
  644. pResult = lpAdsDestValue->pCaseIgnoreList;
  645. while ( pResult) {
  646. pNext = pResult->Next;
  647. if (pResult->String) {
  648. FreeADsStr(pResult->String);
  649. }
  650. FreeADsMem(pResult);
  651. pResult = pNext;
  652. }
  653. RRETURN(hr);
  654. }
  655. HRESULT
  656. AdsCopyPath(
  657. PADSVALUE lpAdsSrcValue,
  658. PADSVALUE lpAdsDestValue
  659. )
  660. {
  661. HRESULT hr = S_OK;
  662. if(lpAdsSrcValue->dwType != ADSTYPE_PATH){
  663. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  664. }
  665. if (!lpAdsSrcValue->pPath) {
  666. RRETURN(hr = E_FAIL);
  667. }
  668. lpAdsDestValue->dwType = ADSTYPE_PATH;
  669. lpAdsDestValue->pPath = (PADS_PATH)AllocADsMem(sizeof(ADS_PATH));
  670. if (!lpAdsDestValue->pPath) {
  671. hr = E_OUTOFMEMORY;
  672. BAIL_ON_FAILURE(hr);
  673. }
  674. lpAdsDestValue->pPath->Type = lpAdsSrcValue->pPath->Type;
  675. lpAdsDestValue->pPath->VolumeName = AllocADsStr(lpAdsSrcValue->pPath->VolumeName);
  676. if (!lpAdsDestValue->pPath->VolumeName) {
  677. hr = E_OUTOFMEMORY;
  678. BAIL_ON_FAILURE(hr);
  679. }
  680. lpAdsDestValue->pPath->Path = AllocADsStr(lpAdsSrcValue->pPath->Path);
  681. if (!lpAdsDestValue->pPath->Path) {
  682. hr = E_OUTOFMEMORY;
  683. BAIL_ON_FAILURE(hr);
  684. }
  685. RRETURN(hr);
  686. error:
  687. if (lpAdsDestValue->pPath) {
  688. if (lpAdsDestValue->pPath->VolumeName) {
  689. FreeADsStr(lpAdsDestValue->pPath->VolumeName);
  690. }
  691. FreeADsMem(lpAdsDestValue->pPath);
  692. }
  693. RRETURN(hr);
  694. }
  695. HRESULT
  696. AdsCopyPostalAddress(
  697. PADSVALUE lpAdsSrcValue,
  698. PADSVALUE lpAdsDestValue
  699. )
  700. {
  701. HRESULT hr = S_OK;
  702. long i;
  703. if(lpAdsSrcValue->dwType != ADSTYPE_POSTALADDRESS){
  704. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  705. }
  706. if (!lpAdsSrcValue->pPostalAddress) {
  707. RRETURN(hr = E_FAIL);
  708. }
  709. lpAdsDestValue->pPostalAddress = (PADS_POSTALADDRESS)AllocADsMem(sizeof(ADS_POSTALADDRESS));
  710. if (!lpAdsDestValue->pPostalAddress) {
  711. hr = E_OUTOFMEMORY;
  712. BAIL_ON_FAILURE(hr);
  713. }
  714. lpAdsDestValue->dwType = ADSTYPE_POSTALADDRESS;
  715. for (i=0;i<6;i++) {
  716. lpAdsDestValue->pPostalAddress->PostalAddress[i] = AllocADsStr(lpAdsSrcValue->pPostalAddress->PostalAddress[i]);
  717. if (!lpAdsDestValue->pPostalAddress->PostalAddress[i]) {
  718. hr = E_OUTOFMEMORY;
  719. BAIL_ON_FAILURE(hr);
  720. }
  721. }
  722. RRETURN(hr);
  723. error:
  724. if (lpAdsDestValue->pPostalAddress) {
  725. //
  726. // Ideally I would need to loop only until i<5
  727. // Being extra cautious over here in case some other code gets
  728. // added after the for loop that returns an error which would
  729. // bring us over here
  730. //
  731. for (i=0;i<6;i++) {
  732. if (lpAdsDestValue->pPostalAddress->PostalAddress[i]) {
  733. FreeADsStr(lpAdsDestValue->pPostalAddress->PostalAddress[i]);
  734. }
  735. }
  736. FreeADsMem(lpAdsDestValue->pPostalAddress);
  737. }
  738. RRETURN(hr);
  739. }
  740. HRESULT
  741. AdsCopyBackLink(
  742. PADSVALUE lpAdsSrcValue,
  743. PADSVALUE lpAdsDestValue
  744. )
  745. {
  746. HRESULT hr = S_OK;
  747. if(lpAdsSrcValue->dwType != ADSTYPE_BACKLINK){
  748. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  749. }
  750. lpAdsDestValue->dwType = ADSTYPE_BACKLINK;
  751. lpAdsDestValue->BackLink.RemoteID = lpAdsSrcValue->BackLink.RemoteID;
  752. lpAdsDestValue->BackLink.ObjectName = AllocADsStr(lpAdsSrcValue->BackLink.ObjectName);
  753. if (!lpAdsDestValue->BackLink.ObjectName) {
  754. hr = E_OUTOFMEMORY;
  755. BAIL_ON_FAILURE(hr);
  756. }
  757. error:
  758. RRETURN(hr);
  759. }
  760. HRESULT
  761. AdsCopyTypedName(
  762. PADSVALUE lpAdsSrcValue,
  763. PADSVALUE lpAdsDestValue
  764. )
  765. {
  766. HRESULT hr = S_OK;
  767. LPWSTR ObjectName;
  768. DWORD Level;
  769. DWORD Interval;
  770. if(lpAdsSrcValue->dwType != ADSTYPE_TYPEDNAME){
  771. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  772. }
  773. if (!lpAdsSrcValue->pTypedName) {
  774. RRETURN(hr = E_FAIL);
  775. }
  776. lpAdsDestValue->dwType = ADSTYPE_TYPEDNAME;
  777. lpAdsDestValue->pTypedName = (PADS_TYPEDNAME)AllocADsMem(sizeof(ADS_TYPEDNAME));
  778. if (!lpAdsDestValue->pTypedName) {
  779. hr = E_OUTOFMEMORY;
  780. BAIL_ON_FAILURE(hr);
  781. }
  782. lpAdsDestValue->pTypedName->Level = lpAdsSrcValue->pTypedName->Level;
  783. lpAdsDestValue->pTypedName->Interval = lpAdsSrcValue->pTypedName->Interval;
  784. lpAdsDestValue->pTypedName->ObjectName = AllocADsStr(lpAdsSrcValue->pTypedName->ObjectName);
  785. if (!lpAdsDestValue->pTypedName->ObjectName) {
  786. hr = E_OUTOFMEMORY;
  787. BAIL_ON_FAILURE(hr);
  788. }
  789. RRETURN(hr);
  790. error:
  791. if (lpAdsDestValue->pTypedName) {
  792. FreeADsMem(lpAdsDestValue->pTypedName);
  793. }
  794. RRETURN(hr);
  795. }
  796. HRESULT
  797. AdsCopyHold(
  798. PADSVALUE lpAdsSrcValue,
  799. PADSVALUE lpAdsDestValue
  800. )
  801. {
  802. HRESULT hr = S_OK;
  803. if(lpAdsSrcValue->dwType != ADSTYPE_HOLD){
  804. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  805. }
  806. lpAdsDestValue->dwType = ADSTYPE_HOLD;
  807. lpAdsDestValue->Hold.Amount = lpAdsSrcValue->Hold.Amount;
  808. lpAdsDestValue->Hold.ObjectName = AllocADsStr(lpAdsSrcValue->Hold.ObjectName);
  809. if (!lpAdsDestValue->Hold.ObjectName) {
  810. hr = E_OUTOFMEMORY;
  811. BAIL_ON_FAILURE(hr);
  812. }
  813. error:
  814. RRETURN(hr);
  815. }
  816. HRESULT
  817. AdsCopyReplicaPointer(
  818. PADSVALUE lpAdsSrcValue,
  819. PADSVALUE lpAdsDestValue
  820. )
  821. {
  822. HRESULT hr = S_OK;
  823. LPBYTE lpByteStream = NULL;
  824. DWORD dwNumBytes = 0;
  825. if(lpAdsSrcValue->dwType != ADSTYPE_REPLICAPOINTER){
  826. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  827. }
  828. if (!lpAdsSrcValue->pReplicaPointer) {
  829. RRETURN(hr = E_FAIL);
  830. }
  831. lpAdsDestValue->dwType = ADSTYPE_REPLICAPOINTER;
  832. lpAdsDestValue->pReplicaPointer = (PADS_REPLICAPOINTER)AllocADsMem(sizeof(ADS_REPLICAPOINTER));
  833. if (!lpAdsDestValue->pReplicaPointer) {
  834. hr = E_OUTOFMEMORY;
  835. BAIL_ON_FAILURE(hr);
  836. }
  837. lpAdsDestValue->pReplicaPointer->ReplicaType = lpAdsSrcValue->pReplicaPointer->ReplicaType;
  838. lpAdsDestValue->pReplicaPointer->ReplicaNumber = lpAdsSrcValue->pReplicaPointer->ReplicaNumber;
  839. lpAdsDestValue->pReplicaPointer->Count = lpAdsSrcValue->pReplicaPointer->Count;
  840. lpAdsDestValue->pReplicaPointer->ServerName = AllocADsStr(lpAdsSrcValue->pReplicaPointer->ServerName);
  841. if (!lpAdsDestValue->pReplicaPointer->ServerName) {
  842. hr = E_OUTOFMEMORY;
  843. BAIL_ON_FAILURE(hr);
  844. }
  845. //
  846. // Doing NetAddress
  847. //
  848. lpAdsDestValue->pReplicaPointer->ReplicaAddressHints = (PADS_NETADDRESS)AllocADsMem(sizeof(ADS_NETADDRESS));
  849. if (!lpAdsDestValue->pReplicaPointer->ReplicaAddressHints) {
  850. hr = E_OUTOFMEMORY;
  851. BAIL_ON_FAILURE(hr);
  852. }
  853. lpAdsDestValue->pReplicaPointer->ReplicaAddressHints->AddressType = lpAdsSrcValue->pReplicaPointer->ReplicaAddressHints->AddressType;
  854. hr = CopyOctetString(
  855. lpAdsSrcValue->pReplicaPointer->ReplicaAddressHints->AddressLength,
  856. lpAdsSrcValue->pReplicaPointer->ReplicaAddressHints->Address,
  857. &lpAdsDestValue->pReplicaPointer->ReplicaAddressHints->AddressLength,
  858. &lpAdsDestValue->pReplicaPointer->ReplicaAddressHints->Address);
  859. BAIL_ON_FAILURE(hr);
  860. RRETURN(hr);
  861. error:
  862. if (lpAdsDestValue->pReplicaPointer) {
  863. if (lpAdsDestValue->pReplicaPointer->ServerName) {
  864. FreeADsStr(lpAdsDestValue->pReplicaPointer->ServerName);
  865. }
  866. if (lpAdsDestValue->pReplicaPointer->ReplicaAddressHints) {
  867. FreeADsMem(lpAdsDestValue->pReplicaPointer->ReplicaAddressHints);
  868. }
  869. FreeADsMem(lpAdsDestValue->pReplicaPointer);
  870. }
  871. RRETURN(hr);
  872. }
  873. HRESULT
  874. AdsCopyFaxNumber(
  875. PADSVALUE lpAdsSrcValue,
  876. PADSVALUE lpAdsDestValue
  877. )
  878. {
  879. HRESULT hr = S_OK;
  880. LPBYTE lpByteStream = NULL;
  881. DWORD dwNumBytes = 0;
  882. if(lpAdsSrcValue->dwType != ADSTYPE_FAXNUMBER){
  883. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  884. }
  885. if (!lpAdsSrcValue->pFaxNumber) {
  886. RRETURN(hr = E_FAIL);
  887. }
  888. lpAdsDestValue->pFaxNumber = (PADS_FAXNUMBER)AllocADsMem(sizeof(ADS_FAXNUMBER));
  889. if (!lpAdsDestValue->pFaxNumber) {
  890. hr = E_OUTOFMEMORY;
  891. BAIL_ON_FAILURE(hr);
  892. }
  893. lpAdsDestValue->dwType = ADSTYPE_FAXNUMBER;
  894. dwNumBytes = lpAdsSrcValue->pFaxNumber->NumberOfBits;
  895. lpByteStream = (LPBYTE)AllocADsMem(dwNumBytes);
  896. if (!lpByteStream) {
  897. hr = E_OUTOFMEMORY;
  898. BAIL_ON_FAILURE(hr);
  899. }
  900. memcpy(
  901. lpByteStream,
  902. lpAdsSrcValue->pFaxNumber->Parameters,
  903. dwNumBytes
  904. );
  905. lpAdsDestValue->pFaxNumber->NumberOfBits = dwNumBytes;
  906. lpAdsDestValue->pFaxNumber->Parameters = lpByteStream;
  907. lpAdsDestValue->pFaxNumber->TelephoneNumber = AllocADsStr(lpAdsSrcValue->pFaxNumber->TelephoneNumber);
  908. if (!lpAdsDestValue->pFaxNumber->TelephoneNumber) {
  909. hr = E_OUTOFMEMORY;
  910. BAIL_ON_FAILURE(hr);
  911. }
  912. RRETURN(hr);
  913. error:
  914. if (lpAdsDestValue->pFaxNumber) {
  915. FreeADsMem(lpAdsDestValue->pFaxNumber);
  916. }
  917. if (lpByteStream) {
  918. FreeADsMem(lpByteStream);
  919. }
  920. RRETURN(hr);
  921. }
  922. HRESULT
  923. AdsCopyNDSTimestamp(
  924. PADSVALUE lpAdsSrcValue,
  925. PADSVALUE lpAdsDestValue
  926. )
  927. {
  928. HRESULT hr = S_OK;
  929. if(lpAdsSrcValue->dwType != ADSTYPE_TIMESTAMP){
  930. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  931. }
  932. lpAdsDestValue->dwType = ADSTYPE_TIMESTAMP;
  933. lpAdsDestValue->Timestamp.WholeSeconds = lpAdsSrcValue->Timestamp.WholeSeconds;
  934. lpAdsDestValue->Timestamp.EventID = lpAdsSrcValue->Timestamp.EventID;
  935. RRETURN(hr);
  936. }
  937. HRESULT
  938. AdsCopyDNWithBinary(
  939. PADSVALUE lpAdsSrcValue,
  940. PADSVALUE lpAdsDestValue
  941. )
  942. {
  943. HRESULT hr = S_OK;
  944. PADS_DN_WITH_BINARY pDestDNBin = NULL;
  945. PADS_DN_WITH_BINARY pSrcDNBin = NULL;
  946. if (lpAdsSrcValue->dwType != ADSTYPE_DN_WITH_BINARY) {
  947. BAIL_ON_FAILURE(hr = E_ADS_CANT_CONVERT_DATATYPE);
  948. }
  949. if (!lpAdsSrcValue->pDNWithBinary) {
  950. //
  951. // No source object so return
  952. //
  953. RRETURN(hr);
  954. }
  955. pSrcDNBin = lpAdsSrcValue->pDNWithBinary;
  956. pDestDNBin = (PADS_DN_WITH_BINARY)
  957. AllocADsMem(sizeof(ADS_DN_WITH_BINARY));
  958. if (!pDestDNBin) {
  959. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  960. }
  961. if (pSrcDNBin->dwLength) {
  962. //
  963. // Copy the octet string over.
  964. //
  965. pDestDNBin->lpBinaryValue = (LPBYTE) AllocADsMem(pSrcDNBin->dwLength);
  966. if (!pDestDNBin->lpBinaryValue) {
  967. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  968. }
  969. pDestDNBin->dwLength = pSrcDNBin->dwLength;
  970. memcpy(
  971. pDestDNBin->lpBinaryValue,
  972. pSrcDNBin->lpBinaryValue,
  973. pSrcDNBin->dwLength
  974. );
  975. }
  976. if (pSrcDNBin->pszDNString) {
  977. //
  978. // Copy the DNString value over
  979. //
  980. pDestDNBin->pszDNString = AllocADsStr(pSrcDNBin->pszDNString);
  981. if (!pDestDNBin->pszDNString) {
  982. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  983. }
  984. }
  985. lpAdsDestValue->pDNWithBinary = pDestDNBin;
  986. lpAdsDestValue->dwType = ADSTYPE_DN_WITH_BINARY;
  987. RRETURN(hr);
  988. error:
  989. if (pDestDNBin) {
  990. //
  991. // Clean up the mem for string and byte array
  992. //
  993. if (pDestDNBin->pszDNString) {
  994. FreeADsStr(pDestDNBin->pszDNString);
  995. }
  996. if (pDestDNBin->lpBinaryValue) {
  997. FreeADsMem(pDestDNBin->lpBinaryValue);
  998. }
  999. FreeADsMem(pDestDNBin);
  1000. }
  1001. RRETURN(hr);
  1002. }
  1003. HRESULT
  1004. AdsCopyDNWithString(
  1005. PADSVALUE lpAdsSrcValue,
  1006. PADSVALUE lpAdsDestValue
  1007. )
  1008. {
  1009. HRESULT hr = S_OK;
  1010. PADS_DN_WITH_STRING pDestDNStr = NULL;
  1011. PADS_DN_WITH_STRING pSrcDNStr = NULL;
  1012. if (lpAdsSrcValue->dwType != ADSTYPE_DN_WITH_STRING) {
  1013. BAIL_ON_FAILURE(hr = E_ADS_CANT_CONVERT_DATATYPE);
  1014. }
  1015. if (!lpAdsSrcValue->pDNWithString) {
  1016. //
  1017. // No source object so return
  1018. //
  1019. RRETURN(hr);
  1020. }
  1021. pSrcDNStr = lpAdsSrcValue->pDNWithString;
  1022. pDestDNStr = (PADS_DN_WITH_STRING)
  1023. AllocADsMem(sizeof(ADS_DN_WITH_STRING));
  1024. if (!pDestDNStr) {
  1025. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  1026. }
  1027. if (pSrcDNStr->pszStringValue) {
  1028. //
  1029. // Copy the string over.
  1030. //
  1031. pDestDNStr->pszStringValue = AllocADsStr(pSrcDNStr->pszStringValue);
  1032. if (!pDestDNStr->pszStringValue) {
  1033. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  1034. }
  1035. }
  1036. if (pSrcDNStr->pszDNString) {
  1037. //
  1038. // Copy the DNString value over
  1039. //
  1040. pDestDNStr->pszDNString = AllocADsStr(pSrcDNStr->pszDNString);
  1041. if (!pDestDNStr->pszDNString) {
  1042. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  1043. }
  1044. }
  1045. lpAdsDestValue->pDNWithString = pDestDNStr;
  1046. lpAdsDestValue->dwType = ADSTYPE_DN_WITH_STRING;
  1047. RRETURN(hr);
  1048. error:
  1049. if (pDestDNStr) {
  1050. //
  1051. // Clean up the mem for string and byte array
  1052. //
  1053. if (pDestDNStr->pszDNString) {
  1054. FreeADsStr(pDestDNStr->pszDNString);
  1055. }
  1056. if (pDestDNStr->pszStringValue) {
  1057. FreeADsMem(pDestDNStr->pszStringValue);
  1058. }
  1059. FreeADsMem(pDestDNStr);
  1060. }
  1061. RRETURN(hr);
  1062. }
  1063. HRESULT
  1064. AdsCopy(
  1065. PADSVALUE lpAdsSrcValue,
  1066. PADSVALUE lpAdsDestValue
  1067. )
  1068. {
  1069. HRESULT hr = E_FAIL;
  1070. switch (lpAdsSrcValue->dwType){
  1071. case ADSTYPE_DN_STRING:
  1072. hr = AdsCopyDNString(
  1073. lpAdsSrcValue,
  1074. lpAdsDestValue
  1075. );
  1076. break;
  1077. case ADSTYPE_CASE_EXACT_STRING:
  1078. hr = AdsCopyCaseExactString(
  1079. lpAdsSrcValue,
  1080. lpAdsDestValue
  1081. );
  1082. break;
  1083. case ADSTYPE_CASE_IGNORE_STRING:
  1084. hr = AdsCopyCaseIgnoreString(
  1085. lpAdsSrcValue,
  1086. lpAdsDestValue
  1087. );
  1088. break;
  1089. case ADSTYPE_PRINTABLE_STRING:
  1090. hr = AdsCopyPrintableString(
  1091. lpAdsSrcValue,
  1092. lpAdsDestValue
  1093. );
  1094. break;
  1095. case ADSTYPE_NUMERIC_STRING:
  1096. hr = AdsCopyNumericString(
  1097. lpAdsSrcValue,
  1098. lpAdsDestValue
  1099. );
  1100. break;
  1101. case ADSTYPE_BOOLEAN:
  1102. hr = AdsCopyBoolean(
  1103. lpAdsSrcValue,
  1104. lpAdsDestValue
  1105. );
  1106. break;
  1107. case ADSTYPE_INTEGER:
  1108. hr = AdsCopyInteger(
  1109. lpAdsSrcValue,
  1110. lpAdsDestValue
  1111. );
  1112. break;
  1113. case ADSTYPE_LARGE_INTEGER:
  1114. hr = AdsCopyLargeInteger(
  1115. lpAdsSrcValue,
  1116. lpAdsDestValue
  1117. );
  1118. break;
  1119. case ADSTYPE_OCTET_STRING:
  1120. hr = AdsCopyOctetString(
  1121. lpAdsSrcValue,
  1122. lpAdsDestValue
  1123. );
  1124. break;
  1125. case ADSTYPE_PROV_SPECIFIC:
  1126. hr = AdsCopyProvSpecific(
  1127. lpAdsSrcValue,
  1128. lpAdsDestValue
  1129. );
  1130. break;
  1131. case ADSTYPE_UTC_TIME:
  1132. hr = AdsCopyTime(
  1133. lpAdsSrcValue,
  1134. lpAdsDestValue
  1135. );
  1136. break;
  1137. case ADSTYPE_CASEIGNORE_LIST:
  1138. hr = AdsCopyCaseIgnoreList(
  1139. lpAdsSrcValue,
  1140. lpAdsDestValue
  1141. );
  1142. break;
  1143. case ADSTYPE_FAXNUMBER:
  1144. hr = AdsCopyFaxNumber(
  1145. lpAdsSrcValue,
  1146. lpAdsDestValue
  1147. );
  1148. break;
  1149. case ADSTYPE_NETADDRESS:
  1150. hr = AdsCopyNetAddress(
  1151. lpAdsSrcValue,
  1152. lpAdsDestValue
  1153. );
  1154. break;
  1155. case ADSTYPE_OCTET_LIST:
  1156. hr = AdsCopyOctetList(
  1157. lpAdsSrcValue,
  1158. lpAdsDestValue
  1159. );
  1160. break;
  1161. case ADSTYPE_EMAIL:
  1162. hr = AdsCopyEmail(
  1163. lpAdsSrcValue,
  1164. lpAdsDestValue
  1165. );
  1166. break;
  1167. case ADSTYPE_PATH:
  1168. hr = AdsCopyPath(
  1169. lpAdsSrcValue,
  1170. lpAdsDestValue
  1171. );
  1172. break;
  1173. case ADSTYPE_REPLICAPOINTER:
  1174. hr = AdsCopyReplicaPointer(
  1175. lpAdsSrcValue,
  1176. lpAdsDestValue
  1177. );
  1178. break;
  1179. case ADSTYPE_TIMESTAMP:
  1180. hr = AdsCopyNDSTimestamp(
  1181. lpAdsSrcValue,
  1182. lpAdsDestValue
  1183. );
  1184. break;
  1185. case ADSTYPE_POSTALADDRESS:
  1186. hr = AdsCopyPostalAddress(
  1187. lpAdsSrcValue,
  1188. lpAdsDestValue
  1189. );
  1190. break;
  1191. case ADSTYPE_BACKLINK:
  1192. hr = AdsCopyBackLink(
  1193. lpAdsSrcValue,
  1194. lpAdsDestValue
  1195. );
  1196. break;
  1197. case ADSTYPE_TYPEDNAME:
  1198. hr = AdsCopyTypedName(
  1199. lpAdsSrcValue,
  1200. lpAdsDestValue
  1201. );
  1202. break;
  1203. case ADSTYPE_HOLD:
  1204. hr = AdsCopyHold(
  1205. lpAdsSrcValue,
  1206. lpAdsDestValue
  1207. );
  1208. break;
  1209. case ADSTYPE_DN_WITH_BINARY:
  1210. hr = AdsCopyDNWithBinary(
  1211. lpAdsSrcValue,
  1212. lpAdsDestValue
  1213. );
  1214. break;
  1215. case ADSTYPE_DN_WITH_STRING:
  1216. hr = AdsCopyDNWithString(
  1217. lpAdsSrcValue,
  1218. lpAdsDestValue
  1219. );
  1220. break;
  1221. case ADSTYPE_NT_SECURITY_DESCRIPTOR:
  1222. //
  1223. // This should be handled elsewhere not here !
  1224. //
  1225. ADsAssert(!"Invalid option to adscopy");
  1226. break;
  1227. default:
  1228. hr = E_FAIL;
  1229. break;
  1230. }
  1231. RRETURN(hr);
  1232. }
  1233. //
  1234. // This routine is typically used by GetPropertyItem calls.
  1235. //
  1236. HRESULT
  1237. AdsCopyADsValueToPropObj(
  1238. PADSVALUE lpAdsSrcValue,
  1239. CPropertyValue* lpPropObj,
  1240. LPWSTR pszServerName,
  1241. CCredentials* pCredentials,
  1242. BOOL fNTDSType
  1243. )
  1244. {
  1245. HRESULT hr = S_OK;
  1246. PADSVALUE lpAdsDestValue = lpPropObj->getADsValue();
  1247. CCredentials localCredentials(NULL, NULL, 0);
  1248. switch (lpAdsSrcValue->dwType){
  1249. case ADSTYPE_NT_SECURITY_DESCRIPTOR:
  1250. if (pCredentials) {
  1251. localCredentials = *pCredentials;
  1252. }
  1253. hr = AdsCopyNTSecurityDescriptor(
  1254. lpAdsSrcValue,
  1255. lpPropObj,
  1256. pszServerName,
  1257. localCredentials,
  1258. fNTDSType
  1259. );
  1260. break;
  1261. default:
  1262. hr = AdsCopy(
  1263. lpAdsSrcValue,
  1264. lpAdsDestValue
  1265. );
  1266. break;
  1267. }
  1268. RRETURN(hr);
  1269. }
  1270. //
  1271. // This routine is typically used from PutPropertyItem.
  1272. //
  1273. HRESULT
  1274. AdsCopyPropObjToADsValue(
  1275. CPropertyValue *lpPropObj,
  1276. PADSVALUE lpAdsDestValue,
  1277. LPWSTR pszServerName,
  1278. CCredentials* pCredentials,
  1279. BOOL fNTDSType
  1280. )
  1281. {
  1282. HRESULT hr = E_FAIL;
  1283. PADSVALUE lpAdsSrcValue = lpPropObj->getADsValue();
  1284. DWORD dwDataType = 0;
  1285. DWORD dwSDLength = 0;
  1286. PSECURITY_DESCRIPTOR pSecurityDescriptor = NULL;
  1287. CCredentials locCredentials(NULL, NULL, 0);
  1288. IDispatch *pIDispatch = NULL;
  1289. IADsSecurityDescriptor *pIADsSecDesc = NULL;
  1290. switch (lpAdsSrcValue->dwType) {
  1291. case ADSTYPE_NT_SECURITY_DESCRIPTOR :
  1292. dwDataType = lpPropObj->getExtendedDataTypeInfo();
  1293. //
  1294. // if we have the octet blob send it back
  1295. //
  1296. if (dwDataType == CPropertyValue::VAL_IDISPATCH_SECDESC_ALL) {
  1297. hr = AdsCopyOctetString(
  1298. lpAdsSrcValue,
  1299. lpAdsDestValue
  1300. );
  1301. BAIL_ON_FAILURE(hr);
  1302. }
  1303. else if (dwDataType == CPropertyValue::VAL_IDISPATCH_SECDESC_ONLY) {
  1304. if (pCredentials) {
  1305. locCredentials = *pCredentials;
  1306. }
  1307. pIDispatch = lpPropObj->getDispatchPointer();
  1308. if (pIDispatch) {
  1309. hr = pIDispatch->QueryInterface(
  1310. IID_IADsSecurityDescriptor,
  1311. (void **) &pIADsSecDesc
  1312. );
  1313. BAIL_ON_FAILURE(hr);
  1314. }
  1315. hr = ConvertSecurityDescriptorToSecDes(
  1316. pszServerName,
  1317. locCredentials,
  1318. pIADsSecDesc,
  1319. &pSecurityDescriptor,
  1320. &dwSDLength,
  1321. fNTDSType
  1322. );
  1323. BAIL_ON_FAILURE(hr);
  1324. lpAdsDestValue->OctetString.lpValue
  1325. = (LPBYTE) AllocADsMem(dwSDLength);
  1326. if (!(lpAdsDestValue->OctetString.lpValue)) {
  1327. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  1328. }
  1329. memcpy(
  1330. lpAdsDestValue->OctetString.lpValue,
  1331. pSecurityDescriptor,
  1332. dwSDLength
  1333. );
  1334. lpAdsDestValue->dwType = ADSTYPE_OCTET_STRING;
  1335. lpAdsDestValue->OctetString.dwLength = dwSDLength;
  1336. } // secdesc idispatch only
  1337. break;
  1338. default:
  1339. hr = AdsCopy(
  1340. lpAdsSrcValue,
  1341. lpAdsDestValue
  1342. );
  1343. break;
  1344. } // end case
  1345. error :
  1346. //
  1347. // Needs to be executed in all cases, currently only ret is below
  1348. //
  1349. if (pIADsSecDesc) {
  1350. pIADsSecDesc->Release();
  1351. }
  1352. if (pSecurityDescriptor) {
  1353. FreeADsMem(pSecurityDescriptor);
  1354. }
  1355. RRETURN(hr);
  1356. }
  1357. HRESULT
  1358. PropVariantToAdsType(
  1359. PVARIANT pVariant,
  1360. DWORD dwNumVariant,
  1361. PADSVALUE *ppAdsValues,
  1362. PDWORD pdwNumValues
  1363. )
  1364. {
  1365. return(PropVariantToAdsType2(
  1366. pVariant,
  1367. dwNumVariant,
  1368. ppAdsValues,
  1369. pdwNumValues,
  1370. NULL, // serverName,
  1371. NULL, // pCredentials
  1372. TRUE // NTDS Type
  1373. ));
  1374. }
  1375. HRESULT
  1376. PropVariantToAdsType2(
  1377. PVARIANT pVariant,
  1378. DWORD dwNumVariant,
  1379. PADSVALUE *ppAdsValues,
  1380. PDWORD pdwNumValues,
  1381. LPWSTR pszServerName,
  1382. CCredentials* pCredentials,
  1383. BOOL fNTDSType
  1384. )
  1385. {
  1386. DWORD i = 0;
  1387. VARIANT * pVar = NULL;
  1388. DWORD dwCount = 0;
  1389. IDispatch FAR * pDispatch = NULL;
  1390. IADsValue FAR * pPropValue = NULL;
  1391. PADSVALUE pADsValues = NULL;
  1392. HRESULT hr = S_OK;
  1393. LPWSTR pszUserName = NULL;
  1394. LPWSTR pszPassWord = NULL;
  1395. DWORD dwFlags = 0;
  1396. pADsValues = (PADSVALUE)AllocADsMem(dwNumVariant * sizeof(ADSVALUE));
  1397. if (!pADsValues) {
  1398. RRETURN(E_OUTOFMEMORY);
  1399. }
  1400. //
  1401. // If !pCredentials, use the initialized values as they
  1402. // represent an object with CCredentials(NULL, NULL, 0)
  1403. //
  1404. if (pCredentials) {
  1405. hr = pCredentials->GetUserName(&pszUserName);
  1406. BAIL_ON_FAILURE(hr);
  1407. hr = pCredentials->GetPassword(&pszPassWord);
  1408. BAIL_ON_FAILURE(hr);
  1409. dwFlags = pCredentials->GetAuthFlags();
  1410. }
  1411. for (i = 0; i < dwNumVariant; i++ ) {
  1412. pVar = pVariant + i;
  1413. pDispatch = V_DISPATCH(pVar);
  1414. hr = pDispatch->QueryInterface(
  1415. IID_IADsValue,
  1416. (void **)&pPropValue
  1417. );
  1418. CONTINUE_ON_FAILURE(hr);
  1419. hr = pPropValue->ConvertPropertyValueToADsValue2(
  1420. (pADsValues + dwCount),
  1421. pszServerName,
  1422. pszUserName,
  1423. pszPassWord,
  1424. dwFlags,
  1425. fNTDSType
  1426. );
  1427. pPropValue->Release();
  1428. BAIL_ON_FAILURE(hr);
  1429. dwCount++;
  1430. }
  1431. *ppAdsValues = pADsValues;
  1432. *pdwNumValues = dwCount;
  1433. error:
  1434. if (pszUserName) {
  1435. FreeADsStr(pszUserName);
  1436. }
  1437. if (pszPassWord) {
  1438. FreeADsStr(pszPassWord);
  1439. }
  1440. if (FAILED(hr) && pADsValues) {
  1441. FreeADsMem(pADsValues);
  1442. }
  1443. RRETURN(hr);
  1444. }
  1445. HRESULT
  1446. AdsTypeToPropVariant2(
  1447. PADSVALUE pAdsValues,
  1448. DWORD dwNumValues,
  1449. PVARIANT pVarDestObjects,
  1450. LPWSTR pszServerName,
  1451. CCredentials* pCredentials,
  1452. BOOL fNTDSType
  1453. )
  1454. {
  1455. long i = 0;
  1456. HRESULT hr = S_OK;
  1457. CPropertyValue * pAdsValue = NULL;
  1458. VariantInit( pVarDestObjects );
  1459. //
  1460. // The following are for handling are multi-value properties
  1461. //
  1462. SAFEARRAY *aList = NULL;
  1463. SAFEARRAYBOUND aBound;
  1464. aBound.lLbound = 0;
  1465. aBound.cElements = dwNumValues;
  1466. aList = SafeArrayCreate( VT_VARIANT, 1, &aBound );
  1467. if ( aList == NULL )
  1468. {
  1469. hr = E_OUTOFMEMORY;
  1470. BAIL_ON_FAILURE(hr);
  1471. }
  1472. for ( i = 0; i < (long)dwNumValues; i++ )
  1473. {
  1474. VARIANT v;
  1475. IDispatch FAR * pDispatch = NULL;
  1476. VariantInit(&v);
  1477. hr = CPropertyValue::AllocatePropertyValueObject(&pAdsValue);
  1478. BAIL_ON_FAILURE(hr);
  1479. hr = pAdsValue->ConvertADsValueToPropertyValue2(
  1480. pAdsValues + i,
  1481. pszServerName,
  1482. pCredentials,
  1483. fNTDSType
  1484. );
  1485. BAIL_ON_FAILURE(hr);
  1486. pAdsValue->QueryInterface(
  1487. IID_IDispatch,
  1488. (void **)&pDispatch
  1489. );
  1490. BAIL_ON_FAILURE(hr);
  1491. V_DISPATCH(&v) = pDispatch;
  1492. V_VT(&v) = VT_DISPATCH;
  1493. if (pAdsValue) {
  1494. pAdsValue->Release();
  1495. }
  1496. hr = SafeArrayPutElement( aList, &i, &v );
  1497. VariantClear(&v);
  1498. pDispatch = NULL;
  1499. BAIL_ON_FAILURE(hr);
  1500. }
  1501. V_VT(pVarDestObjects) = VT_ARRAY | VT_VARIANT;
  1502. V_ARRAY(pVarDestObjects) = aList;
  1503. RRETURN(S_OK);
  1504. error:
  1505. if ( aList )
  1506. SafeArrayDestroy( aList );
  1507. RRETURN(hr);
  1508. }
  1509. HRESULT
  1510. AdsTypeToPropVariant(
  1511. PADSVALUE pAdsValues,
  1512. DWORD dwNumValues,
  1513. PVARIANT pVarDestObjects
  1514. )
  1515. {
  1516. RRETURN( AdsTypeToPropVariant2(
  1517. pAdsValues,
  1518. dwNumValues,
  1519. pVarDestObjects,
  1520. NULL, // serverName
  1521. NULL, // pCredentials
  1522. TRUE // serverType
  1523. )
  1524. );
  1525. }
  1526. void
  1527. AdsFreeAdsValues(
  1528. PADSVALUE pAdsValues,
  1529. DWORD dwNumValues
  1530. )
  1531. {
  1532. LPBYTE pMem = NULL;
  1533. for ( DWORD i = 0; i < dwNumValues; i++ )
  1534. {
  1535. AdsClear(&pAdsValues[i]);
  1536. }
  1537. }