1 /* accesslog.c - log operations for audit/history purposes */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2005-2011 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_base {
60 struct log_base *lb_next;
62 struct berval lb_base;
63 struct berval lb_line;
66 typedef struct log_info {
68 struct berval li_db_suffix;
75 log_attr *li_oldattrs;
78 ldap_pvt_thread_rmutex_t li_op_rmutex;
79 ldap_pvt_thread_mutex_t li_log_mutex;
82 static ConfigDriver log_cf_gen;
94 static ConfigTable log_cfats[] = {
95 { "logdb", "suffix", 2, 2, 0, ARG_DN|ARG_MAGIC|LOG_DB,
96 log_cf_gen, "( OLcfgOvAt:4.1 NAME 'olcAccessLogDB' "
97 "DESC 'Suffix of database for log content' "
98 "SUP distinguishedName SINGLE-VALUE )", NULL, NULL },
99 { "logops", "op|writes|reads|session|all", 2, 0, 0,
101 log_cf_gen, "( OLcfgOvAt:4.2 NAME 'olcAccessLogOps' "
102 "DESC 'Operation types to log' "
103 "EQUALITY caseIgnoreMatch "
104 "SYNTAX OMsDirectoryString )", NULL, NULL },
105 { "logpurge", "age> <interval", 3, 3, 0, ARG_MAGIC|LOG_PURGE,
106 log_cf_gen, "( OLcfgOvAt:4.3 NAME 'olcAccessLogPurge' "
107 "DESC 'Log cleanup parameters' "
108 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
109 { "logsuccess", NULL, 2, 2, 0, ARG_MAGIC|ARG_ON_OFF|LOG_SUCCESS,
110 log_cf_gen, "( OLcfgOvAt:4.4 NAME 'olcAccessLogSuccess' "
111 "DESC 'Log successful ops only' "
112 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
113 { "logold", "filter", 2, 2, 0, ARG_MAGIC|LOG_OLD,
114 log_cf_gen, "( OLcfgOvAt:4.5 NAME 'olcAccessLogOld' "
115 "DESC 'Log old values when modifying entries matching the filter' "
116 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
117 { "logoldattr", "attrs", 2, 0, 0, ARG_MAGIC|LOG_OLDATTR,
118 log_cf_gen, "( OLcfgOvAt:4.6 NAME 'olcAccessLogOldAttr' "
119 "DESC 'Log old values of these attributes even if unmodified' "
120 "EQUALITY caseIgnoreMatch "
121 "SYNTAX OMsDirectoryString )", NULL, NULL },
122 { "logbase", "op|writes|reads|session|all< <baseDN", 3, 3, 0,
124 log_cf_gen, "( OLcfgOvAt:4.7 NAME 'olcAccessLogBase' "
125 "DESC 'Operation types to log under a specific branch' "
126 "EQUALITY caseIgnoreMatch "
127 "SYNTAX OMsDirectoryString )", NULL, NULL },
131 static ConfigOCs log_cfocs[] = {
133 "NAME 'olcAccessLogConfig' "
134 "DESC 'Access log configuration' "
135 "SUP olcOverlayConfig "
136 "MUST olcAccessLogDB "
137 "MAY ( olcAccessLogOps $ olcAccessLogPurge $ olcAccessLogSuccess $ "
138 "olcAccessLogOld $ olcAccessLogOldAttr $ olcAccessLogBase ) )",
139 Cft_Overlay, log_cfats },
143 static slap_verbmasks logops[] = {
144 { BER_BVC("all"), LOG_OP_ALL },
145 { BER_BVC("writes"), LOG_OP_WRITES },
146 { BER_BVC("session"), LOG_OP_SESSION },
147 { BER_BVC("reads"), LOG_OP_READS },
148 { BER_BVC("add"), LOG_OP_ADD },
149 { BER_BVC("delete"), LOG_OP_DELETE },
150 { BER_BVC("modify"), LOG_OP_MODIFY },
151 { BER_BVC("modrdn"), LOG_OP_MODRDN },
152 { BER_BVC("compare"), LOG_OP_COMPARE },
153 { BER_BVC("search"), LOG_OP_SEARCH },
154 { BER_BVC("bind"), LOG_OP_BIND },
155 { BER_BVC("unbind"), LOG_OP_UNBIND },
156 { BER_BVC("abandon"), LOG_OP_ABANDON },
157 { BER_BVC("extended"), LOG_OP_EXTENDED },
158 { BER_BVC("unknown"), LOG_OP_UNKNOWN },
162 /* Start with "add" in logops */
180 static ObjectClass *log_ocs[LOG_EN__COUNT], *log_container,
181 *log_oc_read, *log_oc_write;
183 #define LOG_SCHEMA_ROOT "1.3.6.1.4.1.4203.666.11.5"
185 #define LOG_SCHEMA_AT LOG_SCHEMA_ROOT ".1"
186 #define LOG_SCHEMA_OC LOG_SCHEMA_ROOT ".2"
187 #define LOG_SCHEMA_SYN LOG_SCHEMA_ROOT ".3"
189 static AttributeDescription *ad_reqDN, *ad_reqStart, *ad_reqEnd, *ad_reqType,
190 *ad_reqSession, *ad_reqResult, *ad_reqAuthzID, *ad_reqControls,
191 *ad_reqRespControls, *ad_reqMethod, *ad_reqAssertion, *ad_reqNewRDN,
192 *ad_reqNewSuperior, *ad_reqDeleteOldRDN, *ad_reqMod,
193 *ad_reqScope, *ad_reqFilter, *ad_reqAttr, *ad_reqEntries,
194 *ad_reqSizeLimit, *ad_reqTimeLimit, *ad_reqAttrsOnly, *ad_reqData,
195 *ad_reqId, *ad_reqMessage, *ad_reqVersion, *ad_reqDerefAliases,
196 *ad_reqReferral, *ad_reqOld, *ad_auditContext;
199 logSchemaControlValidate(
201 struct berval *val );
203 char *mrControl[] = {
204 "objectIdentifierFirstComponentMatch",
210 slap_syntax_defs_rec syn;
213 { LOG_SCHEMA_SYN ".1" ,
214 { "( " LOG_SCHEMA_SYN ".1 DESC 'Control' )",
217 logSchemaControlValidate,
225 AttributeDescription **ad;
227 { "( " LOG_SCHEMA_AT ".1 NAME 'reqDN' "
228 "DESC 'Target DN of request' "
229 "EQUALITY distinguishedNameMatch "
231 "SINGLE-VALUE )", &ad_reqDN },
232 { "( " LOG_SCHEMA_AT ".2 NAME 'reqStart' "
233 "DESC 'Start time of request' "
234 "EQUALITY generalizedTimeMatch "
235 "ORDERING generalizedTimeOrderingMatch "
236 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 "
237 "SINGLE-VALUE )", &ad_reqStart },
238 { "( " LOG_SCHEMA_AT ".3 NAME 'reqEnd' "
239 "DESC 'End time of request' "
240 "EQUALITY generalizedTimeMatch "
241 "ORDERING generalizedTimeOrderingMatch "
242 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 "
243 "SINGLE-VALUE )", &ad_reqEnd },
244 { "( " LOG_SCHEMA_AT ".4 NAME 'reqType' "
245 "DESC 'Type of request' "
246 "EQUALITY caseIgnoreMatch "
247 "SYNTAX OMsDirectoryString "
248 "SINGLE-VALUE )", &ad_reqType },
249 { "( " LOG_SCHEMA_AT ".5 NAME 'reqSession' "
250 "DESC 'Session ID of request' "
251 "EQUALITY caseIgnoreMatch "
252 "SYNTAX OMsDirectoryString "
253 "SINGLE-VALUE )", &ad_reqSession },
254 { "( " LOG_SCHEMA_AT ".6 NAME 'reqAuthzID' "
255 "DESC 'Authorization ID of requestor' "
256 "EQUALITY distinguishedNameMatch "
258 "SINGLE-VALUE )", &ad_reqAuthzID },
259 { "( " LOG_SCHEMA_AT ".7 NAME 'reqResult' "
260 "DESC 'Result code of request' "
261 "EQUALITY integerMatch "
262 "ORDERING integerOrderingMatch "
264 "SINGLE-VALUE )", &ad_reqResult },
265 { "( " LOG_SCHEMA_AT ".8 NAME 'reqMessage' "
266 "DESC 'Error text of request' "
267 "EQUALITY caseIgnoreMatch "
268 "SUBSTR caseIgnoreSubstringsMatch "
269 "SYNTAX OMsDirectoryString "
270 "SINGLE-VALUE )", &ad_reqMessage },
271 { "( " LOG_SCHEMA_AT ".9 NAME 'reqReferral' "
272 "DESC 'Referrals returned for request' "
273 "SUP labeledURI )", &ad_reqReferral },
274 { "( " LOG_SCHEMA_AT ".10 NAME 'reqControls' "
275 "DESC 'Request controls' "
276 "EQUALITY objectIdentifierFirstComponentMatch "
277 "SYNTAX " LOG_SCHEMA_SYN ".1 "
278 "X-ORDERED 'VALUES' )", &ad_reqControls },
279 { "( " LOG_SCHEMA_AT ".11 NAME 'reqRespControls' "
280 "DESC 'Response controls of request' "
281 "EQUALITY objectIdentifierFirstComponentMatch "
282 "SYNTAX " LOG_SCHEMA_SYN ".1 "
283 "X-ORDERED 'VALUES' )", &ad_reqRespControls },
284 { "( " LOG_SCHEMA_AT ".12 NAME 'reqId' "
285 "DESC 'ID of Request to Abandon' "
286 "EQUALITY integerMatch "
287 "ORDERING integerOrderingMatch "
289 "SINGLE-VALUE )", &ad_reqId },
290 { "( " LOG_SCHEMA_AT ".13 NAME 'reqVersion' "
291 "DESC 'Protocol version of Bind request' "
292 "EQUALITY integerMatch "
293 "ORDERING integerOrderingMatch "
295 "SINGLE-VALUE )", &ad_reqVersion },
296 { "( " LOG_SCHEMA_AT ".14 NAME 'reqMethod' "
297 "DESC 'Bind method of request' "
298 "EQUALITY caseIgnoreMatch "
299 "SYNTAX OMsDirectoryString "
300 "SINGLE-VALUE )", &ad_reqMethod },
301 { "( " LOG_SCHEMA_AT ".15 NAME 'reqAssertion' "
302 "DESC 'Compare Assertion of request' "
303 "SYNTAX OMsDirectoryString "
304 "SINGLE-VALUE )", &ad_reqAssertion },
305 { "( " LOG_SCHEMA_AT ".16 NAME 'reqMod' "
306 "DESC 'Modifications of request' "
307 "EQUALITY octetStringMatch "
308 "SUBSTR octetStringSubstringsMatch "
309 "SYNTAX OMsOctetString )", &ad_reqMod },
310 { "( " LOG_SCHEMA_AT ".17 NAME 'reqOld' "
311 "DESC 'Old values of entry before request completed' "
312 "EQUALITY octetStringMatch "
313 "SUBSTR octetStringSubstringsMatch "
314 "SYNTAX OMsOctetString )", &ad_reqOld },
315 { "( " LOG_SCHEMA_AT ".18 NAME 'reqNewRDN' "
316 "DESC 'New RDN of request' "
317 "EQUALITY distinguishedNameMatch "
319 "SINGLE-VALUE )", &ad_reqNewRDN },
320 { "( " LOG_SCHEMA_AT ".19 NAME 'reqDeleteOldRDN' "
321 "DESC 'Delete old RDN' "
322 "EQUALITY booleanMatch "
324 "SINGLE-VALUE )", &ad_reqDeleteOldRDN },
325 { "( " LOG_SCHEMA_AT ".20 NAME 'reqNewSuperior' "
326 "DESC 'New superior DN of request' "
327 "EQUALITY distinguishedNameMatch "
329 "SINGLE-VALUE )", &ad_reqNewSuperior },
330 { "( " LOG_SCHEMA_AT ".21 NAME 'reqScope' "
331 "DESC 'Scope of request' "
332 "EQUALITY caseIgnoreMatch "
333 "SYNTAX OMsDirectoryString "
334 "SINGLE-VALUE )", &ad_reqScope },
335 { "( " LOG_SCHEMA_AT ".22 NAME 'reqDerefAliases' "
336 "DESC 'Disposition of Aliases in request' "
337 "EQUALITY caseIgnoreMatch "
338 "SYNTAX OMsDirectoryString "
339 "SINGLE-VALUE )", &ad_reqDerefAliases },
340 { "( " LOG_SCHEMA_AT ".23 NAME 'reqAttrsOnly' "
341 "DESC 'Attributes and values of request' "
342 "EQUALITY booleanMatch "
344 "SINGLE-VALUE )", &ad_reqAttrsOnly },
345 { "( " LOG_SCHEMA_AT ".24 NAME 'reqFilter' "
346 "DESC 'Filter of request' "
347 "EQUALITY caseIgnoreMatch "
348 "SUBSTR caseIgnoreSubstringsMatch "
349 "SYNTAX OMsDirectoryString "
350 "SINGLE-VALUE )", &ad_reqFilter },
351 { "( " LOG_SCHEMA_AT ".25 NAME 'reqAttr' "
352 "DESC 'Attributes of request' "
353 "EQUALITY caseIgnoreMatch "
354 "SYNTAX OMsDirectoryString )", &ad_reqAttr },
355 { "( " LOG_SCHEMA_AT ".26 NAME 'reqSizeLimit' "
356 "DESC 'Size limit of request' "
357 "EQUALITY integerMatch "
358 "ORDERING integerOrderingMatch "
360 "SINGLE-VALUE )", &ad_reqSizeLimit },
361 { "( " LOG_SCHEMA_AT ".27 NAME 'reqTimeLimit' "
362 "DESC 'Time limit of request' "
363 "EQUALITY integerMatch "
364 "ORDERING integerOrderingMatch "
366 "SINGLE-VALUE )", &ad_reqTimeLimit },
367 { "( " LOG_SCHEMA_AT ".28 NAME 'reqEntries' "
368 "DESC 'Number of entries returned' "
369 "EQUALITY integerMatch "
370 "ORDERING integerOrderingMatch "
372 "SINGLE-VALUE )", &ad_reqEntries },
373 { "( " LOG_SCHEMA_AT ".29 NAME 'reqData' "
374 "DESC 'Data of extended request' "
375 "EQUALITY octetStringMatch "
376 "SUBSTR octetStringSubstringsMatch "
377 "SYNTAX OMsOctetString "
378 "SINGLE-VALUE )", &ad_reqData },
381 * from <draft-chu-ldap-logschema-01.txt>:
384 ( LOG_SCHEMA_AT .30 NAME 'auditContext'
385 DESC 'DN of auditContainer'
386 EQUALITY distinguishedNameMatch
387 SYNTAX 1.3.6.1.4.1.1466.115.121.1.12
388 SINGLE-VALUE NO-USER-MODIFICATION USAGE directoryOperation )
390 * - removed EQUALITY matchingRule
391 * - changed directoryOperation in dSAOperation
393 { "( " LOG_SCHEMA_AT ".30 NAME 'auditContext' "
394 "DESC 'DN of auditContainer' "
395 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
397 "NO-USER-MODIFICATION "
398 "USAGE dSAOperation )", &ad_auditContext },
406 { "( " LOG_SCHEMA_OC ".0 NAME 'auditContainer' "
407 "DESC 'AuditLog container' "
408 "SUP top STRUCTURAL "
409 "MAY ( cn $ reqStart $ reqEnd ) )", &log_container },
410 { "( " LOG_SCHEMA_OC ".1 NAME 'auditObject' "
411 "DESC 'OpenLDAP request auditing' "
412 "SUP top STRUCTURAL "
413 "MUST ( reqStart $ reqType $ reqSession ) "
414 "MAY ( reqDN $ reqAuthzID $ reqControls $ reqRespControls $ reqEnd $ "
415 "reqResult $ reqMessage $ reqReferral ) )",
416 &log_ocs[LOG_EN_UNBIND] },
417 { "( " LOG_SCHEMA_OC ".2 NAME 'auditReadObject' "
418 "DESC 'OpenLDAP read request record' "
419 "SUP auditObject STRUCTURAL )", &log_oc_read },
420 { "( " LOG_SCHEMA_OC ".3 NAME 'auditWriteObject' "
421 "DESC 'OpenLDAP write request record' "
422 "SUP auditObject STRUCTURAL )", &log_oc_write },
423 { "( " LOG_SCHEMA_OC ".4 NAME 'auditAbandon' "
424 "DESC 'Abandon operation' "
425 "SUP auditObject STRUCTURAL "
426 "MUST reqId )", &log_ocs[LOG_EN_ABANDON] },
427 { "( " LOG_SCHEMA_OC ".5 NAME 'auditAdd' "
428 "DESC 'Add operation' "
429 "SUP auditWriteObject STRUCTURAL "
430 "MUST reqMod )", &log_ocs[LOG_EN_ADD] },
431 { "( " LOG_SCHEMA_OC ".6 NAME 'auditBind' "
432 "DESC 'Bind operation' "
433 "SUP auditObject STRUCTURAL "
434 "MUST ( reqVersion $ reqMethod ) )", &log_ocs[LOG_EN_BIND] },
435 { "( " LOG_SCHEMA_OC ".7 NAME 'auditCompare' "
436 "DESC 'Compare operation' "
437 "SUP auditReadObject STRUCTURAL "
438 "MUST reqAssertion )", &log_ocs[LOG_EN_COMPARE] },
439 { "( " LOG_SCHEMA_OC ".8 NAME 'auditDelete' "
440 "DESC 'Delete operation' "
441 "SUP auditWriteObject STRUCTURAL "
442 "MAY reqOld )", &log_ocs[LOG_EN_DELETE] },
443 { "( " LOG_SCHEMA_OC ".9 NAME 'auditModify' "
444 "DESC 'Modify operation' "
445 "SUP auditWriteObject STRUCTURAL "
446 "MAY reqOld MUST reqMod )", &log_ocs[LOG_EN_MODIFY] },
447 { "( " LOG_SCHEMA_OC ".10 NAME 'auditModRDN' "
448 "DESC 'ModRDN operation' "
449 "SUP auditWriteObject STRUCTURAL "
450 "MUST ( reqNewRDN $ reqDeleteOldRDN ) "
451 "MAY ( reqNewSuperior $ reqMod $ reqOld ) )", &log_ocs[LOG_EN_MODRDN] },
452 { "( " LOG_SCHEMA_OC ".11 NAME 'auditSearch' "
453 "DESC 'Search operation' "
454 "SUP auditReadObject STRUCTURAL "
455 "MUST ( reqScope $ reqDerefAliases $ reqAttrsonly ) "
456 "MAY ( reqFilter $ reqAttr $ reqEntries $ reqSizeLimit $ "
457 "reqTimeLimit ) )", &log_ocs[LOG_EN_SEARCH] },
458 { "( " LOG_SCHEMA_OC ".12 NAME 'auditExtended' "
459 "DESC 'Extended operation' "
460 "SUP auditObject STRUCTURAL "
461 "MAY reqData )", &log_ocs[LOG_EN_EXTENDED] },
465 #define RDNEQ "reqStart="
467 /* Our time intervals are of the form [ddd+]hh:mm[:ss]
468 * If a field is present, it must be two digits. (Except for
469 * days, which can be arbitrary width.)
472 log_age_parse(char *agestr)
478 t1 = strtol( agestr, &endptr, 10 );
479 /* Is there a days delimiter? */
480 if ( *endptr == '+' ) {
481 /* 32 bit time only covers about 68 years */
482 if ( t1 < 0 || t1 > 25000 )
488 if ( agestr[2] != ':' ) {
489 /* No valid delimiter found, fail */
500 /* if there's a delimiter, it can only be a colon */
501 if ( agestr[2] != ':' )
504 /* If we're at the end of the string, and we started with days,
505 * fail because we expected to find minutes too.
507 return gotdays ? -1 : t1 * 60;
513 /* last field can only be seconds */
514 if ( agestr[2] && ( agestr[2] != ':' || !gotdays ))
524 t1 += atoi( agestr );
525 } else if ( gotdays ) {
526 /* only got days+hh:mm */
533 log_age_unparse( int age, struct berval *agebv, size_t size )
535 int dd, hh, mm, ss, len;
551 len = snprintf( ptr, size, "%d+", dd );
552 assert( len >= 0 && (unsigned) len < size );
556 len = snprintf( ptr, size, "%02d:%02d", hh, mm );
557 assert( len >= 0 && (unsigned) len < size );
561 len = snprintf( ptr, size, ":%02d", ss );
562 assert( len >= 0 && (unsigned) len < size );
567 agebv->bv_len = ptr - agebv->bv_val;
570 static slap_callback nullsc = { NULL, NULL, NULL, NULL };
572 #define PURGE_INCREMENT 100
574 typedef struct purge_data {
579 struct berval csn; /* an arbitrary old CSN */
583 log_old_lookup( Operation *op, SlapReply *rs )
585 purge_data *pd = op->o_callback->sc_private;
588 if ( rs->sr_type != REP_SEARCH) return 0;
590 if ( slapd_shutdown ) return 0;
592 /* Remember max CSN: should always be the last entry
593 * seen, since log entries are ordered chronologically...
595 a = attr_find( rs->sr_entry->e_attrs,
596 slap_schema.si_ad_entryCSN );
598 ber_len_t len = a->a_nvals[0].bv_len;
599 /* Paranoid len check, normalized CSNs are always the same length */
600 if ( len > LDAP_PVT_CSNSTR_BUFSIZE )
601 len = LDAP_PVT_CSNSTR_BUFSIZE;
602 if ( memcmp( a->a_nvals[0].bv_val, pd->csn.bv_val, len ) > 0 ) {
603 AC_MEMCPY( pd->csn.bv_val, a->a_nvals[0].bv_val, len );
604 pd->csn.bv_len = len;
607 if ( pd->used >= pd->slots ) {
608 pd->slots += PURGE_INCREMENT;
609 pd->dn = ch_realloc( pd->dn, pd->slots * sizeof( struct berval ));
610 pd->ndn = ch_realloc( pd->ndn, pd->slots * sizeof( struct berval ));
612 ber_dupbv( &pd->dn[pd->used], &rs->sr_entry->e_name );
613 ber_dupbv( &pd->ndn[pd->used], &rs->sr_entry->e_nname );
618 /* Periodically search for old entries in the log database and delete them */
620 accesslog_purge( void *ctx, void *arg )
622 struct re_s *rtask = arg;
623 struct log_info *li = rtask->arg;
625 Connection conn = {0};
626 OperationBuffer opbuf;
628 SlapReply rs = {REP_RESULT};
629 slap_callback cb = { NULL, log_old_lookup, NULL, NULL };
631 AttributeAssertion ava = ATTRIBUTEASSERTION_INIT;
633 char timebuf[LDAP_LUTIL_GENTIME_BUFSIZE];
634 char csnbuf[LDAP_PVT_CSNSTR_BUFSIZE];
635 time_t old = slap_get_time();
637 connection_fake_init( &conn, &opbuf, ctx );
640 f.f_choice = LDAP_FILTER_LE;
644 ava.aa_desc = ad_reqStart;
645 ava.aa_value.bv_val = timebuf;
646 ava.aa_value.bv_len = sizeof(timebuf);
649 slap_timestamp( &old, &ava.aa_value );
651 op->o_tag = LDAP_REQ_SEARCH;
652 op->o_bd = li->li_db;
653 op->o_dn = li->li_db->be_rootdn;
654 op->o_ndn = li->li_db->be_rootndn;
655 op->o_req_dn = li->li_db->be_suffix[0];
656 op->o_req_ndn = li->li_db->be_nsuffix[0];
657 op->o_callback = &cb;
658 op->ors_scope = LDAP_SCOPE_ONELEVEL;
659 op->ors_deref = LDAP_DEREF_NEVER;
660 op->ors_tlimit = SLAP_NO_LIMIT;
661 op->ors_slimit = SLAP_NO_LIMIT;
663 filter2bv_x( op, &f, &op->ors_filterstr );
664 op->ors_attrs = slap_anlist_no_attrs;
665 op->ors_attrsonly = 1;
667 pd.csn.bv_len = sizeof( csnbuf );
668 pd.csn.bv_val = csnbuf;
672 op->o_bd->be_search( op, &rs );
673 op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
678 /* delete the expired entries */
679 op->o_tag = LDAP_REQ_DELETE;
680 op->o_callback = &nullsc;
682 op->o_dont_replicate = 1;
684 for (i=0; i<pd.used; i++) {
685 op->o_req_dn = pd.dn[i];
686 op->o_req_ndn = pd.ndn[i];
687 if ( !slapd_shutdown ) {
688 rs_reinit( &rs, REP_RESULT );
689 op->o_bd->be_delete( op, &rs );
691 ch_free( pd.ndn[i].bv_val );
692 ch_free( pd.dn[i].bv_val );
700 rs_reinit( &rs, REP_RESULT );
701 /* update context's entryCSN to reflect oldest CSN */
706 mod.sml_nvalues = NULL;
707 mod.sml_desc = slap_schema.si_ad_entryCSN;
708 mod.sml_op = LDAP_MOD_REPLACE;
709 mod.sml_flags = SLAP_MOD_INTERNAL;
712 op->o_tag = LDAP_REQ_MODIFY;
713 op->orm_modlist = &mod;
714 op->orm_no_opattrs = 1;
715 op->o_req_dn = li->li_db->be_suffix[0];
716 op->o_req_ndn = li->li_db->be_nsuffix[0];
717 op->o_no_schema_check = 1;
718 op->o_managedsait = SLAP_CONTROL_NONCRITICAL;
719 op->o_bd->be_modify( op, &rs );
720 if ( mod.sml_next ) {
721 slap_mods_free( mod.sml_next, 1 );
726 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
727 ldap_pvt_runqueue_stoptask( &slapd_rq, rtask );
728 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
734 log_cf_gen(ConfigArgs *c)
736 slap_overinst *on = (slap_overinst *)c->bi;
737 struct log_info *li = on->on_bi.bi_private;
739 slap_mask_t tmask = 0;
740 char agebuf[2*STRLENOF("ddddd+hh:mm:ss ")];
741 struct berval agebv, cyclebv;
744 case SLAP_CONFIG_EMIT:
747 if ( !BER_BVISEMPTY( &li->li_db_suffix )) {
748 value_add_one( &c->rvalue_vals, &li->li_db_suffix );
749 value_add_one( &c->rvalue_nvals, &li->li_db_suffix );
750 } else if ( li->li_db ) {
751 value_add_one( &c->rvalue_vals, li->li_db->be_suffix );
752 value_add_one( &c->rvalue_nvals, li->li_db->be_nsuffix );
754 snprintf( c->cr_msg, sizeof( c->cr_msg ),
755 "accesslog: \"logdb <suffix>\" must be specified" );
756 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
757 c->log, c->cr_msg, c->value_dn.bv_val );
763 rc = mask_to_verbs( logops, li->li_ops, &c->rvalue_vals );
770 agebv.bv_val = agebuf;
771 log_age_unparse( li->li_age, &agebv, sizeof( agebuf ) );
772 agebv.bv_val[agebv.bv_len] = ' ';
774 cyclebv.bv_val = agebv.bv_val + agebv.bv_len;
775 log_age_unparse( li->li_cycle, &cyclebv, sizeof( agebuf ) - agebv.bv_len );
776 agebv.bv_len += cyclebv.bv_len;
777 value_add_one( &c->rvalue_vals, &agebv );
780 if ( li->li_success )
781 c->value_int = li->li_success;
787 filter2bv( li->li_oldf, &agebv );
788 ber_bvarray_add( &c->rvalue_vals, &agebv );
794 if ( li->li_oldattrs ) {
797 for ( la = li->li_oldattrs; la; la=la->next )
798 value_add_one( &c->rvalue_vals, &la->attr->ad_cname );
804 if ( li->li_bases ) {
807 for ( lb = li->li_bases; lb; lb=lb->lb_next )
808 value_add_one( &c->rvalue_vals, &lb->lb_line );
815 case LDAP_MOD_DELETE:
818 /* noop. this should always be a valid backend. */
824 rc = verbs_to_mask( 1, &c->line, logops, &tmask );
826 li->li_ops &= ~tmask;
831 struct re_s *re = li->li_task;
833 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
834 if ( ldap_pvt_runqueue_isrunning( &slapd_rq, re ))
835 ldap_pvt_runqueue_stoptask( &slapd_rq, re );
836 ldap_pvt_runqueue_remove( &slapd_rq, re );
837 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
847 filter_free( li->li_oldf );
855 for ( la = li->li_oldattrs; la; la = ln ) {
860 log_attr *la = NULL, **lp;
863 for ( lp = &li->li_oldattrs, i=0; i < c->valx; i++ ) {
875 for ( lb = li->li_bases; lb; lb = ln ) {
880 log_base *lb = NULL, **lp;
883 for ( lp = &li->li_bases, i=0; i < c->valx; i++ ) {
896 if ( CONFIG_ONLINE_ADD( c )) {
897 li->li_db = select_backend( &c->value_ndn, 0 );
899 snprintf( c->cr_msg, sizeof( c->cr_msg ),
900 "<%s> no matching backend found for suffix",
902 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
903 c->log, c->cr_msg, c->value_dn.bv_val );
906 ch_free( c->value_ndn.bv_val );
908 li->li_db_suffix = c->value_ndn;
910 ch_free( c->value_dn.bv_val );
913 rc = verbs_to_mask( c->argc, c->argv, logops, &tmask );
918 li->li_age = log_age_parse( c->argv[1] );
919 if ( li->li_age < 1 ) {
922 li->li_cycle = log_age_parse( c->argv[2] );
923 if ( li->li_cycle < 1 ) {
925 } else if ( slapMode & SLAP_SERVER_MODE ) {
926 struct re_s *re = li->li_task;
928 re->interval.tv_sec = li->li_cycle;
930 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
931 li->li_task = ldap_pvt_runqueue_insert( &slapd_rq,
932 li->li_cycle, accesslog_purge, li,
933 "accesslog_purge", li->li_db ?
934 li->li_db->be_suffix[0].bv_val :
935 c->be->be_suffix[0].bv_val );
936 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
942 li->li_success = c->value_int;
945 li->li_oldf = str2filter( c->argv[1] );
946 if ( !li->li_oldf ) {
947 snprintf( c->cr_msg, sizeof( c->cr_msg ), "bad filter!" );
953 AttributeDescription *ad;
956 for ( i=1; i< c->argc; i++ ) {
958 if ( slap_str2ad( c->argv[i], &ad, &text ) == LDAP_SUCCESS ) {
959 log_attr *la = ch_malloc( sizeof( log_attr ));
961 la->next = li->li_oldattrs;
962 li->li_oldattrs = la;
964 snprintf( c->cr_msg, sizeof( c->cr_msg ), "%s <%s>: %s",
965 c->argv[0], c->argv[i], text );
966 Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
967 "%s: %s\n", c->log, c->cr_msg, 0 );
976 rc = verbstring_to_mask( logops, c->argv[1], '|', &m );
978 struct berval dn, ndn;
979 ber_str2bv( c->argv[2], 0, 0, &dn );
980 rc = dnNormalize( 0, NULL, NULL, &dn, &ndn, NULL );
985 mask_to_verbstring( logops, m, '|', &mbv );
986 lb = ch_malloc( sizeof( log_base ) + mbv.bv_len + ndn.bv_len + 3 + 1 );
987 lb->lb_line.bv_val = (char *)(lb + 1);
988 lb->lb_line.bv_len = mbv.bv_len + ndn.bv_len + 3;
989 ptr = lutil_strcopy( lb->lb_line.bv_val, mbv.bv_val );
992 lb->lb_base.bv_val = ptr;
993 lb->lb_base.bv_len = ndn.bv_len;
994 ptr = lutil_strcopy( ptr, ndn.bv_val );
997 lb->lb_next = li->li_bases;
1000 snprintf( c->cr_msg, sizeof( c->cr_msg ), "%s invalid DN: %s",
1001 c->argv[0], c->argv[2] );
1002 Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
1003 "%s: %s\n", c->log, c->cr_msg, 0 );
1006 snprintf( c->cr_msg, sizeof( c->cr_msg ), "%s invalid ops: %s",
1007 c->argv[0], c->argv[1] );
1008 Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
1009 "%s: %s\n", c->log, c->cr_msg, 0 );
1021 logSchemaControlValidate(
1023 struct berval *valp )
1025 struct berval val, bv;
1027 int rc = LDAP_SUCCESS;
1029 assert( valp != NULL );
1033 /* check minimal size */
1034 if ( val.bv_len < STRLENOF( "{*}" ) ) {
1035 return LDAP_INVALID_SYNTAX;
1040 /* check SEQUENCE boundaries */
1041 if ( val.bv_val[ 0 ] != '{' /*}*/ ||
1042 val.bv_val[ val.bv_len ] != /*{*/ '}' )
1044 return LDAP_INVALID_SYNTAX;
1047 /* extract and check OID */
1048 for ( i = 1; i < val.bv_len; i++ ) {
1049 if ( !ASCII_SPACE( val.bv_val[ i ] ) ) {
1054 bv.bv_val = &val.bv_val[ i ];
1056 for ( i++; i < val.bv_len; i++ ) {
1057 if ( ASCII_SPACE( val.bv_val[ i ] ) )
1063 bv.bv_len = &val.bv_val[ i ] - bv.bv_val;
1065 rc = numericoidValidate( NULL, &bv );
1066 if ( rc != LDAP_SUCCESS ) {
1070 if ( i == val.bv_len ) {
1071 return LDAP_SUCCESS;
1074 if ( val.bv_val[ i ] != ' ' ) {
1075 return LDAP_INVALID_SYNTAX;
1078 for ( i++; i < val.bv_len; i++ ) {
1079 if ( !ASCII_SPACE( val.bv_val[ i ] ) ) {
1084 if ( i == val.bv_len ) {
1085 return LDAP_SUCCESS;
1088 /* extract and check criticality */
1089 if ( strncasecmp( &val.bv_val[ i ], "criticality ", STRLENOF( "criticality " ) ) == 0 )
1091 i += STRLENOF( "criticality " );
1092 for ( ; i < val.bv_len; i++ ) {
1093 if ( !ASCII_SPACE( val.bv_val[ i ] ) ) {
1098 if ( i == val.bv_len ) {
1099 return LDAP_INVALID_SYNTAX;
1102 bv.bv_val = &val.bv_val[ i ];
1104 for ( ; i < val.bv_len; i++ ) {
1105 if ( ASCII_SPACE( val.bv_val[ i ] ) ) {
1110 bv.bv_len = &val.bv_val[ i ] - bv.bv_val;
1112 if ( !bvmatch( &bv, &slap_true_bv ) && !bvmatch( &bv, &slap_false_bv ) )
1114 return LDAP_INVALID_SYNTAX;
1117 if ( i == val.bv_len ) {
1118 return LDAP_SUCCESS;
1121 if ( val.bv_val[ i ] != ' ' ) {
1122 return LDAP_INVALID_SYNTAX;
1125 for ( i++; i < val.bv_len; i++ ) {
1126 if ( !ASCII_SPACE( val.bv_val[ i ] ) ) {
1131 if ( i == val.bv_len ) {
1132 return LDAP_SUCCESS;
1136 /* extract and check controlValue */
1137 if ( strncasecmp( &val.bv_val[ i ], "controlValue ", STRLENOF( "controlValue " ) ) == 0 )
1139 ber_len_t valueStart, valueLen;
1141 i += STRLENOF( "controlValue " );
1142 for ( ; i < val.bv_len; i++ ) {
1143 if ( !ASCII_SPACE( val.bv_val[ i ] ) ) {
1148 if ( i == val.bv_len ) {
1149 return LDAP_INVALID_SYNTAX;
1152 if ( val.bv_val[ i ] != '"' ) {
1153 return LDAP_INVALID_SYNTAX;
1159 for ( ; i < val.bv_len; i++ ) {
1160 if ( val.bv_val[ i ] == '"' ) {
1164 if ( !ASCII_HEX( val.bv_val[ i ] ) ) {
1165 return LDAP_INVALID_SYNTAX;
1169 if ( val.bv_val[ i ] != '"' ) {
1170 return LDAP_INVALID_SYNTAX;
1173 valueLen = i - valueStart;
1174 if ( (valueLen/2)*2 != valueLen ) {
1175 return LDAP_INVALID_SYNTAX;
1178 for ( i++; i < val.bv_len; i++ ) {
1179 if ( !ASCII_SPACE( val.bv_val[ i ] ) ) {
1184 if ( i == val.bv_len ) {
1185 return LDAP_SUCCESS;
1189 return LDAP_INVALID_SYNTAX;
1194 LDAPControl **ctrls,
1201 assert( valsp != NULL );
1202 assert( ctrls != NULL );
1207 for ( i = 0; ctrls[ i ] != NULL; i++ ) {
1215 if ( ctrls[ i ]->ldctl_oid == NULL ) {
1216 return LDAP_PROTOCOL_ERROR;
1219 idx.bv_len = snprintf( buf, sizeof( buf ), "{%ld}", i );
1222 ber_str2bv( ctrls[ i ]->ldctl_oid, 0, 0, &oid );
1223 noid.bv_len = idx.bv_len + oid.bv_len;
1224 ptr = noid.bv_val = ber_memalloc_x( noid.bv_len + 1, memctx );
1225 ptr = lutil_strcopy( ptr, idx.bv_val );
1226 ptr = lutil_strcopy( ptr, oid.bv_val );
1228 bv.bv_len = idx.bv_len + STRLENOF( "{}" ) + oid.bv_len;
1230 if ( ctrls[ i ]->ldctl_iscritical ) {
1231 bv.bv_len += STRLENOF( " criticality TRUE" );
1234 if ( !BER_BVISNULL( &ctrls[ i ]->ldctl_value ) ) {
1235 bv.bv_len += STRLENOF( " controlValue \"\"" )
1236 + 2 * ctrls[ i ]->ldctl_value.bv_len;
1239 ptr = bv.bv_val = ber_memalloc_x( bv.bv_len + 1, memctx );
1240 if ( ptr == NULL ) {
1241 ber_bvarray_free( *valsp );
1243 ber_bvarray_free( *nvalsp );
1248 ptr = lutil_strcopy( ptr, idx.bv_val );
1250 *ptr++ = '{' /*}*/ ;
1251 ptr = lutil_strcopy( ptr, oid.bv_val );
1253 if ( ctrls[ i ]->ldctl_iscritical ) {
1254 ptr = lutil_strcopy( ptr, " criticality TRUE" );
1257 if ( !BER_BVISNULL( &ctrls[ i ]->ldctl_value ) ) {
1260 ptr = lutil_strcopy( ptr, " controlValue \"" );
1261 for ( j = 0; j < ctrls[ i ]->ldctl_value.bv_len; j++ ) {
1262 *ptr++ = SLAP_ESCAPE_HI(ctrls[ i ]->ldctl_value.bv_val[ j ]);
1263 *ptr++ = SLAP_ESCAPE_LO(ctrls[ i ]->ldctl_value.bv_val[ j ]);
1272 ber_bvarray_add_x( valsp, &bv, memctx );
1273 ber_bvarray_add_x( nvalsp, &noid, memctx );
1280 static Entry *accesslog_entry( Operation *op, SlapReply *rs, int logop,
1282 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
1283 log_info *li = on->on_bi.bi_private;
1285 char rdnbuf[STRLENOF(RDNEQ)+LDAP_LUTIL_GENTIME_BUFSIZE+8];
1286 char nrdnbuf[STRLENOF(RDNEQ)+LDAP_LUTIL_GENTIME_BUFSIZE+8];
1288 struct berval rdn, nrdn, timestamp, ntimestamp, bv;
1289 slap_verbmasks *lo = logops+logop+EN_OFFSET;
1291 Entry *e = entry_alloc();
1293 strcpy( rdnbuf, RDNEQ );
1294 rdn.bv_val = rdnbuf;
1295 strcpy( nrdnbuf, RDNEQ );
1296 nrdn.bv_val = nrdnbuf;
1298 timestamp.bv_val = rdnbuf+STRLENOF(RDNEQ);
1299 timestamp.bv_len = sizeof(rdnbuf) - STRLENOF(RDNEQ);
1300 slap_timestamp( &op->o_time, ×tamp );
1301 snprintf( timestamp.bv_val + timestamp.bv_len-1, sizeof(".123456Z"), ".%06dZ", op->o_tincr );
1302 timestamp.bv_len += STRLENOF(".123456");
1304 rdn.bv_len = STRLENOF(RDNEQ)+timestamp.bv_len;
1305 ad_reqStart->ad_type->sat_equality->smr_normalize(
1306 SLAP_MR_VALUE_OF_ASSERTION_SYNTAX, ad_reqStart->ad_type->sat_syntax,
1307 ad_reqStart->ad_type->sat_equality, ×tamp, &ntimestamp,
1310 strcpy( nrdn.bv_val + STRLENOF(RDNEQ), ntimestamp.bv_val );
1311 nrdn.bv_len = STRLENOF(RDNEQ)+ntimestamp.bv_len;
1312 build_new_dn( &e->e_name, li->li_db->be_suffix, &rdn, NULL );
1313 build_new_dn( &e->e_nname, li->li_db->be_nsuffix, &nrdn, NULL );
1315 attr_merge_one( e, slap_schema.si_ad_objectClass,
1316 &log_ocs[logop]->soc_cname, NULL );
1317 attr_merge_one( e, slap_schema.si_ad_structuralObjectClass,
1318 &log_ocs[logop]->soc_cname, NULL );
1319 attr_merge_one( e, ad_reqStart, ×tamp, &ntimestamp );
1320 op->o_tmpfree( ntimestamp.bv_val, op->o_tmpmemctx );
1322 slap_op_time( &op2->o_time, &op2->o_tincr );
1324 timestamp.bv_len = sizeof(rdnbuf) - STRLENOF(RDNEQ);
1325 slap_timestamp( &op2->o_time, ×tamp );
1326 snprintf( timestamp.bv_val + timestamp.bv_len-1, sizeof(".123456Z"), ".%06dZ", op2->o_tincr );
1327 timestamp.bv_len += STRLENOF(".123456");
1329 attr_merge_normalize_one( e, ad_reqEnd, ×tamp, op->o_tmpmemctx );
1331 /* Exops have OID appended */
1332 if ( logop == LOG_EN_EXTENDED ) {
1333 bv.bv_len = lo->word.bv_len + op->ore_reqoid.bv_len + 2;
1334 bv.bv_val = ch_malloc( bv.bv_len + 1 );
1335 AC_MEMCPY( bv.bv_val, lo->word.bv_val, lo->word.bv_len );
1336 bv.bv_val[lo->word.bv_len] = '{';
1337 AC_MEMCPY( bv.bv_val+lo->word.bv_len+1, op->ore_reqoid.bv_val,
1338 op->ore_reqoid.bv_len );
1339 bv.bv_val[bv.bv_len-1] = '}';
1340 bv.bv_val[bv.bv_len] = '\0';
1341 attr_merge_one( e, ad_reqType, &bv, NULL );
1343 attr_merge_one( e, ad_reqType, &lo->word, NULL );
1346 rdn.bv_len = snprintf( rdn.bv_val, sizeof( rdnbuf ), "%lu", op->o_connid );
1347 if ( rdn.bv_len < sizeof( rdnbuf ) ) {
1348 attr_merge_one( e, ad_reqSession, &rdn, NULL );
1351 if ( BER_BVISNULL( &op->o_dn ) ) {
1352 attr_merge_one( e, ad_reqAuthzID, (struct berval *)&slap_empty_bv,
1353 (struct berval *)&slap_empty_bv );
1355 attr_merge_one( e, ad_reqAuthzID, &op->o_dn, &op->o_ndn );
1358 /* FIXME: need to add reqControls and reqRespControls */
1359 if ( op->o_ctrls ) {
1360 BerVarray vals = NULL,
1363 if ( accesslog_ctrls( op->o_ctrls, &vals, &nvals,
1364 op->o_tmpmemctx ) == LDAP_SUCCESS && vals )
1366 attr_merge( e, ad_reqControls, vals, nvals );
1367 ber_bvarray_free_x( vals, op->o_tmpmemctx );
1368 ber_bvarray_free_x( nvals, op->o_tmpmemctx );
1372 if ( rs->sr_ctrls ) {
1373 BerVarray vals = NULL,
1376 if ( accesslog_ctrls( rs->sr_ctrls, &vals, &nvals,
1377 op->o_tmpmemctx ) == LDAP_SUCCESS && vals )
1379 attr_merge( e, ad_reqRespControls, vals, nvals );
1380 ber_bvarray_free_x( vals, op->o_tmpmemctx );
1381 ber_bvarray_free_x( nvals, op->o_tmpmemctx );
1389 static struct berval scopes[] = {
1396 static struct berval derefs[] = {
1398 BER_BVC("searching"),
1403 static struct berval simple = BER_BVC("SIMPLE");
1405 static void accesslog_val2val(AttributeDescription *ad, struct berval *val,
1406 char c_op, struct berval *dst) {
1409 dst->bv_len = ad->ad_cname.bv_len + val->bv_len + 2;
1410 if ( c_op ) dst->bv_len++;
1412 dst->bv_val = ch_malloc( dst->bv_len+1 );
1414 ptr = lutil_strcopy( dst->bv_val, ad->ad_cname.bv_val );
1419 AC_MEMCPY( ptr, val->bv_val, val->bv_len );
1420 dst->bv_val[dst->bv_len] = '\0';
1423 static int accesslog_response(Operation *op, SlapReply *rs) {
1424 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
1425 log_info *li = on->on_bi.bi_private;
1426 Attribute *a, *last_attr;
1432 Entry *e = NULL, *old = NULL;
1433 char timebuf[LDAP_LUTIL_GENTIME_BUFSIZE+8];
1437 Operation op2 = {0};
1438 SlapReply rs2 = {REP_RESULT};
1440 if ( rs->sr_type != REP_RESULT && rs->sr_type != REP_EXTENDED )
1441 return SLAP_CB_CONTINUE;
1443 switch ( op->o_tag ) {
1444 case LDAP_REQ_ADD: logop = LOG_EN_ADD; break;
1445 case LDAP_REQ_DELETE: logop = LOG_EN_DELETE; break;
1446 case LDAP_REQ_MODIFY: logop = LOG_EN_MODIFY; break;
1447 case LDAP_REQ_MODRDN: logop = LOG_EN_MODRDN; break;
1448 case LDAP_REQ_COMPARE: logop = LOG_EN_COMPARE; break;
1449 case LDAP_REQ_SEARCH: logop = LOG_EN_SEARCH; break;
1450 case LDAP_REQ_BIND: logop = LOG_EN_BIND; break;
1451 case LDAP_REQ_EXTENDED: logop = LOG_EN_EXTENDED; break;
1452 default: /* unknown operation type */
1453 logop = LOG_EN_UNKNOWN; break;
1454 } /* Unbind and Abandon never reach here */
1456 lo = logops+logop+EN_OFFSET;
1457 if ( !( li->li_ops & lo->mask )) {
1461 for ( lb = li->li_bases; lb; lb=lb->lb_next )
1462 if (( lb->lb_ops & lo->mask ) && dnIsSuffix( &op->o_req_ndn, &lb->lb_base )) {
1467 return SLAP_CB_CONTINUE;
1470 if ( lo->mask & LOG_OP_WRITES ) {
1473 /* These internal ops are not logged */
1474 if ( op->o_dont_replicate && op->orm_no_opattrs )
1475 return SLAP_CB_CONTINUE;
1477 ldap_pvt_thread_mutex_lock( &li->li_log_mutex );
1480 /* Disarm mod_cleanup */
1481 for ( cb = op->o_callback; cb; cb = cb->sc_next ) {
1482 if ( cb->sc_private == (void *)on ) {
1483 cb->sc_private = NULL;
1487 ldap_pvt_thread_rmutex_unlock( &li->li_op_rmutex, op->o_tid );
1490 if ( li->li_success && rs->sr_err != LDAP_SUCCESS )
1493 e = accesslog_entry( op, rs, logop, &op2 );
1495 attr_merge_one( e, ad_reqDN, &op->o_req_dn, &op->o_req_ndn );
1497 if ( rs->sr_text ) {
1498 ber_str2bv( rs->sr_text, 0, 0, &bv );
1499 attr_merge_one( e, ad_reqMessage, &bv, NULL );
1501 bv.bv_len = snprintf( timebuf, sizeof( timebuf ), "%d", rs->sr_err );
1502 if ( bv.bv_len < sizeof( timebuf ) ) {
1503 bv.bv_val = timebuf;
1504 attr_merge_one( e, ad_reqResult, &bv, NULL );
1507 last_attr = attr_find( e->e_attrs, ad_reqResult );
1511 case LOG_EN_DELETE: {
1515 if ( logop == LOG_EN_ADD ) {
1524 /* count all the vals */
1526 for ( a=e2->e_attrs; a; a=a->a_next ) {
1529 vals = ch_malloc( (i+1) * sizeof( struct berval ));
1531 for ( a=e2->e_attrs; a; a=a->a_next ) {
1533 for (b=a->a_vals; !BER_BVISNULL( b ); b++,i++) {
1534 accesslog_val2val( a->a_desc, b, c_op, &vals[i] );
1538 vals[i].bv_val = NULL;
1540 a = attr_alloc( logop == LOG_EN_ADD ? ad_reqMod : ad_reqOld );
1544 last_attr->a_next = a;
1550 /* count all the mods */
1552 for ( m = op->orm_modlist; m; m = m->sml_next ) {
1553 if ( m->sml_values ) {
1554 i += m->sml_numvals;
1555 } else if ( m->sml_op == LDAP_MOD_DELETE ||
1556 m->sml_op == LDAP_MOD_REPLACE )
1561 vals = ch_malloc( (i+1) * sizeof( struct berval ));
1564 /* init flags on old entry */
1566 for ( a = old->e_attrs; a; a = a->a_next ) {
1570 /* look for attrs that are always logged */
1571 for ( la = li->li_oldattrs; la; la = la->next ) {
1572 if ( a->a_desc == la->attr ) {
1579 for ( m = op->orm_modlist; m; m = m->sml_next ) {
1580 /* Mark this attribute as modified */
1582 a = attr_find( old->e_attrs, m->sml_desc );
1588 /* don't log the RDN mods; they're explicitly logged later */
1589 if ( logop == LOG_EN_MODRDN &&
1590 ( m->sml_op == SLAP_MOD_SOFTADD ||
1591 m->sml_op == LDAP_MOD_DELETE ) )
1596 if ( m->sml_values ) {
1597 for ( b = m->sml_values; !BER_BVISNULL( b ); b++, i++ ) {
1600 switch ( m->sml_op ) {
1601 case LDAP_MOD_ADD: c_op = '+'; break;
1602 case LDAP_MOD_DELETE: c_op = '-'; break;
1603 case LDAP_MOD_REPLACE: c_op = '='; break;
1604 case LDAP_MOD_INCREMENT: c_op = '#'; break;
1606 /* unknown op. there shouldn't be any of these. we
1607 * don't know what to do with it, but we shouldn't just
1610 default: c_op = '?'; break;
1612 accesslog_val2val( m->sml_desc, b, c_op, &vals[i] );
1614 } else if ( m->sml_op == LDAP_MOD_DELETE ||
1615 m->sml_op == LDAP_MOD_REPLACE )
1617 vals[i].bv_len = m->sml_desc->ad_cname.bv_len + 2;
1618 vals[i].bv_val = ch_malloc( vals[i].bv_len + 1 );
1619 ptr = lutil_strcopy( vals[i].bv_val,
1620 m->sml_desc->ad_cname.bv_val );
1622 if ( m->sml_op == LDAP_MOD_DELETE ) {
1633 BER_BVZERO( &vals[i] );
1634 a = attr_alloc( ad_reqMod );
1638 last_attr->a_next = a;
1646 /* count all the vals */
1648 for ( a = old->e_attrs; a != NULL; a = a->a_next ) {
1649 if ( a->a_vals && a->a_flags ) {
1654 vals = ch_malloc( (i + 1) * sizeof( struct berval ) );
1656 for ( a=old->e_attrs; a; a=a->a_next ) {
1657 if ( a->a_vals && a->a_flags ) {
1658 for (b=a->a_vals; !BER_BVISNULL( b ); b++,i++) {
1659 accesslog_val2val( a->a_desc, b, 0, &vals[i] );
1663 vals[i].bv_val = NULL;
1665 a = attr_alloc( ad_reqOld );
1669 last_attr->a_next = a;
1672 if ( logop == LOG_EN_MODIFY ) {
1676 /* Now log the actual modRDN info */
1677 attr_merge_one( e, ad_reqNewRDN, &op->orr_newrdn, &op->orr_nnewrdn );
1678 attr_merge_one( e, ad_reqDeleteOldRDN, op->orr_deleteoldrdn ?
1679 (struct berval *)&slap_true_bv : (struct berval *)&slap_false_bv,
1681 if ( op->orr_newSup ) {
1682 attr_merge_one( e, ad_reqNewSuperior, op->orr_newSup, op->orr_nnewSup );
1686 case LOG_EN_COMPARE:
1687 bv.bv_len = op->orc_ava->aa_desc->ad_cname.bv_len + 1 +
1688 op->orc_ava->aa_value.bv_len;
1689 bv.bv_val = op->o_tmpalloc( bv.bv_len+1, op->o_tmpmemctx );
1690 ptr = lutil_strcopy( bv.bv_val, op->orc_ava->aa_desc->ad_cname.bv_val );
1692 AC_MEMCPY( ptr, op->orc_ava->aa_value.bv_val, op->orc_ava->aa_value.bv_len );
1693 bv.bv_val[bv.bv_len] = '\0';
1694 attr_merge_one( e, ad_reqAssertion, &bv, NULL );
1695 op->o_tmpfree( bv.bv_val, op->o_tmpmemctx );
1699 attr_merge_one( e, ad_reqScope, &scopes[op->ors_scope], NULL );
1700 attr_merge_one( e, ad_reqDerefAliases, &derefs[op->ors_deref], NULL );
1701 attr_merge_one( e, ad_reqAttrsOnly, op->ors_attrsonly ?
1702 (struct berval *)&slap_true_bv : (struct berval *)&slap_false_bv,
1704 if ( !BER_BVISEMPTY( &op->ors_filterstr ))
1705 attr_merge_one( e, ad_reqFilter, &op->ors_filterstr, NULL );
1706 if ( op->ors_attrs ) {
1709 for (i=0; !BER_BVISNULL(&op->ors_attrs[i].an_name );i++)
1711 vals = op->o_tmpalloc( (i+1) * sizeof(struct berval),
1713 for (i=0, j=0; !BER_BVISNULL(&op->ors_attrs[i].an_name );i++) {
1714 if (!BER_BVISEMPTY(&op->ors_attrs[i].an_name)) {
1715 vals[j] = op->ors_attrs[i].an_name;
1719 BER_BVZERO(&vals[j]);
1720 attr_merge( e, ad_reqAttr, vals, NULL );
1721 op->o_tmpfree( vals, op->o_tmpmemctx );
1723 bv.bv_val = timebuf;
1724 bv.bv_len = snprintf( bv.bv_val, sizeof( timebuf ), "%d", rs->sr_nentries );
1725 if ( bv.bv_len < sizeof( timebuf ) ) {
1726 attr_merge_one( e, ad_reqEntries, &bv, NULL );
1729 bv.bv_len = snprintf( bv.bv_val, sizeof( timebuf ), "%d", op->ors_tlimit );
1730 if ( bv.bv_len < sizeof( timebuf ) ) {
1731 attr_merge_one( e, ad_reqTimeLimit, &bv, NULL );
1734 bv.bv_len = snprintf( bv.bv_val, sizeof( timebuf ), "%d", op->ors_slimit );
1735 if ( bv.bv_len < sizeof( timebuf ) ) {
1736 attr_merge_one( e, ad_reqSizeLimit, &bv, NULL );
1741 bv.bv_val = timebuf;
1742 bv.bv_len = snprintf( bv.bv_val, sizeof( timebuf ), "%d", op->o_protocol );
1743 if ( bv.bv_len < sizeof( timebuf ) ) {
1744 attr_merge_one( e, ad_reqVersion, &bv, NULL );
1746 if ( op->orb_method == LDAP_AUTH_SIMPLE ) {
1747 attr_merge_one( e, ad_reqMethod, &simple, NULL );
1749 bv.bv_len = STRLENOF("SASL()") + op->orb_mech.bv_len;
1750 bv.bv_val = op->o_tmpalloc( bv.bv_len + 1, op->o_tmpmemctx );
1751 ptr = lutil_strcopy( bv.bv_val, "SASL(" );
1752 ptr = lutil_strcopy( ptr, op->orb_mech.bv_val );
1755 attr_merge_one( e, ad_reqMethod, &bv, NULL );
1756 op->o_tmpfree( bv.bv_val, op->o_tmpmemctx );
1761 case LOG_EN_EXTENDED:
1762 if ( op->ore_reqdata ) {
1763 attr_merge_one( e, ad_reqData, op->ore_reqdata, NULL );
1767 case LOG_EN_UNKNOWN:
1768 /* we don't know its parameters, don't add any */
1772 op2.o_hdr = op->o_hdr;
1773 op2.o_tag = LDAP_REQ_ADD;
1774 op2.o_bd = li->li_db;
1775 op2.o_dn = li->li_db->be_rootdn;
1776 op2.o_ndn = li->li_db->be_rootndn;
1777 op2.o_req_dn = e->e_name;
1778 op2.o_req_ndn = e->e_nname;
1780 op2.o_callback = &nullsc;
1782 if (( lo->mask & LOG_OP_WRITES ) && !BER_BVISEMPTY( &op->o_csn )) {
1783 slap_queue_csn( &op2, &op->o_csn );
1786 op2.o_bd->be_add( &op2, &rs2 );
1787 if ( e == op2.ora_e ) entry_free( e );
1791 if ( lo->mask & LOG_OP_WRITES )
1792 ldap_pvt_thread_mutex_unlock( &li->li_log_mutex );
1793 if ( old ) entry_free( old );
1794 return SLAP_CB_CONTINUE;
1797 /* Since Bind success is sent by the frontend, it won't normally enter
1798 * the overlay response callback. Add another callback to make sure it
1802 accesslog_bind_resp( Operation *op, SlapReply *rs )
1811 db.bd_info = op->o_callback->sc_private;
1812 rc = accesslog_response( op, rs );
1814 sc = op->o_callback;
1815 op->o_callback = sc->sc_next;
1816 op->o_tmpfree( sc, op->o_tmpmemctx );
1821 accesslog_op_bind( Operation *op, SlapReply *rs )
1825 sc = op->o_tmpcalloc( 1, sizeof(slap_callback), op->o_tmpmemctx );
1826 sc->sc_response = accesslog_bind_resp;
1827 sc->sc_private = op->o_bd->bd_info;
1829 if ( op->o_callback ) {
1830 sc->sc_next = op->o_callback->sc_next;
1831 op->o_callback->sc_next = sc;
1833 op->o_callback = sc;
1835 return SLAP_CB_CONTINUE;
1839 accesslog_mod_cleanup( Operation *op, SlapReply *rs )
1841 slap_callback *sc = op->o_callback;
1842 slap_overinst *on = sc->sc_private;
1843 op->o_callback = sc->sc_next;
1845 op->o_tmpfree( sc, op->o_tmpmemctx );
1848 BackendInfo *bi = op->o_bd->bd_info;
1849 op->o_bd->bd_info = (BackendInfo *)on;
1850 accesslog_response( op, rs );
1851 op->o_bd->bd_info = bi;
1857 accesslog_op_mod( Operation *op, SlapReply *rs )
1859 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
1860 log_info *li = on->on_bi.bi_private;
1863 /* These internal ops are not logged */
1864 if ( op->o_dont_replicate && op->orm_no_opattrs )
1865 return SLAP_CB_CONTINUE;
1868 if ( li->li_ops & LOG_OP_WRITES ) {
1872 for ( lb = li->li_bases; lb; lb = lb->lb_next )
1873 if (( lb->lb_ops & LOG_OP_WRITES ) && dnIsSuffix( &op->o_req_ndn, &lb->lb_base )) {
1880 slap_callback *cb = op->o_tmpalloc( sizeof( slap_callback ), op->o_tmpmemctx ), *cb2;
1881 cb->sc_cleanup = accesslog_mod_cleanup;
1882 cb->sc_response = NULL;
1883 cb->sc_private = on;
1885 for ( cb2 = op->o_callback; cb2->sc_next; cb2 = cb2->sc_next );
1888 ldap_pvt_thread_rmutex_lock( &li->li_op_rmutex, op->o_tid );
1889 if ( li->li_oldf && ( op->o_tag == LDAP_REQ_DELETE ||
1890 op->o_tag == LDAP_REQ_MODIFY ||
1891 ( op->o_tag == LDAP_REQ_MODRDN && li->li_oldattrs ))) {
1895 op->o_bd->bd_info = (BackendInfo *)on->on_info;
1896 rc = be_entry_get_rw( op, &op->o_req_ndn, NULL, NULL, 0, &e );
1898 if ( test_filter( op, e, li->li_oldf ) == LDAP_COMPARE_TRUE )
1899 li->li_old = entry_dup( e );
1900 be_entry_release_rw( op, e, 0 );
1902 op->o_bd->bd_info = (BackendInfo *)on;
1905 return SLAP_CB_CONTINUE;
1908 /* unbinds are broadcast to all backends; we only log it if this
1909 * backend was used for the original bind.
1912 accesslog_unbind( Operation *op, SlapReply *rs )
1914 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
1915 if ( op->o_conn->c_authz_backend == on->on_info->oi_origdb ) {
1916 log_info *li = on->on_bi.bi_private;
1917 Operation op2 = {0};
1918 void *cids[SLAP_MAX_CIDS];
1919 SlapReply rs2 = {REP_RESULT};
1922 if ( !( li->li_ops & LOG_OP_UNBIND ))
1923 return SLAP_CB_CONTINUE;
1925 e = accesslog_entry( op, rs, LOG_EN_UNBIND, &op2 );
1926 op2.o_hdr = op->o_hdr;
1927 op2.o_tag = LDAP_REQ_ADD;
1928 op2.o_bd = li->li_db;
1929 op2.o_dn = li->li_db->be_rootdn;
1930 op2.o_ndn = li->li_db->be_rootndn;
1931 op2.o_req_dn = e->e_name;
1932 op2.o_req_ndn = e->e_nname;
1934 op2.o_callback = &nullsc;
1935 op2.o_controls = cids;
1936 memset(cids, 0, sizeof( cids ));
1938 op2.o_bd->be_add( &op2, &rs2 );
1939 if ( e == op2.ora_e )
1942 return SLAP_CB_CONTINUE;
1946 accesslog_abandon( Operation *op, SlapReply *rs )
1948 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
1949 log_info *li = on->on_bi.bi_private;
1950 Operation op2 = {0};
1951 void *cids[SLAP_MAX_CIDS];
1952 SlapReply rs2 = {REP_RESULT};
1957 if ( !op->o_time || !( li->li_ops & LOG_OP_ABANDON ))
1958 return SLAP_CB_CONTINUE;
1960 e = accesslog_entry( op, rs, LOG_EN_ABANDON, &op2 );
1962 bv.bv_len = snprintf( buf, sizeof( buf ), "%d", op->orn_msgid );
1963 if ( bv.bv_len < sizeof( buf ) ) {
1964 attr_merge_one( e, ad_reqId, &bv, NULL );
1967 op2.o_hdr = op->o_hdr;
1968 op2.o_tag = LDAP_REQ_ADD;
1969 op2.o_bd = li->li_db;
1970 op2.o_dn = li->li_db->be_rootdn;
1971 op2.o_ndn = li->li_db->be_rootndn;
1972 op2.o_req_dn = e->e_name;
1973 op2.o_req_ndn = e->e_nname;
1975 op2.o_callback = &nullsc;
1976 op2.o_controls = cids;
1977 memset(cids, 0, sizeof( cids ));
1979 op2.o_bd->be_add( &op2, &rs2 );
1980 if ( e == op2.ora_e )
1983 return SLAP_CB_CONTINUE;
1987 accesslog_operational( Operation *op, SlapReply *rs )
1989 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
1990 log_info *li = on->on_bi.bi_private;
1992 if ( op->o_sync != SLAP_CONTROL_NONE )
1993 return SLAP_CB_CONTINUE;
1995 if ( rs->sr_entry != NULL
1996 && dn_match( &op->o_bd->be_nsuffix[0], &rs->sr_entry->e_nname ) )
2000 for ( ap = &rs->sr_operational_attrs; *ap; ap = &(*ap)->a_next )
2003 if ( SLAP_OPATTRS( rs->sr_attr_flags ) ||
2004 ad_inlist( ad_auditContext, rs->sr_attrs ) )
2006 *ap = attr_alloc( ad_auditContext );
2008 &li->li_db->be_suffix[0],
2009 &li->li_db->be_nsuffix[0], 1 );
2013 return SLAP_CB_CONTINUE;
2016 static slap_overinst accesslog;
2024 slap_overinst *on = (slap_overinst *)be->bd_info;
2025 log_info *li = ch_calloc(1, sizeof(log_info));
2027 on->on_bi.bi_private = li;
2028 ldap_pvt_thread_rmutex_init( &li->li_op_rmutex );
2029 ldap_pvt_thread_mutex_init( &li->li_log_mutex );
2034 accesslog_db_destroy(
2039 slap_overinst *on = (slap_overinst *)be->bd_info;
2040 log_info *li = on->on_bi.bi_private;
2044 filter_free( li->li_oldf );
2045 for ( la=li->li_oldattrs; la; la=li->li_oldattrs ) {
2046 li->li_oldattrs = la->next;
2049 ldap_pvt_thread_mutex_destroy( &li->li_log_mutex );
2050 ldap_pvt_thread_rmutex_destroy( &li->li_op_rmutex );
2052 return LDAP_SUCCESS;
2055 /* Create the logdb's root entry if it's missing */
2061 struct re_s *rtask = arg;
2062 slap_overinst *on = rtask->arg;
2063 log_info *li = on->on_bi.bi_private;
2065 Connection conn = {0};
2066 OperationBuffer opbuf;
2072 connection_fake_init( &conn, &opbuf, ctx );
2074 op->o_bd = li->li_db;
2075 op->o_dn = li->li_db->be_rootdn;
2076 op->o_ndn = li->li_db->be_rootndn;
2077 rc = be_entry_get_rw( op, li->li_db->be_nsuffix, NULL, NULL, 0, &e );
2080 be_entry_release_rw( op, e, 0 );
2083 SlapReply rs = {REP_RESULT};
2084 struct berval rdn, nrdn, attr;
2086 AttributeDescription *ad = NULL;
2087 const char *text = NULL;
2091 ber_dupbv( &e->e_name, li->li_db->be_suffix );
2092 ber_dupbv( &e->e_nname, li->li_db->be_nsuffix );
2094 attr_merge_one( e, slap_schema.si_ad_objectClass,
2095 &log_container->soc_cname, NULL );
2097 dnRdn( &e->e_name, &rdn );
2098 dnRdn( &e->e_nname, &nrdn );
2099 ptr = ber_bvchr( &rdn, '=' );
2101 assert( ptr != NULL );
2103 attr.bv_val = rdn.bv_val;
2104 attr.bv_len = ptr - rdn.bv_val;
2106 slap_bv2ad( &attr, &ad, &text );
2109 rdn.bv_len -= attr.bv_len + 1;
2110 ptr = ber_bvchr( &nrdn, '=' );
2111 nrdn.bv_len -= ptr - nrdn.bv_val + 1;
2112 nrdn.bv_val = ptr+1;
2113 attr_merge_one( e, ad, &rdn, &nrdn );
2115 /* Get contextCSN from main DB */
2116 op->o_bd = on->on_info->oi_origdb;
2117 rc = be_entry_get_rw( op, op->o_bd->be_nsuffix, NULL,
2118 slap_schema.si_ad_contextCSN, 0, &e_ctx );
2123 a = attr_find( e_ctx->e_attrs, slap_schema.si_ad_contextCSN );
2125 /* FIXME: contextCSN could have multiple values!
2126 * should select the one with the server's SID */
2127 attr_merge_one( e, slap_schema.si_ad_entryCSN,
2128 &a->a_vals[0], &a->a_nvals[0] );
2129 attr_merge( e, a->a_desc, a->a_vals, a->a_nvals );
2131 be_entry_release_rw( op, e_ctx, 0 );
2133 op->o_bd = li->li_db;
2136 op->o_req_dn = e->e_name;
2137 op->o_req_ndn = e->e_nname;
2138 op->o_callback = &nullsc;
2139 SLAP_DBFLAGS( op->o_bd ) |= SLAP_DBFLAG_NOLASTMOD;
2140 rc = op->o_bd->be_add( op, &rs );
2141 SLAP_DBFLAGS( op->o_bd ) ^= SLAP_DBFLAG_NOLASTMOD;
2142 if ( e == op->ora_e )
2145 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
2146 ldap_pvt_runqueue_stoptask( &slapd_rq, rtask );
2147 ldap_pvt_runqueue_remove( &slapd_rq, rtask );
2148 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
2159 slap_overinst *on = (slap_overinst *)be->bd_info;
2160 log_info *li = on->on_bi.bi_private;
2163 if ( !BER_BVISEMPTY( &li->li_db_suffix )) {
2164 li->li_db = select_backend( &li->li_db_suffix, 0 );
2165 ch_free( li->li_db_suffix.bv_val );
2166 BER_BVZERO( &li->li_db_suffix );
2168 if ( li->li_db == NULL ) {
2169 Debug( LDAP_DEBUG_ANY,
2170 "accesslog: \"logdb <suffix>\" missing or invalid.\n",
2175 if ( slapMode & SLAP_TOOL_MODE )
2178 if ( BER_BVISEMPTY( &li->li_db->be_rootndn )) {
2179 ber_dupbv( &li->li_db->be_rootdn, li->li_db->be_suffix );
2180 ber_dupbv( &li->li_db->be_rootndn, li->li_db->be_nsuffix );
2183 ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
2184 ldap_pvt_runqueue_insert( &slapd_rq, 3600, accesslog_db_root, on,
2185 "accesslog_db_root", li->li_db->be_suffix[0].bv_val );
2186 ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
2191 int accesslog_initialize()
2195 accesslog.on_bi.bi_type = "accesslog";
2196 accesslog.on_bi.bi_db_init = accesslog_db_init;
2197 accesslog.on_bi.bi_db_destroy = accesslog_db_destroy;
2198 accesslog.on_bi.bi_db_open = accesslog_db_open;
2200 accesslog.on_bi.bi_op_add = accesslog_op_mod;
2201 accesslog.on_bi.bi_op_bind = accesslog_op_bind;
2202 accesslog.on_bi.bi_op_delete = accesslog_op_mod;
2203 accesslog.on_bi.bi_op_modify = accesslog_op_mod;
2204 accesslog.on_bi.bi_op_modrdn = accesslog_op_mod;
2205 accesslog.on_bi.bi_op_unbind = accesslog_unbind;
2206 accesslog.on_bi.bi_op_abandon = accesslog_abandon;
2207 accesslog.on_bi.bi_operational = accesslog_operational;
2208 accesslog.on_response = accesslog_response;
2210 accesslog.on_bi.bi_cf_ocs = log_cfocs;
2212 nullsc.sc_response = slap_null_cb;
2214 rc = config_register_schema( log_cfats, log_cfocs );
2215 if ( rc ) return rc;
2217 /* log schema integration */
2218 for ( i=0; lsyntaxes[i].oid; i++ ) {
2221 code = register_syntax( &lsyntaxes[ i ].syn );
2223 Debug( LDAP_DEBUG_ANY,
2224 "accesslog_init: register_syntax failed\n",
2229 if ( lsyntaxes[i].mrs != NULL ) {
2230 code = mr_make_syntax_compat_with_mrs(
2231 lsyntaxes[i].oid, lsyntaxes[i].mrs );
2233 Debug( LDAP_DEBUG_ANY,
2235 "mr_make_syntax_compat_with_mrs "
2243 for ( i=0; lattrs[i].at; i++ ) {
2246 code = register_at( lattrs[i].at, lattrs[i].ad, 0 );
2248 Debug( LDAP_DEBUG_ANY,
2249 "accesslog_init: register_at failed\n",
2254 (*lattrs[i].ad)->ad_type->sat_flags |= SLAP_AT_HIDE;
2258 for ( i=0; locs[i].ot; i++ ) {
2261 code = register_oc( locs[i].ot, locs[i].oc, 0 );
2263 Debug( LDAP_DEBUG_ANY,
2264 "accesslog_init: register_oc failed\n",
2269 (*locs[i].oc)->soc_flags |= SLAP_OC_HIDE;
2273 return overlay_register(&accesslog);
2276 #if SLAPD_OVER_ACCESSLOG == SLAPD_MOD_DYNAMIC
2278 init_module( int argc, char *argv[] )
2280 return accesslog_initialize();
2284 #endif /* SLAPD_OVER_ACCESSLOG */