module LDAP.Init(ldapOpen,
ldapInit,
ldapSimpleBind)
where
import Foreign.Ptr
import Foreign.C.String
import LDAP.Types
import Foreign.C.Types
import LDAP.Utils
import Foreign.Marshal.Utils
ldapInit :: String
-> LDAPInt
-> IO LDAP
ldapInit host port =
withCString host (\cs ->
with ((3)::LDAPInt) (\copt ->
do cld <- cldap_init cs port
rv <- fromLDAPPtr "ldapInit" (return cld)
ldap_set_option cld 17 (castPtr copt)
return rv
))
ldapOpen :: String
-> LDAPInt
-> IO LDAP
ldapOpen host port =
withCString host (\cs ->
fromLDAPPtr "ldapOpen" $ cldap_open cs port)
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_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