aboutsummaryrefslogtreecommitdiffhomepage
path: root/cmd/fsu/main.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-02-14 16:43:55 +0900
committerOphestra <cat@gensokyo.uk>2025-02-14 16:43:55 +0900
commit1fd571d5619459bd29077b84418d913a8c5462a0 (patch)
tree70e0ffe8e31b25416356565df97c9cd5ceb544fc /cmd/fsu/main.go
parentbe30e2f11ebc94fb8a78abe61a5d5531c38805b7 (diff)
cmd/fsu: check parse behaviour
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'cmd/fsu/main.go')
-rw-r--r--cmd/fsu/main.go13
1 files changed, 12 insertions, 1 deletions
diff --git a/cmd/fsu/main.go b/cmd/fsu/main.go
index 1f90a390..fd3ba1e2 100644
--- a/cmd/fsu/main.go
+++ b/cmd/fsu/main.go
@@ -61,8 +61,19 @@ func main() {
// aid
uid := 1000000
+ // refuse to run if fsurc is not protected correctly
+ if s, err := os.Stat(fsuConfFile); err != nil {
+ log.Fatal(err)
+ } else if s.Mode().Perm() != 0400 {
+ log.Fatal("bad fsurc perm")
+ } else if st := s.Sys().(*syscall.Stat_t); st.Uid != 0 || st.Gid != 0 {
+ log.Fatal("fsurc must be owned by uid 0")
+ }
+
// authenticate before accepting user input
- if fid, ok := parseConfig(fsuConfFile, puid); !ok {
+ if f, err := os.Open(fsuConfFile); err != nil {
+ log.Fatal(err)
+ } else if fid, ok := mustParseConfig(f, puid); !ok {
log.Fatalf("uid %d is not in the fsurc file", puid)
} else {
uid += fid * 10000