Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for unregistering server from serverlist (Fixes #644) #647

Merged
merged 2 commits into from
Jun 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/java/com/hierynomus/smbj/SMBClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,8 @@ public void close() {
}
}
}

public ServerList getServerList() {
return serverList;
}
}
9 changes: 9 additions & 0 deletions src/main/java/com/hierynomus/smbj/server/ServerList.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,13 @@ public void registerServer(Server server) {
lock.unlock();
}
}

public void unregister(String name) {
lock.lock();
try {
lookup.remove(name);
} finally {
lock.unlock();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import com.hierynomus.msdtyp.FileTime
import com.hierynomus.mserref.NtStatus
import com.hierynomus.mssmb2.SMB2Dialect
import com.hierynomus.mssmb2.SMBApiException
import com.hierynomus.mssmb2.SMB2Dialect
import com.hierynomus.mssmb2.SMB2MessageCommandCode
import com.hierynomus.mssmb2.messages.SMB2NegotiateRequest
import com.hierynomus.mssmb2.messages.SMB2NegotiateResponse
import com.hierynomus.mssmb2.messages.SMB2TreeConnectRequest
import com.hierynomus.mssmb2.SMB2GlobalCapability
Expand All @@ -31,6 +34,7 @@ import com.hierynomus.smbj.event.ConnectionClosed
import com.hierynomus.smbj.event.SMBEvent
import com.hierynomus.smbj.event.SMBEventBus
import com.hierynomus.smbj.event.SessionLoggedOff
import com.hierynomus.protocol.transport.TransportException
import net.engio.mbassy.listener.Handler
import spock.lang.Specification

Expand Down Expand Up @@ -140,14 +144,49 @@ class ConnectionSpec extends Specification {
return resp
})
config.dfsEnabled = true
client = new SMBClient(config)

when:
def conn = client.connect("foo")

then:
!(conn.pathResolver instanceof DFSPathResolver)
}

def "should remove server from serverlist if identification changed"() {
given:
def sent = false
config = smbConfig({ req ->
req = req.packet
if (!sent && req instanceof SMB2NegotiateRequest) {
sent = true
def response = new SMB2NegotiateResponse()
response.header.message = SMB2MessageCommandCode.SMB2_NEGOTIATE
response.header.statusCode = NtStatus.STATUS_SUCCESS.value
response.dialect = SMB2Dialect.SMB_2_1
response.systemTime = FileTime.now();
response.serverGuid = UUID.fromString("ffeeddcc-bbaa-9988-7766-554433221100")
return response
}
})
client = new SMBClient(config)

when:
def conn = client.connect("foo")
conn.close()

conn = client.connect("foo")

then:
thrown(TransportException)

when:
client.getServerList().unregister("foo")
conn = client.connect("foo")

then:
noExceptionThrown()
}

def "should add DFS path resolver if server supports DFS"() {
given:
config = smbConfig({ req ->
Expand Down