From bc61feca29e24a529b7dd85fadabfe1b898e4b52 Mon Sep 17 00:00:00 2001 From: Felix Schumacher Date: Wed, 6 Aug 2008 16:27:38 +0200 Subject: [PATCH] jcifs-1.1.7 from tgz 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 | 15 ++++ build.xml | 4 +- examples/CheckAllDC.java | 23 ++++++ examples/CountPerms.java | 114 ++++++++++++++++++++++++++ examples/ListDC.java | 7 +- examples/TestCopy.java | 25 ++++++ src/jcifs/smb/NtlmPasswordAuthentication.java | 3 +- src/jcifs/smb/SmbFile.java | 33 ++++++-- src/jcifs/smb/SmbSession.java | 7 +- src/jcifs/smb/SmbTransport.java | 1 + 10 files changed, 218 insertions(+), 14 deletions(-) create mode 100644 examples/CheckAllDC.java create mode 100644 examples/CountPerms.java create mode 100644 examples/TestCopy.java diff --git a/README.txt b/README.txt index d6713c8..bc841c2 100644 --- a/README.txt +++ b/README.txt @@ -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 diff --git a/build.xml b/build.xml index 0715361..8927408 100644 --- a/build.xml +++ b/build.xml @@ -1,7 +1,7 @@ - - + + diff --git a/examples/CheckAllDC.java b/examples/CheckAllDC.java new file mode 100644 index 0000000..d76feb6 --- /dev/null +++ b/examples/CheckAllDC.java @@ -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 " ); + 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 index 0000000..7f84945 --- /dev/null +++ b/examples/CountPerms.java @@ -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 " ); + System.exit(1); + } + + int depth = Integer.parseInt( argv[1] ); + CountPerms cp = new CountPerms( depth ); + cp.run( argv[0] ); + } +} diff --git a/examples/ListDC.java b/examples/ListDC.java index b0ad0f2..4a1cda4 100644 --- a/examples/ListDC.java +++ b/examples/ListDC.java @@ -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 index 0000000..556dfbf --- /dev/null +++ b/examples/TestCopy.java @@ -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 [ [ " + args[i + 1] ); + e.printStackTrace(); + } + } + } +} diff --git a/src/jcifs/smb/NtlmPasswordAuthentication.java b/src/jcifs/smb/NtlmPasswordAuthentication.java index 635e98c..b0e1939 100644 --- a/src/jcifs/smb/NtlmPasswordAuthentication.java +++ b/src/jcifs/smb/NtlmPasswordAuthentication.java @@ -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(); diff --git a/src/jcifs/smb/SmbFile.java b/src/jcifs/smb/SmbFile.java index 6615e46..2900345 100644 --- a/src/jcifs/smb/SmbFile.java +++ b/src/jcifs/smb/SmbFile.java @@ -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 SmbFileOutputStream created with this file. + * + * @throw IOException thrown by SmbFileOutputStream constructor + */ + public OutputStream getOutputStream() throws IOException { + return new SmbFileOutputStream( this ); + } } diff --git a/src/jcifs/smb/SmbSession.java b/src/jcifs/smb/SmbSession.java index 545817e..7e0d3a8 100644 --- a/src/jcifs/smb/SmbSession.java +++ b/src/jcifs/smb/SmbSession.java @@ -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 ); diff --git a/src/jcifs/smb/SmbTransport.java b/src/jcifs/smb/SmbTransport.java index 1e21ad1..b6035d2 100644 --- a/src/jcifs/smb/SmbTransport.java +++ b/src/jcifs/smb/SmbTransport.java @@ -945,6 +945,7 @@ synchronized( snd_buf ) { } state = ST_NEGOTIATED; + notifyAll(); } public String toString() { String ret = "SmbTransport[address=" + address; -- 2.11.0