]> ruderich.org/simon Gitweb - nsscash/nsscash.git/blobdiff - group.go
nsscash: support longer lines in passwd/group files
[nsscash/nsscash.git] / group.go
index 0ad86711431d068ff0922ceace8c39cdba01a1a0..214f91438d78740a331c487cbfe5ecab1355718c 100644 (file)
--- a/group.go
+++ b/group.go
@@ -62,9 +62,15 @@ func toKey(g Group) GroupKey {
 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
 }