05dbc8
From 233d3784d04bee37b772f391da8726f0cd7b223e Mon Sep 17 00:00:00 2001
6a048c
From: Petr Mensik <pemensik@redhat.com>
6a048c
Date: Fri, 18 Oct 2019 21:30:52 +0200
6a048c
Subject: [PATCH] Move USE_PKCS11 and USE_OPENSSL out of config.h
6a048c
6a048c
Building two variants with the same common code requires to unset
6a048c
USE_PKCS11 on part of build. That is not possible with config.h value.
6a048c
Move it as normal define to CDEFINES.
6a048c
---
05dbc8
 bin/confgen/Makefile.in |  2 +-
05dbc8
 bin/dig/Makefile.in     |  2 +-
05dbc8
 bin/dnssec/Makefile.in  |  2 +-
05dbc8
 bin/named/Makefile.in   |  2 +-
05dbc8
 configure.ac            |  8 ++++++--
05dbc8
 lib/dns/Makefile.in     |  2 +-
05dbc8
 lib/dns/dst_internal.h  | 12 +++++++++---
05dbc8
 lib/ns/Makefile.in      |  2 +-
05dbc8
 8 files changed, 21 insertions(+), 11 deletions(-)
6a048c
6a048c
diff --git a/bin/confgen/Makefile.in b/bin/confgen/Makefile.in
6a048c
index dc3a7f6..1e0fe0e 100644
6a048c
--- a/bin/confgen/Makefile.in
6a048c
+++ b/bin/confgen/Makefile.in
6a048c
@@ -22,7 +22,7 @@ VERSION=@BIND9_VERSION@
6a048c
 CINCLUDES = -I${srcdir}/include ${ISC_INCLUDES} ${ISCCC_INCLUDES} \
6a048c
 	${ISCCFG_INCLUDES} ${DNS_INCLUDES} ${BIND9_INCLUDES}
6a048c
 
6a048c
-CDEFINES =
6a048c
+CDEFINES = @USE_PKCS11@
6a048c
 CWARNINGS =
6a048c
 
6a048c
 ISCCFGLIBS =	../../lib/isccfg/libisccfg.@A@
6a048c
diff --git a/bin/dig/Makefile.in b/bin/dig/Makefile.in
6a048c
index 0601939..2317ec0 100644
6a048c
--- a/bin/dig/Makefile.in
6a048c
+++ b/bin/dig/Makefile.in
6a048c
@@ -21,7 +21,7 @@ CINCLUDES =	-I${srcdir}/include ${DNS_INCLUDES} \
6a048c
 		${BIND9_INCLUDES} ${ISC_INCLUDES} \
6a048c
 		${IRS_INCLUDES} ${ISCCFG_INCLUDES} @LIBIDN2_CFLAGS@ @OPENSSL_INCLUDES@
6a048c
 
6a048c
-CDEFINES =	-DVERSION=\"${VERSION}\"
6a048c
+CDEFINES =	-DVERSION=\"${VERSION}\" @USE_PKCS11@
6a048c
 CWARNINGS =
6a048c
 
6a048c
 ISCCFGLIBS =	../../lib/isccfg/libisccfg.@A@
6a048c
diff --git a/bin/dnssec/Makefile.in b/bin/dnssec/Makefile.in
6a048c
index 321058b..1dad340 100644
6a048c
--- a/bin/dnssec/Makefile.in
6a048c
+++ b/bin/dnssec/Makefile.in
6a048c
@@ -17,7 +17,7 @@ VERSION=@BIND9_VERSION@
6a048c
 
6a048c
 CINCLUDES =	${DNS_INCLUDES} ${ISC_INCLUDES} @OPENSSL_INCLUDES@
6a048c
 
6a048c
-CDEFINES =	-DVERSION=\"${VERSION}\"
6a048c
+CDEFINES =	-DVERSION=\"${VERSION}\" @USE_PKCS11@
6a048c
 CWARNINGS =
6a048c
 
6a048c
 DNSLIBS =	../../lib/dns/libdns.@A@ ${MAXMINDDB_LIBS} @DNS_CRYPTO_LIBS@
6a048c
diff --git a/bin/named/Makefile.in b/bin/named/Makefile.in
6a048c
index eecfa76..e5b0d4b 100644
6a048c
--- a/bin/named/Makefile.in
6a048c
+++ b/bin/named/Makefile.in
6a048c
@@ -49,7 +49,7 @@ CINCLUDES =	-I${srcdir}/include -I${srcdir}/unix/include -I. \
6a048c
 		${DBDRIVER_INCLUDES} ${MAXMINDDB_CFLAGS} \
6a048c
 		@OPENSSL_INCLUDES@
6a048c
 
6a048c
-CDEFINES =      @CONTRIB_DLZ@
6a048c
+CDEFINES =      @CONTRIB_DLZ@ @USE_PKCS11@
6a048c
 
6a048c
 CWARNINGS =
6a048c
 
6a048c
diff --git a/configure.ac b/configure.ac
05dbc8
index 80039b7..6cce3bb 100644
6a048c
--- a/configure.ac
6a048c
+++ b/configure.ac
6a048c
@@ -963,9 +963,13 @@ AS_CASE([$enable_native_pkcs11],
6a048c
 AC_SUBST([PKCS11_TEST])
6a048c
 AC_SUBST([PKCS11_TOOLS])
6a048c
 
05dbc8
+USE_PKCS11='-DUSE_PKCS11=0'
05dbc8
+USE_OPENSSL='-DUSE_OPENSSL=0'
6a048c
 AS_CASE([$CRYPTO],
6a048c
-	[pkcs11],[AC_DEFINE([USE_PKCS11], [1], [define if PKCS11 is used for Public-Key Cryptography])],
6a048c
-	[AC_DEFINE([USE_OPENSSL], [1], [define if OpenSSL is used for Public-Key Cryptography])])
05dbc8
+	[pkcs11],[USE_PKCS11='-DUSE_PKCS11=1'],
05dbc8
+	[USE_OPENSSL='-DUSE_OPENSSL=1'])
6a048c
+AC_SUBST(USE_PKCS11)
6a048c
+AC_SUBST(USE_OPENSSL)
6a048c
 
6a048c
 # preparation for automake
6a048c
 # AM_CONDITIONAL([PKCS11_TOOLS], [test "$with_native_pkcs11" = "yes"])
6a048c
diff --git a/lib/dns/Makefile.in b/lib/dns/Makefile.in
6a048c
index 60c87a8..9125b10 100644
6a048c
--- a/lib/dns/Makefile.in
6a048c
+++ b/lib/dns/Makefile.in
6a048c
@@ -30,7 +30,7 @@ CINCLUDES =	-I. -I${top_srcdir}/lib/dns -Iinclude ${DNS_INCLUDES} \
6a048c
 		${ISC_INCLUDES} ${MAXMINDDB_CFLAGS} \
6a048c
 		@OPENSSL_INCLUDES@ @DST_GSSAPI_INC@
6a048c
 
6a048c
-CDEFINES =	@USE_GSSAPI@ ${USE_ISC_SPNEGO}
6a048c
+CDEFINES =	@USE_GSSAPI@ ${USE_ISC_SPNEGO} @USE_OPENSSL@ @USE_PKCS11@
6a048c
 
6a048c
 CWARNINGS =
6a048c
 
05dbc8
diff --git a/lib/dns/dst_internal.h b/lib/dns/dst_internal.h
05dbc8
index bfa28f0..d3ff613 100644
05dbc8
--- a/lib/dns/dst_internal.h
05dbc8
+++ b/lib/dns/dst_internal.h
05dbc8
@@ -40,6 +40,13 @@
05dbc8
 #include <isc/stdtime.h>
05dbc8
 #include <isc/hmac.h>
05dbc8
 
05dbc8
+#ifndef USE_OPENSSL
05dbc8
+#define USE_OPENSSL 1
05dbc8
+#endif
05dbc8
+#ifndef USE_PKCS11
05dbc8
+#define USE_PKCS11 0
05dbc8
+#endif
05dbc8
+
05dbc8
 #if USE_PKCS11
05dbc8
 #include <pk11/pk11.h>
05dbc8
 #include <pk11/site.h>
05dbc8
@@ -99,11 +106,10 @@ struct dst_key {
05dbc8
 		void *generic;
05dbc8
 		gss_ctx_id_t gssctx;
05dbc8
 		DH *dh;
05dbc8
-#if USE_OPENSSL
05dbc8
-		EVP_PKEY *pkey;
05dbc8
-#endif
05dbc8
 #if USE_PKCS11
05dbc8
 		pk11_object_t *pkey;
05dbc8
+#else
05dbc8
+		EVP_PKEY *pkey;
05dbc8
 #endif
05dbc8
 		dst_hmac_key_t *hmac_key;
05dbc8
 	} keydata;			/*%< pointer to key in crypto pkg fmt */
6a048c
diff --git a/lib/ns/Makefile.in b/lib/ns/Makefile.in
6a048c
index a14728d..58d731a 100644
6a048c
--- a/lib/ns/Makefile.in
6a048c
+++ b/lib/ns/Makefile.in
6a048c
@@ -24,7 +24,7 @@ CINCLUDES =	-I. -I${top_srcdir}/lib/ns -Iinclude \
6a048c
 		${NS_INCLUDES} ${DNS_INCLUDES} ${ISC_INCLUDES} \
6a048c
 		@OPENSSL_INCLUDES@ @DST_GSSAPI_INC@
6a048c
 
6a048c
-CDEFINES =	-DNAMED_PLUGINDIR=\"${plugindir}\"
6a048c
+CDEFINES =	@USE_PKCS11@ -DNAMED_PLUGINDIR=\"${plugindir}\"
6a048c
 
6a048c
 CWARNINGS =
6a048c
 
6a048c
-- 
6a048c
2.20.1
6a048c