-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexecute.go
63 lines (60 loc) · 1.35 KB
/
execute.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package hq
import (
"os"
"os/exec"
)
// runExec ...
func (id *HQ) runExec() bool {
s := matchShebang(id.IO.TokenExec)
if s.interp == "disabled" {
errExit("executable interpreter [" + s.name + "] for [" + s.ext + "] is explicitly disabled by security policy")
}
var (
err error
f *os.File
)
switch {
case id.IO.PlainTextScript:
f, err = os.Open(id.IO.FileName)
if err != nil {
errExit("unable to open file [" + id.IO.FileName + "] [" + err.Error() + "]")
}
f.Close()
default:
script := string(decompressZstd(id.IO.SCRIPT))
f, err = os.CreateTemp("/var/tmp", "scratchpad")
if err != nil {
errExit("unable to create shell temp scratch file")
}
if _, err := f.Write([]byte(script)); err != nil {
errExit("unable to write to shell temp scratch file")
}
defer os.Remove(f.Name())
}
f.Close()
p := getArgs()
cmd := exec.Command(s.interp, f.Name(), p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8], p[9])
cmd.Env = os.Environ()
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
if err := cmd.Start(); err != nil {
return false
}
if err = cmd.Wait(); err != nil {
return false
}
return true
}
// runExecPlain ...
func (c *Config) runExecPlain() bool {
id := &HQ{
ID{},
IO{
TokenExec: "POSIX=",
PlainTextScript: true,
FileName: c.FileName,
},
}
return id.runExec()
}