Re: URL not correctly parsed if password contains number sign ('#')
Michael B Allen <[email protected]> Sat, 6 Feb 2016 15:49:33 -0500
| Newsgroups | gmane.network.samba.java |
|---|---|
| Message-ID | <CAGMFw4hg9oj-rhjvXOt95f8WjWU0jn+yNgTfm2V285BnbJZDTA@mail.gmail.com> |
--047d7b3a8390e869b9052b201a7c Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Thu, Feb 4, 2016 at 9:12 AM, Guertler Mario <[email protected]> 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 (=E2=80=98#=E2=80=99) i= s used in password > then we get problems. > > I already figured out where the problem is; the passed URL string of > constructor =E2=80=98public SmbFile(String url)=E2=80=99 is not correctly= parsed. > > > > The following code: > > > > String connectString =3D"smb://user:passwort#123456789@host/share/Test/= =E2=80=9D; > > SmbFile polledFile =3D new SmbFile(connectString); > > > > Results in following field variables of class SmbFile or better of class > URL > > > > authority "user:test#123456789@host" > > file "#123456789@host/share/Test/" > > path "#123456789@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 --047d7b3a8390e869b9052b201a7c Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">On Thu, Feb 4, 2016 at 9:12 AM, Guertler Mario <span dir= =3D"ltr"><<a href=3D"mailto:[email protected]" target=3D"_blank">m.guert= [email protected]</a>></span> wrote:<br><div class=3D"gmail_extra"><div class= =3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px = 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> <div link=3D"#0563C1" vlink=3D"#954F72" lang=3D"DE"> <div> <p class=3D"MsoNormal"><span lang=3D"EN-US">Hi all,<u></u><u></u></span></p= > <p class=3D"MsoNormal"><span lang=3D"EN-US"><u></u>=C2=A0<u></u></span></p> <p class=3D"MsoNormal"><span lang=3D"EN-US">I think I found a bug in your i= mplementation. We are using JCIFS in many applications successfully, but if= the number sign (=E2=80=98#=E2=80=99) is used in password then we get prob= lems. <u></u><u></u></span></p> <p class=3D"MsoNormal"><span lang=3D"EN-US">I already figured out where the= problem is; the passed URL string of constructor =E2=80=98public SmbFile(S= tring url)=E2=80=99 is not correctly parsed.<u></u><u></u></span></p> <p class=3D"MsoNormal"><span lang=3D"EN-US"><u></u>=C2=A0<u></u></span></p> <p class=3D"MsoNormal"><span lang=3D"EN-US">The following code:<u></u><u></= u></span></p> <p class=3D"MsoNormal"><span lang=3D"EN-US"><u></u>=C2=A0<u></u></span></p> <p class=3D"MsoNormal"><span lang=3D"EN-US">String connectString =3D"s= mb://user:passwort#123456789@host/share/Test/=E2=80=9D;<u></u><u></u></span= ></p> <p class=3D"MsoNormal"><span lang=3D"EN-US">SmbFile polledFile =3D new SmbF= ile(connectString);<u></u><u></u></span></p> <p class=3D"MsoNormal"><span lang=3D"EN-US"><u></u>=C2=A0<u></u></span></p> <p class=3D"MsoNormal"><span lang=3D"EN-US">Results in following field vari= ables of class SmbFile or better of class URL<u></u><u></u></span></p> <p class=3D"MsoNormal"><span lang=3D"EN-US"><u></u>=C2=A0<u></u></span></p> <p class=3D"MsoNormal"><span lang=3D"EN-US">authority=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 "user:test#1234567= 89@host"<u></u><u></u></span></p> <p class=3D"MsoNormal"><span lang=3D"EN-US">file=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 "#123456789@host/share/Test= /"<u></u><u></u></span></p> <p class=3D"MsoNormal"><span lang=3D"EN-US">path=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 "#123456789@host/share/Test/"<u></u><u><= /u></span></p> <p class=3D"MsoNormal"><span lang=3D"EN-US">protocol=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 "smb"<u= ></u><u></u></span></p> <p class=3D"MsoNormal"><span lang=3D"EN-US">userInfo=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 "user:test#1= 23456789"<u></u><u></u></span></p> <p class=3D"MsoNormal"><span lang=3D"EN-US"><u></u>=C2=A0<u></u></span></p> <p class=3D"MsoNormal"><span lang=3D"EN-US">So you can see that the file/pa= th is not correct und the access to this file will fail because it does not= exist.</span></p></div></div></blockquote><div><br><div><div><div>Hi Mario= ,<br><br></div>This is actually not a bug. You=20 must URL encode any characters in a URL that are special characters for URL= s. The # sign is a ref marker. Try=20 substituting with %23.<br><br></div>However, you should not put the=20 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=20 appropriate constructor.<br><br></div><div>Mike<br></div></div></div></div>= </div> --047d7b3a8390e869b9052b201a7c--