summaryrefslogtreecommitdiff
path: root/user.go
blob: 1d47b5fb80369214369055f464a880ad0b0ebdd3 (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 roadrunner

import (
	"os/user"
	"fmt"
)

// resolveUser attempt to find system user by it's name or uid.
func resolveUser(u string) (usr *user.User, err error) {
	usr, err = user.LookupId(u)
	if usr != nil {
		return usr, nil
	}

	return user.Lookup(u)
}

// resolveUser attempt to find system group by it's name or uid.
func resolveGroup(g string) (grp *user.Group, err error) {
	grp, err = user.LookupGroupId(g)
	if grp != nil && grp.Name != "nogroup" {
		return grp, nil
	}

	grp, err = user.LookupGroup(g)
	if grp != nil && grp.Name != "nogroup" {
		return grp, nil
	}

	return nil, fmt.Errorf("no such group %s", g)
}