| 56 | } |
| 57 | |
| 58 | func parseEntry(line string) (*Entry, error) { |
| 59 | parts := strings.Split(line, ":") |
| 60 | if len(parts) != 9 { |
| 61 | return nil, errors.New("read: malformed entry") |
| 62 | } |
| 63 | |
| 64 | res := &Entry{ |
| 65 | Name: parts[0], |
| 66 | Pass: parts[1], |
| 67 | } |
| 68 | |
| 69 | for i, value := range [...]*int{ |
| 70 | &res.LastChange, &res.MinPassAge, &res.MaxPassAge, |
| 71 | &res.WarnPeriod, &res.InactivityPeriod, &res.AcctExpiry, &res.Flags, |
| 72 | } { |
| 73 | if parts[2+i] == "" { |
| 74 | *value = -1 |
| 75 | } else { |
| 76 | var err error |
| 77 | *value, err = strconv.Atoi(parts[2+i]) |
| 78 | if err != nil { |
| 79 | return nil, fmt.Errorf("read: invalid value for field %d", 2+i) |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | return res, nil |
| 85 | } |
| 86 | |
| 87 | func Lookup(name string) (*Entry, error) { |
| 88 | entries, err := Read() |