{-# LINE 1 "System/Posix/User/Common.hsc" #-}
{-# LANGUAGE Safe #-}
module System.Posix.User.Common where
import Data.ByteString ( ByteString )
import System.Posix.Types
{-# LINE 25 "System/Posix/User/Common.hsc" #-}
import Foreign.Ptr
import Foreign.Marshal
import Foreign.Storable
import Data.ByteString ( packCString )
data {-# CTYPE "struct passwd" #-} CPasswd
data {-# CTYPE "struct group" #-} CGroup
data LKUPTYPE = GETONE | GETALL
unpackGroupEntry :: Ptr CGroup -> IO GroupEntry
unpackGroupEntry :: Ptr CGroup -> IO GroupEntry
unpackGroupEntry Ptr CGroup
ptr = do
ByteString
name <- ((\Ptr CGroup
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr CGroup
hsc_ptr Int
0)) Ptr CGroup
ptr forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= CString -> IO ByteString
packCString
{-# LINE 39 "System/Posix/User/Common.hsc" #-}
passwd <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) ptr >>= packCString
{-# LINE 40 "System/Posix/User/Common.hsc" #-}
gid <- ((\hsc_ptr -> peekByteOff hsc_ptr 16)) ptr
{-# LINE 41 "System/Posix/User/Common.hsc" #-}
mem <- ((\hsc_ptr -> peekByteOff hsc_ptr 24)) ptr
{-# LINE 42 "System/Posix/User/Common.hsc" #-}
members <- peekArray0 nullPtr mem >>= mapM packCString
forall (m :: * -> *) a. Monad m => a -> m a
return (ByteString -> ByteString -> GroupID -> [ByteString] -> GroupEntry
GroupEntry ByteString
name ByteString
passwd GroupID
gid [ByteString]
members)
unpackUserEntry :: Ptr CPasswd -> IO UserEntry
unpackUserEntry :: Ptr CPasswd -> IO UserEntry
unpackUserEntry Ptr CPasswd
ptr = do
ByteString
name <- ((\Ptr CPasswd
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr CPasswd
hsc_ptr Int
0)) Ptr CPasswd
ptr forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= CString -> IO ByteString
packCString
{-# LINE 48 "System/Posix/User/Common.hsc" #-}
passwd <- ((\hsc_ptr -> peekByteOff hsc_ptr 8)) ptr >>= packCString
{-# LINE 49 "System/Posix/User/Common.hsc" #-}
uid <- ((\hsc_ptr -> peekByteOff hsc_ptr 16)) ptr
{-# LINE 50 "System/Posix/User/Common.hsc" #-}
gid <- ((\hsc_ptr -> peekByteOff hsc_ptr 20)) ptr
{-# LINE 51 "System/Posix/User/Common.hsc" #-}
{-# LINE 54 "System/Posix/User/Common.hsc" #-}
ByteString
gecos <- ((\Ptr CPasswd
hsc_ptr -> forall a b. Storable a => Ptr b -> Int -> IO a
peekByteOff Ptr CPasswd
hsc_ptr Int
24)) Ptr CPasswd
ptr forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= CString -> IO ByteString
packCString
{-# LINE 55 "System/Posix/User/Common.hsc" #-}
{-# LINE 56 "System/Posix/User/Common.hsc" #-}
dir <- ((\hsc_ptr -> peekByteOff hsc_ptr 32)) ptr >>= packCString
{-# LINE 57 "System/Posix/User/Common.hsc" #-}
shell <- ((\hsc_ptr -> peekByteOff hsc_ptr 40)) ptr >>= packCString
{-# LINE 58 "System/Posix/User/Common.hsc" #-}
return (UserEntry name passwd uid gid gecos dir shell)
{-# LINE 61 "System/Posix/User/Common.hsc" #-}
data UserEntry =
UserEntry {
UserEntry -> ByteString
userName :: ByteString,
UserEntry -> ByteString
userPassword :: ByteString,
UserEntry -> UserID
userID :: UserID,
UserEntry -> GroupID
userGroupID :: GroupID,
UserEntry -> ByteString
userGecos :: ByteString,
UserEntry -> ByteString
homeDirectory :: ByteString,
UserEntry -> ByteString
userShell :: ByteString
} deriving (Int -> UserEntry -> ShowS
[UserEntry] -> ShowS
UserEntry -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UserEntry] -> ShowS
$cshowList :: [UserEntry] -> ShowS
show :: UserEntry -> String
$cshow :: UserEntry -> String
showsPrec :: Int -> UserEntry -> ShowS
$cshowsPrec :: Int -> UserEntry -> ShowS
Show, ReadPrec [UserEntry]
ReadPrec UserEntry
Int -> ReadS UserEntry
ReadS [UserEntry]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UserEntry]
$creadListPrec :: ReadPrec [UserEntry]
readPrec :: ReadPrec UserEntry
$creadPrec :: ReadPrec UserEntry
readList :: ReadS [UserEntry]
$creadList :: ReadS [UserEntry]
readsPrec :: Int -> ReadS UserEntry
$creadsPrec :: Int -> ReadS UserEntry
Read, UserEntry -> UserEntry -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UserEntry -> UserEntry -> Bool
$c/= :: UserEntry -> UserEntry -> Bool
== :: UserEntry -> UserEntry -> Bool
$c== :: UserEntry -> UserEntry -> Bool
Eq)
data GroupEntry =
GroupEntry {
GroupEntry -> ByteString
groupName :: ByteString,
GroupEntry -> ByteString
groupPassword :: ByteString,
GroupEntry -> GroupID
groupID :: GroupID,
GroupEntry -> [ByteString]
groupMembers :: [ByteString]
} deriving (Int -> GroupEntry -> ShowS
[GroupEntry] -> ShowS
GroupEntry -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GroupEntry] -> ShowS
$cshowList :: [GroupEntry] -> ShowS
show :: GroupEntry -> String
$cshow :: GroupEntry -> String
showsPrec :: Int -> GroupEntry -> ShowS
$cshowsPrec :: Int -> GroupEntry -> ShowS
Show, ReadPrec [GroupEntry]
ReadPrec GroupEntry
Int -> ReadS GroupEntry
ReadS [GroupEntry]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GroupEntry]
$creadListPrec :: ReadPrec [GroupEntry]
readPrec :: ReadPrec GroupEntry
$creadPrec :: ReadPrec GroupEntry
readList :: ReadS [GroupEntry]
$creadList :: ReadS [GroupEntry]
readsPrec :: Int -> ReadS GroupEntry
$creadsPrec :: Int -> ReadS GroupEntry
Read, GroupEntry -> GroupEntry -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GroupEntry -> GroupEntry -> Bool
$c/= :: GroupEntry -> GroupEntry -> Bool
== :: GroupEntry -> GroupEntry -> Bool
$c== :: GroupEntry -> GroupEntry -> Bool
Eq)