sambal 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ spec/sambashare
16
+ spec/smb.conf
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sambal.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 John Axel Eriksson
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # Sambal
2
+
3
+ Sambal is a ruby samba client
4
+
5
+ Quite a bit of code was borrowed from https://github.com/reivilo/rsmbclient - Thanks!
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'sambal'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install sambal
20
+
21
+ ## Usage
22
+
23
+ client = Sambal::Client.new(domain: 'WORKGROUP', host: '127.0.0.1', share: '', user: 'guest', password: '--no-pass', port: 445)
24
+ client.ls # returns hash of files
25
+ client.put("local_file.txt","remote_file.txt") # uploads file to server
26
+ client.put_content("My content here", "remote_file") # uploads content to a file on server
27
+ client.get("remote_file.txt", "local_file.txt") # downloads file from server
28
+ client.delete("remote_file.txt") # deletes files from server
29
+ client.cd("some_directory") # changes directory on server
30
+ client.close # closes connection
31
+
32
+ ## Contributing
33
+
34
+ 1. Fork it
35
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
36
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
37
+ 4. Push to the branch (`git push origin my-new-feature`)
38
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ # coding: UTF-8
2
+
3
+ module Sambal
4
+ VERSION = "0.0.1"
5
+ end
data/lib/sambal.rb ADDED
@@ -0,0 +1,150 @@
1
+ # coding: UTF-8
2
+
3
+ require "sambal/version"
4
+ require 'open3'
5
+ require 'logger'
6
+ require 'json'
7
+ require 'pty'
8
+ require 'expect'
9
+ require 'time'
10
+ require 'tempfile'
11
+
12
+ module Sambal
13
+
14
+ class Client
15
+
16
+ attr_reader :connected
17
+
18
+ def initialize(options={})
19
+ begin
20
+ options = {domain: 'WORKGROUP', host: '127.0.0.1', share: '', user: 'guest', password: '--no-pass', port: 445}.merge(options)
21
+ @o, @i, @pid = PTY.spawn("smbclient //#{options[:host]}/#{options[:share]} #{options[:password]} -W #{options[:domain]} -U #{options[:user]}, -p #{options[:port]}")
22
+ #@o.set_encoding('UTF-8:UTF-8') ## don't know didn't work, we only have this problem when the files are named using non-english characters
23
+ #@i.set_encoding('UTF-8:UTF-8')
24
+ res = @o.expect(/^smb:.*\\>/, 10)[0]
25
+ @connected = case res
26
+ when /^put/
27
+ res['putting'].nil? ? false : true
28
+ else
29
+ if res['NT_STATUS']
30
+ false
31
+ elsif res['timed out'] || res['Server stopped']
32
+ false
33
+ else
34
+ true
35
+ end
36
+ end
37
+
38
+ unless @connected
39
+ close if @pid
40
+ exit(1)
41
+ end
42
+ rescue
43
+ raise RuntimeError.exception("Unknown Process Failed!! (#{$!.to_s})")
44
+ end
45
+ end
46
+
47
+ def ls
48
+ parse_files(ask("ls"))
49
+ end
50
+
51
+ def cd(dir)
52
+ if ask "cd #{dir}"
53
+ return true
54
+ else
55
+ return false
56
+ end
57
+ end
58
+
59
+ def get(file, output)
60
+ response = ask "get #{file} #{output}"
61
+ if response =~ /^getting\sfile.*$/
62
+ true
63
+ else
64
+ false
65
+ end
66
+ end
67
+
68
+ def put(file, destination)
69
+ response = ask "put #{file} #{destination}"
70
+ if response =~ /^putting\sfile.*$/
71
+ true
72
+ else
73
+ false
74
+ end
75
+ end
76
+
77
+ def put_content(content, destination)
78
+ t = Tempfile.new("upload-smb-content-#{destination}")
79
+ File.open(t.path, 'w') do |f|
80
+ f << content
81
+ end
82
+ response = ask "put #{t.path} #{destination}"
83
+ if response =~ /^putting\sfile.*$/
84
+ true
85
+ else
86
+ false
87
+ end
88
+ ensure
89
+ t.close
90
+ end
91
+
92
+ def del(file)
93
+ response = ask "del #{file}"
94
+ next_line = response.split("\n")[1]
95
+ if next_line =~ /^smb:.*\\>/
96
+ true
97
+ elsif next_line =~ /^NT_STATUS_NO_SUCH_FILE.*$/
98
+ false
99
+ elsif next_line =~ /^NT_STATUS_ACCESS_DENIED.*$/
100
+ false
101
+ else
102
+ false
103
+ end
104
+ end
105
+
106
+ def close
107
+ @i.printf("quit\n")
108
+ @connected = false
109
+ end
110
+
111
+ private
112
+
113
+ def ask(cmd)
114
+ @i.printf("#{cmd}\n")
115
+ response = @o.expect(/^smb:.*\\>/,10)[0] rescue nil
116
+ if response.nil?
117
+ $stderr.puts "Failed to do #{cmd}"
118
+ exit(1)
119
+ else
120
+ return response
121
+ end
122
+ end
123
+
124
+ def parse_files(str)
125
+ files = {}
126
+ str.each_line do |line|
127
+ if line =~ /\s+([\w\.\d\-\_\?\!\s]+)\s+([DAH]?)\s+(\d+)\s+(.+)$/
128
+ lsplit = line.split(/\s+/)
129
+ lsplit.shift ## remove first empty string
130
+ name = lsplit.shift#$1
131
+ if lsplit.first =~ /^[A-Za-z]+$/
132
+ type = lsplit.shift
133
+ else
134
+ type = ""
135
+ end
136
+ size = lsplit.shift#$3
137
+ date = lsplit.join(' ')#$4
138
+ name.gsub!(/\s+$/,'')
139
+ files[name] = if type =~/^D.*$/
140
+ {type: :directory, size: size, modified: (Time.parse(date) rescue "!!#{date}")}
141
+ else
142
+ {type: :file, size: size , modified: (Time.parse(date) rescue "!!#{date}")}
143
+ end
144
+ end
145
+ end
146
+ files
147
+ end
148
+
149
+ end
150
+ end
data/sambal.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/sambal/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["John Axel Eriksson"]
6
+ gem.email = ["john@insane.se"]
7
+ gem.description = %q{Ruby Samba Client}
8
+ gem.summary = %q{Ruby Samba Client}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "sambal"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Sambal::VERSION
17
+
18
+ gem.add_development_dependency "rspec", '>=2.6.0'
19
+ end
@@ -0,0 +1,111 @@
1
+ # coding: UTF-8
2
+
3
+ require 'spec_helper'
4
+ require 'tempfile'
5
+
6
+ describe Sambal::Client do
7
+
8
+ SMB_PORT = 2321
9
+ SHARE_NAME = 'spec'
10
+
11
+ def smbd_pids
12
+ pids = `ps ax | grep smbd | grep #{SMB_PORT} | grep -v grep | awk '{print \$1}'`.chomp
13
+ pids.split("\n").map {|p| (p.nil? || p=='') ? nil : p.to_i }
14
+ end
15
+
16
+ def start_smbd
17
+ ## we just start an smb server here for the duration of this spec
18
+ @smb_server_pid = fork do
19
+ `smbd -S -F -s #{SAMBA_CONF} -p 2321`
20
+ end
21
+ sleep 2 ## takes a short time to start up
22
+ end
23
+
24
+ def stop_smbd
25
+ ## stopping is done in an ugly way now by greping etc - it works
26
+ pids = smbd_pids
27
+ pids.each { |ppid| `kill -9 #{ppid} 2> /dev/null` }
28
+ end
29
+
30
+ let(:file_to_upload) do
31
+ t = Tempfile.new('sambal-smbclient-spec')
32
+ File.open(t.path,'w') do |f|
33
+ f << "Hello from specs"
34
+ end
35
+ t
36
+ end
37
+
38
+ let(:test_directory) do
39
+ 'testdir'
40
+ end
41
+
42
+ let(:testfile) do
43
+ 'testfile.txt'
44
+ end
45
+
46
+ before(:all) do
47
+ File.open("#{SAMBA_SHARE}/#{testfile}", 'w') do |f|
48
+ f << "Hello"
49
+ end
50
+ FileUtils.mkdir_p "#{SAMBA_SHARE}/#{test_directory}"
51
+ FileUtils.chmod 0775, "#{SAMBA_SHARE}/#{test_directory}"
52
+ FileUtils.chmod 0777, "#{SAMBA_SHARE}/#{testfile}"
53
+ start_smbd
54
+ @sambal_client = described_class.new(host: '127.0.0.1', share: SHARE_NAME, port: SMB_PORT)
55
+ end
56
+
57
+ after(:all) do
58
+ @sambal_client.close
59
+ stop_smbd
60
+ end
61
+
62
+ it "should list files on an smb server" do
63
+ @sambal_client.ls.should have_key(testfile)
64
+ end
65
+
66
+ it "should get files from an smb server" do
67
+ @sambal_client.get(testfile, "/tmp/sambal_spec_testfile.txt").should == true
68
+ File.exists?("/tmp/sambal_spec_testfile.txt").should == true
69
+ File.size("/tmp/sambal_spec_testfile.txt").should == @sambal_client.ls[testfile][:size].to_i
70
+ end
71
+
72
+ it "should return false when getting a file from an smb server fails" do
73
+ @sambal_client.get("non_existant_file.txt", "/tmp/sambal_spec_non_existant_file.txt").should == false
74
+ File.exists?("/tmp/sambal_spec_non_existant_file.txt").should == false
75
+ end
76
+
77
+ it "should upload files to an smb server" do
78
+ @sambal_client.ls.should_not have_key("uploaded_file.txt")
79
+ @sambal_client.put(file_to_upload.path, 'uploaded_file.txt')
80
+ @sambal_client.ls.should have_key("uploaded_file.txt")
81
+ end
82
+
83
+ it "should upload content to an smb server" do
84
+ @sambal_client.ls.should_not have_key("content_uploaded_file.txt")
85
+ @sambal_client.put_content("Content upload", 'content_uploaded_file.txt')
86
+ @sambal_client.ls.should have_key("content_uploaded_file.txt")
87
+ end
88
+
89
+ it "should delete files on an smb server" do
90
+ @sambal_client.del(testfile).should == true
91
+ @sambal_client.ls.should_not have_key(testfile)
92
+ end
93
+
94
+ it "should return false when deleting a file from an smb server fails" do
95
+ @sambal_client.del("non_existant_file.txt").should == false
96
+ end
97
+
98
+ it "should switch directory on an smb server" do
99
+ @sambal_client.put_content("testing directories", 'dirtest.txt') ## a bit stupid, but now we can check that this isn't listed when we switch dirs
100
+ @sambal_client.ls.should have_key('dirtest.txt')
101
+ @sambal_client.cd(test_directory)
102
+ @sambal_client.ls.should_not have_key('dirtest.txt')
103
+ @sambal_client.put_content("in #{test_directory}", 'intestdir.txt')
104
+ @sambal_client.ls.should have_key('intestdir.txt')
105
+ @sambal_client.cd('..')
106
+ @sambal_client.ls.should_not have_key('intestdir.txt')
107
+ @sambal_client.ls.should have_key('dirtest.txt')
108
+ end
109
+
110
+
111
+ end
data/spec/smb.conf.erb ADDED
@@ -0,0 +1,362 @@
1
+ #
2
+ # Sample configuration file for the Samba suite for Debian GNU/Linux.
3
+ #
4
+ #
5
+ # This is the main Samba configuration file. You should read the
6
+ # smb.conf(5) manual page in order to understand the options listed
7
+ # here. Samba has a huge number of configurable options most of which
8
+ # are not shown in this example
9
+ #
10
+ # Some options that are often worth tuning have been included as
11
+ # commented-out examples in this file.
12
+ # - When such options are commented with ";", the proposed setting
13
+ # differs from the default Samba behaviour
14
+ # - When commented with "#", the proposed setting is the default
15
+ # behaviour of Samba but the option is considered important
16
+ # enough to be mentioned here
17
+ #
18
+ # NOTE: Whenever you modify this file you should run the command
19
+ # "testparm" to check that you have not made any basic syntactic
20
+ # errors.
21
+ # A well-established practice is to name the original file
22
+ # "smb.conf.master" and create the "real" config file with
23
+ # testparm -s smb.conf.master >smb.conf
24
+ # This minimizes the size of the really used smb.conf file
25
+ # which, according to the Samba Team, impacts performance
26
+ # However, use this with caution if your smb.conf file contains nested
27
+ # "include" statements. See Debian bug #483187 for a case
28
+ # where using a master file is not a good idea.
29
+ #
30
+
31
+ #======================= Global Settings =======================
32
+
33
+ [global]
34
+
35
+ ## Browsing/Identification ###
36
+
37
+ # Change this to the workgroup/NT-domain name your Samba server will part of
38
+ workgroup = WORKGROUP
39
+
40
+ # server string is the equivalent of the NT Description field
41
+ server string = %h server (Samba, SPEC)
42
+
43
+ # Windows Internet Name Serving Support Section:
44
+ # WINS Support - Tells the NMBD component of Samba to enable its WINS Server
45
+ # wins support = no
46
+
47
+ # WINS Server - Tells the NMBD components of Samba to be a WINS Client
48
+ # Note: Samba can be either a WINS Server, or a WINS Client, but NOT both
49
+ ; wins server = w.x.y.z
50
+
51
+ # This will prevent nmbd to search for NetBIOS names through DNS.
52
+ dns proxy = no
53
+
54
+ # What naming service and in what order should we use to resolve host names
55
+ # to IP addresses
56
+ ; name resolve order = lmhosts host wins bcast
57
+
58
+ #### Networking ####
59
+
60
+ # The specific set of interfaces / networks to bind to
61
+ # This can be either the interface name or an IP address/netmask;
62
+ # interface names are normally preferred
63
+ ; interfaces = 127.0.0.0/8 eth0
64
+
65
+ # Only bind to the named interfaces and/or networks; you must use the
66
+ # 'interfaces' option above to use this.
67
+ # It is recommended that you enable this feature if your Samba machine is
68
+ # not protected by a firewall or is a firewall itself. However, this
69
+ # option cannot handle dynamic or non-broadcast interfaces correctly.
70
+ ; bind interfaces only = yes
71
+
72
+
73
+
74
+ #### Debugging/Accounting ####
75
+
76
+ # This tells Samba to use a separate log file for each machine
77
+ # that connects
78
+ log file = /tmp/vp6samba/samba/log.%m
79
+
80
+ # Cap the size of the individual log files (in KiB).
81
+ max log size = 1000
82
+
83
+ # If you want Samba to only log through syslog then set the following
84
+ # parameter to 'yes'.
85
+ # syslog only = no
86
+
87
+ # We want Samba to log a minimum amount of information to syslog. Everything
88
+ # should go to /var/log/samba/log.{smbd,nmbd} instead. If you want to log
89
+ # through syslog you should set the following parameter to something higher.
90
+ syslog = 0
91
+
92
+ # Do something sensible when Samba crashes: mail the admin a backtrace
93
+ # panic action = /usr/share/samba/panic-action %d
94
+
95
+
96
+ ####### Authentication #######
97
+
98
+ # "security = user" is always a good idea. This will require a Unix account
99
+ # in this server for every user accessing the server. See
100
+ # /usr/share/doc/samba-doc/htmldocs/Samba3-HOWTO/ServerType.html
101
+ # in the samba-doc package for details.
102
+ # security = user
103
+ security = share
104
+ # we set it to whoever is running the specs
105
+ guest account = <%= local_user %>
106
+
107
+ # You may wish to use password encryption. See the section on
108
+ # 'encrypt passwords' in the smb.conf(5) manpage before enabling.
109
+ encrypt passwords = true
110
+
111
+ # If you are using encrypted passwords, Samba will need to know what
112
+ # password database type you are using.
113
+ passdb backend = tdbsam
114
+
115
+ # obey pam restrictions = yes
116
+
117
+ # This boolean parameter controls whether Samba attempts to sync the Unix
118
+ # password with the SMB password when the encrypted SMB password in the
119
+ # passdb is changed.
120
+ # unix password sync = yes
121
+
122
+ # For Unix password sync to work on a Debian GNU/Linux system, the following
123
+ # parameters must be set (thanks to Ian Kahan <<kahan@informatik.tu-muenchen.de> for
124
+ # sending the correct chat script for the passwd program in Debian Sarge).
125
+ # passwd program = /usr/bin/passwd %u
126
+ # passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .
127
+
128
+ #client plaintext auth = yes
129
+ #client ntlmv2 auth = no
130
+
131
+ # This boolean controls whether PAM will be used for password changes
132
+ # when requested by an SMB client instead of the program listed in
133
+ # 'passwd program'. The default is 'no'.
134
+ # pam password change = yes
135
+
136
+ # This option controls how unsuccessful authentication attempts are mapped
137
+ # to anonymous connections
138
+ # map to guest = anonymous
139
+
140
+ ########## Domains ###########
141
+
142
+ # Is this machine able to authenticate users. Both PDC and BDC
143
+ # must have this setting enabled. If you are the BDC you must
144
+ # change the 'domain master' setting to no
145
+ #
146
+ ; domain logons = yes
147
+ #
148
+ # The following setting only takes effect if 'domain logons' is set
149
+ # It specifies the location of the user's profile directory
150
+ # from the client point of view)
151
+ # The following required a [profiles] share to be setup on the
152
+ # samba server (see below)
153
+ ; logon path = \\%N\profiles\%U
154
+ # Another common choice is storing the profile in the user's home directory
155
+ # (this is Samba's default)
156
+ # logon path = \\%N\%U\profile
157
+
158
+ # The following setting only takes effect if 'domain logons' is set
159
+ # It specifies the location of a user's home directory (from the client
160
+ # point of view)
161
+ ; logon drive = H:
162
+ # logon home = \\%N\%U
163
+
164
+ # The following setting only takes effect if 'domain logons' is set
165
+ # It specifies the script to run during logon. The script must be stored
166
+ # in the [netlogon] share
167
+ # NOTE: Must be store in 'DOS' file format convention
168
+ ; logon script = logon.cmd
169
+
170
+ # This allows Unix users to be created on the domain controller via the SAMR
171
+ # RPC pipe. The example command creates a user account with a disabled Unix
172
+ # password; please adapt to your needs
173
+ ; add user script = /usr/sbin/adduser --quiet --disabled-password --gecos "" %u
174
+
175
+ # This allows machine accounts to be created on the domain controller via the
176
+ # SAMR RPC pipe.
177
+ # The following assumes a "machines" group exists on the system
178
+ ; add machine script = /usr/sbin/useradd -g machines -c "%u machine account" -d /var/lib/samba -s /bin/false %u
179
+
180
+ # This allows Unix groups to be created on the domain controller via the SAMR
181
+ # RPC pipe.
182
+ ; add group script = /usr/sbin/addgroup --force-badname %g
183
+
184
+ ########## Printing ##########
185
+
186
+ # If you want to automatically load your printer list rather
187
+ # than setting them up individually then you'll need this
188
+ # load printers = yes
189
+
190
+ # lpr(ng) printing. You may wish to override the location of the
191
+ # printcap file
192
+ ; printing = bsd
193
+ ; printcap name = /etc/printcap
194
+
195
+ # CUPS printing. See also the cupsaddsmb(8) manpage in the
196
+ # cupsys-client package.
197
+ ; printing = cups
198
+ ; printcap name = cups
199
+
200
+ ############ Misc ############
201
+
202
+ # Using the following line enables you to customise your configuration
203
+ # on a per machine basis. The %m gets replaced with the netbios name
204
+ # of the machine that is connecting
205
+ ; include = /home/samba/etc/smb.conf.%m
206
+
207
+ # Most people will find that this option gives better performance.
208
+ # See smb.conf(5) and /usr/share/doc/samba-doc/htmldocs/Samba3-HOWTO/speed.html
209
+ # for details
210
+ # You may want to add the following on a Linux system:
211
+ # SO_RCVBUF=8192 SO_SNDBUF=8192
212
+ # socket options = TCP_NODELAY
213
+
214
+ # The following parameter is useful only if you have the linpopup package
215
+ # installed. The samba maintainer and the linpopup maintainer are
216
+ # working to ease installation and configuration of linpopup and samba.
217
+ ; message command = /bin/sh -c '/usr/bin/linpopup "%f" "%m" %s; rm %s' &
218
+
219
+ # Domain Master specifies Samba to be the Domain Master Browser. If this
220
+ # machine will be configured as a BDC (a secondary logon server), you
221
+ # must set this to 'no'; otherwise, the default behavior is recommended.
222
+ # domain master = auto
223
+
224
+ # Some defaults for winbind (make sure you're not using the ranges
225
+ # for something else.)
226
+ ; idmap uid = 10000-20000
227
+ ; idmap gid = 10000-20000
228
+ ; template shell = /bin/bash
229
+
230
+ # The following was the default behaviour in sarge,
231
+ # but samba upstream reverted the default because it might induce
232
+ # performance issues in large organizations.
233
+ # See Debian bug #368251 for some of the consequences of *not*
234
+ # having this setting and smb.conf(5) for details.
235
+ ; winbind enum groups = yes
236
+ ; winbind enum users = yes
237
+
238
+ # Setup usershare options to enable non-root users to share folders
239
+ # with the net usershare command.
240
+
241
+ # Maximum number of usershare. 0 (default) means that usershare is disabled.
242
+ ; usershare max shares = 100
243
+
244
+ # Allow users who've been granted usershare privileges to create
245
+ # public shares, not just authenticated ones
246
+ usershare allow guests = yes
247
+
248
+ #======================= Share Definitions =======================
249
+
250
+ # Un-comment the following (and tweak the other settings below to suit)
251
+ # to enable the default home directory shares. This will share each
252
+ # user's home director as \\server\username
253
+ [homes]
254
+ comment = Home Directories
255
+ browseable = yes
256
+
257
+ # By default, the home directories are exported read-only. Change the
258
+ # next parameter to 'no' if you want to be able to write to them.
259
+ ; read only = yes
260
+ writable = yes
261
+ # File creation mask is set to 0700 for security reasons. If you want to
262
+ # create files with group=rw permissions, set next parameter to 0775.
263
+ create mask = 0700
264
+
265
+ # Directory creation mask is set to 0700 for security reasons. If you want to
266
+ # create dirs. with group=rw permissions, set next parameter to 0775.
267
+ directory mask = 0700
268
+
269
+ # By default, \\server\username shares can be connected to by anyone
270
+ # with access to the samba server. Un-comment the following parameter
271
+ # to make sure that only "username" can connect to \\server\username
272
+ # The following parameter makes sure that only "username" can connect
273
+ #
274
+ # This might need tweaking when using external authentication schemes
275
+ valid users = %S
276
+
277
+ # Un-comment the following and create the netlogon directory for Domain Logons
278
+ # (you need to configure Samba to act as a domain controller too.)
279
+ ;[netlogon]
280
+ ; comment = Network Logon Service
281
+ ; path = /home/samba/netlogon
282
+ ; guest ok = yes
283
+ ; read only = yes
284
+
285
+ # Un-comment the following and create the profiles directory to store
286
+ # users profiles (see the "logon path" option above)
287
+ # (you need to configure Samba to act as a domain controller too.)
288
+ # The path below should be writable by all users so that their
289
+ # profile directory may be created the first time they log on
290
+ ;[profiles]
291
+ ; comment = Users profiles
292
+ ; path = /home/samba/profiles
293
+ ; guest ok = no
294
+ ; browseable = no
295
+ ; create mask = 0600
296
+ ; directory mask = 0700
297
+
298
+ [printers]
299
+ comment = All Printers
300
+ browseable = no
301
+ path = /var/spool/samba
302
+ printable = yes
303
+ guest ok = no
304
+ read only = yes
305
+ create mask = 0700
306
+
307
+ # Windows clients look for this share name as a source of downloadable
308
+ # printer drivers
309
+ [print$]
310
+ comment = Printer Drivers
311
+ path = /var/lib/samba/printers
312
+ browseable = yes
313
+ read only = yes
314
+ guest ok = no
315
+ # Uncomment to allow remote administration of Windows print drivers.
316
+ # You may need to replace 'lpadmin' with the name of the group your
317
+ # admin users are members of.
318
+ # Please note that you also need to set appropriate Unix permissions
319
+ # to the drivers directory for these users to have write rights in it
320
+ ; write list = root, @lpadmin
321
+
322
+ # A sample share for sharing your CD-ROM with others.
323
+ ;[cdrom]
324
+ ; comment = Samba server's CD-ROM
325
+ ; read only = yes
326
+ ; locking = no
327
+ ; path = /cdrom
328
+ ; guest ok = yes
329
+
330
+ [spec]
331
+ comment = Spec directory
332
+ read only = no
333
+ writeable = yes
334
+ write list = <%= local_user %>, @staff
335
+ locking = no
336
+ path = <%= samba_share %>
337
+ guest ok = yes
338
+ browseable = yes
339
+ create mask = 777
340
+ directory mask = 777
341
+ force create mode = 777
342
+ force directory mode = 775
343
+ force group = staff
344
+ force user = <%= local_user %>
345
+ guest account = <%= local_user %>
346
+ guest only = yes
347
+ security = share
348
+ acl check permissions = False
349
+
350
+ # The next two parameters show how to auto-mount a CD-ROM when the
351
+ # cdrom share is accesed. For this to work /etc/fstab must contain
352
+ # an entry like this:
353
+ #
354
+ # /dev/scd0 /cdrom iso9660 defaults,noauto,ro,user 0 0
355
+ #
356
+ # The CD-ROM gets unmounted automatically after the connection to the
357
+ #
358
+ # If you don't want to use auto-mounting/unmounting make sure the CD
359
+ # is mounted on /cdrom
360
+ #
361
+ ; preexec = /bin/mount /cdrom
362
+ ; postexec = /bin/umount /cdrom
@@ -0,0 +1,65 @@
1
+ # coding: UTF-8
2
+
3
+ ENV['PATH']=ENV['PATH']+':/usr/local/bin/:/usr/local/sbin'
4
+
5
+ require 'bundler/setup'
6
+
7
+ lib_path = File.expand_path('../lib', File.dirname(__FILE__))
8
+ $:.unshift(lib_path) if File.directory?(lib_path) && !$:.include?(lib_path)
9
+
10
+ require 'sambal'
11
+
12
+ FileUtils.rm_rf "/tmp/sambal_spec/samba"
13
+ FileUtils.mkdir_p "/tmp/sambal_spec/samba/"
14
+
15
+ spec_path = File.expand_path('./', File.dirname(__FILE__))
16
+
17
+ SAMBA_SHARE = "#{spec_path}/sambashare"
18
+ SAMBA_CONF = "#{spec_path}/smb.conf"
19
+
20
+ FileUtils.rm_rf SAMBA_SHARE
21
+ FileUtils.mkdir_p SAMBA_SHARE
22
+ #
23
+ require "erb"
24
+ #
25
+ class Hash
26
+ def to_binding(object = Object.new)
27
+ object.instance_eval("def binding_for(#{keys.join(",")}) binding end")
28
+ object.binding_for(*values)
29
+ end
30
+ end
31
+
32
+ class Document
33
+ def initialize(template)
34
+ @template = ERB.new(template)
35
+ end
36
+
37
+ def interpolate(replacements = {})
38
+ @template.result(replacements.to_binding)
39
+ end
40
+ end
41
+ #
42
+
43
+ File.open(SAMBA_CONF, 'w') do |f|
44
+ f << Document.new(IO.binread("#{spec_path}/smb.conf.erb")).interpolate(samba_share: SAMBA_SHARE, local_user: ENV['USER'])
45
+ end
46
+
47
+ #
48
+ #
49
+
50
+ RSpec.configure do |config|
51
+ # == Mock Framework
52
+ #
53
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
54
+ #
55
+ # config.mock_with :mocha
56
+ # config.mock_with :flexmock
57
+ # config.mock_with :rr
58
+ config.mock_with :rspec
59
+
60
+ ## perhaps this should be removed as well
61
+ ## and done in Rakefile?
62
+ config.color_enabled = true
63
+ ## dont do this, do it in Rakefile instead
64
+ #config.formatter = 'd'
65
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sambal
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - John Axel Eriksson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70166692509740 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 2.6.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70166692509740
25
+ description: Ruby Samba Client
26
+ email:
27
+ - john@insane.se
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - lib/sambal.rb
38
+ - lib/sambal/version.rb
39
+ - sambal.gemspec
40
+ - spec/sambal/client_spec.rb
41
+ - spec/smb.conf.erb
42
+ - spec/spec_helper.rb
43
+ homepage: ''
44
+ licenses: []
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 1.8.11
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: Ruby Samba Client
67
+ test_files:
68
+ - spec/sambal/client_spec.rb
69
+ - spec/smb.conf.erb
70
+ - spec/spec_helper.rb