57726f
diff --git a/bin/Makefile.in b/bin/Makefile.in
e48f32
index a18b222..26a7e4e 100644
57726f
--- a/bin/Makefile.in
57726f
+++ b/bin/Makefile.in
57726f
@@ -11,8 +11,8 @@ srcdir =	@srcdir@
57726f
 VPATH =		@srcdir@
57726f
 top_srcdir =	@top_srcdir@
57726f
 
57726f
-SUBDIRS =	named rndc dig delv dnssec tools nsupdate check confgen \
57726f
-		@NZD_TOOLS@ @PYTHON_TOOLS@ @PKCS11_TOOLS@ tests
57726f
+SUBDIRS =	named named-pkcs11 rndc dig delv dnssec dnssec-pkcs11 tools nsupdate \
57726f
+		check confgen @NZD_TOOLS@ @PYTHON_TOOLS@ @PKCS11_TOOLS@ tests
57726f
 TARGETS =
57726f
 
57726f
 @BIND9_MAKE_RULES@
57726f
diff --git a/bin/dnssec-pkcs11/Makefile.in b/bin/dnssec-pkcs11/Makefile.in
e48f32
index 390aa0c..e59a118 100644
57726f
--- a/bin/dnssec-pkcs11/Makefile.in
57726f
+++ b/bin/dnssec-pkcs11/Makefile.in
57726f
@@ -15,18 +15,18 @@ VERSION=@BIND9_VERSION@
57726f
 
57726f
 @BIND9_MAKE_INCLUDES@
57726f
 
57726f
-CINCLUDES =	${DNS_INCLUDES} ${ISC_INCLUDES} @DST_OPENSSL_INC@
57726f
+CINCLUDES =	${DNS_PKCS11_INCLUDES} ${ISC_PKCS11_INCLUDES}
57726f
 
57726f
-CDEFINES =	-DVERSION=\"${VERSION}\" @USE_PKCS11@ @PKCS11_ENGINE@ \
57726f
-		@CRYPTO@ -DPK11_LIB_LOCATION=\"@PKCS11_PROVIDER@\"
57726f
+CDEFINES =	-DVERSION=\"${VERSION}\" @PKCS11_ENGINE@ \
57726f
+		@CRYPTO_PK11@ -DPK11_LIB_LOCATION=\"@PKCS11_PROVIDER@\"
57726f
 CWARNINGS =
57726f
 
57726f
-DNSLIBS =	../../lib/dns/libdns.@A@ ${MAXMINDDB_LIBS} @DNS_CRYPTO_LIBS@
57726f
-ISCLIBS =	../../lib/isc/libisc.@A@
57726f
-ISCNOSYMLIBS =	../../lib/isc/libisc-nosymtbl.@A@
57726f
+DNSLIBS =	../../lib/dns-pkcs11/libdns-pkcs11.@A@ ${MAXMINDDB_LIBS} @DNS_CRYPTO_LIBS@
57726f
+ISCLIBS =	../../lib/isc-pkcs11/libisc-pkcs11.@A@
57726f
+ISCNOSYMLIBS =	../../lib/isc-pkcs11/libisc-pkcs11-nosymtbl.@A@
57726f
 
57726f
-DNSDEPLIBS =	../../lib/dns/libdns.@A@
57726f
-ISCDEPLIBS =	../../lib/isc/libisc.@A@
57726f
+DNSDEPLIBS =	../../lib/dns-pkcs11/libdns-pkcs11.@A@
57726f
+ISCDEPLIBS =	../../lib/isc-pkcs11/libisc-pkcs11.@A@
57726f
 
57726f
 DEPLIBS =	${DNSDEPLIBS} ${ISCDEPLIBS}
57726f
 
57726f
@@ -35,10 +35,10 @@ LIBS =		${DNSLIBS} ${ISCLIBS} @LIBS@
57726f
 NOSYMLIBS =	${DNSLIBS} ${ISCNOSYMLIBS} @LIBS@
57726f
 
57726f
 # Alphabetically
57726f
-TARGETS =	dnssec-keygen@EXEEXT@ dnssec-signzone@EXEEXT@ \
57726f
-		dnssec-keyfromlabel@EXEEXT@ dnssec-dsfromkey@EXEEXT@ \
57726f
-		dnssec-revoke@EXEEXT@ dnssec-settime@EXEEXT@ \
57726f
-		dnssec-verify@EXEEXT@ dnssec-importkey@EXEEXT@
57726f
+TARGETS =	dnssec-keygen-pkcs11@EXEEXT@ dnssec-signzone-pkcs11@EXEEXT@ \
57726f
+		dnssec-keyfromlabel-pkcs11@EXEEXT@ dnssec-dsfromkey-pkcs11@EXEEXT@ \
57726f
+		dnssec-revoke-pkcs11@EXEEXT@ dnssec-settime-pkcs11@EXEEXT@ \
57726f
+		dnssec-verify-pkcs11@EXEEXT@ dnssec-importkey-pkcs11@EXEEXT@
57726f
 
57726f
 OBJS =		dnssectool.@O@
57726f
 
57726f
@@ -59,15 +59,15 @@ MANOBJS =	${MANPAGES} ${HTMLPAGES}
57726f
 
57726f
 @BIND9_MAKE_RULES@
57726f
 
57726f
-dnssec-dsfromkey@EXEEXT@: dnssec-dsfromkey.@O@ ${OBJS} ${DEPLIBS}
57726f
+dnssec-dsfromkey-pkcs11@EXEEXT@: dnssec-dsfromkey.@O@ ${OBJS} ${DEPLIBS}
57726f
 	export BASEOBJS="dnssec-dsfromkey.@O@ ${OBJS}"; \
57726f
 	${FINALBUILDCMD}
57726f
 
57726f
-dnssec-keyfromlabel@EXEEXT@: dnssec-keyfromlabel.@O@ ${OBJS} ${DEPLIBS}
57726f
+dnssec-keyfromlabel-pkcs11@EXEEXT@: dnssec-keyfromlabel.@O@ ${OBJS} ${DEPLIBS}
57726f
 	export BASEOBJS="dnssec-keyfromlabel.@O@ ${OBJS}"; \
57726f
 	${FINALBUILDCMD}
57726f
 
57726f
-dnssec-keygen@EXEEXT@: dnssec-keygen.@O@ ${OBJS} ${DEPLIBS}
57726f
+dnssec-keygen-pkcs11@EXEEXT@: dnssec-keygen.@O@ ${OBJS} ${DEPLIBS}
57726f
 	export BASEOBJS="dnssec-keygen.@O@ ${OBJS}"; \
57726f
 	${FINALBUILDCMD}
57726f
 
57726f
@@ -75,7 +75,7 @@ dnssec-signzone.@O@: dnssec-signzone.c
57726f
 	${LIBTOOL_MODE_COMPILE} ${CC} ${ALL_CFLAGS} -DVERSION=\"${VERSION}\" \
57726f
 		-c ${srcdir}/dnssec-signzone.c
57726f
 
57726f
-dnssec-signzone@EXEEXT@: dnssec-signzone.@O@ ${OBJS} ${DEPLIBS}
57726f
+dnssec-signzone-pkcs11@EXEEXT@: dnssec-signzone.@O@ ${OBJS} ${DEPLIBS}
57726f
 	export BASEOBJS="dnssec-signzone.@O@ ${OBJS}"; \
57726f
 	${FINALBUILDCMD}
57726f
 
57726f
@@ -83,19 +83,19 @@ dnssec-verify.@O@: dnssec-verify.c
57726f
 	${LIBTOOL_MODE_COMPILE} ${CC} ${ALL_CFLAGS} -DVERSION=\"${VERSION}\" \
57726f
 		-c ${srcdir}/dnssec-verify.c
57726f
 
57726f
-dnssec-verify@EXEEXT@: dnssec-verify.@O@ ${OBJS} ${DEPLIBS}
57726f
+dnssec-verify-pkcs11@EXEEXT@: dnssec-verify.@O@ ${OBJS} ${DEPLIBS}
57726f
 	export BASEOBJS="dnssec-verify.@O@ ${OBJS}"; \
57726f
 	${FINALBUILDCMD}
57726f
 
57726f
-dnssec-revoke@EXEEXT@: dnssec-revoke.@O@ ${OBJS} ${DEPLIBS}
57726f
+dnssec-revoke-pkcs11@EXEEXT@: dnssec-revoke.@O@ ${OBJS} ${DEPLIBS}
57726f
 	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
57726f
 	dnssec-revoke.@O@ ${OBJS} ${LIBS}
57726f
 
57726f
-dnssec-settime@EXEEXT@: dnssec-settime.@O@ ${OBJS} ${DEPLIBS}
57726f
+dnssec-settime-pkcs11@EXEEXT@: dnssec-settime.@O@ ${OBJS} ${DEPLIBS}
57726f
 	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
57726f
 	dnssec-settime.@O@ ${OBJS} ${LIBS}
57726f
 
57726f
-dnssec-importkey@EXEEXT@: dnssec-importkey.@O@ ${OBJS} ${DEPLIBS}
57726f
+dnssec-importkey-pkcs11@EXEEXT@: dnssec-importkey.@O@ ${OBJS} ${DEPLIBS}
57726f
 	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
57726f
 	dnssec-importkey.@O@ ${OBJS} ${LIBS}
57726f
 
57726f
@@ -106,16 +106,14 @@ docclean manclean maintainer-clean::
57726f
 
57726f
 installdirs:
57726f
 	$(SHELL) ${top_srcdir}/mkinstalldirs ${DESTDIR}${sbindir}
57726f
-	$(SHELL) ${top_srcdir}/mkinstalldirs ${DESTDIR}${mandir}/man8
57726f
 
57726f
 install-man8: ${MANPAGES}
57726f
 	${INSTALL_DATA} $^ ${DESTDIR}${mandir}/man8
57726f
 
57726f
-install:: ${TARGETS} installdirs install-man8
57726f
+install:: ${TARGETS} installdirs
57726f
 	for t in ${TARGETS}; do ${LIBTOOL_MODE_INSTALL} ${INSTALL_PROGRAM} $$t ${DESTDIR}${sbindir} || exit 1; done
57726f
 
57726f
 uninstall::
57726f
-	for m in ${MANPAGES}; do rm -f ${DESTDIR}${mandir}/man8/$$m || exit 1; done
57726f
 	for t in ${TARGETS}; do ${LIBTOOL_MODE_UNINSTALL} rm -f ${DESTDIR}${sbindir}/$$t || exit 1; done
57726f
 
57726f
 clean distclean::
57726f
diff --git a/bin/dnssec/Makefile.in b/bin/dnssec/Makefile.in
e48f32
index 390aa0c..851a008 100644
57726f
--- a/bin/dnssec/Makefile.in
57726f
+++ b/bin/dnssec/Makefile.in
57726f
@@ -17,7 +17,7 @@ VERSION=@BIND9_VERSION@
57726f
 
57726f
 CINCLUDES =	${DNS_INCLUDES} ${ISC_INCLUDES} @DST_OPENSSL_INC@
57726f
 
57726f
-CDEFINES =	-DVERSION=\"${VERSION}\" @USE_PKCS11@ @PKCS11_ENGINE@ \
57726f
+CDEFINES =	-DVERSION=\"${VERSION}\" \
57726f
 		@CRYPTO@ -DPK11_LIB_LOCATION=\"@PKCS11_PROVIDER@\"
57726f
 CWARNINGS =
57726f
 
57726f
diff --git a/bin/named-pkcs11/Makefile.in b/bin/named-pkcs11/Makefile.in
ce773a
index 277a0f5..52a6375 100644
57726f
--- a/bin/named-pkcs11/Makefile.in
57726f
+++ b/bin/named-pkcs11/Makefile.in
57726f
@@ -43,27 +43,27 @@ DLZDRIVER_INCLUDES =	@DLZ_DRIVER_INCLUDES@
57726f
 DLZDRIVER_LIBS =	@DLZ_DRIVER_LIBS@
57726f
 
57726f
 CINCLUDES =	-I${srcdir}/include -I${srcdir}/unix/include -I. \
57726f
-		${LWRES_INCLUDES} ${DNS_INCLUDES} ${BIND9_INCLUDES} \
57726f
-		${ISCCFG_INCLUDES} ${ISCCC_INCLUDES} ${ISC_INCLUDES} \
57726f
+		${LWRES_INCLUDES} ${DNS_PKCS11_INCLUDES} ${BIND9_INCLUDES} \
57726f
+		${ISCCFG_INCLUDES} ${ISCCC_INCLUDES} ${ISC_PKCS11_INCLUDES} \
57726f
 		${DLZDRIVER_INCLUDES} ${DBDRIVER_INCLUDES} ${MAXMINDDB_CFLAGS} \
57726f
 		@DST_OPENSSL_INC@
57726f
 
57726f
-CDEFINES =      @CONTRIB_DLZ@ @USE_PKCS11@ @PKCS11_ENGINE@ @CRYPTO@
57726f
+CDEFINES =      @USE_PKCS11@ @PKCS11_ENGINE@ @CRYPTO_PK11@ @USE_GSSAPI@
57726f
 
57726f
 CWARNINGS =
57726f
 
57726f
-DNSLIBS =	../../lib/dns/libdns.@A@ ${MAXMINDDB_LIBS} @DNS_CRYPTO_LIBS@
57726f
+DNSLIBS =	../../lib/dns-pkcs11/libdns-pkcs11.@A@ ${MAXMINDDB_LIBS} @DNS_CRYPTO_LIBS@
57726f
 ISCCFGLIBS =	../../lib/isccfg/libisccfg.@A@
57726f
 ISCCCLIBS =	../../lib/isccc/libisccc.@A@
57726f
-ISCLIBS =	../../lib/isc/libisc.@A@
57726f
-ISCNOSYMLIBS =	../../lib/isc/libisc-nosymtbl.@A@
57726f
+ISCLIBS =	../../lib/isc-pkcs11/libisc-pkcs11.@A@
57726f
+ISCNOSYMLIBS =	../../lib/isc-pkcs11/libisc-pkcs11-nosymtbl.@A@
57726f
 LWRESLIBS =	../../lib/lwres/liblwres.@A@
57726f
 BIND9LIBS =	../../lib/bind9/libbind9.@A@
57726f
 
57726f
-DNSDEPLIBS =	../../lib/dns/libdns.@A@
57726f
+DNSDEPLIBS =	../../lib/dns-pkcs11/libdns-pkcs11.@A@
57726f
 ISCCFGDEPLIBS =	../../lib/isccfg/libisccfg.@A@
57726f
 ISCCCDEPLIBS =	../../lib/isccc/libisccc.@A@
57726f
-ISCDEPLIBS =	../../lib/isc/libisc.@A@
57726f
+ISCDEPLIBS =	../../lib/isc-pkcs11/libisc-pkcs11.@A@
57726f
 LWRESDEPLIBS =	../../lib/lwres/liblwres.@A@
57726f
 BIND9DEPLIBS =	../../lib/bind9/libbind9.@A@
57726f
 
57726f
@@ -72,15 +72,15 @@ DEPLIBS =	${LWRESDEPLIBS} ${DNSDEPLIBS} ${BIND9DEPLIBS} \
57726f
 
57726f
 LIBS =		${LWRESLIBS} ${DNSLIBS} ${BIND9LIBS} \
57726f
 		${ISCCFGLIBS} ${ISCCCLIBS} ${ISCLIBS} \
57726f
-		${DLZDRIVER_LIBS} ${DBDRIVER_LIBS} @LIBS@
57726f
+		@LIBS@
57726f
 
57726f
 NOSYMLIBS =	${LWRESLIBS} ${DNSLIBS} ${BIND9LIBS} \
57726f
 		${ISCCFGLIBS} ${ISCCCLIBS} ${ISCNOSYMLIBS} \
57726f
-		${DLZDRIVER_LIBS} ${DBDRIVER_LIBS} @LIBS@
57726f
+		@LIBS@
57726f
 
57726f
 SUBDIRS =	unix
57726f
 
57726f
-TARGETS =	named@EXEEXT@ lwresd@EXEEXT@
57726f
+TARGETS =	named-pkcs11@EXEEXT@
57726f
 
57726f
 GEOIPLINKOBJS = geoip.@O@
57726f
 GEOIP2LINKOBJS = geoip.@O@
57726f
@@ -94,8 +94,7 @@ OBJS =		builtin.@O@ client.@O@ config.@O@ control.@O@ \
57726f
 		tkeyconf.@O@ tsigconf.@O@ update.@O@ xfrout.@O@ \
57726f
 		zoneconf.@O@ \
57726f
 		lwaddr.@O@ lwresd.@O@ lwdclient.@O@ lwderror.@O@ lwdgabn.@O@ \
57726f
-		lwdgnba.@O@ lwdgrbn.@O@ lwdnoop.@O@ lwsearch.@O@ \
57726f
-		${DLZDRIVER_OBJS} ${DBDRIVER_OBJS}
57726f
+        lwdgnba.@O@ lwdgrbn.@O@ lwdnoop.@O@ lwsearch.@O@
57726f
 
57726f
 UOBJS =		unix/os.@O@ unix/dlz_dlopen_driver.@O@
57726f
 
57726f
@@ -113,8 +112,7 @@ SRCS =		builtin.c client.c config.c control.c \
57726f
 		tkeyconf.c tsigconf.c update.c xfrout.c \
57726f
 		zoneconf.c \
57726f
 		lwaddr.c lwresd.c lwdclient.c lwderror.c lwdgabn.c \
57726f
-		lwdgnba.c lwdgrbn.c lwdnoop.c lwsearch.c \
57726f
-		${DLZDRIVER_SRCS} ${DBDRIVER_SRCS}
57726f
+        lwdgnba.c lwdgrbn.c lwdnoop.c lwsearch.c
57726f
 
57726f
 MANPAGES =	named.8 lwresd.8 named.conf.5
57726f
 
57726f
@@ -154,14 +152,14 @@ server.@O@: server.c
57726f
 		-DPRODUCT=\"${PRODUCT}\" \
57726f
 		-DVERSION=\"${VERSION}\" -c ${srcdir}/server.c
57726f
 
57726f
-named@EXEEXT@: ${OBJS} ${DEPLIBS}
57726f
+named-pkcs11@EXEEXT@: ${OBJS} ${DEPLIBS}
57726f
 	export MAKE_SYMTABLE="yes"; \
57726f
 	export BASEOBJS="${OBJS} ${UOBJS}"; \
57726f
 	${FINALBUILDCMD}
57726f
 
57726f
-lwresd@EXEEXT@: named@EXEEXT@
57726f
+lwresd@EXEEXT@: named-pkcs11@EXEEXT@
57726f
 	rm -f lwresd@EXEEXT@
57726f
-	@LN@ named@EXEEXT@ lwresd@EXEEXT@
57726f
+	@LN@ named-pkcs11@EXEEXT@ lwresd@EXEEXT@
57726f
 
57726f
 doc man:: ${MANOBJS}
57726f
 
57726f
@@ -192,16 +190,11 @@ install-man8: named.8 lwresd.8
57726f
 
57726f
 install-man: install-man5 install-man8
57726f
 
57726f
-install:: named@EXEEXT@ lwresd@EXEEXT@ installdirs install-man
57726f
-	${LIBTOOL_MODE_INSTALL} ${INSTALL_PROGRAM} named@EXEEXT@ ${DESTDIR}${sbindir}
57726f
-	(cd ${DESTDIR}${sbindir}; rm -f lwresd@EXEEXT@; @LN@ named@EXEEXT@ lwresd@EXEEXT@)
57726f
+install:: named-pkcs11@EXEEXT@ installdirs
57726f
+	${LIBTOOL_MODE_INSTALL} ${INSTALL_PROGRAM} named-pkcs11@EXEEXT@ ${DESTDIR}${sbindir}
57726f
 
57726f
 uninstall::
57726f
-	rm -f ${DESTDIR}${mandir}/man5/named.conf.5
57726f
-	rm -f ${DESTDIR}${mandir}/man8/lwresd.8
57726f
-	rm -f ${DESTDIR}${mandir}/man8/named.8
57726f
-	rm -f ${DESTDIR}${sbindir}/lwresd@EXEEXT@
57726f
-	${LIBTOOL_MODE_UNINSTALL} rm -f ${DESTDIR}${sbindir}/named@EXEEXT@
57726f
+	${LIBTOOL_MODE_UNINSTALL} rm -f ${DESTDIR}${sbindir}/named-pkcs11@EXEEXT@
57726f
 
57726f
 @DLZ_DRIVER_RULES@
57726f
 
57726f
diff --git a/bin/named/Makefile.in b/bin/named/Makefile.in
ce773a
index 277a0f5..0e00885 100644
57726f
--- a/bin/named/Makefile.in
57726f
+++ b/bin/named/Makefile.in
57726f
@@ -48,7 +48,7 @@ CINCLUDES =	-I${srcdir}/include -I${srcdir}/unix/include -I. \
57726f
 		${DLZDRIVER_INCLUDES} ${DBDRIVER_INCLUDES} ${MAXMINDDB_CFLAGS} \
57726f
 		@DST_OPENSSL_INC@
57726f
 
57726f
-CDEFINES =      @CONTRIB_DLZ@ @USE_PKCS11@ @PKCS11_ENGINE@ @CRYPTO@
57726f
+CDEFINES =      @CONTRIB_DLZ@ @USE_GSSAPI@ @CRYPTO@
57726f
 
57726f
 CWARNINGS =
57726f
 
57726f
diff --git a/bin/pkcs11/Makefile.in b/bin/pkcs11/Makefile.in
e48f32
index 2c19e7e..8223d5e 100644
57726f
--- a/bin/pkcs11/Makefile.in
57726f
+++ b/bin/pkcs11/Makefile.in
e48f32
@@ -13,13 +13,13 @@ top_srcdir =	@top_srcdir@
57726f
 
57726f
 @BIND9_MAKE_INCLUDES@
57726f
 
57726f
-CINCLUDES =	${ISC_INCLUDES}
57726f
+CINCLUDES =	${ISC_PKCS11_INCLUDES}
57726f
 
57726f
 CDEFINES =
57726f
 
57726f
-ISCLIBS =	../../lib/isc/libisc.@A@ @ISC_OPENSSL_LIBS@
57726f
+ISCLIBS =	../../lib/isc-pkcs11/libisc-pkcs11.@A@ @ISC_OPENSSL_LIBS@
57726f
 
57726f
-ISCDEPLIBS =	../../lib/isc/libisc.@A@
57726f
+ISCDEPLIBS =	../../lib/isc-pkcs11/libisc-pkcs11.@A@
57726f
 
57726f
 DEPLIBS =	${ISCDEPLIBS}
57726f
 
57726f
diff --git a/configure.ac b/configure.ac
ce773a
index 83cad4a..e1e1a32 100644
57726f
--- a/configure.ac
57726f
+++ b/configure.ac
ce773a
@@ -1178,12 +1178,14 @@ AC_SUBST(USE_GSSAPI)
57726f
 AC_SUBST(DST_GSSAPI_INC)
57726f
 AC_SUBST(DNS_GSSAPI_LIBS)
57726f
 DNS_CRYPTO_LIBS="$DNS_GSSAPI_LIBS $DNS_CRYPTO_LIBS"
57726f
+DNS_CRYPTO_PK11_LIBS="$DNS_GSSAPI_LIBS $DNS_CRYPTO_PK11_LIBS"
57726f
 
57726f
 #
57726f
 # Applications linking with libdns also need to link with these libraries.
57726f
 #
57726f
 
57726f
 AC_SUBST(DNS_CRYPTO_LIBS)
57726f
+AC_SUBST(DNS_CRYPTO_PK11_LIBS)
57726f
 
57726f
 #
57726f
 # was --with-randomdev specified?
ce773a
@@ -1556,12 +1558,12 @@ AC_ARG_ENABLE(openssl-hash,
57726f
 AC_MSG_CHECKING(for OpenSSL library)
57726f
 OPENSSL_WARNING=
57726f
 openssldirs="/usr /usr/local /usr/local/ssl /opt/local /usr/pkg /usr/sfw"
57726f
-if test "yes" = "$want_native_pkcs11"
57726f
-then
57726f
-	use_openssl="native_pkcs11"
e48f32
-	want_openssl_hash="no"
57726f
-	AC_MSG_RESULT(use of native PKCS11 instead)
57726f
-fi
e48f32
+#if test "yes" = "$want_native_pkcs11"
e48f32
+#then
e48f32
+#	use_openssl="native_pkcs11"
e48f32
+#	want_openssl_hash="no"
e48f32
+#	AC_MSG_RESULT(use of native PKCS11 instead)
e48f32
+#fi
57726f
 
57726f
 if test "auto" = "$use_openssl"
57726f
 then
ce773a
@@ -1574,6 +1576,7 @@ then
57726f
 		fi
57726f
 	done
57726f
 fi
57726f
+CRYPTO_PK11=""
57726f
 OPENSSL_ECDSA=""
57726f
 OPENSSL_GOST=""
57726f
 OPENSSL_ED25519=""
ce773a
@@ -1595,11 +1598,10 @@ case "$with_gost" in
57726f
 		;;
57726f
 esac
57726f
 
57726f
-case "$use_openssl" in
57726f
-	native_pkcs11)
57726f
-		AC_MSG_RESULT(disabled because of native PKCS11)
57726f
+if test "$want_native_pkcs11" = "yes"
57726f
+then
57726f
 		DST_OPENSSL_INC=""
57726f
-		CRYPTO="-DPKCS11CRYPTO"
57726f
+		CRYPTO_PK11="-DPKCS11CRYPTO"
57726f
 		CRYPTOLIB="pkcs11"
57726f
 		OPENSSLECDSALINKOBJS=""
57726f
 		OPENSSLECDSALINKSRCS=""
ce773a
@@ -1609,7 +1611,9 @@ case "$use_openssl" in
57726f
 		OPENSSLGOSTLINKSRCS=""
57726f
 		OPENSSLLINKOBJS=""
57726f
 		OPENSSLLINKSRCS=""
57726f
-		;;
57726f
+fi
57726f
+
57726f
+case "$use_openssl" in
57726f
 	no)
57726f
 		AC_MSG_RESULT(no)
57726f
 		DST_OPENSSL_INC=""
ce773a
@@ -1641,7 +1645,7 @@ case "$use_openssl" in
57726f
 If you do not want OpenSSL, use --without-openssl])
57726f
 		;;
57726f
 	*)
57726f
-		if test "yes" = "$want_native_pkcs11"
57726f
+		if false # test "yes" = "$want_native_pkcs11"
57726f
 		then
57726f
 			AC_MSG_RESULT()
57726f
 			AC_MSG_ERROR([OpenSSL and native PKCS11 cannot be used together.])
ce773a
@@ -2077,6 +2081,7 @@ AC_SUBST(OPENSSL_ED25519)
57726f
 AC_SUBST(OPENSSL_GOST)
57726f
 
57726f
 DNS_CRYPTO_LIBS="$DNS_CRYPTO_LIBS $DST_OPENSSL_LIBS"
57726f
+DNS_CRYPTO_PK11_LIBS="$DNS_CRYPTO_LIBS"
57726f
 
57726f
 ISC_PLATFORM_WANTAES="#undef ISC_PLATFORM_WANTAES"
57726f
 if test "yes" = "$with_aes"
ce773a
@@ -2363,6 +2368,7 @@ esac
57726f
 AC_SUBST(PKCS11LINKOBJS)
57726f
 AC_SUBST(PKCS11LINKSRCS)
57726f
 AC_SUBST(CRYPTO)
57726f
+AC_SUBST(CRYPTO_PK11)
57726f
 AC_SUBST(PKCS11_ECDSA)
57726f
 AC_SUBST(PKCS11_GOST)
57726f
 AC_SUBST(PKCS11_ED25519)
ce773a
@@ -5491,8 +5497,11 @@ AC_CONFIG_FILES([
57726f
 	bin/delv/Makefile
57726f
 	bin/dig/Makefile
57726f
 	bin/dnssec/Makefile
57726f
+	bin/dnssec-pkcs11/Makefile	
57726f
 	bin/named/Makefile
57726f
 	bin/named/unix/Makefile
57726f
+	bin/named-pkcs11/Makefile
57726f
+	bin/named-pkcs11/unix/Makefile
57726f
 	bin/nsupdate/Makefile
57726f
 	bin/pkcs11/Makefile
57726f
 	bin/python/Makefile
ce773a
@@ -5565,6 +5574,10 @@ AC_CONFIG_FILES([
57726f
 	lib/dns/include/dns/Makefile
57726f
 	lib/dns/include/dst/Makefile
57726f
 	lib/dns/tests/Makefile
57726f
+	lib/dns-pkcs11/Makefile
57726f
+	lib/dns-pkcs11/include/Makefile
57726f
+	lib/dns-pkcs11/include/dns/Makefile
57726f
+	lib/dns-pkcs11/include/dst/Makefile
57726f
 	lib/irs/Makefile
57726f
 	lib/irs/include/Makefile
57726f
 	lib/irs/include/irs/Makefile
ce773a
@@ -5589,6 +5602,24 @@ AC_CONFIG_FILES([
57726f
 	lib/isc/unix/include/Makefile
57726f
 	lib/isc/unix/include/isc/Makefile
57726f
 	lib/isc/unix/include/pkcs11/Makefile
57726f
+	lib/isc-pkcs11/$arch/Makefile
57726f
+	lib/isc-pkcs11/$arch/include/Makefile
57726f
+	lib/isc-pkcs11/$arch/include/isc/Makefile
57726f
+	lib/isc-pkcs11/$thread_dir/Makefile
57726f
+	lib/isc-pkcs11/$thread_dir/include/Makefile
57726f
+	lib/isc-pkcs11/$thread_dir/include/isc/Makefile
57726f
+	lib/isc-pkcs11/Makefile
57726f
+	lib/isc-pkcs11/include/Makefile
57726f
+	lib/isc-pkcs11/include/isc/Makefile
57726f
+	lib/isc-pkcs11/include/isc/platform.h
57726f
+	lib/isc-pkcs11/include/pk11/Makefile
57726f
+	lib/isc-pkcs11/include/pkcs11/Makefile
57726f
+	lib/isc-pkcs11/tests/Makefile
57726f
+	lib/isc-pkcs11/nls/Makefile
57726f
+	lib/isc-pkcs11/unix/Makefile
57726f
+	lib/isc-pkcs11/unix/include/Makefile
57726f
+	lib/isc-pkcs11/unix/include/isc/Makefile
57726f
+	lib/isc-pkcs11/unix/include/pkcs11/Makefile
57726f
 	lib/isccc/Makefile
57726f
 	lib/isccc/include/Makefile
57726f
 	lib/isccc/include/isccc/Makefile
57726f
diff --git a/lib/Makefile.in b/lib/Makefile.in
e48f32
index f089bea..3ed939b 100644
57726f
--- a/lib/Makefile.in
57726f
+++ b/lib/Makefile.in
57726f
@@ -15,7 +15,7 @@ top_srcdir =	@top_srcdir@
57726f
 # Attempt to disable parallel processing.
57726f
 .NOTPARALLEL:
57726f
 .NO_PARALLEL:
57726f
-SUBDIRS =	isc isccc dns isccfg bind9 lwres irs samples
57726f
+SUBDIRS =	isc isc-pkcs11 isccc dns dns-pkcs11 isccfg bind9 lwres irs samples
57726f
 TARGETS =
57726f
 
57726f
 @BIND9_MAKE_RULES@
57726f
diff --git a/lib/dns-pkcs11/Makefile.in b/lib/dns-pkcs11/Makefile.in
ce773a
index 1d0f5df..98c9ba0 100644
57726f
--- a/lib/dns-pkcs11/Makefile.in
57726f
+++ b/lib/dns-pkcs11/Makefile.in
ce773a
@@ -24,17 +24,17 @@ VERSION=@BIND9_VERSION@
57726f
 
ce773a
 @BIND9_MAKE_INCLUDES@
57726f
 
57726f
-CINCLUDES =	-I. -I${top_srcdir}/lib/dns -Iinclude ${DNS_INCLUDES} \
57726f
-		${ISC_INCLUDES} ${MAXMINDDB_CFLAGS} \
57726f
+CINCLUDES =	-I. -I${top_srcdir}/lib/dns-pkcs11 -Iinclude ${DNS_PKCS11_INCLUDES} \
ce773a
+		${ISC_PKCS11_INCLUDES} ${MAXMINDDB_CFLAGS} \
ce773a
 		@DST_OPENSSL_INC@ @DST_GSSAPI_INC@
57726f
 
ce773a
-CDEFINES =	-DUSE_MD5 @CRYPTO@ @USE_GSSAPI@
ce773a
+CDEFINES =	-DUSE_MD5 @CRYPTO_PK11@ @USE_GSSAPI@
57726f
 
57726f
 CWARNINGS =
57726f
 
57726f
-ISCLIBS =	../../lib/isc/libisc.@A@
57726f
+ISCLIBS =	../../lib/isc-pkcs11/libisc-pkcs11.@A@
57726f
 
57726f
-ISCDEPLIBS =	../../lib/isc/libisc.@A@
57726f
+ISCDEPLIBS =	../../lib/isc-pkcs11/libisc-pkcs11.@A@
57726f
 
57726f
 LIBS =		${MAXMINDDB_LIBS} @LIBS@
57726f
 
ce773a
@@ -148,15 +148,15 @@ version.@O@: version.c
57726f
 		-DLIBAGE=${LIBAGE} \
57726f
 		-c ${srcdir}/version.c
57726f
 
57726f
-libdns.@SA@: ${OBJS}
57726f
+libdns-pkcs11.@SA@: ${OBJS}
57726f
 	${AR} ${ARFLAGS} $@ ${OBJS}
57726f
 	${RANLIB} $@
57726f
 
57726f
-libdns.la: ${OBJS}
57726f
+libdns-pkcs11.la: ${OBJS}
57726f
 	${LIBTOOL_MODE_LINK} \
57726f
-		${CC} ${ALL_CFLAGS} ${LDFLAGS} -o libdns.la -rpath ${libdir} \
57726f
+		${CC} ${ALL_CFLAGS} ${LDFLAGS} -o libdns-pkcs11.la -rpath ${libdir} \
57726f
 		-version-info ${LIBINTERFACE}:${LIBREVISION}:${LIBAGE} \
57726f
-		${OBJS} ${ISCLIBS} @DNS_CRYPTO_LIBS@ ${LIBS}
57726f
+		${OBJS} ${ISCLIBS} @DNS_CRYPTO_PK11_LIBS@ ${LIBS}
57726f
 
57726f
 include: gen
57726f
 	${MAKE} include/dns/enumtype.h
ce773a
@@ -187,22 +187,22 @@ gen: gen.c
57726f
 	${BUILD_CPPFLAGS} ${BUILD_LDFLAGS} -o $@ ${srcdir}/gen.c \
57726f
 	${BUILD_LIBS} ${LFS_LIBS}
57726f
 
57726f
-timestamp: include libdns.@A@
57726f
+timestamp: include libdns-pkcs11.@A@
57726f
 	touch timestamp
57726f
 
57726f
-testdirs: libdns.@A@
57726f
+testdirs: libdns-pkcs11.@A@
57726f
 
57726f
 installdirs:
57726f
 	$(SHELL) ${top_srcdir}/mkinstalldirs ${DESTDIR}${libdir}
57726f
 
57726f
 install:: timestamp installdirs
57726f
-	${LIBTOOL_MODE_INSTALL} ${INSTALL_LIBRARY} libdns.@A@ ${DESTDIR}${libdir}
57726f
+	${LIBTOOL_MODE_INSTALL} ${INSTALL_LIBRARY} libdns-pkcs11.@A@ ${DESTDIR}${libdir}
57726f
 
57726f
 uninstall::
57726f
-	${LIBTOOL_MODE_UNINSTALL} rm -f ${DESTDIR}${libdir}/libdns.@A@
57726f
+	${LIBTOOL_MODE_UNINSTALL} rm -f ${DESTDIR}${libdir}/libdns-pkcs11.@A@
57726f
 
57726f
 clean distclean::
57726f
-	rm -f libdns.@A@ timestamp
57726f
+	rm -f libdns-pkcs11.@A@ timestamp
57726f
 	rm -f gen code.h include/dns/enumtype.h include/dns/enumclass.h
57726f
 	rm -f include/dns/rdatastruct.h
57726f
 	rm -f dnstap.pb-c.c dnstap.pb-c.h
57726f
diff --git a/lib/isc-pkcs11/Makefile.in b/lib/isc-pkcs11/Makefile.in
e48f32
index 7e3e9ce..58d7466 100644
57726f
--- a/lib/isc-pkcs11/Makefile.in
57726f
+++ b/lib/isc-pkcs11/Makefile.in
57726f
@@ -23,8 +23,8 @@ CINCLUDES =	-I${srcdir}/unix/include \
57726f
 		-I${srcdir}/@ISC_THREAD_DIR@/include \
57726f
 		-I${srcdir}/@ISC_ARCH_DIR@/include \
57726f
 		-I./include \
57726f
-		-I${srcdir}/include ${DNS_INCLUDES} @ISC_OPENSSL_INC@
57726f
-CDEFINES =	@CRYPTO@ -DPK11_LIB_LOCATION=\"${PROVIDER}\"
57726f
+		-I${srcdir}/include ${DNS_PKCS11_INCLUDES}
57726f
+CDEFINES =	@CRYPTO_PK11@ -DPK11_LIB_LOCATION=\"${PROVIDER}\"
57726f
 CWARNINGS =
57726f
 
57726f
 # Alphabetically
e48f32
@@ -107,40 +107,40 @@ version.@O@: version.c
57726f
 		-DLIBAGE=${LIBAGE} \
57726f
 		-c ${srcdir}/version.c
57726f
 
57726f
-libisc.@SA@: ${OBJS} ${SYMTBLOBJS}
57726f
+libisc-pkcs11.@SA@: ${OBJS} ${SYMTBLOBJS}
57726f
 	${AR} ${ARFLAGS} $@ ${OBJS} ${SYMTBLOBJS}
57726f
 	${RANLIB} $@
57726f
 
57726f
-libisc-nosymtbl.@SA@: ${OBJS}
57726f
+libisc-pkcs11-nosymtbl.@SA@: ${OBJS}
57726f
 	${AR} ${ARFLAGS} $@ ${OBJS}
57726f
 	${RANLIB} $@
57726f
 
57726f
-libisc.la: ${OBJS} ${SYMTBLOBJS}
57726f
+libisc-pkcs11.la: ${OBJS} ${SYMTBLOBJS}
57726f
 	${LIBTOOL_MODE_LINK} \
57726f
-		${CC} ${ALL_CFLAGS} ${LDFLAGS} -o libisc.la -rpath ${libdir} \
57726f
+		${CC} ${ALL_CFLAGS} ${LDFLAGS} -o libisc-pkcs11.la -rpath ${libdir} \
57726f
 		-version-info ${LIBINTERFACE}:${LIBREVISION}:${LIBAGE} \
57726f
 		${OBJS} ${SYMTBLOBJS} ${LIBS}
57726f
 
57726f
-libisc-nosymtbl.la: ${OBJS}
57726f
+libisc-pkcs11-nosymtbl.la: ${OBJS}
57726f
 	${LIBTOOL_MODE_LINK} \
57726f
-		${CC} ${ALL_CFLAGS} ${LDFLAGS} -o libisc-nosymtbl.la -rpath ${libdir} \
57726f
+		${CC} ${ALL_CFLAGS} ${LDFLAGS} -o libisc-pkcs11-nosymtbl.la -rpath ${libdir} \
57726f
 		-version-info ${LIBINTERFACE}:${LIBREVISION}:${LIBAGE} \
57726f
 		${OBJS} ${LIBS}
57726f
 
57726f
-timestamp: libisc.@A@ libisc-nosymtbl.@A@
57726f
+timestamp: libisc-pkcs11.@A@ libisc-pkcs11-nosymtbl.@A@
57726f
 	touch timestamp
57726f
 
57726f
-testdirs: libisc.@A@ libisc-nosymtbl.@A@
57726f
+testdirs: libisc-pkcs11.@A@ libisc-pkcs11-nosymtbl.@A@
57726f
 
57726f
 installdirs:
57726f
 	$(SHELL) ${top_srcdir}/mkinstalldirs ${DESTDIR}${libdir}
57726f
 
57726f
 install:: timestamp installdirs
57726f
-	${LIBTOOL_MODE_INSTALL} ${INSTALL_LIBRARY} libisc.@A@ ${DESTDIR}${libdir}
57726f
+	${LIBTOOL_MODE_INSTALL} ${INSTALL_LIBRARY} libisc-pkcs11.@A@ ${DESTDIR}${libdir}
57726f
 
57726f
 uninstall::
57726f
-	${LIBTOOL_MODE_UNINSTALL} rm -f ${DESTDIR}${libdir}/libisc.@A@
57726f
+	${LIBTOOL_MODE_UNINSTALL} rm -f ${DESTDIR}${libdir}/libisc-pkcs11.@A@
57726f
 
57726f
 clean distclean::
57726f
-	rm -f libisc.@A@ libisc-nosymtbl.@A@ libisc.la \
57726f
-	libisc-nosymtbl.la timestamp
57726f
+	rm -f libisc-pkcs11.@A@ libisc-pkcs11-nosymtbl.@A@ libisc-pkcs11.la \
57726f
+	libisc-pkcs11-nosymtbl.la timestamp
57726f
diff --git a/make/includes.in b/make/includes.in
e48f32
index 66efe68..966671f 100644
57726f
--- a/make/includes.in
57726f
+++ b/make/includes.in
e48f32
@@ -41,3 +41,13 @@ BIND9_INCLUDES = @BIND9_BIND9_BUILDINCLUDE@ \
57726f
 
57726f
 TEST_INCLUDES = \
57726f
 	-I${top_srcdir}/lib/tests/include
57726f
+
57726f
+ISC_PKCS11_INCLUDES = @BIND9_ISC_BUILDINCLUDE@ \
57726f
+	-I${top_srcdir}/lib/isc-pkcs11 \
57726f
+	-I${top_srcdir}/lib/isc-pkcs11/include \
57726f
+	-I${top_srcdir}/lib/isc-pkcs11/unix/include \
57726f
+	-I${top_srcdir}/lib/isc-pkcs11/@ISC_THREAD_DIR@/include \
57726f
+	-I${top_srcdir}/lib/isc-pkcs11/@ISC_ARCH_DIR@/include
57726f
+
57726f
+DNS_PKCS11_INCLUDES = @BIND9_DNS_BUILDINCLUDE@ \
57726f
+	-I${top_srcdir}/lib/dns-pkcs11/include