check if password is locked for idempotency sake
This commit is contained in:
parent
a0a416780d
commit
c8bd343697
|
@ -7,6 +7,7 @@ import Data.Maybe
|
||||||
import Property
|
import Property
|
||||||
import Utility.SafeCommand
|
import Utility.SafeCommand
|
||||||
import Utility.Exception
|
import Utility.Exception
|
||||||
|
import Utility.Process
|
||||||
|
|
||||||
type UserName = String
|
type UserName = String
|
||||||
|
|
||||||
|
@ -25,10 +26,16 @@ nuked user = check (isJust <$> homedir user) $ cmdProperty "userdel"
|
||||||
]
|
]
|
||||||
|
|
||||||
lockedPassword :: UserName -> Property
|
lockedPassword :: UserName -> Property
|
||||||
lockedPassword user = cmdProperty "passwd"
|
lockedPassword user = check (not <$> isLockedPassword user) $ cmdProperty "passwd"
|
||||||
[ Param "--lock"
|
[ Param "--lock"
|
||||||
, Param user
|
, Param user
|
||||||
]
|
]
|
||||||
|
|
||||||
|
isLockedPassword :: UserName -> IO Bool
|
||||||
|
isLockedPassword user = parse . words <$> readProcess "passwd" ["-S", user]
|
||||||
|
where
|
||||||
|
parse (_:"L":_) = True
|
||||||
|
parse _ = False
|
||||||
|
|
||||||
homedir :: UserName -> IO (Maybe FilePath)
|
homedir :: UserName -> IO (Maybe FilePath)
|
||||||
homedir user = catchMaybeIO $ homeDirectory <$> getUserEntryForName user
|
homedir user = catchMaybeIO $ homeDirectory <$> getUserEntryForName user
|
||||||
|
|
Loading…
Reference in New Issue