Skip to content

Commit db03a2b

Browse files
authored
Merge pull request #634 from twpayne/ignore-lookupgroupid-errors
Only set group value if user.LookupGroupId succeeds
2 parents d0ab459 + d22a3cf commit db03a2b

File tree

3 files changed

+11
-21
lines changed

3 files changed

+11
-21
lines changed

cmd/cgo.go

Lines changed: 0 additions & 5 deletions
This file was deleted.

cmd/config.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -317,20 +317,20 @@ func (c *Config) getDefaultData() (map[string]interface{}, error) {
317317
}
318318
data["username"] = currentUser.Username
319319

320-
// user.LookupGroupId looks up a group by gid. If CGO is enabled, then this
321-
// uses an underlying C library call (e.g. getgrgid_r on Linux) and is
322-
// trustworthy. If CGO is disabled then the fallback implementation only
323-
// searches /etc/group, which is typically empty if an external directory
324-
// service is being used, and so the lookup fails. So, if
325-
// user.LookupGroupId returns an error, only return an error if CGO is
326-
// enabled.
320+
// user.LookupGroupId is generally unreliable:
321+
//
322+
// If CGO is enabled, then this uses an underlying C library call (e.g.
323+
// getgrgid_r on Linux) and is trustworthy, except on recent versions of Go
324+
// on Android, where LookupGroupId is not implemented.
325+
//
326+
// If CGO is disabled then the fallback implementation only searches
327+
// /etc/group, which is typically empty if an external directory service is
328+
// being used, and so the lookup fails.
329+
//
330+
// So, only set group if user.LookupGroupId does not return an error.
327331
group, err := user.LookupGroupId(currentUser.Gid)
328332
if err == nil {
329333
data["group"] = group.Name
330-
} else if cgoEnabled && runtime.GOOS != "windows" {
331-
// Only return an error if CGO is enabled and the platform is
332-
// non-Windows (groups don't really mean much on Windows).
333-
return nil, err
334334
}
335335

336336
homedir, err := os.UserHomeDir()

cmd/nocgo.go

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)