[Date Prev][Date Next] [Chronological] [Thread] [Top]

problem with ldap_search _ext and ldap_result

After binding the ldap server, here are my code snippets, 
finished = 0;

rc = ldap_search_ext( ld, "testactivedirectory.com", sub_tree, "(sAMAccountName=user1)", NULL, 0, NULL, NULL, NULL, 1, &msgid );

        if ( rc != LDAP_SUCCESS ) {
                fprintf( stderr, "ldap_search_ext: %s \n", ldap_err2string( rc ) );
                ldap_unbind( ld );
                return( 1 );
        while (!finished)
                rc = ldap_result( ld, msgid, LDAP_MSG_ONE, &zerotime, &res );
                printf("check the search result :%d\n", rc);

                switch ( rc ) {
                        case -1:
                                fprintf( stderr, "ldap_result: %s\n", ldap_err2string( rc ) );
                                ldap_unbind( ld );
                                return( 1 );

                        case 0:

                        case LDAP_RES_SEARCH_ENTRY:
                                /* Get and print the DN of the entry. */
                                if (( dn = ldap_get_dn( ld, res )) != NULL ) {
                                        printf( "dn-> %s\n", dn );
                                        ldap_memfree( dn );
                        case LDAP_RES_SEARCH_RESULT:
                                finished = 1;


while running this program, i could get the intended result what the distinguished name i want, but the ldap_result in not being exit with LDAP_RES_SEARCH_RESULT option. it tooks lot of time to respond with LDAP_RES_SEARCH_RESULT, even no more entry to provide.

check the search result :100
dn-> CN=user1,CN=Users,DC=testactivedirectory,DC=com
(it waits in looop... it exits after a very long time)
check the search result :101

i wanted to avoid this waiting time, even i have been sending entries should be limited to 1, it doesn't seems to be reflected,
i have found other way of fixing this, doing two bind and two unbind option. but that is not seems a optimized manner.

Let me know how to fix this problem, 

LDAP Learner