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.

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