components/puppet/files/solaris/lib/puppet/provider/ldap/solaris.rb
author Drew Fisher <drew.fisher@oracle.com>
Fri, 31 Jan 2014 14:12:10 -0700
branchs11-update
changeset 2928 43b3da52b84a
parent 2771 8e4227dc2fc4
permissions -rw-r--r--
PSARC 2013/426 Puppet 3.4.1 17783988 Add zone.rb to Facter 17798202 Several providers return errors due to Ruby 1.9 changes. 17945378 backport of 17257851 to 11.2 was never actually done 18010466 Update Puppet to 3.4.1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2771
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
     1
#
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
     2
# CDDL HEADER START
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
     3
#
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
     4
# The contents of this file are subject to the terms of the
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
     5
# Common Development and Distribution License (the "License").
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
     6
# You may not use this file except in compliance with the License.
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
     7
#
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
     8
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
     9
# or http://www.opensolaris.org/os/licensing.
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    10
# See the License for the specific language governing permissions
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    11
# and limitations under the License.
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    12
#
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    13
# When distributing Covered Code, include this CDDL HEADER in each
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    14
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    15
# If applicable, add the following below this CDDL HEADER, with the
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    16
# fields enclosed by brackets "[]" replaced with your own identifying
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    17
# information: Portions Copyright [yyyy] [name of copyright owner]
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    18
#
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    19
# CDDL HEADER END
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    20
#
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    21
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    22
#
2928
43b3da52b84a PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents: 2771
diff changeset
    23
# Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
2771
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    24
#
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    25
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    26
Puppet::Type.type(:ldap).provide(:ldap) do
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    27
    desc "Provider for management of the LDAP client for Oracle Solaris"
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    28
    confine :operatingsystem => [:solaris]
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    29
    defaultfor :osfamily => :solaris, :kernelrelease => ['5.11', '5.12']
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    30
    commands :svccfg => '/usr/sbin/svccfg', :svcprop => '/usr/bin/svcprop'
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    31
2928
43b3da52b84a PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents: 2771
diff changeset
    32
    Ldap_fmri = "svc:/network/ldap/client"
43b3da52b84a PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents: 2771
diff changeset
    33
43b3da52b84a PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents: 2771
diff changeset
    34
    def initialize(resource)
43b3da52b84a PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents: 2771
diff changeset
    35
        super
43b3da52b84a PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents: 2771
diff changeset
    36
        @refresh_needed = false
43b3da52b84a PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents: 2771
diff changeset
    37
    end
2771
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    38
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    39
    def self.instances
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    40
        if Process.euid != 0
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    41
            return []
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    42
        end
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    43
        props = {}
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    44
        validprops = Puppet::Type.type(:ldap).validproperties
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    45
2928
43b3da52b84a PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents: 2771
diff changeset
    46
        svcprop("-p", "config", Ldap_fmri).each_line.collect do |line|
2771
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    47
            data = line.split()
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    48
            fullprop = data[0]
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    49
            type = data[1]
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    50
            if data.length > 2
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    51
                value = data[2..-1].join(" ")
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    52
            else
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    53
                value = nil
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    54
            end
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    55
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    56
            pg, prop = fullprop.split("/")
2928
43b3da52b84a PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents: 2771
diff changeset
    57
            props[prop] = value if validprops.include? prop.to_sym
43b3da52b84a PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents: 2771
diff changeset
    58
        end
43b3da52b84a PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents: 2771
diff changeset
    59
        begin
43b3da52b84a PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents: 2771
diff changeset
    60
            props[:bind_passwd] = svcprop("-p", "cred/bind_passwd",
43b3da52b84a PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents: 2771
diff changeset
    61
                                          "svc:/network/ldap/client").strip
43b3da52b84a PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents: 2771
diff changeset
    62
        rescue
43b3da52b84a PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents: 2771
diff changeset
    63
        end
2771
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    64
2928
43b3da52b84a PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents: 2771
diff changeset
    65
        props[:name] = "current"
2771
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    66
        return Array new(props)
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    67
    end
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    68
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    69
    Puppet::Type.type(:ldap).validproperties.each do |field|
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    70
        # get the property group
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    71
        pg = Puppet::Type.type(:ldap).propertybyname(field).pg
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    72
        define_method(field) do
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    73
            begin
2928
43b3da52b84a PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents: 2771
diff changeset
    74
                svcprop("-p", pg + "/" + field.to_s, Ldap_fmri).strip()
2771
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    75
            rescue
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    76
                # if the property isn't set, don't raise an error
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    77
                nil
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    78
            end
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    79
        end
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    80
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    81
        define_method(field.to_s + "=") do |should|
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    82
            begin
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    83
                if should.is_a? Array
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    84
                    should.collect! { |value| value.to_s }
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    85
2928
43b3da52b84a PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents: 2771
diff changeset
    86
                    # in Solaris 11, the list of values needs to be single
43b3da52b84a PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents: 2771
diff changeset
    87
                    # argument to svccfg.
43b3da52b84a PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents: 2771
diff changeset
    88
                    values = ""
43b3da52b84a PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents: 2771
diff changeset
    89
                    for entry in should
43b3da52b84a PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents: 2771
diff changeset
    90
                        values += "\"#{entry}\" "
43b3da52b84a PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents: 2771
diff changeset
    91
                    end
43b3da52b84a PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents: 2771
diff changeset
    92
                    values = "(" + values + ")"
43b3da52b84a PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents: 2771
diff changeset
    93
                    svccfg("-s", Ldap_fmri, "setprop",
43b3da52b84a PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents: 2771
diff changeset
    94
                           pg + "/" + field.to_s, "=", values)
2771
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
    95
                else
2928
43b3da52b84a PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents: 2771
diff changeset
    96
                    # Puppet seems to get confused about when to pass an empty
43b3da52b84a PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents: 2771
diff changeset
    97
                    # string or "\"\"".  Catch either condition to handle
43b3da52b84a PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents: 2771
diff changeset
    98
                    # passing values to SMF correctly
43b3da52b84a PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents: 2771
diff changeset
    99
                    if should.to_s.empty? or should.to_s == '""'
43b3da52b84a PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents: 2771
diff changeset
   100
                        value = should.to_s
43b3da52b84a PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents: 2771
diff changeset
   101
                    else
43b3da52b84a PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents: 2771
diff changeset
   102
                        value = "\"" + should.to_s + "\""
43b3da52b84a PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents: 2771
diff changeset
   103
                    end
43b3da52b84a PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents: 2771
diff changeset
   104
                    svccfg("-s", Ldap_fmri, "setprop",
43b3da52b84a PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents: 2771
diff changeset
   105
                           pg + "/" + field.to_s, "=", value)
2771
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
   106
                end
2928
43b3da52b84a PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents: 2771
diff changeset
   107
                @refresh_needed = true
2771
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
   108
            rescue => detail
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
   109
                raise Puppet::Error,
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
   110
                    "Unable to set #{field.to_s} to #{should.inspect}\n"
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
   111
                    "#{detail}\n"
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
   112
            end
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
   113
        end
2928
43b3da52b84a PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents: 2771
diff changeset
   114
    end
2771
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
   115
2928
43b3da52b84a PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents: 2771
diff changeset
   116
    def flush
43b3da52b84a PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents: 2771
diff changeset
   117
        if @refresh_needed == true
43b3da52b84a PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents: 2771
diff changeset
   118
            svccfg("-s", Ldap_fmri, "refresh")
43b3da52b84a PSARC 2013/426 Puppet 3.4.1
Drew Fisher <drew.fisher@oracle.com>
parents: 2771
diff changeset
   119
        end
2771
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
   120
    end
8e4227dc2fc4 16453463 Update Puppet's offerings on Solaris
Virginia Wray <virginia.wray@oracle.com>
parents:
diff changeset
   121
end