X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=group.go;h=214f91438d78740a331c487cbfe5ecab1355718c;hb=c6b898ea9ab372c58c59658c2acf17ea831d71db;hp=4513758df41c4a8d22eb32f8fac5653e773ca3dd;hpb=1d028880cfb17a7c8a9e3b1f54cf1e980baca63d;p=nsscash%2Fnsscash.git diff --git a/group.go b/group.go index 4513758..214f914 100644 --- a/group.go +++ b/group.go @@ -45,7 +45,7 @@ type GroupKey struct { Name string Passwd string Gid uint64 - Members string + Members string // "," separated } func toKey(g Group) GroupKey { @@ -58,13 +58,19 @@ func toKey(g Group) GroupKey { } // ParseGroups parses a file in the format of /etc/group and returns all -// entries as Group structs. +// entries as slice of Group structs. func ParseGroups(r io.Reader) ([]Group, error) { var res []Group - s := bufio.NewScanner(r) - for s.Scan() { - t := s.Text() + s := bufio.NewReader(r) + for { + t, err := s.ReadString('\n') + if err != nil { + if err == io.EOF { + break + } + return nil, err + } x := strings.Split(t, ":") if len(x) != 4 { @@ -76,6 +82,9 @@ func ParseGroups(r io.Reader) ([]Group, error) { return nil, errors.Wrapf(err, "invalid gid in line %q", t) } + // ReadString() contains the delimiter + x[3] = strings.TrimSuffix(x[3], "\n") + var members []string // No members must result in empty slice, not slice with the // empty string @@ -89,10 +98,6 @@ func ParseGroups(r io.Reader) ([]Group, error) { Members: members, }) } - err := s.Err() - if err != nil { - return nil, err - } return res, nil }