Page 1 of 1

ldapsdk.dll from novell with purebasic

Posted: Tue Apr 11, 2006 12:11 pm
by electron

Code: Select all

for (e=ldap_first_entry(ld,result); e !=NULL; e=ldap_next_entry(ld,e))
      {
        //fonction spécifique pour le dn
        printf("DN: %s\n",ldap_get_dn(ld,e));
        //parcours des attributs<->valeurs d'une entrée
        for (attribute = ldap_first_attribute(ld,e,&ber);
   attribute != NULL; attribute = ldap_next_attribute(ld,e,ber))
            {
             //valeur(s) d'attribut, handle connexion, entrée, attribut
             if ((vals = ldap_get_values(ld,e,attribute)) != NULL)
             {
             //parcours eventuel des attributs multivalués,sinon une seule valeur
             for (i=0; vals[i] != NULL; i++)
              {
               printf ("\t%s: %s\n",attribute,vals[i]);
              }
             //libération de la mémoire allouée aux valeurs d'attribut
             ldap_value_free(vals);
             }
             //liberation de la mémoire allouée à l'attribut
             ldap_memfree(attribute);
           }
  
              
        if (ber != NULL)
           {
             ber_free (ber, 0);
           }
I'm unable to obtain the same code functions with pb

Posted: Tue Apr 11, 2006 12:46 pm
by dagcrack
AFAIK this is not a "supported" lib... You must make your own "wrapper" if you'll be using the DLL or call the lib..

LDAPSDK.dll

Posted: Tue Apr 11, 2006 3:31 pm
by electron
ASAIK, this library is support, and many other functions.
The only problem is ldap_get_values with dim type for the result (dynamics arrays).
an exemple (not perfect) with the first entry


lpres.l
base$ = "dc=ldap, dc=fr"
filter$ = "(objectClass=*)"
#LDAP_SUCCESS = 0
#LDAP_OPT_VERSION = $11
#LDAP_VERSIONV3 = 3
#LDAP_SCOPE_SUBTREE = $02
#LDAP_MSG_ONE = $00
#LDAP_PORT = 389
#LDAP_NO_LIMIT=0
#null=0

OpenLibrary(0,"LDAPSDK.DLL")

*ld= CallFunction(0, "ldap_init", "127.0.0.1", #LDAP_PORT)
Debug "ldap_init:"
Debug "$"+Hex(*ld)

rt = CallFunction(0, "ldap_simple_bind",*ld)
Debug "ldap_simple_bind:"
Debug "$"+Hex(rt)

rt = CallFunction(0, "ldap_search_ext_s", *ld, base$, #LDAP_SCOPE_SUBTREE, filter$,#null, 0,#null,#null, 0, #LDAP_NO_LIMIT, @result)
Debug "ldap_search_ext_s:"
Debug "$"+Hex(rt)

rt = CallFunction(0, "ldap_count_entries", *ld, result)
Debug "ldap_count_entries:"
Debug "$"+Hex(rt)


entry=CallFunction(0,"ldap_first_entry",*ld,result)
Debug "ldap_first_entry:"
Debug "$"+Hex(entry)

Debug "dn =" +PeekS(dn=CallFunction(0,"ldap_get_dn",*ld, entry))
Debug "attribut: "+ PeekS(attr = CallFunction(0,"ldap_first_attribute",*ld,entry,@ptr))

;;;;;the attribute dc has only one value;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Debug PeekS(vals= CallFunction(0,"ldap_get_values",*ld,entry,"dc"))
;;;;;;;;;;;;help;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Debug "attribut: "+PeekS(attr=CallFunction(0,"ldap_next_attribute",*ld,entry,ptr))

;;the attribute o has only one value ;;;;;;;;;;;;;;;;;;;;;;
Debug PeekS(vals= CallFunction(0,"ldap_get_values",*ld,entry,"o"))
;;;;;;;;;;;;;;;;help;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


rt = CallFunction(0, "ldap_unbind", *ld)
CloseLibrary(0)








With c, i have no problem with the ldapsdk.dll, when i put it in my project 's workspace.

Posted: Tue Apr 11, 2006 5:21 pm
by dagcrack
When I say "SUPPORTED" I'm talking about a purelibrary.

1) Don't use callfunction, use callfunctionfast instead.

2) if this is C, check out that the functions arent cdecl, if they are, use callcfunctionfast.

3) check the original prototypes, once youve got that, you can make it work in PB or any other language..

callcfunctionfast with ldapsdk.dll

Posted: Tue Apr 11, 2006 10:24 pm
by electron
If OpenLibrary(0, "LDAPSDK.DLL")

ExamineLibraryFunctions(0)
While NextLibraryFunction()<>0
Debug LibraryFunctionName()
result.l = LibraryFunctionAddress()
Debug "adress :" +Hex(result)
Wend
Else

MessageRequester("Problem","Can't open library.",#MB_ICONEXCLAMATION)

EndIf

i obtain all the available functions of the librairie with this code
can you give me an example with callcfunctionfast and ldap, please...:oops:

I use the documentation from novell:
ldaplibc.pdf

The initial code example is based on anonymous access

You can use openldap on windows http://lucas.bergmans.us/hacks/openldap/ for the test