Support Heimdal Kerberos.

This commit is contained in:
Aaron Hodgen 2012-02-22 15:42:53 -05:00
parent 3a7d5d3a05
commit 5c2f7bd4a6
3 changed files with 44 additions and 2 deletions

View File

@ -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 */"

View File

@ -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)

View File

@ -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