コード例 #1
0
        public static string GetSQLServerInstanceNameStr(bool isWap)
        {
            string sqlMachine            = SelectDatabaseServerPage.sqlMachineName;
            string sqlServerInstanceName = String.Empty;
            String sqlMachineName        = String.Empty;
            String instanceName          = (String)SetupInputs.Instance.FindItem(SetupInputTags.GetSqlInstanceNameTag(isWap));

            if (String.IsNullOrEmpty(sqlMachine))
            {
                sqlMachineName = (String)SetupInputs.Instance.FindItem(SetupInputTags.GetSqlMachineNameTag(isWap));
            }
            else
            {
                sqlMachineName = sqlMachine;
            }
            if (String.IsNullOrEmpty(instanceName) || String.Equals(instanceName, sqlMachineName, StringComparison.OrdinalIgnoreCase))
            {
                sqlServerInstanceName = sqlMachineName;
            }
            else
            {
                sqlServerInstanceName = String.Format(SetupConstants.UserAccountTemplate, sqlMachineName, instanceName);
            }
            int sqlPort = (int)SetupInputs.Instance.FindItem(SetupInputTags.SqlServerPortTag);

            if (sqlPort != 0 && sqlPort != 1433)
            {
                sqlServerInstanceName = String.Format("{0},{1}", sqlServerInstanceName, sqlPort);
            }

            return(sqlServerInstanceName);
        }
コード例 #2
0
        public static string ConfigureServerCommandLineArguments()
        {
            StringBuilder arguments = new StringBuilder();

            // Check to see if this is an uninstall
            if (PropertyBagDictionary.Instance.PropertyExists(PropertyBagConstants.Uninstall))
            {
                arguments.Append("REMOVE=ALL ");
                arguments.AppendFormat(CultureInfo.InvariantCulture, "UNINSTALLSERVER = 1 ");
            }
            else
            {
                String serviceAccount = UserAccountHelper.GetServiceAccount();
                arguments.AppendFormat(CultureInfo.InvariantCulture, "SERVERACCOUNTNAME=\"{0}\" ", serviceAccount);  // for agent installation
                if (SetupInputs.Instance.FindItem(SetupInputTags.CmpServiceLocalAccountTag))
                {
                    serviceAccount = SetupConstants.LocalSystem;
                }
                arguments.AppendFormat(CultureInfo.InvariantCulture, "SERVICEACCOUNT=\"{0}\" ", serviceAccount); // for registry
                arguments.AppendFormat(CultureInfo.InvariantCulture, "USERNAME=\"{0}\" ", (String)SetupInputs.Instance.FindItem(SetupInputTags.UserNameTag));

                arguments.AppendFormat(CultureInfo.InvariantCulture, "SQLPORT=\"{0}\" ", (int)SetupInputs.Instance.FindItem(SetupInputTags.SqlServerPortTag));
                string sqlInstanceName = InstallItemCustomDelegates.GetSQLServerInstanceNameStr(false);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "INSTANCENAME=\"{0}\" ", sqlInstanceName);

                String dbName = (String)SetupInputs.Instance.FindItem(SetupInputTags.SqlDatabaseNameTag);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "DATABASENAME=\"{0}\" ", dbName);
                string partialConnectionString = SetupDatabaseHelper.ConstructConnectionString(sqlInstanceName);
                string connectionString        = String.Format("{0}database={1}", partialConnectionString, dbName);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "CONNECTIONSTR=\"{0}\" ", connectionString);

                string sqlMachineName  = DnsHelper.GetComputerNameFromFqdnOrNetBios((String)SetupInputs.Instance.FindItem(SetupInputTags.GetSqlMachineNameTag(false)));
                bool   onRemoteMachine = String.Compare(sqlMachineName, Environment.MachineName, true) != 0;
                arguments.AppendFormat(CultureInfo.InvariantCulture, "ONREMOTESERVER=\"{0}\" ", onRemoteMachine ? 1 : 0);

                String sqlMachineFqdn = DnsHelper.GetFullyQualifiedName(sqlMachineName);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "SQLMACHINENAME=\"{0}\" ", sqlMachineName);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "SQLMACHINEFQDN=\"{0}\" ", sqlMachineFqdn);

                arguments.AppendFormat(CultureInfo.InvariantCulture, "SETUPLANGUAGE=\"{0}\" ", CultureInfo.CurrentUICulture.Name);

                String certificateThumbprint = (String)SetupInputs.Instance.FindItem(SetupInputTags.CmpCertificateThumbprintTag);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "CERTIFICATETHUMBPRINT=\"{0}\" ", "LocalMachine,My," + certificateThumbprint);

                // Encrypt the password of the worker service so that WAP extensions can use it
                InputParameter pwd            = SetupInputs.Instance.FindItem(SetupInputTags.SqlDBAdminPasswordTag);
                string         passwordAsText = null;
                if (pwd != null)
                {
                    IntPtr unmanagedString = IntPtr.Zero;
                    try
                    {
                        unmanagedString = Marshal.SecureStringToGlobalAllocUnicode(pwd);
                        passwordAsText  = Marshal.PtrToStringUni(unmanagedString);
                    }
                    finally
                    {
                        Marshal.ZeroFreeGlobalAllocUnicode(unmanagedString);
                    }
                }
                string encryptedPassword = String.Format("{0}{1}{2}", "[KText]", UserAccountHelper.EncryptStringUsingLocalCertificate(passwordAsText, certificateThumbprint), "[KText]");

                arguments.AppendFormat(CultureInfo.InvariantCulture, "CMPCONTEXTPASSWORDSTRING=\"{0}\" ", encryptedPassword);
            }

            return(arguments.ToString());
        }
コード例 #3
0
        public static string ConfigureWAPExtensionCommonCommandLineArguments()
        {
            StringBuilder arguments = new StringBuilder();

            // Check to see if this is an uninstall
            if (PropertyBagDictionary.Instance.PropertyExists(PropertyBagConstants.Uninstall))
            {
                arguments.Append("REMOVE=ALL ");
            }
            else
            {
                arguments.Append("ADDLOCAL=ProductFeature,ServiceFeature ");

                // Save the user name to use on the cmp service database
                String userName = SetupInputs.Instance.FindItem(SetupInputTags.SqlDBAdminNameTag);

                // Add the SQL database information so that it can be written to the registry and accessed by the services
                arguments.AppendFormat(CultureInfo.InvariantCulture, "SQLPORT=\"{0}\" ", (int)SetupInputs.Instance.FindItem(SetupInputTags.SqlServerPortTag));
                string sqlInstanceName = InstallItemCustomDelegates.GetSQLServerInstanceNameStr(false);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "INSTANCENAME=\"{0}\" ", sqlInstanceName);

                arguments.AppendFormat(CultureInfo.InvariantCulture, "WAPSQLPORT=\"{0}\" ", (int)SetupInputs.Instance.FindItem(SetupInputTags.WapSqlServerPortTag));
                string wapSqlInstanceName = InstallItemCustomDelegates.GetSQLServerInstanceNameStr(true);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "WAPINSTANCENAME=\"{0}\" ", wapSqlInstanceName);

                String dbName = (String)SetupInputs.Instance.FindItem(SetupInputTags.SqlDatabaseNameTag);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "DATABASENAME=\"{0}\" ", dbName);
                string partialConnectionString = SetupDatabaseHelper.ConstructWebsiteConnectionString(SetupDatabaseHelper.SqlUsernameDuringInstall, sqlInstanceName);
                string connectionString        = String.Format("{0}database={1}", partialConnectionString, dbName);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "CMPCONNECTIONSTR=\"{0}\" ", connectionString);

                String wapDbName = (String)SetupInputs.Instance.FindItem(SetupInputTags.WapSqlDatabaseNameTag);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "WAPDATABASENAME=\"{0}\" ", wapDbName);
                string wapPartialConnectionString = SetupDatabaseHelper.ConstructWebsiteConnectionString(SetupDatabaseHelper.SqlUsernameDuringInstall, wapSqlInstanceName);
                string wapConnectionString        = String.Format("{0}database={1}", wapPartialConnectionString, wapDbName);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "WAPCONNECTIONSTR=\"{0}\" ", wapConnectionString);

                string sqlMachineName  = DnsHelper.GetComputerNameFromFqdnOrNetBios((String)SetupInputs.Instance.FindItem(SetupInputTags.GetSqlMachineNameTag(false)));
                bool   onRemoteMachine = String.Compare(sqlMachineName, Environment.MachineName, StringComparison.OrdinalIgnoreCase) != 0;
                arguments.AppendFormat(CultureInfo.InvariantCulture, "ONREMOTESERVER=\"{0}\" ", onRemoteMachine ? 1 : 0);

                string wapSqlMachineName  = DnsHelper.GetComputerNameFromFqdnOrNetBios((String)SetupInputs.Instance.FindItem(SetupInputTags.GetSqlMachineNameTag(true)));
                bool   wapOnRemoteMachine = String.Compare(wapSqlMachineName, Environment.MachineName, StringComparison.OrdinalIgnoreCase) != 0;
                arguments.AppendFormat(CultureInfo.InvariantCulture, "WAPONREMOTESERVER=\"{0}\" ", wapOnRemoteMachine ? 1 : 0);

                String sqlMachineFqdn = DnsHelper.GetFullyQualifiedName(sqlMachineName);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "SQLMACHINENAME=\"{0}\" ", sqlMachineName);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "SQLMACHINEFQDN=\"{0}\" ", sqlMachineFqdn);

                String wapSqlMachineFqdn = DnsHelper.GetFullyQualifiedName(sqlMachineName);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "WAPSQLMACHINENAME=\"{0}\" ", wapSqlMachineName);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "WAPSQLMACHINEFQDN=\"{0}\" ", wapSqlMachineFqdn);

                String certificateThumbprint = (String)SetupInputs.Instance.FindItem(SetupInputTags.CmpCertificateThumbprintTag);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "CERTIFICATETHUMBPRINT=\"{0}\" ", "LocalMachine,My," + certificateThumbprint);

                // Write the cmp database connection string
                sqlInstanceName            = InstallItemCustomDelegates.GetSQLServerInstanceNameStr(false);
                wapDbName                  = (String)SetupInputs.Instance.FindItem(SetupInputTags.SqlDatabaseNameTag);
                wapPartialConnectionString = SetupDatabaseHelper.ConstructWebsiteConnectionString(SetupDatabaseHelper.SqlUsernameDuringInstall, sqlInstanceName);
                wapConnectionString        = String.Format("{0}database={1}", wapPartialConnectionString, wapDbName);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "CMPCONNECTIONSTR=\"{0}\" ", wapConnectionString);

                String domain       = SetupInputs.Instance.FindItem(SetupInputTags.SqlDBAdminDomainTag);
                string fullUserName = String.IsNullOrEmpty(domain) ? userName : domain + @"\" + userName;
                arguments.AppendFormat(CultureInfo.InvariantCulture, "CMPDATABASEUSERNAME=\"{0}\" ", fullUserName);

                // Encrypt the password of the worker service so that WAP extensions can use it
                InputParameter pwd            = SetupInputs.Instance.FindItem(SetupInputTags.SqlDBAdminPasswordTag);
                string         passwordAsText = null;
                if (pwd != null)
                {
                    IntPtr unmanagedString = IntPtr.Zero;
                    try
                    {
                        unmanagedString = Marshal.SecureStringToGlobalAllocUnicode(pwd);
                        passwordAsText  = Marshal.PtrToStringUni(unmanagedString);
                    }
                    finally
                    {
                        Marshal.ZeroFreeGlobalAllocUnicode(unmanagedString);
                    }
                }
                string encryptedPassword = String.Format("{0}{1}{2}", "[KText]", UserAccountHelper.EncryptStringUsingLocalCertificate(passwordAsText, certificateThumbprint), "[KText]");

                arguments.AppendFormat(CultureInfo.InvariantCulture, "CMPCONTEXTPASSWORDSTRING=\"{0}\" ", encryptedPassword);

                //Write the MicrosoftMgmtSvcStoreContext connection string (part of WAP original installation)
                wapDbName = SetupConstants.DefaultWapStoreDBName;
                wapPartialConnectionString = SetupDatabaseHelper.ConstructWebsiteConnectionString(SetupDatabaseHelper.SqlUsernameDuringInstall, sqlInstanceName);
                wapConnectionString        = String.Format("{0}database={1}", wapPartialConnectionString, wapDbName);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "WAPSTORECONNECTIONSTR=\"{0}\" ", wapConnectionString);

                X509Krypto krypto = new X509Krypto("My", "LocalMachine", certificateThumbprint);
                // Encrypt the password of the sql user that will be used by the website to access CMP DB
                //string encryptedCmpDbPassword = String.Format("{0}{1}{2}", "[KText]", UserAccountHelper.EncryptStringUsingLocalCertificate(SetupDatabaseHelper.SqlDbUserPassword, certificateThumbprint), "[KText]");

                string encryptedCmpDbPassword = krypto.EncyptKText(SetupDatabaseHelper.SqlDbUserPassword);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "CMPDBPASSWORDSTRING=\"{0}\" ", encryptedCmpDbPassword);

                // Encrypt the password of the sql user that will be used by the website to access CMP WAP DB
                //string encryptedCmpWapDbPassword = String.Format("{0}{1}{2}", "[KText]", UserAccountHelper.EncryptStringUsingLocalCertificate(SetupDatabaseHelper.SqlDbUserPassword, certificateThumbprint), "[KText]");
                string encryptedCmpWapDbPassword = krypto.EncyptKText(SetupDatabaseHelper.SqlDbUserPassword);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "CMPWAPDBPASSWORDSTRING=\"{0}\" ", encryptedCmpWapDbPassword);

                // Encrypt the password of the sql user that will be used by the website to access WAP's Microsoft.MgmtSvc.Store DB
                //string encryptedMgmtStoreDbPassword = String.Format("{0}{1}{2}", "[KText]", UserAccountHelper.EncryptStringUsingLocalCertificate(SetupDatabaseHelper.SqlDbUserPassword, certificateThumbprint), "[KText]");
                string encryptedMgmtStoreDbPassword = krypto.EncyptKText(SetupDatabaseHelper.SqlDbUserPassword);
                arguments.AppendFormat(CultureInfo.InvariantCulture, "MGMTSTOREPASSWORDSTRING=\"{0}\" ", encryptedMgmtStoreDbPassword);
            }

            return(arguments.ToString());
        }
コード例 #4
0
        /// <summary>
        /// Reset the registry values
        /// </summary>
        private static void ResetRegistry()
        {
            // sql
            string sqlInstanceName    = GetSQLServerInstanceNameStr(false);
            string wapSqlInstanceName = GetSQLServerInstanceNameStr(true);

            WriteSqlRegistryValue(SetupConstants.InstanceNameRegistryValueName, sqlInstanceName);
            WriteWapSqlRegistryValue(SetupConstants.WapInstanceNameRegistryValueName, wapSqlInstanceName);
            string dbName = (String)SetupInputs.Instance.FindItem(SetupInputTags.SqlDatabaseNameTag);

            WriteSqlRegistryValue(SetupConstants.DBNameRegistryValueName, dbName);
            string wapDBName = (String)SetupInputs.Instance.FindItem(SetupInputTags.WapSqlDatabaseNameTag);

            WriteWapSqlRegistryValue(SetupConstants.WapDbNameRegistryValueName, wapDBName);
            string partialConnectionString    = SetupDatabaseHelper.ConstructConnectionString(sqlInstanceName);
            string wapPartialConnectionString = SetupDatabaseHelper.ConstructConnectionString(wapSqlInstanceName);
            string connectionString           = String.Format("{0}database={1}", partialConnectionString, dbName);
            string wapConnectionString        = String.Format("{0}database={1}", partialConnectionString, wapDBName);

            WriteSqlRegistryValue(SetupConstants.ConnectionStringRegistryValueName, connectionString);
            WriteWapSqlRegistryValue(SetupConstants.ConnectionStringRegistryValueName, wapConnectionString);

            string sqlMachineName  = DnsHelper.GetComputerNameFromFqdnOrNetBios((String)SetupInputs.Instance.FindItem(SetupInputTags.GetSqlMachineNameTag(false)));
            bool   onRemoteMachine = String.Compare(sqlMachineName, Environment.MachineName, true) != 0;

            WriteSqlRegistryValue(SetupConstants.OnRemoteRegistryValueName, onRemoteMachine ? 1 : 0);
            WriteSqlRegistryValue(SetupConstants.MachineNameRegistryValueName, sqlMachineName);
            String sqlMachineFqdn = DnsHelper.GetFullyQualifiedName(sqlMachineName);

            WriteSqlRegistryValue(SetupConstants.FqdnRegistryValueName, sqlMachineFqdn);

            sqlMachineName  = DnsHelper.GetComputerNameFromFqdnOrNetBios((String)SetupInputs.Instance.FindItem(SetupInputTags.GetSqlMachineNameTag(true)));
            onRemoteMachine = String.Compare(sqlMachineName, Environment.MachineName, true) != 0;
            WriteWapSqlRegistryValue(SetupConstants.OnRemoteRegistryValueName, onRemoteMachine ? 1 : 0);
            WriteWapSqlRegistryValue(SetupConstants.MachineNameRegistryValueName, sqlMachineName);
            sqlMachineFqdn = DnsHelper.GetFullyQualifiedName(sqlMachineName);
            WriteWapSqlRegistryValue(SetupConstants.FqdnRegistryValueName, sqlMachineFqdn);

            // user name, company name under server
            String userName = SetupInputs.Instance.FindItem(SetupInputTags.UserNameTag);

            WriteServerRegistrationRegistryValue(SetupConstants.UserNameRegistryValueName, userName);

            // VmmServiceAccount
            String serviceAccount = UserAccountHelper.GetServiceAccount();

            if (SetupInputs.Instance.FindItem(SetupInputTags.CmpServiceLocalAccountTag))
            {
                serviceAccount = SetupConstants.LocalSystem;
            }

            WriteConfigSettingsRegistryValue(SetupConstants.ServerSetupInfoRegKey, SetupConstants.VmmServiceAccountValueName, serviceAccount);
        }
コード例 #5
0
        /// <summary>
        /// Validates the inputs on this page
        /// </summary>
        /// <returns></returns>
        public override bool ValidatePage()
        {
            bool isPageValid = true;

            try
            {
                Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;

                SetupInputs.Instance.EditItem(SetupInputTags.SqlMachineNameTag, this.textBoxServer.Text);
                SetupInputs.Instance.EditItem(SetupInputTags.SqlInstanceNameTag,
                                              IsDefaultInstance(this.comboBoxInstance.Text) ? String.Empty : this.comboBoxInstance.Text);

                this.port = String.IsNullOrEmpty(this.textBoxPort.Text) ?
                            InputDefaults.SqlServerPort : Convert.ToInt32(this.textBoxPort.Text);
                SetupInputs.Instance.EditItem(SetupInputTags.SqlServerPortTag, this.port);

                bool isNewDB = this.radioNewDatabase.IsChecked.GetValueOrDefault(false);

                SetupInputs.Instance.EditItem(SetupInputTags.CreateNewSqlDatabaseTag, isNewDB);

                if (isNewDB)
                {
                    SetupInputs.Instance.EditItem(SetupInputTags.SqlDatabaseNameTag, this.textBoxNewDatabaseName.Text);
                }
                else
                {
                    SetupInputs.Instance.EditItem(SetupInputTags.SqlDatabaseNameTag, this.comboBoxExistingDatabaseName.Text);
                }

                if (this.checkBoxNewUserId.IsChecked.GetValueOrDefault(false))
                {
                    String userName   = SetupInputs.Instance.FindItem(SetupInputTags.SqlDBAdminNameTag);
                    String domainName = SetupInputs.Instance.FindItem(SetupInputTags.SqlDBAdminDomainTag);
                    if (!UserAccountHelper.ValidateCredentials(userName, domainName, this.passwordBoxPassword.SecurePassword))
                    {
                        throw new Exception("Either the domain account or the password you entered are not valid.");
                    }
                }

                String fullInstanceName = SetupDatabaseHelper.ConstructFullInstanceName(
                    !SetupDatabaseHelper.SqlServerIsOnLocalComputer(this.serverName),
                    (String)SetupInputs.Instance.FindItem(SetupInputTags.SqlMachineNameTag),
                    (String)SetupInputs.Instance.FindItem(SetupInputTags.SqlInstanceNameTag),
                    (int)SetupInputs.Instance.FindItem(SetupInputTags.SqlServerPortTag));

                SetupDatabaseHelper.CheckDatabase(
                    fullInstanceName,
                    (String)SetupInputs.Instance.FindItem(SetupInputTags.GetSqlDatabaseNameTag(false)),
                    false);
            }
            catch (SqlException)
            {
                Exception exception = new Exception("Setup cannot connect to the specified SQL Server instance.");

                SetupLogger.LogException(exception);
                SetupHelpers.ShowError(exception.Message);

                isPageValid = false;
            }
            catch (Exception exception)
            {
                SetupLogger.LogException(exception);
                SetupHelpers.ShowError(exception.Message);

                isPageValid = false;
            }
            finally
            {
                Mouse.OverrideCursor = null;
            }

            return(isPageValid);
        }