LDAP Access from this program

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matrixinline

    #1

    LDAP Access from this program

    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=loc alhost,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=loc alhost,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_bin d_s( ld, null, null);
    if ( rc != LDAP_SUCCESS )
    {
    fprintf(stderr, "ldap_simple_bi nd_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_ex t_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_entr y( ld, result );
    if ( e != NULL )
    {
    printf( "\nFound %s:\n\n", FIND_DN );

    /* Iterate through each attribute in the entry. */
    for ( a = ldap_first_attr ibute( ld, e, &ber );
    a != NULL; a = ldap_next_attri bute( 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[i] != NULL; i++ )
    {
    printf( "%s: %s\n", a, vals[i] );
    }
    ldap_value_free ( vals );
    }
    ldap_memfree( a );
    }
    if ( ber != NULL )
    {
    ber_free( ber, 0 );
    }
    }
    ldap_msgfree( result );
    ldap_unbind( ld );
    return( 0 );
    }

  • Mark McIntyre

    #2
    Re: LDAP Access from this program

    On Sun, 14 Oct 2007 22:49:33 -0700, in comp.lang.c , Matrixinline
    <anup.kataria@g mail.comwrote:
    >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=lo calhost,DN=com" . It always give me error
    >ldap_search_ex t_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

    Comment

    Working...