Skip to content

Commit 23eb47f

Browse files
Thomas LE ROUXtianon
authored andcommitted
Export user and group lookup errors as variables.
Export errors as variables when no matching entries are found in passwd or group file. Signed-off-by: Thomas LE ROUX <[email protected]>
1 parent 652fbaa commit 23eb47f

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

user/lookup.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ package user
22

33
import (
44
"errors"
5-
"fmt"
65
"syscall"
76
)
87

98
var (
109
// The current operating system does not provide the required data for user lookups.
1110
ErrUnsupported = errors.New("user lookup: operating system does not provide passwd-formatted data")
11+
// No matching entries found in file.
12+
ErrNoPasswdEntries = errors.New("no matching entries in passwd file")
13+
ErrNoGroupEntries = errors.New("no matching entries in group file")
1214
)
1315

1416
func lookupUser(filter func(u User) bool) (User, error) {
@@ -27,7 +29,7 @@ func lookupUser(filter func(u User) bool) (User, error) {
2729

2830
// No user entries found.
2931
if len(users) == 0 {
30-
return User{}, fmt.Errorf("no matching entries in passwd file")
32+
return User{}, ErrNoPasswdEntries
3133
}
3234

3335
// Assume the first entry is the "correct" one.
@@ -75,7 +77,7 @@ func lookupGroup(filter func(g Group) bool) (Group, error) {
7577

7678
// No user entries found.
7779
if len(groups) == 0 {
78-
return Group{}, fmt.Errorf("no matching entries in group file")
80+
return Group{}, ErrNoGroupEntries
7981
}
8082

8183
// Assume the first entry is the "correct" one.

0 commit comments

Comments
 (0)