Page 1 of 1

LDAP and PureBasic

Posted: Sun Jan 18, 2004 3:53 pm
by mhgschmidt
Hi,

ist there anybody here who made some experiences with LDAP
using PureBasic ?

Posted: Sun Jan 18, 2004 6:29 pm
by Dreglor
what is LDAP exactly?

Posted: Sun Jan 18, 2004 6:40 pm
by mhgschmidt
Quote: "LDAP (Lightweight Directory Access Protocol) is a software protocol for enabling anyone to locate organizations, individuals, and other resources such as files and devices in a network, whether on the public Internet or on a corporate intranet. LDAP is a "lightweight" (smaller amount of code) version of Directory Access Protocol (DAP), which is part of X.500, a standard for directory services in a network. LDAP is lighter because in its initial version it did not include security features. LDAP originated at the University of Michigan and has been endorsed by at least 40 companies. Netscape includes it in its latest Communicator suite of products. Microsoft includes it as part of what it calls Active Directory in a number of products including Outlook Express. Novell's NetWare Directory Services interoperates with LDAP. Cisco also supports it in its networking products."

... found somewhere in the net... search at google with: "whatis LDAP"

Posted: Sun Jan 18, 2004 9:36 pm
by Dreglor
doh! i need to use google more often...
for this ldap i havent used it or heard of it :/

Posted: Mon Jan 19, 2004 12:03 pm
by mhgschmidt
The problem I have is as follows. Is there anybody here who can help ?

please :-)

Remark: I'm new to PureBasic but not new to the Windoze API and Network programming.
But - i'm not able to make the following code run:

> ---snip---
> res.s=Space(1000)
> attr.s=""
> dn.s="cn=Manager, dc=regio,dc=net"
> base.s="dc=regio,dc=net"
> cred.s="secret"
> user.s=dn.s
> password.s=cred.s
> filter.s="(objectClass=*)"
> attr.s=""
> attrsonly.l=0
> method.l=$80 ; LDAP_AUTH_SIMPLE
> LDAP_OPT_VERSION.l=$11
> LDAP_VERSIONV3.s="LDAP_VERSION3"
> LDAP_SCOPE_SUBTREE.l=$02
> LDAP_MSG_ONE.l=$00
> LDAP_MSG_ALL.l=$01
> LDAP_MSG_RECEIVED.l=$02
> msgid.l=0
> timeout.l=0
>
> ;
> ; Initialize Libraries
> ;
>
> OpenLibrary(0,"wldap32.dll")
> OpenConsole()
>
>
> ;
> ; LDAP Connect...
> ;
> ld_handle.l=CallFunction(0,"ldap_init","ha-solutions.regio.net", 389)
> rt=CallFunction(0,"ldap_set_option",ld_handle, LDAP_OPT_VERSION.l,@LDAP_VERSIONV3)
> rt=CallFunction(0,"ldap_connect",ld_handle,timeout.l)
> ;rt=CallFunction(0,"ldap_bind",ld_handle, @dn.s, @cred.s, method.l)
> rt=CallFunction(0,"ldap_simple_bind",ld_handle, @user.s, @password.s)
> rt=CallFunction(0,"ldap_search",ld_handle, @base.s, LDAP_SCOPE_SUBTREE.l, @filter.s, @attr.s, attrsonly.l)
> rt=CallFunction(0,"ldap_count_entries",ld_handle, @res.s)
> ;rt=CallFunction(0,"ldap_result",ld_handle, msgid.l,LDAP_MSG_ONE.l, @timeout.l, @res.s)
> ;rt=CallFunction(0,"ldap_first_entry",ld_handle, @res.s)
> PrintN (Str(rt))
>
> ;
> ; Close All and End.
> ;
> PrintN ( "- End. ---> ENTER to quit." ) : key$=Input()
> rt=CallFunction(0,"ldap_unbind",ld_handle)
> CloseLibrary(0)
> CloseConsole()
>
> ---snip---

Everything works fine until the point i try to use one of the last three API-Calls. I'm sorry, but I cannot see the reason for that. Do you have any idea - or better can you show me how to acces LDAP Directorys with PureBasic (via Windoze AND Linux) ?
The Reason is: I plan to program a new LDAP-Browser that will run on Windoze AND Linux.

Oh - I forgot: In case somebody needs some LDAP Server to test on drop me mail and i will give you access to my testserver (OpenBSD with OpenLDAP)

Regards

Posted: Mon Jan 19, 2004 12:47 pm
by LarsG
just a little hint (kind of off-topic).. you might want to use the [ code ] [ /code ] tags... (without the spaces)..
like this:

Code: Select all

 This is my amazing code!! :) 
:wink:

Posted: Mon Jan 19, 2004 1:38 pm
by Rings
often (or mostly) newer Windows-Api-Dll's use the Ascii-Wide-CharacterSet.
So you have first to convert the normal ascii code to wide characters.
I remember this from my NetApi-DLL Tests. But of course it should been described in the DLL-docu.

Posted: Tue Jan 20, 2004 2:59 pm
by blueznl
a bit off topic, but perhaps helpfull to some... many api's now exist in two flavours, xxxA and xxxW, there's often a xxxA version available, even when not documented

and then, there are api's only documented in their xxx version, while that version doesn't exist, and only the xxxA and xxxW versions do... then there are api's where the xxx is actually xxxW, or xxx is actually xxxA, to stay consistently inconsistent :twisted:

Posted: Tue Jan 20, 2004 3:57 pm
by mhgschmidt
hmmmm.... this sounds like normal behaviour for M$Products. Doesn't it ? :lol:

Posted: Fri Jan 23, 2004 11:22 pm
by mhgschmidt
Hi ! :D

Somebody (Miguel) solved the problem for me. Here is the code:

(Thanks also to "blueznl": Your suggestion to use "A" - functions was
effective - I think. @Miguel: What do you think ?)

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