1 /* accesslog.c - log operations for audit/history purposes */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2005-2006 The OpenLDAP Foundation.
6 * Portions copyright 2004-2005 Symas Corporation.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in the file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
18 * This work was initially developed by Howard Chu for inclusion in
24 #ifdef SLAPD_OVER_ACCESSLOG
28 #include <ac/string.h>
36 #define LOG_OP_ADD 0x001
37 #define LOG_OP_DELETE 0x002
38 #define LOG_OP_MODIFY 0x004
39 #define LOG_OP_MODRDN 0x008
40 #define LOG_OP_COMPARE 0x010
41 #define LOG_OP_SEARCH 0x020
42 #define LOG_OP_BIND 0x040
43 #define LOG_OP_UNBIND 0x080
44 #define LOG_OP_ABANDON 0x100
45 #define LOG_OP_EXTENDED 0x200
46 #define LOG_OP_UNKNOWN 0x400
48 #define LOG_OP_WRITES (LOG_OP_ADD|LOG_OP_DELETE|LOG_OP_MODIFY|LOG_OP_MODRDN)
49 #define LOG_OP_READS (LOG_OP_COMPARE|LOG_OP_SEARCH)
50 #define LOG_OP_SESSION (LOG_OP_BIND|LOG_OP_UNBIND|LOG_OP_ABANDON)
51 #define LOG_OP_ALL (LOG_OP_READS|LOG_OP_WRITES|LOG_OP_SESSION| \
52 LOG_OP_EXTENDED|LOG_OP_UNKNOWN)
54 typedef struct log_attr {
55 struct log_attr *next;
56 AttributeDescription *attr;
59 typedef struct log_info {
67 log_attr *li_oldattrs;
69 ldap_pvt_thread_rmutex_t li_op_rmutex;
70 ldap_pvt_thread_mutex_t li_log_mutex;
73 static ConfigDriver log_cf_gen;
84 static ConfigTable log_cfats[] = {
85 { "logdb", "suffix", 2, 2, 0, ARG_DN|ARG_MAGIC|LOG_DB,
86 log_cf_gen, "( OLcfgOvAt:4.1 NAME 'olcAccessLogDB' "
87 "DESC 'Suffix of database for log content' "
88 "SUP distinguishedName SINGLE-VALUE )", NULL, NULL },
89 { "logops", "op|writes|reads|session|all", 2, 0, 0,
91 log_cf_gen, "( OLcfgOvAt:4.2 NAME 'olcAccessLogOps' "
92 "DESC 'Operation types to log' "
93 "EQUALITY caseIgnoreMatch "
94 "SYNTAX OMsDirectoryString )", NULL, NULL },
95 { "logpurge", "age> <interval", 3, 3, 0, ARG_MAGIC|LOG_PURGE,
96 log_cf_gen, "( OLcfgOvAt:4.3 NAME 'olcAccessLogPurge' "
97 "DESC 'Log cleanup parameters' "
98 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
99 { "logsuccess", NULL, 2, 2, 0, ARG_MAGIC|ARG_ON_OFF|LOG_SUCCESS,
100 log_cf_gen, "( OLcfgOvAt:4.4 NAME 'olcAccessLogSuccess' "
101 "DESC 'Log successful ops only' "
102 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
103 { "logold", "filter", 2, 2, 0, ARG_MAGIC|LOG_OLD,
104 log_cf_gen, "( OLcfgOvAt:4.5 NAME 'olcAccessLogOld' "
105 "DESC 'Log old values when modifying entries matching the filter' "
106 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
107 { "logoldattr", "attrs", 2, 0, 0, ARG_MAGIC|LOG_OLDATTR,
108 log_cf_gen, "( OLcfgOvAt:4.6 NAME 'olcAccessLogOldAttr' "
109 "DESC 'Log old values of these attributes even if unmodified' "
110 "SYNTAX OMsDirectoryString )", NULL, NULL },
114 static ConfigOCs log_cfocs[] = {
116 "NAME 'olcAccessLogConfig' "
117 "DESC 'Access log configuration' "
118 "SUP olcOverlayConfig "
119 "MUST olcAccessLogDB "
120 "MAY ( olcAccessLogOps $ olcAccessLogPurge $ olcAccessLogSuccess $ "
121 "olcAccessLogOld $ olcAccessLogOldAttr ) )",
122 Cft_Overlay, log_cfats },
126 static slap_verbmasks logops[] = {
127 { BER_BVC("all"), LOG_OP_ALL },
128 { BER_BVC("writes"), LOG_OP_WRITES },
129 { BER_BVC("session"), LOG_OP_SESSION },
130 { BER_BVC("reads"), LOG_OP_READS },
131 { BER_BVC("add"), LOG_OP_ADD },
132 { BER_BVC("delete"), LOG_OP_DELETE },
133 { BER_BVC("modify"), LOG_OP_MODIFY },
134 { BER_BVC("modrdn"), LOG_OP_MODRDN },
135 { BER_BVC("compare"), LOG_OP_COMPARE },
136 { BER_BVC("search"), LOG_OP_SEARCH },
137 { BER_BVC("bind"), LOG_OP_BIND },
138 { BER_BVC("unbind"), LOG_OP_UNBIND },
139 { BER_BVC("abandon"), LOG_OP_ABANDON },
140 { BER_BVC("extended"), LOG_OP_EXTENDED },
141 { BER_BVC("unknown"), LOG_OP_UNKNOWN },
145 /* Start with "add" in logops */
163 static ObjectClass *log_ocs[LOG_EN__COUNT], *log_container;
165 #define LOG_SCHEMA_ROOT "1.3.6.1.4.1.4203.666.11.5"
167 #define LOG_SCHEMA_AT LOG_SCHEMA_ROOT ".1"
168 #define LOG_SCHEMA_OC LOG_SCHEMA_ROOT ".2"
170 static AttributeDescription *ad_reqDN, *ad_reqStart, *ad_reqEnd, *ad_reqType,
171 *ad_reqSession, *ad_reqResult, *ad_reqAuthzID, *ad_reqControls,
172 *ad_reqRespControls, *ad_reqMethod, *ad_reqAssertion, *ad_reqNewRDN,
173 *ad_reqNewSuperior, *ad_reqDeleteOldRDN, *ad_reqMod,
174 *ad_reqScope, *ad_reqFilter, *ad_reqAttr, *ad_reqEntries,
175 *ad_reqSizeLimit, *ad_reqTimeLimit, *ad_reqAttrsOnly, *ad_reqData,
176 *ad_reqId, *ad_reqMessage, *ad_reqVersion, *ad_reqDerefAliases,
177 *ad_reqReferral, *ad_reqOld;
181 AttributeDescription **ad;
183 { "( " LOG_SCHEMA_AT ".1 NAME 'reqDN' "
184 "DESC 'Target DN of request' "
185 "EQUALITY distinguishedNameMatch "
187 "SINGLE-VALUE )", &ad_reqDN },
188 { "( " LOG_SCHEMA_AT ".2 NAME 'reqStart' "
189 "DESC 'Start time of request' "
190 "EQUALITY generalizedTimeMatch "
191 "ORDERING generalizedTimeOrderingMatch "
192 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 "
193 "SINGLE-VALUE )", &ad_reqStart },
194 { "( " LOG_SCHEMA_AT ".3 NAME 'reqEnd' "
195 "DESC 'End time of request' "
196 "EQUALITY generalizedTimeMatch "
197 "ORDERING generalizedTimeOrderingMatch "
198 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 "
199 "SINGLE-VALUE )", &ad_reqEnd },
200 { "( " LOG_SCHEMA_AT ".4 NAME 'reqType' "
201 "DESC 'Type of request' "
202 "EQUALITY caseIgnoreMatch "
203 "SYNTAX OMsDirectoryString "
204 "SINGLE-VALUE )", &ad_reqType },
205 { "( " LOG_SCHEMA_AT ".5 NAME 'reqSession' "
206 "DESC 'Session ID of request' "
207 "EQUALITY caseIgnoreMatch "
208 "SYNTAX OMsDirectoryString "
209 "SINGLE-VALUE )", &ad_reqSession },
210 { "( " LOG_SCHEMA_AT ".6 NAME 'reqAuthzID' "
211 "DESC 'Authorization ID of requestor' "
212 "EQUALITY distinguishedNameMatch "
214 "SINGLE-VALUE )", &ad_reqAuthzID },
215 { "( " LOG_SCHEMA_AT ".7 NAME 'reqResult' "
216 "DESC 'Result code of request' "
217 "EQUALITY integerMatch "
218 "ORDERING integerOrderingMatch "
220 "SINGLE-VALUE )", &ad_reqResult },
221 { "( " LOG_SCHEMA_AT ".8 NAME 'reqMessage' "
222 "DESC 'Error text of request' "
223 "EQUALITY caseIgnoreMatch "
224 "SUBSTR caseIgnoreSubstringsMatch "
225 "SYNTAX OMsDirectoryString "
226 "SINGLE-VALUE )", &ad_reqMessage },
227 { "( " LOG_SCHEMA_AT ".9 NAME 'reqReferral' "
228 "DESC 'Referrals returned for request' "
229 "SUP labeledURI )", &ad_reqReferral },
230 { "( " LOG_SCHEMA_AT ".10 NAME 'reqControls' "
231 "DESC 'Request controls' "
232 "SYNTAX OMsOctetString )", &ad_reqControls },
233 { "( " LOG_SCHEMA_AT ".11 NAME 'reqRespControls' "
234 "DESC 'Response controls of request' "
235 "SYNTAX OMsOctetString )", &ad_reqRespControls },
236 { "( " LOG_SCHEMA_AT ".12 NAME 'reqId' "
237 "DESC 'ID of Request to Abandon' "
238 "EQUALITY integerMatch "
239 "ORDERING integerOrderingMatch "
241 "SINGLE-VALUE )", &ad_reqId },
242 { "( " LOG_SCHEMA_AT ".13 NAME 'reqVersion' "
243 "DESC 'Protocol version of Bind request' "
244 "EQUALITY integerMatch "
245 "ORDERING integerOrderingMatch "
247 "SINGLE-VALUE )", &ad_reqVersion },
248 { "( " LOG_SCHEMA_AT ".14 NAME 'reqMethod' "
249 "DESC 'Bind method of request' "
250 "EQUALITY caseIgnoreMatch "
251 "SYNTAX OMsDirectoryString "
252 "SINGLE-VALUE )", &ad_reqMethod },
253 { "( " LOG_SCHEMA_AT ".15 NAME 'reqAssertion' "
254 "DESC 'Compare Assertion of request' "
255 "SYNTAX OMsDirectoryString "
256 "SINGLE-VALUE )", &ad_reqAssertion },
257 { "( " LOG_SCHEMA_AT ".16 NAME 'reqMod' "
258 "DESC 'Modifications of request' "
259 "EQUALITY octetStringMatch "
260 "SUBSTR octetStringSubstringsMatch "
261 "SYNTAX OMsOctetString )", &ad_reqMod },
262 { "( " LOG_SCHEMA_AT ".17 NAME 'reqOld' "
263 "DESC 'Old values of entry before request completed' "
264 "EQUALITY octetStringMatch "
265 "SUBSTR octetStringSubstringsMatch "
266 "SYNTAX OMsOctetString )", &ad_reqOld },
267 { "( " LOG_SCHEMA_AT ".18 NAME 'reqNewRDN' "
268 "DESC 'New RDN of request' "
269 "EQUALITY distinguishedNameMatch "
271 "SINGLE-VALUE )", &ad_reqNewRDN },
272 { "( " LOG_SCHEMA_AT ".19 NAME 'reqDeleteOldRDN' "
273 "DESC 'Delete old RDN' "
274 "EQUALITY booleanMatch "
276 "SINGLE-VALUE )", &ad_reqDeleteOldRDN },
277 { "( " LOG_SCHEMA_AT ".20 NAME 'reqNewSuperior' "
278 "DESC 'New superior DN of request' "
279 "EQUALITY distinguishedNameMatch "
281 "SINGLE-VALUE )", &ad_reqNewSuperior },
282 { "( " LOG_SCHEMA_AT ".21 NAME 'reqScope' "
283 "DESC 'Scope of request' "
284 "EQUALITY caseIgnoreMatch "
285 "SYNTAX OMsDirectoryString "
286 "SINGLE-VALUE )", &ad_reqScope },
287 { "( " LOG_SCHEMA_AT ".22 NAME 'reqDerefAliases' "
288 "DESC 'Disposition of Aliases in request' "
289 "EQUALITY caseIgnoreMatch "
290 "SYNTAX OMsDirectoryString "
291 "SINGLE-VALUE )", &ad_reqDerefAliases },
292 { "( " LOG_SCHEMA_AT ".23 NAME 'reqAttrsOnly' "
293 "DESC 'Attributes and values of request' "
294 "EQUALITY booleanMatch "
296 "SINGLE-VALUE )", &ad_reqAttrsOnly },
297 { "( " LOG_SCHEMA_AT ".24 NAME 'reqFilter' "
298 "DESC 'Filter of request' "
299 "EQUALITY caseIgnoreMatch "
300 "SUBSTR caseIgnoreSubstringsMatch "
301 "SYNTAX OMsDirectoryString "
302 "SINGLE-VALUE )", &ad_reqFilter },
303 { "( " LOG_SCHEMA_AT ".25 NAME 'reqAttr' "
304 "DESC 'Attributes of request' "
305 "EQUALITY caseIgnoreMatch "
306 "SYNTAX OMsDirectoryString )", &ad_reqAttr },
307 { "( " LOG_SCHEMA_AT ".26 NAME 'reqSizeLimit' "
308 "DESC 'Size limit of request' "
309 "EQUALITY integerMatch "
310 "ORDERING integerOrderingMatch "
312 "SINGLE-VALUE )", &ad_reqSizeLimit },
313 { "( " LOG_SCHEMA_AT ".27 NAME 'reqTimeLimit' "
314 "DESC 'Time limit of request' "
315 "EQUALITY integerMatch "
316 "ORDERING integerOrderingMatch "
318 "SINGLE-VALUE )", &ad_reqTimeLimit },
319 { "( " LOG_SCHEMA_AT ".28 NAME 'reqEntries' "
320 "DESC 'Number of entries returned' "
321 "EQUALITY integerMatch "
322 "ORDERING integerOrderingMatch "
324 "SINGLE-VALUE )", &ad_reqEntries },
325 { "( " LOG_SCHEMA_AT ".29 NAME 'reqData' "
326 "DESC 'Data of extended request' "
327 "EQUALITY octetStringMatch "
328 "SUBSTR octetStringSubstringsMatch "
329 "SYNTAX OMsOctetString "
330 "SINGLE-VALUE )", &ad_reqData },
338 { "( " LOG_SCHEMA_OC ".0 NAME 'auditContainer' "
339 "DESC 'AuditLog container' "
340 "SUP top STRUCTURAL "
341 "MAY ( cn $ reqStart $ reqEnd ) )", &log_container },
342 { "( " LOG_SCHEMA_OC ".1 NAME 'auditObject' "
343 "DESC 'OpenLDAP request auditing' "
344 "SUP top STRUCTURAL "
345 "MUST ( reqStart $ reqType $ reqSession ) "
346 "MAY ( reqDN $ reqAuthzID $ reqControls $ reqRespControls $ reqEnd $ "
347 "reqResult $ reqMessage $ reqReferral ) )",
348 &log_ocs[LOG_EN_UNBIND] },
349 { "( " LOG_SCHEMA_OC ".2 NAME 'auditReadObject' "
350 "DESC 'OpenLDAP read request record' "
351 "SUP auditObject STRUCTURAL )", NULL },
352 { "( " LOG_SCHEMA_OC ".3 NAME 'auditWriteObject' "
353 "DESC 'OpenLDAP write request record' "
354 "SUP auditObject STRUCTURAL )", NULL },
355 { "( " LOG_SCHEMA_OC ".4 NAME 'auditAbandon' "
356 "DESC 'Abandon operation' "
357 "SUP auditObject STRUCTURAL "
358 "MUST reqId )", &log_ocs[LOG_EN_ABANDON] },
359 { "( " LOG_SCHEMA_OC ".5 NAME 'auditAdd' "
360 "DESC 'Add operation' "
361 "SUP auditWriteObject STRUCTURAL "
362 "MUST reqMod )", &log_ocs[LOG_EN_ADD] },
363 { "( " LOG_SCHEMA_OC ".6 NAME 'auditBind' "
364 "DESC 'Bind operation' "
365 "SUP auditObject STRUCTURAL "
366 "MUST ( reqVersion $ reqMethod ) )", &log_ocs[LOG_EN_BIND] },
367 { "( " LOG_SCHEMA_OC ".7 NAME 'auditCompare' "
368 "DESC 'Compare operation' "
369 "SUP auditReadObject STRUCTURAL "
370 "MUST reqAssertion )", &log_ocs[LOG_EN_COMPARE] },
371 { "( " LOG_SCHEMA_OC ".8 NAME 'auditDelete' "
372 "DESC 'Delete operation' "
373 "SUP auditWriteObject STRUCTURAL "
374 "MAY reqOld )", &log_ocs[LOG_EN_DELETE] },
375 { "( " LOG_SCHEMA_OC ".9 NAME 'auditModify' "
376 "DESC 'Modify operation' "
377 "SUP auditWriteObject STRUCTURAL "
378 "MAY reqOld MUST reqMod )", &log_ocs[LOG_EN_MODIFY] },
379 { "( " LOG_SCHEMA_OC ".10 NAME 'auditModRDN' "
380 "DESC 'ModRDN operation' "
381 "SUP auditWriteObject STRUCTURAL "
382 "MUST ( reqNewRDN $ reqDeleteOldRDN ) "
383 "MAY ( reqNewSuperior $ reqOld ) )", &log_ocs[LOG_EN_MODRDN] },
384 { "( " LOG_SCHEMA_OC ".11 NAME 'auditSearch' "
385 "DESC 'Search operation' "
386 "SUP auditReadObject STRUCTURAL "
387 "MUST ( reqScope $ reqDerefAliases $ reqAttrsonly ) "
388 "MAY ( reqFilter $ reqAttr $ reqEntries $ reqSizeLimit $ "
389 "reqTimeLimit ) )", &log_ocs[LOG_EN_SEARCH] },
390 { "( " LOG_SCHEMA_OC ".12 NAME 'auditExtended' "
391 "DESC 'Extended operation' "
392 "SUP auditObject STRUCTURAL "
393 "MAY reqData )", &log_ocs[LOG_EN_EXTENDED] },
397 #define RDNEQ "reqStart="
399 /* Our time intervals are of the form [ddd+]hh:mm[:ss]
400 * If a field is present, it must be two digits. (Except for
401 * days, which can be arbitrary width.)
404 log_age_parse(char *agestr)
410 t1 = strtol( agestr, &endptr, 10 );
411 /* Is there a days delimiter? */
412 if ( *endptr == '+' ) {
413 /* 32 bit time only covers about 68 years */
414 if ( t1 < 0 || t1 > 25000 )
420 if ( agestr[2] != ':' ) {
421 /* No valid delimiter found, fail */
432 /* if there's a delimiter, it can only be a colon */
433 if ( agestr[2] != ':' )
436 /* If we're at the end of the string, and we started with days,
437 * fail because we expected to find minutes too.
439 return gotdays ? -1 : t1 * 60;
445 /* last field can only be seconds */
446 if ( agestr[2] && ( agestr[2] != ':' || !gotdays ))
456 t1 += atoi( agestr );
457 } else if ( gotdays ) {
458 /* only got days+hh:mm */
465 log_age_unparse( int age, struct berval *agebv )
481 ptr += sprintf( ptr, "%d+", dd );
482 ptr += sprintf( ptr, "%02d:%02d", hh, mm );
484 ptr += sprintf( ptr, ":%02d", ss );
486 agebv->bv_len = ptr - agebv->bv_val;
489 static slap_callback nullsc = { NULL, NULL, NULL, NULL };
491 #define PURGE_INCREMENT 100
493 typedef struct purge_data {
501 log_old_lookup( Operation *op, SlapReply *rs )
503 purge_data *pd = op->o_callback->sc_private;
505 if ( rs->sr_type != REP_SEARCH) return 0;
507 if ( pd->used >= pd->slots ) {
508 pd->slots += PURGE_INCREMENT;
509 pd->dn = ch_realloc( pd->dn, pd->slots * sizeof( struct berval ));
510 pd->ndn = ch_realloc( pd->ndn, pd->slots * sizeof( struct berval ));
512 ber_dupbv( &pd->dn[pd->used], &rs->sr_entry->e_name );
513 ber_dupbv( &pd->ndn[pd->used], &rs->sr_entry->e_nname );
518 /* Periodically search for old entries in the log database and delete them */
520 accesslog_purge( void *ctx, void *arg )
522 struct re_s *rtask = arg;
523 struct log_info *li = rtask->arg;
525 Connection conn = {0};
526 OperationBuffer opbuf;
527 Operation *op = (Operation *) &opbuf;
528 SlapReply rs = {REP_RESULT};
529 slap_callback cb = { NULL, log_old_lookup, NULL, NULL };
531 AttributeAssertion ava = {0};
533 char timebuf[LDAP_LUTIL_GENTIME_BUFSIZE];
534 time_t old = slap_get_time();
536 connection_fake_init( &conn, op, ctx );
538 f.f_choice = LDAP_FILTER_LE;
542 ava.aa_desc = ad_reqStart;
543 ava.aa_value.bv_val = timebuf;
544 ava.aa_value.bv_len = sizeof(timebuf);
547 slap_timestamp( &old, &ava.aa_value );
549 op->o_tag = LDAP_REQ_SEARCH;
550 op->o_bd = li->li_db;
551 op->o_dn = li->li_db->be_rootdn;
552 op->o_ndn = li->li_db->be_rootndn;
553 op->o_req_dn = li->li_db->be_suffix[0];
554 op->o_req_ndn = li->li_db->be_nsuffix[0];
555 op->o_callback = &cb;
556 op->ors_scope = LDAP_SCOPE_ONELEVEL;
557 op->ors_deref = LDAP_DEREF_NEVER;
558 op->ors_tlimit = SLAP_NO_LIMIT;
559 op->ors_slimit = SLAP_NO_LIMIT;
561 filter2bv_x( op, &f, &op->ors_filterstr );
562 op->ors_attrs = slap_anlist_no_attrs;
563 op->ors_attrsonly = 1;
567 op->o_bd->be_search( op, &rs );
568 op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
573 op->o_tag = LDAP_REQ_DELETE;
574 op->o_callback = &nullsc;
576 for (i=0; i<pd.used; i++) {
577 op->o_req_dn = pd.dn[i];
578 op->o_req_ndn = pd.ndn[i];
579 if ( !slapd_shutdown )
580 op->o_bd->be_delete( op, &rs );
581 ch_free( pd.ndn[i].bv_val );
582 ch_free( pd.dn[i].bv_val );
588 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
589 ldap_pvt_runqueue_stoptask( &slapd_rq, rtask );
590 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
596 log_cf_gen(ConfigArgs *c)
598 slap_overinst *on = (slap_overinst *)c->bi;
599 struct log_info *li = on->on_bi.bi_private;
601 slap_mask_t tmask = 0;
602 char agebuf[2*STRLENOF("ddddd+hh:mm:ss ")];
603 struct berval agebv, cyclebv;
606 case SLAP_CONFIG_EMIT:
609 if ( li->li_db == NULL ) {
610 snprintf( c->msg, sizeof( c->msg ),
611 "accesslog: \"logdb <suffix>\" must be specified" );
612 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
613 c->log, c->msg, c->value_dn.bv_val );
617 value_add( &c->rvalue_vals, li->li_db->be_suffix );
618 value_add( &c->rvalue_nvals, li->li_db->be_nsuffix );
621 rc = mask_to_verbs( logops, li->li_ops, &c->rvalue_vals );
628 agebv.bv_val = agebuf;
629 log_age_unparse( li->li_age, &agebv );
630 agebv.bv_val[agebv.bv_len] = ' ';
632 cyclebv.bv_val = agebv.bv_val + agebv.bv_len;
633 log_age_unparse( li->li_cycle, &cyclebv );
634 agebv.bv_len += cyclebv.bv_len;
635 value_add_one( &c->rvalue_vals, &agebv );
638 if ( li->li_success )
639 c->value_int = li->li_success;
645 filter2bv( li->li_oldf, &agebv );
646 value_add_one( &c->rvalue_vals, &agebv );
652 if ( li->li_oldattrs ) {
655 for ( la = li->li_oldattrs; la; la=la->next )
656 value_add_one( &c->rvalue_vals, &la->attr->ad_cname );
663 case LDAP_MOD_DELETE:
666 /* noop. this should always be a valid backend. */
672 rc = verbs_to_mask( 1, &c->line, logops, &tmask );
674 li->li_ops &= ~tmask;
679 struct re_s *re = li->li_task;
681 if ( ldap_pvt_runqueue_isrunning( &slapd_rq, re ))
682 ldap_pvt_runqueue_stoptask( &slapd_rq, re );
683 ldap_pvt_runqueue_remove( &slapd_rq, re );
693 filter_free( li->li_oldf );
701 for ( la = li->li_oldattrs; la; la = ln ) {
706 log_attr *la = NULL, **lp;
709 for ( lp = &li->li_oldattrs, i=0; i < c->valx; i++ ) {
722 li->li_db = select_backend( &c->value_ndn, 0, 0 );
724 snprintf( c->msg, sizeof( c->msg ),
725 "<%s> no matching backend found for suffix",
727 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
728 c->log, c->msg, c->value_dn.bv_val );
730 } else if ( BER_BVISEMPTY( &li->li_db->be_rootdn )) {
731 snprintf( c->msg, sizeof( c->msg ),
732 "<%s> no rootDN was configured for suffix",
734 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
735 c->log, c->msg, c->value_dn.bv_val );
738 ch_free( c->value_dn.bv_val );
739 ch_free( c->value_ndn.bv_val );
742 rc = verbs_to_mask( c->argc, c->argv, logops, &tmask );
747 li->li_age = log_age_parse( c->argv[1] );
748 if ( li->li_age < 1 ) {
751 li->li_cycle = log_age_parse( c->argv[2] );
752 if ( li->li_cycle < 1 ) {
754 } else if ( slapMode & SLAP_SERVER_MODE ) {
755 struct re_s *re = li->li_task;
757 re->interval.tv_sec = li->li_cycle;
759 li->li_task = ldap_pvt_runqueue_insert( &slapd_rq,
760 li->li_cycle, accesslog_purge, li,
761 "accesslog_purge", li->li_db ?
762 li->li_db->be_suffix[0].bv_val :
763 c->be->be_suffix[0].bv_val );
768 li->li_success = c->value_int;
771 li->li_oldf = str2filter( c->argv[1] );
772 if ( !li->li_oldf ) {
773 sprintf( c->msg, "bad filter!" );
779 AttributeDescription *ad;
782 for ( i=1; i< c->argc; i++ ) {
784 if ( slap_str2ad( c->argv[i], &ad, &text ) == LDAP_SUCCESS ) {
785 log_attr *la = ch_malloc( sizeof( log_attr ));
787 la->next = li->li_oldattrs;
788 li->li_oldattrs = la;
790 sprintf( c->msg, "%s: %s", c->argv[i], text );
803 static Entry *accesslog_entry( Operation *op, int logop,
805 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
806 log_info *li = on->on_bi.bi_private;
808 char rdnbuf[STRLENOF(RDNEQ)+LDAP_LUTIL_GENTIME_BUFSIZE+8];
809 char nrdnbuf[STRLENOF(RDNEQ)+LDAP_LUTIL_GENTIME_BUFSIZE+8];
811 struct berval rdn, nrdn, timestamp, ntimestamp, bv;
812 slap_verbmasks *lo = logops+logop+EN_OFFSET;
814 Entry *e = ch_calloc( 1, sizeof(Entry) );
816 strcpy( rdnbuf, RDNEQ );
818 strcpy( nrdnbuf, RDNEQ );
819 nrdn.bv_val = nrdnbuf;
821 timestamp.bv_val = rdnbuf+STRLENOF(RDNEQ);
822 timestamp.bv_len = sizeof(rdnbuf) - STRLENOF(RDNEQ);
823 slap_timestamp( &op->o_time, ×tamp );
824 sprintf( timestamp.bv_val + timestamp.bv_len-1, ".%06dZ", op->o_tincr );
825 timestamp.bv_len += 7;
827 rdn.bv_len = STRLENOF(RDNEQ)+timestamp.bv_len;
828 ad_reqStart->ad_type->sat_equality->smr_normalize(
829 SLAP_MR_VALUE_OF_ASSERTION_SYNTAX, ad_reqStart->ad_type->sat_syntax,
830 ad_reqStart->ad_type->sat_equality, ×tamp, &ntimestamp,
833 strcpy( nrdn.bv_val + STRLENOF(RDNEQ), ntimestamp.bv_val );
834 nrdn.bv_len = STRLENOF(RDNEQ)+ntimestamp.bv_len;
835 build_new_dn( &e->e_name, li->li_db->be_suffix, &rdn, NULL );
836 build_new_dn( &e->e_nname, li->li_db->be_nsuffix, &nrdn, NULL );
838 attr_merge_one( e, slap_schema.si_ad_objectClass,
839 &log_ocs[logop]->soc_cname, NULL );
840 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass,
841 &log_ocs[logop]->soc_cname, NULL );
842 attr_merge_one( e, ad_reqStart, ×tamp, &ntimestamp );
843 op->o_tmpfree( ntimestamp.bv_val, op->o_tmpmemctx );
845 slap_op_time( &op2->o_time, &op2->o_tincr );
847 timestamp.bv_len = sizeof(rdnbuf) - STRLENOF(RDNEQ);
848 slap_timestamp( &op2->o_time, ×tamp );
849 sprintf( timestamp.bv_val + timestamp.bv_len-1, ".%06dZ", op2->o_tincr );
850 timestamp.bv_len += 7;
852 attr_merge_normalize_one( e, ad_reqEnd, ×tamp, op->o_tmpmemctx );
854 /* Exops have OID appended */
855 if ( logop == LOG_EN_EXTENDED ) {
856 bv.bv_len = lo->word.bv_len + op->ore_reqoid.bv_len + 2;
857 bv.bv_val = ch_malloc( bv.bv_len + 1 );
858 AC_MEMCPY( bv.bv_val, lo->word.bv_val, lo->word.bv_len );
859 bv.bv_val[lo->word.bv_len] = '{';
860 AC_MEMCPY( bv.bv_val+lo->word.bv_len+1, op->ore_reqoid.bv_val,
861 op->ore_reqoid.bv_len );
862 bv.bv_val[bv.bv_len-1] = '}';
863 bv.bv_val[bv.bv_len] = '\0';
864 attr_merge_one( e, ad_reqType, &bv, NULL );
866 attr_merge_one( e, ad_reqType, &lo->word, NULL );
869 rdn.bv_len = sprintf( rdn.bv_val, "%lu", op->o_connid );
870 attr_merge_one( e, ad_reqSession, &rdn, NULL );
872 if ( BER_BVISNULL( &op->o_dn ))
873 attr_merge_one( e, ad_reqAuthzID, (struct berval *)&slap_empty_bv,
874 (struct berval *)&slap_empty_bv );
876 attr_merge_one( e, ad_reqAuthzID, &op->o_dn, &op->o_ndn );
878 /* FIXME: need to add reqControls and reqRespControls */
883 static struct berval scopes[] = {
890 static struct berval derefs[] = {
892 BER_BVC("searching"),
897 static struct berval simple = BER_BVC("SIMPLE");
899 static void accesslog_val2val(AttributeDescription *ad, struct berval *val,
900 char c_op, struct berval *dst) {
903 dst->bv_len = ad->ad_cname.bv_len + val->bv_len + 2;
904 if ( c_op ) dst->bv_len++;
906 dst->bv_val = ch_malloc( dst->bv_len+1 );
908 ptr = lutil_strcopy( dst->bv_val, ad->ad_cname.bv_val );
913 AC_MEMCPY( ptr, val->bv_val, val->bv_len );
914 dst->bv_val[dst->bv_len] = '\0';
917 static int accesslog_response(Operation *op, SlapReply *rs) {
918 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
919 log_info *li = on->on_bi.bi_private;
920 Attribute *a, *last_attr;
926 Entry *e = NULL, *old = NULL;
927 char timebuf[LDAP_LUTIL_GENTIME_BUFSIZE+8];
932 SlapReply rs2 = {REP_RESULT};
934 if ( rs->sr_type != REP_RESULT && rs->sr_type != REP_EXTENDED )
935 return SLAP_CB_CONTINUE;
937 switch ( op->o_tag ) {
938 case LDAP_REQ_ADD: logop = LOG_EN_ADD; break;
939 case LDAP_REQ_DELETE: logop = LOG_EN_DELETE; break;
940 case LDAP_REQ_MODIFY: logop = LOG_EN_MODIFY; break;
941 case LDAP_REQ_MODRDN: logop = LOG_EN_MODRDN; break;
942 case LDAP_REQ_COMPARE: logop = LOG_EN_COMPARE; break;
943 case LDAP_REQ_SEARCH: logop = LOG_EN_SEARCH; break;
944 case LDAP_REQ_BIND: logop = LOG_EN_BIND; break;
945 case LDAP_REQ_EXTENDED: logop = LOG_EN_EXTENDED; break;
946 default: /* unknown operation type */
947 logop = LOG_EN_UNKNOWN; break;
948 } /* Unbind and Abandon never reach here */
950 lo = logops+logop+EN_OFFSET;
951 if ( !( li->li_ops & lo->mask ))
952 return SLAP_CB_CONTINUE;
954 if ( lo->mask & LOG_OP_WRITES ) {
955 ldap_pvt_thread_mutex_lock( &li->li_log_mutex );
958 ldap_pvt_thread_rmutex_unlock( &li->li_op_rmutex, op->o_tid );
961 if ( li->li_success && rs->sr_err != LDAP_SUCCESS )
964 e = accesslog_entry( op, logop, &op2 );
966 attr_merge_one( e, ad_reqDN, &op->o_req_dn, &op->o_req_ndn );
969 ber_str2bv( rs->sr_text, 0, 0, &bv );
970 attr_merge_one( e, ad_reqMessage, &bv, NULL );
972 bv.bv_len = sprintf( timebuf, "%d", rs->sr_err );
975 attr_merge_one( e, ad_reqResult, &bv, NULL );
977 last_attr = attr_find( e->e_attrs, ad_reqResult );
981 case LOG_EN_DELETE: {
985 if ( logop == LOG_EN_ADD ) {
994 /* count all the vals */
996 for ( a=e2->e_attrs; a; a=a->a_next ) {
998 for (b=a->a_vals; !BER_BVISNULL( b ); b++) {
1003 vals = ch_malloc( (i+1) * sizeof( struct berval ));
1005 for ( a=e2->e_attrs; a; a=a->a_next ) {
1007 for (b=a->a_vals; !BER_BVISNULL( b ); b++,i++) {
1008 accesslog_val2val( a->a_desc, b, c_op, &vals[i] );
1012 vals[i].bv_val = NULL;
1014 a = attr_alloc( logop == LOG_EN_ADD ? ad_reqMod : ad_reqOld );
1017 last_attr->a_next = a;
1022 /* count all the mods */
1024 for ( m=op->orm_modlist; m; m=m->sml_next ) {
1025 if ( m->sml_values ) {
1026 for (b=m->sml_values; !BER_BVISNULL( b ); b++) {
1029 } else if ( m->sml_op == LDAP_MOD_DELETE ) {
1033 vals = ch_malloc( (i+1) * sizeof( struct berval ));
1036 /* init flags on old entry */
1038 for ( a=old->e_attrs; a; a=a->a_next ) {
1042 /* look for attrs that are always logged */
1043 for ( la=li->li_oldattrs; la; la=la->next )
1044 if ( a->a_desc == la->attr )
1049 for ( m=op->orm_modlist; m; m=m->sml_next ) {
1050 /* Mark this attribute as modified */
1052 a = attr_find( old->e_attrs, m->sml_desc );
1056 if ( m->sml_values ) {
1057 for (b=m->sml_values; !BER_BVISNULL( b ); b++,i++) {
1060 switch( m->sml_op ) {
1061 case LDAP_MOD_ADD: c_op = '+'; break;
1062 case LDAP_MOD_DELETE: c_op = '-'; break;
1063 case LDAP_MOD_REPLACE: c_op = '='; break;
1064 case LDAP_MOD_INCREMENT: c_op = '#'; break;
1066 /* unknown op. there shouldn't be any of these. we
1067 * don't know what to do with it, but we shouldn't just
1070 default: c_op = '?'; break;
1072 accesslog_val2val( m->sml_desc, b, c_op, &vals[i] );
1074 } else if ( m->sml_op == LDAP_MOD_DELETE ) {
1075 vals[i].bv_len = m->sml_desc->ad_cname.bv_len + 2;
1076 vals[i].bv_val = ch_malloc( vals[i].bv_len+1 );
1077 ptr = lutil_strcopy( vals[i].bv_val,
1078 m->sml_desc->ad_cname.bv_val );
1085 vals[i].bv_val = NULL;
1087 a = attr_alloc( ad_reqMod );
1090 last_attr->a_next = a;
1094 /* count all the vals */
1096 for ( a=old->e_attrs; a; a=a->a_next ) {
1097 if ( a->a_vals && a->a_flags ) {
1098 for (b=a->a_vals; !BER_BVISNULL( b ); b++) {
1103 vals = ch_malloc( (i+1) * sizeof( struct berval ));
1105 for ( a=old->e_attrs; a; a=a->a_next ) {
1106 if ( a->a_vals && a->a_flags ) {
1107 for (b=a->a_vals; !BER_BVISNULL( b ); b++,i++) {
1108 accesslog_val2val( a->a_desc, b, 0, &vals[i] );
1112 vals[i].bv_val = NULL;
1114 a = attr_alloc( ad_reqOld );
1117 last_attr->a_next = a;
1123 /* count all the vals */
1125 for ( a=old->e_attrs; a; a=a->a_next ) {
1128 /* look for attrs that are always logged */
1129 for ( la=li->li_oldattrs; la; la=la->next ) {
1130 if ( a->a_desc == la->attr ) {
1131 for (b=a->a_vals; !BER_BVISNULL( b ); b++) {
1137 vals = ch_malloc( (i+1) * sizeof( struct berval ));
1139 for ( a=old->e_attrs; a; a=a->a_next ) {
1141 for ( la=li->li_oldattrs; la; la=la->next ) {
1142 if ( a->a_desc == la->attr ) {
1143 for (b=a->a_vals; !BER_BVISNULL( b ); b++,i++) {
1144 accesslog_val2val( a->a_desc, b, 0, &vals[i] );
1149 vals[i].bv_val = NULL;
1151 a = attr_alloc( ad_reqOld );
1154 last_attr->a_next = a;
1156 attr_merge_one( e, ad_reqNewRDN, &op->orr_newrdn, &op->orr_nnewrdn );
1157 attr_merge_one( e, ad_reqDeleteOldRDN, op->orr_deleteoldrdn ?
1158 (struct berval *)&slap_true_bv : (struct berval *)&slap_false_bv,
1160 if ( op->orr_newSup ) {
1161 attr_merge_one( e, ad_reqNewSuperior, op->orr_newSup, op->orr_nnewSup );
1165 case LOG_EN_COMPARE:
1166 bv.bv_len = op->orc_ava->aa_desc->ad_cname.bv_len + 1 +
1167 op->orc_ava->aa_value.bv_len;
1168 bv.bv_val = op->o_tmpalloc( bv.bv_len+1, op->o_tmpmemctx );
1169 ptr = lutil_strcopy( bv.bv_val, op->orc_ava->aa_desc->ad_cname.bv_val );
1171 AC_MEMCPY( ptr, op->orc_ava->aa_value.bv_val, op->orc_ava->aa_value.bv_len );
1172 bv.bv_val[bv.bv_len] = '\0';
1173 attr_merge_one( e, ad_reqAssertion, &bv, NULL );
1174 op->o_tmpfree( bv.bv_val, op->o_tmpmemctx );
1178 attr_merge_one( e, ad_reqScope, &scopes[op->ors_scope], NULL );
1179 attr_merge_one( e, ad_reqDerefAliases, &derefs[op->ors_deref], NULL );
1180 attr_merge_one( e, ad_reqAttrsOnly, op->ors_attrsonly ?
1181 (struct berval *)&slap_true_bv : (struct berval *)&slap_false_bv,
1183 if ( !BER_BVISEMPTY( &op->ors_filterstr ))
1184 attr_merge_one( e, ad_reqFilter, &op->ors_filterstr, NULL );
1185 if ( op->ors_attrs ) {
1187 for (i=0; !BER_BVISNULL(&op->ors_attrs[i].an_name );i++)
1189 vals = op->o_tmpalloc( (i+1) * sizeof(struct berval),
1191 for (i=0; !BER_BVISNULL(&op->ors_attrs[i].an_name );i++)
1192 vals[i] = op->ors_attrs[i].an_name;
1193 vals[i].bv_val = NULL;
1195 attr_merge( e, ad_reqAttr, vals, NULL );
1196 op->o_tmpfree( vals, op->o_tmpmemctx );
1198 bv.bv_val = timebuf;
1199 bv.bv_len = sprintf( bv.bv_val, "%d", rs->sr_nentries );
1200 attr_merge_one( e, ad_reqEntries, &bv, NULL );
1202 bv.bv_len = sprintf( bv.bv_val, "%d", op->ors_tlimit );
1203 attr_merge_one( e, ad_reqTimeLimit, &bv, NULL );
1205 bv.bv_len = sprintf( bv.bv_val, "%d", op->ors_slimit );
1206 attr_merge_one( e, ad_reqSizeLimit, &bv, NULL );
1210 bv.bv_val = timebuf;
1211 bv.bv_len = sprintf( bv.bv_val, "%d", op->o_protocol );
1212 attr_merge_one( e, ad_reqVersion, &bv, NULL );
1213 if ( op->orb_method == LDAP_AUTH_SIMPLE ) {
1214 attr_merge_one( e, ad_reqMethod, &simple, NULL );
1216 bv.bv_len = STRLENOF("SASL()") + op->orb_tmp_mech.bv_len;
1217 bv.bv_val = op->o_tmpalloc( bv.bv_len + 1, op->o_tmpmemctx );
1218 ptr = lutil_strcopy( bv.bv_val, "SASL(" );
1219 ptr = lutil_strcopy( ptr, op->orb_tmp_mech.bv_val );
1222 attr_merge_one( e, ad_reqMethod, &bv, NULL );
1223 op->o_tmpfree( bv.bv_val, op->o_tmpmemctx );
1228 case LOG_EN_EXTENDED:
1229 if ( op->ore_reqdata ) {
1230 attr_merge_one( e, ad_reqData, op->ore_reqdata, NULL );
1234 case LOG_EN_UNKNOWN:
1235 /* we don't know its parameters, don't add any */
1239 op2.o_hdr = op->o_hdr;
1240 op2.o_tag = LDAP_REQ_ADD;
1241 op2.o_bd = li->li_db;
1242 op2.o_dn = li->li_db->be_rootdn;
1243 op2.o_ndn = li->li_db->be_rootndn;
1244 op2.o_req_dn = e->e_name;
1245 op2.o_req_ndn = e->e_nname;
1247 op2.o_callback = &nullsc;
1249 if (( lo->mask & LOG_OP_WRITES ) && !BER_BVISEMPTY( &op->o_csn )) {
1250 slap_queue_csn( &op2, &op->o_csn );
1253 op2.o_bd->be_add( &op2, &rs2 );
1256 if ( lo->mask & LOG_OP_WRITES )
1257 ldap_pvt_thread_mutex_unlock( &li->li_log_mutex );
1258 if ( e ) entry_free( e );
1259 if ( old ) entry_free( old );
1260 return SLAP_CB_CONTINUE;
1263 /* Since Bind success is sent by the frontend, it won't normally enter
1264 * the overlay response callback. Add another callback to make sure it
1268 accesslog_bind_resp( Operation *op, SlapReply *rs )
1277 db.bd_info = op->o_callback->sc_private;
1278 rc = accesslog_response( op, rs );
1280 sc = op->o_callback;
1281 op->o_callback = sc->sc_next;
1282 op->o_tmpfree( sc, op->o_tmpmemctx );
1287 accesslog_op_bind( Operation *op, SlapReply *rs )
1291 sc = op->o_tmpcalloc( 1, sizeof(slap_callback), op->o_tmpmemctx );
1292 sc->sc_response = accesslog_bind_resp;
1293 sc->sc_private = op->o_bd->bd_info;
1295 if ( op->o_callback ) {
1296 sc->sc_next = op->o_callback->sc_next;
1297 op->o_callback->sc_next = sc;
1299 op->o_callback = sc;
1301 return SLAP_CB_CONTINUE;
1305 accesslog_op_mod( Operation *op, SlapReply *rs )
1307 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
1308 log_info *li = on->on_bi.bi_private;
1310 if ( li->li_ops & LOG_OP_WRITES ) {
1311 ldap_pvt_thread_rmutex_lock( &li->li_op_rmutex, op->o_tid );
1312 if ( li->li_oldf && ( op->o_tag == LDAP_REQ_DELETE ||
1313 op->o_tag == LDAP_REQ_MODIFY ||
1314 ( op->o_tag == LDAP_REQ_MODRDN && li->li_oldattrs ))) {
1318 op->o_bd->bd_info = on->on_info->oi_orig;
1319 rc = be_entry_get_rw( op, &op->o_req_ndn, NULL, NULL, 0, &e );
1321 if ( test_filter( op, e, li->li_oldf ) == LDAP_COMPARE_TRUE )
1322 li->li_old = entry_dup( e );
1323 be_entry_release_rw( op, e, 0 );
1325 op->o_bd->bd_info = (BackendInfo *)on;
1328 return SLAP_CB_CONTINUE;
1331 /* unbinds are broadcast to all backends; we only log it if this
1332 * backend was used for the original bind.
1335 accesslog_unbind( Operation *op, SlapReply *rs )
1337 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
1338 if ( op->o_conn->c_authz_backend == on->on_info->oi_origdb ) {
1339 log_info *li = on->on_bi.bi_private;
1340 Operation op2 = {0};
1341 void *cids[SLAP_MAX_CIDS];
1342 SlapReply rs2 = {REP_RESULT};
1345 if ( !( li->li_ops & LOG_OP_UNBIND ))
1346 return SLAP_CB_CONTINUE;
1348 e = accesslog_entry( op, LOG_EN_UNBIND, &op2 );
1349 op2.o_hdr = op->o_hdr;
1350 op2.o_tag = LDAP_REQ_ADD;
1351 op2.o_bd = li->li_db;
1352 op2.o_dn = li->li_db->be_rootdn;
1353 op2.o_ndn = li->li_db->be_rootndn;
1354 op2.o_req_dn = e->e_name;
1355 op2.o_req_ndn = e->e_nname;
1357 op2.o_callback = &nullsc;
1358 op2.o_controls = cids;
1359 memset(cids, 0, sizeof( cids ));
1361 op2.o_bd->be_add( &op2, &rs2 );
1364 return SLAP_CB_CONTINUE;
1368 accesslog_abandon( Operation *op, SlapReply *rs )
1370 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
1371 log_info *li = on->on_bi.bi_private;
1372 Operation op2 = {0};
1373 void *cids[SLAP_MAX_CIDS];
1374 SlapReply rs2 = {REP_RESULT};
1379 if ( !op->o_time || !( li->li_ops & LOG_OP_ABANDON ))
1380 return SLAP_CB_CONTINUE;
1382 e = accesslog_entry( op, LOG_EN_ABANDON, &op2 );
1384 bv.bv_len = sprintf( buf, "%d", op->orn_msgid );
1385 attr_merge_one( e, ad_reqId, &bv, NULL );
1387 op2.o_hdr = op->o_hdr;
1388 op2.o_tag = LDAP_REQ_ADD;
1389 op2.o_bd = li->li_db;
1390 op2.o_dn = li->li_db->be_rootdn;
1391 op2.o_ndn = li->li_db->be_rootndn;
1392 op2.o_req_dn = e->e_name;
1393 op2.o_req_ndn = e->e_nname;
1395 op2.o_callback = &nullsc;
1396 op2.o_controls = cids;
1397 memset(cids, 0, sizeof( cids ));
1399 op2.o_bd->be_add( &op2, &rs2 );
1402 return SLAP_CB_CONTINUE;
1405 static slap_overinst accesslog;
1412 slap_overinst *on = (slap_overinst *)be->bd_info;
1413 log_info *li = ch_calloc(1, sizeof(log_info));
1415 on->on_bi.bi_private = li;
1416 ldap_pvt_thread_rmutex_init( &li->li_op_rmutex );
1417 ldap_pvt_thread_mutex_init( &li->li_log_mutex );
1422 accesslog_db_destroy(
1426 slap_overinst *on = (slap_overinst *)be->bd_info;
1427 log_info *li = on->on_bi.bi_private;
1429 ldap_pvt_thread_mutex_destroy( &li->li_log_mutex );
1430 ldap_pvt_thread_rmutex_destroy( &li->li_op_rmutex );
1432 return LDAP_SUCCESS;
1440 slap_overinst *on = (slap_overinst *)be->bd_info;
1441 log_info *li = on->on_bi.bi_private;
1444 OperationBuffer opbuf;
1445 Operation *op = (Operation *) &opbuf;
1450 if ( li->li_db == NULL ) {
1451 Debug( LDAP_DEBUG_ANY,
1452 "accesslog: \"logdb <suffix>\" must be specified.\n",
1457 if ( slapMode & SLAP_TOOL_MODE )
1460 thrctx = ldap_pvt_thread_pool_context();
1461 connection_fake_init( &conn, op, thrctx );
1462 op->o_bd = li->li_db;
1463 op->o_dn = li->li_db->be_rootdn;
1464 op->o_ndn = li->li_db->be_rootndn;
1466 rc = be_entry_get_rw( op, li->li_db->be_nsuffix, NULL, NULL, 0, &e );
1469 be_entry_release_rw( op, e, 0 );
1471 SlapReply rs = {REP_RESULT};
1472 struct berval rdn, nrdn, attr;
1474 AttributeDescription *ad = NULL;
1475 const char *text = NULL;
1478 e = ch_calloc( 1, sizeof( Entry ));
1479 e->e_name = *li->li_db->be_suffix;
1480 e->e_nname = *li->li_db->be_nsuffix;
1482 attr_merge_one( e, slap_schema.si_ad_objectClass,
1483 &log_container->soc_cname, NULL );
1485 dnRdn( &e->e_name, &rdn );
1486 dnRdn( &e->e_nname, &nrdn );
1487 ptr = ber_bvchr( &rdn, '=' );
1489 assert( ptr != NULL );
1491 attr.bv_val = rdn.bv_val;
1492 attr.bv_len = ptr - rdn.bv_val;
1494 slap_bv2ad( &attr, &ad, &text );
1497 rdn.bv_len -= attr.bv_len + 1;
1498 ptr = ber_bvchr( &nrdn, '=' );
1499 nrdn.bv_len -= ptr - nrdn.bv_val + 1;
1500 nrdn.bv_val = ptr+1;
1501 attr_merge_one( e, ad, &rdn, &nrdn );
1503 /* Get contextCSN from main DB */
1505 op->o_bd->bd_info = on->on_info->oi_orig;
1506 rc = be_entry_get_rw( op, be->be_nsuffix, NULL,
1507 slap_schema.si_ad_contextCSN, 0, &e_ctx );
1512 a = attr_find( e_ctx->e_attrs, slap_schema.si_ad_contextCSN );
1514 attr_merge( e, slap_schema.si_ad_entryCSN, a->a_vals, NULL );
1515 attr_merge( e, a->a_desc, a->a_vals, NULL );
1517 be_entry_release_rw( op, e_ctx, 0 );
1519 op->o_bd->bd_info = (BackendInfo *)on;
1520 op->o_bd = li->li_db;
1523 op->o_req_dn = e->e_name;
1524 op->o_req_ndn = e->e_nname;
1525 op->o_callback = &nullsc;
1526 SLAP_DBFLAGS( op->o_bd ) |= SLAP_DBFLAG_NOLASTMOD;
1527 rc = op->o_bd->be_add( op, &rs );
1528 SLAP_DBFLAGS( op->o_bd ) ^= SLAP_DBFLAG_NOLASTMOD;
1529 attrs_free( e->e_attrs );
1532 ldap_pvt_thread_pool_context_reset( thrctx );
1536 int accesslog_initialize()
1540 accesslog.on_bi.bi_type = "accesslog";
1541 accesslog.on_bi.bi_db_init = accesslog_db_init;
1542 accesslog.on_bi.bi_db_destroy = accesslog_db_destroy;
1543 accesslog.on_bi.bi_db_open = accesslog_db_open;
1545 accesslog.on_bi.bi_op_add = accesslog_op_mod;
1546 accesslog.on_bi.bi_op_bind = accesslog_op_bind;
1547 accesslog.on_bi.bi_op_delete = accesslog_op_mod;
1548 accesslog.on_bi.bi_op_modify = accesslog_op_mod;
1549 accesslog.on_bi.bi_op_modrdn = accesslog_op_mod;
1550 accesslog.on_bi.bi_op_unbind = accesslog_unbind;
1551 accesslog.on_bi.bi_op_abandon = accesslog_abandon;
1552 accesslog.on_response = accesslog_response;
1554 accesslog.on_bi.bi_cf_ocs = log_cfocs;
1556 nullsc.sc_response = slap_null_cb;
1558 rc = config_register_schema( log_cfats, log_cfocs );
1559 if ( rc ) return rc;
1561 /* log schema integration */
1562 for ( i=0; lattrs[i].at; i++ ) {
1563 LDAPAttributeType *lat;
1568 lat = ldap_str2attributetype( lattrs[i].at, &code, &err,
1569 LDAP_SCHEMA_ALLOW_ALL );
1571 Debug( LDAP_DEBUG_ANY, "accesslog_init: "
1572 "ldap_str2attributetype failed on %d: %s, %s\n",
1573 i, ldap_scherr2str(code), err );
1576 code = at_add( lat, 0, &at, &err );
1577 ldap_memfree( lat );
1579 Debug( LDAP_DEBUG_ANY, "log_back_initialize: "
1580 "at_add failed on %d: %s\n",
1581 i, scherr2str(code), 0 );
1584 if ( slap_bv2ad( &at->sat_cname, lattrs[i].ad, &err )) {
1585 Debug( LDAP_DEBUG_ANY, "accesslog_init: "
1586 "slap_bv2ad failed on %d: %s\n",
1591 for ( i=0; locs[i].ot; i++ ) {
1592 LDAPObjectClass *loc;
1597 loc = ldap_str2objectclass( locs[i].ot, &code, &err,
1598 LDAP_SCHEMA_ALLOW_ALL );
1600 Debug( LDAP_DEBUG_ANY, "accesslog_init: "
1601 "ldap_str2objectclass failed on %d: %s, %s\n",
1602 i, ldap_scherr2str(code), err );
1606 code = oc_add( loc, 0, &oc, &err );
1607 ldap_memfree( loc );
1609 Debug( LDAP_DEBUG_ANY, "accesslog_init: "
1610 "oc_add failed on %d: %s\n",
1611 i, scherr2str(code), 0 );
1618 return overlay_register(&accesslog);
1621 #if SLAPD_OVER_ACCESSLOG == SLAPD_MOD_DYNAMIC
1623 init_module( int argc, char *argv[] )
1625 return accesslog_initialize();
1629 #endif /* SLAPD_OVER_ACCESSLOG */