$NetBSD: patch-its8885,v 1.1 2018/07/31 12:39:52 manu Exp $

Add a configure test for hdb_generate_key_set_password() prototype

From upstream ITS #8885

contrib/slapd-modules/smbk5pwd uses hdb_generate_key_set_password() from
Heimdal, which was shortly turned from a 5 arguments function to a 7 arguments
function before the prototype change was rolled back to address API
incompatibility.

Unfortunately, the 7 arguments hdb_generate_key_set_password() made it into
released NetBSD 8.0, causing a build break in contrib/slapd-modules/smbk5pwd.

This change adds a configure test for 7 arguments prototype so that
contrib/slapd-modules/smbk5pwd build again on NetBSD 8.0, and other OS that
would include the 7 arguments hdb_generate_key_set_password().

--- build/openldap.m4.orig	2018-03-22 16:44:27.000000000 +0100
+++ build/openldap.m4	2018-07-30 03:50:36.291294379 +0200
@@ -1141,4 +1141,27 @@
 	char *__ssl_compat = "0.9.7d";
 #endif
 	], [ol_cv_ssl_crl_compat=yes], [ol_cv_ssl_crl_compat=no])])
 ])
+dnl ====================================================================
+dnl check for db_generate_key_set_password prototype
+AC_DEFUN([OL_HDB_GENERATE_KEY_SET_PASSWORD],
+[AC_CACHE_CHECK([if hdb_generate_key_set_password requires 7 arguments],
+	[ol_cv_hdb_generate_key_set_password_7_args],[
+	AC_COMPILE_IFELSE([
+		AC_LANG_PROGRAM([
+			#include "krb5/krb5.h"
+			#include "krb5/hdb.h"
+		],[
+			(void)hdb_generate_key_set_password(
+				NULL,	/* context */
+				NULL,	/* principal */
+				NULL,	/* password */
+				NULL,	/* ks_tuple */
+				0,	/* n_ks_tuple */
+				NULL,	/* keys */
+				0	/* num_keys */
+			);
+		])],
+		[ol_cv_hdb_generate_key_set_password_7_args=yes],
+		[ol_cv_hdb_generate_key_set_password_7_args=no])])
+])
--- include/portable.hin.orig	2018-03-22 16:44:27.000000000 +0100
+++ include/portable.hin	2018-07-30 03:50:36.309332999 +0200
@@ -399,8 +399,11 @@
 
 /* Define to 1 if you have the <openssl/ssl.h> header file. */
 #undef HAVE_OPENSSL_SSL_H
 
+/* Define to 1 if hdb_generate_key_set_password needs 7 arguments */
+#undef HAVE_HDB_GENERATE_KEY_SET_PASSWORD_7_ARGS
+
 /* Define to 1 if you have the `pipe' function. */
 #undef HAVE_PIPE
 
 /* Define to 1 if you have the `poll' function. */
--- contrib/slapd-modules/smbk5pwd/smbk5pwd.c.orig	2018-03-22 16:44:27.000000000 +0100
+++ contrib/slapd-modules/smbk5pwd/smbk5pwd.c	2018-07-30 03:50:36.307164222 +0200
@@ -462,10 +462,15 @@
 				"dn=\"%s\" missing krb5KeyVersionNumber\n",
 				op->o_log_prefix, e->e_name.bv_val, 0 );
 		}
 
+#ifdef HAVE_HDB_GENERATE_KEY_SET_PASSWORD_7_ARGS
+		ret = hdb_generate_key_set_password(context, ent.principal,
+			qpw->rs_new.bv_val, NULL, 0, &ent.keys.val, &nkeys);
+#else
 		ret = hdb_generate_key_set_password(context, ent.principal,
 			qpw->rs_new.bv_val, &ent.keys.val, &nkeys);
+#endif
 		ent.keys.len = nkeys;
 		hdb_seal_keys(context, db, &ent);
 		krb5_free_principal( context, ent.principal );
 
--- configure.orig	2018-03-22 16:44:27.000000000 +0100
+++ configure	2018-07-30 03:50:36.300456664 +0200
@@ -15815,8 +15815,55 @@
 $as_echo "#define SLAPD_LMHASH 1" >>confdefs.h
 
 fi
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if hdb_generate_key_set_password requires 7 arguments" >&5
+$as_echo_n "checking if hdb_generate_key_set_password requires 7 arguments... " >&6; }
+if test "${ol_cv_hdb_generate_key_set_password_7_args+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+
+	cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+
+			#include "krb5/krb5.h"
+			#include "krb5/hdb.h"
+
+int
+main ()
+{
+
+			(void)hdb_generate_key_set_password(
+				NULL,	/* context */
+				NULL,	/* principal */
+				NULL,	/* password */
+				NULL,	/* ks_tuple */
+				0,	/* n_ks_tuple */
+				NULL,	/* keys */
+				0	/* num_keys */
+			);
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ol_cv_hdb_generate_key_set_password_7_args=yes
+else
+  ol_cv_hdb_generate_key_set_password_7_args=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ol_cv_hdb_generate_key_set_password_7_args" >&5
+$as_echo "$ol_cv_hdb_generate_key_set_password_7_args" >&6; }
+
+if test $ol_cv_hdb_generate_key_set_password_7_args = yes ; then
+
+$as_echo "#define HAVE_HDB_GENERATE_KEY_SET_PASSWORD_7_ARGS 1" >>confdefs.h
+
+fi
+
 ol_link_threads=no
 
 case $ol_with_threads in auto | yes | nt)
 
--- configure.in.orig	2018-03-22 16:44:27.000000000 +0100
+++ configure.in	2018-07-30 03:54:41.886303506 +0200
@@ -1279,8 +1279,16 @@
 	AC_DEFINE(SLAPD_LMHASH, 1, [define to support LAN Manager passwords])
 fi
 
 dnl ----------------------------------------------------------------
+dnl hdb_generate_key_set_password prototype
+OL_HDB_GENERATE_KEY_SET_PASSWORD
+if test $ol_cv_hdb_generate_key_set_password_7_args = yes ; then
+	AC_DEFINE(HAVE_HDB_GENERATE_KEY_SET_PASSWORD_7_ARGS, 1, 
+		[define if hdb_generate_key_set_password needs 7 arguments])
+fi
+
+dnl ----------------------------------------------------------------
 dnl Threads?
 ol_link_threads=no
 
 case $ol_with_threads in auto | yes | nt)
