From 460be9cfd1ff9e6ea2555e83d05003ed78737b92 Mon Sep 17 00:00:00 2001 From: Felix Schumacher Date: Wed, 6 Aug 2008 16:02:07 +0200 Subject: [PATCH] jcifs-0.6b from tgz Fri Nov 16 04:07:05 EST 2001 jcifs-0.6b released This is the first beta of 0.6. --- README.txt | 62 ++++++++++++++++++++++++++++++++----- build.xml | 16 +++++----- examples/Append.java | 39 ----------------------- examples/Dns.java | 10 ------ examples/List.java | 1 - examples/ProcTest.java | 17 ---------- examples/README.txt | 2 ++ src/jcifs/UniAddress.java | 42 +++++++++++++++++++------ src/jcifs/smb/BufferCache.java | 18 +++++++++++ src/jcifs/smb/SmbAuthException.java | 18 +++++++++++ src/jcifs/smb/SmbException.java | 6 ++++ src/jcifs/smb/SmbTransport.java | 8 +++-- src/jcifs/smb/SmbURL.java | 4 ++- src/jcifs/util/AuthHandler.java | 18 +++++++++++ src/jcifs/util/AuthInfo.java | 18 +++++++++++ 15 files changed, 184 insertions(+), 95 deletions(-) delete mode 100644 examples/Append.java delete mode 100644 examples/Dns.java delete mode 100644 examples/ProcTest.java create mode 100644 examples/README.txt diff --git a/README.txt b/README.txt index 21ea297..f26743d 100644 --- a/README.txt +++ b/README.txt @@ -1,6 +1,25 @@ -There have been significant changes under the hood. The primitives such as packet encoding/decoding and transport have proven very sturdy however the top level glue and logic driving the client really needed an overhaul in hindsight. The client is much smarter now whereas previously jCIFS was quite chatty and used some messages abusively (NodeStatusRequest). Some other cleanups that took into account allocation of buffers and large numbers of objects have resulted in measureable performance improvements. All of this should be transparent to the user however my confidence in the stabilty of 0.5.1 no longer applies. It will take some time to confirm everything works as advertised. I am confident however that any bugs will only require minor adjustments to fix. Of course the name resolution bug that triggered this crusade has been fixed. +Fri Nov 16 04:07:05 EST 2001 -There are some API changes. Most methods of SmbFile throw the now public SmbException. Natrually, this will require changes to existing code. For example, if your code was: +jcifs-0.6b released + +This is the first beta of 0.6. + +There have been significant changes under the hood. The primitives such +as packet encoding/decoding and transport have proven very sturdy however +the top level glue and logic driving the client really needed an overhaul +in hindsight. The client is much smarter now whereas previously jCIFS was +quite chatty and used some messages abusively (NodeStatusRequest). Some +other cleanups that took into account allocation of buffers and +large numbers of objects have resulted in measureable performance +improvements. All of this should be transparent to the user however my +confidence in the stabilty of 0.5.1 no longer applies. It will take some +time to confirm everything works as advertised. I am confident however +that any bugs will only require minor adjustments to fix. Of course the +name resolution bug that triggered this crusade has been fixed. + +There are some API changes. Most methods of SmbFile throw the now public +SmbException. Natrually, this will require changes to existing code. For +example, if your code was: if( r.delete() ) { System.out.println( "delete successfull" ); @@ -24,19 +43,41 @@ The device is not ready All pipe instances are busy ... -not all of which have text messages (and which ones do have messages are in only English at the moment). You can test and make dicisions based on the errorClass and errorCode of an SmbException. All SmbExceptions are thrown through these methods unless an object implementing the AuthHandler interface has been called with the static SmbFile.setAuthHanler method. If an AuthHandler has been specified the following authentication related SmbExceptions: +not all of which have text messages (and which ones do have messages are +in only English at the moment). You can test and make dicisions based on +the errorClass and errorCode of an SmbException. All SmbExceptions are +thrown through these methods unless an object implementing the AuthHandler +interface has been called with the static SmbFile.setAuthHanler method. If +an AuthHandler has been specified the following authentication related +SmbExceptions: Access denied Bad password -The client does not have the necessary access rights for the requested function +The client does not have the necessary access rights for the + requested function The user account has expired The user is not allowed to access this server from this client The user is not permitted to access the server at this time The password of the user has expired -will not be thrown by SmbFile methods but rather passed in the AuthInfo object to the AuthHandler's authenticate() method along with the username, password, domain, and target URL if one of these SmbExceptions occurs. See http://lists.samba.org/pipermail/jcifs/2001-October/001553.html for a related discussion. I believe this is a powerfull feature in itself. This provides for sophisticated error handling and consistent error messages (the messages are the same as those reported by Windows clients). There is also an oppurunity to introduce a ResourceBundle of text messages here. I beleive it will work quite well and in practice I do not believe code will be cluttered with try/catch. - -The NbtAddress class was designed to handle NetBIOS name queries similarly to the common InetAddress class. Unfortunately a lapse in judgment integrated DNS queries into this class in jcifs-0.5 (thus the name service bug). The solution is to remove this DNS code and provide a wrapper class that handles both DNS queries as well as NetBIOS queries mainly delegating the work to InetAddress and NbtAddress. This class is UniAddress. Here is how each of these classes should be used: +will not be thrown by SmbFile methods but rather passed in the AuthInfo +object to the AuthHandler's authenticate() method along with the username, +password, domain, and target URL if one of these SmbExceptions occurs. See +http://lists.samba.org/pipermail/jcifs/2001-October/001553.html for a +related discussion. I believe this is a powerfull feature in itself. This +provides for sophisticated error handling and consistent error messages +(the messages are the same as those reported by Windows clients). There +is also an oppurunity to introduce a ResourceBundle of text messages +here. I beleive it will work quite well and in practice I do not believe +code will be cluttered with try/catch. + +The NbtAddress class was designed to handle NetBIOS name queries +similarly to the common InetAddress class. Unfortunately a lapse in +judgment integrated DNS queries into this class in jcifs-0.5 (thus the +name service bug). The solution is to remove this DNS code and provide +a wrapper class that handles both DNS queries as well as NetBIOS queries +mainly delegating the work to InetAddress and NbtAddress. This class is +UniAddress. Here is how each of these classes should be used: o InetAddress - Lookup a DNS name o NbtAddress - Lookup a NetBIOS name or perform NetBIOS specific @@ -49,6 +90,13 @@ So generally the UniAddress class should be used if you wish to interface with name services directly (normally not necessary when working with the jcifs.smb package). +In summary the classes that have been added or made public are: + +jcifs.UniAddress +jcifs.util.AuthHandler +jcifs.util.AuthInfo +jcifs.smb.SmbException + Mon Aug 27 00:29:02 EDT 2001 jcifs-0.5.1 diff --git a/build.xml b/build.xml index 8561843..17c6fcc 100644 --- a/build.xml +++ b/build.xml @@ -43,24 +43,24 @@ - + - + - - - + + + - + - + @@ -75,7 +75,7 @@ version="true" use="true" windowtitle="jcifs API"> - + diff --git a/examples/Append.java b/examples/Append.java deleted file mode 100644 index a685320..0000000 --- a/examples/Append.java +++ /dev/null @@ -1,39 +0,0 @@ -/* examples for the jcifs smb client library in Java - * Copyright (C) 2001 "Michael B. Allen" - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -import jcifs.smb.SmbFile; -import jcifs.smb.SmbFileOutputStream; - -public class Append { - - public static void main( String argv[] ) throws Exception { - - SmbFile f = new SmbFile( argv[0] ); - SmbFileOutputStream out = new SmbFileOutputStream( f, true ); - - byte[] msg; - int i = 0; - while( i++ < 10 ) { - msg = new String( "this is msg #" + i ).getBytes(); - out.write( msg ); - Thread.sleep( 17000 ); - } - - out.close(); - } -} diff --git a/examples/Dns.java b/examples/Dns.java deleted file mode 100644 index 2a5209f..0000000 --- a/examples/Dns.java +++ /dev/null @@ -1,10 +0,0 @@ -import jcifs.netbios.NbtAddress; -import java.net.*; - -public class Dns { - - public static void main( String argv[] ) throws Exception { - DatagramSocket s = new DatagramSocket( 0, InetAddress.getByName( "255.255.255.255" )); - } -} - diff --git a/examples/List.java b/examples/List.java index fe4ab54..56c15a1 100644 --- a/examples/List.java +++ b/examples/List.java @@ -27,7 +27,6 @@ public class List { SmbFile file = new SmbFile( argv[0] ); - file.list(); long t1 = System.currentTimeMillis(); String[] files = file.list(); long t2 = System.currentTimeMillis() - t1; diff --git a/examples/ProcTest.java b/examples/ProcTest.java deleted file mode 100644 index a8b9758..0000000 --- a/examples/ProcTest.java +++ /dev/null @@ -1,17 +0,0 @@ -import java.io.*; - -public class ProcTest { - - public static void main( String[] argv ) throws Exception { - BufferedReader br = new BufferedReader( new InputStreamReader( System.in )); - String pid = br.readLine(); - - FileInputStream fis = new FileInputStream( "/proc/" + pid + "/status" ); - - int ch; - while(( ch = fis.read() ) != -1 ) { - System.out.print( (char)ch ); - } - System.out.println( "done" ); - } -} diff --git a/examples/README.txt b/examples/README.txt new file mode 100644 index 0000000..fc40721 --- /dev/null +++ b/examples/README.txt @@ -0,0 +1,2 @@ +Many of these examples are quite wrong now that SmbFile methods throw +SmbException. They will be cleaned up before 0.6 final. diff --git a/src/jcifs/UniAddress.java b/src/jcifs/UniAddress.java index 81e8873..4eae90f 100644 --- a/src/jcifs/UniAddress.java +++ b/src/jcifs/UniAddress.java @@ -1,3 +1,21 @@ +/* jcifs smb client library in Java + * Copyright (C) 2000 "Michael B. Allen" + * + * 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; import java.net.InetAddress; @@ -118,30 +136,30 @@ public class UniAddress { static NbtAddress lookupServerOrWorkgroup( String name, InetAddress svr ) throws UnknownHostException { Object lock = new Object(); - QueryThread q1d = new QueryThread( lock, name, 0x1d, null, svr ); + int type = svr == nbns ? 0x1b : 0x1d; + QueryThread q1x = new QueryThread( lock, name, type, null, svr ); QueryThread q20 = new QueryThread( lock, name, 0x20, null, svr ); - q1d.setDaemon( true ); + q1x.setDaemon( true ); q20.setDaemon( true ); try { synchronized( lock ) { - q1d.start(); + q1x.start(); q20.start(); int i = 2; - while( i-- > 0 && q1d.ans == null && q20.ans == null ) { + while( i-- > 0 && q1x.ans == null && q20.ans == null ) { lock.wait(); } } } catch( InterruptedException ie ) { throw new UnknownHostException( name ); } - if( q1d.ans != null ) { -// why was this: return NbtAddress.getByName( q1d.ans.getHostAddress(), 0x1d, null ); - return q1d.ans; + if( q1x.ans != null ) { + return q1x.ans; } else if( q20.ans != null ) { return q20.ans; } else { - throw q1d.uhe; + throw q1x.uhe; } } public static UniAddress getByName( String hostname ) @@ -162,7 +180,7 @@ public class UniAddress { // probably an IP address return true; } - if( data[i] == '.' ) { + if( i < len && data[i] == '.' ) { dots++; i++; } @@ -200,7 +218,11 @@ public class UniAddress { // invalid netbios name continue; } - addr = NbtAddress.getByName( hostname, 0x20, null, nbns ); + if( possibleNTDomainOrWorkgroup ) { + addr = lookupServerOrWorkgroup( hostname, nbns ); + } else { + addr = NbtAddress.getByName( hostname, 0x20, null, nbns ); + } break; case RESOLVER_BCAST: if( hostname.length() > 15 ) { diff --git a/src/jcifs/smb/BufferCache.java b/src/jcifs/smb/BufferCache.java index f07f331..38c1246 100644 --- a/src/jcifs/smb/BufferCache.java +++ b/src/jcifs/smb/BufferCache.java @@ -1,3 +1,21 @@ +/* jcifs smb client library in Java + * Copyright (C) 2000 "Michael B. Allen" + * + * 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.Config; diff --git a/src/jcifs/smb/SmbAuthException.java b/src/jcifs/smb/SmbAuthException.java index 0419498..4d6e9d8 100644 --- a/src/jcifs/smb/SmbAuthException.java +++ b/src/jcifs/smb/SmbAuthException.java @@ -1,3 +1,21 @@ +/* jcifs smb client library in Java + * Copyright (C) 2000 "Michael B. Allen" + * + * 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; public class SmbAuthException extends SmbException { diff --git a/src/jcifs/smb/SmbException.java b/src/jcifs/smb/SmbException.java index 6b73a99..54b6c6c 100644 --- a/src/jcifs/smb/SmbException.java +++ b/src/jcifs/smb/SmbException.java @@ -19,6 +19,7 @@ package jcifs.smb; import java.io.IOException; +import jcifs.UniAddress; /** * Don't get to attached to these constants, we'll be switching to NT @@ -324,6 +325,11 @@ public class SmbException extends IOException { this.errorClass = errorClass; this.errorCode = errorCode; } + SmbException( int errorClass, int errorCode, UniAddress addr ) { + super( getErrorString( errorClass, errorCode ) + " " + addr.toString() ); + this.errorClass = errorClass; + this.errorCode = errorCode; + } SmbException( int errorClass, int errorCode, String message ) { super( message ); this.errorClass = errorClass; diff --git a/src/jcifs/smb/SmbTransport.java b/src/jcifs/smb/SmbTransport.java index ed1d903..641a5aa 100644 --- a/src/jcifs/smb/SmbTransport.java +++ b/src/jcifs/smb/SmbTransport.java @@ -460,7 +460,9 @@ class SmbTransport implements Runnable { } if( response.received == false ) { - throw new SmbException( SmbException.ERRserverTimeout ); + throw new SmbException( SmbException.ERRCLI, + SmbException.ERRserverTimeout, + address ); } switch( response.errorCode & 0xFF ) { case SmbException.SUCCESS: @@ -569,6 +571,7 @@ class SmbTransport implements Runnable { do { // default it 1 so that 0 can be used as forever + response.received = false; response.wait( response.responseTimeout == 1 ? responseTimeout : response.responseTimeout ); } while( response.received && response.hasMoreElements() ); } @@ -584,7 +587,8 @@ class SmbTransport implements Runnable { if( response.received == false ) { throw new SmbException( SmbException.ERRCLI, - SmbException.ERRserverTimeout ); + SmbException.ERRserverTimeout, + address ); } switch( response.errorCode & 0xFF ) { case SmbException.SUCCESS: diff --git a/src/jcifs/smb/SmbURL.java b/src/jcifs/smb/SmbURL.java index 04d0787..cefb30a 100644 --- a/src/jcifs/smb/SmbURL.java +++ b/src/jcifs/smb/SmbURL.java @@ -68,9 +68,11 @@ final class SmbURL { beg++; } if( beg == end && Character.isDigit( url.charAt( start + 2 )) == false ) { + int type; // Could be a workgroup. Need to query the network to find out. file.address = UniAddress.getByName( url.substring( 6, end ), true ); - if( ((NbtAddress)file.address.getAddress()).getNameType() == 0x1d ) { + type = ((NbtAddress)file.address.getAddress()).getNameType(); + if( type == 0x1d || type == 0x1b ) { if( name != null ) { url = "smb://" + name; name = null; diff --git a/src/jcifs/util/AuthHandler.java b/src/jcifs/util/AuthHandler.java index 3e72557..6ef6ef5 100644 --- a/src/jcifs/util/AuthHandler.java +++ b/src/jcifs/util/AuthHandler.java @@ -1,3 +1,21 @@ +/* jcifs smb client library in Java + * Copyright (C) 2000 "Michael B. Allen" + * + * 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.util; public interface AuthHandler { diff --git a/src/jcifs/util/AuthInfo.java b/src/jcifs/util/AuthInfo.java index c2e9f8b..a8989e1 100644 --- a/src/jcifs/util/AuthInfo.java +++ b/src/jcifs/util/AuthInfo.java @@ -1,3 +1,21 @@ +/* jcifs smb client library in Java + * Copyright (C) 2000 "Michael B. Allen" + * + * 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.util; public class AuthInfo { -- 2.11.0