2 # Cookbook Name:: openldap
5 # Copyright 2013-2016, whitestar
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
43 'reconnect_sleeptime',
44 'reconnect_retrytime',
54 'nss_initgroups_ignoreusers',
58 if node['openldap']['with_ssl_cert_cookbook'] then
59 node.override['openldap']['nss-ldapd']['tls_cacertfile'] \
60 = node['ssl_cert']["#{node['openldap']['ssl_cert']['ca_name']}_cert_path"]
63 case node[:platform_family]
76 supports :status => true, :restart => true, :reload => false
79 resources(:service => 'nscd') rescue service 'nscd' do
81 supports :status => true, :restart => true, :reload => false
84 template '/etc/nslcd.conf' do
85 source 'etc/nslcd.conf'
89 variables({'nslcd_conf_keys' => nslcd_conf_keys})
90 notifies :restart, 'service[nslcd]'
91 notifies :restart, 'service[nscd]'
94 package 'nss-pam-ldapd' do
100 supports :status => true, :restart => true, :reload => true
103 resources(:service => 'nscd') rescue service 'nscd' do
105 supports :status => true, :restart => true, :reload => true
108 template '/etc/nslcd.conf' do
109 source 'etc/nslcd.conf'
113 variables({'nslcd_conf_keys' => nslcd_conf_keys})
114 notifies :restart, 'service[nslcd]'
115 notifies :restart, 'service[nscd]'
119 ruby_block 'configuring_nameservices' do
121 conf_file = '/etc/nsswitch.conf'
122 nameservices = node['openldap']['ldap_lookup_nameservices']
123 if !nameservices.nil? && !nameservices.empty? then
124 open(conf_file, 'r+') {|file|
125 file.flock(File::LOCK_EX)
129 if line =~ /^(\w+):\s+(.*)$/ then
130 if nameservices.include?($1) && !$2.include?('ldap')
131 line.chomp! << " ldap\n"
138 print "\nnew #{conf_file}: [#{buf}]"
141 file.truncate(file.tell)
147 notifies :restart, 'service[nscd]'