From 5c2f7bd4a665f2c5bd7c39a315fbb730ccb7fc14 Mon Sep 17 00:00:00 2001 From: Aaron Hodgen Date: Wed, 22 Feb 2012 15:42:53 -0500 Subject: [PATCH] Support Heimdal Kerberos. --- authenticate-kerberos/Setup.lhs | 38 ++++++++++++++++++- .../Web/Authenticate/Kerberos.hs | 6 +++ .../authenticate-kerberos.cabal | 2 +- 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/authenticate-kerberos/Setup.lhs b/authenticate-kerberos/Setup.lhs index 06e2708f..55b68a11 100755 --- a/authenticate-kerberos/Setup.lhs +++ b/authenticate-kerberos/Setup.lhs @@ -2,6 +2,42 @@ > module Main where > import Distribution.Simple +> import System.Process (readProcessWithExitCode) +> import System.Exit (ExitCode(..)) +> import System.Directory (removeFile) +> import System.IO.Error (try) > main :: IO () -> main = defaultMain +> main = defaultMainWithHooks simpleUserHooks' +> where +> simpleUserHooks' = simpleUserHooks +> { postConf = postConf' +> , postClean = postClean' +> } +> +> postConf' x configFlags desc y = do +> hconf <- checkHeimKinit +> writeFile "config.h" $ concat +> [ "#ifndef CONFIG_H\n" +> , "#define CONFIG_H\n" +> , "\n" +> , "/* Define to 1 if you have Heimdal Kerberos. */\n" +> , hconf +> , "\n\n" +> , "#endif\n" +> ] +> let configFlags' = updateConfigFlags configFlags +> postConf simpleUserHooks x configFlags' desc y +> where +> updateConfigFlags configFlags = configFlags +> +> postClean' _ _ _ _ = do +> try . removeFile $ "config.h" +> return () +> +> checkHeimKinit :: IO String +> checkHeimKinit = do +> (e,_,_) <- readProcessWithExitCode "kinit" ["--version"] "" +> if e == ExitSuccess then +> return "#define HAVE_HEIMDAL 1" +> else return "/* #undef HAVE_HEIMDAL */" diff --git a/authenticate-kerberos/Web/Authenticate/Kerberos.hs b/authenticate-kerberos/Web/Authenticate/Kerberos.hs index c2c4aa58..7f56673e 100644 --- a/authenticate-kerberos/Web/Authenticate/Kerberos.hs +++ b/authenticate-kerberos/Web/Authenticate/Kerberos.hs @@ -1,4 +1,6 @@ {-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE CPP #-} +#include "../../config.h" -- | Module for using a kerberos authentication service. -- -- Please note that all configuration should have been done @@ -65,7 +67,11 @@ loginKerberos username password = do fetch :: IO KerberosAuthResult fetch = do (exitCode, _out, err) <- readProcessWithExitCode +#ifdef HAVE_HEIMDAL + "kinit" ["--password-file=STDIN", T.unpack username] (T.unpack password) +#else "kinit" [T.unpack username] (T.unpack password) +#endif case exitCode of ExitSuccess -> return Ok ExitFailure x -> return $ interpretError x (T.pack err) diff --git a/authenticate-kerberos/authenticate-kerberos.cabal b/authenticate-kerberos/authenticate-kerberos.cabal index aa645089..8159fb7e 100644 --- a/authenticate-kerberos/authenticate-kerberos.cabal +++ b/authenticate-kerberos/authenticate-kerberos.cabal @@ -9,7 +9,7 @@ description: Kerberos authenticate. category: Web stability: Stable cabal-version: >= 1.6 -build-type: Simple +build-type: Custom homepage: http://github.com/yesodweb/authenticate library