Class: RubySMB::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_smb/server.rb,
lib/ruby_smb/server/server_client.rb,
lib/ruby_smb/server/server_client/negotiation.rb,
lib/ruby_smb/server/server_client/session_setup.rb

Overview

This class provides the SMB server core. Settings that are relevant server wide are managed by this object. Currently, the server only supports negotiating and authenticating requests. No other server functionality is available at this time. The negotiating and authentication is supported for SMB versions 1 through 3.1.1.

Defined Under Namespace

Classes: Connection, ServerClient

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server_sock: nil, gss_provider: nil) ⇒ Server

Returns a new instance of Server.

Parameters:

  • server_sock (defaults to: nil)

    the socket on which the server should listen

  • the (Gss::Provider)

    authentication provider



15
16
17
18
19
20
21
22
23
24
# File 'lib/ruby_smb/server.rb', line 15

def initialize(server_sock: nil, gss_provider: nil)
  server_sock = ::TCPServer.new(445) if server_sock.nil?

  @guid = Random.new.bytes(16)
  @socket = server_sock
  @connections = []
  @gss_provider = gss_provider || Gss::Provider::NTLM.new
  # reject the wildcard dialect because it's not a real dialect we can use for this purpose
  @dialects = RubySMB::Dialect::ALL.keys.reject { |dialect| dialect == "0x%04x" % RubySMB::SMB2::SMB2_WILDCARD_REVISION }.reverse
end

Instance Attribute Details

#dialectsArray<String>

Returns:

  • (Array<String>)


41
42
43
# File 'lib/ruby_smb/server.rb', line 41

def dialects
  @dialects
end

#gss_providerObject (readonly)

The GSS Provider instance that this server will use to authenticate incoming client connections.



47
48
49
# File 'lib/ruby_smb/server.rb', line 47

def gss_provider
  @gss_provider
end

#guidObject (readonly)

The 16 byte GUID that uniquely identifies this server instance.



51
52
53
# File 'lib/ruby_smb/server.rb', line 51

def guid
  @guid
end

Instance Method Details

#run(&block) ⇒ Object

Run the server and accept any connections. For each connection, the block will be executed if specified. When the block returns false, the loop will exit and the server will no long accept new connections.



28
29
30
31
32
33
34
35
36
# File 'lib/ruby_smb/server.rb', line 28

def run(&block)
  loop do
    sock = @socket.accept
    server_client = ServerClient.new(self, RubySMB::Dispatcher::Socket.new(sock))
    @connections << Connection.new(server_client, Thread.new { server_client.run })

    break unless block.nil? || block.call(server_client)
  end
end