Signed-off-by: Doug Nazar <nazard@xxxxxxxx> --- support/nfsidmap/libnfsidmap.c | 40 ++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/support/nfsidmap/libnfsidmap.c b/support/nfsidmap/libnfsidmap.c index 6b5647d2..22b319b8 100644 --- a/support/nfsidmap/libnfsidmap.c +++ b/support/nfsidmap/libnfsidmap.c @@ -237,24 +237,40 @@ static int load_translation_plugin(char *method, struct mapping_plugin *plgn) { void *dl = NULL; struct trans_func *trans = NULL; - libnfsidmap_plugin_init_t init_func; + libnfsidmap_plugin_init_t init_func = NULL; char plgname[128]; int ret = 0; - snprintf(plgname, sizeof(plgname), "%s/%s.so", PATH_PLUGINS, method); + /* Look for library using search path first to allow overriding */ + snprintf(plgname, sizeof(plgname), "%s.so", method); dl = dlopen(plgname, RTLD_NOW | RTLD_LOCAL); - if (dl == NULL) { - IDMAP_LOG(1, ("libnfsidmap: Unable to load plugin: %s", - dlerror())); - return -1; + if (dl != NULL) { + /* Is it really one of our libraries */ + init_func = (libnfsidmap_plugin_init_t) dlsym(dl, PLUGIN_INIT_FUNC); + if (init_func == NULL) { + dlclose(dl); + dl = NULL; + } } - init_func = (libnfsidmap_plugin_init_t) dlsym(dl, PLUGIN_INIT_FUNC); - if (init_func == NULL) { - IDMAP_LOG(1, ("libnfsidmap: Unable to get init function: %s", - dlerror())); - dlclose(dl); - return -1; + + if (dl == NULL) { + /* Fallback to hard-coded path */ + snprintf(plgname, sizeof(plgname), "%s/%s.so", PATH_PLUGINS, method); + + dl = dlopen(plgname, RTLD_NOW | RTLD_LOCAL); + if (dl == NULL) { + IDMAP_LOG(1, ("libnfsidmap: Unable to load plugin: %s", + dlerror())); + return -1; + } + init_func = (libnfsidmap_plugin_init_t) dlsym(dl, PLUGIN_INIT_FUNC); + if (init_func == NULL) { + IDMAP_LOG(1, ("libnfsidmap: Unable to get init function: %s", + dlerror())); + dlclose(dl); + return -1; + } } trans = init_func(); if (trans == NULL) { -- 2.26.2