{-# 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 = do
name <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr >>= 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
return (GroupEntry name passwd gid members)
unpackUserEntry :: Ptr CPasswd -> IO UserEntry
unpackUserEntry ptr = do
name <- ((\hsc_ptr -> peekByteOff hsc_ptr 0)) ptr >>= 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" #-}
gecos <- ((\hsc_ptr -> peekByteOff hsc_ptr 24)) ptr >>= 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 {
userName :: ByteString,
userPassword :: ByteString,
userID :: UserID,
userGroupID :: GroupID,
userGecos :: ByteString,
homeDirectory :: ByteString,
userShell :: ByteString
} deriving (Show, Read, Eq)
data GroupEntry =
GroupEntry {
groupName :: ByteString,
groupPassword :: ByteString,
groupID :: GroupID,
groupMembers :: [ByteString]
} deriving (Show, Read, Eq)