summaryrefslogtreecommitdiffstats
path: root/lib/puppet/provider/user/pw.rb
blob: bc81e5ce55f03eaef1aa2d3151f39acc51a8f6b7 (plain)
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
require 'puppet/provider/nameservice/pw'

Puppet::Type.type(:user).provide :pw, :parent => Puppet::Provider::NameService::PW do
    desc "User management via ``pw`` on FreeBSD."

    commands :pw => "pw"

    defaultfor :operatingsystem => :freebsd

    options :home, :flag => "-d", :method => :dir
    options :comment, :method => :gecos
    options :groups, :flag => "-G"

    verify :gid, "GID must be an integer" do |value|
        value.is_a? Integer
    end

    verify :groups, "Groups must be comma-separated" do |value|
        value !~ /\s/
    end

    def addcmd
        cmd = [command(:pw), "useradd", @model[:name]]
        @model.class.validstates.each do |state|
            next if state == :ensure
            # the value needs to be quoted, mostly because -c might
            # have spaces in it
            if value = @model.should(state) and value != ""
                cmd << flag(state) << value
            end
        end

        if @model[:allowdupe] == :true
            cmd << "-o"
        end

        return cmd
    end
end

# $Id$