Read reads system shadow passwords database and returns all entires in it.
()
| 34 | |
| 35 | // Read reads system shadow passwords database and returns all entires in it. |
| 36 | func Read() ([]Entry, error) { |
| 37 | f, err := os.Open("/etc/shadow") |
| 38 | if err != nil { |
| 39 | return nil, err |
| 40 | } |
| 41 | scnr := bufio.NewScanner(f) |
| 42 | |
| 43 | var res []Entry |
| 44 | for scnr.Scan() { |
| 45 | ent, err := parseEntry(scnr.Text()) |
| 46 | if err != nil { |
| 47 | return res, err |
| 48 | } |
| 49 | |
| 50 | res = append(res, *ent) |
| 51 | } |
| 52 | if err := scnr.Err(); err != nil { |
| 53 | return res, err |
| 54 | } |
| 55 | return res, nil |
| 56 | } |
| 57 | |
| 58 | func parseEntry(line string) (*Entry, error) { |
| 59 | parts := strings.Split(line, ":") |
no test coverage detected