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

Revert "delete System.PosixCompat.User module" #9

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Version 0.7.2 (2024-02-15)

- Re-Add `System.PosixCompat.User` module again for backwards compat

## Version 0.7.1 (2023-12-06) Santa Clause edition

- Add `System.PosixCompat.Process` module, exporting `getProcessID`
Expand Down
2 changes: 2 additions & 0 deletions src/System/PosixCompat.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module System.PosixCompat (
, module System.PosixCompat.Time
, module System.PosixCompat.Types
, module System.PosixCompat.Unistd
, module System.PosixCompat.User
, usingPortableImpl
) where

Expand All @@ -21,6 +22,7 @@ import System.PosixCompat.Temp
import System.PosixCompat.Time
import System.PosixCompat.Types
import System.PosixCompat.Unistd
import System.PosixCompat.User

-- | 'True' if unix-compat is using its portable implementation,
-- or 'False' if the unix package is simply being re-exported.
Expand Down
133 changes: 133 additions & 0 deletions src/System/PosixCompat/User.hsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
{-# LANGUAGE CPP #-}

{-|
This module makes the operations exported by @System.Posix.User@
available on all platforms. On POSIX systems it re-exports operations from
@System.Posix.User@. On other platforms it provides dummy implementations.
-}
module System.PosixCompat.User (
-- * User environment
-- ** Querying the user environment
getRealUserID
, getRealGroupID
, getEffectiveUserID
, getEffectiveGroupID
, getGroups
, getLoginName
, getEffectiveUserName

-- *** The group database
, GroupEntry(..)
, getGroupEntryForID
, getGroupEntryForName
, getAllGroupEntries

-- *** The user database
, UserEntry(..)
, getUserEntryForID
, getUserEntryForName
, getAllUserEntries

-- ** Modifying the user environment
, setUserID
, setGroupID
) where

#ifndef mingw32_HOST_OS

#include "HsUnixCompat.h"

import System.Posix.User

#if __GLASGOW_HASKELL__<605
getAllGroupEntries :: IO [GroupEntry]
getAllGroupEntries = return []

getAllUserEntries :: IO [UserEntry]
getAllUserEntries = return []
#endif

#else /* Portable implementation */

import System.IO.Error
import System.PosixCompat.Types

unsupported :: String -> IO a
unsupported f = ioError $ mkIOError illegalOperationErrorType x Nothing Nothing
where x = "System.PosixCompat.User." ++ f ++ ": not supported"

-- -----------------------------------------------------------------------------
-- User environment

getRealUserID :: IO UserID
getRealUserID = unsupported "getRealUserID"

getRealGroupID :: IO GroupID
getRealGroupID = unsupported "getRealGroupID"

getEffectiveUserID :: IO UserID
getEffectiveUserID = unsupported "getEffectiveUserID"

getEffectiveGroupID :: IO GroupID
getEffectiveGroupID = unsupported "getEffectiveGroupID"

getGroups :: IO [GroupID]
getGroups = return []

getLoginName :: IO String
getLoginName = unsupported "getLoginName"

setUserID :: UserID -> IO ()
setUserID _ = return ()

setGroupID :: GroupID -> IO ()
setGroupID _ = return ()

-- -----------------------------------------------------------------------------
-- User names

getEffectiveUserName :: IO String
getEffectiveUserName = unsupported "getEffectiveUserName"

-- -----------------------------------------------------------------------------
-- The group database

data GroupEntry = GroupEntry
{ groupName :: String
, groupPassword :: String
, groupID :: GroupID
, groupMembers :: [String]
} deriving (Show, Read, Eq)

getGroupEntryForID :: GroupID -> IO GroupEntry
getGroupEntryForID _ = unsupported "getGroupEntryForID"

getGroupEntryForName :: String -> IO GroupEntry
getGroupEntryForName _ = unsupported "getGroupEntryForName"

getAllGroupEntries :: IO [GroupEntry]
getAllGroupEntries = return []

-- -----------------------------------------------------------------------------
-- The user database (pwd.h)

data UserEntry = UserEntry
{ userName :: String
, userPassword :: String
, userID :: UserID
, userGroupID :: GroupID
, userGecos :: String
, homeDirectory :: String
, userShell :: String
} deriving (Show, Read, Eq)

getUserEntryForID :: UserID -> IO UserEntry
getUserEntryForID _ = unsupported "getUserEntryForID"

getUserEntryForName :: String -> IO UserEntry
getUserEntryForName _ = unsupported "getUserEntryForName"

getAllUserEntries :: IO [UserEntry]
getAllUserEntries = return []

#endif
1 change: 1 addition & 0 deletions unix-compat.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Library
System.PosixCompat.Time
System.PosixCompat.Types
System.PosixCompat.Unistd
System.PosixCompat.User

if os(windows)
c-sources:
Expand Down
Loading