]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
Make plugin auto-registration work on Windows
authorGreg Hudson <ghudson@mit.edu>
Wed, 16 May 2018 18:02:20 +0000 (11:02 -0700)
committerGreg Hudson <ghudson@mit.edu>
Tue, 12 Jun 2018 17:11:24 +0000 (13:11 -0400)
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
src/include/osconf.hin
src/lib/krb5/krb/init_ctx.c
src/lib/krb5/krb/plugin.c

index ce545492d222868e7426f858083442d68f3c1723..3d44c56027d7bdaf3c603d6eee5830a1b96ea75e 100644 (file)
@@ -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
index 98a467454b4feed9265a0f285b51d1cae0efcddd..4b6f91b8f9ffbfc38895681e6997301d6e61ef9c 100644 (file)
 #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"
index 4246c5dd274f2ca890a2e989b69ac7c8cb05df65..bd8ba2467b13d89321d28c49b44e87a465b8ee75 100644 (file)
@@ -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;
 }
index 31aaf661d9afba202a3d8730ab3d60733d820751..5761de009472f6ccf4d52a8b2d88ddf0ee06597e 100644 (file)
@@ -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;