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.

402 lines
8.8 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995
  5. //
  6. // File: core.cxx
  7. //
  8. // Contents:
  9. //
  10. // History: 11-1-95 krishnag Created.
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "winnt.hxx"
  14. #pragma hdrstop
  15. HRESULT
  16. CCoreADsObject::InitializeCoreObject(
  17. LPWSTR Parent,
  18. LPWSTR Name,
  19. LPWSTR ClassName,
  20. LPWSTR Schema,
  21. REFCLSID rclsid,
  22. DWORD dwObjectState
  23. )
  24. {
  25. HRESULT hr = S_OK;
  26. ADsAssert(Parent);
  27. ADsAssert(Name);
  28. ADsAssert(ClassName);
  29. hr = BuildADsGuid(
  30. rclsid,
  31. &_ADsGuid
  32. );
  33. BAIL_ON_FAILURE(hr);
  34. if ( ( _tcsicmp( ClassName, PRINTJOB_CLASS_NAME ) == 0 )
  35. || ( _tcsicmp( ClassName, SESSION_CLASS_NAME ) == 0 )
  36. || ( _tcsicmp( ClassName, RESOURCE_CLASS_NAME ) == 0 )
  37. )
  38. {
  39. //
  40. // This three classes are not really DS objects so they don't
  41. // really have a parent. Hence, we set the parent string to empty
  42. // string.
  43. //
  44. _ADsPath = AllocADsStr(TEXT(""));
  45. hr = (_ADsPath ? S_OK: E_OUTOFMEMORY);
  46. BAIL_ON_FAILURE(hr);
  47. _Parent = AllocADsStr(TEXT(""));
  48. hr = (_Parent ? S_OK: E_OUTOFMEMORY);
  49. _dwNumComponents = 0;
  50. }
  51. else
  52. {
  53. hr = BuildADsPath(
  54. Parent,
  55. Name,
  56. &_ADsPath
  57. );
  58. BAIL_ON_FAILURE(hr);
  59. // get the number of components in the ADsPath
  60. hr = GetNumComponents();
  61. BAIL_ON_FAILURE(hr);
  62. _Parent = AllocADsStr(Parent);
  63. hr = (_Parent ? S_OK: E_OUTOFMEMORY);
  64. }
  65. BAIL_ON_FAILURE(hr);
  66. _Name = AllocADsStr(Name);
  67. hr = (_Name ? S_OK: E_OUTOFMEMORY);
  68. BAIL_ON_FAILURE(hr);
  69. _ADsClass = AllocADsStr(ClassName);
  70. hr = (_ADsClass ? S_OK: E_OUTOFMEMORY);
  71. BAIL_ON_FAILURE(hr);
  72. hr = BuildSchemaPath(
  73. Parent,
  74. Name,
  75. Schema,
  76. &_Schema
  77. );
  78. BAIL_ON_FAILURE(hr);
  79. _dwObjectState = dwObjectState;
  80. error:
  81. RRETURN(hr);
  82. }
  83. CCoreADsObject::CCoreADsObject():
  84. _Name(NULL),
  85. _ADsPath(NULL),
  86. _Parent(NULL),
  87. _ADsClass(NULL),
  88. _Schema(NULL),
  89. _ADsGuid(NULL),
  90. _dwObjectState(0),
  91. _pUnkOuter(NULL),
  92. _pObjectInfo(NULL),
  93. _pDispatch(NULL)
  94. {
  95. }
  96. CCoreADsObject::~CCoreADsObject()
  97. {
  98. if (_Name) {
  99. FreeADsStr(_Name);
  100. }
  101. if (_ADsPath) {
  102. FreeADsStr(_ADsPath);
  103. }
  104. if (_Parent) {
  105. FreeADsStr(_Parent);
  106. }
  107. if (_ADsClass) {
  108. FreeADsStr(_ADsClass);
  109. }
  110. if (_Schema) {
  111. FreeADsStr(_Schema);
  112. }
  113. if (_ADsGuid) {
  114. FreeADsStr(_ADsGuid);
  115. }
  116. if(_pObjectInfo != NULL) {
  117. FreeObjectInfo(&_ObjectInfo, TRUE);
  118. }
  119. }
  120. HRESULT
  121. CCoreADsObject::get_CoreName(BSTR * retval)
  122. {
  123. HRESULT hr;
  124. if (FAILED(hr = ValidateOutParameter(retval))){
  125. RRETURN_EXP_IF_ERR(hr);
  126. }
  127. hr = ADsAllocString(_Name, retval);
  128. RRETURN_EXP_IF_ERR(hr);
  129. }
  130. HRESULT
  131. CCoreADsObject::get_CoreADsPath(BSTR * retval)
  132. {
  133. HRESULT hr;
  134. if (FAILED(hr = ValidateOutParameter(retval))){
  135. RRETURN_EXP_IF_ERR(hr);
  136. }
  137. hr = ADsAllocString(_ADsPath, retval);
  138. RRETURN_EXP_IF_ERR(hr);
  139. }
  140. HRESULT
  141. CCoreADsObject::get_CoreADsClass(BSTR * retval)
  142. {
  143. HRESULT hr;
  144. if (FAILED(hr = ValidateOutParameter(retval))){
  145. RRETURN_EXP_IF_ERR(hr);
  146. }
  147. hr = ADsAllocString(_ADsClass, retval);
  148. RRETURN_EXP_IF_ERR(hr);
  149. }
  150. HRESULT
  151. CCoreADsObject::get_CoreParent(BSTR * retval)
  152. {
  153. HRESULT hr;
  154. if (FAILED(hr = ValidateOutParameter(retval))){
  155. RRETURN_EXP_IF_ERR(hr);
  156. }
  157. hr = ADsAllocString(_Parent, retval);
  158. RRETURN_EXP_IF_ERR(hr);
  159. }
  160. HRESULT
  161. CCoreADsObject::get_CoreSchema(BSTR * retval)
  162. {
  163. HRESULT hr;
  164. if (FAILED(hr = ValidateOutParameter(retval))){
  165. RRETURN_EXP_IF_ERR(hr);
  166. }
  167. if ( _Schema == NULL || *_Schema == 0 )
  168. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  169. hr = ADsAllocString(_Schema, retval);
  170. RRETURN_EXP_IF_ERR(hr);
  171. }
  172. HRESULT
  173. CCoreADsObject::get_CoreGUID(BSTR * retval)
  174. {
  175. HRESULT hr;
  176. if (FAILED(hr = ValidateOutParameter(retval))){
  177. RRETURN_EXP_IF_ERR(hr);
  178. }
  179. hr = ADsAllocString(_ADsGuid, retval);
  180. RRETURN_EXP_IF_ERR(hr);
  181. }
  182. STDMETHODIMP
  183. CCoreADsObject::GetInfo(THIS_ DWORD dwApiLevel, BOOL fExplicit)
  184. {
  185. RRETURN(E_NOTIMPL);
  186. }
  187. STDMETHODIMP
  188. CCoreADsObject::ImplicitGetInfo(void)
  189. {
  190. RRETURN(E_NOTIMPL);
  191. }
  192. //----------------------------------------------------------------------------
  193. // Function: InitUmiObject
  194. //
  195. // Synopsis: Initializes UMI object.
  196. //
  197. // Arguments:
  198. //
  199. // Credentials Credentials stored in the underlying WinNT object
  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. // pClassInfo Pointer to class information if this object is a class object.
  208. // NULL otherwise.
  209. //
  210. // Returns: S_OK if a UMI object is created and the interface is obtained.
  211. // Error code otherwise
  212. //
  213. // Modifies: *ppvObj to return the UMI interface requested.
  214. //
  215. //----------------------------------------------------------------------------
  216. HRESULT CCoreADsObject::InitUmiObject(
  217. CWinNTCredentials& Credentials,
  218. PPROPERTYINFO pSchema,
  219. DWORD dwSchemaSize,
  220. CPropertyCache * pPropertyCache,
  221. IUnknown *pUnkInner,
  222. CADsExtMgr *pExtMgr,
  223. REFIID riid,
  224. LPVOID *ppvObj,
  225. CLASSINFO *pClassInfo
  226. )
  227. {
  228. CUmiObject *pUmiObject = NULL;
  229. HRESULT hr = S_OK;
  230. // riid is a UMI interface
  231. if(NULL == ppvObj)
  232. RRETURN(E_POINTER);
  233. pUmiObject = new CUmiObject();
  234. if(NULL == pUmiObject)
  235. RRETURN(E_OUTOFMEMORY);
  236. hr = pUmiObject->FInit(
  237. Credentials,
  238. pSchema,
  239. dwSchemaSize,
  240. pPropertyCache,
  241. pUnkInner,
  242. pExtMgr,
  243. this,
  244. pClassInfo
  245. );
  246. BAIL_ON_FAILURE(hr);
  247. //
  248. // Bump up reference count of pUnkInner. On any error after this point,
  249. // the UMI object's destructor will call Release() on pUnkInner and we
  250. // don't want this to delete the WinNT object.
  251. //
  252. pUnkInner->AddRef();
  253. hr = pUmiObject->QueryInterface(riid, ppvObj);
  254. BAIL_ON_FAILURE(hr);
  255. // DECLARE_STD_REFCOUNTING initializes the refcount to 1. Call Release()
  256. // on the created object, so that releasing the interface pointer will
  257. // free the object.
  258. pUmiObject->Release();
  259. // Restore ref count of inner unknown
  260. pUnkInner->Release();
  261. //
  262. // reset ADS_AUTH_RESERVED flag in credentials. This is so that the
  263. // underlying WinNT object may be returned through IUmiCustomInterface to
  264. // the client. Doing this will ensure that the WinNT object should behave
  265. // like a ADSI object, not a UMI object.
  266. //
  267. Credentials.ResetUmiFlag();
  268. RRETURN(S_OK);
  269. error:
  270. if(pUmiObject != NULL)
  271. delete pUmiObject;
  272. RRETURN(hr);
  273. }
  274. //----------------------------------------------------------------------------
  275. // Function: GetNumComponents
  276. //
  277. // Synopsis: This function returns the number of components in the ADsPath.
  278. // A component is enclosed by '/' in an ADsPath.
  279. //
  280. // Arguments:
  281. //
  282. // None
  283. //
  284. // Returns: S_OK on success. Error code otherwise.
  285. //
  286. // Modifies: Nothing.
  287. //
  288. //----------------------------------------------------------------------------
  289. HRESULT CCoreADsObject::GetNumComponents(void)
  290. {
  291. CLexer Lexer(_ADsPath);
  292. HRESULT hr = S_OK;
  293. _pObjectInfo = &_ObjectInfo;
  294. memset(_pObjectInfo, 0, sizeof(OBJECTINFO));
  295. hr = Object(&Lexer, _pObjectInfo);
  296. if(FAILED(hr)) {
  297. _pObjectInfo = NULL; // so we don't attempt to free object info later
  298. goto error;
  299. }
  300. _dwNumComponents = _pObjectInfo->NumComponents;
  301. RRETURN(S_OK);
  302. error:
  303. if(_pObjectInfo != NULL)
  304. FreeObjectInfo(&_ObjectInfo, TRUE);
  305. RRETURN(hr);
  306. }