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.

722 lines
14 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(hr);
  100. }
  101. HRESULT
  102. CNDSClass::CreateClass(
  103. BSTR Parent,
  104. BSTR CommonName,
  105. NDS_CONTEXT_HANDLE hADsContext,
  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. hr = ADsNdsReadClassDef(
  119. hADsContext,
  120. DS_EXPANDED_CLASS_DEFS,
  121. &CommonName,
  122. 1,
  123. &hOperationData
  124. );
  125. BAIL_ON_FAILURE(hr);
  126. hr = ADsNdsGetClassDefListFromBuffer(
  127. hADsContext,
  128. hOperationData,
  129. &dwObjectsReturned,
  130. &dwInfoType,
  131. &lpClassDefs
  132. );
  133. BAIL_ON_FAILURE(hr);
  134. if (!lpClassDefs) {
  135. hr = E_FAIL;
  136. BAIL_ON_FAILURE(hr);
  137. }
  138. hr = CNDSClass::CreateClass(
  139. Parent,
  140. CommonName,
  141. lpClassDefs,
  142. Credentials,
  143. dwObjectState,
  144. riid,
  145. ppvObj
  146. );
  147. error:
  148. if (hOperationData) {
  149. ADsNdsFreeBuffer(hOperationData);
  150. }
  151. ADsNdsFreeClassDefList(lpClassDefs, dwObjectsReturned);
  152. RRETURN(hr);
  153. }
  154. CNDSClass::~CNDSClass( )
  155. {
  156. if ( _bstrCLSID ) {
  157. ADsFreeString( _bstrCLSID );
  158. }
  159. if ( _bstrOID ) {
  160. ADsFreeString( _bstrOID );
  161. }
  162. if ( _bstrPrimaryInterface ) {
  163. ADsFreeString( _bstrPrimaryInterface );
  164. }
  165. if ( _bstrHelpFileName ) {
  166. ADsFreeString( _bstrHelpFileName );
  167. }
  168. if (_lpSuperClasses) {
  169. FreePropertyList(_lpSuperClasses);
  170. }
  171. if (_lpContainmentClasses) {
  172. FreePropertyList(_lpContainmentClasses);
  173. }
  174. if (_lpNamingAttributes) {
  175. FreePropertyList(_lpNamingAttributes);
  176. }
  177. if (_lpMandatoryAttributes) {
  178. FreePropertyList(_lpMandatoryAttributes);
  179. }
  180. if (_lpOptionalAttributes) {
  181. FreePropertyList(_lpOptionalAttributes);
  182. }
  183. VariantClear( &_vFilter );
  184. delete _pDispMgr;
  185. }
  186. STDMETHODIMP
  187. CNDSClass::QueryInterface(
  188. REFIID iid,
  189. LPVOID FAR* ppv
  190. )
  191. {
  192. if (ppv == NULL) {
  193. RRETURN(E_POINTER);
  194. }
  195. if (IsEqualIID(iid, IID_IUnknown))
  196. {
  197. *ppv = (IADsClass FAR *) this;
  198. }
  199. else if (IsEqualIID(iid, IID_IADsClass))
  200. {
  201. *ppv = (IADsClass FAR *) this;
  202. }
  203. else if (IsEqualIID(iid, IID_IADs))
  204. {
  205. *ppv = (IADsClass FAR *) this;
  206. }
  207. else if (IsEqualIID(iid, IID_IDispatch))
  208. {
  209. *ppv = (IADsClass FAR *) this;
  210. }
  211. else
  212. {
  213. *ppv = NULL;
  214. return E_NOINTERFACE;
  215. }
  216. AddRef();
  217. return NOERROR;
  218. }
  219. STDMETHODIMP
  220. CNDSClass::SetInfo(THIS)
  221. {
  222. RRETURN(E_NOTIMPL);
  223. }
  224. STDMETHODIMP
  225. CNDSClass::GetInfo(THIS)
  226. {
  227. RRETURN(E_NOTIMPL);
  228. }
  229. STDMETHODIMP
  230. CNDSClass::GetInfoEx(THIS_ VARIANT vProperties, long lnReserved)
  231. {
  232. RRETURN(E_NOTIMPL);
  233. }
  234. HRESULT
  235. CNDSClass::AllocateClassObject(
  236. CCredentials& Credentials,
  237. CNDSClass ** ppClass
  238. )
  239. {
  240. CNDSClass FAR * pClass = NULL;
  241. CDispatchMgr FAR * pDispMgr = NULL;
  242. HRESULT hr = S_OK;
  243. pClass = new CNDSClass();
  244. if (pClass == NULL) {
  245. hr = E_OUTOFMEMORY;
  246. }
  247. BAIL_ON_FAILURE(hr);
  248. pDispMgr = new CDispatchMgr;
  249. if (pDispMgr == NULL) {
  250. hr = E_OUTOFMEMORY;
  251. }
  252. BAIL_ON_FAILURE(hr);
  253. hr = LoadTypeInfoEntry(
  254. pDispMgr,
  255. LIBID_ADs,
  256. IID_IADsClass,
  257. (IADsClass *)pClass,
  258. DISPID_REGULAR
  259. );
  260. BAIL_ON_FAILURE(hr);
  261. pClass->_pDispMgr = pDispMgr;
  262. *ppClass = pClass;
  263. RRETURN(hr);
  264. error:
  265. delete pDispMgr;
  266. RRETURN(hr);
  267. }
  268. STDMETHODIMP
  269. CNDSClass::GetInfo(
  270. THIS_ DWORD dwApiLevel,
  271. BOOL fExplicit
  272. )
  273. {
  274. RRETURN(E_NOTIMPL);
  275. }
  276. STDMETHODIMP
  277. CNDSClass::Get(
  278. THIS_ BSTR bstrName,
  279. VARIANT FAR* pvProp
  280. )
  281. {
  282. RRETURN(E_NOTIMPL);
  283. }
  284. STDMETHODIMP
  285. CNDSClass::Put(
  286. THIS_ BSTR bstrName,
  287. VARIANT vProp
  288. )
  289. {
  290. RRETURN(E_NOTIMPL);
  291. }
  292. STDMETHODIMP
  293. CNDSClass::GetEx(
  294. THIS_ BSTR bstrName,
  295. VARIANT FAR* pvProp
  296. )
  297. {
  298. RRETURN(E_NOTIMPL);
  299. }
  300. STDMETHODIMP
  301. CNDSClass::PutEx(
  302. THIS_ long lnControlCode,
  303. BSTR bstrName,
  304. VARIANT vProp
  305. )
  306. {
  307. RRETURN(E_NOTIMPL);
  308. }
  309. /* IADsClass methods */
  310. STDMETHODIMP
  311. CNDSClass::get_PrimaryInterface( THIS_ BSTR FAR *pbstrGUID )
  312. {
  313. RRETURN(E_ADS_PROPERTY_NOT_SUPPORTED);
  314. }
  315. STDMETHODIMP
  316. CNDSClass::get_CLSID( THIS_ BSTR FAR *pbstrCLSID )
  317. {
  318. RRETURN(E_ADS_PROPERTY_NOT_SUPPORTED);
  319. }
  320. STDMETHODIMP
  321. CNDSClass::put_CLSID( THIS_ BSTR bstrCLSID )
  322. {
  323. RRETURN(E_ADS_PROPERTY_NOT_SUPPORTED);
  324. }
  325. STDMETHODIMP
  326. CNDSClass::get_OID( THIS_ BSTR FAR *pbstrOID )
  327. {
  328. RRETURN(E_ADS_PROPERTY_NOT_SUPPORTED);
  329. }
  330. STDMETHODIMP
  331. CNDSClass::put_OID( THIS_ BSTR bstrOID )
  332. {
  333. RRETURN(E_ADS_PROPERTY_NOT_SUPPORTED);
  334. }
  335. STDMETHODIMP
  336. CNDSClass::get_Abstract( THIS_ VARIANT_BOOL FAR *pfAbstract )
  337. {
  338. if (_dwFlags & NDS_EFFECTIVE_CLASS) {
  339. *pfAbstract = VARIANT_FALSE;
  340. }else {
  341. *pfAbstract = VARIANT_TRUE;
  342. }
  343. RRETURN(S_OK);
  344. }
  345. STDMETHODIMP
  346. CNDSClass::put_Abstract( THIS_ VARIANT_BOOL fAbstract )
  347. {
  348. RRETURN(E_ADS_PROPERTY_NOT_SUPPORTED);
  349. }
  350. STDMETHODIMP
  351. CNDSClass::get_Auxiliary( THIS_ VARIANT_BOOL FAR *pfAuxiliary )
  352. {
  353. *pfAuxiliary = VARIANT_FALSE;
  354. RRETURN(S_OK);
  355. }
  356. STDMETHODIMP
  357. CNDSClass::put_Auxiliary( THIS_ VARIANT_BOOL fAuxiliary )
  358. {
  359. RRETURN(E_ADS_PROPERTY_NOT_SUPPORTED);
  360. }
  361. STDMETHODIMP
  362. CNDSClass::get_MandatoryProperties( THIS_ VARIANT FAR *pvMandatoryProperties )
  363. {
  364. HRESULT hr = S_OK;
  365. hr = MakeVariantFromPropList(
  366. _lpMandatoryAttributes,
  367. _dwNumberOfMandatoryAttributes,
  368. pvMandatoryProperties
  369. );
  370. RRETURN(hr);
  371. }
  372. STDMETHODIMP
  373. CNDSClass::put_MandatoryProperties( THIS_ VARIANT vMandatoryProperties )
  374. {
  375. RRETURN(E_ADS_PROPERTY_NOT_SUPPORTED);
  376. }
  377. STDMETHODIMP
  378. CNDSClass::get_DerivedFrom( THIS_ VARIANT FAR *pvDerivedFrom )
  379. {
  380. HRESULT hr = S_OK;
  381. hr = MakeVariantFromPropList(
  382. _lpSuperClasses,
  383. _dwNumberOfSuperClasses,
  384. pvDerivedFrom
  385. );
  386. RRETURN(hr);
  387. }
  388. STDMETHODIMP
  389. CNDSClass::put_DerivedFrom( THIS_ VARIANT vDerivedFrom )
  390. {
  391. RRETURN(E_ADS_PROPERTY_NOT_SUPPORTED);
  392. }
  393. STDMETHODIMP
  394. CNDSClass::get_AuxDerivedFrom( THIS_ VARIANT FAR *pvAuxDerivedFrom )
  395. {
  396. RRETURN(E_NOTIMPL);
  397. }
  398. STDMETHODIMP
  399. CNDSClass::put_AuxDerivedFrom( THIS_ VARIANT vAuxDerivedFrom )
  400. {
  401. RRETURN(E_ADS_PROPERTY_NOT_SUPPORTED);
  402. }
  403. STDMETHODIMP
  404. CNDSClass::get_PossibleSuperiors( THIS_ VARIANT FAR *pvPossSuperiors)
  405. {
  406. RRETURN(E_NOTIMPL);
  407. }
  408. STDMETHODIMP
  409. CNDSClass::put_PossibleSuperiors( THIS_ VARIANT vPossSuperiors )
  410. {
  411. RRETURN(E_ADS_PROPERTY_NOT_SUPPORTED);
  412. }
  413. STDMETHODIMP
  414. CNDSClass::get_Containment( THIS_ VARIANT FAR *pvContainment )
  415. {
  416. HRESULT hr = S_OK;
  417. hr = MakeVariantFromPropList(
  418. _lpContainmentClasses,
  419. _dwNumberOfContainmentClasses,
  420. pvContainment
  421. );
  422. RRETURN(hr);
  423. }
  424. STDMETHODIMP
  425. CNDSClass::put_Containment( THIS_ VARIANT vContainment )
  426. {
  427. RRETURN(E_ADS_PROPERTY_NOT_SUPPORTED);
  428. }
  429. STDMETHODIMP
  430. CNDSClass::get_Container( THIS_ VARIANT_BOOL FAR *pfContainer )
  431. {
  432. if (_dwFlags & NDS_CONTAINER_CLASS) {
  433. *pfContainer = VARIANT_TRUE;
  434. }else {
  435. *pfContainer = VARIANT_FALSE;
  436. }
  437. RRETURN(S_OK);
  438. }
  439. STDMETHODIMP
  440. CNDSClass::put_Container( THIS_ VARIANT_BOOL fContainer )
  441. {
  442. RRETURN(E_ADS_PROPERTY_NOT_SUPPORTED);
  443. }
  444. STDMETHODIMP
  445. CNDSClass::get_HelpFileName( THIS_ BSTR FAR *pbstrHelpFileName )
  446. {
  447. if ( !pbstrHelpFileName )
  448. RRETURN(E_ADS_BAD_PARAMETER);
  449. RRETURN( ADsAllocString( _bstrHelpFileName, pbstrHelpFileName ));
  450. }
  451. STDMETHODIMP
  452. CNDSClass::put_HelpFileName( THIS_ BSTR bstrHelpFile )
  453. {
  454. RRETURN(E_ADS_PROPERTY_NOT_SUPPORTED);
  455. }
  456. STDMETHODIMP
  457. CNDSClass::get_HelpFileContext( THIS_ long FAR *plHelpContext )
  458. {
  459. if ( !plHelpContext )
  460. RRETURN(E_ADS_BAD_PARAMETER);
  461. *plHelpContext = _lHelpFileContext;
  462. RRETURN(S_OK);
  463. }
  464. STDMETHODIMP
  465. CNDSClass::put_HelpFileContext( THIS_ long lHelpContext )
  466. {
  467. RRETURN(E_ADS_PROPERTY_NOT_SUPPORTED);
  468. }
  469. STDMETHODIMP
  470. CNDSClass::Qualifiers(THIS_ IADsCollection FAR* FAR* ppQualifiers)
  471. {
  472. RRETURN(E_NOTIMPL);
  473. }
  474. PPROPENTRY
  475. CreatePropertyList(
  476. LPWSTR_LIST lpStringList
  477. )
  478. {
  479. PPROPENTRY pStart = NULL;
  480. PPROPENTRY pPropEntry = NULL;
  481. while (lpStringList) {
  482. pPropEntry = CreatePropertyEntry(
  483. lpStringList->szString,
  484. 0
  485. );
  486. if (!pPropEntry)
  487. goto error;
  488. pPropEntry->pNext = pStart;
  489. pStart = pPropEntry;
  490. lpStringList = lpStringList->Next;
  491. }
  492. error:
  493. return(pStart);
  494. }
  495. HRESULT
  496. MakeVariantFromPropList(
  497. PPROPENTRY pPropList,
  498. DWORD dwNumEntries,
  499. VARIANT * pVarList
  500. )
  501. {
  502. SAFEARRAYBOUND sabNewArray;
  503. SAFEARRAY * pFilter = NULL;
  504. HRESULT hr = S_OK;
  505. DWORD dwSLBound = 0;
  506. DWORD dwSUBound = 0;
  507. DWORD i = 0;
  508. VARIANT v;
  509. VariantInit(pVarList);
  510. sabNewArray.cElements = dwNumEntries;
  511. sabNewArray.lLbound = 0;
  512. pFilter = SafeArrayCreate(
  513. VT_VARIANT,
  514. 1,
  515. &sabNewArray
  516. );
  517. if (!pFilter) {
  518. hr = E_OUTOFMEMORY;
  519. BAIL_ON_FAILURE(hr);
  520. }
  521. for (i = dwSLBound; i < (dwSLBound + dwNumEntries); i++) {
  522. VariantInit(&v);
  523. V_VT(&v) = VT_BSTR;
  524. V_BSTR(&v) = SysAllocString(pPropList->pszPropName);
  525. hr = SafeArrayPutElement(
  526. pFilter,
  527. (long*)&i,
  528. (void *)&v
  529. );
  530. VariantClear(&v);
  531. BAIL_ON_FAILURE(hr);
  532. pPropList = pPropList->pNext;
  533. }
  534. V_VT(pVarList) = VT_ARRAY | VT_VARIANT;
  535. V_ARRAY(pVarList) = pFilter;
  536. RRETURN(S_OK);
  537. error:
  538. if (pFilter) {
  539. SafeArrayDestroy(pFilter);
  540. }
  541. RRETURN(hr);
  542. }
  543. STDMETHODIMP
  544. CNDSClass::get_OptionalProperties( THIS_ VARIANT FAR *retval )
  545. {
  546. HRESULT hr = S_OK;
  547. hr = MakeVariantFromPropList(
  548. _lpOptionalAttributes,
  549. _dwNumberOfOptionalAttributes,
  550. retval
  551. );
  552. RRETURN(hr);
  553. }
  554. STDMETHODIMP
  555. CNDSClass::put_OptionalProperties( THIS_ VARIANT vOptionalProperties )
  556. {
  557. HRESULT hr = E_NOTIMPL;
  558. RRETURN(hr);
  559. }
  560. STDMETHODIMP
  561. CNDSClass::get_NamingProperties( THIS_ VARIANT FAR *retval )
  562. {
  563. HRESULT hr = S_OK;
  564. hr = MakeVariantFromPropList(
  565. _lpNamingAttributes,
  566. _dwNumberOfNamingAttributes,
  567. retval
  568. );
  569. RRETURN(hr);
  570. }
  571. STDMETHODIMP
  572. CNDSClass::put_NamingProperties( THIS_ VARIANT vNamingProperties )
  573. {
  574. RRETURN(E_NOTIMPL);
  575. }