LDAP Access from this program

M

Matrixinline

Hi

I have a application to search an entry in the LDAP server.
I tried to run this application and it runs perfectly. But the issue
is I am nnot able to Login to the server and searhc for the entry
"CN=anip,DN=localhost,DN=com". It always give me error
ldap_search_ext_s error here.

Can you please let me know what exatly is the kind of error and
possible solution for this.
Here is the code for my application


#include <stdio.h>
#include <stdlib.h>
#include "ldap.h"

//1. Domain Name ..2.3.
//2. Deprartment DP
//3. GROUP - Organization - Module-



/* Adjust these setting for your own LDAP server */
#define HOSTNAME 192.168.1.20
#define PORT_NUMBER LDAP_PORT
#define FIND_DN "CN=anip,DN=localhost,DN=com"
// OpenLDAP Project
int main( int argc, char **argv )
{
LDAP *ld;
LDAPMessage *result, *e;
BerElement *ber;
char *a;
char **vals;
int i, rc;

/* Get a handle to an LDAP connection. */
if ( (ld = ldap_init( HOSTNAME, PORT_NUMBER )) == NULL )
{
perror( "ldap_init" );
return( 1 );
}

/* Bind anonymously to the LDAP server. */
rc = ldap_simple_bind_s( ld, null, null);
if ( rc != LDAP_SUCCESS )
{
fprintf(stderr, "ldap_simple_bind_s: %s\n",
ldap_err2string(rc));
return( 1 );
}

/* Search for the entry. */
if ( ( rc = ldap_search_ext_s( ld, FIND_DN, LDAP_SCOPE_BASE,
"(objectclass=*)", NULL, 0, NULL,
NULL, LDAP_NO_LIMIT,
LDAP_NO_LIMIT, &result ) ) !=
LDAP_SUCCESS )
{
fprintf(stderr, "ldap_search_ext_s: %s\n",
ldap_err2string(rc));
return( 1 );
}

/* Since we are doing a base search, there should be only
one matching entry. */
e = ldap_first_entry( ld, result );
if ( e != NULL )
{
printf( "\nFound %s:\n\n", FIND_DN );

/* Iterate through each attribute in the entry. */
for ( a = ldap_first_attribute( ld, e, &ber );
a != NULL; a = ldap_next_attribute( ld, e, ber ) )
{

/* For each attribute, print the attribute name and
values. */
if ((vals = ldap_get_values( ld, e, a)) != NULL )
{
for ( i = 0; vals != NULL; i++ )
{
printf( "%s: %s\n", a, vals );
}
ldap_value_free( vals );
}
ldap_memfree( a );
}
if ( ber != NULL )
{
ber_free( ber, 0 );
}
}
ldap_msgfree( result );
ldap_unbind( ld );
return( 0 );
}
 
M

Mark McIntyre

Hi

I have a application to search an entry in the LDAP server.
I tried to run this application and it runs perfectly. But the issue
is I am nnot able to Login to the server and searhc for the entry
"CN=anip,DN=localhost,DN=com". It always give me error
ldap_search_ext_s error here.

Your question seems to be about how to use LDAP. This is offtopic
here - I would suggest a better place but I have no idea where.

Also you will need to explain (to the experts in which ever news group
or forum you move to) exactly at what point you get the error, and how
you've checked that nothing went wrong earlier.

--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,130
Latest member
MitchellTe
Top