hierynomus / smbj

Server Message Block (SMB2, SMB3) implementation in Java
Other
707 stars 180 forks source link

DFS name resolution #505

Open dja1000o opened 4 years ago

dja1000o commented 4 years ago

I recently came across one issue. After some investigation we found out that it is related on how the DFS for the share is resolved. In fact the path is resolved correctly but the DNS domain name is not added to the resolved server. As long as the application is executed on a PC that is part of the XPTO domain that works fine as the suffix xpto.xxx.xx.org is added automatically. But for Linux server in the data center this doesn’t work.

Caused by: java.net.UnknownHostException: nas-server-test at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184) at java.net.Socket.connect(Socket.java:589) at com.hierynomus.protocol.commons.socket.ProxySocketFactory.createSocket(ProxySocketFactory.java:87) at com.hierynomus.protocol.commons.socket.ProxySocketFactory.createSocket(ProxySocketFactory.java:63) at com.hierynomus.smbj.transport.tcp.direct.DirectTcpTransport.connect(DirectTcpTransport.java:88) at com.hierynomus.smbj.connection.Connection.connect(Connection.java:117) at com.hierynomus.smbj.SMBClient.getEstablishedOrConnect(SMBClient.java:103) at com.hierynomus.smbj.SMBClient.connect(SMBClient.java:77) at com.hierynomus.smbj.session.Session.buildNestedSession(Session.java:203)

In the meantime, as a workaround, we extended the SMBClient.java and add the domain name on-the-fly.

@Override public Connection connect(String hostname) throws IOException { if(!hostname.contains(XPTO_SERVER_SUFFIX)) { return hostname.replace(hostname, format(XPTO_HOST_NAME, hostname, XPTO_SERVER_SUFFIX)); } return hostname; }

So the server above 'nas-server-test' would become 'nas-server-test.xpto.xxx.xx.org'. Of course that is not the preferred solution as we need to test that option carefully after each library update.

Please let me know if there is already another way of solving/mitigating this issue.

hierynomus commented 4 years ago

This means that the hostname you're getting back from the DFS resolution is not complete/valid. I wonder how samba or another DFS client fixes that. @pepijnve do you have any idea?