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.

599 lines
15 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995
  5. //
  6. // File: cfpnwres.cxx
  7. //
  8. // Contents: Contains methods for the following objects
  9. // CFPNWResource, CFPNWFSResourceGeneralInfo
  10. //
  11. //
  12. // History: 05/01/96 ramv (Ram Viswanathan) Created.
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "winnt.hxx"
  16. #pragma hdrstop
  17. #define INITGUID
  18. DECLARE_INFOLEVEL( FPNWResource );
  19. DECLARE_DEBUG( FPNWResource );
  20. #define FPNWResourceDebugOut(x) FPNWResourceInlineDebugOut x
  21. DEFINE_IDispatch_ExtMgr_Implementation(CFPNWResource);
  22. DEFINE_IADsExtension_ExtMgr_Implementation(CFPNWResource);
  23. DEFINE_IADs_TempImplementation(CFPNWResource);
  24. DEFINE_IADs_PutGetImplementation(CFPNWResource,FPNWResourceClass,gdwFPNWResourceTableSize) ;
  25. DEFINE_IADsPropertyList_Implementation(CFPNWResource, FPNWResourceClass,gdwFPNWResourceTableSize)
  26. CFPNWResource::CFPNWResource()
  27. {
  28. _pDispMgr = NULL;
  29. _pExtMgr = NULL;
  30. _pszServerName = NULL;
  31. _pPropertyCache = NULL;
  32. _pszServerADsPath = NULL;
  33. _pszUserName = NULL;
  34. _pszPath = NULL;
  35. ENLIST_TRACKING(CFPNWResource);
  36. return;
  37. }
  38. CFPNWResource::~CFPNWResource()
  39. {
  40. delete _pExtMgr; // created last, destroyed first
  41. delete _pDispMgr;
  42. if(_pszServerName){
  43. FreeADsStr(_pszServerName);
  44. }
  45. if (_pszServerADsPath)
  46. {
  47. FreeADsStr(_pszServerADsPath);
  48. }
  49. if (_pszUserName)
  50. {
  51. ADsFreeString(_pszUserName);
  52. }
  53. if (_pszPath)
  54. {
  55. FreeADsStr(_pszPath);
  56. }
  57. delete _pPropertyCache;
  58. return;
  59. }
  60. //+---------------------------------------------------------------------------
  61. //
  62. // Function: CFPNWResource::Create
  63. //
  64. // Synopsis: Static function used to create a Resource object. This
  65. // will be called by EnumResources::Next
  66. //
  67. // Arguments: [ppFPNWResource] -- Ptr to a ptr to a new Resource object.
  68. //
  69. // Returns: HRESULT.
  70. //
  71. // Modifies:
  72. //
  73. // History: 12-11-95 RamV Created.
  74. //
  75. //----------------------------------------------------------------------------
  76. HRESULT
  77. CFPNWResource::Create(LPTSTR pszServerADsPath,
  78. PNWFILEINFO pFileInfo,
  79. DWORD dwObject,
  80. REFIID riid,
  81. CWinNTCredentials& Credentials,
  82. LPVOID * ppvoid
  83. )
  84. {
  85. CFPNWResource FAR * pCFPNWResource = NULL;
  86. HRESULT hr;
  87. TCHAR szFileName[MAX_LONG_LENGTH];
  88. TCHAR szUncServerName[MAX_PATH];
  89. hr =CFPNWResource::AllocateResourceObject(pszServerADsPath,
  90. pFileInfo,
  91. &pCFPNWResource );
  92. BAIL_IF_ERROR(hr);
  93. ADsAssert(pCFPNWResource->_pDispMgr);
  94. //
  95. // convert the FileId that we have into a string that we move
  96. // into the Name field
  97. //
  98. _ltow(pFileInfo->dwFileId, szFileName, 10);
  99. hr = pCFPNWResource->InitializeCoreObject(pszServerADsPath,
  100. szFileName,
  101. RESOURCE_CLASS_NAME,
  102. FPNW_RESOURCE_SCHEMA_NAME,
  103. CLSID_FPNWResource,
  104. dwObject);
  105. pCFPNWResource->_dwFileId = pFileInfo->dwFileId;
  106. pCFPNWResource->_Credentials = Credentials;
  107. hr = pCFPNWResource->_Credentials.RefServer(
  108. pCFPNWResource->_pszServerName);
  109. BAIL_IF_ERROR(hr);
  110. hr = SetLPTSTRPropertyInCache(
  111. pCFPNWResource->_pPropertyCache,
  112. TEXT("Name"),
  113. pCFPNWResource->_Name,
  114. TRUE
  115. );
  116. BAIL_IF_ERROR(hr);
  117. //
  118. // Load ext mgr and extensions
  119. //
  120. hr = ADSILoadExtensionManager(
  121. RESOURCE_CLASS_NAME,
  122. (IADs* ) pCFPNWResource,
  123. pCFPNWResource->_pDispMgr,
  124. Credentials,
  125. &pCFPNWResource->_pExtMgr
  126. );
  127. BAIL_IF_ERROR(hr);
  128. ADsAssert(pCFPNWResource->_pExtMgr);
  129. // check if the call is from UMI
  130. if(Credentials.GetFlags() & ADS_AUTH_RESERVED) {
  131. //
  132. // we do not pass riid to InitUmiObject below. This is because UMI object
  133. // does not support IDispatch. There are several places in ADSI code where
  134. // riid passed into this function is defaulted to IID_IDispatch -
  135. // IADsContainer::Create for example. To handle these cases, we always
  136. // request IID_IUnknown from the UMI object. Subsequent code within UMI
  137. // will QI for the appropriate interface.
  138. //
  139. // Resource objects have "" as their ADsPath. Just set the class to
  140. // resource for identification purposes.
  141. pCFPNWResource->_CompClasses[0] = L"Resource";
  142. hr = pCFPNWResource->InitUmiObject(
  143. pCFPNWResource->_Credentials,
  144. FPNWResourceClass,
  145. gdwFPNWResourceTableSize,
  146. pCFPNWResource->_pPropertyCache,
  147. (IUnknown *) (INonDelegatingUnknown *) pCFPNWResource,
  148. pCFPNWResource->_pExtMgr,
  149. IID_IUnknown,
  150. ppvoid
  151. );
  152. BAIL_IF_ERROR(hr);
  153. //
  154. // UMI object was created and the interface was obtained successfully.
  155. // UMI object now has a reference to the inner unknown of IADs, since
  156. // the call to Release() below is not going to be made in this case.
  157. //
  158. RRETURN(hr);
  159. }
  160. ADsAssert(ppvoid);
  161. hr = pCFPNWResource->QueryInterface(riid, (void **)ppvoid);
  162. BAIL_IF_ERROR(hr);
  163. pCFPNWResource->Release();
  164. RRETURN(hr);
  165. cleanup:
  166. if(SUCCEEDED(hr)){
  167. RRETURN(hr);
  168. }
  169. delete pCFPNWResource;
  170. RRETURN_EXP_IF_ERR(hr);
  171. }
  172. HRESULT
  173. CFPNWResource::AllocateResourceObject(LPTSTR pszServerADsPath,
  174. PNWFILEINFO pFileInfo,
  175. CFPNWResource ** ppResource)
  176. {
  177. CFPNWResource FAR * pCFPNWResource = NULL;
  178. HRESULT hr;
  179. TCHAR szFileName[MAX_LONG_LENGTH];
  180. TCHAR szUncServerName[MAX_PATH];
  181. POBJECTINFO pServerObjectInfo = NULL;
  182. //
  183. // Create the Resource Object
  184. //
  185. pCFPNWResource = new CFPNWResource();
  186. if (pCFPNWResource == NULL) {
  187. hr = E_OUTOFMEMORY;
  188. goto cleanup;
  189. }
  190. pCFPNWResource->_pDispMgr = new CAggregatorDispMgr;
  191. if(pCFPNWResource ->_pDispMgr == NULL){
  192. hr = E_OUTOFMEMORY;
  193. goto cleanup;
  194. }
  195. hr = LoadTypeInfoEntry(pCFPNWResource->_pDispMgr,
  196. LIBID_ADs,
  197. IID_IADsResource,
  198. (IADsResource *)pCFPNWResource,
  199. DISPID_REGULAR);
  200. BAIL_IF_ERROR(hr);
  201. hr = LoadTypeInfoEntry(pCFPNWResource->_pDispMgr,
  202. LIBID_ADs,
  203. IID_IADsPropertyList,
  204. (IADsPropertyList *)pCFPNWResource,
  205. DISPID_VALUE);
  206. BAIL_IF_ERROR(hr);
  207. pCFPNWResource->_pszServerADsPath =
  208. AllocADsStr(pszServerADsPath);
  209. if(!(pCFPNWResource->_pszServerADsPath)){
  210. hr = E_OUTOFMEMORY;
  211. goto cleanup;
  212. }
  213. hr = BuildObjectInfo(pszServerADsPath,
  214. &pServerObjectInfo);
  215. BAIL_IF_ERROR(hr);
  216. pCFPNWResource->_pszServerName =
  217. AllocADsStr(pServerObjectInfo->ComponentArray[1]);
  218. if(!(pCFPNWResource->_pszServerName)){
  219. hr = E_OUTOFMEMORY;
  220. goto cleanup;
  221. }
  222. hr = CPropertyCache::createpropertycache(
  223. FPNWResourceClass,
  224. gdwFPNWResourceTableSize,
  225. (CCoreADsObject *)pCFPNWResource,
  226. &(pCFPNWResource->_pPropertyCache)
  227. );
  228. hr = SetLPTSTRPropertyInCache(pCFPNWResource->_pPropertyCache,
  229. TEXT("User"),
  230. pFileInfo->lpUserName,
  231. TRUE
  232. );
  233. BAIL_IF_ERROR(hr);
  234. hr = ADsAllocString(pFileInfo->lpUserName,
  235. &(pCFPNWResource->_pszUserName));
  236. BAIL_IF_ERROR(hr);
  237. hr = SetLPTSTRPropertyInCache(pCFPNWResource->_pPropertyCache,
  238. TEXT("Path"),
  239. pFileInfo->lpPathName,
  240. TRUE
  241. );
  242. BAIL_IF_ERROR(hr);
  243. pCFPNWResource->_pszPath =
  244. AllocADsStr(pFileInfo->lpPathName);
  245. if(!(pCFPNWResource->_pszPath)){
  246. hr = E_OUTOFMEMORY;
  247. goto cleanup;
  248. }
  249. hr = SetDWORDPropertyInCache(pCFPNWResource->_pPropertyCache,
  250. TEXT("LockCount"),
  251. pFileInfo->dwLocks,
  252. TRUE
  253. );
  254. pCFPNWResource->_dwLockCount = pFileInfo->dwLocks;
  255. pCFPNWResource->_pDispMgr->RegisterPropertyCache(
  256. pCFPNWResource->_pPropertyCache
  257. );
  258. *ppResource = pCFPNWResource;
  259. cleanup:
  260. if(pServerObjectInfo){
  261. FreeObjectInfo(pServerObjectInfo);
  262. }
  263. if (!SUCCEEDED(hr)) {
  264. //
  265. // direct memeber assignement assignement at pt of creation, so
  266. // do NOT delete _pPropertyCache or _pDisMgr here to avoid attempt
  267. // of deletion again in pPrintJob destructor and AV
  268. //
  269. delete pCFPNWResource;
  270. }
  271. RRETURN(hr);
  272. }
  273. /* IUnknown methods for Resource object */
  274. //----------------------------------------------------------------------------
  275. // Function: QueryInterface
  276. //
  277. // Synopsis: If this object is aggregated within another object, then
  278. // all calls will delegate to the outer object. Otherwise, the
  279. // non-delegating QI is called
  280. //
  281. // Arguments:
  282. //
  283. // iid interface requested
  284. // ppInterface Returns pointer to interface requested. NULL if interface
  285. // is not supported.
  286. //
  287. // Returns: S_OK on success. Error code otherwise.
  288. //
  289. // Modifies: *ppInterface to return interface pointer
  290. //
  291. //----------------------------------------------------------------------------
  292. STDMETHODIMP CFPNWResource::QueryInterface(
  293. REFIID iid,
  294. LPVOID *ppInterface
  295. )
  296. {
  297. if(_pUnkOuter != NULL)
  298. RRETURN(_pUnkOuter->QueryInterface(
  299. iid,
  300. ppInterface
  301. ));
  302. RRETURN(NonDelegatingQueryInterface(
  303. iid,
  304. ppInterface
  305. ));
  306. }
  307. //----------------------------------------------------------------------------
  308. // Function: AddRef
  309. //
  310. // Synopsis: IUnknown::AddRef. If this object is aggregated within
  311. // another, all calls will delegate to the outer object.
  312. // Otherwise, the non-delegating AddRef is called
  313. //
  314. // Arguments:
  315. //
  316. // None
  317. //
  318. // Returns: New reference count
  319. //
  320. // Modifies: Nothing
  321. //
  322. //----------------------------------------------------------------------------
  323. STDMETHODIMP_(ULONG) CFPNWResource::AddRef(void)
  324. {
  325. if(_pUnkOuter != NULL)
  326. RRETURN(_pUnkOuter->AddRef());
  327. RRETURN(NonDelegatingAddRef());
  328. }
  329. //----------------------------------------------------------------------------
  330. // Function: Release
  331. //
  332. // Synopsis: IUnknown::Release. If this object is aggregated within
  333. // another, all calls will delegate to the outer object.
  334. // Otherwise, the non-delegating Release is called
  335. //
  336. // Arguments:
  337. //
  338. // None
  339. //
  340. // Returns: New reference count
  341. //
  342. // Modifies: Nothing
  343. //
  344. //----------------------------------------------------------------------------
  345. STDMETHODIMP_(ULONG) CFPNWResource::Release(void)
  346. {
  347. if(_pUnkOuter != NULL)
  348. RRETURN(_pUnkOuter->Release());
  349. RRETURN(NonDelegatingRelease());
  350. }
  351. //----------------------------------------------------------------------------
  352. STDMETHODIMP
  353. CFPNWResource::NonDelegatingQueryInterface(REFIID riid, LPVOID FAR* ppvObj)
  354. {
  355. HRESULT hr = S_OK;
  356. if(ppvObj == NULL){
  357. RRETURN(E_POINTER);
  358. }
  359. if (IsEqualIID(riid, IID_IUnknown))
  360. {
  361. *ppvObj = (IADs *) this;
  362. }
  363. else if (IsEqualIID(riid, IID_IDispatch))
  364. {
  365. *ppvObj = (IADs *)this;
  366. }
  367. else if (IsEqualIID(riid, IID_ISupportErrorInfo))
  368. {
  369. *ppvObj = (ISupportErrorInfo FAR *) this;
  370. }
  371. else if (IsEqualIID(riid, IID_IADs))
  372. {
  373. *ppvObj = (IADs FAR *) this;
  374. }
  375. else if (IsEqualIID(riid, IID_IADsPropertyList))
  376. {
  377. *ppvObj = (IADsPropertyList FAR *) this;
  378. }
  379. else if (IsEqualIID(riid, IID_IADsResource))
  380. {
  381. *ppvObj = (IADsResource FAR *) this;
  382. }
  383. else if( (_pDispatch != NULL) &&
  384. IsEqualIID(riid, IID_IADsExtension) )
  385. {
  386. *ppvObj = (IADsExtension *) this;
  387. }
  388. else if (_pExtMgr)
  389. {
  390. RRETURN( _pExtMgr->QueryInterface(riid, ppvObj));
  391. }
  392. else
  393. {
  394. *ppvObj = NULL;
  395. RRETURN(E_NOINTERFACE);
  396. }
  397. ((LPUNKNOWN)*ppvObj)->AddRef();
  398. RRETURN(S_OK);
  399. }
  400. /* ISupportErrorInfo method */
  401. STDMETHODIMP
  402. CFPNWResource::InterfaceSupportsErrorInfo(
  403. THIS_ REFIID riid
  404. )
  405. {
  406. if (IsEqualIID(riid, IID_IADs) ||
  407. IsEqualIID(riid, IID_IADsResource) ||
  408. IsEqualIID(riid, IID_IADsPropertyList)) {
  409. RRETURN(S_OK);
  410. } else {
  411. RRETURN(S_FALSE);
  412. }
  413. }
  414. /* IADs methods */
  415. //+-----------------------------------------------------------------
  416. //
  417. // Function: SetInfo
  418. //
  419. // Synopsis: SetInfo on actual Resource
  420. //
  421. // Arguments: void
  422. //
  423. // Returns: HRESULT.
  424. //
  425. // Modifies:
  426. //
  427. // History: 02/08/96 RamV Created
  428. //----------------------------------------------------------------------------
  429. STDMETHODIMP
  430. CFPNWResource::SetInfo(THIS)
  431. {
  432. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  433. }
  434. STDMETHODIMP
  435. CFPNWResource::GetInfo(THIS)
  436. {
  437. _pPropertyCache->flushpropcache();
  438. RRETURN(S_OK);
  439. }
  440. STDMETHODIMP
  441. CFPNWResource::ImplicitGetInfo(THIS)
  442. {
  443. RRETURN(S_OK);
  444. }
  445. STDMETHODIMP
  446. CFPNWResource::get_User(THIS_ BSTR FAR* retval)
  447. {
  448. HRESULT hr;
  449. if(!retval){
  450. RRETURN_EXP_IF_ERR(E_ADS_BAD_PARAMETER);
  451. }
  452. hr = ADsAllocString(_pszUserName, retval);
  453. RRETURN_EXP_IF_ERR(hr);
  454. }
  455. STDMETHODIMP
  456. CFPNWResource::get_UserPath(THIS_ BSTR FAR* retval)
  457. {
  458. RRETURN_EXP_IF_ERR(E_ADS_PROPERTY_NOT_SUPPORTED);
  459. }
  460. STDMETHODIMP
  461. CFPNWResource::get_Path(THIS_ BSTR FAR* retval)
  462. {
  463. HRESULT hr;
  464. if(!retval){
  465. RRETURN_EXP_IF_ERR(E_ADS_BAD_PARAMETER);
  466. }
  467. hr = ADsAllocString(_pszPath, retval);
  468. RRETURN_EXP_IF_ERR(hr);
  469. }
  470. STDMETHODIMP
  471. CFPNWResource::get_LockCount(THIS_ LONG FAR* retval)
  472. {
  473. if(!retval){
  474. RRETURN_EXP_IF_ERR(E_ADS_BAD_PARAMETER);
  475. }
  476. *retval = _dwLockCount;
  477. RRETURN(S_OK);
  478. }