testprogs: Add system_or_builddir_binary()
authorAndreas Schneider <asn@samba.org>
Thu, 22 Dec 2022 07:36:26 +0000 (08:36 +0100)
committerAndreas Schneider <asn@cryptomilk.org>
Fri, 23 Dec 2022 14:35:31 +0000 (14:35 +0000)
This should be used if we use a system or builddir binary.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
testprogs/blackbox/common_test_fns.inc
testprogs/blackbox/test_password_settings.sh

index a9e94b82e9953b1cdd61fc47e890d8150053fbba..4b9a6a481aa11ee2531d7d62a937877993594d51 100755 (executable)
@@ -124,3 +124,31 @@ remove_directory()
 
        rm -rf "$xdir"
 }
+
+# This function should be used to either use a system tool or one of our
+# build dir if available.
+#
+# Examples:
+#
+#   system_or_builddir_binary ldbsearch ${BUILDDIR}
+#   system_or_builddir_binary kinit ${BUILDDIR} samba4kinit
+#
+system_or_builddir_binary()
+{
+       _bin_name="${1}"
+       _build_dir="${2}"
+       _alt_bin_name="${3}"
+
+       _bin="$(command -v ${_bin_name})"
+       _bin_build_path="${_build_dir}/${_bin_name}"
+
+       if [ -n "${_alt_bin_name}" ]; then
+           _bin_build_path="${_build_dir}/${_alt_bin_name}"
+       fi
+
+       if [ -x "${_bin_build_path}" ]; then
+               _bin="${_bin_build_path}"
+       fi
+
+       echo "${_bin}"
+}
index a757f80700cd6e54609b60e35eefe53cf70459c8..609e26dee740cd717aa761d246c6b03ef84a6370 100755 (executable)
@@ -23,11 +23,6 @@ failed=0
 
 samba_bindir="$BINDIR"
 
-samba_kinit=kinit
-if test -x $samba_bindir/samba4kinit; then
-       samba_kinit=$samba_bindir/samba4kinit
-fi
-
 smbclient="$samba_bindir/smbclient"
 samba_tool="$samba_bindir/samba-tool"
 smbpasswd="$samba_bindir/smbpasswd"
@@ -39,6 +34,8 @@ SMB_UNC="//$SERVER/tmp"
 . $(dirname $0)/subunit.sh
 . $(dirname $0)/common_test_fns.inc
 
+samba_kinit=$(system_or_builddir_binary kinit "${BINDIR}" samba4kinit)
+
 do_kinit()
 {
        principal="$1"