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.

755 lines
16 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 pClass;
  280. delete pDispMgr;
  281. RRETURN(hr);
  282. }
  283. /* ISupportErrorInfo method*/
  284. STDMETHODIMP
  285. CNDSClass::InterfaceSupportsErrorInfo(
  286. THIS_ REFIID riid
  287. )
  288. {
  289. if (IsEqualIID(riid, IID_IADs) ||
  290. IsEqualIID(riid, IID_IADsClass)) {
  291. RRETURN(S_OK);
  292. } else {
  293. RRETURN(S_FALSE);
  294. }
  295. }
  296. STDMETHODIMP
  297. CNDSClass::GetInfo(
  298. THIS_ DWORD dwApiLevel,
  299. BOOL fExplicit
  300. )
  301. {
  302. RRETURN_EXP_IF_ERR(S_OK);
  303. }
  304. STDMETHODIMP
  305. CNDSClass::Get(
  306. THIS_ BSTR bstrName,
  307. VARIANT FAR* pvProp
  308. )
  309. {
  310. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  311. }
  312. STDMETHODIMP
  313. CNDSClass::Put(
  314. THIS_ BSTR bstrName,
  315. VARIANT vProp
  316. )
  317. {
  318. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  319. }
  320. STDMETHODIMP
  321. CNDSClass::GetEx(
  322. THIS_ BSTR bstrName,
  323. VARIANT FAR* pvProp
  324. )
  325. {
  326. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  327. }
  328. STDMETHODIMP
  329. CNDSClass::PutEx(
  330. THIS_ long lnControlCode,
  331. BSTR bstrName,
  332. VARIANT vProp
  333. )
  334. {
  335. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  336. }
  337. /* IADsClass methods */
  338. STDMETHODIMP
  339. CNDSClass::get_PrimaryInterface( THIS_ BSTR FAR *pbstrGUID )
  340. {
  341. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  342. }
  343. STDMETHODIMP
  344. CNDSClass::get_CLSID( THIS_ BSTR FAR *pbstrCLSID )
  345. {
  346. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  347. }
  348. STDMETHODIMP
  349. CNDSClass::put_CLSID( THIS_ BSTR bstrCLSID )
  350. {
  351. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  352. }
  353. STDMETHODIMP
  354. CNDSClass::get_OID( THIS_ BSTR FAR *pbstrOID )
  355. {
  356. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  357. }
  358. STDMETHODIMP
  359. CNDSClass::put_OID( THIS_ BSTR bstrOID )
  360. {
  361. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  362. }
  363. STDMETHODIMP
  364. CNDSClass::get_Abstract( THIS_ VARIANT_BOOL FAR *pfAbstract )
  365. {
  366. if (_dwFlags & NDS_EFFECTIVE_CLASS) {
  367. *pfAbstract = VARIANT_FALSE;
  368. }else {
  369. *pfAbstract = VARIANT_TRUE;
  370. }
  371. RRETURN(S_OK);
  372. }
  373. STDMETHODIMP
  374. CNDSClass::put_Abstract( THIS_ VARIANT_BOOL fAbstract )
  375. {
  376. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  377. }
  378. STDMETHODIMP
  379. CNDSClass::get_Auxiliary( THIS_ VARIANT_BOOL FAR *pfAuxiliary )
  380. {
  381. *pfAuxiliary = VARIANT_FALSE;
  382. RRETURN(S_OK);
  383. }
  384. STDMETHODIMP
  385. CNDSClass::put_Auxiliary( THIS_ VARIANT_BOOL fAuxiliary )
  386. {
  387. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  388. }
  389. STDMETHODIMP
  390. CNDSClass::get_MandatoryProperties( THIS_ VARIANT FAR *pvMandatoryProperties )
  391. {
  392. HRESULT hr = S_OK;
  393. hr = MakeVariantFromPropList(
  394. _lpMandatoryAttributes,
  395. _dwNumberOfMandatoryAttributes,
  396. pvMandatoryProperties
  397. );
  398. RRETURN_EXP_IF_ERR(hr);
  399. }
  400. STDMETHODIMP
  401. CNDSClass::put_MandatoryProperties( THIS_ VARIANT vMandatoryProperties )
  402. {
  403. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  404. }
  405. STDMETHODIMP
  406. CNDSClass::get_DerivedFrom( THIS_ VARIANT FAR *pvDerivedFrom )
  407. {
  408. HRESULT hr = S_OK;
  409. hr = MakeVariantFromPropList(
  410. _lpSuperClasses,
  411. _dwNumberOfSuperClasses,
  412. pvDerivedFrom
  413. );
  414. RRETURN_EXP_IF_ERR(hr);
  415. }
  416. STDMETHODIMP
  417. CNDSClass::put_DerivedFrom( THIS_ VARIANT vDerivedFrom )
  418. {
  419. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  420. }
  421. STDMETHODIMP
  422. CNDSClass::get_AuxDerivedFrom( THIS_ VARIANT FAR *pvAuxDerivedFrom )
  423. {
  424. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  425. }
  426. STDMETHODIMP
  427. CNDSClass::put_AuxDerivedFrom( THIS_ VARIANT vAuxDerivedFrom )
  428. {
  429. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  430. }
  431. STDMETHODIMP
  432. CNDSClass::get_PossibleSuperiors( THIS_ VARIANT FAR *pvPossSuperiors)
  433. {
  434. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  435. }
  436. STDMETHODIMP
  437. CNDSClass::put_PossibleSuperiors( THIS_ VARIANT vPossSuperiors )
  438. {
  439. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  440. }
  441. STDMETHODIMP
  442. CNDSClass::get_Containment( THIS_ VARIANT FAR *pvContainment )
  443. {
  444. HRESULT hr = S_OK;
  445. hr = MakeVariantFromPropList(
  446. _lpContainmentClasses,
  447. _dwNumberOfContainmentClasses,
  448. pvContainment
  449. );
  450. RRETURN_EXP_IF_ERR(hr);
  451. }
  452. STDMETHODIMP
  453. CNDSClass::put_Containment( THIS_ VARIANT vContainment )
  454. {
  455. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  456. }
  457. STDMETHODIMP
  458. CNDSClass::get_Container( THIS_ VARIANT_BOOL FAR *pfContainer )
  459. {
  460. if (_dwFlags & NDS_CONTAINER_CLASS) {
  461. *pfContainer = VARIANT_TRUE;
  462. }else {
  463. *pfContainer = VARIANT_FALSE;
  464. }
  465. RRETURN(S_OK);
  466. }
  467. STDMETHODIMP
  468. CNDSClass::put_Container( THIS_ VARIANT_BOOL fContainer )
  469. {
  470. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  471. }
  472. STDMETHODIMP
  473. CNDSClass::get_HelpFileName( THIS_ BSTR FAR *pbstrHelpFileName )
  474. {
  475. if ( !pbstrHelpFileName )
  476. RRETURN_EXP_IF_ERR(E_ADS_BAD_PARAMETER);
  477. HRESULT hr;
  478. hr = ADsAllocString( _bstrHelpFileName, pbstrHelpFileName );
  479. RRETURN_EXP_IF_ERR(hr);
  480. }
  481. STDMETHODIMP
  482. CNDSClass::put_HelpFileName( THIS_ BSTR bstrHelpFile )
  483. {
  484. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  485. }
  486. STDMETHODIMP
  487. CNDSClass::get_HelpFileContext( THIS_ long FAR *plHelpContext )
  488. {
  489. if ( !plHelpContext )
  490. RRETURN_EXP_IF_ERR(E_ADS_BAD_PARAMETER);
  491. *plHelpContext = _lHelpFileContext;
  492. RRETURN(S_OK);
  493. }
  494. STDMETHODIMP
  495. CNDSClass::put_HelpFileContext( THIS_ long lHelpContext )
  496. {
  497. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  498. }
  499. STDMETHODIMP
  500. CNDSClass::Qualifiers(THIS_ IADsCollection FAR* FAR* ppQualifiers)
  501. {
  502. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  503. }
  504. PPROPENTRY
  505. CreatePropertyList(
  506. LPWSTR_LIST lpStringList
  507. )
  508. {
  509. PPROPENTRY pStart = NULL;
  510. PPROPENTRY pPropEntry = NULL;
  511. while (lpStringList) {
  512. pPropEntry = CreatePropertyEntry(
  513. lpStringList->szString,
  514. 0
  515. );
  516. if (!pPropEntry) {
  517. goto error;
  518. }
  519. pPropEntry->pNext = pStart;
  520. pStart = pPropEntry;
  521. lpStringList = lpStringList->Next;
  522. }
  523. error:
  524. return(pStart);
  525. }
  526. HRESULT
  527. MakeVariantFromPropList(
  528. PPROPENTRY pPropList,
  529. DWORD dwNumEntries,
  530. VARIANT * pVarList
  531. )
  532. {
  533. SAFEARRAYBOUND sabNewArray;
  534. SAFEARRAY * pFilter = NULL;
  535. HRESULT hr = S_OK;
  536. DWORD dwSLBound = 0;
  537. DWORD dwSUBound = 0;
  538. DWORD i = 0;
  539. VARIANT v;
  540. VariantInit(pVarList);
  541. sabNewArray.cElements = dwNumEntries;
  542. sabNewArray.lLbound = 0;
  543. pFilter = SafeArrayCreate(
  544. VT_VARIANT,
  545. 1,
  546. &sabNewArray
  547. );
  548. if (!pFilter) {
  549. hr = E_OUTOFMEMORY;
  550. BAIL_ON_FAILURE(hr);
  551. }
  552. for (i = dwSLBound; i < (dwSLBound + dwNumEntries); i++) {
  553. VariantInit(&v);
  554. V_VT(&v) = VT_BSTR;
  555. V_BSTR(&v) = SysAllocString(pPropList->pszPropName);
  556. hr = SafeArrayPutElement(
  557. pFilter,
  558. (long*)&i,
  559. (void *)&v
  560. );
  561. VariantClear(&v);
  562. BAIL_ON_FAILURE(hr);
  563. pPropList = pPropList->pNext;
  564. }
  565. V_VT(pVarList) = VT_ARRAY | VT_VARIANT;
  566. V_ARRAY(pVarList) = pFilter;
  567. RRETURN(S_OK);
  568. error:
  569. if (pFilter) {
  570. SafeArrayDestroy(pFilter);
  571. }
  572. RRETURN_EXP_IF_ERR(hr);
  573. }
  574. STDMETHODIMP
  575. CNDSClass::get_OptionalProperties( THIS_ VARIANT FAR *retval )
  576. {
  577. HRESULT hr = S_OK;
  578. hr = MakeVariantFromPropList(
  579. _lpOptionalAttributes,
  580. _dwNumberOfOptionalAttributes,
  581. retval
  582. );
  583. RRETURN_EXP_IF_ERR(hr);
  584. }
  585. STDMETHODIMP
  586. CNDSClass::put_OptionalProperties( THIS_ VARIANT vOptionalProperties )
  587. {
  588. HRESULT hr = E_NOTIMPL;
  589. RRETURN_EXP_IF_ERR(hr);
  590. }
  591. STDMETHODIMP
  592. CNDSClass::get_NamingProperties( THIS_ VARIANT FAR *retval )
  593. {
  594. HRESULT hr = S_OK;
  595. hr = MakeVariantFromPropList(
  596. _lpNamingAttributes,
  597. _dwNumberOfNamingAttributes,
  598. retval
  599. );
  600. RRETURN_EXP_IF_ERR(hr);
  601. }
  602. STDMETHODIMP
  603. CNDSClass::put_NamingProperties( THIS_ VARIANT vNamingProperties )
  604. {
  605. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  606. }