[Date Prev][Date Next]
[Chronological]
[Thread]
[Top]
ldap_simple_bind_s gives error
Hi all,
I am using openldap verrsion 1.1.14 on Linux.
The server is up and running. I am able to use ldapsearch and ldapmodify
commands to produce expected results.
I wrote a simple client program that connects using ldap_simple_bind_s()
function. When I run the code it gives an error saying 'can't contact LDAP
server'
On the other hand if I use ldap_open() function,instead, I am able to
connect as well as perform search on it.
Any clues ????
I am including the sample code for both
sample code
---------------------------NON WORKING CODE-------------------------------
#include <stdio.h>
#include <lber.h>
#include <ldap.h>
#define LDAPHOST "server.uky.edu"
#define LDAPPORT 1000
#define SEARCHBASE "o= univ name"
main() {
LDAP *ld;
LDAPMessage *result;
int nentries;
if ( (ld = ldap_init(LDAPHOST, LDAPPORT)) == NULL) {
perror("ldap_init");
return( 1 );
}
if( ldap_simple_bind_s( ld, NULL, NULL ) != LDAP_SUCCESS) {
ldap_perror( ld, "bind ->>>" );
ldap_unbind( ld );
return( 1 );
}
printf("The SERVER is UP\n");
if ( ldap_search_s( ld, SEARCHBASE, LDAP_SCOPE_SUBTREE,
"(objectclass=Hosts)", NULL, 0, &result ) != LDAP_SUCCESS) {
ldap_perror ( ld, "ldap_searc_s");
exit(1);
}
This code gives me error as "bind ->>>: Can't contact LDAP server"
----------------------------The working code
Headers same as above
if ( (ld = ldap_open( LDAPHOST, LDAPPORT)) == NULL) {
printf("The server cannot be contacted\n");
perror("ldap_open");
exit( 1 );
}
printf("The SERVER is UP\n");
if ( ldap_search_s( ld, SEARCHBASE, LDAP_SCOPE_SUBTREE,
"(objectclass=Hosts)", NULL, 0, &result ) != LDAP_SUCCESS) {
ldap_perror ( ld, "ldap_searc_s");
exit(1);
}
This code returns right number of entries.
--------------------------------------------------------------------------