Source code of Windows XP (NT5)
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.

754 lines
15 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995
  5. //
  6. // File: cclsobj.cxx
  7. //
  8. // Contents: Microsoft ADs NDS Provider Generic Object
  9. //
  10. //
  11. // History: 01-30-95 krishnag Created.
  12. //
  13. //----------------------------------------------------------------------------
  14. #include "nds.hxx"
  15. #pragma hdrstop
  16. // Class CNDSClass
  17. DEFINE_IDispatch_Implementation(CNDSClass)
  18. DEFINE_IADs_Implementation(CNDSClass)
  19. CNDSClass::CNDSClass():
  20. _pDispMgr( NULL ),
  21. _bstrCLSID( NULL ),
  22. _bstrOID( NULL ),
  23. _bstrPrimaryInterface( NULL ),
  24. _bstrHelpFileName( NULL ),
  25. _lHelpFileContext( 0 ),
  26. _dwFlags(0),
  27. _lpClassName(0),
  28. _dwNumberOfSuperClasses(0),
  29. _lpSuperClasses(0),
  30. _dwNumberOfContainmentClasses(0),
  31. _lpContainmentClasses(0),
  32. _dwNumberOfNamingAttributes(0),
  33. _lpNamingAttributes(0),
  34. _dwNumberOfMandatoryAttributes(0),
  35. _lpMandatoryAttributes(0),
  36. _dwNumberOfOptionalAttributes(0),
  37. _lpOptionalAttributes(0)
  38. {
  39. VariantInit(&_vFilter);
  40. ENLIST_TRACKING(CNDSClass);
  41. }
  42. HRESULT
  43. CNDSClass::CreateClass(
  44. BSTR Parent,
  45. BSTR CommonName,
  46. LPNDS_CLASS_DEF lpClassDefs,
  47. CCredentials& Credentials,
  48. DWORD dwObjectState,
  49. REFIID riid,
  50. void **ppvObj
  51. )
  52. {
  53. CNDSClass FAR * pClass = NULL;
  54. HRESULT hr = S_OK;
  55. hr = AllocateClassObject(Credentials, &pClass);
  56. BAIL_ON_FAILURE(hr);
  57. hr = pClass->InitializeCoreObject(
  58. Parent,
  59. CommonName,
  60. CLASS_CLASS_NAME,
  61. L"",
  62. CLSID_NDSClass,
  63. dwObjectState
  64. );
  65. BAIL_ON_FAILURE(hr);
  66. hr = pClass->QueryInterface(riid, ppvObj);
  67. BAIL_ON_FAILURE(hr);
  68. pClass->_Credentials = Credentials;
  69. pClass->_dwFlags = lpClassDefs->dwFlags;
  70. pClass->_dwNumberOfSuperClasses =
  71. lpClassDefs->dwNumberOfSuperClasses;
  72. pClass->_lpSuperClasses = CreatePropertyList(
  73. lpClassDefs->lpSuperClasses
  74. );
  75. pClass->_dwNumberOfContainmentClasses =
  76. lpClassDefs->dwNumberOfContainmentClasses;
  77. pClass->_lpContainmentClasses = CreatePropertyList(
  78. lpClassDefs->lpContainmentClasses
  79. );
  80. pClass->_dwNumberOfNamingAttributes =
  81. lpClassDefs->dwNumberOfNamingAttributes;
  82. pClass->_lpNamingAttributes = CreatePropertyList(
  83. lpClassDefs->lpNamingAttributes
  84. );
  85. pClass->_dwNumberOfMandatoryAttributes =
  86. lpClassDefs->dwNumberOfMandatoryAttributes;
  87. pClass->_lpMandatoryAttributes = CreatePropertyList(
  88. lpClassDefs->lpMandatoryAttributes
  89. );
  90. pClass->_dwNumberOfOptionalAttributes =
  91. lpClassDefs->dwNumberOfOptionalAttributes;
  92. pClass->_lpOptionalAttributes = CreatePropertyList(
  93. lpClassDefs->lpOptionalAttributes
  94. );
  95. pClass->Release();
  96. RRETURN(hr);
  97. error:
  98. delete pClass;
  99. RRETURN_EXP_IF_ERR(hr);
  100. }
  101. HRESULT
  102. CNDSClass::CreateClass(
  103. BSTR Parent,
  104. BSTR CommonName,
  105. HANDLE hTree,
  106. CCredentials& Credentials,
  107. DWORD dwObjectState,
  108. REFIID riid,
  109. void **ppvObj
  110. )
  111. {
  112. DWORD dwStatus = 0;
  113. HRESULT hr = S_OK;
  114. LPNDS_CLASS_DEF lpClassDefs = NULL;
  115. DWORD dwObjectsReturned = 0;
  116. DWORD dwInfoType = 0;
  117. HANDLE hOperationData = NULL;
  118. dwStatus = NwNdsCreateBuffer(
  119. NDS_SCHEMA_READ_CLASS_DEF,
  120. &hOperationData
  121. );
  122. CHECK_AND_SET_EXTENDED_ERROR(dwStatus, hr);
  123. dwStatus = NwNdsPutInBuffer(
  124. CommonName,
  125. 0,
  126. NULL,
  127. 0,
  128. 0,
  129. hOperationData
  130. );
  131. CHECK_AND_SET_EXTENDED_ERROR(dwStatus, hr);
  132. dwStatus = NwNdsReadClassDef(
  133. hTree,
  134. NDS_CLASS_INFO_EXPANDED_DEFS,
  135. &hOperationData
  136. );
  137. CHECK_AND_SET_EXTENDED_ERROR(dwStatus, hr);
  138. dwStatus = NwNdsGetClassDefListFromBuffer(
  139. hOperationData,
  140. &dwObjectsReturned,
  141. &dwInfoType,
  142. (LPVOID *) &lpClassDefs
  143. );
  144. CHECK_AND_SET_EXTENDED_ERROR(dwStatus, hr);
  145. if (!lpClassDefs) {
  146. hr = E_FAIL;
  147. BAIL_ON_FAILURE(hr);
  148. }
  149. hr = CNDSClass::CreateClass(
  150. Parent,
  151. CommonName,
  152. lpClassDefs,
  153. Credentials,
  154. dwObjectState,
  155. riid,
  156. ppvObj
  157. );
  158. error:
  159. if (hOperationData) {
  160. NwNdsFreeBuffer(hOperationData);
  161. }
  162. RRETURN_EXP_IF_ERR(hr);
  163. }
  164. CNDSClass::~CNDSClass( )
  165. {
  166. if ( _bstrCLSID ) {
  167. ADsFreeString( _bstrCLSID );
  168. }
  169. if ( _bstrOID ) {
  170. ADsFreeString( _bstrOID );
  171. }
  172. if ( _bstrPrimaryInterface ) {
  173. ADsFreeString( _bstrPrimaryInterface );
  174. }
  175. if ( _bstrHelpFileName ) {
  176. ADsFreeString( _bstrHelpFileName );
  177. }
  178. if (_lpSuperClasses) {
  179. FreePropertyList(_lpSuperClasses);
  180. }
  181. if (_lpContainmentClasses) {
  182. FreePropertyList(_lpContainmentClasses);
  183. }
  184. if (_lpNamingAttributes) {
  185. FreePropertyList(_lpNamingAttributes);
  186. }
  187. if (_lpMandatoryAttributes) {
  188. FreePropertyList(_lpMandatoryAttributes);
  189. }
  190. if (_lpOptionalAttributes) {
  191. FreePropertyList(_lpOptionalAttributes);
  192. }
  193. VariantClear( &_vFilter );
  194. delete _pDispMgr;
  195. }
  196. STDMETHODIMP
  197. CNDSClass::QueryInterface(
  198. REFIID iid,
  199. LPVOID FAR* ppv
  200. )
  201. {
  202. if (ppv == NULL) {
  203. RRETURN(E_POINTER);
  204. }
  205. if (IsEqualIID(iid, IID_IUnknown))
  206. {
  207. *ppv = (IADsClass FAR *) this;
  208. }
  209. else if (IsEqualIID(iid, IID_IADsClass))
  210. {
  211. *ppv = (IADsClass FAR *) this;
  212. }
  213. else if (IsEqualIID(iid, IID_IADs))
  214. {
  215. *ppv = (IADsClass FAR *) this;
  216. }
  217. else if (IsEqualIID(iid, IID_IDispatch))
  218. {
  219. *ppv = (IADsClass FAR *) this;
  220. }
  221. else if (IsEqualIID(iid, IID_ISupportErrorInfo))
  222. {
  223. *ppv = (ISupportErrorInfo FAR *) this;
  224. }
  225. else
  226. {
  227. *ppv = NULL;
  228. return E_NOINTERFACE;
  229. }
  230. AddRef();
  231. return NOERROR;
  232. }
  233. STDMETHODIMP
  234. CNDSClass::SetInfo(THIS)
  235. {
  236. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  237. }
  238. STDMETHODIMP
  239. CNDSClass::GetInfo(THIS)
  240. {
  241. RRETURN_EXP_IF_ERR(S_OK);
  242. }
  243. STDMETHODIMP
  244. CNDSClass::GetInfoEx(THIS_ VARIANT vProperties, long lnReserved)
  245. {
  246. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  247. }
  248. HRESULT
  249. CNDSClass::AllocateClassObject(
  250. CCredentials& Credentials,
  251. CNDSClass ** ppClass
  252. )
  253. {
  254. CNDSClass FAR * pClass = NULL;
  255. CDispatchMgr FAR * pDispMgr = NULL;
  256. HRESULT hr = S_OK;
  257. pClass = new CNDSClass();
  258. if (pClass == NULL) {
  259. hr = E_OUTOFMEMORY;
  260. }
  261. BAIL_ON_FAILURE(hr);
  262. pDispMgr = new CDispatchMgr;
  263. if (pDispMgr == NULL) {
  264. hr = E_OUTOFMEMORY;
  265. }
  266. BAIL_ON_FAILURE(hr);
  267. hr = LoadTypeInfoEntry(
  268. pDispMgr,
  269. LIBID_ADs,
  270. IID_IADsClass,
  271. (IADsClass *)pClass,
  272. DISPID_REGULAR
  273. );
  274. BAIL_ON_FAILURE(hr);
  275. pClass->_pDispMgr = pDispMgr;
  276. *ppClass = pClass;
  277. RRETURN(hr);
  278. error:
  279. delete pDispMgr;
  280. RRETURN(hr);
  281. }
  282. /* ISupportErrorInfo method*/
  283. STDMETHODIMP
  284. CNDSClass::InterfaceSupportsErrorInfo(
  285. THIS_ REFIID riid
  286. )
  287. {
  288. if (IsEqualIID(riid, IID_IADs) ||
  289. IsEqualIID(riid, IID_IADsClass)) {
  290. RRETURN(S_OK);
  291. } else {
  292. RRETURN(S_FALSE);
  293. }
  294. }
  295. STDMETHODIMP
  296. CNDSClass::GetInfo(
  297. THIS_ DWORD dwApiLevel,
  298. BOOL fExplicit
  299. )
  300. {
  301. RRETURN_EXP_IF_ERR(S_OK);
  302. }
  303. STDMETHODIMP
  304. CNDSClass::Get(
  305. THIS_ BSTR bstrName,
  306. VARIANT FAR* pvProp
  307. )
  308. {
  309. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  310. }
  311. STDMETHODIMP
  312. CNDSClass::Put(
  313. THIS_ BSTR bstrName,
  314. VARIANT vProp
  315. )
  316. {
  317. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  318. }
  319. STDMETHODIMP
  320. CNDSClass::GetEx(
  321. THIS_ BSTR bstrName,
  322. VARIANT FAR* pvProp
  323. )
  324. {
  325. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  326. }
  327. STDMETHODIMP
  328. CNDSClass::PutEx(
  329. THIS_ long lnControlCode,
  330. BSTR bstrName,
  331. VARIANT vProp
  332. )
  333. {
  334. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  335. }
  336. /* IADsClass methods */
  337. STDMETHODIMP
  338. CNDSClass::get_PrimaryInterface( THIS_ BSTR FAR *pbstrGUID )
  339. {
  340. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  341. }
  342. STDMETHODIMP
  343. CNDSClass::get_CLSID( THIS_ BSTR FAR *pbstrCLSID )
  344. {
  345. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  346. }
  347. STDMETHODIMP
  348. CNDSClass::put_CLSID( THIS_ BSTR bstrCLSID )
  349. {
  350. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  351. }
  352. STDMETHODIMP
  353. CNDSClass::get_OID( THIS_ BSTR FAR *pbstrOID )
  354. {
  355. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  356. }
  357. STDMETHODIMP
  358. CNDSClass::put_OID( THIS_ BSTR bstrOID )
  359. {
  360. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  361. }
  362. STDMETHODIMP
  363. CNDSClass::get_Abstract( THIS_ VARIANT_BOOL FAR *pfAbstract )
  364. {
  365. if (_dwFlags & NDS_EFFECTIVE_CLASS) {
  366. *pfAbstract = VARIANT_FALSE;
  367. }else {
  368. *pfAbstract = VARIANT_TRUE;
  369. }
  370. RRETURN(S_OK);
  371. }
  372. STDMETHODIMP
  373. CNDSClass::put_Abstract( THIS_ VARIANT_BOOL fAbstract )
  374. {
  375. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  376. }
  377. STDMETHODIMP
  378. CNDSClass::get_Auxiliary( THIS_ VARIANT_BOOL FAR *pfAuxiliary )
  379. {
  380. *pfAuxiliary = VARIANT_FALSE;
  381. RRETURN(S_OK);
  382. }
  383. STDMETHODIMP
  384. CNDSClass::put_Auxiliary( THIS_ VARIANT_BOOL fAuxiliary )
  385. {
  386. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  387. }
  388. STDMETHODIMP
  389. CNDSClass::get_MandatoryProperties( THIS_ VARIANT FAR *pvMandatoryProperties )
  390. {
  391. HRESULT hr = S_OK;
  392. hr = MakeVariantFromPropList(
  393. _lpMandatoryAttributes,
  394. _dwNumberOfMandatoryAttributes,
  395. pvMandatoryProperties
  396. );
  397. RRETURN_EXP_IF_ERR(hr);
  398. }
  399. STDMETHODIMP
  400. CNDSClass::put_MandatoryProperties( THIS_ VARIANT vMandatoryProperties )
  401. {
  402. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  403. }
  404. STDMETHODIMP
  405. CNDSClass::get_DerivedFrom( THIS_ VARIANT FAR *pvDerivedFrom )
  406. {
  407. HRESULT hr = S_OK;
  408. hr = MakeVariantFromPropList(
  409. _lpSuperClasses,
  410. _dwNumberOfSuperClasses,
  411. pvDerivedFrom
  412. );
  413. RRETURN_EXP_IF_ERR(hr);
  414. }
  415. STDMETHODIMP
  416. CNDSClass::put_DerivedFrom( THIS_ VARIANT vDerivedFrom )
  417. {
  418. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  419. }
  420. STDMETHODIMP
  421. CNDSClass::get_AuxDerivedFrom( THIS_ VARIANT FAR *pvAuxDerivedFrom )
  422. {
  423. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  424. }
  425. STDMETHODIMP
  426. CNDSClass::put_AuxDerivedFrom( THIS_ VARIANT vAuxDerivedFrom )
  427. {
  428. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  429. }
  430. STDMETHODIMP
  431. CNDSClass::get_PossibleSuperiors( THIS_ VARIANT FAR *pvPossSuperiors)
  432. {
  433. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  434. }
  435. STDMETHODIMP
  436. CNDSClass::put_PossibleSuperiors( THIS_ VARIANT vPossSuperiors )
  437. {
  438. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  439. }
  440. STDMETHODIMP
  441. CNDSClass::get_Containment( THIS_ VARIANT FAR *pvContainment )
  442. {
  443. HRESULT hr = S_OK;
  444. hr = MakeVariantFromPropList(
  445. _lpContainmentClasses,
  446. _dwNumberOfContainmentClasses,
  447. pvContainment
  448. );
  449. RRETURN_EXP_IF_ERR(hr);
  450. }
  451. STDMETHODIMP
  452. CNDSClass::put_Containment( THIS_ VARIANT vContainment )
  453. {
  454. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  455. }
  456. STDMETHODIMP
  457. CNDSClass::get_Container( THIS_ VARIANT_BOOL FAR *pfContainer )
  458. {
  459. if (_dwFlags & NDS_CONTAINER_CLASS) {
  460. *pfContainer = VARIANT_TRUE;
  461. }else {
  462. *pfContainer = VARIANT_FALSE;
  463. }
  464. RRETURN(S_OK);
  465. }
  466. STDMETHODIMP
  467. CNDSClass::put_Container( THIS_ VARIANT_BOOL fContainer )
  468. {
  469. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  470. }
  471. STDMETHODIMP
  472. CNDSClass::get_HelpFileName( THIS_ BSTR FAR *pbstrHelpFileName )
  473. {
  474. if ( !pbstrHelpFileName )
  475. RRETURN_EXP_IF_ERR(E_ADS_BAD_PARAMETER);
  476. HRESULT hr;
  477. hr = ADsAllocString( _bstrHelpFileName, pbstrHelpFileName );
  478. RRETURN_EXP_IF_ERR(hr);
  479. }
  480. STDMETHODIMP
  481. CNDSClass::put_HelpFileName( THIS_ BSTR bstrHelpFile )
  482. {
  483. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  484. }
  485. STDMETHODIMP
  486. CNDSClass::get_HelpFileContext( THIS_ long FAR *plHelpContext )
  487. {
  488. if ( !plHelpContext )
  489. RRETURN_EXP_IF_ERR(E_ADS_BAD_PARAMETER);
  490. *plHelpContext = _lHelpFileContext;
  491. RRETURN(S_OK);
  492. }
  493. STDMETHODIMP
  494. CNDSClass::put_HelpFileContext( THIS_ long lHelpContext )
  495. {
  496. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  497. }
  498. STDMETHODIMP
  499. CNDSClass::Qualifiers(THIS_ IADsCollection FAR* FAR* ppQualifiers)
  500. {
  501. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  502. }
  503. PPROPENTRY
  504. CreatePropertyList(
  505. LPWSTR_LIST lpStringList
  506. )
  507. {
  508. PPROPENTRY pStart = NULL;
  509. PPROPENTRY pPropEntry = NULL;
  510. while (lpStringList) {
  511. pPropEntry = CreatePropertyEntry(
  512. lpStringList->szString,
  513. 0
  514. );
  515. if (!pPropEntry) {
  516. goto error;
  517. }
  518. pPropEntry->pNext = pStart;
  519. pStart = pPropEntry;
  520. lpStringList = lpStringList->Next;
  521. }
  522. error:
  523. return(pStart);
  524. }
  525. HRESULT
  526. MakeVariantFromPropList(
  527. PPROPENTRY pPropList,
  528. DWORD dwNumEntries,
  529. VARIANT * pVarList
  530. )
  531. {
  532. SAFEARRAYBOUND sabNewArray;
  533. SAFEARRAY * pFilter = NULL;
  534. HRESULT hr = S_OK;
  535. DWORD dwSLBound = 0;
  536. DWORD dwSUBound = 0;
  537. DWORD i = 0;
  538. VARIANT v;
  539. VariantInit(pVarList);
  540. sabNewArray.cElements = dwNumEntries;
  541. sabNewArray.lLbound = 0;
  542. pFilter = SafeArrayCreate(
  543. VT_VARIANT,
  544. 1,
  545. &sabNewArray
  546. );
  547. if (!pFilter) {
  548. hr = E_OUTOFMEMORY;
  549. BAIL_ON_FAILURE(hr);
  550. }
  551. for (i = dwSLBound; i < (dwSLBound + dwNumEntries); i++) {
  552. VariantInit(&v);
  553. V_VT(&v) = VT_BSTR;
  554. V_BSTR(&v) = SysAllocString(pPropList->pszPropName);
  555. hr = SafeArrayPutElement(
  556. pFilter,
  557. (long*)&i,
  558. (void *)&v
  559. );
  560. VariantClear(&v);
  561. BAIL_ON_FAILURE(hr);
  562. pPropList = pPropList->pNext;
  563. }
  564. V_VT(pVarList) = VT_ARRAY | VT_VARIANT;
  565. V_ARRAY(pVarList) = pFilter;
  566. RRETURN(S_OK);
  567. error:
  568. if (pFilter) {
  569. SafeArrayDestroy(pFilter);
  570. }
  571. RRETURN_EXP_IF_ERR(hr);
  572. }
  573. STDMETHODIMP
  574. CNDSClass::get_OptionalProperties( THIS_ VARIANT FAR *retval )
  575. {
  576. HRESULT hr = S_OK;
  577. hr = MakeVariantFromPropList(
  578. _lpOptionalAttributes,
  579. _dwNumberOfOptionalAttributes,
  580. retval
  581. );
  582. RRETURN_EXP_IF_ERR(hr);
  583. }
  584. STDMETHODIMP
  585. CNDSClass::put_OptionalProperties( THIS_ VARIANT vOptionalProperties )
  586. {
  587. HRESULT hr = E_NOTIMPL;
  588. RRETURN_EXP_IF_ERR(hr);
  589. }
  590. STDMETHODIMP
  591. CNDSClass::get_NamingProperties( THIS_ VARIANT FAR *retval )
  592. {
  593. HRESULT hr = S_OK;
  594. hr = MakeVariantFromPropList(
  595. _lpNamingAttributes,
  596. _dwNumberOfNamingAttributes,
  597. retval
  598. );
  599. RRETURN_EXP_IF_ERR(hr);
  600. }
  601. STDMETHODIMP
  602. CNDSClass::put_NamingProperties( THIS_ VARIANT vNamingProperties )
  603. {
  604. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  605. }