Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Id module #54

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/Streamly/Coreutils/Id.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
-- |
-- Module : Streamly.Coreutils.Id
-- Copyright : (c) 2022 Composewell Technologies
-- License : BSD-3-Clause
-- Maintainer : [email protected]
-- Stability : experimental
-- Portability : GHC
--
-- Get real and effective user and group IDs.

module Streamly.Coreutils.Id
(
getRealUserID
, getRealGroupID
, getEffectiveUserID
, getEffectiveGroupID
, getGroups
, getLoginName
, getEffectiveUserName
rnjtranjan marked this conversation as resolved.
Show resolved Hide resolved
)
where

import Data.Word (Word32)
import System.Posix.Types (CGid(CGid), CUid(CUid))

import qualified System.Posix.User as Posix

getRealUserID :: IO Word32
getRealUserID = do
CUid x <- Posix.getRealUserID
return x

getRealGroupID :: IO Word32
getRealGroupID = do
CGid x <- Posix.getRealGroupID
return x

getEffectiveUserID :: IO Word32
getEffectiveUserID = do
CUid x <- Posix.getEffectiveUserID
return x

getEffectiveGroupID :: IO Word32
getEffectiveGroupID = do
CGid x <- Posix.getEffectiveGroupID
return x

getGroups :: IO [Word32]
getGroups =
map (\(CGid x) -> x) <$> Posix.getGroups

getLoginName :: IO String
getLoginName = Posix.getLoginName

getEffectiveUserName :: IO String
getEffectiveUserName = Posix.getEffectiveUserName
1 change: 1 addition & 0 deletions streamly-coreutils.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ library
, Streamly.Coreutils.Common
, Streamly.Coreutils.Cp
, Streamly.Coreutils.FileTest
, Streamly.Coreutils.Id
, Streamly.Coreutils.ShellWords
, Streamly.Coreutils.Uniq
, Streamly.Coreutils.Which
Expand Down