]> git.sur5r.net Git - openldap/blob - servers/slapd/overlays/accesslog.c
fix ITS#3788: don't free slapo-rwm callback, rather reuse it
[openldap] / servers / slapd / overlays / accesslog.c
1 /* accesslog.c - log operations for audit/history purposes */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2005 The OpenLDAP Foundation.
6  * Portions copyright 2004-2005 Symas Corporation.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted only as authorized by the OpenLDAP
11  * Public License.
12  *
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>.
16  */
17 /* ACKNOWLEDGEMENTS:
18  * This work was initially developed by Howard Chu for inclusion in
19  * OpenLDAP Software.
20  */
21
22 #include "portable.h"
23
24 #ifdef SLAPD_OVER_ACCESSLOG
25
26 #include <stdio.h>
27
28 #include <ac/string.h>
29 #include <ac/ctype.h>
30
31 #include "slap.h"
32 #include "config.h"
33 #include "lutil.h"
34 #include "ldap_rq.h"
35
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
47 #define LOG_OP_WRITES   (LOG_OP_ADD|LOG_OP_DELETE|LOG_OP_MODIFY|LOG_OP_MODRDN)
48 #define LOG_OP_READS    (LOG_OP_COMPARE|LOG_OP_SEARCH)
49 #define LOG_OP_SESSION  (LOG_OP_BIND|LOG_OP_UNBIND|LOG_OP_ABANDON)
50 #define LOG_OP_ALL              (LOG_OP_READS|LOG_OP_WRITES|LOG_OP_SESSION|LOG_OP_EXTENDED)
51
52 typedef struct log_info {
53         BackendDB *li_db;
54         slap_mask_t li_ops;
55         int li_age;
56         int li_cycle;
57         struct re_s *li_task;
58 } log_info;
59
60 static ConfigDriver log_cf_gen;
61
62 enum {
63         LOG_DB = 1,
64         LOG_OPS,
65         LOG_PURGE
66 };
67
68 static ConfigTable log_cfats[] = {
69         { "logdb", "suffix", 2, 2, 0, ARG_DN|ARG_MAGIC|LOG_DB,
70                 log_cf_gen, "( OLcfgOvAt:4.1 NAME 'olcAccessLogDB' "
71                         "DESC 'Suffix of database for log content' "
72                         "SUP distinguishedName SINGLE-VALUE )", NULL, NULL },
73         { "logops", "op|writes|reads|session|all", 2, 0, 0,
74                 ARG_MAGIC|LOG_OPS,
75                 log_cf_gen, "( OLcfgOvAt:4.2 NAME 'olcAccessLogOps' "
76                         "DESC 'Operation types to log' "
77                         "EQUALITY caseIgnoreMatch "
78                         "SYNTAX OMsDirectoryString )", NULL, NULL },
79         { "logpurge", "age> <interval", 3, 3, 0, ARG_MAGIC|LOG_PURGE,
80                 log_cf_gen, "( OLcfgOvAt:4.3 NAME 'olcAccessLogPurge' "
81                         "DESC 'Log cleanup parameters' "
82                         "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
83         { NULL }
84 };
85
86 static ConfigOCs log_cfocs[] = {
87         { "( OLcfgOvOc:4.1 "
88                 "NAME 'olcAccessLogConfig' "
89                 "DESC 'Access log configuration' "
90                 "SUP olcOverlayConfig "
91                 "MUST olcAccessLogDB "
92                 "MAY ( olcAccessLogOps $ olcAccessLogPurge ) )",
93                         Cft_Overlay, log_cfats },
94         { NULL }
95 };
96
97 static slap_verbmasks logops[] = {
98         { BER_BVC("all"),               LOG_OP_ALL },
99         { BER_BVC("writes"),    LOG_OP_WRITES },
100         { BER_BVC("session"),   LOG_OP_SESSION },
101         { BER_BVC("reads"),             LOG_OP_READS },
102         { BER_BVC("add"),               LOG_OP_ADD },
103         { BER_BVC("delete"),    LOG_OP_DELETE },
104         { BER_BVC("modify"),    LOG_OP_MODIFY },
105         { BER_BVC("modrdn"),    LOG_OP_MODRDN },
106         { BER_BVC("compare"),   LOG_OP_COMPARE },
107         { BER_BVC("search"),    LOG_OP_SEARCH },
108         { BER_BVC("bind"),              LOG_OP_BIND },
109         { BER_BVC("unbind"),    LOG_OP_UNBIND },
110         { BER_BVC("abandon"),   LOG_OP_ABANDON },
111         { BER_BVC("extended"),  LOG_OP_EXTENDED },
112         { BER_BVNULL, 0 }
113 };
114
115 /* Start with "add" in logops */
116 #define EN_OFFSET       4
117
118 enum {
119         LOG_EN_ADD = 0,
120         LOG_EN_DELETE,
121         LOG_EN_MODIFY,
122         LOG_EN_MODRDN,
123         LOG_EN_COMPARE,
124         LOG_EN_SEARCH,
125         LOG_EN_BIND,
126         LOG_EN_UNBIND,
127         LOG_EN_ABANDON,
128         LOG_EN_EXTENDED,
129         LOG_EN__COUNT
130 };
131
132 static ObjectClass *log_ocs[LOG_EN__COUNT];
133
134 #define LOG_SCHEMA_ROOT "1.3.6.1.4.1.4203.666.11.5"
135
136 #define LOG_SCHEMA_AT LOG_SCHEMA_ROOT ".1"
137 #define LOG_SCHEMA_OC LOG_SCHEMA_ROOT ".2"
138
139 static AttributeDescription *ad_reqDN, *ad_reqStart, *ad_reqEnd, *ad_reqType,
140         *ad_reqSession, *ad_reqResult, *ad_reqAuthzID, *ad_reqControls,
141         *ad_reqRespControls, *ad_reqMethod, *ad_reqAssertion, *ad_reqNewRDN,
142         *ad_reqNewSuperior, *ad_reqDeleteOldRDN, *ad_reqMod,
143         *ad_reqScope, *ad_reqFilter, *ad_reqAttr, *ad_reqEntries,
144         *ad_reqSizeLimit, *ad_reqTimeLimit, *ad_reqAttrsOnly, *ad_reqData,
145         *ad_reqId, *ad_reqMessage, *ad_oldest;
146
147 static struct {
148         char *at;
149         AttributeDescription **ad;
150 } lattrs[] = {
151         { "( " LOG_SCHEMA_AT ".1 NAME 'reqDN' "
152                 "DESC 'Target DN of request' "
153                 "EQUALITY distinguishedNameMatch "
154                 "SYNTAX OMsDN "
155                 "SINGLE-VALUE )", &ad_reqDN },
156         { "( " LOG_SCHEMA_AT ".2 NAME 'reqStart' "
157                 "DESC 'Start time of request' "
158                 "EQUALITY generalizedTimeMatch "
159                 "ORDERING generalizedTimeOrderingMatch "
160                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 "
161                 "SINGLE-VALUE )", &ad_reqStart },
162         { "( " LOG_SCHEMA_AT ".3 NAME 'reqEnd' "
163                 "DESC 'End time of request' "
164                 "EQUALITY generalizedTimeMatch "
165                 "ORDERING generalizedTimeOrderingMatch "
166                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 "
167                 "SINGLE-VALUE )", &ad_reqEnd },
168         { "( " LOG_SCHEMA_AT ".4 NAME 'reqType' "
169                 "DESC 'Type of request' "
170                 "EQUALITY caseIgnoreMatch "
171                 "SYNTAX OMsDirectoryString "
172                 "SINGLE-VALUE )", &ad_reqType },
173         { "( " LOG_SCHEMA_AT ".5 NAME 'reqSession' "
174                 "DESC 'Session ID of request' "
175                 "EQUALITY caseIgnoreMatch "
176                 "SYNTAX OMsDirectoryString "
177                 "SINGLE-VALUE )", &ad_reqSession },
178         { "( " LOG_SCHEMA_AT ".6 NAME 'reqResult' "
179                 "DESC 'Result code of request' "
180                 "EQUALITY integerMatch "
181                 "SYNTAX OMsInteger "
182                 "SINGLE-VALUE )", &ad_reqResult },
183         { "( " LOG_SCHEMA_AT ".7 NAME 'reqAuthzID' "
184                 "DESC 'AUthorization ID of requestor' "
185                 "EQUALITY distinguishedNameMatch "
186                 "SYNTAX OMsDN "
187                 "SINGLE-VALUE )", &ad_reqAuthzID },
188         { "( " LOG_SCHEMA_AT ".8 NAME 'reqControls' "
189                 "DESC 'Request controls' "
190                 "SYNTAX OMsOctetString )", &ad_reqControls },
191         { "( " LOG_SCHEMA_AT ".9 NAME 'reqRespControls' "
192                 "DESC 'Response controls of request' "
193                 "SYNTAX OMsOctetString )", &ad_reqRespControls },
194         { "( " LOG_SCHEMA_AT ".10 NAME 'reqMethod' "
195                 "DESC 'Bind method of request' "
196                 "EQUALITY caseIgnoreMatch "
197                 "SYNTAX OMsDirectoryString "
198                 "SINGLE-VALUE )", &ad_reqMethod },
199         { "( " LOG_SCHEMA_AT ".11 NAME 'reqAssertion' "
200                 "DESC 'Compare Assertion of request' "
201                 "SYNTAX OMsDirectoryString "
202                 "SINGLE-VALUE )", &ad_reqAssertion },
203         { "( " LOG_SCHEMA_AT ".12 NAME 'reqNewRDN' "
204                 "DESC 'New RDN of request' "
205                 "EQUALITY distinguishedNameMatch "
206                 "SYNTAX OMsDN "
207                 "SINGLE-VALUE )", &ad_reqNewRDN },
208         { "( " LOG_SCHEMA_AT ".13 NAME 'reqNewSuperior' "
209                 "DESC 'New superior DN of request' "
210                 "EQUALITY distinguishedNameMatch "
211                 "SYNTAX OMsDN "
212                 "SINGLE-VALUE )", &ad_reqNewSuperior },
213         { "( " LOG_SCHEMA_AT ".14 NAME 'reqDeleteOldRDN' "
214                 "DESC 'Delete old RDN' "
215                 "SYNTAX OMsBoolean "
216                 "SINGLE-VALUE )", &ad_reqDeleteOldRDN },
217         { "( " LOG_SCHEMA_AT ".15 NAME 'reqMod' "
218                 "DESC 'Modifications of request' "
219                 "SYNTAX OMsDirectoryString "
220                 "EQUALITY caseIgnoreMatch "
221                 "SUBSTR caseIgnoreSubstringsMatch )", &ad_reqMod },
222         { "( " LOG_SCHEMA_AT ".16 NAME 'reqScope' "
223                 "DESC 'Scope of request' "
224                 "SYNTAX OMsDirectoryString "
225                 "SINGLE-VALUE )", &ad_reqScope },
226         { "( " LOG_SCHEMA_AT ".17 NAME 'reqFilter' "
227                 "DESC 'Filter of request' "
228                 "SYNTAX OMsDirectoryString "
229                 "SINGLE-VALUE )", &ad_reqFilter },
230         { "( " LOG_SCHEMA_AT ".18 NAME 'reqAttr' "
231                 "DESC 'Attributes of request' "
232                 "SYNTAX OMsDirectoryString )", &ad_reqAttr },
233         { "( " LOG_SCHEMA_AT ".19 NAME 'reqEntries' "
234                 "DESC 'Number of entries returned' "
235                 "SYNTAX OMsInteger "
236                 "SINGLE-VALUE )", &ad_reqEntries },
237         { "( " LOG_SCHEMA_AT ".20 NAME 'reqSizeLimit' "
238                 "DESC 'Size limit of request' "
239                 "SYNTAX OMsInteger "
240                 "SINGLE-VALUE )", &ad_reqSizeLimit },
241         { "( " LOG_SCHEMA_AT ".21 NAME 'reqTimeLimit' "
242                 "DESC 'Time limit of request' "
243                 "SYNTAX OMsInteger "
244                 "SINGLE-VALUE )", &ad_reqTimeLimit },
245         { "( " LOG_SCHEMA_AT ".22 NAME 'reqAttrsOnly' "
246                 "DESC 'Attributes and values of request' "
247                 "SYNTAX OMsBoolean "
248                 "SINGLE-VALUE )", &ad_reqAttrsOnly },
249         { "( " LOG_SCHEMA_AT ".23 NAME 'reqData' "
250                 "DESC 'Data of extended request' "
251                 "SYNTAX OMsOctetString "
252                 "SINGLE-VALUE )", &ad_reqData },
253         { "( " LOG_SCHEMA_AT ".24 NAME 'reqId' "
254                 "DESC 'ID of Request to Abandon' "
255                 "SYNTAX OMsInteger "
256                 "SINGLE-VALUE )", &ad_reqId },
257         { "( " LOG_SCHEMA_AT ".25 NAME 'reqMessage' "
258                 "DESC 'Error text of request' "
259                 "SYNTAX OMsDirectoryString "
260                 "SINGLE-VALUE )", &ad_reqMessage },
261 #if 0
262         { "( " LOG_SCHEMA_AT ".26 NAME 'auditOldest' "
263                 "DESC 'Oldest record in this branch' "
264                 "EQUALITY generalizedTimeMatch "
265                 "ORDERING generalizedTimeOrderingMatch "
266                 "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 "
267                 "SINGLE-VALUE )", &ad_oldest },
268 #endif
269         { NULL, NULL }
270 };
271
272 static struct {
273         char *ot;
274         ObjectClass **oc;
275 } locs[] = {
276 #if 0
277         { "( " LOG_SCHEMA_OC ".0 NAME 'auditContainer' "
278                 "SUP top STRUCTURAL "
279                 "MUST auditOldest "
280                 "MAY cn )", &oc_container },
281 #endif
282         { "( " LOG_SCHEMA_OC ".1 NAME 'auditObject' "
283                 "DESC 'OpenLDAP request auditing' "
284                 "SUP top STRUCTURAL "
285                 "MUST ( reqStart $ reqType $ reqSession ) "
286                 "MAY ( reqDN $ reqAuthzID $ reqControls $ reqRespControls $ reqEnd $ "
287                         "reqResult $ reqMessage ) )", &log_ocs[LOG_EN_UNBIND] },
288         { "( " LOG_SCHEMA_OC ".2 NAME 'auditReadObject' "
289                 "DESC 'OpenLDAP read request record' "
290                 "SUP auditObject STRUCTURAL )", NULL },
291         { "( " LOG_SCHEMA_OC ".3 NAME 'auditWriteObject' "
292                 "DESC 'OpenLDAP write request record' "
293                 "SUP auditObject STRUCTURAL )", &log_ocs[LOG_EN_DELETE] },
294         { "( " LOG_SCHEMA_OC ".4 NAME 'auditAbandon' "
295                 "DESC 'Abandon operation' "
296                 "SUP auditObject STRUCTURAL "
297                 "MUST reqId )", &log_ocs[LOG_EN_ABANDON] },
298         { "( " LOG_SCHEMA_OC ".5 NAME 'auditAdd' "
299                 "DESC 'Add operation' "
300                 "SUP auditWriteObject STRUCTURAL "
301                 "MUST reqMod )", &log_ocs[LOG_EN_ADD] },
302         { "( " LOG_SCHEMA_OC ".6 NAME 'auditBind' "
303                 "DESC 'Bind operation' "
304                 "SUP auditObject STRUCTURAL "
305                 "MUST reqMethod )", &log_ocs[LOG_EN_BIND] },
306         { "( " LOG_SCHEMA_OC ".7 NAME 'auditCompare' "
307                 "DESC 'Compare operation' "
308                 "SUP auditReadObject STRUCTURAL "
309                 "MUST reqAssertion )", &log_ocs[LOG_EN_COMPARE] },
310         { "( " LOG_SCHEMA_OC ".8 NAME 'auditModify' "
311                 "DESC 'Modify operation' "
312                 "SUP auditWriteObject STRUCTURAL "
313                 "MUST reqMod )", &log_ocs[LOG_EN_MODIFY] },
314         { "( " LOG_SCHEMA_OC ".9 NAME 'auditModRDN' "
315                 "DESC 'ModRDN operation' "
316                 "SUP auditWriteObject STRUCTURAL "
317                 "MUST ( reqNewRDN $ reqDeleteOldRDN ) "
318                 "MAY reqNewSuperior )", &log_ocs[LOG_EN_MODRDN] },
319         { "( " LOG_SCHEMA_OC ".10 NAME 'auditSearch' "
320                 "DESC 'Search operation' "
321                 "SUP auditReadObject STRUCTURAL "
322                 "MUST ( reqScope $ reqAttrsonly ) "
323                 "MAY ( reqFilter $ reqAttr $ reqEntries $ reqSizeLimit $ "
324                         "reqTimeLimit ) )", &log_ocs[LOG_EN_SEARCH] },
325         { "( " LOG_SCHEMA_OC ".11 NAME 'auditExtended' "
326                 "DESC 'Extended operation' "
327                 "SUP auditObject STRUCTURAL "
328                 "MAY reqData )", &log_ocs[LOG_EN_EXTENDED] },
329         { NULL, NULL }
330 };
331
332 #define RDNEQ   "reqStart="
333
334 /* Our time intervals are of the form [dd+]hh:mm[:ss]
335  * If a field is present, it must be two digits. We assume no one
336  * will want to keep log records for longer than 99 days.
337  */
338 static int
339 log_age_parse(char *agestr)
340 {
341         char *ptr;
342         int t1, t2;
343         int gotdays = 0;
344
345         t1 = atoi( agestr );
346         /* Is there a days delimiter? */
347         if ( agestr[2] == '+' ) {
348                 t1 *= 24;
349                 gotdays = 1;
350         } else if ( agestr[2] != ':' ) {
351         /* No valid delimiter found, fail */
352                 return -1;
353         }
354
355         agestr += 3;
356         t2 = atoi( agestr );
357
358         /* if there's a delimiter, it can only be a colon */
359         if ( agestr[2] && agestr[2] != ':' )
360                 return -1;
361
362         /* If we're at the end of the string, and we started with days,
363          * fail because we expected to find minutes too.
364          */
365         if ( gotdays && !agestr[2] )
366                 return -1;
367
368         t1 *= 60;
369         t1 += t2;
370
371         if ( !agestr[2] )
372                 return t1 * 60;
373
374         agestr += 3;
375         t2 = atoi( agestr );
376
377         /* last field can only be seconds */
378         if ( agestr[2] && ( agestr[2] != ':' || !gotdays ))
379                 return -1;
380         t1 *= 60;
381         t1 += t2;
382
383         t1 *= 60;
384         if ( agestr[2] ) {
385                 agestr += 3;
386                 if ( agestr[2] )
387                         return -1;
388                 t1 += atoi( agestr );
389         }
390         return t1;
391 }
392
393 static void
394 log_age_unparse( int age, struct berval *agebv )
395 {
396         int dd, hh, mm, ss;
397         char *ptr;
398
399         ss = age % 60;
400         age /= 60;
401         mm = age % 60;
402         age /= 60;
403         hh = age % 60;
404         age /= 24;
405         dd = age;
406
407         ptr = agebv->bv_val;
408
409         if ( dd ) 
410                 ptr += sprintf( ptr, "%02d+", dd );
411         ptr += sprintf( ptr, "%02d:%02d", hh, mm );
412         if ( ss )
413                 ptr += sprintf( ptr, ":%02d", ss );
414
415         agebv->bv_len = ptr - agebv->bv_val;
416 }
417
418 static slap_callback nullsc = { NULL, slap_null_cb, NULL, NULL };
419
420 #define PURGE_INCREMENT 100
421
422 typedef struct purge_data {
423         int slots;
424         int used;
425         BerVarray dn;
426         BerVarray ndn;
427 } purge_data;
428
429 static int
430 log_old_lookup( Operation *op, SlapReply *rs )
431 {
432         purge_data *pd = op->o_callback->sc_private;
433
434         if ( rs->sr_type != REP_SEARCH) return 0;
435
436         if ( pd->used >= pd->slots ) {
437                 pd->slots += PURGE_INCREMENT;
438                 pd->dn = ch_realloc( pd->dn, pd->slots * sizeof( struct berval ));
439                 pd->ndn = ch_realloc( pd->ndn, pd->slots * sizeof( struct berval ));
440         }
441         ber_dupbv( &pd->dn[pd->used], &rs->sr_entry->e_name );
442         ber_dupbv( &pd->ndn[pd->used], &rs->sr_entry->e_nname );
443         pd->used++;
444         return 0;
445 }
446
447 /* Periodically search for old entries in the log database and delete them */
448 static void *
449 accesslog_purge( void *ctx, void *arg )
450 {
451         struct re_s *rtask = arg;
452         struct log_info *li = rtask->arg;
453
454         Connection conn = {0};
455         char opbuf[OPERATION_BUFFER_SIZE];
456         Operation *op = (Operation *)opbuf;
457         SlapReply rs = {REP_RESULT};
458         slap_callback cb = { NULL, log_old_lookup, NULL, NULL };
459         Filter f;
460         AttributeAssertion ava = {0};
461         purge_data pd = {0};
462         char timebuf[LDAP_LUTIL_GENTIME_BUFSIZE];
463         time_t old = slap_get_time();
464
465         connection_fake_init( &conn, op, ctx );
466
467         f.f_choice = LDAP_FILTER_LE;
468         f.f_ava = &ava;
469         f.f_next = NULL;
470
471         ava.aa_desc = ad_reqStart;
472         ava.aa_value.bv_val = timebuf;
473         ava.aa_value.bv_len = sizeof(timebuf);
474
475         old -= li->li_age;
476         slap_timestamp( &old, &ava.aa_value );
477
478         op->o_tag = LDAP_REQ_SEARCH;
479         op->o_bd = li->li_db;
480         op->o_dn = li->li_db->be_rootdn;
481         op->o_ndn = li->li_db->be_rootndn;
482         op->o_req_dn = li->li_db->be_suffix[0];
483         op->o_req_ndn = li->li_db->be_nsuffix[0];
484         op->o_callback = &cb;
485         op->ors_scope = LDAP_SCOPE_ONELEVEL;
486         op->ors_deref = LDAP_DEREF_NEVER;
487         op->ors_tlimit = SLAP_NO_LIMIT;
488         op->ors_slimit = SLAP_NO_LIMIT;
489         op->ors_filter = &f;
490         filter2bv_x( op, &f, &op->ors_filterstr );
491         op->ors_attrs = slap_anlist_no_attrs;
492         op->ors_attrsonly = 1;
493         
494         cb.sc_private = &pd;
495
496         op->o_bd->be_search( op, &rs );
497         op->o_tmpfree( op->ors_filterstr.bv_val, op->o_tmpmemctx );
498
499         if ( pd.used ) {
500                 int i;
501
502                 op->o_tag = LDAP_REQ_DELETE;
503                 op->o_callback = &nullsc;
504
505                 for (i=0; i<pd.used; i++) {
506                         op->o_req_dn = pd.dn[i];
507                         op->o_req_ndn = pd.ndn[i];
508                         op->o_bd->be_delete( op, &rs );
509                         ch_free( pd.ndn[i].bv_val );
510                         ch_free( pd.dn[i].bv_val );
511                 }
512                 ch_free( pd.ndn );
513                 ch_free( pd.dn );
514         }
515
516         ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
517         ldap_pvt_runqueue_stoptask( &slapd_rq, rtask );
518         ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
519
520         return NULL;
521 }
522
523 static int
524 log_cf_gen(ConfigArgs *c)
525 {
526         slap_overinst *on = (slap_overinst *)c->bi;
527         struct log_info *li = on->on_bi.bi_private;
528         int rc = 0;
529         slap_mask_t tmask = 0;
530         char agebuf[2*STRLENOF("dd+hh:mm:ss  ")];
531         struct berval agebv, cyclebv;
532
533         switch( c->op ) {
534         case SLAP_CONFIG_EMIT:
535                 switch( c->type ) {
536                 case LOG_DB:
537                         value_add( &c->rvalue_vals, li->li_db->be_suffix );
538                         value_add( &c->rvalue_nvals, li->li_db->be_nsuffix );
539                         break;
540                 case LOG_OPS:
541                         rc = mask_to_verbs( logops, li->li_ops, &c->rvalue_vals );
542                         break;
543                 case LOG_PURGE:
544                         agebv.bv_val = agebuf;
545                         log_age_unparse( li->li_age, &agebv );
546                         agebv.bv_val[agebv.bv_len] = ' ';
547                         agebv.bv_len++;
548                         cyclebv.bv_val = agebv.bv_val + agebv.bv_len;
549                         log_age_unparse( li->li_cycle, &cyclebv );
550                         agebv.bv_len += cyclebv.bv_len;
551                         value_add_one( &c->rvalue_vals, &agebv );
552                         break;
553                 }
554                 break;
555         case LDAP_MOD_DELETE:
556                 switch( c->type ) {
557                 case LOG_DB:
558                         /* noop. this should always be a valid backend. */
559                         break;
560                 case LOG_OPS:
561                         if ( c->valx < 0 ) {
562                                 li->li_ops = 0;
563                         } else {
564                                 rc = verbs_to_mask( 1, &c->line, logops, &tmask );
565                                 if ( rc == 0 )
566                                         li->li_ops &= ~tmask;
567                         }
568                         break;
569                 case LOG_PURGE:
570                         if ( li->li_task ) {
571                                 struct re_s *re = li->li_task;
572                                 li->li_task = NULL;
573                                 if ( ldap_pvt_runqueue_isrunning( &slapd_rq, re ))
574                                         ldap_pvt_runqueue_stoptask( &slapd_rq, re );
575                                 ldap_pvt_runqueue_remove( &slapd_rq, re );
576                         }
577                         li->li_age = 0;
578                         li->li_cycle = 0;
579                         break;
580                 }
581                 break;
582         default:
583                 switch( c->type ) {
584                 case LOG_DB:
585                         li->li_db = select_backend( &c->value_ndn, 0, 0 );
586                         if ( !li->li_db ) {
587                                 sprintf( c->msg, "<%s> no matching backend found for suffix",
588                                         c->argv[0] );
589                                 Debug( LDAP_DEBUG_ANY, "%s: %s \"%s\"\n",
590                                         c->log, c->msg, c->value_dn.bv_val );
591                                 rc = 1;
592                         }
593                         ch_free( c->value_dn.bv_val );
594                         ch_free( c->value_ndn.bv_val );
595                         break;
596                 case LOG_OPS:
597                         rc = verbs_to_mask( c->argc, c->argv, logops, &tmask );
598                         if ( rc == 0 )
599                                 li->li_ops |= tmask;
600                         break;
601                 case LOG_PURGE:
602                         li->li_age = log_age_parse( c->argv[1] );
603                         if ( li->li_age == -1 ) {
604                                 rc = 1;
605                         } else {
606                                 li->li_cycle = log_age_parse( c->argv[2] );
607                                 if ( li->li_cycle == -1 ) {
608                                         rc = 1;
609                                 } else if ( slapMode & SLAP_SERVER_MODE ) {
610                                         struct re_s *re = li->li_task;
611                                         if ( re )
612                                                 re->interval.tv_sec = li->li_cycle;
613                                         else
614                                                 li->li_task = ldap_pvt_runqueue_insert( &slapd_rq,
615                                                         li->li_cycle, accesslog_purge, li,
616                                                         "accesslog_purge", li->li_db ?
617                                                                 li->li_db->be_suffix[0].bv_val :
618                                                                 c->be->be_suffix[0].bv_val );
619                                 }
620                         }
621                         break;
622                 }
623                 break;
624         }
625         return rc;
626 }
627
628 static Entry *accesslog_entry( Operation *op, int logop ) {
629         slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
630         log_info *li = on->on_bi.bi_private;
631
632         char rdnbuf[STRLENOF(RDNEQ)+LDAP_LUTIL_GENTIME_BUFSIZE+8];
633         struct berval rdn, timestamp, bv;
634         slap_verbmasks *lo = logops+logop+EN_OFFSET;
635
636         Entry *e = ch_calloc( 1, sizeof(Entry) );
637
638         strcpy( rdnbuf, RDNEQ );
639         rdn.bv_val = rdnbuf;
640
641         timestamp.bv_val = rdnbuf+STRLENOF(RDNEQ);
642         timestamp.bv_len = sizeof(rdnbuf) - STRLENOF(RDNEQ);
643         slap_timestamp( &op->o_time, &timestamp );
644         if ( op->o_tincr ) {
645                 sprintf( timestamp.bv_val + timestamp.bv_len-1, ".%06dZ", op->o_tincr );
646                 timestamp.bv_len += 7;
647         }
648         rdn.bv_len = STRLENOF(RDNEQ)+timestamp.bv_len;
649         build_new_dn( &e->e_name, li->li_db->be_suffix, &rdn, NULL );
650         build_new_dn( &e->e_nname, li->li_db->be_nsuffix, &rdn, NULL );
651
652         attr_merge_one( e, slap_schema.si_ad_objectClass,
653                 &log_ocs[logop]->soc_cname, NULL );
654         attr_merge_one( e, slap_schema.si_ad_structuralObjectClass,
655                 &log_ocs[logop]->soc_cname, NULL );
656         attr_merge_one( e, ad_reqStart, &timestamp, NULL );
657
658         /* Exops have OID appended */
659         if ( logop == LOG_EN_EXTENDED ) {
660                 bv.bv_len = lo->word.bv_len + op->ore_reqoid.bv_len + 2;
661                 bv.bv_val = ch_malloc( bv.bv_len + 1 );
662                 AC_MEMCPY( bv.bv_val, lo->word.bv_val, lo->word.bv_len );
663                 bv.bv_val[lo->word.bv_len] = '{';
664                 AC_MEMCPY( bv.bv_val+lo->word.bv_len+1, op->ore_reqoid.bv_val,
665                         op->ore_reqoid.bv_len );
666                 bv.bv_val[bv.bv_len-1] = '}';
667                 bv.bv_val[bv.bv_len] = '\0';
668                 attr_merge_one( e, ad_reqType, &bv, NULL );
669         } else {
670                 attr_merge_one( e, ad_reqType, &lo->word, NULL );
671         }
672
673         rdn.bv_len = sprintf( rdn.bv_val, "%d", op->o_connid );
674         attr_merge_one( e, ad_reqSession, &rdn, NULL );
675
676         if ( BER_BVISNULL( &op->o_dn )) 
677                 attr_merge_one( e, ad_reqAuthzID, (struct berval *)&slap_empty_bv,
678                         (struct berval *)&slap_empty_bv );
679         else
680                 attr_merge_one( e, ad_reqAuthzID, &op->o_dn, &op->o_ndn );
681
682         /* FIXME: need to add reqControls and reqRespControls */
683
684         return e;
685 }
686
687 static struct berval scopes[] = {
688         BER_BVC("base"),
689         BER_BVC("onelevel"),
690         BER_BVC("subtree"),
691         BER_BVC("subordinate")
692 };
693
694 static struct berval simple = BER_BVC("SIMPLE");
695
696 static int accesslog_response(Operation *op, SlapReply *rs) {
697         slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
698         log_info *li = on->on_bi.bi_private;
699         Attribute *a, *last_attr;
700         Modifications *m;
701         struct berval *b;
702         time_t endtime;
703         int i;
704         int logop;
705         slap_verbmasks *lo;
706         Entry *e;
707         char timebuf[LDAP_LUTIL_GENTIME_BUFSIZE];
708         struct berval bv;
709         char *ptr;
710         BerVarray vals;
711         Operation op2;
712         SlapReply rs2 = {REP_RESULT};
713
714         if ( rs->sr_type != REP_RESULT && rs->sr_type != REP_EXTENDED )
715                 return SLAP_CB_CONTINUE;
716
717         switch ( op->o_tag ) {
718         case LDAP_REQ_ADD:              logop = LOG_EN_ADD; break;
719         case LDAP_REQ_DELETE:   logop = LOG_EN_DELETE; break;
720         case LDAP_REQ_MODIFY:   logop = LOG_EN_MODIFY; break;
721         case LDAP_REQ_MODRDN:   logop = LOG_EN_MODRDN; break;
722         case LDAP_REQ_COMPARE:  logop = LOG_EN_COMPARE; break;
723         case LDAP_REQ_SEARCH:   logop = LOG_EN_SEARCH; break;
724         case LDAP_REQ_BIND:             logop = LOG_EN_BIND; break;
725         case LDAP_REQ_EXTENDED: logop = LOG_EN_EXTENDED; break;
726         }       /* Unbind and Abandon never reach here */
727
728         lo = logops+logop+EN_OFFSET;
729         if ( !( li->li_ops & lo->mask ))
730                 return SLAP_CB_CONTINUE;
731
732         endtime = slap_get_time();
733
734         e = accesslog_entry( op, logop );
735
736         bv.bv_val = timebuf;
737         bv.bv_len = sizeof(timebuf);
738         slap_timestamp( &endtime, &bv );
739
740         attr_merge_one( e, ad_reqEnd, &bv, NULL );
741
742         attr_merge_one( e, ad_reqDN, &op->o_req_dn, &op->o_req_ndn );
743
744         if ( rs->sr_text ) {
745                 ber_str2bv( rs->sr_text, 0, 0, &bv );
746                 attr_merge_one( e, ad_reqMessage, &bv, NULL );
747         }
748         bv.bv_len = sprintf( timebuf, "%d", rs->sr_err );
749         bv.bv_val = timebuf;
750
751         attr_merge_one( e, ad_reqResult, &bv, NULL );
752
753         last_attr = attr_find( e->e_attrs, ad_reqResult );
754
755         switch( logop ) {
756         case LOG_EN_ADD:
757                 /* count all the vals */
758                 i = 0;
759                 for ( a=op->ora_e->e_attrs; a; a=a->a_next ) {
760                         if ( a->a_vals ) {
761                                 for (b=a->a_vals; !BER_BVISNULL( b ); b++) {
762                                         i++;
763                                 }
764                         }
765                 }
766                 vals = ch_malloc( (i+1) * sizeof( struct berval ));
767                 i = 0;
768                 for ( a=op->ora_e->e_attrs; a; a=a->a_next ) {
769                         if ( a->a_vals ) {
770                                 for (b=a->a_vals; !BER_BVISNULL( b ); b++,i++) {
771                                         vals[i].bv_len = a->a_desc->ad_cname.bv_len + b->bv_len +3;
772                                         vals[i].bv_val = ch_malloc( vals[i].bv_len+1 );
773                                         ptr = lutil_strcopy( vals[i].bv_val,
774                                                 a->a_desc->ad_cname.bv_val );
775                                         *ptr++ = ':';
776                                         *ptr++ = '+';
777                                         *ptr++ = ' ';
778                                         AC_MEMCPY( ptr, b->bv_val, b->bv_len );
779                                         vals[i].bv_val[vals[i].bv_len] = '\0';
780                                 }
781                         }
782                 }
783                 vals[i].bv_val = NULL;
784                 vals[i].bv_len = 0;
785                 a = attr_alloc( ad_reqMod );
786                 a->a_vals = vals;
787                 a->a_nvals = vals;
788                 last_attr->a_next = a;
789                 break;
790
791         case LOG_EN_DELETE:
792                 /* needs nothing else */
793                 break;
794
795         case LOG_EN_MODIFY:
796                 /* count all the mods */
797                 i = 0;
798                 for ( m=op->orm_modlist; m; m=m->sml_next ) {
799                         if ( m->sml_values ) {
800                                 for (b=m->sml_values; !BER_BVISNULL( b ); b++) {
801                                         i++;
802                                 }
803                         } else if ( m->sml_op == LDAP_MOD_DELETE ) {
804                                 i++;
805                         }
806                 }
807                 vals = ch_malloc( (i+1) * sizeof( struct berval ));
808                 i = 0;
809                 for ( m=op->orm_modlist; m; m=m->sml_next ) {
810                         if ( m->sml_values ) {
811                                 for (b=m->sml_values; !BER_BVISNULL( b ); b++,i++) {
812                                         char c_op;
813                                         vals[i].bv_len = a->a_desc->ad_cname.bv_len + b->bv_len +3;
814                                         vals[i].bv_val = ch_malloc( vals[i].bv_len+1 );
815                                         ptr = lutil_strcopy( vals[i].bv_val,
816                                                 a->a_desc->ad_cname.bv_val );
817                                         *ptr++ = ':';
818                                         switch( m->sml_op ) {
819                                         case LDAP_MOD_ADD: c_op = '+'; break;
820                                         case LDAP_MOD_DELETE:   c_op = '-'; break;
821                                         case LDAP_MOD_REPLACE:  c_op = '='; break;
822                                         case LDAP_MOD_INCREMENT:        c_op = '#'; break;
823                                         }
824                                         *ptr++ = c_op;
825                                         *ptr++ = ' ';
826                                         AC_MEMCPY( ptr, b->bv_val, b->bv_len );
827                                         vals[i].bv_val[vals[i].bv_len] = '\0';
828                                 }
829                         } else if ( m->sml_op == LDAP_MOD_DELETE ) {
830                                 vals[i].bv_len = a->a_desc->ad_cname.bv_len + 2;
831                                 vals[i].bv_val = ch_malloc( vals[i].bv_len+1 );
832                                 ptr = lutil_strcopy( vals[i].bv_val,
833                                         a->a_desc->ad_cname.bv_val );
834                                 *ptr++ = ':';
835                                 *ptr++ = '-';
836                                 *ptr = '\0';
837                                 i++;
838                         }
839                 }
840                 vals[i].bv_val = NULL;
841                 vals[i].bv_len = 0;
842                 a = attr_alloc( ad_reqMod );
843                 a->a_vals = vals;
844                 a->a_nvals = vals;
845                 last_attr->a_next = a;
846                 break;
847
848         case LOG_EN_MODRDN:
849                 attr_merge_one( e, ad_reqNewRDN, &op->orr_newrdn, &op->orr_nnewrdn );
850                 attr_merge_one( e, ad_reqDeleteOldRDN, op->orr_deleteoldrdn ?
851                         (struct berval *)&slap_true_bv : (struct berval *)&slap_false_bv,
852                         NULL );
853                 if ( op->orr_newSup ) {
854                         attr_merge_one( e, ad_reqNewSuperior, op->orr_newSup, op->orr_nnewSup );
855                 }
856                 break;
857
858         case LOG_EN_COMPARE:
859                 bv.bv_len = op->orc_ava->aa_desc->ad_cname.bv_len + 1 +
860                         op->orc_ava->aa_value.bv_len;
861                 bv.bv_val = op->o_tmpalloc( bv.bv_len+1, op->o_tmpmemctx );
862                 ptr = lutil_strcopy( bv.bv_val, op->orc_ava->aa_desc->ad_cname.bv_val );
863                 *ptr++ = '=';
864                 AC_MEMCPY( ptr, op->orc_ava->aa_value.bv_val, op->orc_ava->aa_value.bv_len );
865                 bv.bv_val[bv.bv_len] = '\0';
866                 attr_merge_one( e, ad_reqAssertion, &bv, NULL );
867                 op->o_tmpfree( bv.bv_val, op->o_tmpmemctx );
868                 break;
869
870         case LOG_EN_SEARCH:
871                 attr_merge_one( e, ad_reqScope, &scopes[op->ors_scope], NULL );
872                 attr_merge_one( e, ad_reqAttrsOnly, op->ors_attrsonly ?
873                         (struct berval *)&slap_true_bv : (struct berval *)&slap_false_bv,
874                         NULL );
875                 if ( !BER_BVISEMPTY( &op->ors_filterstr ))
876                         attr_merge_one( e, ad_reqFilter, &op->ors_filterstr, NULL );
877                 if ( op->ors_attrs ) {
878                         /* count them */
879                         for (i=0; !BER_BVISNULL(&op->ors_attrs[i].an_name );i++)
880                                 ;
881                         vals = op->o_tmpalloc( (i+1) * sizeof(struct berval),
882                                 op->o_tmpmemctx );
883                         for (i=0; !BER_BVISNULL(&op->ors_attrs[i].an_name );i++)
884                                 vals[i] = op->ors_attrs[i].an_name;
885                         vals[i].bv_val = NULL;
886                         vals[i].bv_len = 0;
887                         attr_merge( e, ad_reqAttr, vals, NULL );
888                         op->o_tmpfree( vals, op->o_tmpmemctx );
889                 }
890                 bv.bv_val = timebuf;
891                 bv.bv_len = sprintf( bv.bv_val, "%d", rs->sr_nentries );
892                 attr_merge_one( e, ad_reqEntries, &bv, NULL );
893
894                 bv.bv_len = sprintf( bv.bv_val, "%d", op->ors_tlimit );
895                 attr_merge_one( e, ad_reqTimeLimit, &bv, NULL );
896                 /* FIXME: slimit was zeroed by the backends */
897                 break;
898
899         case LOG_EN_BIND:
900                 if ( op->orb_method == LDAP_AUTH_SIMPLE ) {
901                         attr_merge_one( e, ad_reqMethod, &simple, NULL );
902                 } else {
903                         bv.bv_len = STRLENOF("SASL()") + op->orb_tmp_mech.bv_len;
904                         bv.bv_val = op->o_tmpalloc( bv.bv_len + 1, op->o_tmpmemctx );
905                         ptr = lutil_strcopy( bv.bv_val, "SASL(" );
906                         ptr = lutil_strcopy( ptr, op->orb_tmp_mech.bv_val );
907                         *ptr++ = ')';
908                         *ptr = '\0';
909                         attr_merge_one( e, ad_reqMethod, &bv, NULL );
910                         op->o_tmpfree( bv.bv_val, op->o_tmpmemctx );
911                 }
912                 break;
913
914         case LOG_EN_EXTENDED:
915                 if ( op->ore_reqdata ) {
916                         attr_merge_one( e, ad_reqData, op->ore_reqdata, NULL );
917                 }
918                 break;
919         }
920
921         op2.o_hdr = op->o_hdr;
922         op2.o_tag = LDAP_REQ_ADD;
923         op2.o_time = endtime;
924         op2.o_tincr = 0;
925         op2.o_bd = li->li_db;
926         op2.o_dn = li->li_db->be_rootdn;
927         op2.o_ndn = li->li_db->be_rootndn;
928         op2.o_req_dn = e->e_name;
929         op2.o_req_ndn = e->e_nname;
930         op2.ora_e = e;
931         op2.o_callback = &nullsc;
932
933         op2.o_bd->be_add( &op2, &rs2 );
934         entry_free( e );
935
936         return SLAP_CB_CONTINUE;
937 }
938
939 /* unbinds are broadcast to all backends; we only log it if this
940  * backend was used for the original bind.
941  */
942 static int
943 accesslog_unbind( Operation *op, SlapReply *rs )
944 {
945         if ( op->o_conn->c_authz_backend == op->o_bd ) {
946                 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
947                 log_info *li = on->on_bi.bi_private;
948                 Operation op2;
949                 SlapReply rs2 = {REP_RESULT};
950                 Entry *e;
951
952                 e = accesslog_entry( op, LOG_EN_UNBIND );
953                 op2.o_hdr = op->o_hdr;
954                 op2.o_tag = LDAP_REQ_ADD;
955                 op2.o_time = op->o_time;
956                 op2.o_tincr = 0;
957                 op2.o_bd = li->li_db;
958                 op2.o_dn = li->li_db->be_rootdn;
959                 op2.o_ndn = li->li_db->be_rootndn;
960                 op2.o_req_dn = e->e_name;
961                 op2.o_req_ndn = e->e_nname;
962                 op2.ora_e = e;
963                 op2.o_callback = &nullsc;
964
965                 op2.o_bd->be_add( &op2, &rs2 );
966                 entry_free( e );
967         }
968         return SLAP_CB_CONTINUE;
969 }
970
971 static int
972 accesslog_abandon( Operation *op, SlapReply *rs )
973 {
974         slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
975         log_info *li = on->on_bi.bi_private;
976         Operation op2;
977         SlapReply rs2 = {REP_RESULT};
978         Entry *e;
979         char buf[64];
980         struct berval bv;
981
982         if ( !op->o_time )
983                 return SLAP_CB_CONTINUE;
984
985         e = accesslog_entry( op, LOG_EN_ABANDON );
986         bv.bv_val = buf;
987         bv.bv_len = sprintf( buf, "%d", op->orn_msgid );
988         attr_merge_one( e, ad_reqId, &bv, NULL );
989
990         op2.o_hdr = op->o_hdr;
991         op2.o_tag = LDAP_REQ_ADD;
992         op2.o_time = op->o_time;
993         op2.o_tincr = 0;
994         op2.o_bd = li->li_db;
995         op2.o_dn = li->li_db->be_rootdn;
996         op2.o_ndn = li->li_db->be_rootndn;
997         op2.o_req_dn = e->e_name;
998         op2.o_req_ndn = e->e_nname;
999         op2.ora_e = e;
1000         op2.o_callback = &nullsc;
1001
1002         op2.o_bd->be_add( &op2, &rs2 );
1003         entry_free( e );
1004
1005         return SLAP_CB_CONTINUE;
1006 }
1007
1008 static slap_overinst accesslog;
1009
1010 static int
1011 accesslog_db_init(
1012         BackendDB *be
1013 )
1014 {
1015         slap_overinst *on = (slap_overinst *)be->bd_info;
1016         log_info *li = ch_calloc(1, sizeof(log_info));
1017
1018         on->on_bi.bi_private = li;
1019         return 0;
1020 }
1021
1022 static int
1023 accesslog_db_destroy(
1024         BackendDB *be
1025 )
1026 {
1027         slap_overinst *on = (slap_overinst *)be->bd_info;
1028         log_info *li = on->on_bi.bi_private;
1029         
1030         free( li );
1031         return LDAP_SUCCESS;
1032 }
1033
1034 int accesslog_init()
1035 {
1036         int i, rc;
1037
1038         accesslog.on_bi.bi_type = "accesslog";
1039         accesslog.on_bi.bi_db_init = accesslog_db_init;
1040         accesslog.on_bi.bi_db_destroy = accesslog_db_destroy;
1041
1042         accesslog.on_bi.bi_op_unbind = accesslog_unbind;
1043         accesslog.on_bi.bi_op_abandon = accesslog_abandon;
1044         accesslog.on_response = accesslog_response;
1045
1046         accesslog.on_bi.bi_cf_ocs = log_cfocs;
1047
1048         rc = config_register_schema( log_cfats, log_cfocs );
1049         if ( rc ) return rc;
1050
1051         /* log schema integration */
1052         for ( i=0; lattrs[i].at; i++ ) {
1053                 LDAPAttributeType *lat;
1054                 AttributeType *at;
1055                 int code;
1056                 const char *err;
1057
1058                 lat = ldap_str2attributetype( lattrs[i].at, &code, &err,
1059                         LDAP_SCHEMA_ALLOW_ALL );
1060                 if ( !lat ) {
1061                         Debug( LDAP_DEBUG_ANY, "accesslog_init: "
1062                                 "ldap_str2attributetype failed on %d: %s, %s\n",
1063                                 i, ldap_scherr2str(code), err );
1064                         return -1;
1065                 }
1066                 code = at_add( lat, 0, &at, &err );
1067                 ldap_memfree( lat );
1068                 if ( code ) {
1069                         Debug( LDAP_DEBUG_ANY, "log_back_initialize: "
1070                                 "at_add failed on %d: %s\n",
1071                                 i, scherr2str(code), 0 );
1072                         return -1;
1073                 }
1074                 if ( slap_bv2ad( &at->sat_cname, lattrs[i].ad, &err )) {
1075                         Debug( LDAP_DEBUG_ANY, "accesslog_init: "
1076                                 "slap_bv2ad failed on %d: %s\n",
1077                                 i, err, 0 );
1078                         return -1;
1079                 }
1080         }
1081         for ( i=0; locs[i].ot; i++ ) {
1082                 LDAPObjectClass *loc;
1083                 ObjectClass *oc;
1084                 int code;
1085                 const char *err;
1086
1087                 loc = ldap_str2objectclass( locs[i].ot, &code, &err,
1088                         LDAP_SCHEMA_ALLOW_ALL );
1089                 if ( !loc ) {
1090                         Debug( LDAP_DEBUG_ANY, "accesslog_init: "
1091                                 "ldap_str2objectclass failed on %d: %s, %s\n",
1092                                 i, ldap_scherr2str(code), err );
1093                         return -1;
1094                 }
1095                 
1096                 code = oc_add( loc, 0, &oc, &err );
1097                 ldap_memfree( loc );
1098                 if ( code ) {
1099                         Debug( LDAP_DEBUG_ANY, "accesslog_init: "
1100                                 "oc_add failed on %d: %s\n",
1101                                 i, scherr2str(code), 0 );
1102                         return -1;
1103                 }
1104                 if ( locs[i].oc )
1105                         *locs[i].oc = oc;
1106         }
1107
1108         return overlay_register(&accesslog);
1109 }
1110
1111 #if SLAPD_OVER_ACCESSLOG == SLAPD_MOD_DYNAMIC
1112 int init_module( int argc, char *argv[]) {
1113         return accesslog_init();
1114 }
1115 #endif
1116
1117 #endif /* SLAPD_OVER_ACCESSLOG */