krb5 commit: Make plugin auto-registration work on Windows

Greg Hudson <[email protected]>
Newsgroups gmane.comp.encryption.kerberos.cvs
Message-ID <[email protected]>
https://github.com/krb5/krb5/commit/bae5aae9a6e937e4eaa995e6a0d68b398199d841
commit bae5aae9a6e937e4eaa995e6a0d68b398199d841
Author: Greg Hudson <[email protected]>
Date:   Wed May 16 11:02:20 2018 -0700

    Make plugin auto-registration work on Windows
    
    Make plugin_base_dir subject to parameter expansion, and set its
    default to %{LIBDIR}\plugins on Windows (%{LIBDIR} expands to the
    directory where the krb5 DLL lives).  For auto-registered modules,
    assume that we will build 32-bit and 64-bit DLLs and name them
    "modname32.dll" and "modname64.dll".  In k5_plugin_register_dyn(), use
    k5_path_join() instead of assuming the path separator is "/".
    
    ticket: 8685 (new)

 doc/admin/conf_files/krb5_conf.rst |    3 ++-
 src/include/osconf.hin             |   11 +++++++++++
 src/lib/krb5/krb/init_ctx.c        |    9 ++++++---
 src/lib/krb5/krb/plugin.c          |    8 ++++++--
 4 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/doc/admin/conf_files/krb5_conf.rst b/doc/admin/conf_files/krb5_conf.rst
index ce54549..3d44c56 100644
--- a/doc/admin/conf_files/krb5_conf.rst
+++ b/doc/admin/conf_files/krb5_conf.rst
@@ -328,7 +328,8 @@ The libdefaults section may contain any of the following relations:
 **plugin_base_dir**
     If set, determines the base directory where krb5 plugins are
     located.  The default value is the ``krb5/plugins`` subdirectory
-    of the krb5 library directory.
+    of the krb5 library directory.  This relation is subject to
+    parameter expansion (see below) in release 1.17 and later.
 
 **preferred_preauth_types**
     This allows you to set the preferred preauthentication types which
diff --git a/src/include/osconf.hin b/src/include/osconf.hin
index 98a4674..4b6f91b 100644
--- a/src/include/osconf.hin
+++ b/src/include/osconf.hin
@@ -55,8 +55,19 @@
 #endif
 #endif /* _WINDOWS  */
 
+#ifdef _WIN32
+#define DEFAULT_PLUGIN_BASE_DIR "%{LIBDIR}\\plugins"
+#else
 #define DEFAULT_PLUGIN_BASE_DIR "@LIBDIR/krb5/plugins"
+#endif
+
+#if defined(_WIN64)
+#define PLUGIN_EXT              "64.dll"
+#elif defined(_WIN32)
+#define PLUGIN_EXT              "32.dll"
+#else
 #define PLUGIN_EXT              "@DYNOBJEXT"
+#endif
 
 #define KDC_DIR                 "@LOCALSTATEDIR/krb5kdc"
 #define KDC_RUN_DIR             "@RUNSTATEDIR/krb5kdc"
diff --git a/src/lib/krb5/krb/init_ctx.c b/src/lib/krb5/krb/init_ctx.c
index 4246c5d..bd8ba24 100644
--- a/src/lib/krb5/krb/init_ctx.c
+++ b/src/lib/krb5/krb/init_ctx.c
@@ -145,6 +145,7 @@ krb5_init_context_profile(profile_t profile, krb5_flags flags,
     } seed_data;
     krb5_data seed;
     int tmp;
+    char *plugin_dir = NULL;
 
     /* Verify some assumptions.  If the assumptions hold and the
        compiler is optimizing, this should result in no code being
@@ -261,8 +262,9 @@ krb5_init_context_profile(profile_t profile, krb5_flags flags,
 
     retval = profile_get_string(ctx->profile, KRB5_CONF_LIBDEFAULTS,
                                 KRB5_CONF_PLUGIN_BASE_DIR, 0,
-                                DEFAULT_PLUGIN_BASE_DIR,
-                                &ctx->plugin_base_dir);
+                                DEFAULT_PLUGIN_BASE_DIR, &plugin_dir);
+    if (!retval)
+        retval = k5_expand_path_tokens(ctx, plugin_dir, &ctx->plugin_base_dir);
     if (retval) {
         TRACE_PROFILE_ERR(ctx, KRB5_CONF_PLUGIN_BASE_DIR,
                           KRB5_CONF_LIBDEFAULTS, retval);
@@ -288,9 +290,10 @@ krb5_init_context_profile(profile_t profile, krb5_flags flags,
     (void)profile_get_string(ctx->profile, KRB5_CONF_LIBDEFAULTS,
                              KRB5_CONF_ERR_FMT, NULL, NULL, &ctx->err_fmt);
     *context_out = ctx;
-    return 0;
+    ctx = NULL;
 
 cleanup:
+    profile_release_string(plugin_dir);
     krb5_free_context(ctx);
     return retval;
 }
diff --git a/src/lib/krb5/krb/plugin.c b/src/lib/krb5/krb/plugin.c
index 31aaf66..5761de0 100644
--- a/src/lib/krb5/krb/plugin.c
+++ b/src/lib/krb5/krb/plugin.c
@@ -473,14 +473,18 @@ k5_plugin_register_dyn(krb5_context context, int interface_id,
 {
     krb5_error_code ret;
     struct plugin_interface *interface = get_interface(context, interface_id);
-    char *path;
+    char *fname, *path;
 
     /* Disallow registering plugins after load. */
     if (interface == NULL || interface->configured)
         return EINVAL;
 
-    if (asprintf(&path, "%s/%s%s", modsubdir, modname, PLUGIN_EXT) < 0)
+    if (asprintf(&fname, "%s%s", modname, PLUGIN_EXT) < 0)
         return ENOMEM;
+    ret = k5_path_join(modsubdir, fname, &path);
+    free(fname);
+    if (ret)
+        return ret;
     ret = register_module(context, interface, modname, path, NULL);
     free(path);
     return ret;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.