vagrant-better-smb 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5e7e0dfa577c1d154a7e01618af61ef510865c22
4
+ data.tar.gz: 60eb224da97674d6b6b61bb9d92fc9666fa03bbe
5
+ SHA512:
6
+ metadata.gz: 9f3f7d3170af07d24bae8949fd5f7b9d59f2fe86b75c72c99706106b71af4726b7c3cd44b7a5e13b5807127c005b6dc18567e44e907e23f286f54a54becb8a64
7
+ data.tar.gz: b6dee4a9ec31a468f5dd221cf15ed1784cfe2d225313990ca5b9a68a48fa8b50cf6da38f0c4f4fd0c3f1ff4c7dd29f849486c1aeca0e44f2c83fe4109850556b
@@ -0,0 +1,65 @@
1
+ # Better SMB support for Vagrant
2
+
3
+ Vagrant's core SMB synced folder implementation doesn't use guest and host
4
+ capabilities and doesn't provide developers with an easy means of extending
5
+ support to non-Windows platforms. This plugin aims to fix this problem by
6
+ providing an alternative synced folder implementation.
7
+
8
+ * * *
9
+
10
+ ## Work in progress
11
+
12
+ Don't use me for anything important just yet -- I'm still undergoing heavy
13
+ development. I'll be on RubyGems soon.
14
+
15
+ ## Using
16
+
17
+ To install the plugin:
18
+
19
+ $ vagrant plugin install vagrant-better-smb
20
+
21
+ Then, in your ```Vagrantfile```:
22
+
23
+ config.vm.network :private_network, ip: "<your guest ip>"
24
+
25
+ config.vm.synced_folder "testdata", "<your drive letter>:", type: "better_smb",
26
+ better_smb_machine_ip: "<your guest ip>",
27
+ better_smb_share_name: "<your share name>",
28
+ better_smb_host_ip: "<your host ip>",
29
+ better_smb_share_user: "<your username>",
30
+ better_smb_share_password: "<your password>"
31
+
32
+ ## Debugging
33
+
34
+ 1. Have you added your user account as an SMB user with
35
+ ```sudo smbpasswd -a <your username>```?
36
+ 2. Is your password up to date? Update it with ```smbpasswd```.
37
+ 3. Can you see your share in ```smbclient -L 127.0.0.1 -U <your username>```?
38
+ 4. Have you configured SELinux correctly? Allow Samba to access home directories
39
+ with ```setsebool -P samba_enable_home_dirs 1```
40
+
41
+ ## Hacking
42
+
43
+ 1. Install Ruby and Bundler.
44
+ 2. If you need any local dependencies (i.e. ```json```), pop them into a new
45
+ file called ```Gemfile.local```. We'll source it for you -- there's no need
46
+ to alter the top level ```Gemfile```.
47
+ 3. Install the bundle with ```bundle install```.
48
+ 4. Use Vagrant as normal -- just run it with ```bundle exec vagrant```.
49
+
50
+ ### Building
51
+
52
+ It's easy:
53
+
54
+ $ bundle install
55
+ $ rake build
56
+ $ ls pkg/
57
+
58
+ ### To do
59
+
60
+ * Enable multiple clients to connect to the same SMB share
61
+ * Sanity check and cleanse the values we're placing in samba.conf
62
+ * Implement support for Windows hosts
63
+ * Implement support for Linux guests
64
+ * Clean up existing shares
65
+ * Ensure Linux server implementation works outside of Fedora
@@ -0,0 +1,21 @@
1
+ #
2
+ # Better SMB for Vagrant
3
+ #
4
+ # @author Luke Carrier <luke@carrier.im>
5
+ # @copyright 2015 Luke Carrier
6
+ # @license GPL v3
7
+ #
8
+
9
+ require "vagrant"
10
+ require "vagrant-better-smb/plugin"
11
+
12
+ module VagrantPlugins
13
+ module BetterSmb
14
+ autoload :Caps, "vagrant-better-smb/caps"
15
+ autoload :Errors, "vagrant-better-smb/errors"
16
+
17
+ def self.source_root
18
+ @source_root ||= Pathname.new File.expand_path("../../", __FILE__)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,22 @@
1
+ #
2
+ # Better SMB for Vagrant
3
+ #
4
+ # @author Luke Carrier <luke@carrier.im>
5
+ # @copyright 2015 Luke Carrier
6
+ # @license GPL v3
7
+ #
8
+
9
+ module VagrantPlugins
10
+ module BetterSmb
11
+ class ActionPrepareValidIDs
12
+ def initialize(app, env)
13
+ @app = app
14
+ end
15
+
16
+ def call(env)
17
+ env[:better_smb_valid_ids] = env[:machine].provider.driver.read_vms.values
18
+ @app.call(env)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,27 @@
1
+ #
2
+ # Better SMB for Vagrant
3
+ #
4
+ # @author Luke Carrier <luke@carrier.im>
5
+ # @copyright 2015 Luke Carrier
6
+ # @license GPL v3
7
+ #
8
+
9
+ module VagrantPlugins
10
+ module BetterSmb
11
+ class ActionPrune
12
+ def initialize(app, env)
13
+ @app = app
14
+ end
15
+
16
+ def call(env)
17
+ if env[:machine].env.host.capability?(:smb_folders_prune) &&
18
+ env[:better_smb_valid_ids]
19
+ env[:machine].env.host.capability(
20
+ :smb_folders_prune, env[:machine].ui, env[:better_smb_valid_ids])
21
+ end
22
+
23
+ @app.call(env)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,16 @@
1
+ #
2
+ # Better SMB for Vagrant
3
+ #
4
+ # @author Luke Carrier <luke@carrier.im>
5
+ # @copyright 2015 Luke Carrier
6
+ # @license GPL v3
7
+ #
8
+
9
+ module VagrantPlugins
10
+ module BetterSmb
11
+ module Caps
12
+ autoload :Linux, "vagrant-better-smb/caps/linux"
13
+ autoload :Windows, "vagrant-better-smb/caps/windows"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,110 @@
1
+ #
2
+ # Better SMB for Vagrant
3
+ #
4
+ # @author Luke Carrier <luke@carrier.im>
5
+ # @copyright 2015 Luke Carrier
6
+ # @license GPL v3
7
+ #
8
+
9
+ module VagrantPlugins
10
+ module BetterSmb
11
+ module Caps
12
+ class Linux
13
+ SAMBA_CONF = "/etc/samba/smb.conf"
14
+ SAMBA_ETC_DIR = "/etc/samba"
15
+ SAMBA_SMBD = "/usr/sbin/smbd"
16
+
17
+ SMBD_STATUS_COMMAND = "systemctl status smb"
18
+ SMBD_START_COMMAND = "systemctl start smb"
19
+ SMBD_RESTART_COMMAND = "systemctl restart smb"
20
+
21
+ def self.smb_folders_export(env, ui, id, folders)
22
+ config = share_config(Process.uid, id, folders)
23
+
24
+ sudo_command = ""
25
+ sudo_command = "sudo " unless File.writable?(SAMBA_CONF)
26
+
27
+ cleanup_exports(id)
28
+
29
+ config.split("\n").each do |line|
30
+ line = Vagrant::Util::ShellQuote.escape(line, "'")
31
+ system(%Q[echo '#{line}' | #{sudo_command}tee -a #{SAMBA_CONF} >/dev/null])
32
+ end
33
+
34
+ if smb_running?
35
+ restart_smb
36
+ else
37
+ start_smb
38
+ end
39
+ end
40
+
41
+ def self.smb_folders_prune(env, ui, valid_ids)
42
+ return unless File.exist?(SAMBA_CONF)
43
+
44
+ output = false
45
+ user = Process.uid
46
+
47
+ File.read(SAMBA_CONF).lines.each do |line|
48
+ if id = line[/^# VAGRANT-BEGIN:( #{user})? ([\.\/A-Za-z0-9\-_:]+?)$/, 2]
49
+ unless valid_ids.include?(id)
50
+ if !output
51
+ # We want to warn the user but we only want to output once
52
+ ui.info I18n.t("vagrant_plugins.better_smb.messages.pruning")
53
+ output = true
54
+ end
55
+
56
+ nfs_cleanup(id)
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ def self.smb_server_installed(env)
63
+ File.directory?(SAMBA_ETC_DIR) &&
64
+ File.file?(SAMBA_CONF) &&
65
+ File.file?(SAMBA_SMBD)
66
+ end
67
+
68
+ protected
69
+
70
+ def self.cleanup_exports(id)
71
+ return unless File.exist?(SAMBA_CONF)
72
+
73
+ sudo_command = ""
74
+ sudo_command = "sudo " unless File.writable?(SAMBA_CONF)
75
+
76
+ user = Regexp.escape(Process.uid.to_s)
77
+ id = Regexp.escape(id.to_s)
78
+
79
+ # Use sed to just strip out the block of code which was inserted
80
+ # by Vagrant
81
+ command = "#{sudo_command}sed -r -e '\\\x01^# VAGRANT-BEGIN:( #{user})? #{id}\x01,\\\x01^# VAGRANT-END:( #{user})? #{id}\x01 d' -i.bak #{SAMBA_CONF}"
82
+ system(command)
83
+ end
84
+
85
+ def self.share_config(uid, id, folders)
86
+ export_template = File.expand_path(
87
+ "templates/smb/linux_share", BetterSmb.source_root)
88
+
89
+ Vagrant::Util::TemplateRenderer.render(
90
+ export_template,
91
+ user: Process.uid,
92
+ uuid: id,
93
+ folders: folders)
94
+ end
95
+
96
+ def self.smb_running?
97
+ system "#{SMBD_STATUS_COMMAND} >/dev/null"
98
+ end
99
+
100
+ def self.restart_smb
101
+ system "sudo #{SMBD_RESTART_COMMAND} >/dev/null"
102
+ end
103
+
104
+ def self.start_smb
105
+ system "sudo #{SMBD_START_COMMAND} >/dev/null"
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,42 @@
1
+ #
2
+ # Better SMB for Vagrant
3
+ #
4
+ # @author Luke Carrier <luke@carrier.im>
5
+ # @copyright 2015 Luke Carrier
6
+ # @license GPL v3
7
+ #
8
+
9
+ module VagrantPlugins
10
+ module BetterSmb
11
+ module Caps
12
+ class Windows
13
+ def self.smb_client_installed(env)
14
+ true
15
+ end
16
+
17
+ def self.smb_folders_mount(env, machine, folders)
18
+ folders.each do |folder, opts|
19
+ share_name = clean_string opts[:better_smb_share_name]
20
+ guest_path = clean_string opts[:guestpath]
21
+ user = clean_string opts[:better_smb_share_user]
22
+ password = clean_string opts[:better_smb_share_password]
23
+
24
+ share = "\\\\#{opts[:better_smb_host_ip]}\\#{share_name}"
25
+
26
+ auth_command = "cmdkey /add:#{opts[:better_smb_host_ip]} /user:#{user} /pass:#{password}"
27
+ clean_command = "NET USE #{guest_path} /DELETE /Y"
28
+ unfuck_command = "NET USE #{share}"
29
+ mount_command = "NET USE #{guest_path} #{share} /PERSISTENT:yes"
30
+
31
+ machine.communicate.execute "#{auth_command} ; #{clean_command} ; #{unfuck_command} ; #{mount_command}", {
32
+ shell: :powershell, elevated: true, error_check: false}
33
+ end
34
+ end
35
+
36
+ def self.clean_string(string)
37
+ string.gsub "$", "```$"
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,25 @@
1
+ #
2
+ # Better SMB for Vagrant
3
+ #
4
+ # @author Luke Carrier <luke@carrier.im>
5
+ # @copyright 2015 Luke Carrier
6
+ # @license GPL v3
7
+ #
8
+
9
+ module VagrantPlugins
10
+ module BetterSmb
11
+ module Errors
12
+ class BetterSmbError < Vagrant::Errors::VagrantError
13
+ error_namespace "vagrant_plugins.better_smb.errors"
14
+ end
15
+
16
+ class SmbClientNotInstalledOnGuest < BetterSmbError
17
+ error_key :smb_client_not_installed_on_guest
18
+ end
19
+
20
+ class SmbServerNotInstalledOnHost < BetterSmbError
21
+ error_key :smb_server_not_installed_on_host
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,75 @@
1
+ #
2
+ # Better SMB for Vagrant
3
+ #
4
+ # @author Luke Carrier <luke@carrier.im>
5
+ # @copyright 2015 Luke Carrier
6
+ # @license GPL v3
7
+ #
8
+
9
+ module VagrantPlugins
10
+ module BetterSmb
11
+ class Plugin < Vagrant.plugin("2")
12
+ name "BetterSmb"
13
+ description "Better SMB support for Vagrant"
14
+
15
+ host_capability :linux, :smb_folders_export do
16
+ init!
17
+ Caps::Linux
18
+ end
19
+
20
+ host_capability :linux, :smb_folders_prune do
21
+ init!
22
+ Caps::Linux
23
+ end
24
+
25
+ host_capability :linux, :smb_server_installed do
26
+ init!
27
+ Caps::Linux
28
+ end
29
+
30
+ guest_capability :windows, :smb_client_installed do
31
+ init!
32
+ Caps::Windows
33
+ end
34
+
35
+ guest_capability :windows, :smb_folders_mount do
36
+ init!
37
+ Caps::Windows
38
+ end
39
+
40
+ synced_folder :better_smb, 1 do
41
+ init!
42
+
43
+ require_relative "synced_folder"
44
+ SyncedFolder
45
+ end
46
+
47
+ action_hook :better_smb_prepare_valid_ids, :machine_action_up do |hook|
48
+ init!
49
+
50
+ require_relative "action_prepare_valid_ids"
51
+ hook.append(ActionPrepareValidIDs)
52
+ end
53
+
54
+ action_hook :better_smb_prune, :machine_action_halt do |hook|
55
+ init!
56
+
57
+ require_relative "action_prepare_valid_ids"
58
+ require_relative "action_prune"
59
+ hook.append(ActionPrepareValidIDs)
60
+ hook.after(ActionPrepareValidIDs, ActionPrune)
61
+ end
62
+
63
+ protected
64
+
65
+ def self.init!
66
+ return if defined?(@initialized)
67
+
68
+ I18n.load_path << File.expand_path(
69
+ "templates/locales/better_smb.yml", BetterSmb.source_root)
70
+ I18n.reload!
71
+ @initialized = true
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,61 @@
1
+ #
2
+ # Better SMB for Vagrant
3
+ #
4
+ # @author Luke Carrier <luke@carrier.im>
5
+ # @copyright 2015 Luke Carrier
6
+ # @license GPL v3
7
+ #
8
+
9
+ module VagrantPlugins
10
+ module BetterSmb
11
+ class SyncedFolder < Vagrant.plugin("2", :synced_folder)
12
+ @@lock = Mutex.new
13
+ def initialize(*args)
14
+ end
15
+
16
+ def usable?(machine, raise_error=false)
17
+ installed = machine.env.host.capability(:smb_server_installed)
18
+ raise Errors::SmbServerNotInstalledOnHost if raise_error and !installed
19
+
20
+ installed
21
+ end
22
+
23
+ def prepare(machine, folders, opts)
24
+ # Pre-boot
25
+ end
26
+
27
+ def enable(machine, folders, opts)
28
+ if !machine.guest.capability(:smb_client_installed)
29
+ raise Errors::SmbClientNotInstalledOnGuest
30
+ end
31
+
32
+ @@lock.synchronize do
33
+ begin
34
+ machine.env.lock("better-smb-lock") do
35
+ machine.ui.info I18n.t("vagrant_plugins.better_smb.messages.exporting")
36
+ machine.env.host.capability(
37
+ :smb_folders_export, machine.ui, machine.id, folders)
38
+ end
39
+ rescue Vagrant::Errors::EnvironmentLockedError
40
+ sleep 1
41
+ retry
42
+ end
43
+ end
44
+
45
+ machine.ui.info I18n.t("vagrant_plugins.better_smb.messages.mounting")
46
+ machine.guest.capability(:smb_folders_mount, machine, folders)
47
+ end
48
+
49
+ def cleanup(machine, opts)
50
+ # Post-halt
51
+ end
52
+
53
+ protected
54
+
55
+ def addressable_ip
56
+ machine.guest.capability(
57
+ :choose_addressable_ip_addr, candidate_ips)
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,13 @@
1
+ #
2
+ # Better SMB for Vagrant
3
+ #
4
+ # @author Luke Carrier <luke@carrier.im>
5
+ # @copyright 2015 Luke Carrier
6
+ # @license GPL v3
7
+ #
8
+
9
+ module VagrantPlugins
10
+ module BetterSmb
11
+ VERSION = "0.1.0"
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ ---
2
+ en:
3
+ vagrant_plugins:
4
+ better_smb:
5
+ errors:
6
+ smb_client_not_installed_on_guest: |-
7
+ No SMB client is installed on the guest
8
+ smb_server_not_installed_on_host: |-
9
+ No SMB server is installed on the host
10
+ messages:
11
+ exporting: |-
12
+ Exporting folders as SMB shares
13
+ mounting: |-
14
+ Mounting SMB shares on guest
15
+ pruning: |-
16
+ Pruning invalid SMB shares from host
@@ -0,0 +1,8 @@
1
+ # VAGRANT-BEGIN: <%= user %> <%= uuid %>
2
+ <% folders.each do |name, opts| %>
3
+ [<%= opts[:better_smb_share_name] %>]
4
+ path = <%= opts[:hostpath] %>
5
+ writeable = yes
6
+ hosts allow = <%= opts[:better_smb_machine_ip] %>
7
+ <% end %>
8
+ # VAGRANT-END: <%= user %> <%= uuid %>
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-better-smb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Luke Carrier
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-08 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Better SMB support for Vagrant
14
+ email: luke@carrier.im
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - README.md
20
+ - lib/vagrant-better-smb.rb
21
+ - lib/vagrant-better-smb/action_prepare_valid_ids.rb
22
+ - lib/vagrant-better-smb/action_prune.rb
23
+ - lib/vagrant-better-smb/caps.rb
24
+ - lib/vagrant-better-smb/caps/linux.rb
25
+ - lib/vagrant-better-smb/caps/windows.rb
26
+ - lib/vagrant-better-smb/errors.rb
27
+ - lib/vagrant-better-smb/plugin.rb
28
+ - lib/vagrant-better-smb/synced_folder.rb
29
+ - lib/vagrant-better-smb/version.rb
30
+ - templates/locales/better_smb.yml
31
+ - templates/smb/linux_share.erb
32
+ homepage: https://github.com/LukeCarrier/vagrant-better-smb
33
+ licenses:
34
+ - GPL v3
35
+ metadata: {}
36
+ post_install_message:
37
+ rdoc_options: []
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubyforge_project:
52
+ rubygems_version: 2.4.5
53
+ signing_key:
54
+ specification_version: 4
55
+ summary: Better SMB support for Vagrant
56
+ test_files: []