Skip to content

Commit

Permalink
Prevent setup as root
Browse files Browse the repository at this point in the history
  • Loading branch information
quexten committed Feb 9, 2024
1 parent 52156f8 commit f224276
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions cmd/setup_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,31 @@ package cmd

import (
"fmt"
"log"
"os"
"os/exec"
"os/user"
"strings"

"github.com/quexten/goldwarden/agent/systemauth/biometrics"
"github.com/quexten/goldwarden/browserbiometrics"
"github.com/spf13/cobra"
)

func isRoot() bool {
currentUser, err := user.Current()
if err != nil {
log.Fatalf("[isRoot] Unable to get current user: %s", err)
}
return currentUser.Username == "root"
}

func setupPolkit() {
if isRoot() {
fmt.Println("Do not run this command as root!")
return
}

file, err := os.Create("/tmp/goldwarden-policy")
if err != nil {
panic(err)
Expand Down Expand Up @@ -77,6 +92,11 @@ ExecStart=BINARY_PATH daemonize
WantedBy=graphical-session.target`

func setupSystemd() {
if isRoot() {
fmt.Println("Do not run this command as root!")
return
}

file, err := os.Create("/tmp/goldwarden.service")
if err != nil {
panic(err)
Expand Down Expand Up @@ -125,6 +145,11 @@ var systemdCmd = &cobra.Command{
Short: "Sets up systemd autostart",
Long: "Sets up systemd autostart",
Run: func(cmd *cobra.Command, args []string) {
if isRoot() {
fmt.Println("Do not run this command as root!")
return
}

setupSystemd()
},
}
Expand All @@ -134,6 +159,11 @@ var browserbiometricsCmd = &cobra.Command{
Short: "Sets up browser biometrics",
Long: "Sets up browser biometrics",
Run: func(cmd *cobra.Command, args []string) {
if isRoot() {
fmt.Println("Do not run this command as root!")
return
}

err := browserbiometrics.DetectAndInstallBrowsers()
if err != nil {
fmt.Println("Error: " + err.Error())
Expand Down

0 comments on commit f224276

Please sign in to comment.