diff options
| author | Joey Hess <joey@kitenet.net> | 2014-03-30 01:57:10 -0400 |
|---|---|---|
| committer | Joey Hess <joey@kitenet.net> | 2014-03-30 01:57:10 -0400 |
| commit | c8bd3436973f2c6f742ab9d4189e686f58bfa412 (patch) | |
| tree | 2850ccd1f7fa6c7de94a0528bc145e1c5f4a57ad /Property/User.hs | |
| parent | a0a416780d0ed1b9a7fc34cd871708b84b9647dd (diff) | |
check if password is locked for idempotency sake
Diffstat (limited to 'Property/User.hs')
| -rw-r--r-- | Property/User.hs | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/Property/User.hs b/Property/User.hs index 47d6fb5b..3cd74964 100644 --- a/Property/User.hs +++ b/Property/User.hs @@ -7,6 +7,7 @@ import Data.Maybe import Property import Utility.SafeCommand import Utility.Exception +import Utility.Process type UserName = String @@ -25,10 +26,16 @@ nuked user = check (isJust <$> homedir user) $ cmdProperty "userdel" ] lockedPassword :: UserName -> Property -lockedPassword user = cmdProperty "passwd" +lockedPassword user = check (not <$> isLockedPassword user) $ cmdProperty "passwd" [ Param "--lock" , 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 user = catchMaybeIO $ homeDirectory <$> getUserEntryForName user |
