<commit_before>#
# Cookbook Name:: openldap
# Recipe:: users
#
# Copyright 2013, <NAME>, computerlyrik
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#


::Chef::Recipe.send(:include, Opscode::OpenSSL::Password)

################################################
# Set up a anon user for auth and search purpose
################################################
node.set_unless['openldap']['anon_user'] = "anon"
node.set_unless['openldap']['anon_binddn'] = "cn=#{node['openldap']['anon_user']},#{node['openldap']['basedn']}"
unless node['openldap']['anon_pass']
  node.set['openldap']['anon_pass'] = <PASSWORD>
  anon_pass = Mixlib::ShellOut.new("slappasswd -h {ssha} -s #{node['openldap']['anon_pass']}").run_command
  Chef::Log.info(anon_pass.stdout)
  node.set['openldap']['anon_hash'] = anon_pass.stdout.chomp
end


openldap_node node['openldap']['anon_binddn'] do
  attributes ({
    :objectClass => ["organizationalRole","shadowAccount" ],
    :uid => node['openldap']['anon_user'],
    :userPassword => node['openldap']['anon_hash']
  })
end
  
=begin UNUSED
openldap_config "olcDatabase={1}hdb,cn=config" do
  attributes ({
    :olcDbDirectory => node['openldap']['db_dir'],
    :olcSuffix => node['openldap']['basedn'],
    :olcAccess => [ 
      "{0}to attrs=userPassword,shadowLastChange 
          by self write 
          by anonymous auth 
          by dn=\"#{node['openldap']['rootdn']}\" write 
          by dn=\"#{node['openldap']['anon_binddn']}\" read 
          by * none",
      "{1}to dn.base="" 
          by * read",
      "{2}to * 
          by self write 
          by dn=\"#{node['openldap']['rootdn']}\" write 
          by dn=\"#{node['openldap']['anon_binddn']}\" read"
    ],
    :olcLastMod => "TRUE",
    :olcRootDN => node['openldap']['rootdn'],
    :olcRootPW => node['openldap']['roothash']
  })
end
=end

################################################
# Set up a structure for users and groups
################################################

openldap_node "ou=Users,#{node['openldap']['basedn']}" do
  attributes ({
    :objectClass => ["organizationalUnit", "top"],
    :ou => "Users"
  })<commit_msg>enabled auth settings on users secipe<commit_after>#
# Cookbook Name:: openldap
# Recipe:: users
#
# Copyright 2013, <NAME>, computerlyrik
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#


::Chef::Recipe.send(:include, Opscode::OpenSSL::Password)

################################################
# Set up a anon user for auth and search purpose
################################################
node.set_unless['openldap']['anon_user'] = "anon"
node.set_unless['openldap']['anon_binddn'] = "cn=#{node['openldap']['anon_user']},#{node['openldap']['basedn']}"
unless node['openldap']['anon_pass']
  node.set['openldap']['anon_pass'] = secure_password
  anon_pass = Mixlib::ShellOut.new("slappasswd -h {ssha} -s #{node['openldap']['anon_pass']}").run_command
  Chef::Log.info(anon_pass.stdout)
  node.set['openldap']['anon_hash'] = anon_pass.stdout.chomp
end


openldap_node node['openldap']['anon_binddn'] do
  attributes ({
    :objectClass => ["organizationalRole","shadowAccount" ],
    :uid => node['openldap']['anon_user'],
    :userPassword => node['openldap']['anon_hash']
  })
end
  
openldap_config "olcDatabase={1}hdb,cn=config" do
  attributes ({
    :olcDbDirectory => node['openldap']['db_dir'],
    :olcSuffix => node['openldap']['basedn'],
    :olcAccess => [ 
      "{0}to attrs=userPassword,shadowLastChange 
          by self write 
          by anonymous auth 
          by dn=\"#{node['openldap']['rootdn']}\" write 
          by dn=\"#{node['openldap']['anon_binddn']}\" read 
          by * none",
      "{1}to dn.base="" 
          by * read",
      "{2}to * 
          by self write 
          by dn=\"#{node['openldap']['rootdn']}\" write 
          by dn=\"#{node['openldap']['anon_binddn']}\" read"
    ],
    :olcLastMod => "TRUE",
    :olcRootDN => node['openldap']['rootdn'],
    :olcRootPW => node['openldap']['roothash']
  })
end

################################################
# Set up a structure for users and groups
################################################

openldap_node "ou=Users,#{node['openldap']['basedn']}" do
  attributes ({
    :objectClass => ["organizationalUnit", "top"],
    :ou => "Users"
  })
{'fraction_non_alphanumeric': 0.22986767485822307, 'fraction_numerical': 0.004536862003780718, 'mean_word_length': 4.505723204994797, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3049669', 'n_tokens_mistral': 1663, 'n_tokens_neox': 1627, 'n_words': 392}