|
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, 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(:domainname) do |
|
42 desc "The NIS domainname" |
|
43 isnamevar |
|
44 end |
|
45 |
|
46 newproperty(:ypservers, :parent => Puppet::Property::List) do |
|
47 desc "The hosts or IP addresses to use as NIS servers. Specify |
|
48 multiple entries as an array" |
|
49 |
|
50 # ensure should remains an array |
|
51 def should |
|
52 @should |
|
53 end |
|
54 |
|
55 def insync?(is) |
|
56 is = [] if is == :absent or is.nil? |
|
57 is.sort == self.should.sort |
|
58 end |
|
59 |
|
60 # svcprop returns multivalue entries delimited with a space |
|
61 def delimiter |
|
62 " " |
|
63 end |
|
64 |
|
65 validate do |value| |
|
66 begin |
|
67 ip = IPAddr.new(value) |
|
68 rescue ArgumentError |
|
69 # the value wasn't a valid IP address, so check the hostname |
|
70 raise Puppet::Error, "ypserver entry: #{value} is |
|
71 invalid" if not valid_hostname? value |
|
72 end |
|
73 end |
|
74 end |
|
75 |
|
76 newproperty(:securenets, :parent => Puppet::Property::List) do |
|
77 desc "Entries for /var/yp/securenets. Each entry must be a 2 element |
|
78 array. The first element must be either a host or a netmask. |
|
79 The second element must be an IP network address. Specify |
|
80 multiple entires as an array of arrays" |
|
81 |
|
82 # ensure should remains an array |
|
83 def should |
|
84 @should |
|
85 end |
|
86 |
|
87 def insync?(is) |
|
88 is = [] if is == :absent or is.nil? |
|
89 is.sort == self.should.sort |
|
90 end |
|
91 |
|
92 # svcprop returns multivalue entries delimited with a space |
|
93 def delimiter |
|
94 " " |
|
95 end |
|
96 |
|
97 validate do |value| |
|
98 netmask, network = value |
|
99 # check the netmask |
|
100 begin |
|
101 ip = IPAddr.new(netmask) |
|
102 rescue ArgumentError |
|
103 # the value wasn't a valid IP address, so check the hostname |
|
104 raise Puppet::Error, "securenets entry: #{value} has an |
|
105 invalid netmask" if not valid_hostname? netmask |
|
106 end |
|
107 |
|
108 begin |
|
109 ip = IPAddr.net(network) |
|
110 rescue ArgumentError |
|
111 # the value wasn't a valid IP address |
|
112 raise Puppet::Error, "securenets entry: #{value} has an |
|
113 invalid network" |
|
114 end |
|
115 end |
|
116 end |
|
117 |
|
118 newproperty(:use_broadcast) do |
|
119 desc "Send a broadcast datagram requesting needed bind information for |
|
120 a specific NIS server. Valid vales are true, false" |
|
121 newvalues(:true, :false) |
|
122 end |
|
123 |
|
124 newproperty(:use_ypsetme) do |
|
125 desc "Only allow root on the client to change the binding to a desired |
|
126 server. Valid values are true, false" |
|
127 newvalues(:true, :false) |
|
128 end |
|
129 end |