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.

3561 lines
95 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 2000.
  5. //
  6. // File: cpropmgr.cxx
  7. //
  8. // Contents: Property manager - object that implements/helps implement
  9. // IUMIPropList functions.
  10. // The property manager needs to be initialized in one of 2 modes
  11. // 1) PropertyCache mode in which case it uses the objects existing
  12. // to provide IUMIPropList support and
  13. // 2) Interface property mode in which case ???
  14. //
  15. // Functions: TBD.
  16. //
  17. // History: 02-07-00 AjayR Created.
  18. //
  19. //----------------------------------------------------------------------------
  20. #include "ldap.hxx"
  21. //
  22. // These are global utility fucntions. Might be worth moving to a
  23. // better location subsequently.
  24. //
  25. //+---------------------------------------------------------------------------
  26. // Function: FreeOneUmiProperty -- Global scope.
  27. //
  28. // Synopsis: Walk through and free all information being pointed to
  29. // including the values.
  30. //
  31. // Arguments: self explanatory
  32. //
  33. //
  34. // Returns: HRESULT - S_OK or any failure error code.
  35. //
  36. // Modifies: N/A.
  37. //
  38. //----------------------------------------------------------------------------
  39. HRESULT FreeOneUmiProperty(UMI_PROPERTY umiProperty)
  40. {
  41. //
  42. // Free the name now if we can
  43. //
  44. if (umiProperty.pszPropertyName) {
  45. FreeADsStr(umiProperty.pszPropertyName);
  46. umiProperty.pszPropertyName = NULL;
  47. }
  48. if (!umiProperty.pUmiValue) {
  49. //
  50. // We are done if count is 0
  51. //
  52. if (umiProperty.uCount == 0) {
  53. RRETURN(S_OK);
  54. }
  55. else {
  56. RRETURN(E_ADS_BAD_PARAMETER);
  57. }
  58. }
  59. //
  60. // Must have valid umiValues at this point.
  61. //
  62. for (ULONG ulCtr = 0; ulCtr < umiProperty.uCount; ulCtr++) {
  63. switch (umiProperty.uType) {
  64. case UMI_TYPE_LPWSTR:
  65. //
  66. // Go through and free each of the values.
  67. //
  68. if (umiProperty.pUmiValue->pszStrValue[ulCtr]) {
  69. FreeADsStr(umiProperty.pUmiValue->pszStrValue[ulCtr]);
  70. umiProperty.pUmiValue->pszStrValue[ulCtr] = NULL;
  71. }
  72. break;
  73. case UMI_TYPE_BOOL:
  74. case UMI_TYPE_I4:
  75. case UMI_TYPE_FILETIME:
  76. case UMI_TYPE_SYSTEMTIME:
  77. case UMI_TYPE_I8:
  78. //
  79. // In all these cases nothing much to free except the value array
  80. //
  81. break;
  82. case UMI_TYPE_OCTETSTRING:
  83. //
  84. // Go through and free each of the values.
  85. //
  86. if (umiProperty.pUmiValue->octetStr[ulCtr].lpValue) {
  87. FreeADsMem(umiProperty.pUmiValue->octetStr[ulCtr].lpValue);
  88. umiProperty.pUmiValue->octetStr[ulCtr].lpValue = NULL;
  89. }
  90. break;
  91. case UMI_TYPE_IUNKNOWN:
  92. //
  93. // Need to release the ptr and Free the riid.
  94. //
  95. UMI_COM_OBJECT ComObject;
  96. if (umiProperty.pUmiValue->comObject) {
  97. ComObject = umiProperty.pUmiValue->comObject[ulCtr];
  98. if (ComObject.pInterface) {
  99. ((IUnknown*)ComObject.pInterface)->Release();
  100. ComObject.pInterface = NULL;
  101. }
  102. if (ComObject.priid) {
  103. FreeADsMem((void *)ComObject.priid);
  104. ComObject.priid = NULL;
  105. }
  106. }
  107. break;
  108. default:
  109. //
  110. // UmiType that we do not know anything about ??
  111. //
  112. ADsAssert(!"Unknown umitype in free memory");
  113. RRETURN(E_ADS_BAD_PARAMETER);
  114. break;
  115. } // end of case
  116. } // end of for
  117. //
  118. // Free the array of values now
  119. //
  120. if (umiProperty.pUmiValue) {
  121. FreeADsMem( (void *)umiProperty.pUmiValue);
  122. umiProperty.pUmiValue = NULL;
  123. }
  124. RRETURN(S_OK);
  125. }
  126. //+---------------------------------------------------------------------------
  127. // Function: FreeUmiPropertyValues -- Global scope.
  128. //
  129. // Synopsis: Walk through and free all information being pointed to
  130. // including the values.
  131. //
  132. // Arguments: self explanatory
  133. //
  134. //
  135. // Returns: HRESULT - S_OK or any failure error code.
  136. //
  137. // Modifies: N/A.
  138. //
  139. //----------------------------------------------------------------------------
  140. HRESULT FreeUmiPropertyValues(UMI_PROPERTY_VALUES *pUmiProps)
  141. {
  142. HRESULT hr = S_OK;
  143. if (pUmiProps) {
  144. __try {
  145. //
  146. // Go through and free each property in the list
  147. //
  148. for (ULONG ulCtr = 0; ulCtr < pUmiProps->uCount; ulCtr++) {
  149. hr = FreeOneUmiProperty(pUmiProps->pPropArray[ulCtr]);
  150. }
  151. //
  152. // Free the inner array.
  153. //
  154. if (pUmiProps->pPropArray) {
  155. FreeADsMem(pUmiProps->pPropArray);
  156. }
  157. //
  158. // Free the array itself.
  159. //
  160. FreeADsMem( (LPVOID) pUmiProps);
  161. }
  162. __except (EXCEPTION_EXECUTE_HANDLER) {
  163. hr = E_INVALIDARG;
  164. }
  165. }
  166. else {
  167. hr = E_INVALIDARG;
  168. }
  169. RRETURN(hr);
  170. }
  171. //+---------------------------------------------------------------------------
  172. // Function: ConvertUmiPropCodeToLdapCode -- Global scope.
  173. //
  174. // Synopsis: Convert the property code appropriately.
  175. //
  176. // Arguments: umiFlags - the umiPropCode,
  177. // dwLdapOpCode& - byRef return value.
  178. //
  179. // Returns: HRESULT - S_OK or E_ADS_BAD_PARAMETER
  180. //
  181. // Modifies: N/A.
  182. //
  183. //----------------------------------------------------------------------------
  184. HRESULT ConvertUmiPropCodeToLdapCode(ULONG umiFlags, DWORD& dwLdapOpCode)
  185. {
  186. HRESULT hr = S_OK;
  187. switch (umiFlags) {
  188. case UMI_OPERATION_APPEND:
  189. dwLdapOpCode = PROPERTY_ADD;
  190. break;
  191. case UMI_OPERATION_UPDATE:
  192. dwLdapOpCode = PROPERTY_UPDATE;
  193. break;
  194. case UMI_OPERATION_EMPTY:
  195. dwLdapOpCode = PROPERTY_DELETE;
  196. break;
  197. case UMI_OPERATION_DELETE_ALL_MATCHES:
  198. dwLdapOpCode = PROPERTY_DELETE_VALUE;
  199. break;
  200. default:
  201. //
  202. // we do not handle these values.
  203. // UMI_OPERATION_INSERT_AT
  204. // UMI_OPERATION_REMOVE_AT
  205. // UMI_OPERATION_DELETE_AT
  206. // UMI_OPERATION_DELETE_FIRST_MATCH
  207. // UMI_OPERATION_DELETE_ALL_MATCHES
  208. //
  209. hr = UMI_E_UNSUPPORTED_OPERATION;
  210. break;
  211. }
  212. RRETURN(hr);
  213. }
  214. //+---------------------------------------------------------------------------
  215. // Function: ConvertLdapCodeToUmiPropCode -- Global scope.
  216. //
  217. // Synopsis: Convert the property code appropriately.
  218. //
  219. // Arguments: dwLdapOpCode& - property cache operation code.
  220. // umiFlags& - byRef return value.
  221. //
  222. // Returns: HRESULT - S_OK or E_ADS_BAD_PARAMETER
  223. //
  224. // Modifies: N/A.
  225. //
  226. //----------------------------------------------------------------------------
  227. HRESULT
  228. ConvertLdapCodeToUmiPropCode(
  229. DWORD dwLdapCode,
  230. ULONG &uUmiFlags
  231. )
  232. {
  233. HRESULT hr = S_OK;
  234. switch (dwLdapCode) {
  235. case PROPERTY_ADD:
  236. uUmiFlags = UMI_OPERATION_APPEND;
  237. break;
  238. case PROPERTY_UPDATE:
  239. uUmiFlags = UMI_OPERATION_UPDATE;
  240. break;
  241. case PROPERTY_DELETE:
  242. uUmiFlags = UMI_OPERATION_EMPTY;
  243. break;
  244. case PROPERTY_DELETE_VALUE:
  245. uUmiFlags = UMI_OPERATION_DELETE_ALL_MATCHES;
  246. break;
  247. case 0:
  248. //
  249. // special case values that are just in the cache.
  250. //
  251. uUmiFlags = 0;
  252. break;
  253. default:
  254. hr = E_ADS_BAD_PARAMETER;
  255. break;
  256. }
  257. RRETURN(hr);
  258. }
  259. //****************************************************************************
  260. //
  261. //Internal helpers - restricted scope
  262. //
  263. //****************************************************************************
  264. //+---------------------------------------------------------------------------
  265. // Function: ConvertVariantLongToUmiProp.
  266. //
  267. // Synopsis: Convert the variant to a corresponding UmiProp.
  268. //
  269. // Arguments: vVariant - variant containg long val to convert.
  270. // ppProp - Output UmiPropertyValues.
  271. //
  272. // Returns: HRESULT - S_OK or any failure ecode.
  273. //
  274. // Modifies: *pProp to point to valid UMI_PROPERTY_VALUES.
  275. //
  276. //----------------------------------------------------------------------------
  277. HRESULT
  278. ConvertVariantLongToUmiProp(
  279. VARIANT vVariant,
  280. UMI_PROPERTY_VALUES **ppProp
  281. )
  282. {
  283. HRESULT hr = S_OK;
  284. LONG *pLArray = NULL;
  285. *ppProp = (PUMI_PROPERTY_VALUES) AllocADsMem(sizeof(UMI_PROPERTY_VALUES));
  286. if (!*ppProp) {
  287. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  288. }
  289. (*ppProp)->pPropArray =
  290. (UMI_PROPERTY *) AllocADsMem(sizeof(UMI_PROPERTY));
  291. if (!((*ppProp)->pPropArray)) {
  292. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  293. }
  294. (*ppProp)->uCount = 1;
  295. (*ppProp)->pPropArray[0].uType = UMI_TYPE_I4;
  296. (*ppProp)->pPropArray[0].uCount = 1;
  297. pLArray = (LONG *) AllocADsMem(sizeof(LONG) * 1);
  298. if (!pLArray) {
  299. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  300. }
  301. pLArray[0] = vVariant.lVal;
  302. (*ppProp)->pPropArray[0].pUmiValue = (UMI_VALUE *)(void *)pLArray;
  303. error :
  304. if (FAILED(hr)) {
  305. if (pLArray) {
  306. FreeADsMem( (void*) pLArray);
  307. }
  308. FreeUmiPropertyValues(*ppProp);
  309. }
  310. RRETURN(hr);
  311. }
  312. HRESULT
  313. GetEmptyLPWSTRProp(UMI_PROPERTY_VALUES **ppProp)
  314. {
  315. HRESULT hr = S_OK;
  316. *ppProp = (PUMI_PROPERTY_VALUES) AllocADsMem(sizeof(UMI_PROPERTY_VALUES));
  317. if (!*ppProp) {
  318. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  319. }
  320. (*ppProp)->pPropArray =
  321. (UMI_PROPERTY *) AllocADsMem(sizeof(UMI_PROPERTY));
  322. if (!((*ppProp)->pPropArray)) {
  323. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  324. }
  325. (*ppProp)->uCount = 1;
  326. (*ppProp)->pPropArray[0].uType = UMI_TYPE_LPWSTR;
  327. (*ppProp)->pPropArray[0].uCount = 0;
  328. (*ppProp)->pPropArray[0].pUmiValue = NULL;
  329. error :
  330. if (FAILED(hr)) {
  331. FreeUmiPropertyValues(*ppProp);
  332. }
  333. RRETURN(hr);
  334. }
  335. //+---------------------------------------------------------------------------
  336. // Function: ConvertBSTRToUmiProp.
  337. //
  338. // Synopsis: Convert the bstr to a corresponding UmiProp.
  339. //
  340. // Arguments: bstrStringVal - String to convert to umi values.
  341. // ppProp - Output UmiPropertyValues.
  342. //
  343. // Returns: HRESULT - S_OK or any failure ecode.
  344. //
  345. // Modifies: *pProp to point to valid UMI_PROPERTY_VALUES.
  346. //
  347. //----------------------------------------------------------------------------
  348. HRESULT
  349. ConvertBSTRToUmiProp(
  350. BSTR bstrStringVal,
  351. UMI_PROPERTY_VALUES **ppProp
  352. )
  353. {
  354. HRESULT hr = S_OK;
  355. LPWSTR * pszStrArray = NULL;
  356. LPWSTR pszTmpStr = NULL;
  357. *ppProp = (PUMI_PROPERTY_VALUES) AllocADsMem(sizeof(UMI_PROPERTY_VALUES));
  358. if (!*ppProp) {
  359. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  360. }
  361. (*ppProp)->pPropArray =
  362. (UMI_PROPERTY *) AllocADsMem(sizeof(UMI_PROPERTY));
  363. if (!((*ppProp)->pPropArray)) {
  364. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  365. }
  366. (*ppProp)->uCount = 1;
  367. (*ppProp)->pPropArray[0].uType = UMI_TYPE_LPWSTR;
  368. (*ppProp)->pPropArray[0].uCount = 1;
  369. pszStrArray = (LPWSTR *) AllocADsMem(sizeof(LPWSTR) * 1);
  370. if (!pszStrArray) {
  371. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  372. }
  373. //
  374. // If the value is NULL, then we return an array with a NULL
  375. // value as the result.
  376. //
  377. if (bstrStringVal) {
  378. pszStrArray[0] = AllocADsStr(bstrStringVal);
  379. if (!pszStrArray[0]) {
  380. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  381. }
  382. }
  383. (*ppProp)->pPropArray[0].pUmiValue = (UMI_VALUE *)(void *)pszStrArray;
  384. error :
  385. if (FAILED(hr)) {
  386. if (pszStrArray) {
  387. FreeADsMem( (void*) pszStrArray);
  388. }
  389. FreeUmiPropertyValues(*ppProp);
  390. }
  391. RRETURN(hr);
  392. }
  393. //+---------------------------------------------------------------------------
  394. // Function: ConvertIUnkToUmiProp.
  395. //
  396. // Synopsis: Convert the IUnk to a corresponding UmiProp.
  397. //
  398. // Arguments: pUnk - IUnk ptr.
  399. // iid - iid of the ptr.
  400. // ppProp - Output UmiPropertyValues.
  401. //
  402. // Returns: HRESULT - S_OK or any failure ecode.
  403. //
  404. // Modifies: *pProp to point to valid UMI_PROPERTY_VALUES.
  405. //
  406. //----------------------------------------------------------------------------
  407. HRESULT
  408. ConvertIUnkToUmiProp(
  409. IUnknown * pUnk,
  410. IID iid,
  411. UMI_PROPERTY_VALUES **ppProp
  412. )
  413. {
  414. HRESULT hr = S_OK;
  415. PUMI_COM_OBJECT pComObjArray = NULL;
  416. *ppProp = (PUMI_PROPERTY_VALUES) AllocADsMem(sizeof(UMI_PROPERTY_VALUES));
  417. if (!*ppProp) {
  418. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  419. }
  420. (*ppProp)->pPropArray =
  421. (UMI_PROPERTY *) AllocADsMem(sizeof(UMI_PROPERTY));
  422. if (!((*ppProp)->pPropArray)) {
  423. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  424. }
  425. (*ppProp)->uCount = 1;
  426. (*ppProp)->pPropArray[0].uType = UMI_TYPE_IUNKNOWN;
  427. (*ppProp)->pPropArray[0].uCount = 1;
  428. pComObjArray = (PUMI_COM_OBJECT) AllocADsMem(sizeof(UMI_COM_OBJECT) * 1);
  429. if (!pComObjArray) {
  430. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  431. }
  432. hr = pUnk->QueryInterface(
  433. iid,
  434. (void **) &(pComObjArray[0].pInterface)
  435. );
  436. BAIL_ON_FAILURE(hr);
  437. pComObjArray[0].priid = (IID *) AllocADsMem(sizeof(IID));
  438. if (!pComObjArray[0].priid) {
  439. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  440. }
  441. memcpy(pComObjArray[0].priid, &iid, sizeof(IID));
  442. (*ppProp)->pPropArray[0].pUmiValue = (UMI_VALUE *)(void *)pComObjArray;
  443. error :
  444. if (FAILED(hr)) {
  445. if (pComObjArray) {
  446. if (pComObjArray[0].pInterface) {
  447. ((IUnknown *)pComObjArray[0].pInterface)->Release();
  448. }
  449. FreeADsMem( (void*) pComObjArray);
  450. }
  451. FreeUmiPropertyValues(*ppProp);
  452. }
  453. RRETURN(hr);
  454. }
  455. //+---------------------------------------------------------------------------
  456. // Function: HelperGetUmiRelUrl.
  457. //
  458. // Synopsis: Gets the __RELURL property for the object. This routine
  459. // combines the IADs::get_Name and IADs::get_Class
  460. //
  461. // Arguments: pIADs - Pointer to obj implementing IADs.
  462. // bstrRetVal - Pointer for retrun bstr value.
  463. //
  464. // Returns: HRESULT - S_OK or any failure ecode.
  465. //
  466. // Modifies: *pProp to point to valid UMI_PROPERTY_VALUES.
  467. //
  468. //----------------------------------------------------------------------------
  469. HRESULT
  470. HelperGetUmiRelUrl(
  471. IADs * pIADs,
  472. BSTR * bstrRetVal
  473. )
  474. {
  475. HRESULT hr = S_OK;
  476. BSTR bstrName = NULL, bstrClass = NULL;
  477. LPWSTR pszTempVal = NULL;
  478. BOOL fSchemaObject = FALSE;
  479. hr = pIADs->get_Name(&bstrName);
  480. BAIL_ON_FAILURE(hr);
  481. hr = pIADs->get_Class(&bstrClass);
  482. BAIL_ON_FAILURE(hr);
  483. //
  484. // See if this is a schema object.
  485. //
  486. if (!_wcsicmp(bstrClass, L"Schema")
  487. || !_wcsicmp(bstrClass, L"Class")
  488. || !_wcsicmp(bstrClass, L"Property")
  489. )
  490. {
  491. LPWSTR pszTemp;
  492. //
  493. // If this is indeed a schema object then the name
  494. // wont have any = sign in it. Equal is not allowed
  495. // in the names of schema objects.
  496. //
  497. if ((pszTemp = wcschr(bstrName, L'=')) == NULL)
  498. fSchemaObject = TRUE;
  499. }
  500. //
  501. // Add 2 as we need 1 for the \0 and the other for the .
  502. // in class.name
  503. //
  504. DWORD dwLen;
  505. dwLen = wcslen(bstrName) + wcslen(bstrClass) + 2;
  506. if (fSchemaObject) {
  507. //
  508. // Need to add space for .Name
  509. //
  510. dwLen = dwLen + 6;
  511. }
  512. pszTempVal = (LPWSTR) AllocADsMem(dwLen * sizeof(WCHAR));
  513. if (!pszTempVal) {
  514. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  515. }
  516. if (!fSchemaObject) {
  517. wsprintf(pszTempVal, L"%s.%s", bstrClass, bstrName);
  518. }
  519. else {
  520. wsprintf(pszTempVal, L"%s.Name=%s", bstrClass, bstrName);
  521. }
  522. hr = ADsAllocString(pszTempVal, bstrRetVal);
  523. BAIL_ON_FAILURE(hr);
  524. error:
  525. if (bstrName) {
  526. SysFreeString(bstrName);
  527. }
  528. if (bstrClass) {
  529. SysFreeString(bstrClass);
  530. }
  531. if (pszTempVal) {
  532. FreeADsStr(pszTempVal);
  533. }
  534. RRETURN(hr);
  535. }
  536. //+---------------------------------------------------------------------------
  537. // Function: HelperGetUmiSchemaContainerPath.
  538. //
  539. // Synopsis: Gets the Umi path to the schema container for this object.
  540. //
  541. // Arguments: pIADs - Pointer to obj implementing IADs.
  542. // bstrRetVal - Pointer for retrun bstr value.
  543. //
  544. // Returns: HRESULT - S_OK or any failure ecode.
  545. //
  546. // Modifies: *bstrRetVal points to the correct schema path.
  547. //
  548. //----------------------------------------------------------------------------
  549. HRESULT
  550. HelperGetUmiSchemaContainerPath(
  551. IADs * pIADs,
  552. BSTR * bstrRetVal
  553. )
  554. {
  555. HRESULT hr = S_OK;
  556. BSTR bstrSchema = NULL;
  557. LPWSTR pszParent = NULL, pszCN = NULL, pszUmiSchema = NULL;
  558. //
  559. // First we need the path of the schema object itslef.
  560. //
  561. hr = pIADs->get_Schema(&bstrSchema);
  562. BAIL_ON_FAILURE(hr);
  563. //
  564. // Now we can build the path to the schema container from the path.
  565. //
  566. hr = BuildADsParentPath(
  567. bstrSchema,
  568. &pszParent,
  569. &pszCN
  570. );
  571. BAIL_ON_FAILURE(hr);
  572. hr = ADsPathToUmiURL(pszParent, &pszUmiSchema);
  573. BAIL_ON_FAILURE(hr);
  574. hr = ADsAllocString(pszUmiSchema, bstrRetVal);
  575. BAIL_ON_FAILURE(hr);
  576. error:
  577. if (bstrSchema) {
  578. SysFreeString(bstrSchema);
  579. }
  580. if (pszCN) {
  581. FreeADsStr(pszCN);
  582. }
  583. if (pszParent) {
  584. FreeADsStr(pszParent);
  585. }
  586. if (pszUmiSchema) {
  587. FreeADsStr(pszUmiSchema);
  588. }
  589. RRETURN(hr);
  590. }
  591. //+---------------------------------------------------------------------------
  592. // Function: HelperGetUmiDerivedFrom.
  593. //
  594. // Synopsis: Gets the value of the class that the current class object
  595. // is derived from.
  596. //
  597. // Arguments: pIADs - Pointer to obj implementing IADs.
  598. // bstrRetVal - Pointer for retrun bstr value.
  599. //
  600. // Returns: HRESULT - S_OK or any failure ecode.
  601. //
  602. // Modifies: *bstrRetVal points to the correct schema path.
  603. //
  604. //----------------------------------------------------------------------------
  605. HRESULT
  606. HelperGetUmiDerivedFrom(
  607. IADs * pIADs,
  608. BSTR * pbstrRetVal
  609. )
  610. {
  611. HRESULT hr = S_OK;
  612. IADsClass *pClass = NULL;
  613. BSTR bstrName = NULL;
  614. VARIANT vVariant;
  615. VariantInit(&vVariant);
  616. *pbstrRetVal = NULL;
  617. hr = pIADs->get_Name(&bstrName);
  618. BAIL_ON_FAILURE(hr);
  619. //
  620. // If the class is Top then we just return NULL.
  621. //
  622. if (_wcsicmp(bstrName, L"Top")) {
  623. //
  624. // Get the IADsClass interface, this is done because IADs::Get
  625. // will need to ask for different attributes based on the server.
  626. // IADsClass encapsulates this difference for us.
  627. //
  628. hr = pIADs->QueryInterface(IID_IADsClass, (void **) &pClass);
  629. if (FAILED(hr)) {
  630. BAIL_ON_FAILURE(hr = E_FAIL);
  631. }
  632. hr = pClass->get_DerivedFrom(&vVariant);
  633. BAIL_ON_FAILURE(hr);
  634. ADsAssert(vVariant.vt == VT_BSTR);
  635. hr = ADsAllocString(vVariant.bstrVal, pbstrRetVal);
  636. }
  637. BAIL_ON_FAILURE(hr);
  638. error:
  639. VariantClear(&vVariant);
  640. if (bstrName) {
  641. SysFreeString(bstrName);
  642. }
  643. if (pClass) {
  644. pClass->Release();
  645. }
  646. RRETURN(hr);
  647. }
  648. //+---------------------------------------------------------------------------
  649. // Function: HelperConvertNameToKey.
  650. //
  651. // Synopsis: Converts the value of the BSTR (of the form cn=test) to cn
  652. // as required by UMI.
  653. //
  654. // Arguments: bstrName - Value to get the key from.
  655. // pszUmiKey - Return value for the key.
  656. //
  657. // Returns: HRESULT - S_OK or any failure ecode.
  658. //
  659. // Modifies: *pszUmiUrl points to the key.
  660. //
  661. //----------------------------------------------------------------------------
  662. HRESULT
  663. HelperConvertNameToKey(
  664. BSTR bstrName,
  665. LPWSTR * pszUmiUrl
  666. )
  667. {
  668. HRESULT hr = S_OK;
  669. LPWSTR pszTemp = bstrName;
  670. BOOL fEqualFound = FALSE;
  671. DWORD dwCount = 0;
  672. ADsAssert(bstrName && pszTemp && *pszTemp);
  673. while (pszTemp
  674. && *pszTemp
  675. && (!fEqualFound)
  676. ) {
  677. if (*pszTemp == L'=') {
  678. fEqualFound = TRUE;
  679. }
  680. dwCount++;
  681. pszTemp++;
  682. }
  683. if (!fEqualFound) {
  684. BAIL_ON_FAILURE(hr = E_ADS_PROPERTY_NOT_FOUND);
  685. }
  686. *pszUmiUrl = (LPWSTR) AllocADsMem(dwCount * sizeof(WCHAR));
  687. if (!*pszUmiUrl) {
  688. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  689. }
  690. wcsncpy(*pszUmiUrl, bstrName, (dwCount-1));
  691. error:
  692. RRETURN(hr);
  693. }
  694. //+---------------------------------------------------------------------------
  695. // Function: HelperUpdateSDFlags.
  696. //
  697. // Synopsis: On put/get calls updates the security flags appropriately.
  698. //
  699. // Arguments: pIADs - IADs pointer to use to update sd.
  700. // uFlags - Flags to use for getting SD.
  701. // pfUpdated - Return boolean value.
  702. //
  703. // Returns: HRESULT - S_OK or any failure ecode.
  704. //
  705. // Modifies: Underlying property cache and pfUpdated to TRUE if the
  706. // flags on the object had to be changed and FALSE otherwise.
  707. //
  708. //----------------------------------------------------------------------------
  709. HRESULT
  710. HelperUpdateSDFlags(
  711. IADs *pIADs,
  712. ULONG uFlags,
  713. BOOL *pfUpdated = NULL
  714. )
  715. {
  716. HRESULT hr = S_OK;
  717. IADsObjOptPrivate *pPrivOpt = NULL;
  718. SECURITY_INFORMATION secInfo;
  719. ADsAssert(pIADs);
  720. if (pfUpdated) {
  721. *pfUpdated = FALSE;
  722. }
  723. //
  724. // Get the objOpt intf and make sure the flags are right.
  725. //
  726. hr = pIADs->QueryInterface(IID_IADsObjOptPrivate, (void **) &pPrivOpt);
  727. BAIL_ON_FAILURE(hr);
  728. hr = pPrivOpt->GetOption(
  729. LDAP_SECURITY_MASK,
  730. (void *) &secInfo
  731. );
  732. BAIL_ON_FAILURE(hr);
  733. if (secInfo != uFlags) {
  734. //
  735. // We need to update the security mask on the object.
  736. //
  737. hr = pPrivOpt->SetOption(
  738. LDAP_SECURITY_MASK,
  739. (void **) &uFlags
  740. );
  741. BAIL_ON_FAILURE(hr);
  742. //
  743. // Need to let caller know that the flags have changed.
  744. //
  745. if (pfUpdated) {
  746. *pfUpdated = TRUE;
  747. }
  748. }
  749. error:
  750. if (pPrivOpt) {
  751. pPrivOpt->Release();
  752. }
  753. RRETURN(hr);
  754. }
  755. //+---------------------------------------------------------------------------
  756. // Function: HelperGetSDIntoCache.
  757. //
  758. // Synopsis: Reads the sd into the property cache using the appropriate
  759. // flags as needed.
  760. //
  761. // Arguments: pIADs - IADs pointer to use to update sd.
  762. // uFlags - Flags to use for getting SD.
  763. //
  764. // Returns: HRESULT - S_OK or any failure ecode.
  765. //
  766. // Modifies: Underlying property cache.
  767. //
  768. //----------------------------------------------------------------------------
  769. HRESULT HelperGetSDIntoCache(
  770. IADs * pIADs,
  771. ULONG uFlags
  772. )
  773. {
  774. HRESULT hr = S_OK;
  775. VARIANT vVar;
  776. BOOL fUpdated = FALSE;
  777. LPWSTR szSecDesc[] = {L"ntSecurityDescriptor"};
  778. VariantInit(&vVar);
  779. hr = HelperUpdateSDFlags(
  780. pIADs,
  781. (uFlags & UMI_SECURITY_MASK),
  782. &fUpdated
  783. );
  784. BAIL_ON_FAILURE(hr);
  785. if (fUpdated) {
  786. //
  787. // Update just the SD by calling GetInfoEx.
  788. //
  789. hr = ADsBuildVarArrayStr(
  790. szSecDesc,
  791. 1,
  792. &vVar
  793. );
  794. BAIL_ON_FAILURE(hr);
  795. hr = pIADs->GetInfoEx(vVar, 0);
  796. BAIL_ON_FAILURE(hr);
  797. }
  798. error :
  799. VariantClear(&vVar);
  800. RRETURN(hr);
  801. }
  802. //+---------------------------------------------------------------------------
  803. // Function: HelperGetOrigin.
  804. //
  805. // Synopsis: Gets the originating class for the property in question.
  806. //
  807. // Arguments: pIADs - IADs pointer to backing object.
  808. // pszName - Name of the property whose origin is needed.
  809. // ppProp - Return value.
  810. //
  811. // Returns: HRESULT - S_OK or any failure ecode.
  812. //
  813. // Modifies: N/A.
  814. //
  815. //----------------------------------------------------------------------------
  816. HRESULT
  817. HelperGetOrigin(
  818. IADs *pIADs,
  819. LPCWSTR pszName,
  820. UMI_PROPERTY_VALUES **ppProp
  821. )
  822. {
  823. HRESULT hr = S_OK;
  824. IADsUmiHelperPrivate *pHelper = NULL;
  825. BSTR bstrVal = NULL;
  826. hr = pIADs->QueryInterface(
  827. IID_IADsUmiHelperPrivate,
  828. (void **) &pHelper
  829. );
  830. if (FAILED(hr)) {
  831. //
  832. // This object does not support this property as it is not
  833. // a class object.
  834. //
  835. BAIL_ON_FAILURE(hr = E_ADS_PROPERTY_NOT_FOUND);
  836. }
  837. hr = pHelper->GetOriginHelper(
  838. pszName,
  839. &bstrVal
  840. );
  841. BAIL_ON_FAILURE(hr);
  842. hr = ConvertBSTRToUmiProp(
  843. bstrVal,
  844. ppProp
  845. );
  846. error:
  847. if (bstrVal) {
  848. SysFreeString(bstrVal);
  849. }
  850. if (pHelper) {
  851. pHelper->Release();
  852. }
  853. RRETURN(hr);
  854. }
  855. //+---------------------------------------------------------------------------
  856. // Function: CopyUmiProperty.
  857. //
  858. // Synopsis: Copy the input value into a newly allocated output buffer.
  859. // Note that since this is an internal routine assumptions are made
  860. // as to the data. Currently handles only UMI_TYPE_LPWSTR,
  861. // UMI_TYPE_I4 and UMI_TYPE_BOOL. If multivalued, we can only copy
  862. // strings (things like filter on enum can be multi-valued).
  863. //
  864. // Arguments: umiProp - Umi property value to copy.
  865. // ppUmiProp - Return value for new umi property.
  866. //
  867. // Returns: HRESULT - S_OK or any failure ecode.
  868. //
  869. // Modifies: *ppUmiProp to point to valid UMI_PROPERTY.
  870. //
  871. //----------------------------------------------------------------------------
  872. HRESULT
  873. CopyUmiProperty(
  874. UMI_PROPERTY umiProp,
  875. PUMI_PROPERTY *ppUmiProp
  876. )
  877. {
  878. HRESULT hr = S_OK;
  879. UMI_PROPERTY *pUmiPropLocal = NULL;
  880. ULONG ulUmiType = umiProp.uType;
  881. ULONG ulPropCount = umiProp.uCount;
  882. *ppUmiProp = NULL;
  883. //
  884. // Multi valued has to be string.
  885. //
  886. if ((ulPropCount > 1) && (ulUmiType != UMI_TYPE_LPWSTR)) {
  887. BAIL_ON_FAILURE(hr = E_ADS_BAD_PARAMETER);
  888. }
  889. pUmiPropLocal = (UMI_PROPERTY *) AllocADsMem(sizeof(UMI_PROPERTY));
  890. if (!pUmiPropLocal) {
  891. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  892. }
  893. pUmiPropLocal->pszPropertyName = AllocADsStr(umiProp.pszPropertyName);
  894. if (!pUmiPropLocal->pszPropertyName) {
  895. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  896. }
  897. pUmiPropLocal->uOperationType = umiProp.uOperationType;
  898. pUmiPropLocal->uType = umiProp.uType;
  899. switch (umiProp.uType) {
  900. case UMI_TYPE_LPWSTR :
  901. LPWSTR *pszTmpArray;
  902. pszTmpArray = (LPWSTR *) AllocADsMem(sizeof(LPWSTR) * ulPropCount);
  903. if (!pszTmpArray) {
  904. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  905. }
  906. for (DWORD dwCtr = 0; dwCtr < ulPropCount; dwCtr++) {
  907. pszTmpArray[dwCtr] = AllocADsStr(
  908. umiProp.pUmiValue->pszStrValue[dwCtr]
  909. );
  910. if (!pszTmpArray[dwCtr]) {
  911. //
  912. // NULL is allowed as a value only if it is the
  913. // only value being set.
  914. //
  915. if (ulPropCount != 1
  916. || umiProp.pUmiValue->pszStrValue[dwCtr]
  917. ) {
  918. //
  919. // Cleanup and exit.
  920. //
  921. for (DWORD dwCtr2 = 0; dwCtr2 < dwCtr; dwCtr2++) {
  922. if (pszTmpArray[dwCtr2]) {
  923. FreeADsStr(pszTmpArray[dwCtr2]);
  924. pszTmpArray[dwCtr2] = NULL;
  925. }
  926. }
  927. FreeADsMem(pszTmpArray);
  928. pszTmpArray = NULL;
  929. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  930. }
  931. } // if alloc failed in middle of array.
  932. }
  933. pUmiPropLocal->pUmiValue = (PUMI_VALUE) (void *) pszTmpArray;
  934. break;
  935. case UMI_TYPE_I4:
  936. LONG *pLongArray;
  937. pLongArray = (LONG *) AllocADsMem(sizeof(LONG) * 1);
  938. if (!pLongArray) {
  939. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  940. }
  941. pLongArray[0] = umiProp.pUmiValue->lValue[0];
  942. pUmiPropLocal->pUmiValue = (PUMI_VALUE) (void *) pLongArray;
  943. break;
  944. case UMI_TYPE_BOOL:
  945. BOOL *pBoolArray;
  946. pBoolArray = (BOOL *) AllocADsMem(sizeof(BOOL) * 1);
  947. if (!pBoolArray) {
  948. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  949. }
  950. pBoolArray[0] = umiProp.pUmiValue->bValue[0];
  951. pUmiPropLocal->pUmiValue = (PUMI_VALUE) (void *) pBoolArray;
  952. break;
  953. default:
  954. BAIL_ON_FAILURE(hr = E_ADS_BAD_PARAMETER);
  955. break;
  956. }
  957. pUmiPropLocal->uCount = ulPropCount;
  958. *ppUmiProp = pUmiPropLocal;
  959. RRETURN(hr);
  960. error:
  961. //
  962. // Cleanup cause we hit an error.
  963. //
  964. if (pUmiPropLocal) {
  965. FreeOneUmiProperty(*pUmiPropLocal);
  966. FreeADsMem( (void*) pUmiPropLocal);
  967. }
  968. RRETURN(hr);
  969. }
  970. //****************************************************************************
  971. //
  972. //CPropertyManager Methods.
  973. //
  974. //****************************************************************************
  975. //+---------------------------------------------------------------------------
  976. // Function: CPropertyManager::CPropertyManager
  977. //
  978. // Synopsis: Constructor
  979. //
  980. // Arguments: None
  981. //
  982. // Returns: N/A
  983. //
  984. // Modifies: N/A
  985. //
  986. //----------------------------------------------------------------------------
  987. CPropertyManager::CPropertyManager():
  988. _dwMaxProperties(0),
  989. _pPropCache(NULL),
  990. _pIntfProperties(NULL),
  991. _dwMaxLimit(0),
  992. _fPropCacheMode(TRUE),
  993. _pStaticPropData(NULL),
  994. _ulStatus(0),
  995. _pIADs(NULL),
  996. _pUnk(NULL),
  997. _pCreds(NULL),
  998. _pszServerName(NULL)
  999. {
  1000. }
  1001. //+---------------------------------------------------------------------------
  1002. // Function: CPropertyManager::~CPropertyManager
  1003. //
  1004. // Synopsis: Destructor
  1005. //
  1006. // Arguments: None
  1007. //
  1008. // Returns: N/A
  1009. //
  1010. // Modifies: N/A
  1011. //
  1012. //----------------------------------------------------------------------------
  1013. CPropertyManager::~CPropertyManager()
  1014. {
  1015. //
  1016. // Need to cleanup inftProps table
  1017. //
  1018. if (_pIntfProperties) {
  1019. DWORD dwCtr;
  1020. for (dwCtr = 0; dwCtr < _dwMaxProperties; dwCtr++) {
  1021. //
  1022. // Free each of the entries and their contents.
  1023. //
  1024. PINTF_PROPERTY pIntfProp = &(_pIntfProperties[dwCtr]);
  1025. if (pIntfProp->pszPropertyName) {
  1026. FreeADsStr(pIntfProp->pszPropertyName);
  1027. pIntfProp->pszPropertyName = NULL;
  1028. }
  1029. if (pIntfProp->pUmiProperty) {
  1030. FreeOneUmiProperty(*(pIntfProp->pUmiProperty));
  1031. FreeADsMem(pIntfProp->pUmiProperty);
  1032. pIntfProp->pUmiProperty = NULL;
  1033. }
  1034. }
  1035. FreeADsMem(_pIntfProperties);
  1036. }
  1037. _pIntfProperties = NULL;
  1038. //
  1039. // The rest of the stuff is taken care of when the
  1040. // destructor to the IADs obj is called. This object
  1041. // itself will be released only in the destructor of the
  1042. // IADs object is called.
  1043. //
  1044. _pPropCache = NULL;
  1045. if (_pIADs) {
  1046. _pIADs->Release();
  1047. }
  1048. _pIADs = NULL;
  1049. _dwMaxProperties = 0;
  1050. //
  1051. // Do not free as these are owned by the owning object.
  1052. //
  1053. _pszServerName = NULL;
  1054. _pCreds = NULL;
  1055. _pUnk = NULL;
  1056. }
  1057. //+---------------------------------------------------------------------------
  1058. // Function: CPropertyManager::CreatePropertyManager (overloaded)
  1059. //
  1060. // Synopsis: Static allocation routine (property cache mode).
  1061. //
  1062. // Arguments: IADs* - pointer to IADs implementor object.
  1063. // pUnk - owning object unknown.
  1064. // pPropCache - pointer to propertyCache used by object.
  1065. // pCredentials - pointer to credentials.
  1066. // pszServerName - pointer to servername.
  1067. // ppPropertyManager - return ptr for new prop mgr.
  1068. //
  1069. // Returns: HRESULT - S_OK or any failure error code.
  1070. //
  1071. // Modifies: CPropertyManager ** - ptr to newly created object.
  1072. //
  1073. //----------------------------------------------------------------------------
  1074. HRESULT
  1075. CPropertyManager::CreatePropertyManager(
  1076. IADs *pADsObj,
  1077. IUnknown *pUnk,
  1078. CPropertyCache *pPropCache,
  1079. CCredentials *pCredentials,
  1080. LPWSTR pszServerName,
  1081. CPropertyManager FAR * FAR * ppPropertyManager
  1082. )
  1083. {
  1084. CPropertyManager FAR * pPropMgr = NULL;
  1085. pPropMgr = new CPropertyManager();
  1086. if (!pPropMgr) {
  1087. RRETURN_EXP_IF_ERR(E_OUTOFMEMORY);
  1088. }
  1089. if (pADsObj) {
  1090. pADsObj->QueryInterface(IID_IADs, (void**) &(pPropMgr->_pIADs));
  1091. }
  1092. pPropMgr->_pUnk = pUnk;
  1093. pPropMgr->_pPropCache = pPropCache;
  1094. pPropMgr->_fPropCacheMode = TRUE;
  1095. pPropMgr->_pIntfProperties = NULL;
  1096. pPropMgr->_pszServerName = pszServerName;
  1097. pPropMgr->_pCreds = pCredentials;
  1098. *ppPropertyManager = pPropMgr;
  1099. RRETURN(S_OK);
  1100. }
  1101. //+---------------------------------------------------------------------------
  1102. // Function: CPropertyManager::CreatePropertyManager (overloaded)
  1103. //
  1104. // Synopsis: Static allocation routine (interface properties mode).
  1105. //
  1106. // Arguments: pUnk - pointer to owner (umi) object.
  1107. // pIADs - pointer to IADs implementor.
  1108. // pCredentials - pointer to credentials.
  1109. // pTable - property table.
  1110. // ppPropertyManager - return value for new prop mgr.
  1111. //
  1112. // Returns: HRESULT - S_OK or any failure error code.
  1113. //
  1114. // Modifies: CPropertyManager ** - ptr to newly created object.
  1115. //
  1116. //----------------------------------------------------------------------------
  1117. HRESULT
  1118. CPropertyManager::CreatePropertyManager(
  1119. IUnknown *pUnk,
  1120. IUnknown *pIADs,
  1121. CCredentials *pCredentials,
  1122. INTF_PROP_DATA pTable[],
  1123. CPropertyManager FAR * FAR * ppPropertyManager
  1124. )
  1125. {
  1126. CPropertyManager FAR * pPropMgr = NULL;
  1127. pPropMgr = new CPropertyManager();
  1128. if (!pPropMgr) {
  1129. RRETURN_EXP_IF_ERR(E_OUTOFMEMORY);
  1130. }
  1131. pPropMgr->_pUnk = pUnk;
  1132. //
  1133. // We can ignore any failures here.
  1134. //
  1135. if (pIADs) {
  1136. pIADs->QueryInterface(IID_IADs, (void**) &(pPropMgr->_pIADs));
  1137. }
  1138. pPropMgr->_pPropCache = NULL;
  1139. pPropMgr->_fPropCacheMode = FALSE;
  1140. pPropMgr->_pIntfProperties = NULL;
  1141. pPropMgr->_pCreds = pCredentials;
  1142. pPropMgr->_pStaticPropData = pTable;
  1143. *ppPropertyManager = pPropMgr;
  1144. RRETURN(S_OK);
  1145. }
  1146. STDMETHODIMP
  1147. CPropertyManager::QueryInterface(REFIID iid, LPVOID FAR* ppv)
  1148. {
  1149. HRESULT hr = S_OK;
  1150. SetLastStatus(0);
  1151. if (ppv == NULL) {
  1152. RRETURN(E_POINTER);
  1153. }
  1154. if (IsEqualIID(iid, IID_IUnknown)){
  1155. *ppv = (IUnknown FAR *) this;
  1156. }
  1157. else if (IsEqualIID(iid, IID_IUmiPropList)) {
  1158. *ppv = (IUmiPropList FAR *) this;
  1159. }
  1160. else {
  1161. *ppv = NULL;
  1162. SetLastStatus(E_NOINTERFACE);
  1163. return E_NOINTERFACE;
  1164. }
  1165. AddRef();
  1166. return NOERROR;
  1167. }
  1168. //
  1169. // Methods defined on the proplist interface.
  1170. //
  1171. //+---------------------------------------------------------------------------
  1172. // Function: CPropertyManager::Put (IUmiPropList support).
  1173. //
  1174. // Synopsis: Sets the value for the attribute in the cache.
  1175. //
  1176. // Arguments: self explanatory
  1177. //
  1178. //
  1179. // Returns: HRESULT - S_OK or any failure error code.
  1180. //
  1181. // Modifies: PropertyCache or internal interface property list.
  1182. //
  1183. //----------------------------------------------------------------------------
  1184. STDMETHODIMP
  1185. CPropertyManager::Put(
  1186. IN LPCWSTR pszName,
  1187. IN ULONG uFlags,
  1188. IN UMI_PROPERTY_VALUES *pProp
  1189. )
  1190. {
  1191. HRESULT hr = S_OK;
  1192. LDAPOBJECTARRAY ldapDestObjects;
  1193. DWORD dwOperationFlags = 0;
  1194. BOOL fSecurityFlags = FALSE;
  1195. IUmiObject *pUmiObj = NULL;
  1196. BOOL fInternalPut = FALSE;
  1197. SetLastStatus(0);
  1198. //
  1199. // Initialize so that we are not trying to free junk.
  1200. //
  1201. if (_fPropCacheMode) {
  1202. LDAPOBJECTARRAY_INIT(ldapDestObjects);
  1203. }
  1204. //
  1205. // Pre process and pull out the highest flag, all these
  1206. // because we are not allowed to support Put with 0.
  1207. //
  1208. if (uFlags & 0x8000000) {
  1209. uFlags &= 0x4000000;
  1210. fInternalPut = TRUE;
  1211. }
  1212. if (uFlags > UMI_SECURITY_MASK) {
  1213. BAIL_ON_FAILURE(hr = UMI_E_INVALID_FLAGS);
  1214. }
  1215. if (!pProp || !pszName) {
  1216. BAIL_ON_FAILURE(hr = E_ADS_BAD_PARAMETER);
  1217. }
  1218. if (uFlags & UMI_SECURITY_MASK) {
  1219. fSecurityFlags = TRUE;
  1220. }
  1221. //
  1222. // We support only putting one property at a time.
  1223. //
  1224. if (pProp->uCount != 1) {
  1225. BAIL_ON_FAILURE(hr = E_ADS_BAD_PARAMETER);
  1226. }
  1227. //
  1228. // Make sure that the data passed in is correct.
  1229. //
  1230. if (!pProp->pPropArray
  1231. || !pProp->pPropArray[0].pszPropertyName) {
  1232. BAIL_ON_FAILURE(hr = E_INVALIDARG);
  1233. }
  1234. if (_fPropCacheMode) {
  1235. DWORD dwLdapSyntaxId = 1;
  1236. if (fInternalPut
  1237. && pProp->pPropArray[0].uOperationType == 0) {
  1238. dwOperationFlags = 0;
  1239. }
  1240. else {
  1241. //
  1242. // Verify that the operationType is something we support.
  1243. //
  1244. hr = ConvertUmiPropCodeToLdapCode(
  1245. pProp->pPropArray[0].uOperationType,
  1246. dwOperationFlags
  1247. );
  1248. BAIL_ON_FAILURE(hr);
  1249. }
  1250. if (fSecurityFlags) {
  1251. //
  1252. // Only this ntSecurityDescriptor can use the security flags.
  1253. //
  1254. if (_wcsicmp(L"ntSecurityDescriptor", pszName)) {
  1255. BAIL_ON_FAILURE(hr = E_FAIL);
  1256. }
  1257. hr = HelperUpdateSDFlags(
  1258. _pIADs,
  1259. uFlags & UMI_SECURITY_MASK
  1260. );
  1261. BAIL_ON_FAILURE(hr);
  1262. }
  1263. //
  1264. // In this case we need to convert data to ldap values and
  1265. // store in cache.
  1266. //
  1267. hr = UmiTypeToLdapTypeCopy(
  1268. *pProp,
  1269. uFlags,
  1270. &ldapDestObjects,
  1271. dwLdapSyntaxId, // byRef
  1272. _pCreds,
  1273. _pszServerName
  1274. );
  1275. BAIL_ON_FAILURE(hr);
  1276. //
  1277. // PutpropertyExt will add to the cache if needed.
  1278. //
  1279. hr = _pPropCache->putpropertyext(
  1280. (LPWSTR)pszName,
  1281. dwOperationFlags,
  1282. dwLdapSyntaxId,
  1283. ldapDestObjects
  1284. );
  1285. BAIL_ON_FAILURE(hr);
  1286. }
  1287. else {
  1288. //
  1289. // Local cache for interface properties. Verify property is
  1290. // legal and update the local information accordingly.
  1291. //
  1292. if (VerifyIfValidProperty(
  1293. pProp->pPropArray[0].pszPropertyName,
  1294. pProp->pPropArray[0]
  1295. )
  1296. ) {
  1297. if (fSecurityFlags
  1298. || !_wcsicmp(pszName, L"__SECURITY_DESCRIPTOR")
  1299. ) {
  1300. //
  1301. // Make sure name is correct.
  1302. //
  1303. if (_wcsicmp(L"__SECURITY_DESCRIPTOR", pszName)) {
  1304. BAIL_ON_FAILURE(hr = E_FAIL);
  1305. }
  1306. //
  1307. // We need turn around and call put on the owning object.
  1308. // This means we need to package the UMI_PROPERTY_VALUES
  1309. // accordingly.
  1310. //
  1311. UMI_PROPERTY pUmiProperty[] = {
  1312. pProp->pPropArray[0].uType,
  1313. pProp->pPropArray[0].uCount,
  1314. pProp->pPropArray[0].uOperationType,
  1315. L"ntSecurityDescriptor",
  1316. pProp->pPropArray[0].pUmiValue
  1317. };
  1318. UMI_PROPERTY_VALUES pUmiProp[] = {1, pUmiProperty};
  1319. hr = _pUnk->QueryInterface(
  1320. IID_IUmiObject,
  1321. (void **) &pUmiObj
  1322. );
  1323. BAIL_ON_FAILURE(hr);
  1324. hr = pUmiObj->Put(
  1325. L"ntSecurityDescriptor",
  1326. uFlags,
  1327. pUmiProp
  1328. );
  1329. BAIL_ON_FAILURE(hr);
  1330. }
  1331. else {
  1332. //
  1333. // We need to update this value in our cache
  1334. //
  1335. hr = AddProperty(
  1336. pszName,
  1337. pProp->pPropArray[0]
  1338. );
  1339. BAIL_ON_FAILURE(hr);
  1340. }
  1341. } // not valid property.
  1342. else {
  1343. BAIL_ON_FAILURE(hr = E_FAIL);
  1344. }
  1345. }
  1346. error :
  1347. //
  1348. // Free ldapDestObjects if applicable.
  1349. //
  1350. if (_fPropCacheMode) {
  1351. LdapTypeFreeLdapObjects( &ldapDestObjects );
  1352. }
  1353. if (pUmiObj) {
  1354. pUmiObj->Release();
  1355. }
  1356. if (FAILED(hr)) {
  1357. SetLastStatus(hr);
  1358. hr = MapHrToUmiError(hr);
  1359. }
  1360. RRETURN(hr);
  1361. }
  1362. //+---------------------------------------------------------------------------
  1363. // Function: CPropertyManager::Get (IUmiPropList support).
  1364. //
  1365. // Synopsis: Gets the value for the attribute. This will read data
  1366. // from the server as needed.
  1367. //
  1368. // Arguments: self explanatory
  1369. //
  1370. //
  1371. // Returns: HRESULT - S_OK or any failure error code.
  1372. //
  1373. // Modifies: UMI_PROPERTY_VALUES* has the values of the attribute.
  1374. //
  1375. //----------------------------------------------------------------------------
  1376. STDMETHODIMP
  1377. CPropertyManager::Get(
  1378. IN LPCWSTR pszName,
  1379. IN ULONG uFlags,
  1380. OUT UMI_PROPERTY_VALUES **pProp
  1381. )
  1382. {
  1383. HRESULT hr = S_OK;
  1384. ULONG uUmiFlag;
  1385. LDAPOBJECTARRAY ldapSrcObjects;
  1386. BOOL fSecurityFlag = FALSE;
  1387. BOOL fSchemaFlag = FALSE;
  1388. IADsObjOptPrivate *pPrivOpt = NULL;
  1389. SetLastStatus(0);
  1390. LDAPOBJECTARRAY_INIT(ldapSrcObjects);
  1391. if (!pProp) {
  1392. BAIL_ON_FAILURE(hr = E_INVALIDARG);
  1393. }
  1394. *pProp = NULL;
  1395. //
  1396. // Currently this is the highest flag we support.
  1397. //
  1398. if (uFlags > UMI_FLAG_PROPERTY_ORIGIN) {
  1399. BAIL_ON_FAILURE(hr = UMI_E_INVALID_FLAGS);
  1400. }
  1401. else if (uFlags & UMI_SECURITY_MASK) {
  1402. fSecurityFlag = TRUE;
  1403. }
  1404. else if (uFlags == UMI_FLAG_PROPERTY_ORIGIN) {
  1405. fSchemaFlag = TRUE;
  1406. }
  1407. if (fSchemaFlag && fSecurityFlag) {
  1408. BAIL_ON_FAILURE(hr = E_INVALIDARG);
  1409. }
  1410. //
  1411. // Name cannot be NULL.
  1412. //
  1413. if (!pszName) {
  1414. BAIL_ON_FAILURE(hr = E_INVALIDARG)
  1415. }
  1416. //
  1417. // If this is Property Manager is for server properties.
  1418. //
  1419. if (_fPropCacheMode) {
  1420. DWORD dwSyntaxId;
  1421. DWORD dwStatus;
  1422. DWORD dwSecOptions;
  1423. if (fSchemaFlag) {
  1424. BAIL_ON_FAILURE(hr = UMI_E_UNSUPPORTED_FLAGS);
  1425. }
  1426. if (fSecurityFlag) {
  1427. if (_wcsicmp(L"ntSecurityDescriptor", pszName)) {
  1428. //
  1429. // Security flag used and attrib not securityDescriptor.
  1430. //
  1431. BAIL_ON_FAILURE(hr = E_FAIL);
  1432. }
  1433. else {
  1434. //
  1435. // Valid flag we need to process the flags.
  1436. //
  1437. hr = HelperGetSDIntoCache(
  1438. _pIADs,
  1439. uFlags
  1440. );
  1441. BAIL_ON_FAILURE(hr);
  1442. }
  1443. }
  1444. //
  1445. // Object maybe unbound, so we should return no such prop if
  1446. // we get back E_ADS_OBJECT_UNBOUND.
  1447. //
  1448. hr = _pPropCache->getproperty(
  1449. (LPWSTR)pszName,
  1450. &dwSyntaxId,
  1451. &dwStatus,
  1452. &ldapSrcObjects
  1453. );
  1454. if (hr == E_ADS_OBJECT_UNBOUND) {
  1455. hr = E_ADS_PROPERTY_NOT_FOUND;
  1456. }
  1457. BAIL_ON_FAILURE(hr);
  1458. hr = ConvertLdapCodeToUmiPropCode(dwStatus, uUmiFlag);
  1459. BAIL_ON_FAILURE(hr);
  1460. //
  1461. // Return error if provider cache is not set and
  1462. // the cache is dirty.
  1463. //
  1464. if (uUmiFlag && !(uFlags & UMI_FLAG_PROVIDER_CACHE)) {
  1465. BAIL_ON_FAILURE(hr = UMI_E_SYNCHRONIZATION_REQUIRED);
  1466. }
  1467. //
  1468. // At this point we might have ldapSrcObjects.pLdapObjects == NULL.
  1469. // Typically that would be for property delete operations.
  1470. //
  1471. hr = LdapTypeToUmiTypeCopy(
  1472. ldapSrcObjects,
  1473. pProp,
  1474. dwStatus,
  1475. dwSyntaxId,
  1476. _pCreds,
  1477. _pszServerName,
  1478. uUmiFlag
  1479. );
  1480. }
  1481. else {
  1482. //
  1483. // Property Manager is for interface properties.
  1484. //
  1485. DWORD dwIndex;
  1486. //
  1487. // If the schema flag is set then we need to get the origin
  1488. // and not the property itself.
  1489. //
  1490. if (fSchemaFlag) {
  1491. hr = HelperGetOrigin(
  1492. _pIADs,
  1493. pszName,
  1494. pProp
  1495. );
  1496. }
  1497. else {
  1498. //
  1499. // Make sure this property is valid.
  1500. //
  1501. hr = GetIndexInStaticTable(pszName, dwIndex); // dwIndex is byRef
  1502. BAIL_ON_FAILURE(hr);
  1503. hr = GetInterfaceProperty(
  1504. pszName,
  1505. uFlags,
  1506. pProp,
  1507. dwIndex
  1508. );
  1509. }
  1510. }
  1511. BAIL_ON_FAILURE(hr);
  1512. //
  1513. // Stuff the name in the return value.
  1514. //
  1515. if (pProp && *pProp) {
  1516. (*pProp)->pPropArray[0].pszPropertyName = AllocADsStr(pszName);
  1517. if (!(*pProp)->pPropArray[0].pszPropertyName) {
  1518. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  1519. }
  1520. }
  1521. error:
  1522. if (_fPropCacheMode) {
  1523. LdapTypeFreeLdapObjects(&ldapSrcObjects);
  1524. }
  1525. if (FAILED(hr)) {
  1526. SetLastStatus(hr);
  1527. hr = MapHrToUmiError(hr);
  1528. if (pProp && *pProp) {
  1529. this->FreeMemory(0, (void *) *pProp);
  1530. *pProp = NULL;
  1531. }
  1532. }
  1533. RRETURN(hr);
  1534. }
  1535. //+---------------------------------------------------------------------------
  1536. // Function: CPropertyManager::GetAt (IUmiPropList support).
  1537. //
  1538. // Synopsis: Used to get the value by index ???
  1539. //
  1540. // Arguments: Not implemented
  1541. //
  1542. //
  1543. // Returns: E_NOTIMPL
  1544. //
  1545. // Modifies: Not implemented
  1546. //
  1547. //----------------------------------------------------------------------------
  1548. STDMETHODIMP
  1549. CPropertyManager::GetAt(
  1550. IN LPCWSTR pszName,
  1551. IN ULONG uFlags,
  1552. IN ULONG uBufferLength,
  1553. OUT LPVOID pExisitingMem
  1554. )
  1555. {
  1556. SetLastStatus(E_NOTIMPL);
  1557. RRETURN(E_NOTIMPL);
  1558. }
  1559. //+---------------------------------------------------------------------------
  1560. // Function: CPropertyManager::GetAs (IUmiPropList support).
  1561. //
  1562. // Synopsis: Gets the value for the attribute in the specified format.
  1563. //
  1564. // Arguments: self explanatory
  1565. //
  1566. //
  1567. // Returns: HRESULT - S_OK or any failure error code.
  1568. //
  1569. // Modifies: UMI_PROPERTY_VALUES* has the values of the attribute.
  1570. //
  1571. //----------------------------------------------------------------------------
  1572. STDMETHODIMP
  1573. CPropertyManager::GetAs(
  1574. IN LPCWSTR pszName,
  1575. IN ULONG uFlags,
  1576. IN ULONG uCoercionType,
  1577. IN OUT UMI_PROPERTY_VALUES **pProp
  1578. )
  1579. {
  1580. HRESULT hr = S_OK;
  1581. LDAPOBJECTARRAY ldapSrcObjects;
  1582. LDAPOBJECTARRAY ldapSrcObjectsTmp;
  1583. LDAPOBJECTARRAY * pldapObjects = NULL;
  1584. ULONG uUmiFlag;
  1585. DWORD dwSyntaxId, dwStatus, dwRequestedSyntax;
  1586. DWORD dwCachedSyntax, dwUserSyntax;
  1587. SetLastStatus(0);
  1588. LDAPOBJECTARRAY_INIT(ldapSrcObjects);
  1589. LDAPOBJECTARRAY_INIT(ldapSrcObjectsTmp);
  1590. if (!pszName || !pProp) {
  1591. BAIL_ON_FAILURE(hr = E_INVALIDARG);
  1592. }
  1593. //
  1594. // Has to be in prop cache mode.
  1595. //
  1596. if (!_fPropCacheMode || !_pPropCache) {
  1597. BAIL_ON_FAILURE(hr = E_NOTIMPL);
  1598. }
  1599. if (uFlags > UMI_SECURITY_MASK) {
  1600. BAIL_ON_FAILURE(hr = UMI_E_UNSUPPORTED_FLAGS);
  1601. }
  1602. if (uFlags & UMI_SECURITY_MASK) {
  1603. //
  1604. // Make sure it is the SD they are interested in.
  1605. //
  1606. if (_wcsicmp(L"ntSecurityDescriptor", pszName)) {
  1607. BAIL_ON_FAILURE(hr = E_INVALIDARG);
  1608. }
  1609. //
  1610. // At this point we need to get the SD in the cache.
  1611. //
  1612. hr = HelperGetSDIntoCache(_pIADs, uFlags);
  1613. BAIL_ON_FAILURE(hr);
  1614. }
  1615. //
  1616. // Object maybe unbound, so we should return no such prop if
  1617. // we get back E_ADS_OBJECT_UNBOUND.
  1618. //
  1619. hr = _pPropCache->getproperty(
  1620. (LPWSTR)pszName,
  1621. &dwSyntaxId,
  1622. &dwStatus,
  1623. &ldapSrcObjects
  1624. );
  1625. if (hr == E_ADS_OBJECT_UNBOUND) {
  1626. hr = E_ADS_PROPERTY_NOT_FOUND;
  1627. }
  1628. BAIL_ON_FAILURE(hr);
  1629. //
  1630. // Get the appropriate umi code for the status.
  1631. //
  1632. hr = ConvertLdapCodeToUmiPropCode(dwStatus, uUmiFlag);
  1633. BAIL_ON_FAILURE(hr);
  1634. //
  1635. // At this point we need to see if we can convert the data
  1636. // to the format requested. This code is similar to that in
  1637. // proplist.cxx GetPropertyItem but there appears to be no
  1638. // easy way to avoid this duplication.
  1639. //
  1640. dwCachedSyntax = dwSyntaxId;
  1641. //
  1642. // Need to take the requested type to ADs types and from there to
  1643. // ldap types.
  1644. //
  1645. hr = UmiTypeToLdapTypeEnum(uCoercionType, &dwUserSyntax);
  1646. BAIL_ON_FAILURE(hr);
  1647. //
  1648. // We can convert to any requested type only if it is unknown.
  1649. //
  1650. if (dwCachedSyntax == LDAPTYPE_UNKNOWN) {
  1651. dwRequestedSyntax = dwUserSyntax;
  1652. }
  1653. else if (dwCachedSyntax == dwUserSyntax) {
  1654. //
  1655. // Easy one !
  1656. //
  1657. dwRequestedSyntax = dwCachedSyntax;
  1658. }
  1659. else {
  1660. //
  1661. // This means we already have a type. In this case the only
  1662. // coercion we allows is SD to binary blob and vice-versa.
  1663. //
  1664. if ((dwCachedSyntax == LDAPTYPE_SECURITY_DESCRIPTOR)
  1665. && (dwUserSyntax == LDAPTYPE_OCTETSTRING)
  1666. ) {
  1667. dwRequestedSyntax = dwUserSyntax;
  1668. }
  1669. else if ((dwCachedSyntax == LDAPTYPE_OCTETSTRING)
  1670. && (dwUserSyntax == LDAPTYPE_SECURITY_DESCRIPTOR)
  1671. ) {
  1672. dwRequestedSyntax = dwUserSyntax;
  1673. }
  1674. else {
  1675. BAIL_ON_FAILURE(hr = E_FAIL);
  1676. }
  1677. }
  1678. //
  1679. // If the data is in a state that needs conversion the fn will
  1680. // take care - note that if the source is already in the correct
  1681. // format then the HR will S_FALSE.
  1682. //
  1683. hr = LdapTypeBinaryToString(
  1684. dwRequestedSyntax,
  1685. &ldapSrcObjects,
  1686. &ldapSrcObjectsTmp
  1687. );
  1688. BAIL_ON_FAILURE(hr);
  1689. if (hr == S_OK) {
  1690. pldapObjects = &ldapSrcObjectsTmp;
  1691. }
  1692. else {
  1693. //
  1694. // We already have the data in the right format.
  1695. //
  1696. pldapObjects = &ldapSrcObjects;
  1697. hr = S_OK;
  1698. }
  1699. //
  1700. // Now that we have the correct data in pLdapObjects, we need
  1701. // to convert that to Umi Properties.
  1702. //
  1703. hr = LdapTypeToUmiTypeCopy(
  1704. *pldapObjects,
  1705. pProp,
  1706. dwStatus,
  1707. dwRequestedSyntax,
  1708. _pCreds,
  1709. _pszServerName,
  1710. uUmiFlag
  1711. );
  1712. BAIL_ON_FAILURE(hr);
  1713. //
  1714. // Stuff the name in the return value.
  1715. //
  1716. if (pProp) {
  1717. (*pProp)->pPropArray[0].pszPropertyName = AllocADsStr(pszName);
  1718. if (!(*pProp)->pPropArray[0].pszPropertyName) {
  1719. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  1720. }
  1721. }
  1722. error:
  1723. if (_fPropCacheMode) {
  1724. LdapTypeFreeLdapObjects(&ldapSrcObjects);
  1725. LdapTypeFreeLdapObjects(&ldapSrcObjectsTmp);
  1726. }
  1727. if (FAILED(hr)) {
  1728. SetLastStatus(hr);
  1729. hr = MapHrToUmiError(hr);
  1730. if (pProp) {
  1731. this->FreeMemory(0, (void *)*pProp);
  1732. *pProp = NULL;
  1733. }
  1734. }
  1735. RRETURN(hr);
  1736. }
  1737. //+---------------------------------------------------------------------------
  1738. // Function: CPropertyManager::FreeMemory (IUmiPropList support).
  1739. //
  1740. // Synopsis: Free memory pointed to. Note that the pointer should have
  1741. // originally come from a Get/GetAs call.
  1742. //
  1743. // Arguments: Ptr to data to be freed.
  1744. //
  1745. // Returns: HRESULT - S_OK or any failure error code.
  1746. //
  1747. // Modifies: *pMem is of course freed.
  1748. //
  1749. //----------------------------------------------------------------------------
  1750. STDMETHODIMP
  1751. CPropertyManager::FreeMemory(
  1752. ULONG uReserved,
  1753. LPVOID pMem
  1754. )
  1755. {
  1756. HRESULT hr = S_OK;
  1757. SetLastStatus(0);
  1758. if (uReserved) {
  1759. BAIL_ON_FAILURE(hr = E_INVALIDARG);
  1760. }
  1761. if (pMem) {
  1762. //
  1763. // At this time this has to be a pUmiProperty. Ideally we should
  1764. // tag this in some way so that we can check to make sure.
  1765. //
  1766. hr = FreeUmiPropertyValues((UMI_PROPERTY_VALUES *)pMem);
  1767. }
  1768. else {
  1769. hr = E_INVALIDARG;
  1770. }
  1771. error:
  1772. if (FAILED(hr)) {
  1773. SetLastStatus(hr);
  1774. hr = MapHrToUmiError(hr);
  1775. }
  1776. RRETURN(hr);
  1777. }
  1778. //+---------------------------------------------------------------------------
  1779. // Function: CPropertyManager::Delete (IUmiPropList support).
  1780. //
  1781. // Synopsis: Delete the named property from the cache.
  1782. //
  1783. // Arguments: pszName - Name of property to delete.
  1784. // uFlags - Standard flags parameter.
  1785. //
  1786. // Returns: E_NOTIMPL.
  1787. //
  1788. // Modifies: N/A.
  1789. //
  1790. //----------------------------------------------------------------------------
  1791. STDMETHODIMP
  1792. CPropertyManager::Delete(
  1793. IN LPCWSTR pszName,
  1794. IN ULONG uFlags
  1795. )
  1796. {
  1797. SetLastStatus(E_NOTIMPL);
  1798. RRETURN(E_NOTIMPL);
  1799. }
  1800. //+---------------------------------------------------------------------------
  1801. // Function: CPropertyManager::GetProps (IUmiPropList support).
  1802. //
  1803. // Synopsis: Gets the values for the attributes. This will read data
  1804. // from the server as needed.
  1805. //
  1806. // Arguments: self explanatory
  1807. //
  1808. //
  1809. // Returns: HRESULT - S_OK or any failure error code.
  1810. //
  1811. // Modifies: UMI_PROPERTY_VALUES* has the an array of values for the
  1812. // attributes. Note that there is no ordering specified
  1813. // for the return values.
  1814. //
  1815. //----------------------------------------------------------------------------
  1816. STDMETHODIMP
  1817. CPropertyManager::GetProps(
  1818. IN LPCWSTR* pszNames,
  1819. IN ULONG uNameCount,
  1820. IN ULONG uFlags,
  1821. OUT UMI_PROPERTY_VALUES **pProps
  1822. )
  1823. {
  1824. HRESULT hr = S_OK;
  1825. if ((uFlags != UMI_FLAG_GETPROPS_NAMES)
  1826. && (uFlags != UMI_FLAG_GETPROPS_SCHEMA)
  1827. ) {
  1828. BAIL_ON_FAILURE(hr = UMI_E_INVALID_FLAGS);
  1829. }
  1830. //
  1831. // Currently we support only getting the names of all the properties.
  1832. //
  1833. if (pszNames
  1834. || uNameCount
  1835. || !pProps
  1836. ) {
  1837. BAIL_ON_FAILURE(hr = E_INVALIDARG);
  1838. }
  1839. *pProps = NULL;
  1840. if (_fPropCacheMode) {
  1841. //
  1842. // Only UMI_FLAG_GETPROPS_NAMES is valid in this case.
  1843. //
  1844. if (uFlags != UMI_FLAG_GETPROPS_NAMES) {
  1845. BAIL_ON_FAILURE(hr = UMI_E_UNSUPPORTED_FLAGS);
  1846. }
  1847. hr = _pPropCache->GetPropertyNames(pProps);
  1848. }
  1849. else {
  1850. //
  1851. // Need to see what type of flag it is and extra check needed,
  1852. // if this is UMI_FLAGS_GETPROPS_SCHEMA.
  1853. //
  1854. if (uFlags == UMI_FLAG_GETPROPS_SCHEMA) {
  1855. LONG lVal;
  1856. hr = GetLongProperty(L"__GENUS", &lVal);
  1857. BAIL_ON_FAILURE(hr);
  1858. if (lVal != UMI_GENUS_CLASS) {
  1859. BAIL_ON_FAILURE(hr = UMI_E_UNSUPPORTED_FLAGS);
  1860. }
  1861. hr = GetPropertyNamesSchema(pProps);
  1862. }
  1863. else {
  1864. //
  1865. // Need to do get our static list.
  1866. //
  1867. hr = this->GetPropertyNames(pProps);
  1868. }
  1869. } // else for !propertyCacheMode.
  1870. error:
  1871. RRETURN(hr);
  1872. }
  1873. //+---------------------------------------------------------------------------
  1874. // Function: CPropertyManager::PutProps (IUmiPropList support).
  1875. //
  1876. // Synopsis: Puts the value for the attributes in the cache.
  1877. //
  1878. // Arguments: self explanatory
  1879. //
  1880. //
  1881. // Returns: HRESULT - S_OK or any failure error code.
  1882. //
  1883. // Modifies: Property cache for the object.
  1884. //
  1885. //----------------------------------------------------------------------------
  1886. HRESULT
  1887. CPropertyManager::PutProps(
  1888. IN LPCWSTR* pszNames,
  1889. IN ULONG uNameCount,
  1890. IN ULONG uFlags,
  1891. IN UMI_PROPERTY_VALUES *pProps
  1892. )
  1893. {
  1894. HRESULT hr = S_OK;
  1895. //
  1896. // When done - should get and put multiple work directly of the server ?
  1897. // That would take care off problems like 5 can be put in the cache
  1898. // but sixth cannot ...
  1899. //
  1900. SetLastStatus(E_NOTIMPL);
  1901. RRETURN(E_NOTIMPL);
  1902. }
  1903. //+---------------------------------------------------------------------------
  1904. // Function: CPropertyManager::PutFrom (IUmiPropList support).
  1905. //
  1906. // Synopsis: Clarify exactly what this is supposed to do ?
  1907. //
  1908. // Arguments: self explanatory
  1909. //
  1910. // Returns: HRESULT - S_OK or any failure error code.
  1911. //
  1912. // Modifies: Property cache for the object.
  1913. //
  1914. //----------------------------------------------------------------------------
  1915. STDMETHODIMP
  1916. CPropertyManager::PutFrom(
  1917. IN LPCWSTR pszName,
  1918. IN ULONG uFlags,
  1919. IN ULONG uBufferLength,
  1920. IN LPVOID pExistingMem
  1921. )
  1922. {
  1923. SetLastStatus(E_NOTIMPL);
  1924. RRETURN(E_NOTIMPL);
  1925. }
  1926. //
  1927. // PropertyManager methods that are not part of the IUmiPropList interface.
  1928. //
  1929. //+---------------------------------------------------------------------------
  1930. // Function: CPropertyManager::GetLastStatus
  1931. //
  1932. // Synopsis: Returns the error from the last operation on this object.
  1933. // For now only the status code is supported.
  1934. //
  1935. // Arguments: uFlags - Must be 0 for now.
  1936. // puSpecificStatus - Status is returned in this value.
  1937. // riid - IID requested on status obj.
  1938. // pStatusObj - Must be NULL for now.
  1939. //
  1940. //
  1941. // Returns: HRESULT - S_OK or any failure error code.
  1942. //
  1943. // Modifies: *puSpecificStatus with last status code.
  1944. //
  1945. //----------------------------------------------------------------------------
  1946. HRESULT
  1947. CPropertyManager::GetLastStatus(
  1948. ULONG uFlags,
  1949. ULONG *puSpecificStatus,
  1950. REFIID riid,
  1951. LPVOID *pStatusObj
  1952. )
  1953. {
  1954. if (!puSpecificStatus || pStatusObj) {
  1955. RRETURN(E_INVALIDARG);
  1956. }
  1957. if (uFlags) {
  1958. RRETURN(UMI_E_INVALID_FLAGS);
  1959. }
  1960. *puSpecificStatus = _ulStatus;
  1961. RRETURN(S_OK);
  1962. }
  1963. //+---------------------------------------------------------------------------
  1964. // Function: CPropertyManager::AddProperty.
  1965. //
  1966. // Synopsis: Updates the value of the property to the interface
  1967. // property cache. This fn is called only in interface mode.
  1968. // If necessary the property will be added to the cache.
  1969. //
  1970. // Arguments: self explanatory
  1971. //
  1972. //
  1973. // Returns: HRESULT - S_OK or any failure error code.
  1974. //
  1975. // Modifies: Changes the internal property table.
  1976. //
  1977. //----------------------------------------------------------------------------
  1978. HRESULT
  1979. CPropertyManager::AddProperty(
  1980. LPCWSTR szPropertyName,
  1981. UMI_PROPERTY umiProperty
  1982. )
  1983. {
  1984. HRESULT hr = S_OK;
  1985. DWORD dwIndex = (DWORD) -1;
  1986. BOOL fAddedName = FALSE;
  1987. //
  1988. // Make sure we do not have property in the cache.
  1989. //
  1990. hr = FindProperty(szPropertyName, &dwIndex);
  1991. if (FAILED(hr)) {
  1992. //
  1993. // We actually need to add this property in our list.
  1994. //
  1995. hr = AddToTable(szPropertyName, &dwIndex);
  1996. fAddedName = TRUE;
  1997. }
  1998. BAIL_ON_FAILURE(hr);
  1999. //
  2000. // At this point we can just dump the value into the cache.
  2001. //
  2002. hr = UpdateProperty(
  2003. dwIndex,
  2004. umiProperty
  2005. );
  2006. BAIL_ON_FAILURE(hr);
  2007. error:
  2008. if (FAILED(hr) && fAddedName) {
  2009. //
  2010. // Do we delete the name from the cache.
  2011. //
  2012. DeleteProperty(dwIndex);
  2013. }
  2014. RRETURN(hr);
  2015. }
  2016. //+---------------------------------------------------------------------------
  2017. // Function: CPropertyManager::UpdateProperty.
  2018. //
  2019. // Synopsis: Updates the value of an interface property in the local cache.
  2020. // The assumption is that this function is only called with from
  2021. // AddProperty (or anywhere else where we have the correct index).
  2022. //
  2023. // Arguments: dwIndex - index in our table of the property to update
  2024. // UMI_PROPERTY - the value to add to our table, note that
  2025. // if the operation is delete we should remove the element
  2026. // from our table (value returned if any will be default value
  2027. // for subsequent get calls).
  2028. //
  2029. // Returns: HRESULT - S_OK or any failure error code.
  2030. //
  2031. // Modifies: Underlying data in the cache is changed
  2032. //
  2033. //----------------------------------------------------------------------------
  2034. HRESULT
  2035. CPropertyManager::UpdateProperty(
  2036. DWORD dwIndex,
  2037. UMI_PROPERTY umiProp
  2038. )
  2039. {
  2040. HRESULT hr = E_NOTIMPL;
  2041. DWORD dwFlags, dwCacheSyntaxId, dwNumElements;
  2042. PUMI_PROPERTY pUmiProperty = NULL;
  2043. if (!_pIntfProperties) {
  2044. //
  2045. // Should we check the index ? It is after all an internal
  2046. // value, so it should not be wrong.
  2047. //
  2048. BAIL_ON_FAILURE(hr = E_FAIL);
  2049. }
  2050. //
  2051. // Only update and delete are really supported.
  2052. //
  2053. if ((umiProp.uOperationType != UMI_OPERATION_UPDATE)
  2054. && (umiProp.uOperationType != UMI_OPERATION_DELETE_ALL_MATCHES)) {
  2055. BAIL_ON_FAILURE(hr = E_INVALIDARG);
  2056. }
  2057. if (_pIntfProperties[dwIndex].pUmiProperty) {
  2058. //
  2059. // Free the current data in the table and set initial values.
  2060. //
  2061. hr = FreeOneUmiProperty(*(_pIntfProperties[dwIndex].pUmiProperty));
  2062. BAIL_ON_FAILURE(hr);
  2063. FreeADsMem(_pIntfProperties[dwIndex].pUmiProperty);
  2064. _pIntfProperties[dwIndex].pUmiProperty = NULL;
  2065. _pIntfProperties[dwIndex].dwFlags = 0;
  2066. _pIntfProperties[dwIndex].dwSyntaxId = 0;
  2067. }
  2068. //
  2069. // Copy the value to temp variable, so we can handle failures gracefully.
  2070. //
  2071. hr = CopyUmiProperty(
  2072. umiProp,
  2073. &pUmiProperty
  2074. );
  2075. BAIL_ON_FAILURE(hr);
  2076. _pIntfProperties[dwIndex].pUmiProperty = pUmiProperty;
  2077. error:
  2078. RRETURN(hr);
  2079. }
  2080. //+---------------------------------------------------------------------------
  2081. // Function: CPropertyManager::FindProperty.
  2082. //
  2083. // Synopsis: Searches for the specified property in the local cache.
  2084. //
  2085. // Arguments: szPropertyName, name of property.
  2086. // pdwIndex - pointer to DWORD with index in table.
  2087. //
  2088. // Returns: HRESULT - S_OK or E_ADS_PROPERTY_NOT_FOUND.
  2089. //
  2090. // Modifies: *pdwIndex to.
  2091. //
  2092. //----------------------------------------------------------------------------
  2093. HRESULT
  2094. CPropertyManager::FindProperty(
  2095. LPCWSTR szPropertyName,
  2096. PDWORD pdwIndex
  2097. )
  2098. {
  2099. DWORD dwIndex;
  2100. if (!_pIntfProperties) {
  2101. RRETURN(E_ADS_PROPERTY_NOT_FOUND);
  2102. }
  2103. for (dwIndex = 0; dwIndex < _dwMaxProperties; dwIndex++) {
  2104. if (_wcsicmp(
  2105. _pIntfProperties[dwIndex].pszPropertyName,
  2106. szPropertyName
  2107. ) == 0) {
  2108. *pdwIndex = dwIndex;
  2109. RRETURN(S_OK);
  2110. }
  2111. }
  2112. RRETURN(E_ADS_PROPERTY_NOT_FOUND);
  2113. }
  2114. //+---------------------------------------------------------------------------
  2115. // Function: CPropertyManager::DeleteProperty.
  2116. //
  2117. // Synopsis: Deletes the property specified from the cahce.
  2118. //
  2119. // Arguments: Index to element to delete.
  2120. //
  2121. //
  2122. // Returns: HRESULT - S_OK or any failure error code.
  2123. //
  2124. // Modifies: Underlying data in the cache is changed.
  2125. //
  2126. //----------------------------------------------------------------------------
  2127. HRESULT
  2128. CPropertyManager::DeleteProperty(
  2129. DWORD dwIndex
  2130. )
  2131. {
  2132. HRESULT hr = S_OK;
  2133. INTF_PROPERTY* pIntfProp = NULL;
  2134. if (_pIntfProperties && ((_dwMaxProperties-1) < dwIndex)) {
  2135. //
  2136. // Valid property in cache.
  2137. //
  2138. pIntfProp = _pIntfProperties + dwIndex;
  2139. ADsAssert(pIntfProp);
  2140. if (pIntfProp->pszPropertyName) {
  2141. FreeADsStr(pIntfProp->pszPropertyName);
  2142. pIntfProp->pszPropertyName = NULL;
  2143. }
  2144. //
  2145. // Now Copy over the rest of the data here.
  2146. //
  2147. }
  2148. else {
  2149. hr = E_FAIL;
  2150. }
  2151. RRETURN (hr);
  2152. }
  2153. //+---------------------------------------------------------------------------
  2154. // Function: CPropertyManager::FlushPropertyCache.
  2155. //
  2156. // Synopsis: Clear all internal data in the property cache.
  2157. //
  2158. // Arguments:
  2159. //
  2160. // Returns: N/A
  2161. //
  2162. // Modifies: Underlying data in the cache is changed
  2163. //
  2164. //----------------------------------------------------------------------------
  2165. VOID
  2166. CPropertyManager::flushpropertycache()
  2167. {
  2168. //
  2169. // Free any data in our table
  2170. if (_pIntfProperties) {
  2171. for (DWORD dwCtr = 0; (dwCtr < _dwMaxProperties); dwCtr++) {
  2172. INTF_PROPERTY *pIntfProp = (PINTF_PROPERTY)_pIntfProperties+ dwCtr;
  2173. if (pIntfProp) {
  2174. if (pIntfProp->pszPropertyName) {
  2175. FreeADsStr(pIntfProp->pszPropertyName);
  2176. pIntfProp->pszPropertyName = NULL;
  2177. }
  2178. }
  2179. }
  2180. //
  2181. // Now free the array of pointers.
  2182. //
  2183. FreeADsMem((void *) _pIntfProperties);
  2184. _pIntfProperties = NULL;
  2185. }
  2186. }
  2187. //+---------------------------------------------------------------------------
  2188. // Function: CPropertyManager::ClearAllPropertyFlags.
  2189. //
  2190. // Synopsis: Resets all property flags to zero.
  2191. //
  2192. // Arguments: None.
  2193. //
  2194. // Returns: HRESULT - S_OK or any failure error code.
  2195. //
  2196. // Modifies: Underlying data in the cache is changed.
  2197. //
  2198. //
  2199. //----------------------------------------------------------------------------
  2200. HRESULT
  2201. CPropertyManager::ClearAllPropertyFlags(
  2202. VOID
  2203. )
  2204. {
  2205. RRETURN(E_NOTIMPL);
  2206. }
  2207. //+---------------------------------------------------------------------------
  2208. // Function: CPropertyManager::GetPropertyNames.
  2209. //
  2210. // Synopsis: Returns list of names of interface properties available.
  2211. //
  2212. // Arguments: out params only
  2213. //
  2214. // Returns: HRESULT - S_OK or any failure error code
  2215. //
  2216. // Modifies: ppStringsNames to point to valid array of strings.
  2217. // pUlCount to point to number of strings in the array.
  2218. //
  2219. //----------------------------------------------------------------------------
  2220. HRESULT
  2221. CPropertyManager::GetPropertyNames(
  2222. PUMI_PROPERTY_VALUES *pUmiProps
  2223. )
  2224. {
  2225. HRESULT hr = S_OK;
  2226. PUMI_PROPERTY_VALUES pUmiPropVals = NULL;
  2227. PUMI_PROPERTY pUmiProperties = NULL;
  2228. DWORD dwCtr, dwPropCount = 0;
  2229. pUmiPropVals = (PUMI_PROPERTY_VALUES) AllocADsMem(
  2230. sizeof(UMI_PROPERTY_VALUES)
  2231. );
  2232. if (!pUmiPropVals) {
  2233. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  2234. }
  2235. //
  2236. // Need to count the properties.
  2237. //
  2238. while (_pStaticPropData[dwPropCount].pszPropertyName) {
  2239. dwPropCount++;
  2240. }
  2241. if (!dwPropCount) {
  2242. *pUmiProps = pUmiPropVals;
  2243. RRETURN(S_OK);
  2244. }
  2245. pUmiProperties = (PUMI_PROPERTY) AllocADsMem(
  2246. sizeof(UMI_PROPERTY) * dwPropCount
  2247. );
  2248. if (!pUmiProperties) {
  2249. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  2250. }
  2251. //
  2252. // Need to go through the table and alloc the values.
  2253. //
  2254. for (dwCtr = 0; dwCtr < dwPropCount; dwCtr++) {
  2255. pUmiProperties[dwCtr].pszPropertyName =
  2256. AllocADsStr(_pStaticPropData[dwCtr].pszPropertyName);
  2257. if (!pUmiProperties[dwCtr].pszPropertyName) {
  2258. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  2259. }
  2260. pUmiProperties[dwCtr].uType = UMI_TYPE_NULL;
  2261. }
  2262. pUmiPropVals->pPropArray = pUmiProperties;
  2263. pUmiPropVals->uCount = dwPropCount;
  2264. *pUmiProps = pUmiPropVals;
  2265. RRETURN(S_OK);
  2266. error :
  2267. if (pUmiProperties) {
  2268. for (dwCtr = 0; dwCtr < dwPropCount; dwCtr++) {
  2269. if (pUmiProperties[dwCtr].pszPropertyName) {
  2270. FreeADsStr(pUmiProperties[dwCtr].pszPropertyName);
  2271. }
  2272. }
  2273. FreeADsMem(pUmiProperties);
  2274. }
  2275. if (pUmiPropVals) {
  2276. FreeADsMem(pUmiPropVals);
  2277. }
  2278. RRETURN(hr);
  2279. }
  2280. //+---------------------------------------------------------------------------
  2281. // Function: CPropertyManager::GetPropertyNamesSchema
  2282. //
  2283. // Synopsis: Returns list of the names and types of the properties this
  2284. // object can contain. Note that this method is valid only if the
  2285. // underlying object is an instance of class Class (schema class).
  2286. //
  2287. // Arguments: out params only
  2288. //
  2289. // Returns: HRESULT - S_OK or any failure error code
  2290. //
  2291. // Modifies:
  2292. //
  2293. //----------------------------------------------------------------------------
  2294. HRESULT
  2295. CPropertyManager::GetPropertyNamesSchema(
  2296. PUMI_PROPERTY_VALUES *pUmiProps
  2297. )
  2298. {
  2299. HRESULT hr = S_OK;
  2300. IADsUmiHelperPrivate *pIADsUmiPriv = NULL;
  2301. // Array of ptr to PROPERTYINFO
  2302. PPROPERTYINFO *pPropArray = NULL;
  2303. DWORD dwPropCount = 0;
  2304. PUMI_PROPERTY_VALUES pUmiPropVals = NULL;
  2305. PUMI_PROPERTY pUmiProperties = NULL;
  2306. //
  2307. // Need a ptr to the helper routine.
  2308. //
  2309. hr = this->_pIADs->QueryInterface(
  2310. IID_IADsUmiHelperPrivate,
  2311. (void **) &pIADsUmiPriv
  2312. );
  2313. if (hr == E_NOINTERFACE) {
  2314. BAIL_ON_FAILURE(hr = UMI_E_UNSUPPORTED_FLAGS);
  2315. }
  2316. hr = pIADsUmiPriv->GetPropertiesHelper(
  2317. (void**) &pPropArray,
  2318. &dwPropCount
  2319. );
  2320. BAIL_ON_FAILURE(hr);
  2321. //
  2322. // Need to prepare the return values.
  2323. //
  2324. pUmiPropVals = (PUMI_PROPERTY_VALUES) AllocADsMem(
  2325. sizeof(UMI_PROPERTY_VALUES)
  2326. );
  2327. if (!pUmiPropVals) {
  2328. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  2329. }
  2330. if (!dwPropCount) {
  2331. *pUmiProps = pUmiPropVals;
  2332. RRETURN(S_OK);
  2333. }
  2334. pUmiProperties = (PUMI_PROPERTY) AllocADsMem(
  2335. sizeof(UMI_PROPERTY) * dwPropCount
  2336. );
  2337. if (!pUmiProperties) {
  2338. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  2339. }
  2340. for (DWORD dwCtr = 0; dwCtr < dwPropCount; dwCtr++) {
  2341. DWORD dwSyntaxId = 0;
  2342. pUmiProperties[dwCtr].pszPropertyName =
  2343. AllocADsStr(pPropArray[dwCtr]->pszPropertyName);
  2344. if (!pUmiProperties[dwCtr].pszPropertyName) {
  2345. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  2346. }
  2347. //
  2348. // Need to update the type with the type from the schema.
  2349. //
  2350. dwSyntaxId = LdapGetSyntaxIdOfAttribute(
  2351. pPropArray[dwCtr]->pszSyntax
  2352. );
  2353. //
  2354. // If we get dwSyntaxId == -1 we could not find the entry in
  2355. // our table.
  2356. //
  2357. if (dwSyntaxId == -1) {
  2358. pUmiProperties[dwCtr].uType = UMI_TYPE_UNDEFINED;
  2359. }
  2360. else {
  2361. hr = ConvertLdapSyntaxIdToUmiType(
  2362. dwSyntaxId,
  2363. (pUmiProperties[dwCtr].uType)
  2364. );
  2365. if (FAILED(hr)) {
  2366. hr = S_OK;
  2367. //
  2368. // Cannot do anything about this.
  2369. //
  2370. pUmiProperties[dwCtr].uType = UMI_TYPE_UNDEFINED;
  2371. }
  2372. //
  2373. // If this property is multivalued.
  2374. //
  2375. if (!pPropArray[dwCtr]->fSingleValued) {
  2376. pUmiProperties[dwCtr].uType |= UMI_TYPE_ARRAY_FLAG;
  2377. }
  2378. }
  2379. } // for each property.
  2380. pUmiPropVals->pPropArray = pUmiProperties;
  2381. pUmiPropVals->uCount = dwPropCount;
  2382. *pUmiProps = pUmiPropVals;
  2383. error:
  2384. if (pIADsUmiPriv) {
  2385. pIADsUmiPriv->Release();
  2386. }
  2387. //
  2388. // Need to free the array not the elements which are ptrs into
  2389. // the global parsed schema's we hold.
  2390. //
  2391. if (pPropArray) {
  2392. FreeADsMem(pPropArray);
  2393. }
  2394. RRETURN(hr);
  2395. }
  2396. //+---------------------------------------------------------------------------
  2397. // Function: CPropertyManager::GetInterfaceProperty
  2398. //
  2399. // Synopsis: Gets the interface property from the owning object or the
  2400. // default value and packages the value as an UMI_PROPERTY_VALUE.
  2401. //
  2402. // Arguments: pszName - name of property to get.
  2403. // uFlags - flags has to be zero for now.
  2404. // ppProp - value is returned in this ptr.
  2405. // dwTableIndex - index to entry in table describing this item.
  2406. //
  2407. // Returns: HRESULT - S_OK or any failure error code
  2408. //
  2409. // Modifies: ppProp which will point to return value if the fn succeeds.
  2410. //
  2411. //----------------------------------------------------------------------------
  2412. HRESULT
  2413. CPropertyManager::GetInterfaceProperty(
  2414. LPCWSTR pszName,
  2415. ULONG uFlags,
  2416. UMI_PROPERTY_VALUES **ppProp,
  2417. DWORD dwTableIndex
  2418. )
  2419. {
  2420. HRESULT hr;
  2421. ULONG ulOperationAllowed = _pStaticPropData[dwTableIndex].ulOpCode;
  2422. ULONG ulVal;
  2423. LONG lGenus;
  2424. LPWSTR pszStringVal = NULL;
  2425. BSTR bstrRetVal = NULL, bstrTempVal = NULL;
  2426. LPWSTR pszUmiUrl = NULL;
  2427. IADsObjectOptions *pObjOpt = NULL;
  2428. VARIANT vVariant;
  2429. DWORD dwIndex;
  2430. PUMI_PROPERTY pUmiPropLocal = NULL;
  2431. IUnknown *pUnk = NULL;
  2432. IUmiObject *pUmiObj = NULL;
  2433. BOOL fUnkPtr = FALSE;
  2434. BOOL fClassInstance = FALSE;
  2435. VariantInit(&vVariant);
  2436. if (!_pUnk) {
  2437. BAIL_ON_FAILURE(hr = E_FAIL);
  2438. }
  2439. //
  2440. // If the property is READ/WRITE, we need to see if there is a value
  2441. // in the propCache. If yes, return that. If not return the default
  2442. // value.
  2443. //
  2444. if (ulOperationAllowed == OPERATION_CODE_READWRITE) {
  2445. hr = FindProperty(pszName, &dwIndex);
  2446. //
  2447. // If it succeeded it was updated in the cache.
  2448. //
  2449. if (SUCCEEDED(hr)) {
  2450. hr = CopyUmiProperty(
  2451. *(_pIntfProperties[dwIndex].pUmiProperty),
  2452. &pUmiPropLocal
  2453. );
  2454. BAIL_ON_FAILURE(hr);
  2455. //
  2456. // We need to free the name of the first property cause
  2457. // that is allocated again by the Get call.
  2458. //
  2459. if (pUmiPropLocal && pUmiPropLocal->pszPropertyName) {
  2460. FreeADsStr(pUmiPropLocal->pszPropertyName);
  2461. pUmiPropLocal->pszPropertyName = NULL;
  2462. }
  2463. //
  2464. // Got the property need to package in umi property values.
  2465. //
  2466. *ppProp = (PUMI_PROPERTY_VALUES) AllocADsMem(
  2467. sizeof(UMI_PROPERTY_VALUES)
  2468. );
  2469. if (!*ppProp) {
  2470. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  2471. }
  2472. (*ppProp)->pPropArray = pUmiPropLocal;
  2473. (*ppProp)->uCount = 1;
  2474. RRETURN(hr);
  2475. } // value found in cache
  2476. else {
  2477. //
  2478. // Setting this should trigger a read of the default
  2479. // value for this property.
  2480. //
  2481. ulOperationAllowed = OPERATION_CODE_READABLE;
  2482. }
  2483. }
  2484. //
  2485. // We need to check for the securityDescriptor as that needs
  2486. // some special handling.
  2487. //
  2488. if (!_wcsicmp(pszName, L"__SECURITY_DESCRIPTOR")) {
  2489. //
  2490. // Need to read this from the actual object.
  2491. //
  2492. hr = _pUnk->QueryInterface(IID_IUmiObject, (void **) &pUmiObj);
  2493. BAIL_ON_FAILURE(hr);
  2494. hr = pUmiObj->GetAs(
  2495. L"ntSecurityDescriptor",
  2496. uFlags,
  2497. UMI_TYPE_OCTETSTRING,
  2498. ppProp
  2499. );
  2500. if (SUCCEEDED(hr)) {
  2501. //
  2502. // Need to make sure that we do not set name twice.
  2503. //
  2504. if (*ppProp
  2505. && (*ppProp)[0].pPropArray
  2506. && (*ppProp)[0].pPropArray[0].pszPropertyName
  2507. ) {
  2508. FreeADsStr((*ppProp)[0].pPropArray[0].pszPropertyName);
  2509. (*ppProp)[0].pPropArray[0].pszPropertyName = NULL;
  2510. }
  2511. }
  2512. //
  2513. // This seems the cleanest ...
  2514. //
  2515. goto error;
  2516. }
  2517. //
  2518. // If the property is only readable, then get it from owning object.
  2519. // If not get the value from cache or use defualt value as appropriate.
  2520. //
  2521. if (ulOperationAllowed == OPERATION_CODE_READABLE) {
  2522. hr = GetLongProperty(L"__GENUS", &lGenus);
  2523. if (FAILED(hr)) {
  2524. //
  2525. // There was no genus property = connection for example.
  2526. //
  2527. fClassInstance = FALSE;
  2528. }
  2529. else if (lGenus == UMI_GENUS_CLASS) {
  2530. fClassInstance = TRUE;
  2531. }
  2532. //
  2533. // The value can be a string/long for now and it has to
  2534. // be either the default value or the value from the owning object.
  2535. //
  2536. switch (_pStaticPropData[dwTableIndex].ulDataType) {
  2537. case UMI_TYPE_I4:
  2538. //
  2539. // Use default value from the static table.
  2540. //
  2541. vVariant.lVal = _pStaticPropData[dwTableIndex].umiVal.lValue[0];
  2542. hr = ConvertVariantLongToUmiProp(vVariant, ppProp);
  2543. break;
  2544. case UMI_TYPE_BOOL:
  2545. //
  2546. // Use default value from table.
  2547. //
  2548. vVariant.lVal = _pStaticPropData[dwTableIndex].umiVal.bValue[0];
  2549. hr = ConvertVariantLongToUmiProp(vVariant, ppProp);
  2550. (*ppProp)[0].pPropArray[0].uType = UMI_TYPE_BOOL;
  2551. break;
  2552. case UMI_TYPE_LPWSTR:
  2553. //
  2554. // In this case it has to be NULL.
  2555. //
  2556. hr = GetEmptyLPWSTRProp(ppProp);
  2557. break;
  2558. case 9999:
  2559. if (!_pIADs) {
  2560. //
  2561. // Nothing we can do here !
  2562. //
  2563. BAIL_ON_FAILURE(hr = E_FAIL);
  2564. }
  2565. if (!_wcsicmp(pszName, L"__Path")) {
  2566. hr = _pIADs->get_ADsPath(&bstrRetVal);
  2567. }
  2568. else if (!_wcsicmp(pszName, L"__Class")) {
  2569. if (fClassInstance) {
  2570. //
  2571. // For classes, the class is the name,
  2572. // not "class" itself.
  2573. //
  2574. hr = _pIADs->get_Name(&bstrRetVal);
  2575. }
  2576. else {
  2577. hr = _pIADs->get_Class(&bstrRetVal);
  2578. }
  2579. }
  2580. else if (!_wcsicmp(pszName, L"__KEY")) {
  2581. hr = _pIADs->get_Name(&bstrRetVal);
  2582. BAIL_ON_FAILURE(hr);
  2583. if (SUCCEEDED(hr)) {
  2584. hr = HelperConvertNameToKey(bstrRetVal, &pszUmiUrl);
  2585. }
  2586. }
  2587. else if (!_wcsicmp(pszName, L"__GUID")) {
  2588. hr = _pIADs->get_GUID(&bstrRetVal);
  2589. }
  2590. else if (!_wcsicmp(pszName, L"__Parent")) {
  2591. hr = _pIADs->get_Parent(&bstrRetVal);
  2592. if (SUCCEEDED(hr)) {
  2593. hr = ADsPathToUmiURL(bstrRetVal, &pszUmiUrl);
  2594. }
  2595. }
  2596. else if (!_wcsicmp(pszName, L"__Schema")) {
  2597. hr = _pIADs->get_Schema(&bstrRetVal);
  2598. //
  2599. // Now need to bind to this object.
  2600. //
  2601. if (SUCCEEDED(hr)) {
  2602. hr = GetObject(
  2603. bstrRetVal,
  2604. *_pCreds,
  2605. (void **) &pUnk
  2606. );
  2607. BAIL_ON_FAILURE(hr);
  2608. fUnkPtr = TRUE;
  2609. }
  2610. }
  2611. else if (!_wcsicmp(pszName, L"__URL")) {
  2612. hr = _pIADs->get_ADsPath(&bstrTempVal);
  2613. if (SUCCEEDED(hr)) {
  2614. hr = ADsPathToUmiURL(bstrTempVal, &pszUmiUrl);
  2615. }
  2616. }
  2617. else if (!_wcsicmp(pszName, L"__Name")) {
  2618. if (fClassInstance) {
  2619. hr = _pIADs->get_Name(&bstrRetVal);
  2620. } else {
  2621. hr = HelperGetUmiRelUrl(_pIADs, &bstrRetVal);
  2622. }
  2623. }
  2624. else if (!_wcsicmp(pszName, L"__RELURL")) {
  2625. hr = HelperGetUmiRelUrl(_pIADs, &bstrRetVal);
  2626. }
  2627. else if (!_wcsicmp(pszName, L"__RELPATH")) {
  2628. hr = HelperGetUmiRelUrl(_pIADs, &bstrRetVal);
  2629. }
  2630. else if (!_wcsicmp(pszName, L"__FULLRELURL")) {
  2631. //
  2632. // Same as __RELURL, __NAME and __RELPATH
  2633. //
  2634. hr = HelperGetUmiRelUrl(_pIADs, &bstrRetVal);
  2635. }
  2636. else if (!_wcsicmp(pszName, L"__PADS_SCHEMA_CONTAINER_PATH")) {
  2637. hr = HelperGetUmiSchemaContainerPath(_pIADs, &bstrRetVal);
  2638. }
  2639. else if (!_wcsicmp(pszName, L"__SUPERCLASS")) {
  2640. if (!fClassInstance) {
  2641. //
  2642. // Only supported if this is a class.
  2643. //
  2644. hr = E_FAIL;
  2645. }
  2646. else {
  2647. hr = HelperGetUmiDerivedFrom(_pIADs, &bstrRetVal);
  2648. }
  2649. }
  2650. else {
  2651. hr = E_FAIL;
  2652. }
  2653. BAIL_ON_FAILURE(hr);
  2654. //
  2655. // If not schema then it has to be a string.
  2656. //
  2657. if (!fUnkPtr) {
  2658. hr = ConvertBSTRToUmiProp(
  2659. pszUmiUrl ? pszUmiUrl:bstrRetVal,
  2660. ppProp
  2661. );
  2662. }
  2663. else {
  2664. hr = ConvertIUnkToUmiProp(
  2665. pUnk,
  2666. IID_IUmiObject,
  2667. ppProp
  2668. );
  2669. }
  2670. break;
  2671. default:
  2672. hr = E_FAIL;
  2673. } // end of switch
  2674. BAIL_ON_FAILURE(hr);
  2675. } // opeartion code is READABLE.
  2676. else {
  2677. hr = E_FAIL;
  2678. }
  2679. error:
  2680. if (pObjOpt) {
  2681. pObjOpt->Release();
  2682. }
  2683. VariantClear(&vVariant);
  2684. if (bstrRetVal) {
  2685. SysFreeString(bstrRetVal);
  2686. }
  2687. if (bstrTempVal) {
  2688. SysFreeString(bstrTempVal);
  2689. }
  2690. if (pszUmiUrl) {
  2691. FreeADsStr(pszUmiUrl);
  2692. }
  2693. if (pUnk) {
  2694. pUnk->Release();
  2695. }
  2696. if (pUmiObj) {
  2697. pUmiObj->Release();
  2698. }
  2699. RRETURN(hr);
  2700. }
  2701. //+---------------------------------------------------------------------------
  2702. // Function: CPropertyManager::DeleteSDIfPresent --- Helper method.
  2703. //
  2704. // Synopsis: Helps remove the SD from the property cache so that we do not
  2705. // set it when we Commit the changes.
  2706. //
  2707. // Arguments: N/A.
  2708. //
  2709. // Returns: HRESULT - S_OK or any failure error code
  2710. //
  2711. // Modifies: Underlying property cache.
  2712. //
  2713. //----------------------------------------------------------------------------
  2714. HRESULT
  2715. CPropertyManager::DeleteSDIfPresent()
  2716. {
  2717. HRESULT hr = S_OK;
  2718. DWORD dwIndex = 0;
  2719. if (!_fPropCacheMode) {
  2720. //
  2721. // Sanity check, should never be here.
  2722. //
  2723. RRETURN(S_OK);
  2724. }
  2725. if (!_pPropCache) {
  2726. //
  2727. // Want to delete SD when we do not have a cache - weird.
  2728. //
  2729. RRETURN(S_OK);
  2730. }
  2731. hr = _pPropCache->findproperty(L"ntSecurityDescriptor", &dwIndex);
  2732. if (FAILED(hr)) {
  2733. RRETURN(S_OK);
  2734. }
  2735. else {
  2736. //
  2737. // Get rid of this from the cache.
  2738. //
  2739. _pPropCache->deleteproperty(dwIndex);
  2740. }
  2741. RRETURN(S_OK);
  2742. }
  2743. //+---------------------------------------------------------------------------
  2744. // Function: CPropertyManager::GetIndexInStaticTable
  2745. //
  2746. // Synopsis: Verifies that the named property can be found in the list of
  2747. // valid properties and returns the index.
  2748. //
  2749. // Arguments: Self explanatory.
  2750. //
  2751. // Returns: S_OK or E_ADS_PROPERTY_NOT_FOUND as appropriate.
  2752. //
  2753. // Modifies: N/A.
  2754. //
  2755. //----------------------------------------------------------------------------
  2756. HRESULT
  2757. CPropertyManager::GetIndexInStaticTable(
  2758. LPCWSTR pszName,
  2759. DWORD &dwIndex
  2760. )
  2761. {
  2762. for (DWORD dwCtr = 0;
  2763. _pStaticPropData[dwCtr].pszPropertyName;
  2764. dwCtr++ ) {
  2765. if (!_wcsicmp(
  2766. pszName,
  2767. _pStaticPropData[dwCtr].pszPropertyName
  2768. )) {
  2769. dwIndex = dwCtr;
  2770. RRETURN(S_OK);
  2771. }
  2772. }
  2773. RRETURN(E_ADS_PROPERTY_NOT_FOUND);
  2774. }
  2775. //+---------------------------------------------------------------------------
  2776. // Function: CPropertyManager::VerifyIfValidProperty.
  2777. //
  2778. // Synopsis: Makes sure that a valid interface property is being set. This
  2779. // function is called internally if we know we are not in the
  2780. // property cache mode. The internal static table pointer is used to
  2781. // verify the property.
  2782. //
  2783. // Arguments: Self explanatory.
  2784. //
  2785. // Returns: Bool - True or False as appropriate.
  2786. //
  2787. // Modifies: N/A.
  2788. //
  2789. //----------------------------------------------------------------------------
  2790. BOOL
  2791. CPropertyManager::VerifyIfValidProperty(
  2792. LPCWSTR pszPropertyName,
  2793. UMI_PROPERTY umiProperty
  2794. )
  2795. {
  2796. DWORD dwIndex;
  2797. //
  2798. // if _pStaticPropData is NULL then there are no interface properties.
  2799. // If the count is zero, then the only operation is delete.
  2800. //
  2801. if ((!_pStaticPropData)
  2802. || ((umiProperty.uCount == 0)
  2803. && (umiProperty.uOperationType != UMI_OPERATION_DELETE_ALL_MATCHES)
  2804. )
  2805. )
  2806. {
  2807. return FALSE;
  2808. }
  2809. if (SUCCEEDED(GetIndexInStaticTable(
  2810. pszPropertyName,
  2811. dwIndex
  2812. ))
  2813. ) {
  2814. //
  2815. // Verify type and if property can be changed.
  2816. // If the types do not match we should still allow 9999 for
  2817. // things like __SECURITY_DESCRIPTOR that can be changed.
  2818. // If the attribute cannot be written, then the next part of
  2819. // the check will fail, so you still wont be able to write
  2820. // things the __URL property.
  2821. //
  2822. if (((_pStaticPropData[dwIndex].ulDataType == umiProperty.uType)
  2823. || (_pStaticPropData[dwIndex].ulDataType == 9999))
  2824. && (_pStaticPropData[dwIndex].ulOpCode
  2825. != OPERATION_CODE_READABLE)
  2826. ) {
  2827. //
  2828. // Need to make sure count is correct.
  2829. //
  2830. if ((umiProperty.uCount > 1)
  2831. && (!_pStaticPropData[dwIndex].fMultiValued)
  2832. ) {
  2833. return FALSE;
  2834. }
  2835. return TRUE;
  2836. }
  2837. }
  2838. //
  2839. // Either we did not satisfy requirements or not found
  2840. //
  2841. return FALSE;
  2842. }
  2843. HRESULT
  2844. CPropertyManager::AddToTable(
  2845. LPCWSTR pszPropertyName,
  2846. PDWORD pdwIndex
  2847. )
  2848. {
  2849. HRESULT hr = S_OK;
  2850. PINTF_PROPERTY pNewProperty = NULL;
  2851. //
  2852. // Check to see if the table is already there. If not create
  2853. // the table with potential to store upto 10 entries. This should
  2854. // suffice unless we have more properties. Set the current pointer
  2855. // and current top appropriately.
  2856. //
  2857. if (!_pIntfProperties) {
  2858. _pIntfProperties = (PINTF_PROPERTY) AllocADsMem(
  2859. sizeof(INTF_PROPERTY) * MAX_PROPMGR_PROP_COUNT
  2860. );
  2861. if (!_pIntfProperties) {
  2862. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  2863. }
  2864. _dwMaxProperties = 0;
  2865. _dwMaxLimit = MAX_PROPMGR_PROP_COUNT;
  2866. }
  2867. if ((_dwMaxProperties+1) < _dwMaxLimit) {
  2868. //
  2869. // We can add this property to the table.
  2870. //
  2871. DWORD dwTop;
  2872. dwTop = _dwMaxProperties++;
  2873. _pIntfProperties[dwTop].pszPropertyName =
  2874. AllocADsStr(pszPropertyName);
  2875. if (!_pIntfProperties[dwTop].pszPropertyName) {
  2876. //
  2877. // Reset the count.
  2878. //
  2879. _dwMaxProperties--;
  2880. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  2881. }
  2882. *pdwIndex = dwTop;
  2883. }
  2884. else {
  2885. //
  2886. // We do not have space in the table - return an error.
  2887. //
  2888. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  2889. }
  2890. error:
  2891. RRETURN(hr);
  2892. }
  2893. //+---------------------------------------------------------------------------
  2894. // Function: CPropertyManager::GetStringProperty.
  2895. //
  2896. // Synopsis: Retrieves the string property if one is set in the cache or
  2897. // returns NULL if the property is not in the cache. The assumption
  2898. // here is that string properties are defaulted to NULL always.
  2899. //
  2900. // Arguments: Self explanatory.
  2901. //
  2902. // Returns: S_OK, UMI_E_NOT_FOUND, E_FAIL.
  2903. //
  2904. // Modifies: pszRetVal to point to the appropriate value.
  2905. //
  2906. //----------------------------------------------------------------------------
  2907. HRESULT
  2908. CPropertyManager::GetStringProperty(
  2909. LPCWSTR pszPropName,
  2910. LPWSTR *ppszRetStrVal
  2911. )
  2912. {
  2913. DWORD dwIndex;
  2914. HRESULT hr = FindProperty(pszPropName, &dwIndex);
  2915. PUMI_PROPERTY pUmiProp;
  2916. if (FAILED(hr)) {
  2917. //
  2918. // Do we lookup the static table ? The table wont have strings in
  2919. // it though cause the union assumes chars.
  2920. //
  2921. *ppszRetStrVal = NULL;
  2922. RRETURN(S_OK);
  2923. }
  2924. pUmiProp = _pIntfProperties[dwIndex].pUmiProperty;
  2925. //
  2926. // Make sure that this is a string.
  2927. //
  2928. if (pUmiProp->uType != UMI_TYPE_LPWSTR) {
  2929. BAIL_ON_FAILURE(hr = E_FAIL);
  2930. }
  2931. if (pUmiProp->pUmiValue
  2932. && pUmiProp->pUmiValue->pszStrValue[0]) {
  2933. *ppszRetStrVal = AllocADsStr(pUmiProp->pUmiValue->pszStrValue[0]);
  2934. if (!*ppszRetStrVal) {
  2935. BAIL_ON_FAILURE(hr = E_OUTOFMEMORY);
  2936. }
  2937. }
  2938. error:
  2939. RRETURN(hr);
  2940. }
  2941. //+---------------------------------------------------------------------------
  2942. // Function: CPropertyManager::GetLongProperty - Helper method.
  2943. //
  2944. // Synopsis: Retrieves the long property if one is set in the cache or
  2945. // returns the defaulted value if the property is not in the cache.
  2946. //
  2947. // Arguments: pszPropName --- Name of property being retrieved.
  2948. // plVal --- Ptr for return value.
  2949. //
  2950. // Returns: S_OK, UMI_E_NOT_FOUND or E_FAIL.
  2951. //
  2952. // Modifies: *plVal with appropriate value.
  2953. //
  2954. //----------------------------------------------------------------------------
  2955. HRESULT
  2956. CPropertyManager::GetLongProperty(
  2957. LPCWSTR pszPropName,
  2958. LONG *plVal
  2959. )
  2960. {
  2961. DWORD dwIndex;
  2962. HRESULT hr = FindProperty(pszPropName, &dwIndex);
  2963. PUMI_PROPERTY pUmiProp;
  2964. *plVal = 0;
  2965. if (FAILED(hr)) {
  2966. //
  2967. // We need to look for the property in the static table.
  2968. //
  2969. hr = GetIndexInStaticTable(pszPropName, dwIndex);
  2970. if (SUCCEEDED(hr)
  2971. && (_pStaticPropData[dwIndex].ulDataType == UMI_TYPE_I4)
  2972. ) {
  2973. //
  2974. // Get the correct value from the table.
  2975. //
  2976. *plVal = _pStaticPropData[dwIndex].umiVal.lValue[0];
  2977. }
  2978. else {
  2979. hr = UMI_E_NOT_FOUND;
  2980. }
  2981. RRETURN(hr);
  2982. }
  2983. pUmiProp = _pIntfProperties[dwIndex].pUmiProperty;
  2984. //
  2985. // Make sure that this is a long.
  2986. //
  2987. if (pUmiProp->uType != UMI_TYPE_I4) {
  2988. BAIL_ON_FAILURE(hr = E_FAIL);
  2989. }
  2990. if (pUmiProp->pUmiValue) {
  2991. *plVal = pUmiProp->pUmiValue->lValue[0];
  2992. }
  2993. error:
  2994. RRETURN(hr);
  2995. }
  2996. //+---------------------------------------------------------------------------
  2997. // Function: CPropertyManager::GetBoolProperty - Helper method.
  2998. //
  2999. // Synopsis: Retrieves the bool property if one is set in the cache or
  3000. // returns the defaulted value if the property is not in the cache.
  3001. //
  3002. // Arguments: pszPropName --- Name of property being retrieved.
  3003. // pfFlag --- Ptr for return value.
  3004. //
  3005. // Returns: S_OK, UMI_E_NOT_FOUND or E_FAIL.
  3006. //
  3007. // Modifies: ofFlag with appropriate value of the property.
  3008. //
  3009. //----------------------------------------------------------------------------
  3010. HRESULT
  3011. CPropertyManager::GetBoolProperty(
  3012. LPCWSTR pszPropName,
  3013. BOOL *pfFlag
  3014. )
  3015. {
  3016. DWORD dwIndex;
  3017. HRESULT hr = FindProperty(pszPropName, &dwIndex);
  3018. PUMI_PROPERTY pUmiProp;
  3019. *pfFlag = FALSE;
  3020. if (FAILED(hr)) {
  3021. //
  3022. // We need to look for the property in the static table.
  3023. //
  3024. hr = GetIndexInStaticTable(pszPropName, dwIndex);
  3025. if (SUCCEEDED(hr)
  3026. && (_pStaticPropData[dwIndex].ulDataType == UMI_TYPE_BOOL)
  3027. ) {
  3028. //
  3029. // Get the correct value from the table.
  3030. //
  3031. *pfFlag = _pStaticPropData[dwIndex].umiVal.bValue[0];
  3032. }
  3033. else {
  3034. hr = E_FAIL;
  3035. }
  3036. RRETURN(hr);
  3037. }
  3038. pUmiProp = _pIntfProperties[dwIndex].pUmiProperty;
  3039. //
  3040. // Make sure that this is a long.
  3041. //
  3042. if (pUmiProp->uType != UMI_TYPE_BOOL) {
  3043. BAIL_ON_FAILURE(hr = E_FAIL);
  3044. }
  3045. if (pUmiProp->pUmiValue) {
  3046. *pfFlag = pUmiProp->pUmiValue->bValue[0];
  3047. }
  3048. error:
  3049. RRETURN(hr);
  3050. }