]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/modify.c
Use #ifdef, not #if
[openldap] / servers / slapd / modify.c
index 8c96cb2abb1eeb322baf8cb3ee8e48ab8e36b962..af40315e35c028dbb374e33aaa97d8f58f71e0dd 100644 (file)
@@ -49,7 +49,7 @@ do_modify(
        Modifications *mods = NULL;
        Backend         *be;
        int rc;
-       char    *text;
+       const char      *text;
 
        Debug( LDAP_DEBUG_TRACE, "do_modify\n", 0, 0, 0 );
 
@@ -218,7 +218,7 @@ do_modify(
                {
                        int update = be->be_update_ndn != NULL;
 #ifdef SLAPD_SCHEMA_NOT_COMPAT
-                       char *text;
+                       const char *text;
                        rc = slap_modlist2mods( modlist, update, &mods, &text );
 
                        if( rc != LDAP_SUCCESS ) {
@@ -235,7 +235,14 @@ do_modify(
                                global_lastmod == ON)) && !update )
                        {
 #ifdef SLAPD_SCHEMA_NOT_COMPAT
-                               rc = slap_mods_opattrs( op, &mods, &text );
+                               Modifications **modstail;
+                               for( modstail = &mods;
+                                       *modstail != NULL;
+                                       modstail = &(*modstail)->sml_next )
+                               {
+                                       /* empty */
+                               }
+                               rc = slap_mods_opattrs( op, modstail, &text );
 #else
                                char *text = "no-user-modification attribute type";
                                rc = add_modified_attrs( op, &mods );
@@ -269,7 +276,7 @@ do_modify(
                }
        } else {
                send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
-                   NULL, "modify function not implemented", NULL, NULL );
+                   NULL, "operation not supported within namingContext", NULL, NULL );
        }
 
 cleanup:
@@ -291,7 +298,7 @@ int slap_modlist2mods(
        LDAPModList *ml,
        int update,
        Modifications **mods,
-       char **text )
+       const char **text )
 {
        int rc;
        Modifications **modtail = mods;
@@ -303,16 +310,19 @@ int slap_modlist2mods(
                mod = (Modifications *)
                        ch_calloc( 1, sizeof(Modifications) );
 
-               ad = mod->sml_desc;
+               /* copy the op */
+               mod->sml_op = ml->ml_op;
 
                /* convert to attribute description */
-               rc = slap_str2ad( ml->ml_type, &ad, text );
+               rc = slap_str2ad( ml->ml_type, &mod->sml_desc, text );
 
                if( rc != LDAP_SUCCESS ) {
                        slap_mods_free( mod );
                        return rc;
                }
 
+               ad = mod->sml_desc;
+
                if( slap_syntax_is_binary( ad->ad_type->sat_syntax )
                        && !slap_ad_is_binary( ad ))
                {
@@ -346,6 +356,15 @@ int slap_modlist2mods(
                        slap_syntax_validate_func *validate =
                                ad->ad_type->sat_syntax->ssyn_validate;
 
+                       if( !validate ) {
+                               Debug( LDAP_DEBUG_TRACE,
+                                       "modlist2mods: no validator for syntax %s\n",
+                                       ad->ad_type->sat_syntax->ssyn_oid, 0, 0 );
+                               slap_mods_free( mod );
+                               *text = "no validator for syntax";
+                               return LDAP_INVALID_SYNTAX;
+                       }
+
                        /*
                         * check that each value is valid per syntax
                         */
@@ -363,7 +382,7 @@ int slap_modlist2mods(
                         * a rough single value check... an additional check is needed
                         * to catch add of single value to existing single valued attribute
                         */
-                       if( ( ml->ml_op == LDAP_MOD_ADD || ml->ml_op == LDAP_MOD_REPLACE )
+                       if( ( mod->sml_op == LDAP_MOD_ADD || mod->sml_op == LDAP_MOD_REPLACE )
                                && nvals > 1 && is_at_single_value( ad->ad_type ))
                        {
                                slap_mods_free( mod );
@@ -385,7 +404,7 @@ int slap_modlist2mods(
 int slap_mods_opattrs(
        Operation *op,
        Modifications **modtail,
-       char **text )
+       const char **text )
 {
        struct berval name, timestamp;
        time_t now = slap_get_time();
@@ -396,6 +415,9 @@ int slap_mods_opattrs(
        int mop = op->o_tag == LDAP_REQ_ADD
                ? LDAP_MOD_ADD : LDAP_MOD_REPLACE;
 
+       assert( modtail != NULL );
+       assert( *modtail == NULL );
+
        ldap_pvt_thread_mutex_lock( &gmtime_mutex );
        ltm = gmtime( &now );
        strftime( timebuf, sizeof(timebuf), "%Y%m%d%H%M%SZ", ltm );
@@ -404,8 +426,8 @@ int slap_mods_opattrs(
        timestamp.bv_len = strlen(timebuf);
 
        if( op->o_dn == NULL || op->o_dn[0] == '\0' ) {
-               name.bv_val = "<anonymous>";
-               name.bv_len = sizeof("<anonymous>")-1;
+               name.bv_val = SLAPD_ANONYMOUS;
+               name.bv_len = sizeof(SLAPD_ANONYMOUS)-1;
        } else {
                name.bv_val = op->o_dn;
                name.bv_len = strlen( op->o_dn );
@@ -414,7 +436,7 @@ int slap_mods_opattrs(
        if( op->o_tag == LDAP_REQ_ADD ) {
                mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ) );
                mod->sml_op = mop;
-               mod->sml_desc = slap_schema.si_ad_creatorsName;
+               mod->sml_desc = ad_dup( slap_schema.si_ad_creatorsName );
                mod->sml_bvalues = (struct berval **) malloc( 2 * sizeof( struct berval * ) );
                mod->sml_bvalues[0] = ber_bvdup( &name );
                mod->sml_bvalues[1] = NULL;
@@ -424,7 +446,7 @@ int slap_mods_opattrs(
 
                mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ) );
                mod->sml_op = mop;
-               mod->sml_desc = slap_schema.si_ad_createTimestamp;
+               mod->sml_desc = ad_dup( slap_schema.si_ad_createTimestamp );
                mod->sml_bvalues = (struct berval **) malloc( 2 * sizeof( struct berval * ) );
                mod->sml_bvalues[0] = ber_bvdup( &timestamp );
                mod->sml_bvalues[1] = NULL;
@@ -434,7 +456,7 @@ int slap_mods_opattrs(
 
        mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ) );
        mod->sml_op = mop;
-       mod->sml_desc = slap_schema.si_ad_modifiersName;
+       mod->sml_desc = ad_dup( slap_schema.si_ad_modifiersName );
        mod->sml_bvalues = (struct berval **) malloc( 2 * sizeof( struct berval * ) );
        mod->sml_bvalues[0] = ber_bvdup( &name );
        mod->sml_bvalues[1] = NULL;
@@ -443,7 +465,7 @@ int slap_mods_opattrs(
 
        mod = (Modifications *) ch_calloc( 1, sizeof( Modifications ) );
        mod->sml_op = mop;
-       mod->sml_desc = slap_schema.si_ad_modifyTimestamp;
+       mod->sml_desc = ad_dup( slap_schema.si_ad_modifyTimestamp );
        mod->sml_bvalues = (struct berval **) malloc( 2 * sizeof( struct berval * ) );
        mod->sml_bvalues[0] = ber_bvdup( &timestamp );
        mod->sml_bvalues[1] = NULL;
@@ -475,8 +497,8 @@ add_modified_attrs( Operation *op, Modifications **modlist )
        }
 
        if ( op->o_dn == NULL || op->o_dn[0] == '\0' ) {
-               bv.bv_val = "<anonymous>";
-               bv.bv_len = sizeof("<anonymous>")-1;
+               bv.bv_val = SLAPD_ANONYMOUS;
+               bv.bv_len = sizeof(SLAPD_ANONYMOUS)-1;
        } else {
                bv.bv_val = op->o_dn;
                bv.bv_len = strlen( bv.bv_val );