aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/sys
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-02-18 23:05:37 +0900
committerOphestra <cat@gensokyo.uk>2025-02-18 23:07:28 +0900
commit648e1d641a8b0ae7c5bc4899f84b884d4335c97f (patch)
treefdb45d1fedb60487c22a1fceb9d87ba883f03779 /internal/sys
parent3c327084d387b316795f45420e8d0c6f9ce71ffe (diff)
app: separate interface from implementation
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/sys')
-rw-r--r--internal/sys/interface.go15
-rw-r--r--internal/sys/std.go5
2 files changed, 6 insertions, 14 deletions
diff --git a/internal/sys/interface.go b/internal/sys/interface.go
index da1cf077..0d2ebaf3 100644
--- a/internal/sys/interface.go
+++ b/internal/sys/interface.go
@@ -6,6 +6,7 @@ import (
"path"
"strconv"
+ "git.gensokyo.uk/security/fortify/fst"
"git.gensokyo.uk/security/fortify/internal/fmsg"
)
@@ -38,24 +39,14 @@ type State interface {
Printf(format string, v ...any)
// Paths returns a populated [Paths] struct.
- Paths() Paths
+ Paths() fst.Paths
// Uid invokes fsu and returns target uid.
// Any errors returned by Uid is already wrapped [fmsg.BaseError].
Uid(aid int) (int, error)
}
-// Paths contains environment dependent paths used by fortify.
-type Paths struct {
- // path to shared directory e.g. /tmp/fortify.%d
- SharePath string `json:"share_path"`
- // XDG_RUNTIME_DIR value e.g. /run/user/%d
- RuntimePath string `json:"runtime_path"`
- // application runtime directory e.g. /run/user/%d/fortify
- RunDirPath string `json:"run_dir_path"`
-}
-
// CopyPaths is a generic implementation of [System.Paths].
-func CopyPaths(os State, v *Paths) {
+func CopyPaths(os State, v *fst.Paths) {
v.SharePath = path.Join(os.TempDir(), "fortify."+strconv.Itoa(os.Geteuid()))
fmsg.Verbosef("process share directory at %q", v.SharePath)
diff --git a/internal/sys/std.go b/internal/sys/std.go
index 88579f6d..bab2b923 100644
--- a/internal/sys/std.go
+++ b/internal/sys/std.go
@@ -13,13 +13,14 @@ import (
"sync"
"syscall"
+ "git.gensokyo.uk/security/fortify/fst"
"git.gensokyo.uk/security/fortify/internal"
"git.gensokyo.uk/security/fortify/internal/fmsg"
)
// Std implements System using the standard library.
type Std struct {
- paths Paths
+ paths fst.Paths
pathsOnce sync.Once
uidOnce sync.Once
@@ -46,7 +47,7 @@ func (s *Std) Printf(format string, v ...any) { fmsg.Verbosef(form
const xdgRuntimeDir = "XDG_RUNTIME_DIR"
-func (s *Std) Paths() Paths {
+func (s *Std) Paths() fst.Paths {
s.pathsOnce.Do(func() { CopyPaths(s, &s.paths) })
return s.paths
}