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.

1010 lines
25 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: ods2nds.cxx
  7. //
  8. // Contents: NDS Object to Variant Copy Routines
  9. //
  10. // Functions:
  11. //
  12. // History: 25-Apr-96 KrishnaG Created.
  13. //
  14. //
  15. //
  16. //----------------------------------------------------------------------------
  17. #include "nds.hxx"
  18. HRESULT
  19. AdsTypeToNdsTypeCopyDNString(
  20. PADSVALUE lpAdsSrcValue,
  21. PNDSOBJECT lpNdsDestObject
  22. )
  23. {
  24. HRESULT hr = S_OK;
  25. if(lpAdsSrcValue->dwType != ADSTYPE_DN_STRING){
  26. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  27. }
  28. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_1;
  29. lpNdsDestObject->NdsValue.value_1.DNString =
  30. AllocADsStr(
  31. lpAdsSrcValue->DNString
  32. );
  33. if (!lpNdsDestObject->NdsValue.value_1.DNString) {
  34. hr = E_OUTOFMEMORY;
  35. }
  36. RRETURN(hr);
  37. }
  38. HRESULT
  39. AdsTypeToNdsTypeCopyCaseExactString(
  40. PADSVALUE lpAdsSrcValue,
  41. PNDSOBJECT lpNdsDestObject
  42. )
  43. {
  44. HRESULT hr = S_OK;
  45. if(lpAdsSrcValue->dwType != ADSTYPE_CASE_EXACT_STRING){
  46. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  47. }
  48. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_2;
  49. lpNdsDestObject->NdsValue.value_2.CaseExactString =
  50. AllocADsStr(
  51. lpAdsSrcValue->CaseExactString
  52. );
  53. if (!lpNdsDestObject->NdsValue.value_2.CaseExactString) {
  54. hr = E_OUTOFMEMORY;
  55. }
  56. RRETURN(hr);
  57. }
  58. HRESULT
  59. AdsTypeToNdsTypeCopyCaseIgnoreList(
  60. PADSVALUE lpAdsSrcValue,
  61. PNDSOBJECT lpNdsDestObject
  62. )
  63. {
  64. HRESULT hr = S_OK;
  65. PADS_PROV_SPECIFIC test;
  66. PADS_CASEIGNORE_LIST pAdsNext = lpAdsSrcValue->pCaseIgnoreList;
  67. struct _NDS_CI_LIST *pNdsOutput = &lpNdsDestObject->NdsValue.value_6;
  68. struct _NDS_CI_LIST *pNdsCurrent = NULL;
  69. if(lpAdsSrcValue->dwType != ADSTYPE_CASEIGNORE_LIST){
  70. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  71. }
  72. if (pAdsNext == NULL) {
  73. hr = E_FAIL;
  74. BAIL_ON_FAILURE(hr);
  75. }
  76. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_6;
  77. pNdsOutput->String = AllocADsStr(pAdsNext->String);
  78. if (!pNdsOutput->String ) {
  79. hr = E_OUTOFMEMORY;
  80. BAIL_ON_FAILURE(hr);
  81. }
  82. pAdsNext = pAdsNext->Next;
  83. while (pAdsNext) {
  84. pNdsCurrent = (struct _NDS_CI_LIST *)AllocADsMem(sizeof(struct _NDS_CI_LIST));
  85. if (!pNdsCurrent) {
  86. hr = E_OUTOFMEMORY;
  87. BAIL_ON_FAILURE(hr);
  88. }
  89. pNdsCurrent->String = AllocADsStr(pAdsNext->String);
  90. if (!pNdsCurrent->String ) {
  91. hr = E_OUTOFMEMORY;
  92. BAIL_ON_FAILURE(hr);
  93. }
  94. pNdsOutput->Next = pNdsCurrent;
  95. pNdsOutput = pNdsOutput->Next;
  96. pAdsNext = pAdsNext->Next;
  97. }
  98. pNdsOutput->Next = NULL;
  99. error:
  100. RRETURN(hr);
  101. }
  102. HRESULT
  103. AdsTypeToNdsTypeCopyOctetList(
  104. PADSVALUE lpAdsSrcValue,
  105. PNDSOBJECT lpNdsDestObject
  106. )
  107. {
  108. HRESULT hr = S_OK;
  109. PADS_OCTET_LIST pAdsNext = lpAdsSrcValue->pOctetList;
  110. struct _NDS_OCTET_LIST *pNdsOutput = &lpNdsDestObject->NdsValue.value_13;
  111. struct _NDS_OCTET_LIST *pNdsCurrent = NULL;
  112. if(lpAdsSrcValue->dwType != ADSTYPE_OCTET_LIST){
  113. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  114. }
  115. if (pAdsNext == NULL) {
  116. hr = E_FAIL;
  117. RRETURN(hr);
  118. }
  119. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_13;
  120. pNdsOutput->Next = NULL;
  121. pNdsOutput->Data = NULL;
  122. hr = CopyOctetString(pAdsNext->Length,
  123. pAdsNext->Data,
  124. &pNdsOutput->Length,
  125. &pNdsOutput->Data);
  126. BAIL_ON_FAILURE(hr);
  127. pAdsNext = pAdsNext->Next;
  128. while (pAdsNext) {
  129. pNdsCurrent = (struct _NDS_OCTET_LIST *)AllocADsMem(sizeof(struct _NDS_OCTET_LIST));
  130. if (!pNdsCurrent) {
  131. hr = E_OUTOFMEMORY;
  132. BAIL_ON_FAILURE(hr);
  133. }
  134. pNdsCurrent->Next = NULL;
  135. pNdsCurrent->Data = NULL;
  136. hr = CopyOctetString(pAdsNext->Length,
  137. pAdsNext->Data,
  138. &pNdsCurrent->Length,
  139. &pNdsCurrent->Data);
  140. if (FAILED(hr)) {
  141. FreeADsMem(pNdsCurrent);
  142. BAIL_ON_FAILURE(hr);
  143. }
  144. pNdsOutput->Next = pNdsCurrent;
  145. pNdsOutput = pNdsCurrent;
  146. pAdsNext = pAdsNext->Next;
  147. }
  148. pNdsOutput->Next = NULL;
  149. RRETURN(hr);
  150. error:
  151. if (lpNdsDestObject->NdsValue.value_13.Data) {
  152. FreeADsMem(lpNdsDestObject->NdsValue.value_13.Data);
  153. }
  154. pNdsOutput = lpNdsDestObject->NdsValue.value_13.Next;
  155. while (pNdsOutput) {
  156. if (pNdsOutput->Data) {
  157. FreeADsMem(pNdsOutput->Data);
  158. }
  159. pNdsCurrent = pNdsOutput->Next;
  160. FreeADsMem(pNdsOutput);
  161. pNdsOutput = pNdsCurrent;
  162. }
  163. RRETURN(hr);
  164. }
  165. HRESULT
  166. AdsTypeToNdsTypeCopyPath(
  167. PADSVALUE lpAdsSrcValue,
  168. PNDSOBJECT lpNdsDestObject
  169. )
  170. {
  171. HRESULT hr = S_OK;
  172. if(lpAdsSrcValue->dwType != ADSTYPE_PATH){
  173. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  174. }
  175. if (lpAdsSrcValue->pPath == NULL) {
  176. hr = E_FAIL;
  177. BAIL_ON_FAILURE(hr);
  178. }
  179. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_15;
  180. lpNdsDestObject->NdsValue.value_15.VolumeName =
  181. AllocADsStr(
  182. lpAdsSrcValue->pPath->VolumeName
  183. );
  184. if (!lpNdsDestObject->NdsValue.value_15.VolumeName) {
  185. hr = E_OUTOFMEMORY;
  186. BAIL_ON_FAILURE(hr);
  187. }
  188. lpNdsDestObject->NdsValue.value_15.Path=
  189. AllocADsStr(
  190. lpAdsSrcValue->pPath->Path
  191. );
  192. if (!lpNdsDestObject->NdsValue.value_15.Path) {
  193. hr = E_OUTOFMEMORY;
  194. BAIL_ON_FAILURE(hr);
  195. }
  196. lpNdsDestObject->NdsValue.value_15.Type =
  197. lpAdsSrcValue->pPath->Type;
  198. error:
  199. RRETURN(hr);
  200. }
  201. HRESULT
  202. AdsTypeToNdsTypeCopyPostalAddress(
  203. PADSVALUE lpAdsSrcValue,
  204. PNDSOBJECT lpNdsDestObject
  205. )
  206. {
  207. HRESULT hr = S_OK;
  208. long i;
  209. if(lpAdsSrcValue->dwType != ADSTYPE_POSTALADDRESS){
  210. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  211. }
  212. if (lpAdsSrcValue->pPostalAddress == NULL) {
  213. hr = E_FAIL;
  214. BAIL_ON_FAILURE(hr);
  215. }
  216. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_18;
  217. for (i=0;i<6;i++) {
  218. if (lpAdsSrcValue->pPostalAddress->PostalAddress[i]) {
  219. lpNdsDestObject->NdsValue.value_18.PostalAddress[i] =
  220. AllocADsStr(
  221. lpAdsSrcValue->pPostalAddress->PostalAddress[i]
  222. );
  223. if (!lpNdsDestObject->NdsValue.value_18.PostalAddress[i]) {
  224. hr = E_OUTOFMEMORY;
  225. BAIL_ON_FAILURE(hr);
  226. }
  227. }
  228. else {
  229. lpNdsDestObject->NdsValue.value_18.PostalAddress[i] =
  230. AllocADsStr(
  231. L""
  232. );
  233. if (!lpNdsDestObject->NdsValue.value_18.PostalAddress[i]) {
  234. hr = E_OUTOFMEMORY;
  235. BAIL_ON_FAILURE(hr);
  236. }
  237. }
  238. }
  239. error:
  240. RRETURN(hr);
  241. }
  242. HRESULT
  243. AdsTypeToNdsTypeCopyNdsTime(
  244. PADSVALUE lpAdsSrcValue,
  245. PNDSOBJECT lpNdsDestObject
  246. )
  247. {
  248. HRESULT hr = S_OK;
  249. if(lpAdsSrcValue->dwType != ADSTYPE_TIMESTAMP){
  250. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  251. }
  252. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_19;
  253. lpNdsDestObject->NdsValue.value_19.WholeSeconds =
  254. lpAdsSrcValue->Timestamp.WholeSeconds;
  255. lpNdsDestObject->NdsValue.value_19.EventID =
  256. lpAdsSrcValue->Timestamp.EventID;
  257. RRETURN(hr);
  258. }
  259. HRESULT
  260. AdsTypeToNdsTypeCopyBackLink(
  261. PADSVALUE lpAdsSrcValue,
  262. PNDSOBJECT lpNdsDestObject
  263. )
  264. {
  265. HRESULT hr = S_OK;
  266. if(lpAdsSrcValue->dwType != ADSTYPE_BACKLINK){
  267. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  268. }
  269. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_23;
  270. lpNdsDestObject->NdsValue.value_23.ObjectName =
  271. AllocADsStr(
  272. lpAdsSrcValue->BackLink.ObjectName
  273. );
  274. if (!lpNdsDestObject->NdsValue.value_23.ObjectName) {
  275. hr = E_OUTOFMEMORY;
  276. BAIL_ON_FAILURE(hr);
  277. }
  278. lpNdsDestObject->NdsValue.value_23.RemoteID =
  279. lpAdsSrcValue->BackLink.RemoteID;
  280. error:
  281. RRETURN(hr);
  282. }
  283. HRESULT
  284. AdsTypeToNdsTypeCopyTypedName(
  285. PADSVALUE lpAdsSrcValue,
  286. PNDSOBJECT lpNdsDestObject
  287. )
  288. {
  289. HRESULT hr = S_OK;
  290. if(lpAdsSrcValue->dwType != ADSTYPE_TYPEDNAME){
  291. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  292. }
  293. if (lpAdsSrcValue->pTypedName == NULL) {
  294. hr = E_FAIL;
  295. BAIL_ON_FAILURE(hr);
  296. }
  297. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_25;
  298. lpNdsDestObject->NdsValue.value_25.ObjectName=
  299. AllocADsStr(
  300. lpAdsSrcValue->pTypedName->ObjectName
  301. );
  302. if (!lpNdsDestObject->NdsValue.value_25.ObjectName) {
  303. hr = E_OUTOFMEMORY;
  304. BAIL_ON_FAILURE(hr);
  305. }
  306. lpNdsDestObject->NdsValue.value_25.Level=
  307. lpAdsSrcValue->pTypedName->Level;
  308. lpNdsDestObject->NdsValue.value_25.Interval=
  309. lpAdsSrcValue->pTypedName->Interval;
  310. error:
  311. RRETURN(hr);
  312. }
  313. HRESULT
  314. AdsTypeToNdsTypeCopyHold(
  315. PADSVALUE lpAdsSrcValue,
  316. PNDSOBJECT lpNdsDestObject
  317. )
  318. {
  319. HRESULT hr = S_OK;
  320. if(lpAdsSrcValue->dwType != ADSTYPE_HOLD){
  321. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  322. }
  323. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_26;
  324. lpNdsDestObject->NdsValue.value_26.ObjectName=
  325. AllocADsStr(
  326. lpAdsSrcValue->Hold.ObjectName
  327. );
  328. if (!lpNdsDestObject->NdsValue.value_26.ObjectName) {
  329. hr = E_OUTOFMEMORY;
  330. BAIL_ON_FAILURE(hr);
  331. }
  332. lpNdsDestObject->NdsValue.value_26.Amount=
  333. lpAdsSrcValue->Hold.Amount;
  334. error:
  335. RRETURN(hr);
  336. }
  337. HRESULT
  338. AdsTypeToNdsTypeCopyEmail(
  339. PADSVALUE lpAdsSrcValue,
  340. PNDSOBJECT lpNdsDestObject
  341. )
  342. {
  343. HRESULT hr = S_OK;
  344. if(lpAdsSrcValue->dwType != ADSTYPE_EMAIL){
  345. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  346. }
  347. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_14;
  348. lpNdsDestObject->NdsValue.value_14.Address=
  349. AllocADsStr(
  350. lpAdsSrcValue->Email.Address
  351. );
  352. if (!lpNdsDestObject->NdsValue.value_14.Address) {
  353. hr = E_OUTOFMEMORY;
  354. BAIL_ON_FAILURE(hr);
  355. }
  356. lpNdsDestObject->NdsValue.value_14.Type=
  357. lpAdsSrcValue->Email.Type;
  358. error:
  359. RRETURN(hr);
  360. }
  361. HRESULT
  362. AdsTypeToNdsTypeCopyNetAddress(
  363. PADSVALUE lpAdsSrcValue,
  364. PNDSOBJECT lpNdsDestObject
  365. )
  366. {
  367. HRESULT hr = S_OK;
  368. if(lpAdsSrcValue->dwType != ADSTYPE_NETADDRESS){
  369. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  370. }
  371. if (lpAdsSrcValue->pNetAddress == NULL) {
  372. hr = E_FAIL;
  373. BAIL_ON_FAILURE(hr);
  374. }
  375. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_12;
  376. lpNdsDestObject->NdsValue.value_12.AddressType =
  377. lpAdsSrcValue->pNetAddress->AddressType;
  378. hr = CopyOctetString(lpAdsSrcValue->pNetAddress->AddressLength,
  379. lpAdsSrcValue->pNetAddress->Address,
  380. &lpNdsDestObject->NdsValue.value_12.AddressLength,
  381. &lpNdsDestObject->NdsValue.value_12.Address);
  382. BAIL_ON_FAILURE(hr);
  383. error:
  384. RRETURN(hr);
  385. }
  386. HRESULT
  387. AdsTypeToNdsTypeCopyFaxNumber(
  388. PADSVALUE lpAdsSrcValue,
  389. PNDSOBJECT lpNdsDestObject
  390. )
  391. {
  392. HRESULT hr = S_OK;
  393. if(lpAdsSrcValue->dwType != ADSTYPE_FAXNUMBER){
  394. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  395. }
  396. if (lpAdsSrcValue->pFaxNumber == NULL) {
  397. hr = E_FAIL;
  398. BAIL_ON_FAILURE(hr);
  399. }
  400. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_11;
  401. lpNdsDestObject->NdsValue.value_11.TelephoneNumber =
  402. AllocADsStr(lpAdsSrcValue->pFaxNumber->TelephoneNumber);
  403. if (!lpNdsDestObject->NdsValue.value_11.TelephoneNumber) {
  404. hr = E_OUTOFMEMORY;
  405. BAIL_ON_FAILURE(hr);
  406. }
  407. hr = CopyOctetString(lpAdsSrcValue->pFaxNumber->NumberOfBits,
  408. lpAdsSrcValue->pFaxNumber->Parameters,
  409. &lpNdsDestObject->NdsValue.value_11.NumberOfBits,
  410. &lpNdsDestObject->NdsValue.value_11.Parameters);
  411. BAIL_ON_FAILURE(hr);
  412. error:
  413. RRETURN(hr);
  414. }
  415. HRESULT
  416. AdsTypeToNdsTypeCopyReplicaPointer(
  417. PADSVALUE lpAdsSrcValue,
  418. PNDSOBJECT lpNdsDestObject
  419. )
  420. {
  421. HRESULT hr = S_OK;
  422. DWORD dwCount,dwIter;
  423. if(lpAdsSrcValue->dwType != ADSTYPE_REPLICAPOINTER){
  424. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  425. }
  426. if (lpAdsSrcValue->pReplicaPointer == NULL) {
  427. hr = E_FAIL;
  428. BAIL_ON_FAILURE(hr);
  429. }
  430. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_16;
  431. lpNdsDestObject->NdsValue.value_16.ServerName=
  432. AllocADsStr(
  433. lpAdsSrcValue->pReplicaPointer->ServerName
  434. );
  435. if (!lpNdsDestObject->NdsValue.value_16.ServerName) {
  436. hr = E_OUTOFMEMORY;
  437. BAIL_ON_FAILURE(hr);
  438. }
  439. lpNdsDestObject->NdsValue.value_16.ReplicaType =
  440. lpAdsSrcValue->pReplicaPointer->ReplicaType;
  441. lpNdsDestObject->NdsValue.value_16.ReplicaNumber =
  442. lpAdsSrcValue->pReplicaPointer->ReplicaNumber;
  443. dwCount = lpAdsSrcValue->pReplicaPointer->Count;
  444. lpNdsDestObject->NdsValue.value_16.ReplicaAddressHints =
  445. (LPNDS_ASN1_TYPE_12)AllocADsMem(sizeof(NDS_ASN1_TYPE_12 )*dwCount);
  446. if (!lpNdsDestObject->NdsValue.value_16.ReplicaAddressHints) {
  447. hr = E_OUTOFMEMORY;
  448. BAIL_ON_FAILURE(hr);
  449. }
  450. memset(lpNdsDestObject->NdsValue.value_16.ReplicaAddressHints, 0, sizeof(NDS_ASN1_TYPE_12 )*dwCount);
  451. for ( dwIter = 0; dwIter < dwCount; dwIter++ ) {
  452. (lpNdsDestObject->NdsValue.value_16.ReplicaAddressHints+dwIter)->AddressType =
  453. (lpAdsSrcValue->pReplicaPointer->ReplicaAddressHints+dwIter)->AddressType;
  454. hr = CopyOctetString((lpAdsSrcValue->pReplicaPointer->ReplicaAddressHints+dwIter)->AddressLength,
  455. (lpAdsSrcValue->pReplicaPointer->ReplicaAddressHints+dwIter)->Address,
  456. &((lpNdsDestObject->NdsValue.value_16.ReplicaAddressHints+dwIter)->AddressLength),
  457. &((lpNdsDestObject->NdsValue.value_16.ReplicaAddressHints+dwIter)->Address));
  458. }
  459. lpNdsDestObject->NdsValue.value_16.Count = dwCount;
  460. error:
  461. RRETURN(hr);
  462. }
  463. HRESULT
  464. AdsTypeToNdsTypeCopyCaseIgnoreString(
  465. PADSVALUE lpAdsSrcValue,
  466. PNDSOBJECT lpNdsDestObject
  467. )
  468. {
  469. HRESULT hr = S_OK;
  470. if(lpAdsSrcValue->dwType != ADSTYPE_CASE_IGNORE_STRING){
  471. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  472. }
  473. lpNdsDestObject->NdsType = ADSTYPE_CASE_IGNORE_STRING;
  474. lpNdsDestObject->NdsValue.value_3.CaseIgnoreString =
  475. AllocADsStr(
  476. lpAdsSrcValue->CaseIgnoreString
  477. );
  478. if (!lpNdsDestObject->NdsValue.value_3.CaseIgnoreString) {
  479. hr = E_OUTOFMEMORY;
  480. }
  481. RRETURN(hr);
  482. }
  483. HRESULT
  484. AdsTypeToNdsTypeCopyPrintableString(
  485. PADSVALUE lpAdsSrcValue,
  486. PNDSOBJECT lpNdsDestObject
  487. )
  488. {
  489. HRESULT hr = S_OK;
  490. if(lpAdsSrcValue->dwType != ADSTYPE_PRINTABLE_STRING){
  491. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  492. }
  493. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_4;
  494. lpNdsDestObject->NdsValue.value_4.PrintableString =
  495. AllocADsStr(
  496. lpAdsSrcValue->PrintableString
  497. );
  498. if (!lpNdsDestObject->NdsValue.value_4.PrintableString) {
  499. hr = E_OUTOFMEMORY;
  500. BAIL_ON_FAILURE(hr);
  501. }
  502. error:
  503. RRETURN(hr);
  504. }
  505. HRESULT
  506. AdsTypeToNdsTypeCopyNumericString(
  507. PADSVALUE lpAdsSrcValue,
  508. PNDSOBJECT lpNdsDestObject
  509. )
  510. {
  511. HRESULT hr = S_OK;
  512. if(lpAdsSrcValue->dwType != ADSTYPE_NUMERIC_STRING){
  513. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  514. }
  515. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_5;
  516. lpNdsDestObject->NdsValue.value_5.NumericString =
  517. AllocADsStr(
  518. lpAdsSrcValue->NumericString
  519. );
  520. if (!lpNdsDestObject->NdsValue.value_5.NumericString) {
  521. hr = E_OUTOFMEMORY;
  522. BAIL_ON_FAILURE(hr);
  523. }
  524. error:
  525. RRETURN(hr);
  526. }
  527. HRESULT
  528. AdsTypeToNdsTypeCopyBoolean(
  529. PADSVALUE lpAdsSrcValue,
  530. PNDSOBJECT lpNdsDestObject
  531. )
  532. {
  533. HRESULT hr = S_OK;
  534. if(lpAdsSrcValue->dwType != ADSTYPE_BOOLEAN){
  535. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  536. }
  537. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_7;
  538. lpNdsDestObject->NdsValue.value_7.Boolean =
  539. lpAdsSrcValue->Boolean;
  540. RRETURN(hr);
  541. }
  542. HRESULT
  543. AdsTypeToNdsTypeCopyInteger(
  544. PADSVALUE lpAdsSrcValue,
  545. PNDSOBJECT lpNdsDestObject
  546. )
  547. {
  548. HRESULT hr = S_OK;
  549. if(lpAdsSrcValue->dwType != ADSTYPE_INTEGER){
  550. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  551. }
  552. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_8;
  553. lpNdsDestObject->NdsValue.value_8.Integer =
  554. lpAdsSrcValue->Integer;
  555. RRETURN(hr);
  556. }
  557. HRESULT
  558. AdsTypeToNdsTypeCopyOctetString(
  559. PADSVALUE lpAdsSrcValue,
  560. PNDSOBJECT lpNdsDestObject
  561. )
  562. {
  563. LPBYTE lpByteStream = NULL;
  564. DWORD dwNumBytes = 0;
  565. HRESULT hr = S_OK;
  566. if(lpAdsSrcValue->dwType != ADSTYPE_OCTET_STRING){
  567. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  568. }
  569. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_9;
  570. dwNumBytes = lpAdsSrcValue->OctetString.dwLength;
  571. lpByteStream = (LPBYTE)AllocADsMem(dwNumBytes);
  572. if (!lpByteStream) {
  573. hr = E_OUTOFMEMORY;
  574. BAIL_ON_FAILURE(hr);
  575. }
  576. memcpy(
  577. lpByteStream,
  578. lpAdsSrcValue->OctetString.lpValue,
  579. dwNumBytes
  580. );
  581. lpNdsDestObject->NdsValue.value_9.Length = dwNumBytes;
  582. lpNdsDestObject->NdsValue.value_9.OctetString = lpByteStream;
  583. error:
  584. RRETURN(hr);
  585. }
  586. HRESULT
  587. AdsTypeToNdsTypeCopyTime(
  588. PADSVALUE lpAdsSrcValue,
  589. PNDSOBJECT lpNdsDestObject
  590. )
  591. {
  592. HRESULT hr = S_OK;
  593. if(lpAdsSrcValue->dwType != ADSTYPE_UTC_TIME){
  594. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  595. }
  596. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_24;
  597. hr = ConvertSYSTEMTIMEtoDWORD(
  598. &(lpAdsSrcValue->UTCTime),
  599. &(lpNdsDestObject->NdsValue.value_24.Time)
  600. );
  601. RRETURN(hr);
  602. }
  603. HRESULT
  604. AdsTypeToNdsTypeCopyObjectClass(
  605. PADSVALUE lpAdsSrcValue,
  606. PNDSOBJECT lpNdsDestObject
  607. )
  608. {
  609. HRESULT hr = S_OK;
  610. if(lpAdsSrcValue->dwType != ADSTYPE_OBJECT_CLASS){
  611. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  612. }
  613. lpNdsDestObject->NdsType = NDS_SYNTAX_ID_20;
  614. lpNdsDestObject->NdsValue.value_20.ClassName =
  615. AllocADsStr(
  616. lpAdsSrcValue->ClassName
  617. );
  618. if (!lpNdsDestObject->NdsValue.value_20.ClassName) {
  619. hr = E_OUTOFMEMORY;
  620. BAIL_ON_FAILURE(hr);
  621. }
  622. error:
  623. RRETURN(hr);
  624. }
  625. HRESULT
  626. AdsTypeToNdsTypeCopy(
  627. PADSVALUE lpAdsSrcValue,
  628. PNDSOBJECT lpNdsDestObject
  629. )
  630. {
  631. HRESULT hr = S_OK;
  632. switch (lpAdsSrcValue->dwType){
  633. case ADSTYPE_DN_STRING:
  634. hr = AdsTypeToNdsTypeCopyDNString(
  635. lpAdsSrcValue,
  636. lpNdsDestObject
  637. );
  638. break;
  639. case ADSTYPE_CASE_EXACT_STRING:
  640. hr = AdsTypeToNdsTypeCopyCaseExactString(
  641. lpAdsSrcValue,
  642. lpNdsDestObject
  643. );
  644. break;
  645. case ADSTYPE_CASE_IGNORE_STRING:
  646. hr = AdsTypeToNdsTypeCopyCaseIgnoreString(
  647. lpAdsSrcValue,
  648. lpNdsDestObject
  649. );
  650. break;
  651. case ADSTYPE_PRINTABLE_STRING:
  652. hr = AdsTypeToNdsTypeCopyPrintableString(
  653. lpAdsSrcValue,
  654. lpNdsDestObject
  655. );
  656. break;
  657. case ADSTYPE_NUMERIC_STRING:
  658. hr = AdsTypeToNdsTypeCopyNumericString(
  659. lpAdsSrcValue,
  660. lpNdsDestObject
  661. );
  662. break;
  663. case ADSTYPE_BOOLEAN:
  664. hr = AdsTypeToNdsTypeCopyBoolean(
  665. lpAdsSrcValue,
  666. lpNdsDestObject
  667. );
  668. break;
  669. case ADSTYPE_INTEGER:
  670. hr = AdsTypeToNdsTypeCopyInteger(
  671. lpAdsSrcValue,
  672. lpNdsDestObject
  673. );
  674. break;
  675. case ADSTYPE_OCTET_STRING:
  676. hr = AdsTypeToNdsTypeCopyOctetString(
  677. lpAdsSrcValue,
  678. lpNdsDestObject
  679. );
  680. break;
  681. case ADSTYPE_UTC_TIME:
  682. hr = AdsTypeToNdsTypeCopyTime(
  683. lpAdsSrcValue,
  684. lpNdsDestObject
  685. );
  686. break;
  687. case ADSTYPE_OBJECT_CLASS:
  688. hr = AdsTypeToNdsTypeCopyObjectClass(
  689. lpAdsSrcValue,
  690. lpNdsDestObject
  691. );
  692. break;
  693. case ADSTYPE_CASEIGNORE_LIST:
  694. hr = AdsTypeToNdsTypeCopyCaseIgnoreList(
  695. lpAdsSrcValue,
  696. lpNdsDestObject
  697. );
  698. break;
  699. case ADSTYPE_FAXNUMBER:
  700. hr = AdsTypeToNdsTypeCopyFaxNumber(
  701. lpAdsSrcValue,
  702. lpNdsDestObject
  703. );
  704. break;
  705. case ADSTYPE_NETADDRESS:
  706. hr = AdsTypeToNdsTypeCopyNetAddress(
  707. lpAdsSrcValue,
  708. lpNdsDestObject
  709. );
  710. break;
  711. case ADSTYPE_OCTET_LIST:
  712. hr = AdsTypeToNdsTypeCopyOctetList(
  713. lpAdsSrcValue,
  714. lpNdsDestObject
  715. );
  716. break;
  717. case ADSTYPE_EMAIL:
  718. hr = AdsTypeToNdsTypeCopyEmail(
  719. lpAdsSrcValue,
  720. lpNdsDestObject
  721. );
  722. break;
  723. case ADSTYPE_PATH:
  724. hr = AdsTypeToNdsTypeCopyPath(
  725. lpAdsSrcValue,
  726. lpNdsDestObject
  727. );
  728. break;
  729. case ADSTYPE_REPLICAPOINTER:
  730. hr = AdsTypeToNdsTypeCopyReplicaPointer(
  731. lpAdsSrcValue,
  732. lpNdsDestObject
  733. );
  734. break;
  735. case ADSTYPE_TIMESTAMP:
  736. hr = AdsTypeToNdsTypeCopyNdsTime(
  737. lpAdsSrcValue,
  738. lpNdsDestObject
  739. );
  740. break;
  741. case ADSTYPE_POSTALADDRESS:
  742. hr = AdsTypeToNdsTypeCopyPostalAddress(
  743. lpAdsSrcValue,
  744. lpNdsDestObject
  745. );
  746. break;
  747. case ADSTYPE_BACKLINK:
  748. hr = AdsTypeToNdsTypeCopyBackLink(
  749. lpAdsSrcValue,
  750. lpNdsDestObject
  751. );
  752. break;
  753. case ADSTYPE_TYPEDNAME:
  754. hr = AdsTypeToNdsTypeCopyTypedName(
  755. lpAdsSrcValue,
  756. lpNdsDestObject
  757. );
  758. break;
  759. case ADSTYPE_HOLD:
  760. hr = AdsTypeToNdsTypeCopyHold(
  761. lpAdsSrcValue,
  762. lpNdsDestObject
  763. );
  764. break;
  765. default:
  766. hr = E_FAIL;
  767. break;
  768. }
  769. RRETURN(hr);
  770. }
  771. HRESULT
  772. AdsTypeToNdsTypeCopyConstruct(
  773. LPADSVALUE pAdsSrcValues,
  774. DWORD dwNumObjects,
  775. LPNDSOBJECT * ppNdsDestObjects,
  776. PDWORD pdwNumNdsObjects,
  777. PDWORD pdwNdsSyntaxId
  778. )
  779. {
  780. DWORD i = 0;
  781. LPNDSOBJECT pNdsDestObjects = NULL;
  782. HRESULT hr = S_OK;
  783. pNdsDestObjects = (LPNDSOBJECT)AllocADsMem(
  784. dwNumObjects * sizeof(NDSOBJECT)
  785. );
  786. if (!pNdsDestObjects) {
  787. RRETURN(E_FAIL);
  788. }
  789. for (i = 0; i < dwNumObjects; i++ ) {
  790. hr = AdsTypeToNdsTypeCopy(
  791. pAdsSrcValues + i,
  792. pNdsDestObjects + i
  793. );
  794. BAIL_ON_FAILURE(hr);
  795. }
  796. *ppNdsDestObjects = pNdsDestObjects;
  797. *pdwNumNdsObjects = dwNumObjects;
  798. *pdwNdsSyntaxId = pNdsDestObjects->NdsType;
  799. RRETURN(S_OK);
  800. error:
  801. if (pNdsDestObjects) {
  802. NdsTypeFreeNdsObjects(
  803. pNdsDestObjects,
  804. dwNumObjects
  805. );
  806. }
  807. *ppNdsDestObjects = NULL;
  808. *pdwNumNdsObjects = 0;
  809. RRETURN(hr);
  810. }