You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ma...@apache.org on 2010/09/30 19:35:40 UTC
svn commit: r1003178 - in /db/derby/code/branches/10.4: ./
java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
Author: mamta
Date: Thu Sep 30 17:35:40 2010
New Revision: 1003178
URL: http://svn.apache.org/viewvc?rev=1003178&view=rev
Log:
Backporting revision 999119 from trunk into 10.4 for DERBY-4786 (Shutdown command without username and password should work with mixed client and network server releases.)
Modified:
db/derby/code/branches/10.4/ (props changed)
db/derby/code/branches/10.4/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
Propchange: db/derby/code/branches/10.4/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Sep 30 17:35:40 2010
@@ -1,2 +1,2 @@
/db/derby/code/branches/10.5:814216,958230
-/db/derby/code/trunk:788436,793588,794303,796316,796372,797147,798347,798742,800523,803548,805696,809643,812669,816536,835286,882732,898635,915733,928065,934996,946794,954544,958163,958230,959550,980684
+/db/derby/code/trunk:788436,793588,794303,796316,796372,797147,798347,798742,800523,803548,805696,809643,812669,816536,835286,882732,898635,915733,928065,934996,946794,954544,958163,958230,959550,980684,999119
Modified: db/derby/code/branches/10.4/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java?rev=1003178&r1=1003177&r2=1003178&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java (original)
+++ db/derby/code/branches/10.4/java/drda/org/apache/derby/impl/drda/NetworkServerControlImpl.java Thu Sep 30 17:35:40 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();
@@ -1023,12 +1029,45 @@ getFormattedTimestamp()});
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
@@ -1607,7 +1646,7 @@ getFormattedTimestamp()});
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)
@@ -1640,10 +1679,18 @@ getFormattedTimestamp()});
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);
@@ -2607,8 +2654,9 @@ getFormattedTimestamp()});
*/
/**
- * 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
*
@@ -2616,10 +2664,26 @@ getFormattedTimestamp()});
*/
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)
{