Add device agent library
Provide enrollment, elevated install, posture checks, keystore, and system-tray helpers shared by the probo-agent binary. Signed-off-by: Ludovic Vielle <ludovic@probo.com>
This commit is contained in:
@@ -83,6 +83,11 @@ func CommandExists(cmd string) bool {
|
||||
return exists
|
||||
}
|
||||
|
||||
// CommandCandidates returns absolute paths for known commands on the current platform.
|
||||
func CommandCandidates(cmd string) []string {
|
||||
return commandCandidates(cmd)
|
||||
}
|
||||
|
||||
func resolveCommandPath(cmd string) (string, bool) {
|
||||
if filepath.IsAbs(cmd) {
|
||||
return cmd, isExecutableFile(cmd)
|
||||
|
||||
@@ -23,6 +23,7 @@ package checks
|
||||
var darwinCommandPaths = map[string][]string{
|
||||
"defaults": {"/usr/bin/defaults"},
|
||||
"fdesetup": {"/usr/bin/fdesetup"},
|
||||
"osascript": {"/usr/bin/osascript"},
|
||||
"pwpolicy": {"/usr/bin/pwpolicy"},
|
||||
"softwareupdate": {"/usr/sbin/softwareupdate"},
|
||||
"stat": {"/usr/bin/stat"},
|
||||
|
||||
@@ -21,35 +21,41 @@
|
||||
package checks
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var windowsCommandPaths = map[string][]string{
|
||||
"manage-bde": {`%s\System32\manage-bde.exe`},
|
||||
"net": {`%s\System32\net.exe`},
|
||||
"netsh": {`%s\System32\netsh.exe`},
|
||||
"powershell": {`%s\System32\WindowsPowerShell\v1.0\powershell.exe`},
|
||||
"sc": {`%s\System32\sc.exe`},
|
||||
"w32tm": {`%s\System32\w32tm.exe`},
|
||||
}
|
||||
|
||||
func commandCandidates(cmd string) []string {
|
||||
templates := windowsCommandPaths[normalizeWindowsCommand(cmd)]
|
||||
if len(templates) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
systemRoot := os.Getenv("SystemRoot")
|
||||
if systemRoot == "" {
|
||||
systemRoot = `C:\Windows`
|
||||
}
|
||||
|
||||
system32 := filepath.Join(systemRoot, "System32")
|
||||
|
||||
switch strings.ToLower(cmd) {
|
||||
case "powershell", "powershell.exe":
|
||||
return []string{
|
||||
filepath.Join(system32, "WindowsPowerShell", "v1.0", "powershell.exe"),
|
||||
}
|
||||
case "manage-bde", "manage-bde.exe":
|
||||
return []string{filepath.Join(system32, "manage-bde.exe")}
|
||||
case "netsh", "netsh.exe":
|
||||
return []string{filepath.Join(system32, "netsh.exe")}
|
||||
case "w32tm", "w32tm.exe":
|
||||
return []string{filepath.Join(system32, "w32tm.exe")}
|
||||
case "sc", "sc.exe":
|
||||
return []string{filepath.Join(system32, "sc.exe")}
|
||||
case "net", "net.exe":
|
||||
return []string{filepath.Join(system32, "net.exe")}
|
||||
default:
|
||||
return nil
|
||||
paths := make([]string, len(templates))
|
||||
for i, template := range templates {
|
||||
paths[i] = fmt.Sprintf(template, systemRoot)
|
||||
}
|
||||
|
||||
return paths
|
||||
}
|
||||
|
||||
func normalizeWindowsCommand(name string) string {
|
||||
name = strings.ToLower(strings.TrimSpace(name))
|
||||
|
||||
return strings.TrimSuffix(name, ".exe")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user