plugins: Require an exe extension on windows

This commit is contained in:
Danielle Tomlinson
2019-01-16 15:22:03 +01:00
parent 3287c3f019
commit 8ffd94ca55
3 changed files with 26 additions and 6 deletions

View File

@@ -0,0 +1,10 @@
// +build !windows
package loader
import "os"
// executable Checks to see if the file is executable by anyone.
func executable(path string, f os.FileInfo) bool {
return f.Mode().Perm()&0111 != 0
}

View File

@@ -0,0 +1,15 @@
// +build windows
package loader
import (
"os"
"path/filepath"
)
// On windows, an executable can be any file with any extension. To avoid
// introspecting the file, here we skip executability checks on windows systems
// and simply check for the convention of an `exe` extension.
func executable(path string, s os.FileInfo) bool {
return filepath.Ext(path) == "exe"
}

View File

@@ -5,7 +5,6 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"sort"
multierror "github.com/hashicorp/go-multierror"
@@ -251,11 +250,7 @@ func (l *PluginLoader) scan() ([]os.FileInfo, error) {
continue
}
// Check if it is executable by anyone. On windows, an executable is any file with any
// extension and the file begins with MZ, however, there is no easy way for us to
// actually validate the executability of a file, so here we skip executability checks
// for windows systems.
if runtime.GOOS != "windows" && s.Mode().Perm()&0111 == 0 {
if !executable(f, s) {
l.logger.Debug("skipping un-executable file in plugin folder", "file", f)
continue
}