Add reporting of LDAPv3 referrals. Should also report returned controls.

Also, as written, the code will behave better in the face of unsolicited
noticifications (such as notice of disconnect).  However, code needs to
be improved to better distinguished such from expected result response.
Delete improvements are limited to base object delete.  Should be applied
to -p[rune] option as well.
This commit is contained in:
Kurt Zeilenga 2000-07-03 19:03:22 +00:00
parent 2eb664f481
commit 8be1d467b8
3 changed files with 151 additions and 28 deletions

View File

@ -435,7 +435,10 @@ static int dodelete(
LDAP *ld,
const char *dn)
{
int rc;
int id;
int rc, code;
char *matcheddn = NULL, *text = NULL, **refs = NULL;
LDAPMessage *res;
if ( verbose ) {
printf( "%sdeleting entry \"%s\"\n",
@ -451,16 +454,49 @@ static int dodelete(
*/
if ( prune ) deletechildren( ld, dn );
rc = ldap_delete_s( ld, dn );
rc = ldap_delete_ext( ld, dn, NULL, NULL, &id );
if ( rc != LDAP_SUCCESS ) {
ldap_perror( ld, "ldap_delete" );
ldap_perror( ld, "ldap_delete_ext" );
return rc;
}
if ( verbose ) {
printf( "\tremoved\n" );
rc = ldap_result( ld, LDAP_RES_ANY, 0, NULL, &res );
if ( rc != LDAP_SUCCESS ) {
ldap_perror( ld, "ldap_result" );
return rc;
}
return rc;
rc = ldap_parse_result( ld, res, &code, &matcheddn, &text, &refs, NULL, 1 );
if( rc != LDAP_SUCCESS ) {
ldap_perror( ld, "ldap_parse_result" );
return rc;
}
if( verbose || code != LDAP_SUCCESS || matcheddn || text || refs ) {
printf( "Result: %s (%d)\n", ldap_err2string( code ), code );
if( text && *text ) {
printf( "Additional info: %s\n", text );
}
if( matcheddn && *matcheddn ) {
printf( "Matched DN: %s\n", matcheddn );
}
if( refs ) {
int i;
for( i=0; refs[i]; i++ ) {
printf("Referral: %s\n", refs[i] );
}
}
}
ber_memfree( text );
ber_memfree( matcheddn );
ber_memvfree( refs );
return code;
}
/*

View File

@ -490,7 +490,9 @@ static int domodrdn(
char *newSuperior,
int remove ) /* flag: remove old RDN */
{
int i;
int rc, code, id;
char *matcheddn=NULL, *text=NULL, **refs=NULL;
LDAPMessage *res;
if ( verbose ) {
printf( "Renaming \"%s\"\n", dn );
@ -501,16 +503,51 @@ static int domodrdn(
}
}
if ( !not ) {
i = ldap_rename2_s( ld, dn, rdn, newSuperior, remove );
if ( i != LDAP_SUCCESS ) {
ldap_perror( ld, "ldap_rename2_s" );
} else if ( verbose ) {
printf( "modrdn complete\n" );
}
} else {
i = LDAP_SUCCESS;
}
if( not ) return LDAP_SUCCESS;
return( i );
rc = ldap_rename( ld, dn, rdn, newSuperior, remove,
NULL, NULL, &id );
if ( rc != LDAP_SUCCESS ) {
ldap_perror( ld, "ldap_rename" );
return rc;
}
rc = ldap_result( ld, LDAP_RES_ANY, 0, NULL, &res );
if ( rc != LDAP_SUCCESS ) {
ldap_perror( ld, "ldap_result" );
return rc;
}
rc = ldap_parse_result( ld, res, &code, &matcheddn, &text, &refs, NULL, 1 );
if( rc != LDAP_SUCCESS ) {
ldap_perror( ld, "ldap_parse_result" );
return rc;
}
if( verbose || code != LDAP_SUCCESS || matcheddn || text || refs ) {
printf( "Result: %s (%d)\n", ldap_err2string( code ), code );
if( text && *text ) {
printf( "Additional info: %s\n", text );
}
if( matcheddn && *matcheddn ) {
printf( "Matched DN: %s\n", matcheddn );
}
if( refs ) {
int i;
for( i=0; refs[i]; i++ ) {
printf("Referral: %s\n", refs[i] );
}
}
}
ber_memfree( text );
ber_memfree( matcheddn );
ber_memvfree( refs );
return code;
}

View File

@ -91,8 +91,11 @@ main( int argc, char *argv[] )
LDAP *ld;
struct berval *bv = NULL;
char *retoid;
struct berval *retdata;
int id, code;
LDAPMessage *res;
char *matcheddn = NULL, *text = NULL, **refs = NULL;
char *retoid = NULL;
struct berval *retdata = NULL;
if (argc == 1)
usage (argv[0]);
@ -429,13 +432,43 @@ main( int argc, char *argv[] )
ber_free( ber, 1 );
}
rc = ldap_extended_operation_s( ld,
if ( noupdates ) {
rc = LDAP_SUCCESS;
goto skip;
}
rc = ldap_extended_operation( ld,
LDAP_EXOP_X_MODIFY_PASSWD, bv,
NULL, NULL,
&retoid, &retdata );
NULL, NULL, &id );
ber_bvfree( bv );
if( rc != LDAP_SUCCESS ) {
ldap_perror( ld, "ldap_extended_operation" );
ldap_unbind( ld );
return EXIT_FAILURE;
}
rc = ldap_result( ld, LDAP_RES_ANY, 0, NULL, &res );
if ( rc != LDAP_SUCCESS ) {
ldap_perror( ld, "ldap_result" );
return rc;
}
rc = ldap_parse_result( ld, res, &code, &matcheddn, &text, &refs, NULL, 0 );
if( rc != LDAP_SUCCESS ) {
ldap_perror( ld, "ldap_parse_result" );
return rc;
}
rc = ldap_parse_extended_result( ld, res, &retoid, &retdata, 1 );
if( rc != LDAP_SUCCESS ) {
ldap_perror( ld, "ldap_parse_result" );
return rc;
}
if( retdata != NULL ) {
ber_tag_t tag;
char *s;
@ -460,15 +493,32 @@ main( int argc, char *argv[] )
ber_free( ber, 1 );
}
if ( rc != LDAP_SUCCESS ) {
ldap_perror( ld, "ldap_extended_operation" );
ldap_unbind( ld );
return EXIT_FAILURE;
if( verbose || code != LDAP_SUCCESS || matcheddn || text || refs ) {
printf( "Result: %s (%d)\n", ldap_err2string( code ), code );
if( text && *text ) {
printf( "Additional info: %s\n", text );
}
if( matcheddn && *matcheddn ) {
printf( "Matched DN: %s\n", matcheddn );
}
if( refs ) {
int i;
for( i=0; refs[i]; i++ ) {
printf("Referral: %s\n", refs[i] );
}
}
}
ldap_memfree( retoid );
ber_memfree( text );
ber_memfree( matcheddn );
ber_memvfree( refs );
ber_memfree( retoid );
ber_bvfree( retdata );
skip:
/* disconnect from server */
ldap_unbind (ld);