trace.c 5.15 KB
Newer Older
1
2
3
4
/* trace.c - traces overlay invocation */
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
 *
Quanah Gibson-Mount's avatar
Quanah Gibson-Mount committed
5
 * Copyright 2006-2020 The OpenLDAP Foundation.
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted only as authorized by the OpenLDAP
 * Public License.
 *
 * A copy of this license is available in the file LICENSE in the
 * top-level directory of the distribution or, alternatively, at
 * <http://www.OpenLDAP.org/license.html>.
 */
/* ACKNOWLEDGEMENTS:
 * This work was initially developed by Pierangelo Masarati for inclusion in
 * OpenLDAP Software.
 */

#include "portable.h"

#ifdef SLAPD_OVER_TRACE

#include <stdio.h>

#include <ac/string.h>
#include <ac/socket.h>

#include "slap.h"
#include "lutil.h"

static int
Pierangelo Masarati's avatar
Pierangelo Masarati committed
34
trace_op2str( Operation *op, char **op_strp )
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
{
	switch ( op->o_tag ) {
	case LDAP_REQ_BIND:
		*op_strp = "BIND";
		break;

	case LDAP_REQ_UNBIND:
		*op_strp = "UNBIND";
		break;

	case LDAP_REQ_SEARCH:
		*op_strp = "SEARCH";
		break;

	case LDAP_REQ_MODIFY:
		*op_strp = "MODIFY";
		break;

	case LDAP_REQ_ADD:
		*op_strp = "ADD";
		break;

	case LDAP_REQ_DELETE:
		*op_strp = "DELETE";
		break;

	case LDAP_REQ_MODRDN:
		*op_strp = "MODRDN";
		break;

	case LDAP_REQ_COMPARE:
		*op_strp = "COMPARE";
		break;

	case LDAP_REQ_ABANDON:
		*op_strp = "ABANDON";
		break;

	case LDAP_REQ_EXTENDED:
		*op_strp = "EXTENDED";
		break;

	default:
		assert( 0 );
	}

	return 0;
}

static int
trace_op_func( Operation *op, SlapReply *rs )
{
	char	*op_str = NULL;

Pierangelo Masarati's avatar
Pierangelo Masarati committed
89
	(void)trace_op2str( op, &op_str );
90

Pierangelo Masarati's avatar
Pierangelo Masarati committed
91
92
	switch ( op->o_tag ) {
	case LDAP_REQ_EXTENDED:
93
		Log( LDAP_DEBUG_ANY, LDAP_LEVEL_INFO,
Pierangelo Masarati's avatar
Pierangelo Masarati committed
94
95
96
97
98
99
100
			"%s trace op=EXTENDED dn=\"%s\" reqoid=%s\n",
			op->o_log_prefix, 
			BER_BVISNULL( &op->o_req_ndn ) ? "(null)" : op->o_req_ndn.bv_val,
			BER_BVISNULL( &op->ore_reqoid ) ? "" : op->ore_reqoid.bv_val );
		break;

	default:
101
		Log( LDAP_DEBUG_ANY, LDAP_LEVEL_INFO,
Pierangelo Masarati's avatar
Pierangelo Masarati committed
102
103
104
105
106
			"%s trace op=%s dn=\"%s\"\n",
			op->o_log_prefix, op_str,
			BER_BVISNULL( &op->o_req_ndn ) ? "(null)" : op->o_req_ndn.bv_val );
		break;
	}
107
108
109
110
111
112
113
114
115

	return SLAP_CB_CONTINUE;
}

static int
trace_response( Operation *op, SlapReply *rs )
{
	char	*op_str = NULL;

Pierangelo Masarati's avatar
Pierangelo Masarati committed
116
	(void)trace_op2str( op, &op_str );
117

Pierangelo Masarati's avatar
Pierangelo Masarati committed
118
119
	switch ( op->o_tag ) {
	case LDAP_REQ_EXTENDED:
120
		Log( LDAP_DEBUG_ANY, LDAP_LEVEL_INFO,
Pierangelo Masarati's avatar
Pierangelo Masarati committed
121
122
123
124
125
126
127
128
129
130
131
			"%s trace op=EXTENDED RESPONSE dn=\"%s\" reqoid=%s rspoid=%s err=%d\n",
			op->o_log_prefix,
			BER_BVISNULL( &op->o_req_ndn ) ? "(null)" : op->o_req_ndn.bv_val,
			BER_BVISNULL( &op->ore_reqoid ) ? "" : op->ore_reqoid.bv_val,
			rs->sr_rspoid == NULL ? "" : rs->sr_rspoid,
			rs->sr_err );
		break;

	case LDAP_REQ_SEARCH:
		switch ( rs->sr_type ) {
		case REP_SEARCH:
132
			Log( LDAP_DEBUG_ANY, LDAP_LEVEL_INFO,
Pierangelo Masarati's avatar
Pierangelo Masarati committed
133
134
135
136
137
138
				"%s trace op=SEARCH ENTRY dn=\"%s\"\n",
				op->o_log_prefix,
				rs->sr_entry->e_name.bv_val );
			goto done;

		case REP_SEARCHREF:
139
			Log( LDAP_DEBUG_ANY, LDAP_LEVEL_INFO,
Pierangelo Masarati's avatar
Pierangelo Masarati committed
140
141
142
143
144
145
146
147
148
149
150
151
152
153
				"%s trace op=SEARCH REFERENCE ref=\"%s\"\n",
				op->o_log_prefix,
				rs->sr_ref[ 0 ].bv_val );
			goto done;

		case REP_RESULT:
			break;

		default:
			assert( 0 );
		}
		/* fallthru */

	default:
154
		Log( LDAP_DEBUG_ANY, LDAP_LEVEL_INFO,
Pierangelo Masarati's avatar
Pierangelo Masarati committed
155
156
157
158
159
160
161
			"%s trace op=%s RESPONSE dn=\"%s\" err=%d\n",
			op->o_log_prefix,
			op_str,
			BER_BVISNULL( &op->o_req_ndn ) ? "(null)" : op->o_req_ndn.bv_val,
			rs->sr_err );
		break;
	}
162

Pierangelo Masarati's avatar
Pierangelo Masarati committed
163
done:;
164
165
166
167
	return SLAP_CB_CONTINUE;
}

static int
168
trace_db_init( BackendDB *be, ConfigReply *cr )
169
{
170
	Log( LDAP_DEBUG_ANY, LDAP_LEVEL_INFO,
171
172
173
174
175
176
177
178
179
180
181
182
183
		"trace DB_INIT\n" );

	return 0;
}

static int
trace_db_config(
	BackendDB	*be,
	const char	*fname,
	int		lineno,
	int		argc,
	char		**argv )
{
184
	Log( LDAP_DEBUG_ANY, LDAP_LEVEL_INFO,
185
186
187
188
189
190
191
		"trace DB_CONFIG argc=%d argv[0]=\"%s\"\n",
		argc, argv[ 0 ] );

	return 0;
}

static int
192
trace_db_open( BackendDB *be, ConfigReply *cr )
193
{
194
	Log( LDAP_DEBUG_ANY, LDAP_LEVEL_INFO,
195
196
197
198
199
200
		"trace DB_OPEN\n" );

	return 0;
}

static int
201
trace_db_close( BackendDB *be, ConfigReply *cr )
202
{
203
	Log( LDAP_DEBUG_ANY, LDAP_LEVEL_INFO,
204
205
206
207
208
209
		"trace DB_CLOSE\n" );

	return 0;
}

static int
210
trace_db_destroy( BackendDB *be, ConfigReply *cr )
211
{
212
	Log( LDAP_DEBUG_ANY, LDAP_LEVEL_INFO,
213
214
215
216
217
218
219
220
221
222
223
224
		"trace DB_DESTROY\n" );

	return 0;
}

static slap_overinst 		trace;

int
trace_initialize()
{
	trace.on_bi.bi_type = "trace";

225
	trace.on_bi.bi_flags = SLAPO_BFLAG_SINGLE;
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
	trace.on_bi.bi_db_init = trace_db_init;
	trace.on_bi.bi_db_open = trace_db_open;
	trace.on_bi.bi_db_config = trace_db_config;
	trace.on_bi.bi_db_close = trace_db_close;
	trace.on_bi.bi_db_destroy = trace_db_destroy;

	trace.on_bi.bi_op_add = trace_op_func;
	trace.on_bi.bi_op_bind = trace_op_func;
	trace.on_bi.bi_op_unbind = trace_op_func;
	trace.on_bi.bi_op_compare = trace_op_func;
	trace.on_bi.bi_op_delete = trace_op_func;
	trace.on_bi.bi_op_modify = trace_op_func;
	trace.on_bi.bi_op_modrdn = trace_op_func;
	trace.on_bi.bi_op_search = trace_op_func;
	trace.on_bi.bi_op_abandon = trace_op_func;
	trace.on_bi.bi_extended = trace_op_func;

	trace.on_response = trace_response;

	return overlay_register( &trace );
}

#if SLAPD_OVER_TRACE == SLAPD_MOD_DYNAMIC
int
init_module( int argc, char *argv[] )
{
	return trace_initialize();
}
#endif /* SLAPD_OVER_TRACE == SLAPD_MOD_DYNAMIC */

#endif /* defined(SLAPD_OVER_TRACE) */