jcifs-1.2.8 from tgz
authorFelix Schumacher <p0354740@isib001.(none)>
Wed, 6 Aug 2008 14:36:08 +0000 (16:36 +0200)
committerFelix Schumacher <p0354740@isib001.(none)>
Wed, 6 Aug 2008 14:36:08 +0000 (16:36 +0200)
Fri Mar 24 23:14:35 EST 2006
jcifs-1.2.8 released / Deadlock Fix, ACLs, DFS, NTLM HTTP Filter, and More

There are several significant changes in this release. These include:

 o A deadlock could occur if the client tried to logoff and logon at
   the same instant. This has been fixed.
 o It was discovered that in at least some cases "preauthentication"
   did not work properly. A very simple logical error would cause the
   wrong signing digest to be installed. This has been fixed.
 o The ACL patch has been integrated. The SmbFile.getSecurity() method
   is now available.
 o The jcifs.smb.client.responseTimeout and jcifs.smb.client.soTimeout
   values have been increased from 10000ms and 15000ms to 30000ms and
   35000 respectively. Users with crawler type applications will almost
   certainly want to reduce these values.
 o Several logical errors in DFS referral handling have been fixed
   (still no fix for the mystery preemtive behavior observed by Windows
   clients).
 o Documentation has been updated significantly.

37 files changed:
README.txt
build.xml
examples/GrowWrite.java
examples/ListACL.java
examples/MultiLogon.java [new file with mode: 0644]
examples/SmbTimeout.java [new file with mode: 0644]
examples/run1.sh
examples/runtests.sh
patches/README.txt
patches/SecurityDescriptors.patch [deleted file]
src/jcifs/http/NtlmHttpURLConnection.java
src/jcifs/ntlmssp/NtlmMessage.java
src/jcifs/smb/NtTransQuerySecurityDesc.jav [deleted file]
src/jcifs/smb/NtTransQuerySecurityDesc.java [new file with mode: 0644]
src/jcifs/smb/NtTransQuerySecurityDescResponse.jav [deleted file]
src/jcifs/smb/NtTransQuerySecurityDescResponse.java [new file with mode: 0644]
src/jcifs/smb/ServerMessageBlock.java
src/jcifs/smb/SmbComMove.jav [deleted file]
src/jcifs/smb/SmbComMoveResponse.jav [deleted file]
src/jcifs/smb/SmbComNTCreateAndX.java
src/jcifs/smb/SmbComNtTransaction.jav [deleted file]
src/jcifs/smb/SmbComNtTransaction.java [new file with mode: 0644]
src/jcifs/smb/SmbComNtTransactionResponse.jav [deleted file]
src/jcifs/smb/SmbComNtTransactionResponse.java [new file with mode: 0644]
src/jcifs/smb/SmbComOpenAndX.java
src/jcifs/smb/SmbComTransaction.java
src/jcifs/smb/SmbComTransactionResponse.java
src/jcifs/smb/SmbConstants.java
src/jcifs/smb/SmbFile.java
src/jcifs/smb/SmbFileInputStream.java
src/jcifs/smb/SmbFileOutputStream.java
src/jcifs/smb/SmbRandomAccessFile.java
src/jcifs/smb/SmbSession.java
src/jcifs/smb/SmbTransport.java
src/jcifs/smb/SmbTree.java
src/jcifs/smb/TransactNamedPipeOutputStream.java
src/jcifs/util/transport/Transport.java

index f53164a..a6f6ad5 100644 (file)
@@ -1,3 +1,24 @@
+Fri Mar 24 23:14:35 EST 2006
+jcifs-1.2.8 released / Deadlock Fix, ACLs, DFS, NTLM HTTP Filter, and More
+
+There are several significant changes in this release. These include:
+
+ o A deadlock could occur if the client tried to logoff and logon at
+   the same instant. This has been fixed.
+ o It was discovered that in at least some cases "preauthentication"
+   did not work properly. A very simple logical error would cause the
+   wrong signing digest to be installed. This has been fixed.
+ o The ACL patch has been integrated. The SmbFile.getSecurity() method
+   is now available.
+ o The jcifs.smb.client.responseTimeout and jcifs.smb.client.soTimeout
+   values have been increased from 10000ms and 15000ms to 30000ms and
+   35000 respectively. Users with crawler type applications will almost
+   certainly want to reduce these values.
+ o Several logical errors in DFS referral handling have been fixed
+   (still no fix for the mystery preemtive behavior observed by Windows
+   clients).
+ o Documentation has been updated significantly.
+
 Fri Nov 18 17:08:56 EST 2005
 jcifs-1.2.7 released / Transport Error, Filter Changes, Integer Overflow,
 User Contributed Patches, and More
index e03e3f2..4ed372d 100644 (file)
--- a/build.xml
+++ b/build.xml
@@ -1,7 +1,7 @@
 <project name="jcifs" default="usage" basedir=".">
 
-    <property name="version" value="1.2.7"/>
-    <property name="reldate" value="Nov 18, 2005"/>
+    <property name="version" value="1.2.8"/>
+    <property name="reldate" value="Mar 28, 2006"/>
 
     <target name="usage">
         <echo>
@@ -47,7 +47,11 @@ dependencies: Checks that all class dependencies are met.
 
     <target name="compile" depends="dependencies">
         <mkdir dir="build"/>
-        <javac srcdir="src" destdir="build" debug="on"/>
+        <javac srcdir="src" destdir="build" debug="on">
+<!--
+            <compilerarg line="-Xlint:deprecation -Xlint:unchecked"/>
+-->
+        </javac>
         <copy file="src/jcifs/util/mime.map" tofile="build/jcifs/util/mime.map" overwrite="yes"/>
         <copy file="src/jcifs/http/ne.css" tofile="build/jcifs/http/ne.css" overwrite="yes"/>
     </target>
@@ -66,7 +70,7 @@ dependencies: Checks that all class dependencies are met.
             author="true"
             version="true"
             use="true"
-            sourcefiles="src/jcifs/Config.java,src/jcifs/UniAddress.java,src/jcifs/netbios/NbtAddress.java,src/jcifs/smb/DosFileFilter.java,src/jcifs/smb/NtlmAuthenticator.java,src/jcifs/smb/NtlmPasswordAuthentication.java,src/jcifs/smb/SmbAuthException.java,src/jcifs/smb/SmbException.java,src/jcifs/smb/SmbFile.java,src/jcifs/smb/SmbFileFilter.java,src/jcifs/smb/SmbFileInputStream.java,src/jcifs/smb/SmbFilenameFilter.java,src/jcifs/smb/SmbFileOutputStream.java,src/jcifs/smb/SmbNamedPipe.java,src/jcifs/smb/SmbRandomAccessFile.java,src/jcifs/smb/SmbSession.java"
+            sourcefiles="src/jcifs/smb/ACE.java,src/jcifs/smb/SID.java,src/jcifs/Config.java,src/jcifs/UniAddress.java,src/jcifs/netbios/NbtAddress.java,src/jcifs/smb/DosFileFilter.java,src/jcifs/smb/NtlmAuthenticator.java,src/jcifs/smb/NtlmPasswordAuthentication.java,src/jcifs/smb/SmbAuthException.java,src/jcifs/smb/SmbException.java,src/jcifs/smb/SmbFile.java,src/jcifs/smb/SmbFileFilter.java,src/jcifs/smb/SmbFileInputStream.java,src/jcifs/smb/SmbFilenameFilter.java,src/jcifs/smb/SmbFileOutputStream.java,src/jcifs/smb/SmbNamedPipe.java,src/jcifs/smb/SmbRandomAccessFile.java,src/jcifs/smb/SmbSession.java"
             windowtitle="JCIFS API">
 
             <sourcepath path="src"/>
index 1517316..f064338 100644 (file)
@@ -4,7 +4,7 @@ import java.io.FileInputStream;
 
 public class GrowWrite {
 
-    static final int SIZE = 0x4FFF;
+    static final int SIZE = 0x1FFF;
 
     public static void main( String argv[] ) throws Exception {
         int n, tot;
index a29e1c5..c671c13 100644 (file)
@@ -3,6 +3,10 @@ import jcifs.smb.*;
 public class ListACL {
 
     public static void main( String[] args ) throws Exception {
+        if (args.length < 1) {
+            System.err.println( "usage: ListACL <smburl>\n" );
+            return 0;
+        }
         SmbFile f = new SmbFile( args[0] );
         ACE[] acl = f.getSecurity();
         for (int i = 0; i < acl.length; i++) {
diff --git a/examples/MultiLogon.java b/examples/MultiLogon.java
new file mode 100644 (file)
index 0000000..72fd74f
--- /dev/null
@@ -0,0 +1,21 @@
+import jcifs.smb.*;
+
+public class MultiLogon {
+
+    public static void main( String argv[] ) throws Exception {
+        if (argv.length < 1) {
+            System.err.println( "usage: Dual <cred1> <cred2> <smburl>\n");
+            return;
+        }
+
+        NtlmPasswordAuthentication auth1 = new NtlmPasswordAuthentication( argv[0] );
+        NtlmPasswordAuthentication auth2 = new NtlmPasswordAuthentication( argv[1] );
+
+        SmbFile f1 = new SmbFile( argv[2], auth1 );
+        SmbFile f2 = new SmbFile( argv[2], auth2 );
+
+        f1.exists();
+        f2.exists();
+    }
+}
+
diff --git a/examples/SmbTimeout.java b/examples/SmbTimeout.java
new file mode 100644 (file)
index 0000000..2b412cc
--- /dev/null
@@ -0,0 +1,25 @@
+import jcifs.smb.SmbFile;
+
+public class SmbTimeout {
+
+    public static void jcifsScan(String root, int sleepTime) throws Exception {
+        long start = System.currentTimeMillis();
+        SmbFile smbRoot = new SmbFile(root);
+        SmbFile[] files = smbRoot.listFiles();
+        for(SmbFile f : files) {
+            System.out.println( f + ": " + f.canRead()+" : "+ f.length() + ": " + (System.currentTimeMillis()-start));
+        Thread.sleep(sleepTime);
+        }
+    }
+
+    public static void main(String[] p_args) throws Exception {
+        if(p_args.length!=2) {
+            System.out.println("Usage: <smbroot> <sleeptime(ms)>");
+            return;
+        }
+        String smbRoot = p_args[0];
+        int sleepTime = Integer.parseInt(p_args[1]);
+        jcifsScan(smbRoot,sleepTime);
+    }
+        
+}
index 923499e..010f5ad 100644 (file)
@@ -5,8 +5,8 @@ CLASSPATH=../build:.
 PROPERTIES=../../miallen.prp
 RUN="${JAVA_HOME}/bin/java -cp ${CLASSPATH} -Djcifs.properties=${PROPERTIES}"
 
-SERVER=rnyxwbf8s5v31
-SHARE=pub
+SERVER=xp1
+SHARE=temp
 WRITE_DIR=test/
 SRC_DIR=test/Junk
 FILE1=test/Junk/10883563.doc
index 2d49d26..d79cae1 100644 (file)
@@ -5,8 +5,8 @@ CLASSPATH=../build:.
 PROPERTIES=../../miallen.prp
 RUN="${JAVA_HOME}/bin/java -cp ${CLASSPATH} -Djcifs.properties=${PROPERTIES}"
 
-SERVER=rnyxwbf8s5v31
-SHARE=pub
+SERVER=xp1
+SHARE=temp
 WRITE_DIR=test/
 SRC_DIR=test/Junk
 FILE1=test/Junk/10883563.doc
index 031ee8d..036e78e 100644 (file)
@@ -2,33 +2,6 @@ These patches are not supported. They are provided here only for your
 conveinience. If you port a patch to a newer version of jCIFS please
 resubmit it to the mailing list.
 
-SecurityDescriptors.patch:
-
-This patch add an SmbFile.getSecurity() method that returns an ACE[]
-array for the target file. Note however that there is still no way to
-resolve SIDs to names or visa versa. This patch is also rather intrusive
-so it will take a bit of work to apply. There are file that go with this
-patch that I placed into the smb directory rather than putting them in
-the patch. They are ACE.java NtTransQuerySecurityDesc*.java SID.java
-SmbComNtTransaction*.java but some have been renamed to .jav to disable
-them from being compiled. So to apply the patch you will need to go
-through each of the affected files adjusting as necessary to the 1.2.7
-codebase and then also rename the .jav files to .java and try to compile.
-
-Also see examples/ListACL.java and examples/AclCrawler.java.
-
-The ListACL.java example will list the ACEs of a specified path. Consider
-the following commandline with resulting output of ListACL:
-
-$ java -Djcifs.properties=../miallen.prp ListACL smb://svr01/pub/a/b/c/d
-direct    allow 0x001F01FF S-1-5-21-839522115-1425521274-1417001333-61012
-inherited deny  0x000F01FF S-1-5-21-839522115-1425521274-1417001333-61011
-inherited allow 0x001F01FF S-1-5-21-839522115-1425521274-1417001333-61007
-inherited deny  0x000F01FF S-1-5-21-839522115-1425521274-1417001333-61012
-inherited allow 0x001F01FF S-1-5-32-544
-inherited allow 0x001F01FF S-1-5-18
-inherited allow 0x001200A9 S-1-5-32-545
-
 LargeReadWrite.patch:
 
 This patch adds two SMBs that supposedly improves read and write
diff --git a/patches/SecurityDescriptors.patch b/patches/SecurityDescriptors.patch
deleted file mode 100644 (file)
index 497f79a..0000000
+++ /dev/null
@@ -1,480 +0,0 @@
-diff -Naur jcifs_1.1.11/src/jcifs/smb/ServerMessageBlock.java jcifs_1.1.11acl2/src/jcifs/smb/ServerMessageBlock.java
---- jcifs_1.1.11/src/jcifs/smb/ServerMessageBlock.java  2005-05-04 23:10:46.000000000 -0400
-+++ jcifs_1.1.11acl2/src/jcifs/smb/ServerMessageBlock.java  2005-05-10 22:09:32.000000000 -0400
-@@ -274,6 +274,8 @@
-     static final byte SMB_COM_SESSION_SETUP_ANDX = (byte)0x73;
-     static final byte SMB_COM_LOGOFF_ANDX        = (byte)0x74;
-     static final byte SMB_COM_TREE_CONNECT_ANDX  = (byte)0x75;
-+    static final byte SMB_COM_NT_TRANSACT        = (byte)0xA0;
-+    static final byte SMB_COM_NT_TRANSACT_SECONDARY = (byte)0xA1;
-     static final byte SMB_COM_NT_CREATE_ANDX     = (byte)0xA2;
-     /*
-@@ -622,6 +624,12 @@
-             case SMB_COM_CREATE_DIRECTORY:
-                 c = "SMB_COM_CREATE_DIRECTORY";
-                 break;
-+            case SMB_COM_NT_TRANSACT:
-+                c = "SMB_COM_NT_TRANSACT";
-+                break;
-+            case SMB_COM_NT_TRANSACT_SECONDARY:
-+                c = "SMB_COM_NT_TRANSACT_SECONDARY";
-+                break;
-             default:
-                 c = "UNKNOWN";
-         }
-diff -Naur jcifs_1.1.11/src/jcifs/smb/SmbComNTCreateAndX.java jcifs_1.1.11acl2/src/jcifs/smb/SmbComNTCreateAndX.java
---- jcifs_1.1.11/src/jcifs/smb/SmbComNTCreateAndX.java  2005-05-04 23:10:46.000000000 -0400
-+++ jcifs_1.1.11acl2/src/jcifs/smb/SmbComNTCreateAndX.java  2005-05-10 22:09:32.000000000 -0400
-@@ -107,6 +107,7 @@
-     private int namelen_index;
-     SmbComNTCreateAndX( String name, int flags,
-+                int access,
-                 int shareAccess,
-                 int extFileAttributes,
-                 int createOptions,
-@@ -116,7 +117,7 @@
-         command = SMB_COM_NT_CREATE_ANDX;
-         // desiredAccess
--        desiredAccess = ( flags >>> 16 ) & 0xFFFF;
-+        desiredAccess = access;
-         desiredAccess |= FILE_READ_EA | FILE_READ_ATTRIBUTES;
-         // extFileAttributes
-diff -Naur jcifs_1.1.11/src/jcifs/smb/SmbComOpenAndX.java jcifs_1.1.11acl2/src/jcifs/smb/SmbComOpenAndX.java
---- jcifs_1.1.11/src/jcifs/smb/SmbComOpenAndX.java  2005-05-04 23:10:46.000000000 -0400
-+++ jcifs_1.1.11acl2/src/jcifs/smb/SmbComOpenAndX.java  2005-05-10 22:09:32.000000000 -0400
-@@ -58,13 +58,13 @@
-     // flags is NOT the same as flags member
--    SmbComOpenAndX( String fileName, int flags, ServerMessageBlock andx ) {
-+    SmbComOpenAndX( String fileName, int flags, int access, ServerMessageBlock andx ) {
-         super( andx );
-         this.path = fileName;
-         command = SMB_COM_OPEN_ANDX;
-         // desiredAccess
--        desiredAccess = ( flags >>> 16 ) & 0x3;
-+        desiredAccess = access & 0x3;
-         if( desiredAccess == 0x3 ) {
-             desiredAccess = 0x2; /* Mmm, I thought 0x03 was RDWR */
-         }
-diff -Naur jcifs_1.1.11/src/jcifs/smb/SmbComTransaction.java jcifs_1.1.11acl2/src/jcifs/smb/SmbComTransaction.java
---- jcifs_1.1.11/src/jcifs/smb/SmbComTransaction.java   2005-05-04 23:10:46.000000000 -0400
-+++ jcifs_1.1.11acl2/src/jcifs/smb/SmbComTransaction.java   2005-05-10 22:09:32.000000000 -0400
-@@ -32,44 +32,47 @@
-     private static final int PRIMARY_SETUP_OFFSET        = 61;
-     private static final int SECONDARY_PARAMETER_OFFSET  = 51;
--    private static final int DISCONNECT_TID      = 0x01;
-+    private static final int DISCONNECT_TID   = 0x01;
-     private static final int ONE_WAY_TRANSACTION = 0x02;
-     private static final int PADDING_SIZE = 2;
-     private int flags = 0x00;
--    private int parameterCount;
--    private int parameterOffset;
--    private int parameterDisplacement;
--    private int dataCount;
--    private int dataOffset;
--    private int dataDisplacement;
-     private int fid;
--    private int pad = 0;
--    private int pad1 = 0;
--    private boolean hasMore = true;
--    private boolean isPrimary = true;
--    private int bufParameterOffset;
--    private int bufDataOffset;
-     static final int TRANSACTION_BUF_SIZE = 0xFFFF;
-     static final byte TRANS2_FIND_FIRST2            = (byte)0x01;
--    static final byte TRANS2_FIND_NEXT2             = (byte)0x02;
-+    static final byte TRANS2_FIND_NEXT2          = (byte)0x02;
-     static final byte TRANS2_QUERY_FS_INFORMATION   = (byte)0x03;
-     static final byte TRANS2_QUERY_PATH_INFORMATION = (byte)0x05;
--    static final byte TRANS2_GET_DFS_REFERRAL       = (byte)0x10;
-+    static final byte TRANS2_GET_DFS_REFERRAL      = (byte)0x10;
-     static final byte TRANS2_SET_FILE_INFORMATION   = (byte)0x08;
-     static final int NET_SHARE_ENUM   = 0x0000;
-     static final int NET_SERVER_ENUM2 = 0x0068;
-     static final int NET_SERVER_ENUM3 = 0x00D7;
--    static final byte TRANS_PEEK_NAMED_PIPE     = (byte)0x23;
--    static final byte TRANS_WAIT_NAMED_PIPE     = (byte)0x53;
--    static final byte TRANS_CALL_NAMED_PIPE     = (byte)0x54;
-+    static final byte TRANS_PEEK_NAMED_PIPE  = (byte)0x23;
-+    static final byte TRANS_WAIT_NAMED_PIPE  = (byte)0x53;
-+    static final byte TRANS_CALL_NAMED_PIPE  = (byte)0x54;
-     static final byte TRANS_TRANSACT_NAMED_PIPE = (byte)0x26;
-+    protected int primarySetupOffset;
-+    protected int secondaryParameterOffset;
-+    protected int parameterCount;
-+    protected int parameterOffset;
-+    protected int parameterDisplacement;
-+    protected int dataCount;
-+    protected int dataOffset;
-+    protected int dataDisplacement;
-+    protected int pad = 0;
-+    protected int pad1 = 0;
-+    protected boolean hasMore = true;
-+    protected boolean isPrimary = true;
-+    protected int bufParameterOffset;
-+    protected int bufDataOffset;
-+
-     int totalParameterCount;
-     int totalDataCount;
-     int maxParameterCount;
-@@ -85,6 +88,8 @@
-     SmbComTransaction() {
-         maxParameterCount = 1024;
-+        primarySetupOffset = PRIMARY_SETUP_OFFSET;
-+        secondaryParameterOffset = SECONDARY_PARAMETER_OFFSET;
-     }
-     void reset() {
-@@ -100,9 +105,13 @@
-         if( isPrimary ) {
-             isPrimary = false;
--            parameterOffset = PRIMARY_SETUP_OFFSET + ( setupCount * 2 ) + 2;
--            if( command == SMB_COM_TRANSACTION && isResponse() == false ) {
--                parameterOffset += stringWireLength( name, parameterOffset );
-+            parameterOffset = primarySetupOffset + ( setupCount * 2 ) + 2;
-+            if (command != SMB_COM_NT_TRANSACT) {
-+                if( command == SMB_COM_TRANSACTION && isResponse() == false ) {
-+                    parameterOffset += stringWireLength( name, parameterOffset );
-+                }
-+            } else if (command == SMB_COM_NT_TRANSACT) {
-+                parameterOffset += 2;
-             }
-             pad = parameterOffset % PADDING_SIZE;
-             pad = pad == 0 ? 0 : PADDING_SIZE - pad;
-@@ -124,7 +133,11 @@
-             dataCount = Math.min( totalDataCount, available );
-         } else {
--            command = SMB_COM_TRANSACTION_SECONDARY;
-+            if (command != SMB_COM_NT_TRANSACT) {
-+                command = SMB_COM_TRANSACTION_SECONDARY;
-+            } else {
-+                command = SMB_COM_NT_TRANSACT_SECONDARY;
-+            }
-             // totalParameterCount and totalDataCount are set ok from primary
-             parameterOffset = SECONDARY_PARAMETER_OFFSET;
-@@ -170,12 +183,12 @@
-             writeInt2( maxDataCount, dst, dstIndex );
-             dstIndex += 2;
-             dst[dstIndex++] = maxSetupCount;
--            dst[dstIndex++] = (byte)0x00;           // Reserved1
-+            dst[dstIndex++] = (byte)0x00;          // Reserved1
-             writeInt2( flags, dst, dstIndex );
-             dstIndex += 2;
-             writeInt4( timeout, dst, dstIndex );
-             dstIndex += 4;
--            dst[dstIndex++] = (byte)0x00;           // Reserved2
-+            dst[dstIndex++] = (byte)0x00;          // Reserved2
-             dst[dstIndex++] = (byte)0x00;
-         }
-         writeInt2( parameterCount, dst, dstIndex );
-@@ -195,7 +208,7 @@
-             dstIndex += 2;
-         } else {
-             dst[dstIndex++] = (byte)setupCount;
--            dst[dstIndex++] = (byte)0x00;           // Reserved3
-+            dst[dstIndex++] = (byte)0x00;          // Reserved3
-             dstIndex += writeSetupWireFormat( dst, dstIndex );
-         }
-@@ -211,7 +224,7 @@
-         if( parameterCount > 0 ) {
-             while( p-- > 0 ) {
--                dst[dstIndex++] = (byte)0x00;       // Pad
-+                dst[dstIndex++] = (byte)0x00;      // Pad
-             }
-             System.arraycopy( txn_buf, bufParameterOffset, dst, dstIndex, parameterCount );
-@@ -221,7 +234,7 @@
-         if( dataCount > 0 ) {
-             p = pad1;
-             while( p-- > 0 ) {
--                dst[dstIndex++] = (byte)0x00;       // Pad1
-+                dst[dstIndex++] = (byte)0x00;      // Pad1
-             }
-             System.arraycopy( txn_buf, bufDataOffset, dst, dstIndex, dataCount );
-             bufDataOffset += dataCount;
-diff -Naur jcifs_1.1.11/src/jcifs/smb/SmbComTransactionResponse.java jcifs_1.1.11acl2/src/jcifs/smb/SmbComTransactionResponse.java
---- jcifs_1.1.11/src/jcifs/smb/SmbComTransactionResponse.java   2005-05-04 23:10:46.000000000 -0400
-+++ jcifs_1.1.11acl2/src/jcifs/smb/SmbComTransactionResponse.java   2005-05-10 22:09:32.000000000 -0400
-@@ -22,26 +22,26 @@
- abstract class SmbComTransactionResponse extends ServerMessageBlock implements Enumeration {
--    // relative to headerStart
--    private static final int SETUP_OFFSET        = 61;
-     private static final int DISCONNECT_TID      = 0x01;
-     private static final int ONE_WAY_TRANSACTION = 0x02;
--    private int totalParameterCount;
--    private int totalDataCount;
--    private int parameterCount;
--    private int parameterOffset;
--    private int parameterDisplacement;
--    private int dataOffset;
--    private int dataDisplacement;
--    private int setupCount;
--    private int pad;
--    private int pad1;
--    private boolean parametersDone, dataDone;
-+    protected int totalParameterCount;
-+    protected int totalDataCount;
-+    protected int parameterCount;
-+    protected int parameterOffset;
-+    protected int parameterDisplacement;
-+    protected int dataOffset;
-+    protected int dataDisplacement;
-+    protected int setupCount;
-+    protected int pad;
-+    protected int pad1;
-+    protected boolean parametersDone, dataDone;
--    private int bufParameterStart;
--    private int bufDataStart;
-+    protected int bufParameterStart;
-+    protected int bufDataStart;
-+
-+    static final int SETUP_OFFSET        = 61;
-     int dataCount;
-     byte subCommand;
-diff -Naur jcifs_1.1.11/src/jcifs/smb/SmbFileInputStream.java jcifs_1.1.11acl2/src/jcifs/smb/SmbFileInputStream.java
---- jcifs_1.1.11/src/jcifs/smb/SmbFileInputStream.java  2005-05-04 23:10:46.000000000 -0400
-+++ jcifs_1.1.11acl2/src/jcifs/smb/SmbFileInputStream.java  2005-05-10 22:09:32.000000000 -0400
-@@ -65,7 +65,7 @@
-     SmbFileInputStream( SmbFile file, int openFlags ) throws SmbException, MalformedURLException, UnknownHostException {
-         this.file = file;
-         this.openFlags = openFlags;
--        file.open( openFlags, SmbFile.ATTR_NORMAL, 0 );
-+        file.open( openFlags, 0, SmbFile.ATTR_NORMAL, 0 );
-         readSize = Math.min( file.tree.session.transport.rcv_buf_size - 70,
-                             file.tree.session.transport.server.maxBufferSize - 70 );
-     }
-@@ -121,7 +121,7 @@
-             throw new IOException( "Bad file descriptor" );
-         }
-         // ensure file is open
--        file.open( openFlags, SmbFile.ATTR_NORMAL, 0 );
-+        file.open( openFlags, 0, SmbFile.ATTR_NORMAL, 0 );
-         /*
-          * Read AndX Request / Response
-@@ -179,7 +179,7 @@
-         }
-         pipe = (SmbNamedPipe)file;
--        file.open(( pipe.pipeType & 0xFF0000 ) | SmbFile.O_EXCL, SmbFile.ATTR_NORMAL, 0 );
-+        file.open( SmbFile.O_EXCL, pipe.pipeType, SmbFile.ATTR_NORMAL, 0 );
-         req = new TransPeekNamedPipe( file.unc, file.fid );
-         resp = new TransPeekNamedPipeResponse( pipe );
-diff -Naur jcifs_1.1.11/src/jcifs/smb/SmbFile.java jcifs_1.1.11acl2/src/jcifs/smb/SmbFile.java
---- jcifs_1.1.11/src/jcifs/smb/SmbFile.java 2005-05-04 23:10:46.000000000 -0400
-+++ jcifs_1.1.11acl2/src/jcifs/smb/SmbFile.java 2005-05-10 22:09:32.000000000 -0400
-@@ -265,11 +265,10 @@
- public class SmbFile extends URLConnection {
--    // these are shifted for use in flags
--    static final int O_RDONLY = 0x010000;
--    static final int O_WRONLY = 0x020000;
--    static final int O_RDWR   = 0x030000;
--    static final int O_APPEND = 0x040000;
-+    static final int O_RDONLY = 0x01;
-+    static final int O_WRONLY = 0x02;
-+    static final int O_RDWR   = 0x04;
-+    static final int O_APPEND = 0x08;
-     // share access
- /**
-@@ -846,7 +845,7 @@
-     boolean isConnected() {
-         return (connected = tree != null && tree.treeConnected);
-     }
--    int open0( int flags, int attrs, int options ) throws SmbException {
-+    int open0( int flags, int access, int attrs, int options ) throws SmbException {
-         int f;
-         connect0();
-@@ -860,7 +859,7 @@
-         if( tree.session.transport.hasCapability( ServerMessageBlock.CAP_NT_SMBS )) {
-             SmbComNTCreateAndXResponse response = new SmbComNTCreateAndXResponse();
--            send( new SmbComNTCreateAndX( unc, flags, shareAccess,
-+            send( new SmbComNTCreateAndX( unc, flags, access, shareAccess,
-                     attrs, options, null ), response );
-             f = response.fid;
-             attributes = response.extFileAttributes & ATTR_GET_MASK;
-@@ -868,17 +867,17 @@
-             isExists = true;
-         } else {
-             SmbComOpenAndXResponse response = new SmbComOpenAndXResponse();
--            send( new SmbComOpenAndX( unc, flags, null ), response );
-+            send( new SmbComOpenAndX( unc, flags, access, null ), response );
-             f = response.fid;
-         }
-         return f;
-     }
--    void open( int flags, int attrs, int options ) throws SmbException {
-+    void open( int flags, int access, int attrs, int options ) throws SmbException {
-         if( isOpen() ) {
-             return;
-         }
--        fid = open0( flags, attrs, options );
-+        fid = open0( flags, access, attrs, options );
-         opened = true;
-     }
-     boolean isOpen() {
-@@ -1933,17 +1932,17 @@
-             int off;
- try {
--            open( SmbFile.O_RDONLY, ATTR_NORMAL, 0 );
-+            open( SmbFile.O_RDONLY, 0, ATTR_NORMAL, 0 );
-             try {
--                dest.open( SmbFile.O_CREAT | SmbFile.O_WRONLY | SmbFile.O_TRUNC |
--                        SmbComNTCreateAndX.FILE_WRITE_ATTRIBUTES << 16, attributes, 0 );
-+                dest.open( SmbFile.O_CREAT | SmbFile.O_WRONLY | SmbFile.O_TRUNC,
-+                        SmbComNTCreateAndX.FILE_WRITE_ATTRIBUTES, attributes, 0 );
-             } catch( SmbAuthException sae ) {
-                 if(( dest.attributes & ATTR_READONLY ) != 0 ) {
-                                             /* Remove READONLY and try again
-                                              */
-                     dest.setPathInformation( dest.attributes & ~ATTR_READONLY, 0L, 0L );
--                    dest.open( SmbFile.O_CREAT | SmbFile.O_WRONLY | SmbFile.O_TRUNC |
--                            SmbComNTCreateAndX.FILE_WRITE_ATTRIBUTES << 16, attributes, 0 );
-+                    dest.open( SmbFile.O_CREAT | SmbFile.O_WRONLY | SmbFile.O_TRUNC,
-+                            SmbComNTCreateAndX.FILE_WRITE_ATTRIBUTES, attributes, 0 );
-                 } else {
-                     throw sae;
-                 }
-@@ -2262,7 +2261,7 @@
-         if( getUncPath0().length() == 1 ) {
-             throw new SmbException( "Invalid operation for workgroups, servers, or shares" );
-         }
--        close( open0( O_RDWR | O_CREAT | O_EXCL, ATTR_NORMAL, 0 ), 0L );
-+        close( open0( O_RDWR | O_CREAT | O_EXCL, 0, ATTR_NORMAL, 0 ), 0L );
-     }
-     void setPathInformation( int attrs, long ctime, long mtime ) throws SmbException {
-@@ -2272,7 +2271,7 @@
-             options = 1;
-         }
--        f = open0( O_RDONLY | SmbComNTCreateAndX.FILE_WRITE_ATTRIBUTES << 16, attrs, options );
-+        f = open0( O_RDONLY, SmbComNTCreateAndX.FILE_WRITE_ATTRIBUTES, attrs, options );
-         sendTransaction( new Trans2SetFileInformation( f, attrs, ctime, mtime ),
-                 new Trans2SetFileInformationResponse() );
-         close( f, 0L );
-@@ -2502,4 +2501,19 @@
-     public OutputStream getOutputStream() throws IOException {
-         return new SmbFileOutputStream( this );
-     }
-+
-+    public ACE[] getSecurity() throws IOException {
-+        int f = open0( O_RDONLY, SmbComNTCreateAndX.READ_CONTROL, 0, isDirectory() ? 1 : 0 );
-+
-+        /*
-+         * NtTrans Query Security Desc Request / Response
-+         */
-+
-+        NtTransQuerySecurityDesc request = new NtTransQuerySecurityDesc( f, 0x04 );
-+        NtTransQuerySecurityDescResponse response = new NtTransQuerySecurityDescResponse();
-+        sendTransaction( request, response );
-+
-+        close( f, 0L );
-+        return response.aces;
-+    }
- }
-diff -Naur jcifs_1.1.11/src/jcifs/smb/SmbFileOutputStream.java jcifs_1.1.11acl2/src/jcifs/smb/SmbFileOutputStream.java
---- jcifs_1.1.11/src/jcifs/smb/SmbFileOutputStream.java 2005-05-04 23:10:46.000000000 -0400
-+++ jcifs_1.1.11acl2/src/jcifs/smb/SmbFileOutputStream.java 2005-05-10 22:09:32.000000000 -0400
-@@ -136,7 +136,7 @@
-             file.sendTransaction( new TransWaitNamedPipe( "\\pipe" + file.unc ),
-                                         new TransWaitNamedPipeResponse() );
-         }
--        file.open( openFlags, SmbFile.ATTR_NORMAL, 0 );
-+        file.open( openFlags, openFlags >>> 16, SmbFile.ATTR_NORMAL, 0 );
-         this.openFlags &= ~(SmbFile.O_CREAT | SmbFile.O_TRUNC); /* in case close and reopen */
-         writeSize = file.tree.session.transport.snd_buf_size - 70;
-@@ -206,7 +206,7 @@
-                 file.sendTransaction( new TransWaitNamedPipe( "\\pipe" + file.unc ),
-                                         new TransWaitNamedPipeResponse() );
-             }
--            file.open( openFlags, SmbFile.ATTR_NORMAL, 0 );
-+            file.open( openFlags, openFlags >>> 16, SmbFile.ATTR_NORMAL, 0 );
-             if( append ) {
-                 fp = file.length();
-             }
-diff -Naur jcifs_1.1.11/src/jcifs/smb/SmbRandomAccessFile.java jcifs_1.1.11acl2/src/jcifs/smb/SmbRandomAccessFile.java
---- jcifs_1.1.11/src/jcifs/smb/SmbRandomAccessFile.java 2005-05-04 23:10:46.000000000 -0400
-+++ jcifs_1.1.11acl2/src/jcifs/smb/SmbRandomAccessFile.java 2005-05-10 22:09:32.000000000 -0400
-@@ -53,7 +53,7 @@
-         } else {
-             throw new IllegalArgumentException( "Invalid mode" );
-         }
--        file.open( openFlags, SmbFile.ATTR_NORMAL, options );
-+        file.open( openFlags, 0, SmbFile.ATTR_NORMAL, options );
-         readSize = file.tree.session.transport.rcv_buf_size - 70;
-         writeSize = file.tree.session.transport.snd_buf_size - 70;
-         fp = 0L;
-@@ -76,7 +76,7 @@
-         // ensure file is open
-         if( file.isOpen() == false ) {
--            file.open( openFlags, SmbFile.ATTR_NORMAL, options );
-+            file.open( openFlags, 0, SmbFile.ATTR_NORMAL, options );
-         }
-         int r, n;
-@@ -129,7 +129,7 @@
-         // ensure file is open
-         if( file.isOpen() == false ) {
--            file.open( openFlags, SmbFile.ATTR_NORMAL, options );
-+            file.open( openFlags, 0, SmbFile.ATTR_NORMAL, options );
-         }
-         int w;
-@@ -153,7 +153,7 @@
-     public void setLength( long newLength ) throws SmbException {
-         // ensure file is open
-         if( file.isOpen() == false ) {
--            file.open( openFlags, SmbFile.ATTR_NORMAL, options );
-+            file.open( openFlags, 0, SmbFile.ATTR_NORMAL, options );
-         }
-         SmbComWriteResponse rsp = new SmbComWriteResponse();
-         file.send( new SmbComWrite( file.fid, (int)(newLength & 0xFFFFFFFFL), 0, tmp, 0, 0 ), rsp );
-diff -Naur jcifs_1.1.11/src/jcifs/smb/TransactNamedPipeOutputStream.java jcifs_1.1.11acl2/src/jcifs/smb/TransactNamedPipeOutputStream.java
---- jcifs_1.1.11/src/jcifs/smb/TransactNamedPipeOutputStream.java   2005-05-04 23:10:46.000000000 -0400
-+++ jcifs_1.1.11acl2/src/jcifs/smb/TransactNamedPipeOutputStream.java   2005-05-10 22:09:32.000000000 -0400
-@@ -57,7 +57,7 @@
-                                         new TransCallNamedPipeResponse( pipe ));
-         } else if(( pipe.pipeType & SmbNamedPipe.PIPE_TYPE_TRANSACT ) ==
-                                                     SmbNamedPipe.PIPE_TYPE_TRANSACT ) {
--            pipe.open(( pipe.pipeType & 0xFFFF0000 ) | SmbFile.O_EXCL, SmbFile.ATTR_NORMAL, 0 );
-+            pipe.open( SmbFile.O_EXCL, pipe.pipeType, SmbFile.ATTR_NORMAL, 0 );
-             TransTransactNamedPipe req = new TransTransactNamedPipe( pipe.fid, b, off, len );
-             if (dcePipe) {
-                 req.maxDataCount = 1024;
index b4cd9ac..a539ecc 100644 (file)
@@ -317,7 +317,7 @@ public class NtlmHttpURLConnection extends HttpURLConnection {
         while (entries.hasNext()) {
             Map.Entry entry = (Map.Entry) entries.next();
             if (key.equalsIgnoreCase((String) entry.getKey())) {
-                entry.setValue(value);
+                entry.setValue(values);
                 found = true;
                 break;
             }
index c9ed00f..5464f4d 100644 (file)
@@ -34,9 +34,7 @@ public abstract class NtlmMessage implements NtlmFlags {
         (byte) 'S', (byte) 'S', (byte) 'P', (byte) 0
     };
 
-    private static final String OEM_ENCODING =
-                Config.getProperty("jcifs.encoding",
-                        System.getProperty("file.encoding"));
+    private static final String OEM_ENCODING = Config.getProperty("jcifs.encoding", "Cp850" );
 
     private int flags;
 
diff --git a/src/jcifs/smb/NtTransQuerySecurityDesc.jav b/src/jcifs/smb/NtTransQuerySecurityDesc.jav
deleted file mode 100644 (file)
index 7522e8b..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-/* jcifs smb client library in Java
- * Copyright (C) 2005  "Michael B. Allen" <jcifs at samba dot org>
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-package jcifs.smb;
-
-import jcifs.util.Hexdump;
-
-class NtTransQuerySecurityDesc extends SmbComNtTransaction {
-
-    int fid;
-    int securityInformation;
-
-    NtTransQuerySecurityDesc( int fid, int securityInformation ) {
-        this.fid = fid;
-        this.securityInformation = securityInformation;
-        command = SMB_COM_NT_TRANSACT;
-        function = NT_TRANSACT_QUERY_SECURITY_DESC;
-        setupCount = 0;
-        totalDataCount = 0;
-        maxParameterCount = 4;
-        maxDataCount = 4096;
-        maxSetupCount = (byte)0x00;
-    }
-
-    int writeSetupWireFormat( byte[] dst, int dstIndex ) {
-        return 0;
-    }
-    int writeParametersWireFormat( byte[] dst, int dstIndex ) {
-        int start = dstIndex;
-
-        writeInt2( fid, dst, dstIndex );
-        dstIndex += 2;
-        dst[dstIndex++] = (byte)0x00; // Reserved
-        dst[dstIndex++] = (byte)0x00; // Reserved
-        writeInt4( securityInformation, dst, dstIndex );
-        dstIndex += 4;
-
-        return dstIndex - start;
-    }
-    int writeDataWireFormat( byte[] dst, int dstIndex ) {
-        return 0;
-    }
-    int readSetupWireFormat( byte[] buffer, int bufferIndex, int len ) {
-        return 0;
-    }
-    int readParametersWireFormat( byte[] buffer, int bufferIndex, int len ) {
-        return 0;
-    }
-    int readDataWireFormat( byte[] buffer, int bufferIndex, int len ) {
-        return 0;
-    }
-    public String toString() {
-        return new String( "NtTransGetSecurityDesc[" + super.toString() +
-            ",fid=0x" + Hexdump.toHexString( fid, 4 ) +
-            ",securityInformation=0x" + Hexdump.toHexString( securityInformation, 8 ) + "]" );
-    }
-}
diff --git a/src/jcifs/smb/NtTransQuerySecurityDesc.java b/src/jcifs/smb/NtTransQuerySecurityDesc.java
new file mode 100644 (file)
index 0000000..7522e8b
--- /dev/null
@@ -0,0 +1,72 @@
+/* jcifs smb client library in Java
+ * Copyright (C) 2005  "Michael B. Allen" <jcifs at samba dot org>
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+package jcifs.smb;
+
+import jcifs.util.Hexdump;
+
+class NtTransQuerySecurityDesc extends SmbComNtTransaction {
+
+    int fid;
+    int securityInformation;
+
+    NtTransQuerySecurityDesc( int fid, int securityInformation ) {
+        this.fid = fid;
+        this.securityInformation = securityInformation;
+        command = SMB_COM_NT_TRANSACT;
+        function = NT_TRANSACT_QUERY_SECURITY_DESC;
+        setupCount = 0;
+        totalDataCount = 0;
+        maxParameterCount = 4;
+        maxDataCount = 4096;
+        maxSetupCount = (byte)0x00;
+    }
+
+    int writeSetupWireFormat( byte[] dst, int dstIndex ) {
+        return 0;
+    }
+    int writeParametersWireFormat( byte[] dst, int dstIndex ) {
+        int start = dstIndex;
+
+        writeInt2( fid, dst, dstIndex );
+        dstIndex += 2;
+        dst[dstIndex++] = (byte)0x00; // Reserved
+        dst[dstIndex++] = (byte)0x00; // Reserved
+        writeInt4( securityInformation, dst, dstIndex );
+        dstIndex += 4;
+
+        return dstIndex - start;
+    }
+    int writeDataWireFormat( byte[] dst, int dstIndex ) {
+        return 0;
+    }
+    int readSetupWireFormat( byte[] buffer, int bufferIndex, int len ) {
+        return 0;
+    }
+    int readParametersWireFormat( byte[] buffer, int bufferIndex, int len ) {
+        return 0;
+    }
+    int readDataWireFormat( byte[] buffer, int bufferIndex, int len ) {
+        return 0;
+    }
+    public String toString() {
+        return new String( "NtTransGetSecurityDesc[" + super.toString() +
+            ",fid=0x" + Hexdump.toHexString( fid, 4 ) +
+            ",securityInformation=0x" + Hexdump.toHexString( securityInformation, 8 ) + "]" );
+    }
+}
diff --git a/src/jcifs/smb/NtTransQuerySecurityDescResponse.jav b/src/jcifs/smb/NtTransQuerySecurityDescResponse.jav
deleted file mode 100644 (file)
index cde45e6..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-/* jcifs smb client library in Java
- * Copyright (C) 2005  "Michael B. Allen" <jcifs at samba dot org>
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-package jcifs.smb;
-
-class NtTransQuerySecurityDescResponse extends SmbComNtTransactionResponse {
-
-    int type;
-    ACE[] aces;
-
-    NtTransQuerySecurityDescResponse() {
-        super();
-    }
-
-    int writeSetupWireFormat( byte[] dst, int dstIndex ) {
-        return 0;
-    }
-    int writeParametersWireFormat( byte[] dst, int dstIndex ) {
-        return 0;
-    }
-    int writeDataWireFormat( byte[] dst, int dstIndex ) {
-        return 0;
-    }
-    int readSetupWireFormat( byte[] buffer, int bufferIndex, int len ) {
-        return 0;
-    }
-    int readParametersWireFormat( byte[] buffer, int bufferIndex, int len ) {
-        length = readInt4( buffer, bufferIndex );
-        return 4;
-    }
-    int readDataWireFormat( byte[] buffer, int bufferIndex, int len ) {
-        int start = bufferIndex;
-
-        bufferIndex++; // revision
-        bufferIndex++;
-        type = readInt2(buffer, bufferIndex);
-        bufferIndex += 2;
-        readInt4(buffer, bufferIndex); // offset to owner sid
-        bufferIndex += 4;
-        readInt4(buffer, bufferIndex); // offset to group sid
-        bufferIndex += 4;
-        readInt4(buffer, bufferIndex); // offset to sacl
-        bufferIndex += 4;
-        int daclOffset = readInt4(buffer, bufferIndex);
-
-        bufferIndex = start + daclOffset;
-
-        bufferIndex++; // revision
-        bufferIndex++;
-        int size = readInt2(buffer, bufferIndex);
-        bufferIndex += 2;
-        int numAces = readInt4(buffer, bufferIndex);
-        bufferIndex += 4;
-
-        if (numAces > 4096)
-            throw new RuntimeException( "Invalid SecurityDescriptor" );
-
-        aces = new ACE[numAces];
-        for (int i = 0; i < numAces; i++) {
-            aces[i] = new ACE();
-            bufferIndex += aces[i].decode(buffer, bufferIndex);
-        }
-
-        return bufferIndex - start;
-    }
-    public String toString() {
-        return new String( "NtTransQuerySecurityResponse[" +
-            super.toString() + "]" );
-    }
-}
diff --git a/src/jcifs/smb/NtTransQuerySecurityDescResponse.java b/src/jcifs/smb/NtTransQuerySecurityDescResponse.java
new file mode 100644 (file)
index 0000000..cde45e6
--- /dev/null
@@ -0,0 +1,85 @@
+/* jcifs smb client library in Java
+ * Copyright (C) 2005  "Michael B. Allen" <jcifs at samba dot org>
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+package jcifs.smb;
+
+class NtTransQuerySecurityDescResponse extends SmbComNtTransactionResponse {
+
+    int type;
+    ACE[] aces;
+
+    NtTransQuerySecurityDescResponse() {
+        super();
+    }
+
+    int writeSetupWireFormat( byte[] dst, int dstIndex ) {
+        return 0;
+    }
+    int writeParametersWireFormat( byte[] dst, int dstIndex ) {
+        return 0;
+    }
+    int writeDataWireFormat( byte[] dst, int dstIndex ) {
+        return 0;
+    }
+    int readSetupWireFormat( byte[] buffer, int bufferIndex, int len ) {
+        return 0;
+    }
+    int readParametersWireFormat( byte[] buffer, int bufferIndex, int len ) {
+        length = readInt4( buffer, bufferIndex );
+        return 4;
+    }
+    int readDataWireFormat( byte[] buffer, int bufferIndex, int len ) {
+        int start = bufferIndex;
+
+        bufferIndex++; // revision
+        bufferIndex++;
+        type = readInt2(buffer, bufferIndex);
+        bufferIndex += 2;
+        readInt4(buffer, bufferIndex); // offset to owner sid
+        bufferIndex += 4;
+        readInt4(buffer, bufferIndex); // offset to group sid
+        bufferIndex += 4;
+        readInt4(buffer, bufferIndex); // offset to sacl
+        bufferIndex += 4;
+        int daclOffset = readInt4(buffer, bufferIndex);
+
+        bufferIndex = start + daclOffset;
+
+        bufferIndex++; // revision
+        bufferIndex++;
+        int size = readInt2(buffer, bufferIndex);
+        bufferIndex += 2;
+        int numAces = readInt4(buffer, bufferIndex);
+        bufferIndex += 4;
+
+        if (numAces > 4096)
+            throw new RuntimeException( "Invalid SecurityDescriptor" );
+
+        aces = new ACE[numAces];
+        for (int i = 0; i < numAces; i++) {
+            aces[i] = new ACE();
+            bufferIndex += aces[i].decode(buffer, bufferIndex);
+        }
+
+        return bufferIndex - start;
+    }
+    public String toString() {
+        return new String( "NtTransQuerySecurityResponse[" +
+            super.toString() + "]" );
+    }
+}
index 983459f..d90ce5c 100644 (file)
@@ -151,6 +151,8 @@ abstract class ServerMessageBlock extends Response implements Request, SmbConsta
     static final byte SMB_COM_SESSION_SETUP_ANDX = (byte)0x73;
     static final byte SMB_COM_LOGOFF_ANDX        = (byte)0x74;
     static final byte SMB_COM_TREE_CONNECT_ANDX  = (byte)0x75;
+    static final byte SMB_COM_NT_TRANSACT        = (byte)0xA0;
+    static final byte SMB_COM_NT_TRANSACT_SECONDARY = (byte)0xA1;
     static final byte SMB_COM_NT_CREATE_ANDX     = (byte)0xA2;
 
     /*
@@ -467,6 +469,12 @@ Hexdump.hexdump( System.err, src, srcIndex, maxLen < 128 ? maxLen + 8 : 128 );
             case SMB_COM_CREATE_DIRECTORY:
                 c = "SMB_COM_CREATE_DIRECTORY";
                 break;
+            case SMB_COM_NT_TRANSACT:
+                c = "SMB_COM_NT_TRANSACT";
+                break;
+            case SMB_COM_NT_TRANSACT_SECONDARY:
+                c = "SMB_COM_NT_TRANSACT_SECONDARY";
+                break;
             default:
                 c = "UNKNOWN";
         }
diff --git a/src/jcifs/smb/SmbComMove.jav b/src/jcifs/smb/SmbComMove.jav
deleted file mode 100644 (file)
index cf096aa..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-/* jcifs smb client library in Java
- * Copyright (C) 2000  "Michael B. Allen" <jcifs at samba dot org>
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-package jcifs.smb;
-
-class SmbComMove extends ServerMessageBlock {
-
-    String oldFileName;
-    String newFileName;
-    int tid2;
-    int openFunction;
-    int flags;
-
-    SmbComMove( String oldFileName, String newFileName, int tid2 ) {
-        command = SMB_COM_MOVE;
-        this.oldFileName = oldFileName;
-        this.newFileName = newFileName;
-        this.tid2 = tid2 == 0 ? -1 : tid2;
-
-        // these will need to be adjusted
-        openFunction = OPEN_FUNCTION_FAIL_IF_EXISTS;
-        flags = FLAGS_TARGET_MUST_BE_FILE;
-    }
-
-    int writeParameterWordsWireFormat( byte[] dst, int dstIndex ) {
-        writeInt2( tid2, dst, dstIndex );
-        dstIndex += 2;
-        writeInt2( openFunction, dst, dstIndex );
-        dstIndex += 2;
-        writeInt2( flags, dst, dstIndex );
-        return 6;
-    }
-    int writeBytesWireFormat( byte[] dst, int dstIndex ) {
-        int start = dstIndex;
-
-        dst[dstIndex++] = (byte)0x04;
-        dstIndex += writeString( oldFileName, dst, dstIndex );
-        dst[dstIndex++] = (byte)0x04;
-        dstIndex += writeString( newFileName, dst, dstIndex );
-
-        return dstIndex - start;
-    }
-    int readParameterWordsWireFormat( byte[] buffer, int bufferIndex ) {
-        return 0;
-    }
-    int readBytesWireFormat( byte[] buffer, int bufferIndex ) {
-        return 0;
-    }
-    public String toString() {
-        return new String( "SmbComMove[" +
-            super.toString() +
-            ",oldFileName=" + oldFileName +
-            ",newFileName=" + newFileName +
-            ",tid2=" + tid2 +
-            ",openFunction=" + openFunction +
-            ",flags=" + flags + "]" );
-    }
-}
diff --git a/src/jcifs/smb/SmbComMoveResponse.jav b/src/jcifs/smb/SmbComMoveResponse.jav
deleted file mode 100644 (file)
index 6c3e894..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/* jcifs smb client library in Java
- * Copyright (C) 2000  "Michael B. Allen" <jcifs at samba dot org>
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-package jcifs.smb;
-
-class SmbComMoveResponse extends ServerMessageBlock {
-
-    int count;
-    String errorFileName;
-
-    SmbComMoveResponse() {
-        count = 0;
-        errorFileName = "";
-    }
-
-    int writeParameterWordsWireFormat( byte[] dst, int dstIndex ) {
-        return 0;
-    }
-    int writeBytesWireFormat( byte[] dst, int dstIndex ) {
-        return 0;
-    }
-    int readParameterWordsWireFormat( byte[] buffer, int bufferIndex ) {
-        count = readInt2( buffer, bufferIndex );
-        return 2;
-    }
-    int readBytesWireFormat( byte[] buffer, int bufferIndex ) {
-        bufferIndex++;
-        errorFileName = readString( buffer, bufferIndex );
-        return stringWireLength( errorFileName, bufferIndex );
-    }
-    public String toString() {
-        return new String( "SmbComMoveResponse[" +
-            super.toString() +
-            ",count=" + count +
-            ",errorFileName=" + errorFileName + "]" );
-    }
-}
index 469b21b..7c219fe 100644 (file)
@@ -22,26 +22,6 @@ import jcifs.util.Hexdump;
 
 class SmbComNTCreateAndX extends AndXServerMessageBlock {
 
-    // access mask encoding
-    static final int FILE_READ_DATA        = 0x00000001; // 1
-    static final int FILE_WRITE_DATA       = 0x00000002; // 2
-    static final int FILE_APPEND_DATA      = 0x00000004; // 3
-    static final int FILE_READ_EA          = 0x00000008; // 4
-    static final int FILE_WRITE_EA         = 0x00000010; // 5
-    static final int FILE_EXECUTE          = 0x00000020; // 6
-    static final int FILE_DELETE           = 0x00000040; // 7
-    static final int FILE_READ_ATTRIBUTES  = 0x00000080; // 8
-    static final int FILE_WRITE_ATTRIBUTES = 0x00000100; // 9
-    static final int DELETE                = 0x00010000; // 16
-    static final int READ_CONTROL          = 0x00020000; // 17
-    static final int WRITE_DAC             = 0x00040000; // 18
-    static final int WRITE_OWNER           = 0x00080000; // 19
-    static final int SYNCHRONIZE           = 0x00100000; // 20
-    static final int GENERIC_ALL           = 0x10000000; // 28
-    static final int GENERIC_EXECUTE       = 0x20000000; // 29
-    static final int GENERIC_WRITE         = 0x40000000; // 30
-    static final int GENERIC_READ          = 0x80000000; // 31
-
     // share access specified in SmbFile
 
     // create disposition
@@ -105,6 +85,7 @@ class SmbComNTCreateAndX extends AndXServerMessageBlock {
     private int namelen_index;
 
     SmbComNTCreateAndX( String name, int flags,
+                int access,
                 int shareAccess,
                 int extFileAttributes,
                 int createOptions,
@@ -113,9 +94,8 @@ class SmbComNTCreateAndX extends AndXServerMessageBlock {
         this.path = name;
         command = SMB_COM_NT_CREATE_ANDX;
 
-        // desiredAccess
-        desiredAccess = ( flags >>> 16 ) & 0xFFFF;
-        desiredAccess |= FILE_READ_EA | FILE_READ_ATTRIBUTES;
+        desiredAccess = access;
+        desiredAccess |= FILE_READ_DATA | FILE_READ_EA | FILE_READ_ATTRIBUTES;
 
         // extFileAttributes
         this.extFileAttributes = extFileAttributes;
diff --git a/src/jcifs/smb/SmbComNtTransaction.jav b/src/jcifs/smb/SmbComNtTransaction.jav
deleted file mode 100644 (file)
index 69d2814..0000000
+++ /dev/null
@@ -1,82 +0,0 @@
-/* jcifs smb client library in Java
- * Copyright (C) 2005  "Michael B. Allen" <jcifs at samba dot org>
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-package jcifs.smb;
-
-abstract class SmbComNtTransaction extends SmbComTransaction {
-
-    // relative to headerStart
-    private static final int NTT_PRIMARY_SETUP_OFFSET       = 69;
-    private static final int NTT_SECONDARY_PARAMETER_OFFSET  = 51;
-
-    static final int NT_TRANSACT_QUERY_SECURITY_DESC = 6;
-
-    int function;
-
-    SmbComNtTransaction() {
-        super();
-        primarySetupOffset = NTT_PRIMARY_SETUP_OFFSET;
-        secondaryParameterOffset = NTT_SECONDARY_PARAMETER_OFFSET;
-    }
-
-    int writeParameterWordsWireFormat( byte[] dst, int dstIndex ) {
-        int start = dstIndex;
-
-        if (command != SMB_COM_NT_TRANSACT_SECONDARY) {
-            dst[dstIndex++] = maxSetupCount;
-        } else {
-            dst[dstIndex++] = (byte)0x00;          // Reserved
-        }
-        dst[dstIndex++] = (byte)0x00;          // Reserved
-        dst[dstIndex++] = (byte)0x00;          // Reserved
-        writeInt4( totalParameterCount, dst, dstIndex );
-        dstIndex += 4;
-        writeInt4( totalDataCount, dst, dstIndex );
-        dstIndex += 4;
-        if (command != SMB_COM_NT_TRANSACT_SECONDARY) {
-            writeInt4( maxParameterCount, dst, dstIndex );
-            dstIndex += 4;
-            writeInt4( maxDataCount, dst, dstIndex );
-            dstIndex += 4;
-        }
-        writeInt4( parameterCount, dst, dstIndex );
-        dstIndex += 4;
-        writeInt4(( parameterCount == 0 ? 0 : parameterOffset ), dst, dstIndex );
-        dstIndex += 4;
-        if (command == SMB_COM_NT_TRANSACT_SECONDARY) {
-            writeInt4( parameterDisplacement, dst, dstIndex );
-            dstIndex += 4;
-        }
-        writeInt4( dataCount, dst, dstIndex );
-        dstIndex += 4;
-        writeInt4(( dataCount == 0 ? 0 : dataOffset ), dst, dstIndex );
-        dstIndex += 4;
-        if (command == SMB_COM_NT_TRANSACT_SECONDARY) {
-            writeInt4( dataDisplacement, dst, dstIndex );
-            dstIndex += 4;
-            dst[dstIndex++] = (byte)0x00;      // Reserved1
-        } else {
-            dst[dstIndex++] = (byte)setupCount;
-            writeInt2( function, dst, dstIndex );
-            dstIndex += 2;
-            dstIndex += writeSetupWireFormat( dst, dstIndex );
-        }
-
-        return dstIndex - start;
-    }
-}
diff --git a/src/jcifs/smb/SmbComNtTransaction.java b/src/jcifs/smb/SmbComNtTransaction.java
new file mode 100644 (file)
index 0000000..69d2814
--- /dev/null
@@ -0,0 +1,82 @@
+/* jcifs smb client library in Java
+ * Copyright (C) 2005  "Michael B. Allen" <jcifs at samba dot org>
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+package jcifs.smb;
+
+abstract class SmbComNtTransaction extends SmbComTransaction {
+
+    // relative to headerStart
+    private static final int NTT_PRIMARY_SETUP_OFFSET       = 69;
+    private static final int NTT_SECONDARY_PARAMETER_OFFSET  = 51;
+
+    static final int NT_TRANSACT_QUERY_SECURITY_DESC = 6;
+
+    int function;
+
+    SmbComNtTransaction() {
+        super();
+        primarySetupOffset = NTT_PRIMARY_SETUP_OFFSET;
+        secondaryParameterOffset = NTT_SECONDARY_PARAMETER_OFFSET;
+    }
+
+    int writeParameterWordsWireFormat( byte[] dst, int dstIndex ) {
+        int start = dstIndex;
+
+        if (command != SMB_COM_NT_TRANSACT_SECONDARY) {
+            dst[dstIndex++] = maxSetupCount;
+        } else {
+            dst[dstIndex++] = (byte)0x00;          // Reserved
+        }
+        dst[dstIndex++] = (byte)0x00;          // Reserved
+        dst[dstIndex++] = (byte)0x00;          // Reserved
+        writeInt4( totalParameterCount, dst, dstIndex );
+        dstIndex += 4;
+        writeInt4( totalDataCount, dst, dstIndex );
+        dstIndex += 4;
+        if (command != SMB_COM_NT_TRANSACT_SECONDARY) {
+            writeInt4( maxParameterCount, dst, dstIndex );
+            dstIndex += 4;
+            writeInt4( maxDataCount, dst, dstIndex );
+            dstIndex += 4;
+        }
+        writeInt4( parameterCount, dst, dstIndex );
+        dstIndex += 4;
+        writeInt4(( parameterCount == 0 ? 0 : parameterOffset ), dst, dstIndex );
+        dstIndex += 4;
+        if (command == SMB_COM_NT_TRANSACT_SECONDARY) {
+            writeInt4( parameterDisplacement, dst, dstIndex );
+            dstIndex += 4;
+        }
+        writeInt4( dataCount, dst, dstIndex );
+        dstIndex += 4;
+        writeInt4(( dataCount == 0 ? 0 : dataOffset ), dst, dstIndex );
+        dstIndex += 4;
+        if (command == SMB_COM_NT_TRANSACT_SECONDARY) {
+            writeInt4( dataDisplacement, dst, dstIndex );
+            dstIndex += 4;
+            dst[dstIndex++] = (byte)0x00;      // Reserved1
+        } else {
+            dst[dstIndex++] = (byte)setupCount;
+            writeInt2( function, dst, dstIndex );
+            dstIndex += 2;
+            dstIndex += writeSetupWireFormat( dst, dstIndex );
+        }
+
+        return dstIndex - start;
+    }
+}
diff --git a/src/jcifs/smb/SmbComNtTransactionResponse.jav b/src/jcifs/smb/SmbComNtTransactionResponse.jav
deleted file mode 100644 (file)
index 2238456..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/* jcifs smb client library in Java
- * Copyright (C) 2005  "Michael B. Allen" <jcifs at samba dot org>
- * 
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- * 
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-package jcifs.smb;
-
-abstract class SmbComNtTransactionResponse extends SmbComTransactionResponse {
-
-    SmbComNtTransactionResponse() {
-        super();
-    }
-
-    int readParameterWordsWireFormat( byte[] buffer, int bufferIndex ) {
-        int start = bufferIndex;
-
-        buffer[bufferIndex++] = (byte)0x00;        // Reserved
-        buffer[bufferIndex++] = (byte)0x00;        // Reserved
-        buffer[bufferIndex++] = (byte)0x00;        // Reserved
-
-        totalParameterCount = readInt4( buffer, bufferIndex );
-        if( bufDataStart == 0 ) {
-            bufDataStart = totalParameterCount;
-        }
-        bufferIndex += 4;
-        totalDataCount = readInt4( buffer, bufferIndex );
-        bufferIndex += 4;
-        parameterCount = readInt4( buffer, bufferIndex );
-        bufferIndex += 4;
-        parameterOffset = readInt4( buffer, bufferIndex );
-        bufferIndex += 4;
-        parameterDisplacement = readInt4( buffer, bufferIndex );
-        bufferIndex += 4;
-        dataCount = readInt4( buffer, bufferIndex );
-        bufferIndex += 4;
-        dataOffset = readInt4( buffer, bufferIndex );
-        bufferIndex += 4;
-        dataDisplacement = readInt4( buffer, bufferIndex );
-        bufferIndex += 4;
-        setupCount = buffer[bufferIndex] & 0xFF;
-        bufferIndex += 2;
-        if( setupCount != 0 ) {
-            if( log.level > 2 )
-                log.println( "setupCount is not zero: " + setupCount );
-        }
-
-        return bufferIndex - start;
-    }
-}
diff --git a/src/jcifs/smb/SmbComNtTransactionResponse.java b/src/jcifs/smb/SmbComNtTransactionResponse.java
new file mode 100644 (file)
index 0000000..2238456
--- /dev/null
@@ -0,0 +1,62 @@
+/* jcifs smb client library in Java
+ * Copyright (C) 2005  "Michael B. Allen" <jcifs at samba dot org>
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+package jcifs.smb;
+
+abstract class SmbComNtTransactionResponse extends SmbComTransactionResponse {
+
+    SmbComNtTransactionResponse() {
+        super();
+    }
+
+    int readParameterWordsWireFormat( byte[] buffer, int bufferIndex ) {
+        int start = bufferIndex;
+
+        buffer[bufferIndex++] = (byte)0x00;        // Reserved
+        buffer[bufferIndex++] = (byte)0x00;        // Reserved
+        buffer[bufferIndex++] = (byte)0x00;        // Reserved
+
+        totalParameterCount = readInt4( buffer, bufferIndex );
+        if( bufDataStart == 0 ) {
+            bufDataStart = totalParameterCount;
+        }
+        bufferIndex += 4;
+        totalDataCount = readInt4( buffer, bufferIndex );
+        bufferIndex += 4;
+        parameterCount = readInt4( buffer, bufferIndex );
+        bufferIndex += 4;
+        parameterOffset = readInt4( buffer, bufferIndex );
+        bufferIndex += 4;
+        parameterDisplacement = readInt4( buffer, bufferIndex );
+        bufferIndex += 4;
+        dataCount = readInt4( buffer, bufferIndex );
+        bufferIndex += 4;
+        dataOffset = readInt4( buffer, bufferIndex );
+        bufferIndex += 4;
+        dataDisplacement = readInt4( buffer, bufferIndex );
+        bufferIndex += 4;
+        setupCount = buffer[bufferIndex] & 0xFF;
+        bufferIndex += 2;
+        if( setupCount != 0 ) {
+            if( log.level > 2 )
+                log.println( "setupCount is not zero: " + setupCount );
+        }
+
+        return bufferIndex - start;
+    }
+}
index 8d352fb..f755a9d 100644 (file)
@@ -56,13 +56,12 @@ class SmbComOpenAndX extends AndXServerMessageBlock {
 
     // flags is NOT the same as flags member
 
-    SmbComOpenAndX( String fileName, int flags, ServerMessageBlock andx ) {
+    SmbComOpenAndX( String fileName, int access, int flags, ServerMessageBlock andx ) {
         super( andx );
         this.path = fileName;
         command = SMB_COM_OPEN_ANDX;
 
-        // desiredAccess
-        desiredAccess = ( flags >>> 16 ) & 0x3;
+        desiredAccess = access & 0x3;
         if( desiredAccess == 0x3 ) {
             desiredAccess = 0x2; /* Mmm, I thought 0x03 was RDWR */
         }
index ca38b7a..10f194c 100644 (file)
@@ -38,12 +38,6 @@ abstract class SmbComTransaction extends ServerMessageBlock implements Enumerati
     private static final int PADDING_SIZE = 2;
 
     private int flags = 0x00;
-    private int parameterCount;
-    private int parameterOffset;
-    private int parameterDisplacement;
-    private int dataCount;
-    private int dataOffset;
-    private int dataDisplacement;
     private int fid;
     private int pad = 0;
     private int pad1 = 0;
@@ -70,6 +64,15 @@ abstract class SmbComTransaction extends ServerMessageBlock implements Enumerati
     static final byte TRANS_CALL_NAMED_PIPE     = (byte)0x54;
     static final byte TRANS_TRANSACT_NAMED_PIPE = (byte)0x26;
 
+    protected int primarySetupOffset;
+    protected int secondaryParameterOffset;
+    protected int parameterCount;
+    protected int parameterOffset;
+    protected int parameterDisplacement;
+    protected int dataCount;
+    protected int dataOffset;
+    protected int dataDisplacement;
+
     int totalParameterCount;
     int totalDataCount;
     int maxParameterCount;
@@ -85,6 +88,8 @@ abstract class SmbComTransaction extends ServerMessageBlock implements Enumerati
 
     SmbComTransaction() {
         maxParameterCount = 1024;
+        primarySetupOffset = PRIMARY_SETUP_OFFSET;
+        secondaryParameterOffset = SECONDARY_PARAMETER_OFFSET;
     }
 
     void reset() {
@@ -101,9 +106,13 @@ abstract class SmbComTransaction extends ServerMessageBlock implements Enumerati
         if( isPrimary ) {
             isPrimary = false;
 
-            parameterOffset = PRIMARY_SETUP_OFFSET + ( setupCount * 2 ) + 2;
-            if( command == SMB_COM_TRANSACTION && isResponse() == false ) {
-                parameterOffset += stringWireLength( name, parameterOffset );
+            parameterOffset = primarySetupOffset + ( setupCount * 2 ) + 2;
+            if (command != SMB_COM_NT_TRANSACT) {
+                if( command == SMB_COM_TRANSACTION && isResponse() == false ) {
+                    parameterOffset += stringWireLength( name, parameterOffset );
+                }
+            } else if (command == SMB_COM_NT_TRANSACT) {
+                parameterOffset += 2;
             }
             pad = parameterOffset % PADDING_SIZE;
             pad = pad == 0 ? 0 : PADDING_SIZE - pad;
@@ -125,7 +134,11 @@ abstract class SmbComTransaction extends ServerMessageBlock implements Enumerati
 
             dataCount = Math.min( totalDataCount, available );
         } else {
-            command = SMB_COM_TRANSACTION_SECONDARY;
+            if (command != SMB_COM_NT_TRANSACT) {
+                command = SMB_COM_TRANSACTION_SECONDARY;
+            } else {
+                command = SMB_COM_NT_TRANSACT_SECONDARY;
+            }
             // totalParameterCount and totalDataCount are set ok from primary
 
             parameterOffset = SECONDARY_PARAMETER_OFFSET;
index b10e1bd..f4e2fc3 100644 (file)
@@ -28,20 +28,20 @@ abstract class SmbComTransactionResponse extends ServerMessageBlock implements E
     private static final int DISCONNECT_TID      = 0x01;
     private static final int ONE_WAY_TRANSACTION = 0x02;
 
-    private int totalParameterCount;
-    private int totalDataCount;
-    private int parameterCount;
-    private int parameterOffset;
-    private int parameterDisplacement;
-    private int dataOffset;
-    private int dataDisplacement;
-    private int setupCount;
     private int pad;
     private int pad1;
     private boolean parametersDone, dataDone;
 
-    private int bufParameterStart;
-    private int bufDataStart;
+    protected int totalParameterCount;
+    protected int totalDataCount;
+    protected int parameterCount;
+    protected int parameterOffset;
+    protected int parameterDisplacement;
+    protected int dataOffset;
+    protected int dataDisplacement;
+    protected int setupCount;
+    protected int bufParameterStart;
+    protected int bufDataStart;
 
     int dataCount;
     byte subCommand;
index 9429cea..1dde3f0 100644 (file)
@@ -10,8 +10,8 @@ interface SmbConstants {
     static final int DEFAULT_PORT = 445;
 
     static final int DEFAULT_MAX_MPX_COUNT = 10;
-    static final int DEFAULT_RESPONSE_TIMEOUT = 10000;
-    static final int DEFAULT_SO_TIMEOUT = 15000;
+    static final int DEFAULT_RESPONSE_TIMEOUT = 30000;
+    static final int DEFAULT_SO_TIMEOUT = 35000;
     static final int DEFAULT_RCV_BUF_SIZE = 60416;
     static final int DEFAULT_SND_BUF_SIZE = 16644;
     static final int DEFAULT_SSN_LIMIT = 250;
@@ -75,6 +75,27 @@ interface SmbConstants {
     static final int ATTR_NORMAL     = 0x080;
     static final int ATTR_TEMPORARY  = 0x100;
 
+    // access mask encoding
+    static final int FILE_READ_DATA        = 0x00000001; // 1
+    static final int FILE_WRITE_DATA       = 0x00000002; // 2
+    static final int FILE_APPEND_DATA      = 0x00000004; // 3
+    static final int FILE_READ_EA          = 0x00000008; // 4
+    static final int FILE_WRITE_EA         = 0x00000010; // 5
+    static final int FILE_EXECUTE          = 0x00000020; // 6
+    static final int FILE_DELETE           = 0x00000040; // 7
+    static final int FILE_READ_ATTRIBUTES  = 0x00000080; // 8
+    static final int FILE_WRITE_ATTRIBUTES = 0x00000100; // 9
+    static final int DELETE                = 0x00010000; // 16
+    static final int READ_CONTROL          = 0x00020000; // 17
+    static final int WRITE_DAC             = 0x00040000; // 18
+    static final int WRITE_OWNER           = 0x00080000; // 19
+    static final int SYNCHRONIZE           = 0x00100000; // 20
+    static final int GENERIC_ALL           = 0x10000000; // 28
+    static final int GENERIC_EXECUTE       = 0x20000000; // 29
+    static final int GENERIC_WRITE         = 0x40000000; // 30
+    static final int GENERIC_READ          = 0x80000000; // 31
+
+
     // flags for move and copy
     static final int FLAGS_TARGET_MUST_BE_FILE         = 0x0001; 
     static final int FLAGS_TARGET_MUST_BE_DIRECTORY    = 0x0002; 
@@ -103,9 +124,7 @@ interface SmbConstants {
     static final TimeZone TZ = TimeZone.getDefault();
 
     static final boolean USE_BATCHING = Config.getBoolean( "jcifs.smb.client.useBatching", true );
-    static final String OEM_ENCODING =
-                Config.getProperty( "jcifs.encoding",
-                        System.getProperty( "file.encoding" ));
+    static final String OEM_ENCODING = Config.getProperty( "jcifs.encoding", "Cp850" );
     static final int DEFAULT_FLAGS2 =
                 FLAGS2_LONG_FILENAMES |
                 FLAGS2_EXTENDED_ATTRIBUTES |
index fc0ad88..161abfb 100644 (file)
@@ -263,13 +263,12 @@ import java.util.Date;
  * @see       java.io.File
  */
 
-public class SmbFile extends URLConnection {
+public class SmbFile extends URLConnection implements SmbConstants {
 
-    // these are shifted for use in flags
-    static final int O_RDONLY = 0x010000;
-    static final int O_WRONLY = 0x020000;
-    static final int O_RDWR   = 0x030000;
-    static final int O_APPEND = 0x040000;
+    static final int O_RDONLY = 0x01;
+    static final int O_WRONLY = 0x02;
+    static final int O_RDWR   = 0x03;
+    static final int O_APPEND = 0x04;
 
     // share access
 /**
@@ -622,6 +621,7 @@ public class SmbFile extends URLConnection {
 
         if( context.share != null ) {
             this.tree = context.tree;
+            this.dfsReferral = context.dfsReferral;
         }
         int last = name.length() - 1;
         if( name.charAt( last ) == '/' ) {
@@ -672,13 +672,12 @@ public class SmbFile extends URLConnection {
 
                     trans = SmbTransport.getSmbTransport( addr, url.getPort() );
                     tree = trans.getSmbSession( auth ).getSmbTree( dr.share, null );
-                    unc = dr.nodepath + unc.substring( dr.path.length() );
-                    if( request.path.charAt( request.path.length() - 1 ) == '\\' ) {
-                        request.path = unc + '\\'; /* preserve trailing slash */
-                    } else {
-                        request.path = unc;
-                    }
-                    dfsReferral = dr; /* for getDfsPath */
+
+                    if (log.level > 2)
+                        System.out.println( dr );
+
+                    dfsReferral = dr;
+                    request.path = getDfsUncPath0();
                 }
                 request.flags2 |= ServerMessageBlock.FLAGS2_RESOLVE_PATHS_IN_DFS;
             } else {
@@ -811,7 +810,7 @@ public class SmbFile extends URLConnection {
     boolean isConnected() {
         return (connected = tree != null && tree.treeConnected);
     }
-    int open0( int flags, int attrs, int options ) throws SmbException {
+    int open0( int flags, int access, int attrs, int options ) throws SmbException {
         int f;
 
         connect0();
@@ -825,7 +824,7 @@ public class SmbFile extends URLConnection {
 
         if( tree.session.transport.hasCapability( ServerMessageBlock.CAP_NT_SMBS )) {
             SmbComNTCreateAndXResponse response = new SmbComNTCreateAndXResponse();
-            send( new SmbComNTCreateAndX( unc, flags, shareAccess,
+            send( new SmbComNTCreateAndX( unc, flags, access, shareAccess,
                     attrs, options, null ), response );
             f = response.fid;
             attributes = response.extFileAttributes & ATTR_GET_MASK;
@@ -833,17 +832,17 @@ public class SmbFile extends URLConnection {
             isExists = true;
         } else {
             SmbComOpenAndXResponse response = new SmbComOpenAndXResponse();
-            send( new SmbComOpenAndX( unc, flags, null ), response );
+            send( new SmbComOpenAndX( unc, flags, access, null ), response );
             f = response.fid;
         }
 
         return f;
     }
-    void open( int flags, int attrs, int options ) throws SmbException {
+    void open( int flags, int access, int attrs, int options ) throws SmbException {
         if( isOpen() ) {
             return;
         }
-        fid = open0( flags, attrs, options );
+        fid = open0( flags, access, attrs, options );
         opened = true;
         tree_num = tree.tree_num;
     }
@@ -1167,6 +1166,10 @@ public class SmbFile extends URLConnection {
     Info queryPath( String path, int infoLevel ) throws SmbException {
         connect0();
 
+        if (dfsReferral != null) {
+            path = dfsReferral.nodepath + path.substring( dfsReferral.path.length() );
+        }
+
         if( log.level > 2 )
             log.println( "queryPath: " + path );
 
@@ -1359,6 +1362,14 @@ public class SmbFile extends URLConnection {
         return ( attributes & ATTR_HIDDEN ) == ATTR_HIDDEN;
     }
 
+    String getDfsUncPath0() throws SmbException {
+        getUncPath0();
+        if( dfsReferral == null ) {
+            return null;
+        }
+        String dunc = dfsReferral.nodepath + unc.substring( dfsReferral.path.length() );
+        return "".equals( dunc ) ? "\\" : dunc;
+    }
 /**
  * If the path of this <code>SmbFile</code> falls within a DFS volume,
  * this method will return the referral path to which it maps. Otherwise
@@ -1373,7 +1384,8 @@ public class SmbFile extends URLConnection {
         if( dfsReferral == null ) {
             return null;
         }
-        String path = "smb:/" + (new String( dfsReferral.node + unc )).replace( '\\', '/' );
+        String path = "smb:/" + dfsReferral.node + getDfsUncPath0();
+        path = path.replace( '\\', '/' );
         if (isDirectory()) {
             path += '/';
         }
@@ -1902,17 +1914,19 @@ public class SmbFile extends URLConnection {
             int off;
 
 try {
-            open( SmbFile.O_RDONLY, ATTR_NORMAL, 0 );
+            open( SmbFile.O_RDONLY, 0, ATTR_NORMAL, 0 );
             try {
-                dest.open( SmbFile.O_CREAT | SmbFile.O_WRONLY | SmbFile.O_TRUNC |
-                        SmbComNTCreateAndX.FILE_WRITE_ATTRIBUTES << 16, attributes, 0 );
+                dest.open( SmbFile.O_CREAT | SmbFile.O_WRONLY | SmbFile.O_TRUNC,
+                        FILE_WRITE_DATA | FILE_WRITE_ATTRIBUTES,
+                        attributes, 0 );
             } catch( SmbAuthException sae ) {
                 if(( dest.attributes & ATTR_READONLY ) != 0 ) {
                                             /* Remove READONLY and try again
                                              */
                     dest.setPathInformation( dest.attributes & ~ATTR_READONLY, 0L, 0L );
-                    dest.open( SmbFile.O_CREAT | SmbFile.O_WRONLY | SmbFile.O_TRUNC |
-                            SmbComNTCreateAndX.FILE_WRITE_ATTRIBUTES << 16, attributes, 0 );
+                    dest.open( SmbFile.O_CREAT | SmbFile.O_WRONLY | SmbFile.O_TRUNC,
+                            FILE_WRITE_DATA | FILE_WRITE_ATTRIBUTES,
+                            attributes, 0 );
                 } else {
                     throw sae;
                 }
@@ -2258,7 +2272,7 @@ try {
         if( getUncPath0().length() == 1 ) {
             throw new SmbException( "Invalid operation for workgroups, servers, or shares" );
         }
-        close( open0( O_RDWR | O_CREAT | O_EXCL, ATTR_NORMAL, 0 ), 0L );
+        close( open0( O_RDWR | O_CREAT | O_EXCL, 0, ATTR_NORMAL, 0 ), 0L );
     }
 
     void setPathInformation( int attrs, long ctime, long mtime ) throws SmbException {
@@ -2267,7 +2281,7 @@ try {
         exists();
         dir = attributes & ATTR_DIRECTORY;
 
-        f = open0( O_RDONLY | SmbComNTCreateAndX.FILE_WRITE_ATTRIBUTES << 16,
+        f = open0( O_RDONLY, FILE_WRITE_ATTRIBUTES,
                 dir, dir != 0 ? 0x0001 : 0x0040 );
         send( new Trans2SetFileInformation( f, attrs | dir, ctime, mtime ),
                 new Trans2SetFileInformationResponse() );
@@ -2497,4 +2511,19 @@ try {
     public OutputStream getOutputStream() throws IOException {
         return new SmbFileOutputStream( this );
     }
+
+    public ACE[] getSecurity() throws IOException {
+        int f = open0( O_RDONLY, READ_CONTROL, 0, isDirectory() ? 1 : 0 );
+
+        /*
+         * NtTrans Query Security Desc Request / Response
+         */
+
+        NtTransQuerySecurityDesc request = new NtTransQuerySecurityDesc( f, 0x04 );
+        NtTransQuerySecurityDescResponse response = new NtTransQuerySecurityDescResponse();
+        send( request, response );
+
+        close( f, 0L );
+        return response.aces;
+    }
 }
index 519eba4..eb9dfc7 100644 (file)
@@ -66,7 +66,7 @@ public class SmbFileInputStream extends InputStream {
         this.file = file;
         this.openFlags = openFlags;
         if (file.type != SmbFile.TYPE_NAMED_PIPE) {
-            file.open( openFlags, SmbFile.ATTR_NORMAL, 0 );
+            file.open( openFlags, 0, SmbFile.ATTR_NORMAL, 0 );
             this.openFlags &= ~(SmbFile.O_CREAT | SmbFile.O_TRUNC);
         } else {
             file.connect0();
@@ -126,7 +126,7 @@ public class SmbFileInputStream extends InputStream {
             throw new IOException( "Bad file descriptor" );
         }
         // ensure file is open
-        file.open( openFlags, SmbFile.ATTR_NORMAL, 0 );
+        file.open( openFlags, 0, SmbFile.ATTR_NORMAL, 0 );
 
         /*
          * Read AndX Request / Response
@@ -184,7 +184,7 @@ public class SmbFileInputStream extends InputStream {
         }
 
         pipe = (SmbNamedPipe)file;
-        file.open(( pipe.pipeType & 0xFF0000 ) | SmbFile.O_EXCL, SmbFile.ATTR_NORMAL, 0 );
+        file.open(SmbFile.O_EXCL, pipe.pipeType & 0xFF0000, SmbFile.ATTR_NORMAL, 0 );
 
         req = new TransPeekNamedPipe( file.unc, file.fid );
         resp = new TransPeekNamedPipeResponse( pipe );
index 4075e99..b15385e 100644 (file)
@@ -136,7 +136,7 @@ write, and/or delete the file while the jCIFS user has the file open.
             file.send( new TransWaitNamedPipe( "\\pipe" + file.unc ),
                                         new TransWaitNamedPipeResponse() );
         }
-        file.open( openFlags, SmbFile.ATTR_NORMAL, 0 );
+        file.open( openFlags, SmbConstants.FILE_WRITE_DATA, SmbFile.ATTR_NORMAL, 0 );
         this.openFlags &= ~(SmbFile.O_CREAT | SmbFile.O_TRUNC); /* in case close and reopen */
         writeSize = file.tree.session.transport.snd_buf_size - 70;
 
@@ -206,7 +206,7 @@ write, and/or delete the file while the jCIFS user has the file open.
                 file.send( new TransWaitNamedPipe( "\\pipe" + file.unc ),
                                         new TransWaitNamedPipeResponse() );
             }
-            file.open( openFlags, SmbFile.ATTR_NORMAL, 0 );
+            file.open( openFlags, SmbConstants.FILE_WRITE_DATA, SmbFile.ATTR_NORMAL, 0 );
             if( append ) {
                 fp = file.length();
             }
index 51d01c9..7760961 100644 (file)
@@ -33,7 +33,7 @@ public class SmbRandomAccessFile implements DataOutput, DataInput {
 
     private SmbFile file;
     private long fp;
-    private int openFlags, readSize, writeSize, ch, options = 0;
+    private int openFlags, access = 0, readSize, writeSize, ch, options = 0;
     private byte[] tmp = new byte[8];
     private SmbComWriteAndXResponse write_andx_resp = null;
 
@@ -50,10 +50,11 @@ public class SmbRandomAccessFile implements DataOutput, DataInput {
             this.openFlags = SmbFile.O_CREAT | SmbFile.O_RDWR | SmbFile.O_APPEND;
             write_andx_resp = new SmbComWriteAndXResponse();
             options = WRITE_OPTIONS;
+            access = SmbConstants.FILE_READ_DATA | SmbConstants.FILE_WRITE_DATA;
         } else {
             throw new IllegalArgumentException( "Invalid mode" );
         }
-        file.open( openFlags, SmbFile.ATTR_NORMAL, options );
+        file.open( openFlags, access, SmbFile.ATTR_NORMAL, options );
         readSize = file.tree.session.transport.rcv_buf_size - 70;
         writeSize = file.tree.session.transport.snd_buf_size - 70;
         fp = 0L;
@@ -76,7 +77,7 @@ public class SmbRandomAccessFile implements DataOutput, DataInput {
 
         // ensure file is open
         if( file.isOpen() == false ) {
-            file.open( openFlags, SmbFile.ATTR_NORMAL, options );
+            file.open( openFlags, 0, SmbFile.ATTR_NORMAL, options );
         }
 
         int r, n;
@@ -129,7 +130,7 @@ public class SmbRandomAccessFile implements DataOutput, DataInput {
 
         // ensure file is open
         if( file.isOpen() == false ) {
-            file.open( openFlags, SmbFile.ATTR_NORMAL, options );
+            file.open( openFlags, 0, SmbFile.ATTR_NORMAL, options );
         }
 
         int w;
@@ -153,7 +154,7 @@ public class SmbRandomAccessFile implements DataOutput, DataInput {
     public void setLength( long newLength ) throws SmbException {
         // ensure file is open
         if( file.isOpen() == false ) {
-            file.open( openFlags, SmbFile.ATTR_NORMAL, options );
+            file.open( openFlags, 0, SmbFile.ATTR_NORMAL, options );
         }
         SmbComWriteResponse rsp = new SmbComWriteResponse();
         file.send( new SmbComWrite( file.fid, (int)(newLength & 0xFFFFFFFFL), 0, tmp, 0, 0 ), rsp );
index b565b19..581363a 100644 (file)
@@ -219,15 +219,19 @@ public final class SmbSession {
         if( response != null ) {
             response.received = false;
         }
-        expiration = System.currentTimeMillis() + SmbTransport.SO_TIMEOUT;
-        sessionSetup( request, response );
-        if( response != null && response.received ) {
-            return;
+
+        synchronized(transport.setupDiscoLock) {
+            expiration = System.currentTimeMillis() + SmbTransport.SO_TIMEOUT;
+            sessionSetup( request, response );
+            if( response != null && response.received ) {
+                return;
+            }
+            request.uid = uid;
+            request.auth = auth;
+            transport.send( request, response );
         }
-        request.uid = uid;
-        request.auth = auth;
-        transport.send( request, response );
     }
+int x = 0;
     void sessionSetup( ServerMessageBlock andx,
                             ServerMessageBlock andxResponse ) throws SmbException {
 synchronized( transport() ) {
@@ -256,8 +260,9 @@ synchronized( transport() ) {
                 /* preauthentication
                  */
                 transport.getSmbSession( NtlmPasswordAuthentication.DEFAULT ).getSmbTree( LOGON_SHARE, null ).treeConnect( null, null );
+            } else {
+                request.digest = new SigningDigest( transport, auth );
             }
-            request.digest = new SigningDigest( transport, auth );
         }
 
         request.auth = auth;
index 5248e3b..71dfea7 100644 (file)
@@ -463,6 +463,13 @@ public class SmbTransport extends Transport implements SmbConstants {
             if (digest != null && resp.errorCode == 0) {
                 digest.verify( BUF, 4, resp );
             }
+
+            if (log.level > 3) {
+                log.println( response );
+                if (log.level > 5) {
+                    Hexdump.hexdump( log, BUF, 4, size );
+                }
+            }
         }
     }
     protected void doSkip() throws IOException {
index 78e5c73..a39670a 100644 (file)
@@ -115,7 +115,10 @@ class SmbTree {
     void treeConnect( ServerMessageBlock andx,
                             ServerMessageBlock andxResponse ) throws SmbException {
         String unc;
-synchronized( session.transport() ) {
+        SmbTransport transport = session.transport();
+
+synchronized(transport.setupDiscoLock) {
+synchronized(transport) {
 
         if (treeConnected) {
             return;
@@ -149,6 +152,7 @@ synchronized( session.transport() ) {
         treeConnected = true;
         tree_num = tree_conn_counter++;
 }
+}
     }
     void treeDisconnect( boolean inError ) {
 synchronized( session.transport ) {
index 90033a6..3b38129 100644 (file)
@@ -57,7 +57,7 @@ class TransactNamedPipeOutputStream extends OutputStream {
                                         new TransCallNamedPipeResponse( pipe ));
         } else if(( pipe.pipeType & SmbNamedPipe.PIPE_TYPE_TRANSACT ) ==
                                                     SmbNamedPipe.PIPE_TYPE_TRANSACT ) {
-            pipe.open(( pipe.pipeType & 0xFFFF0000 ) | SmbFile.O_EXCL, SmbFile.ATTR_NORMAL, 0 );
+            pipe.open(SmbFile.O_EXCL, pipe.pipeType & 0xFFFF0000, SmbFile.ATTR_NORMAL, 0 );
             TransTransactNamedPipe req = new TransTransactNamedPipe( pipe.fid, b, off, len );
             if (dcePipe) {
                 req.maxDataCount = 1024;
index 6438c8b..c31268b 100644 (file)
@@ -57,6 +57,8 @@ public abstract class Transport implements Runnable {
     protected abstract void doRecv( Response response ) throws IOException;
     protected abstract void doSkip() throws IOException;
 
+    public Object setupDiscoLock = new Object();
+
     public void sendrecv( Request request,
                     Response response,
                     long timeout ) throws IOException {
@@ -110,7 +112,7 @@ public abstract class Transport implements Runnable {
                         response_map.notifyAll();
                     }
                 }
-            } catch( IOException ex ) {
+            } catch( Exception ex ) {
                 String msg = ex.getMessage();
                 boolean hard = true;
 
@@ -188,21 +190,25 @@ public abstract class Transport implements Runnable {
             }
         }
     }
-    public synchronized void disconnect( boolean hard ) throws IOException {
-        switch (state) {
-            case 0: /* not connected - just return */
-                return;
-            case 3: /* connected - go ahead and disconnect */
-                if (response_map.size() != 0 && !hard) {
-                    break; /* outstanding requests */
+    public void disconnect( boolean hard ) throws IOException {
+        synchronized(setupDiscoLock) {
+            synchronized(this) {
+                switch (state) {
+                    case 0: /* not connected - just return */
+                        return;
+                    case 3: /* connected - go ahead and disconnect */
+                        if (response_map.size() != 0 && !hard) {
+                            break; /* outstanding requests */
+                        }
+                        doDisconnect( hard );
+                    case 4: /* in error - reset the transport */
+                        thread = null;
+                        state = 0;
+                        break;
+                    default:
+                        throw new TransportException( "Invalid state: " + state );
                 }
-                doDisconnect( hard );
-            case 4: /* in error - reset the transport */
-                thread = null;
-                state = 0;
-                break;
-            default:
-                throw new TransportException( "Invalid state: " + state );
+            }
         }
     }
     public void run() {