Index: src/SSO/Src/SSPIJNIClient.cpp
===================================================================
RCS file: /cvsroot/jtds/jtds/src/SSO/Src/SSPIJNIClient.cpp,v
retrieving revision 1.2
diff -u -r1.2 SSPIJNIClient.cpp
--- src/SSO/Src/SSPIJNIClient.cpp	14 Dec 2004 08:51:49 -0000	1.2
+++ src/SSO/Src/SSPIJNIClient.cpp	12 Oct 2005 20:28:23 -0000
@@ -1,5 +1,13 @@
 #include "StdAfx.h"
 
+/****************************************************************
+ *  Copyright 2005 Hewlett-Packard Development Company, L.P.   *
+ *                                                              *
+ * Portions of this file have been altered by HP. Changed code  *
+ * has been notated with " 2005 HPDC".                         *
+ *                                                              * 
+ ****************************************************************/
+
 //Global variables
 
 PSecurityFunctionTable  _pSecurityInterface = NULL;      // security interface table
@@ -49,10 +57,22 @@
 }
 
 JNIEXPORT jbyteArray JNICALL Java_net_sourceforge_jtds_util_SSPIJNIClient_prepareSSORequest
-(JNIEnv *env, jobject obj) {
+(JNIEnv *env, jobject obj, jstring user, jstring password, jstring domain) {
 
 	client = new SspiClient(_T("NTLM"), NULL );
-    client->AcquireCredentials ();
+	
+	// begin hp modified code -  2005 HPDC - Oct 11, 2005
+	const char *userstr = env->GetStringUTFChars(user,0);
+ 	const char *pwdstr = env->GetStringUTFChars(password,0);
+	const char *domainstr = env->GetStringUTFChars(domain,0);
+	
+    client->AcquireCredentials (userstr, pwdstr, domainstr);
+    
+    env->ReleaseStringUTFChars(user,userstr);
+	env->ReleaseStringUTFChars(password,pwdstr);
+	env->ReleaseStringUTFChars(domain,domainstr);
+	// end hp modified code -  2005 HPDC - Oct, 2005
+    
     SspiData* ntlmMsg = client->PrepareOutboundPackage (NULL, 0);
 	if (ntlmMsg->Size > 0) {
 		jbyteArray retBuf = env->NewByteArray((unsigned long)ntlmMsg->Size);
Index: src/SSO/Src/SspiClient.cpp
===================================================================
RCS file: /cvsroot/jtds/jtds/src/SSO/Src/Attic/SspiClient.cpp,v
retrieving revision 1.1
diff -u -r1.1 SspiClient.cpp
--- src/SSO/Src/SspiClient.cpp	13 Dec 2004 12:36:55 -0000	1.1
+++ src/SSO/Src/SspiClient.cpp	12 Oct 2005 20:28:23 -0000
@@ -4,6 +4,14 @@
 // Description:	SspiClient class implementation. This acts as an sspi client
 //              for authentication agains an sspi server
 //==============================================================================
+/****************************************************************
+ *  Copyright 2005 Hewlett-Packard Development Company, L.P.   *
+ *                                                              *
+ * Portions of this file have been altered by HP. Changed code  *
+ * has been notated with " 2005 HPDC".                         *
+ *                                                              * 
+ ****************************************************************/
+
 
 #include "StdAfx.h"
 
@@ -75,25 +83,60 @@
 // SspiClient::AcquireCredentials()
 //	Description
 //		Acquires credentials based on the current logon id
+//      Or uses the supplied credentials if the userstr is
+//      not null or not zero length.
 //      
 //	Parameters
 //	Return
 //		void		 - 
 //==========================================================
-void SspiClient::AcquireCredentials ( )
+void SspiClient::AcquireCredentials ( const char *userstr, 
+									  const char *passstr,
+									  const char *domainstr )
 {
-    TimeStamp           Expiration;
-    SECURITY_STATUS     status;
+    TimeStamp           	Expiration;
+    SECURITY_STATUS     	status;
+    // begin hp modified code -  2005 HPDC - Oct 11 2005
+    SEC_WINNT_AUTH_IDENTITY *suppliedCredentials = NULL;
+    
+    if( userstr != NULL && strlen(userstr) > 0){
+        suppliedCredentials = (SEC_WINNT_AUTH_IDENTITY *) malloc( sizeof SEC_WINNT_AUTH_IDENTITY);
+		suppliedCredentials->Domain = (unsigned char *) strdup( domainstr ? domainstr : "" );
+		suppliedCredentials->DomainLength = domainstr ? strlen (domainstr ) : 0;
+		suppliedCredentials->User = (unsigned char *) strdup( userstr ? userstr: "" );
+        suppliedCredentials->UserLength = userstr ? strlen( userstr ) : 0;
+        suppliedCredentials->Password = (unsigned char *) strdup( passstr ? passstr : "" );
+        suppliedCredentials->PasswordLength = passstr ? strlen( passstr ) : 0;
+#ifdef UNICODE        
+        suppliedCredentials->Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;
+#else
+        suppliedCredentials->Flags = SEC_WINNT_AUTH_IDENTITY_ANSI;
+#endif        
+    } 
+    // end hp modified code -  2005 HPDC - Oct 11 2005
 
     status = _pSecurityInterface->AcquireCredentialsHandle ( 
                             NULL,
                             m_Package->Name,
                             SECPKG_CRED_OUTBOUND,
-                            NULL, NULL,
+                            NULL, suppliedCredentials, //  2005 HPDC - Oct 11, 2005
                             NULL, NULL,
                             &m_Credentials,
                             &Expiration
                         );
+                        
+    // begin hp modified code -  2005 HPDC - Oct 11 2005                    
+    if( suppliedCredentials != NULL ){
+    	if( suppliedCredentials->User != NULL ) 
+	    	free(suppliedCredentials->User);
+        if( suppliedCredentials->Password != NULL ) 
+    		free(suppliedCredentials->Password);
+    	if( suppliedCredentials->Domain != NULL ) 
+	    	free(suppliedCredentials->Domain);
+    	free(suppliedCredentials);
+    }
+    // end hp modified code -  2005 HPDC - Oct 11, 2005
+    
     if ( status != SEC_E_OK )
         THROWEXE ( ErrorNoCredentials, status );
 
Index: src/SSO/Src/SspiClient.h
===================================================================
RCS file: /cvsroot/jtds/jtds/src/SSO/Src/Attic/SspiClient.h,v
retrieving revision 1.1
diff -u -r1.1 SspiClient.h
--- src/SSO/Src/SspiClient.h	13 Dec 2004 12:36:55 -0000	1.1
+++ src/SSO/Src/SspiClient.h	12 Oct 2005 20:28:23 -0000
@@ -4,6 +4,13 @@
 // Description:	SspiClient class declaration
 //
 //==============================================================================
+/****************************************************************
+ *  Copyright 2005 Hewlett-Packard Development Company, L.P.   *
+ *                                                              *
+ * Portions of this file have been altered by HP. Changed code  *
+ * has been notated with " 2005 HPDC".                         *
+ *                                                              * 
+ ****************************************************************/
 
 #if !defined(_SSPISERVER_H_)
 #define _SSPISERVER_H
@@ -17,7 +24,7 @@
 	    SspiClient ( const SspiPackage & package, const TCHAR * target = NULL );
 	    virtual ~SspiClient ( );
 
-        virtual void AcquireCredentials();
+        virtual void AcquireCredentials(const char *user, const char *password, const char *domain); //  2005 HPDC - Oct 11, 2005
         virtual SspiData* PrepareOutboundPackage (jbyte* pInbound, jlong bufSize);
 
         // -- buffer management --
Index: src/SSO/Src/ntlm_SSPIJNIClient.h
===================================================================
RCS file: /cvsroot/jtds/jtds/src/SSO/Src/ntlm_SSPIJNIClient.h,v
retrieving revision 1.2
diff -u -r1.2 ntlm_SSPIJNIClient.h
--- src/SSO/Src/ntlm_SSPIJNIClient.h	14 Dec 2004 08:51:49 -0000	1.2
+++ src/SSO/Src/ntlm_SSPIJNIClient.h	12 Oct 2005 20:28:23 -0000
@@ -30,7 +30,7 @@
  * Signature: ()[B
  */
 JNIEXPORT jbyteArray JNICALL Java_net_sourceforge_jtds_util_SSPIJNIClient_prepareSSORequest
-  (JNIEnv *, jobject);
+  (JNIEnv *, jobject, jstring, jstring, jstring);
 
 /*
  * Class:     ntlm_SSPIJNIClient
Index: src/main/net/sourceforge/jtds/jdbc/ConnectionJDBC2.java
===================================================================
RCS file: /cvsroot/jtds/jtds/src/main/net/sourceforge/jtds/jdbc/ConnectionJDBC2.java,v
retrieving revision 1.68
diff -u -r1.68 ConnectionJDBC2.java
--- src/main/net/sourceforge/jtds/jdbc/ConnectionJDBC2.java	9 Feb 2005 09:57:35 -0000	1.68
+++ src/main/net/sourceforge/jtds/jdbc/ConnectionJDBC2.java	12 Oct 2005 20:28:23 -0000
@@ -15,6 +15,14 @@
 // License along with this library; if not, write to the Free Software
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 //
+/****************************************************************
+ *  Copyright 2005 Hewlett-Packard Development Company, L.P.   *
+ *                                                              *
+ * Portions of this file have been altered by HP. Changed code  *
+ * has been notated with " 2005 HPDC".                         *
+ *                                                              * 
+ ****************************************************************/
+
 package net.sourceforge.jtds.jdbc;
 
 import java.lang.ref.WeakReference;
@@ -134,6 +142,8 @@
     /** The user password. */
     private String password;
     /** The server character set. */
+    private boolean ntlmv2Flag; //  2005 HPDC - Oct 11 2005
+    /** indicates the credentials should be passed to the SSO dll */
     private String serverCharset;
     /** The application name. */
     private String appName;
@@ -331,7 +341,8 @@
                           progName,
                           language,
                           macAddress,
-                          packetSize);
+                          packetSize,
+                          ntlmv2Flag);  //  2005 HPDC - Oct 11 2005
 
             if (timer != null) {
                 // Cancel loginTimer
@@ -703,6 +714,8 @@
         instanceName = info.getProperty(Messages.get(Driver.INSTANCE));
         domainName = info.getProperty(Messages.get(Driver.DOMAIN));
         user = info.getProperty(Messages.get(Driver.USER));
+        ntlmv2Flag = "true".equalsIgnoreCase(info.getProperty(Messages.get(Driver.NTLMV2))); //  2005 HPDC - Oct 11 2005
+        ntlmv2Flag = true;  //  2005 HPDC - Oct 11 2005 ( HP Specific fix to always use the SSO ddl)
         password = info.getProperty(Messages.get(Driver.PASSWORD));
         macAddress = info.getProperty(Messages.get(Driver.MACADDRESS));
         appName = info.getProperty(Messages.get(Driver.APPNAME));
Index: src/main/net/sourceforge/jtds/jdbc/Driver.java
===================================================================
RCS file: /cvsroot/jtds/jtds/src/main/net/sourceforge/jtds/jdbc/Driver.java,v
retrieving revision 1.48.2.1
diff -u -r1.48.2.1 Driver.java
--- src/main/net/sourceforge/jtds/jdbc/Driver.java	15 Feb 2005 10:02:25 -0000	1.48.2.1
+++ src/main/net/sourceforge/jtds/jdbc/Driver.java	12 Oct 2005 20:28:23 -0000
@@ -15,6 +15,13 @@
 // License along with this library; if not, write to the Free Software
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 //
+/****************************************************************
+ *  Copyright 2005 Hewlett-Packard Development Company, L.P.   *
+ *                                                              *
+ * Portions of this file have been altered by HP. Changed code  *
+ * has been notated with " 2005 HPDC".                         *
+ *                                                              * 
+ ****************************************************************/
 package net.sourceforge.jtds.jdbc;
 
 import java.sql.Connection;
@@ -90,6 +97,7 @@
     public static final String MACADDRESS    = "prop.macaddress";
     public static final String MAXSTATEMENTS = "prop.maxstatements";
     public static final String NAMEDPIPE     = "prop.namedpipe";
+    public static final String NTLMV2		 = "prop.ntlmv2"; //  2005 HPDC - Oct 11, 2005
     public static final String PACKETSIZE    = "prop.packetsize";
     public static final String PASSWORD      = "prop.password";
     public static final String PORTNUMBER    = "prop.portnumber";
Index: src/main/net/sourceforge/jtds/jdbc/Messages.properties
===================================================================
RCS file: /cvsroot/jtds/jtds/src/main/net/sourceforge/jtds/jdbc/Messages.properties,v
retrieving revision 1.31
diff -u -r1.31 Messages.properties
--- src/main/net/sourceforge/jtds/jdbc/Messages.properties	2 Feb 2005 13:42:37 -0000	1.31
+++ src/main/net/sourceforge/jtds/jdbc/Messages.properties	12 Oct 2005 20:28:23 -0000
@@ -11,6 +11,7 @@
 prop.macaddress=MACADDRESS
 prop.maxstatements=MAXSTATEMENTS
 prop.namedpipe=NAMEDPIPE
+prop.ntlmv2=NTLMV2
 prop.packetsize=PACKETSIZE
 prop.password=PASSWORD
 prop.portnumber=PORTNUMBER
@@ -38,6 +39,7 @@
 prop.desc.macaddress=Hex-encoded client MAC address.
 prop.desc.maxstatements=The maximum number of statements to keep open. This is only a target for the cache.
 prop.desc.namedpipe=Use named pipes to connect instead of TCP/IP sockets.
+prop.desc.ntlmv2=Pass the supplied credentials to the SSO dll for ntlmv2 authentication
 prop.desc.packetsize=The network packet size (a multiple of 512).
 prop.desc.password=The database password.
 prop.desc.portnumber=The database server port number.
Index: src/main/net/sourceforge/jtds/jdbc/TdsCore.java
===================================================================
RCS file: /cvsroot/jtds/jtds/src/main/net/sourceforge/jtds/jdbc/TdsCore.java,v
retrieving revision 1.68
diff -u -r1.68 TdsCore.java
--- src/main/net/sourceforge/jtds/jdbc/TdsCore.java	9 Feb 2005 09:57:36 -0000	1.68
+++ src/main/net/sourceforge/jtds/jdbc/TdsCore.java	12 Oct 2005 20:28:24 -0000
@@ -15,6 +15,14 @@
 // License along with this library; if not, write to the Free Software
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 //
+/****************************************************************
+ *  Copyright 2005 Hewlett-Packard Development Company, L.P.   *
+ *                                                              *
+ * Portions of this file have been altered by HP. Changed code  *
+ * has been notated with " 2005 HPDC".                         *
+ *                                                              * 
+ ****************************************************************/
+
 package net.sourceforge.jtds.jdbc;
 
 import java.io.*;
@@ -537,13 +545,14 @@
                final String progName,
                final String language,
                final String macAddress,
-               final int packetSize)
+               final int packetSize,
+               final boolean ntlmv2Flag)
         throws SQLException {
         try {
             if (tdsVersion >= Driver.TDS70) {
                 sendMSLoginPkt(serverName, database, user, password,
                                 domain, appName, progName, language,
-                                macAddress, packetSize);
+                                macAddress, packetSize, ntlmv2Flag);
             } else if (tdsVersion == Driver.TDS50) {
                 send50LoginPkt(serverName, user, password,
                                 charset, appName, progName,
@@ -1788,14 +1797,19 @@
                                 final String progName,
                                 final String language,
                                 final String macAddress,
-                                final int netPacketSize)
+                                final int netPacketSize,
+                                final boolean ntlmv2Flag) //  2005 HPDC - Oct 11, 2005
             throws IOException, SQLException {
         final byte[] empty = new byte[0];
         final String clientName = getHostName();
         boolean ntlmAuth = false;
         byte[] ntlmMessage = null;
 
-        if (user == null || user.length() == 0) {
+        if( ( domain == null || domain.length() == 0) &&               //  2005 HPDC - Oct 11, 2005
+        		( user != null && user.length() > 0)){    			   //  2005 HPDC - Oct 11, 2005
+        	//username set without domain implies SQL Auth             //  2005 HPDC - Oct 11, 2005
+        	//so no special flags to set                               //  2005 HPDC - Oct 11, 2005
+        }else if (user == null || user.length() == 0 || ntlmv2Flag ) { //  2005 HPDC - Oct 11, 2005
             // See if executing on a Windows platform and if so try and
             // use the single sign on native library.
             if (System.getProperty("os.name").toLowerCase().startsWith("windows")) {
@@ -1812,10 +1826,16 @@
         }
 
         if (ntlmAuthSSO) {
+        	//begin hp modified code -  2005 HPDC - Oct 11, 2005
+        	if (Logger.isActive()  && ntlmv2Flag ) {
+                Logger.println("Authenticating using jar supplied credentials for user");
+            }
+        	//end hp modified code -  2005 HPDC - Oct 11, 2005
             try {
                 // Create the NTLM request block using the native library
                 sspiJNIClient = SSPIJNIClient.getInstance();
-                ntlmMessage = sspiJNIClient.invokePrepareSSORequest();
+                ntlmMessage = sspiJNIClient.invokePrepareSSORequest(user, password, domain); //  2005 HPDC - Oct 11, 2005
+                
             } catch (Exception e) {
                 throw new IOException("SSO Failed: " + e.getMessage());
             }
Index: src/main/net/sourceforge/jtds/util/SSPIJNIClient.java
===================================================================
RCS file: /cvsroot/jtds/jtds/src/main/net/sourceforge/jtds/util/SSPIJNIClient.java,v
retrieving revision 1.3
diff -u -r1.3 SSPIJNIClient.java
--- src/main/net/sourceforge/jtds/util/SSPIJNIClient.java	17 Dec 2004 14:33:45 -0000	1.3
+++ src/main/net/sourceforge/jtds/util/SSPIJNIClient.java	12 Oct 2005 20:28:25 -0000
@@ -47,7 +47,7 @@
      * Prepares the NTLM TYPE-1 message and returns it as a
      * <code>byte[]</code>.
      */
-    private native byte[] prepareSSORequest();
+    private native byte[] prepareSSORequest(String user, String password, String domain);
 
     /**
      * Prepares the NTLM TYPE-3 message using the current user's credentials.
@@ -120,11 +120,11 @@
      * @throws Exception if an error occurs during the call or the SSPI client
      *                   is uninitialized
      */
-    public byte[] invokePrepareSSORequest() throws Exception {
+    public byte[] invokePrepareSSORequest(String user, String password, String domain) throws Exception {
         if (!initialized) {
             throw new Exception("SSPI Not Initialized");
         }
-        return prepareSSORequest();
+        return prepareSSORequest(user, password, domain);
     }
 
     /**
@@ -151,7 +151,7 @@
             client.invokeInitialize();
             System.out.println("init..done");
             System.out.println("preare req request..");
-            str = client.invokePrepareSSORequest();
+            str = client.invokePrepareSSORequest(null,null,null);
             hexDump(str);
             System.out.println("\nRequest.length: " + str.length);
             System.out.println("prepare done...");
