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.

226 lines
6.9 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. /*++
  3. Copyright (C) Microsoft Corporation
  4. Module Name:
  5. rtradvise.h
  6. Abstract:
  7. this class implement IRtrAdviseSink interface to redirect notification of changes
  8. to the snapin node
  9. Author:
  10. Wei Jiang 1/7/99
  11. Revision History:
  12. weijiang 1/7/99 - created
  13. --*/
  14. //////////////////////////////////////////////////////////////////////////////
  15. #if !defined(_IAS_MMC_RTRADVISE_H_)
  16. #define _IAS_MMC_RTRADVISE_H_
  17. #include <rrasui.h>
  18. #include <winreg.h>
  19. #include "iastrace.h"
  20. #define RegKeyRouterAccountingProviders _T("System\\CurrentControlSet\\Services\\RemoteAccess\\Accounting\\Providers")
  21. #define RegKeyRouterAuthenticationProviders _T("System\\CurrentControlSet\\Services\\RemoteAccess\\Authentication\\Providers")
  22. #define RegRemoteAccessKey _T("System\\CurrentControlSet\\Services\\RemoteAccess")
  23. #define RegRtrConfigured _T("ConfigurationFlags")
  24. #define NTRouterAccountingProvider _T("{1AA7F846-C7F5-11D0-A376-00C04FC9DA04}")
  25. #define NTRouterAuthenticationProvider _T("{1AA7F841-C7F5-11D0-A376-00C04FC9DA04}")
  26. #define RegValueName_RouterActiveAuthenticationProvider _T("ActiveProvider")
  27. #define RegValueName_RouterActiveAccountingProvider _T("ActiveProvider")
  28. //----------------------------------------------------------------------------
  29. // Function: ConnectRegistry
  30. //
  31. // Connects to the registry on the specified machine
  32. //----------------------------------------------------------------------------
  33. DWORD ConnectRegistry(
  34. IN LPCTSTR pszMachine, // NULL if local
  35. OUT HKEY* phkeyMachine
  36. );
  37. //----------------------------------------------------------------------------
  38. // Function: DisconnectRegistry
  39. //
  40. // Disconnects the specified config-handle. The handle is assumed to have been
  41. // acquired by calling 'ConnectRegistry'.
  42. //----------------------------------------------------------------------------
  43. VOID DisconnectRegistry( IN HKEY hkeyMachine );
  44. DWORD ReadRegistryStringValue(LPCTSTR pszMachine, LPCTSTR pszKeyUnderLocalMachine, LPCTSTR pszName, ::CString& strValue);
  45. DWORD ReadRegistryDWORDValue(LPCTSTR pszMachine, LPCTSTR pszKeyUnderLocalMachine, LPCTSTR pszName, DWORD* pdwValue);
  46. BOOL IsRRASConfigured(LPCTSTR pszMachine); // when NULL: local machine
  47. //----------------------------------------------------------------------------
  48. //
  49. // helper functions to check if RRAS is using NT Authentication
  50. //
  51. //----------------------------------------------------------------------------
  52. BOOL IsRRASUsingNTAuthentication(LPCTSTR pszMachine); // when NULL: local machine
  53. //----------------------------------------------------------------------------
  54. //
  55. // helper function to check if RRAS is using NT accounting for logging
  56. //
  57. //----------------------------------------------------------------------------
  58. BOOL IsRRASUsingNTAccounting(LPCTSTR pszMachine); // when NULL, local machine
  59. /////////////////////////////////////////////////////////////////////////////
  60. // CRtrAdviseSinkForIAS
  61. template <class TSnapinNode>
  62. class ATL_NO_VTABLE CRtrAdviseSinkForIAS :
  63. public CComObjectRoot,
  64. public IRtrAdviseSink
  65. {
  66. BEGIN_COM_MAP(CRtrAdviseSinkForIAS)
  67. COM_INTERFACE_ENTRY(IRtrAdviseSink)
  68. END_COM_MAP()
  69. public:
  70. CRtrAdviseSinkForIAS() : m_pSnapinNode(NULL){};
  71. ~CRtrAdviseSinkForIAS()
  72. {
  73. ReleaseSink();
  74. };
  75. // Need to call ReleaseSink when the snapin node is removed,
  76. void ReleaseSink()
  77. {
  78. if(m_pSnapinNode)
  79. {
  80. IASTracePrintf("UnadviseRefresh, snapinnode: ", (DWORD_PTR)m_pSnapinNode);
  81. ASSERT(m_spRouterRefresh != NULL);
  82. m_spRouterRefresh->UnadviseRefresh(m_ulConnection);
  83. m_spRouterRefresh.Release();
  84. m_pSnapinNode = NULL;
  85. };
  86. };
  87. public:
  88. STDMETHOD(OnChange)(
  89. /* [in] */ LONG_PTR ulConnection,
  90. /* [in] */ DWORD dwChangeType,
  91. /* [in] */ DWORD dwObjectType,
  92. /* [in] */ LPARAM lUserParam,
  93. /* [in] */ LPARAM lParam)
  94. {
  95. if(m_pSnapinNode)
  96. return m_pSnapinNode->OnRRASChange(ulConnection, dwChangeType, dwObjectType, lUserParam, lParam);
  97. else
  98. return S_OK;
  99. };
  100. // the object is created within the static function, and
  101. static CRtrAdviseSinkForIAS<TSnapinNode>* SetAdvise(TSnapinNode* pSnapinNode, IDataObject* pRRASDataObject)
  102. {
  103. if(pSnapinNode == NULL || pRRASDataObject == NULL)
  104. return NULL;
  105. // RRAS refresh advise setup F bug 213623:
  106. CComPtr<IRouterRefreshAccess> spRefreshAccess;
  107. CComPtr<IRouterRefresh> spRouterRefresh;
  108. CComObject< CRtrAdviseSinkForIAS<TSnapinNode> >* pSink = NULL;
  109. pRRASDataObject->QueryInterface(IID_IRouterRefreshAccess, (void**)&spRefreshAccess);
  110. if(spRefreshAccess != NULL)
  111. spRefreshAccess->GetRefreshObject(&spRouterRefresh);
  112. if(spRouterRefresh != NULL)
  113. {
  114. if(S_OK == CComObject< CRtrAdviseSinkForIAS<TSnapinNode> >::CreateInstance(&pSink))
  115. {
  116. ASSERT(pSink);
  117. pSink->AddRef();
  118. LONG_PTR ulConnection;
  119. IASTracePrintf("AdviseRefresh, snapinnode: ", (DWORD_PTR)pSnapinNode);
  120. spRouterRefresh->AdviseRefresh(pSink, &ulConnection, (LONG_PTR)pSnapinNode);
  121. pSink->m_ulConnection = ulConnection;
  122. pSink->m_pSnapinNode = pSnapinNode;
  123. pSink->m_spRouterRefresh = spRouterRefresh;
  124. }
  125. }
  126. // ~RRAS
  127. return pSink;
  128. };
  129. public:
  130. LONG_PTR m_ulConnection;
  131. TSnapinNode* m_pSnapinNode;
  132. CComPtr<IRouterRefresh> m_spRouterRefresh;
  133. };
  134. BOOL ExtractComputerAddedAsLocal(LPDATAOBJECT lpDataObject);
  135. //
  136. // Extracts a data type from a data object
  137. //
  138. template <class TYPE>
  139. TYPE* Extract(LPDATAOBJECT lpDataObject, CLIPFORMAT cf, int nSize)
  140. {
  141. ASSERT(lpDataObject != NULL);
  142. TYPE* p = NULL;
  143. STGMEDIUM stgmedium = { TYMED_HGLOBAL, NULL };
  144. FORMATETC formatetc = { cf, NULL,
  145. DVASPECT_CONTENT, -1, TYMED_HGLOBAL
  146. };
  147. int len;
  148. // Allocate memory for the stream
  149. if (nSize == -1)
  150. {
  151. len = sizeof(TYPE);
  152. }
  153. else
  154. {
  155. //int len = (cf == CDataObject::m_cfWorkstation) ?
  156. // ((MAX_COMPUTERNAME_LENGTH+1) * sizeof(TYPE)) : sizeof(TYPE);
  157. len = nSize;
  158. }
  159. stgmedium.hGlobal = GlobalAlloc(GMEM_SHARE, len);
  160. // Get the workstation name from the data object
  161. do
  162. {
  163. if (stgmedium.hGlobal == NULL)
  164. break;
  165. if (FAILED(lpDataObject->GetDataHere(&formatetc, &stgmedium)))
  166. break;
  167. p = reinterpret_cast<TYPE*>(stgmedium.hGlobal);
  168. if (p == NULL)
  169. break;
  170. } while (FALSE);
  171. return p;
  172. }
  173. #endif // _IAS_MMC_RTRADVISE_H_