Back to index

openldap  2.4.31
trace.c
Go to the documentation of this file.
00001 /* trace.c - traces overlay invocation */
00002 /* $OpenLDAP$ */
00003 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00004  *
00005  * Copyright 2006-2012 The OpenLDAP Foundation.
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted only as authorized by the OpenLDAP
00010  * Public License.
00011  *
00012  * A copy of this license is available in the file LICENSE in the
00013  * top-level directory of the distribution or, alternatively, at
00014  * <http://www.OpenLDAP.org/license.html>.
00015  */
00016 /* ACKNOWLEDGEMENTS:
00017  * This work was initially developed by Pierangelo Masarati for inclusion in
00018  * OpenLDAP Software.
00019  */
00020 
00021 #include "portable.h"
00022 
00023 #ifdef SLAPD_OVER_TRACE
00024 
00025 #include <stdio.h>
00026 
00027 #include <ac/string.h>
00028 #include <ac/socket.h>
00029 
00030 #include "slap.h"
00031 #include "lutil.h"
00032 
00033 static int
00034 trace_op2str( Operation *op, char **op_strp )
00035 {
00036        switch ( op->o_tag ) {
00037        case LDAP_REQ_BIND:
00038               *op_strp = "BIND";
00039               break;
00040 
00041        case LDAP_REQ_UNBIND:
00042               *op_strp = "UNBIND";
00043               break;
00044 
00045        case LDAP_REQ_SEARCH:
00046               *op_strp = "SEARCH";
00047               break;
00048 
00049        case LDAP_REQ_MODIFY:
00050               *op_strp = "MODIFY";
00051               break;
00052 
00053        case LDAP_REQ_ADD:
00054               *op_strp = "ADD";
00055               break;
00056 
00057        case LDAP_REQ_DELETE:
00058               *op_strp = "DELETE";
00059               break;
00060 
00061        case LDAP_REQ_MODRDN:
00062               *op_strp = "MODRDN";
00063               break;
00064 
00065        case LDAP_REQ_COMPARE:
00066               *op_strp = "COMPARE";
00067               break;
00068 
00069        case LDAP_REQ_ABANDON:
00070               *op_strp = "ABANDON";
00071               break;
00072 
00073        case LDAP_REQ_EXTENDED:
00074               *op_strp = "EXTENDED";
00075               break;
00076 
00077        default:
00078               assert( 0 );
00079        }
00080 
00081        return 0;
00082 }
00083 
00084 static int
00085 trace_op_func( Operation *op, SlapReply *rs )
00086 {
00087        char   *op_str = NULL;
00088 
00089        (void)trace_op2str( op, &op_str );
00090 
00091        switch ( op->o_tag ) {
00092        case LDAP_REQ_EXTENDED:
00093               Log3( LDAP_DEBUG_ANY, LDAP_LEVEL_INFO,
00094                      "%s trace op=EXTENDED dn=\"%s\" reqoid=%s\n",
00095                      op->o_log_prefix, 
00096                      BER_BVISNULL( &op->o_req_ndn ) ? "(null)" : op->o_req_ndn.bv_val,
00097                      BER_BVISNULL( &op->ore_reqoid ) ? "" : op->ore_reqoid.bv_val );
00098               break;
00099 
00100        default:
00101               Log3( LDAP_DEBUG_ANY, LDAP_LEVEL_INFO,
00102                      "%s trace op=%s dn=\"%s\"\n",
00103                      op->o_log_prefix, op_str,
00104                      BER_BVISNULL( &op->o_req_ndn ) ? "(null)" : op->o_req_ndn.bv_val );
00105               break;
00106        }
00107 
00108        return SLAP_CB_CONTINUE;
00109 }
00110 
00111 static int
00112 trace_response( Operation *op, SlapReply *rs )
00113 {
00114        char   *op_str = NULL;
00115 
00116        (void)trace_op2str( op, &op_str );
00117 
00118        switch ( op->o_tag ) {
00119        case LDAP_REQ_EXTENDED:
00120               Log5( LDAP_DEBUG_ANY, LDAP_LEVEL_INFO,
00121                      "%s trace op=EXTENDED RESPONSE dn=\"%s\" reqoid=%s rspoid=%s err=%d\n",
00122                      op->o_log_prefix,
00123                      BER_BVISNULL( &op->o_req_ndn ) ? "(null)" : op->o_req_ndn.bv_val,
00124                      BER_BVISNULL( &op->ore_reqoid ) ? "" : op->ore_reqoid.bv_val,
00125                      rs->sr_rspoid == NULL ? "" : rs->sr_rspoid,
00126                      rs->sr_err );
00127               break;
00128 
00129        case LDAP_REQ_SEARCH:
00130               switch ( rs->sr_type ) {
00131               case REP_SEARCH:
00132                      Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_INFO,
00133                             "%s trace op=SEARCH ENTRY dn=\"%s\"\n",
00134                             op->o_log_prefix,
00135                             rs->sr_entry->e_name.bv_val );
00136                      goto done;
00137 
00138               case REP_SEARCHREF:
00139                      Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_INFO,
00140                             "%s trace op=SEARCH REFERENCE ref=\"%s\"\n",
00141                             op->o_log_prefix,
00142                             rs->sr_ref[ 0 ].bv_val );
00143                      goto done;
00144 
00145               case REP_RESULT:
00146                      break;
00147 
00148               default:
00149                      assert( 0 );
00150               }
00151               /* fallthru */
00152 
00153        default:
00154               Log4( LDAP_DEBUG_ANY, LDAP_LEVEL_INFO,
00155                      "%s trace op=%s RESPONSE dn=\"%s\" err=%d\n",
00156                      op->o_log_prefix,
00157                      op_str,
00158                      BER_BVISNULL( &op->o_req_ndn ) ? "(null)" : op->o_req_ndn.bv_val,
00159                      rs->sr_err );
00160               break;
00161        }
00162 
00163 done:;
00164        return SLAP_CB_CONTINUE;
00165 }
00166 
00167 static int
00168 trace_db_init(
00169        BackendDB *be )
00170 {
00171        Log0( LDAP_DEBUG_ANY, LDAP_LEVEL_INFO,
00172               "trace DB_INIT\n" );
00173 
00174        return 0;
00175 }
00176 
00177 static int
00178 trace_db_config(
00179        BackendDB     *be,
00180        const char    *fname,
00181        int           lineno,
00182        int           argc,
00183        char          **argv )
00184 {
00185        Log2( LDAP_DEBUG_ANY, LDAP_LEVEL_INFO,
00186               "trace DB_CONFIG argc=%d argv[0]=\"%s\"\n",
00187               argc, argv[ 0 ] );
00188 
00189        return 0;
00190 }
00191 
00192 static int
00193 trace_db_open(
00194        BackendDB *be )
00195 {
00196        Log0( LDAP_DEBUG_ANY, LDAP_LEVEL_INFO,
00197               "trace DB_OPEN\n" );
00198 
00199        return 0;
00200 }
00201 
00202 static int
00203 trace_db_close(
00204        BackendDB *be )
00205 {
00206        Log0( LDAP_DEBUG_ANY, LDAP_LEVEL_INFO,
00207               "trace DB_CLOSE\n" );
00208 
00209        return 0;
00210 }
00211 
00212 static int
00213 trace_db_destroy(
00214        BackendDB *be )
00215 {
00216        Log0( LDAP_DEBUG_ANY, LDAP_LEVEL_INFO,
00217               "trace DB_DESTROY\n" );
00218 
00219        return 0;
00220 }
00221 
00222 static slap_overinst               trace;
00223 
00224 int
00225 trace_initialize()
00226 {
00227        trace.on_bi.bi_type = "trace";
00228 
00229        trace.on_bi.bi_db_init = trace_db_init;
00230        trace.on_bi.bi_db_open = trace_db_open;
00231        trace.on_bi.bi_db_config = trace_db_config;
00232        trace.on_bi.bi_db_close = trace_db_close;
00233        trace.on_bi.bi_db_destroy = trace_db_destroy;
00234 
00235        trace.on_bi.bi_op_add = trace_op_func;
00236        trace.on_bi.bi_op_bind = trace_op_func;
00237        trace.on_bi.bi_op_unbind = trace_op_func;
00238        trace.on_bi.bi_op_compare = trace_op_func;
00239        trace.on_bi.bi_op_delete = trace_op_func;
00240        trace.on_bi.bi_op_modify = trace_op_func;
00241        trace.on_bi.bi_op_modrdn = trace_op_func;
00242        trace.on_bi.bi_op_search = trace_op_func;
00243        trace.on_bi.bi_op_abandon = trace_op_func;
00244        trace.on_bi.bi_extended = trace_op_func;
00245 
00246        trace.on_response = trace_response;
00247 
00248        return overlay_register( &trace );
00249 }
00250 
00251 #if SLAPD_OVER_TRACE == SLAPD_MOD_DYNAMIC
00252 int
00253 init_module( int argc, char *argv[] )
00254 {
00255        return trace_initialize();
00256 }
00257 #endif /* SLAPD_OVER_TRACE == SLAPD_MOD_DYNAMIC */
00258 
00259 #endif /* defined(SLAPD_OVER_TRACE) */