X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fmodify.c;h=c3b5fc9cc84629c5d1f6961ddbb5bd2a8f45c56f;hb=af423fd393488947252da5fd6cd927edfd1bf110;hp=692d4fbe4fb584e3d35ee650c9d60ea904dbf1aa;hpb=c89fab6acca61316fc8ee49909d27e101a288c55;p=openldap diff --git a/servers/slapd/modify.c b/servers/slapd/modify.c index 692d4fbe4f..c3b5fc9cc8 100644 --- a/servers/slapd/modify.c +++ b/servers/slapd/modify.c @@ -30,7 +30,7 @@ do_modify( Operation *op ) { - char *dn, *odn; + char *ndn; char *last; unsigned long tag, len; LDAPModList *modlist, *tmp; @@ -58,15 +58,15 @@ do_modify( * } */ - if ( ber_scanf( op->o_ber, "{a" /*}*/, &dn ) == LBER_ERROR ) { + if ( ber_scanf( op->o_ber, "{a" /*}*/, &ndn ) == LBER_ERROR ) { Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 ); send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL, "" ); return; } - odn = ch_strdup( dn ); - dn_normalize( dn ); - Debug( LDAP_DEBUG_ARGS, "do_modify: dn (%s)\n", dn, 0, 0 ); + Debug( LDAP_DEBUG_ARGS, "do_modify: dn (%s)\n", ndn, 0, 0 ); + + (void) dn_normalize_case( ndn ); /* collect modifications & save for later */ modlist = NULL; @@ -84,8 +84,7 @@ do_modify( { send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL, "decoding error" ); - free( dn ); - free( odn ); + free( ndn ); free( *modtail ); *modtail = NULL; modlist_free( modlist ); @@ -98,8 +97,7 @@ do_modify( { send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL, "unrecognized modify operation" ); - free( dn ); - free( odn ); + free( ndn ); modlist_free( modlist ); return; } @@ -109,8 +107,7 @@ do_modify( { send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL, "no values given" ); - free( dn ); - free( odn ); + free( ndn ); modlist_free( modlist ); return; } @@ -131,42 +128,41 @@ do_modify( #endif Statslog( LDAP_DEBUG_STATS, "conn=%d op=%d MOD dn=\"%s\"\n", - conn->c_connid, op->o_opid, dn, 0, 0 ); + conn->c_connid, op->o_opid, ndn, 0, 0 ); /* * We could be serving multiple database backends. Select the * appropriate one, or send a referral to our "referral server" * if we don't hold it. */ - if ( (be = select_backend( dn )) == NULL ) { - free( dn ); - free( odn ); + if ( (be = select_backend( ndn )) == NULL ) { + free( ndn ); modlist_free( modlist ); send_ldap_result( conn, op, LDAP_PARTIAL_RESULTS, NULL, default_referral ); return; } - /* alias suffix if approp */ - dn = suffixAlias ( dn, op, be ); + /* alias suffix if approp */ + ndn = suffixAlias ( ndn, op, be ); /* * do the modify if 1 && (2 || 3) * 1) there is a modify function implemented in this backend; * 2) this backend is master for what it holds; - * 3) it's a replica and the dn supplied is the updatedn. + * 3) it's a replica and the dn supplied is the update_ndn. */ - if ( be->be_modify != NULL ) { + if ( be->be_modify ) { /* do the update here */ - if ( be->be_updatedn == NULL || - strcasecmp( be->be_updatedn, op->o_dn ) == 0 ) { - + if ( be->be_update_ndn == NULL || + strcmp( be->be_update_ndn, op->o_ndn ) == 0 ) + { if ( (be->be_lastmod == ON || ( be->be_lastmod == UNDEFINED && - global_lastmod == ON ) ) && be->be_updatedn == NULL ) { + global_lastmod == ON ) ) && be->be_update_ndn == NULL ) { add_lastmods( op, &modlist ); } - if ( (*be->be_modify)( be, conn, op, odn, modlist ) == 0 ) { - replog( be, LDAP_REQ_MODIFY, dn, modlist, 0 ); + if ( (*be->be_modify)( be, conn, op, ndn, modlist ) == 0 ) { + replog( be, LDAP_REQ_MODIFY, ndn, modlist, 0 ); } /* send a referral */ @@ -179,8 +175,7 @@ do_modify( "Function not implemented" ); } - free( dn ); - free( odn ); + free( ndn ); modlist_free( modlist ); } @@ -211,6 +206,7 @@ add_lastmods( Operation *op, LDAPModList **modlist ) LDAPModList **m; LDAPModList *tmp; struct tm *ltm; + time_t currenttime; Debug( LDAP_DEBUG_TRACE, "add_lastmods\n", 0, 0, 0 ); @@ -249,13 +245,13 @@ add_lastmods( Operation *op, LDAPModList **modlist ) tmp = (LDAPModList *) ch_calloc( 1, sizeof(LDAPModList) ); tmp->ml_type = ch_strdup( "modifiersname" ); tmp->ml_op = LDAP_MOD_REPLACE; - tmp->ml_bvalues = (struct berval **) ch_calloc( 1, - 2 * sizeof(struct berval *) ); + tmp->ml_bvalues = (struct berval **) ch_calloc(2, sizeof(struct berval *)); tmp->ml_bvalues[0] = ber_bvdup( &bv ); tmp->ml_next = *modlist; *modlist = tmp; - pthread_mutex_lock( ¤ttime_mutex ); + currenttime = slap_get_time(); + ldap_pvt_thread_mutex_lock( &gmtime_mutex ); #ifndef LDAP_LOCALTIME ltm = gmtime( ¤ttime ); strftime( buf, sizeof(buf), "%Y%m%d%H%M%SZ", ltm ); @@ -263,13 +259,14 @@ add_lastmods( Operation *op, LDAPModList **modlist ) ltm = localtime( ¤ttime ); strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm ); #endif - pthread_mutex_unlock( ¤ttime_mutex ); + ldap_pvt_thread_mutex_unlock( &gmtime_mutex ); + bv.bv_val = buf; bv.bv_len = strlen( bv.bv_val ); tmp = (LDAPModList *) ch_calloc( 1, sizeof(LDAPModList) ); tmp->ml_type = ch_strdup( "modifytimestamp" ); tmp->ml_op = LDAP_MOD_REPLACE; - tmp->ml_bvalues = (struct berval **) ch_calloc( 1, 2 * sizeof(struct berval *) ); + tmp->ml_bvalues = (struct berval **) ch_calloc(2, sizeof(struct berval *)); tmp->ml_bvalues[0] = ber_bvdup( &bv ); tmp->ml_next = *modlist; *modlist = tmp;