#!/bin/sh -f

# if we are not server 
[ -f /etc/sysconfig/system ] || exit 0

. /etc/sysconfig/system

[ "$SERVER_ROLE" = "master" ] || exit 0

. shell-quote
. shell-config

enable_schema()
{
    local samba="$(quote_sed_regexp "/etc/openldap/schema/samba3.schema")"
    local kerberos="$(quote_sed_regexp "/etc/openldap/schema/kerberos.schema")"
    local conf="/etc/openldap/slapd.conf"

    sed -i -r -e "s,^[[:space:]]*#[[:space:]]*include[[:space:]]+$samba,include\t\t$samba\ninclude\t\t$kerberos\n," "$conf"
}

enable_server()
{
    local SLAPD_CONF_DIR="/etc/openldap"
    local LDAP_SYSCONFIG="/etc/sysconfig/ldap"
    local LDAP_CONF="$SLAPD_CONF_DIR/ldap.conf"
    local url="ldap:///"

    shell_config_set "$LDAP_SYSCONFIG" SLAPDURLLIST "\"'$url'\""
    shell_config_set "$LDAP_CONF" URI "$url" ' ' ' '
}


enable_schema
enable_server
