module LDAP.Init(ldapOpen,
ldapInit,
ldapInitialize,
ldapSimpleBind)
where
import Foreign.Ptr
import Foreign.ForeignPtr
import Foreign.C.String
import Foreign.Marshal.Alloc
import Foreign.Storable
import LDAP.Types
import Foreign.C.Types
import LDAP.Utils
import Foreign.Marshal.Utils
ldapSetVersion3 :: LDAPPtr -> IO LDAPInt
ldapSetVersion3 cld =
with ((3)::LDAPInt) $ \copt ->
ldap_set_option cld 17 (castPtr copt)
ldapSetRestart :: LDAPPtr -> IO LDAPInt
ldapSetRestart cld =
with ((134524036)::LDAPInt) $ \copt ->
ldap_set_option cld 9 (castPtr copt)
ldapInit :: String
-> LDAPInt
-> IO LDAP
ldapInit host port =
withCString host $ \cs ->
do rv <- fromLDAPPtr "ldapInit" (cldap_init cs port)
withForeignPtr rv $ \cld -> do
ldapSetVersion3 cld
ldapSetRestart cld
return rv
ldapOpen :: String
-> LDAPInt
-> IO LDAP
ldapOpen host port =
withCString host (\cs ->
do rv <- fromLDAPPtr "ldapOpen" (cldap_open cs port)
withForeignPtr rv ldapSetRestart
return rv)
ldapInitialize :: String
-> IO LDAP
ldapInitialize uri =
withCString uri $ \cs ->
alloca $ \pp -> do
r <- ldap_initialize pp cs
ldap <- fromLDAPPtr "ldapInitialize" (peek pp)
_ <- checkLE "ldapInitialize" ldap (return r)
withForeignPtr ldap $ \p -> do
ldapSetVersion3 p
ldapSetRestart p
return ldap
ldapSimpleBind :: LDAP
-> String
-> String
-> IO ()
ldapSimpleBind ld dn passwd =
withLDAPPtr ld (\ptr ->
withCString dn (\cdn ->
withCString passwd (\cpasswd ->
do checkLE "ldapSimpleBind" ld
(ldap_simple_bind_s ptr cdn cpasswd)
return ()
)))
foreign import ccall unsafe "ldap.h ldap_init"
cldap_init :: CString -> CInt -> IO LDAPPtr
foreign import ccall unsafe "ldap.h ldap_open"
cldap_open :: CString -> CInt -> IO LDAPPtr
foreign import ccall unsafe "ldap.h ldap_initialize"
ldap_initialize :: Ptr LDAPPtr -> CString -> IO LDAPInt
foreign import ccall unsafe "ldap.h ldap_simple_bind_s"
ldap_simple_bind_s :: LDAPPtr -> CString -> CString -> IO LDAPInt
foreign import ccall unsafe "ldap.h ldap_set_option"
ldap_set_option :: LDAPPtr -> LDAPInt -> Ptr () -> IO LDAPInt