propellor/Property/User.hs

40 lines
1.0 KiB
Haskell
Raw Normal View History

module Property.User where
import System.Posix
2014-03-30 19:31:57 +00:00
import Common
type UserName = String
2014-03-30 19:53:35 +00:00
sshAccountFor :: UserName -> Property
sshAccountFor user = check (isNothing <$> homedir user) $ cmdProperty "adduser"
[ Param "--disabled-password"
, Param "--gecos", Param ""
, Param user
]
2014-03-30 19:53:35 +00:00
`describe` ("ssh account " ++ 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
]
2014-03-30 19:53:35 +00:00
`describe` ("nuked user " ++ user)
2014-03-30 04:17:44 +00:00
lockedPassword :: UserName -> Property
lockedPassword user = check (not <$> isLockedPassword user) $ cmdProperty "passwd"
2014-03-30 04:17:44 +00:00
[ Param "--lock"
, Param user
]
2014-03-30 19:53:35 +00:00
`describe` ("locked " ++ user ++ " password")
2014-03-30 04:17:44 +00:00
isLockedPassword :: UserName -> IO Bool
isLockedPassword user = parse . words <$> readProcess "passwd" ["-S", user]
where
parse (_:"L":_) = True
parse _ = False
homedir :: UserName -> IO (Maybe FilePath)
homedir user = catchMaybeIO $ homeDirectory <$> getUserEntryForName user