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.

866 lines
24 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 2000.
  5. //
  6. // File: umi2ldap.cxx
  7. //
  8. // Contents: File containing the implemenation of the conversion routines
  9. // that convert the user given UMI values to ldap values that can
  10. // subsequently be cached if required.
  11. //
  12. // History: 02-17-00 AjayR Created.
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "ldap.hxx"
  16. //+---------------------------------------------------------------------------
  17. // Function: UmiTypeLPWSTRToLdapString
  18. //
  19. // Synopsis: Converts a string value to an equivalent ldap value.
  20. //
  21. // Arguments: Self explanatory
  22. //
  23. //
  24. // Returns: HRESULT - S_OK or any failure error code.
  25. //
  26. // Modifies: LDAPOBJECT_STRING(pLdaDestObject)
  27. //
  28. //----------------------------------------------------------------------------
  29. HRESULT
  30. UmiTypeLPWSTRToLdapString(
  31. LPWSTR pszSourceString,
  32. PLDAPOBJECT pLdapDestObject
  33. )
  34. {
  35. ADsAssert(pszSourceString);
  36. //
  37. // We should not have NULL values but it is a good idea to check.
  38. //
  39. if (pszSourceString) {
  40. LDAPOBJECT_STRING(pLdapDestObject) = AllocADsStr(pszSourceString);
  41. if (!LDAPOBJECT_STRING(pLdapDestObject)) {
  42. RRETURN(E_OUTOFMEMORY);
  43. }
  44. }
  45. RRETURN(S_OK);
  46. }
  47. //+---------------------------------------------------------------------------
  48. // Function: UmiTypeToLdapTypeBoolean
  49. //
  50. // Synopsis: Converts a bool value to an ldap boolean value.
  51. //
  52. // Arguments: Self explanatory
  53. //
  54. // Returns: HRESULT - S_OK or any failure error code.
  55. //
  56. // Modifies: LDAPOBJECT_STRING(pLdaDestObject) appropriately.
  57. //
  58. //----------------------------------------------------------------------------
  59. HRESULT
  60. UmiTypeToLdapTypeBoolean(
  61. BOOL fBool,
  62. PLDAPOBJECT pLdapDestObject
  63. )
  64. {
  65. if (fBool) {
  66. LDAPOBJECT_STRING(pLdapDestObject) = AllocADsStr(L"TRUE");
  67. }
  68. else {
  69. LDAPOBJECT_STRING(pLdapDestObject) = AllocADsStr(L"FALSE");
  70. }
  71. if (!LDAPOBJECT_STRING(pLdapDestObject)) {
  72. RRETURN(E_OUTOFMEMORY);
  73. }
  74. RRETURN(S_OK);
  75. }
  76. //+---------------------------------------------------------------------------
  77. // Function: UmiTypeToLdapTypeCopyI4
  78. //
  79. // Synopsis: Converts a long (I4) value to an equivalent ldap value.
  80. //
  81. // Arguments: Self explanatory
  82. //
  83. // Returns: HRESULT - S_OK or any failure error code.
  84. //
  85. // Modifies: LDAPOBJECT_STRING(pLdaDestObject) contains the new values.
  86. //
  87. //----------------------------------------------------------------------------
  88. HRESULT
  89. UmiTypeToLdapTypeCopyI4(
  90. LONG lVal,
  91. PLDAPOBJECT pLdapDestObject
  92. )
  93. {
  94. HRESULT hr = S_OK;
  95. TCHAR Buffer[64];
  96. ADsAssert(pLdapDestObject);
  97. _ltot(lVal, Buffer, 10);
  98. LDAPOBJECT_STRING(pLdapDestObject) = AllocADsStr(Buffer);
  99. if (!LDAPOBJECT_STRING(pLdapDestObject)) {
  100. hr = E_OUTOFMEMORY;
  101. }
  102. RRETURN(hr);
  103. }
  104. //+---------------------------------------------------------------------------
  105. // Function: UmiTypeToLdapTypeOctetString
  106. //
  107. // Synopsis: Converts an UmiOctetString to an ldap ber value.
  108. //
  109. // Arguments: Self explanatory
  110. //
  111. // Returns: HRESULT - S_OK or any failure error code.
  112. //
  113. // Modifies: pLdapDestObject is updated suitably with the ber value.
  114. //
  115. //----------------------------------------------------------------------------
  116. HRESULT
  117. UmiTypeToLdapTypeOctetString(
  118. UMI_OCTET_STRING umiOctetStr,
  119. PLDAPOBJECT pLdapDestObject
  120. )
  121. {
  122. DWORD dwLength = 0;
  123. if (umiOctetStr.lpValue) {
  124. dwLength = umiOctetStr.uLength;
  125. LDAPOBJECT_BERVAL(pLdapDestObject) = (struct berval *)
  126. AllocADsMem(dwLength + sizeof(struct berval));
  127. if (!LDAPOBJECT_BERVAL(pLdapDestObject)) {
  128. RRETURN(E_OUTOFMEMORY);
  129. }
  130. //
  131. // Set the pointer to data and the length in the dest object.
  132. //
  133. LDAPOBJECT_BERVAL_LEN(pLdapDestObject) = dwLength;
  134. LDAPOBJECT_BERVAL_VAL(pLdapDestObject) = (CHAR *)
  135. ( (LPBYTE) LDAPOBJECT_BERVAL(pLdapDestObject)
  136. + sizeof(struct berval));
  137. memcpy(
  138. LDAPOBJECT_BERVAL_VAL(pLdapDestObject),
  139. umiOctetStr.lpValue,
  140. dwLength
  141. );
  142. } // umiOctetStr.lpValue
  143. RRETURN(S_OK);
  144. }
  145. //+---------------------------------------------------------------------------
  146. // Function: UmiTypeToLdapTypeSecurityDescriptor.
  147. //
  148. // Synopsis: Converts a UmiComObject that is an SD to an equivalent
  149. // ldap binary blob.
  150. //
  151. // Arguments: umiComObject - Has the IADsSecDesc to convert.
  152. // pLdapDestObjects - Return value of encoded ldap data.
  153. // pCreds - Credentials to use for conversion.
  154. // pszServerName - ServerName associated with SD.
  155. //
  156. // Returns: HRESULT - S_OK or any failure error code.
  157. //
  158. // Modifies: pLdapDestObject is updated suitably with the ber value.
  159. //
  160. //----------------------------------------------------------------------------
  161. HRESULT
  162. UmiTypeToLdapTypeCopySecurityDescriptor(
  163. UMI_COM_OBJECT umiComObject,
  164. PLDAPOBJECT pLdapDestObject,
  165. CCredentials *pCreds,
  166. LPWSTR pszServerName
  167. )
  168. {
  169. HRESULT hr = S_OK;
  170. PSECURITY_DESCRIPTOR pBinarySecDesc = NULL;
  171. IUnknown *pUnk = (IUnknown *) umiComObject.pInterface;
  172. IADsSecurityDescriptor* pADsSecDesc = NULL;
  173. CCredentials creds;
  174. DWORD dwSDLength = 0;
  175. //
  176. // QI for the IADsSecDesc, that way we can be sure of the interface.
  177. //
  178. hr = pUnk->QueryInterface(
  179. IID_IADsSecurityDescriptor,
  180. (void **) &pADsSecDesc
  181. );
  182. BAIL_ON_FAILURE(hr);
  183. //
  184. // Update the credentials if needed.
  185. //
  186. if (pCreds) {
  187. creds = *pCreds;
  188. }
  189. //
  190. // Call the helper that does the conversion in activeds.dll
  191. //
  192. hr = ConvertSecurityDescriptorToSecDes(
  193. pszServerName,
  194. creds,
  195. pADsSecDesc,
  196. &pBinarySecDesc,
  197. &dwSDLength,
  198. TRUE // NT style SD.
  199. );
  200. BAIL_ON_FAILURE(hr);
  201. //
  202. // Now we need to copy over the data into the ldap struct.
  203. //
  204. LDAPOBJECT_BERVAL(pLdapDestObject) =
  205. (struct berval *) AllocADsMem( sizeof(struct berval) + dwSDLength);
  206. if ( LDAPOBJECT_BERVAL(pLdapDestObject) == NULL) {
  207. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  208. }
  209. LDAPOBJECT_BERVAL_LEN(pLdapDestObject) = dwSDLength;
  210. LDAPOBJECT_BERVAL_VAL(pLdapDestObject) =
  211. (CHAR *) ((LPBYTE) LDAPOBJECT_BERVAL(pLdapDestObject)
  212. + sizeof(struct berval));
  213. memcpy(
  214. LDAPOBJECT_BERVAL_VAL(pLdapDestObject),
  215. pBinarySecDesc,
  216. dwSDLength
  217. );
  218. error:
  219. if (pBinarySecDesc) {
  220. FreeADsMem(pBinarySecDesc);
  221. }
  222. if (pADsSecDesc) {
  223. pADsSecDesc->Release();
  224. }
  225. RRETURN(hr);
  226. }
  227. //+---------------------------------------------------------------------------
  228. // Function: UmiTypeToLdapTypeCopyDNWithBinary.
  229. //
  230. // Synopsis: Converts a UmiComObject that is DNWithBinary obj to
  231. // and equivalent ldap data.
  232. //
  233. // Arguments: umiComObject - Has the IADsDNWithBinary to convert.
  234. // pLdapDestObjects - Return value of encoded ldap data.
  235. //
  236. // Returns: HRESULT - S_OK or any failure error code.
  237. //
  238. // Modifies: pLdapDestObject is updated suitably with the ber value.
  239. //
  240. //----------------------------------------------------------------------------
  241. HRESULT
  242. UmiTypeToLdapTypeCopyDNWithBinary(
  243. UMI_COM_OBJECT umiComObject,
  244. PLDAPOBJECT pLdapDestObject
  245. )
  246. {
  247. HRESULT hr = S_OK;
  248. IUnknown * pUnk = (IUnknown *)umiComObject.pInterface;
  249. VARIANT vVar;
  250. VariantInit(&vVar);
  251. vVar.vt = VT_DISPATCH;
  252. hr = pUnk->QueryInterface(IID_IDispatch, (void **) &vVar.pdispVal);
  253. BAIL_ON_FAILURE(hr);
  254. //
  255. // Call the var2ldap conversion helper to do all the hard work !.
  256. //
  257. hr = VarTypeToLdapTypeDNWithBinary(
  258. &vVar,
  259. pLdapDestObject
  260. );
  261. error:
  262. VariantClear(&vVar);
  263. RRETURN(hr);
  264. }
  265. //+---------------------------------------------------------------------------
  266. // Function: UmiTypeToLdapTypeCopyDNWithString.
  267. //
  268. // Synopsis: Converts a UmiComObject that is DNWithString obj to
  269. // and equivalent ldap data.
  270. //
  271. // Arguments: umiComObject - Has the IADsDNWithString to convert.
  272. // pLdapDestObjects - Return value of encoded ldap data.
  273. //
  274. // Returns: HRESULT - S_OK or any failure error code.
  275. //
  276. // Modifies: pLdapDestObject is updated suitably with the ber value.
  277. //
  278. //----------------------------------------------------------------------------
  279. HRESULT
  280. UmiTypeToLdapTypeCopyDNWithString(
  281. UMI_COM_OBJECT umiComObject,
  282. PLDAPOBJECT pLdapDestObject
  283. )
  284. {
  285. HRESULT hr = S_OK;
  286. IUnknown * pUnk = (IUnknown *)umiComObject.pInterface;
  287. VARIANT vVar;
  288. VariantInit(&vVar);
  289. vVar.vt = VT_DISPATCH;
  290. hr = pUnk->QueryInterface(IID_IDispatch, (void **) &vVar.pdispVal);
  291. BAIL_ON_FAILURE(hr);
  292. //
  293. // Call the var2ldap conversion helper to do all the hard work !.
  294. //
  295. hr = VarTypeToLdapTypeDNWithString(
  296. &vVar,
  297. pLdapDestObject
  298. );
  299. error:
  300. VariantClear(&vVar);
  301. RRETURN(hr);
  302. }
  303. //+---------------------------------------------------------------------------
  304. // Function: UmiTypeToLdapTypeCopyI8
  305. //
  306. // Synopsis: Convert an int64 value to the corresponding ldap value.
  307. //
  308. // Arguments: Self explanatory
  309. //
  310. // Returns: HRESULT - S_OK or any failure error code.
  311. //
  312. // Modifies: pLdapDestObject contains the encoded large integer object.
  313. //
  314. //----------------------------------------------------------------------------
  315. HRESULT
  316. UmiTypeToLdapTypeCopyI8(
  317. __int64 int64Val,
  318. PLDAPOBJECT pLdapDestObject
  319. )
  320. {
  321. HRESULT hr = S_OK;
  322. TCHAR Buffer[64];
  323. if (!swprintf (Buffer, L"%I64d", int64Val))
  324. BAIL_ON_FAILURE(hr = E_ADS_CANT_CONVERT_DATATYPE);
  325. LDAPOBJECT_STRING(pLdapDestObject) = /*(LPTSTR)*/ AllocADsStr( Buffer );
  326. if (!LDAPOBJECT_STRING(pLdapDestObject)) {
  327. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  328. }
  329. error :
  330. RRETURN(hr);
  331. }
  332. //+---------------------------------------------------------------------------
  333. // Function: UmiTypeToLdapTypeCopyUTCTime
  334. //
  335. // Synopsis: Convert a SYSTEMTIME object to the corresponding ldap value.
  336. //
  337. // Arguments: Self explanatory
  338. //
  339. // Returns: HRESULT - S_OK or any failure error code.
  340. //
  341. // Modifies: pLdapDestObject contains the encoded utc time value.
  342. //
  343. //----------------------------------------------------------------------------
  344. HRESULT
  345. UmiTypeToLdapTypeCopyUTCTime(
  346. SYSTEMTIME sysTimeObj,
  347. PLDAPOBJECT pLdapDestObject
  348. )
  349. {
  350. HRESULT hr;
  351. DWORD dwSyntaxId;
  352. ADSVALUE adsValue;
  353. adsValue.dwType = ADSTYPE_UTC_TIME;
  354. adsValue.UTCTime = sysTimeObj;
  355. //
  356. // Use the helper to convert the value appropriately.
  357. //
  358. hr = AdsTypeToLdapTypeCopyTime(
  359. &adsValue,
  360. pLdapDestObject,
  361. &dwSyntaxId
  362. );
  363. RRETURN(hr);
  364. }
  365. //+---------------------------------------------------------------------------
  366. // Function: UmiTypeToLdapTypeCopyGeneralizedTime
  367. //
  368. // Synopsis: Converts a SystemTime value to a ldap generalized time value.
  369. //
  370. // Arguments: Self explanatory
  371. //
  372. // Returns: HRESULT - S_OK or any failure error code.
  373. //
  374. // Modifies: pLdapDestObject contains the encoded generalized time value.
  375. //
  376. //----------------------------------------------------------------------------
  377. HRESULT
  378. UmiTypeToLdapTypeCopyGeneralizedTime(
  379. SYSTEMTIME sysTimeObj,
  380. PLDAPOBJECT pLdapDestObject
  381. )
  382. {
  383. HRESULT hr;
  384. DWORD dwSyntaxId;
  385. ADSVALUE adsValue;
  386. adsValue.dwType = ADSTYPE_UTC_TIME;
  387. adsValue.UTCTime = sysTimeObj;
  388. //
  389. // Use the helper to convert the value appropriately.
  390. //
  391. hr = AdsTypeToLdapTypeCopyGeneralizedTime(
  392. &adsValue,
  393. pLdapDestObject,
  394. &dwSyntaxId
  395. );
  396. RRETURN(hr);
  397. }
  398. //+---------------------------------------------------------------------------
  399. // Function: UmiTypeEnumToLdapTypeEnum
  400. //
  401. // Synopsis: Converts the passed in umiType to the equivalent ldapType.
  402. // Note that the conversion is just for the type and not the actual
  403. // data itself. Example UMI_TYPE_I4 to LDAPTYPE_INTEGER.
  404. //
  405. // Arguments: ulUmiType - Umi type to convert.
  406. // pdwSyntax - Return ldap syntax.
  407. //
  408. // Returns: HRESULT - S_OK or any failure error code.
  409. //
  410. // Modifies: *pdwSyntax with appropriate value.
  411. //
  412. //----------------------------------------------------------------------------
  413. HRESULT
  414. UmiTypeToLdapTypeEnum(
  415. ULONG ulUmiType,
  416. PDWORD pdwSyntax
  417. )
  418. {
  419. HRESULT hr = S_OK;
  420. switch (ulUmiType) {
  421. case UMI_TYPE_I4 :
  422. *pdwSyntax = LDAPTYPE_INTEGER;
  423. break;
  424. case UMI_TYPE_I8 :
  425. *pdwSyntax = LDAPTYPE_INTEGER8;
  426. break;
  427. case UMI_TYPE_SYSTEMTIME :
  428. //
  429. // What about utc Time ?
  430. //
  431. *pdwSyntax = LDAPTYPE_GENERALIZEDTIME;
  432. break;
  433. case UMI_TYPE_BOOL :
  434. *pdwSyntax = LDAPTYPE_BOOLEAN;
  435. break;
  436. case UMI_TYPE_IUNKNOWN :
  437. //
  438. // How about the other IUnknowns ?
  439. //
  440. *pdwSyntax = LDAPTYPE_SECURITY_DESCRIPTOR;
  441. break;
  442. case UMI_TYPE_LPWSTR :
  443. *pdwSyntax = LDAPTYPE_CASEIGNORESTRING;
  444. break;
  445. case UMI_TYPE_OCTETSTRING :
  446. *pdwSyntax = LDAPTYPE_OCTETSTRING;
  447. break;
  448. case UMI_TYPE_UNDEFINED:
  449. case UMI_TYPE_NULL :
  450. case UMI_TYPE_I1 :
  451. case UMI_TYPE_I2 :
  452. case UMI_TYPE_UI1 :
  453. case UMI_TYPE_UI2 :
  454. case UMI_TYPE_UI4 :
  455. case UMI_TYPE_UI8 :
  456. case UMI_TYPE_R4 :
  457. case UMI_TYPE_R8 :
  458. case UMI_TYPE_FILETIME :
  459. case UMI_TYPE_IDISPATCH :
  460. case UMI_TYPE_VARIANT :
  461. case UMI_TYPE_UMIARRAY :
  462. case UMI_TYPE_DISCOVERY :
  463. case UMI_TYPE_DEFAULT :
  464. default:
  465. *pdwSyntax = (DWORD) -1;
  466. hr = E_FAIL;
  467. break;
  468. }
  469. RRETURN(hr);
  470. }
  471. //+---------------------------------------------------------------------------
  472. // Function: UmiTypeToLdapTypeCopy
  473. //
  474. // Synopsis: Helper routine to convert ldap values to the required UMI
  475. // data type.
  476. //
  477. // Arguments: umiPropArray - input UMI data.
  478. // ulFlags - flags indicating type of operation.
  479. // pLdapDestObjects - Ptr to hold the output from routine.
  480. // dwLdapSyntaxId - ref to dword.
  481. // fUtcTime - optional defaulted to False.
  482. //
  483. // Returns: HRESULT - S_OK or any failure error code.
  484. //
  485. // Modifies: pLdapDestObjects to point to valid data.
  486. // dwLdapSyntaxId with the ldap syntax id for the data type (this
  487. // will enable us to return the data correctly to the user).
  488. //
  489. //----------------------------------------------------------------------------
  490. HRESULT
  491. UmiTypeToLdapTypeCopy(
  492. UMI_PROPERTY_VALUES umiPropArray,
  493. ULONG ulFlags,
  494. LDAPOBJECTARRAY *pLdapDestObjects,
  495. DWORD &dwLdapSyntaxId,
  496. CCredentials *pCreds,
  497. LPWSTR pszServerName,
  498. BOOL fUtcTime
  499. )
  500. {
  501. HRESULT hr = S_OK;
  502. ULONG ulUmiType, ulCount, ulCtr;
  503. PUMI_PROPERTY pUmiProp;
  504. //
  505. // Internal routine so an assert should be enough.
  506. //
  507. ADsAssert(pLdapDestObjects);
  508. //
  509. // Initalize count on ldapobjects to zero and
  510. // default is string values for the contents.
  511. //
  512. pLdapDestObjects->dwCount = 0;
  513. pLdapDestObjects->fIsString = TRUE;
  514. //
  515. // Verify that we have some valid data.
  516. //
  517. if (!umiPropArray.pPropArray || (umiPropArray.uCount != 1)) {
  518. BAIL_ON_FAILURE(hr = E_INVALIDARG);
  519. }
  520. pUmiProp = umiPropArray.pPropArray;
  521. ulUmiType = pUmiProp->uType;
  522. ulCount = pUmiProp->uCount;
  523. if ( ulCount == 0 ) {
  524. pLdapDestObjects->dwCount = 0;
  525. pLdapDestObjects->pLdapObjects = NULL;
  526. RRETURN(S_OK);
  527. }
  528. pLdapDestObjects->pLdapObjects =
  529. (PLDAPOBJECT)AllocADsMem( ulCount * sizeof(LDAPOBJECT));
  530. if (pLdapDestObjects->pLdapObjects == NULL)
  531. RRETURN(E_OUTOFMEMORY);
  532. //
  533. // If we are here, then pUmiValue has to be valid.
  534. //
  535. if (!pUmiProp->pUmiValue) {
  536. BAIL_ON_FAILURE(hr = E_INVALIDARG);
  537. }
  538. for (ulCtr =0; ulCtr < ulCount; ulCtr++) {
  539. //
  540. // Need to go through and convert each of the values.
  541. //
  542. switch (ulUmiType) {
  543. //
  544. // Call appropriate routine based on type.
  545. //
  546. case UMI_TYPE_I1 :
  547. case UMI_TYPE_I2 :
  548. hr = E_ADS_CANT_CONVERT_DATATYPE;
  549. break;
  550. case UMI_TYPE_I4 :
  551. if (!pUmiProp->pUmiValue->lValue) {
  552. BAIL_ON_FAILURE(hr = E_INVALIDARG);
  553. }
  554. hr = UmiTypeToLdapTypeCopyI4(
  555. pUmiProp->pUmiValue->lValue[ulCtr],
  556. pLdapDestObjects->pLdapObjects + ulCtr
  557. );
  558. dwLdapSyntaxId = LDAPTYPE_INTEGER;
  559. break;
  560. case UMI_TYPE_I8 :
  561. if (!pUmiProp->pUmiValue->nValue64) {
  562. BAIL_ON_FAILURE(hr = E_INVALIDARG);
  563. }
  564. hr = UmiTypeToLdapTypeCopyI8(
  565. pUmiProp->pUmiValue->nValue64[ulCtr],
  566. pLdapDestObjects->pLdapObjects + ulCtr
  567. );
  568. dwLdapSyntaxId = LDAPTYPE_INTEGER8;
  569. break;
  570. case UMI_TYPE_UI1 :
  571. case UMI_TYPE_UI2 :
  572. case UMI_TYPE_UI4 :
  573. case UMI_TYPE_UI8 :
  574. case UMI_TYPE_R4 :
  575. case UMI_TYPE_R8 :
  576. //
  577. // We do not handle any of the unsigned data types or
  578. // the real data types..
  579. //
  580. hr = E_ADS_CANT_CONVERT_DATATYPE;
  581. break;
  582. case UMI_TYPE_SYSTEMTIME :
  583. if (!pUmiProp->pUmiValue->sysTimeValue) {
  584. BAIL_ON_FAILURE(hr = E_INVALIDARG);
  585. }
  586. //
  587. // Need to use the special info to see if this is an UTC Time
  588. // value or if this is a Generalized time value - GenTime is
  589. // always the default value though.
  590. //
  591. if (fUtcTime) {
  592. hr = UmiTypeToLdapTypeCopyUTCTime(
  593. pUmiProp->pUmiValue->sysTimeValue[ulCtr],
  594. pLdapDestObjects->pLdapObjects + ulCtr
  595. );
  596. dwLdapSyntaxId = LDAPTYPE_UTCTIME;
  597. }
  598. else {
  599. hr = UmiTypeToLdapTypeCopyGeneralizedTime(
  600. pUmiProp->pUmiValue->sysTimeValue[ulCtr],
  601. pLdapDestObjects->pLdapObjects + ulCtr
  602. );
  603. dwLdapSyntaxId = LDAPTYPE_GENERALIZEDTIME;
  604. }
  605. break;
  606. case UMI_TYPE_BOOL :
  607. if (!pUmiProp->pUmiValue->bValue) {
  608. BAIL_ON_FAILURE(hr = E_INVALIDARG);
  609. }
  610. hr = UmiTypeToLdapTypeBoolean(
  611. pUmiProp->pUmiValue->bValue[ulCtr],
  612. pLdapDestObjects->pLdapObjects + ulCtr
  613. );
  614. dwLdapSyntaxId = LDAPTYPE_BOOLEAN;
  615. break;
  616. case UMI_TYPE_IDISPATCH :
  617. case UMI_TYPE_VARIANT :
  618. //
  619. // We do not support these.
  620. //
  621. hr = E_ADS_CANT_CONVERT_DATATYPE;
  622. break;
  623. case UMI_TYPE_LPWSTR :
  624. if (!pUmiProp->pUmiValue->pszStrValue) {
  625. BAIL_ON_FAILURE(hr = E_INVALIDARG);
  626. }
  627. hr = UmiTypeLPWSTRToLdapString(
  628. pUmiProp->pUmiValue->pszStrValue[ulCtr],
  629. pLdapDestObjects->pLdapObjects + ulCtr
  630. );
  631. dwLdapSyntaxId = LDAPTYPE_CASEEXACTSTRING;
  632. break;
  633. case UMI_TYPE_OCTETSTRING :
  634. if (!pUmiProp->pUmiValue->octetStr) {
  635. BAIL_ON_FAILURE(hr = E_INVALIDARG);
  636. }
  637. //
  638. // Override default settings as this is no longer true.
  639. //
  640. pLdapDestObjects->fIsString = FALSE;
  641. hr = UmiTypeToLdapTypeOctetString(
  642. pUmiProp->pUmiValue->octetStr[ulCtr],
  643. pLdapDestObjects->pLdapObjects + ulCtr
  644. );
  645. dwLdapSyntaxId = LDAPTYPE_OCTETSTRING;
  646. break;
  647. case UMI_TYPE_IUNKNOWN:
  648. if (!pUmiProp->pUmiValue->comObject
  649. || !pUmiProp->pUmiValue->comObject[ulCtr].pInterface
  650. ) {
  651. BAIL_ON_FAILURE(hr = E_INVALIDARG);
  652. }
  653. //
  654. // Based on the type we should call the appropriate function.
  655. //
  656. IID *priid;
  657. priid = pUmiProp->pUmiValue->comObject[ulCtr].priid;
  658. if (!priid) {
  659. BAIL_ON_FAILURE(hr = E_ADS_BAD_PARAMETER);
  660. }
  661. if (*priid == IID_IADsSecurityDescriptor) {
  662. //
  663. // SD is stored as berval in cache.
  664. //
  665. pLdapDestObjects->fIsString = FALSE;
  666. //
  667. // SD needs the servername and credentials for conversion.
  668. //
  669. hr = UmiTypeToLdapTypeCopySecurityDescriptor(
  670. pUmiProp->pUmiValue->comObject[ulCtr],
  671. pLdapDestObjects->pLdapObjects + ulCtr,
  672. pCreds,
  673. pszServerName
  674. );
  675. dwLdapSyntaxId = LDAPTYPE_SECURITY_DESCRIPTOR;
  676. }
  677. else if (*priid == IID_IADsDNWithBinary) {
  678. //
  679. // Convert DNBin obj to ldap equivalent.
  680. //
  681. hr = UmiTypeToLdapTypeCopyDNWithBinary(
  682. pUmiProp->pUmiValue->comObject[ulCtr],
  683. pLdapDestObjects->pLdapObjects + ulCtr
  684. );
  685. dwLdapSyntaxId = LDAPTYPE_DNWITHBINARY;
  686. }
  687. else if (*priid == IID_IADsDNWithString) {
  688. //
  689. // Convert DNStr obj to ldap equivalent.
  690. //
  691. hr = UmiTypeToLdapTypeCopyDNWithString(
  692. pUmiProp->pUmiValue->comObject[ulCtr],
  693. pLdapDestObjects->pLdapObjects + ulCtr
  694. );
  695. dwLdapSyntaxId = LDAPTYPE_DNWITHSTRING;
  696. }
  697. else {
  698. //
  699. // Unknown type.
  700. //
  701. BAIL_ON_FAILURE(hr = E_ADS_BAD_PARAMETER);
  702. }
  703. break;
  704. case UMI_TYPE_UMIARRAY :
  705. case UMI_TYPE_DISCOVERY :
  706. case UMI_TYPE_UNDEFINED :
  707. case UMI_TYPE_DEFAULT :
  708. hr = HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
  709. break;
  710. default :
  711. hr = HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
  712. break;
  713. } // end of case statement
  714. //
  715. // if hr is set there was a problem converting value.
  716. //
  717. BAIL_ON_FAILURE(hr);
  718. //
  719. // In case of failure we now have one more object to free
  720. // in the ldap object array.
  721. //
  722. pLdapDestObjects->dwCount++;
  723. } // end of for statement
  724. BAIL_ON_FAILURE(hr);
  725. RRETURN(hr);
  726. error:
  727. //
  728. // Free the ldapProperty array as needed.
  729. //
  730. LdapTypeFreeLdapObjects(pLdapDestObjects);
  731. RRETURN(hr);
  732. }