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.

401 lines
9.0 KiB

  1. /*++
  2. Copyright (c) 1999-2000 Microsoft Corporation
  3. Module Name:
  4. HelpMgr.h
  5. Abstract:
  6. Declaration of the CRemoteDesktopHelpSessionMgr
  7. Author:
  8. HueiWang 2/17/2000
  9. --*/
  10. #ifndef __REMOTEDESKTOPHELPSESSIONMGR_H_
  11. #define __REMOTEDESKTOPHELPSESSIONMGR_H_
  12. #include "resource.h" // main symbols
  13. typedef struct __ExpertLogoffStruct {
  14. HANDLE hWaitObject;
  15. HANDLE hWaitProcess;
  16. LONG ExpertSessionId;
  17. CComBSTR bstrHelpedTicketId;
  18. CComBSTR bstrWinStationName;
  19. __ExpertLogoffStruct() {
  20. hWaitObject = NULL;
  21. hWaitProcess = NULL;
  22. };
  23. ~__ExpertLogoffStruct() {
  24. if( NULL != hWaitObject )
  25. {
  26. UnregisterWait( hWaitObject );
  27. }
  28. if( NULL != hWaitProcess )
  29. {
  30. CloseHandle( hWaitProcess );
  31. }
  32. }
  33. } EXPERTLOGOFFSTRUCT, *PEXPERTLOGOFFSTRUCT;
  34. #ifdef __cplusplus
  35. extern "C"{
  36. #endif
  37. HRESULT
  38. ImpersonateClient();
  39. void
  40. EndImpersonateClient();
  41. HRESULT
  42. LoadLocalSystemSID();
  43. HRESULT
  44. RegisterResolverWithGIT(
  45. ISAFRemoteDesktopCallback* pResolver
  46. );
  47. HRESULT
  48. LoadResolverFromGIT(
  49. ISAFRemoteDesktopCallback** ppResolver
  50. );
  51. HRESULT
  52. UnInitializeGlobalInterfaceTable();
  53. HRESULT
  54. InitializeGlobalInterfaceTable();
  55. DWORD
  56. MonitorExpertLogoff(
  57. IN LONG pidToWaitFor,
  58. IN LONG expertSessionId,
  59. IN BSTR bstrHelpedTicketId
  60. );
  61. VOID
  62. CleanupMonitorExpertList();
  63. #ifdef __cplusplus
  64. }
  65. #endif
  66. typedef MAP<PVOID, PEXPERTLOGOFFSTRUCT> EXPERTLOGOFFMONITORLIST;
  67. class CRemoteDesktopHelpSession;
  68. //
  69. // Help Session Manager service name, this must be consistent with
  70. // with COM or COM won't find us.
  71. //
  72. #define HELPSESSIONMGR_SERVICE_NAME \
  73. _TEXT("RemoteDesktopHelpSessionMgr")
  74. //
  75. // STL Help Session ID to actual help session object map.
  76. //
  77. typedef MAP< CComBSTR, CComObject<CRemoteDesktopHelpSession>* > IDToSessionMap;
  78. typedef CComObject< CRemoteDesktopHelpSession > RemoteDesktopHelpSessionObj;
  79. /////////////////////////////////////////////////////////////////////////////
  80. // CRemoteDesktopHelpSessionMgr
  81. class ATL_NO_VTABLE CRemoteDesktopHelpSessionMgr :
  82. public CComObjectRootEx<CComMultiThreadModel>,
  83. public CComCoClass<CRemoteDesktopHelpSessionMgr, &CLSID_RemoteDesktopHelpSessionMgr>,
  84. public IDispatchImpl<IRemoteDesktopHelpSessionMgr, &IID_IRemoteDesktopHelpSessionMgr, &LIBID_RDSESSMGRLib>
  85. {
  86. friend class CRemoteDesktopUserPolicy;
  87. public:
  88. CRemoteDesktopHelpSessionMgr();
  89. ~CRemoteDesktopHelpSessionMgr() {}
  90. DECLARE_REGISTRY_RESOURCEID(IDR_REMOTEDESKTOPHELPSESSIONMGR)
  91. //DECLARE_CLASSFACTORY_SINGLETON(CRemoteDesktopHelpSessionMgr)
  92. DECLARE_PROTECT_FINAL_CONSTRUCT()
  93. BEGIN_COM_MAP(CRemoteDesktopHelpSessionMgr)
  94. COM_INTERFACE_ENTRY(IRemoteDesktopHelpSessionMgr)
  95. COM_INTERFACE_ENTRY(IDispatch)
  96. END_COM_MAP()
  97. //
  98. // Can't impersonate so can't pre-load user SID at FinalConstruct()
  99. //
  100. HRESULT
  101. FinalConstruct()
  102. {
  103. ULONG count = _Module.AddRef();
  104. DebugPrintf(
  105. _TEXT("Module AddRef by CRemoteDesktopHelpSessionMgr() %d...\n"),
  106. count
  107. );
  108. BOOL bSuccess = _Module.InitializeSessmgr();
  109. DebugPrintf(
  110. _TEXT("_Module.InitializeSessmgr() return %d\n"),
  111. bSuccess
  112. );
  113. return S_OK;
  114. }
  115. void
  116. FinalRelease()
  117. {
  118. Cleanup();
  119. ULONG count = _Module.Release();
  120. DebugPrintf(
  121. _TEXT("Module Release by CRemoteDesktopHelpSessionMgr() %d ...\n"),
  122. count
  123. );
  124. }
  125. // IRemoteDesktopHelpSessionMgr
  126. public:
  127. STDMETHOD(ResetHelpAssistantAccount)(
  128. /*[in]*/ BOOL bForce
  129. );
  130. STDMETHOD(CreateHelpSession)(
  131. /*[in]*/ BSTR bstrSessName,
  132. /*[in]*/ BSTR bstrSessPwd,
  133. /*[in]*/ BSTR bstrUserHelpBlob,
  134. /*[in]*/ BSTR bstrUserHelpCreateBlob,
  135. /*[out, retval]*/ IRemoteDesktopHelpSession** ppIRemoteDesktopHelpSession
  136. );
  137. STDMETHOD(DeleteHelpSession)(
  138. /*[in]*/ BSTR HelpSessionID
  139. );
  140. STDMETHOD(RetrieveHelpSession)(
  141. /*[in]*/ BSTR HelpSessionID,
  142. /*[out, retval]*/ IRemoteDesktopHelpSession** ppIRemoteDesktopHelpSession
  143. );
  144. STDMETHOD(VerifyUserHelpSession)(
  145. /*[in]*/ BSTR HelpSessionId,
  146. /*[in]*/ BSTR bstrSessPwd,
  147. /*[in]*/ BSTR bstrResolverConnectBlob,
  148. /*[in]*/ BSTR bstrUserHelpCreateBlob,
  149. /*[in]*/ LONG CallerProcessId,
  150. /*[out]*/ ULONG_PTR* phHelpCtr,
  151. /*[out]*/ LONG* pResolverRetCode,
  152. /*[out, retval]*/ long* pdwUserLogonSession
  153. );
  154. STDMETHOD(GetUserSessionRdsSetting)(
  155. /*[out, retval]*/ REMOTE_DESKTOP_SHARING_CLASS* sessionRdsLevel
  156. );
  157. STDMETHOD(RemoteCreateHelpSession)(
  158. /*[in]*/ REMOTE_DESKTOP_SHARING_CLASS sharingClass,
  159. /*[in]*/ LONG timeOut,
  160. /*[in]*/ LONG userSessionId,
  161. /*[in]*/ BSTR userSid,
  162. /*[in]*/ BSTR bstrUserHelpCreateBlob,
  163. /*[out, retval]*/ BSTR* parms
  164. );
  165. STDMETHOD(CreateHelpSessionEx)(
  166. /*[in]*/ REMOTE_DESKTOP_SHARING_CLASS sharingClass,
  167. /*[in]*/ BOOL fEnableCallback,
  168. /*[in]*/ LONG timeOut,
  169. /*[in]*/ LONG userSessionId,
  170. /*[in]*/ BSTR userSid,
  171. /*[in]*/ BSTR bstrUserHelpCreateBlob,
  172. /*[out, retval]*/ IRemoteDesktopHelpSession** ppIRemoteDesktopHelpSession
  173. );
  174. HRESULT RemoteCreateHelpSessionEx(
  175. /*[in]*/ BOOL bCacheEntry,
  176. /*[in]*/ BOOL bEnableResolver,
  177. /*[in]*/ REMOTE_DESKTOP_SHARING_CLASS sharingClass,
  178. /*[in]*/ LONG timeOut,
  179. /*[in]*/ LONG userSessionId,
  180. /*[in]*/ BSTR userSid,
  181. /*[in]*/ BSTR bstrUserHelpCreateBlob,
  182. /*[out, retval]*/ RemoteDesktopHelpSessionObj** ppIRemoteDesktopHelpSession
  183. );
  184. STDMETHOD(IsValidHelpSession)(
  185. /*[in]*/ BSTR HelpSessionId,
  186. /*[in]*/ BSTR HelpSessionPwd
  187. );
  188. STDMETHOD(LogSalemEvent)(
  189. /*[in]*/ long ulEventType,
  190. /*[in]*/ long ulEventCode,
  191. /*[in]*/ VARIANT* pEventStrings
  192. );
  193. static HRESULT
  194. AddHelpSessionToCache(
  195. IN BSTR bstrHelpId,
  196. IN CComObject<CRemoteDesktopHelpSession>* pIHelpSession
  197. );
  198. static HRESULT
  199. DeleteHelpSessionFromCache(
  200. IN BSTR bstrHelpId
  201. );
  202. static void
  203. TimeoutHelpSesion();
  204. static void
  205. LockIDToSessionMapCache()
  206. {
  207. gm_HelpIdToHelpSession.Lock();
  208. }
  209. static void
  210. UnlockIDToSessionMapCache()
  211. {
  212. gm_HelpIdToHelpSession.Unlock();
  213. }
  214. static HRESULT
  215. LogoffUserHelpSessionCallback(
  216. IN CComBSTR& bstrHelpId,
  217. IN HANDLE userData
  218. );
  219. static void
  220. NotifyHelpSesionLogoff(
  221. DWORD dwLogonId
  222. );
  223. static void
  224. NotifyExpertLogoff(
  225. LONG ExpertSessionId,
  226. BSTR HelpedTicketId
  227. );
  228. static void
  229. NotifyPendingHelpServiceStartup();
  230. static HRESULT
  231. NotifyPendingHelpServiceStartCallback(
  232. IN CComBSTR& bstrHelpId,
  233. IN HANDLE userData
  234. );
  235. private:
  236. HRESULT
  237. LogSalemEvent(
  238. IN long ulEventType,
  239. IN long ulEventCode,
  240. IN long numStrings = 0,
  241. IN LPCTSTR* strings = NULL
  242. );
  243. static
  244. RemoteDesktopHelpSessionObj*
  245. LoadHelpSessionObj(
  246. IN CRemoteDesktopHelpSessionMgr* pMgr,
  247. IN BSTR bstrHelpSession,
  248. IN BOOL bLoadExpiredHelp = FALSE
  249. );
  250. static HRESULT
  251. ExpireUserHelpSessionCallback(
  252. IN CComBSTR& pHelp,
  253. IN HANDLE userData
  254. );
  255. static HRESULT
  256. GenerateHelpSessionId(
  257. OUT CComBSTR& bstrHelpId
  258. );
  259. static HRESULT
  260. AcquireAssistantAccount();
  261. static HRESULT
  262. ReleaseAssistantAccount();
  263. void
  264. Cleanup();
  265. HRESULT
  266. IsUserAllowToGetHelp(
  267. OUT BOOL* pbAllow
  268. );
  269. BOOL
  270. CheckAccessRights(
  271. IN CComObject<CRemoteDesktopHelpSession>* pIHelpSess
  272. );
  273. HRESULT
  274. CreateHelpSession(
  275. IN BOOL bCacheEntry,
  276. IN BSTR bstrSessName,
  277. IN BSTR bstrSessPwd,
  278. IN BSTR bstrSessDesc,
  279. IN BSTR bstrSessBlob,
  280. IN LONG userLogonId,
  281. IN BSTR bstrClientSID,
  282. OUT RemoteDesktopHelpSessionObj** ppIRemoteDesktopHelpSession
  283. );
  284. HRESULT
  285. LoadUserSid();
  286. LONG m_LogonId;
  287. PBYTE m_pbUserSid; // Client SID.
  288. DWORD m_cbUserSid; // size of client SID.
  289. CComBSTR m_bstrUserSid; // For performance reason, convert SID to string
  290. // form once for all.
  291. //LONG m_lAccountAcquiredByLocal; // number of reference lock this connection placed on
  292. // help assistant account
  293. typedef vector< CComBSTR > LocalHelpSessionCache;
  294. // STL does not like list<CComBSTR>, CComBSTR has & defined.
  295. //LocalHelpSessionCache m_HelpListByLocal; // ID of Help Session created by this connection.
  296. static CCriticalSection gm_AccRefCountCS;
  297. //
  298. // COM create a new CRemoteDesktopHelpSessionMgr object for new connection
  299. // so these values must be static
  300. //
  301. static IDToSessionMap gm_HelpIdToHelpSession;
  302. };
  303. #endif //__REMOTEDESKTOPHELPSESSIONMGR_H_