All checks were successful
Test / Create distribution (push) Successful in 32s
Test / Sandbox (push) Successful in 1m52s
Test / Sandbox (race detector) (push) Successful in 3m14s
Test / Planterette (push) Successful in 3m36s
Test / Hakurei (race detector) (push) Successful in 4m31s
Test / Hakurei (push) Successful in 2m3s
Test / Flake checks (push) Successful in 1m13s
This allows slightly easier use of the vanity url. This also provides some disambiguation between low level containers and hakurei app containers. Signed-off-by: Ophestra <cat@gensokyo.uk>
62 lines
1.4 KiB
Go
62 lines
1.4 KiB
Go
package ldd
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"io"
|
|
"os"
|
|
"os/exec"
|
|
"time"
|
|
|
|
"git.gensokyo.uk/security/hakurei/container"
|
|
"git.gensokyo.uk/security/hakurei/container/seccomp"
|
|
)
|
|
|
|
const lddTimeout = 2 * time.Second
|
|
|
|
var (
|
|
msgStatic = []byte("Not a valid dynamic program")
|
|
msgStaticGlibc = []byte("not a dynamic executable")
|
|
)
|
|
|
|
func Exec(ctx context.Context, p string) ([]*Entry, error) { return ExecFilter(ctx, nil, nil, p) }
|
|
|
|
func ExecFilter(ctx context.Context,
|
|
commandContext func(context.Context) *exec.Cmd,
|
|
f func([]byte) []byte,
|
|
p string) ([]*Entry, error) {
|
|
c, cancel := context.WithTimeout(ctx, lddTimeout)
|
|
defer cancel()
|
|
z := container.New(c, "ldd", p)
|
|
z.CommandContext = commandContext
|
|
z.Hostname = "hakurei-ldd"
|
|
z.SeccompFlags |= seccomp.AllowMultiarch
|
|
z.SeccompPresets |= seccomp.PresetStrict
|
|
stdout, stderr := new(bytes.Buffer), new(bytes.Buffer)
|
|
z.Stdout = stdout
|
|
z.Stderr = stderr
|
|
z.Bind("/", "/", 0).Proc("/proc").Dev("/dev")
|
|
|
|
if err := z.Start(); err != nil {
|
|
return nil, err
|
|
}
|
|
defer func() { _, _ = io.Copy(os.Stderr, stderr) }()
|
|
if err := z.Serve(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := z.Wait(); err != nil {
|
|
m := stderr.Bytes()
|
|
if bytes.Contains(m, append([]byte(p+": "), msgStatic...)) ||
|
|
bytes.Contains(m, msgStaticGlibc) {
|
|
return nil, nil
|
|
}
|
|
return nil, err
|
|
}
|
|
|
|
v := stdout.Bytes()
|
|
if f != nil {
|
|
v = f(v)
|
|
}
|
|
return Parse(v)
|
|
}
|