jcifs-0.9.4 from tgz
authorFelix Schumacher <p0354740@isib001.(none)>
Wed, 6 Aug 2008 14:18:19 +0000 (16:18 +0200)
committerFelix Schumacher <p0354740@isib001.(none)>
Wed, 6 Aug 2008 14:18:19 +0000 (16:18 +0200)
Mon Jun 28 13:29:39 EDT 2004
jcifs-0.9.3 released

The  specification  of a port in the SMB URL has been fixed. Full workgroup
and  server  enumeration  was  also  broken.  JCIFS  can  now enumerate ALL
workgroups  and  servers.  The  NtlmHttpURLConnection class for negotiating
NTLM with HTTP clients has been updated to be more robust and support POST.

README.txt
build.xml
examples/web.xml
src/jcifs/http/NtlmHttpURLConnection.java
src/jcifs/smb/Handler.java
src/jcifs/smb/NetServerEnum2.java
src/jcifs/smb/NetShareEnum.java
src/jcifs/smb/SmbFile.java

index 5de5b2b..faeea6e 100644 (file)
@@ -1,3 +1,13 @@
+Mon Jun 28 13:29:39 EDT 2004
+jcifs-0.9.3 released
+
+The  specification  of a port in the SMB URL has been fixed. Full workgroup
+and  server  enumeration  was  also  broken.  JCIFS  can  now enumerate ALL
+workgroups  and  servers.  The  NtlmHttpURLConnection class for negotiating
+NTLM with HTTP clients has been updated to be more robust and support POST.
+
+jcifs-0.9.2 released
+
 Removed the HTTP redirect from the filter.
 
 Tue Jun  1 23:23:08 EDT 2004
index 0d3d126..9732470 100644 (file)
--- a/build.xml
+++ b/build.xml
@@ -1,6 +1,6 @@
 <project name="jcifs" default="usage" basedir=".">
 
-    <property name="version" value="0.9.2"/>
+    <property name="version" value="0.9.4"/>
 
     <target name="usage">
         <echo>
@@ -181,8 +181,8 @@ dependencies: Checks that all class dependencies are met.
     <target name="docs">
         <style basedir="docs" destdir="docs" extension=".html" style="plain.xsl"
                 includes="pipes.xml,faq.xml,wins.xml,capture.xml,httpclient.xml,resolver.xml,authhandler.xml,ntlmhttpauth.xml">
-<param name="date" expression="Jun 8, 2004"/>
-<param name="lib" expression="jcifs-0.9.2"/>
+<param name="date" expression="Jun 30, 2004"/>
+<param name="lib" expression="jcifs-0.9.4"/>
 <param name="title" expression="JCIFS"/>
 <param name="copyright" expression="The JCIFS Project"/>
 <param name="edge" expression="#808080"/>
@@ -195,13 +195,13 @@ dependencies: Checks that all class dependencies are met.
         </style>
         <style basedir="docs" destdir="docs" extension=".html" style="proj.xsl"
                 includes="index.xml">
-<param name="date" expression="Jun 8, 2004"/>
-<param name="lib" expression="jcifs-0.9.2"/>
+<param name="date" expression="Jun 30, 2004"/>
+<param name="lib" expression="jcifs-0.9.4"/>
 <param name="title" expression="JCIFS"/>
 <param name="copyright" expression="The JCIFS Project"/>
 <param name="edge" expression="#808080"/>
 <param name="mainpane" expression="#ffffff"/>
-<param name="leftpane" expression="#FFD700"/>
+<param name="leftpane" expression="#e0e0FF"/>
 <param name="middlepane" expression="#ffffff"/>
 <param name="footer" expression="#808080"/>
 <param name="text1" expression="#000000"/>
index ec3c7f1..a9ed68d 100644 (file)
@@ -6,28 +6,8 @@
     filter-name='ntlm'
     filter-class='jcifs.http.NtlmHttpFilter'>
     <init-param>
-        <param-name>jcifs.http.domainController</param-name>
-        <param-value>172.23.22.27</param-value>
-    </init-param>
-    <init-param>
-        <param-name>jcifs.smb.client.soTimeout</param-name>
-        <param-value>8000</param-value>
-    </init-param>
-    <init-param>
         <param-name>jcifs.smb.client.domain</param-name>
-        <param-value>AMRS</param-value>
-    </init-param>
-    <init-param>
-        <param-name>jcifs.smb.client.username</param-name>
-        <param-value>produser1</param-value>
-    </init-param>
-    <init-param>
-        <param-name>jcifs.smb.client.password</param-name>
-        <param-value>control96</param-value>
-    </init-param>
-    <init-param>
-        <param-name>jcifs.smb.client.signingPreferred</param-name>
-        <param-value>true</param-value>
+        <param-value>MYDOMAIN</param-value>
     </init-param>
 </filter>
 <filter-mapping
     </init-param>
     <init-param>
         <param-name>jcifs.netbios.wins</param-name>
-        <param-value>146.125.87.65,169.242.200.2</param-value>
+        <param-value>164.215.78.56,196.141.101.3</param-value>
     </init-param>
     <init-param>
         <param-name>jcifs.smb.client.domain</param-name>
-        <param-value>AMRS</param-value>
+        <param-value>MYDOMAIN</param-value>
     </init-param>
 </servlet>
 <servlet-mapping
index 83bf518..b4cd9ac 100644 (file)
@@ -19,6 +19,7 @@
 
 package jcifs.http;
 
+import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
 import java.io.IOException;
 import java.io.OutputStream;
@@ -71,9 +72,13 @@ public class NtlmHttpURLConnection extends HttpURLConnection {
 
     private Map headerFields;
 
+    private ByteArrayOutputStream cachedOutput;
+
     private String authProperty;
 
-    private String method;
+    private String authMethod;
+
+    private boolean handshakeComplete;
 
     static {
         String domain = System.getProperty("http.auth.ntlm.domain");
@@ -89,64 +94,70 @@ public class NtlmHttpURLConnection extends HttpURLConnection {
 
     public void connect() throws IOException {
         if (connected) return;
-        doConnect();
+        connection.connect();
         connected = true;
     }
 
+    private void handshake() throws IOException {
+        if (handshakeComplete) return;
+        doHandshake();
+        handshakeComplete = true;
+    }
+
     public URL getURL() {
         return connection.getURL();
     }
 
     public int getContentLength() {
         try {
-            connect();
+            handshake();
         } catch (IOException ex) { }
         return connection.getContentLength();
     }
 
     public String getContentType() {
         try {
-            connect();
+            handshake();
         } catch (IOException ex) { }
         return connection.getContentType();
     }
 
     public String getContentEncoding() {
         try {
-            connect();
+            handshake();
         } catch (IOException ex) { }
         return connection.getContentEncoding();
     }
 
     public long getExpiration() {
         try {
-            connect();
+            handshake();
         } catch (IOException ex) { }
         return connection.getExpiration();
     }
 
     public long getDate() {
         try {
-            connect();
+            handshake();
         } catch (IOException ex) { }
         return connection.getDate();
     }
 
     public long getLastModified() {
         try {
-            connect();
+            handshake();
         } catch (IOException ex) { }
         return connection.getLastModified();
     }
 
     public String getHeaderField(String header) {
         try {
-            connect();
+            handshake();
         } catch (IOException ex) { }
         return connection.getHeaderField(header);
     }
 
-    private synchronized Map getHeaderFields0() {
+    private Map getHeaderFields0() {
         if (headerFields != null) return headerFields;
         Map map = new HashMap();
         String key = connection.getHeaderFieldKey(0);
@@ -171,53 +182,51 @@ public class NtlmHttpURLConnection extends HttpURLConnection {
     }
 
     public Map getHeaderFields() {
-        synchronized (this) {
-            if (headerFields != null) return headerFields;
-        }
+        if (headerFields != null) return headerFields;
         try {
-            connect();
+            handshake();
         } catch (IOException ex) { }
         return getHeaderFields0();
     }
 
     public int getHeaderFieldInt(String header, int def) {
         try {
-            connect();
+            handshake();
         } catch (IOException ex) { }
         return connection.getHeaderFieldInt(header, def);
     }
 
     public long getHeaderFieldDate(String header, long def) {
         try {
-            connect();
+            handshake();
         } catch (IOException ex) { }
         return connection.getHeaderFieldDate(header, def);
     }
 
     public String getHeaderFieldKey(int index) {
         try {
-            connect();
+            handshake();
         } catch (IOException ex) { }
         return connection.getHeaderFieldKey(index);
     }
 
     public String getHeaderField(int index) {
         try {
-            connect();
+            handshake();
         } catch (IOException ex) { }
         return connection.getHeaderField(index);
     }
 
     public Object getContent() throws IOException {
         try {
-            connect();
+            handshake();
         } catch (IOException ex) { }
         return connection.getContent();
     }
 
     public Object getContent(Class[] classes) throws IOException {
         try {
-            connect();
+            handshake();
         } catch (IOException ex) { }
         return connection.getContent(classes);
     }
@@ -228,7 +237,7 @@ public class NtlmHttpURLConnection extends HttpURLConnection {
 
     public InputStream getInputStream() throws IOException {
         try {
-            connect();
+            handshake();
         } catch (IOException ex) { }
         return connection.getInputStream();
     }
@@ -237,7 +246,9 @@ public class NtlmHttpURLConnection extends HttpURLConnection {
         try {
             connect();
         } catch (IOException ex) { }
-        return connection.getOutputStream();
+        OutputStream output = connection.getOutputStream();
+        cachedOutput = new ByteArrayOutputStream();
+        return new CacheStream(output, cachedOutput);
     }
 
     public String toString() {
@@ -302,40 +313,36 @@ public class NtlmHttpURLConnection extends HttpURLConnection {
         List values = new ArrayList();
         values.add(value);
         boolean found = false;
-        synchronized (requestProperties) {
-            Iterator entries = requestProperties.entrySet().iterator();
-            while (entries.hasNext()) {
-                Map.Entry entry = (Map.Entry) entries.next();
-                if (key.equalsIgnoreCase((String) entry.getKey())) {
-                    entry.setValue(value);
-                    found = true;
-                    break;
-                }
+        Iterator entries = requestProperties.entrySet().iterator();
+        while (entries.hasNext()) {
+            Map.Entry entry = (Map.Entry) entries.next();
+            if (key.equalsIgnoreCase((String) entry.getKey())) {
+                entry.setValue(value);
+                found = true;
+                break;
             }
-            if (!found) requestProperties.put(key, values);
         }
+        if (!found) requestProperties.put(key, values);
         connection.setRequestProperty(key, value);
     }
 
     public void addRequestProperty(String key, String value) {
         if (key == null) throw new NullPointerException();
         List values = null;
-        synchronized (requestProperties) {
-            Iterator entries = requestProperties.entrySet().iterator();
-            while (entries.hasNext()) {
-                Map.Entry entry = (Map.Entry) entries.next();
-                if (key.equalsIgnoreCase((String) entry.getKey())) {
-                    values = (List) entry.getValue();
-                    values.add(value);
-                    break;
-                }
-            }
-            if (values == null) {
-                values = new ArrayList();
+        Iterator entries = requestProperties.entrySet().iterator();
+        while (entries.hasNext()) {
+            Map.Entry entry = (Map.Entry) entries.next();
+            if (key.equalsIgnoreCase((String) entry.getKey())) {
+                values = (List) entry.getValue();
                 values.add(value);
-                requestProperties.put(key, values);
+                break;
             }
         }
+        if (values == null) {
+            values = new ArrayList();
+            values.add(value);
+            requestProperties.put(key, values);
+        }
         // 1.3-compatible.
         StringBuffer buffer = new StringBuffer();
         Iterator propertyValues = values.iterator();
@@ -354,13 +361,11 @@ public class NtlmHttpURLConnection extends HttpURLConnection {
 
     public Map getRequestProperties() {
         Map map = new HashMap();
-        synchronized (requestProperties) {
-            Iterator entries = requestProperties.entrySet().iterator();
-            while (entries.hasNext()) {
-                Map.Entry entry = (Map.Entry) entries.next();
-                map.put(entry.getKey(),
-                        Collections.unmodifiableList((List) entry.getValue()));
-            }
+        Iterator entries = requestProperties.entrySet().iterator();
+        while (entries.hasNext()) {
+            Map.Entry entry = (Map.Entry) entries.next();
+            map.put(entry.getKey(),
+                    Collections.unmodifiableList((List) entry.getValue()));
         }
         return Collections.unmodifiableMap(map);
     }
@@ -376,6 +381,7 @@ public class NtlmHttpURLConnection extends HttpURLConnection {
     public void setRequestMethod(String requestMethod)
             throws ProtocolException {
         connection.setRequestMethod(requestMethod);
+        this.method = requestMethod;
     }
 
     public String getRequestMethod() {
@@ -383,15 +389,22 @@ public class NtlmHttpURLConnection extends HttpURLConnection {
     }
 
     public int getResponseCode() throws IOException {
+        try {
+            handshake();
+        } catch (IOException ex) { }
         return connection.getResponseCode();
     }
 
     public String getResponseMessage() throws IOException {
+        try {
+            handshake();
+        } catch (IOException ex) { }
         return connection.getResponseMessage();
     }
 
     public void disconnect() {
         connection.disconnect();
+        handshakeComplete = false;
         connected = false;
     }
 
@@ -400,6 +413,9 @@ public class NtlmHttpURLConnection extends HttpURLConnection {
     }
 
     public InputStream getErrorStream() {
+        try {
+            handshake();
+        } catch (IOException ex) { }
         return connection.getErrorStream();
     }
 
@@ -414,41 +430,57 @@ public class NtlmHttpURLConnection extends HttpURLConnection {
         }
     }
 
-    private synchronized void doConnect() throws IOException {
-        connection.connect();
-        int response = parseResponseCode();
-        if (response != HTTP_UNAUTHORIZED && response != HTTP_PROXY_AUTH) {
-            return;
-        }
-        Type1Message type1 = (Type1Message) attemptNegotiation(response);
-        if (type1 == null) return; // no NTLM
-        int attempt = 0;
-        while (attempt < MAX_REDIRECTS) {
-            connection.setRequestProperty(authProperty, method + ' ' +
-                    Base64.encode(type1.toByteArray()));
-            connection.connect(); // send type 1
-            response = parseResponseCode();
+    private void doHandshake() throws IOException {
+        connect();
+        try {
+            int response = parseResponseCode();
             if (response != HTTP_UNAUTHORIZED && response != HTTP_PROXY_AUTH) {
                 return;
             }
-            Type3Message type3 = (Type3Message) attemptNegotiation(response);
-            if (type3 == null) return;
-            connection.setRequestProperty(authProperty, method + ' ' +
-                    Base64.encode(type3.toByteArray()));
-            connection.connect(); // send type 3
-            response = parseResponseCode();
-            if (response != HTTP_UNAUTHORIZED && response != HTTP_PROXY_AUTH) {
-                return;
+            Type1Message type1 = (Type1Message) attemptNegotiation(response);
+            if (type1 == null) return; // no NTLM
+            int attempt = 0;
+            while (attempt < MAX_REDIRECTS) {
+                connection.setRequestProperty(authProperty, authMethod + ' ' +
+                        Base64.encode(type1.toByteArray()));
+                connection.connect(); // send type 1
+                response = parseResponseCode();
+                if (response != HTTP_UNAUTHORIZED &&
+                        response != HTTP_PROXY_AUTH) {
+                    return;
+                }
+                Type3Message type3 = (Type3Message)
+                        attemptNegotiation(response);
+                if (type3 == null) return;
+                connection.setRequestProperty(authProperty, authMethod + ' ' +
+                        Base64.encode(type3.toByteArray()));
+                connection.connect(); // send type 3
+                if (cachedOutput != null && doOutput) {
+                    OutputStream output = connection.getOutputStream();
+                    cachedOutput.writeTo(output);
+                    output.flush();
+                }
+                response = parseResponseCode();
+                if (response != HTTP_UNAUTHORIZED &&
+                        response != HTTP_PROXY_AUTH) {
+                    return;
+                }
+                attempt++;
+                if (allowUserInteraction && attempt < MAX_REDIRECTS) {
+                    reconnect();
+                } else {
+                    break;
+                }
             }
-            attempt++;
-            if (attempt < MAX_REDIRECTS) reconnect();
+            throw new IOException("Unable to negotiate NTLM authentication.");
+        } finally {
+            cachedOutput = null;
         }
-        throw new IOException("Unable to negotiate NTLM authentication.");
     }
 
     private NtlmMessage attemptNegotiation(int response) throws IOException {
         authProperty = null;
-        method = null;
+        authMethod = null;
         InputStream errorStream = connection.getErrorStream();
         if (errorStream != null && errorStream.available() != 0) {
             int count;
@@ -468,28 +500,28 @@ public class NtlmHttpURLConnection extends HttpURLConnection {
         if (methods == null) return null;
         Iterator iterator = methods.iterator();
         while (iterator.hasNext()) {
-            String authMethod = (String) iterator.next();
-            if (authMethod.startsWith("NTLM")) {
-                if (authMethod.length() == 4) {
-                    method = "NTLM";
+            String currentAuthMethod = (String) iterator.next();
+            if (currentAuthMethod.startsWith("NTLM")) {
+                if (currentAuthMethod.length() == 4) {
+                    authMethod = "NTLM";
                     break;
                 }
-                if (authMethod.indexOf(' ') != 4) continue;
-                method = "NTLM";
-                authorization = authMethod.substring(5).trim();
+                if (currentAuthMethod.indexOf(' ') != 4) continue;
+                authMethod = "NTLM";
+                authorization = currentAuthMethod.substring(5).trim();
                 break;
-            } else if (authMethod.startsWith("Negotiate")) {
-                if (authMethod.length() == 9) {
-                    method = "Negotiate";
+            } else if (currentAuthMethod.startsWith("Negotiate")) {
+                if (currentAuthMethod.length() == 9) {
+                    authMethod = "Negotiate";
                     break;
                 }
-                if (authMethod.indexOf(' ') != 9) continue;
-                method = "Negotiate";
-                authorization = authMethod.substring(10).trim();
+                if (currentAuthMethod.indexOf(' ') != 9) continue;
+                authMethod = "Negotiate";
+                authorization = currentAuthMethod.substring(10).trim();
                 break;
             }
         }
-        if (method == null) return null;
+        if (authMethod == null) return null;
         NtlmMessage message = (authorization != null) ?
                 new Type2Message(Base64.decode(authorization)) : null;
         reconnect();
@@ -514,6 +546,7 @@ public class NtlmHttpURLConnection extends HttpURLConnection {
                 user = (index != -1) ? user.substring(index + 1) : user;
             }
             if (user == null) {
+                if (!allowUserInteraction) return null;
                 try {
                     URL url = getURL();
                     String protocol = url.getProtocol();
@@ -523,11 +556,10 @@ public class NtlmHttpURLConnection extends HttpURLConnection {
                     }
                     PasswordAuthentication auth =
                             Authenticator.requestPasswordAuthentication(null,
-                                    port, protocol, "", method);
-                    if (auth != null) {
-                        user = auth.getUserName();
-                        password = new String(auth.getPassword());
-                    }
+                                    port, protocol, "", authMethod);
+                    if (auth == null) return null;
+                    user = auth.getUserName();
+                    password = new String(auth.getPassword());
                 } catch (Exception ex) { }
             }
             Type2Message type2 = (Type2Message) message;
@@ -539,20 +571,19 @@ public class NtlmHttpURLConnection extends HttpURLConnection {
 
     private void reconnect() throws IOException {
         connection = (HttpURLConnection) connection.getURL().openConnection();
+        connection.setRequestMethod(method);
         headerFields = null;
-        synchronized (requestProperties) {
-            Iterator properties = requestProperties.entrySet().iterator();
-            while (properties.hasNext()) {
-                Map.Entry property = (Map.Entry) properties.next();
-                String key = (String) property.getKey();
-                StringBuffer value = new StringBuffer();
-                Iterator values = ((List) property.getValue()).iterator();
-                while (values.hasNext()) {
-                    value.append(values.next());
-                    if (values.hasNext()) value.append(", ");
-                }
-                connection.setRequestProperty(key, value.toString());
+        Iterator properties = requestProperties.entrySet().iterator();
+        while (properties.hasNext()) {
+            Map.Entry property = (Map.Entry) properties.next();
+            String key = (String) property.getKey();
+            StringBuffer value = new StringBuffer();
+            Iterator values = ((List) property.getValue()).iterator();
+            while (values.hasNext()) {
+                value.append(values.next());
+                if (values.hasNext()) value.append(", ");
             }
+            connection.setRequestProperty(key, value.toString());
         }
         connection.setAllowUserInteraction(allowUserInteraction);
         connection.setDoInput(doInput);
@@ -560,4 +591,43 @@ public class NtlmHttpURLConnection extends HttpURLConnection {
         connection.setIfModifiedSince(ifModifiedSince);
         connection.setUseCaches(useCaches);
     }
+
+    private static class CacheStream extends OutputStream {
+
+        private final OutputStream stream;
+
+        private final OutputStream collector;
+
+        public CacheStream(OutputStream stream, OutputStream collector) {
+            this.stream = stream;
+            this.collector = collector;
+        }
+
+        public void close() throws IOException {
+            stream.close();
+            collector.close();
+        }
+
+        public void flush() throws IOException {
+            stream.flush();
+            collector.flush();
+        }
+
+        public void write(byte[] b) throws IOException {
+            stream.write(b);
+            collector.write(b);
+        }
+
+        public void write(byte[] b, int off, int len) throws IOException {
+            stream.write(b, off, len);
+            collector.write(b, off, len);
+        }
+
+        public void write(int b) throws IOException {
+            stream.write(b);
+            collector.write(b);
+        }
+
+    }
+
 }
index 116f964..bf7167c 100644 (file)
@@ -76,6 +76,8 @@ public class Handler extends URLStreamHandler {
     protected void parseURL( URL u, String spec, int start, int limit ) {
         String host = u.getHost();
         String userinfo, path, ref;
+        int port;
+
         if( spec.equals( "smb://" )) {
             spec = "smb:////";
             limit += 2;
@@ -95,7 +97,11 @@ public class Handler extends URLStreamHandler {
         if (ref != null) {
             path += '#' + ref;
         }
-        setURL( u, "smb://", u.getHost(), getDefaultPort(),
+        port = u.getPort();
+        if( port == -1 ) {
+            port = getDefaultPort();
+        }
+        setURL( u, "smb://", u.getHost(), port,
                     u.getAuthority(), userinfo,
                     path, u.getQuery(), null );
     }
index 8c553ed..c2627da 100644 (file)
@@ -42,7 +42,7 @@ class NetServerEnum2 extends SmbComTransaction {
         name = "\\PIPE\\LANMAN";
 
         maxParameterCount = 8;
-        maxDataCount = 4096;
+//        maxDataCount = 4096; why was this here?
         maxSetupCount = (byte)0x00;
         setupCount = 0;
         timeout = 5000;
index 685fb9f..16b423f 100644 (file)
@@ -30,7 +30,7 @@ class NetShareEnum extends SmbComTransaction {
         name = new String( "\\PIPE\\LANMAN" );
         maxParameterCount = 8;
 
-        maxDataCount = 4096;
+//        maxDataCount = 4096; why was this set?
         maxSetupCount = (byte)0x00;
         setupCount = 0;
         timeout = 5000;
index 7a37317..2c7ba61 100644 (file)
@@ -585,6 +585,11 @@ public class SmbFile extends URLConnection {
             new URL( null, "smb://" + name + "/", Handler.SMB_HANDLER ) :
             new URL( context.url, name + (( attributes & ATTR_DIRECTORY ) > 0 ? "/" : "" )));
 
+
+        /* why was this removed before? DFS? copyTo? Am I going around in circles? */
+        auth = context.auth;
+
+
         if( context.share != null ) {
             this.tree = context.tree;
         }
@@ -678,7 +683,7 @@ public class SmbFile extends URLConnection {
                         throw new SmbException( dr.server, uhe );
                     }
 
-                    trans = SmbTransport.getSmbTransport( addr, 0 );
+                    trans = SmbTransport.getSmbTransport( addr, url.getPort() );
                     tree = trans.getSmbSession( auth ).getSmbTree( dr.share, null );
                     unc = request.path = dr.nodepath + unc.substring( dr.path.length() );
                     dfsReferral = dr; /* for getDfsPath */
@@ -1590,15 +1595,21 @@ public class SmbFile extends URLConnection {
                 throw new SmbException( "The requested list operations is invalid: " + url.toString() );
         }
 
+            boolean more;
         do {
+            int n;
+
             sendTransaction( req, resp );
-    
+
+            more = resp.status == SmbException.ERROR_MORE_DATA;
+
             if( resp.status != SmbException.ERROR_SUCCESS &&
                     resp.status != SmbException.ERROR_MORE_DATA ) {
                 throw new SmbException( resp.status, true );
             }
-    
-            for( int i = 0; i < resp.numEntries; i++ ) {
+
+            n = more ? resp.numEntries - 1 : resp.numEntries;
+            for( int i = 0; i < n; i++ ) {
                 FileEntry e = resp.results[i];
                 String name = e.getName();
                 if( fnf != null && fnf.accept( this, name ) == false ) {
@@ -1618,12 +1629,12 @@ public class SmbFile extends URLConnection {
                     }
                 }
             }
-            if( listType != 0 || listType != TYPE_WORKGROUP ) {
+            if( listType != 0 && listType != TYPE_WORKGROUP ) {
                 break;
             }
             req.subCommand = (byte)SmbComTransaction.NET_SERVER_ENUM3;
             req.reset( 0, ((NetServerEnum2Response)resp).lastName );
-        } while( resp.status == SmbException.ERROR_MORE_DATA );
+        } while( more );
     }
     void doFindFirstNext( ArrayList list,
                 boolean files,
@@ -2150,7 +2161,7 @@ public class SmbFile extends URLConnection {
         SmbFile parent;
 
         try {
-            parent = new SmbFile( new URL( null, getParent(), Handler.SMB_HANDLER ));
+            parent = new SmbFile( getParent(), auth );
         } catch( IOException ioe ) {
             return;
         }