mirror of
https://github.com/Luzifer/nginx-sso.git
synced 2024-12-20 04:41: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:
parent
7f6de7097a
commit
cfa158ea18
1 changed files with 10 additions and 5 deletions
15
plugins.go
15
plugins.go
|
@ -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))(
|
||||||
|
|
Loading…
Reference in a new issue