jcifs-1.1.7 from tgz
authorFelix Schumacher <p0354740@isib001.(none)>
Wed, 6 Aug 2008 14:27:38 +0000 (16:27 +0200)
committerFelix Schumacher <p0354740@isib001.(none)>
Wed, 6 Aug 2008 14:27:38 +0000 (16:27 +0200)
Sun Jan 16 17:30:17 EST 2005
jcifs-1.1.7 released

A  bug  introduced  in  a  recent  release that could cause threads to wait
indefinately  has  been  fixed.  After  time  many threads could be blocked
resulting  in  wasted  resources.  The  DC lookup code has been modified to
gracefully  handle  WINS  returning  an  empty  list (e.g. due to temporary
network failure). A simple fix has been applied that premits SMB signatures
to work without specifying preauthentication credentials. The getAttributes
method  will  now  return 31 bits of attributes whereas previously it would
mask  off the lower 6 bits that JCIFS actually makes use of. A bug has been
fixed  that under certain conditions prevented copyTo() from copying entire
shares.  A try/catch block has been added to copyTo() to permit the copy to
continue if an error occurs.

README.txt
build.xml
examples/CheckAllDC.java [new file with mode: 0644]
examples/CountPerms.java [new file with mode: 0644]
examples/ListDC.java
examples/TestCopy.java [new file with mode: 0644]
src/jcifs/smb/NtlmPasswordAuthentication.java
src/jcifs/smb/SmbFile.java
src/jcifs/smb/SmbSession.java
src/jcifs/smb/SmbTransport.java

index d6713c8..bc841c2 100644 (file)
@@ -1,3 +1,18 @@
+Sun Jan 16 17:30:17 EST 2005
+jcifs-1.1.7 released
+
+A  bug  introduced  in  a  recent  release that could cause threads to wait
+indefinately  has  been  fixed.  After  time  many threads could be blocked
+resulting  in  wasted  resources.  The  DC lookup code has been modified to
+gracefully  handle  WINS  returning  an  empty  list (e.g. due to temporary
+network failure). A simple fix has been applied that premits SMB signatures
+to work without specifying preauthentication credentials. The getAttributes
+method  will  now  return 31 bits of attributes whereas previously it would
+mask  off the lower 6 bits that JCIFS actually makes use of. A bug has been
+fixed  that under certain conditions prevented copyTo() from copying entire
+shares.  A try/catch block has been added to copyTo() to permit the copy to
+continue if an error occurs. 
+
 Mon Dec 27 17:53:42 EST 2004
 jcifs-1.1.6 released
 
index 0715361..8927408 100644 (file)
--- a/build.xml
+++ b/build.xml
@@ -1,7 +1,7 @@
 <project name="jcifs" default="usage" basedir=".">
 
-    <property name="version" value="1.1.6"/>
-    <property name="reldate" value="Dec 27, 2004"/>
+    <property name="version" value="1.1.7"/>
+    <property name="reldate" value="Jan 16, 2005"/>
 
     <target name="usage">
         <echo>
diff --git a/examples/CheckAllDC.java b/examples/CheckAllDC.java
new file mode 100644 (file)
index 0000000..d76feb6
--- /dev/null
@@ -0,0 +1,23 @@
+import jcifs.netbios.NbtAddress;
+import jcifs.*;
+import jcifs.smb.*;
+
+public class CheckAllDC {
+
+    public static void main( String argv[] ) throws Exception {
+
+        if( argv.length < 2 ) {
+            System.err.println( "usage: CheckAllDC <domain> <dom;user:pass>" );
+            System.exit(1);
+        }
+
+        NbtAddress[] addrs = NbtAddress.getAllByName( argv[0], 0x1C, null, null );
+
+        for( int i = 0; i < addrs.length; i++ ) {
+            System.out.println( addrs[i] );
+            UniAddress dc = new UniAddress( addrs[i] );
+            NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication( argv[1] );
+            SmbSession.logon( dc, auth );
+        }
+    }
+}
diff --git a/examples/CountPerms.java b/examples/CountPerms.java
new file mode 100644 (file)
index 0000000..7f84945
--- /dev/null
@@ -0,0 +1,114 @@
+import jcifs.smb.SmbFile;
+import java.util.LinkedList;
+import java.util.ListIterator;
+import java.net.MalformedURLException;
+import java.io.IOException;
+import jcifs.util.Hexdump;
+
+public class CountPerms {
+
+    int maxDepth;
+    int numFiles;
+    int numDirectories;
+    int numMeta;
+    int numMetaWithArch;
+
+    int[] permissionCounts = new int[16];
+
+    String[] permissionNames = {
+        "Read Only",
+        "Hidden",
+        "System",
+        "Volume ID",
+        "Directory",
+        "Archive",
+        "Device",
+        "Normal",
+        "Temporary",
+        "Sparse",
+        "Reparse Point",
+        "Compressed",
+        "Offline",
+        "Content Indexed",
+        "Encrypted",
+        "Unknown"
+    };
+
+    CountPerms( int maxDepth ) {
+        this.maxDepth = maxDepth;
+    }
+
+    void traverse( SmbFile f, int depth ) throws MalformedURLException, IOException {
+
+        if( depth == 0 ) {
+            return;
+        }
+
+        SmbFile[] l = f.listFiles();
+
+        for(int i = 0; l != null && i < l.length; i++ ) {
+            try {
+                int attrs = l[i].getAttributes();
+
+                if(( attrs & 0x7FEE ) != 0) {
+                    if(( attrs & 0x7FCE ) != 0) {
+                        numMeta++;
+                    }
+                    numMetaWithArch++;
+                }
+                for (int b = 0; b < 16; b++) {
+                    if(( attrs & (1 << b)) != 0 ) {
+                        permissionCounts[b]++;
+                    }
+                }
+
+                System.out.print( Hexdump.toHexString( l[i].getAttributes(), 4 ) + ": " );
+                for( int j = maxDepth - depth; j > 0; j-- ) {
+                    System.out.print( "    " );
+                }
+                System.out.println( l[i].getName()  );
+                if( l[i].isDirectory() ) {
+                    traverse( l[i], depth - 1 );
+                }
+
+                if(( attrs & SmbFile.ATTR_DIRECTORY ) != 0 ) {
+                    numDirectories++;
+                } else {
+                    numFiles++;
+                }
+            } catch( IOException ioe ) {
+                System.out.println( l[i] + ": " + ioe.getMessage() );
+            }
+        }
+    }
+
+    void run( String url ) throws Exception {
+        traverse( new SmbFile( url ), maxDepth );
+
+        for (int p = 0; p < 16; p++) {
+            int len = 15 - permissionNames[p].length();
+            while( len > 0 ) {
+                System.out.print( " " );
+                len--;
+            }
+            System.out.println( permissionNames[p] + ": " + permissionCounts[p] );
+        }
+        System.out.println( "            num files: " + numFiles );
+        System.out.println( "      num directories: " + numDirectories );
+        System.out.println( "             num both: " + (numFiles + numDirectories) );
+        System.out.println( "             meta req: " + numMeta );
+        System.out.println( "meta (incl. arch) req: " + numMetaWithArch );
+    }
+
+    public static void main(String[] argv) throws Exception {
+
+        if( argv.length < 2 ) {
+            System.err.println( "usage: CountPerms <dir> <maxdepth>" );
+            System.exit(1);
+        }
+
+        int depth = Integer.parseInt( argv[1] );
+        CountPerms cp = new CountPerms( depth );
+        cp.run( argv[0] );
+    }
+}
index b0ad0f2..4a1cda4 100644 (file)
@@ -1,6 +1,8 @@
 import jcifs.netbios.NbtAddress;
+import jcifs.*;
+import jcifs.smb.*;
 
-public class ListDC {
+public class CheckAllDC {
 
     public static void main( String argv[] ) throws Exception {
 
@@ -8,6 +10,9 @@ public class ListDC {
 
         for( int i = 0; i < addrs.length; i++ ) {
             System.out.println( addrs[i] );
+            UniAddress dc = new UniAddress( addrs[i] );
+            NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication( argv[1] );
+            SmbSession.logon( dc, auth );
         }
     }
 }
diff --git a/examples/TestCopy.java b/examples/TestCopy.java
new file mode 100644 (file)
index 0000000..556dfbf
--- /dev/null
@@ -0,0 +1,25 @@
+import jcifs.smb.*;
+
+public class TestCopy {
+
+    public static void main( String[] args ) throws Exception {
+
+        if( args.length < 1 ) {
+            System.err.println( "usage: TestCopy <from1> <to1> [<from2> <to2> [<from3 ...]]");
+            System.exit(1);
+        }
+
+        for( int i = 0; i < args.length; i += 2 ) {
+            try {
+                SmbFile remote = new SmbFile( args[i] );
+                if( remote.exists() ) {
+                    SmbFile local = new SmbFile( args[i + 1] );
+                    remote.copyTo( local );
+                }
+            } catch( Exception e ) {
+                System.err.println( args[i] + " -> " + args[i + 1] );
+                e.printStackTrace();
+            }
+        }
+    }
+}
index 635e98c..b0e1939 100644 (file)
@@ -51,8 +51,9 @@ public final class NtlmPasswordAuthentication implements Principal, Serializable
     private static final String DEFAULT_USERNAME =
             Config.getProperty("jcifs.smb.client.username", "GUEST");
 
+    static final String BLANK = "";
     static final String DEFAULT_PASSWORD =
-            Config.getProperty("jcifs.smb.client.password", "");
+            Config.getProperty("jcifs.smb.client.password", BLANK);
 
     private static final Random RANDOM = new Random();
 
index 6615e46..2900345 100644 (file)
@@ -346,7 +346,7 @@ public class SmbFile extends URLConnection {
     static final int ATTR_NORMAL           = 0x080;
     static final int ATTR_TEMPORARY        = 0x100;
 
-    static final int ATTR_GET_MASK = 0x3F;
+    static final int ATTR_GET_MASK = 0x7FFF;
     static final int ATTR_SET_MASK = 0x27;
 
     static final int DEFAULT_ATTR_EXPIRATION_PERIOD = 5000;
@@ -1899,13 +1899,16 @@ public class SmbFile extends URLConnection {
             SmbFile[] files;
             SmbFile ndest;
 
-            try {
-                dest.mkdir();
-                dest.setPathInformation( attributes, createTime, lastModified );
-            } catch( SmbException se ) {
-                if( se.getNtStatus() != NtStatus.NT_STATUS_ACCESS_DENIED &&
-                        se.getNtStatus() != NtStatus.NT_STATUS_OBJECT_NAME_COLLISION ) {
-                    throw se;
+            String path = dest.getUncPath0();
+            if( path.length() > 1 ) {
+                try {
+                    dest.mkdir();
+                    dest.setPathInformation( attributes, createTime, lastModified );
+                } catch( SmbException se ) {
+                    if( se.getNtStatus() != NtStatus.NT_STATUS_ACCESS_DENIED &&
+                            se.getNtStatus() != NtStatus.NT_STATUS_OBJECT_NAME_COLLISION ) {
+                        throw se;
+                    }
                 }
             }
 
@@ -1929,6 +1932,7 @@ public class SmbFile extends URLConnection {
         } else {
             int off;
 
+try {
             open( SmbFile.O_RDONLY, ATTR_NORMAL, 0 );
             try {
                 dest.open( SmbFile.O_CREAT | SmbFile.O_WRONLY | SmbFile.O_TRUNC |
@@ -1977,6 +1981,10 @@ public class SmbFile extends URLConnection {
                     new Trans2SetFileInformationResponse() );
             dest.close( 0L );
             close();
+} catch( Exception ex ) {
+    if( log.level > 1 )
+        ex.printStackTrace( log );
+}
         }
     }
 /**
@@ -2485,4 +2493,13 @@ public class SmbFile extends URLConnection {
     public InputStream getInputStream() throws IOException {
         return new SmbFileInputStream( this );
     }
+
+/**
+ * This URLConnection method just returns a new <tt>SmbFileOutputStream</tt> created with this file.
+ *
+ * @throw IOException thrown by <tt>SmbFileOutputStream</tt> constructor
+ */
+    public OutputStream getOutputStream() throws IOException {
+        return new SmbFileOutputStream( this );
+    }
 }
index 545817e..7e0d3a8 100644 (file)
@@ -93,7 +93,10 @@ synchronized( DOMAIN ) {
             }
 
             NbtAddress[] new_dc_list = NbtAddress.getAllByName( DOMAIN, 0x1C, null, null );
-            if( new_dc_list != null && new_dc_list.length >= dc_list_range ) {
+            if( new_dc_list == null) {
+                dc_list_expiration = System.currentTimeMillis() + 10000; /* 10sec */
+                throw new UnknownHostException( DOMAIN );
+            } else if( new_dc_list.length >= dc_list_range ) {
                 dc_list = new_dc_list;
             }
             if( dc_list_range > 1 ) {
@@ -274,7 +277,7 @@ synchronized( transport() ) {
          * Only the first SMB_COM_SESSION_SETUP_ANX with creds other than NULL initializes signing.
          */
         if( transport.isSignatureSetupRequired( auth )) {
-            if( auth.hashesExternal && NtlmPasswordAuthentication.DEFAULT_PASSWORD != null ) {
+            if( auth.hashesExternal && NtlmPasswordAuthentication.DEFAULT_PASSWORD != NtlmPasswordAuthentication.BLANK ) {
                 /* preauthentication
                  */
                 transport.getSmbSession( NtlmPasswordAuthentication.DEFAULT ).getSmbTree( LOGON_SHARE, null ).treeConnect( null, null );
index 1e21ad1..b6035d2 100644 (file)
@@ -945,6 +945,7 @@ synchronized( snd_buf ) {
         }
 
         state = ST_NEGOTIATED;
+        notifyAll();
     }
     public String toString() {
         String ret = "SmbTransport[address=" + address;