summaryrefslogtreecommitdiff
path: root/internal/user/name.go
blob: 28ab0a4e654f69b0d4d2b7c2e712189881dae9e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package user

import (
	"os/user"
)

// NoRootCheck verifies that the DTail run user is not with UID or GID 0.
func NoRootCheck() {
	user, err := user.Current()
	if err != nil {
		panic(err)
	}

	if user.Uid == "0" {
		panic("Not allowed to run as UID 0")
	}

	if user.Gid == "0" {
		panic("Not allowed to run as GID 0")
	}
}

// Name of the current run user.
func Name() string {
	user, err := user.Current()
	if err != nil {
		panic(err)
	}

	return user.Username
}