From cfa158ea1850601c96085504e53a638f09e7d97c Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Sun, 17 Mar 2019 15:41:24 +0100 Subject: [PATCH] Fix: Do not crash main program on incompatible plugins Signed-off-by: Knut Ahlers --- plugins.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/plugins.go b/plugins.go index 5971cda..2386f12 100644 --- a/plugins.go +++ b/plugins.go @@ -2,6 +2,7 @@ package main import ( "os" + "path" "path/filepath" "plugin" "strings" @@ -28,24 +29,28 @@ func loadPlugins(pluginDir string) error { return errors.New("Plugin directory is not a directory") } - return errors.Wrap(filepath.Walk(pluginDir, func(path string, info os.FileInfo, err error) error { + return errors.Wrap(filepath.Walk(pluginDir, func(currentPath string, info os.FileInfo, err error) error { if err != nil { return err } - if !strings.HasSuffix(path, ".so") { + if !strings.HasSuffix(currentPath, ".so") { // Ignore that file, is not a plugin return nil } - p, err := plugin.Open(path) + logger := log.WithField("plugin", path.Base(currentPath)) + + p, err := plugin.Open(currentPath) if err != nil { - return errors.Wrapf(err, "Unable to load plugin %q", path) + logger.WithError(err).Error("Unable to open plugin") + return nil } f, err := p.Lookup("Register") if err != nil { - return errors.Wrapf(err, "Unable to find register function in %q", path) + logger.WithError(err).Error("Unable to find register function") + return nil } f.(func(plugins.RegisterAuthenticatorFunc, plugins.RegisterMFAProviderFunc))(