X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fadd.c;h=196a3189d5fd7b90d85bb7d14f347d0605e45481;hb=8743c05359d008eab5d65d5aacf1836bd583dafb;hp=cfff625602d4a1bae1e6c9ced059ffcb7eb45807;hpb=73276e84ae32e9e148197971d1d6729739980353;p=openldap diff --git a/servers/slapd/add.c b/servers/slapd/add.c index cfff625602..196a3189d5 100644 --- a/servers/slapd/add.c +++ b/servers/slapd/add.c @@ -20,13 +20,13 @@ #include "slap.h" -static void add_created_attrs(Operation *op, Entry *e); +static int add_created_attrs(Operation *op, Entry *e); int do_add( Connection *conn, Operation *op ) { BerElement *ber = op->o_ber; - char *dn, *last; + char *dn, *ndn, *last; ber_len_t len; ber_tag_t tag; Entry *e; @@ -62,10 +62,21 @@ do_add( Connection *conn, Operation *op ) return -1; } + ndn = ch_strdup( dn ); + + if ( dn_normalize_case( ndn ) == NULL ) { + Debug( LDAP_DEBUG_ANY, "do_add: invalid dn (%s)\n", dn, 0, 0 ); + send_ldap_result( conn, op, LDAP_INVALID_DN_SYNTAX, NULL, + "invalid DN", NULL, NULL ); + free( dn ); + free( ndn ); + return LDAP_INVALID_DN_SYNTAX; + } + e = (Entry *) ch_calloc( 1, sizeof(Entry) ); e->e_dn = dn; - e->e_ndn = dn_normalize_case( ch_strdup( dn ) ); + e->e_ndn = ndn; e->e_private = NULL; dn = NULL; @@ -117,7 +128,7 @@ do_add( Connection *conn, Operation *op ) } Statslog( LDAP_DEBUG_STATS, "conn=%d op=%d ADD dn=\"%s\"\n", - conn->c_connid, op->o_opid, e->e_ndn, 0, 0 ); + op->o_connid, op->o_opid, e->e_ndn, 0, 0 ); /* * We could be serving multiple database backends. Select the @@ -144,12 +155,21 @@ do_add( Connection *conn, Operation *op ) strcmp( be->be_update_ndn, op->o_ndn ) == 0 ) { if ( (be->be_lastmod == ON || (be->be_lastmod == UNDEFINED && - global_lastmod == ON)) && be->be_update_ndn == NULL ) { - - add_created_attrs( op, e ); + global_lastmod == ON)) && be->be_update_ndn == NULL ) + { + rc = add_created_attrs( op, e ); + + if( rc != LDAP_SUCCESS ) { + entry_free( e ); + send_ldap_result( conn, op, rc, + NULL, "no-user-modification attribute type", + NULL, NULL ); + return rc; + } } + if ( (*be->be_add)( be, conn, op, e ) == 0 ) { - replog( be, LDAP_REQ_ADD, e->e_dn, e, 0 ); + replog( be, op, e->e_dn, e ); be_entry_release_w( be, e ); } @@ -168,13 +188,13 @@ do_add( Connection *conn, Operation *op ) return rc; } -static void +static int add_created_attrs( Operation *op, Entry *e ) { char buf[22]; struct berval bv; struct berval *bvals[2]; - Attribute **a, **next; + Attribute *a; Attribute *tmp; struct tm *ltm; time_t currenttime; @@ -184,15 +204,10 @@ add_created_attrs( Operation *op, Entry *e ) bvals[0] = &bv; bvals[1] = NULL; - /* remove any attempts by the user to add these attrs */ - for ( a = &e->e_attrs; *a != NULL; a = next ) { - if ( oc_check_no_usermod_attr( (*a)->a_type ) ) { - tmp = *a; - *a = (*a)->a_next; - attr_free( tmp ); - next = a; - } else { - next = &(*a)->a_next; + /* return error on any attempts by the user to add these attrs */ + for ( a = e->e_attrs; a != NULL; a = a->a_next ) { + if ( oc_check_no_usermod_attr( a->a_type ) ) { + return LDAP_CONSTRAINT_VIOLATION; } } @@ -219,4 +234,6 @@ add_created_attrs( Operation *op, Entry *e ) bv.bv_val = buf; bv.bv_len = strlen( bv.bv_val ); attr_merge( e, "createtimestamp", bvals ); + + return LDAP_SUCCESS; }