Simplify the Host datatype.
This commit is contained in:
parent
ce4e99b7d6
commit
f2d0a73aa8
@ -55,7 +55,7 @@ main = do
|
|||||||
|
|
||||||
login :: Conf -> IO (Either LdapError ())
|
login :: Conf -> IO (Either LdapError ())
|
||||||
login conf =
|
login conf =
|
||||||
Ldap.with (Ldap.Secure (host conf)) (port conf) $ \l -> do
|
Ldap.with (Ldap.Tls (host conf) Ldap.defaultTlsSettings) (port conf) $ \l -> do
|
||||||
Ldap.bind l (dn conf) (password conf)
|
Ldap.bind l (dn conf) (password conf)
|
||||||
fix $ \loop -> do
|
fix $ \loop -> do
|
||||||
uid <- prompt "Username: "
|
uid <- prompt "Username: "
|
||||||
|
|||||||
@ -10,6 +10,8 @@
|
|||||||
module Ldap.Client
|
module Ldap.Client
|
||||||
( with
|
( with
|
||||||
, Host(..)
|
, Host(..)
|
||||||
|
, defaultTlsSettings
|
||||||
|
, insecureTlsSettings
|
||||||
, PortNumber
|
, PortNumber
|
||||||
, Ldap
|
, Ldap
|
||||||
, LdapError(..)
|
, LdapError(..)
|
||||||
@ -162,26 +164,28 @@ with host port f = do
|
|||||||
{ Conn.connectionHostname =
|
{ Conn.connectionHostname =
|
||||||
case host of
|
case host of
|
||||||
Plain h -> h
|
Plain h -> h
|
||||||
Secure h -> h
|
Tls h _ -> h
|
||||||
SecureWithTLSSettings h _ -> h
|
|
||||||
Insecure h -> h
|
|
||||||
, Conn.connectionPort = port
|
, Conn.connectionPort = port
|
||||||
, Conn.connectionUseSecure =
|
, Conn.connectionUseSecure =
|
||||||
case host of
|
case host of
|
||||||
Plain _ -> Nothing
|
Plain _ -> Nothing
|
||||||
Secure _ -> Just Conn.TLSSettingsSimple
|
Tls _ settings -> pure settings
|
||||||
|
, Conn.connectionUseSocks = Nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
defaultTlsSettings :: Conn.TLSSettings
|
||||||
|
defaultTlsSettings = Conn.TLSSettingsSimple
|
||||||
{ Conn.settingDisableCertificateValidation = False
|
{ Conn.settingDisableCertificateValidation = False
|
||||||
, Conn.settingDisableSession = False
|
, Conn.settingDisableSession = False
|
||||||
, Conn.settingUseServerName = False
|
, Conn.settingUseServerName = False
|
||||||
}
|
}
|
||||||
SecureWithTLSSettings _ settings -> Just settings
|
|
||||||
Insecure _ -> Just Conn.TLSSettingsSimple
|
insecureTlsSettings :: Conn.TLSSettings
|
||||||
|
insecureTlsSettings = Conn.TLSSettingsSimple
|
||||||
{ Conn.settingDisableCertificateValidation = True
|
{ Conn.settingDisableCertificateValidation = True
|
||||||
, Conn.settingDisableSession = False
|
, Conn.settingDisableSession = False
|
||||||
, Conn.settingUseServerName = False
|
, Conn.settingUseServerName = False
|
||||||
}
|
}
|
||||||
, Conn.connectionUseSocks = Nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
input :: FromAsn1 a => TQueue a -> Connection -> IO b
|
input :: FromAsn1 a => TQueue a -> Connection -> IO b
|
||||||
input inq conn = wrap . flip fix [] $ \loop chunks -> do
|
input inq conn = wrap . flip fix [] $ \loop chunks -> do
|
||||||
|
|||||||
@ -44,10 +44,7 @@ import qualified Ldap.Asn1.Type as Type
|
|||||||
-- | LDAP host.
|
-- | LDAP host.
|
||||||
data Host =
|
data Host =
|
||||||
Plain String -- ^ Plain LDAP.
|
Plain String -- ^ Plain LDAP.
|
||||||
| Insecure String -- ^ LDAP over TLS without the certificate validity check.
|
| Tls String TLSSettings -- ^ LDAP over TLS.
|
||||||
| Secure String -- ^ LDAP over TLS.
|
|
||||||
| SecureWithTLSSettings String TLSSettings
|
|
||||||
-- ^ LDAP over TLS with the ability to specify detailed TLS settings.
|
|
||||||
deriving (Show)
|
deriving (Show)
|
||||||
|
|
||||||
-- | A token. All functions that interact with the Directory require one.
|
-- | A token. All functions that interact with the Directory require one.
|
||||||
|
|||||||
@ -53,7 +53,7 @@ locally f =
|
|||||||
(\_ -> Ldap.with localhost port f)
|
(\_ -> Ldap.with localhost port f)
|
||||||
|
|
||||||
localhost :: Host
|
localhost :: Host
|
||||||
localhost = Insecure "localhost"
|
localhost = Tls "localhost" insecureTlsSettings
|
||||||
|
|
||||||
port :: Num a => a
|
port :: Num a => a
|
||||||
port = 24620
|
port = 24620
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user