2023-01-24 15:29:31 +01:00
|
|
|
|
/* Copyright (c) Cloud Software Group, Inc.
|
2013-06-24 13:41:48 +02:00
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms,
|
|
|
|
|
* with or without modification, are permitted provided
|
|
|
|
|
* that the following conditions are met:
|
|
|
|
|
*
|
|
|
|
|
* * Redistributions of source code must retain the above
|
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
|
* following disclaimer.
|
|
|
|
|
* * Redistributions in binary form must reproduce the above
|
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
|
* following disclaimer in the documentation and/or other
|
|
|
|
|
* materials provided with the distribution.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
|
|
|
|
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
|
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using Microsoft.Win32;
|
|
|
|
|
|
2019-09-26 13:36:47 +02:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
namespace XenAdmin.Core
|
|
|
|
|
{
|
2019-09-26 13:36:47 +02:00
|
|
|
|
public static class Registry
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
|
|
2019-09-03 00:12:38 +02:00
|
|
|
|
internal static bool AllowCredentialSave => ReadBool(ALLOW_CREDENTIAL_SAVE, true);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2019-09-03 00:12:38 +02:00
|
|
|
|
internal static bool DisablePlugins => ReadBool(DISABLE_PLUGINS, false);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2019-09-03 00:12:38 +02:00
|
|
|
|
internal static bool ForceSystemFonts => ReadBool(FORCE_SYSTEM_FONTS, false);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2019-09-03 00:12:38 +02:00
|
|
|
|
internal static bool DontSudo => ReadBool(DONT_SUDO, false);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2019-09-26 13:36:47 +02:00
|
|
|
|
public static SSLCertificateTypes SSLCertificateTypes
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2019-09-26 13:36:47 +02:00
|
|
|
|
string v = ReadString(SSL_CERTIFICATES_KEY);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2019-09-26 13:36:47 +02:00
|
|
|
|
if (v != null && v.ToUpperInvariant() == SSL_CERTIFICATES_CHANGED_ONLY)
|
|
|
|
|
return SSLCertificateTypes.Changed;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2019-09-26 13:36:47 +02:00
|
|
|
|
if (v != null && v.ToUpperInvariant() == SSL_CERTIFICATES_ALL)
|
|
|
|
|
return SSLCertificateTypes.All;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2019-09-26 13:36:47 +02:00
|
|
|
|
return SSLCertificateTypes.None;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-26 13:36:47 +02:00
|
|
|
|
public static void AssertPowerShellInstalled()
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2019-09-26 13:36:47 +02:00
|
|
|
|
string v = ReadRegistryValue(Microsoft.Win32.Registry.LocalMachine, PowerShellKey, PowerShellStamp);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2019-09-26 13:36:47 +02:00
|
|
|
|
if (!int.TryParse(v, out var result) || result != 1)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
throw new I18NException(I18NExceptionType.PowerShellNotPresent);
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-26 13:36:47 +02:00
|
|
|
|
public static void AssertPowerShellExecutionPolicyNonRestricted()
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2019-09-26 13:36:47 +02:00
|
|
|
|
var val = ReadRegistryValue(Microsoft.Win32.Registry.LocalMachine, PSExecutionPolicyKey, PSExecutionPolicyName) ??
|
|
|
|
|
ReadRegistryValue(Microsoft.Win32.Registry.CurrentUser, PSExecutionPolicyKey, PSExecutionPolicyName);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2019-09-26 13:36:47 +02:00
|
|
|
|
if (val == "Restricted")
|
2013-06-24 13:41:48 +02:00
|
|
|
|
throw new I18NException(I18NExceptionType.PowerShellExecutionPolicyRestricted);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2019-09-26 13:36:47 +02:00
|
|
|
|
/// Reads a bool value key under HKEY_LOCAL_MACHINE\XENCENTER_LOCAL_KEYS
|
2013-06-24 13:41:48 +02:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>False if the value is "false" (case insensitive), true if the key is present but not
|
2019-09-26 13:36:47 +02:00
|
|
|
|
/// "false", defaultVal otherwise.</returns>
|
|
|
|
|
private static bool ReadBool(string k, bool defaultVal)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2019-09-26 13:36:47 +02:00
|
|
|
|
var v = ReadRegistryValue(Microsoft.Win32.Registry.LocalMachine, XENCENTER_LOCAL_KEYS, k);
|
|
|
|
|
return v == null ? defaultVal : v.ToUpperInvariant() != "FALSE";
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-06-02 15:48:59 +02:00
|
|
|
|
/// <summary>
|
2019-09-26 13:36:47 +02:00
|
|
|
|
/// Reads a string value k under HKEY_LOCAL_MACHINE\XENCENTER_LOCAL_KEYS
|
2015-06-02 15:48:59 +02:00
|
|
|
|
/// </summary>
|
2019-09-26 13:36:47 +02:00
|
|
|
|
private static string ReadString(string k)
|
|
|
|
|
{
|
|
|
|
|
return ReadRegistryValue(Microsoft.Win32.Registry.LocalMachine, XENCENTER_LOCAL_KEYS, k);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string ReadRegistryValue(RegistryKey baseKey, string subKey, string k)
|
2015-06-02 15:48:59 +02:00
|
|
|
|
{
|
2019-09-26 13:36:47 +02:00
|
|
|
|
if (baseKey == null)
|
|
|
|
|
return null;
|
|
|
|
|
|
2015-06-02 15:48:59 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
using (var mainKey = baseKey.OpenSubKey(subKey))
|
2015-06-02 15:48:59 +02:00
|
|
|
|
{
|
2021-08-31 12:31:16 +02:00
|
|
|
|
if (mainKey == null)
|
2019-09-26 13:36:47 +02:00
|
|
|
|
return null;
|
|
|
|
|
|
2021-08-31 12:31:16 +02:00
|
|
|
|
var v = mainKey.GetValue(k);
|
2019-09-26 13:36:47 +02:00
|
|
|
|
if (v != null)
|
|
|
|
|
return v.ToString();
|
2015-06-02 15:48:59 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
2019-09-26 13:36:47 +02:00
|
|
|
|
log.Debug($"Failed to read {baseKey.Name}\\{subKey}\\{k} from registry; assuming NULL.", e);
|
2015-06-02 15:48:59 +02:00
|
|
|
|
}
|
2019-09-26 13:36:47 +02:00
|
|
|
|
|
|
|
|
|
return null;
|
2015-06-02 15:48:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-09-26 13:36:47 +02:00
|
|
|
|
private static string ReadRegistryValue(RegistryHive hKey, string subKey, string k, RegistryView rView = RegistryView.Default)
|
2016-01-28 15:57:16 +01:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2019-09-26 13:36:47 +02:00
|
|
|
|
using (var baseKey = RegistryKey.OpenBaseKey(hKey, rView))
|
|
|
|
|
return ReadRegistryValue(baseKey, subKey, k);
|
2016-01-28 15:57:16 +01:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
2019-09-26 13:36:47 +02:00
|
|
|
|
log.Debug($"Failed to read {hKey}\\{subKey}\\{k} from registry view {rView}; assuming NULL.", e);
|
2016-01-28 15:57:16 +01:00
|
|
|
|
}
|
2019-09-26 13:36:47 +02:00
|
|
|
|
|
|
|
|
|
return null;
|
2016-01-28 15:57:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2019-09-26 13:36:47 +02:00
|
|
|
|
/// Reads a string value k under XENCENTER_LOCAL_KEYS, targeting the 32-bit
|
|
|
|
|
/// registry view, and trying CurrentUser first and then LocalMachine
|
2016-01-28 15:57:16 +01:00
|
|
|
|
/// </summary>
|
2022-08-02 15:55:26 +02:00
|
|
|
|
private static string ReadInstalledKey(string k, RegistryView rView = RegistryView.Default)
|
2016-01-28 15:57:16 +01:00
|
|
|
|
{
|
2022-08-02 15:55:26 +02:00
|
|
|
|
var val = ReadRegistryValue(RegistryHive.CurrentUser, XENCENTER_LOCAL_KEYS, k, rView);
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(val))
|
|
|
|
|
val = ReadRegistryValue(RegistryHive.LocalMachine, XENCENTER_LOCAL_KEYS, k, rView);
|
|
|
|
|
|
|
|
|
|
return string.IsNullOrEmpty(val) ? null : val;
|
2016-01-28 15:57:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-02 15:55:26 +02:00
|
|
|
|
public static string HiddenFeatures => ReadInstalledKey(HIDDEN_FEATURES, RegistryView.Registry32);
|
2016-01-21 09:54:22 +01:00
|
|
|
|
|
2022-08-02 15:55:26 +02:00
|
|
|
|
public static string AdditionalFeatures => ReadInstalledKey(ADDITIONAL_FEATURES, RegistryView.Registry32);
|
2016-02-29 15:54:26 +01:00
|
|
|
|
|
2023-07-22 16:52:32 +02:00
|
|
|
|
internal static bool ShowExtraYumRepos
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var str = ReadInstalledKey(SHOW_EXTRA_YUM_REPOS);
|
|
|
|
|
return !string.IsNullOrEmpty(str) && str.Trim() == "1";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-06 17:20:34 +02:00
|
|
|
|
public static string GetCustomClientUpdatesXmlLocation()
|
2020-10-29 13:38:34 +01:00
|
|
|
|
{
|
2023-06-06 17:20:34 +02:00
|
|
|
|
return ReadInstalledKey(CUSTOM_CLIENT_UPDATES_XML_LOCATION);
|
2023-05-11 22:17:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string GetCustomCfuLocation()
|
|
|
|
|
{
|
|
|
|
|
return ReadInstalledKey(CUSTOM_CFU_LOCATION);
|
2020-10-29 13:38:34 +01:00
|
|
|
|
}
|
2016-06-07 17:02:43 +02:00
|
|
|
|
|
2023-06-06 17:20:34 +02:00
|
|
|
|
public static string GetClientUpdatesQueryParam()
|
2022-05-10 13:22:28 +02:00
|
|
|
|
{
|
2023-06-06 17:20:34 +02:00
|
|
|
|
return ReadInstalledKey(CLIENT_UPDATES_QUERY_PARAM);
|
2022-05-10 13:22:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-11 13:04:44 +02:00
|
|
|
|
public static string GetCustomFileServicePrefix()
|
|
|
|
|
{
|
|
|
|
|
return ReadInstalledKey(CUSTOM_FILESERVICE_PREFIX);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string GetCustomClientIdUrl()
|
|
|
|
|
{
|
|
|
|
|
return ReadInstalledKey(CUSTOM_CLIENT_ID_URL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string GetCustomTokenUrl()
|
|
|
|
|
{
|
|
|
|
|
return ReadInstalledKey(CUSTOM_TOKEN_URL);
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-22 16:52:32 +02:00
|
|
|
|
public static string GetYumRepoBaseBin()
|
|
|
|
|
{
|
|
|
|
|
return ReadInstalledKey(YUM_REPO_BASE_BIN);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string GetYumRepoBaseSource()
|
|
|
|
|
{
|
|
|
|
|
return ReadInstalledKey(YUM_REPO_BASE_SRC);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string GetYumRepoEarlyAccessBin()
|
|
|
|
|
{
|
|
|
|
|
return ReadInstalledKey(YUM_REPO_EARLY_ACCESS_BIN);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string GetYumRepoEarlyAccessSource()
|
|
|
|
|
{
|
|
|
|
|
return ReadInstalledKey(YUM_REPO_EARLY_ACCESS_SRC);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string GetYumRepoNormalBin()
|
|
|
|
|
{
|
|
|
|
|
return ReadInstalledKey(YUM_REPO_NORMAL_BIN);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string GetYumRepoNormalSource()
|
|
|
|
|
{
|
|
|
|
|
return ReadInstalledKey(YUM_REPO_NORMAL_SRC);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string GetYumRepoInternalBin()
|
|
|
|
|
{
|
|
|
|
|
return ReadInstalledKey(YUM_REPO_INTERNAL_BIN);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string GetYumRepoInternalSource()
|
|
|
|
|
{
|
|
|
|
|
return ReadInstalledKey(YUM_REPO_INTERNAL_SRC);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string GetYumRepoDevTeamBin()
|
|
|
|
|
{
|
|
|
|
|
return ReadInstalledKey(YUM_REPO_DEV_TEAM_BIN);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string GetYumRepoDevTeamSource()
|
|
|
|
|
{
|
|
|
|
|
return ReadInstalledKey(YUM_REPO_DEV_TEAM_SRC);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private const string YUM_REPO_BASE_BIN = "YumRepoBaseBinOverride";
|
|
|
|
|
private const string YUM_REPO_BASE_SRC = "YumRepoBaseSourceOverride";
|
|
|
|
|
private const string YUM_REPO_EARLY_ACCESS_BIN = "YumRepoEarlyAccessBinOverride";
|
|
|
|
|
private const string YUM_REPO_EARLY_ACCESS_SRC = "YumRepoEarlyAccessSourceOverride";
|
|
|
|
|
private const string YUM_REPO_NORMAL_BIN = "YumRepoNormalBinOverride";
|
|
|
|
|
private const string YUM_REPO_NORMAL_SRC = "YumRepoNormalSourceOverride";
|
|
|
|
|
private const string YUM_REPO_DEV_TEAM_BIN = "YumRepoDevTeamBin";
|
|
|
|
|
private const string YUM_REPO_DEV_TEAM_SRC = "YumRepoDevTeamSource";
|
|
|
|
|
private const string YUM_REPO_INTERNAL_BIN = "YumRepoInternalBin";
|
|
|
|
|
private const string YUM_REPO_INTERNAL_SRC = "YumRepoInternalSource";
|
|
|
|
|
private const string SHOW_EXTRA_YUM_REPOS = "ShowExtraYumRepos";
|
|
|
|
|
|
2019-09-26 13:36:47 +02:00
|
|
|
|
public static string CustomHelpUrl => ReadString(HELP_URL_OVERRIDE);
|
2019-09-12 14:32:30 +02:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
private const string SSL_CERTIFICATES_CHANGED_ONLY = "CHANGED";
|
|
|
|
|
private const string SSL_CERTIFICATES_ALL = "ALL";
|
|
|
|
|
private const string SSL_CERTIFICATES_KEY = "ForceSSLCertificates";
|
|
|
|
|
private const string ALLOW_CREDENTIAL_SAVE = "AllowCredentialSave";
|
|
|
|
|
private const string FORCE_SYSTEM_FONTS = "ForceSystemFonts";
|
|
|
|
|
private const string DISABLE_PLUGINS = "DisablePlugins";
|
|
|
|
|
private const string DONT_SUDO = "DontSudo";
|
2023-09-06 16:48:12 +02:00
|
|
|
|
private static readonly string XENCENTER_LOCAL_KEYS = $"SOFTWARE\\{BrandManager.ProductBrand}\\{BrandManager.BrandConsole}";
|
2013-06-24 13:41:48 +02:00
|
|
|
|
private const string PSExecutionPolicyKey = @"Software\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell";
|
|
|
|
|
private const string PSExecutionPolicyName = "ExecutionPolicy";
|
|
|
|
|
private const string PowerShellKey = @"Software\Microsoft\PowerShell\1";
|
|
|
|
|
private const string PowerShellStamp = "Install";
|
2016-01-21 09:54:22 +01:00
|
|
|
|
private const string HIDDEN_FEATURES = "HiddenFeatures";
|
2016-02-29 15:54:26 +01:00
|
|
|
|
private const string ADDITIONAL_FEATURES = "AdditionalFeatures";
|
2023-06-06 17:20:34 +02:00
|
|
|
|
private const string CUSTOM_CLIENT_UPDATES_XML_LOCATION = "ClientUpdatesXmlLocationOverride";
|
2023-05-11 22:17:57 +02:00
|
|
|
|
private const string CUSTOM_CFU_LOCATION = "CfuLocationOverride";
|
2023-06-06 17:20:34 +02:00
|
|
|
|
private const string CLIENT_UPDATES_QUERY_PARAM = "ClientUpdatesQueryParam";
|
2023-05-11 13:04:44 +02:00
|
|
|
|
private const string CUSTOM_FILESERVICE_PREFIX = "PatchUrlPrefixOverride";
|
|
|
|
|
private const string CUSTOM_CLIENT_ID_URL = "ClientIdUrlOverride";
|
|
|
|
|
private const string CUSTOM_TOKEN_URL = "TokenUrlOverride";
|
2019-09-12 14:32:30 +02:00
|
|
|
|
private const string HELP_URL_OVERRIDE = "HelpUrlOverride";
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum SSLCertificateTypes { None, Changed, All }
|
|
|
|
|
}
|