LDAP and PureBasic
-
mhgschmidt
- New User

- Posts: 9
- Joined: Sun Jan 18, 2004 3:19 pm
- Location: Germany
LDAP and PureBasic
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 ?
Michael H.G. Schmidt
-
mhgschmidt
- New User

- Posts: 9
- Joined: Sun Jan 18, 2004 3:19 pm
- Location: Germany
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"
... found somewhere in the net... search at google with: "whatis LDAP"
Michael H.G. Schmidt
-
mhgschmidt
- New User

- Posts: 9
- Joined: Sun Jan 18, 2004 3:19 pm
- Location: Germany
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
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
Michael H.G. Schmidt
just a little hint (kind of off-topic).. you might want to use the [ code ] [ /code ] tags... (without the spaces)..
like this:

like this:
Code: Select all
This is my amazing code!! :) AMD Athlon XP2400, 512 MB RAM, Hercules 3D Prophet 9600 256MB RAM, WinXP
PIII 800MHz, 320 MB RAM, Nvidia Riva Tnt 2 Mach 64 (32MB), WinXP + Linux
17" iMac, 1.8 GHz G5, 512 MB DDR-RAM, 80 GB HD, 64 MB Geforce FX 5200, SuperDrive, OSX
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
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
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
-
mhgschmidt
- New User

- Posts: 9
- Joined: Sun Jan 18, 2004 3:19 pm
- Location: Germany
-
mhgschmidt
- New User

- Posts: 9
- Joined: Sun Jan 18, 2004 3:19 pm
- Location: Germany
Hi !
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 ?)
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
Michael H.G. Schmidt

