diff options
author | 2010-05-17 18:19:45 +0000 | |
---|---|---|
committer | 2010-05-17 18:19:45 +0000 | |
commit | efddbac1b0e9fd4e016f459d695d37ce5a955555 (patch) | |
tree | c06536887b8089d24656cb085d7382bf32f396b4 /System | |
parent | 3f1779c88f611062e20c1d69662c2af0c4080d81 (diff) |
Add bindings for setting effective user-id and group-id
Having the ability to set the effective user-id and group-id
enables the application to switch between the real user-id
and set-user-id multiple times.
Diffstat (limited to 'System')
-rw-r--r-- | System/Posix/User.hsc | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/System/Posix/User.hsc b/System/Posix/User.hsc index e1c0f95..6c631d5 100644 --- a/System/Posix/User.hsc +++ b/System/Posix/User.hsc @@ -39,6 +39,9 @@ module System.Posix.User ( -- ** Modifying the user environment setUserID, setGroupID, + setEffectiveUserID, + setEffectiveGroupID, + setGroups ) where @@ -109,6 +112,16 @@ foreign import ccall unsafe "getgroups" c_getgroups :: CInt -> Ptr CGid -> IO CInt +-- | @setGroups@ calls @setgroups@ to set the list of +-- supplementary @GroupID@s associated with the current process. +setGroups :: [GroupID] -> IO () +setGroups groups = do + withArrayLen groups $ \ ngroups arr -> + throwErrnoIfMinus1_ "setGroups" (c_setgroups (fromIntegral ngroups) arr) + +foreign import ccall unsafe "setgroups" + c_setgroups :: CInt -> Ptr CGid -> IO CInt + -- | @getLoginName@ calls @getlogin@ to obtain the login name @@ -130,6 +143,15 @@ setUserID uid = throwErrnoIfMinus1_ "setUserID" (c_setuid uid) foreign import ccall unsafe "setuid" c_setuid :: CUid -> IO CInt +-- | @setEffectiveUserID uid@ calls @seteuid@ to set the effective +-- user-id associated with the current process to @uid@. This +-- does not update the real user-id or set-user-id. +setEffectiveUserID :: UserID -> IO () +setEffectiveUserID uid = throwErrnoIfMinus1_ "setEffectiveUserID" (c_seteuid uid) + +foreign import ccall unsafe "seteuid" + c_seteuid :: CUid -> IO CInt + -- | @setGroupID gid@ calls @setgid@ to set the real, effective, and -- saved set-group-id associated with the current process to @gid@. setGroupID :: GroupID -> IO () @@ -138,6 +160,17 @@ setGroupID gid = throwErrnoIfMinus1_ "setGroupID" (c_setgid gid) foreign import ccall unsafe "setgid" c_setgid :: CGid -> IO CInt +-- | @setEffectiveGroupID uid@ calls @setegid@ to set the effective +-- group-id associated with the current process to @gid@. This +-- does not update the real group-id or set-group-id. +setEffectiveGroupID :: GroupID -> IO () +setEffectiveGroupID gid = + throwErrnoIfMinus1_ "setEffectiveGroupID" (c_setegid gid) + + +foreign import ccall unsafe "setegid" + c_setegid :: CGid -> IO CInt + -- ----------------------------------------------------------------------------- -- User names |