From bf1f1e3ec434272fe452f9b3016050b17b456eb2 Mon Sep 17 00:00:00 2001 From: joe Date: Mon, 25 Apr 2016 16:23:52 -0400 Subject: Fixed cokiki build --- cokiki.hs | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'cokiki.hs') diff --git a/cokiki.hs b/cokiki.hs index 3da337a..2cb6491 100644 --- a/cokiki.hs +++ b/cokiki.hs @@ -1,10 +1,15 @@ +{-# LANGUAGE OverloadedStrings #-} +import Control.Applicative +import Data.Bool +import Data.Char +import Data.Maybe +import qualified Data.ByteString.Lazy.Char8 as L +import qualified Data.ByteString.Lazy.Char8 as L8 +import qualified Kiki +import System.Directory import System.Environment import System.IO import System.Posix.User -import qualified Kiki -import Data.Char -import qualified Data.ByteString.Lazy.Char8 as L8 -import qualified Data.ByteString.Lazy.Char8 as L usage = unlines [ "cokiki " @@ -27,13 +32,13 @@ main = do ["strongswan"] -> whenRoot strongswan _ -> hPutStr stderr usage -maybeReadFile :: FilePath -> Maybe L.ByteString +maybeReadFile :: FilePath -> IO (Maybe L.ByteString) maybeReadFile path = do doesFileExist path >>= bool (return Nothing) (Just <$> L.readFile path) sshClient 0 root = do -- /etc/ssh/ssh_config <-- 'GlobalKnownHostsFile /var/cache/kiki/ssh_known_hosts' - sshconfig <- fromMaybe [] parseSshConfig <$> maybeReadFile (root "/etc/ssh/ssh_config") + sshconfig <- parseSshConfig . fromMaybe "" <$> maybeReadFile (root "/etc/ssh/ssh_config") let (ps,qs) = sshSplitAtDirective "GlobalKnownHostsFile" sshconfig sshconfig' <- case qs of @@ -45,7 +50,7 @@ sshClient 0 root = do -- /var/cache/kiki/ssh_known_hosts <-- contains known hosts from /root/.gnupg/... -sshClient uid = return () +sshClient uid root = return () sshServer = do -- /etc/ssh/sshd_config <-- 'HostKey /var/cache/kiki/ssh_host_ecdsa_key' etc. @@ -67,7 +72,9 @@ parseSshConfig bs = map tokenize $ L8.lines bs where (l', comment) = L8.break (=='#') l tokrel x y = isSpace x == isSpace y -sshSplitAtDirective d sshconfig = splitAt (sshIsDirective d) sshconfig +unparseSshConfig ls = L8.unlines $ map L.concat $ ls + +sshSplitAtDirective d sshconfig = break (sshIsDirective d) sshconfig sshIsDirective d ls = case dropWhile isSpaceTok ls of @@ -76,3 +83,7 @@ sshIsDirective d ls = where isSpaceTok "" = True isSpaceTok b = isSpace $ L8.head b + +bool :: a -> a -> Bool -> a +bool f _ False = f +bool _ t True = t -- cgit v1.2.3