List:Commits« Previous MessageNext Message »
From:Vladislav Vaintroub Date:November 19 2010 12:39am
Subject:bzr commit into connector-net-trunk branch (vvaintroub:939) WL#1054
View as plain text  
#At file:///H:/connector_net/trunk-windows-authentication/ based on revid:vvaintroub@stripped

  939 Vladislav Vaintroub	2010-11-19
      Attempt to workaround changes and bugs in of the client/server protocol after WL#1054. 
      Probably final one. Seems to be working somehow, even with COM_CHANGE_USER.

    modified:
      MySql.Data/Provider/Source/NativeDriver.cs
      MySql.Data/Provider/Source/SSPI.cs
      MySql.Data/Tests/Source/ConnectionTests.cs
=== modified file 'MySql.Data/Provider/Source/NativeDriver.cs'
--- a/MySql.Data/Provider/Source/NativeDriver.cs	2010-10-21 18:28:31 +0000
+++ b/MySql.Data/Provider/Source/NativeDriver.cs	2010-11-19 00:39:14 +0000
@@ -486,7 +486,7 @@ namespace MySql.Data.MySqlClient
             }
 
             // Do SSPI authentication handshake
-            SSPI sspi = new SSPI(targetName, stream.BaseStream);
+            SSPI sspi = new SSPI(targetName, stream.BaseStream, stream.SequenceByte);
             sspi.AuthenticateClient();
 
             // read ok packet.
@@ -517,14 +517,15 @@ namespace MySql.Data.MySqlClient
             if (Settings.IntegratedSecurity)
             {
                 // Append authentication method after the database name in the 
-                // handshake authentication packet. Omit it, if we do connection
-                // reset (reset should use the same authentication method)
-                if (!reset)
+                // handshake authentication packet.If we're sending CHANGE_USER
+                // also write charset number after database name prior to plugin name
+                if (reset)
                 {
-                    packet.WriteString(AuthenticationWindowsPlugin);
+                    packet.WriteInteger(8, 2); // Charset number
                 }
+                packet.WriteString(AuthenticationWindowsPlugin);
                 stream.SendPacket(packet);
-                AuthenticateSSPI();
+                AuthenticateSSPI(reset);
                 return;
             }
             else

=== modified file 'MySql.Data/Provider/Source/SSPI.cs'
--- a/MySql.Data/Provider/Source/SSPI.cs	2010-10-22 20:20:50 +0000
+++ b/MySql.Data/Provider/Source/SSPI.cs	2010-11-19 00:39:14 +0000
@@ -114,12 +114,14 @@ namespace MySql.Data.MySqlClient
         [DllImport("secur32.Dll", CharSet = CharSet.Auto, SetLastError = false)]
         public static extern int DeleteSecurityContext(ref SECURITY_HANDLE pCred);
 
-        public SSPI(string targetName, Stream stream)
+
+
+        public SSPI(string targetName, Stream stream, int seqNo)
         {
             this.targetName = null;
             this.stream = stream;
             packetHeader = new byte[4];
-           
+            seq = seqNo;
         }
 
 

=== modified file 'MySql.Data/Tests/Source/ConnectionTests.cs'
--- a/MySql.Data/Tests/Source/ConnectionTests.cs	2010-10-14 22:10:08 +0000
+++ b/MySql.Data/Tests/Source/ConnectionTests.cs	2010-11-19 00:39:14 +0000
@@ -72,7 +72,17 @@ namespace MySql.Data.MySqlClient.Tests
 #if !CF  //No Security.Principal on CF
 
         [Test]
-        public void TestIntegratedSecurity()
+        public void TestIntegratedSecurityNoPooling()
+        {
+            TestIntegratedSecurity(false);
+        }
+
+        [Test]
+        public void TestIntegratedSecurityPooling()
+        {
+            TestIntegratedSecurity(true);
+        }
+        public void TestIntegratedSecurity(bool pooling)
         {
 
 
@@ -141,25 +151,41 @@ namespace MySql.Data.MySqlClient.Tests
 
                 // Finally, use IntegratedSecurity=true for the newly created user
                 string connStr = GetConnectionString(true) + ";Integrated Security=SSPI";
-                using (MySqlConnection c = new MySqlConnection(connStr))
-                {
-                    c.Open();
 
-                    MySqlCommand command = new MySqlCommand("SELECT 1", c);
-                    long ret = (long)command.ExecuteScalar();
-                    Assert.AreEqual(ret, 1);
+                /* If pooling is requested, we'll  run test twice, with connection reset in between */
+                if (pooling)
+                {
+                    connStr += ";Connection Reset=true;Pooling=true";
+                }
+                int testIterations = pooling ? 2 : 1;
 
+                int threadId = -1;
+                for (int i = 0; i < testIterations ;i++ )
+                {
+                    using (MySqlConnection c = new MySqlConnection(connStr))
+                    {
+                        c.Open();
+                        threadId = c.ServerThread;
+                        MySqlCommand command = new MySqlCommand("SELECT 1", c);
+                        long ret = (long)command.ExecuteScalar();
+                        Assert.AreEqual(ret, 1);
+
+                        command.CommandText = "select user()";
+                        string user = (string)command.ExecuteScalar();
+                        // Check if proxy user is correct
+                        Assert.IsTrue(user.StartsWith("auth_windows@"));
+
+                        // check if mysql user is correct 
+                        // (foo_user is mapped to current  OS user)
+                        command.CommandText = "select current_user()";
+                        string currentUser = (string)command.ExecuteScalar();
+                        Assert.IsTrue(currentUser.StartsWith("foo_user@"));
+                    }
+                }
 
-                    command.CommandText = "select user()";
-                    string user = (string)command.ExecuteScalar();
-                    // Check if proxy user is correct
-                    Assert.IsTrue(user.StartsWith("auth_windows@"));
-
-                    // check if mysql user is correct 
-                    // (foo_user is mapped to current  OS user)
-                    command.CommandText = "select current_user()";
-                    string currentUser = (string)command.ExecuteScalar();
-                    Assert.IsTrue(currentUser.StartsWith("foo_user@"));
+                if (pooling)
+                {
+                    suExecSQL("KILL " + threadId);
                 }
             }
             finally


Attachment: [text/bzr-bundle] bzr/vvaintroub@mysql.com-20101119003914-tlnoq1s224pokax0.bundle
Thread
bzr commit into connector-net-trunk branch (vvaintroub:939) WL#1054Vladislav Vaintroub19 Nov