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.

238 lines
6.3 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. /*++
  3. Copyright (C) Microsoft Corporation
  4. Module Name:
  5. rtradvise.cpp
  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. #include "Precompiled.h"
  16. #include "rtradvise.h"
  17. const IID IID_IRtrAdviseSink = {0x66A2DB14,0xD706,0x11d0,{0xA3,0x7B,0x00,0xC0,0x4F,0xC9,0xDA,0x04}};
  18. const IID IID_IRouterRefresh = {0x66a2db15,0xd706,0x11d0,{0xa3,0x7b,0x00,0xc0,0x4f,0xc9,0xda,0x04}};
  19. const IID IID_IRouterRefreshAccess = {0x66a2db1c,0xd706,0x11d0,{0xa3,0x7b,0x00,0xc0,0x4f,0xc9,0xda,0x04}};
  20. //----------------------------------------------------------------------------
  21. // Function: ConnectRegistry
  22. //
  23. // Connects to the registry on the specified machine
  24. //----------------------------------------------------------------------------
  25. DWORD ConnectRegistry(
  26. IN LPCTSTR pszMachine, // NULL if local
  27. OUT HKEY* phkeyMachine
  28. ) {
  29. //
  30. // if no machine name was specified, connect to the local machine.
  31. // otherwise, connect to the specified machine
  32. //
  33. DWORD dwErr = NO_ERROR;
  34. if (NULL == pszMachine)
  35. {
  36. *phkeyMachine = HKEY_LOCAL_MACHINE;
  37. }
  38. else
  39. {
  40. //
  41. // Make the connection
  42. //
  43. dwErr = ::RegConnectRegistry(
  44. (LPTSTR)pszMachine, HKEY_LOCAL_MACHINE, phkeyMachine
  45. );
  46. }
  47. return dwErr;
  48. }
  49. //----------------------------------------------------------------------------
  50. // Function: DisconnectRegistry
  51. //
  52. // Disconnects the specified config-handle. The handle is assumed to have been
  53. // acquired by calling 'ConnectRegistry'.
  54. //----------------------------------------------------------------------------
  55. VOID DisconnectRegistry(
  56. IN HKEY hkeyMachine
  57. ) {
  58. if (hkeyMachine != HKEY_LOCAL_MACHINE)
  59. {
  60. ::RegCloseKey(hkeyMachine);
  61. }
  62. }
  63. DWORD ReadRegistryStringValue(LPCTSTR pszMachine, LPCTSTR pszKeyUnderLocalMachine, LPCTSTR pszName, ::CString& strValue)
  64. {
  65. HKEY rootk = NULL;
  66. HKEY k = NULL;
  67. DWORD ret = NO_ERROR;
  68. if((ret = ConnectRegistry(pszMachine, &rootk)) != NO_ERROR)
  69. goto Error;
  70. // Cool, we have a machine registry entry, now get the
  71. // path down to the routertype key
  72. ret = RegOpenKeyEx(rootk, pszKeyUnderLocalMachine, 0, KEY_READ, &k);
  73. if (ret != NO_ERROR)
  74. goto Error;
  75. // Ok, at this point we just need to get the RouterType value from
  76. // the key
  77. {
  78. DWORD type = REG_SZ;
  79. TCHAR value[MAX_PATH];
  80. DWORD len = MAX_PATH;
  81. ret = ::RegQueryValueEx(k, pszName, 0, &type, (LPBYTE )value, &len);
  82. if(ret == ERROR_SUCCESS)
  83. strValue = value;
  84. }
  85. Error:
  86. if(rootk)
  87. DisconnectRegistry(rootk);
  88. if(k)
  89. RegCloseKey(k);
  90. return ret;
  91. }
  92. DWORD ReadRegistryDWORDValue(LPCTSTR pszMachine, LPCTSTR pszKeyUnderLocalMachine, LPCTSTR pszName, DWORD* pdwValue)
  93. {
  94. HKEY rootk = NULL;
  95. HKEY k = NULL;
  96. DWORD ret = NO_ERROR;
  97. if((ret = ConnectRegistry(pszMachine, &rootk)) != NO_ERROR)
  98. goto Error;
  99. // Cool, we have a machine registry entry, now get the
  100. // path down to the routertype key
  101. ret = RegOpenKeyEx(rootk, pszKeyUnderLocalMachine, 0, KEY_READ, &k);
  102. if (ret != NO_ERROR)
  103. goto Error;
  104. {
  105. // Ok, at this point we just need to get the RouterType value from
  106. // the key
  107. DWORD type = REG_DWORD;
  108. DWORD len = sizeof(DWORD);
  109. ret = ::RegQueryValueEx(k, pszName, 0, &type, (LPBYTE )pdwValue, &len);
  110. }
  111. Error:
  112. if(rootk)
  113. DisconnectRegistry(rootk);
  114. if(k)
  115. RegCloseKey(k);
  116. return ret;
  117. }
  118. //----------------------------------------------------------------------------
  119. //
  120. // helper functions to check if RRAS is using NT Authentication
  121. //
  122. //----------------------------------------------------------------------------
  123. BOOL IsRRASUsingNTAuthentication(LPCTSTR pszMachine) // when NULL: local machine
  124. {
  125. ::CString str;
  126. BOOL ret = FALSE;
  127. if(ERROR_SUCCESS == ReadRegistryStringValue(pszMachine,
  128. RegKeyRouterAuthenticationProviders,
  129. RegValueName_RouterActiveAuthenticationProvider,
  130. str))
  131. {
  132. ret = (str.CompareNoCase(NTRouterAuthenticationProvider) == 0);
  133. }
  134. return ret;
  135. }
  136. //----------------------------------------------------------------------------
  137. //
  138. // helper functions to check if RRAS is configured
  139. //
  140. //----------------------------------------------------------------------------
  141. BOOL IsRRASConfigured(LPCTSTR pszMachine) // when NULL: local machine
  142. {
  143. DWORD dwConfig= 0;
  144. ReadRegistryDWORDValue(pszMachine,
  145. RegRemoteAccessKey,
  146. RegRtrConfigured,
  147. &dwConfig);
  148. return (dwConfig != 0);
  149. }
  150. //----------------------------------------------------------------------------
  151. //
  152. // helper function to check if RRAS is using NT accounting for logging
  153. //
  154. //----------------------------------------------------------------------------
  155. BOOL IsRRASUsingNTAccounting(LPCTSTR pszMachine) // when NULL, local machine
  156. {
  157. ::CString str;
  158. BOOL ret = FALSE;
  159. if(ERROR_SUCCESS == ReadRegistryStringValue(pszMachine,
  160. RegKeyRouterAccountingProviders,
  161. RegValueName_RouterActiveAccountingProvider,
  162. str))
  163. {
  164. ret = (str.CompareNoCase(NTRouterAccountingProvider) == 0);
  165. }
  166. return ret;
  167. };
  168. static unsigned int s_cfComputerAddedAsLocal = RegisterClipboardFormat(L"MMC_MPRSNAP_COMPUTERADDEDASLOCAL");
  169. BOOL ExtractComputerAddedAsLocal(LPDATAOBJECT lpDataObject)
  170. {
  171. BOOL fReturn = FALSE;
  172. BOOL * pReturn;
  173. pReturn = Extract<BOOL>(lpDataObject, (CLIPFORMAT) s_cfComputerAddedAsLocal, -1);
  174. if (pReturn)
  175. {
  176. fReturn = *pReturn;
  177. GlobalFree(pReturn);
  178. }
  179. return fReturn;
  180. }