#!/bin/bash
########################################################################
## Script : ldap-loglevel.sh
## Name : LDAP のログレベル変更スクリプト
## Version : 0.0.1
## Copyright : 2019 Nomura Kei
## License : BSD-2-Clause
## Usage:
## |使用法) ldap-loglevel.sh [オプション] [LogLevel]
## |
## | LDAP のログレベルを設定します。
## | LogLevel の指定が無い場合、stats を設定します。
## | LogLevel には次の Level の値または、Keyword の文字列を指定可能である。
## | 複数指定する場合は、Level の値を OR した値を指定すれば良い。
## |
## | Level Level(Hex) Keyword Description
## | -1 any enable all debugging
## | 0 no debugging (ログ出力なし)
## | 1 0x1 trace trace function calls
## | 2 0x2 packets debug packet handling
## | 4 0x4 args heavy trace debugging
## | 8 0x8 conns connection management
## | 16 0x10 BER print out packets sent and received
## | 32 0x20 filter search filter processing
## | 64 0x40 config configuration processing
## | 128 0x80 ACL access control list processing
## | 256 0x100 stats stats log connections/operations/results
## | 512 0x200 stats2 stats log entries sent
## | 1024 0x400 shell print communication with shell backends
## | 2048 0x800 parse print entry parsing debugging
## | 16384 0x4000 sync syncrepl consumer processing
## | 32768 0x8000 none only messages that get logged whatever log level is set
## |
## | 詳細は、https://www.openldap.org/doc/admin24/slapdconfig.html を参照のこと。
## |
## |[オプション]
## | -h,--help 使用法を表示します。
## | -v,--version バージョンを表示します。
## |
##
########################################################################
SCRIPT_FILE=${0}
SCRIPT_DIR=`dirname ${SCRIPT_FILE}`
LIB_DIR=${SCRIPT_DIR}/../lib
########################################################################
##
## ライブラリのロード
##
[ -f "${LIB_DIR}/functions.sh" ] && . ${LIB_DIR}/bash-utils.sh
########################################################################
##
## デフォルト値
##
LOG_LEVEL=stats
########################################################################
##
## 関数群
##
# ======================================================================
# LDAP のログレベルを指定されたログレベルに変更する
# ldif 形式のデータを標準出力します。
#
# @param $1 ログレベル
# ======================================================================
mkldif_for_change_loglevel()
{
cat << EOF
dn: cn=config
changeType: modify
replace: olcLogLevel
olcLogLevel: ${LOG_LEVEL}
EOF
}
########################################################################
##
## メイン処理
##
for OPT in "$@"; do
case "${OPT}" in
'-h'|'--help') usage; exit 1 ;;
'-v'|'--version') version; exit 1 ;;
-*)
usage
exit 1
;;
*)
if [[ ! -z "$1" ]] && [[ ! "$1" =~ ^-+ ]]; then
LOG_LEVEL=("$1")
shift 1
fi
;;
esac
done
TMP_LDIF=$(mktemp /tmp/ldap.XXXXXXXXXXXX.ldif)
trap 'rm -f ${TMP_LDIF}; exit 1' 1 2 3 15
mkldif_for_change_loglevel ${LOG_LEVEL} > ${TMP_LDIF}
ldapmodify -Y EXTERNAL -H ldapi:/// -f ${TMP_LDIF}
ldapsearch -Y EXTERNAL -H ldapi:/// -b 'cn=config' cn=config
rm -f ${TMP_LDIF}