mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-01-12 10:54:48 +08:00
Rework to support txn intermediate responses
(if only they were implemented :-)
This commit is contained in:
parent
647df2b9cb
commit
0ba4b24c36
@ -114,6 +114,11 @@ static int dorename LDAP_P((
|
|||||||
const char *newsup,
|
const char *newsup,
|
||||||
int deleteoldrdn,
|
int deleteoldrdn,
|
||||||
LDAPControl **pctrls ));
|
LDAPControl **pctrls ));
|
||||||
|
static int process_response(
|
||||||
|
LDAP *ld,
|
||||||
|
int msgid,
|
||||||
|
const char *opstr,
|
||||||
|
const char *dn );
|
||||||
static char *read_one_record LDAP_P(( FILE *fp ));
|
static char *read_one_record LDAP_P(( FILE *fp ));
|
||||||
|
|
||||||
#ifdef LDAP_GROUP_TRANSACTION
|
#ifdef LDAP_GROUP_TRANSACTION
|
||||||
@ -941,7 +946,7 @@ domodify(
|
|||||||
LDAPControl **pctrls,
|
LDAPControl **pctrls,
|
||||||
int newentry )
|
int newentry )
|
||||||
{
|
{
|
||||||
int i, j, k, notascii, op;
|
int rc, i, j, k, notascii, op;
|
||||||
struct berval *bvp;
|
struct berval *bvp;
|
||||||
|
|
||||||
if ( dn == NULL ) {
|
if ( dn == NULL ) {
|
||||||
@ -1004,24 +1009,32 @@ domodify(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( !not ) {
|
if ( !not ) {
|
||||||
|
int msgid;
|
||||||
if ( newentry ) {
|
if ( newentry ) {
|
||||||
i = ldap_add_ext_s( ld, dn, pmods, pctrls, NULL );
|
rc = ldap_add_ext( ld, dn, pmods, pctrls, NULL, &msgid );
|
||||||
} else {
|
} else {
|
||||||
i = ldap_modify_ext_s( ld, dn, pmods, pctrls, NULL );
|
rc = ldap_modify_ext( ld, dn, pmods, pctrls, NULL, &msgid );
|
||||||
}
|
}
|
||||||
if ( i != LDAP_SUCCESS ) {
|
|
||||||
|
if ( rc != LDAP_SUCCESS ) {
|
||||||
/* print error message about failed update including DN */
|
/* print error message about failed update including DN */
|
||||||
fprintf( stderr, _("%s: update failed: %s\n"), prog, dn );
|
fprintf( stderr, _("%s: update failed: %s\n"), prog, dn );
|
||||||
ldap_perror( ld, newentry ? "ldap_add" : "ldap_modify" );
|
ldap_perror( ld, newentry ? "ldap_add" : "ldap_modify" );
|
||||||
|
goto done;
|
||||||
} else if ( verbose ) {
|
} else if ( verbose ) {
|
||||||
printf( _("modify complete\n") );
|
printf( _("modify complete\n") );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rc = process_response( ld, msgid,
|
||||||
|
newentry ? "ldap_add" : "ldap_modify", dn );
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
i = LDAP_SUCCESS;
|
rc = LDAP_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
done:
|
||||||
putchar( '\n' );
|
putchar( '\n' );
|
||||||
return( i );
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1031,20 +1044,26 @@ dodelete(
|
|||||||
LDAPControl **pctrls )
|
LDAPControl **pctrls )
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
int msgid;
|
||||||
|
|
||||||
printf( _("%sdeleting entry \"%s\"\n"), not ? "!" : "", dn );
|
printf( _("%sdeleting entry \"%s\"\n"), not ? "!" : "", dn );
|
||||||
if ( !not ) {
|
if ( !not ) {
|
||||||
rc = ldap_delete_ext_s( ld, dn, pctrls, NULL );
|
rc = ldap_delete_ext( ld, dn, pctrls, NULL, &msgid );
|
||||||
if ( rc != LDAP_SUCCESS ) {
|
if ( rc != LDAP_SUCCESS ) {
|
||||||
fprintf( stderr, _("%s: delete failed: %s\n"), prog, dn );
|
fprintf( stderr, _("%s: delete failed: %s\n"), prog, dn );
|
||||||
ldap_perror( ld, "ldap_delete" );
|
ldap_perror( ld, "ldap_delete" );
|
||||||
|
goto done;
|
||||||
} else if ( verbose ) {
|
} else if ( verbose ) {
|
||||||
printf( _("delete complete") );
|
printf( _("delete complete") );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rc = process_response( ld, msgid, "ldap_delete", dn );
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
rc = LDAP_SUCCESS;
|
rc = LDAP_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
done:
|
||||||
putchar( '\n' );
|
putchar( '\n' );
|
||||||
return( rc );
|
return( rc );
|
||||||
}
|
}
|
||||||
@ -1059,6 +1078,7 @@ dorename(
|
|||||||
LDAPControl **pctrls )
|
LDAPControl **pctrls )
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
int msgid;
|
||||||
|
|
||||||
printf( _("%smodifying rdn of entry \"%s\"\n"), not ? "!" : "", dn );
|
printf( _("%smodifying rdn of entry \"%s\"\n"), not ? "!" : "", dn );
|
||||||
if ( verbose ) {
|
if ( verbose ) {
|
||||||
@ -1066,22 +1086,48 @@ dorename(
|
|||||||
newrdn, deleteoldrdn ? _("do not ") : "" );
|
newrdn, deleteoldrdn ? _("do not ") : "" );
|
||||||
}
|
}
|
||||||
if ( !not ) {
|
if ( !not ) {
|
||||||
rc = ldap_rename_s( ld, dn, newrdn, newsup, deleteoldrdn,
|
rc = ldap_rename( ld, dn, newrdn, newsup, deleteoldrdn,
|
||||||
pctrls, NULL );
|
pctrls, NULL, &msgid );
|
||||||
if ( rc != LDAP_SUCCESS ) {
|
if ( rc != LDAP_SUCCESS ) {
|
||||||
fprintf( stderr, _("%s: rename failed: %s\n"), prog, dn );
|
fprintf( stderr, _("%s: rename failed: %s\n"), prog, dn );
|
||||||
ldap_perror( ld, "ldap_modrdn" );
|
ldap_perror( ld, "ldap_modrdn" );
|
||||||
|
goto done;
|
||||||
} else {
|
} else {
|
||||||
printf( _("modrdn completed\n") );
|
printf( _("modrdn completed\n") );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rc = process_response( ld, msgid, "ldap_rename", dn );
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
rc = LDAP_SUCCESS;
|
rc = LDAP_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
done:
|
||||||
putchar( '\n' );
|
putchar( '\n' );
|
||||||
return( rc );
|
return( rc );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int process_response(
|
||||||
|
LDAP *ld,
|
||||||
|
int msgid,
|
||||||
|
const char *opstr,
|
||||||
|
const char *dn )
|
||||||
|
{
|
||||||
|
LDAPMessage *res;
|
||||||
|
int rc = LDAP_OTHER;
|
||||||
|
|
||||||
|
if( ldap_result( ld, msgid, txn ? 0 : 1, NULL, &res ) == -1 ) {
|
||||||
|
ldap_get_option( ld, LDAP_OPT_ERROR_NUMBER, &rc );
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( ldap_msgtype( res ) != LDAP_RES_INTERMEDIATE ) {
|
||||||
|
return ldap_result2error( ld, res, 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* assume (successful) transaction intermediate response */
|
||||||
|
return LDAP_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
read_one_record( FILE *fp )
|
read_one_record( FILE *fp )
|
||||||
|
Loading…
Reference in New Issue
Block a user