aboutsummaryrefslogtreecommitdiffhomepage
path: root/cmd
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-10-01 13:44:08 +0900
committerOphestra <cat@gensokyo.uk>2026-10-01 13:44:08 +0900
commit0d90eb44ac23052e79d42d7520520ebc0f2d2247 (patch)
tree29fb8870d94dfe9740d7899c682ca55a01b89b7a /cmd
parent815f40c944281ca9a9a68aa612336b13098958c1 (diff)
cmd/mbf: poison open via environment
This enables use of non-cache cmd/mbf utils as root. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/mbf/cache.go8
-rw-r--r--cmd/mbf/main.go2
2 files changed, 9 insertions, 1 deletions
diff --git a/cmd/mbf/cache.go b/cmd/mbf/cache.go
index 0e20ca99..166e1c45 100644
--- a/cmd/mbf/cache.go
+++ b/cmd/mbf/cache.go
@@ -2,6 +2,7 @@ package main
import (
"context"
+ "errors"
"net/http"
"os"
"path/filepath"
@@ -14,6 +15,9 @@ import (
"hakurei.app/pkg"
)
+// poisonOpen is whether cache.open is poisoned. This enables running as root.
+var _, poisonOpen = os.LookupEnv("MBF_POISON_OPEN")
+
// cache refers to an instance of [pkg.Cache] that might be open.
type cache struct {
ctx context.Context
@@ -49,6 +53,10 @@ func writeTitle(msg message.Msg, s string) {
// open opens the underlying [pkg.Cache].
func (cache *cache) open() (err error) {
+ if poisonOpen {
+ return errors.New("attempting to open cache")
+ }
+
if cache.c != nil {
return os.ErrInvalid
}
diff --git a/cmd/mbf/main.go b/cmd/mbf/main.go
index 014a7f47..5dd4e8a0 100644
--- a/cmd/mbf/main.go
+++ b/cmd/mbf/main.go
@@ -71,7 +71,7 @@ func main() {
log.SetPrefix("mbf: ")
msg := message.New(log.Default())
- if os.Geteuid() == 0 {
+ if !poisonOpen && os.Geteuid() == 0 {
log.Fatal("this program must not run as root")
}