Module: RubySMB::Server::Cli
- Defined in:
- lib/ruby_smb/server/cli.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ allow_anonymous: true, allow_guests: false, domain: nil, username: 'RubySMB', password: 'password', share_name: 'home', smbv1: true, smbv2: true, smbv3: true }.freeze
Class Method Summary collapse
-
.build(options) ⇒ Object
Build a server instance from the specified options.
-
.parse(defaults: {}) {|options, parser| ... } ⇒ Hash<Symbol => >
Parse options from the command line.
-
.run(server, out: $stdout, err: $stderr) ⇒ Object
Run the server forever.
Class Method Details
.build(options) ⇒ Object
Build a server instance from the specified options. The NTLM provider will be used for authentication.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/ruby_smb/server/cli.rb', line 84 def self.build() ntlm_provider = RubySMB::Gss::Provider::NTLM.new( allow_anonymous: [:allow_anonymous], allow_guests: [:allow_guests] ) ntlm_provider.put_account([:username], [:password], domain: [:domain]) # password can also be an NTLM hash server = RubySMB::Server.new( gss_provider: ntlm_provider, logger: :stdout ) server.dialects.filter! { |dialect| RubySMB::Dialect[dialect].family != RubySMB::Dialect::FAMILY_SMB1 } unless [:smbv1] server.dialects.filter! { |dialect| RubySMB::Dialect[dialect].family != RubySMB::Dialect::FAMILY_SMB2 } unless [:smbv2] server.dialects.filter! { |dialect| RubySMB::Dialect[dialect].family != RubySMB::Dialect::FAMILY_SMB3 } unless [:smbv3] server end |
.parse(defaults: {}) {|options, parser| ... } ⇒ Hash<Symbol => >
Parse options from the command line. The resulting option hash is suitable for passing to build.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/ruby_smb/server/cli.rb', line 34 def self.parse(defaults: {}, &block) defaults = DEFAULT_OPTIONS.merge(defaults) = defaults.clone OptionParser.new do |parser| parser.on("--share-name SHARE_NAME", "The share name (default: #{defaults[:share_name]})") do |share| [:share_name] = share end parser.on("--[no-]anonymous", "Allow anonymous access (default: #{defaults[:allow_anonymous]})") do |allow_anonymous| [:allow_anonymous] = allow_anonymous end parser.on("--[no-]guests", "Allow guest accounts (default: #{defaults[:allow_guests]})") do |allow_guests| [:allow_guests] = allow_guests end parser.on("--[no-]smbv1", "Enable or disable SMBv1 (default: #{defaults[:smbv1] ? 'Enabled' : 'Disabled'})") do |smbv1| [:smbv1] = smbv1 end parser.on("--[no-]smbv2", "Enable or disable SMBv2 (default: #{defaults[:smbv2] ? 'Enabled' : 'Disabled'})") do |smbv2| [:smbv2] = smbv2 end parser.on("--[no-]smbv3", "Enable or disable SMBv3 (default: #{defaults[:smbv3] ? 'Enabled' : 'Disabled'})") do |smbv3| [:smbv3] = smbv3 end parser.on("--username USERNAME", "The account's username (default: #{defaults[:username]})") do |username| if username.include?('\\') [:domain], [:username] = username.split('\\', 2) else [:username] = username end end parser.on("--password PASSWORD", "The account's password (default: #{defaults[:password]})") do |password| [:password] = password end block.call(, parser) if block_given? end.parse! end |
.run(server, out: $stdout, err: $stderr) ⇒ Object
Run the server forever. At least 1 SMB dialect must be enabled.
107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/ruby_smb/server/cli.rb', line 107 def self.run(server, out: $stdout, err: $stderr) if server.dialects.empty? err.puts 'at least one version must be enabled' return end out.puts 'server is running' server.run do |server_client| out.puts 'received connection' true end end |