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
{
int databaseMajorVersion;
CultureInfo locale = CultureInfo.InvariantCulture;
+ readonly int lifeTime;
+ readonly DateTime created = DateTime.Now;
+
string charset;
string language;
get { return dataSource; }
}
- public bool IsConnected {
+ public virtual bool IsConnected {
get { return connected && comm != null && comm.IsConnected (); }
set { connected = value; }
}
#region Constructors
public Tds (string dataSource, int port, int packetSize, int timeout, TdsVersion tdsVersion)
+ : this (dataSource, port, packetSize, timeout, 0, tdsVersion)
+ {
+ }
+
+ public Tds (string dataSource, int port, int packetSize, int timeout, int lifeTime, TdsVersion tdsVersion)
{
this.tdsVersion = tdsVersion;
this.packetSize = packetSize;
this.dataSource = dataSource;
this.columns = new TdsDataColumnCollection ();
+ this.lifeTime = lifeTime;
+ InitComm (port, timeout);
+ }
+
+ protected virtual void InitComm (int port, int timeout)
+ {
comm = new TdsComm (dataSource, port, packetSize, timeout, tdsVersion);
}
#region Public Methods
+ internal bool Expired {
+ get {
+ if (lifeTime == 0)
+ return false;
+ return DateTime.Now > (created + TimeSpan.FromSeconds (lifeTime));
+ }
+ }
+
internal protected void InitExec ()
{
// clean up
return new TdsTimeoutException (0, 0, message, -2, method, dataSource, "Mono TdsClient Data Provider", 0);
}
- public void Disconnect ()
+ public virtual void Disconnect ()
{
try {
comm.StartPacket (TdsPacketType.Logoff);
// 0x0200 Negotiate NTLM
// 0x8000 Negotiate Always Sign
- Type3Message t3 = new Type3Message ();
- t3.Challenge = t2.Nonce;
+ Type3Message t3 = new Type3Message (t2);
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 ());
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