Options for doing this seem to be limited and of the "roll your own" variety, but I'm having a go. Problem is, I don't know C well enough to follow the function definitions perfectly or know what to pass when it asks for things like a pointer to a "NULL-terminated array of strings". And this is my first time trying to get to grips with prototypes, so apologies for any stupid questions here.
I'm trying to get a useable wrapper for the Novell LDAPSDK dll, because this seems to be a reasonably comprehensive and reasonably well documented library, and has both 32 and 64bit windows binaries (I'll need both 32 and 64bit exes for the resulting project). Documentation starts here http://www.novell.com/documentation/developer/cldap
All I really need is the ability to bind, search, get string, integer and binary properties, and unbind when done. It's just read access I'm after, and all my queries will return either one result, or no results.
I have prototypes that seem to work for ldap_init and ldap_simple_bind_s, and for ldap_err2string:
Code: Select all
PrototypeC.i p_LDAP_init(host$, port.w=389)
PrototypeC.i p_LDAP_simple_bind_s(ld.i, dn$, pw$)
PrototypeC.i p_LDAP_unbind(ld.i)
PrototypeC.i p_LDAP_err2string(err.w)
Global.i ldap_lib
Global LDAP_init.p_LDAP_init
Global LDAP_simple_bind_s.p_LDAP_simple_bind_s
Global LDAP_unbind.p_LDAP_unbind
Global LDAP_err2string.p_LDAP_err2string
#LDAP_SUCCESS = 0
Procedure LDAPLoadLib()
ldap_lib=OpenLibrary(#PB_Any, "ldapsdk.dll")
If ldap_lib
Debug "Opened LDAPSDK"
LDAP_init.p_LDAP_init=GetFunction(ldap_lib, "ldap_init")
LDAP_simple_bind_s.p_LDAP_simple_bind_s=GetFunction(ldap_lib, "ldap_simple_bind_s")
LDAP_unbind.p_LDAP_unbind=GetFunction(ldap_lib, "ldap_unbind")
LDAP_err2string.p_LDAP_err2string=GetFunction(ldap_lib, "ldap_err2string")
Else
Debug "Unable to load LDAP library"
EndIf
EndProcedure
Procedure.s LDAPError(err.w)
Protected out$
Protected *string
out$="Unknown error"
*string=LDAP_err2string(err)
If *string
out$=PeekS(*string)
EndIf
ProcedureReturn out$
EndProcedure
Code: Select all
Define.i ldap_handle
Define.w result
LDAPLoadLib()
ldap_handle=LDAP_init("mydomain.com")
If ldap_handle
result.w=LDAP_simple_bind_s(ldap_handle, "username@mydomain", "password")
Debug "result: "+Str(result)
Else
Debug "LDAP init failed"
EndIf
Where I then run into a brick wall is with prototyping the ldap_seach_ext_s function. Documentation for this function is here: http://www.novell.com/documentation/dev ... wuhb3.html
The function is defined as:
Code: Select all
int ldap_search_ext_s (
LDAP *ld,
const char *base,
int scope,
const char *filter,
char **attrs,
int attrsonly,
LDAPControl **serverctrls,
LDAPControl **clientctrls,
struct timeval *timeout,
int sizelimit,
LDAPMessage **res);
Code: Select all
PrototypeC.i p_LDAP_init(host$, port.w=389)
PrototypeC.i p_LDAP_simple_bind_s(ld.i, dn$, pw$)
PrototypeC.i p_LDAP_unbind(ld.i)
PrototypeC.i p_LDAP_err2string(err.w)
PrototypeC.i p_LDAP_search_ext_s(ld.i, base$, scope.w, filter$, *attrs, attrsonly.w, *serverctrls, *clientctrls, *timeout, sizelimit.w, results.i)
Global.i ldap_lib
Global LDAP_init.p_LDAP_init
Global LDAP_simple_bind_s.p_LDAP_simple_bind_s
Global LDAP_unbind.p_LDAP_unbind
Global LDAP_err2string.p_LDAP_err2string
Global LDAP_search_ext_s.p_LDAP_search_ext_s
Structure ldapcontrol
*oid ; points to string
*berval ; points to berval structure
iscritical$
EndStructure
Structure ldap_berval
len.l
val$
EndStructure
Structure ldap_timeval
secs.l
usecs.l
EndStructure
#LDAP_SUCCESS = 0
#LDAP_SCOPE_BASE = 0
#LDAP_SCOPE_ONELEVEL = 1
#LDAP_SCOPE_SUBTREE = 2
Procedure LDAPLoadLib()
ldap_lib=OpenLibrary(#PB_Any, "ldapsdk.dll")
If ldap_lib
Debug "Opened LDAPSDK"
LDAP_init.p_LDAP_init=GetFunction(ldap_lib, "ldap_init")
LDAP_simple_bind_s.p_LDAP_simple_bind_s=GetFunction(ldap_lib, "ldap_simple_bind_s")
LDAP_unbind.p_LDAP_unbind=GetFunction(ldap_lib, "ldap_unbind")
LDAP_err2string.p_LDAP_err2string=GetFunction(ldap_lib, "ldap_err2string")
LDAP_search_ext_s.p_LDAP_search_ext_s=GetFunction(ldap_lib, "ldap_search_ext_s")
Else
Debug "Unable to load LDAP library"
EndIf
EndProcedure
Procedure.s LDAPError(err.w)
Protected out$
Protected *string
out$="Unknown error"
*string=LDAP_err2string(err)
If *string
out$=PeekS(*string)
EndIf
ProcedureReturn out$
EndProcedure
Code: Select all
Define.i ldap_handle
Define.w result
Define.s base$, filter$
Define *ldapresults
Define timeout.ldap_timeval
Define Dim attrs$(10)
LDAPLoadLib()
ldap_handle=LDAP_init("mydomain.com")
If ldap_handle
result.w=LDAP_simple_bind_s(ldap_handle, "username@mydomain", "password")
Debug "result: "+Str(result)
base$="OU=this,DC=that,DC=theother"
filter$="(&(objectclass=User)(samAccountName=someuser))"
attrs$(0)="cn"
attrs$(1)="department"
attrs$(2)=#NULL$
timeout\secs=10
timeout\usecs=0
result=LDAP_search_ext_s(ldap_handle, base$, #LDAP_SCOPE_SUBTREE, filter$, @attrs$(), 0, 0, 0, @timeout, 0, *ldapresults)
Debug "result: "+Str(result)
Else
Debug "LDAP init failed"
EndIf
Any suggestions on what a prototype for this function should look like?