diff options
| author | Joey Hess <joeyh@joeyh.name> | 2014-12-14 15:24:10 -0400 |
|---|---|---|
| committer | Joey Hess <joeyh@joeyh.name> | 2014-12-14 15:24:10 -0400 |
| commit | 71723ca09f369ccf96462cef1e0200e1615677d1 (patch) | |
| tree | 9519e6a0e1f2a2353df4ef836118bbf3bf96eef4 /src/Propellor/PrivData.hs | |
| parent | 2e2438ae66490a2a00972be16e95f0d9cda2f9ea (diff) | |
support for crypted passwords in privdata
* Added CryptPassword to PrivDataField, for password hashes as produced
by crypt(3).
* User.hasPassword and User.hasSomePassword will now use either
a CryptPassword or a Password from privdata, depending on which is set.
Diffstat (limited to 'src/Propellor/PrivData.hs')
| -rw-r--r-- | src/Propellor/PrivData.hs | 39 |
1 files changed, 32 insertions, 7 deletions
diff --git a/src/Propellor/PrivData.hs b/src/Propellor/PrivData.hs index 06438515..b0228b46 100644 --- a/src/Propellor/PrivData.hs +++ b/src/Propellor/PrivData.hs @@ -53,18 +53,43 @@ withPrivData -> c -> (((PrivData -> Propellor Result) -> Propellor Result) -> Property) -> Property -withPrivData field c mkprop = addinfo $ mkprop $ \a -> - maybe missing a =<< get +withPrivData field = withPrivData' snd [field] + +-- Like withPrivData, but here any of a list of PrivDataFields can be used. +withSomePrivData + :: IsContext c + => [PrivDataField] + -> c + -> ((((PrivDataField, PrivData) -> Propellor Result) -> Propellor Result) -> Property) + -> Property +withSomePrivData = withPrivData' id + +withPrivData' + :: IsContext c + => ((PrivDataField, PrivData) -> v) + -> [PrivDataField] + -> c + -> (((v -> Propellor Result) -> Propellor Result) -> Property) + -> Property +withPrivData' feed fieldlist c mkprop = addinfo $ mkprop $ \a -> + maybe missing (a . feed) =<< getM get fieldlist where - get = do + get field = do context <- mkHostContext hc <$> asks hostName - liftIO $ getLocalPrivData field context + maybe Nothing (\privdata -> Just (field, privdata)) + <$> liftIO (getLocalPrivData field context) missing = do Context cname <- mkHostContext hc <$> asks hostName - warningMessage $ "Missing privdata " ++ show field ++ " (for " ++ cname ++ ")" - liftIO $ putStrLn $ "Fix this by running: propellor --set '" ++ show field ++ "' '" ++ cname ++ "'" + warningMessage $ "Missing privdata " ++ intercalate " or " fieldnames ++ " (for " ++ cname ++ ")" + liftIO $ putStrLn $ "Fix this by running:" + liftIO $ forM_ fieldlist $ \f -> do + putStrLn $ " propellor --set '" ++ show f ++ "' '" ++ cname ++ "'" + putStrLn $ " < ( " ++ howtoMkPrivDataField f ++ " )" + putStrLn "" return FailedChange - addinfo p = p { propertyInfo = propertyInfo p <> mempty { _privDataFields = S.singleton (field, hc) } } + addinfo p = p { propertyInfo = propertyInfo p <> mempty { _privDataFields = fieldset } } + fieldnames = map show fieldlist + fieldset = S.fromList $ zip fieldlist (repeat hc) hc = asHostContext c addPrivDataField :: (PrivDataField, HostContext) -> Property |
