1
0
Fork 0
mirror of https://github.com/Luzifer/nginx-sso.git synced 2024-12-20 12:51:17 +00:00

Fix: Do not crash main program on incompatible plugins

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2019-03-17 15:41:24 +01:00
parent 7f6de7097a
commit cfa158ea18
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E

View file

@ -2,6 +2,7 @@ package main
import ( import (
"os" "os"
"path"
"path/filepath" "path/filepath"
"plugin" "plugin"
"strings" "strings"
@ -28,24 +29,28 @@ func loadPlugins(pluginDir string) error {
return errors.New("Plugin directory is not a directory") 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 { if err != nil {
return err return err
} }
if !strings.HasSuffix(path, ".so") { if !strings.HasSuffix(currentPath, ".so") {
// Ignore that file, is not a plugin // Ignore that file, is not a plugin
return nil return nil
} }
p, err := plugin.Open(path) logger := log.WithField("plugin", path.Base(currentPath))
p, err := plugin.Open(currentPath)
if err != nil { 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") f, err := p.Lookup("Register")
if err != nil { 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))( f.(func(plugins.RegisterAuthenticatorFunc, plugins.RegisterMFAProviderFunc))(