summaryrefslogtreecommitdiff
path: root/src/Propellor/Property/User.hs
diff options
context:
space:
mode:
authorJoey Hess2014-12-07 15:07:03 -0400
committerJoey Hess2014-12-07 15:07:03 -0400
commitfaf4c21ca18bd551573eb56f4f86c16a23dd9806 (patch)
tree18ccf0ad32176c9cb606a8c13861131247683206 /src/Propellor/Property/User.hs
parent322ae878bbaef94736fdc4cae60b6c3b8c17a54d (diff)
parent9ca332e48169ac19dad050a7f99e0db523d8d9c4 (diff)
Merge branch 'joeyconfig'
Diffstat (limited to 'src/Propellor/Property/User.hs')
-rw-r--r--src/Propellor/Property/User.hs28
1 files changed, 13 insertions, 15 deletions
diff --git a/src/Propellor/Property/User.hs b/src/Propellor/Property/User.hs
index 5c8e768c..69794d84 100644
--- a/src/Propellor/Property/User.hs
+++ b/src/Propellor/Property/User.hs
@@ -25,34 +25,32 @@ nuked user _ = check (isJust <$> catchMaybeIO (homedir user)) $ cmdProperty "use
-- | Only ensures that the user has some password set. It may or may
-- not be the password from the PrivData.
hasSomePassword :: UserName -> Property
-hasSomePassword user = property (user ++ "has password") $ do
- hostname <- asks hostName
- ensureProperty $ hasSomePassword' user (Context hostname)
+hasSomePassword user = hasSomePassword' user hostContext
-- | While hasSomePassword uses the name of the host as context,
-- this allows specifying a different context. This is useful when
-- you want to use the same password on multiple hosts, for example.
-hasSomePassword' :: UserName -> Context -> Property
+hasSomePassword' :: IsContext c => UserName -> c -> Property
hasSomePassword' user context = check ((/= HasPassword) <$> getPasswordStatus user) $
hasPassword' user context
-- | Ensures that a user's password is set to the password from the PrivData.
-- (Will change any existing password.)
hasPassword :: UserName -> Property
-hasPassword user = property (user ++ "has password") $ do
- hostname <- asks hostName
- ensureProperty $ hasPassword' user (Context hostname)
+hasPassword user = hasPassword' user hostContext
-hasPassword' :: UserName -> Context -> Property
+hasPassword' :: IsContext c => UserName -> c -> Property
hasPassword' user context = go `requires` shadowConfig True
where
- go = withPrivData (Password user) context $ \getpassword ->
- property (user ++ " has password") $
- getpassword $ \password -> makeChange $
- withHandle StdinHandle createProcessSuccess
- (proc "chpasswd" []) $ \h -> do
- hPutStrLn h $ user ++ ":" ++ password
- hClose h
+ go = withPrivData (Password user) context $
+ property (user ++ " has password") . setPassword user
+
+setPassword :: UserName -> ((PrivData -> Propellor Result) -> Propellor Result) -> Propellor Result
+setPassword user getpassword = getpassword $ \password -> makeChange $
+ withHandle StdinHandle createProcessSuccess
+ (proc "chpasswd" []) $ \h -> do
+ hPutStrLn h $ user ++ ":" ++ password
+ hClose h
lockedPassword :: UserName -> Property
lockedPassword user = check (not <$> isLockedPassword user) $ cmdProperty "passwd"