Imported Upstream version 3.12.0

Former-commit-id: cf92446697332992ec36726e78eb8703e1f259d7
This commit is contained in:
Jo Shields
2015-01-13 10:44:36 +00:00
parent 8b9b85e7f5
commit 181b81b4a4
659 changed files with 12743 additions and 16300 deletions

View File

@@ -41,7 +41,9 @@ using System.ComponentModel;
using System.Diagnostics;
using System.Net.Sockets;
using System.Globalization;
using System.Security;
using System.Text;
using System.Runtime.InteropServices;
namespace Mono.Data.Tds.Protocol
{
@@ -1468,7 +1470,7 @@ namespace Mono.Data.Tds.Protocol
t3.Domain = this.connectionParms.DefaultDomain;
t3.Host = this.connectionParms.Hostname;
t3.Username = this.connectionParms.User;
t3.Password = this.connectionParms.Password;
t3.Password = GetPlainPassword(this.connectionParms.Password);
Comm.StartPacket (TdsPacketType.SspAuth); // 0x11
Comm.Append (t3.GetBytes ());
@@ -1919,6 +1921,20 @@ namespace Mono.Data.Tds.Protocol
comm.Skip(4);
}
public static string GetPlainPassword(SecureString secPass)
{
IntPtr plainString = IntPtr.Zero;
try
{
plainString = Marshal.SecureStringToGlobalAllocUnicode(secPass);
return Marshal.PtrToStringUni(plainString);
}
finally
{
Marshal.ZeroFreeGlobalAllocUnicode(plainString);
}
}
#endregion // Private Methods
#if NET_2_0

View File

@@ -29,6 +29,7 @@
//
using System;
using System.Security;
namespace Mono.Data.Tds.Protocol {
public sealed class Tds42 : Tds
@@ -77,7 +78,7 @@ namespace Mono.Data.Tds.Protocol {
Comm.Append ((byte) (tmp.Length < 30 ? tmp.Length : 30));
// password (offset 62 0x3e)
tmp = Comm.Append (connectionParameters.Password, 30, pad);
tmp = Comm.Append (GetPlainPassword(connectionParameters.Password), 30, pad);
Comm.Append ((byte) (tmp.Length < 30 ? tmp.Length : 30));
// hostproc (offset 93 0x5d)
@@ -145,7 +146,7 @@ namespace Mono.Data.Tds.Protocol {
// remote passwords
Comm.Append (empty, 2, pad);
tmp = Comm.Append (connectionParameters.Password, 253, pad);
tmp = Comm.Append (GetPlainPassword(connectionParameters.Password), 253, pad);
Comm.Append ((byte) (tmp.Length < 253 ? tmp.Length + 2 : 253 + 2));
// tds version

View File

@@ -31,6 +31,7 @@
using Mono.Data.Tds;
using System;
using System.Text;
using System.Security;
namespace Mono.Data.Tds.Protocol
{
@@ -118,7 +119,7 @@ namespace Mono.Data.Tds.Protocol
// password (offset 62 0x3e)
// 62-92
tmp = Comm.Append (connectionParameters.Password, 30, pad);
tmp = Comm.Append (GetPlainPassword(connectionParameters.Password), 30, pad);
Comm.Append ((byte) (tmp.Length < 30 ? tmp.Length : 30));
// hostproc (offset 93 0x5d)
@@ -187,7 +188,7 @@ namespace Mono.Data.Tds.Protocol
// remote passwords
// 202-457
Comm.Append (empty, 2, pad);
tmp = Comm.Append (connectionParameters.Password, 253, pad);
tmp = Comm.Append (GetPlainPassword(connectionParameters.Password), 253, pad);
Comm.Append ((byte) (tmp.Length < 253 ? tmp.Length + 2 : 253 + 2));
// tds version

View File

@@ -37,6 +37,7 @@
using System;
using System.Globalization;
using System.Text;
using System.Security;
using Mono.Security.Protocol.Ntlm;
@@ -392,11 +393,12 @@ namespace Mono.Data.Tds.Protocol
return IsConnected;
}
private static string EncryptPassword (string pass)
private static string EncryptPassword (SecureString secPass)
{
int xormask = 0x5a5a;
int len = pass.Length;
int len = secPass.Length;
char[] chars = new char[len];
string pass = GetPlainPassword(secPass);
for (int i = 0; i < len; ++i) {
int c = ((int) (pass[i])) ^ xormask;
@@ -487,6 +489,19 @@ namespace Mono.Data.Tds.Protocol
Comm.Append ((byte) 0x00); // no param meta data name
Comm.Append ((byte) 0x00); // no status flags
// Convert BigNVarChar values larger than 4000 chars to nvarchar(max)
// Need to do this here so WritePreparedParameterInfo emit the
// correct data type
foreach (TdsMetaParameter param2 in parameters) {
var colType = param2.GetMetaType ();
if (colType == TdsColumnType.BigNVarChar) {
int size = param2.GetActualSize ();
if ((size >> 1) > 4000)
param2.Size = -1;
}
}
// Write sql as a parameter value - UCS2
TdsMetaParameter param = new TdsMetaParameter ("sql",

View File

@@ -31,6 +31,7 @@
//
using System;
using System.Security;
namespace Mono.Data.Tds.Protocol
{
@@ -42,7 +43,8 @@ namespace Mono.Data.Tds.Protocol
public string Hostname;
public string Language;
public string LibraryName;
public string Password;
public SecureString Password;
public bool PasswordSet;
public string ProgName;
public string User;
public bool DomainLogin;
@@ -62,7 +64,8 @@ namespace Mono.Data.Tds.Protocol
Hostname = System.Net.Dns.GetHostName();
Language = String.Empty;
LibraryName = "Mono";
Password = String.Empty;
Password = new SecureString();
PasswordSet = false;
ProgName = "Mono";
User = String.Empty;
DomainLogin = false;

View File

@@ -27,11 +27,11 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace bug4786test
namespace MonoTests.Mono.Data.Tds
{
using NUnit.Framework;
using Mono.Data.Tds.Protocol;
using global::Mono.Data.Tds.Protocol;
using System;
using System.Net;
using System.Net.Sockets;