0 | module System.Linux.User.Passwd
 1 |
 2 | import Data.C.Integer
 3 | import Derive.Prelude
 4 |
 5 | import System.Posix.File
 6 |
 7 | %default total
 8 | %language ElabReflection
 9 |
10 | ||| An entry in the `/etc/passwd` file.
11 | public export
12 | record PasswdEntry where
13 |   constructor PE
14 |   loginName : String
15 |   password  : String
16 |   uid       : UidT
17 |   gid       : GidT
18 |   comment   : String
19 |   homedir   : String
20 |   shell     : String
21 |
22 | %runElab derive "PasswdEntry" [Show,Eq]
23 |
24 | export
25 | readEntry : ByteString -> Maybe PasswdEntry
26 | readEntry bs =
27 |   case split 58 bs of
28 |     [n,p,u,g,c,h,s] =>
29 |       Just $ PE
30 |         { loginName = toString n
31 |         , password  = toString p
32 |         , uid       = maybe 0 cast $ parseInteger u
33 |         , gid       = maybe 0 cast $ parseInteger g
34 |         , comment   = toString c
35 |         , homedir   = toString h
36 |         , shell     = toString s
37 |         }
38 |     _               => Nothing
39 |