-
Notifications
You must be signed in to change notification settings - Fork 0
/
system.go
52 lines (43 loc) · 1.1 KB
/
system.go
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package chkok
import (
"os/user"
"strconv"
)
// ExOK exit code for successful run
const ExOK = 0
// ExDataErr exit code for invalid data
const ExDataErr = 65
// ExSoftware generic failure exit code
const ExSoftware = 70
// ExNoInput exit code for when no input provided
const ExNoInput = 72
// ExTempFail exit code when a runtime error
const ExTempFail = 75
// ExConfig exit code when invlaid configurations
const ExConfig = 78
// getUID returns uid of the specified username, if user doesn't exist, but name is numeric, it's assumed the uid
func getUID(name string) (int, error) {
var uid int
var uidstr string
userInfo, err := user.Lookup(name)
if err == nil {
uidstr = userInfo.Uid
} else {
uidstr = name
}
uid, err = strconv.Atoi(uidstr)
return uid, err
}
// getGID returns gid of the specified group, if group doesn't exist, but name is numeric, it's assumed the gid
func getGID(name string) (int, error) {
var gid int
var gidstr string
group, err := user.LookupGroup(name)
if err == nil {
gidstr = group.Gid
} else {
gidstr = name
}
gid, err = strconv.Atoi(gidstr)
return gid, err
}