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.

3414 lines
80 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995
  5. //
  6. // File: cPropertyValue.cxx
  7. //
  8. // Contents: PropertyValue object
  9. //
  10. // History: 11-1-95 krishnag Created.
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "oleds.hxx"
  14. #pragma hdrstop
  15. DEFINE_IDispatch_Implementation(CPropertyValue)
  16. CPropertyValue::CPropertyValue():
  17. _pDispMgr(NULL),
  18. _dwDataType(0),
  19. _pDispatch(NULL)
  20. {
  21. memset(&_ADsValue, 0, sizeof(ADSVALUE));
  22. ENLIST_TRACKING(CPropertyValue);
  23. }
  24. HRESULT
  25. CPropertyValue::CreatePropertyValue(
  26. REFIID riid,
  27. void **ppvObj
  28. )
  29. {
  30. CPropertyValue FAR * pPropertyValue = NULL;
  31. HRESULT hr = S_OK;
  32. hr = AllocatePropertyValueObject(&pPropertyValue);
  33. BAIL_ON_FAILURE(hr);
  34. hr = pPropertyValue->QueryInterface(riid, ppvObj);
  35. BAIL_ON_FAILURE(hr);
  36. pPropertyValue->Release();
  37. RRETURN(hr);
  38. error:
  39. delete pPropertyValue;
  40. RRETURN_EXP_IF_ERR(hr);
  41. }
  42. CPropertyValue::~CPropertyValue( )
  43. {
  44. ClearData();
  45. delete _pDispMgr;
  46. }
  47. STDMETHODIMP
  48. CPropertyValue::QueryInterface(
  49. REFIID iid,
  50. LPVOID FAR* ppv
  51. )
  52. {
  53. if (IsEqualIID(iid, IID_IUnknown))
  54. {
  55. *ppv = (IADsPropertyValue FAR *) this;
  56. }
  57. else if (IsEqualIID(iid, IID_IADsPropertyValue))
  58. {
  59. *ppv = (IADsPropertyValue FAR *) this;
  60. }
  61. else if (IsEqualIID(iid, IID_IADsPropertyValue2))
  62. {
  63. *ppv = (IADsPropertyValue2 FAR *) this;
  64. }
  65. else if (IsEqualIID(iid, IID_IDispatch))
  66. {
  67. *ppv = (IADsPropertyValue FAR *) this;
  68. }
  69. else if (IsEqualIID(iid, IID_ISupportErrorInfo))
  70. {
  71. *ppv = (ISupportErrorInfo FAR *) this;
  72. }
  73. else if (IsEqualIID(iid, IID_IADsValue))
  74. {
  75. *ppv = (IADsValue FAR *) this;
  76. }
  77. else
  78. {
  79. *ppv = NULL;
  80. return E_NOINTERFACE;
  81. }
  82. AddRef();
  83. return NOERROR;
  84. }
  85. HRESULT
  86. CPropertyValue::AllocatePropertyValueObject(
  87. CPropertyValue ** ppPropertyValue
  88. )
  89. {
  90. CPropertyValue FAR * pPropertyValue = NULL;
  91. CDispatchMgr FAR * pDispMgr = NULL;
  92. HRESULT hr = S_OK;
  93. pPropertyValue = new CPropertyValue();
  94. if (pPropertyValue == NULL) {
  95. hr = E_OUTOFMEMORY;
  96. }
  97. BAIL_ON_FAILURE(hr);
  98. pDispMgr = new CDispatchMgr;
  99. if (pDispMgr == NULL) {
  100. hr = E_OUTOFMEMORY;
  101. }
  102. BAIL_ON_FAILURE(hr);
  103. hr = LoadTypeInfoEntry(
  104. pDispMgr,
  105. LIBID_ADs,
  106. IID_IADsPropertyValue,
  107. (IADsPropertyValue *)pPropertyValue,
  108. DISPID_REGULAR
  109. );
  110. BAIL_ON_FAILURE(hr);
  111. hr = LoadTypeInfoEntry(
  112. pDispMgr,
  113. LIBID_ADs,
  114. IID_IADsPropertyValue2,
  115. (IADsPropertyValue2 *)pPropertyValue,
  116. DISPID_REGULAR
  117. );
  118. BAIL_ON_FAILURE(hr);
  119. pPropertyValue->_pDispMgr = pDispMgr;
  120. *ppPropertyValue = pPropertyValue;
  121. RRETURN(hr);
  122. error:
  123. delete pPropertyValue;
  124. delete pDispMgr;
  125. RRETURN_EXP_IF_ERR(hr);
  126. }
  127. //
  128. // ISupportErrorInfo method
  129. //
  130. STDMETHODIMP
  131. CPropertyValue::InterfaceSupportsErrorInfo(THIS_ REFIID riid)
  132. {
  133. if (IsEqualIID(riid, IID_IADsPropertyValue) ||
  134. IsEqualIID(riid, IID_IADsPropertyValue) ||
  135. IsEqualIID(riid, IID_IADsValue)) {
  136. return S_OK;
  137. } else {
  138. return S_FALSE;
  139. }
  140. }
  141. STDMETHODIMP
  142. CPropertyValue::Clear(THIS_ )
  143. {
  144. ClearData();
  145. RRETURN(S_OK);
  146. }
  147. STDMETHODIMP
  148. CPropertyValue::get_ADsType(THIS_ long FAR * retval)
  149. {
  150. *retval = _ADsValue.dwType;
  151. RRETURN(S_OK);
  152. }
  153. STDMETHODIMP
  154. CPropertyValue::put_ADsType(THIS_ long lnADsType)
  155. {
  156. _ADsValue.dwType = (ADSTYPE)lnADsType;
  157. RRETURN(S_OK);
  158. }
  159. STDMETHODIMP
  160. CPropertyValue::get_DNString(THIS_ BSTR FAR * retval)
  161. {
  162. HRESULT hr = S_OK;
  163. if (_ADsValue.dwType != ADSTYPE_DN_STRING) {
  164. RRETURN(E_ADS_CANT_CONVERT_DATATYPE);
  165. }
  166. hr = ADsAllocString(_ADsValue.DNString, retval);
  167. RRETURN_EXP_IF_ERR(hr);
  168. }
  169. STDMETHODIMP
  170. CPropertyValue::put_DNString(THIS_ BSTR bstrDNString)
  171. {
  172. HRESULT hr = S_OK;
  173. ClearData();
  174. _ADsValue.DNString = NULL;
  175. _ADsValue.DNString = AllocADsStr(bstrDNString);
  176. if(!_ADsValue.DNString && bstrDNString)
  177. {
  178. hr = E_OUTOFMEMORY;
  179. }
  180. _ADsValue.dwType = ADSTYPE_DN_STRING;
  181. RRETURN(hr);
  182. }
  183. STDMETHODIMP
  184. CPropertyValue::get_CaseExactString(THIS_ BSTR FAR * retval)
  185. {
  186. HRESULT hr = S_OK;
  187. if (_ADsValue.dwType != ADSTYPE_CASE_EXACT_STRING) {
  188. RRETURN(E_ADS_CANT_CONVERT_DATATYPE);
  189. }
  190. hr = ADsAllocString(_ADsValue.CaseExactString, retval);
  191. RRETURN_EXP_IF_ERR(hr);
  192. }
  193. STDMETHODIMP
  194. CPropertyValue::put_CaseExactString(THIS_ BSTR bstrCaseExactString)
  195. {
  196. HRESULT hr = S_OK;
  197. ClearData();
  198. _ADsValue.DNString = NULL;
  199. _ADsValue.DNString = AllocADsStr(bstrCaseExactString);
  200. if(!_ADsValue.DNString && bstrCaseExactString)
  201. {
  202. hr = E_OUTOFMEMORY;
  203. }
  204. _ADsValue.dwType = ADSTYPE_CASE_EXACT_STRING;
  205. RRETURN(hr);
  206. }
  207. STDMETHODIMP
  208. CPropertyValue::get_CaseIgnoreString(THIS_ BSTR FAR * retval)
  209. {
  210. HRESULT hr = S_OK;
  211. if (_ADsValue.dwType != ADSTYPE_CASE_IGNORE_STRING) {
  212. RRETURN_EXP_IF_ERR(E_ADS_CANT_CONVERT_DATATYPE);
  213. }
  214. hr = ADsAllocString(_ADsValue.CaseIgnoreString, retval);
  215. RRETURN_EXP_IF_ERR(hr);
  216. }
  217. STDMETHODIMP
  218. CPropertyValue::put_CaseIgnoreString(THIS_ BSTR bstrCaseIgnoreString)
  219. {
  220. HRESULT hr = S_OK;
  221. ClearData();
  222. _ADsValue.DNString = NULL;
  223. _ADsValue.DNString = AllocADsStr(bstrCaseIgnoreString);
  224. if(!_ADsValue.DNString && bstrCaseIgnoreString)
  225. {
  226. hr = E_OUTOFMEMORY;
  227. }
  228. _ADsValue.dwType = ADSTYPE_CASE_IGNORE_STRING;
  229. RRETURN(hr);
  230. }
  231. STDMETHODIMP
  232. CPropertyValue::get_PrintableString(THIS_ BSTR FAR * retval)
  233. {
  234. HRESULT hr = S_OK;
  235. if (_ADsValue.dwType != ADSTYPE_PRINTABLE_STRING) {
  236. RRETURN_EXP_IF_ERR(E_ADS_CANT_CONVERT_DATATYPE);
  237. }
  238. hr = ADsAllocString(_ADsValue.PrintableString, retval);
  239. RRETURN_EXP_IF_ERR(hr);
  240. }
  241. STDMETHODIMP
  242. CPropertyValue::put_PrintableString(THIS_ BSTR bstrPrintableString)
  243. {
  244. HRESULT hr = S_OK;
  245. ClearData();
  246. _ADsValue.PrintableString = NULL;
  247. _ADsValue.PrintableString = AllocADsStr(bstrPrintableString);
  248. if(!_ADsValue.PrintableString && bstrPrintableString)
  249. {
  250. hr = E_OUTOFMEMORY;
  251. }
  252. _ADsValue.dwType = ADSTYPE_PRINTABLE_STRING;
  253. RRETURN(hr);
  254. }
  255. STDMETHODIMP
  256. CPropertyValue::get_NumericString(THIS_ BSTR FAR * retval)
  257. {
  258. HRESULT hr = S_OK;
  259. if (_ADsValue.dwType != ADSTYPE_NUMERIC_STRING) {
  260. RRETURN_EXP_IF_ERR(E_ADS_CANT_CONVERT_DATATYPE);
  261. }
  262. hr = ADsAllocString(_ADsValue.NumericString, retval);
  263. RRETURN_EXP_IF_ERR(hr);
  264. }
  265. STDMETHODIMP
  266. CPropertyValue::put_NumericString(THIS_ BSTR bstrNumericString)
  267. {
  268. HRESULT hr = S_OK;
  269. ClearData();
  270. _ADsValue.DNString = NULL;
  271. _ADsValue.DNString = AllocADsStr(bstrNumericString);
  272. if(!_ADsValue.DNString && bstrNumericString)
  273. {
  274. hr = E_OUTOFMEMORY;
  275. }
  276. _ADsValue.dwType = ADSTYPE_NUMERIC_STRING;
  277. RRETURN(hr);
  278. }
  279. STDMETHODIMP
  280. CPropertyValue::get_OctetString(THIS_ VARIANT FAR *retval )
  281. {
  282. HRESULT hr = S_OK;
  283. SAFEARRAY *aList = NULL;
  284. SAFEARRAYBOUND aBound;
  285. CHAR HUGEP *pArray = NULL;
  286. if (_ADsValue.dwType != ADSTYPE_OCTET_STRING) {
  287. RRETURN(E_ADS_CANT_CONVERT_DATATYPE);
  288. }
  289. aBound.lLbound = 0;
  290. aBound.cElements = _ADsValue.OctetString.dwLength;
  291. aList = SafeArrayCreate( VT_UI1, 1, &aBound );
  292. if ( aList == NULL )
  293. {
  294. hr = E_OUTOFMEMORY;
  295. BAIL_ON_FAILURE(hr);
  296. }
  297. hr = SafeArrayAccessData( aList, (void HUGEP * FAR *) &pArray );
  298. BAIL_ON_FAILURE(hr);
  299. memcpy( pArray,
  300. _ADsValue.OctetString.lpValue,
  301. aBound.cElements );
  302. SafeArrayUnaccessData( aList );
  303. V_VT(retval) = VT_ARRAY | VT_UI1;
  304. V_ARRAY(retval) = aList;
  305. RRETURN(hr);
  306. error:
  307. if ( aList ) {
  308. SafeArrayDestroy( aList );
  309. }
  310. RRETURN_EXP_IF_ERR(hr);
  311. }
  312. STDMETHODIMP
  313. CPropertyValue::put_OctetString(THIS_ VARIANT VarOctetString)
  314. {
  315. LONG dwSLBound = 0;
  316. LONG dwSUBound = 0;
  317. CHAR HUGEP *pArray = NULL;
  318. VARIANT * pvVar = &VarOctetString;
  319. HRESULT hr = S_OK;
  320. ClearData();
  321. _ADsValue.dwType = ADSTYPE_OCTET_STRING;
  322. if ( VarOctetString.vt == (VT_ARRAY | VT_BYREF)) {
  323. pvVar = V_VARIANTREF(&VarOctetString);
  324. }
  325. if( pvVar->vt != (VT_ARRAY | VT_UI1)) {
  326. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  327. }
  328. hr = SafeArrayGetLBound(V_ARRAY(pvVar),
  329. 1,
  330. (long FAR *) &dwSLBound );
  331. BAIL_ON_FAILURE(hr);
  332. hr = SafeArrayGetUBound(V_ARRAY(pvVar),
  333. 1,
  334. (long FAR *) &dwSUBound );
  335. BAIL_ON_FAILURE(hr);
  336. _ADsValue.OctetString.lpValue = (LPBYTE)AllocADsMem(dwSUBound - dwSLBound + 1);
  337. if ( _ADsValue.OctetString.lpValue == NULL) {
  338. hr = E_OUTOFMEMORY;
  339. BAIL_ON_FAILURE(hr);
  340. }
  341. _ADsValue.OctetString.dwLength = dwSUBound - dwSLBound + 1;
  342. hr = SafeArrayAccessData( V_ARRAY(pvVar),
  343. (void HUGEP * FAR *) &pArray );
  344. BAIL_ON_FAILURE(hr);
  345. memcpy( _ADsValue.OctetString.lpValue,
  346. pArray,
  347. dwSUBound-dwSLBound+1);
  348. SafeArrayUnaccessData( V_ARRAY(pvVar) );
  349. error:
  350. RRETURN_EXP_IF_ERR(hr);
  351. }
  352. STDMETHODIMP
  353. CPropertyValue::get_Integer(THIS_ LONG FAR * retval)
  354. {
  355. HRESULT hr = S_OK;
  356. if (_ADsValue.dwType != ADSTYPE_INTEGER) {
  357. RRETURN(E_ADS_CANT_CONVERT_DATATYPE);
  358. }
  359. *retval = _ADsValue.Boolean;
  360. RRETURN_EXP_IF_ERR(hr);
  361. }
  362. STDMETHODIMP
  363. CPropertyValue::put_Integer(THIS_ LONG lnInteger)
  364. {
  365. ClearData();
  366. _ADsValue.Integer = lnInteger;
  367. _ADsValue.dwType = ADSTYPE_INTEGER;
  368. RRETURN(S_OK);
  369. }
  370. STDMETHODIMP
  371. CPropertyValue::get_Boolean(THIS_ LONG FAR * retval)
  372. {
  373. HRESULT hr = S_OK;
  374. if (_ADsValue.dwType != ADSTYPE_BOOLEAN) {
  375. RRETURN(E_ADS_CANT_CONVERT_DATATYPE);
  376. }
  377. *retval = _ADsValue.Boolean;
  378. RRETURN_EXP_IF_ERR(hr);
  379. }
  380. STDMETHODIMP
  381. CPropertyValue::put_Boolean(THIS_ LONG lnBoolean)
  382. {
  383. ClearData();
  384. _ADsValue.Boolean = lnBoolean;
  385. _ADsValue.dwType = ADSTYPE_BOOLEAN;
  386. RRETURN(S_OK);
  387. }
  388. STDMETHODIMP
  389. CPropertyValue::get_SecurityDescriptor(THIS_ IDispatch FAR * FAR * ppDispatch)
  390. {
  391. HRESULT hr = E_ADS_CANT_CONVERT_DATATYPE;
  392. //
  393. // Check if we have a valid IDispatch at this point
  394. //
  395. if (_pDispatch) {
  396. switch (_dwDataType) {
  397. case VAL_IDISPATCH_SECDESC_ONLY :
  398. case VAL_IDISPATCH_SECDESC_ALL :
  399. hr = _pDispatch->QueryInterface(
  400. IID_IDispatch,
  401. (void **) ppDispatch
  402. );
  403. break;
  404. default:
  405. hr = E_ADS_CANT_CONVERT_DATATYPE;
  406. }
  407. }
  408. RRETURN(hr);
  409. }
  410. STDMETHODIMP
  411. CPropertyValue::put_SecurityDescriptor(THIS_ IDispatch * pSecurityDescriptor)
  412. {
  413. HRESULT hr = S_OK;
  414. IADsSecurityDescriptor *pIADsSecDes;
  415. IDispatch* pIDispatch;
  416. ClearData();
  417. _ADsValue.dwType = ADSTYPE_NT_SECURITY_DESCRIPTOR;
  418. //
  419. // This qi ensures that this is a security descriptor
  420. //
  421. hr = pSecurityDescriptor->QueryInterface(
  422. IID_IADsSecurityDescriptor,
  423. (void **) &pIADsSecDes
  424. );
  425. BAIL_ON_FAILURE(hr);
  426. pIADsSecDes->Release();
  427. pIADsSecDes = NULL;
  428. hr = pSecurityDescriptor->QueryInterface(
  429. IID_IDispatch,
  430. (void **) &pIDispatch
  431. );
  432. BAIL_ON_FAILURE(hr);
  433. _dwDataType = VAL_IDISPATCH_SECDESC_ONLY;
  434. _pDispatch = pIDispatch;
  435. RRETURN(hr);
  436. error:
  437. if (pIADsSecDes) {
  438. pIADsSecDes->Release();
  439. }
  440. RRETURN_EXP_IF_ERR(hr);
  441. }
  442. STDMETHODIMP
  443. CPropertyValue::get_LargeInteger(THIS_ IDispatch FAR * FAR *retval)
  444. {
  445. HRESULT hr = S_OK;
  446. IADsLargeInteger * pLargeInteger = NULL;
  447. IDispatch * pDispatch = NULL;
  448. if (_ADsValue.dwType != ADSTYPE_LARGE_INTEGER) {
  449. hr = E_ADS_CANT_CONVERT_DATATYPE;
  450. BAIL_ON_FAILURE(hr);
  451. }
  452. hr = CoCreateInstance(
  453. CLSID_LargeInteger,
  454. NULL,
  455. CLSCTX_INPROC_SERVER,
  456. IID_IADsLargeInteger,
  457. (void **) &pLargeInteger);
  458. BAIL_ON_FAILURE(hr);
  459. hr = pLargeInteger->put_LowPart(_ADsValue.LargeInteger.LowPart);
  460. BAIL_ON_FAILURE(hr);
  461. hr = pLargeInteger->put_HighPart(_ADsValue.LargeInteger.HighPart);
  462. BAIL_ON_FAILURE(hr);
  463. hr = pLargeInteger->QueryInterface(
  464. IID_IDispatch,
  465. (void **) &pDispatch
  466. );
  467. BAIL_ON_FAILURE(hr);
  468. *retval = pDispatch;
  469. error:
  470. if (pLargeInteger) {
  471. pLargeInteger->Release();
  472. }
  473. RRETURN_EXP_IF_ERR(hr);
  474. }
  475. STDMETHODIMP
  476. CPropertyValue::put_LargeInteger(THIS_ IDispatch FAR* lnLargeInteger)
  477. {
  478. IADsLargeInteger *pLargeInteger = NULL;
  479. HRESULT hr = S_OK;
  480. LONG lnDataHigh = 0;
  481. LONG lnDataLow = 0;
  482. ClearData();
  483. hr = lnLargeInteger->QueryInterface(
  484. IID_IADsLargeInteger,
  485. (void **)&pLargeInteger
  486. );
  487. BAIL_ON_FAILURE(hr);
  488. hr = pLargeInteger->get_HighPart(&lnDataHigh);
  489. BAIL_ON_FAILURE(hr);
  490. hr = pLargeInteger->get_LowPart(&lnDataLow);
  491. BAIL_ON_FAILURE(hr);
  492. _ADsValue.dwType = ADSTYPE_LARGE_INTEGER;
  493. _ADsValue.LargeInteger.HighPart = lnDataHigh;
  494. _ADsValue.LargeInteger.LowPart = lnDataLow;
  495. error:
  496. if (pLargeInteger) {
  497. pLargeInteger->Release();
  498. }
  499. RRETURN_EXP_IF_ERR(hr);
  500. }
  501. STDMETHODIMP
  502. CPropertyValue::get_UTCTime(THIS_ DATE *retval)
  503. {
  504. HRESULT hr = S_OK;
  505. int result = FALSE;
  506. if (_ADsValue.dwType != ADSTYPE_UTC_TIME) {
  507. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  508. }
  509. result = SystemTimeToVariantTime(&_ADsValue.UTCTime, retval);
  510. if (result != TRUE) {
  511. hr = E_FAIL;
  512. }
  513. RRETURN_EXP_IF_ERR(hr);
  514. }
  515. STDMETHODIMP
  516. CPropertyValue::put_UTCTime(THIS_ DATE DateInDate)
  517. {
  518. HRESULT hr = S_OK;
  519. int result = FALSE;
  520. ClearData();
  521. _ADsValue.dwType = ADSTYPE_UTC_TIME;
  522. result = VariantTimeToSystemTime(DateInDate, &_ADsValue.UTCTime);
  523. if (result != TRUE) {
  524. hr = E_FAIL;
  525. }
  526. RRETURN_EXP_IF_ERR(hr);
  527. }
  528. STDMETHODIMP
  529. CPropertyValue::ConvertADsValueToPropertyValue(THIS_ PADSVALUE pADsValue)
  530. {
  531. HRESULT hr = S_OK;
  532. hr = ConvertADsValueToPropertyValue2(
  533. pADsValue,
  534. NULL,
  535. NULL,
  536. TRUE
  537. );
  538. RRETURN_EXP_IF_ERR(hr);
  539. }
  540. STDMETHODIMP
  541. CPropertyValue::ConvertADsValueToPropertyValue2(
  542. THIS_ PADSVALUE pADsValue,
  543. LPWSTR pszServerName,
  544. CCredentials* pCredentials,
  545. BOOL fNTDSType
  546. )
  547. {
  548. HRESULT hr = S_OK;
  549. ClearData();
  550. hr = AdsCopyADsValueToPropObj(
  551. pADsValue,
  552. this,
  553. pszServerName,
  554. pCredentials,
  555. fNTDSType
  556. );
  557. RRETURN_EXP_IF_ERR(hr);
  558. }
  559. STDMETHODIMP
  560. CPropertyValue::ConvertPropertyValueToADsValue(THIS_ PADSVALUE pADsValue)
  561. {
  562. return( ConvertPropertyValueToADsValue2(
  563. pADsValue,
  564. NULL, // serverName
  565. NULL, // userName
  566. NULL, // userPassword
  567. 0, // default flags.
  568. TRUE // flag NTDS
  569. )
  570. );
  571. }
  572. //
  573. // Handles all the parameters
  574. //
  575. STDMETHODIMP
  576. CPropertyValue::ConvertPropertyValueToADsValue2(
  577. THIS_ PADSVALUE pADsValue,
  578. LPWSTR pszServerName,
  579. LPWSTR pszUserName,
  580. LPWSTR pszPassWord,
  581. LONG dwFlags,
  582. BOOL fNTDSType
  583. )
  584. {
  585. HRESULT hr = S_OK;
  586. CCredentials Credentials( pszUserName, pszPassWord, dwFlags);
  587. hr = AdsCopyPropObjToADsValue(
  588. this,
  589. pADsValue,
  590. pszServerName,
  591. &Credentials,
  592. fNTDSType
  593. );
  594. RRETURN_EXP_IF_ERR(hr);
  595. }
  596. STDMETHODIMP
  597. CPropertyValue::get_CaseIgnoreList(THIS_ IDispatch FAR * FAR *retval)
  598. {
  599. HRESULT hr = S_OK;
  600. IADsCaseIgnoreList * pCaseIgnoreList = NULL;
  601. IDispatch * pDispatch = NULL;
  602. SAFEARRAY *aList = NULL;
  603. SAFEARRAYBOUND aBound;
  604. CHAR HUGEP *pArray = NULL;
  605. long i;
  606. BSTR bstrAddress = NULL;
  607. PADS_CASEIGNORE_LIST pCurrent = NULL;
  608. DWORD cElements = 0;
  609. VARIANT VarDestObject;
  610. VariantInit( &VarDestObject );
  611. if (_ADsValue.dwType != ADSTYPE_CASEIGNORE_LIST) {
  612. hr = E_ADS_CANT_CONVERT_DATATYPE;
  613. BAIL_ON_FAILURE(hr);
  614. }
  615. if (!_ADsValue.pCaseIgnoreList) {
  616. hr = E_FAIL;
  617. BAIL_ON_FAILURE(hr);
  618. }
  619. hr = CoCreateInstance(
  620. CLSID_CaseIgnoreList,
  621. NULL,
  622. CLSCTX_INPROC_SERVER,
  623. IID_IADsCaseIgnoreList,
  624. (void **) &pCaseIgnoreList);
  625. BAIL_ON_FAILURE(hr);
  626. pCurrent = _ADsValue.pCaseIgnoreList;
  627. while (pCurrent) {
  628. cElements++;
  629. pCurrent = pCurrent->Next;
  630. }
  631. aBound.lLbound = 0;
  632. aBound.cElements = cElements;
  633. aList = SafeArrayCreate( VT_BSTR, 1, &aBound );
  634. if ( aList == NULL ) {
  635. hr = E_OUTOFMEMORY;
  636. BAIL_ON_FAILURE(hr);
  637. }
  638. pCurrent = _ADsValue.pCaseIgnoreList;
  639. for ( i = 0; i < (long)cElements; i++ ) {
  640. hr = ADsAllocString(
  641. pCurrent->String,
  642. &bstrAddress
  643. );
  644. BAIL_ON_FAILURE(hr);
  645. hr = SafeArrayPutElement( aList, &i, bstrAddress );
  646. SysFreeString(bstrAddress);
  647. BAIL_ON_FAILURE(hr);
  648. pCurrent = pCurrent->Next;
  649. }
  650. V_VT(&VarDestObject) = VT_ARRAY | VT_BSTR;
  651. V_ARRAY(&VarDestObject) = aList;
  652. hr = pCaseIgnoreList->put_CaseIgnoreList(VarDestObject);
  653. BAIL_ON_FAILURE(hr);
  654. hr = pCaseIgnoreList->QueryInterface(IID_IDispatch, (void**)&pDispatch);
  655. BAIL_ON_FAILURE(hr);
  656. *retval = pDispatch;
  657. error:
  658. VariantClear( &VarDestObject );
  659. if (pCaseIgnoreList) {
  660. pCaseIgnoreList->Release();
  661. }
  662. if ( aList ) {
  663. SafeArrayDestroy( aList );
  664. }
  665. RRETURN(hr);
  666. }
  667. STDMETHODIMP
  668. CPropertyValue::put_CaseIgnoreList(THIS_ IDispatch FAR* pdCaseIgnoreList)
  669. {
  670. IADsCaseIgnoreList *pCaseIgnoreList = NULL;
  671. HRESULT hr = S_OK;
  672. LONG lnAmount= 0;
  673. DWORD dwSLBound = 0;
  674. DWORD dwSUBound = 0;
  675. long i;
  676. PADS_CASEIGNORE_LIST pCurrent = NULL;
  677. IDispatch FAR * pDispatch = NULL;
  678. BYTE* pbParameter = NULL;
  679. VARIANT varCaseIgnoreList;
  680. VARIANT varBstrElement;
  681. ClearData();
  682. VariantInit(&varCaseIgnoreList);
  683. hr = pdCaseIgnoreList->QueryInterface(
  684. IID_IADsCaseIgnoreList,
  685. (void **)&pCaseIgnoreList
  686. );
  687. BAIL_ON_FAILURE(hr);
  688. _ADsValue.dwType = ADSTYPE_CASEIGNORE_LIST;
  689. hr = pCaseIgnoreList->get_CaseIgnoreList(&varCaseIgnoreList);
  690. BAIL_ON_FAILURE(hr);
  691. if(!((V_VT(&varCaseIgnoreList) & VT_VARIANT) && V_ISARRAY(&varCaseIgnoreList))) {
  692. hr = E_FAIL;
  693. BAIL_ON_FAILURE(hr);
  694. }
  695. if ((V_ARRAY(&varCaseIgnoreList))->cDims != 1) {
  696. hr = E_FAIL;
  697. BAIL_ON_FAILURE(hr);
  698. }
  699. if ((V_ARRAY(&varCaseIgnoreList))->rgsabound[0].cElements <= 0) {
  700. hr = E_FAIL;
  701. BAIL_ON_FAILURE(hr);
  702. }
  703. hr = SafeArrayGetLBound(V_ARRAY(&varCaseIgnoreList),
  704. 1,
  705. (long FAR *)&dwSLBound
  706. );
  707. BAIL_ON_FAILURE(hr);
  708. hr = SafeArrayGetUBound(V_ARRAY(&varCaseIgnoreList),
  709. 1,
  710. (long FAR *)&dwSUBound
  711. );
  712. BAIL_ON_FAILURE(hr);
  713. _ADsValue.pCaseIgnoreList = (PADS_CASEIGNORE_LIST)AllocADsMem(sizeof(ADS_CASEIGNORE_LIST));
  714. if (!_ADsValue.pCaseIgnoreList) {
  715. hr = E_OUTOFMEMORY;
  716. BAIL_ON_FAILURE(hr);
  717. }
  718. pCurrent = _ADsValue.pCaseIgnoreList;
  719. for (i = dwSLBound; i <= (long)dwSUBound; i++) {
  720. VariantInit(&varBstrElement);
  721. hr = SafeArrayGetElement(V_ARRAY(&varCaseIgnoreList),
  722. (long FAR *)&i,
  723. &varBstrElement
  724. );
  725. BAIL_ON_FAILURE(hr);
  726. pCurrent->String = AllocADsStr(V_BSTR(&varBstrElement));
  727. VariantClear(&varBstrElement);
  728. if (!pCurrent->String) {
  729. hr = E_OUTOFMEMORY;
  730. BAIL_ON_FAILURE(hr);
  731. }
  732. if (i != (long)dwSUBound) {
  733. pCurrent->Next = (PADS_CASEIGNORE_LIST)AllocADsMem(sizeof(ADS_CASEIGNORE_LIST));
  734. if (!pCurrent->Next) {
  735. hr = E_OUTOFMEMORY;
  736. BAIL_ON_FAILURE(hr);
  737. }
  738. pCurrent = pCurrent->Next;
  739. }
  740. }
  741. pCurrent->Next = NULL;
  742. RRETURN(S_OK);
  743. error:
  744. VariantClear(&varCaseIgnoreList);
  745. if (pCaseIgnoreList) {
  746. pCaseIgnoreList->Release();
  747. }
  748. RRETURN(hr);
  749. }
  750. STDMETHODIMP
  751. CPropertyValue::get_FaxNumber(THIS_ IDispatch FAR * FAR *retval)
  752. {
  753. HRESULT hr = S_OK;
  754. IADsFaxNumber * pFaxNumber = NULL;
  755. IDispatch * pDispatch = NULL;
  756. VARIANT Var;
  757. if (_ADsValue.dwType != ADSTYPE_FAXNUMBER) {
  758. hr = E_ADS_CANT_CONVERT_DATATYPE;
  759. BAIL_ON_FAILURE(hr);
  760. }
  761. if (!_ADsValue.pFaxNumber) {
  762. hr = E_FAIL;
  763. BAIL_ON_FAILURE(hr);
  764. }
  765. hr = CoCreateInstance(
  766. CLSID_FaxNumber,
  767. NULL,
  768. CLSCTX_INPROC_SERVER,
  769. IID_IADsFaxNumber,
  770. (void **) &pFaxNumber);
  771. BAIL_ON_FAILURE(hr);
  772. VariantInit(&Var);
  773. hr = BinaryToVariant(
  774. _ADsValue.pFaxNumber->NumberOfBits,
  775. _ADsValue.pFaxNumber->Parameters,
  776. &Var);
  777. BAIL_ON_FAILURE(hr);
  778. hr = pFaxNumber->put_Parameters(Var);
  779. VariantClear(&Var);
  780. BAIL_ON_FAILURE(hr);
  781. hr = pFaxNumber->put_TelephoneNumber(_ADsValue.pFaxNumber->TelephoneNumber);
  782. BAIL_ON_FAILURE(hr);
  783. hr = pFaxNumber->QueryInterface(
  784. IID_IDispatch,
  785. (void **) &pDispatch
  786. );
  787. BAIL_ON_FAILURE(hr);
  788. *retval = pDispatch;
  789. error:
  790. if (pFaxNumber) {
  791. pFaxNumber->Release();
  792. }
  793. RRETURN(hr);
  794. }
  795. STDMETHODIMP
  796. CPropertyValue::put_FaxNumber(THIS_ IDispatch FAR* pdFaxNumber)
  797. {
  798. IADsFaxNumber *pFaxNumber = NULL;
  799. HRESULT hr = S_OK;
  800. BSTR bstrTelephoneNumber = NULL;
  801. VARIANT varAddress;
  802. VariantInit(&varAddress);
  803. ClearData();
  804. hr = pdFaxNumber->QueryInterface(
  805. IID_IADsFaxNumber,
  806. (void **)&pFaxNumber
  807. );
  808. BAIL_ON_FAILURE(hr);
  809. hr = pFaxNumber->get_TelephoneNumber(&bstrTelephoneNumber);
  810. BAIL_ON_FAILURE(hr);
  811. _ADsValue.dwType = ADSTYPE_FAXNUMBER;
  812. _ADsValue.pFaxNumber = (PADS_FAXNUMBER)AllocADsMem(sizeof(ADS_FAXNUMBER));
  813. if (!_ADsValue.pFaxNumber) {
  814. hr = E_OUTOFMEMORY;
  815. BAIL_ON_FAILURE(hr);
  816. }
  817. _ADsValue.pFaxNumber->TelephoneNumber = AllocADsStr(bstrTelephoneNumber);
  818. if (!_ADsValue.pFaxNumber->TelephoneNumber && bstrTelephoneNumber) {
  819. hr = E_OUTOFMEMORY;
  820. BAIL_ON_FAILURE(hr);
  821. }
  822. hr = pFaxNumber->get_Parameters(&varAddress);
  823. BAIL_ON_FAILURE(hr);
  824. hr = VariantToBinary(
  825. &varAddress,
  826. &_ADsValue.pFaxNumber->NumberOfBits,
  827. &_ADsValue.pFaxNumber->Parameters
  828. );
  829. BAIL_ON_FAILURE(hr);
  830. error:
  831. VariantClear(&varAddress);
  832. if (pFaxNumber) {
  833. pFaxNumber->Release();
  834. }
  835. if(bstrTelephoneNumber)
  836. {
  837. SysFreeString(bstrTelephoneNumber);
  838. }
  839. RRETURN(hr);
  840. }
  841. STDMETHODIMP
  842. CPropertyValue::get_NetAddress(THIS_ IDispatch FAR * FAR *retval)
  843. {
  844. HRESULT hr = S_OK;
  845. IADsNetAddress * pNetAddress = NULL;
  846. IDispatch * pDispatch = NULL;
  847. VARIANT VarAddress;
  848. VariantInit(&VarAddress);
  849. if (_ADsValue.dwType != ADSTYPE_NETADDRESS) {
  850. hr = E_ADS_CANT_CONVERT_DATATYPE;
  851. BAIL_ON_FAILURE(hr);
  852. }
  853. if (!_ADsValue.pNetAddress) {
  854. hr = E_FAIL;
  855. BAIL_ON_FAILURE(hr);
  856. }
  857. hr = CoCreateInstance(
  858. CLSID_NetAddress,
  859. NULL,
  860. CLSCTX_INPROC_SERVER,
  861. IID_IADsNetAddress,
  862. (void **) &pNetAddress);
  863. BAIL_ON_FAILURE(hr);
  864. hr = pNetAddress->put_AddressType(_ADsValue.pNetAddress->AddressType);
  865. BAIL_ON_FAILURE(hr);
  866. hr = BinaryToVariant(
  867. _ADsValue.pNetAddress->AddressLength,
  868. _ADsValue.pNetAddress->Address,
  869. &VarAddress);
  870. BAIL_ON_FAILURE(hr);
  871. hr = pNetAddress->put_Address(VarAddress);
  872. BAIL_ON_FAILURE(hr);
  873. hr = pNetAddress->QueryInterface(
  874. IID_IDispatch,
  875. (void **) &pDispatch
  876. );
  877. BAIL_ON_FAILURE(hr);
  878. *retval = pDispatch;
  879. error:
  880. VariantClear(&VarAddress);
  881. if (pNetAddress) {
  882. pNetAddress->Release();
  883. }
  884. RRETURN(hr);
  885. }
  886. STDMETHODIMP
  887. CPropertyValue::put_NetAddress(THIS_ IDispatch FAR* pdNetAddress)
  888. {
  889. IADsNetAddress *pNetAddress = NULL;
  890. HRESULT hr = S_OK;
  891. LONG lnAddressType = 0;
  892. VARIANT varAddress;
  893. ClearData();
  894. VariantInit(&varAddress);
  895. _ADsValue.pNetAddress = (PADS_NETADDRESS)AllocADsMem(sizeof(ADS_NETADDRESS));
  896. if (!_ADsValue.pNetAddress) {
  897. hr = E_OUTOFMEMORY;
  898. BAIL_ON_FAILURE(hr);
  899. }
  900. hr = pdNetAddress->QueryInterface(
  901. IID_IADsNetAddress,
  902. (void **)&pNetAddress
  903. );
  904. BAIL_ON_FAILURE(hr);
  905. hr = pNetAddress->get_AddressType(
  906. &lnAddressType
  907. );
  908. BAIL_ON_FAILURE(hr);
  909. hr = pNetAddress->get_Address(
  910. &varAddress
  911. );
  912. BAIL_ON_FAILURE(hr);
  913. hr = VariantToBinary(
  914. &varAddress,
  915. &_ADsValue.pNetAddress->AddressLength,
  916. &_ADsValue.pNetAddress->Address
  917. );
  918. BAIL_ON_FAILURE(hr);
  919. _ADsValue.dwType = ADSTYPE_NETADDRESS;
  920. _ADsValue.pNetAddress->AddressType = lnAddressType;
  921. error:
  922. VariantClear(&varAddress);
  923. if (pNetAddress) {
  924. pNetAddress->Release();
  925. }
  926. RRETURN(hr);
  927. }
  928. STDMETHODIMP
  929. CPropertyValue::get_OctetList(THIS_ IDispatch FAR * FAR *retval)
  930. {
  931. HRESULT hr = S_OK;
  932. IADsOctetList* pOctetList = NULL;
  933. IDispatch * pDispatch = NULL;
  934. SAFEARRAY *aList = NULL;
  935. SAFEARRAYBOUND aBound;
  936. CHAR HUGEP *pArray = NULL;
  937. long i;
  938. PADS_OCTET_LIST pCurrent = NULL;
  939. DWORD cElements = 0;
  940. VARIANT VarDestObject;
  941. VARIANT varElement;
  942. VariantInit( &VarDestObject );
  943. VariantInit(&varElement);
  944. if (_ADsValue.dwType != ADSTYPE_OCTET_LIST) {
  945. hr = E_ADS_CANT_CONVERT_DATATYPE;
  946. BAIL_ON_FAILURE(hr);
  947. }
  948. if (!_ADsValue.pOctetList) {
  949. hr = E_FAIL;
  950. BAIL_ON_FAILURE(hr);
  951. }
  952. hr = CoCreateInstance(
  953. CLSID_OctetList,
  954. NULL,
  955. CLSCTX_INPROC_SERVER,
  956. IID_IADsOctetList,
  957. (void **) &pOctetList);
  958. BAIL_ON_FAILURE(hr);
  959. pCurrent = _ADsValue.pOctetList;
  960. while (pCurrent) {
  961. cElements++;
  962. pCurrent = pCurrent->Next;
  963. }
  964. aBound.lLbound = 0;
  965. aBound.cElements = cElements;
  966. aList = SafeArrayCreate( VT_VARIANT, 1, &aBound );
  967. if ( aList == NULL ) {
  968. hr = E_OUTOFMEMORY;
  969. BAIL_ON_FAILURE(hr);
  970. }
  971. pCurrent = _ADsValue.pOctetList;
  972. for ( i = 0; i < (long)cElements; i++ ) {
  973. hr = BinaryToVariant(
  974. pCurrent->Length,
  975. pCurrent->Data,
  976. &varElement);
  977. BAIL_ON_FAILURE(hr);
  978. hr = SafeArrayPutElement( aList, &i, &varElement);
  979. VariantClear(&varElement);
  980. BAIL_ON_FAILURE(hr);
  981. pCurrent = pCurrent->Next;
  982. }
  983. V_VT(&VarDestObject) = VT_ARRAY | VT_BSTR;
  984. V_ARRAY(&VarDestObject) = aList;
  985. hr = pOctetList->put_OctetList(VarDestObject);
  986. BAIL_ON_FAILURE(hr);
  987. hr = pOctetList->QueryInterface(IID_IDispatch, (void**)&pDispatch);
  988. BAIL_ON_FAILURE(hr);
  989. *retval = pDispatch;
  990. error:
  991. VariantClear( &VarDestObject );
  992. if (pOctetList) {
  993. pOctetList->Release();
  994. }
  995. if ( aList ) {
  996. SafeArrayDestroy( aList );
  997. }
  998. RRETURN(hr);
  999. }
  1000. STDMETHODIMP
  1001. CPropertyValue::put_OctetList(THIS_ IDispatch FAR* pdOctetList)
  1002. {
  1003. IADsOctetList *pOctetList = NULL;
  1004. HRESULT hr = S_OK;
  1005. LONG lnAmount= 0;
  1006. DWORD dwSLBound = 0;
  1007. DWORD dwSUBound = 0;
  1008. long i;
  1009. PADS_OCTET_LIST pCurrent = NULL;
  1010. IDispatch FAR * pDispatch = NULL;
  1011. BYTE* pbParameter = NULL;
  1012. VARIANT varOctetList;
  1013. VARIANT varElement;
  1014. VariantInit(&varOctetList);
  1015. ClearData();
  1016. hr = pdOctetList->QueryInterface(
  1017. IID_IADsOctetList,
  1018. (void **)&pOctetList
  1019. );
  1020. BAIL_ON_FAILURE(hr);
  1021. _ADsValue.dwType = ADSTYPE_OCTET_LIST;
  1022. hr = pOctetList->get_OctetList(&varOctetList);
  1023. BAIL_ON_FAILURE(hr);
  1024. if(!((V_VT(&varOctetList) & VT_VARIANT) && V_ISARRAY(&varOctetList))) {
  1025. hr = E_FAIL;
  1026. BAIL_ON_FAILURE(hr);
  1027. }
  1028. if ((V_ARRAY(&varOctetList))->cDims != 1) {
  1029. hr = E_FAIL;
  1030. BAIL_ON_FAILURE(hr);
  1031. }
  1032. if ((V_ARRAY(&varOctetList))->rgsabound[0].cElements <= 0) {
  1033. hr = E_FAIL;
  1034. BAIL_ON_FAILURE(hr);
  1035. }
  1036. hr = SafeArrayGetLBound(V_ARRAY(&varOctetList),
  1037. 1,
  1038. (long FAR *)&dwSLBound
  1039. );
  1040. BAIL_ON_FAILURE(hr);
  1041. hr = SafeArrayGetUBound(V_ARRAY(&varOctetList),
  1042. 1,
  1043. (long FAR *)&dwSUBound
  1044. );
  1045. BAIL_ON_FAILURE(hr);
  1046. _ADsValue.pOctetList = (PADS_OCTET_LIST)AllocADsMem(sizeof(ADS_OCTET_LIST));
  1047. if (!_ADsValue.pOctetList) {
  1048. hr = E_OUTOFMEMORY;
  1049. BAIL_ON_FAILURE(hr);
  1050. }
  1051. pCurrent = _ADsValue.pOctetList;
  1052. for (i = dwSLBound; i <= (long)dwSUBound; i++) {
  1053. VariantInit(&varElement);
  1054. hr = SafeArrayGetElement(V_ARRAY(&varOctetList),
  1055. (long FAR *)&i,
  1056. &varElement
  1057. );
  1058. BAIL_ON_FAILURE(hr);
  1059. hr = VariantToBinary(
  1060. &varElement,
  1061. &pCurrent->Length,
  1062. &pCurrent->Data
  1063. );
  1064. VariantClear(&varElement);
  1065. BAIL_ON_FAILURE(hr);
  1066. if (i != (long)dwSUBound) {
  1067. pCurrent->Next = (PADS_OCTET_LIST)AllocADsMem(sizeof(ADS_OCTET_LIST));
  1068. if (!pCurrent->Next) {
  1069. hr = E_OUTOFMEMORY;
  1070. BAIL_ON_FAILURE(hr);
  1071. }
  1072. pCurrent = pCurrent->Next;
  1073. }
  1074. }
  1075. pCurrent->Next = NULL;
  1076. error:
  1077. VariantClear(&varOctetList);
  1078. if (pOctetList) {
  1079. pOctetList->Release();
  1080. }
  1081. RRETURN(hr);
  1082. }
  1083. STDMETHODIMP
  1084. CPropertyValue::get_Email(THIS_ IDispatch FAR * FAR *retval)
  1085. {
  1086. HRESULT hr = S_OK;
  1087. IADsEmail* pEmail = NULL;
  1088. IDispatch * pDispatch = NULL;
  1089. if (_ADsValue.dwType != ADSTYPE_EMAIL) {
  1090. hr = E_ADS_CANT_CONVERT_DATATYPE;
  1091. BAIL_ON_FAILURE(hr);
  1092. }
  1093. hr = CoCreateInstance(
  1094. CLSID_Email,
  1095. NULL,
  1096. CLSCTX_INPROC_SERVER,
  1097. IID_IADsEmail,
  1098. (void **) &pEmail);
  1099. BAIL_ON_FAILURE(hr);
  1100. hr = pEmail->put_Type(_ADsValue.Email.Type);
  1101. BAIL_ON_FAILURE(hr);
  1102. hr = pEmail->put_Address(_ADsValue.Email.Address);
  1103. BAIL_ON_FAILURE(hr);
  1104. hr = pEmail->QueryInterface(
  1105. IID_IDispatch,
  1106. (void **) &pDispatch
  1107. );
  1108. BAIL_ON_FAILURE(hr);
  1109. *retval = pDispatch;
  1110. error:
  1111. if (pEmail) {
  1112. pEmail->Release();
  1113. }
  1114. RRETURN(hr);
  1115. }
  1116. STDMETHODIMP
  1117. CPropertyValue::put_Email(THIS_ IDispatch FAR* pdEmail)
  1118. {
  1119. IADsEmail *pEmail = NULL;
  1120. HRESULT hr = S_OK;
  1121. LONG lnType= 0;
  1122. BSTR bstrAddress = NULL;
  1123. ClearData();
  1124. hr = pdEmail->QueryInterface(
  1125. IID_IADsEmail,
  1126. (void **)&pEmail
  1127. );
  1128. BAIL_ON_FAILURE(hr);
  1129. hr = pEmail->get_Type(
  1130. &lnType
  1131. );
  1132. BAIL_ON_FAILURE(hr);
  1133. hr = pEmail->get_Address(&bstrAddress);
  1134. BAIL_ON_FAILURE(hr);
  1135. _ADsValue.dwType = ADSTYPE_EMAIL;
  1136. _ADsValue.Email.Type = lnType;
  1137. _ADsValue.Email.Address = AllocADsStr(bstrAddress);
  1138. if (!_ADsValue.Email.Address && bstrAddress) {
  1139. hr = E_OUTOFMEMORY;
  1140. BAIL_ON_FAILURE(hr);
  1141. }
  1142. error:
  1143. if (pEmail) {
  1144. pEmail->Release();
  1145. }
  1146. if(bstrAddress)
  1147. {
  1148. SysFreeString(bstrAddress);
  1149. }
  1150. RRETURN(hr);
  1151. }
  1152. STDMETHODIMP
  1153. CPropertyValue::get_Path(THIS_ IDispatch FAR * FAR *retval)
  1154. {
  1155. HRESULT hr = S_OK;
  1156. IADsPath* pPath = NULL;
  1157. IDispatch * pDispatch = NULL;
  1158. if (_ADsValue.dwType != ADSTYPE_PATH) {
  1159. hr = E_ADS_CANT_CONVERT_DATATYPE;
  1160. BAIL_ON_FAILURE(hr);
  1161. }
  1162. if (!_ADsValue.pPath) {
  1163. hr = E_FAIL;
  1164. BAIL_ON_FAILURE(hr);
  1165. }
  1166. hr = CoCreateInstance(
  1167. CLSID_Path,
  1168. NULL,
  1169. CLSCTX_INPROC_SERVER,
  1170. IID_IADsPath,
  1171. (void **) &pPath);
  1172. BAIL_ON_FAILURE(hr);
  1173. hr = pPath->put_Type(_ADsValue.pPath->Type);
  1174. BAIL_ON_FAILURE(hr);
  1175. hr = pPath->put_VolumeName(_ADsValue.pPath->VolumeName);
  1176. BAIL_ON_FAILURE(hr);
  1177. hr = pPath->put_Path(_ADsValue.pPath->Path);
  1178. BAIL_ON_FAILURE(hr);
  1179. hr = pPath->QueryInterface(
  1180. IID_IDispatch,
  1181. (void **) &pDispatch
  1182. );
  1183. BAIL_ON_FAILURE(hr);
  1184. *retval = pDispatch;
  1185. error:
  1186. if (pPath) {
  1187. pPath->Release();
  1188. }
  1189. RRETURN(hr);
  1190. }
  1191. STDMETHODIMP
  1192. CPropertyValue::put_Path(THIS_ IDispatch FAR* pdPath)
  1193. {
  1194. IADsPath *pPath = NULL;
  1195. HRESULT hr = S_OK;
  1196. LONG lnType = 0;
  1197. BSTR bstrVolumeName = NULL;
  1198. BSTR bstrPath = NULL;
  1199. ClearData();
  1200. hr = pdPath->QueryInterface(
  1201. IID_IADsPath,
  1202. (void **)&pPath
  1203. );
  1204. BAIL_ON_FAILURE(hr);
  1205. hr = pPath->get_Type(
  1206. &lnType
  1207. );
  1208. BAIL_ON_FAILURE(hr);
  1209. hr = pPath->get_VolumeName(
  1210. &bstrVolumeName
  1211. );
  1212. BAIL_ON_FAILURE(hr);
  1213. hr = pPath->get_Path(
  1214. &bstrPath
  1215. );
  1216. BAIL_ON_FAILURE(hr);
  1217. _ADsValue.dwType = ADSTYPE_PATH;
  1218. _ADsValue.pPath = (PADS_PATH)AllocADsMem(sizeof(ADS_PATH));
  1219. if (!_ADsValue.pPath) {
  1220. hr = E_OUTOFMEMORY;
  1221. BAIL_ON_FAILURE(hr);
  1222. }
  1223. _ADsValue.pPath->Type = lnType;
  1224. _ADsValue.pPath->VolumeName = AllocADsStr(bstrVolumeName);
  1225. if (!_ADsValue.pPath->VolumeName && bstrVolumeName) {
  1226. hr = E_OUTOFMEMORY;
  1227. BAIL_ON_FAILURE(hr);
  1228. }
  1229. _ADsValue.pPath->Path = AllocADsStr(bstrPath);
  1230. if (!_ADsValue.pPath->Path && bstrPath) {
  1231. hr = E_OUTOFMEMORY;
  1232. BAIL_ON_FAILURE(hr);
  1233. }
  1234. error:
  1235. if (pPath) {
  1236. pPath->Release();
  1237. }
  1238. if(bstrVolumeName)
  1239. {
  1240. SysFreeString(bstrVolumeName);
  1241. }
  1242. if(bstrPath)
  1243. {
  1244. SysFreeString(bstrPath);
  1245. }
  1246. RRETURN(hr);
  1247. }
  1248. STDMETHODIMP
  1249. CPropertyValue::get_ReplicaPointer(THIS_ IDispatch FAR * FAR *retval)
  1250. {
  1251. HRESULT hr = S_OK;
  1252. IADsReplicaPointer* pReplicaPointer = NULL;
  1253. IDispatch * pDispatch = NULL;
  1254. IADsNetAddress* pNetAddress = NULL;
  1255. VARIANT VarNetAddress;
  1256. VARIANT VarDest;
  1257. VariantInit(&VarNetAddress);
  1258. VariantInit(&VarDest);
  1259. if (_ADsValue.dwType != ADSTYPE_REPLICAPOINTER) {
  1260. hr = E_ADS_CANT_CONVERT_DATATYPE;
  1261. BAIL_ON_FAILURE(hr);
  1262. }
  1263. if (!_ADsValue.pReplicaPointer) {
  1264. hr = E_FAIL;
  1265. BAIL_ON_FAILURE(hr);
  1266. }
  1267. hr = CoCreateInstance(
  1268. CLSID_ReplicaPointer,
  1269. NULL,
  1270. CLSCTX_INPROC_SERVER,
  1271. IID_IADsReplicaPointer,
  1272. (void **) &pReplicaPointer);
  1273. BAIL_ON_FAILURE(hr);
  1274. hr = pReplicaPointer->put_ReplicaType(_ADsValue.pReplicaPointer->ReplicaType);
  1275. BAIL_ON_FAILURE(hr);
  1276. hr = pReplicaPointer->put_ReplicaNumber(_ADsValue.pReplicaPointer->ReplicaNumber);
  1277. BAIL_ON_FAILURE(hr);
  1278. hr = pReplicaPointer->put_Count(_ADsValue.pReplicaPointer->Count);
  1279. BAIL_ON_FAILURE(hr);
  1280. hr = pReplicaPointer->put_ServerName(_ADsValue.pReplicaPointer->ServerName);
  1281. BAIL_ON_FAILURE(hr);
  1282. ////
  1283. hr = CoCreateInstance(
  1284. CLSID_NetAddress,
  1285. NULL,
  1286. CLSCTX_INPROC_SERVER,
  1287. IID_IADsNetAddress,
  1288. (void **) &pNetAddress);
  1289. BAIL_ON_FAILURE(hr);
  1290. hr = pNetAddress->put_AddressType(_ADsValue.pReplicaPointer->ReplicaAddressHints->AddressType);
  1291. BAIL_ON_FAILURE(hr);
  1292. hr = BinaryToVariant(
  1293. _ADsValue.pReplicaPointer->ReplicaAddressHints->AddressLength,
  1294. _ADsValue.pReplicaPointer->ReplicaAddressHints->Address,
  1295. &VarNetAddress);
  1296. BAIL_ON_FAILURE(hr);
  1297. hr = pNetAddress->put_Address(VarNetAddress);
  1298. BAIL_ON_FAILURE(hr);
  1299. hr = pNetAddress->QueryInterface(
  1300. IID_IDispatch,
  1301. (void **) &pDispatch
  1302. );
  1303. BAIL_ON_FAILURE(hr);
  1304. V_VT(&VarDest) = VT_DISPATCH;
  1305. V_DISPATCH(&VarDest) = pDispatch;
  1306. hr = pReplicaPointer->put_ReplicaAddressHints(VarDest);
  1307. BAIL_ON_FAILURE(hr);
  1308. hr = pReplicaPointer->QueryInterface(
  1309. IID_IDispatch,
  1310. (void **) &pDispatch
  1311. );
  1312. BAIL_ON_FAILURE(hr);
  1313. *retval = pDispatch;
  1314. error:
  1315. VariantClear(&VarNetAddress);
  1316. VariantClear(&VarDest);
  1317. if (pReplicaPointer) {
  1318. pReplicaPointer->Release();
  1319. }
  1320. if (pNetAddress) {
  1321. pNetAddress->Release();
  1322. }
  1323. RRETURN(hr);
  1324. }
  1325. STDMETHODIMP
  1326. CPropertyValue::put_ReplicaPointer(THIS_ IDispatch FAR* pdReplicaPointer)
  1327. {
  1328. IADsReplicaPointer *pReplicaPointer = NULL;
  1329. HRESULT hr = S_OK;
  1330. LONG lnAmount= 0;
  1331. IADsNetAddress *pNetAddress = NULL;
  1332. LONG lnAddressType = 0;
  1333. VARIANT varAddress;
  1334. IDispatch *pdNetAddress = NULL;
  1335. long lnReplicaType;
  1336. long lnReplicaNumber;
  1337. long lnCount;
  1338. BSTR bstrServerName = NULL;
  1339. VariantInit(&varAddress);
  1340. ClearData();
  1341. _ADsValue.pReplicaPointer = (PADS_REPLICAPOINTER)AllocADsMem(sizeof(ADS_REPLICAPOINTER));
  1342. if (!_ADsValue.pReplicaPointer) {
  1343. hr = E_OUTOFMEMORY;
  1344. BAIL_ON_FAILURE(hr);
  1345. }
  1346. _ADsValue.pReplicaPointer->ReplicaAddressHints =
  1347. (PADS_NETADDRESS)
  1348. AllocADsMem(
  1349. sizeof(ADS_NETADDRESS)
  1350. );
  1351. if (!(_ADsValue.pReplicaPointer->ReplicaAddressHints)) {
  1352. hr = E_OUTOFMEMORY;
  1353. BAIL_ON_FAILURE(hr);
  1354. }
  1355. hr = pdReplicaPointer->QueryInterface(
  1356. IID_IADsReplicaPointer,
  1357. (void **)&pReplicaPointer
  1358. );
  1359. BAIL_ON_FAILURE(hr);
  1360. hr = pReplicaPointer->get_ReplicaType(
  1361. &lnReplicaType
  1362. );
  1363. BAIL_ON_FAILURE(hr);
  1364. hr = pReplicaPointer->get_ReplicaNumber(
  1365. &lnReplicaNumber
  1366. );
  1367. BAIL_ON_FAILURE(hr);
  1368. hr = pReplicaPointer->get_Count(
  1369. &lnCount
  1370. );
  1371. BAIL_ON_FAILURE(hr);
  1372. hr = pReplicaPointer->get_ServerName(
  1373. &bstrServerName
  1374. );
  1375. BAIL_ON_FAILURE(hr);
  1376. hr = pReplicaPointer->get_ReplicaAddressHints(&varAddress);
  1377. BAIL_ON_FAILURE(hr);
  1378. if (V_VT(&varAddress) != VT_DISPATCH){
  1379. hr = E_FAIL;
  1380. BAIL_ON_FAILURE(hr);
  1381. }
  1382. pdNetAddress = V_DISPATCH(&varAddress);
  1383. hr = pdNetAddress->QueryInterface(
  1384. IID_IADsNetAddress,
  1385. (void **)&pNetAddress
  1386. );
  1387. BAIL_ON_FAILURE(hr);
  1388. hr = pNetAddress->get_AddressType(
  1389. &lnAddressType
  1390. );
  1391. BAIL_ON_FAILURE(hr);
  1392. hr = pNetAddress->get_Address(
  1393. &varAddress
  1394. );
  1395. BAIL_ON_FAILURE(hr);
  1396. hr = VariantToBinary(
  1397. &varAddress,
  1398. &_ADsValue.pReplicaPointer->ReplicaAddressHints->AddressLength,
  1399. &_ADsValue.pReplicaPointer->ReplicaAddressHints->Address
  1400. );
  1401. BAIL_ON_FAILURE(hr);
  1402. _ADsValue.dwType = ADSTYPE_REPLICAPOINTER;
  1403. _ADsValue.pReplicaPointer->ReplicaAddressHints->AddressType = lnAddressType;
  1404. _ADsValue.pReplicaPointer->ReplicaType = lnReplicaType;
  1405. _ADsValue.pReplicaPointer->ReplicaNumber = lnReplicaNumber;
  1406. _ADsValue.pReplicaPointer->Count = lnCount;
  1407. _ADsValue.pReplicaPointer->ServerName = AllocADsStr(bstrServerName);
  1408. if (!_ADsValue.pReplicaPointer->ServerName && bstrServerName) {
  1409. hr = E_OUTOFMEMORY;
  1410. BAIL_ON_FAILURE(hr);
  1411. }
  1412. error:
  1413. VariantClear(&varAddress);
  1414. if (pNetAddress) {
  1415. pNetAddress->Release();
  1416. }
  1417. if (pReplicaPointer) {
  1418. pReplicaPointer->Release();
  1419. }
  1420. if(bstrServerName)
  1421. {
  1422. SysFreeString(bstrServerName);
  1423. }
  1424. RRETURN(hr);
  1425. }
  1426. STDMETHODIMP
  1427. CPropertyValue::get_Timestamp(THIS_ IDispatch FAR * FAR *retval)
  1428. {
  1429. HRESULT hr = S_OK;
  1430. IADsTimestamp* pTimestamp = NULL;
  1431. IDispatch * pDispatch = NULL;
  1432. if (_ADsValue.dwType != ADSTYPE_TIMESTAMP) {
  1433. hr = E_ADS_CANT_CONVERT_DATATYPE;
  1434. BAIL_ON_FAILURE(hr);
  1435. }
  1436. hr = CoCreateInstance(
  1437. CLSID_Timestamp,
  1438. NULL,
  1439. CLSCTX_INPROC_SERVER,
  1440. IID_IADsTimestamp,
  1441. (void **) &pTimestamp);
  1442. BAIL_ON_FAILURE(hr);
  1443. hr = pTimestamp->put_WholeSeconds(_ADsValue.Timestamp.WholeSeconds);
  1444. BAIL_ON_FAILURE(hr);
  1445. hr = pTimestamp->put_EventID(_ADsValue.Timestamp.EventID);
  1446. BAIL_ON_FAILURE(hr);
  1447. hr = pTimestamp->QueryInterface(
  1448. IID_IDispatch,
  1449. (void **) &pDispatch
  1450. );
  1451. BAIL_ON_FAILURE(hr);
  1452. *retval = pDispatch;
  1453. error:
  1454. if (pTimestamp) {
  1455. pTimestamp->Release();
  1456. }
  1457. RRETURN(hr);
  1458. }
  1459. STDMETHODIMP
  1460. CPropertyValue::put_Timestamp(THIS_ IDispatch FAR* lnTimestamp)
  1461. {
  1462. IADsTimestamp *pTimestamp = NULL;
  1463. HRESULT hr = S_OK;
  1464. LONG lnWholeSeconds = 0;
  1465. LONG lnEventID = 0;
  1466. ClearData();
  1467. hr = lnTimestamp->QueryInterface(
  1468. IID_IADsTimestamp,
  1469. (void **)&pTimestamp
  1470. );
  1471. BAIL_ON_FAILURE(hr);
  1472. hr = pTimestamp->get_WholeSeconds(
  1473. &lnWholeSeconds
  1474. );
  1475. BAIL_ON_FAILURE(hr);
  1476. hr = pTimestamp->get_EventID(
  1477. &lnEventID
  1478. );
  1479. BAIL_ON_FAILURE(hr);
  1480. _ADsValue.dwType = ADSTYPE_TIMESTAMP;
  1481. _ADsValue.Timestamp.WholeSeconds = lnWholeSeconds;
  1482. _ADsValue.Timestamp.EventID = lnEventID;
  1483. error:
  1484. if (pTimestamp) {
  1485. pTimestamp->Release();
  1486. }
  1487. RRETURN(hr);
  1488. }
  1489. STDMETHODIMP
  1490. CPropertyValue::get_PostalAddress(THIS_ IDispatch FAR * FAR *retval)
  1491. {
  1492. HRESULT hr = S_OK;
  1493. IADsPostalAddress * pPostalAddress = NULL;
  1494. IDispatch * pDispatch = NULL;
  1495. SAFEARRAY *aList = NULL;
  1496. SAFEARRAYBOUND aBound;
  1497. CHAR HUGEP *pArray = NULL;
  1498. long i;
  1499. BSTR bstrAddress = NULL;
  1500. DWORD cElements = 0;
  1501. VARIANT VarDestObject;
  1502. VariantInit( &VarDestObject );
  1503. if (_ADsValue.dwType != ADSTYPE_POSTALADDRESS) {
  1504. hr = E_ADS_CANT_CONVERT_DATATYPE;
  1505. BAIL_ON_FAILURE(hr);
  1506. }
  1507. if (!_ADsValue.pPostalAddress) {
  1508. hr = E_FAIL;
  1509. BAIL_ON_FAILURE(hr);
  1510. }
  1511. hr = CoCreateInstance(
  1512. CLSID_PostalAddress,
  1513. NULL,
  1514. CLSCTX_INPROC_SERVER,
  1515. IID_IADsPostalAddress,
  1516. (void **) &pPostalAddress);
  1517. BAIL_ON_FAILURE(hr);
  1518. aBound.lLbound = 0;
  1519. aBound.cElements = 6;
  1520. aList = SafeArrayCreate( VT_BSTR, 1, &aBound );
  1521. if ( aList == NULL ) {
  1522. hr = E_OUTOFMEMORY;
  1523. BAIL_ON_FAILURE(hr);
  1524. }
  1525. for ( i = 0; i < (long) 6; i++ )
  1526. {
  1527. hr = ADsAllocString(
  1528. _ADsValue.pPostalAddress->PostalAddress[i],
  1529. &bstrAddress
  1530. );
  1531. BAIL_ON_FAILURE(hr);
  1532. hr = SafeArrayPutElement( aList, &i, bstrAddress );
  1533. SysFreeString(bstrAddress);
  1534. BAIL_ON_FAILURE(hr);
  1535. }
  1536. V_VT(&VarDestObject) = VT_ARRAY | VT_BSTR;
  1537. V_ARRAY(&VarDestObject) = aList;
  1538. hr = pPostalAddress->put_PostalAddress(VarDestObject);
  1539. BAIL_ON_FAILURE(hr);
  1540. hr = pPostalAddress->QueryInterface(IID_IDispatch, (void**)&pDispatch);
  1541. BAIL_ON_FAILURE(hr);
  1542. *retval = pDispatch;
  1543. RRETURN(hr);
  1544. error:
  1545. VariantClear( &VarDestObject );
  1546. if (pPostalAddress) {
  1547. pPostalAddress->Release();
  1548. }
  1549. if (aList) {
  1550. SafeArrayDestroy( aList );
  1551. }
  1552. RRETURN(hr);
  1553. }
  1554. STDMETHODIMP
  1555. CPropertyValue::put_PostalAddress(THIS_ IDispatch FAR* pdPostalAddress)
  1556. {
  1557. IADsPostalAddress *pPostalAddress = NULL;
  1558. HRESULT hr = S_OK;
  1559. LONG lnAmount= 0;
  1560. DWORD dwSLBound = 0;
  1561. DWORD dwSUBound = 0;
  1562. long i;
  1563. IDispatch FAR * pDispatch = NULL;
  1564. BYTE* pbParameter = NULL;
  1565. VARIANT varAddress;
  1566. VARIANT varBstrElement;
  1567. VariantInit(&varAddress);
  1568. ClearData();
  1569. hr = pdPostalAddress->QueryInterface(
  1570. IID_IADsPostalAddress,
  1571. (void **)&pPostalAddress
  1572. );
  1573. BAIL_ON_FAILURE(hr);
  1574. _ADsValue.dwType = ADSTYPE_POSTALADDRESS;
  1575. _ADsValue.pPostalAddress = (PADS_POSTALADDRESS)AllocADsMem(sizeof(ADS_POSTALADDRESS));
  1576. if (!_ADsValue.pPostalAddress) {
  1577. hr = E_OUTOFMEMORY;
  1578. BAIL_ON_FAILURE(hr);
  1579. }
  1580. hr = pPostalAddress->get_PostalAddress(
  1581. &varAddress
  1582. );
  1583. BAIL_ON_FAILURE(hr);
  1584. if(!((V_VT(&varAddress) & VT_VARIANT) && V_ISARRAY(&varAddress))) {
  1585. hr = E_FAIL;
  1586. BAIL_ON_FAILURE(hr);
  1587. }
  1588. if ((V_ARRAY(&varAddress))->cDims != 1) {
  1589. hr = E_FAIL;
  1590. BAIL_ON_FAILURE(hr);
  1591. }
  1592. if ( ((V_ARRAY(&varAddress))->rgsabound[0].cElements <= 0) ||
  1593. ((V_ARRAY(&varAddress))->rgsabound[0].cElements >6) ) {
  1594. hr = E_FAIL;
  1595. BAIL_ON_FAILURE(hr);
  1596. }
  1597. hr = SafeArrayGetLBound(V_ARRAY(&varAddress),
  1598. 1,
  1599. (long FAR *)&dwSLBound
  1600. );
  1601. BAIL_ON_FAILURE(hr);
  1602. hr = SafeArrayGetUBound(V_ARRAY(&varAddress),
  1603. 1,
  1604. (long FAR *)&dwSUBound
  1605. );
  1606. BAIL_ON_FAILURE(hr);
  1607. for (i = dwSLBound; i <= (long)dwSUBound; i++) {
  1608. VariantInit(&varBstrElement);
  1609. hr = SafeArrayGetElement(V_ARRAY(&varAddress),
  1610. (long FAR *)&i,
  1611. &varBstrElement
  1612. );
  1613. BAIL_ON_FAILURE(hr);
  1614. _ADsValue.pPostalAddress->PostalAddress[i-dwSLBound] = AllocADsStr(V_BSTR(&varBstrElement));
  1615. VariantClear(&varBstrElement);
  1616. if (!_ADsValue.pPostalAddress->PostalAddress[i-dwSLBound]) {
  1617. hr = E_OUTOFMEMORY;
  1618. BAIL_ON_FAILURE(hr);
  1619. }
  1620. }
  1621. RRETURN(S_OK);
  1622. error:
  1623. VariantClear(&varAddress);
  1624. if (pPostalAddress) {
  1625. pPostalAddress->Release();
  1626. }
  1627. RRETURN(hr);
  1628. }
  1629. STDMETHODIMP
  1630. CPropertyValue::get_BackLink(THIS_ IDispatch FAR * FAR *retval)
  1631. {
  1632. HRESULT hr = S_OK;
  1633. IADsBackLink* pBackLink = NULL;
  1634. IDispatch * pDispatch = NULL;
  1635. if (_ADsValue.dwType != ADSTYPE_BACKLINK) {
  1636. hr = E_ADS_CANT_CONVERT_DATATYPE;
  1637. BAIL_ON_FAILURE(hr);
  1638. }
  1639. hr = CoCreateInstance(
  1640. CLSID_BackLink,
  1641. NULL,
  1642. CLSCTX_INPROC_SERVER,
  1643. IID_IADsBackLink,
  1644. (void **) &pBackLink);
  1645. BAIL_ON_FAILURE(hr);
  1646. hr = pBackLink->put_RemoteID(_ADsValue.BackLink.RemoteID);
  1647. BAIL_ON_FAILURE(hr);
  1648. hr = pBackLink->put_ObjectName(_ADsValue.BackLink.ObjectName);
  1649. BAIL_ON_FAILURE(hr);
  1650. hr = pBackLink->QueryInterface(
  1651. IID_IDispatch,
  1652. (void **) &pDispatch
  1653. );
  1654. BAIL_ON_FAILURE(hr);
  1655. *retval = pDispatch;
  1656. error:
  1657. if (pBackLink) {
  1658. pBackLink->Release();
  1659. }
  1660. RRETURN(hr);
  1661. }
  1662. STDMETHODIMP
  1663. CPropertyValue::put_BackLink(THIS_ IDispatch FAR* pdBackLink)
  1664. {
  1665. IADsBackLink *pBackLink = NULL;
  1666. HRESULT hr = S_OK;
  1667. LONG lnRemoteID = 0;
  1668. BSTR bstrObjectName = NULL;
  1669. ClearData();
  1670. hr = pdBackLink->QueryInterface(
  1671. IID_IADsBackLink,
  1672. (void **)&pBackLink
  1673. );
  1674. BAIL_ON_FAILURE(hr);
  1675. hr = pBackLink->get_RemoteID(
  1676. &lnRemoteID
  1677. );
  1678. BAIL_ON_FAILURE(hr);
  1679. hr = pBackLink->get_ObjectName(
  1680. &bstrObjectName
  1681. );
  1682. BAIL_ON_FAILURE(hr);
  1683. _ADsValue.dwType = ADSTYPE_BACKLINK;
  1684. _ADsValue.BackLink.RemoteID = lnRemoteID;
  1685. _ADsValue.BackLink.ObjectName = AllocADsStr(bstrObjectName);
  1686. if (!_ADsValue.BackLink.ObjectName && bstrObjectName ) {
  1687. hr = E_OUTOFMEMORY;
  1688. BAIL_ON_FAILURE(hr);
  1689. }
  1690. error:
  1691. if (pBackLink) {
  1692. pBackLink->Release();
  1693. }
  1694. if(bstrObjectName)
  1695. {
  1696. SysFreeString(bstrObjectName);
  1697. }
  1698. RRETURN(hr);
  1699. }
  1700. STDMETHODIMP
  1701. CPropertyValue::get_TypedName(THIS_ IDispatch FAR * FAR *retval)
  1702. {
  1703. HRESULT hr = S_OK;
  1704. IADsTypedName* pTypedName = NULL;
  1705. IDispatch * pDispatch = NULL;
  1706. if (_ADsValue.dwType != ADSTYPE_TYPEDNAME) {
  1707. hr = E_ADS_CANT_CONVERT_DATATYPE;
  1708. BAIL_ON_FAILURE(hr);
  1709. }
  1710. if (!_ADsValue.pTypedName) {
  1711. hr = E_FAIL;
  1712. BAIL_ON_FAILURE(hr);
  1713. }
  1714. hr = CoCreateInstance(
  1715. CLSID_TypedName,
  1716. NULL,
  1717. CLSCTX_INPROC_SERVER,
  1718. IID_IADsTypedName,
  1719. (void **) &pTypedName);
  1720. BAIL_ON_FAILURE(hr);
  1721. hr = pTypedName->put_Level(_ADsValue.pTypedName->Level);
  1722. BAIL_ON_FAILURE(hr);
  1723. hr = pTypedName->put_Interval(_ADsValue.pTypedName->Interval);
  1724. BAIL_ON_FAILURE(hr);
  1725. hr = pTypedName->put_ObjectName(_ADsValue.pTypedName->ObjectName);
  1726. BAIL_ON_FAILURE(hr);
  1727. hr = pTypedName->QueryInterface(
  1728. IID_IDispatch,
  1729. (void **) &pDispatch
  1730. );
  1731. BAIL_ON_FAILURE(hr);
  1732. *retval = pDispatch;
  1733. error:
  1734. if (pTypedName) {
  1735. pTypedName->Release();
  1736. }
  1737. RRETURN(hr);
  1738. }
  1739. STDMETHODIMP
  1740. CPropertyValue::put_TypedName(THIS_ IDispatch FAR* pdTypedName)
  1741. {
  1742. IADsTypedName* pTypedName = NULL;
  1743. HRESULT hr = S_OK;
  1744. LONG lnLevel= 0;
  1745. LONG lnInterval= 0;
  1746. BSTR bstrObjectName = NULL;
  1747. ClearData();
  1748. hr = pdTypedName->QueryInterface(
  1749. IID_IADsTypedName,
  1750. (void **)&pTypedName
  1751. );
  1752. BAIL_ON_FAILURE(hr);
  1753. hr = pTypedName->get_Level(
  1754. &lnLevel
  1755. );
  1756. BAIL_ON_FAILURE(hr);
  1757. hr = pTypedName->get_Interval(
  1758. &lnInterval
  1759. );
  1760. BAIL_ON_FAILURE(hr);
  1761. hr = pTypedName->get_ObjectName(
  1762. &bstrObjectName
  1763. );
  1764. BAIL_ON_FAILURE(hr);
  1765. _ADsValue.dwType = ADSTYPE_TYPEDNAME;
  1766. _ADsValue.pTypedName = (PADS_TYPEDNAME)AllocADsMem(sizeof(ADS_TYPEDNAME));
  1767. if (!_ADsValue.pTypedName) {
  1768. hr = E_OUTOFMEMORY;
  1769. BAIL_ON_FAILURE(hr);
  1770. }
  1771. _ADsValue.pTypedName->Level= lnLevel;
  1772. _ADsValue.pTypedName->Interval= lnInterval;
  1773. _ADsValue.pTypedName->ObjectName = AllocADsStr(bstrObjectName);
  1774. if (!_ADsValue.pTypedName->ObjectName && bstrObjectName) {
  1775. hr = E_OUTOFMEMORY;
  1776. BAIL_ON_FAILURE(hr);
  1777. }
  1778. error:
  1779. if (pTypedName) {
  1780. pTypedName->Release();
  1781. }
  1782. if(bstrObjectName)
  1783. {
  1784. SysFreeString(bstrObjectName);
  1785. }
  1786. RRETURN(hr);
  1787. }
  1788. STDMETHODIMP
  1789. CPropertyValue::get_Hold(THIS_ IDispatch FAR * FAR *retval)
  1790. {
  1791. HRESULT hr = S_OK;
  1792. IADsHold* pHold = NULL;
  1793. IDispatch * pDispatch = NULL;
  1794. if (_ADsValue.dwType != ADSTYPE_HOLD) {
  1795. hr = E_ADS_CANT_CONVERT_DATATYPE;
  1796. BAIL_ON_FAILURE(hr);
  1797. }
  1798. hr = CoCreateInstance(
  1799. CLSID_Hold,
  1800. NULL,
  1801. CLSCTX_INPROC_SERVER,
  1802. IID_IADsHold,
  1803. (void **) &pHold);
  1804. BAIL_ON_FAILURE(hr);
  1805. hr = pHold->put_Amount(_ADsValue.Hold.Amount);
  1806. BAIL_ON_FAILURE(hr);
  1807. hr = pHold->put_ObjectName(_ADsValue.Hold.ObjectName);
  1808. BAIL_ON_FAILURE(hr);
  1809. hr = pHold->QueryInterface(
  1810. IID_IDispatch,
  1811. (void **) &pDispatch
  1812. );
  1813. BAIL_ON_FAILURE(hr);
  1814. *retval = pDispatch;
  1815. error:
  1816. if (pHold) {
  1817. pHold->Release();
  1818. }
  1819. RRETURN(hr);
  1820. }
  1821. STDMETHODIMP
  1822. CPropertyValue::put_Hold(THIS_ IDispatch FAR* pdHold)
  1823. {
  1824. IADsHold *pHold = NULL;
  1825. HRESULT hr = S_OK;
  1826. LONG lnAmount= 0;
  1827. BSTR bstrObjectName = NULL;
  1828. ClearData();
  1829. hr = pdHold->QueryInterface(
  1830. IID_IADsHold,
  1831. (void **)&pHold
  1832. );
  1833. BAIL_ON_FAILURE(hr);
  1834. hr = pHold->get_Amount(
  1835. &lnAmount
  1836. );
  1837. BAIL_ON_FAILURE(hr);
  1838. hr = pHold->get_ObjectName(
  1839. &bstrObjectName
  1840. );
  1841. BAIL_ON_FAILURE(hr);
  1842. _ADsValue.dwType = ADSTYPE_HOLD;
  1843. _ADsValue.Hold.Amount= lnAmount;
  1844. _ADsValue.Hold.ObjectName = AllocADsStr(bstrObjectName);
  1845. if (!_ADsValue.Hold.ObjectName && bstrObjectName) {
  1846. hr = E_OUTOFMEMORY;
  1847. BAIL_ON_FAILURE(hr);
  1848. }
  1849. error:
  1850. if (pHold) {
  1851. pHold->Release();
  1852. }
  1853. if(bstrObjectName)
  1854. {
  1855. SysFreeString(bstrObjectName);
  1856. }
  1857. RRETURN(hr);
  1858. }
  1859. //
  1860. // Helper to get octetString in variant if we have a
  1861. // secDesc stored underneath.
  1862. //
  1863. STDMETHODIMP
  1864. CPropertyValue::getOctetStringFromSecDesc(VARIANT FAR *retval)
  1865. {
  1866. HRESULT hr = S_OK;
  1867. SAFEARRAY *aList = NULL;
  1868. SAFEARRAYBOUND aBound;
  1869. CHAR HUGEP *pArray = NULL;
  1870. ADSVALUE ADsDestValue;
  1871. memset(&ADsDestValue, 0, sizeof(ADSVALUE));
  1872. hr = AdsCopyPropObjToADsValue(
  1873. this,
  1874. &ADsDestValue,
  1875. NULL, // pszServerName,
  1876. NULL, // pCredentials - use default credentials
  1877. TRUE // fNTDSType
  1878. );
  1879. BAIL_ON_FAILURE(hr);
  1880. if (ADsDestValue.dwType != ADSTYPE_OCTET_STRING) {
  1881. BAIL_ON_FAILURE(hr = E_ADS_CANT_CONVERT_DATATYPE);
  1882. }
  1883. aBound.lLbound = 0;
  1884. aBound.cElements = ADsDestValue.OctetString.dwLength;
  1885. aList = SafeArrayCreate( VT_UI1, 1, &aBound );
  1886. if ( aList == NULL ) {
  1887. hr = E_OUTOFMEMORY;
  1888. BAIL_ON_FAILURE(hr);
  1889. }
  1890. hr = SafeArrayAccessData( aList, (void HUGEP * FAR *) &pArray);
  1891. BAIL_ON_FAILURE(hr);
  1892. memcpy(pArray, ADsDestValue.OctetString.lpValue, aBound.cElements);
  1893. SafeArrayUnaccessData( aList );
  1894. V_VT(retval) = VT_ARRAY | VT_UI1;
  1895. V_ARRAY(retval) = aList;
  1896. error:
  1897. if (FAILED(hr) && aList) {
  1898. SafeArrayDestroy(aList);
  1899. }
  1900. AdsClear(&ADsDestValue);
  1901. RRETURN(hr);
  1902. }
  1903. //
  1904. // Helper to get SecDesc in variant if we have a
  1905. // octetString stored underneath.
  1906. //
  1907. STDMETHODIMP
  1908. CPropertyValue::getSecurityDescriptorFromOctStr(VARIANT FAR *retval)
  1909. {
  1910. HRESULT hr = S_OK;
  1911. CCredentials dummyCredentials(NULL, NULL, 0);
  1912. hr = ConvertSecDescriptorToVariant(
  1913. NULL, // pszServerName
  1914. dummyCredentials,
  1915. _ADsValue.OctetString.lpValue,
  1916. retval,
  1917. TRUE // NTDS Type
  1918. );
  1919. RRETURN(hr);
  1920. }
  1921. //
  1922. // There has to be a better way to do this. Ideally this code
  1923. // should live in one plae and we should be able to use that
  1924. // everywhere. Currently it lives here as well as in the ldap
  1925. // provider - slight differences though.
  1926. // This comment holds true for DNWithString also - AjayR 4-30-99
  1927. //
  1928. STDMETHODIMP
  1929. CPropertyValue::getDNWithBinary(THIS_ IDispatch FAR * FAR * ppDispatch)
  1930. {
  1931. HRESULT hr = S_OK;
  1932. IADsDNWithBinary *pDNWithBinary = NULL;
  1933. SAFEARRAY *aList = NULL;
  1934. SAFEARRAYBOUND aBound;
  1935. CHAR HUGEP *pArray = NULL;
  1936. BSTR bstrTemp = NULL;
  1937. VARIANT vVar;
  1938. VariantInit(&vVar);
  1939. if (_ADsValue.dwType != ADSTYPE_DN_WITH_BINARY) {
  1940. BAIL_ON_FAILURE(hr = E_ADS_CANT_CONVERT_DATATYPE);
  1941. }
  1942. hr = CoCreateInstance(
  1943. CLSID_DNWithBinary,
  1944. NULL,
  1945. CLSCTX_INPROC_SERVER,
  1946. IID_IADsDNWithBinary,
  1947. (void **) &pDNWithBinary
  1948. );
  1949. BAIL_ON_FAILURE(hr);
  1950. if (_ADsValue.pDNWithBinary->pszDNString) {
  1951. hr = ADsAllocString(_ADsValue.pDNWithBinary->pszDNString, &bstrTemp);
  1952. BAIL_ON_FAILURE(hr);
  1953. //
  1954. // Put the value in the object - we can only set BSTR's
  1955. //
  1956. hr = pDNWithBinary->put_DNString(bstrTemp);
  1957. BAIL_ON_FAILURE(hr);
  1958. }
  1959. aBound.lLbound = 0;
  1960. aBound.cElements = _ADsValue.pDNWithBinary->dwLength;
  1961. aList = SafeArrayCreate( VT_UI1, 1, &aBound );
  1962. if ( aList == NULL )
  1963. {
  1964. hr = E_OUTOFMEMORY;
  1965. BAIL_ON_FAILURE(hr);
  1966. }
  1967. hr = SafeArrayAccessData( aList, (void HUGEP * FAR *) &pArray );
  1968. BAIL_ON_FAILURE(hr);
  1969. memcpy( pArray, _ADsValue.pDNWithBinary->lpBinaryValue, aBound.cElements );
  1970. SafeArrayUnaccessData( aList );
  1971. V_VT(&vVar) = VT_ARRAY | VT_UI1;
  1972. V_ARRAY(&vVar) = aList;
  1973. hr = pDNWithBinary->put_BinaryValue(vVar);
  1974. VariantClear(&vVar);
  1975. BAIL_ON_FAILURE(hr);
  1976. hr = pDNWithBinary->QueryInterface(
  1977. IID_IDispatch,
  1978. (void **) ppDispatch
  1979. );
  1980. BAIL_ON_FAILURE(hr);
  1981. error:
  1982. if (pDNWithBinary) {
  1983. pDNWithBinary->Release();
  1984. }
  1985. if (bstrTemp) {
  1986. ADsFreeString(bstrTemp);
  1987. }
  1988. RRETURN(hr);
  1989. }
  1990. STDMETHODIMP
  1991. CPropertyValue::putDNWithBinary(THIS_ IDispatch * pDNWithBinary)
  1992. {
  1993. HRESULT hr = S_OK;
  1994. IADsDNWithBinary * pDNBinary = NULL;
  1995. PADS_DN_WITH_BINARY pDNBin = NULL;
  1996. VARIANT vBinary;
  1997. DWORD dwSUBound = 0;
  1998. DWORD dwSLBound = 0;
  1999. DWORD dwLength = 0;
  2000. BSTR bstrDN = NULL;
  2001. LPBYTE lpByte = NULL;
  2002. CHAR HUGEP *pArray = NULL;
  2003. VariantInit(&vBinary);
  2004. ClearData();
  2005. //
  2006. // This qi ensures that this is a security descriptor
  2007. //
  2008. hr = pDNWithBinary->QueryInterface(
  2009. IID_IADsDNWithBinary,
  2010. (void **) &pDNBinary
  2011. );
  2012. BAIL_ON_FAILURE(hr);
  2013. //
  2014. // Convert to ADSVALUE and then to ldap representation.
  2015. // This way the code to and from LDAP lives in one place.
  2016. //
  2017. hr = pDNBinary->get_BinaryValue(&vBinary);
  2018. BAIL_ON_FAILURE(hr);
  2019. if ((vBinary.vt != (VT_ARRAY | VT_UI1))
  2020. && vBinary.vt != VT_EMPTY) {
  2021. BAIL_ON_FAILURE(hr = E_FAIL);
  2022. }
  2023. hr = pDNBinary->get_DNString(&bstrDN);
  2024. BAIL_ON_FAILURE(hr);
  2025. //
  2026. // Get the byte array in a usable format.
  2027. //
  2028. hr = SafeArrayGetLBound(
  2029. V_ARRAY(&vBinary),
  2030. 1,
  2031. (long FAR *) &dwSLBound
  2032. );
  2033. BAIL_ON_FAILURE(hr);
  2034. hr = SafeArrayGetUBound(
  2035. V_ARRAY(&vBinary),
  2036. 1,
  2037. (long FAR *) &dwSUBound
  2038. );
  2039. BAIL_ON_FAILURE(hr);
  2040. dwLength = dwSUBound - dwSLBound + 1;
  2041. lpByte = (LPBYTE) AllocADsMem(dwLength);
  2042. if (dwLength && !lpByte) {
  2043. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  2044. }
  2045. hr = SafeArrayAccessData(
  2046. V_ARRAY(&vBinary),
  2047. (void HUGEP * FAR *) &pArray
  2048. );
  2049. BAIL_ON_FAILURE(hr);
  2050. memcpy(lpByte, pArray, dwLength);
  2051. SafeArrayUnaccessData( V_ARRAY(&vBinary) );
  2052. pDNBin = (PADS_DN_WITH_BINARY) AllocADsMem(sizeof(ADS_DN_WITH_BINARY));
  2053. if (!pDNBin) {
  2054. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  2055. }
  2056. if (bstrDN) {
  2057. pDNBin->pszDNString = AllocADsStr(bstrDN);
  2058. if (!pDNBin->pszDNString && bstrDN) {
  2059. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  2060. }
  2061. }
  2062. _ADsValue.dwType = ADSTYPE_DN_WITH_BINARY;
  2063. _ADsValue.pDNWithBinary = pDNBin;
  2064. _ADsValue.pDNWithBinary->lpBinaryValue = lpByte;
  2065. _ADsValue.pDNWithBinary->dwLength = dwLength;
  2066. error:
  2067. if (pDNBinary) {
  2068. pDNBinary->Release();
  2069. }
  2070. if (FAILED(hr)) {
  2071. if (lpByte) {
  2072. FreeADsMem(lpByte);
  2073. }
  2074. if (pDNBin) {
  2075. if (pDNBin->pszDNString) {
  2076. FreeADsStr(pDNBin->pszDNString);
  2077. }
  2078. FreeADsMem(pDNBin);
  2079. }
  2080. }
  2081. if (bstrDN) {
  2082. ADsFreeString(bstrDN);
  2083. }
  2084. VariantClear(&vBinary);
  2085. RRETURN(hr);
  2086. }
  2087. STDMETHODIMP
  2088. CPropertyValue::putDNWithString(THIS_ IDispatch * pDNWithString)
  2089. {
  2090. HRESULT hr = S_OK;
  2091. IADsDNWithString *pDNString = NULL;
  2092. PADS_DN_WITH_STRING pDNStr = NULL;
  2093. BSTR bstrStringValue = NULL;
  2094. BSTR bstrDN = NULL;
  2095. ClearData();
  2096. hr = pDNWithString->QueryInterface(
  2097. IID_IADsDNWithString,
  2098. (void **)&pDNString
  2099. );
  2100. BAIL_ON_FAILURE(hr);
  2101. hr = pDNString->get_StringValue(&bstrStringValue);
  2102. BAIL_ON_FAILURE(hr);
  2103. hr = pDNString->get_DNString(&bstrDN);
  2104. BAIL_ON_FAILURE(hr);
  2105. _ADsValue.dwType = ADSTYPE_DN_WITH_STRING;
  2106. pDNStr = (PADS_DN_WITH_STRING) AllocADsMem(sizeof(ADS_DN_WITH_STRING));
  2107. if (!pDNStr) {
  2108. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  2109. }
  2110. //
  2111. // Put String value in the DNString struct.
  2112. //
  2113. pDNStr->pszStringValue = AllocADsStr(bstrStringValue);
  2114. if (bstrStringValue && !pDNStr->pszStringValue) {
  2115. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  2116. }
  2117. pDNStr->pszDNString = AllocADsStr(bstrDN);
  2118. if (bstrDN && !pDNStr->pszDNString) {
  2119. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  2120. }
  2121. _ADsValue.dwType = ADSTYPE_DN_WITH_STRING;
  2122. _ADsValue.pDNWithString = pDNStr;
  2123. error:
  2124. if (pDNString) {
  2125. pDNString->Release();
  2126. }
  2127. if (bstrStringValue) {
  2128. ADsFreeString(bstrStringValue);
  2129. }
  2130. if (bstrDN) {
  2131. ADsFreeString(bstrDN);
  2132. }
  2133. if (pDNStr && FAILED(hr)) {
  2134. if (pDNStr->pszDNString) {
  2135. FreeADsStr(pDNStr->pszDNString);
  2136. }
  2137. if (pDNStr->pszStringValue) {
  2138. FreeADsMem(pDNStr->pszStringValue);
  2139. }
  2140. FreeADsMem(pDNStr);
  2141. }
  2142. RRETURN(hr);
  2143. }
  2144. STDMETHODIMP
  2145. CPropertyValue::getDNWithString(THIS_ IDispatch FAR * FAR * ppDispatch)
  2146. {
  2147. HRESULT hr = S_OK;
  2148. ADSVALUE AdsValue;
  2149. IADsDNWithString *pDNWithString = NULL;
  2150. IDispatch *pDispatch = NULL;
  2151. BSTR bstrStrVal = NULL;
  2152. BSTR bstrDNVal = NULL;
  2153. if (_ADsValue.dwType != ADSTYPE_DN_WITH_STRING) {
  2154. BAIL_ON_FAILURE(hr = E_ADS_CANT_CONVERT_DATATYPE);
  2155. }
  2156. hr = CoCreateInstance(
  2157. CLSID_DNWithString,
  2158. NULL,
  2159. CLSCTX_INPROC_SERVER,
  2160. IID_IADsDNWithString,
  2161. (void **) &pDNWithString
  2162. );
  2163. BAIL_ON_FAILURE(hr);
  2164. if (_ADsValue.pDNWithString->pszDNString) {
  2165. hr = ADsAllocString(_ADsValue.pDNWithString->pszDNString, &bstrDNVal);
  2166. BAIL_ON_FAILURE(hr);
  2167. hr = pDNWithString->put_DNString(bstrDNVal);
  2168. BAIL_ON_FAILURE(hr);
  2169. }
  2170. if (_ADsValue.pDNWithString->pszStringValue) {
  2171. hr = ADsAllocString(
  2172. _ADsValue.pDNWithString->pszStringValue,
  2173. &bstrStrVal
  2174. );
  2175. BAIL_ON_FAILURE(hr);
  2176. hr = pDNWithString->put_StringValue(bstrStrVal);
  2177. BAIL_ON_FAILURE(hr);
  2178. }
  2179. hr = pDNWithString->QueryInterface(
  2180. IID_IDispatch,
  2181. (void **) ppDispatch
  2182. );
  2183. BAIL_ON_FAILURE(hr);
  2184. error:
  2185. if (pDNWithString) {
  2186. pDNWithString->Release();
  2187. }
  2188. if (bstrDNVal) {
  2189. ADsFreeString(bstrDNVal);
  2190. }
  2191. if (bstrStrVal) {
  2192. ADsFreeString(bstrStrVal);
  2193. }
  2194. RRETURN(hr);
  2195. }
  2196. STDMETHODIMP
  2197. CPropertyValue::getProvSpecific(THIS_ VARIANT FAR *retval )
  2198. {
  2199. HRESULT hr = S_OK;
  2200. SAFEARRAY *aList = NULL;
  2201. SAFEARRAYBOUND aBound;
  2202. CHAR HUGEP *pArray = NULL;
  2203. if (_ADsValue.dwType != ADSTYPE_PROV_SPECIFIC) {
  2204. RRETURN(E_ADS_CANT_CONVERT_DATATYPE);
  2205. }
  2206. aBound.lLbound = 0;
  2207. aBound.cElements = _ADsValue.ProviderSpecific.dwLength;
  2208. aList = SafeArrayCreate( VT_UI1, 1, &aBound );
  2209. if ( aList == NULL )
  2210. {
  2211. hr = E_OUTOFMEMORY;
  2212. BAIL_ON_FAILURE(hr);
  2213. }
  2214. hr = SafeArrayAccessData( aList, (void HUGEP * FAR *) &pArray );
  2215. BAIL_ON_FAILURE(hr);
  2216. memcpy( pArray,
  2217. _ADsValue.ProviderSpecific.lpValue,
  2218. aBound.cElements );
  2219. SafeArrayUnaccessData( aList );
  2220. V_VT(retval) = VT_ARRAY | VT_UI1;
  2221. V_ARRAY(retval) = aList;
  2222. RRETURN(hr);
  2223. error:
  2224. if ( aList ) {
  2225. SafeArrayDestroy( aList );
  2226. }
  2227. RRETURN_EXP_IF_ERR(hr);
  2228. }
  2229. STDMETHODIMP
  2230. CPropertyValue::putProvSpecific(THIS_ VARIANT VarProvSpecific)
  2231. {
  2232. LONG dwSLBound = 0;
  2233. LONG dwSUBound = 0;
  2234. CHAR HUGEP *pArray = NULL;
  2235. HRESULT hr = S_OK;
  2236. ClearData();
  2237. _ADsValue.dwType = ADSTYPE_PROV_SPECIFIC;
  2238. if( VarProvSpecific.vt != (VT_ARRAY | VT_UI1)) {
  2239. RRETURN(hr = E_ADS_CANT_CONVERT_DATATYPE);
  2240. }
  2241. hr = SafeArrayGetLBound(V_ARRAY(&VarProvSpecific),
  2242. 1,
  2243. (long FAR *) &dwSLBound );
  2244. BAIL_ON_FAILURE(hr);
  2245. hr = SafeArrayGetUBound(V_ARRAY(&VarProvSpecific),
  2246. 1,
  2247. (long FAR *) &dwSUBound );
  2248. BAIL_ON_FAILURE(hr);
  2249. _ADsValue.ProviderSpecific.lpValue = (LPBYTE)AllocADsMem(dwSUBound - dwSLBound + 1);
  2250. if ( _ADsValue.ProviderSpecific.lpValue == NULL) {
  2251. hr = E_OUTOFMEMORY;
  2252. BAIL_ON_FAILURE(hr);
  2253. }
  2254. _ADsValue.ProviderSpecific.dwLength = dwSUBound - dwSLBound + 1;
  2255. hr = SafeArrayAccessData( V_ARRAY(&VarProvSpecific),
  2256. (void HUGEP * FAR *) &pArray );
  2257. BAIL_ON_FAILURE(hr);
  2258. memcpy( _ADsValue.ProviderSpecific.lpValue,
  2259. pArray,
  2260. dwSUBound-dwSLBound+1);
  2261. SafeArrayUnaccessData( V_ARRAY(&VarProvSpecific) );
  2262. error:
  2263. RRETURN_EXP_IF_ERR(hr);
  2264. }
  2265. void
  2266. CPropertyValue::ClearData()
  2267. {
  2268. //
  2269. // For all the types - this works even if the adsvalue is null
  2270. // as adsvalue.dwType = 0 ---> invalid_type does nothing !!!
  2271. //
  2272. AdsClear(&_ADsValue);
  2273. if (_pDispatch) {
  2274. switch (_dwDataType) {
  2275. case VAL_IDISPATCH_SECDESC_ONLY:
  2276. case VAL_IDISPATCH_SECDESC_ALL:
  2277. _pDispatch->Release();
  2278. _pDispatch = NULL;
  2279. _dwDataType = VAL_IDISPATCH_UNKNOWN;
  2280. break;
  2281. default:
  2282. ADsAssert(!"Internal incosistency secdesc ptr but bad type.");
  2283. _pDispatch = NULL;
  2284. _dwDataType = VAL_IDISPATCH_UNKNOWN;
  2285. break;
  2286. } // end switch
  2287. }
  2288. }
  2289. //+------------------------------------------------------------------------
  2290. //
  2291. // Function: CPropertyValue::GetObjectProperty
  2292. //
  2293. // Synopsis: Gets the values stored in this PropertyValue object. The
  2294. // value returned is determined by the value requested in lnContorlCode.
  2295. // For now though we will only support ADSTYPE_UNKNOWN in which case we
  2296. // get the info from the object itself. Alternatively the type should match
  2297. // that which is in the object.
  2298. //
  2299. //
  2300. // Arguments: lnControlCode - ADSTYPE_INVALID implies whatever we have
  2301. // - anything else implies we return the type.
  2302. // pvProp - the output value goes into this.
  2303. //
  2304. //
  2305. //-------------------------------------------------------------------------
  2306. STDMETHODIMP
  2307. CPropertyValue::GetObjectProperty(
  2308. THIS_ long *lnControlCode,
  2309. VARIANT *pvProp
  2310. )
  2311. {
  2312. HRESULT hr = S_OK;
  2313. ADSTYPE dwTypeAsked = ADSTYPE_INVALID;
  2314. ADsAssert(pvProp);
  2315. ADsAssert(lnControlCode);
  2316. if (*lnControlCode == ADSTYPE_UNKNOWN) {
  2317. dwTypeAsked = _ADsValue.dwType;
  2318. } else {
  2319. dwTypeAsked = (ADSTYPE)*lnControlCode;
  2320. }
  2321. *lnControlCode = dwTypeAsked;
  2322. switch (dwTypeAsked) {
  2323. case ADSTYPE_INVALID:
  2324. BAIL_ON_FAILURE(hr = E_ADS_CANT_CONVERT_DATATYPE);
  2325. break;
  2326. case ADSTYPE_DN_STRING :
  2327. pvProp->vt = VT_BSTR;
  2328. hr = get_DNString(&(pvProp->bstrVal));
  2329. break;
  2330. case ADSTYPE_CASE_EXACT_STRING :
  2331. pvProp->vt = VT_BSTR;
  2332. hr = get_CaseExactString(&(pvProp->bstrVal));
  2333. break;
  2334. case ADSTYPE_CASE_IGNORE_STRING :
  2335. pvProp->vt = VT_BSTR;
  2336. hr = get_CaseIgnoreString(&(pvProp->bstrVal));
  2337. break;
  2338. case ADSTYPE_PRINTABLE_STRING :
  2339. pvProp->vt = VT_BSTR;
  2340. hr = get_PrintableString(&(pvProp->bstrVal));
  2341. break;
  2342. case ADSTYPE_NUMERIC_STRING :
  2343. pvProp->vt = VT_BSTR;
  2344. hr = get_NumericString(&(pvProp->bstrVal));
  2345. break;
  2346. case ADSTYPE_BOOLEAN :
  2347. {
  2348. LONG lnVal = 0;
  2349. pvProp->vt = VT_BOOL;
  2350. hr = get_Boolean(&(lnVal));
  2351. if (SUCCEEDED(hr)) {
  2352. pvProp->boolVal = lnVal ? VARIANT_TRUE : VARIANT_FALSE;
  2353. }
  2354. }
  2355. break;
  2356. case ADSTYPE_INTEGER :
  2357. pvProp->vt = VT_I4;
  2358. hr = get_Integer(&(pvProp->lVal));
  2359. break;
  2360. case ADSTYPE_OCTET_STRING :
  2361. hr = get_OctetString(pvProp);
  2362. if (hr == E_ADS_CANT_CONVERT_DATATYPE) {
  2363. //
  2364. // Try and see if it is a SD and convert
  2365. //
  2366. if (_ADsValue.dwType == ADSTYPE_NT_SECURITY_DESCRIPTOR) {
  2367. hr = getOctetStringFromSecDesc(pvProp);
  2368. }
  2369. }
  2370. break;
  2371. case ADSTYPE_PROV_SPECIFIC :
  2372. hr = getProvSpecific(pvProp);
  2373. break;
  2374. case ADSTYPE_UTC_TIME :
  2375. pvProp->vt = VT_DATE;
  2376. hr = get_UTCTime(&(pvProp->date));
  2377. break;
  2378. case ADSTYPE_LARGE_INTEGER :
  2379. pvProp->vt = VT_DISPATCH;
  2380. hr = get_LargeInteger(&(pvProp->pdispVal));
  2381. break;
  2382. case ADSTYPE_OBJECT_CLASS :
  2383. pvProp->vt = VT_DISPATCH;
  2384. hr = E_ADS_CANT_CONVERT_DATATYPE;
  2385. break;
  2386. case ADSTYPE_CASEIGNORE_LIST :
  2387. pvProp->vt = VT_DISPATCH;
  2388. hr = get_CaseIgnoreList(&(pvProp->pdispVal));
  2389. break;
  2390. case ADSTYPE_OCTET_LIST :
  2391. pvProp->vt = VT_DISPATCH;
  2392. hr = get_OctetList(&(pvProp->pdispVal));
  2393. break;
  2394. case ADSTYPE_PATH :
  2395. pvProp->vt = VT_DISPATCH;
  2396. hr = get_Path(&(pvProp->pdispVal));
  2397. break;
  2398. case ADSTYPE_POSTALADDRESS :
  2399. pvProp->vt = VT_DISPATCH;
  2400. hr = get_PostalAddress(&(pvProp->pdispVal));
  2401. break;
  2402. case ADSTYPE_TIMESTAMP :
  2403. pvProp->vt = VT_DISPATCH;
  2404. hr = get_Timestamp(&(pvProp->pdispVal));
  2405. break;
  2406. case ADSTYPE_BACKLINK :
  2407. pvProp->vt = VT_DISPATCH;
  2408. hr = get_BackLink(&(pvProp->pdispVal));
  2409. break;
  2410. case ADSTYPE_TYPEDNAME :
  2411. pvProp->vt = VT_DISPATCH;
  2412. hr = get_TypedName(&(pvProp->pdispVal));
  2413. break;
  2414. case ADSTYPE_HOLD :
  2415. pvProp->vt = VT_DISPATCH;
  2416. hr = get_Hold(&(pvProp->pdispVal));
  2417. break;
  2418. case ADSTYPE_NETADDRESS :
  2419. pvProp->vt = VT_DISPATCH;
  2420. hr = get_NetAddress(&(pvProp->pdispVal));
  2421. break;
  2422. case ADSTYPE_REPLICAPOINTER :
  2423. pvProp->vt = VT_DISPATCH;
  2424. hr = get_ReplicaPointer(&(pvProp->pdispVal));
  2425. break;
  2426. case ADSTYPE_FAXNUMBER :
  2427. pvProp->vt = VT_DISPATCH;
  2428. hr = get_FaxNumber(&(pvProp->pdispVal));
  2429. break;
  2430. case ADSTYPE_EMAIL :
  2431. pvProp->vt = VT_DISPATCH;
  2432. hr = get_Email(&(pvProp->pdispVal));
  2433. break;
  2434. case ADSTYPE_NT_SECURITY_DESCRIPTOR :
  2435. pvProp->vt = VT_DISPATCH;
  2436. hr = get_SecurityDescriptor(&(pvProp->pdispVal));
  2437. if (hr == E_ADS_CANT_CONVERT_DATATYPE) {
  2438. //
  2439. // Try and see if it is an OctetString needed as SecDesc
  2440. //
  2441. if (_ADsValue.dwType == ADSTYPE_OCTET_STRING) {
  2442. hr = getSecurityDescriptorFromOctStr(pvProp);
  2443. }
  2444. }
  2445. break;
  2446. case ADSTYPE_DN_WITH_BINARY:
  2447. pvProp->vt = VT_DISPATCH;
  2448. hr = getDNWithBinary(&(pvProp->pdispVal));
  2449. break;
  2450. case ADSTYPE_DN_WITH_STRING:
  2451. pvProp->vt = VT_DISPATCH;
  2452. hr = getDNWithString(&(pvProp->pdispVal));
  2453. break;
  2454. case ADSTYPE_UNKNOWN :
  2455. hr = E_ADS_CANT_CONVERT_DATATYPE;
  2456. break;
  2457. default:
  2458. // We should never be here
  2459. hr = E_ADS_BAD_PARAMETER;
  2460. break;
  2461. }
  2462. error:
  2463. RRETURN(hr);
  2464. }
  2465. STDMETHODIMP
  2466. CPropertyValue::PutObjectProperty(
  2467. THIS_ long lnControlCode,
  2468. VARIANT varObj
  2469. )
  2470. {
  2471. HRESULT hr = S_OK;
  2472. VARIANT *pvVar = &varObj;
  2473. if (lnControlCode == ADSTYPE_UNKNOWN
  2474. || lnControlCode == ADSTYPE_INVALID) {
  2475. BAIL_ON_FAILURE(hr=E_ADS_BAD_PARAMETER);
  2476. }
  2477. if (V_VT(pvVar) == (VT_BYREF|VT_VARIANT)) {
  2478. //
  2479. // The value is being passed in byref so we need to
  2480. // deref it for vbs stuff to work
  2481. //
  2482. pvVar = V_VARIANTREF(&varObj);
  2483. }
  2484. switch (lnControlCode) {
  2485. case ADSTYPE_INVALID:
  2486. BAIL_ON_FAILURE(hr = E_ADS_BAD_PARAMETER);
  2487. break;
  2488. case ADSTYPE_DN_STRING :
  2489. if (pvVar->vt != VT_BSTR) {
  2490. BAIL_ON_FAILURE(hr = E_ADS_CANT_CONVERT_DATATYPE);
  2491. }
  2492. hr = put_DNString(pvVar->bstrVal);
  2493. break;
  2494. case ADSTYPE_CASE_EXACT_STRING :
  2495. if (pvVar->vt != VT_BSTR) {
  2496. BAIL_ON_FAILURE(hr = E_ADS_CANT_CONVERT_DATATYPE);
  2497. }
  2498. hr = put_CaseExactString(pvVar->bstrVal);
  2499. break;
  2500. case ADSTYPE_CASE_IGNORE_STRING :
  2501. if (pvVar->vt != VT_BSTR) {
  2502. BAIL_ON_FAILURE(hr = E_ADS_CANT_CONVERT_DATATYPE);
  2503. }
  2504. hr = put_CaseIgnoreString(pvVar->bstrVal);
  2505. break;
  2506. case ADSTYPE_PRINTABLE_STRING :
  2507. if (pvVar->vt != VT_BSTR) {
  2508. BAIL_ON_FAILURE(hr = E_ADS_CANT_CONVERT_DATATYPE);
  2509. }
  2510. hr = put_PrintableString(pvVar->bstrVal);
  2511. break;
  2512. case ADSTYPE_NUMERIC_STRING :
  2513. if (pvVar->vt != VT_BSTR) {
  2514. BAIL_ON_FAILURE(hr = E_ADS_CANT_CONVERT_DATATYPE);
  2515. }
  2516. hr = put_NumericString(pvVar->bstrVal);
  2517. break;
  2518. case ADSTYPE_BOOLEAN :
  2519. if (pvVar->vt != VT_BOOL) {
  2520. BAIL_ON_FAILURE(hr = E_ADS_CANT_CONVERT_DATATYPE);
  2521. }
  2522. hr = put_Boolean((pvVar->boolVal == VARIANT_TRUE) ? TRUE : FALSE);
  2523. break;
  2524. case ADSTYPE_INTEGER :
  2525. if (pvVar->vt != VT_I4) {
  2526. BAIL_ON_FAILURE(hr = E_ADS_CANT_CONVERT_DATATYPE);
  2527. }
  2528. hr = put_Integer(pvVar->lVal);
  2529. break;
  2530. case ADSTYPE_OCTET_STRING :
  2531. hr = put_OctetString(*pvVar);
  2532. break;
  2533. case ADSTYPE_PROV_SPECIFIC :
  2534. hr = putProvSpecific(varObj);
  2535. break;
  2536. case ADSTYPE_UTC_TIME :
  2537. if (pvVar->vt != VT_DATE) {
  2538. BAIL_ON_FAILURE(hr = E_ADS_CANT_CONVERT_DATATYPE);
  2539. }
  2540. hr = put_UTCTime(pvVar->date);
  2541. break;
  2542. case ADSTYPE_LARGE_INTEGER :
  2543. if (pvVar->vt != VT_DISPATCH) {
  2544. BAIL_ON_FAILURE(hr = E_ADS_CANT_CONVERT_DATATYPE);
  2545. }
  2546. hr = put_LargeInteger(pvVar->pdispVal);
  2547. break;
  2548. case ADSTYPE_OBJECT_CLASS :
  2549. hr = E_ADS_CANT_CONVERT_DATATYPE;
  2550. break;
  2551. case ADSTYPE_CASEIGNORE_LIST :
  2552. if (pvVar->vt != VT_DISPATCH) {
  2553. BAIL_ON_FAILURE(hr = E_ADS_CANT_CONVERT_DATATYPE);
  2554. }
  2555. hr = put_CaseIgnoreList(pvVar->pdispVal);
  2556. break;
  2557. case ADSTYPE_OCTET_LIST :
  2558. if (pvVar->vt != VT_DISPATCH) {
  2559. BAIL_ON_FAILURE(hr = E_ADS_CANT_CONVERT_DATATYPE);
  2560. }
  2561. hr = put_OctetList(pvVar->pdispVal);
  2562. break;
  2563. case ADSTYPE_PATH :
  2564. if (pvVar->vt != VT_DISPATCH) {
  2565. BAIL_ON_FAILURE(hr = E_ADS_CANT_CONVERT_DATATYPE);
  2566. }
  2567. hr = put_Path(pvVar->pdispVal);
  2568. break;
  2569. case ADSTYPE_POSTALADDRESS :
  2570. if (pvVar->vt != VT_DISPATCH) {
  2571. BAIL_ON_FAILURE(hr = E_ADS_CANT_CONVERT_DATATYPE);
  2572. }
  2573. hr = put_PostalAddress(pvVar->pdispVal);
  2574. break;
  2575. case ADSTYPE_TIMESTAMP :
  2576. if (pvVar->vt != VT_DISPATCH){
  2577. BAIL_ON_FAILURE(hr = E_ADS_CANT_CONVERT_DATATYPE);
  2578. }
  2579. hr = put_Timestamp(pvVar->pdispVal);
  2580. break;
  2581. case ADSTYPE_BACKLINK :
  2582. if (pvVar->vt != VT_DISPATCH) {
  2583. BAIL_ON_FAILURE(hr = E_ADS_CANT_CONVERT_DATATYPE);
  2584. }
  2585. hr = put_BackLink(pvVar->pdispVal);
  2586. break;
  2587. case ADSTYPE_TYPEDNAME :
  2588. if (pvVar->vt != VT_DISPATCH) {
  2589. BAIL_ON_FAILURE(hr = E_ADS_CANT_CONVERT_DATATYPE);
  2590. }
  2591. hr = put_TypedName(pvVar->pdispVal);
  2592. break;
  2593. case ADSTYPE_HOLD :
  2594. if (pvVar->vt != VT_DISPATCH) {
  2595. BAIL_ON_FAILURE(hr = E_ADS_CANT_CONVERT_DATATYPE);
  2596. }
  2597. hr = put_Hold(pvVar->pdispVal);
  2598. break;
  2599. case ADSTYPE_NETADDRESS :
  2600. if (pvVar->vt != VT_DISPATCH) {
  2601. BAIL_ON_FAILURE(hr = E_ADS_CANT_CONVERT_DATATYPE);
  2602. }
  2603. hr = put_NetAddress(pvVar->pdispVal);
  2604. break;
  2605. case ADSTYPE_REPLICAPOINTER :
  2606. if (pvVar->vt != VT_DISPATCH) {
  2607. BAIL_ON_FAILURE(hr = E_ADS_CANT_CONVERT_DATATYPE);
  2608. }
  2609. hr = put_ReplicaPointer(pvVar->pdispVal);
  2610. break;
  2611. case ADSTYPE_FAXNUMBER :
  2612. if (pvVar->vt != VT_DISPATCH) {
  2613. BAIL_ON_FAILURE(hr = E_ADS_CANT_CONVERT_DATATYPE);
  2614. }
  2615. hr = put_FaxNumber(pvVar->pdispVal);
  2616. break;
  2617. case ADSTYPE_EMAIL :
  2618. if (pvVar->vt != VT_DISPATCH) {
  2619. BAIL_ON_FAILURE(hr = E_ADS_CANT_CONVERT_DATATYPE);
  2620. }
  2621. hr = put_Email(pvVar->pdispVal);
  2622. break;
  2623. case ADSTYPE_NT_SECURITY_DESCRIPTOR :
  2624. if (pvVar->vt != VT_DISPATCH) {
  2625. BAIL_ON_FAILURE(hr = E_ADS_CANT_CONVERT_DATATYPE);
  2626. }
  2627. hr = put_SecurityDescriptor(pvVar->pdispVal);
  2628. break;
  2629. case ADSTYPE_DN_WITH_BINARY :
  2630. if (pvVar->vt != VT_DISPATCH) {
  2631. BAIL_ON_FAILURE(hr = E_ADS_CANT_CONVERT_DATATYPE);
  2632. }
  2633. hr = putDNWithBinary(pvVar->pdispVal);
  2634. break;
  2635. case ADSTYPE_DN_WITH_STRING :
  2636. if (pvVar->vt != VT_DISPATCH) {
  2637. BAIL_ON_FAILURE(hr = E_ADS_CANT_CONVERT_DATATYPE);
  2638. }
  2639. hr = putDNWithString(pvVar->pdispVal);
  2640. break;
  2641. case ADSTYPE_UNKNOWN :
  2642. hr = E_ADS_CANT_CONVERT_DATATYPE;
  2643. break;
  2644. default:
  2645. hr = E_ADS_BAD_PARAMETER;
  2646. break;
  2647. }
  2648. error:
  2649. RRETURN (hr);
  2650. }