From befadb945e61fc47077ed5ff49e1f2631a9751c6 Mon Sep 17 00:00:00 2001 From: Felix Schumacher Date: Wed, 6 Aug 2008 16:28:14 +0200 Subject: [PATCH] jcifs-1.1.8 from tgz Thu Feb 10 22:29:12 EST 2005 jcifs-1.1.8 released The blocked thread bug wasn't quite fixed in the last release. A lookup exception (e.g. caused by an unresponsive domain controller) could leave a thread blocked if many requests are being processed simultaneously. Similarly the fix for the DC lookup code wasn't complete enough to handle the unusual scenario where all DCs are unresponsive. Also, a malfomed NetBIOS name query response could cause the name service thread to exit incorrectly. These issues have been fixed. Finally, the URL handling of smb://@/ (meaning "null" credentials) has been fixed. --- README.txt | 12 ++++++ build.xml | 4 +- examples/Makefile | 2 +- examples/UrlReader.java | 41 ++++++++++++++++++++ examples/runtests.sh | 2 +- src/jcifs/netbios/NameServiceClient.java | 46 +++++++++++----------- src/jcifs/smb/SmbFile.java | 2 +- src/jcifs/smb/SmbSession.java | 18 ++++++--- src/jcifs/smb/SmbTransport.java | 66 ++++++++++++++++---------------- 9 files changed, 129 insertions(+), 64 deletions(-) create mode 100644 examples/UrlReader.java diff --git a/README.txt b/README.txt index bc841c2..5feae4a 100644 --- a/README.txt +++ b/README.txt @@ -1,3 +1,15 @@ +Thu Feb 10 22:29:12 EST 2005 +jcifs-1.1.8 released + +The blocked thread bug wasn't quite fixed in the last release. A lookup +exception (e.g. caused by an unresponsive domain controller) could leave a +thread blocked if many requests are being processed simultaneously. +Similarly the fix for the DC lookup code wasn't complete enough to handle +the unusual scenario where all DCs are unresponsive. Also, a malfomed +NetBIOS name query response could cause the name service thread to exit +incorrectly. These issues have been fixed. Finally, the URL handling of +smb://@/ (meaning "null" credentials) has been fixed. + Sun Jan 16 17:30:17 EST 2005 jcifs-1.1.7 released diff --git a/build.xml b/build.xml index 8927408..b46def1 100644 --- a/build.xml +++ b/build.xml @@ -1,7 +1,7 @@ - - + + diff --git a/examples/Makefile b/examples/Makefile index e5f1df5..4888a83 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -3,7 +3,7 @@ CLASSPATH=../build:. .SUFFIXES: .java .class -CLASSFILES=AllocInfo.class Append.class AuthListFiles.class CallNamedPipe.class CifsTime.class CopyTo.class CreateFile.class Delete.class Equals.class Exists.class FileInfo.class FileOps.class FilterFiles.class Format.class GetDate.class GetDfsPath.class Get.class GetType.class GetURL.class GrowWrite.class HttpURL.class Interleave.class IsDir.class Length.class ListFiles.class List.class ListTypes.class Mkdir.class NodeStatus.class OpenExclusive.class PeekNamedPipe.class PipeTalk.class Put.class Query.class RenameTo.class SetAttrs.class SetTime.class SlowRead.class SlowWrite.class SmbCrawler.class SmbShell.class SmbTableFile.class SmbTableFileRecord.class T2Crawler.class TestRandomAccess.class TestSmbURL.class TestUnicode.class ThreadedNbtQuery.class ThreadedSmbCrawler.class ThreadedUniQuery.class Torture1.class Torture2.class TortureTest5.class TransactNamedPipe.class URLTest.class VerifyGuest.class VerifyIO.class VerifyReads.class +CLASSFILES=AllocInfo.class Append.class AuthListFiles.class CallNamedPipe.class CopyTo.class CreateFile.class Delete.class Equals.class Exists.class FileInfo.class FileOps.class FilterFiles.class Format.class GetDate.class GetDfsPath.class Get.class GetType.class GetURL.class GrowWrite.class HttpURL.class Interleave.class IsDir.class Length.class ListFiles.class List.class ListTypes.class Mkdir.class NodeStatus.class OpenExclusive.class PeekNamedPipe.class PipeTalk.class Put.class Query.class RenameTo.class SetAttrs.class SetTime.class SlowRead.class SlowWrite.class SmbCrawler.class SmbShell.class SmbTableFile.class SmbTableFileRecord.class T2Crawler.class TestRandomAccess.class TestSmbURL.class TestUnicode.class ThreadedNbtQuery.class ThreadedSmbCrawler.class ThreadedUniQuery.class Torture1.class Torture2.class TortureTest5.class TransactNamedPipe.class URLTest.class VerifyGuest.class VerifyIO.class VerifyReads.class all: ${CLASSFILES} diff --git a/examples/UrlReader.java b/examples/UrlReader.java new file mode 100644 index 0000000..6acb728 --- /dev/null +++ b/examples/UrlReader.java @@ -0,0 +1,41 @@ +import java.net.*; +import java.io.*; + +public class UrlReader extends Thread { + + URL url; + byte[] buf; + + public UrlReader( String u, int bufsiz ) throws Exception { + url = new URL( u ); + buf = new byte[bufsiz]; + } + + public void run() { + try { + InputStream in = url.openStream(); + int n; + while ((n = in.read( buf )) > 0) { + System.out.write( buf, 0, n ); + } + in.close(); + System.err.println( url + " read complete" ); + } catch( Exception ex ) { + ex.printStackTrace( System.err ); + } + } + + public static void main( String[] args ) throws Exception { + UrlReader[] readers = new UrlReader[args.length]; + + jcifs.Config.registerSmbURLHandler(); + + int i; + for( i = 0; i < args.length; i++) { + readers[i] = new UrlReader( args[i], (i + 1) * 128 ); + } + for( i = 0; i < args.length; i++) { + readers[i].start(); + } + } +} diff --git a/examples/runtests.sh b/examples/runtests.sh index e690268..6b9bb98 100644 --- a/examples/runtests.sh +++ b/examples/runtests.sh @@ -5,7 +5,7 @@ CLASSPATH=../build:. PROPERTIES=../../miallen.prp RUN="${JAVA_HOME}/bin/java -cp ${CLASSPATH} -Djcifs.properties=${PROPERTIES}" -SERVER=servername +SERVER=rnyxwbf8s5v31 SHARE=pub WRITE_DIR=test SRC_DIR=test/Junk diff --git a/src/jcifs/netbios/NameServiceClient.java b/src/jcifs/netbios/NameServiceClient.java index f03bd70..dbd2011 100644 --- a/src/jcifs/netbios/NameServiceClient.java +++ b/src/jcifs/netbios/NameServiceClient.java @@ -176,35 +176,37 @@ class NameServiceClient implements Runnable { int nameTrnId; NameServicePacket response; - while( thread == Thread.currentThread() ) { - in.setLength( RCV_BUF_SIZE ); - try { + try { + while( thread == Thread.currentThread() ) { + in.setLength( RCV_BUF_SIZE ); + socket.setSoTimeout( closeTimeout ); socket.receive( in ); - } catch( IOException ioe ) { - tryClose(); - break; - } - if( log.level > 3 ) - log.println( "NetBIOS: new data read from socket" ); + if( log.level > 3 ) + log.println( "NetBIOS: new data read from socket" ); - nameTrnId = NameServicePacket.readNameTrnId( rcv_buf, 0 ); - response = (NameServicePacket)responseTable.get( new Integer( nameTrnId )); - if( response == null || response.received ) { - continue; - } - synchronized( response ) { - response.readWireFormat( rcv_buf, 0 ); - response.received = true; - - if( log.level > 3 ) { - log.println( response ); - Hexdump.hexdump( log, rcv_buf, 0, in.getLength() ); + nameTrnId = NameServicePacket.readNameTrnId( rcv_buf, 0 ); + response = (NameServicePacket)responseTable.get( new Integer( nameTrnId )); + if( response == null || response.received ) { + continue; } + synchronized( response ) { + response.readWireFormat( rcv_buf, 0 ); + response.received = true; - response.notify(); + if( log.level > 3 ) { + log.println( response ); + Hexdump.hexdump( log, rcv_buf, 0, in.getLength() ); + } + + response.notify(); + } } + } catch( Exception ex ) { + if( log.level > 2 ) + ex.printStackTrace( log ); + tryClose(); } } void send( NameServicePacket request, NameServicePacket response, diff --git a/src/jcifs/smb/SmbFile.java b/src/jcifs/smb/SmbFile.java index 2900345..4330e50 100644 --- a/src/jcifs/smb/SmbFile.java +++ b/src/jcifs/smb/SmbFile.java @@ -1622,7 +1622,7 @@ public class SmbFile extends URLConnection { UnknownHostException, MalformedURLException { SmbComTransaction req; SmbComTransactionResponse resp; - int listType = url.getAuthority().length() == 0 ? 0 : getType(); + int listType = url.getHost().length() == 0 ? 0 : getType(); String p = url.getPath(); if( p.lastIndexOf( '/' ) != ( p.length() - 1 )) { diff --git a/src/jcifs/smb/SmbSession.java b/src/jcifs/smb/SmbSession.java index 7e0d3a8..5ef8431 100644 --- a/src/jcifs/smb/SmbSession.java +++ b/src/jcifs/smb/SmbSession.java @@ -116,10 +116,14 @@ synchronized( DOMAIN ) { SmbTransport trans = SmbTransport.getSmbTransport( dc, 0 ); if( USERNAME == null ) { if( SmbTransport.log.level > 2 ) - SmbTransport.log.println( "Default credentials (jcifs.smb.client.username/password) not specified. SMB signing may not work propertly. Skipping DC interrogation." ); + SmbTransport.log.println( + "Default credentials (jcifs.smb.client.username/password)" + + " not specified. SMB signing may not work propertly." + + " Skipping DC interrogation." ); trans.negotiate(); } else { - trans.getSmbSession( NtlmPasswordAuthentication.DEFAULT ).getSmbTree( LOGON_SHARE, null ).treeConnect( null, null ); + trans.getSmbSession( NtlmPasswordAuthentication.DEFAULT ).getSmbTree( + LOGON_SHARE, null ).treeConnect( null, null ); } synchronized( trans ) { if( trans.sessions.size() > (trans.SSN_LIMIT / 10)) { @@ -130,7 +134,8 @@ synchronized( trans ) { return new NtlmChallenge( trans.server.encryptionKey, dc ); } catch( SmbException se ) { if( SmbTransport.log.level > 1 ) - SmbTransport.log.println( "Failed validate DC: " + addr + ": " + se.getMessage() ); + SmbTransport.log.println( "Failed validate DC: " + addr + + ": " + se.getMessage() ); } dc_list[dc_list_index] = null; /* dc no good */ incr_dc_list_range(); @@ -139,7 +144,9 @@ synchronized( trans ) { } while( dc_list_index != starting_index ); } - throw new UnknownHostException( "Failed to negotiate with a suitable domain controller for " + DOMAIN ); + dc_list_expiration = System.currentTimeMillis() + 10000; /* 10sec */ + throw new UnknownHostException( + "Failed to negotiate with a suitable domain controller for " + DOMAIN ); } @@ -288,7 +295,8 @@ synchronized( transport() ) { request.auth = auth; transport.send( request, response ); - if( response.isLoggedInAsGuest && "GUEST".equalsIgnoreCase( auth.username ) == false ) { + if( response.isLoggedInAsGuest && + "GUEST".equalsIgnoreCase( auth.username ) == false) { throw new SmbAuthException( NtStatus.NT_STATUS_LOGON_FAILURE ); } diff --git a/src/jcifs/smb/SmbTransport.java b/src/jcifs/smb/SmbTransport.java index b6035d2..c8b2621 100644 --- a/src/jcifs/smb/SmbTransport.java +++ b/src/jcifs/smb/SmbTransport.java @@ -304,21 +304,15 @@ private static byte[] rcv_buf = new byte[0xFFFF]; } state = ST_GROUND; } - void start() throws SmbException { - try { - thread = new Thread( this, "JCIFS-SmbTransport" ); - thread.setDaemon( true ); - thread.start(); + void start() throws Exception { + thread = new Thread( this, "JCIFS-SmbTransport" ); + thread.setDaemon( true ); + thread.start(); - wait( RESPONSE_TIMEOUT ); /* wait for the thread to be started and socket opened */ + wait( RESPONSE_TIMEOUT ); /* wait for the thread to be started and socket opened */ - if( socket == null ) { /* failed to open socket for some reason */ - tryClose( true ); - throw new SmbException( "Timeout trying to open socket (probably no ACK to SYN) for address", socketException ); - } - } catch( InterruptedException ie ) { - tryClose( true ); - throw new SmbException( "Interrupted opening socket", ie ); + if( socket == null ) { /* failed to open socket for some reason */ + throw new SmbException( "Timeout trying to open socket", socketException ); } } public void run() { @@ -867,22 +861,7 @@ synchronized( snd_buf ) { throw new SmbException( response.errorCode, null ); } } - synchronized void negotiate() throws SmbException { - - if( state == ST_GROUND ) { - state = ST_NEGOTIATING; - } else { - while( state != ST_NEGOTIATED ) { - try { - wait(); - } catch( InterruptedException ie ) { - tryClose( true ); - throw new SmbException( "Interrupted opening socket", ie ); - } - } - return; - } - + synchronized void negotiate0() throws Exception { start(); /* start the transport thread (which opens the socket) */ if( this == NULL_TRANSPORT ) { @@ -900,7 +879,6 @@ synchronized( snd_buf ) { send( new SmbComNegotiate(), response ); if( response.dialectIndex > 10 ) { - tryClose( true ); throw new SmbException( "This client does not support the negotiated dialect." ); } @@ -943,9 +921,33 @@ synchronized( snd_buf ) { flags2 &= 0xFFFF ^ ServerMessageBlock.FLAGS2_UNICODE; } } + } + synchronized void negotiate() throws SmbException { + if( state == ST_GROUND ) { + state = ST_NEGOTIATING; + } else { + while( state != ST_NEGOTIATED ) { + try { + wait(); + } catch( InterruptedException ie ) { + tryClose( true ); + throw new SmbException( "Interrupted opening socket", ie ); + } + } + return; + } - state = ST_NEGOTIATED; - notifyAll(); + try { + negotiate0(); + state = ST_NEGOTIATED; + } catch( Exception ex ) { + if( log.level > 1 ) + ex.printStackTrace( log ); + tryClose( true ); + throw new SmbException( "Failed to negotiate", ex ); + } finally { + notifyAll(); + } } public String toString() { String ret = "SmbTransport[address=" + address; -- 2.11.0