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_info {
63 ldap_pvt_thread_mutex_t li_op_mutex;
64 ldap_pvt_thread_mutex_t li_log_mutex;
67 static ConfigDriver log_cf_gen;
77 static ConfigTable log_cfats[] = {
78 { "logdb", "suffix", 2, 2, 0, ARG_DN|ARG_MAGIC|LOG_DB,
79 log_cf_gen, "( OLcfgOvAt:4.1 NAME 'olcAccessLogDB' "
80 "DESC 'Suffix of database for log content' "
81 "SUP distinguishedName SINGLE-VALUE )", NULL, NULL },
82 { "logops", "op|writes|reads|session|all", 2, 0, 0,
84 log_cf_gen, "( OLcfgOvAt:4.2 NAME 'olcAccessLogOps' "
85 "DESC 'Operation types to log' "
86 "EQUALITY caseIgnoreMatch "
87 "SYNTAX OMsDirectoryString )", NULL, NULL },
88 { "logpurge", "age> <interval", 3, 3, 0, ARG_MAGIC|LOG_PURGE,
89 log_cf_gen, "( OLcfgOvAt:4.3 NAME 'olcAccessLogPurge' "
90 "DESC 'Log cleanup parameters' "
91 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
92 { "logsuccess", NULL, 2, 2, 0, ARG_MAGIC|ARG_ON_OFF|LOG_SUCCESS,
93 log_cf_gen, "( OLcfgOvAt:4.4 NAME 'olcAccessLogSuccess' "
94 "DESC 'Log successful ops only' "
95 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
96 { "logold", "filter", 2, 2, 0, ARG_MAGIC|LOG_OLD,
97 log_cf_gen, "( OLcfgOvAt:4.5 NAME 'olcAccessLogOld' "
98 "DESC 'Log old values when modifying entries matching the filter' "
99 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
103 static ConfigOCs log_cfocs[] = {
105 "NAME 'olcAccessLogConfig' "
106 "DESC 'Access log configuration' "
107 "SUP olcOverlayConfig "
108 "MUST olcAccessLogDB "
109 "MAY ( olcAccessLogOps $ olcAccessLogPurge $ olcAccessLogSuccess $ "
110 "olcAccessLogOld ) )",
111 Cft_Overlay, log_cfats },
115 static slap_verbmasks logops[] = {
116 { BER_BVC("all"), LOG_OP_ALL },
117 { BER_BVC("writes"), LOG_OP_WRITES },
118 { BER_BVC("session"), LOG_OP_SESSION },
119 { BER_BVC("reads"), LOG_OP_READS },
120 { BER_BVC("add"), LOG_OP_ADD },
121 { BER_BVC("delete"), LOG_OP_DELETE },
122 { BER_BVC("modify"), LOG_OP_MODIFY },
123 { BER_BVC("modrdn"), LOG_OP_MODRDN },
124 { BER_BVC("compare"), LOG_OP_COMPARE },
125 { BER_BVC("search"), LOG_OP_SEARCH },
126 { BER_BVC("bind"), LOG_OP_BIND },
127 { BER_BVC("unbind"), LOG_OP_UNBIND },
128 { BER_BVC("abandon"), LOG_OP_ABANDON },
129 { BER_BVC("extended"), LOG_OP_EXTENDED },
130 { BER_BVC("unknown"), LOG_OP_UNKNOWN },
134 /* Start with "add" in logops */
152 static ObjectClass *log_ocs[LOG_EN__COUNT], *log_container;
154 #define LOG_SCHEMA_ROOT "1.3.6.1.4.1.4203.666.11.5"
156 #define LOG_SCHEMA_AT LOG_SCHEMA_ROOT ".1"
157 #define LOG_SCHEMA_OC LOG_SCHEMA_ROOT ".2"
159 static AttributeDescription *ad_reqDN, *ad_reqStart, *ad_reqEnd, *ad_reqType,
160 *ad_reqSession, *ad_reqResult, *ad_reqAuthzID, *ad_reqControls,
161 *ad_reqRespControls, *ad_reqMethod, *ad_reqAssertion, *ad_reqNewRDN,
162 *ad_reqNewSuperior, *ad_reqDeleteOldRDN, *ad_reqMod,
163 *ad_reqScope, *ad_reqFilter, *ad_reqAttr, *ad_reqEntries,
164 *ad_reqSizeLimit, *ad_reqTimeLimit, *ad_reqAttrsOnly, *ad_reqData,
165 *ad_reqId, *ad_reqMessage, *ad_reqVersion, *ad_reqDerefAliases,
166 *ad_reqReferral, *ad_reqOld;
170 AttributeDescription **ad;
172 { "( " LOG_SCHEMA_AT ".1 NAME 'reqDN' "
173 "DESC 'Target DN of request' "
174 "EQUALITY distinguishedNameMatch "
176 "SINGLE-VALUE )", &ad_reqDN },
177 { "( " LOG_SCHEMA_AT ".2 NAME 'reqStart' "
178 "DESC 'Start time of request' "
179 "EQUALITY generalizedTimeMatch "
180 "ORDERING generalizedTimeOrderingMatch "
181 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 "
182 "SINGLE-VALUE )", &ad_reqStart },
183 { "( " LOG_SCHEMA_AT ".3 NAME 'reqEnd' "
184 "DESC 'End time of request' "
185 "EQUALITY generalizedTimeMatch "
186 "ORDERING generalizedTimeOrderingMatch "
187 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 "
188 "SINGLE-VALUE )", &ad_reqEnd },
189 { "( " LOG_SCHEMA_AT ".4 NAME 'reqType' "
190 "DESC 'Type of request' "
191 "EQUALITY caseIgnoreMatch "
192 "SYNTAX OMsDirectoryString "
193 "SINGLE-VALUE )", &ad_reqType },
194 { "( " LOG_SCHEMA_AT ".5 NAME 'reqSession' "
195 "DESC 'Session ID of request' "
196 "EQUALITY caseIgnoreMatch "
197 "SYNTAX OMsDirectoryString "
198 "SINGLE-VALUE )", &ad_reqSession },
199 { "( " LOG_SCHEMA_AT ".6 NAME 'reqAuthzID' "
200 "DESC 'Authorization ID of requestor' "
201 "EQUALITY distinguishedNameMatch "
203 "SINGLE-VALUE )", &ad_reqAuthzID },
204 { "( " LOG_SCHEMA_AT ".7 NAME 'reqResult' "
205 "DESC 'Result code of request' "
206 "EQUALITY integerMatch "
207 "ORDERING integerOrderingMatch "
209 "SINGLE-VALUE )", &ad_reqResult },
210 { "( " LOG_SCHEMA_AT ".8 NAME 'reqMessage' "
211 "DESC 'Error text of request' "
212 "EQUALITY caseIgnoreMatch "
213 "SUBSTR caseIgnoreSubstringsMatch "
214 "SYNTAX OMsDirectoryString "
215 "SINGLE-VALUE )", &ad_reqMessage },
216 { "( " LOG_SCHEMA_AT ".9 NAME 'reqReferral' "
217 "DESC 'Referrals returned for request' "
218 "SUP labeledURI )", &ad_reqReferral },
219 { "( " LOG_SCHEMA_AT ".10 NAME 'reqControls' "
220 "DESC 'Request controls' "
221 "SYNTAX OMsOctetString )", &ad_reqControls },
222 { "( " LOG_SCHEMA_AT ".11 NAME 'reqRespControls' "
223 "DESC 'Response controls of request' "
224 "SYNTAX OMsOctetString )", &ad_reqRespControls },
225 { "( " LOG_SCHEMA_AT ".12 NAME 'reqId' "
226 "DESC 'ID of Request to Abandon' "
227 "EQUALITY integerMatch "
228 "ORDERING integerOrderingMatch "
230 "SINGLE-VALUE )", &ad_reqId },
231 { "( " LOG_SCHEMA_AT ".13 NAME 'reqVersion' "
232 "DESC 'Protocol version of Bind request' "
233 "EQUALITY integerMatch "
234 "ORDERING integerOrderingMatch "
236 "SINGLE-VALUE )", &ad_reqVersion },
237 { "( " LOG_SCHEMA_AT ".14 NAME 'reqMethod' "
238 "DESC 'Bind method of request' "
239 "EQUALITY caseIgnoreMatch "
240 "SYNTAX OMsDirectoryString "
241 "SINGLE-VALUE )", &ad_reqMethod },
242 { "( " LOG_SCHEMA_AT ".15 NAME 'reqAssertion' "
243 "DESC 'Compare Assertion of request' "
244 "SYNTAX OMsDirectoryString "
245 "SINGLE-VALUE )", &ad_reqAssertion },
246 { "( " LOG_SCHEMA_AT ".16 NAME 'reqMod' "
247 "DESC 'Modifications of request' "
248 "EQUALITY octetStringMatch "
249 "SUBSTR octetStringSubstringsMatch "
250 "SYNTAX OMsOctetString )", &ad_reqMod },
251 { "( " LOG_SCHEMA_AT ".17 NAME 'reqOld' "
252 "DESC 'Old values of entry before request completed' "
253 "EQUALITY octetStringMatch "
254 "SUBSTR octetStringSubstringsMatch "
255 "SYNTAX OMsOctetString )", &ad_reqOld },
256 { "( " LOG_SCHEMA_AT ".18 NAME 'reqNewRDN' "
257 "DESC 'New RDN of request' "
258 "EQUALITY distinguishedNameMatch "
260 "SINGLE-VALUE )", &ad_reqNewRDN },
261 { "( " LOG_SCHEMA_AT ".19 NAME 'reqDeleteOldRDN' "
262 "DESC 'Delete old RDN' "
263 "EQUALITY booleanMatch "
265 "SINGLE-VALUE )", &ad_reqDeleteOldRDN },
266 { "( " LOG_SCHEMA_AT ".20 NAME 'reqNewSuperior' "
267 "DESC 'New superior DN of request' "
268 "EQUALITY distinguishedNameMatch "
270 "SINGLE-VALUE )", &ad_reqNewSuperior },
271 { "( " LOG_SCHEMA_AT ".21 NAME 'reqScope' "
272 "DESC 'Scope of request' "
273 "EQUALITY caseIgnoreMatch "
274 "SYNTAX OMsDirectoryString "
275 "SINGLE-VALUE )", &ad_reqScope },
276 { "( " LOG_SCHEMA_AT ".22 NAME 'reqDerefAliases' "
277 "DESC 'Disposition of Aliases in request' "
278 "EQUALITY caseIgnoreMatch "
279 "SYNTAX OMsDirectoryString "
280 "SINGLE-VALUE )", &ad_reqDerefAliases },
281 { "( " LOG_SCHEMA_AT ".23 NAME 'reqAttrsOnly' "
282 "DESC 'Attributes and values of request' "
283 "EQUALITY booleanMatch "
285 "SINGLE-VALUE )", &ad_reqAttrsOnly },
286 { "( " LOG_SCHEMA_AT ".24 NAME 'reqFilter' "
287 "DESC 'Filter of request' "
288 "EQUALITY caseIgnoreMatch "
289 "SUBSTR caseIgnoreSubstringsMatch "
290 "SYNTAX OMsDirectoryString "
291 "SINGLE-VALUE )", &ad_reqFilter },
292 { "( " LOG_SCHEMA_AT ".25 NAME 'reqAttr' "
293 "DESC 'Attributes of request' "
294 "EQUALITY caseIgnoreMatch "
295 "SYNTAX OMsDirectoryString )", &ad_reqAttr },
296 { "( " LOG_SCHEMA_AT ".26 NAME 'reqSizeLimit' "
297 "DESC 'Size limit of request' "
298 "EQUALITY integerMatch "
299 "ORDERING integerOrderingMatch "
301 "SINGLE-VALUE )", &ad_reqSizeLimit },
302 { "( " LOG_SCHEMA_AT ".27 NAME 'reqTimeLimit' "
303 "DESC 'Time limit of request' "
304 "EQUALITY integerMatch "
305 "ORDERING integerOrderingMatch "
307 "SINGLE-VALUE )", &ad_reqTimeLimit },
308 { "( " LOG_SCHEMA_AT ".28 NAME 'reqEntries' "
309 "DESC 'Number of entries returned' "
310 "EQUALITY integerMatch "
311 "ORDERING integerOrderingMatch "
313 "SINGLE-VALUE )", &ad_reqEntries },
314 { "( " LOG_SCHEMA_AT ".29 NAME 'reqData' "
315 "DESC 'Data of extended request' "
316 "EQUALITY octetStringMatch "
317 "SUBSTR octetStringSubstringsMatch "
318 "SYNTAX OMsOctetString "
319 "SINGLE-VALUE )", &ad_reqData },
327 { "( " LOG_SCHEMA_OC ".0 NAME 'auditContainer' "
328 "DESC 'AuditLog container' "
329 "SUP top STRUCTURAL "
330 "MAY ( cn $ reqStart $ reqEnd ) )", &log_container },
331 { "( " LOG_SCHEMA_OC ".1 NAME 'auditObject' "
332 "DESC 'OpenLDAP request auditing' "
333 "SUP top STRUCTURAL "
334 "MUST ( reqStart $ reqType $ reqSession ) "
335 "MAY ( reqDN $ reqAuthzID $ reqControls $ reqRespControls $ reqEnd $ "
336 "reqResult $ reqMessage $ reqReferral ) )",
337 &log_ocs[LOG_EN_UNBIND] },
338 { "( " LOG_SCHEMA_OC ".2 NAME 'auditReadObject' "
339 "DESC 'OpenLDAP read request record' "
340 "SUP auditObject STRUCTURAL )", NULL },
341 { "( " LOG_SCHEMA_OC ".3 NAME 'auditWriteObject' "
342 "DESC 'OpenLDAP write request record' "
343 "SUP auditObject STRUCTURAL )", NULL },
344 { "( " LOG_SCHEMA_OC ".4 NAME 'auditAbandon' "
345 "DESC 'Abandon operation' "
346 "SUP auditObject STRUCTURAL "
347 "MUST reqId )", &log_ocs[LOG_EN_ABANDON] },
348 { "( " LOG_SCHEMA_OC ".5 NAME 'auditAdd' "
349 "DESC 'Add operation' "
350 "SUP auditWriteObject STRUCTURAL "
351 "MUST reqMod )", &log_ocs[LOG_EN_ADD] },
352 { "( " LOG_SCHEMA_OC ".6 NAME 'auditBind' "
353 "DESC 'Bind operation' "
354 "SUP auditObject STRUCTURAL "
355 "MUST ( reqVersion $ reqMethod ) )", &log_ocs[LOG_EN_BIND] },
356 { "( " LOG_SCHEMA_OC ".7 NAME 'auditCompare' "
357 "DESC 'Compare operation' "
358 "SUP auditReadObject STRUCTURAL "
359 "MUST reqAssertion )", &log_ocs[LOG_EN_COMPARE] },
360 { "( " LOG_SCHEMA_OC ".8 NAME 'auditDelete' "
361 "DESC 'Delete operation' "
362 "SUP auditWriteObject STRUCTURAL "
363 "MAY reqOld )", &log_ocs[LOG_EN_DELETE] },
364 { "( " LOG_SCHEMA_OC ".9 NAME 'auditModify' "
365 "DESC 'Modify operation' "
366 "SUP auditWriteObject STRUCTURAL "
367 "MAY reqOld MUST reqMod )", &log_ocs[LOG_EN_MODIFY] },
368 { "( " LOG_SCHEMA_OC ".10 NAME 'auditModRDN' "
369 "DESC 'ModRDN operation' "
370 "SUP auditWriteObject STRUCTURAL "
371 "MUST ( reqNewRDN $ reqDeleteOldRDN ) "
372 "MAY reqNewSuperior )", &log_ocs[LOG_EN_MODRDN] },
373 { "( " LOG_SCHEMA_OC ".11 NAME 'auditSearch' "
374 "DESC 'Search operation' "
375 "SUP auditReadObject STRUCTURAL "
376 "MUST ( reqScope $ reqDerefAliases $ reqAttrsonly ) "
377 "MAY ( reqFilter $ reqAttr $ reqEntries $ reqSizeLimit $ "
378 "reqTimeLimit ) )", &log_ocs[LOG_EN_SEARCH] },
379 { "( " LOG_SCHEMA_OC ".12 NAME 'auditExtended' "
380 "DESC 'Extended operation' "
381 "SUP auditObject STRUCTURAL "
382 "MAY reqData )", &log_ocs[LOG_EN_EXTENDED] },
386 #define RDNEQ "reqStart="
388 /* Our time intervals are of the form [ddd+]hh:mm[:ss]
389 * If a field is present, it must be two digits. (Except for
390 * days, which can be arbitrary width.)
393 log_age_parse(char *agestr)
399 t1 = strtol( agestr, &endptr, 10 );
400 /* Is there a days delimiter? */
401 if ( *endptr == '+' ) {
402 /* 32 bit time only covers about 68 years */
403 if ( t1 < 0 || t1 > 25000 )
409 if ( agestr[2] != ':' ) {
410 /* No valid delimiter found, fail */
421 /* if there's a delimiter, it can only be a colon */
422 if ( agestr[2] != ':' )
425 /* If we're at the end of the string, and we started with days,
426 * fail because we expected to find minutes too.
428 return gotdays ? -1 : t1 * 60;
434 /* last field can only be seconds */
435 if ( agestr[2] && ( agestr[2] != ':' || !gotdays ))
445 t1 += atoi( agestr );
446 } else if ( gotdays ) {
447 /* only got days+hh:mm */
454 log_age_unparse( int age, struct berval *agebv )
470 ptr += sprintf( ptr, "%d+", dd );
471 ptr += sprintf( ptr, "%02d:%02d", hh, mm );
473 ptr += sprintf( ptr, ":%02d", ss );
475 agebv->bv_len = ptr - agebv->bv_val;
478 static slap_callback nullsc = { NULL, NULL, NULL, NULL };
480 #define PURGE_INCREMENT 100
482 typedef struct purge_data {
490 log_old_lookup( Operation *op, SlapReply *rs )
492 purge_data *pd = op->o_callback->sc_private;
494 if ( rs->sr_type != REP_SEARCH) return 0;
496 if ( slapd_shutdown ) return 0;
498 if ( pd->used >= pd->slots ) {
499 pd->slots += PURGE_INCREMENT;
500 pd->dn = ch_realloc( pd->dn, pd->slots * sizeof( struct berval ));
501 pd->ndn = ch_realloc( pd->ndn, pd->slots * sizeof( struct berval ));
503 ber_dupbv( &pd->dn[pd->used], &rs->sr_entry->e_name );
504 ber_dupbv( &pd->ndn[pd->used], &rs->sr_entry->e_nname );
509 /* Periodically search for old entries in the log database and delete them */
511 accesslog_purge( void *ctx, void *arg )
513 struct re_s *rtask = arg;
514 struct log_info *li = rtask->arg;
516 Connection conn = {0};
517 OperationBuffer opbuf;
518 Operation *op = (Operation *) &opbuf;
519 SlapReply rs = {REP_RESULT};
520 slap_callback cb = { NULL, log_old_lookup, NULL, NULL };
522 AttributeAssertion ava = {0};
524 char timebuf[LDAP_LUTIL_GENTIME_BUFSIZE];
525 time_t old = slap_get_time();
527 connection_fake_init( &conn, op, ctx );
529 f.f_choice = LDAP_FILTER_LE;
533 ava.aa_desc = ad_reqStart;
534 ava.aa_value.bv_val = timebuf;
535 ava.aa_value.bv_len = sizeof(timebuf);
538 slap_timestamp( &old, &ava.aa_value );
540 op->o_tag = LDAP_REQ_SEARCH;
541 op->o_bd = li->li_db;
542 op->o_dn = li->li_db->be_rootdn;
543 op->o_ndn = li->li_db->be_rootndn;
544 op->o_req_dn = li->li_db->be_suffix[0];
545 op->o_req_ndn = li->li_db->be_nsuffix[0];
546 op->o_callback = &cb;
547 op->ors_scope = LDAP_SCOPE_ONELEVEL;
548 op->ors_deref = LDAP_DEREF_NEVER;
549 op->ors_tlimit = SLAP_NO_LIMIT;
550 op->ors_slimit = SLAP_NO_LIMIT;
552 filter2bv_x( op, &f, &op->ors_filterstr );
553 op->ors_attrs = slap_anlist_no_attrs;
554 op->ors_attrsonly = 1;
558 op->o_bd->be_search( op, &rs );
559 op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
564 op->o_tag = LDAP_REQ_DELETE;
565 op->o_callback = &nullsc;
567 for (i=0; i<pd.used; i++) {
568 op->o_req_dn = pd.dn[i];
569 op->o_req_ndn = pd.ndn[i];
570 if ( !slapd_shutdown )
571 op->o_bd->be_delete( op, &rs );
572 ch_free( pd.ndn[i].bv_val );
573 ch_free( pd.dn[i].bv_val );
579 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
580 ldap_pvt_runqueue_stoptask( &slapd_rq, rtask );
581 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
587 log_cf_gen(ConfigArgs *c)
589 slap_overinst *on = (slap_overinst *)c->bi;
590 struct log_info *li = on->on_bi.bi_private;
592 slap_mask_t tmask = 0;
593 char agebuf[2*STRLENOF("ddddd+hh:mm:ss ")];
594 struct berval agebv, cyclebv;
597 case SLAP_CONFIG_EMIT:
600 value_add( &c->rvalue_vals, li->li_db->be_suffix );
601 value_add( &c->rvalue_nvals, li->li_db->be_nsuffix );
604 rc = mask_to_verbs( logops, li->li_ops, &c->rvalue_vals );
611 agebv.bv_val = agebuf;
612 log_age_unparse( li->li_age, &agebv );
613 agebv.bv_val[agebv.bv_len] = ' ';
615 cyclebv.bv_val = agebv.bv_val + agebv.bv_len;
616 log_age_unparse( li->li_cycle, &cyclebv );
617 agebv.bv_len += cyclebv.bv_len;
618 value_add_one( &c->rvalue_vals, &agebv );
621 if ( li->li_success )
622 c->value_int = li->li_success;
628 filter2bv( li->li_oldf, &agebv );
629 ber_bvarray_add( &c->rvalue_vals, &agebv );
636 case LDAP_MOD_DELETE:
639 /* noop. this should always be a valid backend. */
645 rc = verbs_to_mask( 1, &c->line, logops, &tmask );
647 li->li_ops &= ~tmask;
652 struct re_s *re = li->li_task;
654 if ( ldap_pvt_runqueue_isrunning( &slapd_rq, re ))
655 ldap_pvt_runqueue_stoptask( &slapd_rq, re );
656 ldap_pvt_runqueue_remove( &slapd_rq, re );
666 filter_free( li->li_oldf );
675 li->li_db = select_backend( &c->value_ndn, 0, 0 );
677 sprintf( c->msg, "<%s> no matching backend found for suffix",
679 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
680 c->log, c->msg, c->value_dn.bv_val );
682 } else if ( BER_BVISEMPTY( &li->li_db->be_rootdn )) {
683 snprintf( c->msg, sizeof( c->msg ),
684 "<%s> no rootDN was configured for suffix",
686 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
687 c->log, c->msg, c->value_dn.bv_val );
690 ch_free( c->value_dn.bv_val );
691 ch_free( c->value_ndn.bv_val );
694 rc = verbs_to_mask( c->argc, c->argv, logops, &tmask );
699 li->li_age = log_age_parse( c->argv[1] );
700 if ( li->li_age < 1 ) {
703 li->li_cycle = log_age_parse( c->argv[2] );
704 if ( li->li_cycle < 1 ) {
706 } else if ( slapMode & SLAP_SERVER_MODE ) {
707 struct re_s *re = li->li_task;
709 re->interval.tv_sec = li->li_cycle;
711 li->li_task = ldap_pvt_runqueue_insert( &slapd_rq,
712 li->li_cycle, accesslog_purge, li,
713 "accesslog_purge", li->li_db ?
714 li->li_db->be_suffix[0].bv_val :
715 c->be->be_suffix[0].bv_val );
720 li->li_success = c->value_int;
723 li->li_oldf = str2filter( c->argv[1] );
724 if ( !li->li_oldf ) {
725 sprintf( c->msg, "bad filter!" );
734 static Entry *accesslog_entry( Operation *op, int logop,
736 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
737 log_info *li = on->on_bi.bi_private;
739 char rdnbuf[STRLENOF(RDNEQ)+LDAP_LUTIL_GENTIME_BUFSIZE+8];
740 char nrdnbuf[STRLENOF(RDNEQ)+LDAP_LUTIL_GENTIME_BUFSIZE+8];
742 struct berval rdn, nrdn, timestamp, ntimestamp, bv;
743 slap_verbmasks *lo = logops+logop+EN_OFFSET;
745 Entry *e = ch_calloc( 1, sizeof(Entry) );
747 strcpy( rdnbuf, RDNEQ );
749 strcpy( nrdnbuf, RDNEQ );
750 nrdn.bv_val = nrdnbuf;
752 timestamp.bv_val = rdnbuf+STRLENOF(RDNEQ);
753 timestamp.bv_len = sizeof(rdnbuf) - STRLENOF(RDNEQ);
754 slap_timestamp( &op->o_time, ×tamp );
755 sprintf( timestamp.bv_val + timestamp.bv_len-1, ".%06dZ", op->o_tincr );
756 timestamp.bv_len += 7;
758 rdn.bv_len = STRLENOF(RDNEQ)+timestamp.bv_len;
759 ad_reqStart->ad_type->sat_equality->smr_normalize(
760 SLAP_MR_VALUE_OF_ASSERTION_SYNTAX, ad_reqStart->ad_type->sat_syntax,
761 ad_reqStart->ad_type->sat_equality, ×tamp, &ntimestamp,
764 strcpy( nrdn.bv_val + STRLENOF(RDNEQ), ntimestamp.bv_val );
765 nrdn.bv_len = STRLENOF(RDNEQ)+ntimestamp.bv_len;
766 build_new_dn( &e->e_name, li->li_db->be_suffix, &rdn, NULL );
767 build_new_dn( &e->e_nname, li->li_db->be_nsuffix, &nrdn, NULL );
769 attr_merge_one( e, slap_schema.si_ad_objectClass,
770 &log_ocs[logop]->soc_cname, NULL );
771 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass,
772 &log_ocs[logop]->soc_cname, NULL );
773 attr_merge_one( e, ad_reqStart, ×tamp, &ntimestamp );
774 op->o_tmpfree( ntimestamp.bv_val, op->o_tmpmemctx );
776 slap_op_time( &op2->o_time, &op2->o_tincr );
778 timestamp.bv_len = sizeof(rdnbuf) - STRLENOF(RDNEQ);
779 slap_timestamp( &op2->o_time, ×tamp );
780 sprintf( timestamp.bv_val + timestamp.bv_len-1, ".%06dZ", op2->o_tincr );
781 timestamp.bv_len += 7;
783 attr_merge_normalize_one( e, ad_reqEnd, ×tamp, op->o_tmpmemctx );
785 /* Exops have OID appended */
786 if ( logop == LOG_EN_EXTENDED ) {
787 bv.bv_len = lo->word.bv_len + op->ore_reqoid.bv_len + 2;
788 bv.bv_val = ch_malloc( bv.bv_len + 1 );
789 AC_MEMCPY( bv.bv_val, lo->word.bv_val, lo->word.bv_len );
790 bv.bv_val[lo->word.bv_len] = '{';
791 AC_MEMCPY( bv.bv_val+lo->word.bv_len+1, op->ore_reqoid.bv_val,
792 op->ore_reqoid.bv_len );
793 bv.bv_val[bv.bv_len-1] = '}';
794 bv.bv_val[bv.bv_len] = '\0';
795 attr_merge_one( e, ad_reqType, &bv, NULL );
797 attr_merge_one( e, ad_reqType, &lo->word, NULL );
800 rdn.bv_len = sprintf( rdn.bv_val, "%lu", op->o_connid );
801 attr_merge_one( e, ad_reqSession, &rdn, NULL );
803 if ( BER_BVISNULL( &op->o_dn ))
804 attr_merge_one( e, ad_reqAuthzID, (struct berval *)&slap_empty_bv,
805 (struct berval *)&slap_empty_bv );
807 attr_merge_one( e, ad_reqAuthzID, &op->o_dn, &op->o_ndn );
809 /* FIXME: need to add reqControls and reqRespControls */
814 static struct berval scopes[] = {
821 static struct berval derefs[] = {
823 BER_BVC("searching"),
828 static struct berval simple = BER_BVC("SIMPLE");
830 static void accesslog_val2val(AttributeDescription *ad, struct berval *val,
831 char c_op, struct berval *dst) {
834 dst->bv_len = ad->ad_cname.bv_len + val->bv_len + 2;
835 if ( c_op ) dst->bv_len++;
837 dst->bv_val = ch_malloc( dst->bv_len+1 );
839 ptr = lutil_strcopy( dst->bv_val, ad->ad_cname.bv_val );
844 AC_MEMCPY( ptr, val->bv_val, val->bv_len );
845 dst->bv_val[dst->bv_len] = '\0';
848 static int accesslog_response(Operation *op, SlapReply *rs) {
849 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
850 log_info *li = on->on_bi.bi_private;
851 Attribute *a, *last_attr;
857 Entry *e = NULL, *old = NULL;
858 char timebuf[LDAP_LUTIL_GENTIME_BUFSIZE+8];
863 SlapReply rs2 = {REP_RESULT};
865 if ( rs->sr_type != REP_RESULT && rs->sr_type != REP_EXTENDED )
866 return SLAP_CB_CONTINUE;
868 switch ( op->o_tag ) {
869 case LDAP_REQ_ADD: logop = LOG_EN_ADD; break;
870 case LDAP_REQ_DELETE: logop = LOG_EN_DELETE; break;
871 case LDAP_REQ_MODIFY: logop = LOG_EN_MODIFY; break;
872 case LDAP_REQ_MODRDN: logop = LOG_EN_MODRDN; break;
873 case LDAP_REQ_COMPARE: logop = LOG_EN_COMPARE; break;
874 case LDAP_REQ_SEARCH: logop = LOG_EN_SEARCH; break;
875 case LDAP_REQ_BIND: logop = LOG_EN_BIND; break;
876 case LDAP_REQ_EXTENDED: logop = LOG_EN_EXTENDED; break;
877 default: /* unknown operation type */
878 logop = LOG_EN_UNKNOWN; break;
879 } /* Unbind and Abandon never reach here */
881 lo = logops+logop+EN_OFFSET;
882 if ( !( li->li_ops & lo->mask ))
883 return SLAP_CB_CONTINUE;
885 if ( lo->mask & LOG_OP_WRITES ) {
886 ldap_pvt_thread_mutex_lock( &li->li_log_mutex );
889 ldap_pvt_thread_mutex_unlock( &li->li_op_mutex );
892 if ( li->li_success && rs->sr_err != LDAP_SUCCESS )
895 e = accesslog_entry( op, logop, &op2 );
897 attr_merge_one( e, ad_reqDN, &op->o_req_dn, &op->o_req_ndn );
900 ber_str2bv( rs->sr_text, 0, 0, &bv );
901 attr_merge_one( e, ad_reqMessage, &bv, NULL );
903 bv.bv_len = sprintf( timebuf, "%d", rs->sr_err );
906 attr_merge_one( e, ad_reqResult, &bv, NULL );
908 last_attr = attr_find( e->e_attrs, ad_reqResult );
912 case LOG_EN_DELETE: {
916 if ( logop == LOG_EN_ADD ) {
925 /* count all the vals */
927 for ( a=e2->e_attrs; a; a=a->a_next ) {
929 for (b=a->a_vals; !BER_BVISNULL( b ); b++) {
934 vals = ch_malloc( (i+1) * sizeof( struct berval ));
936 for ( a=e2->e_attrs; a; a=a->a_next ) {
938 for (b=a->a_vals; !BER_BVISNULL( b ); b++,i++) {
939 accesslog_val2val( a->a_desc, b, c_op, &vals[i] );
943 vals[i].bv_val = NULL;
945 a = attr_alloc( logop == LOG_EN_ADD ? ad_reqMod : ad_reqOld );
948 last_attr->a_next = a;
953 /* count all the mods */
955 for ( m=op->orm_modlist; m; m=m->sml_next ) {
956 if ( m->sml_values ) {
957 for (b=m->sml_values; !BER_BVISNULL( b ); b++) {
960 } else if ( m->sml_op == LDAP_MOD_DELETE ) {
964 vals = ch_malloc( (i+1) * sizeof( struct berval ));
967 /* Zero flags on old entry */
969 for ( a=old->e_attrs; a; a=a->a_next )
973 for ( m=op->orm_modlist; m; m=m->sml_next ) {
974 /* Mark this attribute as modified */
976 a = attr_find( old->e_attrs, m->sml_desc );
980 if ( m->sml_values ) {
981 for (b=m->sml_values; !BER_BVISNULL( b ); b++,i++) {
984 switch( m->sml_op ) {
985 case LDAP_MOD_ADD: c_op = '+'; break;
986 case LDAP_MOD_DELETE: c_op = '-'; break;
987 case LDAP_MOD_REPLACE: c_op = '='; break;
988 case LDAP_MOD_INCREMENT: c_op = '#'; break;
990 /* unknown op. there shouldn't be any of these. we
991 * don't know what to do with it, but we shouldn't just
994 default: c_op = '?'; break;
996 accesslog_val2val( m->sml_desc, b, c_op, &vals[i] );
998 } else if ( m->sml_op == LDAP_MOD_DELETE ) {
999 vals[i].bv_len = m->sml_desc->ad_cname.bv_len + 2;
1000 vals[i].bv_val = ch_malloc( vals[i].bv_len+1 );
1001 ptr = lutil_strcopy( vals[i].bv_val,
1002 m->sml_desc->ad_cname.bv_val );
1009 vals[i].bv_val = NULL;
1011 a = attr_alloc( ad_reqMod );
1014 last_attr->a_next = a;
1018 /* count all the vals */
1020 for ( a=old->e_attrs; a; a=a->a_next ) {
1021 if ( a->a_vals && a->a_flags ) {
1022 for (b=a->a_vals; !BER_BVISNULL( b ); b++) {
1027 vals = ch_malloc( (i+1) * sizeof( struct berval ));
1029 for ( a=old->e_attrs; a; a=a->a_next ) {
1030 if ( a->a_vals && a->a_flags ) {
1031 for (b=a->a_vals; !BER_BVISNULL( b ); b++,i++) {
1032 accesslog_val2val( a->a_desc, b, 0, &vals[i] );
1036 vals[i].bv_val = NULL;
1038 a = attr_alloc( ad_reqOld );
1041 last_attr->a_next = a;
1046 attr_merge_one( e, ad_reqNewRDN, &op->orr_newrdn, &op->orr_nnewrdn );
1047 attr_merge_one( e, ad_reqDeleteOldRDN, op->orr_deleteoldrdn ?
1048 (struct berval *)&slap_true_bv : (struct berval *)&slap_false_bv,
1050 if ( op->orr_newSup ) {
1051 attr_merge_one( e, ad_reqNewSuperior, op->orr_newSup, op->orr_nnewSup );
1055 case LOG_EN_COMPARE:
1056 bv.bv_len = op->orc_ava->aa_desc->ad_cname.bv_len + 1 +
1057 op->orc_ava->aa_value.bv_len;
1058 bv.bv_val = op->o_tmpalloc( bv.bv_len+1, op->o_tmpmemctx );
1059 ptr = lutil_strcopy( bv.bv_val, op->orc_ava->aa_desc->ad_cname.bv_val );
1061 AC_MEMCPY( ptr, op->orc_ava->aa_value.bv_val, op->orc_ava->aa_value.bv_len );
1062 bv.bv_val[bv.bv_len] = '\0';
1063 attr_merge_one( e, ad_reqAssertion, &bv, NULL );
1064 op->o_tmpfree( bv.bv_val, op->o_tmpmemctx );
1068 attr_merge_one( e, ad_reqScope, &scopes[op->ors_scope], NULL );
1069 attr_merge_one( e, ad_reqDerefAliases, &derefs[op->ors_deref], NULL );
1070 attr_merge_one( e, ad_reqAttrsOnly, op->ors_attrsonly ?
1071 (struct berval *)&slap_true_bv : (struct berval *)&slap_false_bv,
1073 if ( !BER_BVISEMPTY( &op->ors_filterstr ))
1074 attr_merge_one( e, ad_reqFilter, &op->ors_filterstr, NULL );
1075 if ( op->ors_attrs ) {
1077 for (i=0; !BER_BVISNULL(&op->ors_attrs[i].an_name );i++)
1079 vals = op->o_tmpalloc( (i+1) * sizeof(struct berval),
1081 for (i=0; !BER_BVISNULL(&op->ors_attrs[i].an_name );i++)
1082 vals[i] = op->ors_attrs[i].an_name;
1083 vals[i].bv_val = NULL;
1085 attr_merge( e, ad_reqAttr, vals, NULL );
1086 op->o_tmpfree( vals, op->o_tmpmemctx );
1088 bv.bv_val = timebuf;
1089 bv.bv_len = sprintf( bv.bv_val, "%d", rs->sr_nentries );
1090 attr_merge_one( e, ad_reqEntries, &bv, NULL );
1092 bv.bv_len = sprintf( bv.bv_val, "%d", op->ors_tlimit );
1093 attr_merge_one( e, ad_reqTimeLimit, &bv, NULL );
1095 bv.bv_len = sprintf( bv.bv_val, "%d", op->ors_slimit );
1096 attr_merge_one( e, ad_reqSizeLimit, &bv, NULL );
1100 bv.bv_val = timebuf;
1101 bv.bv_len = sprintf( bv.bv_val, "%d", op->o_protocol );
1102 attr_merge_one( e, ad_reqVersion, &bv, NULL );
1103 if ( op->orb_method == LDAP_AUTH_SIMPLE ) {
1104 attr_merge_one( e, ad_reqMethod, &simple, NULL );
1106 bv.bv_len = STRLENOF("SASL()") + op->orb_tmp_mech.bv_len;
1107 bv.bv_val = op->o_tmpalloc( bv.bv_len + 1, op->o_tmpmemctx );
1108 ptr = lutil_strcopy( bv.bv_val, "SASL(" );
1109 ptr = lutil_strcopy( ptr, op->orb_tmp_mech.bv_val );
1112 attr_merge_one( e, ad_reqMethod, &bv, NULL );
1113 op->o_tmpfree( bv.bv_val, op->o_tmpmemctx );
1118 case LOG_EN_EXTENDED:
1119 if ( op->ore_reqdata ) {
1120 attr_merge_one( e, ad_reqData, op->ore_reqdata, NULL );
1124 case LOG_EN_UNKNOWN:
1125 /* we don't know its parameters, don't add any */
1129 op2.o_hdr = op->o_hdr;
1130 op2.o_tag = LDAP_REQ_ADD;
1131 op2.o_bd = li->li_db;
1132 op2.o_dn = li->li_db->be_rootdn;
1133 op2.o_ndn = li->li_db->be_rootndn;
1134 op2.o_req_dn = e->e_name;
1135 op2.o_req_ndn = e->e_nname;
1137 op2.o_callback = &nullsc;
1139 if (( lo->mask & LOG_OP_WRITES ) && !BER_BVISEMPTY( &op->o_csn )) {
1140 slap_queue_csn( &op2, &op->o_csn );
1143 op2.o_bd->be_add( &op2, &rs2 );
1146 if ( lo->mask & LOG_OP_WRITES )
1147 ldap_pvt_thread_mutex_unlock( &li->li_log_mutex );
1148 if ( e ) entry_free( e );
1149 if ( old ) entry_free( old );
1150 return SLAP_CB_CONTINUE;
1153 /* Since Bind success is sent by the frontend, it won't normally enter
1154 * the overlay response callback. Add another callback to make sure it
1158 accesslog_bind_resp( Operation *op, SlapReply *rs )
1167 db.bd_info = op->o_callback->sc_private;
1168 rc = accesslog_response( op, rs );
1170 sc = op->o_callback;
1171 op->o_callback = sc->sc_next;
1172 op->o_tmpfree( sc, op->o_tmpmemctx );
1177 accesslog_op_bind( Operation *op, SlapReply *rs )
1181 sc = op->o_tmpcalloc( 1, sizeof(slap_callback), op->o_tmpmemctx );
1182 sc->sc_response = accesslog_bind_resp;
1183 sc->sc_private = op->o_bd->bd_info;
1185 if ( op->o_callback ) {
1186 sc->sc_next = op->o_callback->sc_next;
1187 op->o_callback->sc_next = sc;
1189 op->o_callback = sc;
1191 return SLAP_CB_CONTINUE;
1195 accesslog_op_mod( Operation *op, SlapReply *rs )
1197 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
1198 log_info *li = on->on_bi.bi_private;
1200 if ( li->li_ops & LOG_OP_WRITES ) {
1201 /* FIXME: this needs to be a recursive mutex to allow
1202 * overlays like refint to keep working.
1204 ldap_pvt_thread_mutex_lock( &li->li_op_mutex );
1205 if ( li->li_oldf && ( op->o_tag == LDAP_REQ_DELETE ||
1206 op->o_tag == LDAP_REQ_MODIFY )) {
1210 op->o_bd->bd_info = on->on_info->oi_orig;
1211 rc = be_entry_get_rw( op, &op->o_req_ndn, NULL, NULL, 0, &e );
1213 if ( test_filter( op, e, li->li_oldf ) == LDAP_COMPARE_TRUE )
1214 li->li_old = entry_dup( e );
1215 be_entry_release_rw( op, e, 0 );
1217 op->o_bd->bd_info = (BackendInfo *)on;
1220 return SLAP_CB_CONTINUE;
1223 /* unbinds are broadcast to all backends; we only log it if this
1224 * backend was used for the original bind.
1227 accesslog_unbind( Operation *op, SlapReply *rs )
1229 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
1230 if ( op->o_conn->c_authz_backend == on->on_info->oi_origdb ) {
1231 log_info *li = on->on_bi.bi_private;
1232 Operation op2 = {0};
1233 void *cids[SLAP_MAX_CIDS];
1234 SlapReply rs2 = {REP_RESULT};
1237 if ( !( li->li_ops & LOG_OP_UNBIND ))
1238 return SLAP_CB_CONTINUE;
1240 e = accesslog_entry( op, LOG_EN_UNBIND, &op2 );
1241 op2.o_hdr = op->o_hdr;
1242 op2.o_tag = LDAP_REQ_ADD;
1243 op2.o_bd = li->li_db;
1244 op2.o_dn = li->li_db->be_rootdn;
1245 op2.o_ndn = li->li_db->be_rootndn;
1246 op2.o_req_dn = e->e_name;
1247 op2.o_req_ndn = e->e_nname;
1249 op2.o_callback = &nullsc;
1250 op2.o_controls = cids;
1251 memset(cids, 0, sizeof( cids ));
1253 op2.o_bd->be_add( &op2, &rs2 );
1256 return SLAP_CB_CONTINUE;
1260 accesslog_abandon( Operation *op, SlapReply *rs )
1262 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
1263 log_info *li = on->on_bi.bi_private;
1264 Operation op2 = {0};
1265 void *cids[SLAP_MAX_CIDS];
1266 SlapReply rs2 = {REP_RESULT};
1271 if ( !op->o_time || !( li->li_ops & LOG_OP_ABANDON ))
1272 return SLAP_CB_CONTINUE;
1274 e = accesslog_entry( op, LOG_EN_ABANDON, &op2 );
1276 bv.bv_len = sprintf( buf, "%d", op->orn_msgid );
1277 attr_merge_one( e, ad_reqId, &bv, NULL );
1279 op2.o_hdr = op->o_hdr;
1280 op2.o_tag = LDAP_REQ_ADD;
1281 op2.o_bd = li->li_db;
1282 op2.o_dn = li->li_db->be_rootdn;
1283 op2.o_ndn = li->li_db->be_rootndn;
1284 op2.o_req_dn = e->e_name;
1285 op2.o_req_ndn = e->e_nname;
1287 op2.o_callback = &nullsc;
1288 op2.o_controls = cids;
1289 memset(cids, 0, sizeof( cids ));
1291 op2.o_bd->be_add( &op2, &rs2 );
1294 return SLAP_CB_CONTINUE;
1297 static slap_overinst accesslog;
1304 slap_overinst *on = (slap_overinst *)be->bd_info;
1305 log_info *li = ch_calloc(1, sizeof(log_info));
1307 on->on_bi.bi_private = li;
1308 ldap_pvt_thread_mutex_init( &li->li_op_mutex );
1309 ldap_pvt_thread_mutex_init( &li->li_log_mutex );
1314 accesslog_db_destroy(
1318 slap_overinst *on = (slap_overinst *)be->bd_info;
1319 log_info *li = on->on_bi.bi_private;
1322 filter_free( li->li_oldf );
1323 ldap_pvt_thread_mutex_destroy( &li->li_log_mutex );
1324 ldap_pvt_thread_mutex_destroy( &li->li_op_mutex );
1326 return LDAP_SUCCESS;
1334 slap_overinst *on = (slap_overinst *)be->bd_info;
1335 log_info *li = on->on_bi.bi_private;
1338 OperationBuffer opbuf;
1339 Operation *op = (Operation *) &opbuf;
1344 if ( slapMode & SLAP_TOOL_MODE )
1347 thrctx = ldap_pvt_thread_pool_context();
1348 connection_fake_init( &conn, op, thrctx );
1349 op->o_bd = li->li_db;
1350 op->o_dn = li->li_db->be_rootdn;
1351 op->o_ndn = li->li_db->be_rootndn;
1353 rc = be_entry_get_rw( op, li->li_db->be_nsuffix, NULL, NULL, 0, &e );
1356 be_entry_release_rw( op, e, 0 );
1358 SlapReply rs = {REP_RESULT};
1359 struct berval rdn, nrdn, attr;
1361 AttributeDescription *ad = NULL;
1362 const char *text = NULL;
1365 e = ch_calloc( 1, sizeof( Entry ));
1366 e->e_name = *li->li_db->be_suffix;
1367 e->e_nname = *li->li_db->be_nsuffix;
1369 attr_merge_one( e, slap_schema.si_ad_objectClass,
1370 &log_container->soc_cname, NULL );
1372 dnRdn( &e->e_name, &rdn );
1373 dnRdn( &e->e_nname, &nrdn );
1374 ptr = ber_bvchr( &rdn, '=' );
1376 assert( ptr != NULL );
1378 attr.bv_val = rdn.bv_val;
1379 attr.bv_len = ptr - rdn.bv_val;
1381 slap_bv2ad( &attr, &ad, &text );
1384 rdn.bv_len -= attr.bv_len + 1;
1385 ptr = ber_bvchr( &nrdn, '=' );
1386 nrdn.bv_len -= ptr - nrdn.bv_val + 1;
1387 nrdn.bv_val = ptr+1;
1388 attr_merge_one( e, ad, &rdn, &nrdn );
1390 /* Get contextCSN from main DB */
1392 op->o_bd->bd_info = on->on_info->oi_orig;
1393 rc = be_entry_get_rw( op, be->be_nsuffix, NULL,
1394 slap_schema.si_ad_contextCSN, 0, &e_ctx );
1399 a = attr_find( e_ctx->e_attrs, slap_schema.si_ad_contextCSN );
1401 attr_merge( e, slap_schema.si_ad_entryCSN, a->a_vals, NULL );
1402 attr_merge( e, a->a_desc, a->a_vals, NULL );
1404 be_entry_release_rw( op, e_ctx, 0 );
1406 op->o_bd->bd_info = (BackendInfo *)on;
1407 op->o_bd = li->li_db;
1410 op->o_req_dn = e->e_name;
1411 op->o_req_ndn = e->e_nname;
1412 op->o_callback = &nullsc;
1413 SLAP_DBFLAGS( op->o_bd ) |= SLAP_DBFLAG_NOLASTMOD;
1414 rc = op->o_bd->be_add( op, &rs );
1415 SLAP_DBFLAGS( op->o_bd ) ^= SLAP_DBFLAG_NOLASTMOD;
1416 attrs_free( e->e_attrs );
1419 ldap_pvt_thread_pool_context_reset( thrctx );
1423 int accesslog_initialize()
1427 accesslog.on_bi.bi_type = "accesslog";
1428 accesslog.on_bi.bi_db_init = accesslog_db_init;
1429 accesslog.on_bi.bi_db_destroy = accesslog_db_destroy;
1430 accesslog.on_bi.bi_db_open = accesslog_db_open;
1432 accesslog.on_bi.bi_op_add = accesslog_op_mod;
1433 accesslog.on_bi.bi_op_bind = accesslog_op_bind;
1434 accesslog.on_bi.bi_op_delete = accesslog_op_mod;
1435 accesslog.on_bi.bi_op_modify = accesslog_op_mod;
1436 accesslog.on_bi.bi_op_modrdn = accesslog_op_mod;
1437 accesslog.on_bi.bi_op_unbind = accesslog_unbind;
1438 accesslog.on_bi.bi_op_abandon = accesslog_abandon;
1439 accesslog.on_response = accesslog_response;
1441 accesslog.on_bi.bi_cf_ocs = log_cfocs;
1443 nullsc.sc_response = slap_null_cb;
1445 rc = config_register_schema( log_cfats, log_cfocs );
1446 if ( rc ) return rc;
1448 /* log schema integration */
1449 for ( i=0; lattrs[i].at; i++ ) {
1450 LDAPAttributeType *lat;
1455 lat = ldap_str2attributetype( lattrs[i].at, &code, &err,
1456 LDAP_SCHEMA_ALLOW_ALL );
1458 Debug( LDAP_DEBUG_ANY, "accesslog_init: "
1459 "ldap_str2attributetype failed on %d: %s, %s\n",
1460 i, ldap_scherr2str(code), err );
1463 code = at_add( lat, 0, &at, &err );
1464 ldap_memfree( lat );
1466 Debug( LDAP_DEBUG_ANY, "log_back_initialize: "
1467 "at_add failed on %d: %s\n",
1468 i, scherr2str(code), 0 );
1471 if ( slap_bv2ad( &at->sat_cname, lattrs[i].ad, &err )) {
1472 Debug( LDAP_DEBUG_ANY, "accesslog_init: "
1473 "slap_bv2ad failed on %d: %s\n",
1478 for ( i=0; locs[i].ot; i++ ) {
1479 LDAPObjectClass *loc;
1484 loc = ldap_str2objectclass( locs[i].ot, &code, &err,
1485 LDAP_SCHEMA_ALLOW_ALL );
1487 Debug( LDAP_DEBUG_ANY, "accesslog_init: "
1488 "ldap_str2objectclass failed on %d: %s, %s\n",
1489 i, ldap_scherr2str(code), err );
1493 code = oc_add( loc, 0, &oc, &err );
1494 ldap_memfree( loc );
1496 Debug( LDAP_DEBUG_ANY, "accesslog_init: "
1497 "oc_add failed on %d: %s\n",
1498 i, scherr2str(code), 0 );
1505 return overlay_register(&accesslog);
1508 #if SLAPD_OVER_ACCESSLOG == SLAPD_MOD_DYNAMIC
1510 init_module( int argc, char *argv[] )
1512 return accesslog_initialize();
1516 #endif /* SLAPD_OVER_ACCESSLOG */