2009-10-07 15:45:17 +02:00
#!/bin/bash
# AD-Bench utility functions
#
# Copyright (C) 2009 Kai Blin <kai@samba.org>
#
# 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 <http://www.gnu.org/licenses/>.
2022-02-19 16:06:32 +01:00
source $( dirname $0 ) /settings.sh
2009-10-07 15:45:17 +02:00
2022-02-19 16:06:32 +01:00
start_timer( )
{
START_TIME = $( ${ DATE } ${ DATE_FORMATSTR } )
2009-10-07 15:45:17 +02:00
echo " $START_TIME "
}
2022-02-19 16:06:32 +01:00
stop_timer( )
{
STOP_TIME = $( ${ DATE } ${ DATE_FORMATSTR } )
2009-10-07 15:45:17 +02:00
echo " $STOP_TIME "
}
2022-02-19 16:06:32 +01:00
total_time( )
{
2009-10-07 15:45:17 +02:00
START_TIME = $1
END_TIME = $2
2022-02-19 16:06:32 +01:00
TOTAL_TIME = $( echo " scale=9; $STOP_TIME - $START_TIME " | ${ BC } )
2009-10-07 15:45:17 +02:00
echo " $TOTAL_TIME "
}
2022-02-19 16:06:32 +01:00
iterations_per_minute( )
{
2009-10-07 15:45:17 +02:00
START_TIME = $1
STOP_TIME = $2
TOTAL_RUNS = $3
2022-02-19 16:06:32 +01:00
TOTAL_TIME = $( total_time $START_TIME $STOP_TIME )
2009-10-07 15:45:17 +02:00
2022-02-19 16:06:32 +01:00
ITER_PER_MIN = $( echo " scale=2; 60 * $TOTAL_RUNS / $TOTAL_TIME " | ${ BC } )
2009-10-07 15:45:17 +02:00
echo " $ITER_PER_MIN "
}
2022-02-19 16:06:32 +01:00
get_principal( )
{
PRINCIPAL = $( echo $1 | ${ SED } -e "s/\(.*\)%.*/\1/" )
2009-10-07 15:45:17 +02:00
echo " $PRINCIPAL "
}
2022-02-19 16:06:32 +01:00
get_password( )
{
PASSWORD = $( echo $1 | ${ SED } -e "s/.*%\(.*\)/\1/" )
2009-10-07 15:45:17 +02:00
echo " $PASSWORD "
}
2022-02-19 16:06:32 +01:00
get_realm( )
{
REALM = $( echo $1 | ${ SED } -e "s/.*@\(.*\)%.*/\1/" )
2009-10-07 15:45:17 +02:00
echo " $REALM "
}
2022-02-19 16:06:32 +01:00
get_nt_dom( )
{
NT_DOM = $( echo $1 | ${ SED } -e "s/.*@\([A-Z1-9-]*\)\..*/\1/" )
2009-10-07 15:45:17 +02:00
echo " $NT_DOM "
}
2022-02-19 16:06:32 +01:00
set_krb_env( )
{
2009-10-07 15:45:17 +02:00
OLD_KRB5CCNAME = " ${ KRB5CCNAME } "
KRB5CCNAME = " ${ NEW_KRB5CCNAME } "
export KRB5CCNAME
}
2022-02-19 16:06:32 +01:00
restore_krb_env( )
{
2009-10-07 15:45:17 +02:00
KRB5CCNAME = " ${ OLD_KRB5CCNAME } "
export KRB5CCNAME
}
2022-02-19 16:06:32 +01:00
setup_kinit( )
{
2009-10-07 15:45:17 +02:00
${ KINIT } --invalid 2>& 1 | grep -q "password-file"
if [ $? -eq 0 ] ; then
KINIT = " ${ KINIT } ${ KINIT_PARAM_OLD } "
else
KINIT = " ${ KINIT } ${ KINIT_PARAM_NEW } "
fi
}
2022-02-19 16:06:32 +01:00
write_configfile( )
{
2009-10-07 15:45:17 +02:00
REALM = $1
NT_DOM = $2
2022-02-19 16:06:32 +01:00
echo -e "[global]" >$CONFIG_FILE
echo -e " \trealm = $REALM " >>$CONFIG_FILE
echo -e " \tworkgroup = $NT_DOM " >>$CONFIG_FILE
echo -e "\tsecurity = ADS" >>$CONFIG_FILE
2009-10-07 15:45:17 +02:00
}
2022-02-19 16:06:32 +01:00
call_kinit( )
{
2009-10-07 15:45:17 +02:00
PRINCIPAL = $1
PASSWORD = $2
2022-02-19 16:06:32 +01:00
echo " ${ PASSWORD } " | ${ KINIT } ${ PRINCIPAL } >/dev/null
2009-10-07 15:45:17 +02:00
RET = $?
if [ $RET -ne 0 ] ; then
echo " kinit returned an error: $RET "
exit 1
fi
}
2022-02-19 16:06:32 +01:00
pad_number( )
{
2009-10-07 15:45:17 +02:00
NUMBER = $1
DIGITS = $2
PADDED_NO = $( printf " %0 ${ DIGITS } d " $NUMBER )
echo $PADDED_NO
}