Greetings everyone!
I'm new to this list but not to RPG. My latest exploit into somewhat uncharted
territory (at least as far as doing things with RPG is concerned) has me using
the LDAP API's. We're currently on V4R5 so I haven't done anything with free
form RPG yet but I'm sure I can follow along if anyone has examples written
that way to answer my question.
I'm attempting to call the LDAP API ldap_get_values and I'm getting the message
'Decoding error' back after the API call. I've spent quite a bit of time
looking at the API documentation (which hasn't been much help in
troubleshooting) and searching the web looking for a solution.
The only things I've found so far related to this problem are related to either
not getting the attribute values using ldap_search_s() (I've checked and I'm
okay there) or passing a non-existent attribute name (I've double checked and
I'm using the names printed as a result of the QShell utility ldapsearch and I
even pulled in a name using ldap_first_attribute() and I've gotten the same
results).
I've also been referring to the excellent article Barbara Morris put together
on converting C prototypes to RPG prototypes (I was referred to it at
http://www.opensource400.org/hintsandtips.html) and some of the information
contained in the Red Book "Who Knew You Could Do That In RPG IV?". Up to this
point, these resources along with my meager knowledge of C has allowed me to
convert the other API's successfully.
I'm pretty sure that I've either prototyped the API wrong or I'm missing an API
call somewhere. I'd rather not send the complete source to the list (it's even
longer than this post is getting to be <G>) but if someone needs it or the
output from the ldapsearch utility to tell me what I'm doing wrong, I'll gladly
send it privately.
Anyway, here's what my program is doing:
- Call ldap_init (I am getting a pointer).
- Call ldap_simple_bind_s (returns a zero and a call to ldap_err2string returns
'Success').
- Call ldap_set_option to limit myself to 25 results (that's working okay).
- Call ldap_search_s (returns a zero and a call to ldap_err2string returns
'Success') and I am setting parameter 'attrsonly' to 0.
- Call ldap_count_entries to see how many search results are returned (I'm
getting 1 which is what I expect).
- Call ldap_first_entry (I'm getting a pointer and a call to ldap_err2string
returns 'Success').
- Call ldap_count_attributes to see how many attributes I have (I'm getting 6
in this case which is what I expect).
- Call ldap_first_attribute (in this case, it's returning 'mail').
- Call ldap_memfree passing in the pointer I got from ldap_first_attribute.
- Call ldap_get_value which is returning a null pointer and setting error
message 'Decoding error'.
- Call ldap_unbind to close the connection.
I have the ldap_get_values API prototyped like this:
Dldap_get_values PR * extproc('ldap_get_values')
D LDAPinfo * value
D LDAPMessage * value
D attr * value options(*STRING)
The C prototype is like this:
char **ldap_get_values(
LDAP *ld,
LDAPMessage *entry,
char *attr)
Here's a snippet of my program that's using this API:
DptrLDAPinfo S *
Dres S *
DLDAPentry S *
Dattrs S 300A
DptrLDAPvalue S *
DLDAPvalue S 300A based(ptrLDAPvalue)
* Get pointer to first entry
C eval LDAPentry=ldap_first_ent(ptrLDAPinfo:
C res)
Get the values of attribute 'mail'
C eval attrs='mail'
C eval ptrLDAPvalue=ldap_get_values(ptrLDAPinfo:
C LDAPentry:
C %addr(attrs))
C eval ErrorMsg=CheckError(ptrLDAPinfo)
Has anyone else done this and gotten it to work? It's clear that it can since
the QShell utilites are working. Any examples will be much appreciated.
Thanks in advance for your help on this,
Matt