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.

611 lines
15 KiB

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