LDAP and PureBasic

Everything else that doesn't fall into one of the other PB categories.
mhgschmidt
New User
New User
Posts: 9
Joined: Sun Jan 18, 2004 3:19 pm
Location: Germany

LDAP and PureBasic

Post by mhgschmidt »

Hi,

ist there anybody here who made some experiences with LDAP
using PureBasic ?
Michael H.G. Schmidt
Dreglor
Enthusiast
Enthusiast
Posts: 759
Joined: Sat Aug 02, 2003 11:22 pm
Location: OR, USA

Post by Dreglor »

what is LDAP exactly?
~Dreglor
mhgschmidt
New User
New User
Posts: 9
Joined: Sun Jan 18, 2004 3:19 pm
Location: Germany

Post 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"
Michael H.G. Schmidt
Dreglor
Enthusiast
Enthusiast
Posts: 759
Joined: Sat Aug 02, 2003 11:22 pm
Location: OR, USA

Post by Dreglor »

doh! i need to use google more often...
for this ldap i havent used it or heard of it :/
~Dreglor
mhgschmidt
New User
New User
Posts: 9
Joined: Sun Jan 18, 2004 3:19 pm
Location: Germany

Post 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
Michael H.G. Schmidt
LarsG
Enthusiast
Enthusiast
Posts: 713
Joined: Mon Jun 02, 2003 1:06 pm
Location: Norway
Contact:

Post 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:

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
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Post 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.
SPAMINATOR NR.1
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post 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:
( 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... )
mhgschmidt
New User
New User
Posts: 9
Joined: Sun Jan 18, 2004 3:19 pm
Location: Germany

Post by mhgschmidt »

hmmmm.... this sounds like normal behaviour for M$Products. Doesn't it ? :lol:
mhgschmidt
New User
New User
Posts: 9
Joined: Sun Jan 18, 2004 3:19 pm
Location: Germany

Post 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

Michael H.G. Schmidt
Post Reply