From 01b214b29fdaa1cacf151ee62c07d4de1a7ec582 Mon Sep 17 00:00:00 2001 From: equa Date: Fri, 21 Jul 2023 17:34:46 -0400 Subject: [PATCH] make sure user is root --- cmd/rename/main.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/cmd/rename/main.go b/cmd/rename/main.go index 0c7ae19..a0c0950 100644 --- a/cmd/rename/main.go +++ b/cmd/rename/main.go @@ -7,6 +7,7 @@ import ( "path" "os" "os/exec" + "os/user" "git.tilde.town/tildetown/town/towndb" ) @@ -88,10 +89,20 @@ func main() { quit("usage: rename username new_username") } - confirmRename() old_name := os.Args[1] new_name := os.Args[2] + user, err := user.Current() + if err != nil { + quit(fmt.Sprintf("couldn't get user info: %v", err)) + } + + if user.Uid != "0" { + quit("must be run as root") + } + + confirmRename() + if err := killUser(old_name); err != nil { quit(fmt.Sprintf("pkill failed: %v", err)) }