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.

470 lines
9.2 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 CNDSProperty
  17. DECLARE_INFOLEVEL( Syntax );
  18. DECLARE_DEBUG( Syntax );
  19. #define SyntaxDebugOut(x) SyntaxInlineDebugOut x
  20. DEFINE_IDispatch_Implementation(CNDSProperty)
  21. DEFINE_IADs_Implementation(CNDSProperty)
  22. CNDSProperty::CNDSProperty()
  23. : _pDispMgr( NULL ),
  24. _bstrOID( NULL ),
  25. _bstrSyntax( NULL ),
  26. _lMaxRange( 0 ),
  27. _lMinRange( 0 ),
  28. _fMultiValued( FALSE )
  29. {
  30. ENLIST_TRACKING(CNDSProperty);
  31. }
  32. CNDSProperty::~CNDSProperty()
  33. {
  34. delete _pDispMgr;
  35. }
  36. HRESULT
  37. CNDSProperty::CreateProperty(
  38. BSTR bstrParent,
  39. BSTR bstrName,
  40. LPNDS_ATTR_DEF lpAttrDef,
  41. CCredentials& Credentials,
  42. DWORD dwObjectState,
  43. REFIID riid,
  44. void **ppvObj
  45. )
  46. {
  47. CNDSProperty FAR * pProperty = NULL;
  48. HRESULT hr = S_OK;
  49. WCHAR szADsSyntax[MAX_PATH];
  50. WCHAR szNDSSyntax[MAX_PATH];
  51. hr = AllocatePropertyObject( &pProperty );
  52. BAIL_ON_FAILURE(hr);
  53. hr = pProperty->InitializeCoreObject(
  54. bstrParent,
  55. bstrName,
  56. PROPERTY_CLASS_NAME,
  57. L"",
  58. CLSID_NDSProperty,
  59. dwObjectState
  60. );
  61. BAIL_ON_FAILURE(hr);
  62. hr = pProperty->QueryInterface( riid, ppvObj );
  63. BAIL_ON_FAILURE(hr);
  64. #if DBG
  65. SyntaxDebugOut((DEB_TRACE,
  66. "Property %s : SyntaxId %d\n",
  67. lpAttrDef->szAttributeName,
  68. lpAttrDef->dwSyntaxID));
  69. #endif
  70. MapSyntaxIdtoADsSyntax(
  71. lpAttrDef->dwSyntaxID,
  72. szADsSyntax
  73. );
  74. hr = ADsAllocString(
  75. szADsSyntax,
  76. &pProperty->_bstrSyntax
  77. );
  78. BAIL_ON_FAILURE(hr);
  79. MapSyntaxIdtoNDSSyntax(
  80. lpAttrDef->dwSyntaxID,
  81. szNDSSyntax
  82. );
  83. hr = ADsAllocString(
  84. szNDSSyntax,
  85. &pProperty->_bstrOID
  86. );
  87. BAIL_ON_FAILURE(hr);
  88. pProperty->_lMaxRange = lpAttrDef->dwUpperLimit;
  89. pProperty->_lMinRange = lpAttrDef->dwLowerLimit;
  90. pProperty->_fMultiValued = !(lpAttrDef->dwFlags & NDS_SINGLE_VALUED_ATTR);
  91. pProperty->Release();
  92. RRETURN(hr);
  93. error:
  94. delete pProperty;
  95. RRETURN_EXP_IF_ERR(hr);
  96. }
  97. HRESULT
  98. CNDSProperty::CreateProperty(
  99. BSTR bstrParent,
  100. BSTR bstrName,
  101. HANDLE hTree,
  102. CCredentials& Credentials,
  103. DWORD dwObjectState,
  104. REFIID riid,
  105. void **ppvObj
  106. )
  107. {
  108. DWORD dwStatus = 0;
  109. HRESULT hr = S_OK;
  110. LPNDS_ATTR_DEF lpAttrDefs = NULL;
  111. DWORD dwNumberOfEntries = 0;
  112. DWORD dwInfoType = 0;
  113. HANDLE hOperationData = NULL;
  114. dwStatus = NwNdsCreateBuffer(
  115. NDS_SCHEMA_READ_ATTR_DEF,
  116. &hOperationData
  117. );
  118. CHECK_AND_SET_EXTENDED_ERROR(dwStatus, hr);
  119. dwStatus = NwNdsPutInBuffer(
  120. bstrName,
  121. 0,
  122. NULL,
  123. 0,
  124. 0,
  125. hOperationData
  126. );
  127. CHECK_AND_SET_EXTENDED_ERROR(dwStatus, hr);
  128. dwStatus = NwNdsReadAttrDef(
  129. hTree,
  130. NDS_INFO_NAMES_DEFS,
  131. &hOperationData
  132. );
  133. CHECK_AND_SET_EXTENDED_ERROR(dwStatus, hr);
  134. dwStatus = NwNdsGetAttrDefListFromBuffer(
  135. hOperationData,
  136. &dwNumberOfEntries,
  137. &dwInfoType,
  138. (LPVOID *) &lpAttrDefs
  139. );
  140. CHECK_AND_SET_EXTENDED_ERROR(dwStatus, hr);
  141. if (!lpAttrDefs) {
  142. hr = E_FAIL;
  143. BAIL_ON_FAILURE(hr);
  144. }
  145. hr = CNDSProperty::CreateProperty(
  146. bstrParent,
  147. bstrName,
  148. lpAttrDefs,
  149. Credentials,
  150. dwObjectState,
  151. riid,
  152. ppvObj
  153. );
  154. error:
  155. if (hOperationData) {
  156. NwNdsFreeBuffer(hOperationData);
  157. }
  158. RRETURN_EXP_IF_ERR(hr);
  159. }
  160. STDMETHODIMP
  161. CNDSProperty::QueryInterface(
  162. REFIID iid,
  163. LPVOID FAR* ppv
  164. )
  165. {
  166. if (ppv == NULL) {
  167. RRETURN(E_POINTER);
  168. }
  169. if (IsEqualIID(iid, IID_IUnknown))
  170. {
  171. *ppv = (IADsProperty FAR *) this;
  172. }
  173. else if (IsEqualIID(iid, IID_IDispatch))
  174. {
  175. *ppv = (IADsProperty FAR *) this;
  176. }
  177. else if (IsEqualIID(iid, IID_ISupportErrorInfo))
  178. {
  179. *ppv = (ISupportErrorInfo FAR *) this;
  180. }
  181. else if (IsEqualIID(iid, IID_IADsProperty))
  182. {
  183. *ppv = (IADsProperty FAR *) this;
  184. }
  185. else if (IsEqualIID(iid, IID_IADs))
  186. {
  187. *ppv = (IADsProperty FAR *) this;
  188. }
  189. else
  190. {
  191. *ppv = NULL;
  192. return E_NOINTERFACE;
  193. }
  194. AddRef();
  195. return NOERROR;
  196. }
  197. /* IADs methods */
  198. STDMETHODIMP
  199. CNDSProperty::SetInfo(THIS)
  200. {
  201. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  202. }
  203. STDMETHODIMP
  204. CNDSProperty::GetInfo(THIS)
  205. {
  206. RRETURN(S_OK);
  207. }
  208. STDMETHODIMP
  209. CNDSProperty::GetInfoEx(THIS_ VARIANT vProperties, long lnReserved)
  210. {
  211. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  212. }
  213. HRESULT
  214. CNDSProperty::AllocatePropertyObject(
  215. CNDSProperty FAR * FAR * ppProperty
  216. )
  217. {
  218. CNDSProperty FAR *pProperty = NULL;
  219. CDispatchMgr FAR *pDispMgr = NULL;
  220. HRESULT hr = S_OK;
  221. pProperty = new CNDSProperty();
  222. if ( pProperty == NULL )
  223. hr = E_OUTOFMEMORY;
  224. BAIL_ON_FAILURE(hr);
  225. pDispMgr = new CDispatchMgr;
  226. if ( pDispMgr == NULL )
  227. hr = E_OUTOFMEMORY;
  228. BAIL_ON_FAILURE(hr);
  229. hr = LoadTypeInfoEntry(
  230. pDispMgr,
  231. LIBID_ADs,
  232. IID_IADsProperty,
  233. (IADsProperty *) pProperty,
  234. DISPID_REGULAR
  235. );
  236. BAIL_ON_FAILURE(hr);
  237. pProperty->_pDispMgr = pDispMgr;
  238. *ppProperty = pProperty;
  239. RRETURN(hr);
  240. error:
  241. delete pDispMgr;
  242. delete pProperty;
  243. RRETURN(hr);
  244. }
  245. /* ISupportErrorInfo method */
  246. STDMETHODIMP
  247. CNDSProperty::InterfaceSupportsErrorInfo(
  248. THIS_ REFIID riid
  249. )
  250. {
  251. if (IsEqualIID(riid, IID_IADs) ||
  252. IsEqualIID(riid, IID_IADsProperty)) {
  253. RRETURN(S_OK);
  254. } else {
  255. RRETURN(S_FALSE);
  256. }
  257. }
  258. STDMETHODIMP
  259. CNDSProperty::Get(
  260. THIS_ BSTR bstrName,
  261. VARIANT FAR* pvProp
  262. )
  263. {
  264. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  265. }
  266. STDMETHODIMP
  267. CNDSProperty::Put(
  268. THIS_ BSTR bstrName,
  269. VARIANT vProp
  270. )
  271. {
  272. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  273. }
  274. STDMETHODIMP
  275. CNDSProperty::GetEx(
  276. THIS_ BSTR bstrName,
  277. VARIANT FAR* pvProp
  278. )
  279. {
  280. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  281. }
  282. STDMETHODIMP
  283. CNDSProperty::PutEx(
  284. THIS_ long lnControlCode,
  285. BSTR bstrName,
  286. VARIANT vProp
  287. )
  288. {
  289. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  290. }
  291. /* IADsProperty methods */
  292. STDMETHODIMP
  293. CNDSProperty::get_OID( THIS_ BSTR FAR *pbstrOID )
  294. {
  295. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  296. }
  297. STDMETHODIMP
  298. CNDSProperty::put_OID( THIS_ BSTR bstrOID )
  299. {
  300. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  301. }
  302. STDMETHODIMP
  303. CNDSProperty::get_Syntax( THIS_ BSTR FAR *pbstrSyntax )
  304. {
  305. if ( !pbstrSyntax )
  306. RRETURN_EXP_IF_ERR(E_ADS_BAD_PARAMETER);
  307. HRESULT hr;
  308. hr = ( ADsAllocString( _bstrSyntax, pbstrSyntax ));
  309. RRETURN_EXP_IF_ERR(hr);
  310. }
  311. STDMETHODIMP
  312. CNDSProperty::put_Syntax( THIS_ BSTR bstrSyntax )
  313. {
  314. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  315. }
  316. STDMETHODIMP
  317. CNDSProperty::get_MaxRange( THIS_ long FAR *plMaxRange )
  318. {
  319. if ( !plMaxRange )
  320. RRETURN_EXP_IF_ERR(E_ADS_BAD_PARAMETER);
  321. *plMaxRange = _lMaxRange;
  322. RRETURN(S_OK);
  323. }
  324. STDMETHODIMP
  325. CNDSProperty::put_MaxRange( THIS_ long lMaxRange )
  326. {
  327. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  328. }
  329. STDMETHODIMP
  330. CNDSProperty::get_MinRange( THIS_ long FAR *plMinRange )
  331. {
  332. if ( !plMinRange )
  333. RRETURN_EXP_IF_ERR(E_ADS_BAD_PARAMETER);
  334. *plMinRange = _lMinRange;
  335. RRETURN(S_OK);
  336. }
  337. STDMETHODIMP
  338. CNDSProperty::put_MinRange( THIS_ long lMinRange )
  339. {
  340. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  341. }
  342. STDMETHODIMP
  343. CNDSProperty::get_MultiValued( THIS_ VARIANT_BOOL FAR *pfMultiValued )
  344. {
  345. if ( !pfMultiValued )
  346. RRETURN_EXP_IF_ERR(E_ADS_BAD_PARAMETER);
  347. *pfMultiValued = _fMultiValued? VARIANT_TRUE : VARIANT_FALSE;
  348. RRETURN(S_OK);
  349. }
  350. STDMETHODIMP
  351. CNDSProperty::put_MultiValued( THIS_ VARIANT_BOOL fMultiValued )
  352. {
  353. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  354. }
  355. STDMETHODIMP
  356. CNDSProperty::Qualifiers(THIS_ IADsCollection FAR* FAR* ppQualifiers)
  357. {
  358. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  359. }
  360. HRESULT
  361. MapSyntaxIdtoADsSyntax(
  362. DWORD dwSyntaxId,
  363. LPWSTR pszADsSyntax
  364. )
  365. {
  366. if (dwSyntaxId >= g_cNDSSyntaxMap) {
  367. wcscpy(pszADsSyntax, L"Out of Bounds");
  368. }else {
  369. wcscpy(pszADsSyntax, g_aNDSSyntaxMap[dwSyntaxId].bstrName);
  370. }
  371. RRETURN(S_OK);
  372. }
  373. HRESULT
  374. MapSyntaxIdtoNDSSyntax(
  375. DWORD dwSyntaxId,
  376. LPWSTR pszNDSSyntax
  377. )
  378. {
  379. if (dwSyntaxId > g_cNDSSyntaxMap) {
  380. wcscpy(pszNDSSyntax, L"Out of Bounds");
  381. }else {
  382. wcscpy(pszNDSSyntax, g_aNDSSyntaxMap[dwSyntaxId].bstrNDSName);
  383. }
  384. RRETURN(S_OK);
  385. }