summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xzvolcreator.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/zvolcreator.rb b/zvolcreator.rb
index eb79069..a98bee7 100755
--- a/zvolcreator.rb
+++ b/zvolcreator.rb
@@ -3,6 +3,7 @@
require 'zfs'
require 'socket'
require 'json'
+require 'uuid'
require_relative 'zfs_monkeypatch'
load File.dirname($0) + "/" + 'config.rb'
@@ -17,10 +18,14 @@ puts "socket directory: #{sockdir}"
Dir.mkdir(sockdir, 0700) if not File.exists?(sockdir)
File.umask(0077)
+puts "setting up UUID generator"
+UUID.state_file = false
+
server = UNIXServer.open(Config[:socketpath])
loop do
Thread.start(server.accept) do |client|
begin
+ uuid = UUID.new
client.puts({:status => 0, :content => {:app => "zvolcreator", :apiversion => 0}}.to_json)
response = JSON.parse(client.read)
raise ArgumentError.new("Bad status") if response["status"] != 0
@@ -30,6 +35,15 @@ loop do
raise ArgumentError.new("Bad status") if response["status"] != 0
raise ArgumentError.new("No user specified") if not response["content"]["user"]
raise ArgumentError.new("Volume size not specified") if not response["content"]["volsize"]
+ # poor man's check for nasty characters in usernames
+ raise ArgumentError.new("Invalid characters in username") if response["content"]["user"] =~ /[\/\\ ]/
+
+ userfs = Config[:basefs] + "/" + response["content"]["user"].to_s
+
+ ZFS(userfs).create(:zfsopts => ["quota=#{Config[:default_user_quota]}"])
+ volpath = userfs + "/" + uuid.generate
+ ZFS(volpath).create(:sparse => true, :volume => response["content"]["volsize"])
+ client.puts({:status => 0, :content => {:volpath => volpath}}.to_json)
rescue JSON::ParserError, ArgumentError => e
client.puts({:status => 1, :content => e.to_s})
client.close