Add enough static linking support to run the test suite without shared
libraries, to facilitate gcov and other kinds of instrumentation. The
necessary changes include:
* Undo some of the changes which removed static linking support,
and cannibalize the defunct krb5_force_static conditional block
in aclocal.m4.
* Add --enable-static-only configure option.
* For plugins, use a different symbol name for static and dynamic
builds, via a macro in k5plugin.h.
* Add build machinery for building static libraries for plugins
(somewhat grotty due to the difference in names).
* Move plugin subdirs earlier in SUBDIRS in src/Makefile.in.
* Make the in-tree KDB5 plugins dependencies of libkdb5 in a static
build (aclocal.m4 has to know what they are).
* In kdb5.c, cannibalize the broken _KDB5_STATIC_LINK support to
allow "loading" of statically linked plugin libraries.
Preauth, authdata, locate, and GSSAPI plugins are not handled by this
change, as they are not currently necessary to the test suite.
Supporting GSSAPI plugins may be a bit tricky but the others should be
straightforward if they become needed.
$(STLIBEXT) changes from .a-nobuild to .a in a normal shared build as
a result of these changes (except on AIX where aclocal.m4 changes it).
This does not seem to be important as we avoid selecting the static
library for building via other means.
ticket: 6510
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@22406
dc483132-0cff-0310-8789-
dd5450dbe970
# plugins/preauth/wpse
# plugins/preauth/cksum_body
# plugins/authdata/greet
-SUBDIRS=util include lib kdc kadmin @ldap_plugin_dir@ slave clients \
+SUBDIRS=util include lib \
+ @ldap_plugin_dir@ \
plugins/kdb/db2 \
plugins/preauth/pkinit \
plugins/preauth/encrypted_challenge \
- appl tests \
+ kdc kadmin slave clients appl tests \
config-files gen-manpages
BUILDTOP=$(REL)$(C)
LOCALINCLUDES = -I$(srcdir)
fi
AC_SUBST(LIBLIST)
AC_SUBST(LIBLINKS)
+AC_SUBST(PLUGIN)
+AC_SUBST(PLUGINLINK)
+AC_SUBST(PLUGININST)
+AC_SUBST(KDB5_PLUGIN_DEPLIBS)
+AC_SUBST(KDB5_PLUGIN_LIBS)
AC_SUBST(MAKE_SHLIB_COMMAND)
AC_SUBST(SHLIB_RPATH_FLAGS)
AC_SUBST(SHLIB_EXPFLAGS)
[if test "$enableval" != yes; then
AC_MSG_ERROR([Sorry, this release builds only shared libraries, cannot disable them.])
fi])
+AC_ARG_ENABLE([static-only],
+AC_HELP_STRING([--enable-static-only],[use static libraries and plugins]),
+[static_only=$enableval],
+[static_only=no])
+
AC_ARG_ENABLE([rpath],
AC_HELP_STRING([--disable-rpath],[suppress run path flags in link lines]),
[enable_rpath=$enableval],
DEPLIBEXT=$SHLIBEXT
-if test "$krb5_force_static" = "yes"; then
+if test "x$static_only" = xyes; then
LIBLIST='lib$(LIBBASE)$(STLIBEXT)'
LIBLINKS='$(TOPLIBD)/lib$(LIBBASE)$(STLIBEXT)'
+ PLUGIN='libkrb5_$(LIBBASE)$(STLIBEXT)'
+ PLUGINLINK='$(TOPLIBD)/libkrb5_$(LIBBASE)$(STLIBEXT)'
+ PLUGININST=install-static
OBJLISTS=OBJS.ST
- # This used to be install-static, but now we only follow this
- # path for internal libraries we don't want installed, not for
- # configure-time requests for installed static libraries.
- LIBINSTLIST=
-# CFLAGS="$CFLAGS -D_KDB5_STATIC_LINK"
+ LIBINSTLIST=install-static
+ DEPLIBEXT=$STLIBEXT
+ AC_DEFINE([STATIC_PLUGINS], 1, [Define for static plugin linkage])
+
+ KDB5_PLUGIN_DEPLIBS='$(TOPLIBD)/libkrb5_db2$(DEPLIBEXT)'
+ KDB5_PLUGIN_LIBS='-lkrb5_db2'
+ if test "x$OPENLDAP_PLUGIN" = xyes; then
+ KDB5_PLUGIN_DEBLIBS=$KDB5_PLUGIN_DEPLIBS' $(TOPLIBD)/libkrb5_ldap$(DEPLIBEXT)'
+ KDB5_PLUGIN_LIBS=$KDB_LUGIN_LIBS' -lkrb5_ldap'
+ fi
AC_MSG_RESULT([Forcing static libraries.])
# avoid duplicate rules generation for AIX and such
fi
case "$SHLIBSEXT" in
.so.s-nobuild)
- SHLIB_HAVE_MINOR_VERS=no
LIBLIST='lib$(LIBBASE)$(SHLIBEXT)'
LIBLINKS='$(TOPLIBD)/lib$(LIBBASE)$(SHLIBEXT) $(TOPLIBD)/lib$(LIBBASE)$(SHLIBVEXT)'
LIBINSTLIST="install-shared"
;;
*)
- SHLIB_HAVE_MINOR_VERS=yes
LIBLIST='lib$(LIBBASE)$(SHLIBEXT) lib$(LIBBASE)$(SHLIBSEXT)'
LIBLINKS='$(TOPLIBD)/lib$(LIBBASE)$(SHLIBEXT) $(TOPLIBD)/lib$(LIBBASE)$(SHLIBVEXT) $(TOPLIBD)/lib$(LIBBASE)$(SHLIBSEXT)'
LIBINSTLIST="install-shlib-soname"
;;
esac
OBJLISTS="OBJS.SH"
+ PLUGIN='$(LIBBASE)$(DYNOBJEXT)'
+ PLUGINLINK=
+ PLUGININST=install-plugin
+ KDB5_PLUGIN_DEPLIBS=
+ KDB5_PLUGIN_LIBS=
fi
CC_LINK="$CC_LINK_SHARED"
CXX_LINK="$CXX_LINK_SHARED"
-AC_SUBST(SHLIB_HAVE_MINOR_VERS)
if test -z "$LIBLIST"; then
AC_MSG_ERROR([must enable one of shared or static libraries])
# STOBJLISTS=dir1/OBJS.ST dir2/OBJS.ST etc...
SHOBJLISTS=$(STOBJLISTS:.ST=.SH)
+PFOBJLISTS=$(STOBJLISTS:.ST=.PF)
dummy-target-1 $(SUBDIROBJLISTS) $(SUBDIROBJLISTS:.ST=.SH) $(SUBDIROBJLISTS:.ST=.PF): all-recurse
# Gets invoked as $(PARSE_OBJLISTS) list-of-OBJS.*-files
PARSE_OBJLISTS= set -x && $(PERL) -p -e 'BEGIN { $$SIG{__WARN__} = sub {die @_} }; $$e=$$ARGV; $$e =~ s/OBJS\...$$//; s/^/ /; s/ $$//; s/ / $$e/g;'
-SHLIBVEXT=$(SHLIBEXT)
-LIBLIST=$(LIBBASE)$(DYNOBJEXT)
LIBINSTLIST=install-shared
+libkrb5_$(LIBBASE)$(STLIBEXT): $(STOBJLISTS)
+ $(RM) $@
+ @echo "building static $(LIBBASE) library"
+ set -x; objlist=`$(PARSE_OBJLISTS) $(STOBJLISTS)` && $(AR) cq $@ $$objlist
+ $(RANLIB) $@
+
$(LIBBASE)$(DYNOBJEXT): $(SHOBJLISTS) $(DYNOBJ_EXPDEPS) $(SHLIB_EXPORT_FILE_DEP)
$(RM) $@
@echo "building dynamic $(LIBBASE) object"
$(RM) darwin.exports
sed "s/^/_/" < $(SHLIB_EXPORT_FILE) > darwin.exports
-$(TOPLIBD)/$(LIBBASE)$(SHLIBEXT): $(LIBBASE)$(SHLIBEXT)
+libkrb5_$(LIBBASE)$(PFLIBEXT): $(PFOBJLISTS)
+ $(RM) $@
+ @echo "building profiled $(LIBBASE) library"
+ set -x; objlist=`$(PARSE_OBJLISTS) $(PFOBJLISTS)` && $(AR) cq $@ $$objlist
+ $(RANLIB) $@
+
+$(TOPLIBD)/libkrb5_$(LIBBASE)$(STLIBEXT):
$(RM) $@
- (cd $(TOPLIBD) && $(LN_S) $(RELDIR)/$(LIBBASE)$(SHLIBEXT) .)
+ (cd $(TOPLIBD) && $(LN_S) $(RELDIR)/libkrb5_$(LIBBASE)$(STLIBEXT) .)
-all-libs: $(LIBBASE)$(DYNOBJEXT) # $(LIBLIST)
+all-liblinks: all-libs $(PLUGINLINK)
+all-libs: $(PLUGIN)
clean-libs:
$(RM) $(LIBBASE)$(DYNOBJEXT)
$(RM) binutils.versions osf1.exports darwin.exports hpux10.exports
-install-libs: $(LIBINSTLIST)
-install-shared:
+install-libs: $(PLUGININST)
+install-static:
+ $(RM) $(DESTDIR)$(KRB5_LIBDIR)/libkrb5_$(LIBBASE)$(STLIBEXT)
+ $(INSTALL_DATA) libkrb5_$(LIBBASE)$(STLIBEXT) $(DESTDIR)$(KRB5_LIBDIR)
+ $(RANLIB) $(DESTDIR)$(KRB5_LIBDIR)/libkrb5_$(LIBBASE)$(STLIBEXT)
+install-plugin:
$(RM) $(DESTDIR)$(MODULE_INSTALL_DIR)/$(LIBBASE)$(DYNOBJEXT)
$(INSTALL_SHLIB) $(LIBBASE)$(DYNOBJEXT) $(DESTDIR)$(MODULE_INSTALL_DIR)
SHLIBEXT=.so-nobuild
SHLIBVEXT=.so.v-nobuild
SHLIBSEXT=.so.s-nobuild
-STLIBEXT=$(STLIBEXT_if_static)
# depending on whether we're building with shared libraries.
DEPLIBEXT=@DEPLIBEXT@
+KDB5_PLUGIN_DEPLIBS = @KDB5_PLUGIN_DEPLIBS@
+KDB5_PLUGIN_LIBS = @KDB5_PLUGIN_LIBS@
+
KADMCLNT_DEPLIB = $(TOPLIBD)/libkadm5clnt$(DEPLIBEXT)
KADMSRV_DEPLIB = $(TOPLIBD)/libkadm5srv$(DEPLIBEXT)
KDB5_DEPLIB = $(TOPLIBD)/libkdb5$(DEPLIBEXT)
APPUTILS_DEPLIB = $(TOPLIBD)/libapputils.a
KRB5_BASE_DEPLIBS = $(KRB5_DEPLIB) $(CRYPTO_DEPLIB) $(COM_ERR_DEPLIB) $(SUPPORT_DEPLIB)
-KDB5_DEPLIBS = $(KDB5_DEPLIB)
+KDB5_DEPLIBS = $(KDB5_DEPLIB) $(KDB5_PLUGIN_DEPLIBS)
GSS_DEPLIBS = $(GSS_DEPLIB)
GSSRPC_DEPLIBS = $(GSSRPC_DEPLIB) $(GSS_DEPLIBS)
KADM_COMM_DEPLIBS = $(GSSRPC_DEPLIBS) $(KDB5_DEPLIBS) $(GSSRPC_DEPLIBS)
SS_LIB = $(SS_LIB-@SS_VERSION@)
SS_LIB-sys = @SS_LIB@
SS_LIB-k5 = $(TOPLIBD)/libss.a
-KDB5_LIB = -lkdb5
+KDB5_LIB = -lkdb5 $(KDB5_PLUGIN_LIBS)
DL_LIB = @DL_LIB@
# Set to "lib$(LIBBASE)$(STEXT) lib$(LIBBASE)$(SHEXT) lib$(LIBBASE)$(PFEXT)" or
# some subset thereof by configure; determines which types of libs get
# built.
-LIBLIST=$(LIBLIST_@SHLIB_HAVE_MINOR_VERS@)
-LIBLIST_yes=lib$(LIBBASE)$(SHLIBEXT) lib$(LIBBASE)$(SHLIBSEXT)
-LIBLIST_no=lib$(LIBBASE)$(SHLIBEXT)
+LIBLIST=@LIBLIST@
# Set by configure; list of library symlinks to make to $(TOPLIBD)
-LIBLINKS=$(LIBLINKS_@SHLIB_HAVE_MINOR_VERS@)
-LIBLINKS_yes=$(TOPLIBD)/lib$(LIBBASE)$(SHLIBEXT) $(TOPLIBD)/lib$(LIBBASE)$(SHLIBVEXT) $(TOPLIBD)/lib$(LIBBASE)$(SHLIBSEXT)
-LIBLINKS_no=$(TOPLIBD)/lib$(LIBBASE)$(SHLIBEXT) $(TOPLIBD)/lib$(LIBBASE)$(SHLIBVEXT)
+LIBLINKS=@LIBLINKS@
+
+# Set by configure; name of plugin module to build (libfoo.a or foo.so)
+PLUGIN=@PLUGIN@
+
+# Set by configure; symlink for plugin module for static plugin linking
+PLUGINLINK=@PLUGINLINK@
+
+# Set by configure; list of install targets for libraries
+LIBINSTLIST=@LIBINSTLIST@
-# Set by configure; list of install targets
-LIBINSTLIST=$(LIBINSTLIST_@SHLIB_HAVE_MINOR_VERS@)
-LIBINSTLIST_yes=install-shlib-soname
-LIBINSTLIST_no=install-shared
+# Set by configure; install target
+PLUGININST=@PLUGININST@
# Some of these should really move to pre.in, since programs will need
# it too. (e.g. stuff that has dependencies on the libraries)
# usually .a
-STLIBEXT_if_static=@STLIBEXT@
-STLIBEXT=.a-nobuild
+STLIBEXT=@STLIBEXT@
# usually .so.$(LIBMAJOR).$(LIBMINOR)
SHLIBVEXT=@SHLIBVEXT@
# Set to "OBJS.ST OBJS.SH OBJS.PF" or some subset thereof by
# configure; determines which types of object files get built.
-OBJLISTS=OBJS.SH
+OBJLISTS=@OBJLISTS@
# Note that $(LIBSRCS) *cannot* contain any variable references, or
# the suffix substitution will break on some platforms!
#include "k5-err.h"
+/*
+ * Plugins normally export fixed symbol names, but when statically
+ * linking plugins, we need a different symbol name for each plugin.
+ * The first argument to PLUGIN_SYMBOL_NAME acts as the
+ * differentiator, and is only used for static plugin linking.
+ *
+ * Although this macro (and thus this header file) are used in plugins
+ * whose code lies inside the krb5 tree, plugins maintained separately
+ * from the krb5 tree do not need it; they can just use the fixed
+ * symbol name unconditionally.
+ */
+#ifdef STATIC_PLUGINS
+#define PLUGIN_SYMBOL_NAME(prefix, symbol) prefix ## _ ## symbol
+#else
+#define PLUGIN_SYMBOL_NAME(prefix, symbol) symbol
+#endif
+
struct plugin_file_handle; /* opaque */
struct plugin_dir_handle {
static k5_mutex_t db_lock = K5_MUTEX_PARTIAL_INITIALIZER;
-#ifdef _KDB5_STATIC_LINK
-#undef _KDB5_DYNAMIC_LINK
-#else
-#undef _KDB5_DYNAMIC_LINK
-/* to avoid redefinition problem */
-#define _KDB5_DYNAMIC_LINK
-#endif
-
static db_library lib_list;
/*
}
}
-static int kdb_db2_pol_err_loaded = 0;
-#ifdef _KDB5_STATIC_LINK
-#define DEF_SYMBOL(a) extern kdb_vftabl krb5_db_vftabl_ ## a
-#define GET_SYMBOL(a) (krb5_db_vftabl_ ## a)
+#ifdef STATIC_PLUGINS
+
+extern kdb_vftabl krb5_db2_kdb_function_table;
+#ifdef ENABLE_LDAP
+extern kdb_vftabl krb5_db2_ldap_function_table;
+#endif
+
static krb5_error_code
-kdb_load_library(krb5_context kcontext, char *lib_name, db_library * lib)
+kdb_load_library(krb5_context kcontext, char *lib_name, db_library *libptr)
{
krb5_error_code status;
- void *vftabl_addr = NULL;
- char buf[KRB5_MAX_ERR_STR];
-
- if (!strcmp("kdb_db2", lib_name) && (kdb_db2_pol_err_loaded == 0)) {
- initialize_adb_error_table();
- kdb_db2_pol_err_loaded = 1;
+ db_library lib;
+ kdb_vftabl *vftabl_addr = NULL;
+
+ if (strcmp(lib_name, "db2") == 0)
+ vftabl_addr = &krb5_db2_kdb_function_table;
+#ifdef ENABLE_LDAP
+ if (strcmp(lib_name, "ldap") == 0)
+ vftabl_addr = &krb5_ldap_kdb_function_table;
+#endif
+ if (!vftabl_addr) {
+ krb5_set_error_message(kcontext, KRB5_KDB_DBTYPE_NOTFOUND,
+ "Unable to find requested database type: %s",
+ lib_name);
+ return KRB5_KDB_DBTYPE_NOSUP;
}
- *lib = calloc((size_t) 1, sizeof(**lib));
- if (*lib == NULL) {
- status = ENOMEM;
- goto clean_n_exit;
- }
+ lib = calloc(1, sizeof(*lib));
+ if (lib == NULL)
+ return ENOMEM;
status = kdb_init_lib_lock(*lib);
- if (status) {
- goto clean_n_exit;
- }
-
- strlcpy((*lib)->name, lib_name, sizeof((*lib)->name));
-
-#if !defined(KDB5_USE_LIB_KDB_DB2) && !defined(KDB5_USE_LIB_TEST)
-#error No database module defined
-#endif
-
-#ifdef KDB5_USE_LIB_KDB_DB2
- if (strcmp(lib_name, "kdb_db2") == 0) {
- DEF_SYMBOL(kdb_db2);
- vftabl_addr = (void *) &GET_SYMBOL(kdb_db2);
- } else
-#endif
-#ifdef KDB5_USE_LIB_TEST
- if (strcmp(lib_name, "test") == 0) {
- DEF_SYMBOL(test);
- vftabl_addr = (void *) &GET_SYMBOL(test);
- } else
-#endif
- {
- snprintf(buf, sizeof(buf),
- "Program not built to support %s database type\n",
- lib_name);
- status = KRB5_KDB_DBTYPE_NOSUP;
- krb5_db_set_err(kcontext, krb5_err_have_str, status, buf);
- goto clean_n_exit;
- }
+ if (status)
+ goto cleanup;
- memcpy(&(*lib)->vftabl, vftabl_addr, sizeof(kdb_vftabl));
+ strlcpy(lib->name, lib_name, sizeof(lib->name));
+ memcpy(&lib->vftabl, vftabl_addr, sizeof(kdb_vftabl));
+ kdb_setup_opt_functions(lib);
- kdb_setup_opt_functions(*lib);
+ status = lib->vftabl.init_library();
+ if (status)
+ goto cleanup;
- if ((status = (*lib)->vftabl.init_library())) {
- /* ERROR. library not initialized cleanly */
- snprintf(buf, sizeof(buf),
- "%s library initialization failed, error code %ld\n",
- lib_name, status);
- status = KRB5_KDB_DBTYPE_INIT;
- krb5_db_set_err(kcontext, krb5_err_have_str, status, buf);
- goto clean_n_exit;
- }
+ *libptr = lib;
+ return 0;
- clean_n_exit:
- if (status) {
- free(*lib), *lib = NULL;
- }
+cleanup:
+ free(lib);
return status;
}
filebases[0] = lib_name;
filebases[1] = NULL;
- if (!strcmp(DB2_NAME, lib_name) && (kdb_db2_pol_err_loaded == 0)) {
- initialize_adb_error_table();
- kdb_db2_pol_err_loaded = 1;
- }
-
*lib = calloc((size_t) 1, sizeof(**lib));
if (*lib == NULL) {
status = ENOMEM;
krb5_error_code status = 0;
int locked = 0;
db_library curr_elt, prev_elt = NULL;
+ static int kdb_db2_pol_err_loaded = 0;
+
+ if (!strcmp(DB2_NAME, lib_name) && (kdb_db2_pol_err_loaded == 0)) {
+ initialize_adb_error_table();
+ kdb_db2_pol_err_loaded = 1;
+ }
if ((status = kdb_lock_list()) != 0) {
goto clean_n_exit;
SRCS= greet_auth.c
-all-unix:: $(LIBBASE)$(SO_EXT)
+all-unix:: all-liblinks
install-unix:: install-libs
clean-unix:: clean-libs clean-libobjs
pol_xdr.o \
db2_exp.o
-all-unix:: $(LIBBASE)$(SO_EXT)
+all-unix:: all-liblinks
install-unix:: install-libs
clean-unix:: clean-libs clean-libobjs
* Exposed API
*/
-kdb_vftabl kdb_function_table = {
+kdb_vftabl PLUGIN_SYMBOL_NAME(krb5_db2, kdb_function_table) = {
1, /* major version number 1 */
0, /* minor version number 0 */
/* init_library */ hack_init,
STOBJLISTS=OBJS.ST
STLIBOBJS= ldap_exp.o
-all-unix:: $(LIBBASE)$(SO_EXT)
+all-unix:: all-liblinks
install-unix:: install-libs
clean-unix:: clean-libs clean-libobjs
* Exposed API
*/
-kdb_vftabl kdb_function_table = {
+kdb_vftabl PLUGIN_SYMBOL_NAME(krb5_ldap, kdb_function_table) = {
1, /* major version number 1 */
0, /* minor version number 0 */
/* init_library */ krb5_ldap_lib_init,
STOBJLISTS=OBJS.ST
STLIBOBJS= py-locate.o
-all-unix:: $(LIBBASE)$(SO_EXT)
+all-unix:: all-liblinks
install-unix:: install-libs
clean-unix:: clean-libs clean-libobjs
SRCS= $(srcdir)/encrypted_challenge_main.c
-all-unix:: $(LIBBASE)$(SO_EXT)
+all-unix:: all-liblinks
install-unix:: install-libs
clean-unix:: clean-libs clean-libobjs
$(srcdir)/pkinit_matching.c \
$(srcdir)/pkinit_crypto_openssl.c
-all-unix:: $(LIBBASE)$(SO_EXT)
+all-unix:: all-liblinks
install-unix:: install-libs
clean-unix:: clean-libs clean-libobjs
return 0;
}
-struct krb5plugin_preauth_client_ftable_v1 preauthentication_client_1 = {
+/* Only necessary for static plugin linking support. */
+#include "k5-plugin.h"
+
+struct krb5plugin_preauth_client_ftable_v1
+PLUGIN_SYMBOL_NAME(krb5_preauth, preauthentication_client_1) = {
"pkinit", /* name */
supported_client_pa_types, /* pa_type_list */
NULL, /* enctype_list */
free(reqctx);
}
-struct krb5plugin_preauth_server_ftable_v1 preauthentication_server_1 = {
+/* Only necessary for static plugin linking support. */
+#include "k5-plugin.h"
+
+struct krb5plugin_preauth_server_ftable_v1
+PLUGIN_SYMBOL_NAME(krb5_pkinit, preauthentication_server_1) = {
"pkinit", /* name */
supported_server_pa_types, /* pa_type_list */
pkinit_server_plugin_init, /* (*init_proc) */