]> git.sur5r.net Git - openldap/commitdiff
fix library checks; implement client side of "touch" modify (ITS#4183)
authorPierangelo Masarati <ando@openldap.org>
Sun, 20 Nov 2005 14:17:37 +0000 (14:17 +0000)
committerPierangelo Masarati <ando@openldap.org>
Sun, 20 Nov 2005 14:17:37 +0000 (14:17 +0000)
clients/tools/ldapmodify.c
libraries/libldap/add.c
libraries/libldap/modify.c

index c96355951accdd7b296315c6f0a03d8d194b1105..d8e077561b6a15bc1170ed9ddd0e6e867a4183dc 100644 (file)
@@ -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 );
                                        }
                                }
                        }
index 35b0cb6ed1a77134af61b214ab1a127efb3fdb0a..88b849b3599adca773c2ab9f5787531050edd793 100644 (file)
@@ -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;
+                       }
                }
        }
 
index d7ca681bed89c94cb9d41afe5287ac11918144c8..a03fd47057663c5372d73599e2522fe206cea65f 100644 (file)
@@ -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 );
+                       }
                }
        }