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.

263 lines
8.5 KiB

  1. //-----------------------------------------------------------------------------------------
  2. #pragma once
  3. #include <windows.h>
  4. #include <windef.h>
  5. #include <tchar.h>
  6. #include <setupapi.h>
  7. #include <atlbase.h>
  8. #include <string>
  9. #include <vector>
  10. #include <map>
  11. #include <resapi.h>
  12. #include <clusapi.h>
  13. #include "ocmanage.h"
  14. using namespace std;
  15. #define tstring basic_string <TCHAR>
  16. #include "..\shared\propertybag.h"
  17. #define UDDI_SETUP_LOG TEXT( "uddisetup.log" )
  18. #define DEFAULT_SQL_INSTANCE_NAME TEXT( "(default)" )
  19. #define DEFAULT_SQL_INSTANCE_NATIVE TEXT( "MSSQLSERVER" )
  20. //--------------------------------------------------------------------------
  21. #define PROPKEY_UDDIPROVIDER TEXT( "UPRV" )
  22. #define PROPKEY_ADDSERVICES TEXT( "UDDI_ADDSVC" )
  23. #define PROPKEY_UPDATE_AD TEXT( "UDDI_UPDATEAD" )
  24. #define PROPKEY_SYSPATH TEXT( "SFP" )
  25. #define PROPKEY_COREPATH_1 TEXT( "C1P" )
  26. #define PROPKEY_COREPATH_2 TEXT( "C2P" )
  27. #define PROPKEY_JRNLPATH TEXT( "JRNLP" )
  28. #define PROPKEY_STGPATH TEXT( "STGP" )
  29. #define PROPKEY_XLOGPATH TEXT( "XLP" )
  30. #define PROPKEY_CLUSTERNODETYPE TEXT( "CNTYPE" )
  31. #define PROPKEY_ACTIVENODE TEXT( "A" )
  32. #define PROPKEY_PASSIVENODE TEXT( "P" )
  33. //-----------------------------------------------------------------------------------------
  34. typedef enum { UDDI_MSDE, UDDI_DB, UDDI_WEB, UDDI_ADMIN, UDDI_COMBO } UDDI_PACKAGE_ID;
  35. typedef enum { UDDI_NOACTION, UDDI_UNINSTALL, UDDI_INSTALL } INSTALL_LEVEL;
  36. #define MAX_PROPERTY_COUNT 10
  37. #define MSI_GUID_LEN 39
  38. #define UDDI_MSDE_INSTANCE_NAME TEXT( "UDDI" )
  39. const LPCTSTR UDDI_LOCAL_COMPUTER = NULL;
  40. const bool UDDI_INSTALLING_MSDE = true;
  41. const bool UDDI_NOT_INSTALLING_MSDE = false;
  42. //
  43. // SQL Server 2000 SP3
  44. //
  45. #define MIN_SQLSP_VERSION TEXT( "8.0.760" )
  46. //
  47. // These types are used by the clustering routines
  48. //
  49. #define DIM(x) ( sizeof x )/( sizeof x[0] )
  50. typedef struct _cPhysicalDriveInfo
  51. {
  52. tstring sDriveLetter;
  53. tstring sResName;
  54. tstring sOwningNode;
  55. tstring sGroupName;
  56. _cPhysicalDriveInfo( LPCTSTR szName, LPCTSTR szNode, LPCTSTR szGroup, LPCTSTR szDriveLetter )
  57. {
  58. sResName = szName;
  59. sOwningNode = szNode;
  60. sGroupName = szGroup;
  61. sDriveLetter = szDriveLetter;
  62. };
  63. }
  64. cPhysicalDriveInfo;
  65. typedef std::map<tstring, cPhysicalDriveInfo> cDrvMap;
  66. typedef std::pair<tstring, cPhysicalDriveInfo> cDrvMapPair;
  67. typedef cDrvMap::iterator cDrvIterator;
  68. typedef std::map<tstring, tstring> cStrMap;
  69. typedef std::pair<tstring, tstring> cStrMapPair;
  70. typedef cStrMap::iterator cStrIterator;
  71. typedef std::vector<tstring> cStrList;
  72. typedef cStrList::iterator cStrListIterator;
  73. //
  74. // this struct holds data describing a SQL database instance
  75. //
  76. typedef struct tagDbInstance
  77. {
  78. bool bIsLocalComputer;
  79. bool bIsCluster;
  80. tstring cComputerName;
  81. tstring cSQLInstanceName;
  82. tstring cFullName;
  83. tstring cSPVersion;
  84. tstring cSQLVersion;
  85. tagDbInstance() { bIsLocalComputer = true; bIsCluster = false; }
  86. } DB_INSTANCE;
  87. //
  88. // this struct holds all the data needed to install a single UDDI component
  89. //
  90. typedef struct
  91. {
  92. tstring cOCMName;
  93. bool bOCMComponent; // true if an actual component on the OCM
  94. tstring cMSIName;
  95. tstring cCABName;
  96. INSTALL_LEVEL iInstallLevel;
  97. CPropertyBag installProperties;
  98. TCHAR szMSIPath[ MAX_PATH ];
  99. TCHAR szUpgradeCode[ MSI_GUID_LEN ];
  100. TCHAR szProductCode[ MSI_GUID_LEN ];
  101. } SINGLE_UDDI_PACKAGE_DEF;
  102. //
  103. // We have 4 "real" packages and one "virtual" - UDDI Combo
  104. //
  105. #define UDDI_PACKAGE_COUNT 5
  106. //
  107. // This structure is used for clustered environment drive letter filtering
  108. //
  109. #define MAX_DRIVE_COUNT 255
  110. typedef struct
  111. {
  112. int driveCount; // -1 means no filtering at all
  113. tstring drives[ MAX_DRIVE_COUNT ]; // allowed drive letters
  114. }
  115. CLST_ALLOWED_DRIVES;
  116. //
  117. // container class for the struct defined above
  118. //
  119. class CUDDIInstall
  120. {
  121. public:
  122. CUDDIInstall();
  123. void SetInstallLevel( UDDI_PACKAGE_ID id, INSTALL_LEVEL iInstallLevel, BOOL bForceInstall = FALSE );
  124. void SetInstallLevel( LPCTSTR szOCMName, INSTALL_LEVEL iInstallLevel, BOOL bForceInstall = FALSE );
  125. void AddProperty( UDDI_PACKAGE_ID id, LPCTSTR szProperty, LPCTSTR szValue );
  126. void AddProperty( UDDI_PACKAGE_ID id, LPCTSTR szProperty, DWORD dwValue );
  127. LPCTSTR GetProperty ( UDDI_PACKAGE_ID id, LPCTSTR szProperty, LPTSTR szOutBuf );
  128. void DeleteProperty( UDDI_PACKAGE_ID id, LPCTSTR szProperty );
  129. void DeleteProperties( UDDI_PACKAGE_ID id );
  130. void UpdateAllInstallLevel();
  131. bool IsInstalled( UDDI_PACKAGE_ID id );
  132. bool IsInstalled( LPCTSTR szOCMName );
  133. bool IsInstalling( UDDI_PACKAGE_ID id );
  134. bool IsUninstalling( UDDI_PACKAGE_ID id );
  135. bool IsInstalling( LPCTSTR szOCMName );
  136. LPCTSTR GetInstallStateText( LPCTSTR szOCMName );
  137. LPCTSTR GetInstallStateText( UDDI_PACKAGE_ID id );
  138. LPCTSTR GetDefaultDataPath ();
  139. UDDI_PACKAGE_ID GetPackageID( LPCTSTR szOCMName );
  140. void SetInstance( HINSTANCE hInstance ) { m_hInstance = hInstance; }
  141. bool IsAnyInstalling();
  142. bool IsClusteredDBInstance() { return m_dbinstance.bIsCluster; }
  143. bool SetDBInstanceName( LPCTSTR szComputerName, LPCTSTR szNewInstanceName, bool bIsInstallingMSDE, bool bIsCluster );
  144. HRESULT DetectOSFlavor();
  145. UINT GetOSSuiteMask() { return m_uSuiteMask; }
  146. bool IsStdServer() { return ( m_uSuiteMask & VER_SUITE_DATACENTER ) || ( m_uSuiteMask & VER_SUITE_DATACENTER ) ? false : true; }
  147. LPCTSTR GetDBInstanceName();
  148. LPCTSTR GetFullDBInstanceName();
  149. LPCTSTR GetDBComputerName();
  150. UINT Install();
  151. private:
  152. bool SetMSIPath( UDDI_PACKAGE_ID id );
  153. UINT InstallPackage( UDDI_PACKAGE_ID id );
  154. UINT UninstallPackage( UDDI_PACKAGE_ID id );
  155. UINT PostInstallPackage( UDDI_PACKAGE_ID id );
  156. private:
  157. HINSTANCE m_hInstance;
  158. UINT m_uSuiteMask;
  159. tstring m_cDefaultDataDir;
  160. SINGLE_UDDI_PACKAGE_DEF m_package[ UDDI_PACKAGE_COUNT ];
  161. DB_INSTANCE m_dbinstance;
  162. };
  163. //-----------------------------------------------------------------------------------------
  164. //
  165. // container class of the list of all db instances on a given (local or remote) machine
  166. //
  167. #define MAX_INSTANCE_COUNT 50
  168. class CDBInstance
  169. {
  170. public:
  171. CDBInstance( LPCTSTR szRemoteMachine = NULL );
  172. LONG GetInstalledDBInstanceNames( LPCTSTR szRemoteMachine = NULL );
  173. bool GetUDDIDBInstanceName( LPCTSTR szRemoteMachine, LPTSTR szInstanceName, PULONG puLen, bool *pbIsClustered = NULL );
  174. int IsInstanceInstalled( LPCTSTR szInstanceName );
  175. bool GetInstanceName(int i, PTCHAR szBuffer, UINT uBufLen );
  176. int GetInstanceCount() { return m_instanceCount; };
  177. bool GetSqlInstanceVersion( HKEY hParentKey, LPCTSTR szInstanceName, LPTSTR szInstanceVersion, DWORD dwVersionLen, LPTSTR szCDSVersion, DWORD dwCSDVersionLen );
  178. bool IsClusteredDB( HKEY hParentKey, LPCTSTR szInstanceName, LPTSTR szVirtualMachineName, DWORD dwLen );
  179. DB_INSTANCE m_dbinstance[ MAX_INSTANCE_COUNT ];
  180. private:
  181. int m_instanceCount;
  182. };
  183. //-----------------------------------------------------------------------------------------
  184. //
  185. // helper functions
  186. //
  187. DWORD RunMSIEXECCommandLine( tstring &szMSIArgs );
  188. bool IsExistMinDotNetVersion( LPCTSTR szMinDotNetVersion );
  189. bool IsSQLRun08AlreadyUsed( bool *bIsUsed );
  190. bool IsOsWinXP();
  191. DWORD EnableRemoteRegistry();
  192. int CompareVersions( LPCTSTR szVersion1, LPCTSTR szVersion2 );
  193. bool CheckForAdminPrivs();
  194. void RaiseErrorDialog( LPCTSTR szAction, DWORD dwErrorCode );
  195. bool IsTSAppCompat();
  196. HRESULT GetDBSchemaVersion( LPCTSTR szInstanceName, LPTSTR szVerBuf, size_t cbVerBuf );
  197. HRESULT AddServiceAccount( LPCTSTR szInstanceName, LPCTSTR szUser );
  198. //*****************************************************************************************
  199. // Cluster helper functions
  200. //
  201. // Enumerates SQL Server dependencies for a given instance. NULL -> enumerates all instances
  202. // The instance name is expected to be in a fully-qualified format: <virtual server>\<instance>
  203. //
  204. DWORD EnumSQLDependencies( HCLUSTER hCls, cStrList *pList, LPCTSTR szInstanceNameOnly = NULL );
  205. //
  206. // Enumerates physical drives and its characteristics, optionaly filtering out only those
  207. // that appear in the Sql Dependencies list.
  208. // Empty list means no filtering.
  209. // BOTH pointers MUST be valid (no NULLS allowed)
  210. //
  211. DWORD EnumPhysicalDrives( HCLUSTER hCls, cStrList *pSqlDependencies, cDrvMap *pPhysicalDrives );
  212. //
  213. // Retrieves the owning node for the specific SQL instance
  214. // The instance name is expected to be in the fully-qualified format
  215. // i.e. <Virtual Server Name>\<Instance Name>
  216. //
  217. DWORD GetSqlNode( LPCWSTR szInstanceName, LPWSTR szNodeNameBuf, DWORD cbBufSize );