]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/overlays/accesslog.c
ITS#7088 fix deadlock on write operations that do not need to be logged (please check)
[openldap] / servers / slapd / overlays / accesslog.c
index 5cb4d73308933d73c8c2076f5f96ada9c3a1d2d2..bc5b7b6e57a9809d48a4e63f04cca905de998f2d 100644 (file)
@@ -1432,12 +1432,30 @@ static void accesslog_val2val(AttributeDescription *ad, struct berval *val,
        dst->bv_val[dst->bv_len] = '\0';
 }
 
+static int
+accesslog_op2logop( Operation *op )
+{
+       switch ( op->o_tag ) {
+       case LDAP_REQ_ADD:              return LOG_EN_ADD;
+       case LDAP_REQ_DELETE:   return LOG_EN_DELETE;
+       case LDAP_REQ_MODIFY:   return LOG_EN_MODIFY;
+       case LDAP_REQ_MODRDN:   return LOG_EN_MODRDN;
+       case LDAP_REQ_COMPARE:  return LOG_EN_COMPARE;
+       case LDAP_REQ_SEARCH:   return LOG_EN_SEARCH;
+       case LDAP_REQ_BIND:             return LOG_EN_BIND;
+       case LDAP_REQ_EXTENDED: return LOG_EN_EXTENDED;
+       default:        /* unknown operation type */
+               break;
+       }       /* Unbind and Abandon never reach here */
+       return LOG_EN_UNKNOWN;
+}
+
 static int accesslog_response(Operation *op, SlapReply *rs) {
        slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
        log_info *li = on->on_bi.bi_private;
        Attribute *a, *last_attr;
        Modifications *m;
-       struct berval *b;
+       struct berval *b, uuid = BER_BVNULL;
        int i;
        int logop;
        slap_verbmasks *lo;
@@ -1452,19 +1470,7 @@ static int accesslog_response(Operation *op, SlapReply *rs) {
        if ( rs->sr_type != REP_RESULT && rs->sr_type != REP_EXTENDED )
                return SLAP_CB_CONTINUE;
 
-       switch ( op->o_tag ) {
-       case LDAP_REQ_ADD:              logop = LOG_EN_ADD; break;
-       case LDAP_REQ_DELETE:   logop = LOG_EN_DELETE; break;
-       case LDAP_REQ_MODIFY:   logop = LOG_EN_MODIFY; break;
-       case LDAP_REQ_MODRDN:   logop = LOG_EN_MODRDN; break;
-       case LDAP_REQ_COMPARE:  logop = LOG_EN_COMPARE; break;
-       case LDAP_REQ_SEARCH:   logop = LOG_EN_SEARCH; break;
-       case LDAP_REQ_BIND:             logop = LOG_EN_BIND; break;
-       case LDAP_REQ_EXTENDED: logop = LOG_EN_EXTENDED; break;
-       default:        /* unknown operation type */
-               logop = LOG_EN_UNKNOWN; break;
-       }       /* Unbind and Abandon never reach here */
-
+       logop = accesslog_op2logop( op );
        lo = logops+logop+EN_OFFSET;
        if ( !( li->li_ops & lo->mask )) {
                log_base *lb;
@@ -1479,6 +1485,8 @@ static int accesslog_response(Operation *op, SlapReply *rs) {
                        return SLAP_CB_CONTINUE;
        }
 
+       /* mutex and so were only set for write operations;
+        * if we got here, the operation must be logged */
        if ( lo->mask & LOG_OP_WRITES ) {
                slap_callback *cb;
 
@@ -1488,7 +1496,9 @@ static int accesslog_response(Operation *op, SlapReply *rs) {
 
                ldap_pvt_thread_mutex_lock( &li->li_log_mutex );
                old = li->li_old;
+               uuid = li->li_uuid;
                li->li_old = NULL;
+               BER_BVZERO( &li->li_uuid );
                /* Disarm mod_cleanup */
                for ( cb = op->o_callback; cb; cb = cb->sc_next ) {
                        if ( cb->sc_private == (void *)on ) {
@@ -1784,11 +1794,11 @@ static int accesslog_response(Operation *op, SlapReply *rs) {
                break;
        }
 
-       if ( e_uuid || !BER_BVISNULL( &li->li_uuid ) ) {
+       if ( e_uuid || !BER_BVISNULL( &uuid ) ) {
                struct berval *pbv;
 
-               if ( !BER_BVISNULL( &li->li_uuid ) ) {
-                       pbv = &li->li_uuid;
+               if ( !BER_BVISNULL( &uuid ) ) {
+                       pbv = &uuid;
 
                } else {
                        a = attr_find( e_uuid->e_attrs, slap_schema.si_ad_entryUUID );
@@ -1801,9 +1811,9 @@ static int accesslog_response(Operation *op, SlapReply *rs) {
                        attr_merge_normalize_one( e, ad_reqEntryUUID, pbv, op->o_tmpmemctx );
                }
 
-               if ( !BER_BVISNULL( &li->li_uuid ) ) {
-                       ber_memfree( li->li_uuid.bv_val );
-                       BER_BVZERO( &li->li_uuid );
+               if ( !BER_BVISNULL( &uuid ) ) {
+                       ber_memfree( uuid.bv_val );
+                       BER_BVZERO( &uuid );
                }
        }
 
@@ -1896,19 +1906,23 @@ accesslog_op_mod( Operation *op, SlapReply *rs )
 {
        slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
        log_info *li = on->on_bi.bi_private;
+       slap_verbmasks *lo;
+       int logop;
        int doit = 0;
 
        /* These internal ops are not logged */
        if ( op->o_dont_replicate && op->orm_no_opattrs )
                return SLAP_CB_CONTINUE;
 
+       logop = accesslog_op2logop( op );
+       lo = logops+logop+EN_OFFSET;
 
-       if ( li->li_ops & LOG_OP_WRITES ) {
+       if ( li->li_ops & lo->mask ) {
                doit = 1;
        } else {
                log_base *lb;
                for ( lb = li->li_bases; lb; lb = lb->lb_next )
-                       if (( lb->lb_ops & LOG_OP_WRITES ) && dnIsSuffix( &op->o_req_ndn, &lb->lb_base )) {
+                       if (( lb->lb_ops & lo->mask ) && dnIsSuffix( &op->o_req_ndn, &lb->lb_base )) {
                                doit = 1;
                                break;
                        }