From b9f9a3f1057b044d11c8e33240a365533e701fe7 Mon Sep 17 00:00:00 2001 From: kload Date: Mon, 28 Sep 2015 19:47:43 -0400 Subject: [PATCH] [enh] Add slapd conf regen hook --- data/hooks/conf_regen/.15-nginx.swn | Bin 12288 -> 0 bytes data/hooks/conf_regen/06-slapd | 40 ++++++++++++++++++++++++++++ data/templates/slapd/ldap.conf | 18 +++++++++++++ lib/yunohost/service.py | 9 ++++--- 4 files changed, 63 insertions(+), 4 deletions(-) delete mode 100644 data/hooks/conf_regen/.15-nginx.swn create mode 100644 data/hooks/conf_regen/06-slapd create mode 100644 data/templates/slapd/ldap.conf diff --git a/data/hooks/conf_regen/.15-nginx.swn b/data/hooks/conf_regen/.15-nginx.swn deleted file mode 100644 index 72192c866529e1ce91ae554265e8b90c14a73f9c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2-)me&6vt1+2eplgKcEzZ)6HrV0B0l&(h~nQM2nwwa7De#EN53=o-ejYx3%)65;KNO3=AN1P%$X%iW_#oM z)mQlW-m`@AFwu86@4vpYaxdM!LR2{yV)e2Tj1RecZ*N(@4`M(yb@NGSO$a92n_D+_ zKBz(mt;Wvnc$GUl98_jxtlE4ov!l|!yDYA>ivcmP#K1fZvr8-V%*D-(*mJdWo*#YW zjU_KhvltKqVn7Ut0Wly3#DEwO1OF!jVRni>#DeZ=7WG2&JoT4n^Q%0>fEW-1Vn7Ut z0Wly3#DEwO17bi7h=Kp00bLM1{Qx+P$>ab3?f3uRA0oN~eg;2+AHcWZOYjl!K!aDo zOW+A`ANb=zqTj%;;1}=>_!@i+Zh&1d09U~VP~a@MvqJO}xD9TB&%puM0#AV_K^Hs@ z9s}Q>A^HsL0}U>LbKoni;|uU9xCuT1H^23E5CdZ1 zE(V4rF^ZoTj=ibgDRaZ=ekxaH;_!#GnRs*eE!BIsZnnqW!cBE)d+|aoD-&{+CYvtU z_6oJwyw3eTcdk`))8ValI&mQ8_v`frV~z!+)EHYa&5l?5`&qyJ4IP>Hv5NJ7BqBKJ49*YLgO~H7l_-IN$CS;S*3T^FQX1hUyLd= zM+xOBfZ`(=0e-tOCw$2;9~x84Aw3o?Kz~HJh&>} z%RbDaqbYThg%c7Z)+gPmLzEqV@JT4OgAZofntGYN(&n9`20bh5T}JgnZ82?fF?K(x zp3*4&j`wa?hgx8>f3rzkn=kDM`}X&(^h9~VYVIrL$GS3yd!d4v;$7TNuX7(?DN{Z! z93|%NCU-BUYEC8d&8e<4G}ax@wf5{smFc9_9S=``6DC7~<@M36YtleX-Zy>z=`oz!JSF$h4zI2AKE<8PO}~pY_6CQ;Fs+_f+oe_8+K=f^uGH2& diff --git a/data/hooks/conf_regen/06-slapd b/data/hooks/conf_regen/06-slapd new file mode 100644 index 000000000..05fd81728 --- /dev/null +++ b/data/hooks/conf_regen/06-slapd @@ -0,0 +1,40 @@ +#!/bin/bash +set -e + +force=$1 + +function safe_copy () { + if [ $force ]; then + sudo yunohost service safecopy \ + -s slapd \ + $1 $2 \ + --force + else + sudo yunohost service safecopy \ + -s slapd \ + $1 $2 + fi +} + +cd /usr/share/yunohost/templates/slapd + +safe_copy mailserver.schema /etc/ldap/schema/mailserver.schema +safe_copy ldap.conf /etc/ldap/ldap.conf +safe_copy slapd.default /etc/default/slapd + +# Compatibility: change from HDB to MDB on Jessie +version=$(sed 's/\..*//' /etc/debian_version) +if [[ "$version" == '8' ]]; then + sudo sed -i "s/ hdb/ mdb/g" slapd.conf +fi + +safe_copy slapd.conf /etc/ldap/slapd.conf +sudo chown root:openldap /etc/ldap/slapd.conf +sudo rm -Rf /etc/ldap/slapd.d +sudo mkdir /etc/ldap/slapd.d +sudo chown -R openldap:openldap /etc/ldap/schema/ +sudo chown -R openldap:openldap /etc/ldap/slapd.d/ + +sudo slaptest -f /etc/ldap/slapd.conf -F /etc/ldap/slapd.d/ + +sudo service slapd force-reload diff --git a/data/templates/slapd/ldap.conf b/data/templates/slapd/ldap.conf new file mode 100644 index 000000000..bfd86e8ae --- /dev/null +++ b/data/templates/slapd/ldap.conf @@ -0,0 +1,18 @@ +# +# LDAP Defaults +# + +# See ldap.conf(5) for details +# This file should be world readable but not world writable. + +#BASE dc=example,dc=com +#URI ldap://ldap.example.com ldap://ldap-master.example.com:666 + +#SIZELIMIT 12 +#TIMELIMIT 15 +#DEREF never + +# TLS certificates (needed for GnuTLS) +TLS_CACERT /etc/ssl/certs/ca-certificates.crt + +sudoers_base ou=sudo,dc=yunohost,dc=org diff --git a/lib/yunohost/service.py b/lib/yunohost/service.py index 5bed72e95..9fd264f65 100644 --- a/lib/yunohost/service.py +++ b/lib/yunohost/service.py @@ -511,10 +511,11 @@ def service_safecopy(service, new_conf_file, conf_file, force=False): regenerated = False services = _get_services() - if os.path.exists(new_conf_file): - filename = new_conf_file - with open(filename, 'r') as f: - new_conf = ''.join(f.readlines()).rstrip() + if not os.path.exists(new_conf_file): + raise MoulinetteError(errno.EIO, m18n.n('no_such_conf_file', new_conf_file)) + + with open(new_conf_file, 'r') as f: + new_conf = ''.join(f.readlines()).rstrip() # Backup existing file date = time.strftime("%Y%m%d.%H%M%S")