components/ruby/puppet/files/solaris/lib/puppet/type/nis.rb
changeset 5438 c068f8c677e8
parent 5437 449f3459d285
child 5439 a006e5bb8577
equal deleted inserted replaced
5437:449f3459d285 5438:c068f8c677e8
     1 #
       
     2 # CDDL HEADER START
       
     3 #
       
     4 # The contents of this file are subject to the terms of the
       
     5 # Common Development and Distribution License (the "License").
       
     6 # You may not use this file except in compliance with the License.
       
     7 #
       
     8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
       
     9 # or http://www.opensolaris.org/os/licensing.
       
    10 # See the License for the specific language governing permissions
       
    11 # and limitations under the License.
       
    12 #
       
    13 # When distributing Covered Code, include this CDDL HEADER in each
       
    14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
       
    15 # If applicable, add the following below this CDDL HEADER, with the
       
    16 # fields enclosed by brackets "[]" replaced with your own identifying
       
    17 # information: Portions Copyright [yyyy] [name of copyright owner]
       
    18 #
       
    19 # CDDL HEADER END
       
    20 #
       
    21 
       
    22 #
       
    23 # Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
       
    24 #
       
    25 
       
    26 require 'ipaddr'
       
    27 require 'puppet/property/list'
       
    28 
       
    29 def valid_hostname?(hostname)
       
    30     return false if hostname.length > 255 or hostname.scan('..').any?
       
    31     hostname = hostname[0...-1] if hostname.index('.', -1)
       
    32     return hostname.split('.').collect { |i|
       
    33         i.size <= 63 and 
       
    34         not (i.rindex('-', 0) or i.index('-', -1) or i.scan(/[^a-z\d-]/i).any?)
       
    35     }.all?
       
    36 end
       
    37 
       
    38 Puppet::Type.newtype(:nis) do
       
    39     @doc = "Manage the configuration of the NIS client for Oracle Solaris"
       
    40 
       
    41     newparam(:name) do
       
    42        desc "The symbolic name for the NIS domain and client settings to use.
       
    43               This name is used for human reference only."
       
    44         isnamevar
       
    45     end
       
    46 
       
    47     newproperty(:domainname) do
       
    48         desc "The NIS domainname"
       
    49     end
       
    50 
       
    51     newproperty(:ypservers, :parent => Puppet::Property::List) do
       
    52         desc "The hosts or IP addresses to use as NIS servers.  Specify
       
    53               multiple entries as an array"
       
    54 
       
    55         # ensure should remains an array
       
    56         def should
       
    57             @should
       
    58         end
       
    59 
       
    60         def insync?(is)
       
    61             is = [] if is == :absent or is.nil?
       
    62             is.sort == self.should.sort
       
    63         end
       
    64 
       
    65         # svcprop returns multivalue entries delimited with a space
       
    66         def delimiter
       
    67             " "
       
    68         end
       
    69 
       
    70         validate do |value|
       
    71             begin
       
    72                 ip = IPAddr.new(value)
       
    73             rescue ArgumentError
       
    74                 # the value wasn't a valid IP address, so check the hostname
       
    75                 raise Puppet::Error, "ypserver entry:  #{value} is 
       
    76                     invalid" if not valid_hostname? value
       
    77             end
       
    78         end
       
    79     end
       
    80 
       
    81     newproperty(:securenets) do
       
    82         desc "Entries for /var/yp/securenets.  Each entry must be a hash.
       
    83               The first element in the hash is either a host or a netmask.
       
    84               The second element must be an IP network address.  Specify
       
    85               multiple entries as separate entries in the hash."
       
    86 
       
    87         def insync?(is)
       
    88             is = {} if is == :absent or is.nil?
       
    89             is.sort == self.should.sort
       
    90         end
       
    91 
       
    92         def should_to_s(newvalue)
       
    93           newvalue.to_s
       
    94         end
       
    95 
       
    96         def is_to_s(currentvalue)
       
    97           currentvalue.to_s
       
    98         end
       
    99     end
       
   100 
       
   101     newproperty(:use_broadcast) do
       
   102         desc "Send a broadcast datagram requesting needed bind information for
       
   103               a specific NIS server."
       
   104         newvalues(:true, :false)
       
   105     end
       
   106 
       
   107     newproperty(:use_ypsetme) do
       
   108         desc "Only allow root on the client to change the binding to a desired
       
   109               server."
       
   110         newvalues(:true, :false)
       
   111     end
       
   112 end