Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# $Id: nfs_export.rb 2613 2009-06-21 17:43:52Z uwaechte $

Puppet::Type.newtype(:nfs_export) do
  @doc = "Manages nfs-server's /etc/exports file."

  ensurable

  newproperty(:export_point) do
    desc "The directory which is exported"
    isnamevar
  end

  newproperty(:client) do
    desc "The client addresses (or wildcards) to which the export_point should be exported"
    # check for invalid characters
    validate do |value|
      unless value =~ /[-\w\*\?\/\@\.]+/
  raise ArgumentError, "%s is not a valid client specification" % value
      end
    end
  end

  newproperty(:options) do
    desc "Export options in linux-style notation. Those options that are applicable in FreeBSD are converted automatically."
    defaultto "rw,no_subtree_check"    
    munge do |value| 
      if Facter.value(:kernel) == "FreeBSD"
  linux_to_bsd_options(value)
      else
        super
      end
    end


    def linux_to_bsd_options(opts)
      options = []
      optarr = opts.split(",")
      optarr.each { |opt|
  case opt
  when "ro":
    options << "-ro"
  when "no_root_squash"
    options << "-maproot=root"
  when "root_squash"
    uid=nil
    gid=nil
    optarr.each { |k|
      case k 
      when /anonuid=(.*)/
        uid=$1
      when /anongid=(.*)/
        gid=$1
      end
    }
    map=[]
    if !uid.nil?
      map << uid.to_s
    end
    if !gid.nil?
      map << gid.to_s
    end
    if map.length > 0
      maps = map.join(":")
    else
      maps = "root"
    end
    options << "-maproot=#{maps}"
  when "all_squash"
    uid=nil
    gid=nil
    optarr.each { |k|
      case k 
      when /anonuid=(.*)/
        uid=$1
      when /anongid=(.*)/
        gid=$1
      end
    }
    map=[]
    if !uid.nil?
      map << uid.to_s
    end
    if !gid.nil?
      map << gid.to_s
    end
    if map.length > 0
      maps = map.join(":")
    else
      maps = "nobody"
    end
    options << "-mapall=#{maps}"
  end
      }
      return options.join(" ")
    end

  end

  newparam(:name, :namevar => true) do
    desc "The name of this export"
  end
end