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.

1949 lines
47 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 && dwNumBytes) {
  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 && dwNumBytes) {
  433. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  434. }
  435. memcpy(
  436. lpByteStream,
  437. lpAdsSrcValue->OctetString.lpValue,
  438. dwNumBytes
  439. );
  440. //
  441. // Now attempt to conver to security descriptor
  442. //
  443. hr = ConvertSecDescriptorToVariant(
  444. pszServerName,
  445. Credentials,
  446. lpAdsSrcValue->OctetString.lpValue,
  447. &vVarSec,
  448. fNTDSType
  449. );
  450. BAIL_ON_FAILURE(hr);
  451. hr = lpPropValue->put_SecurityDescriptor(V_DISPATCH(&vVarSec));
  452. BAIL_ON_FAILURE(hr);
  453. lpAdsDestValue->OctetString.dwLength = dwNumBytes;
  454. lpAdsDestValue->OctetString.lpValue = lpByteStream;
  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 && lpAdsSrcValue->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 && dwNumBytes) {
  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 && pCurrent->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 && pCurrent->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 && lpAdsSrcValue->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 && lpAdsSrcValue->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. lpAdsSrcValue->pPostalAddress->PostalAddress[i]) {
  719. hr = E_OUTOFMEMORY;
  720. BAIL_ON_FAILURE(hr);
  721. }
  722. }
  723. RRETURN(hr);
  724. error:
  725. if (lpAdsDestValue->pPostalAddress) {
  726. //
  727. // Ideally I would need to loop only until i<5
  728. // Being extra cautious over here in case some other code gets
  729. // added after the for loop that returns an error which would
  730. // bring us over here
  731. //
  732. for (i=0;i<6;i++) {
  733. if (lpAdsDestValue->pPostalAddress->PostalAddress[i]) {
  734. FreeADsStr(lpAdsDestValue->pPostalAddress->PostalAddress[i]);
  735. }
  736. }
  737. FreeADsMem(lpAdsDestValue->pPostalAddress);
  738. }
  739. RRETURN(hr);
  740. }
  741. HRESULT
  742. AdsCopyBackLink(
  743. PADSVALUE lpAdsSrcValue,
  744. PADSVALUE lpAdsDestValue
  745. )
  746. {
  747. HRESULT hr = S_OK;
  748. if(lpAdsSrcValue->dwType != ADSTYPE_BACKLINK){
  749. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  750. }
  751. lpAdsDestValue->dwType = ADSTYPE_BACKLINK;
  752. lpAdsDestValue->BackLink.RemoteID = lpAdsSrcValue->BackLink.RemoteID;
  753. lpAdsDestValue->BackLink.ObjectName = AllocADsStr(lpAdsSrcValue->BackLink.ObjectName);
  754. if (!lpAdsDestValue->BackLink.ObjectName &&
  755. lpAdsSrcValue->BackLink.ObjectName) {
  756. hr = E_OUTOFMEMORY;
  757. BAIL_ON_FAILURE(hr);
  758. }
  759. error:
  760. RRETURN(hr);
  761. }
  762. HRESULT
  763. AdsCopyTypedName(
  764. PADSVALUE lpAdsSrcValue,
  765. PADSVALUE lpAdsDestValue
  766. )
  767. {
  768. HRESULT hr = S_OK;
  769. LPWSTR ObjectName;
  770. DWORD Level;
  771. DWORD Interval;
  772. if(lpAdsSrcValue->dwType != ADSTYPE_TYPEDNAME){
  773. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  774. }
  775. if (!lpAdsSrcValue->pTypedName) {
  776. RRETURN(hr = E_FAIL);
  777. }
  778. lpAdsDestValue->dwType = ADSTYPE_TYPEDNAME;
  779. lpAdsDestValue->pTypedName = (PADS_TYPEDNAME)AllocADsMem(sizeof(ADS_TYPEDNAME));
  780. if (!lpAdsDestValue->pTypedName) {
  781. hr = E_OUTOFMEMORY;
  782. BAIL_ON_FAILURE(hr);
  783. }
  784. lpAdsDestValue->pTypedName->Level = lpAdsSrcValue->pTypedName->Level;
  785. lpAdsDestValue->pTypedName->Interval = lpAdsSrcValue->pTypedName->Interval;
  786. lpAdsDestValue->pTypedName->ObjectName = AllocADsStr(lpAdsSrcValue->pTypedName->ObjectName);
  787. if (!lpAdsDestValue->pTypedName->ObjectName &&
  788. lpAdsSrcValue->pTypedName->ObjectName) {
  789. hr = E_OUTOFMEMORY;
  790. BAIL_ON_FAILURE(hr);
  791. }
  792. RRETURN(hr);
  793. error:
  794. if (lpAdsDestValue->pTypedName) {
  795. FreeADsMem(lpAdsDestValue->pTypedName);
  796. }
  797. RRETURN(hr);
  798. }
  799. HRESULT
  800. AdsCopyHold(
  801. PADSVALUE lpAdsSrcValue,
  802. PADSVALUE lpAdsDestValue
  803. )
  804. {
  805. HRESULT hr = S_OK;
  806. if(lpAdsSrcValue->dwType != ADSTYPE_HOLD){
  807. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  808. }
  809. lpAdsDestValue->dwType = ADSTYPE_HOLD;
  810. lpAdsDestValue->Hold.Amount = lpAdsSrcValue->Hold.Amount;
  811. lpAdsDestValue->Hold.ObjectName = AllocADsStr(lpAdsSrcValue->Hold.ObjectName);
  812. if (!lpAdsDestValue->Hold.ObjectName &&
  813. lpAdsSrcValue->Hold.ObjectName) {
  814. hr = E_OUTOFMEMORY;
  815. BAIL_ON_FAILURE(hr);
  816. }
  817. error:
  818. RRETURN(hr);
  819. }
  820. HRESULT
  821. AdsCopyReplicaPointer(
  822. PADSVALUE lpAdsSrcValue,
  823. PADSVALUE lpAdsDestValue
  824. )
  825. {
  826. HRESULT hr = S_OK;
  827. LPBYTE lpByteStream = NULL;
  828. DWORD dwNumBytes = 0;
  829. if(lpAdsSrcValue->dwType != ADSTYPE_REPLICAPOINTER){
  830. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  831. }
  832. if (!lpAdsSrcValue->pReplicaPointer) {
  833. RRETURN(hr = E_FAIL);
  834. }
  835. lpAdsDestValue->dwType = ADSTYPE_REPLICAPOINTER;
  836. lpAdsDestValue->pReplicaPointer = (PADS_REPLICAPOINTER)AllocADsMem(sizeof(ADS_REPLICAPOINTER));
  837. if (!lpAdsDestValue->pReplicaPointer) {
  838. hr = E_OUTOFMEMORY;
  839. BAIL_ON_FAILURE(hr);
  840. }
  841. lpAdsDestValue->pReplicaPointer->ReplicaType = lpAdsSrcValue->pReplicaPointer->ReplicaType;
  842. lpAdsDestValue->pReplicaPointer->ReplicaNumber = lpAdsSrcValue->pReplicaPointer->ReplicaNumber;
  843. lpAdsDestValue->pReplicaPointer->Count = lpAdsSrcValue->pReplicaPointer->Count;
  844. lpAdsDestValue->pReplicaPointer->ServerName = AllocADsStr(lpAdsSrcValue->pReplicaPointer->ServerName);
  845. if (!lpAdsDestValue->pReplicaPointer->ServerName &&
  846. lpAdsSrcValue->pReplicaPointer->ServerName) {
  847. hr = E_OUTOFMEMORY;
  848. BAIL_ON_FAILURE(hr);
  849. }
  850. //
  851. // Doing NetAddress
  852. //
  853. lpAdsDestValue->pReplicaPointer->ReplicaAddressHints = (PADS_NETADDRESS)AllocADsMem(sizeof(ADS_NETADDRESS));
  854. if (!lpAdsDestValue->pReplicaPointer->ReplicaAddressHints) {
  855. hr = E_OUTOFMEMORY;
  856. BAIL_ON_FAILURE(hr);
  857. }
  858. lpAdsDestValue->pReplicaPointer->ReplicaAddressHints->AddressType = lpAdsSrcValue->pReplicaPointer->ReplicaAddressHints->AddressType;
  859. hr = CopyOctetString(
  860. lpAdsSrcValue->pReplicaPointer->ReplicaAddressHints->AddressLength,
  861. lpAdsSrcValue->pReplicaPointer->ReplicaAddressHints->Address,
  862. &lpAdsDestValue->pReplicaPointer->ReplicaAddressHints->AddressLength,
  863. &lpAdsDestValue->pReplicaPointer->ReplicaAddressHints->Address);
  864. BAIL_ON_FAILURE(hr);
  865. RRETURN(hr);
  866. error:
  867. if (lpAdsDestValue->pReplicaPointer) {
  868. if (lpAdsDestValue->pReplicaPointer->ServerName) {
  869. FreeADsStr(lpAdsDestValue->pReplicaPointer->ServerName);
  870. }
  871. if (lpAdsDestValue->pReplicaPointer->ReplicaAddressHints) {
  872. FreeADsMem(lpAdsDestValue->pReplicaPointer->ReplicaAddressHints);
  873. }
  874. FreeADsMem(lpAdsDestValue->pReplicaPointer);
  875. }
  876. RRETURN(hr);
  877. }
  878. HRESULT
  879. AdsCopyFaxNumber(
  880. PADSVALUE lpAdsSrcValue,
  881. PADSVALUE lpAdsDestValue
  882. )
  883. {
  884. HRESULT hr = S_OK;
  885. LPBYTE lpByteStream = NULL;
  886. DWORD dwNumBytes = 0;
  887. if(lpAdsSrcValue->dwType != ADSTYPE_FAXNUMBER){
  888. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  889. }
  890. if (!lpAdsSrcValue->pFaxNumber) {
  891. RRETURN(hr = E_FAIL);
  892. }
  893. lpAdsDestValue->pFaxNumber = (PADS_FAXNUMBER)AllocADsMem(sizeof(ADS_FAXNUMBER));
  894. if (!lpAdsDestValue->pFaxNumber) {
  895. hr = E_OUTOFMEMORY;
  896. BAIL_ON_FAILURE(hr);
  897. }
  898. lpAdsDestValue->dwType = ADSTYPE_FAXNUMBER;
  899. dwNumBytes = lpAdsSrcValue->pFaxNumber->NumberOfBits;
  900. lpByteStream = (LPBYTE)AllocADsMem(dwNumBytes);
  901. if (!lpByteStream && dwNumBytes) {
  902. hr = E_OUTOFMEMORY;
  903. BAIL_ON_FAILURE(hr);
  904. }
  905. memcpy(
  906. lpByteStream,
  907. lpAdsSrcValue->pFaxNumber->Parameters,
  908. dwNumBytes
  909. );
  910. lpAdsDestValue->pFaxNumber->NumberOfBits = dwNumBytes;
  911. lpAdsDestValue->pFaxNumber->Parameters = lpByteStream;
  912. lpAdsDestValue->pFaxNumber->TelephoneNumber = AllocADsStr(lpAdsSrcValue->pFaxNumber->TelephoneNumber);
  913. if (!lpAdsDestValue->pFaxNumber->TelephoneNumber &&
  914. lpAdsSrcValue->pFaxNumber->TelephoneNumber) {
  915. hr = E_OUTOFMEMORY;
  916. BAIL_ON_FAILURE(hr);
  917. }
  918. RRETURN(hr);
  919. error:
  920. if (lpAdsDestValue->pFaxNumber) {
  921. FreeADsMem(lpAdsDestValue->pFaxNumber);
  922. }
  923. if (lpByteStream) {
  924. FreeADsMem(lpByteStream);
  925. }
  926. RRETURN(hr);
  927. }
  928. HRESULT
  929. AdsCopyNDSTimestamp(
  930. PADSVALUE lpAdsSrcValue,
  931. PADSVALUE lpAdsDestValue
  932. )
  933. {
  934. HRESULT hr = S_OK;
  935. if(lpAdsSrcValue->dwType != ADSTYPE_TIMESTAMP){
  936. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  937. }
  938. lpAdsDestValue->dwType = ADSTYPE_TIMESTAMP;
  939. lpAdsDestValue->Timestamp.WholeSeconds = lpAdsSrcValue->Timestamp.WholeSeconds;
  940. lpAdsDestValue->Timestamp.EventID = lpAdsSrcValue->Timestamp.EventID;
  941. RRETURN(hr);
  942. }
  943. HRESULT
  944. AdsCopyDNWithBinary(
  945. PADSVALUE lpAdsSrcValue,
  946. PADSVALUE lpAdsDestValue
  947. )
  948. {
  949. HRESULT hr = S_OK;
  950. PADS_DN_WITH_BINARY pDestDNBin = NULL;
  951. PADS_DN_WITH_BINARY pSrcDNBin = NULL;
  952. if (lpAdsSrcValue->dwType != ADSTYPE_DN_WITH_BINARY) {
  953. BAIL_ON_FAILURE(hr = E_ADS_CANT_CONVERT_DATATYPE);
  954. }
  955. if (!lpAdsSrcValue->pDNWithBinary) {
  956. //
  957. // No source object so return
  958. //
  959. RRETURN(hr);
  960. }
  961. pSrcDNBin = lpAdsSrcValue->pDNWithBinary;
  962. pDestDNBin = (PADS_DN_WITH_BINARY)
  963. AllocADsMem(sizeof(ADS_DN_WITH_BINARY));
  964. if (!pDestDNBin) {
  965. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  966. }
  967. if (pSrcDNBin->dwLength) {
  968. //
  969. // Copy the octet string over.
  970. //
  971. pDestDNBin->lpBinaryValue = (LPBYTE) AllocADsMem(pSrcDNBin->dwLength);
  972. if (!pDestDNBin->lpBinaryValue && pSrcDNBin->dwLength) {
  973. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  974. }
  975. pDestDNBin->dwLength = pSrcDNBin->dwLength;
  976. memcpy(
  977. pDestDNBin->lpBinaryValue,
  978. pSrcDNBin->lpBinaryValue,
  979. pSrcDNBin->dwLength
  980. );
  981. }
  982. if (pSrcDNBin->pszDNString) {
  983. //
  984. // Copy the DNString value over
  985. //
  986. pDestDNBin->pszDNString = AllocADsStr(pSrcDNBin->pszDNString);
  987. if (!pDestDNBin->pszDNString && pSrcDNBin->pszDNString) {
  988. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  989. }
  990. }
  991. lpAdsDestValue->pDNWithBinary = pDestDNBin;
  992. lpAdsDestValue->dwType = ADSTYPE_DN_WITH_BINARY;
  993. RRETURN(hr);
  994. error:
  995. if (pDestDNBin) {
  996. //
  997. // Clean up the mem for string and byte array
  998. //
  999. if (pDestDNBin->pszDNString) {
  1000. FreeADsStr(pDestDNBin->pszDNString);
  1001. }
  1002. if (pDestDNBin->lpBinaryValue) {
  1003. FreeADsMem(pDestDNBin->lpBinaryValue);
  1004. }
  1005. FreeADsMem(pDestDNBin);
  1006. }
  1007. RRETURN(hr);
  1008. }
  1009. HRESULT
  1010. AdsCopyDNWithString(
  1011. PADSVALUE lpAdsSrcValue,
  1012. PADSVALUE lpAdsDestValue
  1013. )
  1014. {
  1015. HRESULT hr = S_OK;
  1016. PADS_DN_WITH_STRING pDestDNStr = NULL;
  1017. PADS_DN_WITH_STRING pSrcDNStr = NULL;
  1018. if (lpAdsSrcValue->dwType != ADSTYPE_DN_WITH_STRING) {
  1019. BAIL_ON_FAILURE(hr = E_ADS_CANT_CONVERT_DATATYPE);
  1020. }
  1021. if (!lpAdsSrcValue->pDNWithString) {
  1022. //
  1023. // No source object so return
  1024. //
  1025. RRETURN(hr);
  1026. }
  1027. pSrcDNStr = lpAdsSrcValue->pDNWithString;
  1028. pDestDNStr = (PADS_DN_WITH_STRING)
  1029. AllocADsMem(sizeof(ADS_DN_WITH_STRING));
  1030. if (!pDestDNStr) {
  1031. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  1032. }
  1033. if (pSrcDNStr->pszStringValue) {
  1034. //
  1035. // Copy the string over.
  1036. //
  1037. pDestDNStr->pszStringValue = AllocADsStr(pSrcDNStr->pszStringValue);
  1038. if (!pDestDNStr->pszStringValue && pSrcDNStr->pszStringValue) {
  1039. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  1040. }
  1041. }
  1042. if (pSrcDNStr->pszDNString) {
  1043. //
  1044. // Copy the DNString value over
  1045. //
  1046. pDestDNStr->pszDNString = AllocADsStr(pSrcDNStr->pszDNString);
  1047. if (!pDestDNStr->pszDNString && pSrcDNStr->pszDNString) {
  1048. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  1049. }
  1050. }
  1051. lpAdsDestValue->pDNWithString = pDestDNStr;
  1052. lpAdsDestValue->dwType = ADSTYPE_DN_WITH_STRING;
  1053. RRETURN(hr);
  1054. error:
  1055. if (pDestDNStr) {
  1056. //
  1057. // Clean up the mem for string and byte array
  1058. //
  1059. if (pDestDNStr->pszDNString) {
  1060. FreeADsStr(pDestDNStr->pszDNString);
  1061. }
  1062. if (pDestDNStr->pszStringValue) {
  1063. FreeADsMem(pDestDNStr->pszStringValue);
  1064. }
  1065. FreeADsMem(pDestDNStr);
  1066. }
  1067. RRETURN(hr);
  1068. }
  1069. HRESULT
  1070. AdsCopy(
  1071. PADSVALUE lpAdsSrcValue,
  1072. PADSVALUE lpAdsDestValue
  1073. )
  1074. {
  1075. HRESULT hr = E_FAIL;
  1076. switch (lpAdsSrcValue->dwType){
  1077. case ADSTYPE_DN_STRING:
  1078. hr = AdsCopyDNString(
  1079. lpAdsSrcValue,
  1080. lpAdsDestValue
  1081. );
  1082. break;
  1083. case ADSTYPE_CASE_EXACT_STRING:
  1084. hr = AdsCopyCaseExactString(
  1085. lpAdsSrcValue,
  1086. lpAdsDestValue
  1087. );
  1088. break;
  1089. case ADSTYPE_CASE_IGNORE_STRING:
  1090. hr = AdsCopyCaseIgnoreString(
  1091. lpAdsSrcValue,
  1092. lpAdsDestValue
  1093. );
  1094. break;
  1095. case ADSTYPE_PRINTABLE_STRING:
  1096. hr = AdsCopyPrintableString(
  1097. lpAdsSrcValue,
  1098. lpAdsDestValue
  1099. );
  1100. break;
  1101. case ADSTYPE_NUMERIC_STRING:
  1102. hr = AdsCopyNumericString(
  1103. lpAdsSrcValue,
  1104. lpAdsDestValue
  1105. );
  1106. break;
  1107. case ADSTYPE_BOOLEAN:
  1108. hr = AdsCopyBoolean(
  1109. lpAdsSrcValue,
  1110. lpAdsDestValue
  1111. );
  1112. break;
  1113. case ADSTYPE_INTEGER:
  1114. hr = AdsCopyInteger(
  1115. lpAdsSrcValue,
  1116. lpAdsDestValue
  1117. );
  1118. break;
  1119. case ADSTYPE_LARGE_INTEGER:
  1120. hr = AdsCopyLargeInteger(
  1121. lpAdsSrcValue,
  1122. lpAdsDestValue
  1123. );
  1124. break;
  1125. case ADSTYPE_OCTET_STRING:
  1126. hr = AdsCopyOctetString(
  1127. lpAdsSrcValue,
  1128. lpAdsDestValue
  1129. );
  1130. break;
  1131. case ADSTYPE_PROV_SPECIFIC:
  1132. hr = AdsCopyProvSpecific(
  1133. lpAdsSrcValue,
  1134. lpAdsDestValue
  1135. );
  1136. break;
  1137. case ADSTYPE_UTC_TIME:
  1138. hr = AdsCopyTime(
  1139. lpAdsSrcValue,
  1140. lpAdsDestValue
  1141. );
  1142. break;
  1143. case ADSTYPE_CASEIGNORE_LIST:
  1144. hr = AdsCopyCaseIgnoreList(
  1145. lpAdsSrcValue,
  1146. lpAdsDestValue
  1147. );
  1148. break;
  1149. case ADSTYPE_FAXNUMBER:
  1150. hr = AdsCopyFaxNumber(
  1151. lpAdsSrcValue,
  1152. lpAdsDestValue
  1153. );
  1154. break;
  1155. case ADSTYPE_NETADDRESS:
  1156. hr = AdsCopyNetAddress(
  1157. lpAdsSrcValue,
  1158. lpAdsDestValue
  1159. );
  1160. break;
  1161. case ADSTYPE_OCTET_LIST:
  1162. hr = AdsCopyOctetList(
  1163. lpAdsSrcValue,
  1164. lpAdsDestValue
  1165. );
  1166. break;
  1167. case ADSTYPE_EMAIL:
  1168. hr = AdsCopyEmail(
  1169. lpAdsSrcValue,
  1170. lpAdsDestValue
  1171. );
  1172. break;
  1173. case ADSTYPE_PATH:
  1174. hr = AdsCopyPath(
  1175. lpAdsSrcValue,
  1176. lpAdsDestValue
  1177. );
  1178. break;
  1179. case ADSTYPE_REPLICAPOINTER:
  1180. hr = AdsCopyReplicaPointer(
  1181. lpAdsSrcValue,
  1182. lpAdsDestValue
  1183. );
  1184. break;
  1185. case ADSTYPE_TIMESTAMP:
  1186. hr = AdsCopyNDSTimestamp(
  1187. lpAdsSrcValue,
  1188. lpAdsDestValue
  1189. );
  1190. break;
  1191. case ADSTYPE_POSTALADDRESS:
  1192. hr = AdsCopyPostalAddress(
  1193. lpAdsSrcValue,
  1194. lpAdsDestValue
  1195. );
  1196. break;
  1197. case ADSTYPE_BACKLINK:
  1198. hr = AdsCopyBackLink(
  1199. lpAdsSrcValue,
  1200. lpAdsDestValue
  1201. );
  1202. break;
  1203. case ADSTYPE_TYPEDNAME:
  1204. hr = AdsCopyTypedName(
  1205. lpAdsSrcValue,
  1206. lpAdsDestValue
  1207. );
  1208. break;
  1209. case ADSTYPE_HOLD:
  1210. hr = AdsCopyHold(
  1211. lpAdsSrcValue,
  1212. lpAdsDestValue
  1213. );
  1214. break;
  1215. case ADSTYPE_DN_WITH_BINARY:
  1216. hr = AdsCopyDNWithBinary(
  1217. lpAdsSrcValue,
  1218. lpAdsDestValue
  1219. );
  1220. break;
  1221. case ADSTYPE_DN_WITH_STRING:
  1222. hr = AdsCopyDNWithString(
  1223. lpAdsSrcValue,
  1224. lpAdsDestValue
  1225. );
  1226. break;
  1227. case ADSTYPE_NT_SECURITY_DESCRIPTOR:
  1228. //
  1229. // This should be handled elsewhere not here !
  1230. //
  1231. ADsAssert(!"Invalid option to adscopy");
  1232. break;
  1233. default:
  1234. hr = E_FAIL;
  1235. break;
  1236. }
  1237. RRETURN(hr);
  1238. }
  1239. //
  1240. // This routine is typically used by GetPropertyItem calls.
  1241. //
  1242. HRESULT
  1243. AdsCopyADsValueToPropObj(
  1244. PADSVALUE lpAdsSrcValue,
  1245. CPropertyValue* lpPropObj,
  1246. LPWSTR pszServerName,
  1247. CCredentials* pCredentials,
  1248. BOOL fNTDSType
  1249. )
  1250. {
  1251. HRESULT hr = S_OK;
  1252. PADSVALUE lpAdsDestValue = lpPropObj->getADsValue();
  1253. CCredentials localCredentials(NULL, NULL, 0);
  1254. switch (lpAdsSrcValue->dwType){
  1255. case ADSTYPE_NT_SECURITY_DESCRIPTOR:
  1256. if (pCredentials) {
  1257. localCredentials = *pCredentials;
  1258. }
  1259. hr = AdsCopyNTSecurityDescriptor(
  1260. lpAdsSrcValue,
  1261. lpPropObj,
  1262. pszServerName,
  1263. localCredentials,
  1264. fNTDSType
  1265. );
  1266. break;
  1267. default:
  1268. hr = AdsCopy(
  1269. lpAdsSrcValue,
  1270. lpAdsDestValue
  1271. );
  1272. break;
  1273. }
  1274. RRETURN(hr);
  1275. }
  1276. //
  1277. // This routine is typically used from PutPropertyItem.
  1278. //
  1279. HRESULT
  1280. AdsCopyPropObjToADsValue(
  1281. CPropertyValue *lpPropObj,
  1282. PADSVALUE lpAdsDestValue,
  1283. LPWSTR pszServerName,
  1284. CCredentials* pCredentials,
  1285. BOOL fNTDSType
  1286. )
  1287. {
  1288. HRESULT hr = E_FAIL;
  1289. PADSVALUE lpAdsSrcValue = lpPropObj->getADsValue();
  1290. DWORD dwDataType = 0;
  1291. DWORD dwSDLength = 0;
  1292. PSECURITY_DESCRIPTOR pSecurityDescriptor = NULL;
  1293. CCredentials locCredentials(NULL, NULL, 0);
  1294. IDispatch *pIDispatch = NULL;
  1295. IADsSecurityDescriptor *pIADsSecDesc = NULL;
  1296. switch (lpAdsSrcValue->dwType) {
  1297. case ADSTYPE_NT_SECURITY_DESCRIPTOR :
  1298. dwDataType = lpPropObj->getExtendedDataTypeInfo();
  1299. //
  1300. // if we have the octet blob send it back
  1301. //
  1302. if (dwDataType == CPropertyValue::VAL_IDISPATCH_SECDESC_ALL) {
  1303. hr = AdsCopyOctetString(
  1304. lpAdsSrcValue,
  1305. lpAdsDestValue
  1306. );
  1307. BAIL_ON_FAILURE(hr);
  1308. }
  1309. else if (dwDataType == CPropertyValue::VAL_IDISPATCH_SECDESC_ONLY) {
  1310. if (pCredentials) {
  1311. locCredentials = *pCredentials;
  1312. }
  1313. pIDispatch = lpPropObj->getDispatchPointer();
  1314. if (pIDispatch) {
  1315. hr = pIDispatch->QueryInterface(
  1316. IID_IADsSecurityDescriptor,
  1317. (void **) &pIADsSecDesc
  1318. );
  1319. BAIL_ON_FAILURE(hr);
  1320. }
  1321. hr = ConvertSecurityDescriptorToSecDes(
  1322. pszServerName,
  1323. locCredentials,
  1324. pIADsSecDesc,
  1325. &pSecurityDescriptor,
  1326. &dwSDLength,
  1327. fNTDSType
  1328. );
  1329. BAIL_ON_FAILURE(hr);
  1330. lpAdsDestValue->OctetString.lpValue
  1331. = (LPBYTE) AllocADsMem(dwSDLength);
  1332. if (!(lpAdsDestValue->OctetString.lpValue) && dwSDLength) {
  1333. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  1334. }
  1335. memcpy(
  1336. lpAdsDestValue->OctetString.lpValue,
  1337. pSecurityDescriptor,
  1338. dwSDLength
  1339. );
  1340. lpAdsDestValue->dwType = ADSTYPE_OCTET_STRING;
  1341. lpAdsDestValue->OctetString.dwLength = dwSDLength;
  1342. } // secdesc idispatch only
  1343. break;
  1344. default:
  1345. hr = AdsCopy(
  1346. lpAdsSrcValue,
  1347. lpAdsDestValue
  1348. );
  1349. break;
  1350. } // end case
  1351. error :
  1352. //
  1353. // Needs to be executed in all cases, currently only ret is below
  1354. //
  1355. if (pIADsSecDesc) {
  1356. pIADsSecDesc->Release();
  1357. }
  1358. if (pSecurityDescriptor) {
  1359. FreeADsMem(pSecurityDescriptor);
  1360. }
  1361. RRETURN(hr);
  1362. }
  1363. HRESULT
  1364. PropVariantToAdsType(
  1365. PVARIANT pVariant,
  1366. DWORD dwNumVariant,
  1367. PADSVALUE *ppAdsValues,
  1368. PDWORD pdwNumValues
  1369. )
  1370. {
  1371. return(PropVariantToAdsType2(
  1372. pVariant,
  1373. dwNumVariant,
  1374. ppAdsValues,
  1375. pdwNumValues,
  1376. NULL, // serverName,
  1377. NULL, // pCredentials
  1378. TRUE // NTDS Type
  1379. ));
  1380. }
  1381. HRESULT
  1382. PropVariantToAdsType2(
  1383. PVARIANT pVariant,
  1384. DWORD dwNumVariant,
  1385. PADSVALUE *ppAdsValues,
  1386. PDWORD pdwNumValues,
  1387. LPWSTR pszServerName,
  1388. CCredentials* pCredentials,
  1389. BOOL fNTDSType
  1390. )
  1391. {
  1392. DWORD i = 0;
  1393. VARIANT * pVar = NULL;
  1394. DWORD dwCount = 0;
  1395. IDispatch FAR * pDispatch = NULL;
  1396. IADsValue FAR * pPropValue = NULL;
  1397. PADSVALUE pADsValues = NULL;
  1398. HRESULT hr = S_OK;
  1399. LPWSTR pszUserName = NULL;
  1400. LPWSTR pszPassWord = NULL;
  1401. DWORD dwFlags = 0;
  1402. pADsValues = (PADSVALUE)AllocADsMem(dwNumVariant * sizeof(ADSVALUE));
  1403. if (!pADsValues && dwNumVariant) {
  1404. RRETURN(E_OUTOFMEMORY);
  1405. }
  1406. //
  1407. // If !pCredentials, use the initialized values as they
  1408. // represent an object with CCredentials(NULL, NULL, 0)
  1409. //
  1410. if (pCredentials) {
  1411. hr = pCredentials->GetUserName(&pszUserName);
  1412. BAIL_ON_FAILURE(hr);
  1413. hr = pCredentials->GetPassword(&pszPassWord);
  1414. BAIL_ON_FAILURE(hr);
  1415. dwFlags = pCredentials->GetAuthFlags();
  1416. }
  1417. for (i = 0; i < dwNumVariant; i++ ) {
  1418. pVar = pVariant + i;
  1419. pDispatch = V_DISPATCH(pVar);
  1420. hr = pDispatch->QueryInterface(
  1421. IID_IADsValue,
  1422. (void **)&pPropValue
  1423. );
  1424. CONTINUE_ON_FAILURE(hr);
  1425. hr = pPropValue->ConvertPropertyValueToADsValue2(
  1426. (pADsValues + dwCount),
  1427. pszServerName,
  1428. pszUserName,
  1429. pszPassWord,
  1430. dwFlags,
  1431. fNTDSType
  1432. );
  1433. pPropValue->Release();
  1434. BAIL_ON_FAILURE(hr);
  1435. dwCount++;
  1436. }
  1437. *ppAdsValues = pADsValues;
  1438. *pdwNumValues = dwCount;
  1439. error:
  1440. if (pszUserName) {
  1441. FreeADsStr(pszUserName);
  1442. }
  1443. if (pszPassWord) {
  1444. SecureZeroMemory(pszPassWord, wcslen(pszPassWord)*sizeof(WCHAR));
  1445. FreeADsStr(pszPassWord);
  1446. }
  1447. if (FAILED(hr) && pADsValues) {
  1448. FreeADsMem(pADsValues);
  1449. }
  1450. RRETURN(hr);
  1451. }
  1452. HRESULT
  1453. AdsTypeToPropVariant2(
  1454. PADSVALUE pAdsValues,
  1455. DWORD dwNumValues,
  1456. PVARIANT pVarDestObjects,
  1457. LPWSTR pszServerName,
  1458. CCredentials* pCredentials,
  1459. BOOL fNTDSType
  1460. )
  1461. {
  1462. long i = 0;
  1463. HRESULT hr = S_OK;
  1464. CPropertyValue * pAdsValue = NULL;
  1465. VariantInit( pVarDestObjects );
  1466. //
  1467. // The following are for handling are multi-value properties
  1468. //
  1469. SAFEARRAY *aList = NULL;
  1470. SAFEARRAYBOUND aBound;
  1471. aBound.lLbound = 0;
  1472. aBound.cElements = dwNumValues;
  1473. aList = SafeArrayCreate( VT_VARIANT, 1, &aBound );
  1474. if ( aList == NULL )
  1475. {
  1476. hr = E_OUTOFMEMORY;
  1477. BAIL_ON_FAILURE(hr);
  1478. }
  1479. for ( i = 0; i < (long)dwNumValues; i++ )
  1480. {
  1481. VARIANT v;
  1482. IDispatch FAR * pDispatch = NULL;
  1483. VariantInit(&v);
  1484. hr = CPropertyValue::AllocatePropertyValueObject(&pAdsValue);
  1485. BAIL_ON_FAILURE(hr);
  1486. hr = pAdsValue->ConvertADsValueToPropertyValue2(
  1487. pAdsValues + i,
  1488. pszServerName,
  1489. pCredentials,
  1490. fNTDSType
  1491. );
  1492. BAIL_ON_FAILURE(hr);
  1493. hr = pAdsValue->QueryInterface(
  1494. IID_IDispatch,
  1495. (void **)&pDispatch
  1496. );
  1497. BAIL_ON_FAILURE(hr);
  1498. V_DISPATCH(&v) = pDispatch;
  1499. V_VT(&v) = VT_DISPATCH;
  1500. if (pAdsValue) {
  1501. pAdsValue->Release();
  1502. pAdsValue = NULL;
  1503. }
  1504. hr = SafeArrayPutElement( aList, &i, &v );
  1505. VariantClear(&v);
  1506. pDispatch = NULL;
  1507. BAIL_ON_FAILURE(hr);
  1508. }
  1509. V_VT(pVarDestObjects) = VT_ARRAY | VT_VARIANT;
  1510. V_ARRAY(pVarDestObjects) = aList;
  1511. RRETURN(S_OK);
  1512. error:
  1513. if ( aList )
  1514. SafeArrayDestroy( aList );
  1515. if(pAdsValue)
  1516. {
  1517. pAdsValue->Release();
  1518. pAdsValue = NULL;
  1519. }
  1520. RRETURN(hr);
  1521. }
  1522. HRESULT
  1523. AdsTypeToPropVariant(
  1524. PADSVALUE pAdsValues,
  1525. DWORD dwNumValues,
  1526. PVARIANT pVarDestObjects
  1527. )
  1528. {
  1529. RRETURN( AdsTypeToPropVariant2(
  1530. pAdsValues,
  1531. dwNumValues,
  1532. pVarDestObjects,
  1533. NULL, // serverName
  1534. NULL, // pCredentials
  1535. TRUE // serverType
  1536. )
  1537. );
  1538. }
  1539. void
  1540. AdsFreeAdsValues(
  1541. PADSVALUE pAdsValues,
  1542. DWORD dwNumValues
  1543. )
  1544. {
  1545. LPBYTE pMem = NULL;
  1546. for ( DWORD i = 0; i < dwNumValues; i++ )
  1547. {
  1548. AdsClear(&pAdsValues[i]);
  1549. }
  1550. }