From 8daa83a594a2e98f39d764422bfbdbc62c9efd44 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 19:20:00 +0200 Subject: Adding upstream version 2:4.20.0+dfsg. Signed-off-by: Daniel Baumann --- examples/ad-bench/README | 42 ++++++++++++ examples/ad-bench/ad-bench.sh | 38 +++++++++++ examples/ad-bench/settings.sh | 40 +++++++++++ examples/ad-bench/test_utils.sh | 29 ++++++++ examples/ad-bench/time_group.sh | 131 ++++++++++++++++++++++++++++++++++++ examples/ad-bench/time_join.sh | 89 +++++++++++++++++++++++++ examples/ad-bench/time_kinit.sh | 65 ++++++++++++++++++ examples/ad-bench/time_ldap.sh | 144 ++++++++++++++++++++++++++++++++++++++++ examples/ad-bench/time_user.sh | 131 ++++++++++++++++++++++++++++++++++++ examples/ad-bench/utils.sh | 130 ++++++++++++++++++++++++++++++++++++ 10 files changed, 839 insertions(+) create mode 100644 examples/ad-bench/README create mode 100755 examples/ad-bench/ad-bench.sh create mode 100644 examples/ad-bench/settings.sh create mode 100644 examples/ad-bench/test_utils.sh create mode 100644 examples/ad-bench/time_group.sh create mode 100644 examples/ad-bench/time_join.sh create mode 100644 examples/ad-bench/time_kinit.sh create mode 100644 examples/ad-bench/time_ldap.sh create mode 100644 examples/ad-bench/time_user.sh create mode 100644 examples/ad-bench/utils.sh (limited to 'examples/ad-bench') diff --git a/examples/ad-bench/README b/examples/ad-bench/README new file mode 100644 index 0000000..de6235f --- /dev/null +++ b/examples/ad-bench/README @@ -0,0 +1,42 @@ +========================== +Active Directory benchmark +========================== + +Setup +===== + +You need to modify settings.sh to point to the correct binaries for your +platform. One thing you might want to do in order to be able to run the +benchmark as a non-root user is to compile your own samba version with the +--prefix configure option set to some location writeable by the user who will be +running the benchmark. You then need to point the NET variable to the correct +location. + +Most likely, you will also want to put the realm to kdc hostname mappings into +krb5.conf and the hostname to IP address mappings for the kdcs to test into the +hosts file, so you actually benchmark the AD speed, not DNS lookup speed. + +Running the benchmarks +====================== + +Per default, the benchmark looks for a file called runs.txt in the directory the +benchmark is run from. (This is configurable in the settings.sh file) +runs.txt contains the credentials and server names to connect to, one set of +credentials/server per line. The format is as follows: + +user@REALM.EXAMPLE.COM%password:domain_controller_host_name + +License +======= +AD-Bench is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +AD-Bench is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with AD-Bench. If not, see . diff --git a/examples/ad-bench/ad-bench.sh b/examples/ad-bench/ad-bench.sh new file mode 100755 index 0000000..c4c2a4a --- /dev/null +++ b/examples/ad-bench/ad-bench.sh @@ -0,0 +1,38 @@ +#!/bin/bash +# AD-Bench main program, runs all the benchmarks +# +# Copyright (C) 2009 Kai Blin +# +# This file is part of AD-Bench, an Active Directory benchmark tool +# +# AD-Bench is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# AD-Bench is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with AD-Bench. If not, see . + +source $(dirname $0)/utils.sh + +if [ ! -f $RUNS ]; then + echo "Error: please fill in $RUNS" + echo "Sambple entries are" + echo "user@REALM.EXAMPLE.COM%password:domain_controller" + exit 1 +fi + +for run in $(cat $RUNS); do + echo "START RUN" + bash $(dirname $0)/time_kinit.sh $(echo $run | cut -d ":" -f 1) + bash $(dirname $0)/time_join.sh $(echo $run | cut -d ":" -f 1) $(echo $run | cut -d ":" -f 2) + bash $(dirname $0)/time_user.sh $(echo $run | cut -d ":" -f 1) $(echo $run | cut -d ":" -f 2) + bash $(dirname $0)/time_group.sh $(echo $run | cut -d ":" -f 1) $(echo $run | cut -d ":" -f 2) + bash $(dirname $0)/time_ldap.sh $(echo $run | cut -d ":" -f 1) $(echo $run | cut -d ":" -f 2) + echo "END RUN" +done diff --git a/examples/ad-bench/settings.sh b/examples/ad-bench/settings.sh new file mode 100644 index 0000000..b4a68ae --- /dev/null +++ b/examples/ad-bench/settings.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# AD-Bench settings +# +# Copyright (C) 2009 Kai Blin +# +# This file is part of AD-Bench, an Active Directory benchmark tool +# +# AD-Bench is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# AD-Bench is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with AD-Bench. If not, see . + +DATE=date +BC=bc +SED=sed +DATE_FORMATSTR="+%s.%N" + +KINIT=kinit +# MIT krb < 1.6 +KINIT_PARAM_OLD="--password-file=STDIN" +# MIT krb >= 1.6 +KINIT_PARAM_NEW="" + +KDESTROY=kdestroy +SEQ=seq + +NEW_KRB5CCNAME=/tmp/ad_test_ccname + +NET="${HOME}/samba/bin/net" +CONFIG_FILE=$(dirname $0)/smb.conf + +RUNS=$(dirname $0)/runs.txt diff --git a/examples/ad-bench/test_utils.sh b/examples/ad-bench/test_utils.sh new file mode 100644 index 0000000..2580c9d --- /dev/null +++ b/examples/ad-bench/test_utils.sh @@ -0,0 +1,29 @@ +#!/bin/bash +# AD-Bench utility function tests +# +# Copyright (C) 2009 Kai Blin +# +# This file is part of AD-Bench, an Active Directory benchmark tool +# +# AD-Bench is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# AD-Bench is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with AD-Bench. If not, see . + +source $(dirname $0)/utils.sh + +INPUT="administrator@AD.EXAMPLE.COM%secret" +echo "Principal for $INPUT is " $(get_principal $INPUT) +echo "Password for $INPUT is " $(get_password $INPUT) +echo "Realm for $INPUT is " $(get_realm $INPUT) +echo "NT_DOM for $INPUT is " $(get_nt_dom $INPUT) + +echo "Padding 2: " $(pad_number 1 2) " 4: " $(pad_number 23 4) diff --git a/examples/ad-bench/time_group.sh b/examples/ad-bench/time_group.sh new file mode 100644 index 0000000..be47aac --- /dev/null +++ b/examples/ad-bench/time_group.sh @@ -0,0 +1,131 @@ +#!/bin/bash +# AD-Bench group add/remove benchmark +# +# Copyright (C) 2009 Kai Blin +# +# This file is part of AD-Bench, an Active Directory benchmark tool +# +# AD-Bench is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# AD-Bench is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with AD-Bench. If not, see . + +ITERATIONS=100 + +source $(dirname $0)/utils.sh + +PRINCIPAL=$(get_principal $1) +PASSWORD=$(get_password $1) +REALM=$(get_realm $1) +NT_DOM=$(get_nt_dom $1) +SERVER=$2 + +add_group() +{ + GROUP=$1 + ${NET} ads group add "${GROUP}" -k --configfile=$CONFIG_FILE -S ${SERVER} >/dev/null + RET=$? + if [ $RET -ne 0 ]; then + echo "${NET} ads group add returned error: $RET" + exit 1 + fi +} + +del_group() +{ + GROUP=$1 + ${NET} ads group delete "${GROUP}" -k --configfile=$CONFIG_FILE -S ${SERVER} >/dev/null + RET=$? + if [ $RET -ne 0 ]; then + echo "${NET} returned error: $RET" + exit 1 + fi +} + +enum_group() +{ + ${NET} ads group -k --configfile=$CONFIG_FILE -S $SERVER >/dev/null + RET=$? + if [ $RET -ne 0 ]; then + echo "${NET} returned error: $RET" + exit 1 + fi +} + +info_group() +{ + GROUP=$1 + ${NET} ads group info "${GROUP}" -k --configfile=$CONFIG_FILE -S ${SERVER} >/dev/null + RET=$? + if [ $RET -ne 0 ]; then + echo "${NET} returned error: $RET" + exit 1 + fi +} + +set_up() +{ + set_krb_env + setup_kinit + call_kinit "${PRINCIPAL}" "${PASSWORD}" + write_configfile "${REALM}" "${NT_DOM}" +} + +tear_down() +{ + ${KDESTROY} + restore_krb_env +} + +set_up + +echo -e "\tGROUP $SERVER" + +START_TIME=$(start_timer) + +echo -en "\t" +for i in $(${SEQ} 1 $ITERATIONS); do + GROUP=$(echo "ad_test_$(pad_number $i 3)") + add_group $GROUP + echo -n "." +done +echo "done" + +enum_group + +# Requires winbind, which requires root perms to start. Skip this for now +#echo -en "\t" +#for i in $( ${SEQ} 1 $ITERATIONS ); do +# GROUP=$( echo "ad_test_$(pad_number $i 3)" ) +# info_group $GROUP +# echo -n "." +#done +#echo "done" + +echo -en "\t" +for i in $(${SEQ} 1 $ITERATIONS); do + GROUP=$(echo "ad_test_$(pad_number $i 3)") + del_group $GROUP + echo -n "." +done +echo "done" + +STOP_TIME=$(stop_timer) + +TOTAL_TIME=$(total_time $START_TIME $STOP_TIME) + +echo -e "\t\ttotal time:\t\t${TOTAL_TIME}s" + +LOGINS_PER_MINUTE=$(iterations_per_minute $START_TIME $STOP_TIME $ITERATIONS) + +echo -e "\t\titerations/min:\t\t$LOGINS_PER_MINUTE" + +tear_down diff --git a/examples/ad-bench/time_join.sh b/examples/ad-bench/time_join.sh new file mode 100644 index 0000000..2545a9f --- /dev/null +++ b/examples/ad-bench/time_join.sh @@ -0,0 +1,89 @@ +#!/bin/bash +# AD-Bench Machine join/part benchmark +# +# Copyright (C) 2009 Kai Blin +# +# This file is part of AD-Bench, an Active Directory benchmark tool +# +# AD-Bench is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# AD-Bench is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with AD-Bench. If not, see . + +ITERATIONS=100 + +source $(dirname $0)/utils.sh + +PRINCIPAL=$(get_principal $1) +PASSWORD=$(get_password $1) +REALM=$(get_realm $1) +NT_DOM=$(get_nt_dom $1) + +join_domain() +{ + SERVER=$1 + ${NET} ads join -k --configfile=$CONFIG_FILE -S ${SERVER} >/dev/null + RET=$? + if [ $RET -ne 0 ]; then + echo "${NET} returned error: $RET" + exit 1 + fi +} + +leave_domain() +{ + SERVER=$1 + ${NET} ads leave -k --configfile=$CONFIG_FILE -S ${SERVER} >/dev/null + if [ $RET -ne 0 ]; then + echo "${NET} returned error: $RET" + exit 1 + fi +} + +set_up() +{ + set_krb_env + setup_kinit + call_kinit "${PRINCIPAL}" "${PASSWORD}" + write_configfile "${REALM}" "${NT_DOM}" +} + +tear_down() +{ + ${KDESTROY} + restore_krb_env +} + +set_up + +echo -e "\tJOIN $2" + +START_TIME=$(start_timer) + +echo -en "\t" +for i in $(${SEQ} 1 $ITERATIONS); do + join_domain $2 + leave_domain $2 + echo -n "." +done +echo "done" + +STOP_TIME=$(stop_timer) + +TOTAL_TIME=$(total_time $START_TIME $STOP_TIME) + +echo -e "\t\ttotal time:\t\t${TOTAL_TIME}s" + +LOGINS_PER_MINUTE=$(iterations_per_minute $START_TIME $STOP_TIME $ITERATIONS) + +echo -e "\t\titerations/min:\t\t$LOGINS_PER_MINUTE" + +tear_down diff --git a/examples/ad-bench/time_kinit.sh b/examples/ad-bench/time_kinit.sh new file mode 100644 index 0000000..b2e0030 --- /dev/null +++ b/examples/ad-bench/time_kinit.sh @@ -0,0 +1,65 @@ +#!/bin/bash +# AD-Bench Kerberos ticket benchmark +# +# Copyright (C) 2009 Kai Blin +# +# This file is part of AD-Bench, an Active Directory benchmark tool. +# +# AD-Bench is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# AD-Bench is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with AD-Bench. If not, see . + +# Iterations are set per test, so more time-consuming tests can be run less +# often +ITERATIONS=100 + +source $(dirname $0)/utils.sh + +set_up() +{ + set_krb_env + setup_kinit +} + +tear_down() +{ + restore_krb_env +} + +set_up + +PRINCIPAL=$(get_principal $1) +PASSWORD=$(get_password $1) + +echo -e "\tKINIT ${PRINCIPAL}" + +START_TIME=$(start_timer) + +echo -en "\t" +for i in $(${SEQ} 1 $ITERATIONS); do + call_kinit "${PRINCIPAL}" "${PASSWORD}" + ${KDESTROY} + echo -n "." +done +echo "done" + +STOP_TIME=$(stop_timer) + +TOTAL_TIME=$(total_time $START_TIME $STOP_TIME) + +echo -e "\t\ttotal time:\t\t${TOTAL_TIME}s" + +LOGINS_PER_MINUTE=$(iterations_per_minute $START_TIME $STOP_TIME $ITERATIONS) + +echo -e "\t\titerations/min:\t\t$LOGINS_PER_MINUTE" + +tear_down diff --git a/examples/ad-bench/time_ldap.sh b/examples/ad-bench/time_ldap.sh new file mode 100644 index 0000000..4af6ef1 --- /dev/null +++ b/examples/ad-bench/time_ldap.sh @@ -0,0 +1,144 @@ +#!/bin/bash + +ITERATIONS=100 + +source $(dirname $0)/utils.sh + +PRINCIPAL=$(get_principal $1) +PASSWORD=$(get_password $1) +REALM=$(get_realm $1) +NT_DOM=$(get_nt_dom $1) +SERVER=$2 + +search_users() +{ + ${NET} ads search '(objectCategory=user)' sAMAccountName -k --configfile=$CONFIG_FILE -S ${SERVER} >/dev/null + RET=$? + if [ $RET -ne 0 ]; then + echo "${NET} returned error: $RET" + exit 1 + fi +} + +search_groups() +{ + ${NET} ads search '(objectCategory=group)' sAMAccountName -k --configfile=$CONFIG_FILE -S ${SERVER} >/dev/null + if [ $RET -ne 0 ]; then + echo "${NET} returned error: $RET" + exit 1 + fi +} + +search_computers() +{ + ${NET} ads search '(objectCategory=computer)' sAMAccountName -k --configfile=$CONFIG_FILE -S ${SERVER} >/dev/null + if [ $RET -ne 0 ]; then + echo "${NET} returned error: $RET" + exit 1 + fi +} + +search_wildcard() +{ + ${NET} ads search '(objectCategory=*)' sAMAccountName -k --configfile=$CONFIG_FILE -S ${SERVER} >/dev/null + if [ $RET -ne 0 ]; then + echo "${NET} returned error: $RET" + exit 1 + fi +} + +search_unindexed() +{ + ${NET} ads search '(description=Built-in account for adminstering the computer/domain)' sAMAccountName -k --configfile=$CONFIG_FILE -S ${SERVER} >/dev/null + if [ $RET -ne 0 ]; then + echo "${NET} returned error: $RET" + exit 1 + fi +} + +set_up() +{ + set_krb_env + setup_kinit + call_kinit "${PRINCIPAL}" "${PASSWORD}" + write_configfile "${REALM}" "${NT_DOM}" +} + +tear_down() +{ + ${KDESTROY} + restore_krb_env +} + +set_up + +echo -e "\tSEARCH INDEXED $2" + +START_TIME=$(start_timer) + +echo -en "\t" +for i in $(${SEQ} 1 $ITERATIONS); do + search_users + search_groups + search_computers + echo -n "." +done +echo "done" + +STOP_TIME=$(stop_timer) + +TOTAL_TIME=$(total_time $START_TIME $STOP_TIME) + +echo -e "\t\ttotal time:\t\t${TOTAL_TIME}s" + +LOGINS_PER_MINUTE=$(iterations_per_minute $START_TIME $STOP_TIME $ITERATIONS) + +echo -e "\t\titerations/min:\t\t$LOGINS_PER_MINUTE" + +######################## + +echo -e "\tSEARCH WILDCARD $2" + +START_TIME=$(start_timer) + +echo -en "\t" +for i in $(${SEQ} 1 $ITERATIONS); do + search_wildcard + echo -n "." +done +echo "done" + +STOP_TIME=$(stop_timer) + +TOTAL_TIME=$(total_time $START_TIME $STOP_TIME) + +echo -e "\t\ttotal time:\t\t${TOTAL_TIME}s" + +LOGINS_PER_MINUTE=$(iterations_per_minute $START_TIME $STOP_TIME $ITERATIONS) + +echo -e "\t\titerations/min:\t\t$LOGINS_PER_MINUTE" + +######################## + +echo -e "\tSEARCH UNINDEXED $2" + +START_TIME=$(start_timer) + +echo -en "\t" +for i in $(${SEQ} 1 $ITERATIONS); do + search_unindexed + echo -n "." +done +echo "done" + +STOP_TIME=$(stop_timer) + +TOTAL_TIME=$(total_time $START_TIME $STOP_TIME) + +echo -e "\t\ttotal time:\t\t${TOTAL_TIME}s" + +LOGINS_PER_MINUTE=$(iterations_per_minute $START_TIME $STOP_TIME $ITERATIONS) + +echo -e "\t\titerations/min:\t\t$LOGINS_PER_MINUTE" + +tear_down diff --git a/examples/ad-bench/time_user.sh b/examples/ad-bench/time_user.sh new file mode 100644 index 0000000..5fedb7a --- /dev/null +++ b/examples/ad-bench/time_user.sh @@ -0,0 +1,131 @@ +#!/bin/bash +# AD-Bench user add/remove benchmark +# +# Copyright (C) 2009 Kai Blin +# +# This file is part of AD-Bench, an Active Directory benchmark tool +# +# AD-Bench is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# AD-Bench is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with AD-Bench. If not, see . + +ITERATIONS=100 + +source $(dirname $0)/utils.sh + +PRINCIPAL=$(get_principal $1) +PASSWORD=$(get_password $1) +REALM=$(get_realm $1) +NT_DOM=$(get_nt_dom $1) +SERVER=$2 + +add_user() +{ + USER=$1 + ${NET} ads user add "${USER}" 'Sup3rS3cr3T!' -k --configfile=$CONFIG_FILE -S ${SERVER} >/dev/null + RET=$? + if [ $RET -ne 0 ]; then + echo "${NET} ads user add returned error: $RET" + exit 1 + fi +} + +del_user() +{ + USER=$1 + ${NET} ads user delete "${USER}" -k --configfile=$CONFIG_FILE -S ${SERVER} >/dev/null + RET=$? + if [ $RET -ne 0 ]; then + echo "${NET} returned error: $RET" + exit 1 + fi +} + +enum_user() +{ + ${NET} ads user -k --configfile=$CONFIG_FILE -S $SERVER >/dev/null + RET=$? + if [ $RET -ne 0 ]; then + echo "${NET} returned error: $RET" + exit 1 + fi +} + +info_user() +{ + USER=$1 + ${NET} ads user info "${USER}" -k --configfile=$CONFIG_FILE -S ${SERVER} >/dev/null + RET=$? + if [ $RET -ne 0 ]; then + echo "${NET} returned error: $RET" + exit 1 + fi +} + +set_up() +{ + set_krb_env + setup_kinit + call_kinit "${PRINCIPAL}" "${PASSWORD}" + write_configfile "${REALM}" "${NT_DOM}" +} + +tear_down() +{ + ${KDESTROY} + restore_krb_env +} + +set_up + +echo -e "\tUSER $SERVER" + +START_TIME=$(start_timer) + +echo -en "\t" +for i in $(${SEQ} 1 $ITERATIONS); do + USER=$(echo "ad_test_$(pad_number $i 3)") + add_user $USER + echo -n "." +done +echo "done" + +enum_user + +# Requires winbind, which requires root perms to start. Skip this for now +#echo -en "\t" +#for i in $( ${SEQ} 1 $ITERATIONS ); do +# USER=$( echo "ad_test_$(pad_number $i 3)" ) +# info_user $USER +# echo -n "." +#done +#echo "done" + +echo -en "\t" +for i in $(${SEQ} 1 $ITERATIONS); do + USER=$(echo "ad_test_$(pad_number $i 3)") + del_user $USER + echo -n "." +done +echo "done" + +STOP_TIME=$(stop_timer) + +TOTAL_TIME=$(total_time $START_TIME $STOP_TIME) + +echo -e "\t\ttotal time:\t\t${TOTAL_TIME}s" + +LOGINS_PER_MINUTE=$(iterations_per_minute $START_TIME $STOP_TIME $ITERATIONS) + +echo -e "\t\titerations/min:\t\t$LOGINS_PER_MINUTE" + +tear_down diff --git a/examples/ad-bench/utils.sh b/examples/ad-bench/utils.sh new file mode 100644 index 0000000..5a7c015 --- /dev/null +++ b/examples/ad-bench/utils.sh @@ -0,0 +1,130 @@ +#!/bin/bash +# AD-Bench utility functions +# +# Copyright (C) 2009 Kai Blin +# +# This file is part of AD-Bench, an Active Directory benchmark tool +# +# AD-Bench is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# AD-Bench is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with AD-Bench. If not, see . + +source $(dirname $0)/settings.sh + +start_timer() +{ + START_TIME=$(${DATE} ${DATE_FORMATSTR}) + echo "$START_TIME" +} + +stop_timer() +{ + STOP_TIME=$(${DATE} ${DATE_FORMATSTR}) + echo "$STOP_TIME" +} + +total_time() +{ + START_TIME=$1 + END_TIME=$2 + TOTAL_TIME=$(echo "scale=9;$STOP_TIME - $START_TIME" | ${BC}) + echo "$TOTAL_TIME" +} + +iterations_per_minute() +{ + START_TIME=$1 + STOP_TIME=$2 + TOTAL_RUNS=$3 + + TOTAL_TIME=$(total_time $START_TIME $STOP_TIME) + + ITER_PER_MIN=$(echo "scale=2; 60 * $TOTAL_RUNS / $TOTAL_TIME" | ${BC}) + echo "$ITER_PER_MIN" +} + +get_principal() +{ + PRINCIPAL=$(echo $1 | ${SED} -e "s/\(.*\)%.*/\1/") + echo "$PRINCIPAL" +} + +get_password() +{ + PASSWORD=$(echo $1 | ${SED} -e "s/.*%\(.*\)/\1/") + echo "$PASSWORD" +} + +get_realm() +{ + REALM=$(echo $1 | ${SED} -e "s/.*@\(.*\)%.*/\1/") + echo "$REALM" +} + +get_nt_dom() +{ + NT_DOM=$(echo $1 | ${SED} -e "s/.*@\([A-Z1-9-]*\)\..*/\1/") + echo "$NT_DOM" +} + +set_krb_env() +{ + OLD_KRB5CCNAME="${KRB5CCNAME}" + KRB5CCNAME="${NEW_KRB5CCNAME}" + export KRB5CCNAME +} + +restore_krb_env() +{ + KRB5CCNAME="${OLD_KRB5CCNAME}" + export KRB5CCNAME +} + +setup_kinit() +{ + ${KINIT} --invalid 2>&1 | grep -q "password-file" + if [ $? -eq 0 ]; then + KINIT="${KINIT} ${KINIT_PARAM_OLD}" + else + KINIT="${KINIT} ${KINIT_PARAM_NEW}" + fi +} + +write_configfile() +{ + REALM=$1 + NT_DOM=$2 + echo -e "[global]" >$CONFIG_FILE + echo -e "\trealm = $REALM" >>$CONFIG_FILE + echo -e "\tworkgroup = $NT_DOM" >>$CONFIG_FILE + echo -e "\tsecurity = ADS" >>$CONFIG_FILE +} + +call_kinit() +{ + PRINCIPAL=$1 + PASSWORD=$2 + echo "${PASSWORD}" | ${KINIT} ${PRINCIPAL} >/dev/null + RET=$? + if [ $RET -ne 0 ]; then + echo "kinit returned an error: $RET" + exit 1 + fi +} + +pad_number() +{ + NUMBER=$1 + DIGITS=$2 + PADDED_NO=$(printf "%0${DIGITS}d" $NUMBER) + echo $PADDED_NO +} -- cgit v1.2.3