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.

181 lines
4.7 KiB

  1. // SessionResolver.h : Declaration of the CSessionResolver
  2. #ifndef __SESSIONRESOLVER_H_
  3. #define __SESSIONRESOLVER_H_
  4. #include "resource.h" // main symbols
  5. #include <io.h>
  6. #include <fcntl.h>
  7. #include <stdio.h>
  8. #include <sys/types.h>
  9. #include <sys/stat.h>
  10. #define DBG_MSG_DEST_FILE 0x020
  11. extern int gDbgFlag, iDbgFileHandle;
  12. typedef struct _SPLASHLIST
  13. {
  14. void *next;
  15. int refcount;
  16. SID Sid;
  17. } SPLASHLIST, *PSPLASHLIST;
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CSessionResolver
  20. class ATL_NO_VTABLE CSessionResolver :
  21. public CComObjectRootEx<CComSingleThreadModel>,
  22. public CComCoClass<CSessionResolver, &CLSID_SessionResolver>,
  23. public IDispatchImpl<ISAFRemoteDesktopCallback, &IID_ISAFRemoteDesktopCallback, &LIBID_SAFSESSIONRESOLVERLib>
  24. {
  25. public:
  26. CSessionResolver()
  27. {
  28. CRegKey hkSpew;
  29. // initialize our defaults
  30. m_iWaitDuration = 300 * 1000; // 5 minute timeout
  31. #ifdef _PERF_OPTIMIZATIONS
  32. m_bstrResolveURL = OLESTR("hcp://system/Remote%20Assistance/RAStartPage.htm");
  33. m_bstrConnectURL = OLESTR("hcp://system/Remote%20Assistance/RAStartPage.htm");
  34. m_bstrRemoteURL = OLESTR("hcp://system/Remote%20Assistance/RAStartPage.htm");
  35. #else
  36. m_bstrResolveURL = OLESTR("hcp://CN=Microsoft%20Corporation,L=Redmond,S=Washington,C=US/Remote%20Assistance/RAStartPage.htm");
  37. m_bstrConnectURL = OLESTR("hcp://CN=Microsoft%20Corporation,L=Redmond,S=Washington,C=US/Remote%20Assistance/RAStartPage.htm");
  38. m_bstrRemoteURL = OLESTR("hcp://CN=Microsoft%20Corporation,L=Redmond,S=Washington,C=US/Remote%20Assistance/RAStartPage.htm");
  39. #endif
  40. m_lSessionTag = 0;
  41. gDbgFlag = 3;
  42. iDbgFileHandle = 0;
  43. if (ERROR_SUCCESS == hkSpew.Open(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\PCHealth\\HelpCtr\\SAFSessionResolver", KEY_READ))
  44. {
  45. DWORD dwLen = sizeof(gDbgFlag);
  46. hkSpew.QueryValue((LPTSTR)&gDbgFlag, L"DebugSpew", &dwLen);
  47. }
  48. if (gDbgFlag & DBG_MSG_DEST_FILE)
  49. {
  50. WCHAR szLogfileName[MAX_PATH];
  51. GetSystemDirectory(szLogfileName, sizeof(szLogfileName)/sizeof(szLogfileName[0]));
  52. wcscat(szLogfileName, L"\\safrslv.log");
  53. iDbgFileHandle = _wopen(szLogfileName, _O_APPEND | _O_BINARY | _O_RDWR, 0);
  54. if (-1 != iDbgFileHandle)
  55. {
  56. OutputDebugStringA("opened debug log file\n");
  57. }
  58. else
  59. {
  60. unsigned char UniCode[2] = {0xff, 0xfe};
  61. // we must create the file
  62. OutputDebugStringA("must create debug log file");
  63. iDbgFileHandle = _wopen(szLogfileName, _O_BINARY | _O_CREAT | _O_RDWR, _S_IREAD | _S_IWRITE);
  64. if (-1 != iDbgFileHandle)
  65. _write(iDbgFileHandle, UniCode, sizeof(UniCode));
  66. else
  67. {
  68. OutputDebugStringA("ERROR: failed to create debug log file");
  69. iDbgFileHandle = 0;
  70. }
  71. }
  72. }
  73. m_pSplash = (SPLASHLIST *)LocalAlloc(LMEM_FIXED, sizeof(SPLASHLIST));
  74. if (m_pSplash)
  75. {
  76. // make certain that we start the splash list with an empty
  77. // SID.
  78. ZeroMemory(m_pSplash, sizeof(SPLASHLIST));
  79. }
  80. m_bCriticalError = FALSE;
  81. try
  82. {
  83. InitializeCriticalSection(&m_CritSec);
  84. }
  85. catch( ... )
  86. {
  87. m_bCriticalError = TRUE;
  88. }
  89. }
  90. ~CSessionResolver()
  91. {
  92. m_bstrResolveURL.Empty();
  93. m_bstrConnectURL.Empty();
  94. m_bstrRemoteURL.Empty();
  95. DeleteCriticalSection(&m_CritSec);
  96. PSPLASHLIST lpWalker, lpNext;
  97. lpWalker = m_pSplash;
  98. while (lpWalker)
  99. {
  100. lpNext = (SPLASHLIST *)lpWalker->next;
  101. LocalFree(lpWalker);
  102. lpWalker = lpNext;
  103. }
  104. if (iDbgFileHandle)
  105. _close(iDbgFileHandle);
  106. iDbgFileHandle = 0;
  107. }
  108. DECLARE_REGISTRY_RESOURCEID(IDR_SESSIONRESOLVER)
  109. DECLARE_NOT_AGGREGATABLE(CSessionResolver)
  110. DECLARE_PROTECT_FINAL_CONSTRUCT()
  111. BEGIN_COM_MAP(CSessionResolver)
  112. COM_INTERFACE_ENTRY(ISAFRemoteDesktopCallback)
  113. COM_INTERFACE_ENTRY(IDispatch)
  114. END_COM_MAP()
  115. public:
  116. //
  117. // ISAFRemoteDesktopCallback Methods
  118. //
  119. STDMETHOD(OnDisconnect)(
  120. /*[in]*/BSTR connectParms,
  121. /*[in]*/BSTR userSID,
  122. /*[in]*/long sessionID
  123. );
  124. STDMETHOD(ResolveUserSessionID)(
  125. /*[in]*/BSTR connectParms,
  126. /*[in]*/BSTR userSID,
  127. /*[in]*/ BSTR expertHelpBlob,
  128. /*[in]*/ BSTR userHelpBlob,
  129. /*[in]*/ ULONG_PTR hShutdown,
  130. /*[in, out, retval]*/long *sessionID,
  131. /*[in]*/DWORD dwPID
  132. ,/*[out]*/ULONG_PTR* hHelpCtr
  133. ,/*[out, retval]*/int *result
  134. );
  135. private:
  136. int m_iWaitDuration;
  137. int m_iDbgFlag;
  138. long m_lSessionTag;
  139. CRITICAL_SECTION m_CritSec;
  140. PSPLASHLIST m_pSplash;
  141. BOOL m_bCriticalError;
  142. CComBSTR m_bstrResolveURL;
  143. CComBSTR m_bstrConnectURL;
  144. CComBSTR m_bstrRemoteURL;
  145. };
  146. #endif //__SESSIONRESOLVER_H_