db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1002316 - in /db/derby/code/branches/10.5: ./ java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
Date Tue, 28 Sep 2010 18:40:33 GMT
Author: mamta
Date: Tue Sep 28 18:40:33 2010
New Revision: 1002316

URL: http://svn.apache.org/viewvc?rev=1002316&view=rev
Log:
Backporting revision 999119 from trunk into 10.5 for DERBY-4786 (Shutdown command without
username and password should work with mixed client and network server releases.) 


Modified:
    db/derby/code/branches/10.5/   (props changed)
    db/derby/code/branches/10.5/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java

Propchange: db/derby/code/branches/10.5/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Sep 28 18:40:33 2010
@@ -1,2 +1,2 @@
 /db/derby/code/branches/10.6:942027,957000,962738,965351,987678
-/db/derby/code/trunk:757811,769596,769602,769606,769962,772090,772337,772449,772534,774281,777105,779681,782991,785131,785139,785163,785570,785662,788369,788670,788674,788968,789264,790218,791027,792434,793089,793588,794106,794303,794955,795166,795459,796020,796027,796316,796372,797147,798347,798742,800523,803548,803948,805696,808494,808850,809643,810860,812669,816531,816536,819006,822289,823659,824694,827505,829022,829410,830545,831304,831319,832379,833430,835286,881074,881444,882732,884163,885421,885659,887246,888311,892912,897161,898635,901165,901648,901760,902857,903108,905224,908418,908586,909176,910481,910511,911315,911793,915733,916075,916897,918152,918359,921028,927430,928065,929085,934474,936215,938959,940462,940469,942286,942476,942480,942587,946794,948045,948069,951346,951366,952138,952581,954748,955001,955634,956075,956445,956659,958163,959550,962716,965647,967304,980684,986689,986834
+/db/derby/code/trunk:757811,769596,769602,769606,769962,772090,772337,772449,772534,774281,777105,779681,782991,785131,785139,785163,785570,785662,788369,788670,788674,788968,789264,790218,791027,792434,793089,793588,794106,794303,794955,795166,795459,796020,796027,796316,796372,797147,798347,798742,800523,803548,803948,805696,808494,808850,809643,810860,812669,816531,816536,819006,822289,823659,824694,827505,829022,829410,830545,831304,831319,832379,833430,835286,881074,881444,882732,884163,885421,885659,887246,888311,892912,897161,898635,901165,901648,901760,902857,903108,905224,908418,908586,909176,910481,910511,911315,911793,915733,916075,916897,918152,918359,921028,927430,928065,929085,934474,936215,938959,940462,940469,942286,942476,942480,942587,946794,948045,948069,951346,951366,952138,952581,954748,955001,955634,956075,956445,956659,958163,959550,962716,965647,967304,980684,986689,986834,999119

Modified: db/derby/code/branches/10.5/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java?rev=1002316&r1=1002315&r2=1002316&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
(original)
+++ db/derby/code/branches/10.5/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
Tue Sep 28 18:40:33 2010
@@ -130,10 +130,16 @@ public final class NetworkServerControlI
 	public final static int DASHARG_UNSECURE = 10;
 	private final static int DASHARG_SSL = 11;
 
-	// command protocol version - you need to increase this number each time
-	// the command protocol changes 
-    // DERBY-2109: shutdown command now transmits user credentials
-	private final static int PROTOCOL_VERSION = 2;
+	//All the commands except shutdown with username and password are at 
+	//protocol level 1. 
+	private final static int DEFAULT_PROTOCOL_VERSION = 1;
+	// DERBY-2109: shutdown command now transmits optional user credentials
+	//For shutdown with username/password, we have added a new protocol level
+	private final static int SHUTDOWN_WITH_CREDENTIAL_PROTOCOL_VERSION = 2;
+	//The highest protocol level is 2. The reason for it to be at 2 is 
+	//the shutdown command with username/password
+	private final static int MAX_ALLOWED_PROTOCOL_VERSION = 2;
+
 	private final static String COMMAND_HEADER = "CMD:";
 	private final static String REPLY_HEADER = "RPY:";
 	private final static int REPLY_HEADER_LENGTH = REPLY_HEADER.length();
@@ -1028,12 +1034,45 @@ public final class NetworkServerControlI
 		int ntry;
         try {
             setUpSocket();
-            writeCommandHeader(COMMAND_SHUTDOWN);
-            // DERBY-2109: transmit user credentials for System Privileges check
-            writeLDString(userArg);
-            writeLDString(passwordArg);
-            send();
-            readResult();
+            try {
+                writeCommandHeader(COMMAND_SHUTDOWN, SHUTDOWN_WITH_CREDENTIAL_PROTOCOL_VERSION);
+                // DERBY-2109: transmit user credentials for System Privileges check
+                writeLDString(userArg);
+                writeLDString(passwordArg);
+                send();
+                readResult();
+            } catch (Exception e) {
+            	//The shutdown command with protocol level 2 failed. If 
+            	//the username or password were supplied then we can't 
+            	//try the shutdown with protocol level 1 because protocol
+            	//leve 1 does not support username/password. Because of
+            	//that, we should simply throw the caught exception to the
+            	//client
+            	if(userArg != null || passwordArg != null)
+            		throw e;
+                //If no username and password is specified then we can try
+            	//shutdown with the old protocol level of 1 which is the 
+            	//default protocol level. But this can be tried only if the
+            	//exception for attempt of shutdown with protocol level 2
+            	//was DRDA_InvalidReplyHead. This can happen if we are 
+            	//dealing with an older Network server product which do not
+            	//recognize shutdown at protocol level 2.
+            	if (e.getMessage().indexOf("DRDA_InvalidReplyHead") != -1)
+            	{
+                    try {
+                        closeSocket();
+                        setUpSocket();
+                        writeCommandHeader(COMMAND_SHUTDOWN);
+                        send();
+                        readResult();
+                    } catch (Exception e1) {
+                    	e1.initCause(e);
+                    	throw e1;
+                    }
+            	}
+            	else
+            		throw e;
+            }
             savWriter = logWriter;
             // DERBY-1571: If logWriter is null, stack traces are printed to
             // System.err. Set logWriter to a silent stream to suppress stack
@@ -1612,7 +1651,7 @@ public final class NetworkServerControlI
 			String codeset = null;
 			// get the version
 			int version = reader.readNetworkShort();
-			if (version <= 0 || version > PROTOCOL_VERSION)
+			if (version <= 0 || version > MAX_ALLOWED_PROTOCOL_VERSION)
 				throw new Throwable(langUtil.getTextMessage("DRDA_UnknownProtocol.S",  new Integer(version).toString()));
 			int localeLen = reader.readByte();
 			if (localeLen > 0)
@@ -1645,10 +1684,18 @@ public final class NetworkServerControlI
 			switch(command)
 			{
 				case COMMAND_SHUTDOWN:
-					// DERBY-2109: receive user credentials for shutdown
-					// System Privileges check
-					userArg = reader.readCmdString();
-					passwordArg = reader.readCmdString();
+					if (version == SHUTDOWN_WITH_CREDENTIAL_PROTOCOL_VERSION) {
+						//Protocol version of client is not at default protocol
+						//of 1 because this version of shutdown command has
+						//username and password supplied with it. When the
+						//protocol version of client is 
+						//SHUTDOWN_WITH_CREDENTIAL_PROTOCOL_VERSION, then we 
+						//know to expect username and password
+						// DERBY-2109: receive user credentials for shutdown
+						// System Privileges check
+						userArg = reader.readCmdString();
+						passwordArg = reader.readCmdString();
+					}
 					try {
 						checkShutdownPrivileges();
 						sendOK(writer);
@@ -2612,8 +2659,9 @@ public final class NetworkServerControlI
 	 */
 
 	/**
-	 * Write command header consisting of command header string and protocol
-	 * version and command
+	 * Write command header consisting of command header string and default
+	 * protocol version and command. At this point, all the commands except
+	 * shutdown with username/passwrod use default protocol version.
 	 *
 	 * @param command	command to be written
 	 *
@@ -2621,10 +2669,26 @@ public final class NetworkServerControlI
 	 */
 	private void writeCommandHeader(int command) throws Exception
 	{
+		writeCommandHeader(command, DEFAULT_PROTOCOL_VERSION);
+	}
+	
+	/**
+	 * Write command header consisting of command header string and passed
+	 * protocol version and command. At this point, all the commands except
+	 * shutdown with username/passwrod use default protocol version.
+	 *
+	 * @param command	command to be written
+	 * @param protocol_version_for_command protocol version to be used
+	 *   for the given command
+	 *
+	 * @exception Exception	throws an exception if an error occurs
+	 */
+	private void writeCommandHeader(int command, int protocol_version_for_command) throws Exception
+	{
 		try {
 			writeString(COMMAND_HEADER);
-			commandOs.writeByte((byte)((PROTOCOL_VERSION & 0xf0) >> 8 ));
-			commandOs.writeByte((byte)(PROTOCOL_VERSION & 0x0f));
+			commandOs.writeByte((byte)((protocol_version_for_command & 0xf0) >> 8 ));
+			commandOs.writeByte((byte)(protocol_version_for_command & 0x0f));
 
 			if (clientLocale != null && clientLocale != DEFAULT_LOCALE)
 			{



Mime
View raw message