mirror of
https://github.com/kemko/nomad.git
synced 2026-01-04 17:35:43 +03:00
plugins: Require an exe extension on windows
This commit is contained in:
10
plugins/shared/loader/filter_unix.go
Normal file
10
plugins/shared/loader/filter_unix.go
Normal 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
|
||||
}
|
||||
15
plugins/shared/loader/filter_windows.go
Normal file
15
plugins/shared/loader/filter_windows.go
Normal 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"
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user