hierynomus / smbj

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

samba version #626

Closed 151058580845 closed 3 years ago

151058580845 commented 3 years ago

How do I know the version of the connection Samba protocol

hierynomus commented 3 years ago

I'm not sure I understand the question. The protocol version is negotiated, depending on what the server supports and what you have configured in smbj to be allowed. In the logging you can see which protocol was selected.

151058580845 commented 3 years ago

The server comes in Samba 1,2,3 versions, but I now want to know which version of Samba I'm connecting to

hierynomus commented 3 years ago

You can configure SMBJ to require a certain SMB Dialect. For example:

SmbConfig config = SmbConfig.builder().withDialects(SMB2Dialect.SMB_3_0).withSecurityProvider(new BCSecurityProvider()).build();
SMBClient client = new SMBClient(config);
151058580845 commented 3 years ago

I need to be able to connect all versions of Samba, but different versions need to be processed differently, so I want to get the connected version dynamically,thanks

jansohn commented 3 years ago

This is how we log it:

log.info("Connected to {} with Samba protocol {}", remoteSourceDir.getHostname(), connection.getNegotiatedProtocol().getDialect());
hierynomus commented 3 years ago

Once the connection is established, you can do the following:

Connection c = client.connect(host, ip);
SMB2Dialect dialect = c.getConnectionContext().getNegotiatedProtocol().getDialect();

This will get you the dialect that the connection is using.

151058580845 commented 3 years ago

I used this method, but when I connected to different versions of Samba, I always got the same data

hierynomus commented 3 years ago

I think you're mistaken the server version vs the negotiated protocol. The server version we cannot detect. And most samba server versions accept all versions of the SMB protocol (2.0, 2.0.2, 3.x)... So that just depends on what's negotiated during the connection setup.

151058580845 commented 3 years ago

Maybe I made a mistake. I'm sorry to trouble you. Thank you very much

jansohn commented 3 years ago

Once the connection is established, you can do the following:

Connection c = client.connect(host, ip);
SMB2Dialect dialect = c.getConnectionContext().getNegotiatedProtocol().getDialect();

This will get you the dialect that the connection is using.

Has this been refactored? Because I cannot find a connection.getConnectionContext() with latest version smbj 0.10.0...

EDIT: found it. ConnectionInfo was renamed to ConnectionContext...

hierynomus commented 3 years ago

Cool, can this be closed?

vipsikka commented 7 months ago

I'm currently utilizing the smbj 0.12 library for Scala. I have a question regarding the default SMB version: if I don't explicitly pass any dialect, will it default to SMBv2 or SMBv3?