Ldap Query
Posted: Tue Aug 30, 2005 11:23 am
Hi,
I have searched this forum with regards ldap and found 1 post.
While the code contained within the post works for counting the number of entries at the required level I am having trouble retrieving values.
I'm not sure I fully understand what i'm doing
I am unsure how to use the CallCFunction when it comes to returning results other than a numeric.
The code fails at Error 6.
Could anyone help me please.
I have searched this forum with regards ldap and found 1 post.
While the code contained within the post works for counting the number of entries at the required level I am having trouble retrieving values.
I'm not sure I fully understand what i'm doing
Code: Select all
lpres.l
dn$ = "cn=Manager, dc=xxxxxx, dc=xxxx"
base$ = "DC=xx, DC=xxxx"
cred$ = "secret"
;user$ = dn$
;password$ = cred$
user$ = "xxxxxxxx"
password$ = "xxxxxx"
filter$ = "(objectClass=*)"
#LDAP_SUCCESS = 0
#LDAP_OPT_VERSION = $11
#LDAP_VERSIONV3 = 3
#LDAP_SCOPE_BASE = $00
#LDAP_SCOPE_ONELEVEL = $01
#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", "10.1.0.40", #LDAP_PORT)
PrintN("ldap_init: $"+Hex(*ld))
If *ld=0:PrintN("Error1: "+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("Error2: "+LDAPError(rt)):Goto Fin:EndIf
rt = CallCFunction(0, "ldap_simple_bindA", *ld, user$, password$)
PrintN("ldap_simple_bind: $"+Hex(rt))
If rt=-1:PrintN("Error3: "+LDAPError(rt)):Goto Fin:EndIf
rt = CallCFunction(0, "ldap_search_sA", *ld, base$, #LDAP_SCOPE_ONELEVEL, filter$, #Null, 0, @lpres)
PrintN("ldap_search_s: $"+ Hex(rt))
If rt<>#LDAP_SUCCESS:PrintN("Error4: "+LDAPError(rt)):Goto Fin:EndIf
PrintN("ldap_search_s Res: "+ Str(lpres))
rt = CallFunction(0,"ldap_first_entryA",*ld, lpres)
PrintN("ldap_first_entry: "+ Str(rt))
If rt<>0:PrintN("Error5 "+LDAPError(rt)):Goto Fin:EndIf
rt = CallFunction(0,"ldap_get_valuesA",*ld, rt, "distinguishedName")
PrintN("ldap_get_values: "+Str(rt))
If rt='':PrintN("Error6"+LDAPError(rt)):Goto Fin:EndIf
rt = CallCFunction(0, "ldap_count_entries", *ld, lpres)
PrintN("ldap_count_entries: "+Str(rt))
If rt=-1:PrintN("Error7"+LDAPError(rt)):Goto Fin:EndIf
;
; Close All and End.
;
Fin:
PrintN( "- End. ---ENTER to quit." )
key$=Input()
If lpres <> '':rt = CallCFunction(0, "ldap_msgfree", lpres):EndIf
rt = CallCFunction(0, "ldap_unbind", *ld)
CloseLibrary(0)
CloseConsole()
The code fails at Error 6.
Could anyone help me please.