Skip to content
Closed
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 : streamly@composewell.com
-- Stability : experimental
-- Portability : GHC
--
-- Get real and effective user and group IDs.

module Streamly.Coreutils.Id
(
getRealUserID
, getRealGroupID
, getEffectiveUserID
, getEffectiveGroupID
, getGroups
, getLoginName
, getEffectiveUserName
Comment thread
rnjtranjan marked this conversation as resolved.
Outdated
)
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