From 001f998037a041affe4a8e2fb63afa632903e077 Mon Sep 17 00:00:00 2001 From: Chao Luan Date: Tue, 27 Jan 2015 16:28:09 +1100 Subject: [PATCH] Properly split the domain name to support more than two levels of domain component (dc) --- tasks/configure_ldap.yml | 2 +- templates/domain.ldif | 2 +- templates/ldap.conf.j2 | 2 +- templates/slapd.conf.j2 | 8 ++++---- templates/slapd.conf_ubuntu.j2 | 8 ++++---- vars/main.yml | 4 ++-- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/tasks/configure_ldap.yml b/tasks/configure_ldap.yml index 3c561da..3dd6a74 100644 --- a/tasks/configure_ldap.yml +++ b/tasks/configure_ldap.yml @@ -44,4 +44,4 @@ register: result - name: add the base domain - shell: ldapadd -x -D "cn=Manager,dc={{ openldap_server_domain_name.split('.')[0] }},dc={{ openldap_server_domain_name.split('.')[1] }}" -w {{ openldap_server_rootpw }} -f {{ result.dest }} && touch {{ openldap_server_app_path }}/rootdn_created creates={{ openldap_server_app_path }}/rootdn_created + shell: ldapadd -x -D "cn=Manager,{{ domain_component }}" -w {{ openldap_server_rootpw }} -f {{ result.dest }} && touch {{ openldap_server_app_path }}/rootdn_created creates={{ openldap_server_app_path }}/rootdn_created diff --git a/templates/domain.ldif b/templates/domain.ldif index dab1703..71aa57b 100644 --- a/templates/domain.ldif +++ b/templates/domain.ldif @@ -1,4 +1,4 @@ -dn: dc={{ openldap_server_domain_name.split('.')[0] }},dc={{ openldap_server_domain_name.split('.')[1] }} +dn: {{ domain_component }} objectClass: domain dc: {{ openldap_server_domain_name.split('.')[0] }} diff --git a/templates/ldap.conf.j2 b/templates/ldap.conf.j2 index 6f8d3fc..f32eadd 100644 --- a/templates/ldap.conf.j2 +++ b/templates/ldap.conf.j2 @@ -5,7 +5,7 @@ # See ldap.conf(5) for details # This file should be world readable but not world writable. -BASE dc={{ openldap_server_domain_name.split('.')[0] }},dc={{ openldap_server_domain_name.split('.')[1] }} +BASE {{ domain_component }} {% if openldap_server_enable_ssl %} URI ldaps://localhost TLS_REQCERT never diff --git a/templates/slapd.conf.j2 b/templates/slapd.conf.j2 index 3f699d5..0cc8094 100644 --- a/templates/slapd.conf.j2 +++ b/templates/slapd.conf.j2 @@ -8,20 +8,20 @@ modulepath /usr/lib64/openldap access to * by self write - by dn.base="cn=Manager,dc={{ openldap_server_domain_name.split('.')[0] }},dc={{ openldap_server_domain_name.split('.')[1] }}" write + by dn.base="cn=Manager,{{ domain_component }}" write by * read access to attrs=userPassword by self write by anonymous auth - by dn.base="cn=Manager,dc={{ openldap_server_domain_name.split('.')[0] }},dc={{ openldap_server_domain_name.split('.')[1] }}" write + by dn.base="cn=Manager,{{ domain_component }}" write by * none access to attrs=shadowLastChange by self write by * read database bdb -suffix "dc={{ openldap_server_domain_name.split('.')[0] }},dc={{ openldap_server_domain_name.split('.')[1] }}" -rootdn "cn=Manager,dc={{ openldap_server_domain_name.split('.')[0] }},dc={{ openldap_server_domain_name.split('.')[1] }}" +suffix "{{domain_component}}" +rootdn "cn=Manager,{{domain_component}}" rootpw {{ root_password.stdout }} #This directory has to be created and would contain the ldap database. directory /var/lib/ldap/{{ openldap_server_domain_name }}/ diff --git a/templates/slapd.conf_ubuntu.j2 b/templates/slapd.conf_ubuntu.j2 index f256ed6..82052ae 100644 --- a/templates/slapd.conf_ubuntu.j2 +++ b/templates/slapd.conf_ubuntu.j2 @@ -14,20 +14,20 @@ moduleload back_bdb.la access to * by self write - by dn.base="cn=Manager,dc={{ openldap_server_domain_name.split('.')[0] }},dc={{ openldap_server_domain_name.split('.')[1] }}" write + by dn.base="cn=Manager,{{domain_component}}" write by * read access to attrs=userPassword by self write by anonymous auth - by dn.base="cn=Manager,dc={{ openldap_server_domain_name.split('.')[0] }},dc={{ openldap_server_domain_name.split('.')[1] }}" write + by dn.base="cn=Manager,{{domain_component}}" write by * none access to attrs=shadowLastChange by self write by * read database bdb -suffix "dc={{ openldap_server_domain_name.split('.')[0] }},dc={{ openldap_server_domain_name.split('.')[1] }}" -rootdn "cn=Manager,dc={{ openldap_server_domain_name.split('.')[0] }},dc={{ openldap_server_domain_name.split('.')[1] }}" +suffix "{{domain_component}}" +rootdn "cn=Manager,{{domain_component}}" rootpw {{ root_password.stdout }} #This directory has to be created and would contain the ldap database. directory /var/lib/ldap/{{ openldap_server_domain_name }}/ diff --git a/vars/main.yml b/vars/main.yml index c3fd52f..a7385e0 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,4 +1,4 @@ --- - +domain_component: "dc={{ openldap_server_domain_name.split('.') | join(',dc=') }}" env: - RUNLEVEL: 1 + RUNLEVEL: 1 \ No newline at end of file