2014-03-30 03:10:52 +00:00
|
|
|
module Property.User where
|
|
|
|
|
|
|
|
import System.Posix
|
|
|
|
import Control.Applicative
|
|
|
|
import Data.Maybe
|
|
|
|
|
|
|
|
import Property
|
|
|
|
import Utility.SafeCommand
|
|
|
|
import Utility.Exception
|
2014-03-30 05:57:10 +00:00
|
|
|
import Utility.Process
|
2014-03-30 03:10:52 +00:00
|
|
|
|
|
|
|
type UserName = String
|
|
|
|
|
|
|
|
nonsystem :: UserName -> Property
|
|
|
|
nonsystem user = check (isNothing <$> homedir user) $ cmdProperty "adduser"
|
|
|
|
[ Param "--disabled-password"
|
|
|
|
, Param "--gecos", Param ""
|
|
|
|
, Param user
|
|
|
|
]
|
|
|
|
|
2014-03-30 04:17:44 +00:00
|
|
|
{- Removes user home directory!! Use with caution. -}
|
|
|
|
nuked :: UserName -> Property
|
|
|
|
nuked user = check (isJust <$> homedir user) $ cmdProperty "userdel"
|
|
|
|
[ Param "-r"
|
|
|
|
, Param user
|
|
|
|
]
|
|
|
|
|
|
|
|
lockedPassword :: UserName -> Property
|
2014-03-30 05:57:10 +00:00
|
|
|
lockedPassword user = check (not <$> isLockedPassword user) $ cmdProperty "passwd"
|
2014-03-30 04:17:44 +00:00
|
|
|
[ Param "--lock"
|
|
|
|
, Param user
|
|
|
|
]
|
|
|
|
|
2014-03-30 05:57:10 +00:00
|
|
|
isLockedPassword :: UserName -> IO Bool
|
|
|
|
isLockedPassword user = parse . words <$> readProcess "passwd" ["-S", user]
|
|
|
|
where
|
|
|
|
parse (_:"L":_) = True
|
|
|
|
parse _ = False
|
|
|
|
|
2014-03-30 03:10:52 +00:00
|
|
|
homedir :: UserName -> IO (Maybe FilePath)
|
|
|
|
homedir user = catchMaybeIO $ homeDirectory <$> getUserEntryForName user
|