void ber_dump( BerElement *ber, int inout ) { char buf[132]; ber_len_t len; assert( ber != NULL ); assert( LBER_VALID( ber ) ); if ( inout == 1 ) { len = ber_pvt_ber_remaining(ber); } else { len = ber_pvt_ber_write(ber); } sprintf( buf, "ber_dump: buf=%p ptr=%p end=%p len=%ld\n", ber->ber_buf, ber->ber_ptr, ber->ber_end, (long) len ); (void) (*ber_pvt_log_print)( buf ); ber_bprint( ber->ber_ptr, len ); }
static int filter2ber( char *filter ) { int rc; struct berval bv = BER_BVNULL; BerElement *ber; printf( "Filter: %s\n", filter ); ber = ber_alloc_t( LBER_USE_DER ); if( ber == NULL ) { perror( "ber_alloc_t" ); return EXIT_FAILURE; } rc = ldap_pvt_put_filter( ber, filter ); if( rc < 0 ) { fprintf( stderr, "Filter error!\n"); return EXIT_FAILURE; } rc = ber_flatten2( ber, &bv, 0 ); if( rc < 0 ) { perror( "ber_flatten2" ); return EXIT_FAILURE; } printf( "BER encoding (len=%ld):\n", (long) bv.bv_len ); ber_bprint( bv.bv_val, bv.bv_len ); ber_free( ber, 1 ); return EXIT_SUCCESS; }
int ber_log_bprint(int errlvl, int loglvl, const char *data, ber_len_t len ) { assert( data != NULL ); if ( !ber_log_check( errlvl, loglvl )) { return 0; } ber_bprint(data, len); return 1; }
int checkSearchEntry(BerElement *ber) { int rc = LDAP_SUCCESS; ber_tag_t tag; ber_len_t len =0; BerValue attr; BerVarray vals; attr.bv_val = NULL; attr.bv_len = 0; char *a; int n; struct berval dn = BER_BVNULL; BerElement ber_value, ber_backup; ber_value = ber_backup= *ber; #ifdef DEBUG int ival = -1; ber_set_option( NULL, LBER_OPT_DEBUG_LEVEL, &ival ); #endif n=0; for ( a = first_attribute( ber ); a != NULL; a = next_attribute( ber ) ) { struct berval **vals; //printf( "| | ATTR: %s\n", a ); if ( (vals = get_values_len( &ber_value, a )) == NULL ) { printf( "| | %s:\t(no values)\n" , a); }else { int i; for ( i = 0; vals[i] != NULL; i++ ) { int j, nonascii; nonascii = 0; for ( j = 0; (ber_len_t) j < vals[i]->bv_len; j++ ) //Non-display ASCII will be shown as HEX, It is Control code before 33 in ASCII Table if ( !isascii( vals[i]->bv_val[j] ) || vals[i]->bv_val[j] < 33 ) { nonascii = 1; break; } if ( nonascii ) { printf( "|-%s(not ascii):\tlen (%ld) \n",a, vals[i]->bv_len ); ber_bprint( vals[i]->bv_val, vals[i]->bv_len ); continue; } #ifdef DETAIL printf( "|-%s:\tlen (%ld) \t%s\n",a, vals[i]->bv_len, vals[i]->bv_val ); #else printf( "|-%s:\t\t%s\n",a, vals[i]->bv_val ); #endif } ber_bvecfree( vals ); } ber_value = ber_backup; n++; } return n; }
static void print_search_entry( LDAP *ld, LDAPMessage *res ) { LDAPMessage *e; for ( e = ldap_first_entry( ld, res ); e != NULL; e = ldap_next_entry( ld, e ) ) { BerElement *ber = NULL; char *a, *dn, *ufn; if ( e->lm_msgtype == LDAP_RES_SEARCH_RESULT ) break; dn = ldap_get_dn( ld, e ); printf( "\tDN: %s\n", dn ); ufn = ldap_dn2ufn( dn ); printf( "\tUFN: %s\n", ufn ); free( dn ); free( ufn ); for ( a = ldap_first_attribute( ld, e, &ber ); a != NULL; a = ldap_next_attribute( ld, e, ber ) ) { struct berval **vals; printf( "\t\tATTR: %s\n", a ); if ( (vals = ldap_get_values_len( ld, e, a )) == NULL ) { printf( "\t\t\t(no values)\n" ); } else { int i; for ( i = 0; vals[i] != NULL; i++ ) { int j, nonascii; nonascii = 0; for ( j = 0; (ber_len_t) j < vals[i]->bv_len; j++ ) if ( !isascii( vals[i]->bv_val[j] ) ) { nonascii = 1; break; } if ( nonascii ) { printf( "\t\t\tlength (%ld) (not ascii)\n", vals[i]->bv_len ); #ifdef BPRINT_NONASCII ber_bprint( vals[i]->bv_val, vals[i]->bv_len ); #endif /* BPRINT_NONASCII */ continue; } printf( "\t\t\tlength (%ld) %s\n", vals[i]->bv_len, vals[i]->bv_val ); } ber_bvecfree( vals ); } } if(ber != NULL) { ber_free( ber, 0 ); } } if ( res->lm_msgtype == LDAP_RES_SEARCH_RESULT || res->lm_chain != NULL ) print_ldap_result( ld, res, "search" ); }