LDAP and PureBasic
Posted: Sun Jan 18, 2004 3:53 pm
Hi,
ist there anybody here who made some experiences with LDAP
using PureBasic ?
ist there anybody here who made some experiences with LDAP
using PureBasic ?
http://www.purebasic.com
https://www.purebasic.fr/english/
Code: Select all
This is my amazing code!! :) Code: Select all
lpres.l
dn$ = "cn=Manager, dc=xxxxxx, dc=xxxx"
base$ = "dc=xxxxx, dc=xxxx"
cred$ = "secret"
user$ = dn$
password$ = cred$
filter$ = "(objectClass=*)"
#LDAP_SUCCESS = 0
#LDAP_OPT_VERSION = $11
#LDAP_VERSIONV3 = 3
#LDAP_SCOPE_SUBTREE = $02
#LDAP_MSG_ONE = $00
#LDAP_PORT = 389
msgid = 0
timeout.timeval
timeout\tv_sec = 0
timeout\tv_usec = 0
Structure LDAP
ld_deref.l
ld_timelimit.l
ld_sizelimit.l
ld_errno.l
ld_matched.s
ld_error.s
EndStructure
Procedure.s LDAPError(rt)
If rt=-1
errcode = CallCFunction(0, "LdapGetLastError")
Else
errcode = rt
EndIf
ProcedureReturn PeekS(CallCFunction(0, "ldap_err2string", errcode))
EndProcedure
;
; Initialize Libraries
;
OpenLibrary(0, "wldap32.dll")
OpenConsole()
;
; LDAP Connect...
;
*ld.LDAP= CallCFunction(0, "ldap_init", "xxxxxxxx.xxxxx.xxxx", #LDAP_PORT)
PrintN("ldap_init: $"+Hex(*ld))
If *ld=0:PrintN("Error: "+LDAPError(*ld)):Goto Fin:EndIf
;rt = CallCFunction(0, "ldap_set_option", *ld, #LDAP_OPT_VERSION, #LDAP_VERSIONV3)
;PrintN("ldap_set_option: $"+Hex(rt))
;If rt<>#LDAP_SUCCESS:PrintN("Error: "+LDAPError(rt)):Goto Fin:EndIf
rt = CallCFunction(0, "ldap_connect", *ld, 0);@timeout)
PrintN("ldap_connect: $"+Hex(rt))
If rt<>#LDAP_SUCCESS:PrintN("Error: "+LDAPError(rt)):Goto Fin:EndIf
rt = CallCFunction(0, "ldap_simple_bindA", *ld, user$, password$)
PrintN("ldap_simple_bind: $"+Hex(rt))
If rt=-1:PrintN("Error: "+LDAPError(rt)):Goto Fin:EndIf
rt = CallCFunction(0, "ldap_search_sA", *ld, base$, #LDAP_SCOPE_SUBTREE, filter$, #NULL, 0, @lpres)
PrintN("ldap_search_s: $"+Hex(rt))
If rt<>#LDAP_SUCCESS:PrintN("Error: "+LDAPError(rt)):Goto Fin:EndIf
rt = CallCFunction(0, "ldap_count_entries", *ld, lpres)
PrintN("ldap_count_entries: $"+Hex(rt))
If rt=-1:PrintN("Error: "+LDAPError(rt)):Goto Fin:EndIf
;
; Close All and End.
;
Fin:
PrintN( "- End. ---ENTER to quit." )
key$=Input()
rt = CallCFunction(0, "ldap_unbind", *ld)
CloseLibrary(0)
CloseConsole()
; ExecutableFormat=Windows
; CursorPosition=56
; FirstLine=29
; DisableDebugger
; EOF