From 1ce491e4f48fa9ce32925c93f9e0a0ee9beeafa0 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Sun, 20 Nov 2005 14:17:37 +0000 Subject: [PATCH] fix library checks; implement client side of "touch" modify (ITS#4183) --- clients/tools/ldapmodify.c | 78 ++++++++++++++++++++------------------ libraries/libldap/add.c | 29 +++++++------- libraries/libldap/modify.c | 35 +++++++++-------- 3 files changed, 76 insertions(+), 66 deletions(-) diff --git a/clients/tools/ldapmodify.c b/clients/tools/ldapmodify.c index c96355951a..d8e077561b 100644 --- a/clients/tools/ldapmodify.c +++ b/clients/tools/ldapmodify.c @@ -960,47 +960,51 @@ domodify( } if ( pmods == NULL ) { - fprintf( stderr, - _("%s: no attributes to change or add (entry=\"%s\")\n"), - prog, dn ); - return( LDAP_PARAM_ERROR ); - } - - for ( i = 0; pmods[ i ] != NULL; ++i ) { - op = pmods[ i ]->mod_op & ~LDAP_MOD_BVALUES; - if( op == LDAP_MOD_ADD && ( pmods[i]->mod_bvalues == NULL )) { - fprintf( stderr, - _("%s: attribute \"%s\" has no values (entry=\"%s\")\n"), - prog, pmods[i]->mod_type, dn ); - return LDAP_PARAM_ERROR; - } - } + /* implement "touch" (empty sequence) + * modify operation (note that there + * is no symmetry with the UNIX command, + * since \"touch\" on a non-existent entry + * will fail)*/ + printf( "warning: no attributes to %sadd (entry=\"%s\")\n", + newentry ? "" : "change or ", dn ); - if ( verbose ) { + } else { for ( i = 0; pmods[ i ] != NULL; ++i ) { op = pmods[ i ]->mod_op & ~LDAP_MOD_BVALUES; - printf( "%s %s:\n", - op == LDAP_MOD_REPLACE ? _("replace") : - op == LDAP_MOD_ADD ? _("add") : - op == LDAP_MOD_INCREMENT ? _("increment") : - op == LDAP_MOD_DELETE ? _("delete") : - _("unknown"), - pmods[ i ]->mod_type ); - - if ( pmods[ i ]->mod_bvalues != NULL ) { - for ( j = 0; pmods[ i ]->mod_bvalues[ j ] != NULL; ++j ) { - bvp = pmods[ i ]->mod_bvalues[ j ]; - notascii = 0; - for ( k = 0; (unsigned long) k < bvp->bv_len; ++k ) { - if ( !isascii( bvp->bv_val[ k ] )) { - notascii = 1; - break; + if( op == LDAP_MOD_ADD && ( pmods[i]->mod_bvalues == NULL )) { + fprintf( stderr, + _("%s: attribute \"%s\" has no values (entry=\"%s\")\n"), + prog, pmods[i]->mod_type, dn ); + return LDAP_PARAM_ERROR; + } + } + + if ( verbose ) { + for ( i = 0; pmods[ i ] != NULL; ++i ) { + op = pmods[ i ]->mod_op & ~LDAP_MOD_BVALUES; + printf( "%s %s:\n", + op == LDAP_MOD_REPLACE ? _("replace") : + op == LDAP_MOD_ADD ? _("add") : + op == LDAP_MOD_INCREMENT ? _("increment") : + op == LDAP_MOD_DELETE ? _("delete") : + _("unknown"), + pmods[ i ]->mod_type ); + + if ( pmods[ i ]->mod_bvalues != NULL ) { + for ( j = 0; pmods[ i ]->mod_bvalues[ j ] != NULL; ++j ) { + bvp = pmods[ i ]->mod_bvalues[ j ]; + notascii = 0; + for ( k = 0; (unsigned long) k < bvp->bv_len; ++k ) { + if ( !isascii( bvp->bv_val[ k ] )) { + notascii = 1; + break; + } + } + if ( notascii ) { + printf( _("\tNOT ASCII (%ld bytes)\n"), bvp->bv_len ); + } else { + printf( "\t%s\n", bvp->bv_val ); } - } - if ( notascii ) { - printf( _("\tNOT ASCII (%ld bytes)\n"), bvp->bv_len ); - } else { - printf( "\t%s\n", bvp->bv_val ); } } } diff --git a/libraries/libldap/add.c b/libraries/libldap/add.c index 35b0cb6ed1..88b849b359 100644 --- a/libraries/libldap/add.c +++ b/libraries/libldap/add.c @@ -136,19 +136,22 @@ ldap_add_ext( return ld->ld_errno; } - /* for each attribute in the entry... */ - for ( i = 0; attrs[i] != NULL; i++ ) { - if ( ( attrs[i]->mod_op & LDAP_MOD_BVALUES) != 0 ) { - rc = ber_printf( ber, "{s[V]N}", attrs[i]->mod_type, - attrs[i]->mod_bvalues ); - } else { - rc = ber_printf( ber, "{s[v]N}", attrs[i]->mod_type, - attrs[i]->mod_values ); - } - if ( rc == -1 ) { - ld->ld_errno = LDAP_ENCODING_ERROR; - ber_free( ber, 1 ); - return ld->ld_errno; + /* allow attrs to be NULL ("touch"; should fail...) */ + if ( attrs ) { + /* for each attribute in the entry... */ + for ( i = 0; attrs[i] != NULL; i++ ) { + if ( ( attrs[i]->mod_op & LDAP_MOD_BVALUES) != 0 ) { + rc = ber_printf( ber, "{s[V]N}", attrs[i]->mod_type, + attrs[i]->mod_bvalues ); + } else { + rc = ber_printf( ber, "{s[v]N}", attrs[i]->mod_type, + attrs[i]->mod_values ); + } + if ( rc == -1 ) { + ld->ld_errno = LDAP_ENCODING_ERROR; + ber_free( ber, 1 ); + return ld->ld_errno; + } } } diff --git a/libraries/libldap/modify.c b/libraries/libldap/modify.c index d7ca681bed..a03fd47057 100644 --- a/libraries/libldap/modify.c +++ b/libraries/libldap/modify.c @@ -103,22 +103,25 @@ ldap_modify_ext( LDAP *ld, return( ld->ld_errno ); } - /* for each modification to be performed... */ - for ( i = 0; mods[i] != NULL; i++ ) { - if (( mods[i]->mod_op & LDAP_MOD_BVALUES) != 0 ) { - rc = ber_printf( ber, "{e{s[V]N}N}", - (ber_int_t) ( mods[i]->mod_op & ~LDAP_MOD_BVALUES ), - mods[i]->mod_type, mods[i]->mod_bvalues ); - } else { - rc = ber_printf( ber, "{e{s[v]N}N}", - (ber_int_t) mods[i]->mod_op, - mods[i]->mod_type, mods[i]->mod_values ); - } - - if ( rc == -1 ) { - ld->ld_errno = LDAP_ENCODING_ERROR; - ber_free( ber, 1 ); - return( ld->ld_errno ); + /* allow mods to be NULL ("touch") */ + if ( mods ) { + /* for each modification to be performed... */ + for ( i = 0; mods[i] != NULL; i++ ) { + if (( mods[i]->mod_op & LDAP_MOD_BVALUES) != 0 ) { + rc = ber_printf( ber, "{e{s[V]N}N}", + (ber_int_t) ( mods[i]->mod_op & ~LDAP_MOD_BVALUES ), + mods[i]->mod_type, mods[i]->mod_bvalues ); + } else { + rc = ber_printf( ber, "{e{s[v]N}N}", + (ber_int_t) mods[i]->mod_op, + mods[i]->mod_type, mods[i]->mod_values ); + } + + if ( rc == -1 ) { + ld->ld_errno = LDAP_ENCODING_ERROR; + ber_free( ber, 1 ); + return( ld->ld_errno ); + } } } -- 2.39.5