jcifs-1.2.6 from tgz
authorFelix Schumacher <p0354740@isib001.(none)>
Wed, 6 Aug 2008 14:34:40 +0000 (16:34 +0200)
committerFelix Schumacher <p0354740@isib001.(none)>
Wed, 6 Aug 2008 14:34:40 +0000 (16:34 +0200)
Fri Oct  7 19:47:53 EDT 2005
jcifs-1.2.6 released / Session Management and Filter Fix

It  was  discovered  that redundant sessions could be created. This problem
has  been  fixed  but  the  fix  is to not remove sessions from the list of
sessions  for a transport which is somewhat of a waste of memory. This will
probably  need  to  be  revisited. It has been advised that the Filter call
setStatus() before setContentLength(0). This change has been implemented.

README.txt
build.xml
examples/SmbThreadTest.java [new file with mode: 0644]
src/jcifs/http/NtlmHttpFilter.java
src/jcifs/smb/ServerMessageBlock.java
src/jcifs/smb/SmbTransport.java
src/jcifs/util/transport/Transport.java

index 4e90ab2..dbf3812 100644 (file)
@@ -1,3 +1,12 @@
+Fri Oct  7 19:47:53 EDT 2005
+jcifs-1.2.6 released / Session Management and Filter Fix
+
+It  was  discovered  that redundant sessions could be created. This problem
+has  been  fixed  but  the  fix  is to not remove sessions from the list of
+sessions  for a transport which is somewhat of a waste of memory. This will
+probably  need  to  be  revisited. It has been advised that the Filter call
+setStatus() before setContentLength(0). This change has been implemented. 
+
 Fri Sep 30 23:28:51 EDT 2005
 jcifs-1.2.5  released  /  Filter Exceptions, Stressing the Transport Layer,
   and DFS Deadlock Fixed 
index 4817199..2af089c 100644 (file)
--- a/build.xml
+++ b/build.xml
@@ -1,7 +1,7 @@
 <project name="jcifs" default="usage" basedir=".">
 
-    <property name="version" value="1.2.5"/>
-    <property name="reldate" value="Oct 1, 2005"/>
+    <property name="version" value="1.2.6"/>
+    <property name="reldate" value="Oct 7, 2005"/>
 
     <target name="usage">
         <echo>
diff --git a/examples/SmbThreadTest.java b/examples/SmbThreadTest.java
new file mode 100644 (file)
index 0000000..a4000e1
--- /dev/null
@@ -0,0 +1,134 @@
+import jcifs.smb.SmbFile;
+import jcifs.smb.NtlmPasswordAuthentication;
+import jcifs.smb.SmbAuthException;
+
+
+import java.util.Random;
+import java.net.MalformedURLException;
+import java.io.IOException;
+
+public class SmbThreadTest extends Thread {
+
+    int maxDepth;
+    int id;
+    String url;
+    NtlmPasswordAuthentication auth;
+    long start_time;
+
+    static Random rnd = new Random(1234);
+    static long test_time = 100*1000;
+    static long num_sessions = 1000;
+    static long session_time = (test_time / num_sessions) * 400;
+
+    static boolean verbose = false;
+
+
+    SmbThreadTest(NtlmPasswordAuthentication auth, String url, int maxDepth, int id) {
+        this.url = url;
+        this.auth = auth;
+        this.maxDepth = maxDepth;
+        this.id = id;
+        this.start_time = System.currentTimeMillis();
+    }
+
+    void traverse( SmbFile f, int depth ) throws MalformedURLException, IOException {
+
+        if( depth == 0 ) {
+            return;
+        }
+        SmbFile[] l = null;
+        try {
+            if (f.exists())
+                l = f.listFiles();
+        } catch (SmbAuthException ae) {
+            System.err.println("SAE: " + ae.getMessage());
+            ae.printStackTrace( System.err );
+            return;
+        } catch (NullPointerException npe) {
+            System.err.println("NPE");
+            npe.printStackTrace( System.err );
+            return;
+        }
+        for(int i = 0; l != null && i < l.length; i++ ) {
+            try {
+                boolean exists = l[i].exists();
+                if (verbose) {
+                    System.out.print(id);
+                    for( int j = maxDepth - depth; j > 0; j-- ) {
+                       System.out.print( "    " );
+                    }
+                    System.out.println( l[i] + " " + exists );
+                }
+                if( l[i].isDirectory() ) {
+                    traverse( l[i], depth - 1 );
+                }
+            } catch (SmbAuthException ae) {
+                System.err.println("SAE: " + ae.getMessage());
+                ae.printStackTrace( System.err );
+            } catch( IOException ioe ) {
+                System.out.println( l[i] + ":" );
+                ioe.printStackTrace( System.out );
+            }
+            try {
+                Thread.sleep(Math.abs(rnd.nextInt(2)+1));
+            } catch (InterruptedException e) {
+
+            } 
+        }
+    }
+
+    public void run () {
+        SmbFile f = null;
+        int runs = 0;
+        while(true) {
+            try {
+                Thread.sleep(100);
+            }catch (InterruptedException e) {}
+
+            while (f == null) {
+                try {
+                    f = new SmbFile(url, auth);
+                } catch (Exception e) {
+                    System.err.println(e.getMessage());
+                    e.printStackTrace();
+                }
+            }
+            try {
+                traverse(f, maxDepth);
+            } catch (Exception e) {
+                System.err.println(e.getMessage());
+                e.printStackTrace();
+            }
+            runs++;
+            long time =  System.currentTimeMillis() - start_time;
+            if (time > session_time) {
+                System.err.println(id + " exit (" + time/runs + ")");
+                return;
+            }
+        }
+    }
+
+    public static void createThreads(String url, int i, int count) {
+        NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null);
+        int num = 0;
+        System.err.println("creating " + count  + " threads");
+        while (num < count) {
+            SmbThreadTest sc = new SmbThreadTest(auth, url, 3, i * 100 + num++);
+            sc.start();
+            try {
+                Thread.sleep(50);
+            } catch (InterruptedException e) {
+                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+            }
+        }
+    }
+
+    public static void main(String[] argv) throws Exception {
+        for(int i = 0; i < num_sessions; i++) {
+            createThreads(argv[0], i+1, Math.abs(rnd.nextInt(4)+1));
+            sleep((test_time / num_sessions)*100);
+        }
+        sleep(6000000);
+    }
+}
+
index 91e4a65..fa3e453 100644 (file)
@@ -205,8 +205,8 @@ public class NtlmHttpFilter implements Filter {
                     resp.addHeader( "WWW-Authenticate", "Basic realm=\"" +
                             realm + "\"");
                 }
-                resp.setContentLength(0); /* Marcel Feb-15-2005 */
                 resp.setStatus( HttpServletResponse.SC_UNAUTHORIZED );
+                resp.setContentLength(0); /* Marcel Feb-15-2005 */
                 resp.flushBuffer();
                 return null;
             }
index 2a9e52d..983459f 100644 (file)
@@ -470,10 +470,11 @@ Hexdump.hexdump( System.err, src, srcIndex, maxLen < 128 ? maxLen + 8 : 128 );
             default:
                 c = "UNKNOWN";
         }
+        String str = errorCode == 0 ? "0" : SmbException.getMessageByCode( errorCode );
         return new String(
             "command="      + c +
             ",received="    + received +
-            ",errorCode=" + SmbException.getMessageByCode( errorCode ) +
+            ",errorCode="   + str +
             ",flags=0x"     + Hexdump.toHexString( flags & 0xFF, 4 ) +
             ",flags2=0x"    + Hexdump.toHexString( flags2, 4 ) +
             ",signSeq="     + signSeq +
index 28fe58e..9a3fc6d 100644 (file)
@@ -128,7 +128,7 @@ public class SmbTransport extends Transport implements SmbConstants {
             }
         }
 
-                                        /* close old sessions */
+                                        /* logoff old sessions */
         if (SO_TIMEOUT > 0 && sessionExpiration < (now = System.currentTimeMillis())) {
             sessionExpiration = now + SO_TIMEOUT;
             iter = sessions.listIterator();
@@ -136,7 +136,6 @@ public class SmbTransport extends Transport implements SmbConstants {
                 ssn = (SmbSession)iter.next();
                 if( ssn.expiration < now ) {
                     ssn.logoff( false );
-                    iter.remove();
                 }
             }
         }
@@ -149,7 +148,9 @@ public class SmbTransport extends Transport implements SmbConstants {
     }
     boolean matches( UniAddress address, int port, InetAddress localAddr, int localPort ) {
         return address.equals( this.address ) &&
-                    (port == 0 || port == this.port) &&
+                    (port == 0 || port == this.port ||
+                            /* port 139 is ok if 445 was requested */
+                            (port == 445 && this.port == 139)) &&
                     (localAddr == this.localAddr ||
                             (localAddr != null &&
                                     localAddr.equals( this.localAddr ))) &&
@@ -316,7 +317,6 @@ public class SmbTransport extends Transport implements SmbConstants {
         while (iter.hasNext()) {
             SmbSession ssn = (SmbSession)iter.next();
             ssn.logoff( hard );
-            iter.remove();
         }
         socket.shutdownOutput();
         out.close();
index 31408d4..d88628c 100644 (file)
@@ -147,6 +147,7 @@ public abstract class Transport implements Runnable {
     public synchronized void connect( long timeout ) throws TransportException {
         switch (state) {
             case 0:
+System.out.println( name + ":   connect: state=" + state );
                 break;
             case 3:
                 return; // already connected
@@ -179,6 +180,7 @@ public abstract class Transport implements Runnable {
                         throw te;
                     }
                     state = 3;                         /* Success! */
+System.out.println( name + ": connected: state=" + state );
                     return;
                 default:
                     te = new TransportException( "Invalid state: " + state );
@@ -190,10 +192,12 @@ public abstract class Transport implements Runnable {
             case 0: /* not connected - just return */
                 return;
             case 3: /* connected - go ahead and disconnect */
+System.out.println( name + ": disconnecting: state=" + state + ",mapsize=" + response_map.size() + ",hard=" + hard);
                 if (response_map.size() != 0 && !hard) {
                     break; /* outstanding requests */
                 }
                 doDisconnect( hard );
+System.out.println( name + ": disconnected: state=" + state );
             case 4: /* in error - reset the transport */
                 thread = null;
                 state = 0;
@@ -231,6 +235,7 @@ public abstract class Transport implements Runnable {
                 }
                 state = 2; // run connected
                 run_thread.notify();
+System.out.println( name + ": run connected" );
             }
         }