joshuar-go-hass-agent/main.go

33 lines
759 B
Go

// Copyright (c) 2023 Joshua Rich <joshua.rich@gmail.com>
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
package main
import (
"log"
"syscall"
"github.com/joshuar/go-hass-agent/cmd"
)
func main() {
ensureNotEUID()
cmd.Execute()
}
// Following is copied from https://git.kernel.org/pub/scm/libs/libcap/libcap.git/tree/goapps/web/web.go
//
// ensureNotEUID aborts the program if it is running setuid something,
// or being invoked by root.
func ensureNotEUID() {
euid := syscall.Geteuid()
uid := syscall.Getuid()
egid := syscall.Getegid()
gid := syscall.Getgid()
if uid != euid || gid != egid || uid == 0 {
log.Fatalf("go-hass-agent should not be run with additional privileges or as root.")
}
}