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.

340 lines
7.3 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1996
  5. //
  6. // File: core.cxx
  7. //
  8. // Contents:
  9. //
  10. // History: 06-15-96 yihsins Created.
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "ldap.hxx"
  14. #pragma hdrstop
  15. HRESULT
  16. CCoreADsObject::InitializeCoreObject(
  17. BSTR Parent,
  18. BSTR Name,
  19. BSTR SchemaClass,
  20. REFCLSID rclsid,
  21. DWORD dwObjectState
  22. )
  23. {
  24. HRESULT hr = S_OK;
  25. //
  26. // Both should never be NULL, replacing the ADsAsserts with
  27. // this check to make sure that we never get into this problem
  28. // on all builds.
  29. //
  30. if (!Parent || !Name) {
  31. BAIL_ON_FAILURE(hr = E_FAIL);
  32. }
  33. hr = BuildADsPath(
  34. Parent,
  35. Name,
  36. &_ADsPath
  37. );
  38. BAIL_ON_FAILURE(hr);
  39. hr = BuildADsGuid(
  40. rclsid,
  41. &_ADsGuid
  42. );
  43. BAIL_ON_FAILURE(hr);
  44. hr = ADsAllocString( Parent, &_Parent);
  45. BAIL_ON_FAILURE(hr);
  46. hr = ADsAllocString( Name, &_Name);
  47. BAIL_ON_FAILURE(hr);
  48. hr = ADsAllocString( SchemaClass, &_SchemaClass);
  49. BAIL_ON_FAILURE(hr);
  50. _dwObjectState = dwObjectState;
  51. error:
  52. RRETURN(hr);
  53. }
  54. CCoreADsObject::CCoreADsObject():
  55. _Name(NULL),
  56. _ADsPath(NULL),
  57. _Parent(NULL),
  58. _ADsClass(NULL),
  59. _SchemaClass(NULL),
  60. _ADsGuid(NULL),
  61. _pUnkOuter(NULL),
  62. _dwObjectState(0)
  63. {
  64. }
  65. CCoreADsObject::~CCoreADsObject()
  66. {
  67. if (_Name) {
  68. ADsFreeString(_Name);
  69. }
  70. if (_ADsPath) {
  71. ADsFreeString(_ADsPath);
  72. }
  73. if (_Parent) {
  74. ADsFreeString(_Parent);
  75. }
  76. if (_ADsClass) {
  77. ADsFreeString(_ADsClass);
  78. }
  79. if (_SchemaClass) {
  80. ADsFreeString(_SchemaClass);
  81. }
  82. if (_ADsGuid) {
  83. ADsFreeString(_ADsGuid);
  84. }
  85. }
  86. HRESULT
  87. CCoreADsObject::get_CoreName(BSTR * retval)
  88. {
  89. HRESULT hr;
  90. //
  91. // Make sure that the last error is reset
  92. //
  93. Macro_ClearADsLastError(L"LDAP Provider");
  94. if (FAILED(hr = ValidateOutParameter(retval))){
  95. RRETURN_EXP_IF_ERR(hr);
  96. }
  97. hr = ADsAllocString(_Name, retval);
  98. RRETURN_EXP_IF_ERR(hr);
  99. }
  100. HRESULT
  101. CCoreADsObject::get_CoreADsPath(BSTR * retval)
  102. {
  103. HRESULT hr;
  104. //
  105. // Make sure that the last error is reset
  106. //
  107. Macro_ClearADsLastError(L"LDAP Provider");
  108. if (FAILED(hr = ValidateOutParameter(retval))){
  109. RRETURN_EXP_IF_ERR(hr);
  110. }
  111. hr = ADsAllocString(_ADsPath, retval);
  112. RRETURN_EXP_IF_ERR(hr);
  113. }
  114. HRESULT
  115. CCoreADsObject::get_CoreADsClass(BSTR * retval)
  116. {
  117. HRESULT hr;
  118. //
  119. // Make sure that the last error is reset
  120. //
  121. Macro_ClearADsLastError(L"LDAP Provider");
  122. if (FAILED(hr = ValidateOutParameter(retval))){
  123. RRETURN_EXP_IF_ERR(hr);
  124. }
  125. if ( _SchemaClass == NULL || *_SchemaClass == 0 ) {
  126. hr = ADsAllocString(_ADsClass, retval);
  127. RRETURN_EXP_IF_ERR(hr);
  128. }
  129. hr = ADsAllocString(_SchemaClass, retval); // report the actual class
  130. RRETURN_EXP_IF_ERR(hr);
  131. }
  132. HRESULT
  133. CCoreADsObject::get_CoreParent(BSTR * retval)
  134. {
  135. HRESULT hr;
  136. //
  137. // Make sure that the last error is reset
  138. //
  139. Macro_ClearADsLastError(L"LDAP Provider");
  140. if (FAILED(hr = ValidateOutParameter(retval))){
  141. RRETURN_EXP_IF_ERR(hr);
  142. }
  143. hr = ADsAllocString(_Parent, retval);
  144. RRETURN_EXP_IF_ERR(hr);
  145. }
  146. HRESULT
  147. CCoreADsObject::get_CoreSchema(BSTR * retval)
  148. {
  149. HRESULT hr;
  150. //
  151. // Make sure that the last error is reset
  152. //
  153. Macro_ClearADsLastError(L"LDAP Provider");
  154. if (FAILED(hr = ValidateOutParameter(retval))){
  155. RRETURN_EXP_IF_ERR(hr);
  156. }
  157. if ( _SchemaClass == NULL || *_SchemaClass == 0 )
  158. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  159. hr = BuildSchemaPath(
  160. _ADsPath,
  161. _SchemaClass,
  162. retval );
  163. RRETURN_EXP_IF_ERR(hr);
  164. }
  165. HRESULT
  166. CCoreADsObject::get_CoreGUID(BSTR * retval)
  167. {
  168. HRESULT hr;
  169. //
  170. // Make sure that the last error is reset
  171. //
  172. Macro_ClearADsLastError(L"LDAP Provider");
  173. if (FAILED(hr = ValidateOutParameter(retval))){
  174. RRETURN_EXP_IF_ERR(hr);
  175. }
  176. hr = ADsAllocString(_ADsGuid, retval);
  177. RRETURN_EXP_IF_ERR(hr);
  178. }
  179. STDMETHODIMP
  180. CCoreADsObject::GetInfo(THIS_ DWORD dwFlags)
  181. {
  182. RRETURN_EXP_IF_ERR(E_NOTIMPL);
  183. }
  184. STDMETHODIMP
  185. CCoreADsObject::GetInfo(
  186. THIS_ LPWSTR szPropertyName,
  187. DWORD dwSyntaxId,
  188. BOOL fExplicit
  189. )
  190. {
  191. RRETURN(E_NOTIMPL);
  192. }
  193. //----------------------------------------------------------------------------
  194. // Function: InitUmiObject
  195. //
  196. // Synopsis: Initializes UMI object.
  197. //
  198. // Arguments:
  199. //
  200. // pSchema Pointer to schema for this object
  201. // dwSchemaSize Size of schema array
  202. // pPropCache Pointer to property cache for this object
  203. // pUnkInner Pointer to inner unknown of WinNT object
  204. // pExtMgr Pointer to extension manager object on WinNT object
  205. // riid Interface requested
  206. // ppvObj Returns pointer to interface
  207. //
  208. // Returns: S_OK if a UMI object is created and the interface is obtained.
  209. // Error code otherwise
  210. //
  211. // Modifies: *ppvObj to return the UMI interface requested.
  212. //
  213. //----------------------------------------------------------------------------
  214. HRESULT
  215. CCoreADsObject::InitUmiObject(
  216. INTF_PROP_DATA intfProps[],
  217. CPropertyCache * pPropertyCache,
  218. IADs *pIADs,
  219. IUnknown *pUnkInner,
  220. REFIID riid,
  221. LPVOID *ppvObj,
  222. CCredentials *pCreds,
  223. DWORD dwPort, // defaulted to -1
  224. LPWSTR pszServerName, // defaulted to NULL
  225. LPWSTR pszLdapDn, // defaulted to NULL
  226. PADSLDP pLdapHandle, // defaulted to NULL,
  227. CADsExtMgr *pExtMgr // defaulted to NULL
  228. )
  229. {
  230. HRESULT hr = S_OK;
  231. CLDAPUmiObject *pUmiObject = NULL;
  232. if (!ppvObj) {
  233. RRETURN(E_INVALIDARG);
  234. }
  235. hr = CLDAPUmiObject::CreateLDAPUmiObject(
  236. intfProps,
  237. pPropertyCache,
  238. pUnkInner,
  239. this, // pCoreObj
  240. pIADs,
  241. pCreds,
  242. &pUmiObject,
  243. dwPort,
  244. pLdapHandle,
  245. pszServerName,
  246. pszLdapDn,
  247. pExtMgr
  248. );
  249. BAIL_ON_FAILURE(hr);
  250. //
  251. // Bump up reference count of pUnkInner. On any error after this point,
  252. // the UMI object's destructor will call Release() on pUnkInner and we
  253. // don't want this to delete the LDAP object.
  254. //
  255. pUnkInner->AddRef();
  256. hr = pUmiObject->QueryInterface(riid, ppvObj);
  257. BAIL_ON_FAILURE(hr);
  258. //
  259. // Ref on umi object is now 2, reduce by one.
  260. //
  261. pUmiObject->Release();
  262. //
  263. // Restore ref count of inner unknown
  264. //
  265. pUnkInner->Release();
  266. RRETURN(S_OK);
  267. error:
  268. if (pUmiObject) {
  269. delete pUmiObject;
  270. }
  271. RRETURN(hr);
  272. }
  273. 
  274.