--- /dev/null
+Wed Feb 12 01:23:02 EST 2003
+
+From the beginning jCIFS identified SmbSessions uniquely by
+domain\username. This meant that once a session was established it could be
+shared by another requestor even if they supplied an incorrect password.
+This was done for reasons that strangely enough had to do with SMB
+chaining. However with the introduction of the http package it is now
+common to use jCIFS to authenticate web clients from a central jCIFS
+instance. This introduces a security flaw because there would be a brief
+window of opportunity after a user logs in during which an impostor could
+log in as that user with a simple change to their MSIE security settings.
+This problem has been fixed. Another related issue has also been fixed. If
+the NtlmHttpFilter or NetworkExplorer servlet is supplied with bad
+credentials the behavior was to throw an SmbAuthException up through the
+container. Instead these classes will respond with the standard
+Authentication: NTLM response triggering the password dialog to be
+displayed until correct credentials are displayed.
+
+
+Wed Feb 5 00:41:32 EST 2003
+
+There was a bug introduced in jcifs-0.7.0 when the default
+jcifs.smb.client.snd_buf_size was changed to 5000 from 1300. Writes of size
+1501 to 1504 will trigger an ArrayIndexOutOfBounds exception. Two feature
+enhancements have also been added. SmbFileOutputStream will now support
+file offsets larger than 4GB. Second, the FILE_NO_SHARE, FILE_SHARE_READ,
+FILE_SHARE_WRITE, and FILE_SHARE_DELETE constants have been exposed in
+SmbFile. They may be used to construct a shareAccess parameter for use with
+SmbFileOutputStream and SmbFile to control whether or not other processes
+(or other jCIFS threads) can read, write, and/or delete the file while
+jCIFS has it open. The default is (FILE_SHARE_READ | FILE_SHARE_WRITE |
+FILE_SHARE_DELETE) which will permit other processes to have full access.
+See examples/OpenExclusive and the SmbFileOutputStream API documentation.
+
+Wed Jan 15 22:34:14 EST 2003
+
+jcifs-0.7.1 released
+
+Previously the '#' character was being interpreted by the URL parser as the
+delimeter to the '#ref' component of a URL. This character will no longer
+be treated as a delimeter permitting files with '#'s to be addressed with
+SMB URLs. The getContentLength(), getDate(), getLastModified(), and
+getInputStream() method were dropped when converting SmbFile to extend
+URLConnection. They have been restored. Files returned by listFile() were
+initialized in a state such that isExists() would return false (at least
+until the attrExpirationPeriod expired). This has been corrected.
+
+Wed Jan 8 23:46:47 EST 2003
+
+jcifs-0.7.0 released
+
+The default jcifs.smb.client.snd_buf_size has been changed from 1300 to
+5000 and a bug regarding the resolveOrder mechanism was fixed.
+
+Mon Dec 30 20:18:54 EST 2002
+
+jcifs-0.7.0b12 released
+
+A static Handler instance is now passed to URL constructors internally to
+avoid provoking the deficient jcifs.protocol.pkgs Handler detection that is
+causing the "unknown protocol: smb" exception with some application
+servers. URL decoding has been enabled. Previously there was no clean way
+to represent an '@' in a password in an SMB URL. Any character in the user
+info component of the URL can be protected with a hex code escape like
+'%40' for '@'. The calling name in the NetBIOS session establishment
+message was incorrectly type 0x20. This has been changed to 0x00. A bug has
+been fixed regarding the use of plain text passwords with Unicode (obscure
+combination). A patch to the NTLM HTTP Filter has been applied to work
+around a Weblogic 6.1 requrement.
+
+Fri Dec 20 15:59:50 EST 2002
+
+jcifs-0.7.0b11 released
+
+A debugging statement was left uncommented in jcifs/UniAddress:173. When
+listing 'smb://' or 'smb://workgroup/' URLs the following would be printed
+to System.out:
+
+ sem.count=2,q1x.ans=null,q20.ans=null
+
+Fri Dec 13 00:31:01 EST 2002
+
+jcifs-0.7.0b10 released
+
+Please read the FAQ. The first and last questions are new. Some minor
+changes have been made to jcifs.Config try and assist with the "unknown
+protocol: smb" exceptions. Major kudos to Eric Glass for his help with
+decipering the exact source of those errors. Hopefully users will read the
+FAQ before posting this question over and over. An obscure deadlock could
+be provoked by yanking the link while doing IO on a server. Thanks to
+Matthew Tippett for reporting that. In the course of fixing it I also
+re-fixed the name service deadlock discovered in 0.7.0b7 :~) Somehow that
+change was lost and I think I knew it at the time but could remember what
+the complete fix was. I'll have to release a 0.6.8 too because it's got it
+too. It can easily be provoked by using examples/ThreadedSmbCrawler with
+"smb://" and 10 threads on a big WAN. The jcifs.encoding property was not
+being read correctly.
+
+Fri Nov 22 00:41:33 EST 2002
+
+jcifs-0.7.0b9 released
+
+Java 1.3 is required. I thought the java.net.URL.set() variant that we
+require was from 1.2 but not so. Oops. No turning back now. The 0.6.7
+client is pretty mature minus the 3 URL bugs. Use that with Java 1.1 and
+up.
+
+Thanks to Chad for finding that calling getType() on a share returned in a
+list from listFiles() was returning TYPE_FILESYSTEM. This has been fixed.
+
+And thanks to Uwe for finding that calling close() on NamedPipe input and
+output streams had no effect. I believe this has been fixed but I have
+limited testing capability.
+
+The NtlmAuthenticator has been reinplemented. Just call
+NtlmAuthenticator.setDefault( this ) where this extends the abstact
+NtlmAuthenticator class and implements the getNtlmPasswordAuthentication
+method (like java.net.Authenticator) and your NtlmAuthenticator will be
+called apon to return alternate credentials.
+
+The SmbShell example has been repaired completely and extends
+NtlmAuthenticator which means when you cd around the WAN and hit a share
+you're creds can't get through it will ask you:
+
+ $ java -Djcifs.properties=../miallen.prp SmbShell smb://storage15/docs/
+ docs/> cd smb://admin1-n/admin$/
+ Access denied for smb://admin1-n/admin$/
+ username: mydom\miallen
+ password: fretos
+ admin$/>
+
+Wed Nov 13 00:35:13 EST 2002
+
+jcifs-0.7.0b8 released
+
+I forgot to mention that as of jcifs-0.7.0b4 jcifs now requires Java 2.
+Recently there was confusion over this so we have added a check for Java 2
+in the static initializer of jcifs.Config. If the version string
+startsWith( "1.1." ) an error message will be printed to System.err. The
+getUncPath method was not including the share name. The ANY_HOSTS_NAME
+member of NbtAddress was incorrectly using spaces rather than '\0' nulls.
+Suprisingly this only affected nbtstat of Win98. A null pointer exception
+was being generated by UniAddress. I was decrementing the semaphore too
+agressively.
+
+I have not restored the Authenticator functionality. It requires a hook in
+SmbTransport so I will wait for a little more stability (next release).
+
+Mon Nov 4 02:11:05 EST 2002
+
+jcifs-0.7.0b7 released
+
+A deadlock was found and properly fixed in the name service code (stable
+series is also affected; update to 0.6.7). Some URL handling was still not
+quite right after the big java.net.URL conversion. Creating an SmbFile with
+smb://workgroup/ + server/share/path/ would create
+smb://workgroup/server/share/path/ which is illegal. This has been fixed
+and will now correctly create smb://server/share/path/.
+
+Sun Oct 27 18:37:34 EST 2002
+
+jcifs-0.7.0b6 released
+
+o Very pervasive character encoding changes have been made so that an
+ encoding (see new jcifs.encoding property) can be changed. This should,
+ for example, enable the client to operate in the EBCDIC OS/390
+ environment.
+
+o The client is supposed to connect to IPC$ using anonymous credentials
+ (sometimes referred to as "null" credentials") if the supplied
+ credentials fail. The was broken in the 0.7 series however it has now
+ been repaired.
+
+o A concurrency issue in copyTo was identified an fixed. This was most
+ reproducible when issuing many simple requests (SMB_COM_CREATE_DIRECTORY,
+ SMB_COM_DELETE_DIRECTORY) in rapid succession (like when copying deep
+ trees) and could result in "Access Denied" SmbAuthExceptions.
+
+o Minor jcifs.http package cleanups
+
+Tue Oct 22 03:01:13 EDT 2002
+
+jcifs-0.7.0b5 released
+
+Some issues with the NTLM HTTP Authentication Filter have been repaired. An
+abstract NtlmServlet has been added to the jcifs.http package for pre-2.3
+servlet containers to use. The NTLM HTTP Authentication documentation has
+been updated. The API documentation has been slightly updated.
+
+Wed Oct 16 23:10:20 EDT 2002
+
+jcifs-0.7.0b4 released
+
+ ! -= I M P O R T A N T =- !
+
+URLs for directories now require a trailing '/'. This will break
+existing code. To assit you the getName() method will return a name
+with a trailing '/' if the SmbFile is a directory. Take care because
+these illegal URLs will in some cases work. But if you try to list the
+contents of a directory for example you will get an Exception:
+
+jcifs.smb.SmbException: smb://server/share/dir directory must end with '/'
+ at jcifs.smb.SmbFile.listFiles(SmbFile.java:1191)
+ at jcifs.smb.SmbFile.listFiles(SmbFile.java:1157)
+ ...
+
+There are three additional changes (at least) regarding SMB URLs:
+
+ 1) Canonicalization does not exceed the host component. For example:
+
+ smb://host/share/foo/ + ../.././../../foo/ --> smb://host/foo/
+
+ whereas perviously you would get smb://foo/.
+
+ 2) For constructors that accept a second parameter, that parameter
+ can no longer be null.
+
+ 3) Composing a URL with smb://workgroup/ and server/ used to be smart
+ enough to reduce the URL to just smb://server/. This is no longer
+ true. Doing this will yield smb://workgroup/server/ which is illegal.
+
+The trailing '/' requirement is because the java.net.URL class is now
+used internally for all URL handling and it (and the RFCs) requires it. I
+have updated the obvious places in the API documentation but there are
+undoubtedly lingering examples and documentation that need to be updated.
+
+The reason we have converted to the java.net.URL class for URL
+handling internally is because a) the few remaining bugs were
+pervasive SMB URL bugs and b) the existing java.net.URL Handler was
+serverly flawed. Committing whole-heartedly to java.net.URL solved both
+problems. Quite well too actually. The whole thing is quite a bit more
+elegant. SmbFile now extends URLConnection.
+
+The jcifs.http.NtlmHttpFilter and jcifs.http.NetworkExplorer classes
+should work quite well at this point. The Filter is now stateless so it
+should net generate NullPointerExceptions like some Tomcat users were
+experiencing. The NetworkExplorer servlet will now use the negotiated
+credentials to access SMB resources. You cannot use the NetworkExporer
+servlet and NtlmHttpFilter at the same time (meaning the Filter cannot
+be used to protect the servlet).
+
+NtlmAuthenticator has been zapped for the time being. It will be repaired
+in another beta.
+
+Sun Aug 25 05:19:00 EDT 2002
+
+jcifs-0.7.0b3 released
+
+Network Explorer was hoplessly broken. Countless bugs were fixed
+(including removing a hardcoded BASEREF of my workstation, oops!). In
+fact I factored out the BASEREF entirely. Link HREFs are much simpler
+as a result. The style sheet has been extracted from the source and
+loaded from jcifs/http/ne.css in the jar as a resource like the mime.map
+which means it can easily be edited to taste. Default mime type is now
+text/html unless there's an extension that's not in jcifs/util/mime.map
+in which case it's application/octet-stream but you can always easily
+add extensions to the map.
+
+I have improved the NTLM HTTP Authentication/Network Explorer
+documentation significantly (Thanks to Jason for the important
+links). This should really be just a drop'n-go process now for most users.
+
+I stumbled on a potentially serious but in the inners of SMB transport;
+Uniaddress' were not matching resulting in reduntant SmbTransport
+objects. Not sure if that ever impacted users though.
+
+Graceful-reconnect was fixed after being broken with the introduction
+of NtlmPasswordAuthentication. Had to reorganize some credential
+handling. The matching routine uses logical comparison of
+NtlmPasswordAuthentication objects rather than comparing hashes.
+That made fixing graceful-reconnect as easy as just setting the
+NtlmPasswordAuthentication hashes to null so that they would be
+recalculated with the new challange.
+
+mkdirs() has been implemented.
+
+Implemented setting LastModified time in SMB_COM_CLOSE for copyTo (it
+will preserve modified time) but sadly it does not work with NT. Only
+Samba and Win98 identified to work so far.
+
+Implemented Named Pipes available(). Natrually this only applies to file
+IO style named pipes. Hasn't seen thourough testing however.
+
+Wed Aug 21 04:35:05 EDT 2002
+
+jcifs-0.7.0b2 released
+
+Thanks to instructions from skeetz, the NTLM HTTP Authentication interface
+has been greatly simplified. It is now only necessary to drop in the jar
+and add a filter-mapping.
+
+An obvious application for jCIFS is a Network Neighborhood/Windows Explorer
+type application. With the addition of the jcifs.http package this is easy.
+I have added a "Network Explorer" file browser servlet to the jcifs.http
+package.
+
+For much improved instructions regarding NTLM HTTP Authentication and the
+jcifs.http.NetworkExplorer servlet see:
+
+ http://jcifs.samba.org/src/docs/ntlmhttpauth.html
+
+To actually use credentials negotiated during the NTLM HTTP Authentication
+it was necessary to add SmbFile constructors that accept
+NtlmPasswordAuthentication objects which can be obtained from an
+HttpSession like:
+
+ NtlmHttpSession ntlm = (NtlmHttpSession)req.getSession().getAttribute( "NtlmHttpSession" );
+ NtlmPasswordAuthentication auth = ntlm.getNtlmPasswordAuthentication();
+ SmbFile f = new SmbFile( "smb://server/share/path", auth );
+
+The internal datatype used to maintain file offsets in the
+SmbFileInputStream class is not a long which in Java is 64 bits. I have not
+received confirmation that files >4GB can be transfered but that's the
+intention.
+
+Thu Aug 8 04:05:28 EDT 2002
+
+jcifs-0.7.0b released
+
+This beta introduces some new functionality rather than refactoring and
+general cleanup which was the focus of the 0.6 series. There's more to come
+but here's what has made it in so far:
+
+o jcifs.smb.client.codepage property specifies codepage of 8 bit strings.
+This should resolve the issue reported by Dmitry Khlonin who says
+codepage=Cp866 is common on Russian LANs. This does not imply running with
+useUnicode=false however. Some commands like the ones that enumerate shares
+and workgroups will return 8 bit encoded strings regardless of wheather or
+not Unicode is negotiated. If workgroups, servers, and shares do not appear
+correctly try setting this property. If you *are* using useUnicode=false
+setting the codepage property may also have an effect if the JRE is not
+running an a locale compatible with the target machine. This link appears
+to have a good list of valid identifiers.
+
+ http://java.sun.com/j2se/1.3/docs/guide/intl/encoding.doc.html
+
+o Added SmbFile.getType() which will return one of
+
+ SmbFile.TYPE_WORKGROUP
+ SmbFile.TYPE_SERVER
+ SmbFile.TYPE_SHARE
+ SmbFile.TYPE_NAMED_PIPE
+ SmbFile.TYPE_PRINTER
+ SmbFile.TYPE_FILESYSTEM
+
+isWorkgroup() is now deprecated.
+
+o Added a "lookup" table to jcifs.netbios.NbtAddress like the one in
+java.net.InetAddress to prevent redundant queries from reaching the wire.
+
+o Plain text passwords have been implemented but must be enabled with
+jcifs.smb.client.enablePlainTextPasswords=true. This is false by default
+and will generate a "Plain text passwords are disabled" RuntimeException
+exception if you try to use it.
+
+o The SmbFile.length() method now returns the capacity of the disk if
+getType() is TYPE_SHARE.
+
+o Added an SmbFile.freeDiskSpace() method has that reports the amount of
+free disk space in bytes on a disk exported by a share (the SmbFile need
+not refer to a share however it may not refer to a workgroup or server).
+
+o Added SmbFile.copyTo method. This method can copy directories accross
+hosts however at the momement it does not mirror file attributes. See this
+message for a little more discussion about copyTo:
+
+ http://lists.samba.org/pipermail/jcifs/2002-August/002357.html
+
+o Replaced jcifs.util.AuthHandler and jcifs.util.AuthInfo with
+jcifs.smb.NtlmAuthenticator and jcifs.smb.NtlmPasswordAuthentication to be
+consistent with java.net package Authenticator and PasswordAuthentication.
+Underlying behaviour remains the same. This has not been tested thuroughly.
+
+Wed May 29 21:51:36 EDT 2002
+
+jcifs-0.6.5 released
+
+Thanks to Tony for running FileOps.java against Netware. Apparently Netware
+does not like the word alignment pad in SMB_COM_WRITE_ANDX. Just commenting
+out that part of the serialization *appears* to work fine with other
+servers as well but keep your eyes open. In the process of testing things,
+I also found that the fix for read() not returning -1 in the 0.6.2 release
+causes reads to return -1 prematurely if the buffer is a particular size
+and a multiple of the files size etc. Unfortunately Word files and other
+OLE Compound Documents are often multiples of 512 so this is quite possible
+if you use a buffer size like 8192. I've created a new example called
+VerifyIO.java that will identify and therefore prevent these problems in
+the future.
+
+Sat May 18 15:59:33 EDT 2002
+
+jcifs-0.6.4 released
+
+The recurDesired and Broadcast flags where on in Node Status
+Request. Apparently XP doesn't respond to this. Should have never
+had them on anyway. This should fix getAllByAddress problems with XP
+(probably Win2K too). Listing on shares should send a UNC path like '\*'
+but jCIFS was incorrectly sending '\\*'. This confused Netware 5.0. This
+has also been fixed.
+
+Fri May 3 04:44:14 EDT 2002
+
+jcifs-0.6.3 released
+
+Finally the SMB URL has been fixed. It required only small changes but of
+course the effect should be dramatic; no more URL encoding and decoding
+of paths. As discussed on the jCIFS mailing list it is now necessary to
+URL encode passords. For example, instead of:
+
+ smb://miallen:p@ss@server/share/path/to/file.doc
+
+it's:
+
+ smb://miallen:p%40ss@server/share/path/to/file.doc
+
+Actually I URL decode the entire authority section so you might also do:
+
+ smb://domain%2bmiallen:p%40ss@server/share/path/to/file.doc
+
+I added a fix for an ArrayIndexOutOfBounds Exception with passwords
+longer than 14 characters. Thanks, MJZ. I removed all references to
+e-mail address. I think the harvesters are getting out of hand.
+
+Thu Mar 21 21:30:45 EST 2002
+
+jcifs-0.6.2 released
+
+It was discovered that the SmbFileInputStream.read() methods would
+not return -1 when EOF was reached (returned 0 instead which is good
+enough for most code) and that writing to a named pipe with clients that
+support NT SMBs would trigger an "Invalid operation for IPC service"
+exception. Both issues have been fixed.
+
+Thu Feb 21 03:02:23 EST 2002
+
+jcifs-0.6.1 released
+
+If a file is retrived using the SmbFileInputStream class, the file's size
+is precisely a multiple of 4096 and the byte[] b and int len parameters
+used in a read() operation are both larger than 4096, the read( byte[]
+b ) and read( byte[] b, int off, int len ) methods will return -1. The <=
+condition in the middle of read( b, off, len ) has been changed to just <.
+
+Wed Feb 20 02:42:20 EST 2002
+
+jcifs-0.6.0 released
+
+This long and winding beta cycle is finally at an end. There have been
+no problems reported for some time now. This release is simply 0.6b9
+renamed with some improvements to the docuementation.
+
+Now how about that RPC layer ...
+
+Wed Feb 6 02:34:52 EST 2002
+
+jcifs-0.6b9 released
+
+The jcifs.util.ThreadInterruptor has been removed. It was a feable attempt
+to try and interrupt threads stalled within new Socket() because the
+destination host is not responding to the initial SYN packet. These calls
+eventually timeout (3 min 15 sec on Linux). I think most Java network
+clients do the same in this situation. Some logic has been added to
+prevent certain erronous operations such as listFiles() on IPC$. There
+have also been two fixes regarding proper URL enocoding and a getName
+issue. I have caught a few "Timeout waiting for response from server"
+errors with the use of AuthHandler that I have added a fix for but I
+an unable to reproduce the problem now. The todo has been updated as
+well as the documentation. The 0.6.0 release is very close, we're just
+working on API documentation at this point.
+
+Sat Jan 12 16:34:11 EST 2002
+
+jcifs-0.6b8 released
+
+Fixed a problem with deleteing derectories on Win98 and Novell. Also,
+fixed erronous result of calling exists() on a directories created
+immediately before (attributes needed to be artificially expired).
+
+Fri Jan 11 03:16:49 EST 2002
+
+jcifs-0.6b7 released
+
+The introduction of listFiles at the last minute created an issue
+with caching file attributes and enumerating workgroups and hosts of a
+workgroup. There was a compilation problem with URLDecoder and a possible
+null pointer exception in the gracefull reconnect code. Generally the
+last beta was a flop. I strongly advise that you erase it and use this
+release. I have high hopes for it. The good news is listFiles has turned
+out to be quite a screemer on regular directories. I can list every file
+on my NT machine with T2Crawler in 10.095 seconds (yes, over the network).
+
+Mon Jan 7 01:24:54 EST 2002
+
+jcifs-0.6b6 released
+
+There have been a few issues discovered and fixed:
+
+o The listFiles() methods will no longer throw MalformedURLException or
+UnknownHostException - These where there because the SmbFile constructors
+throw them. However they should never be thrown within these methods
+because the URLs are constructed internally (i.e. they should not be
+"malformed") and the host should not be different from the host used
+to create the file listFiles() is being invoked on (i.e. the hostname
+should be cached or valid).
+
+o Gracefull reconnect and internal state consistencey - Previously,
+jCIFS was not very smart about how to handle socket failure on the
+server. If for example, the server was restarted, jCIFS would gernerate
+exceptions and generally fall over in a heap. We have revisited the
+code that invalidates transports, their sessions, and the sessions
+trees and found that the code was somewhat deficient. If for example
+an error occured and the transport instructed it's sessions to "logoff"
+they might try to send a message to the server indicating so. Of course,
+this message too might fail resulting in an inconsistent state. There
+was one report of invlid UID exceptions. This is likely the cause of
+that problem and should not happen again. We have added a boolean inError
+parameter to the tryClose, logoff, and treeDisconnect methods that if
+called with inError = true ensure that the state of all sessions and trees
+associates with a transport are reset forceing jCIFS to reestablish new
+sessions and tree connects. All of this happends under the hood of course.
+
+o Improve SMB header discovery - The detection of the first for "magic"
+bytes of the SMB header (0xFF 'S' 'M' 'B') has been greatly improved. Some
+servers leave garbage bytes at the end of messages which jCIFS is
+sensitive about. This should solve the problem reported with NetWare 5.
+
+o Ensure safe URLDecoding of SMB URL - It was discovered that an SmbFile
+derived from another SmbFile created with URL encoded characters might
+generate an error. This was because the first SmbFile would decode the
+URL and then pass the now invalid characters on to the second file. This
+as been fixed by only decoding the string used to reprsent the files
+path internally and thus not pass it to derived SmbFiles.
+
+o Improved choice of authentication credentials to IPC$ - We recently
+found some strange situations where AuthExceptions would be thrown
+were that probably should not have. For example, if you connect to a
+Win98 share using normal credentials and then try to perform an IPC$
+operation (e.g. list shares) Win98 would not take the "null" login
+credentials and return Access denied. If you connect to IPC$ with "null"
+logon creadentials *first* then everything is fine. So we have made the
+choice of credentials for connecting to IPC$ a little smarter. If normal
+credentials have been supplied jCIFS will try those and if that fails
+it tries the "null" creadentials.
+
+o Ensure share names are submitted in CAPS - Win98 (again *sigh*)
+will reject share names that are not capitalized. Shares will now be
+presented to servers in all CAPS. I guess this was broken during the
+revamping, it worked in 0.5. Again, this happends under the hood; no
+user action necessary.
+
+Wed Dec 19 04:42:28 EST 2001
+
+jcifs-0.6b5 released
+
+I realize we're in the middle of a beta cycle but the listFiles
+methods really need to go in. I didn't realize that the FilenameFilter
+interface is to pass each file to an the accept(File dir, String name)
+method. This is would require retrieving all the files from the server. I
+will implement this but I for now I have created a listFiles( String
+wildcard ) method instead. This is much more efficent because the CIFS
+protocol provides for a wildcard expression to be passed to the server
+and return only the entries that match. For a large directory is really
+is far superior to the default java.io.FilenameFilter interface.
+
+Rob et al. You might as well stick with 6b4 for a while. The listFiles is
+the way to go for you ultimately but they need a little growing time and
+my preliminary benchmarks do not show a real performance improvement. I'll
+leave 0.6b4 up for a while.
+
+Sat Dec 15 17:20:59 EST 2001
+
+jcifs-0.6b4 released
+
+A bug that caused exists() (and methods that call it) to return erronious
+results has been fixed. There have also been numerous other smaller bug
+fixes mostly regarding the behavior of SmbFile methods. This release
+should be fairly stable. I have updated and tested all example programs
+and added a few new tests. I have noticed a problem with certain SMB
+URLs that I'm not sure how to fix yet but they are unusal cases.
+
+PS: The depth argument of the T2Crawler does not work. It causes threads
+to exit prematurely. It will likely never be fixed.
+
+Wed Nov 28 04:39:40 EST 2001
+
+jcifs-0.6b3 released
+
+More refactoring. I found a pretty serious Object sink. I fixed the
+deadlock in beta 2. I'm also trying out a new buffer strategy. There
+are only two 64K buffers (plus the BufferCache for transactions) for
+all transports now. Looks like a nice speed boost from that two. Eww,
+this is getting embarassing :~)
+
+TIP:
+
+Try the T2Crawler.java with:
+
+soTimeout=3
+resolveOrder=WINS
+
+Also, you may have noticed that the crawler example will stall on some
+hosts. This is because they don't respond to SYN packets. This has
+been fixed.
+
+
+Wed Nov 21 03:37:28 EST 2001
+
+jcifs-0.6b2 released
+
+Previously jCIFS could not list hosts of a workgroup/domain if that
+workgroup/domain's master browser was on a different network segment. This
+has been fixed. The client can now enumerate hosts of an entire WAN. There
+have also been two trivial bug fixes. I'm seeing some strange behaviour
+from the ThreadedSmbCrawler test. One particularly slow host seems to
+cause it to stall (although on a small network it flies).
+
+Fri Nov 16 04:07:05 EST 2001
+
+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" );
+} else {
+ System.out.println( "error!" );
+}
+
+you might replace this with:
+
+try {
+ f.delete();
+ System.out.println( "delete successfull" );
+} catch( SmbException se ) {
+ System.out.println( "error: " + se.getMessage() );
+}
+
+There are quite a few different messages that can be provoked such as:
+
+The file is being used by another process
+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:
+
+Access denied
+Bad password
+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:
+
+o InetAddress - Lookup a DNS name
+o NbtAddress - Lookup a NetBIOS name or perform NetBIOS specific
+ queries (NodeStatus with getAllByAddress)
+o UniAddress - Don't know or care what type of name it is, try to
+ find the name with both DNS and NetBIOS queries if necessary. Query
+ behavior is governed by the jcifs.resolveOrder property.
+
+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
+
+Chris did some great testing at the CIFS Conference Interoperability
+Lab and found three minor bugs. They are described in detail here:
+
+http://lists.samba.org/pipermail/jcifs/2001-August/001428
+
+These packages will now work with Java 1.1 as well as Java 2.
+
+Sun Jul 29 04:01:18 EDT 2001
+
+jcifs-0.5
+
+This is the final release of the 0.5 series. It is the most stable and
+complete product the jCIFS team has to offer. There are no known bugs. A bug
+in the renameTo operation (would not always return false when it should have)
+has been fixed, API documentation improvements have been made, and a
+entry to the FAQ has been added.
+
+Fri Jul 13 18:54:37 EDT 2001
+
+jcifs-0.5b2
+
+Thanks to Rob for realizing that attempting to read the same file from
+different processes/threads yielded an "The file is being used by another
+process" exception. We had the share flags and access masks wrong. A
+Log.CRITICAL_EXCEPTIONS mask has been added for logging messages to the
+console. If:
+
+ Log.setMask( Log.CRITICAL_EXCEPTIONS );
+
+is set, the "Access denied", "Bad password", and "The device is not
+ready" sorts of exceptions will NOT be printed. The default is still
+Log.EXCEPTIONS which encompasses both Log.CRITICAL_EXCEPTIONS and regular
+Log.EXCEPTIONS so existing code will not be affected.
+
+Thu Jun 28 21:04:15 EDT 2001
+
+jcifs-0.5b
+
+This is the beta release of jcifs-0.5. The 0.5 series has already been
+through a stable release and there are no know bugs so we are confident
+that it will perform well. New features since jcifs-0.4 include:
+
+o SmbFile.list() Bug Fix - The jcifs-0.4 package had a serious bug that
+ caused a TRANS2_FIND_FIRST2/NEXT2 endless loop. It has been properly
+ fixed. This should be the first *complete* stable release.
+o Share, Server, and Workroup Enumeration - jCIFS can now list the shares
+ on a server, servers of a workgroup, and workgroups on a network.
+o CallNamedPipe, TransactNamedPipe, and CreateFile Named Pipe API (Paul)
+o Complete SMB Filesharing URL Scheme IETF Draft Support - The smb://
+ URL scheme has been fully implemented. (Chris)
+o Transactions and RAP API
+o Transactions - Full multi-part Transaction requests(used by Transact
+ Named Pipes)
+o Daylight Savings Bug Fix - jCIFS was not properly correcting for
+ daylight savings. (Urban)
+o Full SmbComNTCreateAndX Support - We now look just like NT 4 instead
+ of Winblows 95 :~)
+o Unicode Alignment Bug Fix - Unicode alignment was generally not
+ correct and caused many problems in early 0.5dev releases.
+o SmbFile Method Behaviors - Fixed canRead() and re-thought and soul
+ searched over the meaning of each of these methods and their behavior
+ in the smb://, smb://name, and Named Pipe contexts. These methods
+ should start to get pretty stable at this point.
+o Clean, No Wait Exiting - Examples and other programs would wait 15
+ seconds before exiting. This has been fixed by making the Transport
+ thread setDaemon( true ). Same for the NameServiceClient Thread.
+o Full Tuneable Batching
+o NetBIOS Scope Fix
+o New getServer, getShare, isWorkgroup Methods
+o SmbShell and SmbCrawler Utilities
+
+Thanks deserved for this release to Chris, Steve, Paul, The DJ, Urban,
+James, Thierry, savaJe Technologies, and Josef.
-Fri Nov 16 04:07:05 EST 2001
-
-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" );
-} else {
- System.out.println( "error!" );
-}
-
-you might replace this with:
-
-try {
- f.delete();
- System.out.println( "delete successfull" );
-} catch( SmbException se ) {
- System.out.println( "error: " + se.getMessage() );
-}
-
-There are quite a few different messages that can be provoked such as:
-
-The file is being used by another process
-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:
-
-Access denied
-Bad password
-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:
-
-o InetAddress - Lookup a DNS name
-o NbtAddress - Lookup a NetBIOS name or perform NetBIOS specific
- queries (NodeStatus with getAllByAddress)
-o UniAddress - Don't know or care what type of name it is, try to
- find the name with both DNS and NetBIOS queries if necessary. Query
- behavior is governed by the jcifs.resolveOrder property.
-
-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
-
-Chris did some great testing at the CIFS Conference Interoperability
-Lab and found three minor bugs. They are described in detail here:
-
-http://lists.samba.org/pipermail/jcifs/2001-August/001428
-
-These packages will now work with Java 1.1 as well as Java 2.
-
-Sun Jul 29 04:01:18 EDT 2001
-
-jcifs-0.5
-
-This is the final release of the 0.5 series. It is the most stable and
-complete product the jCIFS team has to offer. There are no known bugs. A bug
-in the renameTo operation (would not always return false when it should have)
-has been fixed, API documentation improvements have been made, and a
-entry to the FAQ has been added.
-
-Fri Jul 13 18:54:37 EDT 2001
-
-jcifs-0.5b2
-
-Thanks to Rob for realizing that attempting to read the same file from
-different processes/threads yielded an "The file is being used by another
-process" exception. We had the share flags and access masks wrong. A
-Log.CRITICAL_EXCEPTIONS mask has been added for logging messages to the
-console. If:
-
- Log.setMask( Log.CRITICAL_EXCEPTIONS );
-
-is set, the "Access denied", "Bad password", and "The device is not
-ready" sorts of exceptions will NOT be printed. The default is still
-Log.EXCEPTIONS which encompasses both Log.CRITICAL_EXCEPTIONS and regular
-Log.EXCEPTIONS so existing code will not be affected.
-
-Thu Jun 28 21:04:15 EDT 2001
-
-jcifs-0.5b
-
-This is the beta release of jcifs-0.5. The 0.5 series has already been
-through a stable release and there are no know bugs so we are confident
-that it will perform well. New features since jcifs-0.4 include:
-
-o SmbFile.list() Bug Fix - The jcifs-0.4 package had a serious bug that
- caused a TRANS2_FIND_FIRST2/NEXT2 endless loop. It has been properly
- fixed. This should be the first *complete* stable release.
-o Share, Server, and Workroup Enumeration - jCIFS can now list the shares
- on a server, servers of a workgroup, and workgroups on a network.
-o CallNamedPipe, TransactNamedPipe, and CreateFile Named Pipe API (Paul)
-o Complete SMB Filesharing URL Scheme IETF Draft Support - The smb://
- URL scheme has been fully implemented. (Chris)
-o Transactions and RAP API
-o Transactions - Full multi-part Transaction requests(used by Transact
- Named Pipes)
-o Daylight Savings Bug Fix - jCIFS was not properly correcting for
- daylight savings. (Urban)
-o Full SmbComNTCreateAndX Support - We now look just like NT 4 instead
- of Winblows 95 :~)
-o Unicode Alignment Bug Fix - Unicode alignment was generally not
- correct and caused many problems in early 0.5dev releases.
-o SmbFile Method Behaviors - Fixed canRead() and re-thought and soul
- searched over the meaning of each of these methods and their behavior
- in the smb://, smb://name, and Named Pipe contexts. These methods
- should start to get pretty stable at this point.
-o Clean, No Wait Exiting - Examples and other programs would wait 15
- seconds before exiting. This has been fixed by making the Transport
- thread setDaemon( true ). Same for the NameServiceClient Thread.
-o Full Tuneable Batching
-o NetBIOS Scope Fix
-o New getServer, getShare, isWorkgroup Methods
-o SmbShell and SmbCrawler Utilities
-
-Thanks deserved for this release to Chris, Steve, Paul, The DJ, Urban,
-James, Thierry, savaJe Technologies, and Josef.
-
-FILES:
-
- jcifs-0.5b.tgz jar and javadoc only for UNIX
- jcifs-0.5b.zip jar and javadoc only for WINDOWS
- jcifs-0.5b.jar jar file only
-
-NOTE: The source code is included in the above packages. If
-you would like to actually build jCIFS the ANT jar files are packaged
-separately:
-
- ant.tgz ant jar files
- ant.zip ditto
-
-Just unpack one of the above in the jcifs_0.5b directory, set JAVA_HOME in
-build.{sh,bat} to bootstrap Ant, and run $ ./build.sh smb or > build smb.
-
-IMPORTANT:
-
-The jcifs.netbios.ns.nameserver has been changed to jcifs.netbios.wins
-and the jcifs.util.Config class should now be referenced as
-jcifs.Config. Programs written for jcifs-0.4 will not run without making
-these two changes at least.
-
-The jCIFS project uses the 'Ant' build tool available here:
-
- http://jakarta.apache.org/ant/
-
-If you have *any* trouble please let us know on the mailing list by
-sending mail to jcifs@samba.org or to myself at mballen@erols.com.
-
-Enjoy,
-Michael B. Allen <mballen@erols.com>
+Wed Feb 12 01:23:02 EST 2003
+
+A security issue regarding the SmbSession.logon() method used by NTLM HTTP
+Authentication has been fixed and a modification has been made to trigger
+MSIE to redisplay the Network Password dialog repeatedly until correct
+credentials are supplied. The change was made in the core jcifs.smb package
+however so test this in your dev environments.
+
+Wed Feb 5 00:41:32 EST 2003
+
+The jcifs-0.7.0 and 0.7.1 releases will incorrectly throw an
+ArrayIndexOutOfBounds exception if a write of 1501 to 1504 is performed.
+This release fixes that bug. You may also set jcifs.smb.client.snd_buf_size
+= 1300 as a temporary work-around. It is also now possible to specify a
+"ShareAccess" with SmbFileOutputStream and SmbFile to restrict other
+processes from accessing files jCIFS opens. Also, SmbFileOutputStream now
+supports writing files larger than 4GB.
+
+Wed Jan 15 22:34:14 EST 2003
+
+jcifs-0.7.1 released
+
+Three bugs have been fixed regarding filenames with '#' signs in them, the
+getInputStream(), getLastModified(), getDate(), and getContentLength()
+methods of the URLConnection implementation, and isExists() incorrectly
+returning false.
+
+Thu Jan 9 00:06:23 EST 2003
+
+jcifs-0.7.0 released
+
+This is the 0.7.0 release of jCIFS, the Java SMB client. There is new
+functionality specifically targeting Web applications as well as some
+critical SMB URL fixes and feature improvements:
+
+o The new jcifs.http package is very handy when building Web applications
+ that need to integrate with MS corporate intranets. Adding a hyperlink to
+ a document on a network drive is easy with Network Explorer (pictured
+ right) and will transparently negotiate credentials with MSIE to browse
+ SMB resources (really, no password dialog necessary). This package also
+ boasts an NTLM HTTP Authentication servlet Filter for authenticating MSIE
+ clients. These are useful features because many of the tasks surrounding
+ user management now fall back to computer support and HR. It is not
+ necessary to add and remove users as they join and leave the company.
+ Perhaps most important from the user's perspective; they do not need to
+ enter a username or password if their workstation is a member of an NTLM
+ domain. The password hashes generated when they logged on to their
+ workstation will be negotiated during the initial request for a session,
+ passed through jCIFS, and validated against a PDC or BDC. This also makes
+ the user's domain, username, and password available for managing session
+ information, profiles, preferences, etc.
+
+o The functionality used to authenticate and manage arbitrary creadentials
+ has been exposed in the SmbSession and NtlmPasswordAuthentication
+ classes. This permits NTLM password authentication to be integrated into
+ applications without requiring Microsoft components or JNI.
+
+o With the introduction of the jcifs.encoding property the client is now
+ truely internationalized. It has been used successfully on OS/390 with
+ native EBCDIC character encoding. See the Sun JRE documentation for a
+ list of supported encodings.
+
+o The URL issues remaining in the 0.6 series have been fixed in 0.7 by
+ converting all SMB URL handling internally to use the java.net.URL class
+ (Note: directories must now have a trailing slash and Java 1.3 is
+ required). Also a deadlock in the name service code was identified and
+ fixed (repaired in 0.6.8 as well).
+
+o A copyTo() method has been added to SmbFile that is very fast at copying
+ large directories across hosts.
+
+o There have been numerous other changes including the mkdirs() and
+ getType() methods, plain text password support (disabled by default), the
+ available() method and close() fix for Named Pipes, reading files larger
+ than 4 GB, the NtlmAuthenticator class, and more.
+
+All documentation has been completely reviewed and updated.
--8<--
- JCIFS
+ jCIFS
Common Internet File System Client in 100% Java
http://jcifs.samba.org
-This is the JCIFS SMB client library written in Java. In short it
-will enable Java applications to remotely access shared directories
-on SMB file servers(i.e. a Microsoft Windows "share"). It is a fairly
-religious implementation of the CIFS specification supporting Unicode,
-batching, multiplexing, encrypted authentication, transactions, named
-pipes, share/server/workgroup enumeration, and more. It is licensed
-under LGPL which means commercial organizations can legitimately use it
-with their propertietary code(you just can't modify the library itself
-without reciprocation).
+This is the jCIFS SMB client library written in Java. In short, it will
+enable Java applications to remotely access shared directories on SMB file
+servers(i.e. a Microsoft Windows "share"). It is a fairly religious
+implementation of the CIFS specification supporting Unicode, batching,
+multiplexing, encrypted authentication, transactions, named pipes,
+domain/workgroup/server/share/directory/file enumeration, RAPs and more. It
+is licensed under LGPL which means commercial organizations can
+legitimately use it with their propertietary code (you just can't modify
+the library itself without providing the source for those changes to it's
+users, see the LGPL for details).
REQUIREMENTS:
-Java 1.1 or above - http://java.sun.com/products/
+Java 1.3 or above - http://java.sun.com/products/
-INSTALLATION
+INSTALLATION:
-Just add the jar file to you classpath as you would with any other
-jar. More specifically:
+Just add the jar file to you classpath as you would with any other jar.
+More specifically:
UNIX:
-1) Go to http://jcifs.samba.org and download jcifs-0.5b.tgz
-2) Put it someplace reasonable and extract it with:
+Go to http://jcifs.samba.org and download the latest jar. If you download
+the tgz archive you also get the source code and javadoc API documentation
+(see critical properties discussed on the Overview page). Put it someplace
+reasonable and extract it. For example:
- $ gunzip jcifs-0.5b.tgz
- $ tar -xvf jcifs-0.5b.tar
+ $ gunzip jcifs-0.7.0.tgz
+ $ tar -xvf jcifs-0.7.0.tar
-3) Add the jar to your classpath. There are two ways to do this. One is to
+Add the jar to your classpath. There are two ways to do this. One is to
explicitly set it on the command line when you run your application like:
- $ java -cp path/to/jcifs-0.4b.jar MyApplication
+ $ java -cp myjars/jcifs-0.7.0.jar MyApplication
-or perhaps export it in your .profile/.bash_profile like:
+but a more robust solution is to export it in your ~/.profile or
+~/.bash_profile like:
- CLASSPATH=$CLASSPATH:/home/miallen/path/to/jcifs-0.5b.jar
+ CLASSPATH=$CLASSPATH:/home/produser/myapp/myjars/jcifs-0.7.0.jar
export CLASSPATH
WINDOWS:
-1) Go to http://jcifs.samba.org and download jcifs-0.5b.zip
-2) Extract it with winzip and put the files someplace reasonable.
-3) Add the jar to your classpath. There are two ways to do this. One is to
+Go to http://jcifs.samba.org and download the latest jar. If you download
+the zip archive you also get the source code and javadoc API documentation
+(see critical properties discussed on the Overview page). Put it someplace
+reasonable and extract it with something like Winzip.
+
+Add the jar to your classpath. There are two ways to do this. One is to
explicitly set it on the command line when you run your application like:
- C:\jcifs> java -cp jcifs-0.4b.jar MyApplication
+ C:\> java -cp myjars\jcifs-0.7.0.jar MyApplication
-The other way is to alter your system environment but I'm not confident
-I can tell you accurately how to do that.
+but a more robust solution would be to change your system environment but
+I'm not confident I can tell you accurately how to do that.
-It is also common that the CLASSPATH be specified in a shell script or
-batch file. See build.{sh,bat} as a hint.
+It is also common that the CLASSPATH be specified in a shell script or
+batch file. See the build.bat batch file that runs the Ant build tool as an
+example.
-RUNNING JCIFS:
+USING JCIFS:
-In general the public API is extremely simple. The jcifs.smb.SmbFile,
-jcifs.smb.SmbFileInputStream, and jcifs.smb.SmbFileOutputStream
-classes are analogous to the java.io.File, java.io.FileInputStream,
-and java.io.FileOutputStream classes so if you know how to use those it
-should be quite obvious how to use JCIFS provided you set any necessary
-properties(such as wins) and understand the smb:// URL syntax.
+In general the public API is extremely simple. The jcifs.smb.SmbFile,
+jcifs.smb.SmbFileInputStream, and jcifs.smb.SmbFileOutputStream classes are
+analogous to the java.io.File, java.io.FileInputStream, and
+java.io.FileOutputStream classes so if you know how to use those it should
+be obvious how to use jCIFS provided you set any necessary properties(such
+as WINS) and understand the smb:// URL syntax.
-Here's an example to retrieve a file:
+Here's an example to retrieve a file:
import jcifs.smb.*;
jcifs.Config.setProperty( "wins", "192.168.1.230" );
SmbFileInputStream in = new SmbFileInputStream(
"smb://username:password@host/c/My Documents/report.txt" );
- byte[] b = new byte[65535];
+ byte[] b = new byte[8192];
int n;
while(( n = in.read( b )) > 0 ) {
System.out.write( b, 0, n );
}
-You can also write, rename, list contents of a directory, enumerate
-shares, communicate with Win32 Named Pipe Servers, ...etc.
+You can also write, rename, list contents of a directory, enumerate shares,
+communicate with Win32 Named Pipe Servers, ...etc.
-The protocol handler for java.net.URL is also in place which means you
-retrieve files using the URL class as you would with other protocols. For
-example:
+The protocol handler for java.net.URL is also in place which means you
+retrieve files using the URL class as you would with other protocols. For
+example:
- Class.forName( "jcifs.Config" ); //ensure protocol handler is loaded
- URL url = new URL( "smb://user:pass@host/share/dir/file.txt" );
+ jcifs.Config.registerSmbURLHandler(); //ensure protocol handler is loaded
+ URL url = new URL( "smb://user:pass@host/share/dir/file.doc" );
InputStream in = url.openStream();
-This will also work with whatever else uses the URL class internally. For
-example if you use RMI you can serve class files from an SMB share and
-use the codebase property:
+There are many example programs in the jcifs_0.7.0/examples/ directory. To
+execute the Put example you might do:
+
+ $ java -cp examples:jcifs-0.7.0.jar -Djcifs.properties=jcifs.prp \
+ Put smb://usr:pass@host/share/dir/file.doc
+ ##########
+ 582K transfered
+
+This will also work with whatever else uses the URL class internally. For
+example if you use RMI you can serve class files from an SMB share and use
+the codebase property:
-Djava.rmi.server.codebase=smb://mymachine/c/download/myapp.jar
-To execute the Put example you might do:
+See the extensive API documentation included in the distribution.
-$ java -cp examples:jcifs-0.4b.jar Put smb://usr:pass@host/share/file.zip
-##########
-582K transfered
+BUILDING JCIFS FROM SOURCE:
-API documentation is included.
+If you wish to modify and/or build the jCIFS source simply download the
+ant.tgz or ant.zip available at http://jcifs.samba.org and extract it in
+the jcifs_0.7.0 directory. Edit the build.sh or build.bat file to
+appropriately reflect the location of the JDK on your system and bootstrap
+the Ant build tool. Now type:
+
+ $ ./build.sh
+
+You will be presented with a list of target arguments. The build file is a
+standard Ant build.xml config. You may also integrate the package into your
+existing Ant installation or get the latest version of Ant here:
+
+ http://jakarta.apache.org/ant/
WHAT IS SMB AND CIFS?
-Server Message Block (SMB) is an application layer networking protocol
-for file and print sharing. It is the de-facto networking protocol for
-Microsoft Windows platforms. The Common Internet File System (CIFS)
-is the more generic name for all that encompasses the protocol and its
-many layers. Collectively this is the networking protocol used when you
-"Map Network Drive...", issue "net use * \\server\share" commands, use
-smbclient on UNIX, smbfs on Linux, Sharity, OS2, server vendors such as
-Network Appliance, EMC, and others.
+Server Message Block (SMB) is an application layer networking protocol for
+file and print sharing. It is the de-facto networking protocol for
+Microsoft Windows platforms. The Common Internet File System (CIFS) is the
+more generic name for all that encompasses the protocol and its many
+layers. Collectively this is the networking protocol used when you "Map
+Network Drive...", issue "net use * \\server\share" commands, use smbclient
+on UNIX, smbfs on Linux, Sharity, OS2, server vendors such as Network
+Appliance, EMC, and Novell NetWare.
WHY DO YOU NEED JCIFS?
-This client is 100% Java and will work the same in a variety of
-environments from Palm Pilots and applets to any UNIX that supports
-Java. Naturally you can choose to run your applications on a platform
-that supports mapping or mounting remote volumes into the local
-filesystem but this assumes you know what shares you are accessing in
-advance and what platform your application is running on(do you use
-/mnt/pnt or H:\dir). Such an approach is not portable, unstable due to
-unnecessary dependencies, and can be difficult to manage. JCIFS offers
-Java applications that require access to SMB file services portability
-and therefore the added stability that the UNIX environment can
-provide. The JCIFS infrastructure is also highly extensible. If there
-is a demand it will include a great deal of additional functionality
-not available through a filesystem API such as printing, RPC, NT file
-change notification, etc.
+This client is 100% Java and will work the same in a variety of
+environments from Palm Pilots and applets to any UNIX that supports Java.
+Naturally you can choose to run your applications on a platform that
+supports mapping or mounting remote volumes into the local filesystem but
+this assumes you know what shares you are accessing in advance and what
+platform your application is running on(do you use /mnt/pnt or H:\dir). The
+latency involed makes this approach unsatisfactory for certain applications
+(e.g. Web Gateway). Using locally mapped filesystems is also not portable,
+unstable due to unnecessary dependencies, and more difficult to manage. The
+JCIFS infrastructure is also highly extensible. If there is a demand it
+will include a great deal of additional functionality not available through
+a filesystem API such as printing, RPC, NT file change notification, etc.
ACKNOWLEDGEMENTS
-Special thanks to the Samba organization and Christopher R. Hertel for
-starting the JCIFS project.
+Special thanks to the Samba organization and Christopher R. Hertel for
+starting the JCIFS project.
+
#!/bin/sh
JAVA_HOME=/usr/local/java
-CLASSPATH=ant/ant.jar:ant/jaxp.jar:ant/parser.jar:${JAVA_HOME}/lib/tools.jar
+CLASSPATH=ant/ant.jar:ant/jaxp.jar:ant/parser.jar:${JAVA_HOME}/lib/tools.jar:/usr/local/lib/servlet.jar
+#CLASSPATH=ant/ant.jar:ant/jaxp.jar:ant/parser.jar:/usr/local/resin/lib/jsdk23.jar:.
$JAVA_HOME/bin/java -classpath $CLASSPATH org.apache.tools.ant.Main -buildfile build.xml $@
<echo message=" javadoc"/>
</target>
+ <target name="comm">
+ <mkdir dir="build"/>
+ <javac srcdir="src"
+ destdir="build"
+ includes="jcifs/*.java"
+ debug="on"/>
+ </target>
<target name="util">
<mkdir dir="build"/>
<javac srcdir="src"
includes="jcifs/netbios/*.java"
debug="on"/>
</target>
- <target name="smb" depends="netbios,util">
+ <target name="http">
+ <mkdir dir="build"/>
+ <javac srcdir="src"
+ destdir="build"
+ includes="jcifs/http/*.java"
+ debug="on"/>
+ </target>
+ <target name="smb" depends="comm,netbios,util,http">
<mkdir dir="build"/>
<javac srcdir="src"
destdir="build"
<delete dir="build"/>
</target>
<target name="jar" depends="smb">
- <jar jarfile="jcifs-0.6b.jar" basedir="build"/>
+ <copy file="src/jcifs/util/mime.map" tofile="build/jcifs/util/mime.map" overwrite="yes"/>
+ <copy file="src/jcifs/http/ne.css" tofile="build/jcifs/http/ne.css" overwrite="yes"/>
+ <jar jarfile="jcifs-0.7.3.jar" basedir="build"/>
</target>
<target name="tgz">
- <copy todir="dist_tmp/jcifs_0.6b">
+ <copy todir="dist_tmp/jcifs_0.7.3">
<fileset dir="." excludes="ant,**/.*,build,jcifs.prp,**/*.tgz,**/*.zip"/>
</copy>
- <tar tarfile="jcifs-0.6b.tar" basedir="dist_tmp"/>
- <gzip src="jcifs-0.6b.tar" zipfile="jcifs-0.6b.tgz"/>
- <delete file="jcifs-0.6b.tar"/>
+ <tar tarfile="jcifs-0.7.3.tar" basedir="dist_tmp"/>
+ <gzip src="jcifs-0.7.3.tar" zipfile="jcifs-0.7.3.tgz"/>
+ <delete file="jcifs-0.7.3.tar"/>
<delete dir="dist_tmp"/>
</target>
<target name="zip">
- <copy todir="dist_tmp/jcifs_0.6b">
+ <copy todir="dist_tmp/jcifs_0.7.3">
<fileset dir="." excludes="ant,**/.*,build,jcifs.prp,**/*.tgz,**/*.zip"/>
</copy>
<fixcrlf srcdir="dist_tmp" cr="add" tab="remove" tablength="4" excludes="**/*.jar,**/*.exe"/>
- <zip zipfile="jcifs-0.6b.zip" basedir="dist_tmp"/>
+ <zip zipfile="jcifs-0.7.3.zip" basedir="dist_tmp"/>
<delete dir="dist_tmp"/>
</target>
<target name="javadoc">
<delete dir="docs/api"/>
<mkdir dir="docs/api"/>
- <javadoc sourcefiles="jcifs/netbios/NbtAddress,jcifs/smb/SmbFile,jcifs/smb/SmbException,jcifs/util/AuthHandler,jcifs/util/AuthInfo,jcifs/smb/SmbNamedPipe,jcifs/smb/SmbFileInputStream,jcifs/smb/SmbFileOutputStream,jcifs/smb/SmbURLConnection,jcifs/UniAddress,jcifs/Config,jcifs/util/PropertiesTree,jcifs/util/Log"
+ <javadoc sourcefiles="jcifs/netbios/NbtAddress,jcifs/smb/SmbFile,jcifs/smb/SmbException,jcifs/smb/SmbAuthException,jcifs/smb/SmbNamedPipe,jcifs/smb/SmbFileInputStream,jcifs/smb/SmbFileOutputStream,jcifs/UniAddress,jcifs/Config,jcifs/util/PropertiesTree,jcifs/util/Log,jcifs/smb/SmbSession,jcifs/smb/NtlmPasswordAuthentication,jcifs/http/NtlmSsp,jcifs/http/NtlmHttpFilter,jcifs/http/NetworkExplorer,jcifs/http/NtlmServlet,jcifs/smb/NtlmAuthenticator"
sourcepath="src"
destdir="docs/api"
overview="docs/overview.html"
version="true"
use="true"
windowtitle="jcifs API">
- <link href="http://java.sun.com/products/jdk/1.2/docs/api/"/>
+ <!-- link href="http://java.sun.com/products/jdk/1.2/docs/api/"/-->
</javadoc>
+ <copy file="docs/allclasses-frame.html" tofile="docs/api/allclasses-frame.html" overwrite="yes"/>
</target>
</project>
--- /dev/null
+import jcifs.smb.SmbFile;
+
+public class AllocInfo {
+
+ public static void main( String argv[] ) throws Exception {
+
+ SmbFile f = new SmbFile( argv[0] );
+ System.out.println( f.getDiskFreeSpace() );
+ }
+}
+
--- /dev/null
+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();
+ }
+}
+++ /dev/null
-import java.awt.*;
-import java.awt.event.*;
-
-public class AuthDialog extends Dialog implements ActionListener {
-
- Panel labels, fields, top, middle, buttons;
- TextField username, password;
- Button ok, cancel;
-
- public AuthDialog() {
- super( new Frame(), "Authentication", true );
- setSize( 200, 165 );
- setLocation( 400, 300 );
-
- top = new Panel();
- middle = new Panel();
- labels = new Panel( new GridLayout( 2, 1 ));
- fields = new Panel( new GridLayout( 2, 1 ));
- buttons = new Panel( new GridLayout( 1, 2 ));
-
- username = new TextField( 15 );
- password = new TextField( 15 );
-
- fields.add( username );
- fields.add( password );
-
- labels.add( new Label( "Username:" ));
- labels.add( new Label( "Password:" ));
-
- middle.add( labels, BorderLayout.WEST );
- middle.add( fields, BorderLayout.CENTER );
-
- top.add( new TextArea( "The client does not have the necessary access rights for the requested function", 3, 30, TextArea.SCROLLBARS_NONE ), BorderLayout.CENTER );
- top.add( middle, BorderLayout.SOUTH );
-
- ok = new Button( "Ok" );
- cancel = new Button( "Cancel" );
- password.setEchoChar( '*' );
- ok.addActionListener( this );
- cancel.addActionListener( this );
- buttons.add( ok );
- buttons.add( cancel );
-
- add( top, BorderLayout.CENTER );
- add( buttons, BorderLayout.SOUTH );
-
- addWindowListener( new CloseWindow() );
- }
-
- public void actionPerformed( ActionEvent ae ) {
- setVisible( false );
- }
-
- class CloseWindow extends WindowAdapter {
- public void windowClosing( WindowEvent e ) {
- setVisible( false );
- }
- }
-
- public static void main( String[] argv ) {
- AuthDialog authDialog = new AuthDialog();
- authDialog.setVisible( true );
- }
-}
--- /dev/null
+import jcifs.netbios.NbtAddress;
+import jcifs.util.*;
+import jcifs.smb.*;
+import jcifs.util.Log;
+import java.util.Date;
+
+public class AuthListFiles implements AuthHandler {
+
+ public static String readLine() throws Exception {
+ int c;
+ StringBuffer sb = new StringBuffer();
+ while(( c = System.in.read() ) != '\n' ) {
+ if( c == -1 ) return "";
+ sb.append( (char)c );
+ }
+ return sb.toString().trim();
+ }
+
+ public AuthListFiles( String[] argv ) throws Exception {
+ SmbFile.setAuthHandler( this );
+
+ SmbFile file = new SmbFile( argv[0] );
+
+ SmbFile[] files = file.listFiles();
+
+ for( int i = 0; i < files.length; i++ ) {
+ System.out.print( " " + files[i].getName() );
+ }
+ }
+
+ public boolean authenticate( AuthInfo authInfo ) {
+ System.out.println( authInfo.exception.getMessage() + " for " + authInfo.target );
+ System.out.print( "username: " );
+ int i;
+ try {
+ String user = readLine();
+ if((i = user.indexOf( '\\' )) != -1 ) {
+ authInfo.domain = user.substring( 0, i );
+ authInfo.username = user.substring( i + 1 );
+ } else {
+ authInfo.username = user;
+ }
+ System.out.print( "password: " );
+ authInfo.password = readLine();
+ if( authInfo.password.length() > 0 ) {
+ return true;
+ }
+ } catch( Exception e ) {
+ }
+ return false;
+ }
+
+
+ public static void main( String[] argv ) throws Exception {
+ new AuthListFiles( argv );
+ }
+}
--- /dev/null
+import jcifs.netbios.NbtAddress;
+import jcifs.util.*;
+import jcifs.smb.*;
+import jcifs.util.Log;
+import java.util.Date;
+
+public class Break implements AuthHandler {
+
+ public Break( String[] argv ) throws Exception {
+ SmbFile.setAuthHandler( this );
+ System.out.println( "listed " + (new SmbFile( argv[0] ).listFiles()).length + " files" );
+ }
+
+ public boolean authenticate( AuthInfo authInfo ) {
+ authInfo.domain = "mydom";
+ authInfo.username = "miallen";
+ authInfo.password = "wwcWww";
+ System.out.println( authInfo.exception.getMessage() + ", trying new credentials" );
+ return true;
+ }
+
+
+ public static void main( String[] argv ) throws Exception {
+ for( int i = 0; i < 10; i++ ) {
+ new Break( argv );
+ Thread.sleep( 4000 );
+ }
+ }
+}
-/* examples for the jcifs smb client library in Java
- * Copyright (C) 2001 "Michael B. Allen" <mballen@erols.com>
- *
- * 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.SmbNamedPipe;
import java.io.InputStream;
import java.io.OutputStream;
-/* examples for the jcifs smb client library in Java
- * Copyright (C) 2001 "Michael B. Allen" <mballen@erols.com>
- *
- * 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 java.util.Date;
import java.util.TimeZone;
--- /dev/null
+import jcifs.smb.SmbFile;
+
+public class CopyTo {
+
+ public static void main( String argv[] ) throws Exception {
+
+ SmbFile from = new SmbFile( argv[0] );
+ SmbFile to = new SmbFile( argv[1] );
+ from.copyTo( to );
+ }
+}
+
--- /dev/null
+import jcifs.smb.SmbFile;\r
+\r
+public class CopyTo5 {\r
+\r
+ public static void main( String argv[] ) throws Exception {\r
+ if( argv.length < 7 ) {\r
+ System.err.println( "CopyTo <src directory> <dst directory> <f1> <f2> <f3> <f4> <f5>" );\r
+ System.exit( 1 );\r
+ }\r
+ SmbFile srcdir = new SmbFile( argv[0] );\r
+ SmbFile dstdir = new SmbFile( argv[1] );\r
+\r
+ SmbFile sf1 = new SmbFile( srcdir, argv[2] );\r
+ SmbFile df1 = new SmbFile( dstdir, argv[2] );\r
+ sf1.copyTo( df1 );\r
+\r
+ SmbFile sf2 = new SmbFile( srcdir, argv[3] );\r
+ SmbFile df2 = new SmbFile( dstdir, argv[3] );\r
+ sf2.copyTo( df2 );\r
+\r
+ SmbFile sf3 = new SmbFile( srcdir, argv[4] );\r
+ SmbFile df3 = new SmbFile( dstdir, argv[4] );\r
+ sf3.copyTo( df3 );\r
+\r
+ SmbFile sf4 = new SmbFile( srcdir, argv[5] );\r
+ SmbFile df4 = new SmbFile( dstdir, argv[5] );\r
+ sf4.copyTo( df4 );\r
+\r
+ SmbFile sf5 = new SmbFile( srcdir, argv[6] );\r
+ SmbFile df5 = new SmbFile( dstdir, argv[6] );\r
+ sf5.copyTo( df5 );\r
+ }\r
+}\r
+\r
+++ /dev/null
-/* examples for the jcifs smb client library in Java
- * Copyright (C) 2001 "Michael B. Allen" <mballen@erols.com>
- *
- * 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.util.Log;
-import java.util.LinkedList;
-import java.util.ListIterator;
-import java.net.MalformedURLException;
-import java.io.*;
-
-public class CrawlerBench {
-
- static long time;
-
- class DirEntry {
- SmbFile dir;
- int depth;
-
- DirEntry( SmbFile dir, int depth ) {
- this.dir = dir;
- this.depth = depth;
- }
- }
-
- class SmbCrawlerThread extends Thread {
-
- StringBuffer sb = new StringBuffer();
-
- SmbCrawlerThread() {
- }
-
- public void run() {
- try {
- Thread.sleep( 5000 );
- } catch( Exception e ) {
- }
- while( true ) {
- try {
- DirEntry e;
-
- synchronized( dirList ) {
- while( dirList.isEmpty() ) {
- dirList.wait( 500 );
- }
- e = (DirEntry)dirList.remove( 0 );
- }
-
- if( e.depth == 0 ) {
- continue;
- }
-
- String[] l = e.dir.list();
-
- int n = maxDepth - e.depth;
-
- for(int i = 0; l != null && i < l.length; i++ ) {
- try {
- sb.setLength( 0 );
- for( int k = 0; k < n; k++ ) {
- // sb.append( " " );
- }
- SmbFile d = new SmbFile( e.dir, l[i] );
- // System.out.println( sb.append( d ));
- if( d.isDirectory() ) {
- synchronized( dirList ) {
- dirList.add( new DirEntry( d, e.depth - 1 ));
- dirList.notify();
- }
- }
- } catch( IOException ioe ) {
- }
- }
- } catch( Exception x ) {
- }
- }
- }
- }
-
- LinkedList dirList;
- int maxDepth;
-
- CrawlerBench( String dir, int maxDepth, int numThreads ) throws Exception {
- this.maxDepth = maxDepth;
- dirList = new LinkedList();
- dirList.add( new DirEntry( new SmbFile( dir ), maxDepth ));
- for( int i = 0; i < numThreads; i++ ) {
- (new SmbCrawlerThread()).start();
- }
- }
-
- public static void main(String[] argv) throws Exception {
- if( argv.length < 3 ) {
- System.out.println( "usage: CrawlerBench dir depth numThreads" );
- return;
- }
- System.out.print( "Hit Enter when ready." );
- System.in.read();
-
- new CrawlerBench( argv[0], Integer.parseInt( argv[1] ), Integer.parseInt( argv[2] ));
- }
-}
-/* examples for the jcifs smb client library in Java
- * Copyright (C) 2001 "Michael B. Allen" <mballen@erols.com>
- *
- * 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.SmbFileOutputStream;
public class CreateFile {
-/* examples for the jcifs smb client library in Java
- * Copyright (C) 2001 "Michael B. Allen" <mballen@erols.com>
- *
- * 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.SmbException;
public class Delete {
public static void main( String argv[] ) throws Exception {
-
- long t0 = System.currentTimeMillis();
-
SmbFile f = new SmbFile( argv[0] );
- try {
- if( f.delete() ) {
- System.out.println( f.getCanonicalPath() + " deleted " + ( System.currentTimeMillis() - t0 ) + "ms" );
- } else {
- System.out.println( "Could not find " + f.getCanonicalPath() );
- }
- } catch( SmbException se ) {
- System.out.println( se.getMessage() );
- se.printStackTrace();
- }
+ f.delete();
}
}
-/* examples for the jcifs smb client library in Java
- * Copyright (C) 2001 "Michael B. Allen" <mballen@erols.com>
- *
- * 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;
public class Exists {
-/* examples for the jcifs smb client library in Java
- * Copyright (C) 2001 "Michael B. Allen" <mballen@erols.com>
- *
- * 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.
- */
-
/* Test the following file operations:
*
* canRead
}
SmbFile s = new SmbFile( argv[0] );
- SmbFile d = new SmbFile( s, "JcifsTestOpsDir" );
+ SmbFile d = new SmbFile( s, "JcifsTestOpsDir/" );
// delete - Delete the directory if it exists
o.write( "The Common Internet File System (CIFS) is the de-facto file sharing protocol on the Microsoft Windows platform. It is the underlying networking protocol used when accessing shares with Windows Explorer, the Network Neighborhood, via a Map Network Drive... dialog, the C:\\> net use * \\\\server\\share commands, or smbclient on UNIX, smbfs on Linux, and elsewhere.\r\n".getBytes() );
o.close();
} catch( IOException ioe ) {
- System.out.println( "fail - could not create file " + d + "/foo.txt: " + ioe.getMessage() );
+ System.out.println( "fail - could not create file " + d + "foo.txt: " + ioe.getMessage() );
}
- System.out.println( "okay - created file " + d + "/foo.txt" );
+ System.out.println( "okay - created file " + d + "foo.txt" );
// canRead - Test to see if the new file can be read
System.out.println( "fail - length " + f + " is wrong: " + f.length() );
}
- SmbFile r = new SmbFile( d.getParent(), "JcifsDeleteMe" );
+ SmbFile r = new SmbFile( d.getParent(), "JcifsDeleteMe/" );
// Must delete any left over directory from a previous run
try {
r.delete();
- System.out.println( "okay - delete " + d + " successfull" );
+ System.out.println( "okay - delete " + r + " successfull" );
} catch( SmbException se ) {
- System.out.println( "fail - delete " + d + " failed: " + se.getMessage() );
+ System.out.println( "fail - delete " + r + " failed: " + se.getMessage() );
}
}
}
--- /dev/null
+/*\r
+ * Cay S. Horstmann & Gary Cornell, Core Java\r
+ * Published By Sun Microsystems Press/Prentice-Hall\r
+ * Copyright (C) 1997 Sun Microsystems Inc.\r
+ * All Rights Reserved.\r
+ *\r
+ * Permission to use, copy, modify, and distribute this \r
+ * software and its documentation for NON-COMMERCIAL purposes\r
+ * and without fee is hereby granted provided that this \r
+ * copyright notice appears in all copies. \r
+ * \r
+ * THE AUTHORS AND PUBLISHER MAKE NO REPRESENTATIONS OR \r
+ * WARRANTIES ABOUT THE SUITABILITY OF THE SOFTWARE, EITHER \r
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE \r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A \r
+ * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. THE AUTHORS\r
+ * AND PUBLISHER SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED \r
+ * BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING \r
+ * THIS SOFTWARE OR ITS DERIVATIVES.\r
+ */\r
+ \r
+/**\r
+ * A class for formatting numbers that follows printf conventions.\r
+ * Also implements C-like atoi and atof functions\r
+ * @version 1.04 13 Sep 1998\r
+ * @author Cay Horstmann\r
+ */\r
+\r
+import java.io.*;\r
+\r
+public class Format\r
+\r
+{ /** \r
+ * Formats the number following printf conventions.\r
+ * Main limitation: Can only handle one format parameter at a time\r
+ * Use multiple Format objects to format more than one number\r
+ * @param s the format string following printf conventions\r
+ * The string has a prefix, a format code and a suffix. The prefix and suffix\r
+ * become part of the formatted output. The format code directs the\r
+ * formatting of the (single) parameter to be formatted. The code has the\r
+ * following structure\r
+ * <ul>\r
+ * <li> a % (required)\r
+ * <li> a modifier (optional)\r
+ * <dl>\r
+ * <dt> + <dd> forces display of + for positive numbers\r
+ * <dt> 0 <dd> show leading zeroes\r
+ * <dt> - <dd> align left in the field\r
+ * <dt> space <dd> prepend a space in front of positive numbers\r
+ * <dt> # <dd> use "alternate" format. Add 0 or 0x for octal or hexadecimal numbers. Don't suppress trailing zeroes in general floating point format.\r
+ * </dl>\r
+ * <li> an integer denoting field width (optional)\r
+ * <li> a period followed by an integer denoting precision (optional)\r
+ * <li> a format descriptor (required)\r
+ * <dl>\r
+ * <dt>f <dd> floating point number in fixed format\r
+ * <dt>e, E <dd> floating point number in exponential notation (scientific format). The E format results in an uppercase E for the exponent (1.14130E+003), the e format in a lowercase e.\r
+ * <dt>g, G <dd> floating point number in general format (fixed format for small numbers, exponential format for large numbers). Trailing zeroes are suppressed. The G format results in an uppercase E for the exponent (if any), the g format in a lowercase e.\r
+ * <dt>d, i <dd> integer in decimal\r
+ * <dt>x <dd> integer in hexadecimal\r
+ * <dt>o <dd> integer in octal\r
+ * <dt>s <dd> string\r
+ * <dt>c <dd> character\r
+ * </dl>\r
+ * </ul>\r
+ * @exception IllegalArgumentException if bad format\r
+ */\r
+\r
+ public Format(String s)\r
+ { width = 0;\r
+ precision = -1;\r
+ pre = "";\r
+ post = "";\r
+ leading_zeroes = false;\r
+ show_plus = false;\r
+ alternate = false;\r
+ show_space = false;\r
+ left_align = false;\r
+ fmt = ' '; \r
+ \r
+ int state = 0; \r
+ int length = s.length();\r
+ int parse_state = 0; \r
+ // 0 = prefix, 1 = flags, 2 = width, 3 = precision,\r
+ // 4 = format, 5 = end\r
+ int i = 0;\r
+ \r
+ while (parse_state == 0)\r
+ { if (i >= length) parse_state = 5;\r
+ else if (s.charAt(i) == '%')\r
+ { if (i < length - 1)\r
+ { if (s.charAt(i + 1) == '%')\r
+ { pre = pre + '%';\r
+ i++;\r
+ }\r
+ else\r
+ parse_state = 1;\r
+ }\r
+ else throw new java.lang.IllegalArgumentException();\r
+ }\r
+ else\r
+ pre = pre + s.charAt(i);\r
+ i++;\r
+ }\r
+ while (parse_state == 1)\r
+ { if (i >= length) parse_state = 5;\r
+ else if (s.charAt(i) == ' ') show_space = true;\r
+ else if (s.charAt(i) == '-') left_align = true; \r
+ else if (s.charAt(i) == '+') show_plus = true;\r
+ else if (s.charAt(i) == '0') leading_zeroes = true;\r
+ else if (s.charAt(i) == '#') alternate = true;\r
+ else { parse_state = 2; i--; }\r
+ i++;\r
+ } \r
+ while (parse_state == 2)\r
+ { if (i >= length) parse_state = 5;\r
+ else if ('0' <= s.charAt(i) && s.charAt(i) <= '9')\r
+ { width = width * 10 + s.charAt(i) - '0';\r
+ i++;\r
+ }\r
+ else if (s.charAt(i) == '.')\r
+ { parse_state = 3;\r
+ precision = 0;\r
+ i++;\r
+ }\r
+ else \r
+ parse_state = 4; \r
+ }\r
+ while (parse_state == 3)\r
+ { if (i >= length) parse_state = 5;\r
+ else if ('0' <= s.charAt(i) && s.charAt(i) <= '9')\r
+ { precision = precision * 10 + s.charAt(i) - '0';\r
+ i++;\r
+ }\r
+ else \r
+ parse_state = 4; \r
+ }\r
+ if (parse_state == 4) \r
+ { if (i >= length) parse_state = 5;\r
+ else fmt = s.charAt(i);\r
+ i++;\r
+ }\r
+ if (i < length)\r
+ post = s.substring(i, length);\r
+ } \r
+\r
+ /** \r
+ * prints a formatted number following printf conventions\r
+ * @param s a PrintStream\r
+ * @param fmt the format string\r
+ * @param x the double to print\r
+ */\r
+ \r
+ public static void print(java.io.PrintStream s, String fmt, double x)\r
+ { s.print(new Format(fmt).form(x));\r
+ }\r
+\r
+ /** \r
+ * prints a formatted number following printf conventions\r
+ * @param s a PrintStream\r
+ * @param fmt the format string\r
+ * @param x the long to print\r
+ */\r
+ public static void print(java.io.PrintStream s, String fmt, long x)\r
+ { s.print(new Format(fmt).form(x));\r
+ }\r
+\r
+ /** \r
+ * prints a formatted number following printf conventions\r
+ * @param s a PrintStream\r
+ * @param fmt the format string\r
+ * @param x the character to \r
+ */\r
+ \r
+ public static void print(java.io.PrintStream s, String fmt, char x)\r
+ { s.print(new Format(fmt).form(x));\r
+ }\r
+\r
+ /** \r
+ * prints a formatted number following printf conventions\r
+ * @param s a PrintStream, fmt the format string\r
+ * @param x a string that represents the digits to print\r
+ */\r
+ \r
+ public static void print(java.io.PrintStream s, String fmt, String x)\r
+ { s.print(new Format(fmt).form(x));\r
+ }\r
+ \r
+ /** \r
+ * Converts a string of digits (decimal, octal or hex) to an integer\r
+ * @param s a string\r
+ * @return the numeric value of the prefix of s representing a base 10 integer\r
+ */\r
+ \r
+ public static int atoi(String s)\r
+ { return (int)atol(s);\r
+ } \r
+ \r
+ /** \r
+ * Converts a string of digits (decimal, octal or hex) to a long integer\r
+ * @param s a string\r
+ * @return the numeric value of the prefix of s representing a base 10 integer\r
+ */\r
+ \r
+ public static long atol(String s)\r
+ { int i = 0;\r
+\r
+ while (i < s.length() && Character.isWhitespace(s.charAt(i))) i++;\r
+ if (i < s.length() && s.charAt(i) == '0')\r
+ { if (i + 1 < s.length() && (s.charAt(i + 1) == 'x' || s.charAt(i + 1) == 'X'))\r
+ return parseLong(s.substring(i + 2), 16);\r
+ else return parseLong(s, 8);\r
+ }\r
+ else return parseLong(s, 10);\r
+ }\r
+\r
+ private static long parseLong(String s, int base)\r
+ { int i = 0;\r
+ int sign = 1;\r
+ long r = 0;\r
+ \r
+ while (i < s.length() && Character.isWhitespace(s.charAt(i))) i++;\r
+ if (i < s.length() && s.charAt(i) == '-') { sign = -1; i++; }\r
+ else if (i < s.length() && s.charAt(i) == '+') { i++; }\r
+ while (i < s.length())\r
+ { char ch = s.charAt(i);\r
+ if ('0' <= ch && ch < '0' + base)\r
+ r = r * base + ch - '0';\r
+ else if ('A' <= ch && ch < 'A' + base - 10)\r
+ r = r * base + ch - 'A' + 10 ;\r
+ else if ('a' <= ch && ch < 'a' + base - 10)\r
+ r = r * base + ch - 'a' + 10 ;\r
+ else \r
+ return r * sign;\r
+ i++;\r
+ }\r
+ return r * sign; \r
+ }\r
+ \r
+ /** \r
+ * Converts a string of digits to an double\r
+ * @param s a string\r
+ */\r
+ \r
+ public static double atof(String s)\r
+ { int i = 0;\r
+ int sign = 1;\r
+ double r = 0; // integer part\r
+ double f = 0; // fractional part\r
+ double p = 1; // exponent of fractional part\r
+ int state = 0; // 0 = int part, 1 = frac part\r
+ \r
+ while (i < s.length() && Character.isWhitespace(s.charAt(i))) i++;\r
+ if (i < s.length() && s.charAt(i) == '-') { sign = -1; i++; }\r
+ else if (i < s.length() && s.charAt(i) == '+') { i++; }\r
+ while (i < s.length())\r
+ { char ch = s.charAt(i);\r
+ if ('0' <= ch && ch <= '9')\r
+ { if (state == 0)\r
+ r = r * 10 + ch - '0';\r
+ else if (state == 1)\r
+ { p = p / 10;\r
+ r = r + p * (ch - '0');\r
+ }\r
+ }\r
+ else if (ch == '.') \r
+ { if (state == 0) state = 1; \r
+ else return sign * r;\r
+ }\r
+ else if (ch == 'e' || ch == 'E')\r
+ { long e = (int)parseLong(s.substring(i + 1), 10);\r
+ return sign * r * Math.pow(10, e);\r
+ }\r
+ else return sign * r;\r
+ i++;\r
+ }\r
+ return sign * r;\r
+ }\r
+ \r
+ /** \r
+ * Formats a double into a string (like sprintf in C)\r
+ * @param x the number to format\r
+ * @return the formatted string \r
+ * @exception IllegalArgumentException if bad argument\r
+ */\r
+ \r
+ public String form(double x)\r
+ { String r;\r
+ if (precision < 0) precision = 6;\r
+ int s = 1;\r
+ if (x < 0) { x = -x; s = -1; }\r
+ if (fmt == 'f')\r
+ r = fixed_format(x);\r
+ else if (fmt == 'e' || fmt == 'E' || fmt == 'g' || fmt == 'G')\r
+ r = exp_format(x);\r
+ else throw new java.lang.IllegalArgumentException();\r
+ \r
+ return pad(sign(s, r));\r
+ }\r
+ \r
+ /** \r
+ * Formats a long integer into a string (like sprintf in C)\r
+ * @param x the number to format\r
+ * @return the formatted string \r
+ */\r
+ \r
+ public String form(long x)\r
+ { String r; \r
+ int s = 0;\r
+ if (fmt == 'd' || fmt == 'i')\r
+ { if (x < 0) \r
+ { r = ("" + x).substring(1);\r
+ s = -1; \r
+ }\r
+ else \r
+ { r = "" + x; \r
+ s = 1;\r
+ }\r
+ }\r
+ else if (fmt == 'o')\r
+ r = convert(x, 3, 7, "01234567");\r
+ else if (fmt == 'x')\r
+ r = convert(x, 4, 15, "0123456789abcdef");\r
+ else if (fmt == 'X')\r
+ r = convert(x, 4, 15, "0123456789ABCDEF");\r
+ else throw new java.lang.IllegalArgumentException();\r
+ \r
+ return pad(sign(s, r));\r
+ }\r
+ \r
+ /** \r
+ * Formats a character into a string (like sprintf in C)\r
+ * @param x the value to format\r
+ * @return the formatted string \r
+ */\r
+ \r
+ public String form(char c)\r
+ { if (fmt != 'c')\r
+ throw new java.lang.IllegalArgumentException();\r
+\r
+ String r = "" + c;\r
+ return pad(r);\r
+ }\r
+ \r
+ /** \r
+ * Formats a string into a larger string (like sprintf in C)\r
+ * @param x the value to format\r
+ * @return the formatted string \r
+ */\r
+ \r
+ public String form(String s)\r
+ { if (fmt != 's')\r
+ throw new java.lang.IllegalArgumentException();\r
+ if (precision >= 0 && precision < s.length()) \r
+ s = s.substring(0, precision);\r
+ return pad(s);\r
+ }\r
+ \r
+ \r
+ /**\r
+ * a test stub for the format class\r
+ */\r
+ \r
+ public static void main(String[] a)\r
+ { double x = 1.23456789012;\r
+ double y = 123;\r
+ double z = 1.2345e30;\r
+ double w = 1.02;\r
+ double u = 1.234e-5;\r
+ int d = 0xCAFE;\r
+ Format.print(System.out, "x = |%f|\n", x);\r
+ Format.print(System.out, "u = |%20f|\n", u);\r
+ Format.print(System.out, "x = |% .5f|\n", x);\r
+ Format.print(System.out, "w = |%20.5f|\n", w);\r
+ Format.print(System.out, "x = |%020.5f|\n", x);\r
+ Format.print(System.out, "x = |%+20.5f|\n", x);\r
+ Format.print(System.out, "x = |%+020.5f|\n", x);\r
+ Format.print(System.out, "x = |% 020.5f|\n", x);\r
+ Format.print(System.out, "y = |%#+20.5f|\n", y);\r
+ Format.print(System.out, "y = |%-+20.5f|\n", y);\r
+ Format.print(System.out, "z = |%20.5f|\n", z);\r
+ \r
+ Format.print(System.out, "x = |%e|\n", x);\r
+ Format.print(System.out, "u = |%20e|\n", u);\r
+ Format.print(System.out, "x = |% .5e|\n", x);\r
+ Format.print(System.out, "w = |%20.5e|\n", w);\r
+ Format.print(System.out, "x = |%020.5e|\n", x);\r
+ Format.print(System.out, "x = |%+20.5e|\n", x);\r
+ Format.print(System.out, "x = |%+020.5e|\n", x);\r
+ Format.print(System.out, "x = |% 020.5e|\n", x);\r
+ Format.print(System.out, "y = |%#+20.5e|\n", y);\r
+ Format.print(System.out, "y = |%-+20.5e|\n", y);\r
+ \r
+ Format.print(System.out, "x = |%g|\n", x);\r
+ Format.print(System.out, "z = |%g|\n", z);\r
+ Format.print(System.out, "w = |%g|\n", w);\r
+ Format.print(System.out, "u = |%g|\n", u);\r
+ Format.print(System.out, "y = |%.2g|\n", y);\r
+ Format.print(System.out, "y = |%#.2g|\n", y);\r
+\r
+ Format.print(System.out, "d = |%d|\n", d);\r
+ Format.print(System.out, "d = |%20d|\n", d); \r
+ Format.print(System.out, "d = |%020d|\n", d); \r
+ Format.print(System.out, "d = |%+20d|\n", d);\r
+ Format.print(System.out, "d = |% 020d|\n", d);\r
+ Format.print(System.out, "d = |%-20d|\n", d);\r
+ Format.print(System.out, "d = |%20.8d|\n", d);\r
+ Format.print(System.out, "d = |%x|\n", d); \r
+ Format.print(System.out, "d = |%20X|\n", d); \r
+ Format.print(System.out, "d = |%#20x|\n", d);\r
+ Format.print(System.out, "d = |%020X|\n", d);\r
+ Format.print(System.out, "d = |%20.8x|\n", d);\r
+ Format.print(System.out, "d = |%o|\n", d); \r
+ Format.print(System.out, "d = |%020o|\n", d); \r
+ Format.print(System.out, "d = |%#20o|\n", d);\r
+ Format.print(System.out, "d = |%#020o|\n", d);\r
+ Format.print(System.out, "d = |%20.12o|\n", d);\r
+ \r
+ Format.print(System.out, "s = |%-20s|\n", "Hello"); \r
+ Format.print(System.out, "s = |%-20c|\n", '!'); \r
+\r
+ // regression test to confirm fix of reported bugs\r
+\r
+ Format.print(System.out, "|%i|\n", Long.MIN_VALUE);\r
+\r
+ Format.print(System.out, "|%6.2e|\n", 0.0);\r
+ Format.print(System.out, "|%6.2g|\n", 0.0);\r
+\r
+ Format.print(System.out, "|%6.2f|\n", 9.99);\r
+ Format.print(System.out, "|%6.2f|\n", 9.999);\r
+\r
+ Format.print(System.out, "|%6.0f|\n", 9.999);\r
+ }\r
+ \r
+ private static String repeat(char c, int n)\r
+ { if (n <= 0) return "";\r
+ StringBuffer s = new StringBuffer(n);\r
+ for (int i = 0; i < n; i++) s.append(c);\r
+ return s.toString();\r
+ }\r
+\r
+ private static String convert(long x, int n, int m, String d)\r
+ { if (x == 0) return "0";\r
+ String r = "";\r
+ while (x != 0)\r
+ { r = d.charAt((int)(x & m)) + r;\r
+ x = x >>> n;\r
+ }\r
+ return r;\r
+ }\r
+\r
+ private String pad(String r)\r
+ { String p = repeat(' ', width - r.length());\r
+ if (left_align) return pre + r + p + post;\r
+ else return pre + p + r + post;\r
+ }\r
+ \r
+ private String sign(int s, String r)\r
+ { String p = "";\r
+ if (s < 0) p = "-"; \r
+ else if (s > 0)\r
+ { if (show_plus) p = "+";\r
+ else if (show_space) p = " ";\r
+ }\r
+ else\r
+ { if (fmt == 'o' && alternate && r.length() > 0 && r.charAt(0) != '0') p = "0";\r
+ else if (fmt == 'x' && alternate) p = "0x";\r
+ else if (fmt == 'X' && alternate) p = "0X";\r
+ }\r
+ int w = 0;\r
+ if (leading_zeroes) \r
+ w = width;\r
+ else if ((fmt == 'd' || fmt == 'i' || fmt == 'x' || fmt == 'X' || fmt == 'o') \r
+ && precision > 0) w = precision;\r
+ \r
+ return p + repeat('0', w - p.length() - r.length()) + r;\r
+ }\r
+ \r
+ private String fixed_format(double d)\r
+ { boolean removeTrailing\r
+ = (fmt == 'G' || fmt == 'g') && !alternate;\r
+ // remove trailing zeroes and decimal point\r
+\r
+ if (d > 0x7FFFFFFFFFFFFFFFL) return exp_format(d);\r
+ if (precision == 0) \r
+ return (long)(d + 0.5) + (removeTrailing ? "" : ".");\r
+\r
+ long whole = (long)d;\r
+ double fr = d - whole; // fractional part\r
+ if (fr >= 1 || fr < 0) return exp_format(d);\r
+\r
+ double factor = 1;\r
+ String leading_zeroes = "";\r
+ for (int i = 1; i <= precision && factor <= 0x7FFFFFFFFFFFFFFFL; i++) \r
+ { factor *= 10; \r
+ leading_zeroes = leading_zeroes + "0"; \r
+ }\r
+ long l = (long) (factor * fr + 0.5);\r
+ if (l >= factor) { l = 0; whole++; } // CSH 10-25-97\r
+ \r
+ String z = leading_zeroes + l;\r
+ z = "." + z.substring(z.length() - precision, z.length());\r
+\r
+ if (removeTrailing)\r
+ { int t = z.length() - 1;\r
+ while (t >= 0 && z.charAt(t) == '0') t--;\r
+ if (t >= 0 && z.charAt(t) == '.') t--;\r
+ z = z.substring(0, t + 1);\r
+ }\r
+\r
+ return whole + z;\r
+ }\r
+\r
+ private String exp_format(double d)\r
+ { String f = "";\r
+ int e = 0;\r
+ double dd = d;\r
+ double factor = 1;\r
+ if (d != 0)\r
+ { while (dd > 10) { e++; factor /= 10; dd = dd / 10; }\r
+ while (dd < 1) { e--; factor *= 10; dd = dd * 10; }\r
+ }\r
+ if ((fmt == 'g' || fmt == 'G') && e >= -4 && e < precision) \r
+ return fixed_format(d);\r
+ \r
+ d = d * factor;\r
+ f = f + fixed_format(d);\r
+ \r
+ if (fmt == 'e' || fmt == 'g')\r
+ f = f + "e";\r
+ else\r
+ f = f + "E";\r
+\r
+ String p = "000"; \r
+ if (e >= 0) \r
+ { f = f + "+";\r
+ p = p + e;\r
+ }\r
+ else\r
+ { f = f + "-";\r
+ p = p + (-e);\r
+ }\r
+ \r
+ return f + p.substring(p.length() - 3, p.length());\r
+ }\r
+ \r
+ private int width;\r
+ private int precision;\r
+ private String pre;\r
+ private String post;\r
+ private boolean leading_zeroes;\r
+ private boolean show_plus;\r
+ private boolean alternate;\r
+ private boolean show_space;\r
+ private boolean left_align;\r
+ private char fmt; // one of cdeEfgGiosxXos\r
+}\r
+\r
+\r
+\r
+\r
+\r
-/* examples for the jcifs smb client library in Java
- * Copyright (C) 2001 "Michael B. Allen" <mballen@erols.com>
- *
- * 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.SmbFileInputStream;
import java.io.FileOutputStream;
long t0 = System.currentTimeMillis();
- byte[] b = new byte[65535];
+ byte[] b = new byte[8192];
int n, tot = 0;
long t1 = t0;
- long t2;
while(( n = in.read( b )) > 0 ) {
out.write( b, 0, n );
tot += n;
System.out.print( '#' );
- t2 = System.currentTimeMillis();
- System.out.print( t2 - t1 + "" );
- t1 = t2;
}
long t = System.currentTimeMillis() - t0;
-/* examples for the jcifs smb client library in Java
- * Copyright (C) 2001 "Michael B. Allen" <mballen@erols.com>
- *
- * 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 java.util.Date;
import jcifs.smb.SmbFile;
import java.text.SimpleDateFormat;
--- /dev/null
+import jcifs.netbios.NbtAddress;
+import jcifs.smb.SmbFile;
+import jcifs.util.Log;
+import java.util.Date;
+
+public class GetType {
+
+ static final String[] types = { "TYPE_FILESYSTEM", "TYPE_WORKGROUP",
+ "TYPE_SERVER", "TYPE_SHARE", "TYPE_NAMED_PIPE", "TYPE_PRINTER", "TYPE_COMM" };
+
+ public static void main( String[] argv ) throws Exception {
+
+ SmbFile file = new SmbFile( argv[0] );
+ int type;
+
+ switch( file.getType() ) {
+ case SmbFile.TYPE_FILESYSTEM:
+ type = 0;
+ break;
+ case SmbFile.TYPE_WORKGROUP:
+ type = 1;
+ break;
+ case SmbFile.TYPE_SERVER:
+ type = 2;
+ break;
+ case SmbFile.TYPE_SHARE:
+ type = 3;
+ break;
+ case SmbFile.TYPE_NAMED_PIPE:
+ type = 4;
+ break;
+ case SmbFile.TYPE_PRINTER:
+ type = 5;
+ break;
+ case SmbFile.TYPE_COMM:
+ type = 6;
+ break;
+ default:
+ throw new RuntimeException( "Unknown service type: " + file.getType() );
+ }
+ System.out.println( types[type] );
+ System.out.println();
+
+ long t1 = System.currentTimeMillis();
+ String[] files = file.list();
+ long t2 = System.currentTimeMillis() - t1;
+
+ for( int i = 0; i < files.length; i++ ) {
+ System.out.print( " " + files[i] );
+ }
+ System.out.println();
+ System.out.println( files.length + " files in " + t2 + "ms" );
+ }
+}
-/* examples for the jcifs smb client library in Java
- * Copyright (C) 2001 "Michael B. Allen" <mballen@erols.com>
- *
- * 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 java.net.URL;
import java.io.InputStream;
System.in.read();
- Class.forName( "jcifs.Config" );
+ jcifs.Config.registerSmbURLHandler();
URL url = new URL( argv[0] );
InputStream in = url.openStream();
--- /dev/null
+import jcifs.smb.SmbFile;
+import jcifs.smb.SmbFileOutputStream;
+import java.io.FileInputStream;
+
+public class GrowWrite {
+
+ static final int SIZE = 0x4FFF;
+
+ public static void main( String argv[] ) throws Exception {
+ int n, tot;
+ byte[] buf = new byte[SIZE];
+ SmbFile f = new SmbFile( argv[0] );
+ SmbFileOutputStream out = new SmbFileOutputStream( f );
+
+ n = tot = 0;
+ do {
+ if(( n % 0x1F ) == 0) {
+ f = new SmbFile( argv[0] );
+ out = new SmbFileOutputStream( f );
+ System.out.print( '#' );
+ }
+ out.write( buf, 0, n );
+ out.flush();
+ tot += n;
+ } while( n++ < SIZE );
+
+ System.out.println();
+ System.out.println( tot + " bytes transfered." );
+ }
+}
-/* examples for the jcifs smb client library in Java
- * Copyright (C) 2001 "Michael B. Allen" <mballen@erols.com>
- *
- * 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.*;
public class Interleave {
-/* examples for the jcifs smb client library in Java
- * Copyright (C) 2001 "Michael B. Allen" <mballen@erols.com>
- *
- * 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.util.Log;
import jcifs.smb.SmbFile;
public class IsDir {
public static void main( String argv[] ) throws Exception {
- (new SmbFile( argv[0] )).isDirectory();
+ SmbFile f = new SmbFile( argv[0] );
+ System.out.println( f.isDirectory() );
}
}
-/* examples for the jcifs smb client library in Java
- * Copyright (C) 2001 "Michael B. Allen" <mballen@erols.com>
- *
- * 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;
public class Length {
-/* examples for the jcifs smb client library in Java
- * Copyright (C) 2001 "Michael B. Allen" <mballen@erols.com>
- *
- * 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.netbios.NbtAddress;
import jcifs.smb.SmbFile;
import jcifs.util.Log;
String[] files = file.list();
long t2 = System.currentTimeMillis() - t1;
- if( files != null ) {
- for( int i = 0; i < files.length; i++ ) {
- System.out.print( " " + files[i] );
- }
- System.out.println();
- System.out.println( files.length + " files in " + t2 + "ms" );
- } else {
- System.out.println( "no such file or directory" );
+ for( int i = 0; i < files.length; i++ ) {
+ System.out.print( " " + files[i] );
}
+ System.out.println();
+ System.out.println( files.length + " files in " + t2 + "ms" );
}
}
--- /dev/null
+import jcifs.netbios.NbtAddress;
+import jcifs.smb.SmbFile;
+import jcifs.util.Log;
+import java.util.Date;
+
+public class ListFiles {
+
+ public static void main( String[] argv ) throws Exception {
+
+ SmbFile file = new SmbFile( argv[0] );
+
+ long t1 = System.currentTimeMillis();
+ SmbFile[] files = file.listFiles();
+ long t2 = System.currentTimeMillis() - t1;
+
+ for( int i = 0; i < files.length; i++ ) {
+ System.out.print( " " + files[i].getName() );
+ }
+ System.out.println();
+ System.out.println( files.length + " files in " + t2 + "ms" );
+ }
+}
--- /dev/null
+import jcifs.netbios.NbtAddress;
+import jcifs.smb.SmbFile;
+import jcifs.util.Log;
+import java.util.Date;
+
+public class ListTypes {
+
+ public static void main( String[] argv ) throws Exception {
+
+ SmbFile file = new SmbFile( argv[0] );
+
+ long t1 = System.currentTimeMillis();
+ SmbFile[] files = file.listFiles();
+ long t2 = System.currentTimeMillis() - t1;
+
+ for( int i = 0; i < files.length; i++ ) {
+ System.out.print( " " + files[i].getName() );
+ switch(files[i].getType()) {
+ case SmbFile.TYPE_FILESYSTEM:
+ System.out.println( "[TYPE_FILESYSTEM]" );
+ break;
+ case SmbFile.TYPE_WORKGROUP:
+ System.out.println( "[TYPE_WORKGROUP]" );
+ break;
+ case SmbFile.TYPE_SERVER:
+ System.out.println( "[TYPE_SERVER]" );
+ break;
+ case SmbFile.TYPE_SHARE:
+ System.out.println( "[TYPE_SHARE]" );
+ break;
+ case SmbFile.TYPE_NAMED_PIPE:
+ System.out.println( "[TYPE_NAMEDPIPE]" );
+ break;
+ case SmbFile.TYPE_PRINTER:
+ System.out.println( "[TYPE_PRINTER]" );
+ break;
+ case SmbFile.TYPE_COMM:
+ System.out.println( "[TYPE_COMM]" );
+ break;
+ };
+ }
+ System.out.println( files.length + " files in " + t2 + "ms" );
+ }
+}
-/* examples for the jcifs smb client library in Java
- * Copyright (C) 2001 "Michael B. Allen" <mballen@erols.com>
- *
- * 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.util.Log;
public class LogTest {
--- /dev/null
+import jcifs.UniAddress;
+import jcifs.smb.SmbSession;
+import jcifs.smb.NtlmPasswordAuthentication;
+
+public class LogonTest {
+
+ public static void main( String argv[] ) throws Exception {
+ UniAddress dc = UniAddress.getByName( "miallen2" );
+ NtlmPasswordAuthentication good = new NtlmPasswordAuthentication( "mlamrs", "miallen", "ru_RUhrd" );
+ NtlmPasswordAuthentication bad = new NtlmPasswordAuthentication( "mlamrs", "miallen", "bogus" );
+ SmbSession.logon( dc, good );
+ System.out.println( "good" );
+ SmbSession.logon( dc, bad );
+ System.out.println( "bad" );
+ }
+}
+
-/* examples for the jcifs smb client library in Java
- * Copyright (C) 2001 "Michael B. Allen" <mballen@erols.com>
- *
- * 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.util.Log;
import jcifs.smb.SmbFile;
public class Mkdir {
- public static void main( String argv[] ) {
- try {
- (new SmbFile( argv[0] )).mkdir();
- } catch( Exception e ) {
- e.printStackTrace();
- }
+ public static void main( String argv[] ) throws Exception {
+ (new SmbFile( argv[0] )).mkdir();
}
}
--- /dev/null
+import jcifs.netbios.NbtAddress;
+
+public class NodeStatus {
+
+ public static void main( String argv[] ) throws Exception {
+ NbtAddress[] addrs = NbtAddress.getAllByAddress( argv[0] );
+ for( int i = 0; i < addrs.length; i++ ) {
+ System.out.println( addrs[i] );
+ }
+ }
+}
--- /dev/null
+import java.io.*;\r
+import javax.servlet.*;\r
+import javax.servlet.http.*;\r
+\r
+public class NtlmHttpAuthExample extends HttpServlet {\r
+\r
+ public void doGet( HttpServletRequest req,\r
+ HttpServletResponse resp ) throws IOException, ServletException {\r
+ PrintWriter out = resp.getWriter();\r
+\r
+ resp.setContentType( "text/html" );\r
+ out.println( "<HTML><HEAD><TITLE>NTLM HTTP Authentication Example</TITLE></HEAD><BODY>" );\r
+ out.println( "<h2>NTLM HTTP Authentication Example</h2>" );\r
+\r
+ out.println( req.getRemoteUser() + " successfully logged in" );\r
+\r
+ out.println( "<h3>Please submit some form data using POST</h3>" );\r
+ out.println( "<form action=\"NtlmHttpAuthExample\" method=\"post\">" );\r
+ out.println( "<input type=\"text\" name=\"field1\" size=\"20\"/>" );\r
+ out.println( "<input type=\"submit\"/>" );\r
+ out.println( "</form>" );\r
+\r
+ out.println( "field1 = " + req.getParameter( "field1" ));\r
+\r
+ out.println( "</BODY></HTML>" );\r
+ }\r
+ public void doPost( HttpServletRequest req,\r
+ HttpServletResponse resp ) throws IOException, ServletException {\r
+ doGet( req, resp );\r
+ }\r
+}\r
+\r
--- /dev/null
+import jcifs.smb.SmbFile;
+import jcifs.smb.SmbFileOutputStream;
+
+public class OpenExclusive {
+
+ public static void main( String argv[] ) throws Exception {
+ SmbFileOutputStream out;
+ SmbFile f = new SmbFile( argv[0], "", null, SmbFile.FILE_NO_SHARE );
+ out = new SmbFileOutputStream( f );
+System.in.read();
+ out.close();
+System.in.read();
+// OR
+ out = new SmbFileOutputStream( argv[1], SmbFile.FILE_NO_SHARE );
+System.in.read();
+ out.close();
+System.in.read();
+ }
+}
+
--- /dev/null
+import jcifs.smb.SmbNamedPipe;
+import java.io.OutputStream;
+import java.io.InputStream;
+import java.io.IOException;
+
+public class PeekNamedPipe {
+
+ static class ReceiverThread extends Thread {
+ InputStream in;
+ byte[] buf = new byte[20];
+ int n;
+
+ ReceiverThread( InputStream in ) {
+ this.in = in;
+ }
+ public void run() {
+ try {
+ while( true ) {
+ while(( n = in.available() ) == 0 ) {
+ System.out.println( "0 available" );
+ sleep( 3000 );
+ }
+ System.out.println( n + " available" );
+
+ if(( n = in.read( buf )) == -1 ) {
+ break;
+ }
+ System.out.println( new String( buf, 0, n ));
+ }
+ } catch( Exception e ) {
+ e.printStackTrace();
+ }
+ System.out.println( "run finished" );
+ }
+ }
+
+ public static void main( String[] argv ) throws Exception {
+ SmbNamedPipe pipe = new SmbNamedPipe( argv[0], SmbNamedPipe.PIPE_TYPE_RDWR );
+ InputStream in = pipe.getNamedPipeInputStream();
+ OutputStream out = pipe.getNamedPipeOutputStream();
+
+ ReceiverThread rt = new ReceiverThread( in );
+ rt.start();
+
+ StringBuffer sb = new StringBuffer();
+ String msg;
+ int c;
+ while(( c = System.in.read() ) != -1 ) {
+ if( c == '\n' ) {
+ msg = sb.toString();
+ if( msg.startsWith( "exi" )) {
+ break;
+ }
+ out.write( msg.getBytes() );
+ sb.setLength( 0 );
+ } else {
+ sb.append( (char)c );
+ }
+ }
+ in.close();
+ out.close();
+ }
+}
+
-/* examples for the jcifs smb client library in Java
- * Copyright (C) 2001 "Michael B. Allen" <mballen@erols.com>
- *
- * 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.SmbNamedPipe;
import java.io.OutputStream;
import java.io.InputStream;
-/* examples for the jcifs smb client library in Java
- * Copyright (C) 2001 "Michael B. Allen" <mballen@erols.com>
- *
- * 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;
import java.io.FileInputStream;
long t0 = System.currentTimeMillis();
- byte[] b = new byte[65535];
+ byte[] b = new byte[8192];
int n, tot = 0;
while(( n = in.read( b )) > 0 ) {
out.write( b, 0, n );
-/* examples for the jcifs smb client library in Java
- * Copyright (C) 2001 "Michael B. Allen" <mballen@erols.com>
- *
- * 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.netbios.NbtAddress;
import jcifs.UniAddress;
import java.net.InetAddress;
+++ /dev/null
-Many of these examples are quite wrong now that SmbFile methods throw
-SmbException. They will be cleaned up before 0.6 final.
-/* examples for the jcifs smb client library in Java
- * Copyright (C) 2001 "Michael B. Allen" <mballen@erols.com>
- *
- * 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;
public class RenameTo {
-/* examples for the jcifs smb client library in Java
- * Copyright (C) 2001 "Michael B. Allen" <mballen@erols.com>
- *
- * 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.SmbFileInputStream;
import java.io.FileOutputStream;
-/* examples for the jcifs smb client library in Java
- * Copyright (C) 2001 "Michael B. Allen" <mballen@erols.com>
- *
- * 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.SmbFileOutputStream;
public class SlowWrite {
-/* examples for the jcifs smb client library in Java
- * Copyright (C) 2001 "Michael B. Allen" <mballen@erols.com>
- *
- * 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 java.util.LinkedList;
import java.util.ListIterator;
return;
}
- String[] l = f.list();
+ SmbFile[] l = f.listFiles();
for(int i = 0; l != null && i < l.length; i++ ) {
try {
- SmbFile d = new SmbFile( f, l[i] );
for( int j = maxDepth - depth; j > 0; j-- ) {
System.out.print( " " );
}
- System.out.println( l[i] );
- if( d.isDirectory() ) {
- traverse( d, depth - 1 );
+ System.out.println( l[i] + " " + l[i].exists() );
+ if( l[i].isDirectory() ) {
+ traverse( l[i], depth - 1 );
}
} catch( IOException ioe ) {
System.out.println( l[i] + ": " + ioe.getMessage() );
/* examples for the jcifs smb client library in Java
- * Copyright (C) 2001 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* 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
*/
import jcifs.smb.*;
-import jcifs.util.AuthHandler;
-import jcifs.util.AuthInfo;
import java.net.UnknownHostException;
import java.net.MalformedURLException;
+import java.util.GregorianCalendar;
+import java.text.SimpleDateFormat;
+import java.util.Date;
-public class SmbShell implements AuthHandler {
+public class SmbShell extends NtlmAuthenticator {
+
+ protected NtlmPasswordAuthentication getNtlmPasswordAuthentication() {
+ System.out.println( getRequestingException().getMessage() +
+ " for " + getRequestingURL() );
+ System.out.print( "username: " );
+ try {
+ int i;
+ String username = readLine();
+ String domain = null, password;
+
+ if(( i = username.indexOf( '\\' )) != -1 ) {
+ domain = username.substring( 0, i );
+ username = username.substring( i + 1 );
+ }
+ System.out.print( "password: " );
+ password = readLine();
+ if( password.length() == 0 ) {
+ return null;
+ }
+ return new NtlmPasswordAuthentication( domain, username, password );
+ } catch( Exception e ) {
+ }
+ return null;
+ }
public static String readLine() throws Exception {
int c;
return sb.toString().trim();
}
- public boolean authenticate( AuthInfo authInfo ) {
- System.out.println( authInfo.exception.getMessage() + " on " + authInfo.target + " as " + authInfo.domain + "\\" + authInfo.username );
- System.out.print( " user: " );
- int i;
- try {
- String user = readLine();
- if((i = user.indexOf( '\\' )) != -1 ) {
- authInfo.domain = user.substring( 0, i );
- authInfo.username = user.substring( i + 1 );
- } else {
- authInfo.username = user;
- }
- System.out.print( "password: " );
- authInfo.password = readLine();
- if( authInfo.password.length() > 0 ) {
- return true;
- }
- } catch( Exception e ) {
- }
- return false;
+ String start;
+
+ public SmbShell( String start ) {
+ this.start = start;
+ NtlmAuthenticator.setDefault( this );
}
void run() throws Exception {
int c;
String cmd, prompt;
SmbFile conn, tmp;
+ SimpleDateFormat sdf1 = new SimpleDateFormat( "EEE MMM" );
+ SimpleDateFormat sdf2 = new SimpleDateFormat( "d" );
+ SimpleDateFormat sdf3 = new SimpleDateFormat( "yyyy h:mm a" );
+ sdf1.setCalendar( new GregorianCalendar() );
+ sdf2.setCalendar( new GregorianCalendar() );
+ sdf3.setCalendar( new GregorianCalendar() );
- SmbFile.setAuthHandler( this );
-
- conn = new SmbFile( "smb://" );
+ conn = new SmbFile( start );
while( true ) {
try {
if( conn.exists() ) {
- prompt = new SmbFile( conn.getCanonicalPath() ).getName() + "> ";
+ prompt = conn.getName() + "> ";
} else {
System.out.println( "error reading " + conn );
conn = new SmbFile( "smb://" );
conn = new SmbFile( "smb://" );
continue;
}
- tmp = new SmbFile( conn.getCanonicalPath(), dir );
+ tmp = new SmbFile( conn, dir );
if( tmp.exists() ) {
if( tmp.isDirectory() ) {
conn = tmp;
} else if( cmd.startsWith( "ls" )) {
int i = cmd.indexOf( ' ' );
SmbFile d = conn;
- String dir;
+ String dir, wildcard = "*";
if( i != -1 && (dir = cmd.substring( i ).trim()).length() != 0 ) {
- d = new SmbFile( conn, dir );
+ // there's an argument which could be a directory,
+ // a wildcard, or a directory with a wildcard appended
+ int s = dir.lastIndexOf( '/' );
+ int a = dir.lastIndexOf( '*' );
+ int q = dir.lastIndexOf( '?' );
+
+ if(( a != -1 && a > s ) || ( q != -1 && q > s )) {
+ // it's a wildcard
+ if( s == -1 ) {
+ wildcard = dir;
+ d = conn;
+ } else {
+ wildcard = dir.substring( s + 1 );
+ d = new SmbFile( conn, dir.substring( 0, s ));
+ }
+ } else {
+ d = new SmbFile( conn, dir );
+ }
}
- String[] list = d.list();
+ long t0 = System.currentTimeMillis();
+ SmbFile[] list = d.listFiles( wildcard );
+ t0 = System.currentTimeMillis() - t0;
if( list != null ) {
for( int j = 0; j < list.length; j++ ) {
- System.out.print( " " + list[j] );
+ StringBuffer sb = new StringBuffer();
+ Date date = new Date( list[j].lastModified() );
+ Format.print( System.out, "%-40s", list[j].getName() );
+ sb.append( list[j].isDirectory() ? 'd' : '-' );
+ sb.append( list[j].canRead() ? 'r' : '-' );
+ sb.append( list[j].canWrite() ? 'w' : '-' );
+ sb.append( list[j].isHidden() ? 'h' : '-' );
+ sb.append( list[j].getType() == SmbFile.TYPE_WORKGROUP ? 'g' : '-' );
+ Format.print( System.out, "%-6s", sb.toString() );
+ Format.print( System.out, "%10d ", list[j].length() );
+
+ System.out.print( sdf1.format( date ));
+ Format.print( System.out, "%3s ", sdf2.format( date ));
+ System.out.print( sdf3.format( date ));
+ System.out.println();
}
- System.out.println();
- System.out.println( list.length + " items" );
+ System.out.println( list.length + " items in " + t0 + "ms" );
} else {
System.out.println( "no such file or directory" );
}
} catch( MalformedURLException mue ) {
mue.printStackTrace();
conn = null;
+ } catch( SmbException se ) {
+ se.printStackTrace();
} catch( Exception e ) {
e.printStackTrace();
+ System.exit( 1 );
}
}
System.exit( 0 );
}
public static void main( String[] argv ) throws Exception {
- SmbShell smbsh = new SmbShell();
+ SmbShell smbsh = new SmbShell( argv.length > 0 ? argv[0] : "smb://" );
smbsh.run();
}
}
--- /dev/null
+/* examples for the jcifs smb client library in Java
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
+ *
+ * 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.util.*;
+import java.util.LinkedList;
+import java.util.ListIterator;
+import java.net.MalformedURLException;
+import java.io.IOException;
+
+public class T2Crawler {
+
+ class Semaphore {
+ private int value = 0;
+
+ Semaphore() {value = 0;}
+ Semaphore(int initial) {value = initial;}
+
+ public synchronized void P() {
+ value--;
+ if (value < 0) {
+ try {
+ wait();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public synchronized void V() {
+ value++;
+ notify();
+ }
+ }
+
+ class CrawlerThread extends Thread {
+ LinkedList list;
+ Semaphore sem;
+ SmbFile dir;
+ int depth;
+
+
+ CrawlerThread( SmbFile dir, Semaphore sem, int depth ) {
+ this.dir = dir;
+ list = new LinkedList();
+ list.add( dir );
+ this.sem = sem;
+ this.depth = depth;
+ }
+
+ public void run() {
+ SmbFile d;
+ SmbFile l[];
+
+ while( list.isEmpty() == false ) {
+ int i;
+ d = (SmbFile)list.remove( 0 );
+ try {
+ l = d.listFiles();
+
+/* This is flawed. It decrements depth too agressively and causes the
+ * thread to finish prematurely. I do not know of a way to fix this
+ * because there is no concept of a stack here.
+ */
+ depth--;
+ for( i = 0; i < l.length; i++ ) {
+ System.out.println( l[i] );
+ // if( depth++ > 0 && l[i].isDirectory() && !l[i].isHidden() ) {
+ if( depth > 0 && l[i].isDirectory() ) {
+ list.add( l[i] );
+ }
+ }
+ } catch( Exception e ) {
+ System.out.println( d );
+ e.printStackTrace();
+ }
+ }
+ sem.V();
+ }
+ }
+
+ T2Crawler( String dir, int numThreads, int depth ) throws Exception {
+ SmbFile top = new SmbFile( dir );
+ Semaphore sem = new Semaphore( numThreads );
+ SmbFile[] l = top.listFiles();
+ depth--;
+ for( int i = 0; i < l.length; i++ ) {
+ try {
+ System.out.println( l[i] );
+ if( !l[i].isDirectory() || l[i].isHidden() ) {
+ continue;
+ }
+ if( depth > 0 ) {
+ sem.P();
+ (new CrawlerThread( l[i], sem, depth )).start();
+ }
+ } catch( Exception e ) {
+ e.printStackTrace();
+ }
+ }
+ for( int i = 0; i < l.length; i++ ) {
+ l[i].canRead();
+ }
+ }
+ public static void main(String[] argv) throws Exception {
+ jcifs.util.Log.setMask( Log.EXCEPTIONS | 0x00010000 );
+ if( argv.length < 3) {
+ System.out.println( "$ java -Djcifs.properties=miallen.prp T2Crawler <dir> <num threads> <depth>");
+ System.exit(1);
+ }
+ new T2Crawler( argv[0], Integer.parseInt( argv[1] ), Integer.parseInt( argv[2] ));
+ }
+}
+++ /dev/null
-/* examples for the jcifs smb client library in Java
- * Copyright (C) 2001 "Michael B. Allen" <mballen@erols.com>
- *
- * 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 java.io.File;
-
-public class TestFile {
-
- public static void main( String argv[] ) throws Exception {
- File f = new File( argv[0] );
- System.out.println( "toString()=" + f.toString());
- System.out.println( "getCanonicalPath()=" + f.getCanonicalPath());
- System.out.println( "getName()=" + f.getName());
- System.out.println( "getParent()=" + f.getParent());
- System.out.println( "getPath()=" + f.getPath());
- System.out.println( "toURL().toString()=" + f.toURL().toString());
- System.out.println( "equals( " + argv[1] + " )=" + f.equals( new File( argv[1] )));
- }
-}
-
+++ /dev/null
-/* examples for the jcifs smb client library in Java
- * Copyright (C) 2001 "Michael B. Allen" <mballen@erols.com>
- *
- * 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 java.util.Date;
-import jcifs.smb.*;
-
-public class TestSmbFile {
-
- public static void main( String argv[] ) throws Exception {
- SmbFile f;
- if( argv.length == 1 ) {
- f = new SmbFile( argv[0] );
- } else {
- f = new SmbFile( argv[0], argv[1] );
- }
- System.out.println( "toString() : " + f.toString());
- System.out.println( "getCanonicalPath() : " + f.getCanonicalPath());
- System.out.println( "getName() : " + f.getName());
- System.out.println( "getParent() : " + f.getParent());
- System.out.println( "getPath() : " + f.getPath());
- System.out.println( "getServer() : " + f.getServer());
- System.out.println( "getShare() : " + f.getShare());
- System.out.println( "exists() : " + f.exists());
- System.out.println( "isDirectory() : " + f.isDirectory());
- System.out.println( "isFile() : " + f.isFile());
- System.out.println( "length() : " + f.length());
- System.out.println( "lastModified() : " + (new Date( f.lastModified() )));
- System.out.println( "isWorkgroup() : " + f.isWorkgroup());
-// System.out.println( "toURL().toString() : " + f.toURL().toString());
- if( argv.length > 2 ) {
- System.out.println( "equals( " + argv[1] + " )=" + f.equals( new SmbFile( argv[1] )));
- }
- }
-}
-
--- /dev/null
+import java.util.Date;
+import jcifs.smb.*;
+import java.io.*;
+
+public class TestSmbURL {
+
+ static void test( String url, String name ) throws Exception {
+ SmbFile f;
+
+ if( name == null ) name = "";
+
+ System.out.println( "INPUT[" + url + ", " + name + "]");
+ try {
+ f = new SmbFile( url, name );
+ } catch( Exception e ) {
+ e.printStackTrace();
+ return;
+ }
+
+ System.out.print( "toString() : " );
+ try {
+ System.out.println( f.toString() );
+ } catch( Exception e ) {
+ e.printStackTrace(); System.out.println();
+ }
+ System.out.print( "getCanonicalPath() : " );
+ try {
+ System.out.println( f.getCanonicalPath() );
+ } catch( Exception e ) {
+ e.printStackTrace(); System.out.println();
+ }
+ System.out.print( "getUncPath() : " );
+ try {
+ System.out.println( f.getUncPath() );
+ } catch( Exception e ) {
+ e.printStackTrace(); System.out.println();
+ }
+ System.out.print( "getName() : " );
+ try {
+ System.out.println( f.getName() );
+ } catch( Exception e ) {
+ e.printStackTrace(); System.out.println();
+ }
+ System.out.print( "getParent() : " );
+ try {
+ System.out.println( f.getParent() );
+ } catch( Exception e ) {
+ e.printStackTrace(); System.out.println();
+ }
+ System.out.print( "getPath() : " );
+ try {
+ System.out.println( f.getPath() );
+ } catch( Exception e ) {
+ e.printStackTrace(); System.out.println();
+ }
+ System.out.print( "getServer() : " );
+ try {
+ System.out.println( f.getServer() );
+ } catch( Exception e ) {
+ e.printStackTrace(); System.out.println();
+ }
+ System.out.print( "getShare() : " );
+ try {
+ System.out.println( f.getShare() );
+ } catch( Exception e ) {
+ e.printStackTrace(); System.out.println();
+ }
+ System.out.print( "exists() : " );
+ try {
+ System.out.println( f.exists() );
+ } catch( Exception e ) {
+ e.printStackTrace(); System.out.println();
+ }
+ System.out.print( "isDirectory() : " );
+ try {
+ System.out.println( f.isDirectory() );
+ } catch( Exception e ) {
+ e.printStackTrace(); System.out.println();
+ }
+ System.out.print( "isFile() : " );
+ try {
+ System.out.println( f.isFile() );
+ } catch( Exception e ) {
+ e.printStackTrace(); System.out.println();
+ }
+ System.out.print( "length() : " );
+ try {
+ System.out.println( f.length() );
+ } catch( Exception e ) {
+ e.printStackTrace(); System.out.println();
+ }
+ System.out.print( "lastModified() : " );
+ try {
+ System.out.println( (new Date( f.lastModified() )));
+ } catch( Exception e ) {
+ e.printStackTrace(); System.out.println();
+ }
+ System.out.print( "toURL().toString() : " );
+ try {
+ System.out.println( f.toURL() );
+ } catch( Exception e ) {
+ e.printStackTrace(); System.out.println();
+ }
+
+ System.in.read();
+ }
+
+ public static void main( String argv[] ) throws Exception {
+ String workgroup, server, share, path, file;
+
+ if( argv.length < 5 ) {
+ System.err.println( "TestSmbURL workgroup server share path file" );
+ System.exit( 1 );
+ }
+
+ workgroup = argv[0];
+ server = argv[1];
+ share = argv[2];
+ path = argv[3];
+ file = argv[4];
+
+/*
+ System.out.println();
+ System.out.println( "-- UNUSUAL --" );
+ System.out.println();
+ test( "smb://" + server, "../" + server + "/" + share );
+ test( "smb://foo", "../" + workgroup );
+ test( "smb://", ".." );
+*/
+
+ System.out.println();
+ System.out.println( "-- BASICS: ONE ARGUMENT --" );
+ System.out.println();
+ test( "smb://" + server + "/" + share + "/" + path + "/" + file, null );
+ test( "smb://" + server + "/" + share + "/" + path + "/", null );
+ test( "smb://" + server + "/" + share + "/", null );
+ test( "smb://" + server + "/", null );
+ test( "smb://" + workgroup + "/", null );
+ test( "smb://", null );
+
+ System.out.println();
+ System.out.println( "-- BASICS: TWO ARGUMENTS --" );
+ System.out.println();
+ test( "smb://" + server + "/" + share + "/" + path + "/", file);
+ test( "smb://" + server + "/" + share + "/", path + "/" + file);
+ test( "smb://" + server + "/", share + "/" + path + "/" + file);
+ test( "smb://", server + "/" + share + "/" + path + "/" + file);
+ test( "smb://", "smb://" + server + "/" + share + "/" + path + "/" + file);
+ test( "smb://", "smb://" + server + "/");
+ test( "smb://", "smb://" + workgroup + "/");
+ test( "smb://", "smb://");
+ test( "smb://" + server + "/share/", "smb://");
+
+ System.out.println();
+ System.out.println( "-- CANONICALIZATION --" );
+ System.out.println();
+ test( "smb://" + server + "/" + share + "/foo/../" + path + "/" + file, null );
+ test( "smb://" + server + "/foo/bar/.././../" + share + "/" + path + "/" + file, null );
+ test( "smb://" + server + "/foo/bar/.././.././" + share + "/fake/../" + path + "/" + file, null );
+ test( "smb://" + server + "/foo/bar/.././.././", share + "/fake/../" + path + "/" + file);
+ test( "smb://", server + "/foo/bar/.././.././" + share + "/fake/../" + path + "/" + file);
+ }
+}
+
--- /dev/null
+import java.io.*;
+import jcifs.smb.*;
+import jcifs.util.*;
+
+public class TestUnicode {
+ static SmbFile dir;
+
+ public static void mkobj( String name ) throws Exception {
+ int r = (int)(Math.random() * 100.0);
+ if( r < 50 ) {
+ SmbFile d = new SmbFile( dir.getParent(), dir.getName() + "/" + name );
+ d.mkdir();
+ if( r < 15 ) {
+ dir = d;
+ }
+ } else {
+ SmbFileOutputStream out = new SmbFileOutputStream( dir.getParent() + "/" + dir.getName() + "/" + name );
+ out.close();
+ }
+ }
+
+ public static void main( String argv[] ) throws Exception {
+ if( argv.length < 1 ) {
+ throw new IllegalArgumentException( "Must provide path to directory in which to run test" );
+ }
+ FileInputStream in = new FileInputStream( "data" );
+ byte[] b = new byte[4096];
+ int n = in.read( b );
+ String data = new String( b, 0, n, "UTF-8" );
+ char[] d = data.toCharArray();
+
+ dir = new SmbFile( argv[0] + "/TestUnicode" );
+ try {
+ dir.delete();
+ } catch( SmbException se ) {
+ se.printStackTrace();
+ }
+ dir.mkdir();
+
+ int i, s, max = 8;
+ for( i = s = 0; i < d.length; i++ ) {
+ switch (d[i]) {
+ case '"': case '/': case '\\': case '[': case ']':
+ case ':': case '|': case '<': case '>': case '=':
+ case ';': case ',': case '*': case '?': case '\n':
+ d[i] = '_';
+ }
+ if(Character.isWhitespace( d[i] )) {
+ if( i == s ) {
+ s++;
+ }
+ if( i > (s + max)) {
+ String name = new String( d, s, i - s );
+ mkobj( name );
+ s = i + 1;
+ }
+ }
+ }
+ }
+}
--- /dev/null
+import jcifs.netbios.*;
+
+public class ThreadedNbtQuery {
+
+ static class QThread extends Thread {
+ String name;
+
+ QThread( String name ) {
+ this.name = name;
+ }
+
+ public void run() {
+ try {
+ yield();
+ System.out.println( getName() + ": started" );
+ NbtAddress.getByName( name );
+ System.out.println( getName() + ": done" );
+ } catch( Exception x ) {
+ x.printStackTrace();
+ }
+ }
+ }
+
+ public static void main(String[] argv) throws Exception {
+ if( argv.length < 2 ) {
+ System.out.println( "java ThreadedNbtQuery name [name [name [...]]]" );
+ return;
+ }
+
+ QThread[] t = new QThread[argv.length];
+ for( int i = 0; i < argv.length; i++ ) {
+ t[i] = new QThread( argv[i] );
+ }
+ for( int j = 0; j < argv.length; j++ ) {
+ t[j].start();
+ }
+ }
+}
/* examples for the jcifs smb client library in Java
- * Copyright (C) 2001 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* 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
public class ThreadedSmbCrawler {
- static long time;
+ static int workingThreads = 0;
class DirEntry {
SmbFile dir;
StringBuffer sb = new StringBuffer();
- SmbCrawlerThread() {
- }
-
public void run() {
while( true ) {
try {
DirEntry e;
synchronized( dirList ) {
-time = System.currentTimeMillis();
while( dirList.isEmpty() ) {
- dirList.wait( 500 );
+System.err.println( "workingThreads=" + workingThreads );
+ if( workingThreads == 0 ) {
+ return; // done
+ }
+ dirList.wait( 2000 );
}
e = (DirEntry)dirList.remove( 0 );
- }
-
- if( e.depth == 0 ) {
- continue;
+ if( e.depth == 0 ) {
+ continue;
+ }
+ workingThreads++;
}
String[] l = e.dir.list();
sb.append( " " );
}
SmbFile d = new SmbFile( e.dir, l[i] );
- System.out.println( sb.append( d ));
+ System.err.println( sb.append( d ));
if( d.isDirectory() ) {
synchronized( dirList ) {
dirList.add( new DirEntry( d, e.depth - 1 ));
ioe.printStackTrace();
}
}
+ synchronized( dirList ) {
+ workingThreads--;
+ }
} catch( Exception x ) {
+ synchronized( dirList ) {
+ workingThreads--;
+ }
x.printStackTrace();
}
}
}
LinkedList dirList;
- int maxDepth;
+ int maxDepth, numThreads;
+ Thread[] threads;
ThreadedSmbCrawler( String dir, int maxDepth, int numThreads ) throws Exception {
this.maxDepth = maxDepth;
+ this.numThreads = numThreads;
+ threads = new Thread[numThreads];
dirList = new LinkedList();
dirList.add( new DirEntry( new SmbFile( dir ), maxDepth ));
- for( int i = 0; i < numThreads; i++ ) {
- (new SmbCrawlerThread()).start();
+ }
+
+ long go() throws Exception {
+ int i;
+ long start = System.currentTimeMillis();
+
+ for( i = 0; i < numThreads; i++ ) {
+ threads[i] = new SmbCrawlerThread();
+ threads[i].start();
}
+ for( i = 0; i < numThreads; i++ ) {
+ threads[i].join();
+ }
+
+ return System.currentTimeMillis() - start;
}
public static void main(String[] argv) throws Exception {
+ ThreadedSmbCrawler tsc;
+
if( argv.length < 3 ) {
- System.out.println( "usage: ThreadedSmbCrawler dir depth numThreads" );
- return;
+ System.err.println( "usage: ThreadedSmbCrawler dir depth numThreads" );
+ System.exit( 1 );
}
- Log.setMask( Log.CRITICAL_EXCEPTIONS );
-long start = System.currentTimeMillis();
- new ThreadedSmbCrawler( argv[0], Integer.parseInt( argv[1] ), Integer.parseInt( argv[2] ));
-System.in.read();
-System.out.println( "time=" + (time - start) + "ms" );
+
+ tsc = new ThreadedSmbCrawler( argv[0], Integer.parseInt( argv[1] ), Integer.parseInt( argv[2] ));
+ System.err.println( "Crawling Complete: " + (tsc.go() / 1000 / 60) + "min" );
}
}
--- /dev/null
+import java.net.UnknownHostException;
+import jcifs.*;
+
+public class ThreadedUniQuery {
+
+ static class QThread extends Thread {
+ String name;
+
+ QThread( String name ) {
+ super( name + "-thread" );
+ this.name = name;
+ }
+
+ public void run() {
+ try {
+ System.out.println( getName() + ": started" );
+ for( int i = 0; i < 15; i++ ) {
+ Thread.sleep( (long)(Math.random() * 1000L ));
+ try {
+ UniAddress.getByName( name, true );
+ } catch( UnknownHostException uhe ) {
+ uhe.printStackTrace();
+ }
+ }
+ System.out.println( getName() + ": done" );
+ } catch( Exception x ) {
+ x.printStackTrace();
+ }
+ }
+ }
+
+ public static void main(String[] argv) throws Exception {
+ if( argv.length < 2 ) {
+ System.out.println( "java ThreadedUniQuery name [name [name [...]]]" );
+ return;
+ }
+
+ QThread[] t = new QThread[argv.length];
+ for( int i = 0; i < argv.length; i++ ) {
+ t[i] = new QThread( argv[i] );
+ }
+ for( int j = 0; j < argv.length; j++ ) {
+ t[j].start();
+ }
+ for( int j = 0; j < argv.length; j++ ) {
+ t[j].join();
+ }
+ Runtime.getRuntime().exit(0);
+ }
+}
--- /dev/null
+import java.io.*;
+import jcifs.smb.*;
+import java.util.*;
+
+class Worker extends Thread {
+
+ Torture1 t;
+ Exception e;
+
+ Worker( Torture1 t ) {
+ this.t = t;
+ e = null;
+ }
+ public void run() {
+ try {
+ t.torture();
+ } catch( Exception e ) {
+ this.e = e;
+ }
+ }
+}
+
+public class Torture1 {
+
+ Properties prp;
+
+ Torture1( Properties prp ) {
+ this.prp = prp;
+ }
+
+ void compare( SmbFile f1, SmbFile f2 ) throws Exception {
+ if( f1.isDirectory() && f2.isDirectory() ) {
+ SmbFile[] dirents = f1.listFiles();
+ SmbFile f;
+ for( int i = 0; i < dirents.length; i++ ) {
+ f = new SmbFile( f2, dirents[i].getName() );
+ compare( dirents[i], f );
+ }
+ }
+ if( f1.isDirectory() != f2.isDirectory() ) {
+ System.err.println( "directory comparison failed" );
+ }
+ if( f1.isFile() != f2.isFile() ) {
+ System.err.println( "file comparison failed" );
+ }
+ if( f1.getType() != f2.getType() ) {
+ System.err.println( "type comparison failed" );
+ }
+ if( f1.getName().equals( f2.getName() ) == false ) {
+ System.err.println( "name comparison failed: " + f1.getName() + " " + f2.getName() );
+ }
+ if( f1.length() != f2.length() ) {
+ System.err.println( "length comparison failed: " + f1.length() + " " + f2.length() );
+ }
+ }
+
+ void torture() throws Exception {
+ String domain, username, password, server, share, directory;
+ NtlmPasswordAuthentication ntlm;
+
+ domain = prp.getProperty( "torture.dst.domain" );
+ username = prp.getProperty( "torture.dst.username" );
+ password = prp.getProperty( "torture.dst.password" );
+
+ ntlm = new NtlmPasswordAuthentication( domain, username, password );
+
+ server = prp.getProperty( "torture.dst.server" );
+ share = prp.getProperty( "torture.dst.share" );
+ directory = prp.getProperty( "torture.dst.directory" );
+
+ SmbFile dst = new SmbFile( "smb://", ntlm );
+ dst = new SmbFile( dst, server );
+ dst = new SmbFile( dst, share );
+ dst = new SmbFile( dst, directory );
+
+ SmbFile src = new SmbFile( prp.getProperty( "torture.src.url" ));
+
+System.err.println( src + " --> " + dst );
+System.in.read();
+
+ if( dst.exists() ) {
+ dst.delete();
+ }
+ src.copyTo( dst );
+System.err.println( "CopyTo done" );
+System.in.read();
+ compare( src, dst );
+System.err.println( "Test Complete" );
+ }
+
+ public static void main( String[] argv ) throws Exception {
+ Properties prp = new Properties();
+ prp.load( new FileInputStream( "torture.prp" ));
+ Torture1 t = new Torture1( prp );
+ Worker w = new Worker( t );
+ w.start();
+ w.join();
+ if( w.e != null ) {
+ throw w.e;
+ }
+ }
+}
--- /dev/null
+import java.io.*;
+import jcifs.smb.*;
+import java.util.*;
+
+public class Torture2 extends Thread {
+
+ SmbFile from, to;
+
+ Torture2( String from, String to ) throws Exception {
+ this.from = new SmbFile( from );
+ this.to = new SmbFile( to );
+ }
+
+ public void run() {
+ try {
+ copyAndVerify();
+ } catch( Exception e ) {
+ e.printStackTrace();
+ }
+ }
+
+ void compare( SmbFile f1, SmbFile f2 ) throws Exception {
+//System.err.println( f1.getName() + " | " + f2.getName() );
+try {
+ if( f1.isDirectory() && f2.isDirectory() ) {
+ SmbFile[] dirents = f1.listFiles();
+ SmbFile f;
+ for( int i = 0; i < dirents.length; i++ ) {
+ f = new SmbFile( f2, dirents[i].getName() );
+//System.err.println( f2 + " + " + dirents[i].getName() + " = " + f + ": isDirectory=" + f.isDirectory() );
+ compare( dirents[i], f );
+ }
+ }
+ if( f1.isDirectory() != f2.isDirectory() ) {
+ System.err.println( "directory comparison failed: " + f1.isDirectory() + " " + f2.isDirectory() );
+ }
+ if( f1.isFile() != f2.isFile() ) {
+ System.err.println( "file comparison failed: " + f1.isFile() + " " + f2.isFile() );
+ }
+ if( f1.getType() != f2.getType() ) {
+ System.err.println( "type comparison failed: " + f1.getName() + " " + f2.getName() );
+ }
+ if( f1.getName().equals( f2.getName() ) == false ) {
+ System.err.println( "name comparison failed: " + f1.getName() + " " + f2.getName() );
+ }
+ if( f1.length() != f2.length() ) {
+ System.err.println( "length comparison failed: " + f1.length() + " " + f2.length() );
+ }
+} catch( Exception x ) {
+ System.err.println( "Exception comparing: " + f1 + " | " + f2 );
+ x.printStackTrace();
+}
+ }
+
+ void copyAndVerify() throws Exception {
+ from.copyTo( to );
+ compare( from, to );
+ }
+
+ public static void main( String[] argv ) throws Exception {
+ Properties prp;
+ Torture2[] threads;
+ String from, to;
+ int i;
+
+ if( argv.length < 1 ) {
+ System.err.println( "Torture2 <properties file>" );
+ System.exit( 1 );
+ }
+
+ prp = new Properties();
+ prp.load( new FileInputStream( argv[0] ));
+
+ threads = new Torture2[10];
+
+ for( i = 0; i < 10; i++ ) {
+ from = prp.getProperty( "thread." + i + ".from.url" );
+ to = prp.getProperty( "thread." + i + ".to.url" );
+ if( from == null || to == null ) {
+ break;
+ }
+ threads[i] = new Torture2( from, to );
+ threads[i].start();
+ Thread.sleep( 12345 );
+ }
+ while( i-- > 0 ) {
+ threads[i].join();
+ }
+ System.err.println( "Test complete" );
+ }
+}
+
+++ /dev/null
-/* examples for the jcifs smb client library in Java
- * Copyright (C) 2001 "Michael B. Allen" <mballen@erols.com>
- *
- * 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 java.util.*;
-import jcifs.smb.*;
-
-class TortureTest3 {
-
- static final int NUM_OF_THREADS = 4;
-
- java.util.List dirList;
-
- TortureTest3() throws Exception {
- dirList = Collections.synchronizedList( new LinkedList());
- }
-
- void execute() {
- for( int i = 0; i < NUM_OF_THREADS; i++ ) {
- Thread t = new Worker( this );
- t.start();
- }
- }
-
- class Worker extends Thread {
- TortureTest3 con;
- int count = 0;
-
- Worker( TortureTest3 con ) {
- this.con = con;
- }
-
- public void run() {
- try {
- SmbFile dir, file;
- String[] list;
- while( true ) {
- synchronized( con.dirList ) {
- while( con.dirList.isEmpty() ) {
- con.dirList.wait( 100 );
- System.out.println( "name=" + getName() + ",count=" + count );
- }
- dir = (SmbFile)con.dirList.remove( 0 );
- }
- list = dir.list();
- for( int i = 0; i < list.length; i++ ) {
- file = new SmbFile( dir, list[i] );
- if( file.isDirectory() ) {
- synchronized( con.dirList ) {
- con.dirList.add( file );
- con.dirList.notify();
- }
- System.out.println( "d " + file );
- } else {
- count++;
- System.out.println( " " + file );
- }
- }
- }
- } catch( Exception e ) {
- e.printStackTrace();
- }
- }
- }
-
- public static void main( String argv[] ) throws Exception {
- TortureTest3 con = new TortureTest3();
- con.dirList.add( new SmbFile( argv[0] ));
- con.execute();
- }
-}
-
+++ /dev/null
-/* examples for the jcifs smb client library in Java
- * Copyright (C) 2001 "Michael B. Allen" <mballen@erols.com>
- *
- * 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.*;
-import jcifs.netbios.NbtAddress;
-import jcifs.util.*;
-import java.util.Enumeration;
-
-public class TortureTest4 extends Thread {
-
- String url;
- SmbFile file;
-
- TortureTest4( String domain,
- String username,
- String password,
- String server,
- String share ) {
-
- StringBuffer sb = new StringBuffer( "smb://" );
-
- if( username != null ) {
- if( domain != null ) {
- sb.append( domain ).append( ';' );
- }
- sb.append( username );
- if( password != null ) {
- sb.append( ':' ).append( password );
- }
- sb.append( '@' );
- }
- sb.append( server + "/" + share + "/foo.txt" );
-
- url = sb.toString();
- }
-
- public void run() {
- try {
-System.out.println( "url=" + url );
- file = new SmbFile( url );
- file.exists();
- } catch( Exception e ) {
- e.printStackTrace();
- }
- }
-
- public static void main( String[] argv ) throws Exception {
- Thread[] threads = new Thread[5];
- String key;
- Object val;
- PropertiesTree shares = (PropertiesTree)jcifs.Config.get( argv[0] );
- String server = shares.getProperty( "server" );
- int i = 0;
- for( Enumeration e = shares.keys(); e.hasMoreElements(); ) {
- key = (String)e.nextElement();
- val = shares.get( key );
- if( val instanceof PropertiesTree ) {
- threads[i++] = new TortureTest4( shares.getProperty( key + ".domain" ),
- shares.getProperty( key + ".username" ),
- shares.getProperty( key + ".password" ),
- server,
- key );
- }
- }
- for( int t = 0; t < i; t++ ) {
- threads[t].start();
- }
- for( int j = 0; j < i; j++ ) {
- threads[j].join();
- }
- System.exit( 0 );
- }
-}
-/* examples for the jcifs smb client library in Java
- * Copyright (C) 2001 "Michael B. Allen" <mballen@erols.com>
- *
- * 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.netbios.*;
+import jcifs.UniAddress;
import java.util.Enumeration;
public class TortureTest5 extends Thread {
public void run() {
try {
- System.out.println( NbtAddress.getByName( name ));
+ System.out.println( UniAddress.getByName( name ));
} catch( Exception e ) {
e.printStackTrace();
}
-/* examples for the jcifs smb client library in Java
- * Copyright (C) 2001 "Michael B. Allen" <mballen@erols.com>
- *
- * 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.SmbNamedPipe;
import java.io.InputStream;
import java.io.OutputStream;
--- /dev/null
+import java.net.*;
+import java.util.*;
+
+public class URLTest {
+
+ public static void main( String[] argv ) throws Exception {
+ URL url;
+
+ jcifs.Config.registerSmbURLHandler();
+
+ if( argv.length > 2 ) {
+ url = new URL( new URL( new URL( argv[0] ), argv[1] ), argv[2] );
+ } else if( argv.length > 1 ) {
+ url = new URL( new URL( argv[0] ), argv[1] );
+ } else {
+ url = new URL( argv[0] );
+ }
+ System.out.println( " authority: " + url.getAuthority() );
+ System.out.println( " file: " + url.getFile() );
+ System.out.println( " host: " + url.getHost() );
+ System.out.println( " port: " + url.getPort() );
+ System.out.println( " path: " + url.getPath() );
+ System.out.println( " query: " + url.getQuery() );
+ System.out.println( " ref: " + url.getRef() );
+ System.out.println( " userinfo: " + url.getUserInfo() );
+ System.out.println( "externalform: " + url.toExternalForm() );
+ System.out.println( " string: " + url.toString() );
+
+ System.exit( 0 );
+ }
+}
--- /dev/null
+import java.net.MalformedURLException;
+import jcifs.smb.*;
+import java.io.*;
+
+public class VerifyIO {
+
+ static File get( SmbFile f0 ) throws Exception {
+ int i;
+ File f1;
+ byte[] buf = new byte[8192];
+
+ f1 = new File( f0.getName() );
+ FileOutputStream out = new FileOutputStream( f1 );
+ SmbFileInputStream in = new SmbFileInputStream( f0 );
+
+ while(( i = in.read( buf )) > 0 ) {
+ out.write( buf, 0, i );
+ System.err.print( '.' );
+ }
+
+ in.close();
+ out.close();
+
+ return f1;
+ }
+ static void put( SmbFile f2 ) throws Exception {
+ int i;
+ byte[] buf = new byte[8192];
+
+ FileInputStream in = new FileInputStream( f2.getName() );
+ SmbFileOutputStream out = new SmbFileOutputStream( f2 );
+
+ while(( i = in.read( buf )) > 0 ) {
+ out.write( buf, 0, i );
+ System.err.print( '-' );
+ }
+
+ in.close();
+ out.close();
+ }
+
+ public static void main(String[] argv) throws Exception {
+ BufferedReader in;
+ String name;
+
+ if( argv.length < 2 ) {
+ System.err.println( "Must provide file of SMB URLs and destination directory" );
+ System.exit( 1 );
+ }
+
+ in = new BufferedReader( new FileReader( argv[0] ));
+ while(( name = in.readLine() ) != null ) {
+ SmbFile f0, f2;
+ File f1;
+
+ System.err.print( name + ": " );
+ f0 = new SmbFile( name );
+ f1 = get( f0 );
+
+ if( f0.length() != f1.length() ) {
+ throw new RuntimeException( "File lengths do not match: f0=" + f0.length() + ",f1=" + f1.length() );
+ }
+
+ f2 = new SmbFile( argv[1] + "/" + f0.getName() );
+ put( f2 );
+
+ if( f1.length() != f2.length() ) {
+ throw new RuntimeException( "File lengths do not match: f1=" + f1.length() + ",f2=" + f2.length() );
+ }
+
+ f1.delete();
+ System.err.println( " ok" );
+ }
+ }
+}
+
--- /dev/null
+import java.net.MalformedURLException;
+import jcifs.smb.*;
+import java.io.*;
+
+public class VerifyReads {
+
+ int maxDepth;
+ byte[] buf = new byte[8192];
+
+ VerifyReads( int maxDepth ) {
+ this.maxDepth = maxDepth;
+ }
+
+ void mkdir( File dir ) {
+ if( dir != null && !dir.exists() ) {
+ mkdir( dir.getParentFile() );
+ dir.mkdir();
+ }
+ }
+
+ void copy( SmbFile f, String path, int depth ) throws MalformedURLException, IOException {
+ int i, d;
+ File localFile, dir;
+ SmbFile[] list;
+
+ if( depth == 0 ) {
+ return;
+ }
+
+ localFile = new File( path + "/" + f.getName() );
+ d = f.getName().lastIndexOf( '.' );
+
+ if( f.isDirectory() ) {
+
+ list = f.listFiles();
+
+ for( i = 0; i < list.length; i++ ) {
+ copy( list[i], path + "/" + f.getName(), depth - 1 );
+ }
+ } else if( d > 1 && f.getName().substring( d ).equalsIgnoreCase( ".ini" )) {
+
+ mkdir( new File( path ));
+
+ SmbFileInputStream in = new SmbFileInputStream( f );
+ FileOutputStream out = new FileOutputStream( localFile );
+
+ while(( i = in.read( buf )) > 0 ) {
+ out.write( buf, 0, i );
+ }
+
+ in.close();
+ out.close();
+ }
+ }
+
+ public static void main(String[] argv) throws Exception {
+ VerifyReads cd;
+ SmbFile top;
+ int depth;
+
+ if( argv.length < 2 ) {
+ System.err.println( "Must specify ini directory location (e.g. smb://mlamrs\\;rschprod:grispass@rsch-nyc-19b9/vendorapps) followd by the maximum traversal depth");
+ System.exit( 1 );
+ }
+
+ depth = Integer.parseInt( argv[1] );
+ cd = new VerifyReads( depth );
+ top = new SmbFile( argv[0] );
+
+ if( !top.isDirectory() ) {
+ System.err.println( "The path specified is not a directory" );
+ System.exit( 1 );
+ }
+
+ cd.copy( top, ".", depth );
+ }
+}
+
--- /dev/null
+Unë mund të ha qelq dhe nuk më gjen gjë
+⡌⠁⠧⠑ ⠼⠁⠒ ⡍⠜⠇⠑⠹⠰⠎ ⡣⠕⠌
+Mi povas manĝi vitron, ĝi ne damaĝas min
+yoyo seti @ home Tarzan + Jane Barnum & Baley
+J'peux bouffer d'la vitre, ça m'fa pas mal
+Dji pou magnî do vêre, çoula m' freut nén må
+которая состоится 10-12 марта 1997 года в Майнце в Германии
+Pot să mănânc sticlă și ea nu mă rănește
+Tá mé in ann gloine a ithe; Ní chuireann sé isteach nó amach orm
+Μπορώ να φάω σπασμένα γυαλιά χωρίς να πάθω τίποτα
+Èg get borðað gler, það meiðir mig ekki
+Я можу їсти шкло, й воно мені не пошкодить
+אני יכול לאכול זכוכית וזה לא מזיק לי
+Mo lè je̩ dígí, kò ní pa mí lára
+Μπορώ να φάω σπασμένα να γυαλιά χωρίς να πάθω τίποτα
+Èg get borðað gler, það meiðir mig ekki
+Я можу їсти шкло, й воно мені не пошкодить
-# example jcifs properties tree file
-;baddr=192.168.1.255
-;domain=foo
-username=me
-password=bar
-;wins=146.123.82.22
-;log=all
+domain=rsch
+username=miallen
+password=Fa!e@s
+;wins=169.249.100.243
+wins=146.125.56.78
+;log=ALL
+;resolveOrder=WINS
+;soTimeout=3000
--- /dev/null
+! Lookup any domain contorller in the FOONET<1C> domain
+
+;domain=foonet
+
+! Or explicitly specify any SMB server to use as a
+! "Domain Controller". This could be a real PDC or
+! preferrably a BDC or just a plain workstation
+
+domainController=192.168.1.15
+
+! WINS server is only necessary if you are using the
+! jcifs.smb.client.domain property to lookup a domain
+! controller
+
+;wins=136.135.65.85
+
+! On machines with multiple interfaces it is usually
+! necessary to set the broadcast address. See the jCIFS FAQ.
+
+baddr=192.168.1.255
+
+! If we're sure we have a WINS server this is a
+! little more direct
+
+;resolveOrder=WINS
+
+! Users will have to re-authenticate after 600000ms
+! (10 minutes) if no clients trigger activity on the socket
+! to the domain controller
+
+soTimeout=600000
+
+! Uncomment this if it's not working to see what's going on.
+! Logging output is directed to System.err. On Tomcat this
+! goes to logs/catalina.out. Not sure about Resin.
+
+;log=ALL
+
/* examples for the jcifs smb client library in Java\r
- * Copyright (C) 2001 "Michael B. Allen" <mballen@erols.com>\r
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>\r
*\r
* This program is free software; you can redistribute it and/or modify\r
* it under the terms of the GNU General Public License as published by\r
/* examples for the jcifs smb client library in Java\r
- * Copyright (C) 2001 "Michael B. Allen" <mballen@erols.com>\r
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>\r
*\r
* This program is free software; you can redistribute it and/or modify\r
* it under the terms of the GNU General Public License as published by\r
/* examples for the jcifs smb client library in Java\r
- * Copyright (C) 2001 "Michael B. Allen" <mballen@erols.com>\r
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>\r
*\r
* This program is free software; you can redistribute it and/or modify\r
* it under the terms of the GNU General Public License as published by\r
--- /dev/null
+
+torture.src.url = smb://dom\;miallen:pass@server/pub/
+torture.dst.domain = dom
+torture.dst.username = miallen
+torture.dst.password = pass
+torture.dst.server = server/
+torture.dst.share = share52/
+torture.dst.directory = torture1/
+
--- /dev/null
+
+thread.0.from.url = smb://dom\;usr:pas@svr1/shr/dir/
+thread.0.to.url = smb://dom\;usr:pas@svr2/shr/dir/
+thread.1.from.url = smb://dom\;usr:pas@svr1/shr/dir/
+thread.1.to.url = smb://dom\;usr:pas@svr2/shr/dir/
+thread.2.from.url = smb://dom\;usr:pas@svr1/shr/dir/
+thread.2.to.url = smb://dom\;usr:pas@svr2/shr/dir/
+++ /dev/null
-# config for TortureTest4
-
-;baddr=192.168.1.255
-wins=146.123.82.22
-;log=all
-
-<strauss>
- server = strauss
- username = goober
- password = mypass
- <download>
- place = holder
- </download>
- <etc>
- place = holder
- </etc>
- <temp>
- username = someone
- password = hello
- </temp>
-</strauss>
-<hendrix>
- server = hendrix
- username = mike
- password = x%43hhj
- <temp>
- place = holder
- </temp>
- <etc>
- place = holder
- </etc>
- <My Documents>
- place = holder
- </My Documents>
-</hendrix>
-<fruit>
- server = fruit
- username = guest
- password =
- <orange>
- place = holder
- </orange>
- <apple>
- username = whooly
- password = cranapple
- </apple>
- <grape>
- username = gardner
- password = hoe
- </grape>
-</fruit>
+++ /dev/null
-
-import jcifs.smb.*;
-
-public class zzz implements Runnable
-{
- public zzz()
- {
- }
- public void run() {
- try {
- SmbFile f = new SmbFile("smb://username:password@server/share/file.txt");
- SmbFileInputStream fin = new SmbFileInputStream(f);
- fin.close();
- }
- catch(Exception e) {
- e.printStackTrace();
- }
- }
-
- static public void main(String args[]) {
- jcifs.util.Config.setProperty( "wins", "146.123.82.22" );
-// jcifs.util.Config.setProperty( "maxMpxCount", "1" );
- int i,j;
- int iterations = 1;
- int numthreads = 100;
- for(i=0; i<iterations; ++i)
- {
- System.out.println("Iteration " + i);
- Thread threads[] = new Thread[numthreads];
- for(j=0; j<numthreads; ++j) {
- threads[j] = new Thread(new zzz());
- threads[j].start();
- }
- try {
- for(j=0; j<numthreads; ++j) {
- threads[j].join();
- }
- } catch(InterruptedException e) {
-e.printStackTrace();
- }
- }
- System.out.println("Closing");
- }
-}
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
import java.net.InetAddress;
/**
- * This class enhances the {@link jcifs.util.Config} class to simply add
- * additional configuration information specific to the jcifs smb library.
- * <p>
- * See also <a href="../../overview-summary.html#scp">Setting JCIFS Properties</a>
+ * This class mananges configuration information specific to the jCIFS library. There are several ways to set jCIFS properties. See the <a href="../overview-summary.html#scp">overview page of the API documentation</a> for details.
*/
public class Config {
- static {
- Properties sys;
- String mask;
- String filename;
- FileInputStream in = null;
+/**
+ * This static method registers the SMB URL protocol handler which is required to use SMB URLs with the <tt>java.net.URL</tt> class. If this method is not called before attempting to create an SMB URL with the URL class the following exception will occur:
+<blockquote><pre>
+Exception MalformedURLException: unknown protocol: smb
+ at java.net.URL.<init>(URL.java:480)
+ at java.net.URL.<init>(URL.java:376)
+ at java.net.URL.<init>(URL.java:330)
+ at jcifs.smb.SmbFile.<init>(SmbFile.java:355)
+ ...
+</pre><blockquote>
+ */
- sys = System.getProperties();
- synchronized( sys ) {
- String pkgs = sys.getProperty( "java.protocol.handler.pkgs" );
- if( pkgs == null ) {
- pkgs = "jcifs";
- } else {
- pkgs += "|jcifs";
- }
- sys.put( "java.protocol.handler.pkgs", pkgs );
+ public static void registerSmbURLHandler() {
+ String ver, pkgs;
+
+ ver = System.getProperty( "java.version" );
+ if( ver.startsWith( "1.1." ) || ver.startsWith( "1.2." )) {
+ throw new RuntimeException( "jcifs-0.7.0b4+ requires Java 1.3 or above. You are running " + ver );
}
+ pkgs = System.getProperty( "java.protocol.handler.pkgs" );
+ if( pkgs == null ) {
+ pkgs = "jcifs";
+ } else {
+ pkgs += "|jcifs";
+ }
+ System.setProperty( "java.protocol.handler.pkgs", pkgs );
+ }
+
+ static {
+ String filename, mask;
+ FileInputStream in = null;
try {
- filename = sys.getProperty( "jcifs.properties" );
+ filename = System.getProperty( "jcifs.properties" );
if( filename != null && filename.length() > 1 ) {
in = new FileInputStream( filename );
}
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
import jcifs.netbios.Lmhosts;
/**
- * This class is a wrapper for both {@link jcifs.netbios.NbtAddress} and
- * {@link java.net.InetAddress}. This frees the NetBIOS implementation
- * from trying to handle DNS and abstacts the NetBIOS protocol from the smb
- * package. This is a prerequisite of NetBIOS-less transport; a precedent
- * set by Microsoft's latest servers.
+ * <p>Under normal conditions it is not necessary to use
+ * this class to use jCIFS properly. Name resolusion is
+ * handled internally to the <code>jcifs.smb</code> package.
+ * <p>
+ * This class is a wrapper for both {@link jcifs.netbios.NbtAddress}
+ * and {@link java.net.InetAddress}. The name resolution mechanisms
+ * used will systematically query all available configured resolution
+ * services including WINS, broadcasts, DNS, and LMHOSTS. See
+ * <a href="../../resolver.html">Setting Name Resolution Properties</a>
+ * and the <code>jcifs.resolveOrder</code> property. Changing
+ * jCIFS name resolution properties can greatly affect the behavior of
+ * the client and may be necessary for proper operation.
+ * <p>
+ * This class should be used in favor of <tt>InetAddress</tt> to resolve hostnames on LANs and WANs that
+ * support a mixture of NetBIOS/WINS and DNS resolvable hosts.
*/
public class UniAddress {
static int[] resolveOrder;
static InetAddress nbns, baddr;
- static class QueryThread extends Thread {
-
- Object lock;
- String host, scope;
- int type;
- NbtAddress ans = null;
- InetAddress svr;
- UnknownHostException uhe;
-
- QueryThread( Object lock, String host, int type,
- String scope, InetAddress svr ) {
- this.lock = lock;
- this.host = host;
- this.type = type;
- this.scope = scope;
- this.svr = svr;
- }
- public void run() {
- try {
- ans = NbtAddress.getByName( host, type, scope, svr );
- } catch( UnknownHostException uhe ) {
- this.uhe = uhe;
- }
- synchronized( lock ) {
- lock.notify();
- }
- }
- }
-
static {
String ro = Config.getProperty( "jcifs.resolveOrder" );
nbns = Config.getInetAddress( "jcifs.netbios.wins", null );
}
}
+ static class Sem {
+ Sem( int count ) {
+ this.count = count;
+ }
+ int count;
+ }
+
+ static class QueryThread extends Thread {
+
+ Sem sem;
+ String host, scope;
+ int type;
+ NbtAddress ans = null;
+ InetAddress svr;
+ UnknownHostException uhe;
+
+ QueryThread( Sem sem, String host, int type,
+ String scope, InetAddress svr ) {
+ super( "JCIFS-QueryThread: " + host );
+ this.sem = sem;
+ this.host = host;
+ this.type = type;
+ this.scope = scope;
+ this.svr = svr;
+ }
+ public void run() {
+ try {
+ ans = NbtAddress.getByName( host, type, scope, svr );
+ } catch( UnknownHostException uhe ) {
+ this.uhe = uhe;
+ } catch( Exception ex ) {
+ this.uhe = new UnknownHostException( ex.getMessage() );
+ } finally {
+ synchronized( sem ) {
+ sem.count--;
+ sem.notify();
+ }
+ }
+ }
+ }
+
static NbtAddress lookupServerOrWorkgroup( String name, InetAddress svr )
throws UnknownHostException {
- Object lock = new Object();
+ Sem sem = new Sem( 2 );
int type = svr == nbns ? 0x1b : 0x1d;
- QueryThread q1x = new QueryThread( lock, name, type, null, svr );
- QueryThread q20 = new QueryThread( lock, name, 0x20, null, svr );
+ QueryThread q1x = new QueryThread( sem, name, type, null, svr );
+ QueryThread q20 = new QueryThread( sem, name, 0x20, null, svr );
q1x.setDaemon( true );
q20.setDaemon( true );
try {
- synchronized( lock ) {
+ synchronized( sem ) {
q1x.start();
q20.start();
- int i = 2;
- while( i-- > 0 && q1x.ans == null && q20.ans == null ) {
- lock.wait();
+ while( sem.count > 0 && q1x.ans == null && q20.ans == null ) {
+//System.out.println( "sem.count=" + sem.count + ",q1x.ans=" + q1x.ans + ",q20.ans=" + q20.ans );
+ sem.wait();
}
}
} catch( InterruptedException ie ) {
throw q1x.uhe;
}
}
+
+/**
+ * Determines the address of a host given it's host name. The name can be a
+ * machine name like "jcifs.samba.org", or an IP address like "192.168.1.15".
+ *
+ * @param host NetBIOS or DNS hostname to resolve
+ * @throws java.net.UnknownHostException if there is an error resolving the name
+ */
+
public static UniAddress getByName( String hostname )
throws UnknownHostException {
return getByName( hostname, false );
return false;
}
+ static boolean isValidDnsName( String hostname ) {
+ // Simple for now. Just handles "1" --> 1/0.0.0.1 kind of stuff
+ return Character.isDigit( hostname.charAt( 0 )) == false;
+ }
+
public static UniAddress getByName( String hostname,
boolean possibleNTDomainOrWorkgroup )
throws UnknownHostException {
}
break;
case RESOLVER_DNS:
+ if( isValidDnsName( hostname ) == false ) {
+ throw new UnknownHostException( hostname );
+ }
addr = InetAddress.getByName( hostname );
break;
default:
- throw new UnknownHostException();
+ throw new UnknownHostException( hostname );
}
return new UniAddress( addr ); // Success
} catch( IOException ioe ) {
this.addr = addr;
}
+ public int hashCode() {
+ return addr.hashCode();
+ }
public boolean equals( Object obj ) {
- return obj instanceof UniAddress && addr.equals( ((UniAddress)obj).addr );
+ return obj instanceof UniAddress && addr.hashCode() == obj.hashCode();
+// addr.equals( ((UniAddress)obj).addr );
}
-/* Guess next called name to try for session establishment. These
+/** Guess first called name to try for session establishment. This
* methods are used by the smb package.
*/
public String firstCalledName() {
return calledName;
}
+/** Guess next called name to try for session establishment. This
+ * methods are used by the smb package.
+ */
public String nextCalledName() {
if( addr instanceof NbtAddress ) {
return ((NbtAddress)addr).nextCalledName();
--- /dev/null
+/* jcifs smb client library in Java
+ * Copyright (C) 2002 "Michael B. Allen" <jcifs at samba dot org>
+ *
+ * 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.http;
+
+import java.io.*;
+import javax.servlet.*;
+import javax.servlet.http.*;
+import java.util.*;
+import java.text.SimpleDateFormat;
+import java.net.UnknownHostException;
+import jcifs.*;
+import jcifs.http.*;
+import jcifs.smb.*;
+import jcifs.netbios.NbtAddress;
+import jcifs.util.MimeMap;
+
+/**
+ * This servlet may be used to "browse" the entire hierarchy of resources
+ * on an SMB network like one might with Network Neighborhood or Windows
+ * Explorer. The users credentials with be negotiated using NTLM SSP if
+ * the client is Microsoft Internet Explorer.
+ *
+ * Please read <a href="../../../ntlmhttpauth.html">jCIFS NTLM HTTP Authentication and the Network Explorer Servlet</a>.
+ */
+
+public class NetworkExplorer extends HttpServlet {
+
+ MimeMap mimeMap;
+ String style;
+ NtlmSsp ntlmSsp;
+ boolean useNtlmSsp;
+
+ public void init() throws ServletException {
+ InputStream is;
+ StringBuffer sb = new StringBuffer();
+ byte[] buf = new byte[1024];
+ int n;
+ String name;
+
+ for( Enumeration e = getInitParameterNames(); e.hasMoreElements(); ) {
+ name = (String)e.nextElement();
+ if( name.startsWith( "jcifs." )) {
+ Config.setProperty( name, getInitParameter( name ));
+ }
+ }
+
+ try {
+ mimeMap = new MimeMap();
+ is = getClass().getClassLoader().getResourceAsStream( "jcifs/http/ne.css" );
+ while(( n = is.read( buf )) != -1 ) {
+ sb.append( new String( buf, 0, n, "ISO8859_1" ));
+ }
+ style = sb.toString();
+ } catch( IOException ioe ) {
+ throw new ServletException( ioe.getMessage() );
+ }
+ Config.setProperty( "jcifs.smb.client.attrExpirationPeriod", "120000" );
+
+ if( Config.getProperty( "jcifs.smb.client.username" ) == null ) {
+ ntlmSsp = new NtlmSsp();
+ useNtlmSsp = true;
+ }
+ }
+
+ String parseServerAndShare( String pathInfo ) {
+ char[] out = new char[256];
+ char ch;
+ int len, p, i;
+
+ if( pathInfo == null ) {
+ return null;
+ }
+ len = pathInfo.length();
+
+ p = i = 0;
+ while( p < len && pathInfo.charAt( p ) == '/' ) {
+ p++;
+ }
+ if( p == len ) {
+ return null;
+ }
+ out[i++] = pathInfo.charAt( p++ );
+ while( p < len && ( ch = pathInfo.charAt( p++ )) != '/' ) {
+ out[i++] = ch;
+ }
+ if( p < len ) {
+ out[i++] = '/';
+ while( p < len && pathInfo.charAt( p ) == '/' ) {
+ p++;
+ }
+ if( p == len ) {
+ return new String( out, 0, i - 1 );
+ }
+ while( p < len && ( ch = pathInfo.charAt( p++ )) != '/' ) {
+ out[i++] = ch;
+ }
+ }
+ return new String( out, 0, i );
+ }
+ void doFile( HttpServletRequest req,
+ HttpServletResponse resp, SmbFile file ) throws IOException {
+ byte[] buf = new byte[8192];
+ SmbFileInputStream in;
+ ServletOutputStream out;
+ String url, type;
+ int n;
+
+ in = new SmbFileInputStream( file );
+ out = resp.getOutputStream();
+ url = file.getPath();
+
+ resp.setContentType( "text/plain" );
+
+ if(( n = url.lastIndexOf( '.' )) > 0 &&
+ ( type = url.substring( n + 1 )) != null &&
+ type.length() > 1 && type.length() < 6 ) {
+ resp.setContentType( mimeMap.getMimeType( type ));
+ }
+ resp.setHeader( "Content-Length", file.length() + "" );
+ resp.setHeader( "Accept-Ranges", "Bytes" );
+
+ while(( n = in.read( buf )) != -1 ) {
+ out.write( buf, 0, n );
+ }
+ }
+ int compareNames( SmbFile f1, String f1name, SmbFile f2 ) throws IOException {
+ if( f1.isDirectory() != f2.isDirectory() ) {
+ return f1.isDirectory() ? -1 : 1;
+ }
+ return f1name.compareToIgnoreCase( f2.getName() );
+ }
+ int compareSizes( SmbFile f1, String f1name, SmbFile f2 ) throws IOException {
+ long diff;
+
+ if( f1.isDirectory() != f2.isDirectory() ) {
+ return f1.isDirectory() ? -1 : 1;
+ }
+ if( f1.isDirectory() ) {
+ return f1name.compareToIgnoreCase( f2.getName() );
+ }
+ diff = f1.length() - f2.length();
+ if( diff == 0 ) {
+ return f1name.compareToIgnoreCase( f2.getName() );
+ }
+ return diff > 0 ? -1 : 1;
+ }
+ int compareTypes( SmbFile f1, String f1name, SmbFile f2 ) throws IOException {
+ String f2name, t1, t2;
+ int i;
+
+ if( f1.isDirectory() != f2.isDirectory() ) {
+ return f1.isDirectory() ? -1 : 1;
+ }
+ f2name = f2.getName();
+ if( f1.isDirectory() ) {
+ return f1name.compareToIgnoreCase( f2name );
+ }
+ i = f1name.lastIndexOf( '.' );
+ t1 = i == -1 ? "" : f1name.substring( i + 1 );
+ i = f2name.lastIndexOf( '.' );
+ t2 = i == -1 ? "" : f2name.substring( i + 1 );
+
+ i = t1.compareToIgnoreCase( t2 );
+ if( i == 0 ) {
+ return f1name.compareToIgnoreCase( f2name );
+ }
+ return i;
+ }
+ int compareDates( SmbFile f1, String f1name, SmbFile f2 ) throws IOException {
+ if( f1.isDirectory() != f2.isDirectory() ) {
+ return f1.isDirectory() ? -1 : 1;
+ }
+ if( f1.isDirectory() ) {
+ return f1name.compareToIgnoreCase( f2.getName() );
+ }
+ return f1.lastModified() > f2.lastModified() ? -1 : 1;
+ }
+ void doDirectory( HttpServletRequest req, HttpServletResponse resp, SmbFile dir ) throws IOException {
+ PrintWriter out;
+ SmbFile[] dirents;
+ SmbFile f;
+ int i, j, len, maxLen, dirCount, fileCount, sort;
+ String str, name, path, fmt;
+ LinkedList sorted;
+ ListIterator iter;
+ SimpleDateFormat sdf = new SimpleDateFormat( "MM/d/yy h:mm a" );
+ GregorianCalendar cal = new GregorianCalendar();
+
+ sdf.setCalendar( cal );
+
+ dirents = dir.listFiles();
+ sorted = new LinkedList();
+ if(( fmt = req.getParameter( "fmt" )) == null ) {
+ fmt = "col";
+ }
+ sort = 0;
+ if(( str = req.getParameter( "sort" )) == null || str.equals( "name" )) {
+ sort = 0;
+ } else if( str.equals( "size" )) {
+ sort = 1;
+ } else if( str.equals( "type" )) {
+ sort = 2;
+ } else if( str.equals( "date" )) {
+ sort = 3;
+ }
+ dirCount = fileCount = 0;
+ maxLen = 28;
+ for( i = 0; i < dirents.length; i++ ) {
+ try {
+ if( dirents[i].getType() == SmbFile.TYPE_NAMED_PIPE ) {
+ continue;
+ }
+ } catch( SmbAuthException sae ) {
+ }
+ if( dirents[i].isDirectory() ) {
+ dirCount++;
+ } else {
+ fileCount++;
+ }
+
+ name = dirents[i].getName();
+ len = name.length();
+ if( len > maxLen ) {
+ maxLen = len;
+ }
+
+ iter = sorted.listIterator();
+ for( j = 0; iter.hasNext(); j++ ) {
+ if( sort == 0 ) {
+ if( compareNames( dirents[i], name, (SmbFile)iter.next() ) < 0 ) {
+ break;
+ }
+ } else if( sort == 1 ) {
+ if( compareSizes( dirents[i], name, (SmbFile)iter.next() ) < 0 ) {
+ break;
+ }
+ } else if( sort == 2 ) {
+ if( compareTypes( dirents[i], name, (SmbFile)iter.next() ) < 0 ) {
+ break;
+ }
+ } else if( sort == 3 ) {
+ if( compareDates( dirents[i], name, (SmbFile)iter.next() ) < 0 ) {
+ break;
+ }
+ }
+ }
+ sorted.add( j, dirents[i] );
+ }
+ if( maxLen > 50 ) {
+ maxLen = 50;
+ }
+ maxLen *= 9; /* convert to px */
+
+ out = resp.getWriter();
+
+ resp.setContentType( "text/html" );
+
+ out.println( "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">" );
+ out.println( "<html><head><title>Network Explorer</title>" );
+ out.println( "<meta HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">" );
+ out.println( "<style TYPE=\"text/css\">" );
+
+ out.println( style );
+
+ if( dirents.length < 200 ) {
+ out.println( " a:hover {" );
+ out.println( " background: #a2ff01;" );
+ out.println( " }" );
+ }
+
+ out.println( "</STYLE>" );
+ out.println( "</head><body>" );
+
+ out.print( "<a class=\"sort\" style=\"width: " + maxLen + ";\" href=\"?fmt=detail&sort=name\">Name</a>" );
+ out.println( "<a class=\"sort\" href=\"?fmt=detail&sort=size\">Size</a>" );
+ out.println( "<a class=\"sort\" href=\"?fmt=detail&sort=type\">Type</a>" );
+ out.println( "<a class=\"sort\" style=\"width: 180\" href=\"?fmt=detail&sort=date\">Modified</a><br clear='all'><p>" );
+
+ path = dir.getCanonicalPath();
+
+ if( path.length() < 7 ) {
+ out.println( "<b><big>smb://</big></b><br>" );
+ path = ".";
+ } else {
+ out.println( "<b><big>" + path + "</big></b><br>" );
+ path = "../";
+ }
+ out.println( (dirCount + fileCount) + " objects (" + dirCount + " directories, " + fileCount + " files)<br>" );
+ out.println( "<b><a class=\"plain\" href=\".\">normal</a> | <a class=\"plain\" href=\"?fmt=detail\">detailed</a></b>" );
+ out.println( "<p><table border='0' cellspacing='0' cellpadding='0'><tr><td>" );
+
+ out.print( "<A style=\"width: " + maxLen );
+ out.print( "; height: 18;\" HREF=\"" );
+ out.print( path );
+ out.println( "\"><b>↑</b></a>" );
+ if( fmt.equals( "detail" )) {
+ out.println( "<br clear='all'>" );
+ }
+
+ if( path.length() == 1 || dir.getType() != SmbFile.TYPE_WORKGROUP ) {
+ path = "";
+ }
+
+ iter = sorted.listIterator();
+ while( iter.hasNext() ) {
+ f = (SmbFile)iter.next();
+ name = f.getName();
+
+ if( fmt.equals( "detail" )) {
+ out.print( "<A style=\"width: " + maxLen );
+ out.print( "; height: 18;\" HREF=\"" );
+ out.print( path );
+ out.print( name );
+
+ if( f.isDirectory() ) {
+ out.print( "?fmt=detail\"><b>" );
+ out.print( name );
+ out.print( "</b></a>" );
+ } else {
+ out.print( "\"><b>" );
+ out.print( name );
+ out.print( "</b></a><div align='right'>" );
+ out.print( (f.length() / 1024) + " KB </div><div>" );
+ i = name.lastIndexOf( '.' ) + 1;
+ if( i > 1 && (name.length() - i) < 6 ) {
+ out.print( name.substring( i ).toUpperCase() + "</div class='ext'>" );
+ } else {
+ out.print( " </div>" );
+ }
+ out.print( "<div style='width: 180'>" );
+ out.print( sdf.format( new Date( f.lastModified() )));
+ out.print( "</div>" );
+ }
+ out.println( "<br clear='all'>" );
+ } else {
+ out.print( "<A style=\"width: " + maxLen );
+ if( f.isDirectory() ) {
+ out.print( "; height: 18;\" HREF=\"" );
+ out.print( path );
+ out.print( name );
+ out.print( "\"><b>" );
+ out.print( name );
+ out.print( "</b></a>" );
+ } else {
+ out.print( ";\" HREF=\"" );
+ out.print( path );
+ out.print( name );
+ out.print( "\"><b>" );
+ out.print( name );
+ out.print( "</b><br><small>" );
+ out.print( (f.length() / 1024) + "KB <br>" );
+ out.print( sdf.format( new Date( f.lastModified() )));
+ out.print( "</small>" );
+ out.println( "</a>" );
+ }
+ }
+ }
+
+ out.println( "</td></tr></table>" );
+ out.println( "</BODY></HTML>" );
+ out.close();
+ }
+ public void doGet( HttpServletRequest req,
+ HttpServletResponse resp ) throws IOException, ServletException {
+ NtlmPasswordAuthentication ntlm;
+ UniAddress dc;
+ byte[] challenge;
+ String pathInfo, s;
+ SmbFile file;
+
+ s = null;
+ if(( pathInfo = req.getPathInfo() ) != null ) {
+ s = parseServerAndShare( pathInfo );
+ }
+
+ if( useNtlmSsp ) {
+ String msg = req.getHeader( "Authorization" );
+ if( msg == null || msg.startsWith( "NTLM " ) == false ) {
+ resp.setHeader( "WWW-Authenticate", "NTLM" );
+ resp.setStatus( HttpServletResponse.SC_UNAUTHORIZED );
+ resp.flushBuffer();
+ return;
+ }
+
+ if( pathInfo == null || s == null ) {
+ s = NbtAddress.getByName( NbtAddress.MASTER_BROWSER_NAME, 0x01, null ).getHostAddress();
+ dc = UniAddress.getByName( s );
+ } else {
+ int i = s.indexOf( '/' );
+ if( i > 0 ) {
+ s = s.substring( 0, i );
+ }
+ dc = UniAddress.getByName( s, i == -1 );
+ }
+ challenge = SmbSession.getChallenge( dc );
+
+ /* Be carefull what you put before this. It's called 3 times in a row
+ * before doAuthentication returns a good NtlmPasswordAuthentication
+ * object.
+ */
+
+ if(( ntlm = ntlmSsp.doAuthentication( req, resp, challenge )) == null ) {
+ return;
+ }
+ file = new SmbFile( "smb:/" + pathInfo , ntlm );
+ } else if( s == null ) {
+ file = new SmbFile( "smb://" );
+ } else {
+ file = new SmbFile( "smb:/" + pathInfo );
+ }
+
+ try {
+ if( file.isDirectory() ) {
+ doDirectory( req, resp, file );
+ } else {
+ doFile( req, resp, file );
+ }
+ } catch( SmbAuthException sae ) {
+ resp.setHeader( "WWW-Authenticate", "NTLM" );
+ resp.setHeader( "Connection", "close" );
+ resp.setStatus( HttpServletResponse.SC_UNAUTHORIZED );
+ resp.flushBuffer();
+ return;
+ }
+ }
+}
+
--- /dev/null
+/* jcifs smb client library in Java
+ * Copyright (C) 2002 "Michael B. Allen" <jcifs at samba dot org>
+ * "Jason Pugsley" <jcifs at samba dot org>
+ * "skeetz" <jcifs at samba dot org>
+ * "Eric Glass" <jcifs at samba dot org>
+ *
+ * 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.http;
+
+import java.io.*;
+import java.util.Enumeration;
+import java.net.UnknownHostException;
+import javax.servlet.*;
+import javax.servlet.http.*;
+import jcifs.*;
+import jcifs.smb.SmbSession;
+import jcifs.smb.NtlmPasswordAuthentication;
+import jcifs.smb.SmbAuthException;
+
+/**
+ * This servlet Filter can be used to negotiate password hashes with
+ * MSIE clients using NTLM SSP. This is similar to <tt>Authentication:
+ * BASIC</tt> but weakly encrypted and without requiring the user to re-supply
+ * authentication credentials.
+ * <p>
+ * Read <a href="../../../ntlmhttpauth.html">jCIFS NTLM HTTP Authentication and the Network Explorer Servlet</a> for complete details.
+ */
+
+public class NtlmHttpFilter extends NtlmSsp implements Filter {
+
+ private String domainController;
+
+ public void init( FilterConfig filterConfig ) throws ServletException {
+ String name;
+
+ /* Set jcifs properties we know we want; soTimeout and cachePolicy to 10min.
+ */
+ Config.setProperty( "jcifs.smb.client.soTimeout", "300000" );
+ Config.setProperty( "jcifs.netbios.cachePolicy", "600" );
+
+ Enumeration e = filterConfig.getInitParameterNames();
+ while( e.hasMoreElements() ) {
+ name = (String)e.nextElement();
+ if( name.startsWith( "jcifs." )) {
+ Config.setProperty( name, filterConfig.getInitParameter( name ));
+ }
+ }
+
+ domainController = Config.getProperty( "jcifs.http.domainController" );
+ if( domainController == null ) {
+ domainController = Config.getProperty( "jcifs.smb.client.domain" );
+ }
+ }
+ public void destroy() {
+ }
+ public void doFilter( ServletRequest request,
+ ServletResponse response,
+ FilterChain chain ) throws IOException, ServletException {
+ HttpServletRequest req;
+ HttpServletResponse resp;
+ NtlmPasswordAuthentication ntlm;
+ UniAddress dc;
+ byte[] challenge;
+ String msg;
+ HttpSession ssn;
+
+ req = (HttpServletRequest)request;
+ resp = (HttpServletResponse)response;
+ ssn = req.getSession();
+ msg = req.getHeader( "Authorization" );
+
+ if( msg != null && msg.startsWith( "NTLM " )) {
+ dc = UniAddress.getByName( domainController, true );
+ challenge = SmbSession.getChallenge( dc );
+ if(( ntlm = doAuthentication( req, resp, challenge )) == null ) {
+ return;
+ }
+ try {
+ SmbSession.logon( dc, ntlm );
+ } catch( SmbAuthException sae ) {
+ resp.setHeader( "WWW-Authenticate", "NTLM" );
+ resp.setHeader( "Connection", "close" );
+ resp.setStatus( HttpServletResponse.SC_UNAUTHORIZED );
+ resp.flushBuffer();
+ return;
+ }
+ ssn.setAttribute( "NtlmHttpAuth", ntlm );
+ } else if(( ntlm = (NtlmPasswordAuthentication)ssn.getAttribute( "NtlmHttpAuth" )) == null ) {
+ resp.setHeader( "WWW-Authenticate", "NTLM" );
+ resp.setHeader( "Connection", "close" );
+ resp.setStatus( HttpServletResponse.SC_UNAUTHORIZED );
+ resp.flushBuffer();
+ return;
+ }
+
+ chain.doFilter( new NtlmHttpServletRequest( req, ntlm ), response );
+ }
+
+ // Added by cgross to work with weblogic 6.1.
+ public void setFilterConfig( FilterConfig f ) {
+ try {
+ init( f );
+ } catch( Exception e ) {
+ e.printStackTrace();
+ }
+ }
+ public FilterConfig getFilterConfig() {
+ return null;
+ }
+}
+
--- /dev/null
+/* jcifs smb client library in Java
+ * Copyright (C) 2002 "Michael B. Allen" <jcifs at samba dot org>
+ * "Eric Glass" <jcifs at samba dot org>
+ *
+ * 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.http;
+
+import java.security.Principal;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+
+class NtlmHttpServletRequest extends HttpServletRequestWrapper {
+
+ Principal principal;
+
+ NtlmHttpServletRequest( HttpServletRequest req, Principal principal ) {
+ super( req );
+ this.principal = principal;
+ }
+ public String getRemoteUser() {
+ return principal.getName();
+ }
+ public Principal getUserPrincipal() {
+ return principal;
+ }
+}
+
--- /dev/null
+/* jcifs smb client library in Java
+ * Copyright (C) 2002 "Michael B. Allen" <jcifs at samba dot org>
+ * "Eric Glass" <jcifs at samba dot org>
+ *
+ * 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.http;
+
+import java.io.IOException;
+
+import java.net.UnknownHostException;
+
+import java.util.Enumeration;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.UnavailableException;
+
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import jcifs.Config;
+import jcifs.UniAddress;
+
+import jcifs.smb.NtlmPasswordAuthentication;
+import jcifs.smb.SmbSession;
+
+/**
+ * This servlet may be used with pre-2.3 servlet containers
+ * to protect content with NTLM HTTP Authentication. Servlets that
+ * extend this abstract base class may be authenticatied against an SMB
+ * server or domain controller depending on how the
+ * <tt>jcifs.smb.client.domain</tt> or <tt>jcifs.http.domainController</tt>
+ * properties are be specified. <b>With later containers the
+ * <tt>NtlmHttpFilter</tt> should be used/b>. For custom NTLM HTTP Authentication schemes the <tt>NtlmSsp</tt> may be used.
+ * <p>
+ * Read <a href="../../../ntlmhttpauth.html">jCIFS NTLM HTTP Authentication and the Network Explorer Servlet</a> related information.
+ */
+
+public abstract class NtlmServlet extends HttpServlet {
+
+ private static final NtlmSsp AUTH = new NtlmSsp();
+
+ private UniAddress domainController;
+
+ public void init(ServletConfig config) throws ServletException {
+ super.init(config);
+
+ /* Set jcifs properties we know we want; soTimeout and cachePolicy to 10min.
+ */
+ Config.setProperty( "jcifs.smb.client.soTimeout", "300000" );
+ Config.setProperty( "jcifs.netbios.cachePolicy", "600" );
+
+ Enumeration e = config.getInitParameterNames();
+ String name;
+ while (e.hasMoreElements()) {
+ name = (String) e.nextElement();
+ if (name.startsWith("jcifs.")) {
+ Config.setProperty(name, config.getInitParameter(name));
+ }
+ }
+ String dc = Config.getProperty("jcifs.http.domainController");
+ if (dc == null && (dc = Config.getProperty( "jcifs.smb.client.domain" )) == null) {
+ throw new UnavailableException("No domain controller specified.");
+ }
+ try {
+ domainController = UniAddress.getByName(dc);
+ } catch (UnknownHostException ex) {
+ throw new UnavailableException("Specified DC unreachable.");
+ }
+ }
+
+ protected void service(HttpServletRequest request,
+ HttpServletResponse response) throws ServletException, IOException {
+ String msg = request.getHeader("Authorization");
+ if (msg != null && msg.startsWith("NTLM")) {
+ HttpSession ssn;
+ byte[] challenge = SmbSession.getChallenge(domainController);
+ NtlmPasswordAuthentication ntlm = AUTH.doAuthentication(request,
+ response, challenge);
+ if (ntlm == null) return;
+ SmbSession.logon(domainController, ntlm);
+ ssn = request.getSession();
+ ssn.setAttribute("NtlmHttpAuth", ntlm);
+ ssn.setAttribute( "ntlmdomain", ntlm.getDomain() );
+ ssn.setAttribute( "ntlmuser", ntlm.getUsername() );
+ } else if (request.getSession().getAttribute("NtlmHttpAuth") == null) {
+ response.setHeader("WWW-Authenticate", "NTLM");
+ response.setHeader("Connection", "close");
+ response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
+ response.flushBuffer();
+ return;
+ }
+ super.service(request, response);
+ }
+}
+
--- /dev/null
+/* jcifs smb client library in Java
+ * Copyright (C) 2002 "Michael B. Allen" <jcifs at samba dot org>
+ * "Jason Pugsley" <jcifs at samba dot org>
+ * "skeetz" <jcifs at samba dot org>
+ *
+ * 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.http;
+
+import java.io.*;
+import javax.servlet.*;
+import javax.servlet.http.*;
+import jcifs.smb.NtlmPasswordAuthentication;
+import jcifs.util.Base64;
+
+/**
+ * This class is used internally by <tt>NtlmHttpFilter</tt>,
+ * <tt>NtlmServlet</tt>, and <tt>NetworkExplorer</tt> to negiotiate password
+ * hashes via NTLM SSP with MSIE. It might also be used directly by servlet
+ * containers to incorporate similar functionality.
+ * <p>
+ * How NTLMSSP is used in conjunction with HTTP and MSIE clients is
+ * described in an <A HREF="http://www.innovation.ch/java/ntlm.html">NTLM
+ * Authentication Scheme for HTTP</A>. <p> Also, read <a
+ * href="../../../ntlmhttpauth.html">jCIFS NTLM HTTP Authentication and
+ * the Network Explorer Servlet</a> related information.
+ */
+
+public class NtlmSsp {
+
+ static final byte[] msg2 = {
+ (byte)0x4E, (byte)0x54, (byte)0x4C, (byte)0x4D,
+ (byte)0x53, (byte)0x53, (byte)0x50, (byte)0x00,
+ (byte)0x02, (byte)0x00, (byte)0x00, (byte)0x00,
+ (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
+ (byte)0x28, (byte)0x00, (byte)0x00, (byte)0x00,
+ (byte)0x01, (byte)0x82, (byte)0x00, (byte)0x00,
+ (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF,
+ (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF,
+ (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
+ (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00
+ };
+
+ int readInt2( byte[] src, int srcIndex ) {
+ return ( src[srcIndex] & 0xFF ) +
+ (( src[srcIndex + 1] & 0xFF ) << 8 );
+ }
+
+ /* Decode the type-1-message and encode the type-2-message. Note the "domain"
+ * in the type-1-message isn't necessarily
+ * the authentication domain. There is a good possibilty it is only the
+ * workgroup used for browsing. The 3rd message with have the authenticating
+ * domain.
+ */
+ int encodeType2Message( byte[] src, byte[] dst, byte[] challenge ) throws IOException {
+
+jcifs.util.Log.printHexDump( "type-1-message", src );
+
+ System.arraycopy( msg2, 0, dst, 0, 40 );
+ System.arraycopy( challenge, 0, dst, 24, 8 );
+
+jcifs.util.Log.printHexDump( "type-2-message", dst, 0, 40 );
+ return 40;
+ }
+ /* Decode type-3-message.
+ */
+ NtlmPasswordAuthentication decodeType3Message( byte[] src ) throws IOException {
+ int off, len;
+ byte[] lm_hash = new byte[24];
+ byte[] nt_hash = new byte[24];
+ String domain, user;
+
+jcifs.util.Log.printHexDump( "type-3-message", src );
+
+ off = readInt2( src, 16 );
+ System.arraycopy( src, off, lm_hash, 0, 24 );
+ off = readInt2( src, 24 );
+ System.arraycopy( src, off, nt_hash, 0, 24 );
+ len = readInt2( src, 28 );
+ off = readInt2( src, 32 );
+ domain = new String( src, off, len, "UnicodeLittleUnmarked" );
+ len = readInt2( src, 36 );
+ off = readInt2( src, 40 );
+ user = new String( src, off, len, "UnicodeLittleUnmarked" );
+
+ return new NtlmPasswordAuthentication( domain, user, lm_hash, nt_hash );
+ }
+ public NtlmPasswordAuthentication doAuthentication( HttpServletRequest req,
+ HttpServletResponse resp, byte[] challenge )
+ throws IOException, ServletException {
+ String msg;
+
+ msg = req.getHeader( "Authorization" );
+
+ if( msg != null && msg.startsWith( "NTLM " )) {
+ byte[] src = Base64.decode( msg.substring( 5 ));
+
+ if( src[8] == 1 ) {
+ byte[] dst = new byte[40];
+
+ msg = Base64.encodeBytes( dst, 0, encodeType2Message( src, dst, challenge ));
+
+ resp.setHeader( "WWW-Authenticate", "NTLM " + msg );
+ resp.setContentLength( 0 );
+ } else if( src[8] == 3 ) {
+ return decodeType3Message( src );
+ }
+ } else {
+ resp.setHeader( "WWW-Authenticate", "NTLM" );
+ resp.setHeader( "Connection", "close" );
+ }
+ resp.setStatus( HttpServletResponse.SC_UNAUTHORIZED );
+ resp.flushBuffer();
+
+ return null;
+ }
+}
+
--- /dev/null
+ a {
+ display: block;
+ float: left;
+ width: 300px;
+ height: 50px;
+ padding: 2px;
+ font-family: Verdana, sans-serif;
+ font-size: 10pt;
+ color: #000000;
+ text-decoration: none;
+ }
+ a.plain {
+ display: inline;
+ float: none;
+ width: auto;
+ height: auto;
+ }
+ a.sort {
+ display: block;
+ float: left;
+ width: 100px;
+ height: 15px;
+ font-family: Verdana, sans-serif;
+ font-size: 8pt;
+ font-weight: bold;
+ text-decoration: none;
+ color: #000000;
+ background-color: #d0d0d0;
+ border-top-color: #ffffff;
+ border-bottom-color: #707070;
+ border-right-color: #707070;
+ border-left-color: #ffffff;
+ border-style: solid solid;
+ border-top-width: 1px;
+ border-bottom-width: 2px;
+ border-right-width: 2px;
+ border-left-width: 1px;
+ }
+ a:visited {
+ color: #333897;
+ }
+ a.sort:hover {
+ background-color: #d0d0d0;
+ }
+ a.sort:visited {
+ color: #000000;
+ }
+ div {
+ float: left;
+ width: 100px;
+ height: 18px;
+ padding: 2px;
+ font-family: Verdana, sans-serif;
+ font-size: 10pt;
+ }
+ body {
+ font-family: Verdana, sans-serif;
+ font-size: 10pt;
+ background-color: #ffffff;
+ margin-top: 0;
+ margin-left: 5;
+ }
+ small {
+ font-size: 8pt;
+ }
+ big {
+ font-size: 14pt;
+ }
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
- * "Christopher R. Hertel" <crh@nts.umn.edu>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
+ * "Christopher R. Hertel" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
package jcifs.netbios;
+import java.io.UnsupportedEncodingException;
import jcifs.Config;
class Name {
static String toHexChars( int val ) {
int len = 2;
- byte[] tmp = new byte[2];
+ char[] tmp = new char[2];
while( len > 0 ) {
- tmp[ len - 1 ] = (byte)HEX_DIGITS[ val & 0x000F ];
+ tmp[ len - 1 ] = HEX_DIGITS[val & 0x000F];
if( val != 0 ) {
val >>>= 4;
}
static final int SCOPE_OFFSET = 33;
static String defaultScope = Config.getProperty( "jcifs.netbios.scope" );
+ static String encoding = Config.getProperty( "jcifs.netbios.encoding", "ISO8859_1" );
String name, scope;
int hexCode;
dst[dstIndex] = 0x20;
// write name
- byte tmp[] = name.getBytes();
- int i;
- for( i = 0; i < tmp.length; i++ ) {
- dst[dstIndex + ( 2 * i + 1 )] = (byte)((( tmp[i] & 0xF0 ) >> 4 ) + 0x41 );
- dst[dstIndex + ( 2 * i + 2 )] = (byte)(( tmp[i] & 0x0F ) + 0x41 );
- }
- for( ; i < 15; i++ ) {
- dst[dstIndex + ( 2 * i + 1 )] = (byte)0x43;
- dst[dstIndex + ( 2 * i + 2 )] = (byte)0x41;
- }
- dst[dstIndex + TYPE_OFFSET] = (byte)((( hexCode & 0xF0 ) >> 4 ) + 0x41 );
- dst[dstIndex + TYPE_OFFSET + 1] = (byte)(( hexCode & 0x0F ) + 0x41 );
+ try {
+ byte tmp[] = name.getBytes( Name.encoding );
+ int i;
+ for( i = 0; i < tmp.length; i++ ) {
+ dst[dstIndex + ( 2 * i + 1 )] = (byte)((( tmp[i] & 0xF0 ) >> 4 ) + 0x41 );
+ dst[dstIndex + ( 2 * i + 2 )] = (byte)(( tmp[i] & 0x0F ) + 0x41 );
+ }
+ for( ; i < 15; i++ ) {
+ dst[dstIndex + ( 2 * i + 1 )] = (byte)0x43;
+ dst[dstIndex + ( 2 * i + 2 )] = (byte)0x41;
+ }
+ dst[dstIndex + TYPE_OFFSET] = (byte)((( hexCode & 0xF0 ) >> 4 ) + 0x41 );
+ dst[dstIndex + TYPE_OFFSET + 1] = (byte)(( hexCode & 0x0F ) + 0x41 );
+ } catch( UnsupportedEncodingException uee ) {
+ }
return SCOPE_OFFSET + writeScopeWireFormat( dst, dstIndex + SCOPE_OFFSET );
}
length = i + 1;
}
}
- name = new String( tmp, 0, length );
+ try {
+ name = new String( tmp, 0, length, Name.encoding );
+ } catch( UnsupportedEncodingException uee ) {
+ }
hexCode = (( src[srcIndex + TYPE_OFFSET] & 0xFF ) - 0x41 ) << 4;
hexCode |= (( src[srcIndex + TYPE_OFFSET + 1] & 0xFF ) - 0x41 ) & 0x0F;
return SCOPE_OFFSET + readScopeWireFormat( src, srcIndex + SCOPE_OFFSET );
// copy new scope in
dst[dstIndex++] = (byte)'.';
- System.arraycopy( scope.getBytes(), 0, dst, dstIndex, scope.length() );
+ try {
+ System.arraycopy( scope.getBytes( encoding ), 0, dst, dstIndex, scope.length() );
+ } catch( UnsupportedEncodingException uee ) {
+ }
dstIndex += scope.length();
dst[dstIndex++] = (byte)0x00;
return 1;
}
- sb = new StringBuffer( new String( src, srcIndex, n ));
- srcIndex += n;
- while(( n = src[srcIndex++] & 0xFF ) != 0 ) {
- sb.append( '.' ).append( new String( src, srcIndex, n ));
+ try {
+ sb = new StringBuffer( new String( src, srcIndex, n, Name.encoding ));
srcIndex += n;
+ while(( n = src[srcIndex++] & 0xFF ) != 0 ) {
+ sb.append( '.' ).append( new String( src, srcIndex, n, Name.encoding ));
+ srcIndex += n;
+ }
+ scope = sb.toString();
+ } catch( UnsupportedEncodingException uee ) {
}
- scope = sb.toString();
return srcIndex - start;
}
String n = name;
// fix MSBROWSE name
- if( n.charAt( 0 ) == 0x01 ) {
- byte b[] = n.getBytes();
- b[0] = (byte)'.';
- b[1] = (byte)'.';
- b[14] = (byte)'.';
- n = new String( b );
+ if( n == null ) {
+ n = "null";
+ } else if( n.charAt( 0 ) == 0x01 ) {
+ char c[] = n.toCharArray();
+ c[0] = '.';
+ c[1] = '.';
+ c[14] = '.';
+ n = new String( c );
}
sb.append( n ).append( "<" ).append( toHexChars( hexCode )).append( ">" );
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
} else if( s.equalsIgnoreCase( "BCAST" )) {
tmp[i++] = RESOLVER_BCAST;
} else if( s.equalsIgnoreCase( "DNS" )) {
- i++; // skip
+ ; // skip
} else {
Log.println( Log.WARNINGS, "netbios name service warning",
"unknown resolver method: " + s );
// be ignored; see tryClose comment.
if( socket == null ) {
socket = new DatagramSocket( port, laddr );
- thread = new Thread( this );
+ thread = new Thread( this, "JCIFS-NameServiceClient" );
thread.setDaemon( true );
thread.start();
}
socket.receive( in );
} catch( IOException ioe ) {
tryClose();
- continue;
+ break;
}
Log.println( Log.DEBUGGING, "nbt name service debugging",
Log.printStackTrace( "nbt name service send:", ioe );
throw new UnknownHostException( ioe.getMessage() );
}
+
if( response.received && response.resultCode == 0 ) {
response.addrEntry.hostName.srcHashCode = addr.hashCode();
return response.addrEntry;
}
} while( --n > 0 && request.isBroadcast );
- throw new UnknownHostException( name.name );
+ throw new UnknownHostException( name.toString() );
}
/* If a target address to query was not specified explicitly
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
import java.net.UnknownHostException;
import java.net.SocketException;
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
import java.util.Hashtable;
import jcifs.Config;
public final class NbtAddress {
- static final byte[] MASTER_BROWSER_BYTES = {
- (byte)0x01, (byte)0x02, (byte)0x5F, (byte)0x5F, (byte)0x4D, (byte)0x53,
- (byte)0x42, (byte)0x52, (byte)0x4F, (byte)0x57, (byte)0x53, (byte)0x45,
- (byte)0x5F, (byte)0x5F, (byte)0x02
- };
- static final byte[] SMBSERVER_BYTES = {
- (byte)0x2a, (byte)0x53, (byte)0x4d, (byte)0x42, (byte)0x53, (byte)0x45,
- (byte)0x52, (byte)0x56, (byte)0x45, (byte)0x52, (byte)0x20, (byte)0x20,
- (byte)0x20, (byte)0x20, (byte)0x20
- };
- static final byte[] ALL_HOSTS_BYTES = {
- (byte)0x2A, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
- (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
- (byte)0x00, (byte)0x00, (byte)0x00
- };
-
/*
* This is a special name that means all hosts. If you wish to find all hosts
* on a network querying a workgroup group name is the preferred method.
*/
- static final String ANY_HOSTS_NAME = new String( ALL_HOSTS_BYTES );
+ static final String ANY_HOSTS_NAME = "*\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000";
/**
* This is a special name for querying the master browser that serves the
* list of hosts found in "Network Neighborhood".
*/
- public static final String MASTER_BROWSER_NAME = new String( MASTER_BROWSER_BYTES );
+ public static final String MASTER_BROWSER_NAME = "\u0001\u0002__MSBROWSE__\u0002";
/**
* A special generic name specified when connecting to a host for which
* a name is not known. Not all servers respond to this name.
*/
- public static final String SMBSERVER_NAME = new String( SMBSERVER_BYTES );
+ public static final String SMBSERVER_NAME = "*SMBSERVER ";
/**
* A B node only broadcasts name queries. This is the default if a
static int cachePolicy;
static Hashtable addressCache;
+ static Hashtable lookupTable;
static Name unknownName;
static NbtAddress unknownAddress;
static byte[] unknownMacAddress = new byte[] {
Name localName;
addressCache = new Hashtable();
+ lookupTable = new Hashtable();
cachePolicy = Config.getInt( "jcifs.netbios.cachePolicy", DEFAULT_CACHE_POLICY );
/* Construct the shared static client object that will
* the name deduced above possibly with scope applied and
* cache it forever.
*/
- localName = new Name( localHostname, 0x20,
+ localName = new Name( localHostname, 0x00,
Config.getProperty( "jcifs.netbios.scope", null ));
localhost = new NbtAddress( localName,
localInetAddress.hashCode(),
addr = getCachedAddress( name );
if( addr == null ) {
- try {
- addr = client.getByName( name, svr );
- } catch( UnknownHostException uhe ) {
- addr = unknownAddress;
- } finally {
- cacheAddress( name, addr );
+ /* This was copied amost verbatim from InetAddress.java. See the
+ * comments there for a description of how the lookupTable prevents
+ * redundant queries from going out on the wire.
+ */
+ if(( addr = (NbtAddress)checkLookupTable( name )) == null ) {
+ try {
+ addr = client.getByName( name, svr );
+ } catch( UnknownHostException uhe ) {
+ addr = unknownAddress;
+ } finally {
+ cacheAddress( name, addr );
+ updateLookupTable( name );
+ }
}
}
if( addr == unknownAddress ) {
return addr;
}
+ private static Object checkLookupTable( Name name ) {
+ Object obj;
+
+ synchronized( lookupTable ) {
+ if( lookupTable.containsKey( name ) == false ) {
+ lookupTable.put( name, name );
+ return null;
+ }
+ while( lookupTable.containsKey( name )) {
+ try {
+ lookupTable.wait();
+ } catch( InterruptedException e ) {
+ }
+ }
+ }
+ obj = getCachedAddress( name );
+ if( obj == null ) {
+ synchronized( lookupTable ) {
+ lookupTable.put( name, name );
+ }
+ }
+
+ return obj;
+ }
+ private static void updateLookupTable( Name name ) {
+ synchronized( lookupTable ) {
+ lookupTable.remove( name );
+ lookupTable.notifyAll();
+ }
+ }
+
/**
* Retrieves the local host address.
*
}
/**
- * Determines the address of a host given it's host name. The name can be a
- * machine name like "jcifs.samba.org" or an IP address like "192.168.1.15".
+ * Determines the address of a host given it's host name. The name can be a NetBIOS name like
+ * "freto" or an IP address like "192.168.1.15". It cannot be a DNS name;
+ * the analygous {@link jcifs.UniAddress} or {@link java.net.InetAddress}
+ * <code>getByName</code> methods can be used for that.
*
* @param host hostname to resolve
* @throws java.net.UnknownHostException if there is an error resolving the name
calledName = SMBSERVER_NAME;
break;
}
- if( data[i] == '.' ) {
+ if( i < len && data[i] == '.' ) {
dots++;
i++;
}
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
NodeStatusRequest( Name name ) {
questionName = name;
questionType = NBSTAT;
+ isRecurDesired = false;
+ isBroadcast = false;
}
int writeBodyWireFormat( byte[] dst, int dstIndex ) {
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
package jcifs.netbios;
+import java.io.UnsupportedEncodingException;
+
class NodeStatusResponse extends NameServicePacket {
NbtAddress queryAddress;
boolean isPermanent;
int j;
boolean addrFound = false;
- for( int i = 0; i < numberOfNames; srcIndex += 18, i++ ) {
- for( j = srcIndex + 14; src[j] == 0x20; j-- )
- ;
- n = new String( src, srcIndex, j - srcIndex + 1 );
- hexCode = src[srcIndex + 15] & 0xFF;
- groupName = (( src[srcIndex + 16] & 0x80 ) == 0x80 ) ? true : false;
- ownerNodeType = ( src[srcIndex + 16] & 0x60 ) >> 5;
- isBeingDeleted = (( src[srcIndex + 16] & 0x10 ) == 0x10 ) ? true : false;
- isInConflict = (( src[srcIndex + 16] & 0x08 ) == 0x08 ) ? true : false;
- isActive = (( src[srcIndex + 16] & 0x04 ) == 0x04 ) ? true : false;
- isPermanent = (( src[srcIndex + 16] & 0x02 ) == 0x02 ) ? true : false;
-
-/* The NbtAddress object used to query this node will be in the list
- * returned by the Node Status. A new NbtAddress object should not be
- * created for it because the original is potentially being actively
- * referenced by other objects. We must populate the existing object's
- * data explicitly (and carefully).
- */
- if( !addrFound && queryAddress.hostName.hexCode == hexCode &&
- ( queryAddress.hostName == NbtAddress.unknownName ||
- queryAddress.hostName.name.equals( n ))) {
- if( queryAddress.hostName == NbtAddress.unknownName ) {
- queryAddress.hostName = new Name( n, hexCode, scope );
- }
- queryAddress.groupName = groupName;
- queryAddress.nodeType = ownerNodeType;
- queryAddress.isBeingDeleted = isBeingDeleted;
- queryAddress.isInConflict = isInConflict;
- queryAddress.isActive = isActive;
- queryAddress.isPermanent = isPermanent;
- queryAddress.macAddress = macAddress;
- queryAddress.isDataFromNodeStatus = true;
- addrFound = true;
- addressArray[i] = queryAddress;
- } else {
- addressArray[i] = new NbtAddress( new Name( n, hexCode, scope ),
- queryAddress.address,
- groupName,
- ownerNodeType,
- isBeingDeleted,
- isInConflict,
- isActive,
- isPermanent,
- macAddress );
- }
- }
+ try {
+ for( int i = 0; i < numberOfNames; srcIndex += 18, i++ ) {
+ for( j = srcIndex + 14; src[j] == 0x20; j-- )
+ ;
+ n = new String( src, srcIndex, j - srcIndex + 1, Name.encoding );
+ hexCode = src[srcIndex + 15] & 0xFF;
+ groupName = (( src[srcIndex + 16] & 0x80 ) == 0x80 ) ? true : false;
+ ownerNodeType = ( src[srcIndex + 16] & 0x60 ) >> 5;
+ isBeingDeleted = (( src[srcIndex + 16] & 0x10 ) == 0x10 ) ? true : false;
+ isInConflict = (( src[srcIndex + 16] & 0x08 ) == 0x08 ) ? true : false;
+ isActive = (( src[srcIndex + 16] & 0x04 ) == 0x04 ) ? true : false;
+ isPermanent = (( src[srcIndex + 16] & 0x02 ) == 0x02 ) ? true : false;
+
+ /* The NbtAddress object used to query this node will be in the list
+ * returned by the Node Status. A new NbtAddress object should not be
+ * created for it because the original is potentially being actively
+ * referenced by other objects. We must populate the existing object's
+ * data explicitly (and carefully).
+ */
+ if( !addrFound && queryAddress.hostName.hexCode == hexCode &&
+ ( queryAddress.hostName == NbtAddress.unknownName ||
+ queryAddress.hostName.name.equals( n ))) {
+
+ if( queryAddress.hostName == NbtAddress.unknownName ) {
+ queryAddress.hostName = new Name( n, hexCode, scope );
+ }
+ queryAddress.groupName = groupName;
+ queryAddress.nodeType = ownerNodeType;
+ queryAddress.isBeingDeleted = isBeingDeleted;
+ queryAddress.isInConflict = isInConflict;
+ queryAddress.isActive = isActive;
+ queryAddress.isPermanent = isPermanent;
+ queryAddress.macAddress = macAddress;
+ queryAddress.isDataFromNodeStatus = true;
+ addrFound = true;
+ addressArray[i] = queryAddress;
+ } else {
+ addressArray[i] = new NbtAddress( new Name( n, hexCode, scope ),
+ queryAddress.address,
+ groupName,
+ ownerNodeType,
+ isBeingDeleted,
+ isInConflict,
+ isActive,
+ isPermanent,
+ macAddress );
+ }
+ }
+ } catch( UnsupportedEncodingException uee ) {
+ }
return srcIndex - start;
}
public String toString() {
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
class SocketOutputStream extends FilterOutputStream {
- private static int DEFAULT_BUFR_SIZE = 1500;
+ private static int DEFAULT_BUFR_SIZE = 4400;
private byte[] bufr;
private int count, writeSize;
bufr[count++] = (byte)b;
}
public synchronized void write( byte[] b, int off, int len ) throws IOException {
- if( len >= bufr.length ) {
+ if(( len + 4 ) > bufr.length ) {
Log.println( Log.WARNINGS, "session service warning",
"write len exceeds pre-allocated buffer size; performance " +
"will suffer: len=" + len + ",writeSize=" + writeSize );
--- /dev/null
+/* jcifs smb client library in Java
+ * Copyright (C) 2002 "Michael B. Allen" <jcifs at samba dot org>
+ *
+ * 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;
+
+interface AllocInfo {
+ long getCapacity();
+ long getFree();
+}
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
import java.net.URLConnection;
import java.net.URLStreamHandler;
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+
+import java.io.PrintStream;
public class Handler extends URLStreamHandler {
- SmbFile f;
+ static final URLStreamHandler SMB_HANDLER = new Handler();
+
+static void printURL( URL u, PrintStream out ) {
+ out.println( "host=" + u.getHost() + ",port=" + u.getPort() + ",authority=" + u.getAuthority() + ",userInfo=" + u.getUserInfo() + ",path=" + u.getPath() + ",query=" + u.getQuery() + ",ref=" + u.getRef() );
+}
+
+ static String unescape( String str ) throws NumberFormatException, UnsupportedEncodingException {
+ char ch;
+ int i, j, state, len;
+ char[] out;
+ byte[] b = new byte[1];
+
+ if( str == null ) {
+ return null;
+ }
+
+ len = str.length();
+ out = new char[len];
+ state = 0;
+ for( i = j = 0; i < len; i++ ) {
+ switch( state ) {
+ case 0:
+ ch = str.charAt( i );
+ if( ch == '%' ) {
+ state = 1;
+ } else {
+ out[j++] = ch;
+ }
+ break;
+ case 1:
+ /* Get ASCII hex value and convert to platform dependant
+ * encoding like EBCDIC perhaps
+ */
+ b[0] = (byte)(Integer.parseInt( str.substring( i, i + 2 ), 16 ) & 0xFF);
+ out[j++] = (new String( b, 0, 1, "ASCII" )).charAt( 0 );
+ i++;
+ state = 0;
+ }
+ }
+
+ return new String( out, 0, j );
+ }
+ protected int getDefaultPort() {
+ return 139;
+ }
public URLConnection openConnection( URL u ) throws IOException {
- return new SmbURLConnection( u, f );
+ return new SmbFile( u );
}
protected void parseURL( URL u, String spec, int start, int limit ) {
+ String host = u.getHost();
+ String userinfo, path, ref;
+ if( spec.equals( "smb://" )) {
+ spec = "smb:////";
+ limit += 2;
+ } else if( spec.startsWith( "smb://" ) == false &&
+ host != null && host.length() == 0 ) {
+ spec = "//" + spec;
+ limit += 2;
+ }
+ super.parseURL( u, spec, start, limit );
+ userinfo = u.getUserInfo();
+ path = u.getPath();
+ ref = u.getRef();
try {
- f = new SmbFile( spec, null, start, limit );
- } catch( IOException ioe ) {
- Log.printStackTrace( "smb URLStreamHandler exception", ioe );
+ userinfo = unescape( userinfo );
+ } catch( UnsupportedEncodingException uee ) {
}
- setURL( u, "smb", f.server, f.port, f.canonicalPath, null );
- }
- protected String toExternalForm( URL u ) {
- return f.toString();
+ if (ref != null) {
+ path += '#' + ref;
+ }
+ setURL( u, "smb://", u.getHost(), getDefaultPort(),
+ u.getAuthority(), userinfo,
+ path, u.getQuery(), null );
+//printURL( u, System.err );
}
}
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
package jcifs.smb;
+import java.io.UnsupportedEncodingException;
+
class NetServerEnum2 extends SmbComTransaction {
static final int SV_TYPE_ALL = 0xFFFFFFFF;
static final int SV_TYPE_DOMAIN_ENUM = 0x80000000;
- static final byte[] descripters = new String(
- "WrLehDz" + '\0' + "B16BBDz" + '\0' ).getBytes();
+ static final String DESCR = "WrLehDz\u0000B16BBDz\u0000";
String domain;
int serverTypes;
this.domain = domain;
this.serverTypes = serverTypes;
command = SMB_COM_TRANSACTION;
+ subCommand = NET_SERVER_ENUM2; // not really true be used by upper logic
name = "\\PIPE\\LANMAN";
maxParameterCount = 8;
}
int writeParametersWireFormat( byte[] dst, int dstIndex ) {
int start = dstIndex;
+ byte[] descr;
+
+ try {
+ descr = DESCR.getBytes( "ASCII" );
+ } catch( UnsupportedEncodingException uee ) {
+ return 0;
+ }
writeInt2( NET_SERVER_ENUM2, dst, dstIndex );
dstIndex += 2;
- System.arraycopy( descripters, 0, dst, dstIndex, descripters.length );
- dstIndex += descripters.length;
+ System.arraycopy( descr, 0, dst, dstIndex, descr.length );
+ dstIndex += descr.length;
writeInt2( 0x0001, dst, dstIndex );
dstIndex += 2;
writeInt2( maxDataCount, dst, dstIndex );
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
results = new ServerInfo1[entriesReturned];
for( int i = 0; i < entriesReturned; i++ ) {
results[i] = new ServerInfo1();
- results[i].name = new String( buffer, bufferIndex,
- readStringLength( buffer, bufferIndex, 16 ));
+ results[i].name = readString( buffer, bufferIndex, 16, false );
bufferIndex += 16;
results[i].versionMajor = (int)( buffer[bufferIndex++] & 0xFF );
results[i].versionMinor = (int)( buffer[bufferIndex++] & 0xFF );
bufferIndex += 4;
off = ( off & 0xFFFF ) - converter;
off = start + off;
- results[i].commentOrMasterBrowser = new String( buffer, off,
- readStringLength( buffer, off, 48 ));
-Log.println( Log.DEBUGGING, "net server enum response entry", results[i] );
+ results[i].commentOrMasterBrowser = readString( buffer, off, 48, false );
+Log.println( Log.WARNINGS, "net server enum response entry", results[i] );
}
return bufferIndex - start;
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
package jcifs.smb;
+import java.io.UnsupportedEncodingException;
+
class NetShareEnum extends SmbComTransaction {
- static final byte[] descripters = new String(
- "WrLeh" + '\0' + "B13BWz" + '\0' ).getBytes();
+ static final String DESCR = "WrLeh\u0000B13BWz\u0000";
NetShareEnum() {
command = SMB_COM_TRANSACTION;
+ subCommand = NET_SHARE_ENUM; // not really true be used by upper logic
name = new String( "\\PIPE\\LANMAN" );
maxParameterCount = 8;
}
int writeParametersWireFormat( byte[] dst, int dstIndex ) {
int start = dstIndex;
+ byte[] descr;
+
+ try {
+ descr = DESCR.getBytes( "ASCII" );
+ } catch( UnsupportedEncodingException uee ) {
+ return 0;
+ }
writeInt2( NET_SHARE_ENUM, dst, dstIndex );
dstIndex += 2;
- System.arraycopy( descripters, 0, dst, dstIndex, descripters.length );
- dstIndex += descripters.length;
+ System.arraycopy( descr, 0, dst, dstIndex, descr.length );
+ dstIndex += descr.length;
writeInt2( 0x0001, dst, dstIndex );
dstIndex += 2;
writeInt2( maxDataCount, dst, dstIndex );
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
results = new ShareInfo1[entriesReturned];
for( int i = 0; i < entriesReturned; i++ ) {
results[i] = new ShareInfo1();
- results[i].netName = new String( buffer, bufferIndex,
- readStringLength( buffer, bufferIndex, 13 ));
+ results[i].netName = readString( buffer, bufferIndex, 13, false );
bufferIndex += 14;
results[i].type = readInt2( buffer, bufferIndex );
bufferIndex += 2;
bufferIndex += 4;
off = ( off & 0xFFFF ) - converter;
off = start + off;
- results[i].remark = new String( buffer, off,
- readStringLength( buffer, off, 128 ));
-Log.println( Log.DEBUGGING, "smb warning", results[i] );
+ results[i].remark = readString( buffer, off, 128, false );
+Log.println( Log.WARNINGS, "smb warning", results[i] );
}
return bufferIndex - start;
--- /dev/null
+/* jcifs smb client library in Java
+ * Copyright (C) 2002 "Michael B. Allen" <jcifs at samba dot org>
+ *
+ * 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;
+
+/**
+This class can be extended by applications that wish to trap authentication related exceptions and automatically retry the exceptional operation with different credentials. Read <a href="../../../authhandler.html">jCIFS Exceptions and NtlmAuthenticator</a> for complete details.
+ */
+
+public abstract class NtlmAuthenticator {
+
+ private static NtlmAuthenticator auth;
+
+ private String url;
+ private SmbAuthException sae;
+
+ private void reset() {
+ url = null;
+ sae = null;
+ }
+
+/**
+Set the default <tt>NtlmAuthenticator</tt>. Once the default authenticator is set it cannot be changed. Calling this metho again will have no effect.
+ */
+
+ public synchronized static void setDefault( NtlmAuthenticator a ) {
+ if( auth != null ) {
+ return;
+ }
+ auth = a;
+ }
+
+ protected final String getRequestingURL() {
+ return url;
+ }
+ protected final SmbAuthException getRequestingException() {
+ return sae;
+ }
+
+/**
+Used internally by jCIFS when an <tt>SmbAuthException</tt> is trapped to retrieve new user credentials.
+ */
+
+ public static NtlmPasswordAuthentication
+ requestNtlmPasswordAuthentication( String url, SmbAuthException sae ) {
+ if( auth == null ) {
+ return null;
+ }
+ synchronized( auth ) {
+ auth.url = url;
+ auth.sae = sae;
+ return auth.getNtlmPasswordAuthentication();
+ }
+ }
+/**
+An application extending this class must provide an implementation for this method that returns new user credentials try try when accessing SMB resources described by the <tt>getRequestingURL</tt> and <tt>getRequestingException</tt> methods.
+If this method returns <tt>null</tt> the <tt>SmbAuthException</tt> that triggered the authenticator check will simply be rethrown. The default implementation returns <tt>null</tt>.
+*/
+ protected NtlmPasswordAuthentication getNtlmPasswordAuthentication() {
+ return null;
+ }
+}
--- /dev/null
+/* jcifs smb client library in Java
+ * Copyright (C) 2002 "Michael B. Allen" <jcifs at samba dot org>
+ *
+ * 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.util.DES;
+import jcifs.util.MD4;
+import java.io.UnsupportedEncodingException;
+import java.security.Principal;
+import java.util.Arrays;
+import jcifs.Config;
+
+/**
+ * This class stores and encrypts NTLM user credentials. The default
+ * credentials are retrieved from the <tt>jcifs.smb.client.domain</tt>,
+ * <tt>jcifs.smb.client.username</tt>, and <tt>jcifs.smb.client.password</tt>
+ * properties.
+ * <p>
+ * Read <a href="../../../authhandler.html">jCIFS Exceptions and
+ * NtlmAuthenticator</a> for related information.
+ */
+
+public final class NtlmPasswordAuthentication implements Principal {
+
+ // KGS!@#$%
+ static final byte[] S8 = {
+ (byte)0x4b, (byte)0x47, (byte)0x53, (byte)0x21,
+ (byte)0x40, (byte)0x23, (byte)0x24, (byte)0x25
+ };
+ static void E( byte[] key, byte[] data, byte[] e ) {
+ byte[] key7 = new byte[7];
+ byte[] e8 = new byte[8];
+
+ for( int i = 0; i < key.length / 7; i++ ) {
+ System.arraycopy( key, i * 7, key7, 0, 7 );
+ DES des = new DES( key7 );
+ des.encrypt( data, e8 );
+ System.arraycopy( e8, 0, e, i * 8, 8 );
+ }
+ }
+ static byte[] getPreNTLMResponse( String password, byte[] challenge ) {
+ byte[] p14 = new byte[14];
+ byte[] p21 = new byte[21];
+ byte[] p24 = new byte[24];
+ byte[] passwordBytes;
+ try {
+ passwordBytes = password.toUpperCase().getBytes( ServerMessageBlock.encoding );
+ } catch( UnsupportedEncodingException uee ) {
+ return null;
+ }
+ int passwordLength = passwordBytes.length;
+
+ // Only encrypt the first 14 bytes of the password for Pre 0.12 NT LM
+ if( passwordLength > 14) {
+ passwordLength = 14;
+ }
+ System.arraycopy( passwordBytes, 0, p14, 0, passwordLength );
+ E( p14, S8, p21);
+ E( p21, challenge, p24);
+ return p24;
+ }
+ static byte[] getNTLMResponse( String password, byte[] challenge ) {
+ byte[] uni = null;
+ byte[] p21 = new byte[21];
+ byte[] p24 = new byte[24];
+
+ try {
+ uni = password.getBytes( "UnicodeLittleUnmarked" );
+ } catch( UnsupportedEncodingException uee ) {
+ Log.printStackTrace( "password encryption exception", uee );
+ }
+ MD4 md4 = new MD4();
+ md4.update( uni );
+ System.arraycopy( md4.digest(), 0, p21, 0, 16 );
+ E( p21, challenge, p24 );
+ return p24;
+ }
+
+ static final NtlmPasswordAuthentication NULL =
+ new NtlmPasswordAuthentication( "", "", "" );
+ static final NtlmPasswordAuthentication GUEST =
+ new NtlmPasswordAuthentication( "?", "GUEST", "" );
+
+ String domain;
+ String username;
+ String password;
+ byte[] ansiHash;
+ byte[] unicodeHash;
+ boolean hashesExternal = false;
+
+/**
+ * Create an <tt>NtlmPasswordAuthentication</tt> object from the userinfo
+ * component of an SMB URL like "<tt>domain;user:pass</tt>". This constructor
+ * is used internally be jCIFS when parsing SMB URLs.
+ */
+
+ public NtlmPasswordAuthentication( String userInfo ) {
+ domain = username = password = null;
+
+ if( userInfo != null ) {
+ int i, u, end;
+ char c;
+
+ end = userInfo.length();
+ for( i = 0, u = 0; i < end; i++ ) {
+ c = userInfo.charAt( i );
+ if( c == ';' ) {
+ domain = userInfo.substring( 0, i );
+ u = i + 1;
+ } else if( c == ':' ) {
+ password = userInfo.substring( i + 1 );
+ break;
+ }
+ }
+ username = userInfo.substring( u, i );
+ }
+
+ if( domain == null ) {
+ this.domain = Config.getProperty( "jcifs.smb.client.domain", "?" );
+ }
+ if( username == null ) {
+ this.username = Config.getProperty( "jcifs.smb.client.username", "GUEST" );
+ }
+ if( password == null ) {
+ this.password = Config.getProperty( "jcifs.smb.client.password", "" );
+ }
+ }
+/**
+ * Create an <tt>NtlmPasswordAuthentication</tt> object from a
+ * domain, username, and password. Parameters that are <tt>null</tt>
+ * will be substituted with <tt>jcifs.smb.client.domain</tt>,
+ * <tt>jcifs.smb.client.username</tt>, <tt>jcifs.smb.client.password</tt>
+ * property values.
+ */
+ public NtlmPasswordAuthentication( String domain, String username, String password ) {
+ this.domain = domain;
+ this.username = username;
+ this.password = password;
+ if( domain == null ) {
+ this.domain = Config.getProperty( "jcifs.smb.client.domain", "?" );
+ }
+ if( username == null ) {
+ this.username = Config.getProperty( "jcifs.smb.client.username", "GUEST" );
+ }
+ if( password == null ) {
+ this.password = Config.getProperty( "jcifs.smb.client.password", "" );
+ }
+ }
+/**
+ * Create an <tt>NtlmPasswordAuthentication</tt> object with raw password
+ * hashes. This is used exclusively by the <tt>jcifs.http.NtlmSsp</tt>
+ * class which is in turn used by NTLM HTTP authentication functionality.
+ */
+ public NtlmPasswordAuthentication( String domain, String username,
+ byte[] ansiHash, byte[] unicodeHash ) {
+ if( domain == null || username == null ||
+ ansiHash == null || unicodeHash == null ) {
+ throw new IllegalArgumentException( "External credentials cannot null" );
+ }
+ this.domain = domain;
+ this.username = username;
+ this.password = null;
+ this.ansiHash = ansiHash;
+ this.unicodeHash = unicodeHash;
+ hashesExternal = true;
+ }
+
+/**
+ * Returns the domain.
+ */
+ public String getDomain() {
+ return domain;
+ }
+/**
+ * Returns the username.
+ */
+ public String getUsername() {
+ return username;
+ }
+/**
+ * Returns the password in plain text or <tt>null</tt> if the raw password
+ * hashes were used to construct this <tt>NtlmPasswordAuthentication</tt>
+ * object which will be the case when NTLM HTTP Authentication is
+ * used. There is no way to retrieve a users password in plain text unless
+ * it is supplied by the user at runtime.
+ */
+ public String getPassword() {
+ return password;
+ }
+/**
+ * Return the domain and username in the format:
+ * <tt>domain\\username</tt>. This is equivalent to <tt>toString()</tt>.
+ */
+ public String getName() {
+ boolean d = domain.length() > 0 && domain.equals( "?" ) == false;
+ return d ? domain + "\\" + username : username;
+ }
+/**
+ * Computes the 24 byte ANSI password hash given the 8 byte server challenge.
+ */
+ public byte[] getAnsiHash( byte[] challenge ) {
+ if( hashesExternal ) {
+ return ansiHash;
+ }
+ return getPreNTLMResponse( password, challenge );
+ }
+/**
+ * Computes the 24 byte Unicode password hash given the 8 byte server challenge.
+ */
+ public byte[] getUnicodeHash( byte[] challenge ) {
+ if( hashesExternal ) {
+ return unicodeHash;
+ }
+ return getNTLMResponse( password, challenge );
+ }
+/**
+ * Compares two <tt>NtlmPasswordAuthentication</tt> objects for
+ * equality. Two <tt>NtlmPasswordAuthentication</tt> objects are equal if
+ * their caseless domain and username fields are equal and either both hashes are external and they are equal or both internally supplied passwords are equal. If one <tt>NtlmPasswordAuthentication</tt> object has external hashes (meaning negotiated via NTLM HTTP Authentication) and the other does not they will not be equal. This is technically not correct however the server 8 byte challage would be required to compute and compare the password hashes but that it not available with this method.
+ */
+ public boolean equals( Object obj ) {
+ if( obj instanceof NtlmPasswordAuthentication ) {
+ NtlmPasswordAuthentication ntlm = (NtlmPasswordAuthentication)obj;
+ if( ntlm.domain.toUpperCase().equals( domain.toUpperCase() ) &&
+ ntlm.username.toUpperCase().equals( username.toUpperCase() )) {
+ if( hashesExternal && ntlm.hashesExternal ) {
+ return Arrays.equals( ansiHash, ntlm.ansiHash ) &&
+ Arrays.equals( unicodeHash, ntlm.unicodeHash );
+ /* This still isn't quite right. If one npa object does not have external
+ * hashes and the other does then they will not be considered equal even
+ * though they may be.
+ */
+ } else if( !hashesExternal && password.equals( ntlm.password )) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+
+/**
+ * Return the upcased username hash code.
+ */
+ public int hashCode() {
+ return getName().toUpperCase().hashCode();
+ }
+/**
+ * Return the domain and username in the format:
+ * <tt>domain\\username</tt>. This is equivalent to <tt>getName()</tt>.
+ */
+ public String toString() {
+ return getName();
+ }
+}
+
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
static final TimeZone TZ = TimeZone.getDefault();
static boolean useBatching = Config.getBoolean( "jcifs.smb.client.useBatching", true );
+ static String encoding = Config.getProperty( "jcifs.smb.client.codepage",
+ Config.getProperty( "jcifs.encoding",
+ System.getProperty( "file.encoding" )));
static final byte[] header = {
(byte)0xFF, (byte)'S', (byte)'M', (byte)'B',
synchronized( TZ ) {
if( TZ.inDaylightTime( new Date() )) {
- // in dst
+ // in DST
if( TZ.inDaylightTime( new Date( t ))) {
- // t also in dst so no correction
+ // t also in DST so no correction
return t;
}
- // t not in dst so add 1 hour
+ // t not in DST so add 1 hour
return t + 3600000;
} else {
- // not in dst
+ // not in DST
if( TZ.inDaylightTime( new Date( t ))) {
- // t is in dst so subtract 1 hour
+ // t is in DST so subtract 1 hour
return t - 3600000;
}
- // t isn't in dst either
+ // t isn't in DST either
return t;
}
}
static long readUTime( byte[] buffer, int bufferIndex ) {
return readInt4( buffer, bufferIndex ) * 1000L;
}
+ static void writeTime( long t, byte[] dst, int dstIndex ) {
+ if( t == 0L || t == 0xFFFFFFFFFFFFFFFFL ) {
+ writeInt4( 0xFFFFFFFF, dst, dstIndex );
+ return;
+ }
+ synchronized( TZ ) {
+ if( TZ.inDaylightTime( new Date() )) {
+ // in DST
+ if( TZ.inDaylightTime( new Date( t ))) {
+ // t also in DST so no correction
+ } else {
+ // t not in DST so subtract 1 hour
+ t -= 3600000;
+ }
+ } else {
+ // not in DST
+ if( TZ.inDaylightTime( new Date( t ))) {
+ // t is in DST so add 1 hour
+ t += 3600000;
+ } else {
+ // t isn't in DST either
+ }
+ }
+ }
+ writeInt4( (int)(t / 1000L), dst, dstIndex );
+ }
/*
static final byte SMB_COM_CHECK_DIRECTORY = (byte)0x10;
static final byte SMB_COM_TRANSACTION = (byte)0x25;
static final byte SMB_COM_TRANSACTION_SECONDARY = (byte)0x26;
- static final byte SMB_COM_COPY = (byte)0x29;
static final byte SMB_COM_MOVE = (byte)0x2A;
static final byte SMB_COM_ECHO = (byte)0x2B;
static final byte SMB_COM_OPEN_ANDX = (byte)0x2D;
int writeString( String str, byte[] dst, int dstIndex, boolean useUnicode ) {
int start = dstIndex;
- if( useUnicode ) {
- try {
+ try {
+ if( useUnicode ) {
// Unicode requires word alignment
if((( dstIndex - headerStart ) % 2 ) != 0 ) {
dst[dstIndex++] = (byte)'\0';
System.arraycopy( str.getBytes( "UnicodeLittleUnmarked" ), 0,
dst, dstIndex, str.length() * 2 );
dstIndex += str.length() * 2;
- } catch( UnsupportedEncodingException uee ) {
- Log.printStackTrace( "smb exception", uee );
+ dst[dstIndex++] = (byte)'\0';
+ dst[dstIndex++] = (byte)'\0';
+ } else {
+ byte[] b = str.getBytes( encoding );
+ System.arraycopy( b, 0, dst, dstIndex, b.length );
+ dstIndex += b.length;
+ dst[dstIndex++] = (byte)'\0';
}
- dst[dstIndex++] = (byte)'\0';
- dst[dstIndex++] = (byte)'\0';
- } else {
- System.arraycopy( str.getBytes(), 0, dst, dstIndex, str.length() );
- dstIndex += str.length();
- dst[dstIndex++] = (byte)'\0';
+ } catch( UnsupportedEncodingException uee ) {
+ Log.printStackTrace( "smb exception", uee );
}
return dstIndex - start;
}
String readString( byte[] src, int srcIndex ) {
+ return readString( src, srcIndex, 256, useUnicode );
+ }
+ String readString( byte[] src, int srcIndex, int maxLen, boolean useUnicode ) {
int len = 0;
String str = null;
- if( useUnicode ) {
- // Unicode requires word alignment
- if((( srcIndex - headerStart ) % 2 ) != 0 ) {
- srcIndex++;
- }
- while( src[srcIndex + len] != (byte)0x00 ||
- src[srcIndex + len + 1] != (byte)0x00 ) {
- len += 2;
- if( len > 256 ) {
- throw new RuntimeException( "zero termination not found" );
+ try {
+ if( useUnicode ) {
+ // Unicode requires word alignment
+ if((( srcIndex - headerStart ) % 2 ) != 0 ) {
+ srcIndex++;
+ }
+ while( src[srcIndex + len] != (byte)0x00 ||
+ src[srcIndex + len + 1] != (byte)0x00 ) {
+ len += 2;
+ if( len > maxLen ) {
+jcifs.util.Log.printHexDump( System.err, src, 0, 256 );
+ throw new RuntimeException( "zero termination not found" );
+ }
}
- }
- try {
str = new String( src, srcIndex, len, "UnicodeLittle" );
- } catch( UnsupportedEncodingException uee ) {
- Log.printStackTrace( "smb exception", uee );
- }
- } else {
- while( src[srcIndex + len] != (byte)0x00 ) {
- len++;
- if( len > 256 ) {
- throw new RuntimeException( "zero termination not found" );
+ } else {
+ while( src[srcIndex + len] != (byte)0x00 ) {
+ len++;
+ if( len > maxLen ) {
+ throw new RuntimeException( "zero termination not found" );
+ }
}
+ str = new String( src, srcIndex, len, encoding );
}
- str = new String( src, srcIndex, len );
+ } catch( UnsupportedEncodingException uee ) {
+ Log.printStackTrace( "smb exception", uee );
}
return str;
}
case SMB_COM_RENAME:
c = "SMB_COM_RENAME";
break;
- case SMB_COM_COPY:
- c = "SMB_COM_COPY";
- break;
case SMB_COM_DELETE:
c = "SMB_COM_DELETE";
break;
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
package jcifs.smb;
+/**
+ * The <code>SmbAuthException</code> encapsulates the variety of
+ * authentication related error codes returned by an SMB server.
+ * <p>
+ * See <a href="../../../authhandler.html">jCIFS Exceptions and NtlmAuthenticator</a> for more information about <code>SmbAuthException</code>.
+ */
+
public class SmbAuthException extends SmbException {
public SmbAuthException( int code ) {
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
class SmbComClose extends ServerMessageBlock {
- int fid, lastWriteTime;
+ int fid;
+ long lastWriteTime;
- SmbComClose( int fid ) {
+ SmbComClose( int fid, long lastWriteTime ) {
this.fid = fid;
+ this.lastWriteTime = lastWriteTime;
command = SMB_COM_CLOSE;
}
int writeParameterWordsWireFormat( byte[] dst, int dstIndex ) {
writeInt2( fid, dst, dstIndex );
dstIndex += 2;
- lastWriteTime = 0xFFFFFFFF;
- writeInt4( lastWriteTime, dst, dstIndex );
+ writeTime( lastWriteTime, dst, dstIndex );
return 6;
}
int writeBytesWireFormat( byte[] dst, int dstIndex ) {
return new String( "SmbComClose[" +
super.toString() +
",fid=" + fid +
- ",lastWriteTime=" + ( new Date( lastWriteTime )) + "]" );
+ ",lastWriteTime=" + lastWriteTime + "]" );
}
}
+++ /dev/null
-/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
- *
- * 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;
-
-class SmbComCopy extends ServerMessageBlock {
-
- String sourceFileName;
- String targetFileName;
- int tid2;
- int openFunction;
- int flags;
-
- SmbComCopy( String sourceFileName, String targetFileName, int tid2 ) {
- this.sourceFileName = sourceFileName;
- this.targetFileName = targetFileName;
- this.tid2 = tid2 > 0 ? tid2 : -1;
- command = SMB_COM_COPY;
- openFunction = OPEN_FUNCTION_FAIL_IF_EXISTS;
- flags = FLAGS_TARGET_MUST_BE_FILE;
- }
-
- int writeParameterWordsWireFormat( byte[] dst, int dstIndex ) {
- writeInt2( tid2, dst, dstIndex );
- dstIndex += 2;
- writeInt2( openFunction, dst, dstIndex );
- dstIndex += 2;
- writeInt2( flags, dst, dstIndex );
- return 6;
- }
- int writeBytesWireFormat( byte[] dst, int dstIndex ) {
- int start = dstIndex;
-
- dst[dstIndex++] = (byte)0x04;
- dstIndex += writeString( sourceFileName, dst, dstIndex );
- dst[dstIndex++] = (byte)0x04;
- dstIndex += writeString( targetFileName, dst, dstIndex );
-
- return dstIndex - start;
- }
- int readParameterWordsWireFormat( byte[] buffer, int bufferIndex ) {
- return 0;
- }
- int readBytesWireFormat( byte[] buffer, int bufferIndex ) {
- return 0;
- }
- public String toString() {
- return new String( "SmbComCopy[" +
- super.toString() +
- ",sourceFileName=" + sourceFileName +
- ",targetFileName=" + targetFileName + "]" );
- }
-}
+++ /dev/null
-/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
- *
- * 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;
-
-class SmbComCopyResponse extends ServerMessageBlock {
-
- int count;
- String errorFileName;
-
- SmbComCopyResponse() {
- count = 0;
- errorFileName = "";
- }
-
- int writeParameterWordsWireFormat( byte[] dst, int dstIndex ) {
- return 0;
- }
- int writeBytesWireFormat( byte[] dst, int dstIndex ) {
- return 0;
- }
- int readParameterWordsWireFormat( byte[] buffer, int bufferIndex ) {
- count = readInt2( buffer, bufferIndex );
- return 2;
- }
- int readBytesWireFormat( byte[] buffer, int bufferIndex ) {
- bufferIndex++;
- errorFileName = readString( buffer, bufferIndex );
- return stringWireLength( errorFileName, bufferIndex );
- }
- public String toString() {
- return new String( "SmbComCopyResponse[" +
- super.toString() +
- ",count=" + count +
- ",errorFileName=" + errorFileName + "]" );
- }
-}
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
static final int GENERIC_WRITE = 0x40000000; // 30
static final int GENERIC_READ = 0x80000000; // 31
- // share access
- static final int FILE_NO_SHARE = 0x00;
- static final int FILE_SHARE_READ = 0x01;
- static final int FILE_SHARE_WRITE = 0x02;
- static final int FILE_SHARE_DELETE = 0x04;
+ // share access specified in SmbFile
// create disposition
long allocationSize;
byte securityFlags;
- SmbComNTCreateAndX( String name, int flags, ServerMessageBlock andx ) {
+ SmbComNTCreateAndX( String name, int flags, ServerMessageBlock andx, int shareAccess ) {
super( andx );
this.name = name;
command = SMB_COM_NT_CREATE_ANDX;
extFileAttributes = ATTR_NORMAL;
// shareAccess
- shareAccess = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
+ this.shareAccess = shareAccess;
// createDisposition
if(( flags & SmbFile.O_TRUNC ) == SmbFile.O_TRUNC ) {
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
package jcifs.smb;
+import java.io.UnsupportedEncodingException;
+
class SmbComNegotiate extends ServerMessageBlock {
- static final byte[] dialects = new String(
- '\2' + "NT LM 0.12" + '\0' ).getBytes();
+ static final String DIALECTS = "\u0002NT LM 0.12\u0000";
SmbComNegotiate() {
command = SMB_COM_NEGOTIATE;
return 0;
}
int writeBytesWireFormat( byte[] dst, int dstIndex ) {
+ byte[] dialects;
+ try {
+ dialects = DIALECTS.getBytes( "ASCII" );
+ } catch( UnsupportedEncodingException uee ) {
+ return 0;
+ }
System.arraycopy( dialects, 0, dst, dstIndex, dialects.length );
return dialects.length;
}
return new String( "SmbComNegotiate[" +
super.toString() +
",wordCount=" + wordCount +
- ",byteCount=" + dialects.length +
",dialects=NT LM 0.12]" );
}
}
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
encryptionKey, 0, encryptionKeyLength );
bufferIndex += encryptionKeyLength;
- int len = 0;
- if(( flags2 & FLAGS2_UNICODE ) == FLAGS2_UNICODE ) {
- while( buffer[bufferIndex + len] != (byte)0x00 ||
- buffer[bufferIndex + len + 1] != (byte)0x00 ) {
- len += 2;
- if( len > 256 ) {
- throw new RuntimeException( "zero termination not found" );
+ if( byteCount > encryptionKeyLength ) {
+ int len = 0;
+ if(( flags2 & FLAGS2_UNICODE ) == FLAGS2_UNICODE ) {
+ while( buffer[bufferIndex + len] != (byte)0x00 ||
+ buffer[bufferIndex + len + 1] != (byte)0x00 ) {
+ len += 2;
+ if( len > 256 ) {
+ throw new RuntimeException( "zero termination not found" );
+ }
}
- }
- try {
- oemDomainName = new String( buffer, bufferIndex, len, "UnicodeLittle" );
- } catch( UnsupportedEncodingException uee ) {
- Log.printStackTrace( "smb exception", uee );
- }
- } else {
- while( buffer[bufferIndex + len] != (byte)0x00 ) {
- len++;
- if( len > 256 ) {
- throw new RuntimeException( "zero termination not found" );
+ try {
+ oemDomainName = new String( buffer, bufferIndex, len, "UnicodeLittle" );
+ } catch( UnsupportedEncodingException uee ) {
+ Log.printStackTrace( "smb exception", uee );
+ }
+ } else {
+ while( buffer[bufferIndex + len] != (byte)0x00 ) {
+ len++;
+ if( len > 256 ) {
+ throw new RuntimeException( "zero termination not found" );
+ }
+ }
+ try {
+ oemDomainName = new String( buffer, bufferIndex, len, ServerMessageBlock.encoding );
+ } catch( UnsupportedEncodingException uee ) {
}
}
- oemDomainName = new String( buffer, bufferIndex, len );
+ bufferIndex += len;
+ } else {
+ oemDomainName = new String();
}
- bufferIndex += len;
return bufferIndex - start;
}
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
static final int BATCH_LIMIT = Config.getInt( "jcifs.smb.client.ReadAndX.Close", 1 );
+ long offset;
int fid,
- offset,
maxCount,
minCount,
openTimeout,
remaining;
- SmbComReadAndX( int fid, int offset, int maxCount, ServerMessageBlock andx ) {
+ SmbComReadAndX() {
+ super( null );
+ command = SMB_COM_READ_ANDX;
+ openTimeout = 0xFFFFFFFF;
+ }
+ SmbComReadAndX( int fid, long offset, int maxCount, ServerMessageBlock andx ) {
super( andx );
this.fid = fid;
this.offset = offset;
openTimeout = 0xFFFFFFFF;
}
+ void setParam( int fid, long offset, int maxCount ) {
+ this.fid = fid;
+ this.offset = offset;
+ this.maxCount = minCount = maxCount;
+ }
int getBatchLimit( byte command ) {
return command == SMB_COM_CLOSE ? BATCH_LIMIT : 0;
}
writeInt2( fid, dst, dstIndex );
dstIndex += 2;
- writeInt4( offset, dst, dstIndex );
+ writeInt4( offset & 0xFFFFFFFFL, dst, dstIndex );
dstIndex += 4;
writeInt2( maxCount, dst, dstIndex );
dstIndex += 2;
dstIndex += 4;
writeInt2( remaining, dst, dstIndex );
dstIndex += 2;
- writeInt4( 0, dst, dstIndex );
+ writeInt4(( offset >> 32 ) & 0xFFFFFFFFL, dst, dstIndex );
dstIndex += 4;
return dstIndex - start;
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
dataOffset,
off;
+ SmbComReadAndXResponse() {
+ }
SmbComReadAndXResponse( byte[] b, int off ) {
this.b = b;
this.off = off;
}
+ void setParam( byte[] b, int off ) {
+ this.b = b;
+ this.off = off;
+ }
int writeParameterWordsWireFormat( byte[] dst, int dstIndex ) {
return 0;
}
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
int start = dstIndex;
if( session.transport.server.security == SECURITY_USER &&
- session.password.length() != 0 ) {
+ ( session.auth.hashesExternal ||
+ session.auth.password.length() > 0 )) {
if( session.transport.server.encryptedPasswords ) {
// encrypted
- accountPassword = SmbSession.getPreNTLMResponse( session.password,
- session.transport.server.encryptionKey );
- unicodePassword = SmbSession.getNTLMResponse( session.password,
- session.transport.server.encryptionKey );
+ accountPassword = session.auth.getAnsiHash( session.transport.server.encryptionKey );
+ unicodePassword = session.auth.getUnicodeHash( session.transport.server.encryptionKey );
passwordLength = unicodePasswordLength = 24;
+ } else if( Config.getBoolean( "jcifs.smb.client.disablePlainTextPasswords", true )) {
+ throw new RuntimeException( "Plain text passwords are disabled" );
+ } else if( useUnicode ) {
+ // plain text
+ String password = session.auth.getPassword();
+ accountPassword = new byte[0];
+ passwordLength = 0;
+ unicodePassword = new byte[(password.length() + 1) * 2];
+ unicodePasswordLength = writeString( password, unicodePassword, 0 );
} else {
// plain text
- throw new RuntimeException( "plain text passwords not implemented" );
+ String password = session.auth.getPassword();
+ accountPassword = new byte[(password.length() + 1) * 2];
+ passwordLength = writeString( password, accountPassword, 0 );
+ unicodePassword = new byte[0];
+ unicodePasswordLength = 0;
}
} else {
// no password in session setup
int writeBytesWireFormat( byte[] dst, int dstIndex ) {
int start = dstIndex;
- accountName = session.username;
- primaryDomain = session.domain;
+ accountName = session.auth.username.toUpperCase();
+ primaryDomain = session.auth.domain.toUpperCase();
nativeOs = session.transport.client.nativeOs;
nativeLanMan = session.transport.client.nativeLanMan;
if( session.transport.server.security == SECURITY_USER &&
- session.password.length() != 0 ) {
+ ( session.auth.hashesExternal ||
+ session.auth.password.length() > 0 )) {
System.arraycopy( accountPassword, 0, dst, dstIndex, passwordLength );
dstIndex += passwordLength;
System.arraycopy( unicodePassword, 0, dst, dstIndex, unicodePasswordLength );
",passwordLength=" + passwordLength +
",unicodePasswordLength=" + unicodePasswordLength +
",capabilities=" + session.transport.client.capabilities +
- ",accountPassword=" + accountPassword +
",accountName=" + accountName +
",primaryDomain=" + primaryDomain +
",nativeOs=" + nativeOs +
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
import java.io.IOException;
import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
class SmbComSessionSetupAndXResponse extends AndXServerMessageBlock {
bufferIndex += stringWireLength( nativeOs, bufferIndex );
nativeLanMan = readString( buffer, bufferIndex );
bufferIndex += stringWireLength( nativeLanMan, bufferIndex );
- primaryDomain = readString( buffer, bufferIndex );
- bufferIndex += stringWireLength( primaryDomain, bufferIndex );
+
+ if( useUnicode ) {
+ int len;
+
+ if((( bufferIndex - headerStart ) % 2 ) != 0 ) {
+ bufferIndex++;
+ }
+
+ len = 0;
+ while( buffer[bufferIndex + len] != (byte)0x00 ) {
+ len += 2;
+ if( len > 256 ) {
+jcifs.util.Log.printHexDump( System.err, buffer, 0, 256 );
+ throw new RuntimeException( "zero termination not found" );
+ }
+ }
+ try {
+ primaryDomain = new String( buffer, bufferIndex, len, "UnicodeLittle" );
+ } catch( UnsupportedEncodingException uee ) {
+ Log.printStackTrace( "smb exception", uee );
+ }
+ bufferIndex += len;
+ } else {
+ primaryDomain = readString( buffer, bufferIndex );
+ bufferIndex += stringWireLength( primaryDomain, bufferIndex );
+ }
return bufferIndex - start;
}
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
static final int NET_SHARE_ENUM = 0x0000;
static final int NET_SERVER_ENUM2 = 0x0068;
+ static final byte TRANS_PEEK_NAMED_PIPE = (byte)0x23;
static final byte TRANS_WAIT_NAMED_PIPE = (byte)0x53;
static final byte TRANS_CALL_NAMED_PIPE = (byte)0x54;
static final byte TRANS_TRANSACT_NAMED_PIPE = (byte)0x26;
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
int pad1;
boolean hasMore = true;
boolean isPrimary = true;
+ boolean parametersDone, dataDone;
byte[] txn_buf;
int bufParameterStart;
* read. If so call the read methods.
*/
- if(( parameterDisplacement + parameterCount ) == totalParameterCount &&
- ( dataDisplacement + dataCount ) == totalDataCount ) {
+ if( !parametersDone &&
+ ( parameterDisplacement + parameterCount ) == totalParameterCount) {
+ parametersDone = true;
+ }
+
+ if( !dataDone &&
+ ( dataDisplacement + dataCount ) == totalDataCount) {
+ dataDone = true;
+ }
+
+ if( parametersDone && dataDone ) {
hasMore = false;
readParametersWireFormat( txn_buf, bufParameterStart, totalParameterCount );
readDataWireFormat( txn_buf, bufDataStart, totalDataCount );
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
import jcifs.util.PropertiesTree;
import java.io.IOException;
import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
class SmbComTreeConnectAndX extends AndXServerMessageBlock {
/* batchLimits indecies
*
* 0 = SMB_COM_CHECK_DIRECTORY
- * 1 = SMB_COM_COPY
* 2 = SMB_COM_CREATE_DIRECTORY
* 3 = SMB_COM_DELETE
* 4 = SMB_COM_DELETE_DIRECTORY
if(( s = pt.getProperty( "CheckDirectory" )) != null ) {
batchLimits[0] = Byte.parseByte( s );
}
- if(( s = pt.getProperty( "Copy" )) != null ) {
- batchLimits[1] = Byte.parseByte( s );
- }
if(( s = pt.getProperty( "CreateDirectory" )) != null ) {
batchLimits[2] = Byte.parseByte( s );
}
switch( c ) {
case SMB_COM_CHECK_DIRECTORY:
return batchLimits[0];
- case SMB_COM_COPY:
- return batchLimits[1];
case SMB_COM_CREATE_DIRECTORY:
return batchLimits[2];
case SMB_COM_DELETE:
int writeParameterWordsWireFormat( byte[] dst, int dstIndex ) {
if( session.transport.server.security == SECURITY_SHARE &&
- session.password.length() != 0 ) {
+ ( session.auth.hashesExternal ||
+ session.auth.password.length() > 0 )) {
+
if( session.transport.server.encryptedPasswords ) {
// encrypted
- password = SmbSession.getPreNTLMResponse( session.password,
- session.transport.server.encryptionKey );
+ password = session.auth.getAnsiHash( session.transport.server.encryptionKey );
passwordLength = 24;
+ } else if( Config.getBoolean( "jcifs.smb.client.disablePlainTextPasswords", true )) {
+ throw new RuntimeException( "Plain text passwords are disabled" );
} else {
// plain text
- throw new RuntimeException( "plain text passwords not implemented" );
+ password = new byte[(session.auth.password.length() + 1) * 2];
+ passwordLength = writeString( session.auth.password, password, 0 );
}
} else {
// no password in tree connect
passwordLength = 1;
}
- dst[dstIndex++] = (byte)0x00;
dst[dstIndex++] = disconnectTid ? (byte)0x01 : (byte)0x00;
+ dst[dstIndex++] = (byte)0x00;
writeInt2( passwordLength, dst, dstIndex );
return 4;
}
int start = dstIndex;
if( session.transport.server.security == SECURITY_SHARE &&
- session.password.length() != 0 ) {
- if( session.transport.server.encryptedPasswords ) {
- // encrypted
- System.arraycopy( password, 0, dst, dstIndex, passwordLength );
- dstIndex += passwordLength;
- } else {
- // plain text
- throw new RuntimeException( "plain text passwords not implemented" );
- }
+ ( session.auth.hashesExternal ||
+ session.auth.password.length() > 0 )) {
+ System.arraycopy( password, 0, dst, dstIndex, passwordLength );
+ dstIndex += passwordLength;
} else {
// no password in tree connect
dst[dstIndex++] = (byte)0x00;
}
dstIndex += writeString( path, dst, dstIndex );
- System.arraycopy( service.getBytes(), 0, dst, dstIndex, service.length() );
+ try {
+ System.arraycopy( service.getBytes( "ASCII" ), 0, dst, dstIndex, service.length() );
+ } catch( UnsupportedEncodingException uee ) {
+ return 0;
+ }
dstIndex += service.length();
dst[dstIndex++] = (byte)'\0';
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
import java.io.IOException;
import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
class SmbComTreeConnectAndXResponse extends AndXServerMessageBlock {
int start = bufferIndex;
int len = readStringLength( buffer, bufferIndex, 32 );
- service = new String( buffer, bufferIndex, len );
+ try {
+ service = new String( buffer, bufferIndex, len, "ASCII" );
+ } catch( UnsupportedEncodingException uee ) {
+ return 0;
+ }
bufferIndex += len + 1;
// win98 observed not returning nativeFileSystem
if( byteCount > bufferIndex - start ) {
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Config.getInt( "jcifs.smb.client.WriteAndX.Close", 1 );
int fid,
- offset,
writeMode,
remaining,
dataLength,
dataOffset,
- off,
- pad;
+ off;
byte[] b;
+ long offset;
- SmbComWriteAndX( int fid, int offset, int remaining,
+ SmbComWriteAndX() {
+ super( null );
+ command = SMB_COM_WRITE_ANDX;
+ }
+ SmbComWriteAndX( int fid, long offset, int remaining,
byte[] b, int off, int len, ServerMessageBlock andx ) {
super( andx );
this.fid = fid;
command = SMB_COM_WRITE_ANDX;
}
+ void setParam( int fid, long offset, int remaining,
+ byte[] b, int off, int len ) {
+ this.fid = fid;
+ this.offset = offset;
+ this.remaining = remaining;
+ this.b = b;
+ this.off = off;
+ dataLength = len;
+ }
int getBatchLimit( byte command ) {
if( command == SMB_COM_READ_ANDX ) {
return READ_ANDX_BATCH_LIMIT;
int writeParameterWordsWireFormat( byte[] dst, int dstIndex ) {
int start = dstIndex;
- dataOffset = dstIndex + 22; // 22 = off from here to pad
- pad = ( dataOffset - headerStart ) % 4;
- pad = pad == 0 ? 0 : 4 - pad;
- dataOffset += pad;
+ dataOffset = dstIndex + 26; // 26 = off from here to pad
+/*
+ * pad = ( dataOffset - headerStart ) % 4;
+ * pad = pad == 0 ? 0 : 4 - pad;
+ * dataOffset += pad;
+ */
writeInt2( fid, dst, dstIndex );
dstIndex += 2;
- writeInt4( offset, dst, dstIndex );
+ writeInt4( offset & 0xFFFFFFFFL, dst, dstIndex );
dstIndex += 4;
for( int i = 0; i < 4; i++ ) {
dst[dstIndex++] = (byte)0x00;
dstIndex += 2;
writeInt2( dataOffset, dst, dstIndex );
dstIndex += 2;
- // offsetHigh another day
+ writeInt4(( offset >> 32 ) & 0xFFFFFFFFL, dst, dstIndex );
+ dstIndex += 4;
return dstIndex - start;
}
int writeBytesWireFormat( byte[] dst, int dstIndex ) {
int start = dstIndex;
- while( pad-- > 0 ) {
- dst[dstIndex++] = (byte)0x00;
- }
+/* Netware doesn't like this
+ * while( pad-- > 0 ) {
+ * dst[dstIndex++] = (byte)0x00;
+ * }
+ */
System.arraycopy( b, off, dst, dstIndex, dataLength );
dstIndex += dataLength;
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
import jcifs.UniAddress;
/**
- * Don't get to attached to these constants, we'll be switching to NT
- * status codes sooner or later.
+ * There are hundreds of error codes that may be returned by a CIFS server. Rather than represent each with it's own <code>Exception</code> class, this class represents all of them. For many of the popular error codes, constants and text messages like "The device is not ready" are provided.
+<p>
+ * See <a href="../../../authhandler.html">jCIFS Exceptions and NtlmAuthenticator</a> for more information about <code>SmbException</code>.
*/
public class SmbException extends IOException {
* The network name cannot be found
*/
public static final int ERRbadnetname = 67;
+ public static final int ERRnomoreconn = 71;
public static final int ERRbadparm = 87;
/**
- * Cannot create a file when that file alread exists
+ * Cannot create a file when that file already exists
*/
public static final int ERRfilexists = 80;
/**
*/
public static final int ERRinvname = 123;
/**
+ * The directory is not empty
+ */
+ public static final int ERRnotempty = 145;
+/**
* File exists
*/
public static final int ERRexists = 183;
* The pipe is being closed
*/
public static final int ERRnodata = 232;
+/**
+ * No process is on the other end of the pipe
+ */
+ public static final int ERRnoproc = 233;
// srv error codes
/**
*/
public static final int ERRpasswordExpired = 2242;
+/**
+ * The list of servers for this workgroup is not currently available
+ */
+ public static final int ERRnolisting = 6118;
+
// hrd error codes
/**
* Attempt to write on write-protected media
public static final int ERRserverTimeout = 5000;
public static final int ERRbadDialect = 5001;
public static final int ERRioe = 5002;
+ public static final int ERRlistFiles = 5003;
+ public static final int ERRunknownHost = 5004;
+ public static final int ERRinappro = 5005;
+ public static final int ERRunknownType = 5006;
+ public static final int ERRimpossible = 5007;
int errorClass;
int errorCode;
case ERRinvname:
result += "Invalid name";
break;
+ case ERRnotempty:
+ result += "The directory is not empty";
+ break;
case ERRfilexists:
- result += "File exists";
+ result += "Cannot create a file when that file already exists";
break;
case ERRbadfid:
result += "Invalid file handle";
result += "The network name cannot be found";
break;
case ERRexists:
- result += "Cannot create a file when that file alread exists";
+ result += "File exists";
break;
case ERRpipebusy:
result += "All pipe instances are busy";
case ERRnodata:
result += "The pipe is being closed";
break;
+ case ERRnoproc:
+ result += "No process is on the other end of the pipe";
+ break;
case ERRbrokenpipe:
result += "The pipe has been ended";
break;
+ case ERRnomoreconn:
+ result += "No more connections can be made to this remote computer at this time because there are already as many connections as the computer can accept";
+ break;
default:
- result += "No description available. Please update error string for errorCode=" + errorCode;
+ result += "No description available [ERRDOS/" + errorCode + "]";
}
break;
case ERRSRV:
result += "The password of the user has expired";
break;
default:
- result += "No description available [errorCode=" + errorCode + "]";
+ result += "No description available [ERRSRV/" + errorCode + "]";
}
break;
case ERRHRD:
result += "The device is not ready";
break;
default:
- result += "No description available [errorCode=" + errorCode + "]";
+ result += "No description available [ERRHRD/" + errorCode + "]";
}
break;
case ERRCMD:
case NERR_BasicTransactConfig:
result += "The server is not configured for transactions";
break;
+ case ERRnolisting:
+ result += "The list of servers for this workgroup is not currently available";
+ break;
default:
- result += "No description available [errorCode=" + errorCode + "]";
+ result += "No description available [ERRRAP/" + errorCode + "]";
}
break;
case ERRCLI:
case ERRioe:
result += "An IO error occured.";
break;
+ case ERRlistFiles:
+ result += "The derived URL was malformed or a name service error occured during a listFiles() operation (this should not be possible, please report it to jcifs at samba dot org)";
+ break;
+ case ERRunknownHost:
+ result += "The hostname retrived from the Browser service is no longer valid";
+ break;
+ case ERRinappro:
+ result += "Inappropriate operation";
+ break;
+ case ERRunknownType:
+ result += "Unknown resource type";
+ break;
default:
- result += "No description available [errorCode=" + errorCode + "]";
+ result += "No description available [ERRCLI/" + errorCode + "]";
}
break;
default:
errorCode = ( code >> 16 ) & 0xFFFF;
}
+ /**
+ * Retrieve the error class associated with this error.
+ */
public int getErrorClass() {
return errorClass;
}
+
+ /**
+ * Retrieve the error code associated with this error.
+ */
public int getErrorCode() {
return errorCode;
}
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
package jcifs.smb;
-import jcifs.UniAddress;
-import jcifs.util.Config;
-import jcifs.netbios.NbtAddress;
-import jcifs.util.AuthHandler;
-import jcifs.util.AuthInfo;
+import java.net.URLConnection;
+import java.net.URL;
import java.net.MalformedURLException;
import java.net.UnknownHostException;
-import java.net.URL;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import jcifs.util.Config;
+import jcifs.UniAddress;
+import jcifs.netbios.NbtAddress;
+
+import java.util.Date;
/**
+ * <p>
* This class represents a resource on an SMB network. Mainly these
* resources are files and directories however an <code>SmbFile</code>
* may also refer to servers and workgroups. If the resource is a file or
* directory. SmbFile URLs have the following syntax:
*
* <blockquote><pre>
- * smb://[[[domain;]username[:password]@]server[:port][/share[/path]]]
+ * smb://[[[domain;]username[:password]@]server[:port]/[[share/[dir/]file]]]
* </pre></blockquote>
*
* This example:
* would referece the file <code>foo.txt</code> in the share
* <code>public</code> on the server <code>storage15</code>. In addition
* to referencing files and directories, jCIFS can also address servers,
- * and workgroups. When used in conjunction with the <code>list</code>
+ * and workgroups.
+<p>
+ * <font color="#800000"><i>Please note that beginning with jcifs-0.7.0b4 all SMB URLs that represent workgroups, servers, shares, or directories require a trailing slash '/'. This will break older code and you may or may not get an exception. For example:</i>
+<blockquote><pre>
+smb://server/share/path/to/dir/ <-- GOOD
+
+smb://server/share/path/to/dir <-- BAD
+</pre></blockquote>
+To assist you with this, the <tt>getName</tt> method will now include a slash '/' after the name if the URL refers to a directory (e.g. 'dir/').
+</font>
+<p>
+When using the <tt>java.net.URL</tt> class with 'smb://' URLs it is necessary to first call the static <tt>jcifs.Config.registerSmbURLHandler();</tt> method (prior to jcifs-0.7.0b12 it was <tt>Class.forName( "jcifs.Config" );</tt> but this is no longer necessary).
+<p>
+The userinfo component of the SMB URL (<tt>domain;user:pass</tt>) must be URL encoded if it contains reserved characters. According to RFC 2396 these characters are non US-ASCII characters and most meta characters however jCIFS will work correctly with anything but '@' which is used to delimit the userinfo component from the server and '%' which is the URL escape character itself.
+<p>
+When used in conjunction with the <code>list</code>
* method, this functionality can be usefull for network diagnostics
* tools or "Network Neighborhood" like functionality. The server
* component may a traditional NetBIOS name, a DNS name, or IP
* JCIFS Properties</a>). Here are some examples of SMB URLs with brief
* descriptions of what they do:
*
- * <p><b>*</b> This URL scheme conforms to the <a target="_top"
- * href="http://www.ietf.org/internet-drafts/draft-crhertel-smb-url-00.txt">SMB
+ * <p><b>*</b> This URL scheme is based largely on the <a target="_top"
+ * href="http://www.ietf.org/internet-drafts/draft-crhertel-smb-url-02.txt">SMB
* Filesharing URL Scheme</a> IETF draft.
*
* <p><table border="1" cellpadding="3" cellspacing="0" width="100%">
* <td colspan="2"><b>SMB URL Examples</b></td>
* <tr><td width="20%"><b>URL</b></td><td><b>Description</b></td></tr>
*
- * <tr><td width="20%"><code>smb://users-nyc;miallen:mypass@angus/tmp</code></td><td>
+ * <tr><td width="20%"><code>smb://users-nyc;miallen:mypass@angus/tmp/</code></td><td>
* This URL references a share called <code>tmp</code> on the server
* <code>angus</code> as user <code>miallen</code> who's password is
* <code>mypass</code>.
* </td></tr>
*
* <tr><td width="20%">
- * <code>smb://Administrator:P@ss@msmith1/c/WINDOWS/Desktop/foo.txt</code></td><td>
+ * <code>smb://Administrator:P%40ss@msmith1/c/WINDOWS/Desktop/foo.txt</code></td><td>
* A relativly sophisticated example that references a file
- * <code>msmith1</code>'s desktop as user <code>Administrator</code>.
+ * <code>msmith1</code>'s desktop as user <code>Administrator</code>. Notice the '@' is URL encoded with the '%40' hexcode escape.
* </td></tr>
*
- * <tr><td width="20%"><code>smb://angus</code></td><td>
+ * <tr><td width="20%"><code>smb://angus/</code></td><td>
* This references only a server. The behavior of some methods is different
* in this context(e.g. you cannot <code>delete</code> a server) however
* as you might expect the <code>list</code> method will list the available
* shares on this server.
* </td></tr>
*
- * <tr><td width="20%"><code>smb://myworkgroup</code></td><td>
+ * <tr><td width="20%"><code>smb://myworkgroup/</code></td><td>
* This syntactically is identical to the above example. However if
* <code>myworkgroup</code> happends to be a workgroup(which is indeed
* suggested by the name) the <code>list</code> method will return
* </td></tr>
*
* <tr><td width="20%"><code>smb://</code></td><td>
- * Just as <code>smb://server</code> lists shares and
- * <code>smb://workgroup</code> lists servers, the <code>smb://</code>
+ * Just as <code>smb://server/</code> lists shares and
+ * <code>smb://workgroup/</code> lists servers, the <code>smb://</code>
* URL lists all available workgroups on a netbios LAN. Again,
* in this context many methods are not valid and return default
* values(e.g. <code>isHidden</code> and <code>renameTo</code> will always
* for details.
* </td></tr>
*
- * <tr><td width="20%"><code>smb://192.168.1.15/ADMIN$</code></td><td>
+ * <tr><td width="20%"><code>smb://192.168.1.15/ADMIN$/</code></td><td>
* The server name may also be an IP address. See <a
* href="../../../resolver.html">Setting Name Resolution Properties</a>
* for details.
* A prototypical example that uses all the fields.
* </td></tr>
*
- * <tr><td width="20%"><code>smb://myworkgroup/angus <-- ILLEGAL </code></td><td>
+ * <tr><td width="20%"><code>smb://myworkgroup/angus/ <-- ILLEGAL </code></td><td>
* Despite the hierarchial relationship between workgroups, servers, and
* filesystems this example is not valid.
* </td></tr>
- *
+ *
+ * <tr><td width="20%">
+ * <code>smb://server/share/path/to/dir <-- ILLEGAL </code></td><td>
+ * URLs that represent workgroups, servers, shares, or directories require a trailing slash '/'.
+ * </td></tr>
+ *
* </table>
*
* <p>A second constructor argument may be specified to augment the URL
* <b>First Parameter</b></td><td><b>Second Parameter</b></td><td><b>Result</b></td></tr>
*
* <tr><td width="20%"><code>
- * smb://host/share/a/b
+ * smb://host/share/a/b/
* </code></td><td width="20%"><code>
- * c/d
+ * c/d/
* </code></td><td><code>
- * smb://host/share/a/b/c/d
+ * smb://host/share/a/b/c/d/
* </code></td></tr>
*
* <tr><td width="20%"><code>
- * smb://host/share/foo/bar
+ * smb://host/share/foo/bar/
* </code></td><td width="20%"><code>
* /share2/zig/zag
* </code></td><td><code>
* </code></td></tr>
*
* <tr><td width="20%"><code>
- * smb://host/share/foo/bar
+ * smb://host/share/foo/bar/
* </code></td><td width="20%"><code>
- * ../zip
+ * ../zip/
* </code></td><td><code>
- * smb://host/share/foo/zip
+ * smb://host/share/foo/zip/
* </code></td></tr>
*
* <tr><td width="20%"><code>
* smb://host/share/zig/zag
* </code></td><td width="20%"><code>
- * smb://foo/bar
+ * smb://foo/bar/
* </code></td><td><code>
- * smb://foo/bar
+ * smb://foo/bar/
* </code></td></tr>
*
* <tr><td width="20%"><code>
- * smb://host/share/foo
+ * smb://host/share/foo/
* </code></td><td width="20%"><code>
- * ../.././.././../foo
+ * ../.././.././../foo/
* </code></td><td><code>
- * smb://foo
- * </code></td></tr>
- *
- * <tr><td width="20%"><code>
- * smb://host/share/zig/zag
- * </code></td><td width="20%"><code>
- * null
- * </code></td><td><code>
- * smb://host/share/zig/zag
+ * smb://host/foo/
* </code></td></tr>
*
* <tr><td width="20%"><code>
* </code></td><td width="20%"><code>
* /
* </code></td><td><code>
- * smb://host
+ * smb://host/
* </code></td></tr>
*
* <tr><td width="20%"><code>
- * smb://server
+ * smb://server/
* </code></td><td width="20%"><code>
- * ..
+ * ../
* </code></td><td><code>
- * smb://
+ * smb://server/
* </code></td></tr>
*
* <tr><td width="20%"><code>
* smb://
* </code></td><td width="20%"><code>
- * myworkgroup
+ * myworkgroup/
* </code></td><td><code>
- * smb://myworkgroup
+ * smb://myworkgroup/
* </code></td></tr>
*
* <tr><td width="20%"><code>
- * smb://myworkgroup
+ * smb://myworkgroup/
* </code></td><td width="20%"><code>
- * angus
+ * angus/
* </code></td><td><code>
- * smb://angus
+ * smb://myworkgroup/angus/ <-- ILLEGAL<br>(But if you first create an <tt>SmbFile</tt> with 'smb://workgroup/' and use and use it as the first parameter to a constructor that accepts it with a second <tt>String</tt> parameter jCIFS will factor out the 'workgroup'.)
* </code></td></tr>
*
* </table>
*
- * <p>Notice there are two exceptional examples where the workgroup
- * resource <code>smb://myworkgroup</code> and server <code>angus</code>
- * are combined to produce just <code>smb://angus</code> and not
- * <code>smb://myworkgroup/angus</code>. Similarly, when combining
- * <code>smb://angus</code> with <code>..</code>,
- * angus' workgroup resource <code>smb://myworkgroup</code> is <i>not</i>
- * returned. This is by design and in accordance with the <a target="_top"
- * href="http://www.ietf.org/internet-drafts/draft-crhertel-smb-url-00.txt">SMB
- * Filesharing URL Scheme</a> IETF draft.
- *
* <p>Instances of the <code>SmbFile</code> class are immutable; that is,
* once created, the abstract pathname represented by an SmbFile object
* will never change.
*
* @see java.io.File
- * @since jcifs-0.4
*/
-public class SmbFile {
+public class SmbFile extends URLConnection {
// these are shifted for use in flags
static final int O_RDONLY = 0x010000;
static final int O_RDWR = 0x030000;
static final int O_APPEND = 0x040000;
+ // share access
+ public static final int FILE_NO_SHARE = 0x00;
+ public static final int FILE_SHARE_READ = 0x01;
+ public static final int FILE_SHARE_WRITE = 0x02;
+ public static final int FILE_SHARE_DELETE = 0x04;
+
// Open Function Encoding
// create if the file does not exist
static final int O_CREAT = 0x0010;
static final int ATTR_DIRECTORY = 0x10;
static final int ATTR_ARCHIVE = 0x20;
- static final long ATTR_EXPIRATION_PERIOD = Config.getLong( "jcifs.smb.client.attrExpirationPeriod", 100 );
+ static final int DEFAULT_ATTR_EXPIRATION_PERIOD = 5000;
+
+ static long attrExpirationPeriod;
static {
- // is this needed ??
try {
Class.forName( "jcifs.Config" );
} catch( ClassNotFoundException cnfe ) {
cnfe.printStackTrace();
}
+ attrExpirationPeriod = Config.getLong( "jcifs.smb.client.attrExpirationPeriod", DEFAULT_ATTR_EXPIRATION_PERIOD );
}
- static AuthHandler authHandler = null;
-
- public static void setAuthHandler( AuthHandler authHandler ) {
- SmbFile.authHandler = authHandler;
- }
-
- AuthInfo authInfo = new AuthInfo();
- String url, server, share, canonicalPath, uncPath, name;
- int port;
- boolean isWorkgroup, isExists;
+ /**
+ * Returned by {@link #getType()} if the resource this <tt>SmbFile</tt>
+ * represents is a regular file or directory.
+ */
+ public static final int TYPE_FILESYSTEM = 0x01;
+ /**
+ * Returned by {@link #getType()} if the resource this <tt>SmbFile</tt>
+ * represents is a workgroup.
+ */
+ public static final int TYPE_WORKGROUP = 0x02;
+ /**
+ * Returned by {@link #getType()} if the resource this <tt>SmbFile</tt>
+ * represents is a server.
+ */
+ public static final int TYPE_SERVER = 0x04;
+ /**
+ * Returned by {@link #getType()} if the resource this <tt>SmbFile</tt>
+ * represents is a share.
+ */
+ public static final int TYPE_SHARE = 0x08;
+ /**
+ * Returned by {@link #getType()} if the resource this <tt>SmbFile</tt>
+ * represents is a named pipe.
+ */
+ public static final int TYPE_NAMED_PIPE = 0x10;
+ /**
+ * Returned by {@link #getType()} if the resource this <tt>SmbFile</tt>
+ * represents is a printer.
+ */
+ public static final int TYPE_PRINTER = 0x20;
+ /**
+ * Returned by {@link #getType()} if the resource this <tt>SmbFile</tt>
+ * represents is a communications device.
+ */
+ public static final int TYPE_COMM = 0x40;
+
+
+ SmbTree tree = null; // Initially null; may be !tree.treeConnected
+ String canon; // Initially null; set by getUncPath; dir must end with '/'
+ String unc; // Initially null; set by getUncPath; never ends with '/'
+ String share; // Can be null
+ int fid; // Initially 0; set by open()
+ int type;
+ long lastModified;
+ int attributes;
+ long attrExpiration;
+ long size;
+ long sizeExpiration;
+ NtlmPasswordAuthentication auth; // Cannot be null
+ boolean opened;
+ boolean isExists;
+ int shareAccess = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
+ SmbComBlankResponse blank_resp = new SmbComBlankResponse();
- SmbTree tree;
- int fid, hash;
- int attributes = ATTR_READONLY | ATTR_DIRECTORY;
- long lastModified, size;
- boolean opened, isPipe;
- UniAddress address;
- long attrExpiration = 0;
/**
* Constructs an SmbFile representing a resource on an SMB network such as
* @throws MalformedURLException
* If the <code>parent</code> and <code>child</code> parameters
* do not follow the prescribed syntax
- * @throws UnknownHostException
- * If the name of a server specified cannot be resolved using
- * the configured name resolution methods
*/
- public SmbFile( String url )
- throws MalformedURLException, UnknownHostException {
- this( url, null, 4, url.length() );
+ public SmbFile( String url ) throws MalformedURLException {
+ this( new URL( null, url, Handler.SMB_HANDLER ));
}
/**
* If the <code>parent</code> and <code>child</code> parameters
* do not follow the prescribed syntax
* @throws UnknownHostException
- * If the name of a server specified cannot be resolved using
- * the configured name resolution methods
+ * If the server or workgroup of the <tt>context</tt> file cannot be determined
*/
- public SmbFile( SmbFile parent, String child )
- throws MalformedURLException, UnknownHostException {
- this( parent.getCanonicalPath(), child );
+ public SmbFile( SmbFile context, String name ) throws MalformedURLException, UnknownHostException {
+ this( context.isWorkgroup0() ?
+ new URL( null, "smb://" + name, Handler.SMB_HANDLER ) :
+ new URL( context.url, name, Handler.SMB_HANDLER ), context.auth );
}
/**
* @throws MalformedURLException
* If the <code>parent</code> and <code>child</code> parameters
* do not follow the prescribed syntax
- * @throws UnknownHostException
- * If the name of a server specified cannot be resolved using
- * the configured name resolution methods
*/
- public SmbFile( String parent, String child )
- throws MalformedURLException, UnknownHostException {
- this( parent, child, 4, parent.length() );
+ public SmbFile( String context, String name ) throws MalformedURLException {
+ this( new URL( new URL( null, context, Handler.SMB_HANDLER ), name, Handler.SMB_HANDLER ));
}
- SmbFile( String parent, String child, int start, int limit )
- throws MalformedURLException, UnknownHostException {
-
- SmbURL.parseSmbURL( this, parent, child, start, limit );
- if( server == null ) {
- address = UniAddress.getByName( NbtAddress.getByName(
- NbtAddress.MASTER_BROWSER_NAME,
- 0x01, null).getHostAddress() );
- } else if( isWorkgroup ) {
- address = UniAddress.getByName( address.getHostAddress() );
- } else {
- address = UniAddress.getByName( server );
+ public SmbFile( String url, NtlmPasswordAuthentication auth )
+ throws MalformedURLException {
+ this( new URL( null, url, Handler.SMB_HANDLER ), auth );
+ }
+ public SmbFile( String context, String name, NtlmPasswordAuthentication auth )
+ throws MalformedURLException {
+ this( new URL( new URL( null, context, Handler.SMB_HANDLER ), name, Handler.SMB_HANDLER ), auth );
+ }
+ public SmbFile( String context, String name, NtlmPasswordAuthentication auth, int shareAccess )
+ throws MalformedURLException {
+ this( new URL( new URL( null, context, Handler.SMB_HANDLER ), name, Handler.SMB_HANDLER ), auth );
+ if ((shareAccess & ~(FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE)) != 0) {
+ throw new RuntimeException( "Illegal shareAccess parameter" );
}
+ this.shareAccess = shareAccess;
+ }
+ public SmbFile( URL url ) {
+ this( url, new NtlmPasswordAuthentication( url.getUserInfo() ));
+ }
+ public SmbFile( URL url, NtlmPasswordAuthentication auth ) {
+ super( url );
+ this.auth = auth == null ? new NtlmPasswordAuthentication( url.getUserInfo() ) : auth;
- if( canonicalPath == null ) {
- uncPath = "\\";
+ getUncPath0();
+ }
+ SmbFile( SmbFile context, String name, int type,
+ int attributes, long lastModified, long size )
+ throws MalformedURLException, UnknownHostException {
+ this( context, name + (( attributes & ATTR_DIRECTORY ) > 0 ? "/" : "" ));
+ if( context.share != null ) {
+ this.tree = context.tree;
+ }
+ int last = name.length() - 1;
+ if( name.charAt( last ) == '/' ) {
+ name = name.substring( 0, last );
+ }
+ if( context.share == null ) {
+ this.unc = "\\";
+ } else if( context.unc.equals( "\\" )) {
+ this.unc = '\\' + name;
} else {
- uncPath = canonicalPath.replace( '/', '\\' );
+ this.unc = context.unc + '\\' + name;
}
+ this.type = type;
+ this.attributes = attributes;
+ this.lastModified = lastModified;
+ this.size = size;
+ isExists = true;
+
+ attrExpiration = sizeExpiration =
+ System.currentTimeMillis() + attrExpirationPeriod;
}
void sendTransaction( SmbComTransaction request,
SmbComTransactionResponse response ) throws SmbException {
- while( true ) {
- if( tree == null ) {
- SmbTransport trans = SmbTransport.getSmbTransport( address, port );
- SmbSession ssn = isWorkgroup ? trans.getSmbSession( "", "", "" ) :
- trans.getSmbSession( authInfo.username,
- authInfo.password, authInfo.domain );
- tree = share == null ? ssn.getSmbTree( "IPC$", null ) :
- ssn.getSmbTree( share, null );
- }
- try {
- tree.sendTransaction( request, response );
- break;
- } catch( SmbAuthException sae ) {
- if( authHandler == null ) {
- throw sae;
- }
- tree = null;
- authInfo.exception = sae;
- authInfo.target = url;
- if( authHandler.authenticate( authInfo ) == false ) {
- throw sae;
- }
- }
- }
+ connect0();
+ tree.sendTransaction( request, response );
}
void send( ServerMessageBlock request,
ServerMessageBlock response ) throws SmbException {
- while( true ) {
- if( tree == null ) {
- SmbTransport trans = SmbTransport.getSmbTransport( address, port );
- SmbSession ssn = isWorkgroup ? trans.getSmbSession( "", "", "" ) :
- trans.getSmbSession( authInfo.username,
- authInfo.password, authInfo.domain );
- tree = share == null ? ssn.getSmbTree( "IPC$", null ) :
- ssn.getSmbTree( share, null );
- }
- try {
- tree.send( request, response );
- break;
- } catch( SmbAuthException sae ) {
- if( authHandler == null ) {
- throw sae;
- }
- tree = null;
- authInfo.exception = sae;
- authInfo.target = url;
- if( authHandler.authenticate( authInfo ) == false ) {
- throw sae;
- }
- }
- }
+ connect0();
+ tree.send( request, response );
}
- boolean isOpen() {
- return opened && tree.treeConnected;
+ UniAddress getAddress() throws UnknownHostException {
+ String host = url.getHost();
+ String path = url.getPath();
+
+ if( host.length() == 0 ) {
+ return UniAddress.getByName( NbtAddress.getByName(
+ NbtAddress.MASTER_BROWSER_NAME, 0x01, null).getHostAddress() );
+ } else if( path.length() == 0 || path.equals( "/" )) {
+ return UniAddress.getByName( host, true );
+ } else {
+ return UniAddress.getByName( host );
+ }
}
- void open( int flags ) throws SmbException {
+ void connect0() throws SmbException {
+ try {
+ connect();
+ } catch( UnknownHostException uhe ) {
+ throw new SmbException( SmbException.ERRCLI,
+ SmbException.ERRunknownHost,
+ "Unknown host: " + uhe.getMessage() );
+ } catch( SmbException se ) {
+ throw se;
+ } catch( IOException ioe ) {
+ throw new SmbException( SmbException.ERRCLI,
+ SmbException.ERRioe,
+ ioe.getMessage() );
+ }
+ }
+ public void connect() throws IOException {
SmbTransport trans;
+ SmbSession ssn;
+ UniAddress addr;
+
+ if( isConnected() ) {
+ return;
+ }
+
+ getUncPath0();
+ addr = getAddress();
+
+ trans = SmbTransport.getSmbTransport( addr, url.getPort() );
+ ssn = trans.getSmbSession( auth );
+ tree = ssn.getSmbTree( share, null );
+ try {
+ tree.treeConnect( null, null );
+ } catch( SmbAuthException sae ) {
+ NtlmPasswordAuthentication a;
+
+ if( share == null ) { // IPC$ - try "anonymous" credentials
+ trans = SmbTransport.getSmbTransport( addr, url.getPort() );
+ ssn = trans.getSmbSession( NtlmPasswordAuthentication.NULL );
+ tree = ssn.getSmbTree( null, null );
+ tree.treeConnect( null, null );
+ } else if(( a = NtlmAuthenticator.requestNtlmPasswordAuthentication( url.toString(), sae )) != null ) {
+ auth = a;
+ trans = SmbTransport.getSmbTransport( addr, url.getPort() );
+ ssn = trans.getSmbSession( auth );
+ tree = ssn.getSmbTree( share, null );
+ tree.treeConnect( null, null );
+ } else {
+ throw sae;
+ }
+ }
+ }
+ boolean isConnected() {
+ return (connected = tree != null && tree.treeConnected);
+ }
+ void open( int flags ) throws SmbException {
if( isOpen() ) {
return;
}
+ connect0();
- Log.println( Log.WARNINGS, "smb open warning", " name=" + canonicalPath );
+ Log.println( Log.WARNINGS, "smb open warning: ", unc );
/*
* Open AndX Request / Response
*/
- /* To query server capabilities we must ensure the negotiation has talken place
- */
-
- trans = SmbTransport.getSmbTransport( address, port );
- trans.negotiate();
-
- if(( trans.negotiatedCapabilities &
- ServerMessageBlock.CAP_NT_SMBS ) ==
- ServerMessageBlock.CAP_NT_SMBS ) {
+ if( tree.session.transport.hasCapability( ServerMessageBlock.CAP_NT_SMBS )) {
SmbComNTCreateAndXResponse response = new SmbComNTCreateAndXResponse();
- send( new SmbComNTCreateAndX( uncPath, flags, null ), response );
+ send( new SmbComNTCreateAndX( unc, flags, null, shareAccess ), response );
fid = response.fid;
} else {
SmbComOpenAndXResponse response = new SmbComOpenAndXResponse();
- send( new SmbComOpenAndX( uncPath, flags, null ), response );
+ send( new SmbComOpenAndX( unc, flags, null ), response );
fid = response.fid;
}
opened = true;
}
+ boolean isOpen() {
+ return opened && isConnected();
+ }
void close() throws SmbException {
+ close( 0L );
+ }
+ void close( long lastWriteTime ) throws SmbException {
if( isOpen() == false ) {
return;
}
+
opened = false;
- Log.println( Log.WARNINGS, "smb close warning",
- " fid=" + fid );
+ Log.println( Log.WARNINGS, "smb close warning", " fid=" + fid );
/*
* Close Request / Response
*/
- send( new SmbComClose( fid ), new SmbComBlankResponse() );
+ send( new SmbComClose( fid, lastWriteTime ), blank_resp );
}
-
/**
* Returns the last component of the target URL. This will
* effectively be the name of the file or directory represented by this
* <code>SmbFile</code> or in the case of URLs that only specify a server
* or workgroup, the server or workgroup will be returned. The name of
- * the root URL <code>smb://</code> is also <code>smb://</code>.
+ * the root URL <code>smb://</code> is also <code>smb://</code>. If this
+ * <tt>SmbFile</tt> refers to a workgroup, server, share, or directory,
+ * the name will include a trailing slash '/' so that composing new
+ * <tt>SmbFile</tt>s will maintain the trailing slash requirement introduced
+ * in jcifs-0.7.0b4.
*
* @return The last component of the URL associated with this SMB
* resource or <code>smb://</code> if the resource is <code>smb://</code>
*/
public String getName() {
- int p = url.lastIndexOf( '/' ) + 1;
- return p == url.length() ? "smb://" : url.substring( p );
+ getUncPath0();
+ if( canon.length() > 1 ) {
+ int i = canon.length() - 2;
+ while( canon.charAt( i ) != '/' ) {
+ i--;
+ }
+ return canon.substring( i + 1 );
+ } else if( share != null ) {
+ return share + '/';
+ } else if( url.getHost().length() > 0 ) {
+ return url.getHost() + '/';
+ } else {
+ return "smb://";
+ }
}
/**
*/
public String getParent() {
- int p = url.lastIndexOf( '/' );
- return p > 5 ? url.substring( 0, p ) : "smb://";
+ StringBuffer sb = new StringBuffer( "smb://" );
+ String str = url.getAuthority();
+ if( str.length() > 0 ) {
+ sb.append( str );
+ sb.append( '/' );
+ }
+ getUncPath0();
+ if( canon.length() > 1 ) {
+ int i = canon.length() - 2;
+ while( canon.charAt( i ) != '/' ) {
+ i--;
+ }
+ if( i > 1 ) {
+ sb.append( canon.substring( 1, i ));
+ sb.append( '/' );
+ }
+ }
+ return sb.toString();
}
/**
*/
public String getPath() {
- return url;
+ return url.toString();
}
+ String getUncPath0() {
+ if( unc == null ) {
+ char[] in = url.getPath().toCharArray();
+ char[] out = new char[in.length];
+ int i, o, state, s;
+
+ state = 0;
+ o = 0;
+ for( i = 0; i < in.length; i++ ) {
+ switch( state ) {
+ case 0:
+ if( in[i] != '/' ) {
+ return null;
+ }
+ out[o++] = in[i];
+ state = 1;
+ break;
+ case 1:
+ if( in[i] == '/' ) {
+ break;
+ } else if( in[i] == '.' &&
+ (( i + 1 ) >= in.length || in[i + 1] == '/' )) {
+ i++;
+ break;
+ } else if(( i + 1 ) < in.length &&
+ in[i] == '.' &&
+ in[i + 1] == '.' &&
+ (( i + 2 ) >= in.length || in[i + 2] == '/' )) {
+ i += 2;
+ if( o == 1 ) break;
+ do {
+ o--;
+ } while( o > 1 && out[o - 1] != '/' );
+ break;
+ }
+ state = 2;
+ case 2:
+ if( in[i] == '/' ) {
+ state = 1;
+ }
+ out[o++] = in[i];
+ break;
+ }
+ }
+
+ canon = new String( out, 0, o );
+
+ if( o > 1 ) {
+ o--;
+ i = canon.indexOf( '/', 1 );
+ if( i < 0 ) {
+ share = canon.substring( 1 );
+ unc = "\\";
+ } else if( i == o ) {
+ share = canon.substring( 1, i );
+ unc = "\\";
+ } else {
+ share = canon.substring( 1, i );
+ unc = canon.substring( i, out[o] == '/' ? o : o + 1 );
+ unc = unc.replace( '/', '\\' );
+ }
+ } else {
+ share = null;
+ unc = "\\";
+ }
+ }
+ return unc;
+ }
+/**
+ * Retuns the Windows UNC style path with backslashs intead of forward slashes.
+ *
+ * @return The UNC path.
+ */
+
+ public String getUncPath() {
+ String path = getUncPath0();
+ if( share == null ) {
+ return "\\\\" + url.getHost();
+ }
+ return "\\\\" + url.getHost() + "\\" + share + path;
+ }
/**
* Returns the full URL of this SMB resource with '.' and '..' components
* factored out. An <code>SmbFile</code> constructed with the result of
*/
public String getCanonicalPath() {
- StringBuffer sb = new StringBuffer( "smb://" );
- if( server == null ) {
- return "smb://";
- } else if( authInfo.username != null ) {
- if( authInfo.domain != null ) {
- sb.append( authInfo.domain ).append( ';' );
- }
- sb.append( authInfo.username );
- if( authInfo.password != null ) {
- sb.append( ':' ).append( authInfo.password );
- }
- sb.append( '@' );
- }
- sb.append( server );
- if( port != 0 && port != 139 ) {
- sb.append( ":" ).append( port );
- }
- if( share != null ) {
- sb.append( '/' ).append( share );
- if( canonicalPath != null ) {
- sb.append( canonicalPath );
- }
+ String str = url.getAuthority();
+ getUncPath0();
+ if( str.length() > 0 ) {
+ return "smb://" + url.getAuthority() + canon;
}
- return sb.toString();
+ return "smb://";
}
/**
*/
public String getServer() {
- return server;
+ String str = url.getHost();
+ if( str.length() == 0 ) {
+ return null;
+ }
+ return str;
}
/**
- * Determines wheather or not this resource is an NT Domain/workgroup by querying
- * the NetBIOS name service. Only a URL of the form <code>smb://name</code>
- * has the capacity to be a workgroup.
- *
- * @return <code>true</code> if this <code>SmbFile</code> refers to a
- * workgroup and <code>false</code> otherwise.
+ * Returns type of of object this <tt>SmbFile</tt> represents.
+ * @return <tt>TYPE_FILESYSTEM, TYPE_WORKGROUP, TYPE_SERVER, TYPE_SHARE,
+ * TYPE_PRINTER, TYPE_NAMED_PIPE</tt>, or <tt>TYPE_COMM</tt>.
*/
-
- public boolean isWorkgroup() {
- return isWorkgroup;
+ public int getType() throws SmbException {
+ if( type == 0 ) {
+ if( getUncPath0().length() > 1 ) {
+ type = TYPE_FILESYSTEM;
+ } else if( share != null ) {
+ // treeConnect good enough to test service type
+ connect0();
+ if( share.equals( "IPC$" )) {
+ type = TYPE_NAMED_PIPE;
+ } else if( tree.service.equals( "LPT1:" )) {
+ type = TYPE_PRINTER;
+ } else if( tree.service.equals( "COMM" )) {
+ type = TYPE_COMM;
+ } else {
+ type = TYPE_SHARE;
+ }
+ } else if( url.getAuthority().length() == 0 ) {
+ type = TYPE_WORKGROUP;
+ } else {
+ UniAddress addr;
+ try {
+ addr = getAddress();
+ } catch( UnknownHostException uhe ) {
+ throw new SmbException( SmbException.ERRCLI |
+ SmbException.ERRunknownHost,
+ "Unknown host: " + uhe.getMessage() );
+ }
+ if( addr.getAddress() instanceof NbtAddress ) {
+ int code = ((NbtAddress)addr.getAddress()).getNameType();
+ if( code == 0x1d || code == 0x1b ) {
+ type = TYPE_WORKGROUP;
+ return type;
+ }
+ }
+ type = TYPE_SERVER;
+ }
+ }
+ return type;
+ }
+ boolean isWorkgroup0() throws UnknownHostException {
+ if( type == TYPE_WORKGROUP || url.getHost().length() == 0 ) {
+ type = TYPE_WORKGROUP;
+ return true;
+ } else {
+ getUncPath0();
+ if( share == null ) {
+ UniAddress addr = getAddress();
+ if( addr.getAddress() instanceof NbtAddress ) {
+ int code = ((NbtAddress)addr.getAddress()).getNameType();
+ if( code == 0x1d || code == 0x1b ) {
+ type = TYPE_WORKGROUP;
+ return true;
+ }
+ }
+ type = TYPE_SERVER;
+ }
+ }
+ return false;
}
- Info queryPath( int infoLevel ) throws SmbException {
+ Info queryPath( String path, int infoLevel ) throws SmbException {
SmbTransport trans;
- Info info;
+
+ connect0();
Log.println( Log.WARNINGS, "smb query path warning",
- " querying path=" + uncPath );
+ " querying path=" + path );
/* normally we'd check the negotiatedCapabilities for CAP_NT_SMBS
* however I can't seem to get a good last modified time from
* to(overrides negotiatedCapabilities).
*/
- /* make sure we're negotiated before we query capabilities
- */
- trans = SmbTransport.getSmbTransport( address, port );
- trans.negotiate();
- if(( trans.server.capabilities & ServerMessageBlock.CAP_NT_SMBS ) ==
- ServerMessageBlock.CAP_NT_SMBS ) {
+ if( tree.session.transport.hasCapability( ServerMessageBlock.CAP_NT_SMBS )) {
/*
* Trans2 Query Path Information Request / Response
*/
Trans2QueryPathInformationResponse response =
- new Trans2QueryPathInformationResponse( infoLevel );
- sendTransaction( new Trans2QueryPathInformation( uncPath,
- infoLevel ), response );
- info = response.info;
+ new Trans2QueryPathInformationResponse( infoLevel );
+ sendTransaction( new Trans2QueryPathInformation( path,
+ infoLevel ), response );
+
+ return response.info;
} else {
/*
*/
SmbComQueryInformationResponse response =
- new SmbComQueryInformationResponse(
- trans.server.serverTimeZone * 1000 * 60L );
- send( new SmbComQueryInformation( uncPath ), response );
- info = (Info)response;
+ new SmbComQueryInformationResponse(
+ tree.session.transport.server.serverTimeZone * 1000 * 60L );
+ send( new SmbComQueryInformation( path ), response );
+ return response;
}
-
- return info;
}
/**
* <code>false</code> otherwise
*/
- void updateAttributes() throws SmbException {
- Info info;
+ public boolean exists() throws SmbException {
if( attrExpiration > System.currentTimeMillis() ) {
- return;
+ return isExists;
}
attributes = ATTR_READONLY | ATTR_DIRECTORY;
lastModified = 0L;
- info = queryPath( Trans2QueryPathInformationResponse.SMB_QUERY_FILE_BASIC_INFO );
- attributes = info.getAttributes();
- lastModified = info.getLastWriteTime();
-
- attrExpiration = System.currentTimeMillis() + ATTR_EXPIRATION_PERIOD;
- }
- public boolean exists() throws SmbException {
- if( attrExpiration > System.currentTimeMillis() ) {
- return isExists;
- }
-
isExists = false;
try {
- if( server == null ) {
- isExists = true;
+ if( url.getHost().length() == 0 ) {
} else if( share == null ) {
- if( isWorkgroup ) {
- NbtAddress.getByName( server, 0x1d, null );
+ if( true || type == TYPE_WORKGROUP ) {
+ UniAddress.getByName( url.getHost(), true );
} else {
- UniAddress.getByName( server ).getHostName();
+ UniAddress.getByName( url.getHost() ).getHostName();
}
- } else if( canonicalPath == null ||
+ } else if( getUncPath0().length() == 1 ||
share.equalsIgnoreCase( "IPC$" )) {
- send( null, null ); // treeConnect is good enough
+ connect0(); // treeConnect is good enough
} else {
- updateAttributes();
+ Info info = queryPath( getUncPath0(),
+ Trans2QueryPathInformationResponse.SMB_QUERY_FILE_BASIC_INFO );
+ attributes = info.getAttributes();
+ lastModified = info.getLastWriteTime();
}
/* If any of the above fail, isExists will not be set true
isExists = true;
} catch( UnknownHostException uhe ) {
- isExists = false;
} catch( SmbException se ) {
if( se.errorClass == SmbException.ERRDOS &&
( se.errorCode == SmbException.ERRbadfile ||
- se.errorCode == SmbException.ERRbadnetname )) {
- isExists = false;
+ se.errorCode == SmbException.ERRbadnetname ||
+ se.errorCode == SmbException.ERRbadpath )) {
} else {
throw se;
}
}
+ attrExpiration = System.currentTimeMillis() + attrExpirationPeriod;
+
return isExists;
}
*/
public boolean canRead() throws SmbException {
- if( isPipe ) { // try opening the pipe for writing?
+ if( getType() == TYPE_NAMED_PIPE ) { // try opening the pipe for reading?
return true;
}
return exists(); // try opening and catch sharing violation?
*/
public boolean canWrite() throws SmbException {
- if( isPipe ) { // try opening the pipe for writing?
+ if( getType() == TYPE_NAMED_PIPE ) { // try opening the pipe for writing?
return true;
}
return exists() && ( attributes & ATTR_READONLY ) == 0;
*/
public boolean isDirectory() throws SmbException {
- if( canonicalPath == null ) {
+ if( getUncPath0().length() == 1 ) {
return true;
}
- updateAttributes();
+ exists();
return ( attributes & ATTR_DIRECTORY ) == ATTR_DIRECTORY;
}
*/
public boolean isFile() throws SmbException {
- if( canonicalPath == null ) {
+ if( getUncPath0().length() == 1 ) {
return false;
}
- updateAttributes();
+ exists();
return ( attributes & ATTR_DIRECTORY ) == 0;
}
public boolean isHidden() throws SmbException {
if( share == null ) {
return false;
- } else if( canonicalPath == null ) {
+ } else if( getUncPath0().length() == 1 ) {
if( share.endsWith( "$" )) {
return true;
}
return false;
}
- updateAttributes();
+ exists();
return ( attributes & ATTR_HIDDEN ) == ATTR_HIDDEN;
}
*/
public long lastModified() throws SmbException {
- if( canonicalPath != null ) {
- updateAttributes();
+ if( getUncPath0().length() > 1 ) {
+ exists();
return lastModified;
}
return 0L;
}
/**
- * List the contents of this SMB resource. The list returned by this method will be;
+ * List the contents of this SMB resource. The list returned by this
+ * method will be;
*
* <ul>
- * <li> files and directories contained within this resource if the resource is a normal disk file directory,
- * <li> all available NetBIOS workgroups or domains if this resource is the top level URL <code>smb://</code>,
- * <li> all servers registered as members of a NetBIOS workgroup if this resource refers to a workgroup in a <code>smb://workgroup</code> URL,
- * <li> all browseable shares of a server including printers, IPC services, or disk volumes if this resource is a server URL in the form <code>smb://server</code>,
+ * <li> files and directories contained within this resource if the
+ * resource is a normal disk file directory,
+ * <li> all available NetBIOS workgroups or domains if this resource is
+ * the top level URL <code>smb://</code>,
+ * <li> all servers registered as members of a NetBIOS workgroup if this
+ * resource refers to a workgroup in a <code>smb://workgroup</code> URL,
+ * <li> all browseable shares of a server including printers, IPC
+ * services, or disk volumes if this resource is a server URL in the form
+ * <code>smb://server</code>,
* <li> or <code>null</code> if the resource cannot be resolved.
* </ul>
*
- * @return A <code>String</code> array of file and directories, workgroups, servers, or shares depending on the context of the resource URL
+ * @return A <code>String[]</code> array of files and directories,
+ * workgroups, servers, or shares depending on the context of the
+ * resource URL
*/
public String[] list() throws SmbException {
- if( server == null ) {
- // if share is null send/sendTransaction will tcon to IPC$
- SmbTransport trans = SmbTransport.getSmbTransport( address, port );
- trans.negotiate();
+ connect0();
+
+ if( url.getHost().length() == 0 ) {
NetServerEnum2Response response = new NetServerEnum2Response();
- sendTransaction( new NetServerEnum2( trans.server.oemDomainName,
- NetServerEnum2.SV_TYPE_DOMAIN_ENUM ), response );
+ sendTransaction( new NetServerEnum2(
+ tree.session.transport.server.oemDomainName,
+ NetServerEnum2.SV_TYPE_DOMAIN_ENUM ), response );
if( response.status != SmbException.NERR_Success &&
- response.status != SmbException.ERROR_MORE_DATA ) {
+ response.status != SmbException.ERROR_MORE_DATA ) {
throw new SmbException( SmbException.ERRRAP,
- response.status, response.toString() );
+ response.status, response.toString() );
}
String[] ret = new String[response.entriesReturned];
}
return ret;
} else if( share == null ) {
- if( isWorkgroup ) {
+ if( getType() == TYPE_WORKGROUP ) {
NetServerEnum2Response response = new NetServerEnum2Response();
- sendTransaction( new NetServerEnum2( server,
+ sendTransaction( new NetServerEnum2( url.getHost(),
NetServerEnum2.SV_TYPE_ALL ), response );
if( response.status != SmbException.NERR_Success &&
return ret;
}
} else {
- return list( uncPath );
+ return list( unc );
}
}
String[] list( String dirPath ) throws SmbException {
String filename;
Log.println( Log.WARNINGS, "smb find warning",
- " find with path=" + canonicalPath );
+ " find with path=" + dirPath );
Trans2FindFirst2Response response = new Trans2FindFirst2Response();
sendTransaction( new Trans2FindFirst2( dirPath + "\\*" ), response );
}
}
- send( new SmbComFindClose2( sid ), new SmbComBlankResponse() );
+ send( new SmbComFindClose2( sid ), blank_resp );
if( results.length != count ) {
String[] tmp = results;
}
/**
+ * List the contents of this SMB resource as an array of
+ * <code>SmbFile</code> objects. This method is much more efficient than
+ * the regular <code>list</code> method when querying attributes of each
+ * file in the result set.
+ * <p>
+ * The list of <code>SmbFile</code>s returned by this method will be;
+ *
+ * <ul>
+ * <li> files and directories contained within this resource if the
+ * resource is a normal disk file directory,
+ * <li> all available NetBIOS workgroups or domains if this resource is
+ * the top level URL <code>smb://</code>,
+ * <li> all servers registered as members of a NetBIOS workgroup if this
+ * resource refers to a workgroup in a <code>smb://workgroup</code> URL,
+ * <li> all browseable shares of a server including printers, IPC
+ * services, or disk volumes if this resource is a server URL in the form
+ * <code>smb://server</code>,
+ * <li> or <code>null</code> if the resource cannot be resolved.
+ * </ul>
+ *
+ * @return An array of <code>SmbFile</code> objects representing file
+ * and directories, workgroups, servers, or shares depending on the context
+ * of the resource URL
+ */
+
+ public SmbFile[] listFiles() throws SmbException {
+ return listFiles( "*" );
+ }
+
+/**
+ * The CIFS protocol provides for DOS "wildcards" to be used as
+ * a performance enhancement. The client does not have to filter
+ * the names ane the server does not have to return all directory
+ * entries.
+ * <p>
+ * The wildcard expression may consist of two special meta
+ * characters in addition to the normal filename characters. The '*'
+ * character matches any number of characters in part of a name. If
+ * the expression begins with one or more '?'s then exactly that
+ * many characters will be matched whereas if it ends with '?'s
+ * it will match that many characters <i>or less</i>.
+ * <p>
+ * Wildcard expressions will not filter workgroup names or server names.
+ *
+ * <blockquote><pre>
+ * winnt> ls c?o*
+ * clock.avi -rw-- 82944 Mon Oct 14 1996 1:38 AM
+ * Cookies drw-- 0 Fri Nov 13 1998 9:42 PM
+ * 2 items in 5ms
+ * </pre></blockquote>
+ *
+ * @param wildcard a wildcard expression
+ * @throws SmbException
+ * @return An array of <code>SmbFile</code> objects representing file
+ * and directories, workgroups, servers, or shares depending on the context
+ * of the resource URL
+ */
+
+ public SmbFile[] listFiles( String wildcard ) throws SmbException {
+ if( url.toString().lastIndexOf( '/' ) != ( url.toString().length() - 1 )) {
+ throw new SmbException( SmbException.ERRCLI,
+ SmbException.ERRlistFiles, url.toString() + " directory must end with '/'" );
+ }
+ try {
+ if( url.getHost().length() == 0 ) {
+ connect0();
+
+ NetServerEnum2Response response = new NetServerEnum2Response();
+ sendTransaction( new NetServerEnum2(
+ tree.session.transport.server.oemDomainName,
+ NetServerEnum2.SV_TYPE_DOMAIN_ENUM ), response );
+
+ if( response.status != SmbException.NERR_Success &&
+ response.status != SmbException.ERROR_MORE_DATA ) {
+ throw new SmbException( SmbException.ERRRAP,
+ response.status, response.toString() );
+ }
+
+ SmbFile[] ret = new SmbFile[response.entriesReturned];
+ for( int i = 0; i < response.entriesReturned; i++ ) {
+ ret[i] = new SmbFile( this,
+ response.results[i].name,
+ TYPE_WORKGROUP,
+ ATTR_READONLY | ATTR_DIRECTORY,
+ 0L,
+ 0L );
+ }
+//System.err.println( "ret=" + ret.length + ",ret[0]=" + ret[0] + ",name=" + response.results[0].name );
+
+ return ret;
+ } else if( share == null ) {
+ if( getType() == TYPE_WORKGROUP ) {
+ NetServerEnum2Response response = new NetServerEnum2Response();
+ sendTransaction( new NetServerEnum2( url.getHost(),
+ NetServerEnum2.SV_TYPE_ALL ), response );
+
+ if( response.status != SmbException.NERR_Success &&
+ response.status != SmbException.ERROR_MORE_DATA ) {
+ throw new SmbException( SmbException.ERRRAP, response.status );
+ }
+
+ SmbFile[] ret = new SmbFile[response.entriesReturned];
+ for( int i = 0; i < response.entriesReturned; i++ ) {
+ ret[i] = new SmbFile( this,
+ response.results[i].name,
+ TYPE_SERVER,
+ ATTR_READONLY | ATTR_DIRECTORY,
+ 0L,
+ 0L );
+ }
+
+ return ret;
+ } else {
+ NetShareEnumResponse response = new NetShareEnumResponse();
+ sendTransaction( new NetShareEnum(), response );
+
+ if( response.status != SmbException.NERR_Success &&
+ response.status != SmbException.ERROR_MORE_DATA ) {
+ throw new SmbException( SmbException.ERRRAP, response.status );
+ }
+
+ SmbFile[] ret = new SmbFile[response.entriesReturned];
+ for( int i = 0; i < response.entriesReturned; i++ ) {
+ int shareType = response.results[i].type;
+ switch( shareType ) {
+ case 1:
+ shareType = TYPE_PRINTER;
+ break;
+ case 3:
+ shareType = TYPE_NAMED_PIPE;
+ break;
+ default:
+ shareType = TYPE_SHARE;
+ break;
+ }
+ ret[i] = new SmbFile( this,
+ response.results[i].netName,
+ shareType,
+ ATTR_READONLY | ATTR_DIRECTORY,
+ 0L,
+ 0L );
+ }
+ return ret;
+ }
+ } else {
+ return listFiles( getUncPath0(), wildcard );
+ }
+ } catch( UnknownHostException uhe ) {
+ throw new SmbException( SmbException.ERRCLI,
+ SmbException.ERRunknownHost, url.toString() );
+ } catch( MalformedURLException mue ) {
+ throw new SmbException( SmbException.ERRCLI,
+ SmbException.ERRlistFiles, url.toString() );
+ }
+ }
+ SmbFile[] listFiles( String dirPath, String wildcard ) throws SmbException {
+ int sid, count, i, j;
+ SmbFile[] results;
+ String base, filename;
+
+ Log.println( Log.WARNINGS, "smb find warning",
+ " find with path=" + dirPath );
+
+ Trans2FindFirst2Response response = new Trans2FindFirst2Response();
+ if( dirPath.equals( "\\" )) {
+ filename = "\\" + wildcard;
+ } else {
+ filename = dirPath + "\\" + wildcard;
+ }
+ sendTransaction( new Trans2FindFirst2( filename ), response );
+
+ sid = response.sid;
+ count = response.searchCount;
+ j = 0;
+
+ results = new SmbFile[Math.max( 16, count )];
+
+ int h1 = new String( "." ).hashCode();
+ int h2 = new String( ".." ).hashCode();
+ i = 0;
+ try {
+ while( j < count ) {
+ filename = response.results[i].filename;
+ if( filename.length() < 3 ) {
+ int h = filename.hashCode();
+ if( h == h1 || h == h2 ) {
+ count--;
+ i++;
+ continue;
+ }
+ }
+ results[j++] = new SmbFile( this,
+ filename,
+ TYPE_FILESYSTEM,
+ response.results[i].extFileAttributes,
+ response.results[i].lastWriteTime,
+ response.results[i].endOfFile );
+ i++;
+ }
+
+ /* only difference between first2 and next2
+ * responses is subCommand so let's recycle
+ */
+ response.subCommand = SmbComTransaction.TRANS2_FIND_NEXT2;
+
+ while( response.isEndOfSearch == false && response.searchCount > 0 ) {
+ sendTransaction( new Trans2FindNext2( sid, response.resumeKey,
+ response.lastName ), response );
+ count += response.searchCount;
+
+ if( count > results.length ) {
+ SmbFile[] tmp = results;
+ results = new SmbFile[Math.max( results.length * 2, count )];
+ System.arraycopy( tmp, 0, results, 0, j );
+ }
+ i = 0;
+ while( j < count ) {
+ filename = response.results[i].filename;
+ if( filename.length() < 3 ) {
+ int h = filename.hashCode();
+ if( h == h1 || h == h2 ) {
+ count--;
+ continue;
+ }
+ }
+ results[j++] = new SmbFile( this,
+ filename,
+ TYPE_FILESYSTEM,
+ response.results[i].extFileAttributes,
+ response.results[i].lastWriteTime,
+ response.results[i].endOfFile );
+ i++;
+ }
+ }
+ } catch( UnknownHostException uhe ) {
+ throw new SmbException( SmbException.ERRCLI,
+ SmbException.ERRunknownHost, url.toString() );
+ } catch( MalformedURLException mue ) {
+ throw new SmbException( SmbException.ERRCLI,
+ SmbException.ERRlistFiles, "Malformed URL: " + url.toString() );
+ }
+
+ send( new SmbComFindClose2( sid ), blank_resp );
+
+ if( results.length != count ) {
+ SmbFile[] tmp = results;
+ results = new SmbFile[count];
+ System.arraycopy( tmp, 0, results, 0, count );
+ }
+
+ return results;
+ }
+/**
* Changes the name of the file this <code>SmbFile</code> represents to the name
* designated by the <code>SmbFile</code> argument(Remember:
* <code>SmbFile</code>s are immutible
*/
public void renameTo( SmbFile dest ) throws SmbException {
- if( canonicalPath == null || dest.canonicalPath == null ) {
+ if( getUncPath0().length() == 1 || dest.getUncPath0().length() == 1 ) {
throw new SmbException( SmbException.ERRDOS,
- SmbException.ERRnoaccess );
+ SmbException.ERRnoaccess,
+ "Cannot rename shares, servers, workgroups, or domains" );
+ }
+ connect0();
+ dest.connect0();
+ if( tree != dest.tree ) {
+ throw new SmbException( SmbException.ERRDOS,
+ SmbException.ERRnoaccess,
+ "Cannot rename file to a different share" );
}
Log.println( Log.WARNINGS, "smb rename warning",
- " oldFileName=" + uncPath +
- ",newFileName=" + dest.uncPath );
+ " oldFileName=" + unc +
+ ",newFileName=" + dest.unc );
- attrExpiration = 0;
+ attrExpiration = sizeExpiration = 0;
/*
* Rename Request / Response
*/
- SmbComBlankResponse response = new SmbComBlankResponse();
- send( new SmbComRename( uncPath, dest.uncPath ), response );
+ send( new SmbComRename( unc, dest.unc ), blank_resp );
+ }
+
+ class WriterThread extends Thread {
+ byte[] b;
+ int n, off;
+ boolean ready = true;
+ SmbFile dest;
+ SmbException e = null;
+ SmbComWriteAndX req = new SmbComWriteAndX();
+ SmbComWriteAndXResponse resp = new SmbComWriteAndXResponse();
+
+ WriterThread() {
+ super( "JCIFS-WriterThread" );
+ }
+
+ synchronized void write( byte[] b, int n, SmbFile dest, int off ) {
+ this.b = b;
+ this.n = n;
+ this.dest = dest;
+ this.off = off;
+ ready = false;
+ notify();
+ }
+
+ public void run() {
+ synchronized( this ) {
+ try {
+ for( ;; ) {
+ ready = true;
+ while( ready ) {
+ wait();
+ }
+ if( n == -1 ) {
+ return;
+ }
+ req.setParam( dest.fid, off, n, b, 0, n );
+ dest.send( req, resp );
+ notify();
+ }
+ } catch( SmbException e ) {
+ this.e = e;
+ } catch( Exception x ) {
+ this.e = new SmbException( SmbException.ERRCLI,
+ SmbException.ERRioe, x.getMessage() );
+ }
+ notify();
+ }
+ }
+ }
+ void copyTo0( SmbFile dest, byte[][] b, int bsize, WriterThread w,
+ SmbComReadAndX req, SmbComReadAndXResponse resp ) throws SmbException {
+ int i;
+
+ if( attrExpiration < System.currentTimeMillis() ) {
+ attributes = ATTR_READONLY | ATTR_DIRECTORY;
+ lastModified = 0L;
+ isExists = false;
+
+ Info info = queryPath( getUncPath0(),
+ Trans2QueryPathInformationResponse.SMB_QUERY_FILE_BASIC_INFO );
+ attributes = info.getAttributes();
+ lastModified = info.getLastWriteTime();
+
+ /* If any of the above fails, isExists will not be set true
+ */
+
+ isExists = true;
+ attrExpiration = System.currentTimeMillis() + attrExpirationPeriod;
+ }
+
+ if( isDirectory() ) {
+ SmbFile[] files;
+ SmbFile ndest;
+
+ try {
+ dest.mkdir();
+ } catch( SmbException se ) {
+ if( se.getErrorCode() != SmbException.ERRnoaccess &&
+ se.getErrorCode() != SmbException.ERRexists ) {
+ throw se;
+ }
+ }
+
+ files = listFiles();
+ try {
+ for( i = 0; i < files.length; i++ ) {
+ ndest = new SmbFile( dest,
+ files[i].getName(),
+ files[i].type,
+ files[i].attributes,
+ files[i].lastModified,
+ files[i].size );
+ files[i].copyTo0( ndest, b, bsize, w, req, resp );
+ }
+ } catch( UnknownHostException uhe ) {
+ throw new SmbException( SmbException.ERRCLI,
+ SmbException.ERRunknownHost, url.toString() );
+ } catch( MalformedURLException mue ) {
+ throw new SmbException( SmbException.ERRCLI,
+ SmbException.ERRlistFiles, url.toString() );
+ }
+ } else {
+ int off;
+
+ open( SmbFile.O_RDONLY );
+ dest.open( SmbFile.O_CREAT | SmbFile.O_WRONLY | SmbFile.O_TRUNC );
+
+ i = off = 0;
+ for( ;; ) {
+ req.setParam( fid, off, bsize );
+ resp.setParam( b[i], 0 );
+ send( req, resp );
+
+ synchronized( w ) {
+ while( !w.ready ) {
+ try {
+ w.wait();
+ } catch( InterruptedException ie ) {
+ throw new SmbException( SmbException.ERRCLI,
+ SmbException.ERRioe, ie.getMessage() );
+ }
+ }
+ if( w.e != null ) {
+ throw w.e;
+ }
+ if( resp.dataLength <= 0 ) {
+ break;
+ }
+ w.write( b[i], resp.dataLength, dest, off );
+ }
+
+ i = i == 1 ? 0 : 1;
+ off += resp.dataLength;
+ }
+ dest.close( lastModified - tree.session.transport.server.serverTimeZone * 60 * 1000 );
+ close();
+ }
+ }
+/**
+ * This method will copy the file or directory and it's subcontents represented by this <tt>SmbFile</tt> to the location specified by the <tt>dest</tt> parameter. This file and the destination file do not need to be on the same host. This operation does not copy extended file attibutes and files copied to NT 4.0 will not preserve file modification times.
+*/
+ public void copyTo( SmbFile dest ) throws SmbException {
+ SmbComReadAndX req;
+ SmbComReadAndXResponse resp;
+ WriterThread w;
+ int bsize;
+ byte[][] b;
+
+ /* Should be able to copy an entire share actually
+ */
+ if( getUncPath0().length() == 1 || dest.getUncPath0().length() == 1 ) {
+ throw new SmbException( SmbException.ERRDOS,
+ SmbException.ERRnoaccess,
+ "Cannot copyTo workgroups, servers, or shares" );
+ }
+
+ req = new SmbComReadAndX();
+ resp = new SmbComReadAndXResponse();
+ w = new WriterThread();
+ w.setDaemon( true );
+ w.start();
+
+ connect0();
+ dest.connect0();
+
+ bsize = Math.min( Math.min( tree.session.transport.rcv_buf_size - 70,
+ dest.tree.session.transport.server.maxBufferSize - 70 ),
+ Math.min( tree.session.transport.snd_buf_size - 70,
+ dest.tree.session.transport.server.maxBufferSize - 70 ));
+ b = new byte[2][bsize];
+
+ copyTo0( dest, b, bsize, w, req, resp );
+ w.write( null, -1, null, 0 );
}
/**
* This method will delete the file or directory specified by this
* <code>SmbFile</code>. If the target is a directory, the contents of
- * the directory will be deleted as well.
+ * the directory will be deleted as well. If the resource or sub-resource
+ * is marked read-only or is locked the operation will fail. There is currently no functionality to set the attributes of a file, break locks, or disconnect users.
*
- * @return <code>true</code> if the delete operation was successfull and
- * <code>false</code> otherwise
+ * @throws SmbException
*/
public void delete() throws SmbException {
- delete( uncPath );
+ delete( getUncPath0() );
}
void delete( String fileName ) throws SmbException {
- if( canonicalPath == null ) {
+ if( getUncPath0().length() == 1 ) {
throw new SmbException( SmbException.ERRDOS,
SmbException.ERRnoaccess );
}
- attrExpiration = 0;
-
- Log.println( Log.WARNINGS, "smb delete warning",
- " fileName=" + fileName );
-
/*
* Delete or Delete Directory Request / Response
*/
- ServerMessageBlock request = new SmbComDelete( fileName );
- try {
- send( request, new SmbComBlankResponse() );
- return;
- } catch( SmbException se ) {
- }
+ if( isDirectory() ) {
- /* Recursively delete directory contents using post order DFS
- */
+ /* Recursively delete directory contents
+ */
+
+ SmbFile[] l = listFiles( fileName, "*" );
+
+ for( int i = 0; i < l.length; i++ ) {
+ l[i].delete();
+ }
+
+ Log.println( Log.WARNINGS, "smb delete directory warning",
+ " fileName=" + fileName );
- String[] ls = list( fileName );
- for( int i = 0; i < ls.length; i++ ) {
- delete( fileName + "\\" + ls[i] );
+ send( new SmbComDeleteDirectory( fileName ), blank_resp );
+ } else {
+
+ Log.println( Log.WARNINGS, "smb delete warning",
+ " fileName=" + fileName );
+
+ send( new SmbComDelete( fileName ), blank_resp );
}
- request = new SmbComDeleteDirectory( fileName );
- send( request, new SmbComBlankResponse() );
+ attrExpiration = sizeExpiration = 0;
}
/**
- * Returns the length in bytes of this file represented by this
- * <code>SmbFile</code>. The <code>SmbFile</code> must not be a directory.
+ * Returns the length of this <tt>SmbFile</tt> in bytes.
+ * If this object is a <tt>TYPE_SHARE</tt> the total capacity of the disk shared in bytes is returned.
+ * If this object is a directory or a type other than <tt>TYPE_SHARE</tt>, 0L is returned.
*
- * @return The length of the file in bytes
+ * @return The length of the file in bytes or 0 if this <code>SmbFile</code> is not a file.
*/
public long length() throws SmbException {
- if( canonicalPath != null ) {
- Info info = queryPath( Trans2QueryPathInformationResponse.SMB_QUERY_FILE_STANDARD_INFO );
- return info.getSize();
+ if( sizeExpiration > System.currentTimeMillis() ) {
+ return size;
+ }
+
+ if( getType() == TYPE_SHARE ) {
+ Trans2QueryFSInformationResponse response;
+ int level = Trans2QueryFSInformationResponse.SMB_INFO_ALLOCATION;
+
+ response = new Trans2QueryFSInformationResponse( level );
+ sendTransaction( new Trans2QueryFSInformation( level ), response );
+
+ size = response.info.getCapacity();
+ } else if( getUncPath0().length() > 1 && type != TYPE_NAMED_PIPE ) {
+ Info info = queryPath( getUncPath0(),
+ Trans2QueryPathInformationResponse.SMB_QUERY_FILE_STANDARD_INFO );
+ size = info.getSize();
+ } else {
+ size = 0L;
+ }
+ sizeExpiration = System.currentTimeMillis() + attrExpirationPeriod;
+ return size;
+ }
+
+/**
+ * This method returns the free disk space in bytes of the drive this share
+ * represents or the drive on which the directory or file resides. Objects
+ * other than <tt>TYPE_SHARE</tt> or <tt>TYPE_FILESYSTEM</tt> will result
+ * in 0L being returned.
+ */
+ public long getDiskFreeSpace() throws SmbException {
+ if( getType() == TYPE_SHARE || type == TYPE_FILESYSTEM ) {
+ Trans2QueryFSInformationResponse response;
+ int level = Trans2QueryFSInformationResponse.SMB_INFO_ALLOCATION;
+
+ response = new Trans2QueryFSInformationResponse( level );
+ sendTransaction( new Trans2QueryFSInformation( level ), response );
+
+ if( type == TYPE_SHARE ) {
+ size = response.info.getCapacity();
+ sizeExpiration = System.currentTimeMillis() + attrExpirationPeriod;
+ }
+
+ return response.info.getFree();
}
return 0L;
}
/**
* Creates a directory with the path specified by this
* <code>SmbFile</code>. For this method to be successfull, the target
- * must not already exist. This method will return false when
+ * must not already exist. This method will fail when
* used with <code>smb://</code>, <code>smb://workgroup</code>,
* <code>smb://server</code>, or <code>smb://server/share</code> URLs
* because workgroups, servers, and shares cannot be dynamically created.
*
- * @return <code>true</code> if the file was successfully created or
- * <code>false</code> otherwise
+ * @throws SmbException
*/
public void mkdir() throws SmbException {
- if( canonicalPath == null ) {
+ if( getUncPath0().length() == 1 ) {
throw new SmbException( SmbException.ERRDOS,
SmbException.ERRnoaccess );
}
+
Log.println( Log.WARNINGS, "smb create directory warning",
- " directoryName=" + uncPath );
+ " directoryName=" + getUncPath0() );
/*
* Create Directory Request / Response
*/
- send( new SmbComCreateDirectory( uncPath ),
- new SmbComBlankResponse() );
+ send( new SmbComCreateDirectory( getUncPath0() ), blank_resp );
+
+ attrExpiration = sizeExpiration = 0;
+ }
+/**
+ * Creates a directory with the path specified by this <tt>SmbFile</tt> and any parent directories if necessary.
+ * For this method to be successfull, the target
+ * must not already exist. This method will fail when
+ * used with <code>smb://</code>, <code>smb://workgroup</code>,
+ * <code>smb://server</code>, or <code>smb://server/share</code> URLs
+ * because workgroups, servers, and shares cannot be dynamically created.
+ *
+ * @throws SmbException
+ */
+ public void mkdirs() throws SmbException {
+ SmbFile parent;
+
+ try {
+ parent = new SmbFile( new URL( null, getParent(), Handler.SMB_HANDLER ));
+ } catch( IOException ioe ) {
+ return;
+ }
+ if( parent.exists() == false ) {
+ parent.mkdirs();
+ }
+ mkdir();
}
/**
* Returns a {@link java.net.URL} for this <code>SmbFile</code>. The
* <code>URL</code> may be used as any other <code>URL</code> might to
- * access an smb resource. Currently only retrieving data and information
+ * access an SMB resource. Currently only retrieving data and information
* is supported.
*
- * @return A new <code>URL</code> for this <code>SmbFile</code>
+ * @depricated Use getURL() instead
+ *
+ * @return A new <code>{@link java.net.URL}</code> for this <code>SmbFile</code>
*/
public URL toURL() throws MalformedURLException {
- return new URL( getCanonicalPath() );
+ return url;
}
/**
*/
public int hashCode() {
- if( hash == 0 ) {
- hash = address.hashCode();
- if( port != 0 && port != 139 ) {
- hash += 65621 * port;
- }
- if( share != null ) {
- hash += 65521 * share.toUpperCase().hashCode();
- if( canonicalPath != null ) {
- hash += 65521 * canonicalPath.toUpperCase().hashCode();
- }
- }
- }
- return hash;
+ return url.hashCode();
}
/**
*/
public boolean equals( Object obj ) {
+//HERE
return obj instanceof SmbFile && obj.hashCode() == hashCode();
}
/**
* Returns the string representation of this SmbFile object. This will
- * be the same as the URL used to construct this <code>SmbFile</code>. The
- * path will not be canonicalized. This method will return the same value
+ * be the same as the URL used to construct this <code>SmbFile</code>.
+ * This method will return the same value
* as <code>getPath</code>.
*
- * @return The URL representation of this SMB resource
+ * @return The original URL representation of this SMB resource
*/
public String toString() {
- return url;
+ return url.toString();
+ }
+
+/* URLConnection implementation */
+
+ public int getContentLength() {
+ try {
+ return (int)(length() & 0xFFFFFFFFL);
+ } catch( SmbException se ) {
+ }
+ return 0;
+ }
+ public long getDate() {
+ try {
+ return lastModified();
+ } catch( SmbException se ) {
+ }
+ return 0L;
+ }
+ public long getLastModified() {
+ try {
+ return lastModified();
+ } catch( SmbException se ) {
+ }
+ return 0L;
+ }
+ public InputStream getInputStream() throws IOException {
+ return new SmbFileInputStream( this );
}
}
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
package jcifs.smb;
-import java.io.InputStream;
-import java.io.IOException;
+import java.net.URL;
import java.net.UnknownHostException;
import java.net.MalformedURLException;
+import java.io.InputStream;
+import java.io.IOException;
/**
- * This InputStream can read bytes from a file on an SMB file server.
+ * This InputStream can read bytes from a file on an SMB file server. Offsets are 64 bits.
*/
public class SmbFileInputStream extends InputStream {
private SmbFile file;
- private int fp, off, readSize, openFlags;
+ private long fp;
+ private int off, readSize, openFlags;
private byte[] tmp = new byte[1];
/**
if( len <= 0 ) {
return 0;
}
- int start = fp;
+ long start = fp;
// ensure file is open
file.open( openFlags );
SmbComReadAndXResponse response = new SmbComReadAndXResponse( b, off );
- if( file.isPipe ) {
+ if( file.type == SmbFile.TYPE_NAMED_PIPE ) {
response.responseTimeout = 0;
}
try {
file.send( new SmbComReadAndX( file.fid, fp, r, null ), response );
} catch( SmbException se ) {
- if( file.isPipe && se.errorClass == SmbException.ERRDOS &&
- se.errorCode == SmbException.ERRbrokenpipe ) {
+ if( file.type == SmbFile.TYPE_NAMED_PIPE &&
+ se.errorClass == SmbException.ERRDOS &&
+ se.errorCode == SmbException.ERRbrokenpipe ) {
return -1;
}
throw se;
}
if(( n = response.dataLength ) <= 0 ) {
- return -1;
+ return (int)((fp - start) > 0L ? fp - start : -1);
}
-//System.out.println( "n=" + n );
fp += n;
len -= n;
response.off += n;
} while( len > 0 && n == r );
- return fp - start;
+ return (int)(fp - start);
+ }
+ public int available() throws IOException {
+ SmbNamedPipe pipe;
+ TransPeekNamedPipe req;
+ TransPeekNamedPipeResponse resp;
+
+ if( file.type != SmbFile.TYPE_NAMED_PIPE ) {
+ return 0;
+ }
+
+ pipe = (SmbNamedPipe)file;
+ file.open(( pipe.pipeType & 0xFF0000 ) | SmbFile.O_EXCL );
+
+ req = new TransPeekNamedPipe( file.unc, file.fid );
+ resp = new TransPeekNamedPipeResponse( pipe );
+
+ pipe.sendTransaction( req, resp );
+ if( resp.status == TransPeekNamedPipeResponse.STATUS_DISCONNECTED ||
+ resp.status == TransPeekNamedPipeResponse.STATUS_SERVER_END_CLOSED ) {
+ file.opened = false;
+ return 0;
+ }
+ return resp.available;
}
}
+
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
package jcifs.smb;
+import java.net.URL;
import java.io.OutputStream;
import java.io.IOException;
import java.net.UnknownHostException;
private SmbFile file;
private boolean append;
- private int openFlags, fp, writeSize;
+ private int openFlags, writeSize;
+ private long fp;
private byte[] tmp = new byte[1];
/**
this( file, append, append ? SmbFile.O_CREAT | SmbFile.O_WRONLY | SmbFile.O_APPEND :
SmbFile.O_CREAT | SmbFile.O_WRONLY | SmbFile.O_TRUNC );
}
+/**
+ * Creates an {@link java.io.OutputStream} for writing bytes to a file
+ * on an SMB server addressed by the <code>SmbFile</code> parameter. See
+ * {@link jcifs.smb.SmbFile} for a detailed description and examples of
+ * the smb URL syntax.
+<p>
+The second parameter specifies how the file should be shared. If
+<code>SmbFile.FILE_NO_SHARE</code> is specified the client will
+have exclusive access to the file. An additional open command
+from jCIFS or another application will fail with the "file is being
+accessed by another process" error. The <code>FILE_SHARE_READ</code>,
+<code>FILE_SHARE_WRITE</code>, and <code>FILE_SHARE_DELETE</code> may be
+combined with the bitwise OR '|' to specify that other peocesses may read,
+write, and/or delete the file while the jCIFS user has the file open.
+ *
+ * @param url An <code>SmbFile</code> representing the file to write to
+ * @return A new <code>OutputStream</code> for the specified <code>SmbFile</code>
+ */
+
+ public SmbFileOutputStream( String url, int shareAccess ) throws SmbException, MalformedURLException, UnknownHostException {
+ this( new SmbFile( url, "", null, shareAccess ), false );
+ }
SmbFileOutputStream( SmbFile file, boolean append, int openFlags ) throws SmbException, MalformedURLException, UnknownHostException {
this.file = file;
this.append = append;
this.openFlags = openFlags;
if( append ) {
- fp = (int)file.length();
+ try {
+ fp = file.length();
+ } catch( SmbException se ) {
+ fp = 0L;
+ }
}
file.open( openFlags );
writeSize = Math.min( file.tree.session.transport.snd_buf_size - 70,
if( file.isOpen() == false ) {
file.open( openFlags );
if( append ) {
- fp = (int)file.length();
+ fp = file.length();
}
}
+/*
Log.println( Log.WARNINGS, "smb write warning",
" fid=" + file.fid + ",off=" + off + ",len=" + len );
+*/
int w;
do {
w = len > writeSize ? writeSize : len;
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
- * "Paul Walker" <Paul.Walker@NBNZ.CO.NZ>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
+ * "Paul Walker" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
package jcifs.smb;
+import java.net.URL;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
* Named Pipes</a> for a detailed description of how to use jCIFS with
* Win32 Named Pipe server processes.
*
- * @since jcifs-0.5
*/
public class SmbNamedPipe extends SmbFile {
throws MalformedURLException, UnknownHostException {
super( url );
this.pipeType = pipeType;
- isPipe = true;
+ type = TYPE_NAMED_PIPE;
+ }
+ public SmbNamedPipe( String url, int pipeType, NtlmPasswordAuthentication auth )
+ throws MalformedURLException, UnknownHostException {
+ super( url, auth );
+ this.pipeType = pipeType;
+ type = TYPE_NAMED_PIPE;
+ }
+ public SmbNamedPipe( URL url, int pipeType, NtlmPasswordAuthentication auth )
+ throws MalformedURLException, UnknownHostException {
+ super( url, auth );
+ this.pipeType = pipeType;
+ type = TYPE_NAMED_PIPE;
}
/**
if( pipeIn == null ) {
if(( pipeType & PIPE_TYPE_CALL ) == PIPE_TYPE_CALL ||
( pipeType & PIPE_TYPE_TRANSACT ) == PIPE_TYPE_TRANSACT ) {
- pipeIn = new TransactNamedPipeInputStream();
+ pipeIn = new TransactNamedPipeInputStream( this );
} else {
pipeIn = new SmbFileInputStream( this,
( pipeType & 0xFF0000 ) | SmbFile.O_EXCL );
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
package jcifs.smb;
-import jcifs.util.DES;
-import jcifs.util.MD4;
-import java.io.UnsupportedEncodingException;
-import java.util.Hashtable;
import java.util.Vector;
import java.util.Enumeration;
import java.net.InetAddress;
+import java.net.UnknownHostException;
+import jcifs.UniAddress;
+
+/**
+ * The class represents a user's session established with an SMB/CIFS
+ * server. This class is used internally to the jCIFS library however
+ * applications may wish to authenticate aribrary user credentials
+ * with the <tt>logon</tt> method. It is noteworthy that jCIFS does not
+ * support DCE/RPC at this time and therefore does not use the NETLOGON
+ * procedure. Instead, it simply performs a "tree connect" to IPC$ using
+ * the supplied credentials. This is only a subset of the NETLOGON procedure
+ * but is achives the same effect.
+ */
-class SmbSession {
-
- // KGS!@#$%
- static final byte[] S8 = {
- (byte)0x4b, (byte)0x47, (byte)0x53, (byte)0x21,
- (byte)0x40, (byte)0x23, (byte)0x24, (byte)0x25
- };
- static void E( byte[] key, byte[] data, byte[] e ) {
- byte[] key7 = new byte[7];
- byte[] e8 = new byte[8];
-
- for( int i = 0; i < key.length / 7; i++ ) {
- System.arraycopy( key, i * 7, key7, 0, 7 );
- DES des = new DES( key7 );
- des.encrypt( data, e8 );
- System.arraycopy( e8, 0, e, i * 8, 8 );
- }
- }
- static byte[] getPreNTLMResponse( String password, byte[] challenge ) {
- byte[] p14 = new byte[14];
- byte[] p21 = new byte[21];
- byte[] p24 = new byte[24];
-
- System.arraycopy( password.toUpperCase().getBytes(), 0, p14, 0, password.length() );
- E( p14, S8, p21);
- E( p21, challenge, p24);
- return p24;
+public final class SmbSession {
+
+ public static byte[] getChallenge( UniAddress dc ) throws SmbException, UnknownHostException {
+ SmbTransport trans = SmbTransport.getSmbTransport( dc, 0 );
+ trans.negotiate();
+ return trans.server.encryptionKey;
}
- static byte[] getNTLMResponse( String password, byte[] challenge ) {
- byte[] uni = null;
- byte[] p21 = new byte[21];
- byte[] p24 = new byte[24];
-
- try {
- uni = password.getBytes( "UnicodeLittleUnmarked" );
- } catch( UnsupportedEncodingException uee ) {
- Log.printStackTrace( "password encryption exception", uee );
- }
- MD4 md4 = new MD4();
- md4.update( uni );
- System.arraycopy( md4.digest(), 0, p21, 0, 16 );
- E( p21, challenge, p24 );
- return p24;
+/**
+ * Authenticate arbitrary credentials represented by the
+ * <tt>NtlmPasswordAuthentication</tt> object against the domain controller
+ * specified by the <tt>UniAddress</tt> parameter. If the credentials are
+ * not accepted, an <tt>SmbAuthException</tt> will be thrown. If an error
+ * occurs an <tt>SmbException</tt> will be thrown. If the credentials are
+ * valid, the method will return without throwing an exception. See the
+ * last <a href="../../../../FAQ.html">FAQ</a> question.
+ */
+ public static void logon( UniAddress dc,
+ NtlmPasswordAuthentication auth ) throws SmbException {
+ SmbTransport.getSmbTransport( dc, 0 ).getSmbSession( auth ).getSmbTree( "IPC$", null ).treeConnect( null, null );
}
int uid;
- String username, password, domain;
+ NtlmPasswordAuthentication auth;
SmbTransport transport;
Vector trees;
boolean sessionSetup;
- String passwordString = "*****";
- SmbSession( SmbTransport transport, String username,
- String password, String domain ) {
+ SmbSession( SmbTransport transport, NtlmPasswordAuthentication auth ) {
this.transport = transport;
- this.username = username.toUpperCase();
- this.password = password;
- this.domain = domain.toUpperCase();
+ this.auth = auth;
trees = new Vector();
- passwordString = password == null ? "null" : "";
}
synchronized SmbTree getSmbTree( String share, String service ) {
SmbTree t;
+
+ if( share == null ) {
+ share = "IPC$";
+ }
for( Enumeration e = trees.elements(); e.hasMoreElements(); ) {
t = (SmbTree)e.nextElement();
if( t.matches( share, service )) {
trees.addElement( t );
return t;
}
- boolean matches( String username, String password, String domain ) {
- return this.username.equals( username.toUpperCase() ) &&
- this.password.equals( password ) &&
- this.domain.equals( domain.toUpperCase() );
+ boolean matches( NtlmPasswordAuthentication auth ) {
+ return this.auth == auth || this.auth.equals( auth );
}
void sendTransaction( SmbComTransaction request,
- SmbComTransactionResponse response ) throws SmbException {
+ SmbComTransactionResponse response ) throws SmbException {
// transactions are not batchable
sessionSetup( null, null );
request.uid = uid;
}
Log.println( Log.WARNINGS, "smb session setup warning",
- " requesting session with accountName=" + username +
- ",accountPassword=" + passwordString +
- ",primaryDomain=" + domain );
+ " requesting session with accountName=" + auth.username +
+ ",primaryDomain=" + auth.domain );
/*
* Session Setup And X Request / Response
uid = response.uid;
sessionSetup = true;
}
- synchronized void logoff() throws SmbException {
+ synchronized void logoff( boolean inError ) {
if( sessionSetup == false ) {
return;
}
for( Enumeration e = trees.elements(); e.hasMoreElements(); ) {
SmbTree t = (SmbTree)e.nextElement();
- t.treeDisconnect();
+ t.treeDisconnect( inError );
}
- sessionSetup = false;
if( transport.server.security == ServerMessageBlock.SECURITY_SHARE ) {
return;
}
- /*
- * Logoff And X Request / Response
- */
+ if( !inError ) {
- SmbComLogoffAndX request = new SmbComLogoffAndX( null );
- request.uid = uid;
- transport.send( request, null );
+ /*
+ * Logoff And X Request / Response
+ */
+
+ try {
+ SmbComLogoffAndX request = new SmbComLogoffAndX( null );
+ request.uid = uid;
+ transport.send( request, null );
+ } catch( SmbException se ) {
+ }
+ }
+ sessionSetup = false;
}
public String toString() {
- return "SmbSession[accountName=" + username +
- ",accountPassword=" + passwordString +
- ",primaryDomain=" + domain +
- ",uid=" + uid + "]";
+ return "SmbSession[accountName=" + auth.username +
+ ",primaryDomain=" + auth.domain +
+ ",uid=" + uid +
+ ",sessionSetup=" + sessionSetup + "]";
}
}
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
private static final int DEFAULT_RESPONSE_TIMEOUT = 10000;
private static final int DEFAULT_SO_TIMEOUT = 15000;
private static final int PUSHBACK_BUF_SIZE = 64;
- private static final int DEFAULT_RCV_BUF_SIZE = 4096;
- private static final int DEFAULT_SND_BUF_SIZE = 1300;
+ private static final int DEFAULT_RCV_BUF_SIZE = 60416;
+ private static final int DEFAULT_SND_BUF_SIZE = 5000;
static final int MID_OFFSET = 30;
static final int HEADER_LENGTH = 32;
static final int FLAGS_OFFSET = 9;
static final int FLAGS_RESPONSE = 0x80;
- private byte[] rcv_buf, snd_buf;
-
private NbtSocket socket; // should become UniSocket?
private InputStream in;
private OutputStream out;
private static Vector connections = new Vector();
private static MpxControl mpxCtrl = new MpxControl();
+private static byte[] snd_buf = new byte[0xFFFF];
+private static byte[] rcv_buf = new byte[0xFFFF];
+
Vector sessions;
boolean negotiated, useUnicode;
ServerMessageBlock.CAP_UNICODE | ServerMessageBlock.CAP_NT_SMBS );
String nativeOs = Config.getProperty( "jcifs.smb.client.nativeOs",
System.getProperty( "os.name" ));
- String nativeLanMan = Config.getProperty( "jcifs.smb.client.nativeLanMan", "foo" );
+ String nativeLanMan = Config.getProperty( "jcifs.smb.client.nativeLanMan", "jCIFS" );
int vcNumber = 1;
}
class ServerProperties {
return conn;
}
}
+
conn = new SmbTransport( address, port, localAddr, localPort );
connections.addElement( conn );
return conn;
}
soTimeout = Config.getInt( "jcifs.smb.client.soTimeout", DEFAULT_SO_TIMEOUT );
- responseTimeout = Config.getInt( "jcifs.smb.client.responseTimeout",
- DEFAULT_RESPONSE_TIMEOUT );
+ responseTimeout = Config.getInt( "jcifs.smb.client.responseTimeout", DEFAULT_RESPONSE_TIMEOUT );
rcv_buf_size = Config.getInt( "jcifs.smb.client.rcv_buf_size", DEFAULT_RCV_BUF_SIZE );
snd_buf_size = client.maxBufferSize;
sessions = new Vector();
}
synchronized SmbSession getSmbSession() {
- return getSmbSession( null, null, null );
+ return getSmbSession( new NtlmPasswordAuthentication( null, null, null ));
}
- synchronized SmbSession getSmbSession( String username, String password, String domain ) {
- if( username == null ) {
- username = Config.getProperty( "jcifs.smb.client.username", "guest" );
- }
- if( password == null ) {
- password = Config.getProperty( "jcifs.smb.client.password", "" );
- }
- if( domain == null ) {
- domain = Config.getProperty( "jcifs.smb.client.domain", "?" );
- }
+ synchronized SmbSession getSmbSession( NtlmPasswordAuthentication auth ) {
SmbSession ssn;
+
for( Enumeration e = sessions.elements(); e.hasMoreElements(); ) {
ssn = (SmbSession)e.nextElement();
- if( ssn.matches( username, password, domain )) {
+ if( ssn.matches( auth )) {
+ ssn.auth = auth;
return ssn;
}
}
- ssn = new SmbSession( this, username, password, domain );
+ ssn = new SmbSession( this, auth );
+//System.err.println( "SESSION+: " + ssn + "\n " + sessions.toString() );
sessions.addElement( ssn );
return ssn;
}
la1.equals( la2 ) &&
localPort == this.localPort;
}
+ boolean hasCapability( int cap ) throws SmbException {
+ negotiate();
+ return (negotiatedCapabilities & cap) == cap;
+ }
void ensureOpen() throws IOException {
if( socket == null ) {
Object obj;
}
in = new PushbackInputStream( socket.getInputStream(), PUSHBACK_BUF_SIZE );
out = socket.getOutputStream();
- rcv_buf = BufferCache.getBuffer();
- snd_buf = BufferCache.getBuffer();
- thread = new Thread( this );
+ thread = new Thread( this, "JCIFS-SmbTransport" );
thread.setDaemon( true );
thread.start();
}
}
- void tryClose() {
- synchronized( outLock ) {
- if( socket != null ) {
- try {
- for( Enumeration e = sessions.elements(); e.hasMoreElements(); ) {
- ((SmbSession)e.nextElement()).logoff();
- }
- socket.close();
- } catch( IOException ioe ) {
- }
+ void tryClose( boolean inError ) {
+ SmbSession ssn;
+
+ if( socket == null ) {
+ inError = true;
+ }
+ for( Enumeration e = sessions.elements(); e.hasMoreElements(); ) {
+ ssn = (SmbSession)e.nextElement();
+ ssn.logoff( inError );
+ }
+ if( socket != null ) {
+ try {
+ socket.close();
+ } catch( IOException ioe ) {
}
- in = null;
- out = null;
- socket = null;
- negotiated = false;
- thread = null;
- responseTable.clear();
- BufferCache.releaseBuffer( rcv_buf );
- BufferCache.releaseBuffer( snd_buf );
}
+ in = null;
+ out = null;
+ socket = null;
+ negotiated = false;
+ thread = null;
+ responseTable.clear();
}
public void run() {
- int mid, l, b, n;
+ int mid, l, i, n, m;
ServerMessageBlock response;
+ int magic[] = { 0xFF, 'S', 'M', 'B' };
while( thread == Thread.currentThread() ) {
try {
socket.setSoTimeout( soTimeout );
- if(( b = in.read() ) == -1) {
- break;
- }
- if(( b & 0xFF ) != 0xFF ) {
- continue;
+ m = 0;
+ while( m < 4 ) {
+ if(( i = in.read() ) < 0 ) {
+ return;
+ }
+ if(( i & 0xFF ) == magic[m] ) {
+ m++;
+ } else if(( i & 0xFF ) == 0xFF ) {
+ m = 1;
+ } else {
+ m = 0;
+ }
}
+
+synchronized( rcv_buf ) {
rcv_buf[0] = (byte)0xFF;
+ rcv_buf[1] = (byte)'S';
+ rcv_buf[2] = (byte)'M';
+ rcv_buf[3] = (byte)'B';
- if( in.read( rcv_buf, 1, HEADER_LENGTH - 1 ) != HEADER_LENGTH - 1 ) {
+ if( in.read( rcv_buf, 4, HEADER_LENGTH - 4 ) != ( HEADER_LENGTH - 4 )) {
/* Read on a netbios SocketInputStream does not
* return until len bytes have been read or the stream is
* closed. This must be the latter case.
}
synchronized( response ) {
response.useUnicode = useUnicode;
- Log.println( Log.DEBUGGING, "smb debugging",
+ Log.println( Log.WARNINGS, "smb transport warning",
" new data read from socket" );
if( response instanceof SmbComTransactionResponse ) {
} else {
// it's a request(break oplock)
}
+}
} catch( InterruptedIOException iioe ) {
if( responseTable.size() == 0 ) {
- tryClose();
+ tryClose( false );
} else {
Log.println( Log.WARNINGS, "smb warning",
" soTimeout has occured but there are " +
responseTable.size() + " pending requests" );
}
} catch( IOException ioe ) {
- Log.printStackTrace( "exception reading from socket input", ioe );
- tryClose();
+ tryClose( true );
+ Log.printStackTrace( "exception reading from socket input: " + address, ioe );
}
}
}
try {
synchronized( outLock ) {
ensureOpen();
+synchronized( snd_buf ) {
out.write( snd_buf, 0, request.writeWireFormat( snd_buf, 0 ));
out.flush();
Log.printMessageData( "smb andx data", smb );
}
Log.printHexDump( "smb sent", snd_buf, 0, request.length );
+}
}
} catch( IOException ioe ) {
+ tryClose( true );
throw new SmbException( SmbException.ERRCLI, SmbException.ERRioe, ioe.getMessage() );
} finally {
releaseMid( request.mid );
synchronized( outLock ) {
ensureOpen();
+synchronized( snd_buf ) {
out.write( snd_buf, 0, request.writeWireFormat( snd_buf, 0 ));
out.flush();
Log.printMessageData( "smb andx data", smb );
}
Log.printHexDump( "smb sent", snd_buf, 0, request.length );
+}
}
// default it 1 so that 0 can be used as forever
responseTimeout : response.responseTimeout );
}
} catch( InterruptedException ie ) {
+ tryClose( true );
} catch( IOException ioe ) {
+ tryClose( true );
throw new SmbException( SmbException.ERRCLI, SmbException.ERRioe, ioe.getMessage() );
} finally {
responseTable.remove( mid );
}
if( response.received == false ) {
+ tryClose( true );
throw new SmbException( SmbException.ERRCLI,
SmbException.ERRserverTimeout,
address );
response.hasMore = true;
response.isPrimary = true;
- request.txn_buf = BufferCache.getBuffer();
- response.txn_buf = BufferCache.getBuffer();
-
try {
+ request.txn_buf = BufferCache.getBuffer();
+ response.txn_buf = BufferCache.getBuffer();
+
request.nextElement();
if( request.hasMoreElements() ) {
// multi-part request
synchronized( outLock ) {
ensureOpen();
+synchronized(snd_buf) {
out.write( snd_buf, 0, request.writeWireFormat( snd_buf, 0 ));
out.flush();
Log.printMessageData( "smb sent", request );
Log.printHexDump( "smb sent", snd_buf, 0, request.length );
+}
}
interimResponse.wait( responseTimeout );
case SmbException.SUCCESS:
break;
case SmbException.ERRDOS:
- switch(( interimResponse.errorCode >> 16 ) & 0xFFFF ) {
+ switch(( response.errorCode >> 16 ) & 0xFFFF ) {
case SmbException.ERRnoaccess:
- throw new SmbAuthException( interimResponse.errorCode );
+ throw new SmbAuthException( response.errorCode );
}
- throw new SmbException( interimResponse.errorCode );
+ throw new SmbException( response.errorCode );
case SmbException.ERRSRV:
switch(( interimResponse.errorCode >> 16 ) & 0xFFFF ) {
case SmbException.ERRbadpw:
do {
synchronized( outLock ) {
ensureOpen();
+synchronized( snd_buf ) {
out.write( snd_buf, 0, request.writeWireFormat( snd_buf, 0 ));
out.flush();
Log.printMessageData( "smb sent", request );
Log.printHexDump( "smb sent", snd_buf, 0, request.length );
+}
}
} while( request.hasMoreElements() && request.nextElement() != null );
} while( response.received && response.hasMoreElements() );
}
} catch( InterruptedException ie ) {
+ tryClose( true );
} catch( IOException ioe ) {
+ tryClose( true );
throw new SmbException( SmbException.ERRCLI, SmbException.ERRioe, ioe.getMessage() );
} finally {
responseTable.remove( mid );
}
if( response.received == false ) {
+ tryClose( true );
throw new SmbException( SmbException.ERRCLI,
SmbException.ERRserverTimeout,
address );
return;
}
/* we must set this here rather than later because this
- * calls send which calls negotiate so we don't want to
+ * calls send() which calls negotiate so we don't want to
* end up in a loop. The alternative would be to inline
* the send routine here but this seems okay for now
*/
send( new SmbComNegotiate(), response );
if( response.dialectIndex > 10 ) {
+ tryClose( true );
throw new SmbException( SmbException.ERRCLI, SmbException.ERRbadDialect );
}
server.oemDomainName = response.oemDomainName;
}
public String toString() {
- return "SmbTransport[address=" + address +
- ",port=" + socket.getPort() +
+ String ret = "SmbTransport[address=" + address;
+ if( socket == null ) {
+ ret += ",port=,localAddr=,localPort=]";
+ } else {
+ ret += ",port=" + socket.getPort() +
",localAddr=" + socket.getLocalAddress() +
",localPort=" + socket.getLocalPort() + "]";
+ }
+ return ret;
}
static int aquireMid() throws SmbException {
if( tmp.i == i ) {
if( tmp == first ) {
first = first.next;
- }
- if( tmp == last ) {
+ } else if( tmp == last ) {
last = prev;
last.next = null;
+ } else {
+ prev.next = tmp.next;
}
+ return;
}
prev = tmp;
}
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
SmbTree( SmbSession session, String share, String service ) {
this.session = session;
- this.share = share;
+ this.share = share.toUpperCase();
if( service != null && service.startsWith( "??" ) == false ) {
this.service = service;
}
}
boolean matches( String share, String service ) {
- return this.share.equals( share ) &&
+ return this.share.equalsIgnoreCase( share ) &&
( service == null || service.startsWith( "??" ) ||
- this.service.equals( service ));
+ this.service.equalsIgnoreCase( service ));
}
void sendTransaction( SmbComTransaction request,
SmbComTransactionResponse response ) throws SmbException {
// transactions are not batchable
treeConnect( null, null );
+ if( service.equals( "A:" ) == false ) {
+ switch( ((SmbComTransaction)request).subCommand ) {
+ case SmbComTransaction.NET_SHARE_ENUM:
+ case SmbComTransaction.NET_SERVER_ENUM2:
+ case SmbComTransaction.TRANS_PEEK_NAMED_PIPE:
+ case SmbComTransaction.TRANS_WAIT_NAMED_PIPE:
+ case SmbComTransaction.TRANS_CALL_NAMED_PIPE:
+ case SmbComTransaction.TRANS_TRANSACT_NAMED_PIPE:
+ break;
+ default:
+ throw new SmbException( SmbException.ERRCLI, SmbException.ERRioe,
+ "Invalid operation for " + service + " service");
+ }
+ }
request.tid = tid;
session.sendTransaction( request, response );
}
if( request == null || (response != null && response.received )) {
return;
}
+ if( service.equals( "A:" ) == false ) {
+ switch( request.command ) {
+ case ServerMessageBlock.SMB_COM_OPEN_ANDX:
+ case ServerMessageBlock.SMB_COM_NT_CREATE_ANDX:
+ case ServerMessageBlock.SMB_COM_READ_ANDX:
+ case ServerMessageBlock.SMB_COM_WRITE_ANDX:
+ case ServerMessageBlock.SMB_COM_CLOSE:
+ case ServerMessageBlock.SMB_COM_TREE_DISCONNECT:
+ break;
+ default:
+ throw new SmbException( SmbException.ERRCLI, SmbException.ERRioe,
+ "Invalid operation for " + service + " service");
+ }
+ }
request.tid = tid;
session.send( request, response );
}
- synchronized void treeConnect( ServerMessageBlock andx,
+ void treeConnect( ServerMessageBlock andx,
ServerMessageBlock andxResponse ) throws SmbException {
String unc;
+/*
+ * We must lock the session and *then* this tree because there is a small
+ * possibilty that the session could be trying to disconnect the tree at
+ * the same time. In this case it will have the session locked and wait
+ * indefinately trying to acquire the tree which would be locked trying to
+ * aquire the session resulting in deadlock.
+ */
+synchronized( session ) {
+ synchronized( this ) {
if( treeConnected ) {
return;
tid = response.tid;
service = response.service;
treeConnected = true;
+ }
+}
}
- synchronized void treeDisconnect() {
+ synchronized void treeDisconnect( boolean inError ) {
if( treeConnected == false ) {
return;
}
- try {
- send( new SmbComTreeDisconnect(), null );
- } catch( IOException ioe ) {
- Log.printStackTrace( "smb tree disconnect exception", ioe );
- } finally {
- treeConnected = false;
+ if( !inError ) {
+ try {
+ send( new SmbComTreeDisconnect(), null );
+ } catch( SmbException ioe ) {
+ }
}
+ treeConnected = false;
}
public String toString() {
+++ /dev/null
-/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
- *
- * 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.netbios.NbtAddress;
-import jcifs.UniAddress;
-import java.net.MalformedURLException;
-import java.net.UnknownHostException;
-import java.util.Vector;
-import java.util.Enumeration;
-
-final class SmbURL {
-
- static void parseSmbURL( SmbFile file, String url, String name )
- throws MalformedURLException, UnknownHostException {
- parseSmbURL( file, url, name, 4, url.length() );
- }
- static void parseSmbURL( SmbFile file, String url, String name,
- int start, int limit )
- throws MalformedURLException, UnknownHostException {
- int beg, end, c, at, srv, pat;
-
- try {
- if( name != null ) {
- if( name.regionMatches( true, 0, "smb://", 0, 6 )) {
-
- /* If the secondard argument begins with
- * 'smb://' then we simply replace the
- * primary url argument with it and proceed
- * as usuall.
- */
-
- url = name;
- name = null;
- start = 4;
- limit = url.length();
- } else if( url.equalsIgnoreCase( "smb://" )) {
- url = "smb://" + name;
- name = null;
- start = 4;
- limit = url.length();
- }
- }
-
- beg = start + 2;
- end = limit;
- if( end > beg ) {
- while( end > beg && url.charAt( end - 1 ) == '/' ) {
- end--; // trim trailing slashes
- }
- while( beg < end && url.charAt( beg ) != '/' && url.charAt( beg ) != '@' ) {
- 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 );
- type = ((NbtAddress)file.address.getAddress()).getNameType();
- if( type == 0x1d || type == 0x1b ) {
- if( name != null ) {
- url = "smb://" + name;
- name = null;
- start = 4;
- limit = url.length();
- } else {
- file.isWorkgroup = true;
- }
- }
- }
- }
-
- if( url.startsWith( "smb://" ) == false ) {
- throw new MalformedURLException();
- }
-
- /* The java.net.URL parsing model always provides
- * a start point of right after the ':'. So in the
- * case of 'smb://' this would always be position
- * 4. Because smb:// URLs always have 2 following
- * slashes we can just bump-up start by 2 here
- */
-
- start += 2;
- srv = start;
-
- at = url.lastIndexOf( '@' );
- if( at != -1 ) {
- // server right after '@'
- srv = at + 1;
-
- // parse authentication info
- int u = start;
- int i = start;
- for( i = start; i < at; i++ ) {
- c = url.charAt( i );
- if( c == ';' ) {
- file.authInfo.domain = url.substring( start, i );
- u = i + 1;
- } else if( c == ':' ) {
- file.authInfo.password = url.substring( i + 1, at );
- break;
- }
- }
- file.authInfo.username = url.substring( u, i );
- }
-
- file.server = url.substring( srv );
-
- /* For the moment the server variable will
- * contain everything that follows as well for
- * feeding to the canonicalization via make-shift
- * stack routine below. After that, the server,
- * share, path, etc will be isolated.
- */
-
- if( name != null && name.length() != 0 ) {
-
- /* A secondary argument was provided. If
- * it begins with '/' then we replace
- * everything after the server with
- * name. Otherwise we simply concatonate
- * it onto the current path.
- */
-
- if( name.charAt( 0 ) == '/' ) {
- int sha = url.indexOf( '/', srv );
- if( sha < srv ) {
- sha = limit;
- }
- file.server = url.substring( srv, sha );
- if( name.equals( "/" ) == false ) {
- file.server += name;
- }
- } else {
- if( file.server.length() == 0 || file.server.endsWith( "/" )) {
- file.server += name;
- } else {
- file.server = file.server + '/' + name;
- }
- }
- }
- file.url = url.substring( 0, srv ) + file.server;
- limit = file.server.length();
-
- /* The path must preserve all that was provided in
- * the primary url argument and possibly secondary
- * argument such that it could be fed back into the
- * constructor of an SmbURL and the results would
- * be equal.
- */
-
- Vector stk = new Vector();
- String str;
- for( int i = 0, s = 0; i <= limit; i++ ) {
- if( i == limit || file.server.charAt( i ) == '/' ) {
- if( i > s ) {
- str = file.server.substring( s, i );
- if( str.equals( ".." )) {
- if( stk.isEmpty() == false ) {
- stk.removeElementAt( stk.size() - 1 );
- }
- } else if( str.equals( "." )) {
- } else {
- stk.addElement( str );
- }
- }
- s = i + 1;
- }
- }
-
- file.server = null;
- if( stk.isEmpty() == false ) {
- Enumeration e = stk.elements();
- file.server = (String)e.nextElement();
-
- int p = file.server.indexOf( ':' );
- if( p > 0 ) {
- file.port = Integer.parseInt( file.server.substring( p + 1 ));
- file.server = file.server.substring( 0, p );
- }
-
- if( e.hasMoreElements() ) {
- StringBuffer sb = new StringBuffer();
-
- file.share = (String)e.nextElement();
-
- while( e.hasMoreElements() ) {
- sb.append( '/' ).append( e.nextElement() );
- }
-
- if( sb.length() > 0 ) {
- file.canonicalPath = sb.toString();
- }
- }
- }
- } catch( UnknownHostException uhe ) {
- throw uhe;
- } catch( Exception e ) {
- throw new MalformedURLException( url + ", " + name );
- }
- }
-}
-
+++ /dev/null
-/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
- *
- * 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 java.net.URLConnection;
-import java.net.URL;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-/**
- * This class represents a communications link between an application and
- * an SMB resource represented by a {@link java.net.URL}. An object of this type will be
- * returned by the <code>java.net.URL openConnection</code> method when an SMB URL is
- * used. See the {@link jcifs.smb.SmbFile} class for a detailed decription of
- * the smb URL syntax with examples.
- *
- * Before referencing a <code>java.net.URL</code> or code that uses one
- * with SMB URLs, the <code>jcifs.Config</code> class must be loaded. It
- * contains a static initializer that installs the SMB specific protocol
- * handler. If this protocol handler is not loaded the following Exception
- * will occur:
- *
- * <blockquote><pre>
- * java.net.MalformedURLException: unknown protocol: smb
- * </pre></blockquote>
- *
- * It may be loaded by simply using the <code>jcifs.Config</code> class
- * or if for no other reason the following code will do:
- *
- * <blockquote><pre>
- * Class.forName( "jcifs.Config" );
- * </pre></blockquote>
- *
- * In general this class is deficient; it only supports downloading
- * via an <code>InputStream</code>. Adding more functionality is strait
- * forward. If you require more functionality please express your intrest
- * to the jcifs@samba.org mailing list.
- */
-
-public class SmbURLConnection extends URLConnection {
-
- SmbFile f;
-
- SmbURLConnection( URL u, SmbFile f ) {
- super( u );
- this.f = f;
- }
-
-/**
- * Issue the actual socket IO necesary to open a connection with the server
- * hosting the target resource.
- */
-
- public void connect() throws IOException {
- if( connected ) {
- return;
- }
- f.exists();
- }
-
-/**
- * Return the length in bytes of the resource specified by the URL.
- */
-
- public int getContentLength() {
- try {
- return (int)f.length();
- } catch( SmbException se ) {
- }
- return 0;
- }
-
-/**
- * Retrieves the last modified time of the file or directory specified by
- * the URL for this connection.
- */
-
- public long getDate() {
- try {
- return f.lastModified();
- } catch( SmbException se ) {
- }
- return 0L;
- }
-
-/**
- * Retrieves the last modified time of the file or directory specified by
- * the URL for this connection.
- */
-
- public long getLastModified() {
- try {
- return f.lastModified();
- } catch( SmbException se ) {
- }
- return 0L;
- }
-
-/**
- * Create an <code>InputStream</code> from which bytes may be read from
- * the taget specified by the URL of this connection.
- */
-
- public InputStream getInputStream() throws IOException {
- return new SmbFileInputStream( f );
- }
-
-/**
- * Return a String representing this object.
- */
-
- public String toString() {
- return new String( "SmbURLConnection[url=" + f.toString() + "]" );
- }
-}
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
String readString( byte[] src, int srcIndex, int len ) {
String str = null;
- if( useUnicode ) {
- // should Unicode alignment be corrected for here?
- try {
+ try {
+ if( useUnicode ) {
+ // should Unicode alignment be corrected for here?
str = new String( src, srcIndex, len, "UnicodeLittle" );
- } catch( UnsupportedEncodingException uee ) {
- Log.printStackTrace( "smb exception", uee );
+ } else {
+
+ /* On NT without Unicode the fileNameLength
+ * includes the '\0' whereas on win98 it doesn't. I
+ * guess most clients only support non-unicode so
+ * they don't run into this.
+ */
+
+ /* UPDATE: Maybe not! Could this be a Unicode alignment issue. I hope
+ * so. We cannot just comment out this method and use readString of
+ * ServerMessageBlock.java because the arguments are different, however
+ * one might be able to reduce this.
+ */
+
+ if( len > 0 && src[srcIndex + len - 1] == '\0' ) {
+ len--;
+ }
+ str = new String( src, srcIndex, len, ServerMessageBlock.encoding );
}
- } else {
-
- /* On NT without Unicode the fileNameLength
- * includes the '\0' whereas on win98 it doesn't. I
- * guess most clients only support non-unicode so
- * they don't run into this.
- */
-
-/* UPDATE: Maybe not! Could this be a Unicode alignment issue. I hope
- * so. We cannot just comment out this method and use readString of
- * ServerMessageBlock.java because the arguments are different, however
- * one might be able to reduce this.
- */
-
- if( len > 0 && src[srcIndex + len - 1] == '\0' ) {
- len--;
- }
- str = new String( src, srcIndex, len );
+ } catch( UnsupportedEncodingException uee ) {
+ Log.printStackTrace( "smb exception", uee );
}
return str;
}
results[i].nextEntryOffset = readInt4( buffer, bufferIndex );
results[i].fileIndex = readInt4( buffer, bufferIndex + 4 );
- results[i].creationTime = readTime( buffer, bufferIndex + 8 );
- results[i].lastAccessTime = readTime( buffer, bufferIndex + 16 );
+ // results[i].creationTime = readTime( buffer, bufferIndex + 8 );
+ // results[i].lastAccessTime = readTime( buffer, bufferIndex + 16 );
results[i].lastWriteTime = readTime( buffer, bufferIndex + 24 );
- results[i].changeTime = readTime( buffer, bufferIndex + 32 );
+ // results[i].changeTime = readTime( buffer, bufferIndex + 32 );
results[i].endOfFile = readLong( buffer, bufferIndex + 40 );
- results[i].allocationSize = readLong( buffer, bufferIndex + 48 );
+ // results[i].allocationSize = readLong( buffer, bufferIndex + 48 );
results[i].extFileAttributes = readInt4( buffer, bufferIndex + 56 );
results[i].fileNameLength = readInt4( buffer, bufferIndex + 60 );
- results[i].eaSize = readInt4( buffer, bufferIndex + 64 );
- results[i].shortNameLength = buffer[bufferIndex + 68] & 0xFF;
+ // results[i].eaSize = readInt4( buffer, bufferIndex + 64 );
+ // results[i].shortNameLength = buffer[bufferIndex + 68] & 0xFF;
/* With NT, the shortName is in Unicode regardless of what is negotiated.
*/
- results[i].shortName = readString( buffer, bufferIndex + 70,
- results[i].shortNameLength );
+ // results[i].shortName = readString( buffer, bufferIndex + 70,
+ // results[i].shortNameLength );
results[i].filename = readString( buffer, bufferIndex + 94,
results[i].fileNameLength );
if( lastName == null ) {
- Log.println( Log.DEBUGGING, "Trans2FindFirst2/Next2Response debugging",
- "lastName was null!" );
+ Log.println( Log.WARNINGS, "Trans2FindFirst2/Next2Response debugging",
+ "lastName was null" );
}
/* last nextEntryOffset for NT 4(but not 98) is 0 so we must
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
+++ /dev/null
-/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
- *
- * 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;
-
-class Trans2QueryFSInformation extends SmbComTransaction {
-
- int informationLevel;
-
- Trans2QueryFSInformation() {
- command = SMB_COM_TRANSACTION2;
- subCommand = TRANS2_QUERY_FS_INFORMATION;
- informationLevel = Trans2QueryFSInformationResponse.SMB_QUERY_FS_ATTRIBUTE_INFO;
- totalParameterCount = 2;
- totalDataCount = 0;
- maxParameterCount = 0;
- maxDataCount = 800;
- maxSetupCount = 0;
- }
-
- int writeSetupWireFormat( byte[] dst, int dstIndex ) {
- dst[dstIndex++] = subCommand;
- dst[dstIndex++] = (byte)0x00;
- return 2;
- }
- int writeParametersWireFormat( byte[] dst, int dstIndex ) {
- int start = dstIndex;
-
- writeInt2( informationLevel, dst, dstIndex );
- dstIndex += 2;
-
- /* windows98 has what appears to be another 4 0's followed by the share
- * name as a zero terminated ascii string "\TMP" + '\0'
- *
- * As is this works, but it deviates from the spec section 4.1.6.6 but
- * maybe I should put it in. Wonder what NT does?
- */
-
- return dstIndex - start;
- }
- int writeDataWireFormat( byte[] dst, int dstIndex ) {
- return 0;
- }
- int readSetupWireFormat( byte[] buffer, int bufferIndex, int len ) {
- return 0;
- }
- int readParametersWireFormat( byte[] buffer, int bufferIndex, int len ) {
- return 0;
- }
- int readDataWireFormat( byte[] buffer, int bufferIndex, int len ) {
- return 0;
- }
- public String toString() {
- return new String( "Trans2QueryFSInformation[" + super.toString() +
- ",informationLevel=0x" + Log.getHexString( informationLevel, 3 ) + "]" );
- }
-}
--- /dev/null
+/* jcifs smb client library in Java
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
+ *
+ * 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;
+
+class Trans2QueryFSInformation extends SmbComTransaction {
+
+ int informationLevel;
+
+ Trans2QueryFSInformation( int informationLevel ) {
+ command = SMB_COM_TRANSACTION2;
+ subCommand = TRANS2_QUERY_FS_INFORMATION;
+ this.informationLevel = informationLevel;
+ totalParameterCount = 2;
+ totalDataCount = 0;
+ maxParameterCount = 0;
+ maxDataCount = 800;
+ maxSetupCount = 0;
+ }
+
+ int writeSetupWireFormat( byte[] dst, int dstIndex ) {
+ dst[dstIndex++] = subCommand;
+ dst[dstIndex++] = (byte)0x00;
+ return 2;
+ }
+ int writeParametersWireFormat( byte[] dst, int dstIndex ) {
+ int start = dstIndex;
+
+ writeInt2( informationLevel, dst, dstIndex );
+ dstIndex += 2;
+
+ /* windows98 has what appears to be another 4 0's followed by the share
+ * name as a zero terminated ascii string "\TMP" + '\0'
+ *
+ * As is this works, but it deviates from the spec section 4.1.6.6 but
+ * maybe I should put it in. Wonder what NT does?
+ */
+
+ return dstIndex - start;
+ }
+ int writeDataWireFormat( byte[] dst, int dstIndex ) {
+ return 0;
+ }
+ int readSetupWireFormat( byte[] buffer, int bufferIndex, int len ) {
+ return 0;
+ }
+ int readParametersWireFormat( byte[] buffer, int bufferIndex, int len ) {
+ return 0;
+ }
+ int readDataWireFormat( byte[] buffer, int bufferIndex, int len ) {
+ return 0;
+ }
+ public String toString() {
+ return new String( "Trans2QueryFSInformation[" + super.toString() +
+ ",informationLevel=0x" + Log.getHexString( informationLevel, 3 ) + "]" );
+ }
+}
+++ /dev/null
-/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
- *
- * 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 java.io.UnsupportedEncodingException;
-
-class Trans2QueryFSInformationResponse extends SmbComTransactionResponse {
-
- // information levels
- static final int SMB_QUERY_FS_ATTRIBUTE_INFO = 0x105;
-
- class SmbQueryFSAttributeInfo implements Info {
- int attributes;
- int maxNameLength;
- String name;
-
- public int getAttributes() {
- return attributes;
- }
- public long getLastWriteTime() {
- return 0;
- }
- public long getSize() {
- return 0;
- }
- public String toString() {
- return new String( "SmbQueryFSAttributeInfo[" +
- "attributes=0x" + Log.getHexString( attributes, 4 ) +
- ",maxNameLength=" + maxNameLength +
- ",name=" + name + "]" );
- }
- }
-
- Info info;
-
- Trans2QueryFSInformationResponse() {
- command = SMB_COM_TRANSACTION2;
- subCommand = SmbComTransaction.TRANS2_QUERY_FS_INFORMATION;
- }
-
- int writeSetupWireFormat( byte[] dst, int dstIndex ) {
- return 0;
- }
- int writeParametersWireFormat( byte[] dst, int dstIndex ) {
- return 0;
- }
- int writeDataWireFormat( byte[] dst, int dstIndex ) {
- return 0;
- }
- int readSetupWireFormat( byte[] buffer, int bufferIndex, int len ) {
- return 0;
- }
- int readParametersWireFormat( byte[] buffer, int bufferIndex, int len ) {
- return 0;
- }
- int readDataWireFormat( byte[] buffer, int bufferIndex, int len ) {
- int start = bufferIndex;
-
- SmbQueryFSAttributeInfo info = new SmbQueryFSAttributeInfo();
- info.attributes = readInt4( buffer, bufferIndex );
- bufferIndex += 4;
- info.maxNameLength = readInt2( buffer, bufferIndex );
- bufferIndex += 4;
- int nameLength = readInt2( buffer, bufferIndex );
- bufferIndex += 4;
- try {
- info.name = new String( buffer, bufferIndex, nameLength, "UnicodeLittle" );
- } catch( UnsupportedEncodingException uee ) {
- Log.printStackTrace( "", uee );
- }
- bufferIndex += nameLength;
- this.info = info;
-
- return bufferIndex - start;
- }
- public String toString() {
- return new String( "Trans2QueryFSInformationResponse[" +
- super.toString() + "]" );
- }
-}
--- /dev/null
+/* jcifs smb client library in Java
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
+ *
+ * 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 java.io.UnsupportedEncodingException;
+
+class Trans2QueryFSInformationResponse extends SmbComTransactionResponse {
+
+ // information levels
+ static final int SMB_INFO_ALLOCATION = 1;
+ static final int SMB_QUERY_FS_SIZE_INFO = 0x103;
+
+ class SmbInfoAllocation implements AllocInfo {
+ long alloc; // Also handles SmbQueryFSSizeInfo
+ long free;
+ int sectPerAlloc;
+ int bytesPerSect;
+
+ public long getCapacity() {
+ return alloc * sectPerAlloc * bytesPerSect;
+ }
+ public long getFree() {
+ return free * sectPerAlloc * bytesPerSect;
+ }
+ public String toString() {
+ return new String( "SmbInfoAllocation[" +
+ "alloc=" + alloc + ",free=" + free +
+ ",sectPerAlloc=" + sectPerAlloc +
+ ",bytesPerSect=" + bytesPerSect + "]" );
+ }
+ }
+
+ int informationLevel;
+ AllocInfo info;
+
+ Trans2QueryFSInformationResponse( int informationLevel ) {
+ this.informationLevel = informationLevel;
+ command = SMB_COM_TRANSACTION2;
+ subCommand = SmbComTransaction.TRANS2_QUERY_FS_INFORMATION;
+ }
+
+ int writeSetupWireFormat( byte[] dst, int dstIndex ) {
+ return 0;
+ }
+ int writeParametersWireFormat( byte[] dst, int dstIndex ) {
+ return 0;
+ }
+ int writeDataWireFormat( byte[] dst, int dstIndex ) {
+ return 0;
+ }
+ int readSetupWireFormat( byte[] buffer, int bufferIndex, int len ) {
+ return 0;
+ }
+ int readParametersWireFormat( byte[] buffer, int bufferIndex, int len ) {
+ return 0;
+ }
+ int readDataWireFormat( byte[] buffer, int bufferIndex, int len ) {
+ switch( informationLevel ) {
+ case SMB_INFO_ALLOCATION:
+ return readSmbInfoAllocationWireFormat( buffer, bufferIndex );
+ case SMB_QUERY_FS_SIZE_INFO:
+ return readSmbQueryFSSizeInfoWireFormat( buffer, bufferIndex );
+ default:
+ return 0;
+ }
+ }
+
+ int readSmbInfoAllocationWireFormat( byte[] buffer, int bufferIndex ) {
+ int start = bufferIndex;
+
+ SmbInfoAllocation info = new SmbInfoAllocation();
+
+ bufferIndex += 4; // skip idFileSystem
+
+ info.sectPerAlloc = readInt4( buffer, bufferIndex );
+ bufferIndex += 4;
+
+ info.alloc = readInt4( buffer, bufferIndex );
+ bufferIndex += 4;
+
+ info.free = readInt4( buffer, bufferIndex );
+ bufferIndex += 4;
+
+ info.bytesPerSect = readInt2( buffer, bufferIndex );
+ bufferIndex += 4;
+
+ this.info = info;
+
+ return bufferIndex - start;
+ }
+ int readSmbQueryFSSizeInfoWireFormat( byte[] buffer, int bufferIndex ) {
+ int start = bufferIndex;
+
+ SmbInfoAllocation info = new SmbInfoAllocation();
+
+ info.alloc = readInt4( buffer, bufferIndex );
+ bufferIndex += 4;
+ info.alloc |= readInt4( buffer, bufferIndex ) << 32L;
+ bufferIndex += 4;
+
+ info.free = readInt4( buffer, bufferIndex );
+ bufferIndex += 4;
+ info.free |= readInt4( buffer, bufferIndex ) << 32L;
+ bufferIndex += 4;
+
+ info.sectPerAlloc = readInt4( buffer, bufferIndex );
+ bufferIndex += 4;
+
+ info.bytesPerSect = readInt4( buffer, bufferIndex );
+ bufferIndex += 4;
+
+ this.info = info;
+
+ return bufferIndex - start;
+ }
+ public String toString() {
+ return new String( "Trans2QueryFSInformationResponse[" +
+ super.toString() + "]" );
+ }
+}
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
--- /dev/null
+/* jcifs smb client library in Java
+ * Copyright (C) 2002 "Michael B. Allen" <jcifs at samba dot org>
+ *
+ * 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;
+
+class TransPeekNamedPipe extends SmbComTransaction {
+
+ int fid;
+
+ TransPeekNamedPipe( String pipeName, int fid ) {
+ name = pipeName;
+ this.fid = fid;
+ command = SMB_COM_TRANSACTION;
+ subCommand = TRANS_PEEK_NAMED_PIPE;
+ timeout = 0xFFFFFFFF;
+ maxParameterCount = 6;
+ maxDataCount = 1;
+ maxSetupCount = (byte)0x00;
+ setupCount = 2;
+ }
+
+ int writeSetupWireFormat( byte[] dst, int dstIndex ) {
+ dst[dstIndex++] = subCommand;
+ dst[dstIndex++] = (byte)0x00;
+ // this says "Transaction priority" in netmon
+ writeInt2( fid, dst, dstIndex );
+ return 4;
+ }
+ int readSetupWireFormat( byte[] buffer, int bufferIndex, int len ) {
+ return 0;
+ }
+ int writeParametersWireFormat( byte[] dst, int dstIndex ) {
+ return 0;
+ }
+ int writeDataWireFormat( byte[] dst, int dstIndex ) {
+ return 0;
+ }
+ int readParametersWireFormat( byte[] buffer, int bufferIndex, int len ) {
+ return 0;
+ }
+ int readDataWireFormat( byte[] buffer, int bufferIndex, int len ) {
+ return 0;
+ }
+ public String toString() {
+ return new String( "TransPeekNamedPipe[" + super.toString() +
+ ",pipeName=" + name + "]" );
+ }
+}
--- /dev/null
+/* jcifs smb client library in Java
+ * Copyright (C) 2002 "Michael B. Allen" <jcifs at samba dot org>
+ *
+ * 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;
+
+class TransPeekNamedPipeResponse extends SmbComTransactionResponse {
+
+ static final int STATUS_DISCONNECTED = 1;
+ static final int STATUS_LISTENING = 2;
+ static final int STATUS_CONNECTION_OK = 3;
+ static final int STATUS_SERVER_END_CLOSED = 4;
+
+ SmbNamedPipe pipe;
+ int available, head, status;
+
+ TransPeekNamedPipeResponse( SmbNamedPipe pipe ) {
+ this.pipe = pipe;
+ }
+
+ int writeSetupWireFormat( byte[] dst, int dstIndex ) {
+ return 0;
+ }
+ int writeParametersWireFormat( byte[] dst, int dstIndex ) {
+ return 0;
+ }
+ int writeDataWireFormat( byte[] dst, int dstIndex ) {
+ return 0;
+ }
+ int readSetupWireFormat( byte[] buffer, int bufferIndex, int len ) {
+ return 0;
+ }
+ int readParametersWireFormat( byte[] buffer, int bufferIndex, int len ) {
+ available = readInt2( buffer, bufferIndex ); bufferIndex += 2;
+ head = readInt2( buffer, bufferIndex ); bufferIndex += 2;
+ status = readInt2( buffer, bufferIndex );
+ return 6;
+ }
+ int readDataWireFormat( byte[] buffer, int bufferIndex, int len ) {
+ return 0;
+ }
+ public String toString() {
+ return new String( "TransPeekNamedPipeResponse[" + super.toString() + "]" );
+ }
+}
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
static final int INIT_PIPE_SIZE = 4096;
+ SmbNamedPipe pipe;
byte[] pipe_buf = new byte[INIT_PIPE_SIZE];
int beg_idx, nxt_idx, used;
Object lock;
- TransactNamedPipeInputStream() {
+ TransactNamedPipeInputStream( SmbNamedPipe pipe ) {
+ this.pipe = pipe;
lock = new Object();
}
public void close() throws IOException {
+ pipe.close();
}
public int read() throws IOException {
int result = -1;
if( used > i && result > i ) {
System.arraycopy( pipe_buf, beg_idx, b, off, i );
off += i;
- System.arraycopy( pipe_buf, 0, b, off, result );
+ System.arraycopy( pipe_buf, 0, b, off, result - i );
} else {
System.arraycopy( pipe_buf, beg_idx, b, off, result );
}
}
return result;
}
-
+ public int available() throws IOException {
+ Log.println( Log.WARNINGS, "Named Pipe warning",
+ "available does not apply to TRANSACT Named Pipes" );
+ return 0;
+ }
int receive( byte[] b, int off, int len ) {
int i;
}
tmp = pipe_buf;
pipe_buf = new byte[new_size];
- i = pipe_buf.length - beg_idx;
+ i = tmp.length - beg_idx;
if( used > i ) {
System.arraycopy( tmp, beg_idx, pipe_buf, 0, i );
System.arraycopy( tmp, 0, pipe_buf, i, used - i );
+ nxt_idx = used;
} else {
System.arraycopy( tmp, beg_idx, pipe_buf, 0, used );
}
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
TransactNamedPipeOutputStream( SmbNamedPipe pipe ) throws IOException {
this.pipe = pipe;
- path = pipe.uncPath;
+ path = pipe.unc;
}
public void close() throws IOException {
+ pipe.close();
}
public void write( int b ) throws IOException {
tmp[0] = (byte)b;
if(( pipe.pipeType & SmbNamedPipe.PIPE_TYPE_CALL ) ==
SmbNamedPipe.PIPE_TYPE_CALL ) {
- pipe.tree.sendTransaction( new TransWaitNamedPipe( path ),
+ pipe.sendTransaction( new TransWaitNamedPipe( path ),
new TransWaitNamedPipeResponse() );
- pipe.tree.sendTransaction( new TransCallNamedPipe( path, b, off, len ),
+ pipe.sendTransaction( new TransCallNamedPipe( path, b, off, len ),
new TransCallNamedPipeResponse( pipe ));
} else if(( pipe.pipeType & SmbNamedPipe.PIPE_TYPE_TRANSACT ) ==
SmbNamedPipe.PIPE_TYPE_TRANSACT ) {
pipe.open(( pipe.pipeType & 0xFF0000 ) | SmbFile.O_EXCL );
- pipe.tree.sendTransaction( new TransTransactNamedPipe( pipe.fid, b, off, len ),
+ pipe.sendTransaction( new TransTransactNamedPipe( pipe.fid, b, off, len ),
new TransTransactNamedPipeResponse( pipe ));
}
}
+++ /dev/null
-/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
- *
- * 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 {
-
- public boolean authenticate( AuthInfo auth );
-}
+++ /dev/null
-/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
- *
- * 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 {
-
- public String target;
- public String domain;
- public String username;
- public String password;
- public Exception exception;
-}
--- /dev/null
+package jcifs.util;\r
+\r
+import java.io.UnsupportedEncodingException;\r
+\r
+/**\r
+ * Encodes and decodes to and from Base64 notation.\r
+ *\r
+ * <p>\r
+ * Change Log:\r
+ * </p>\r
+ * <ul>\r
+ * <li>Trimmed object and stream releated methods for inclusion into jcifs.util package.\r
+ * <li>v1.3.5 - Added flag to turn on and off line breaks. Fixed bug in input stream\r
+ * where last buffer being read, if not completely full, was not returned.</li>\r
+ * <li>v1.3.4 - Fixed when "improperly padded stream" error was thrown at the wrong time.</li>\r
+ * <li>v1.3.3 - Fixed I/O streams which were totally messed up.</li>\r
+ * </ul>\r
+ *\r
+ * <p>\r
+ * I am placing this code in the Public Domain. Do with it as you will.\r
+ * This software comes with no guarantees or warranties but with\r
+ * plenty of well-wishing instead!\r
+ * Please visit <a href="http://iharder.net/xmlizable">http://iharder.net/xmlizable</a>\r
+ * periodically to check for updates or to contribute improvements.\r
+ * </p>\r
+ *\r
+ * @author Robert Harder\r
+ * @author rob@iharder.net\r
+ * @version 1.3.4\r
+ */\r
+public class Base64\r
+{\r
+ \r
+ /** Specify encoding (value is <tt>true</tt>). */\r
+ public final static boolean ENCODE = true;\r
+ \r
+ \r
+ /** Specify decoding (value is <tt>false</tt>). */\r
+ public final static boolean DECODE = false;\r
+ \r
+ \r
+ /** Maximum line length (76) of Base64 output. */\r
+ private final static int MAX_LINE_LENGTH = 76;\r
+ \r
+ \r
+ /** The equals sign (=) as a byte. */\r
+ private final static byte EQUALS_SIGN = (byte)'=';\r
+ \r
+ \r
+ /** The new line character (\n) as a byte. */\r
+ private final static byte NEW_LINE = (byte)'\n';\r
+ \r
+ \r
+ /** The 64 valid Base64 values. */\r
+ private final static byte[] ALPHABET =\r
+ {\r
+ (byte)'A', (byte)'B', (byte)'C', (byte)'D', (byte)'E', (byte)'F', (byte)'G',\r
+ (byte)'H', (byte)'I', (byte)'J', (byte)'K', (byte)'L', (byte)'M', (byte)'N',\r
+ (byte)'O', (byte)'P', (byte)'Q', (byte)'R', (byte)'S', (byte)'T', (byte)'U', \r
+ (byte)'V', (byte)'W', (byte)'X', (byte)'Y', (byte)'Z',\r
+ (byte)'a', (byte)'b', (byte)'c', (byte)'d', (byte)'e', (byte)'f', (byte)'g',\r
+ (byte)'h', (byte)'i', (byte)'j', (byte)'k', (byte)'l', (byte)'m', (byte)'n',\r
+ (byte)'o', (byte)'p', (byte)'q', (byte)'r', (byte)'s', (byte)'t', (byte)'u', \r
+ (byte)'v', (byte)'w', (byte)'x', (byte)'y', (byte)'z',\r
+ (byte)'0', (byte)'1', (byte)'2', (byte)'3', (byte)'4', (byte)'5', \r
+ (byte)'6', (byte)'7', (byte)'8', (byte)'9', (byte)'+', (byte)'/'\r
+ };\r
+ \r
+ /** \r
+ * Translates a Base64 value to either its 6-bit reconstruction value\r
+ * or a negative number indicating some other meaning.\r
+ **/\r
+ private final static byte[] DECODABET =\r
+ { \r
+ -9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 0 - 8\r
+ -5,-5, // Whitespace: Tab and Linefeed\r
+ -9,-9, // Decimal 11 - 12\r
+ -5, // Whitespace: Carriage Return\r
+ -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 14 - 26\r
+ -9,-9,-9,-9,-9, // Decimal 27 - 31\r
+ -5, // Whitespace: Space\r
+ -9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 33 - 42\r
+ 62, // Plus sign at decimal 43\r
+ -9,-9,-9, // Decimal 44 - 46\r
+ 63, // Slash at decimal 47\r
+ 52,53,54,55,56,57,58,59,60,61, // Numbers zero through nine\r
+ -9,-9,-9, // Decimal 58 - 60\r
+ -1, // Equals sign at decimal 61\r
+ -9,-9,-9, // Decimal 62 - 64\r
+ 0,1,2,3,4,5,6,7,8,9,10,11,12,13, // Letters 'A' through 'N'\r
+ 14,15,16,17,18,19,20,21,22,23,24,25, // Letters 'O' through 'Z'\r
+ -9,-9,-9,-9,-9,-9, // Decimal 91 - 96\r
+ 26,27,28,29,30,31,32,33,34,35,36,37,38, // Letters 'a' through 'm'\r
+ 39,40,41,42,43,44,45,46,47,48,49,50,51, // Letters 'n' through 'z'\r
+ -9,-9,-9,-9 // Decimal 123 - 126\r
+ /*,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 127 - 139\r
+ -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 140 - 152\r
+ -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 153 - 165\r
+ -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 166 - 178\r
+ -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 179 - 191\r
+ -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 192 - 204\r
+ -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 205 - 217\r
+ -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 218 - 230\r
+ -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9, // Decimal 231 - 243\r
+ -9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9,-9 // Decimal 244 - 255 */\r
+ };\r
+ \r
+ private final static byte BAD_ENCODING = -9; // Indicates error in encoding\r
+ private final static byte WHITE_SPACE_ENC = -5; // Indicates white space in encoding\r
+ private final static byte EQUALS_SIGN_ENC = -1; // Indicates equals sign in encoding\r
+\r
+ \r
+ /** Defeats instantiation. */\r
+ private Base64(){}\r
+ \r
+/* ******** E N C O D I N G M E T H O D S ******** */ \r
+ \r
+ \r
+ /**\r
+ * Encodes the first three bytes of array <var>threeBytes</var>\r
+ * and returns a four-byte array in Base64 notation.\r
+ *\r
+ * @param threeBytes the array to convert\r
+ * @return four byte array in Base64 notation.\r
+ * @since 1.3\r
+ */\r
+ private static byte[] encode3to4( byte[] threeBytes )\r
+ { return encode3to4( threeBytes, 3 );\r
+ } // end encodeToBytes\r
+ \r
+ \r
+ \r
+ /**\r
+ * Encodes up to the first three bytes of array <var>threeBytes</var>\r
+ * and returns a four-byte array in Base64 notation.\r
+ * The actual number of significant bytes in your array is\r
+ * given by <var>numSigBytes</var>.\r
+ * The array <var>threeBytes</var> needs only be as big as\r
+ * <var>numSigBytes</var>.\r
+ *\r
+ * @param threeBytes the array to convert\r
+ * @param numSigBytes the number of significant bytes in your array\r
+ * @return four byte array in Base64 notation.\r
+ * @since 1.3\r
+ */\r
+ private static byte[] encode3to4( byte[] threeBytes, int numSigBytes )\r
+ { byte[] dest = new byte[4];\r
+ encode3to4( threeBytes, 0, numSigBytes, dest, 0 );\r
+ return dest;\r
+ }\r
+ \r
+ \r
+ \r
+ /**\r
+ * Encodes up to three bytes of the array <var>source</var>\r
+ * and writes the resulting four Base64 bytes to <var>destination</var>.\r
+ * The source and destination arrays can be manipulated\r
+ * anywhere along their length by specifying \r
+ * <var>srcOffset</var> and <var>destOffset</var>.\r
+ * This method does not check to make sure your arrays\r
+ * are large enough to accomodate <var>srcOffset</var> + 3 for\r
+ * the <var>source</var> array or <var>destOffset</var> + 4 for\r
+ * the <var>destination</var> array.\r
+ * The actual number of significant bytes in your array is\r
+ * given by <var>numSigBytes</var>.\r
+ *\r
+ * @param source the array to convert\r
+ * @param srcOffset the index where conversion begins\r
+ * @param numSigBytes the number of significant bytes in your array\r
+ * @param destination the array to hold the conversion\r
+ * @param destOffset the index where output will be put\r
+ * @return the <var>destination</var> array\r
+ * @since 1.3\r
+ */\r
+ private static byte[] encode3to4( \r
+ byte[] source, int srcOffset, int numSigBytes,\r
+ byte[] destination, int destOffset )\r
+ {\r
+ // 1 2 3 \r
+ // 01234567890123456789012345678901 Bit position\r
+ // --------000000001111111122222222 Array position from threeBytes\r
+ // --------| || || || | Six bit groups to index ALPHABET\r
+ // >>18 >>12 >> 6 >> 0 Right shift necessary\r
+ // 0x3f 0x3f 0x3f Additional AND\r
+ \r
+ // Create buffer with zero-padding if there are only one or two\r
+ // significant bytes passed in the array.\r
+ // We have to shift left 24 in order to flush out the 1's that appear\r
+ // when Java treats a value as negative that is cast from a byte to an int.\r
+ int inBuff = ( numSigBytes > 0 ? ((source[ srcOffset ] << 24) >>> 8) : 0 )\r
+ | ( numSigBytes > 1 ? ((source[ srcOffset + 1 ] << 24) >>> 16) : 0 )\r
+ | ( numSigBytes > 2 ? ((source[ srcOffset + 2 ] << 24) >>> 24) : 0 );\r
+\r
+ switch( numSigBytes )\r
+ {\r
+ case 3:\r
+ destination[ destOffset ] = ALPHABET[ (inBuff >>> 18) ];\r
+ destination[ destOffset + 1 ] = ALPHABET[ (inBuff >>> 12) & 0x3f ];\r
+ destination[ destOffset + 2 ] = ALPHABET[ (inBuff >>> 6) & 0x3f ];\r
+ destination[ destOffset + 3 ] = ALPHABET[ (inBuff ) & 0x3f ];\r
+ return destination;\r
+ \r
+ case 2:\r
+ destination[ destOffset ] = ALPHABET[ (inBuff >>> 18) ];\r
+ destination[ destOffset + 1 ] = ALPHABET[ (inBuff >>> 12) & 0x3f ];\r
+ destination[ destOffset + 2 ] = ALPHABET[ (inBuff >>> 6) & 0x3f ];\r
+ destination[ destOffset + 3 ] = EQUALS_SIGN;\r
+ return destination;\r
+ \r
+ case 1:\r
+ destination[ destOffset ] = ALPHABET[ (inBuff >>> 18) ];\r
+ destination[ destOffset + 1 ] = ALPHABET[ (inBuff >>> 12) & 0x3f ];\r
+ destination[ destOffset + 2 ] = EQUALS_SIGN;\r
+ destination[ destOffset + 3 ] = EQUALS_SIGN;\r
+ return destination;\r
+ \r
+ default:\r
+ return destination;\r
+ } // end switch\r
+ } // end encode3to4\r
+ \r
+ /**\r
+ * Encodes a byte array into Base64 notation.\r
+ * Equivalen to calling\r
+ * <code>encodeBytes( source, 0, source.length )</code>\r
+ *\r
+ * @param source The data to convert\r
+ * @since 1.4\r
+ */\r
+ public static String encodeBytes( byte[] source )\r
+ {\r
+ return encodeBytes( source, true );\r
+ } // end encodeBytes\r
+ \r
+ /**\r
+ * Encodes a byte array into Base64 notation.\r
+ * Equivalen to calling\r
+ * <code>encodeBytes( source, 0, source.length )</code>\r
+ *\r
+ * @param source The data to convert\r
+ * @param breakLines Break lines at 80 characters or less.\r
+ * @since 1.4\r
+ */\r
+ public static String encodeBytes( byte[] source, boolean breakLines )\r
+ { \r
+ return encodeBytes( source, 0, source.length, breakLines );\r
+ } // end encodeBytes\r
+ \r
+ \r
+ /**\r
+ * Encodes a byte array into Base64 notation.\r
+ *\r
+ * @param source The data to convert\r
+ * @param off Offset in array where conversion should begin\r
+ * @param len Length of data to convert\r
+ * @since 1.4\r
+ */\r
+ public static String encodeBytes( byte[] source, int off, int len )\r
+ {\r
+ return encodeBytes( source, off, len, true );\r
+ } // end encodeBytes\r
+ \r
+ \r
+ /**\r
+ * Encodes a byte array into Base64 notation.\r
+ *\r
+ * @param source The data to convert\r
+ * @param off Offset in array where conversion should begin\r
+ * @param len Length of data to convert\r
+ * @param breakLines Break lines at 80 characters or less.\r
+ * @since 1.4\r
+ */\r
+ public static String encodeBytes( byte[] source, int off, int len, boolean breakLines )\r
+ {\r
+ int len43 = len * 4 / 3;\r
+ byte[] outBuff = new byte[ ( len43 ) // Main 4:3\r
+ + ( (len % 3) > 0 ? 4 : 0 ) // Account for padding\r
+ + (breakLines ? ( len43 / MAX_LINE_LENGTH ) : 0) ]; // New lines \r
+ int d = 0;\r
+ int e = 0;\r
+ int len2 = len - 2;\r
+ int lineLength = 0;\r
+ for( ; d < len2; d+=3, e+=4 )\r
+ {\r
+ encode3to4( source, d+off, 3, outBuff, e );\r
+ \r
+ lineLength += 4;\r
+ if( breakLines && lineLength == MAX_LINE_LENGTH )\r
+ { \r
+ outBuff[e+4] = NEW_LINE;\r
+ e++;\r
+ lineLength = 0;\r
+ } // end if: end of line\r
+ } // en dfor: each piece of array\r
+ \r
+ if( d < len )\r
+ {\r
+ encode3to4( source, d+off, len - d, outBuff, e );\r
+ e += 4;\r
+ } // end if: some padding needed\r
+ \r
+ try {\r
+ return new String( outBuff, 0, e, "ASCII" );\r
+ } catch( UnsupportedEncodingException uee ) {\r
+ }\r
+ return null;\r
+ } // end encodeBytes\r
+ \r
+ \r
+ /**\r
+ * Encodes a string in Base64 notation with line breaks\r
+ * after every 75 Base64 characters.\r
+ *\r
+ * @param s the string to encode\r
+ * @return the encoded string\r
+ * @since 1.3\r
+ */\r
+ public static String encodeString( String s )\r
+ {\r
+ return encodeString( s, true );\r
+ } // end encodeString\r
+ \r
+ /**\r
+ * Encodes a string in Base64 notation with line breaks\r
+ * after every 75 Base64 characters.\r
+ *\r
+ * @param s the string to encode\r
+ * @param breakLines Break lines at 80 characters or less.\r
+ * @return the encoded string\r
+ * @since 1.3\r
+ */\r
+ public static String encodeString( String s, boolean breakLines )\r
+ { \r
+ try {\r
+ return encodeBytes( s.getBytes( "ASCII" ), breakLines );\r
+ } catch( UnsupportedEncodingException uee ) {\r
+ }\r
+ return null;\r
+ } // end encodeString\r
+ \r
+ \r
+ \r
+ \r
+/* ******** D E C O D I N G M E T H O D S ******** */\r
+ \r
+ \r
+ /**\r
+ * Decodes the first four bytes of array <var>fourBytes</var>\r
+ * and returns an array up to three bytes long with the\r
+ * decoded values.\r
+ *\r
+ * @param fourBytes the array with Base64 content\r
+ * @return array with decoded values\r
+ * @since 1.3\r
+ */\r
+ private static byte[] decode4to3( byte[] fourBytes )\r
+ {\r
+ byte[] outBuff1 = new byte[3];\r
+ int count = decode4to3( fourBytes, 0, outBuff1, 0 );\r
+ byte[] outBuff2 = new byte[ count ];\r
+ \r
+ for( int i = 0; i < count; i++ )\r
+ outBuff2[i] = outBuff1[i];\r
+ \r
+ return outBuff2;\r
+ }\r
+ \r
+ \r
+ \r
+ \r
+ /**\r
+ * Decodes four bytes from array <var>source</var>\r
+ * and writes the resulting bytes (up to three of them)\r
+ * to <var>destination</var>.\r
+ * The source and destination arrays can be manipulated\r
+ * anywhere along their length by specifying \r
+ * <var>srcOffset</var> and <var>destOffset</var>.\r
+ * This method does not check to make sure your arrays\r
+ * are large enough to accomodate <var>srcOffset</var> + 4 for\r
+ * the <var>source</var> array or <var>destOffset</var> + 3 for\r
+ * the <var>destination</var> array.\r
+ * This method returns the actual number of bytes that \r
+ * were converted from the Base64 encoding.\r
+ * \r
+ *\r
+ * @param source the array to convert\r
+ * @param srcOffset the index where conversion begins\r
+ * @param destination the array to hold the conversion\r
+ * @param destOffset the index where output will be put\r
+ * @return the number of decoded bytes converted\r
+ * @since 1.3\r
+ */\r
+ private static int decode4to3( byte[] source, int srcOffset, byte[] destination, int destOffset )\r
+ {\r
+ // Example: Dk==\r
+ if( source[ srcOffset + 2] == EQUALS_SIGN )\r
+ {\r
+ // Two ways to do the same thing. Don't know which way I like best.\r
+ //int outBuff = ( ( DECODABET[ source[ srcOffset ] ] << 24 ) >>> 6 )\r
+ // | ( ( DECODABET[ source[ srcOffset + 1] ] << 24 ) >>> 12 );\r
+ int outBuff = ( ( DECODABET[ source[ srcOffset ] ] & 0xFF ) << 18 )\r
+ | ( ( DECODABET[ source[ srcOffset + 1] ] & 0xFF ) << 12 );\r
+ \r
+ destination[ destOffset ] = (byte)( outBuff >>> 16 );\r
+ return 1;\r
+ }\r
+ \r
+ // Example: DkL=\r
+ else if( source[ srcOffset + 3 ] == EQUALS_SIGN )\r
+ {\r
+ // Two ways to do the same thing. Don't know which way I like best.\r
+ //int outBuff = ( ( DECODABET[ source[ srcOffset ] ] << 24 ) >>> 6 )\r
+ // | ( ( DECODABET[ source[ srcOffset + 1 ] ] << 24 ) >>> 12 )\r
+ // | ( ( DECODABET[ source[ srcOffset + 2 ] ] << 24 ) >>> 18 );\r
+ int outBuff = ( ( DECODABET[ source[ srcOffset ] ] & 0xFF ) << 18 )\r
+ | ( ( DECODABET[ source[ srcOffset + 1 ] ] & 0xFF ) << 12 )\r
+ | ( ( DECODABET[ source[ srcOffset + 2 ] ] & 0xFF ) << 6 );\r
+ \r
+ destination[ destOffset ] = (byte)( outBuff >>> 16 );\r
+ destination[ destOffset + 1 ] = (byte)( outBuff >>> 8 );\r
+ return 2;\r
+ }\r
+ \r
+ // Example: DkLE\r
+ else\r
+ {\r
+ try{\r
+ // Two ways to do the same thing. Don't know which way I like best.\r
+ //int outBuff = ( ( DECODABET[ source[ srcOffset ] ] << 24 ) >>> 6 )\r
+ // | ( ( DECODABET[ source[ srcOffset + 1 ] ] << 24 ) >>> 12 )\r
+ // | ( ( DECODABET[ source[ srcOffset + 2 ] ] << 24 ) >>> 18 )\r
+ // | ( ( DECODABET[ source[ srcOffset + 3 ] ] << 24 ) >>> 24 );\r
+ int outBuff = ( ( DECODABET[ source[ srcOffset ] ] & 0xFF ) << 18 )\r
+ | ( ( DECODABET[ source[ srcOffset + 1 ] ] & 0xFF ) << 12 )\r
+ | ( ( DECODABET[ source[ srcOffset + 2 ] ] & 0xFF ) << 6)\r
+ | ( ( DECODABET[ source[ srcOffset + 3 ] ] & 0xFF ) );\r
+\r
+ \r
+ destination[ destOffset ] = (byte)( outBuff >> 16 );\r
+ destination[ destOffset + 1 ] = (byte)( outBuff >> 8 );\r
+ destination[ destOffset + 2 ] = (byte)( outBuff );\r
+\r
+ return 3;\r
+ }catch( Exception e){\r
+ jcifs.util.Log.println( jcifs.util.Log.WARNINGS, "Base64", ""+source[srcOffset]+ ": " + ( DECODABET[ source[ srcOffset ] ] ) );\r
+ jcifs.util.Log.println( jcifs.util.Log.WARNINGS, "Base64", ""+source[srcOffset+1]+ ": " + ( DECODABET[ source[ srcOffset + 1 ] ] ) );\r
+ jcifs.util.Log.println( jcifs.util.Log.WARNINGS, "Base64", ""+source[srcOffset+2]+ ": " + ( DECODABET[ source[ srcOffset + 2 ] ] ) );\r
+ jcifs.util.Log.println( jcifs.util.Log.WARNINGS, "Base64", ""+source[srcOffset+3]+ ": " + ( DECODABET[ source[ srcOffset + 3 ] ] ) );\r
+ return -1;\r
+ } //e nd catch\r
+ }\r
+ } // end decodeToBytes\r
+ \r
+ \r
+ \r
+ /**\r
+ * Decodes data from Base64 notation.\r
+ *\r
+ * @param s the string to decode\r
+ * @return the decoded data\r
+ * @since 1.4\r
+ */\r
+ public static byte[] decode( String s )\r
+ { \r
+ try {\r
+ byte[] bytes = s.getBytes( "ASCII" );\r
+ return decode( bytes, 0, bytes.length );\r
+ } catch( UnsupportedEncodingException uee ) {\r
+ }\r
+ return null;\r
+ } // end decode\r
+ \r
+ \r
+ /**\r
+ * Decodes data from Base64 notation and\r
+ * returns it as a string.\r
+ * Equivlaent to calling\r
+ * <code>new String( decode( s ) )</code>\r
+ *\r
+ * @param s the strind to decode\r
+ * @return The data as a string\r
+ * @since 1.4\r
+ */\r
+ public static String decodeToString( String s )\r
+ {\r
+ try {\r
+ return new String( decode( s ), "ISO8859_1" );\r
+ } catch( UnsupportedEncodingException uee ) {\r
+ }\r
+ return null;\r
+ } // end decodeToString\r
+\r
+\r
+ /**\r
+ * Decodes Base64 content in byte array format and returns\r
+ * the decoded byte array.\r
+ *\r
+ * @param source The Base64 encoded data\r
+ * @param off The offset of where to begin decoding\r
+ * @param len The length of characters to decode\r
+ * @return decoded data\r
+ * @since 1.3\r
+ */\r
+ public static byte[] decode( byte[] source, int off, int len )\r
+ {\r
+ int len34 = len * 3 / 4;\r
+ byte[] outBuff = new byte[ len34 ]; // Upper limit on size of output\r
+ int outBuffPosn = 0;\r
+ \r
+ byte[] b4 = new byte[4];\r
+ int b4Posn = 0;\r
+ int i = 0;\r
+ byte sbiCrop = 0;\r
+ byte sbiDecode = 0;\r
+ for( i = 0; i < len; i++ )\r
+ {\r
+ sbiCrop = (byte)(source[i] & 0x7f); // Only the low seven bits\r
+ sbiDecode = DECODABET[ sbiCrop ];\r
+ \r
+ if( sbiDecode >= WHITE_SPACE_ENC ) // White space, Equals sign or better\r
+ {\r
+ if( sbiDecode >= EQUALS_SIGN_ENC )\r
+ {\r
+ b4[ b4Posn++ ] = sbiCrop;\r
+ if( b4Posn > 3 )\r
+ {\r
+ outBuffPosn += decode4to3( b4, 0, outBuff, outBuffPosn );\r
+ b4Posn = 0;\r
+ \r
+ // If that was the equals sign, break out of 'for' loop\r
+ if( sbiCrop == EQUALS_SIGN )\r
+ break;\r
+ } // end if: quartet built\r
+ \r
+ } // end if: equals sign or better\r
+ \r
+ } // end if: white space, equals sign or better\r
+ else\r
+ {\r
+ System.err.println( "Bad Base64 input character at " + i + ": " + source[i] + "(decimal)" );\r
+ return null;\r
+ } // end else: \r
+ } // each input character\r
+ \r
+ byte[] out = new byte[ outBuffPosn ];\r
+ System.arraycopy( outBuff, 0, out, 0, outBuffPosn ); \r
+ return out;\r
+ } // end decode\r
+} // end class Base64\r
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
- * "Christopher R. Hertel" <crh@nts.umn.edu>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
+ * "Christopher R. Hertel" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
import java.io.Writer;
import java.io.OutputStream;
+import java.io.PrintStream;
import java.util.Properties;
/**
* @see jcifs.util.LogWriter
* @see jcifs.netbios.Log
* @see jcifs.smb.Log
- * @since jcifs-0.1
*/
public class Log {
public static final int EXCEPTIONS = 0x10000001;
/**
+ * <b>Depricated</b> <i>The jCIFS package no longer uses the
+ * <code>CRITICAL_EXCEPTIONS</code> mask. It was invented to compensate
+ * for a deficiency in jCIFS that has since been resolved. It will be
+ * removed in the next release.</i>
+ * <p>
* Log only critical exceptions. All exceptions logged with
* <code>printStackTrace</code> are considered critical. Exceptions are not
* critical if they are logged with the <code>NON_CRITICAL_EXCEPTIONS</code>
public static final int CRITICAL_EXCEPTIONS = 0x00000001;
/**
+ * <b>Depricated</b> <i>The jCIFS package no longer uses the
+ * <code>NON_CRITICAL_EXCEPTIONS</code> mask. It was invented to compensate
+ * for a deficiency in jCIFS that has since been resolved. It will be
+ * removed in the next release.</i>
+ * <p>
* Log non-critical exceptions. The <code>EXCEPTIONS</code> mask consists of both critical and non-critical exceptions.
*/
/**
* The shared output stream of all <code>Log</code> classes. The
- * defualt is <code>System.out</code>.
+ * defualt is <code>System.err</code>.
+ * <p>
+ * <i>This was changed from System.out in jcifs-0.7.0b</i>
*/
- protected static LogWriter out = new LogWriter( System.out );
+ protected static LogWriter out = new LogWriter( System.err );
/**
* This is the integer mask that controls what is logged. It is shared
/**
* Specify an {@link java.io.OutputStream} to be used as the underlying
- * stream.
+ * stream. The default <code>OutputStream</code> is
+ * <code>System.out</code>. Specify a different stream such as a
+ * <code>FileOutputStream</code> perhaps to divert <i>all</i> logging
+ * output to a different stream.
*
- * @param out the output stream
+ * @param out the stream to which logging messages are written
*/
public static void setPrintWriter( OutputStream out ) {
/**
* Set the mask used to screen all calls to logging methods. The idea
* here is that the mask can be specified as an arithmetic expression
- * to perovide a crude but effective syslog style way to dictate what it
+ * to provide a crude but effective syslog style way to dictate what is
* logged. For example:
* <p><blockquote><pre>
* setMask( Log.EXCEPTIONS +
public static void printHexDump( String desc, byte[] src ) {
printHexDump( desc, src, 0, src.length );
}
+ public static void printHexDump( PrintStream ps, byte[] src, int srcIndex, int length ) {
+ int s = length % 16;
+ int r = ( s == 0 ) ? length / 16 : length / 16 + 1;
+ char[] c = new char[r * (74 + NL_LENGTH)];
+ char[] d = new char[16];
+ int i;
+ int si = 0;
+ int ci = 0;
+ do {
+ toHexChars( si, c, ci, 5 );
+ ci += 5;
+ c[ci++] = ':';
+ do {
+ if( si == length ) {
+ int n = 16 - s;
+ System.arraycopy( spaceChars, 0, c, ci, n * 3 );
+ ci += n * 3;
+ System.arraycopy( spaceChars, 0, d, s, n );
+ break;
+ }
+ c[ci++] = ' ';
+ i = src[srcIndex + si] & 0xFF;
+ toHexChars( i, c, ci, 2 );
+ ci += 2;
+ if( i < 0 || Character.isISOControl( (char)i )) {
+ d[si % 16] = '.';
+ } else {
+ d[si % 16] = (char)i;
+ }
+ } while(( ++si % 16 ) != 0 );
+ c[ci++] = ' ';
+ c[ci++] = ' ';
+ c[ci++] = '|';
+ System.arraycopy( d, 0, c, ci, 16 );
+ ci += 16;
+ c[ci++] = '|';
+ NL.getChars( 0, NL_LENGTH, c, ci );
+ ci += NL_LENGTH;
+ } while( si < length );
+ ps.println( c );
+ }
public static void printHexDump( String desc, byte[] src, int srcIndex, int length ) {
if(( HEX_DUMPS & mask ) == 0 || length == 0 ) {
return;
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
out.write( " - " );
out.write( desc );
out.write( lineSeparator );
- out.write( s );
- out.write( lineSeparator );
+ if( s != null ) {
+ out.write( s );
+ out.write( lineSeparator );
+ }
out.flush();
}
} catch( InterruptedIOException x ) {
out.write( " - " );
out.write( desc );
out.write( lineSeparator );
- out.write( String.valueOf( o ));
- out.write( lineSeparator );
+ if (o != null ) {
+ out.write( String.valueOf( o ));
+ out.write( lineSeparator );
+ }
out.flush();
}
} catch( InterruptedIOException x ) {
--- /dev/null
+/* jcifs smb client library in Java
+ * Copyright (C) 2002 "Michael B. Allen" <jcifs at samba dot org>
+ *
+ * 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;
+
+import java.io.InputStream;
+import java.io.IOException;
+
+public class MimeMap {
+
+ static final int IN_SIZE = 7000;
+
+ static final int ST_START = 1;
+ static final int ST_COMM = 2;
+ static final int ST_TYPE = 3;
+ static final int ST_GAP = 4;
+ static final int ST_EXT = 5;
+
+ byte[] in;
+ int inLen;
+
+ public MimeMap() throws IOException {
+ int n;
+
+ in = new byte[IN_SIZE];
+ InputStream is = getClass().getClassLoader().getResourceAsStream( "jcifs/util/mime.map" );
+
+ inLen = 0;
+ while(( n = is.read( in, inLen, IN_SIZE - inLen )) != -1 ) {
+ inLen += n;
+ }
+ if( inLen < 100 || inLen == IN_SIZE ) {
+ throw new IOException( "Error reading jcifs/util/mime.map resource" );
+ }
+ is.close();
+ }
+
+ public String getMimeType( String extension ) throws IOException {
+ return getMimeType( extension, "application/octet-stream" );
+ }
+ public String getMimeType( String extension, String def ) throws IOException {
+ int state, t, x, i, off;
+ byte ch;
+ byte[] type = new byte[128];
+ byte[] buf = new byte[16];
+ byte[] ext = extension.toLowerCase().getBytes( "ASCII" );
+
+ state = ST_START;
+ t = x = i = 0;
+ for( off = 0; off < inLen; off++ ) {
+ ch = in[off];
+ switch( state ) {
+ case ST_START:
+ if( ch == ' ' || ch == '\t' ) {
+ break;
+ } else if( ch == '#' ) {
+ state = ST_COMM;
+ break;
+ }
+ state = ST_TYPE;
+ case ST_TYPE:
+ if( ch == ' ' || ch == '\t' ) {
+ state = ST_GAP;
+ } else {
+ type[t++] = ch;
+ }
+ break;
+ case ST_COMM:
+ if( ch == '\n' ) {
+ t = x = i = 0;
+ state = ST_START;
+ }
+ break;
+ case ST_GAP:
+ if( ch == ' ' || ch == '\t' ) {
+ break;
+ }
+ state = ST_EXT;
+ case ST_EXT:
+ switch( ch ) {
+ case ' ':
+ case '\t':
+ case '\n':
+ case '#':
+ for( i = 0; i < x && x == ext.length && buf[i] == ext[i]; i++ ) {
+ ;
+ }
+ if( i == ext.length ) {
+ return new String( type, 0, t, "ASCII" );
+ }
+ if( ch == '#' ) {
+ state = ST_COMM;
+ } else if( ch == '\n' ) {
+ t = x = i = 0;
+ state = ST_START;
+ }
+ x = 0;
+ break;
+ default:
+ buf[x++] = ch;
+ }
+ break;
+ }
+ }
+ return def;
+ }
+}
+
/* jcifs smb client library in Java
- * Copyright (C) 2000 "Michael B. Allen" <mballen@erols.com>
+ * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* It might also be thought of as overloading <code>net.username</code>
* with <code>net.smb.username</code> but only for the smb branch.
*
- * <p>See the <a href="../../../properties.html">More About PropertiesTree and it's File Format</a> for details.
+ * <p>See the <a href="../../../properties.html">PropertiesTree</a> document for details.
*/
public class PropertiesTree extends Properties {
out.write('\n');
out.flush();
} else {
- System.out.println( "error: " + key + "=" + value );
+ System.err.println( "error: " + key + "=" + value );
}
}
for( Enumeration e1 = sections.elements(); e1.hasMoreElements(); ) {
}
return p.put( s.substring( d + 1 ), value );
} else {
+ Object x;
o = super.get( s );
if( o != null && o instanceof PropertiesTree ) {
throw new IllegalArgumentException( "property tree exists: " + s );
((PropertiesTree)value).label = (String)key;
((PropertiesTree)value).parent = this;
}
- return super.put( key, value );
+ x = super.put( key, value );
+ return x;
}
}
--- /dev/null
+/*
+ * @(#)URLDecoder.java 1.9 00/02/02
+ *
+ * Copyright 1998-2000 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * This software is the proprietary information of Sun Microsystems, Inc.
+ * Use is subject to license terms.
+ *
+ */
+
+package jcifs.util;
+
+import java.io.*;
+
+/**
+ * The class contains a utility method for converting from
+ * a MIME format called "<code>x-www-form-urlencoded</code>"
+ * to a <code>String</code>
+ * <p>
+ * To convert to a <code>String</code>, each character is examined in turn:
+ * <ul>
+ * <li>The ASCII characters '<code>a</code>' through '<code>z</code>',
+ * '<code>A</code>' through '<code>Z</code>', and '<code>0</code>'
+ * through '<code>9</code>' remain the same.
+ * <li>The plus sign '<code>+</code>'is converted into a
+ * space character '<code> </code>'.
+ * <li>The remaining characters are represented by 3-character
+ * strings which begin with the percent sign,
+ * "<code>%<i>xy</i></code>", where <i>xy</i> is the two-digit
+ * hexadecimal representation of the lower 8-bits of the character.
+ * </ul>
+ *
+ * @author Mark Chamness
+ * @author Michael McCloskey
+ * @version 1.9, 02/02/00
+ * @since 1.2
+ */
+
+public class URLDecoder {
+
+/**
+ * Decodes a "x-www-form-urlencoded"
+ * to a <tt>String</tt>.
+ * @param s the <code>String</code> to decode
+ * @return the newly decoded <code>String</code>
+ */
+ public static String decode(String s) {
+ StringBuffer sb = new StringBuffer();
+ for(int i=0; i<s.length(); i++) {
+ char c = s.charAt(i);
+ switch (c) {
+ case '+':
+ sb.append(' ');
+ break;
+ case '%':
+ try {
+ sb.append((char)Integer.parseInt(
+ s.substring(i+1,i+3),16));
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException();
+ }
+ i += 2;
+ break;
+ default:
+ sb.append(c);
+ break;
+ }
+ }
+ // Undo conversion to external encoding
+ String result = sb.toString();
+ try {
+ byte[] inputBytes = result.getBytes("8859_1");
+ result = new String(inputBytes);
+ } catch (UnsupportedEncodingException e) {
+ // The system should always have 8859_1
+ }
+ return result;
+ }
+}
+
+
--- /dev/null
+application/access mdf # Microsoft Access
+#application/excel xls # Microsoft Excel
+application/vnd.ms-excel xls # Microsoft Excel
+application/font-tdpfr pfr # TrueDoc Portable Font Resource
+application/futuresplash spl # Macromedia Flash
+application/hep hep # Hummingbird Host Explorer Profiles
+application/lotus-123 wks # Lotus 123
+application/mac-binhex40 hqx # Macintosh binhexed archives
+application/mspowerpoint ppt # Microsoft Powerpoint
+application/msword doc # Microsoft Word
+application/octet-stream bin exe ani # Binary File
+application/oda oda
+application/pagemaker pm5 pt5 pm # PageMaker
+application/pdf pdf # Adobe Acrobat
+application/postscript ai eps ps # Postscript File
+application/rtf rtf # Rich Text File
+application/toolbook tbk # Toolbook
+application/wordperfect wp # WordPerfect
+application/wordperfect5.1 wp5 # WordPerfect Version 5.1
+application/wordperfect6.1 wp6 # WordPerfect Version 6.1
+application/wordperfectd wpd # WordPerfect
+application/x-bcpio bcpio #
+application/x-cpio cpio #
+application/x-csh csh # C-Shell Program
+application/x-director dcr # Director File
+application/x-dvi dvi # TeX dvi Format
+application/x-gtar gtar # Gzip and Tar file
+application/x-gzip gz tgz # Gzip and Tar file
+application/x-compress z # Gzip and Tar file
+application/x-hdf hdf # NCSA HDF
+application/x-ica ica # WinFrames
+application/x-javascript js # Javascript
+application/x-latex latex # Latex File
+application/x-mif mif #
+application/x-netcdf nc cdf #
+#application/x-sh sh # sh Shell Program
+application/x-shar shar #
+application/x-shockwave-flash swf # Macromedia Shockwave file
+application/x-spss sav spp sbs sps spo # SPSS
+application/x-stuffit sit # Macintosh Stuff-It
+application/x-sv4cpio sv4cpio #
+application/x-sv4crc sv4crc #
+application/x-tar tar # UNIX Tape Archive
+application/x-tcl tcl # TCL Programming Language
+application/x-tex tex # Tex/LaTeX
+application/x-texinfo texinfo texi # TexInfo
+application/x-troff t tr roff # Troff file
+application/x-troff-man man # Troff with MAN macros
+application/x-troff-me me # Troff with ME macros
+application/x-troff-ms ms # Troff with MS macros
+application/x-ustar ustar # Ustar file
+application/vnd.ms-access mdb mda mde # MS Access
+application/vnd.ms-project mpp # MS Project
+application/x-wais-source src # WAIS Sources
+application/zip zip jar # ZIP Compressed File
+audio/basic au snd # Audio Sound File
+audio/x-aiff aif aiff aifc # AIFF Sound File
+audio/x-midi mid # MIDI Sound File
+audio/x-pn-realaudio ra ram rm rpm # REALAUDIO Sound File
+audio/x-wav wav # WAV Sound File
+audio/x-mpegurl mp3 # MP3 Sound File
+audio/mpeg3 mp3 # MP3 Sound File
+audio/x-mpeg-3 mp3 # MP3 Sound File
+audio/mpeg mp2 mpa mpg mpga # MP2 Sound File
+audio/x-mpeg mp2 # MP2 Sound File
+chemical/x-pdb pdb # PDB Chemistry Model File
+chemical/x-xyz xyz # XYZ Chemistry Model File
+drawing/x-dwf dwf # AutoCAD
+image/gif gif # GIF image file
+image/ief ief # Image Exchange
+image/jpeg jpeg jpg jpe # JPG image file
+image/png png # Portable Network Graphics
+image/tiff tiff tif # TIFF image file
+image/x-cmu-raster ras #
+image/x-portable-anymap pnm #
+image/x-portable-bitmap pbm #
+image/x-portable-graymap pgm #
+image/x-portable-pixmap ppm #
+image/x-rgb rgb # RGB Image File
+image/x-xbitmap xbm # X-bitmap Image File
+image/x-xpixmap xpm # X-pixmap Image File
+image/x-xwindowdump xwd #
+text/css css # Cascading Style Sheet
+text/html html htm # HTML Document
+text/plain txt ini log in cfg m4 sh # Plain Text File
+text/richtext rtx # Rich Text File
+text/tab-separated-values tsv #
+text/x-setext etx #
+text/x-sgml sgml sgm # SGML Document
+video/mpeg mpeg mpg mpe # MPEG Movie File
+video/quicktime qt mov # Quicktime Movie File
+video/x-ms-asf asf asx # Windows Media File
+video/x-msvideo avi # AVI Movie File
+video/x-sgi-movie movie # SGI Movie File