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.

438 lines
8.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(hr);
  96. }
  97. HRESULT
  98. CNDSProperty::CreateProperty(
  99. BSTR bstrParent,
  100. BSTR bstrName,
  101. NDS_CONTEXT_HANDLE hADsContext,
  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. hr = ADsNdsReadAttrDef(
  115. hADsContext,
  116. DS_ATTR_DEFS,
  117. &bstrName,
  118. 1,
  119. &hOperationData
  120. );
  121. BAIL_ON_FAILURE(hr);
  122. hr = ADsNdsGetAttrDefListFromBuffer(
  123. hADsContext,
  124. hOperationData,
  125. &dwNumberOfEntries,
  126. &dwInfoType,
  127. &lpAttrDefs
  128. );
  129. BAIL_ON_FAILURE(hr);
  130. if (!lpAttrDefs) {
  131. hr = E_FAIL;
  132. BAIL_ON_FAILURE(hr);
  133. }
  134. hr = CNDSProperty::CreateProperty(
  135. bstrParent,
  136. bstrName,
  137. lpAttrDefs,
  138. Credentials,
  139. dwObjectState,
  140. riid,
  141. ppvObj
  142. );
  143. error:
  144. if (hOperationData) {
  145. ADsNdsFreeBuffer(hOperationData);
  146. }
  147. ADsNdsFreeAttrDefList(lpAttrDefs, dwNumberOfEntries);
  148. RRETURN(hr);
  149. }
  150. STDMETHODIMP
  151. CNDSProperty::QueryInterface(
  152. REFIID iid,
  153. LPVOID FAR* ppv
  154. )
  155. {
  156. if (ppv == NULL) {
  157. RRETURN(E_POINTER);
  158. }
  159. if (IsEqualIID(iid, IID_IUnknown))
  160. {
  161. *ppv = (IADsProperty FAR *) this;
  162. }
  163. else if (IsEqualIID(iid, IID_IDispatch))
  164. {
  165. *ppv = (IADsProperty FAR *) this;
  166. }
  167. else if (IsEqualIID(iid, IID_IADsProperty))
  168. {
  169. *ppv = (IADsProperty FAR *) this;
  170. }
  171. else if (IsEqualIID(iid, IID_IADs))
  172. {
  173. *ppv = (IADsProperty FAR *) this;
  174. }
  175. else
  176. {
  177. *ppv = NULL;
  178. return E_NOINTERFACE;
  179. }
  180. AddRef();
  181. return NOERROR;
  182. }
  183. /* IADs methods */
  184. STDMETHODIMP
  185. CNDSProperty::SetInfo(THIS)
  186. {
  187. RRETURN(E_NOTIMPL);
  188. }
  189. STDMETHODIMP
  190. CNDSProperty::GetInfo(THIS)
  191. {
  192. RRETURN(S_OK);
  193. }
  194. STDMETHODIMP
  195. CNDSProperty::GetInfoEx(THIS_ VARIANT vProperties, long lnReserved)
  196. {
  197. RRETURN(E_NOTIMPL);
  198. }
  199. HRESULT
  200. CNDSProperty::AllocatePropertyObject(
  201. CNDSProperty FAR * FAR * ppProperty
  202. )
  203. {
  204. CNDSProperty FAR *pProperty = NULL;
  205. CDispatchMgr FAR *pDispMgr = NULL;
  206. HRESULT hr = S_OK;
  207. pProperty = new CNDSProperty();
  208. if ( pProperty == NULL )
  209. hr = E_OUTOFMEMORY;
  210. BAIL_ON_FAILURE(hr);
  211. pDispMgr = new CDispatchMgr;
  212. if ( pDispMgr == NULL )
  213. hr = E_OUTOFMEMORY;
  214. BAIL_ON_FAILURE(hr);
  215. hr = LoadTypeInfoEntry(
  216. pDispMgr,
  217. LIBID_ADs,
  218. IID_IADsProperty,
  219. (IADsProperty *) pProperty,
  220. DISPID_REGULAR
  221. );
  222. BAIL_ON_FAILURE(hr);
  223. pProperty->_pDispMgr = pDispMgr;
  224. *ppProperty = pProperty;
  225. RRETURN(hr);
  226. error:
  227. delete pDispMgr;
  228. delete pProperty;
  229. RRETURN(hr);
  230. }
  231. STDMETHODIMP
  232. CNDSProperty::Get(
  233. THIS_ BSTR bstrName,
  234. VARIANT FAR* pvProp
  235. )
  236. {
  237. RRETURN(E_NOTIMPL);
  238. }
  239. STDMETHODIMP
  240. CNDSProperty::Put(
  241. THIS_ BSTR bstrName,
  242. VARIANT vProp
  243. )
  244. {
  245. RRETURN(E_NOTIMPL);
  246. }
  247. STDMETHODIMP
  248. CNDSProperty::GetEx(
  249. THIS_ BSTR bstrName,
  250. VARIANT FAR* pvProp
  251. )
  252. {
  253. RRETURN(E_NOTIMPL);
  254. }
  255. STDMETHODIMP
  256. CNDSProperty::PutEx(
  257. THIS_ long lnControlCode,
  258. BSTR bstrName,
  259. VARIANT vProp
  260. )
  261. {
  262. RRETURN(E_NOTIMPL);
  263. }
  264. /* IADsProperty methods */
  265. STDMETHODIMP
  266. CNDSProperty::get_OID( THIS_ BSTR FAR *pbstrOID )
  267. {
  268. RRETURN(E_ADS_PROPERTY_NOT_SUPPORTED);
  269. }
  270. STDMETHODIMP
  271. CNDSProperty::put_OID( THIS_ BSTR bstrOID )
  272. {
  273. RRETURN(E_ADS_PROPERTY_NOT_SUPPORTED);
  274. }
  275. STDMETHODIMP
  276. CNDSProperty::get_Syntax( THIS_ BSTR FAR *pbstrSyntax )
  277. {
  278. if ( !pbstrSyntax )
  279. RRETURN(E_ADS_BAD_PARAMETER);
  280. RRETURN( ADsAllocString( _bstrSyntax, pbstrSyntax ));
  281. }
  282. STDMETHODIMP
  283. CNDSProperty::put_Syntax( THIS_ BSTR bstrSyntax )
  284. {
  285. RRETURN(E_ADS_PROPERTY_NOT_SUPPORTED);
  286. }
  287. STDMETHODIMP
  288. CNDSProperty::get_MaxRange( THIS_ long FAR *plMaxRange )
  289. {
  290. if ( !plMaxRange )
  291. RRETURN(E_ADS_BAD_PARAMETER);
  292. *plMaxRange = _lMaxRange;
  293. RRETURN(S_OK);
  294. }
  295. STDMETHODIMP
  296. CNDSProperty::put_MaxRange( THIS_ long lMaxRange )
  297. {
  298. RRETURN(E_ADS_PROPERTY_NOT_SUPPORTED);
  299. }
  300. STDMETHODIMP
  301. CNDSProperty::get_MinRange( THIS_ long FAR *plMinRange )
  302. {
  303. if ( !plMinRange )
  304. RRETURN(E_ADS_BAD_PARAMETER);
  305. *plMinRange = _lMinRange;
  306. RRETURN(S_OK);
  307. }
  308. STDMETHODIMP
  309. CNDSProperty::put_MinRange( THIS_ long lMinRange )
  310. {
  311. RRETURN(E_ADS_PROPERTY_NOT_SUPPORTED);
  312. }
  313. STDMETHODIMP
  314. CNDSProperty::get_MultiValued( THIS_ VARIANT_BOOL FAR *pfMultiValued )
  315. {
  316. if ( !pfMultiValued )
  317. RRETURN(E_ADS_BAD_PARAMETER);
  318. *pfMultiValued = _fMultiValued? VARIANT_TRUE : VARIANT_FALSE;
  319. RRETURN(S_OK);
  320. }
  321. STDMETHODIMP
  322. CNDSProperty::put_MultiValued( THIS_ VARIANT_BOOL fMultiValued )
  323. {
  324. RRETURN(E_ADS_PROPERTY_NOT_SUPPORTED);
  325. }
  326. STDMETHODIMP
  327. CNDSProperty::Qualifiers(THIS_ IADsCollection FAR* FAR* ppQualifiers)
  328. {
  329. RRETURN(E_NOTIMPL);
  330. }
  331. HRESULT
  332. MapSyntaxIdtoADsSyntax(
  333. DWORD dwSyntaxId,
  334. LPWSTR pszADsSyntax
  335. )
  336. {
  337. if (dwSyntaxId >= g_cNDSSyntaxMap) {
  338. wcscpy(pszADsSyntax, L"Out of Bounds");
  339. }else {
  340. wcscpy(pszADsSyntax, g_aNDSSyntaxMap[dwSyntaxId].bstrName);
  341. }
  342. RRETURN(S_OK);
  343. }
  344. HRESULT
  345. MapSyntaxIdtoNDSSyntax(
  346. DWORD dwSyntaxId,
  347. LPWSTR pszNDSSyntax
  348. )
  349. {
  350. if (dwSyntaxId > g_cNDSSyntaxMap) {
  351. wcscpy(pszNDSSyntax, L"Out of Bounds");
  352. }else {
  353. wcscpy(pszNDSSyntax, g_aNDSSyntaxMap[dwSyntaxId].bstrNDSName);
  354. }
  355. RRETURN(S_OK);
  356. }