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