Querying LDAP Servers

Querying LDAP Servers

Post by Rohith Bha » Tue, 18 Jan 2000 04:00:00


We are developing a savvy application VC++6.0 under windows 9.x/NT.
We are doing some kind of people search , where we can enter the name
of a person, and you will get his email,organisation,country,and some
other attributes. We are querying the servers such as ldap.yahoo.com,
ladp.bigfoot.com, etc. We are successful in getting the common name,
email for these servers. But for netcenter(memberdir.netscape.com)
the function which I use (ldap_get_dn) returns only uid's(some large
numbers). I want to extract name and email from this uid.We are
making use of netscape LDAP calls(such as
ldap_init,ldap_simple_bind,ldap_search,ldap_result,ldap_get_dn etc).

Is there a way where I can get all the attributes from this uid?




1. Enumerating LDAP query results


I'm have successfully implemented a set of Active Directory interfacing
using ADSI before but now i need to make similar easy to use routines for
pure LDAP.

The connection is fine (in anonymous mode but i do get "Inappropriate
even if account and password is correct; any ideas why?) but i can't seem to
find out how to convert the returned attribute values to proper string
This is the essential parts of my latest attempt:

 LDAP  *p_ld;
 LDAPMessage *p_LDM, *p_m;
 char  *p_szAttrib, *p_szValue, szLabel[500], szV[1000], *p_sz;
 BerElement *p_berList=NULL, *p_ber;
 BERVAL  *p_berval;
 ULONG  ulTag, ulLen;
 CHAR  *p_BerCookie;

// ldap_search_st() used to produce p_ld and p_LDM

if ((p_m=ldap_first_entry(p_ld, p_LDM))!=NULL)
   if ((p_szAttrib=ldap_first_attribute(p_ld, p_m, &p_berList))==NULL)
        ulTag=ber_peek_tag(p_berList, &ulLen); // this gives wrong Tag value
    p_berval=ldap_get_values_len(p_ld, p_m, p_szAttrib); p_szValue=NULL;
    ulTag=ber_first_element(p_berList, &ulLen, &p_BerCookie);
    if (ulTag==LBER_DEFAULT) continue;
              case 0x1U: // boolean: 0=FALSE; 0xFF=TRUE
                   if (*p_sz==0) p_szValue="No"; else p_szValue="Yes";
              case 0x2U: // integer
                   sprintf(szV, "Intvalue(%lu)", ulLen); p_szValue=szV;
              case 0x4U: // octet string
                memcpy(&p_szValue, p_sz, sizeof(void *));
    // will use p_szValue here as value for p_szAttrib with indexes
depending on Entry and Element
    } while ((ulTag=ber_next_element(p_berList, &ulLen,
   } while ((p_szAttrib=ldap_next_attribute(p_ld, p_m, p_berList))!=NULL);
  } while ((p_m=ldap_next_entry(p_ld, p_m))!=NULL);

The problem is that i can't be able to figure out the Type of the attribute
found by ldap_first_attribute() as there obviously isn't anything connecting
the it with ber_peek_tag() or at least i'm missing something.

I have also tried using ldap_get_values() but there doesn't seem to be
a way to find out what type of value that attribute has.
I know the query works as i the debugger shows proper values somewhere in
the buffers.

Help! :)

- Sten

- Sten

2. How do undisclosed recipients work?

3. ldap query

4. FA by eBaY: MultiFace III Serial/Parallel Card (read for description/URL)

5. pass array from component to asp, LDAP phone query

6. VXFTP/PPP problem


8. Winlogon Desktop object

9. LDAP call from server side script using visual interdev

10. Active Directory : How can we see a LDAP server?


12. Obtaining attribute info from an AD LDAP Server

13. Query for for process in NT Server ?