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.

179 lines
5.6 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1996-2000 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // VerCheck.cpp
  7. //
  8. // Abstract:
  9. // Contains the implementation of the ClRtlIsVersionCheckingDisabled()
  10. // function that checks if the cluster version checking has been disabled
  11. // on a particular computer or not.
  12. //
  13. // Author:
  14. // Vijayendra Vasu (VVasu) 11-NOV-2000
  15. //
  16. // Revision History:
  17. // None.
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. //////////////////////////////////////////////////////////////////////////////
  21. // Include files
  22. //////////////////////////////////////////////////////////////////////////////
  23. #include <windows.h>
  24. #include <malloc.h>
  25. #include "clusudef.h"
  26. #include "clusrtl.h"
  27. /////////////////////////////////////////////////////////////////////////////
  28. //++
  29. //
  30. // ClRtlIsVersionCheckingDisabled()
  31. //
  32. // Routine Description:
  33. // Checks if cluster version checking has been disabled on a particular
  34. // computer.
  35. //
  36. // Arguments:
  37. // const WCHAR * pcszNodeNameIn
  38. // Name of the node on which the test for the version checking state
  39. // is to be performed. If NULL, this function checks if cluster
  40. // version checking in disabled on the local node.
  41. //
  42. // BOOL * pfVerCheckDisabledOut
  43. // Pointer to the boolean variable that will be set to TRUE if
  44. // version checking is disabled on pcszNodeNameIn and FALSE otherwise.
  45. //
  46. // Return Value:
  47. // ERROR_SUCCESS
  48. // If all went well.
  49. //
  50. // Other Win32 error codes
  51. // In case of error
  52. //
  53. //--
  54. /////////////////////////////////////////////////////////////////////////////
  55. DWORD ClRtlIsVersionCheckingDisabled(
  56. const WCHAR * pcszNodeNameIn
  57. , BOOL * pfVerCheckDisabledOut
  58. )
  59. {
  60. DWORD dwError = ERROR_SUCCESS;
  61. HKEY hRemoteRegistry = NULL;
  62. HKEY hClusSvcParamsKey = NULL;
  63. WCHAR * pszTempString = NULL;
  64. do
  65. {
  66. HKEY hParentKey = HKEY_LOCAL_MACHINE;
  67. DWORD dwVersionCheck = 0;
  68. DWORD dwType;
  69. DWORD dwSize;
  70. // Validate parameter.
  71. if ( pfVerCheckDisabledOut == NULL )
  72. {
  73. dwError = ERROR_INVALID_PARAMETER;
  74. break;
  75. } // if: the output parameter is invalid
  76. // Initialize output.
  77. *pfVerCheckDisabledOut = FALSE;
  78. // Connect to the remote registry, if required.
  79. if ( pcszNodeNameIn != NULL )
  80. {
  81. const WCHAR * pcszDoubleBackslashes = L"\\\\";
  82. DWORD cchComputerNameSize = wcslen( pcszNodeNameIn ) + 1;
  83. DWORD cchPrefixLen = wcslen( pcszDoubleBackslashes );
  84. // Allocate space for and prefix the computer name with '\\'
  85. pszTempString = reinterpret_cast< WCHAR * >( malloc( ( cchPrefixLen + cchComputerNameSize ) * sizeof( *pszTempString ) ) );
  86. if ( pszTempString == NULL )
  87. {
  88. dwError = ERROR_OUTOFMEMORY;
  89. break;
  90. } // if: memory allocation failed
  91. wcsncpy( pszTempString, pcszDoubleBackslashes, cchPrefixLen );
  92. wcsncpy( pszTempString + cchPrefixLen, pcszNodeNameIn, cchComputerNameSize );
  93. // Open the registry on the remote computer.
  94. dwError = RegConnectRegistry( pszTempString, HKEY_LOCAL_MACHINE, &hRemoteRegistry );
  95. if ( dwError != ERROR_SUCCESS )
  96. {
  97. break;
  98. } // if: RegConnectRegistry() has failed
  99. hParentKey = hRemoteRegistry;
  100. } // if: a remote computer needs to be contacted.
  101. // Open the cluster service parameters registry key.
  102. dwError = RegOpenKeyEx(
  103. hParentKey
  104. , CLUSREG_KEYNAME_CLUSSVC_PARAMETERS
  105. , 0
  106. , KEY_QUERY_VALUE
  107. , &hClusSvcParamsKey
  108. );
  109. if ( dwError != ERROR_SUCCESS )
  110. {
  111. if ( dwError == ERROR_FILE_NOT_FOUND )
  112. {
  113. // This is ok - absence of the value indicates that the cluster service
  114. // does not exist on the target computer.
  115. dwError = ERROR_SUCCESS;
  116. } // if: RegOpenKeyEx did not find the key
  117. break;
  118. } // if: RegOpenKeyEx() has failed
  119. // Read the required registry value
  120. dwSize = sizeof( dwVersionCheck );
  121. dwError = RegQueryValueEx(
  122. hClusSvcParamsKey
  123. , CLUSREG_NAME_SVC_PARAM_NOVER_CHECK
  124. , 0
  125. , &dwType
  126. , reinterpret_cast< BYTE * >( &dwVersionCheck )
  127. , &dwSize
  128. );
  129. if ( dwError == ERROR_FILE_NOT_FOUND )
  130. {
  131. // This is ok - absence of the value indicates that version checking is not disabled.
  132. dwVersionCheck = 0;
  133. dwError = ERROR_SUCCESS;
  134. } // if: RegQueryValueEx did not find the value
  135. else if ( dwError != ERROR_SUCCESS )
  136. {
  137. break;
  138. } // else if: RegQueryValueEx() has failed
  139. *pfVerCheckDisabledOut = ( dwVersionCheck == 0 ) ? FALSE : TRUE;
  140. }
  141. while( false ); // dummy do-while loop to avoid gotos
  142. //
  143. // Free acquired resources
  144. //
  145. if ( hRemoteRegistry != NULL )
  146. {
  147. RegCloseKey( hRemoteRegistry );
  148. } // if: we had opened the remote registry
  149. if ( hClusSvcParamsKey != NULL )
  150. {
  151. RegCloseKey( hClusSvcParamsKey );
  152. } // if: we had opened the cluster service parameters registry key
  153. // Free the allocated temporary string. (note, free( NULL ) is valid)
  154. free( pszTempString );
  155. return dwError;
  156. } //*** ClRtlIsVersionCheckingDisabled()