#!/bin/bash set -e if [[ ! -e /etc/eole/samba4-vars.conf ]] then exit 0 fi . /etc/eole/samba4-vars.conf function updateSchemaDN() { STR=${1} DN=${2} FILE=${3} sed -i -e "s/${STR}/${DN}/g" ${FILE} return ${?} } function user_exists() { local username="${1}" samba-tool user show "${username}" > /dev/null 2>&1 return ${?} } DN="$(CreoleGet cadolesldap_basedn)" BASEDN="CN=Schema,CN=Configuration,${DN}" INITDIR="/etc/cadolesldap/init" RETURNED=$(ldbsearch --option="dsdb:schema update allowed"=true -H /var/lib/samba/private/sam.ldb -b $BASEDN CN=siren CN | grep "returned.*records") if [ "$RETURNED" = "# returned 0 records" ]; then # Import schema SCHEMAS="cadoles.schema" PRIVATE_DIR=/etc/eole/private for schema in $SCHEMAS do updateSchemaDN "{DNCONFIG}" "${DN}" /etc/ldap/schema/eole/${schema}.ldif if [[ $? -ne 0 ]] then echo "Error updating DN for ${schema}" break fi ldbmodify -H /var/lib/samba/private/sam.ldb /etc/ldap/schema/eole/${schema}.ldif --option="dsdb:schema update allowed"=true if [[ $? -ne 0 ]] then echo "Error updating Schema ${schema} !!" break fi done fi lv1=$(CreoleGet cadolesldap_niveau01name ) RETURNED=$(ldbsearch --option="dsdb:schema update allowed"=true -H /var/lib/samba/private/sam.ldb -b $DN OU=${lv1} OU | grep "#.* entries") if [ "$RETURNED" = "# 0 entries" ]; then ldbmodify -H /var/lib/samba/private/sam.ldb ${INITDIR}/cadolesldap.ldif if [[ -e ${INITDIR}/cadolesindex.ldif ]] then ldbmodify --option="dsdb:schema update allowed"=true -H /var/lib/samba/private/sam.ldb ${INITDIR}/cadolesindex.ldif fi if [[ $(CreoleGet cadolesldap_create_reader non) == "oui" ]] then user=$(CreoleGet cadolesldap_reader) password=$(CreoleGet cadolesldap_reader_pass) if ! user_exists ${user} then echo "Ajout du compte d'écriture dans l'annuaire '$user'... " samba-tool user create --random-password $user samba-tool user setexpiry $user --noexpiry samba-tool user setpassword $user --newpassword="${password}" fi fi if [[ $(CreoleGet cadolesldap_create_writer non) == "oui" ]] then user=$(CreoleGet cadolesldap_writer) password=$(CreoleGet cadolesldap_writer_pass) if ! user_exists ${user} then echo "Ajout du compte d'écriture dans l'annuaire '$user'... " samba-tool user create --random-password $user samba-tool user setexpiry $user --noexpiry samba-tool group addmembers 'Domain Admins' $user samba-tool user setpassword $user --newpassword="${password}" fi fi fi exit 0