mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-22 09:35:38 -05:00
Support creating & editing additional user types (#1962)
* WIP * Fix contained user password handling * More user related bug fixes
This commit is contained in:
@@ -14,6 +14,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Utility
|
||||
@@ -86,6 +87,45 @@ namespace Microsoft.SqlTools.ServiceLayer.Utility
|
||||
return ss;
|
||||
}
|
||||
|
||||
public static bool IsSecureStringsEqual(SecureString ss1, SecureString ss2)
|
||||
{
|
||||
IntPtr bstr1 = IntPtr.Zero;
|
||||
IntPtr bstr2 = IntPtr.Zero;
|
||||
try
|
||||
{
|
||||
bstr1 = Marshal.SecureStringToBSTR(ss1);
|
||||
bstr2 = Marshal.SecureStringToBSTR(ss2);
|
||||
int length1 = Marshal.ReadInt32(bstr1, -4);
|
||||
int length2 = Marshal.ReadInt32(bstr2, -4);
|
||||
if (length1 != length2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int x = 0; x < length1; ++x)
|
||||
{
|
||||
byte b1 = Marshal.ReadByte(bstr1, x);
|
||||
byte b2 = Marshal.ReadByte(bstr2, x);
|
||||
if (b1 != b2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (bstr2 != IntPtr.Zero)
|
||||
{
|
||||
Marshal.ZeroFreeBSTR(bstr2);
|
||||
}
|
||||
if (bstr1 != IntPtr.Zero)
|
||||
{
|
||||
Marshal.ZeroFreeBSTR(bstr1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// this is the main method that is called by DropAllObjects for every object
|
||||
/// in the grid
|
||||
|
||||
@@ -4,13 +4,16 @@
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.SqlServer.Management.Common;
|
||||
using Microsoft.SqlServer.Management.Smo;
|
||||
using Microsoft.SqlTools.ServiceLayer.Management;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for CUtils.
|
||||
/// Utility functions for working with server languages
|
||||
/// </summary>
|
||||
internal class LanguageUtils
|
||||
{
|
||||
@@ -20,8 +23,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Utility
|
||||
/// <param name="connectedServer"></param>
|
||||
/// <param name="languageName"></param>
|
||||
/// <returns>Returns string.Empty in case it doesn't find a matching languageName on the server</returns>
|
||||
public static string GetLanguageAliasFromName(Server connectedServer,
|
||||
string languageName)
|
||||
public static string GetLanguageAliasFromName(Server connectedServer, string languageName)
|
||||
{
|
||||
string languageAlias = string.Empty;
|
||||
|
||||
@@ -45,8 +47,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Utility
|
||||
/// <param name="connectedServer"></param>
|
||||
/// <param name="languageAlias"></param>
|
||||
/// <returns>Returns string.Empty in case it doesn't find a matching languageAlias on the server</returns>
|
||||
public static string GetLanguageNameFromAlias(Server connectedServer,
|
||||
string languageAlias)
|
||||
public static string GetLanguageNameFromAlias(Server connectedServer, string languageAlias)
|
||||
{
|
||||
string languageName = string.Empty;
|
||||
|
||||
@@ -70,8 +71,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Utility
|
||||
/// <param name="connectedServer"></param>
|
||||
/// <param name="languageAlias"></param>
|
||||
/// <returns>Throws exception in case it doesn't find a matching languageId on the server</returns>
|
||||
public static int GetLcidFromLangId(Server connectedServer,
|
||||
int langId)
|
||||
public static int GetLcidFromLangId(Server connectedServer, int langId)
|
||||
{
|
||||
int lcid = -1; //Unacceptable Lcid.
|
||||
|
||||
@@ -100,8 +100,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Utility
|
||||
/// <param name="connectedServer"></param>
|
||||
/// <param name="languageAlias"></param>
|
||||
/// <returns>Throws exception in case it doesn't find a matching lcid on the server</returns>
|
||||
public static int GetLangIdFromLcid(Server connectedServer,
|
||||
int lcid)
|
||||
public static int GetLangIdFromLcid(Server connectedServer, int lcid)
|
||||
{
|
||||
int langId = -1; //Unacceptable LangId.
|
||||
|
||||
@@ -129,8 +128,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Utility
|
||||
/// </summary>
|
||||
/// <param name="langid"></param>
|
||||
/// <returns></returns>
|
||||
public static LanguageChoice GetLanguageChoiceAlias(Server connectedServer,
|
||||
int lcid)
|
||||
public static LanguageChoice GetLanguageChoiceAlias(Server connectedServer, int lcid)
|
||||
{
|
||||
SetLanguageDefaultInitFieldsForDefaultLanguages(connectedServer);
|
||||
|
||||
@@ -155,17 +153,46 @@ namespace Microsoft.SqlTools.ServiceLayer.Utility
|
||||
string[] fieldsNeeded = new string[] { "Alias", "Name", "LocaleID", "LangID" };
|
||||
connectedServer.SetDefaultInitFields(typeof(Language), fieldsNeeded);
|
||||
}
|
||||
|
||||
public static IList<LanguageDisplay> GetDefaultLanguageOptions(CDataContainer dataContainer)
|
||||
{
|
||||
// sort the languages alphabetically by alias
|
||||
SortedList sortedLanguages = new SortedList(Comparer.Default);
|
||||
|
||||
LanguageUtils.SetLanguageDefaultInitFieldsForDefaultLanguages(dataContainer.Server);
|
||||
if (dataContainer.Server != null && dataContainer.Server.Languages != null)
|
||||
{
|
||||
foreach (Language language in dataContainer.Server.Languages)
|
||||
{
|
||||
LanguageDisplay listValue = new LanguageDisplay(language);
|
||||
sortedLanguages.Add(language.Alias, listValue);
|
||||
}
|
||||
}
|
||||
|
||||
IList<LanguageDisplay> res = new List<LanguageDisplay>();
|
||||
foreach (LanguageDisplay ld in sortedLanguages.Values)
|
||||
{
|
||||
res.Add(ld);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public static string GetLanguageAliasFromDisplayText(string? displayText)
|
||||
{
|
||||
string[] parts = displayText?.Split(" - ");
|
||||
return (parts != null && parts.Length > 1) ? parts[0] : displayText;
|
||||
}
|
||||
|
||||
public static bool IsDefaultLanguageSupported(Server server)
|
||||
{
|
||||
//Default Language was not supported before Denali.
|
||||
return SqlMgmtUtils.IsSql11OrLater(server.ConnectionContext.ServerVersion)
|
||||
&& server.ServerType != DatabaseEngineType.SqlAzureDatabase;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#region interface - ILanguageLcidWithConnectionInfo - used by property editors to talk with data object
|
||||
interface ILanguageLcidWithConnectionInfo
|
||||
{
|
||||
int Lcid { get; }
|
||||
ServerConnection Connection { get; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region class - LanguageChoice
|
||||
internal class LanguageChoice
|
||||
{
|
||||
public string alias;
|
||||
@@ -181,5 +208,4 @@ namespace Microsoft.SqlTools.ServiceLayer.Utility
|
||||
return alias;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user