[jcifs] URL not correctly parsed if password contains number sign ('#')

Michael B Allen ioplex at gmail.com
Sat Feb 6 20:49:33 UTC 2016


On Thu, Feb 4, 2016 at 9:12 AM, Guertler Mario <m.guertler at znt.de> wrote:

> Hi all,
>
>
>
> I think I found a bug in your implementation. We are using JCIFS in many
> applications successfully, but if the number sign (‘#’) is used in password
> then we get problems.
>
> I already figured out where the problem is; the passed URL string of
> constructor ‘public SmbFile(String url)’ is not correctly parsed.
>
>
>
> The following code:
>
>
>
> String connectString ="smb://user:passwort#123456789@host/share/Test/”;
>
> SmbFile polledFile = new SmbFile(connectString);
>
>
>
> Results in following field variables of class SmbFile or better of class
> URL
>
>
>
> authority             "user:test#123456789 at host"
>
> file                         "#123456789 at host/share/Test/"
>
> path                      "#123456789 at host/share/Test/"
>
> protocol              "smb"
>
> userInfo              "user:test#123456789"
>
>
>
> So you can see that the file/path is not correct und the access to this
> file will fail because it does not exist.
>

Hi Mario,

This is actually not a bug. You must URL encode any characters in a URL
that are special characters for URLs. The # sign is a ref marker. Try
substituting with %23.

However, you should not put the password in the URL in the first place.
That is only for quick and dirty things like running something once from a
commandline. The correct way to pass credentials is to create an
NtlmPasswordAuthentication object and use that with the appropriate
constructor.

Mike
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.samba.org/pipermail/jcifs/attachments/20160206/1ebf46f5/attachment.html>


More information about the jCIFS mailing list