]> git.sur5r.net Git - openldap/blob - servers/slapd/back-monitor/init.c
Fix typo
[openldap] / servers / slapd / back-monitor / init.c
1 /* init.c - initialize monitor backend */
2 /*
3  * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6 /*
7  * Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
8  * 
9  * This work has beed deveolped for the OpenLDAP Foundation 
10  * in the hope that it may be useful to the Open Source community, 
11  * but WITHOUT ANY WARRANTY.
12  * 
13  * Permission is granted to anyone to use this software for any purpose
14  * on any computer system, and to alter it and redistribute it, subject
15  * to the following restrictions:
16  * 
17  * 1. The author and SysNet s.n.c. are not responsible for the consequences
18  *    of use of this software, no matter how awful, even if they arise from
19  *    flaws in it.
20  * 
21  * 2. The origin of this software must not be misrepresented, either by
22  *    explicit claim or by omission.  Since few users ever read sources,
23  *    credits should appear in the documentation.
24  * 
25  * 3. Altered versions must be plainly marked as such, and must not be
26  *    misrepresented as being the original software.  Since few users
27  *    ever read sources, credits should appear in the documentation.
28  *    SysNet s.n.c. cannot be responsible for the consequences of the
29  *    alterations.
30  * 
31  * 4. This notice may not be removed or altered.
32  */
33
34 #include "portable.h"
35
36 #include <stdio.h>
37 #include <ac/string.h>
38
39 #include <lutil.h>
40 #include "slap.h"
41 #include "lber_pvt.h"
42 #include "back-monitor.h"
43
44 #undef INTEGRATE_CORE_SCHEMA
45
46 /*
47  * used by many functions to add description to entries
48  */
49 BackendDB *be_monitor = NULL;
50
51 /*
52  * subsystem data
53  */
54 struct monitorsubsys monitor_subsys[] = {
55         { 
56                 SLAPD_MONITOR_LISTENER, SLAPD_MONITOR_LISTENER_NAME,    
57                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
58                 MONITOR_F_PERSISTENT_CH,
59                 monitor_subsys_listener_init,
60                 NULL,   /* update */
61                 NULL,   /* create */
62                 NULL    /* modify */
63         }, { 
64                 SLAPD_MONITOR_DATABASE, SLAPD_MONITOR_DATABASE_NAME,    
65                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
66                 MONITOR_F_PERSISTENT_CH,
67                 monitor_subsys_database_init,
68                 NULL,   /* update */
69                 NULL,   /* create */
70                 NULL    /* modify */
71         }, { 
72                 SLAPD_MONITOR_BACKEND, SLAPD_MONITOR_BACKEND_NAME, 
73                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
74                 MONITOR_F_PERSISTENT_CH,
75                 monitor_subsys_backend_init,
76                 NULL,   /* update */
77                 NULL,   /* create */
78                 NULL    /* modify */
79         }, { 
80                 SLAPD_MONITOR_THREAD, SLAPD_MONITOR_THREAD_NAME,        
81                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
82                 MONITOR_F_NONE,
83                 monitor_subsys_thread_init,
84                 monitor_subsys_thread_update,
85                 NULL,   /* create */
86                 NULL    /* modify */
87         }, { 
88                 SLAPD_MONITOR_SASL, SLAPD_MONITOR_SASL_NAME,    
89                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
90                 MONITOR_F_NONE,
91                 NULL,   /* init */
92                 NULL,   /* update */
93                 NULL,   /* create */
94                 NULL    /* modify */
95         }, { 
96                 SLAPD_MONITOR_TLS, SLAPD_MONITOR_TLS_NAME,
97                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
98                 MONITOR_F_NONE,
99                 NULL,   /* init */
100                 NULL,   /* update */
101                 NULL,   /* create */
102                 NULL    /* modify */
103         }, { 
104                 SLAPD_MONITOR_CONN, SLAPD_MONITOR_CONN_NAME,
105                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
106                 MONITOR_F_VOLATILE_CH,
107                 monitor_subsys_conn_init,
108                 monitor_subsys_conn_update,
109                 monitor_subsys_conn_create,
110                 NULL    /* modify */
111         }, { 
112                 SLAPD_MONITOR_RWW, SLAPD_MONITOR_RWW_NAME,
113                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
114                 MONITOR_F_PERSISTENT_CH,
115                 monitor_subsys_rww_init,
116                 monitor_subsys_rww_update,
117                 NULL,   /* create */
118                 NULL    /* modify */
119         }, { 
120                 SLAPD_MONITOR_LOG, SLAPD_MONITOR_LOG_NAME,
121                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
122                 MONITOR_F_NONE,
123                 monitor_subsys_log_init,
124                 NULL,   /* update */
125                 NULL,   /* create */
126                 monitor_subsys_log_modify
127         }, { 
128                 SLAPD_MONITOR_OPS, SLAPD_MONITOR_OPS_NAME,
129                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
130                 MONITOR_F_PERSISTENT_CH,
131                 monitor_subsys_ops_init,
132                 monitor_subsys_ops_update,
133                 NULL,   /* create */
134                 NULL,   /* modify */
135         }, { 
136                 SLAPD_MONITOR_SENT, SLAPD_MONITOR_SENT_NAME,
137                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
138                 MONITOR_F_PERSISTENT_CH,
139                 monitor_subsys_sent_init,
140                 monitor_subsys_sent_update,
141                 NULL,   /* create */
142                 NULL,   /* modify */
143         }, { 
144                 SLAPD_MONITOR_TIME, SLAPD_MONITOR_TIME_NAME,
145                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
146                 MONITOR_F_PERSISTENT_CH,
147                 monitor_subsys_time_init,
148                 monitor_subsys_time_update,
149                 NULL,   /* create */
150                 NULL,   /* modify */
151         }, { -1, NULL }
152 };
153
154 #ifdef SLAPD_MONITOR_DYNAMIC
155
156 int
157 back_monitor_LTX_init_module( int argc, char *argv[] )
158 {
159         BackendInfo bi;
160
161         memset( &bi, '\0', sizeof(bi) );
162         bi.bi_type = "monitor";
163         bi.bi_init = monitor_back_initialize;
164         backend_add( &bi );
165         return 0;
166 }
167
168 #endif /* SLAPD_MONITOR_DYNAMIC */
169
170 int
171 monitor_back_initialize(
172         BackendInfo     *bi
173 )
174 {
175         static char *controls[] = {
176                 LDAP_CONTROL_MANAGEDSAIT,
177                 LDAP_CONTROL_VALUESRETURNFILTER,
178                 NULL
179         };
180
181         bi->bi_controls = controls;
182
183         bi->bi_init = 0;
184         bi->bi_open = 0;
185         bi->bi_config = monitor_back_config;
186         bi->bi_close = 0;
187         bi->bi_destroy = 0;
188
189         bi->bi_db_init = monitor_back_db_init;
190         bi->bi_db_config = monitor_back_db_config;
191         bi->bi_db_open = monitor_back_db_open;
192         bi->bi_db_close = 0;
193         bi->bi_db_destroy = monitor_back_db_destroy;
194
195         bi->bi_op_bind = monitor_back_bind;
196         bi->bi_op_unbind = 0;
197         bi->bi_op_search = monitor_back_search;
198         bi->bi_op_compare = monitor_back_compare;
199         bi->bi_op_modify = monitor_back_modify;
200         bi->bi_op_modrdn = 0;
201         bi->bi_op_add = 0;
202         bi->bi_op_delete = 0;
203         bi->bi_op_abandon = 0;
204
205         bi->bi_extended = 0;
206
207         bi->bi_entry_release_rw = 0;
208         bi->bi_chk_referrals = 0;
209         bi->bi_operational = monitor_back_operational;
210
211         /*
212          * hooks for slap tools
213          */
214         bi->bi_tool_entry_open = 0;
215         bi->bi_tool_entry_close = 0;
216         bi->bi_tool_entry_first = 0;
217         bi->bi_tool_entry_next = 0;
218         bi->bi_tool_entry_get = 0;
219         bi->bi_tool_entry_put = 0;
220         bi->bi_tool_entry_reindex = 0;
221         bi->bi_tool_sync = 0;
222
223         bi->bi_connection_init = 0;
224         bi->bi_connection_destroy = 0;
225
226         return 0;
227 }
228
229 int
230 monitor_back_db_init(
231         BackendDB       *be
232 )
233 {
234         struct monitorinfo      *mi;
235         int                     rc;
236         struct berval           dn, ndn;
237         struct berval           bv;
238
239         /*
240          * database monitor can be defined once only
241          */
242         if ( be_monitor ) {
243 #ifdef NEW_LOGGING
244                 LDAP_LOG( OPERATION, CRIT,
245                         "only one monitor backend is allowed\n", 0, 0, 0);
246 #else
247                 Debug( LDAP_DEBUG_ANY,
248                         "only one monitor backend is allowed\n", 0, 0, 0 );
249 #endif
250                 return( -1 );
251         }
252         be_monitor = be;
253
254         /* indicate system schema supported */
255         be->be_flags |= SLAP_BFLAG_MONITOR;
256
257         dn.bv_val = SLAPD_MONITOR_DN;
258         dn.bv_len = sizeof( SLAPD_MONITOR_DN ) - 1;
259
260         rc = dnNormalize( 0, NULL, NULL, &dn, &ndn, NULL );
261         if( rc != LDAP_SUCCESS ) {
262 #ifdef NEW_LOGGING
263                 LDAP_LOG( OPERATION, CRIT,
264                         "unable to normalize monitor DN \"%s\"\n",
265                         SLAPD_MONITOR_DN, 0, 0 );
266 #else
267                 Debug( LDAP_DEBUG_ANY,
268                         "unable to normalize monitor DN \"%s\"\n",
269                         SLAPD_MONITOR_DN, 0, 0 );
270 #endif
271                 return -1;
272         }
273
274         ber_dupbv( &bv, &dn );
275         ber_bvarray_add( &be->be_suffix, &bv );
276         ber_bvarray_add( &be->be_nsuffix, &ndn );
277
278         mi = ( struct monitorinfo * )ch_calloc( sizeof( struct monitorinfo ), 1 );
279         if ( mi == NULL ) {
280 #ifdef NEW_LOGGING
281                 LDAP_LOG( OPERATION, CRIT,
282                         "unable to initialize monitor backend\n", 0, 0, 0 );
283 #else
284                 Debug( LDAP_DEBUG_ANY,
285                         "unable to initialize monitor backend\n", 0, 0, 0 );
286 #endif
287                 return -1;
288         }
289
290         memset( mi, 0, sizeof( struct monitorinfo ) );
291
292         ldap_pvt_thread_mutex_init( &mi->mi_cache_mutex );
293
294         be->be_private = mi;
295         
296         return 0;
297 }
298
299 int
300 monitor_back_db_open(
301         BackendDB       *be
302 )
303 {
304         struct monitorinfo      *mi = (struct monitorinfo *)be->be_private;
305         struct monitorsubsys    *ms;
306         Entry                   *e, *e_tmp;
307         struct monitorentrypriv *mp;
308         int                     i, k;
309         char                    buf[ BACKMONITOR_BUFSIZE ], *end_of_line;
310         const char              *text;
311         struct berval           bv;
312         struct m_s {
313                 char    *name;
314                 char    *schema;
315                 slap_mask_t flags;
316                 int     offset;
317         } moc[] = {
318                 { "monitor", "( 1.3.6.1.4.1.4203.666.3.2 "
319                         "NAME 'monitor' "
320                         "DESC 'OpenLDAP system monitoring' "
321                         "SUP top STRUCTURAL "
322                         "MUST cn "
323                         "MAY ( "
324                                 "description "
325                                 "$ l "
326 #if 0   /* temporarily disabled */
327                                 "$ st "
328                                 "$ street "
329                                 "$ postalAddress "
330                                 "$ postalCode "
331 #endif
332                                 "$ seeAlso "
333                                 "$ monitoredInfo "
334                                 "$ managedInfo "
335                         ") )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
336                         offsetof(struct monitorinfo, mi_oc_monitor) },
337                 { "monitorServer", "( 1.3.6.1.4.1.4203.666.3.7 "
338                         "NAME 'monitorServer' "
339                         "DESC 'Server monitoring root entry' "
340                         "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
341                         offsetof(struct monitorinfo, mi_oc_monitorServer) },
342                 { "monitorContainer", "( 1.3.6.1.4.1.4203.666.3.8 "
343                         "NAME 'monitorContainer' "
344                         "DESC 'monitor container class' "
345                         "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
346                         offsetof(struct monitorinfo, mi_oc_monitorContainer) },
347                 { "monitorCounterObject", "( 1.3.6.1.4.1.4203.666.3.9 "
348                         "NAME 'monitorCounterObject' "
349                         "DESC 'monitor counter class' "
350                         "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
351                         offsetof(struct monitorinfo, mi_oc_monitorCounterObject) },
352                 { "monitorOperation", "( 1.3.6.1.4.1.4203.666.3.10 "
353                         "NAME 'monitorOperation' "
354                         "DESC 'monitor operation class' "
355                         "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
356                         offsetof(struct monitorinfo, mi_oc_monitorOperation) },
357                 { "monitorConnection", "( 1.3.6.1.4.1.4203.666.3.11 "
358                         "NAME 'monitorConnection' "
359                         "DESC 'monitor connection class' "
360                         "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
361                         offsetof(struct monitorinfo, mi_oc_monitorConnection) },
362                 { "managedObject", "( 1.3.6.1.4.1.4203.666.3.12 "
363                         "NAME 'managedObject' "
364                         "DESC 'monitor managed entity class' "
365                         "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
366                         offsetof(struct monitorinfo, mi_oc_managedObject) },
367                 { "monitoredObject", "( 1.3.6.1.4.1.4203.666.3.13 "
368                         "NAME 'monitoredObject' "
369                         "DESC 'monitor monitored entity class' "
370                         "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
371                         offsetof(struct monitorinfo, mi_oc_monitoredObject) },
372                 { NULL, NULL, 0, -1 }
373         }, mat[] = {
374                 { "monitoredInfo", "( 1.3.6.1.4.1.4203.666.1.14 "
375                         "NAME 'monitoredInfo' "
376                         "DESC 'monitored info' "
377                         /* "SUP name " */
378                         "EQUALITY caseIgnoreMatch "
379                         "SUBSTR caseIgnoreSubstringsMatch "
380                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} "
381                         "NO-USER-MODIFICATION "
382                         "USAGE directoryOperation )", SLAP_AT_HIDE,
383                         offsetof(struct monitorinfo, mi_ad_monitoredInfo) },
384                 { "managedInfo", "( 1.3.6.1.4.1.4203.666.1.15 "
385                         "NAME 'managedInfo' "
386                         "DESC 'monitor managed info' "
387                         "SUP name )", SLAP_AT_HIDE,
388                         offsetof(struct monitorinfo, mi_ad_managedInfo) },
389                 { "monitorCounter", "( 1.3.6.1.4.1.4203.666.1.16 "
390                         "NAME 'monitorCounter' "
391                         "DESC 'monitor counter' "
392                         "EQUALITY integerMatch "
393                         "ORDERING integerOrderingMatch "
394                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 "
395                         "NO-USER-MODIFICATION "
396                         "USAGE directoryOperation )", SLAP_AT_HIDE,
397                         offsetof(struct monitorinfo, mi_ad_monitorCounter) },
398                 { "monitorOpCompleted", "( 1.3.6.1.4.1.4203.666.1.17 "
399                         "NAME 'monitorOpCompleted' "
400                         "DESC 'monitor completed operations' "
401                         "SUP monitorCounter "
402                         "NO-USER-MODIFICATION "
403                         "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
404                         offsetof(struct monitorinfo, mi_ad_monitorOpCompleted) },
405                 { "monitorOpInitiated", "( 1.3.6.1.4.1.4203.666.1.18 "
406                         "NAME 'monitorOpInitiated' "
407                         "DESC 'monitor initiated operations' "
408                         "SUP monitorCounter "
409                         "NO-USER-MODIFICATION "
410                         "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
411                         offsetof(struct monitorinfo, mi_ad_monitorOpInitiated) },
412                 { "monitorConnectionNumber", "( 1.3.6.1.4.1.4203.666.1.19 "
413                         "NAME 'monitorConnectionNumber' "
414                         "DESC 'monitor connection number' "
415                         "SUP monitorCounter "
416                         "NO-USER-MODIFICATION "
417                         "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
418                         offsetof(struct monitorinfo, mi_ad_monitorConnectionNumber) },
419                 { "monitorConnectionAuthzDN", "( 1.3.6.1.4.1.4203.666.1.20 "
420                         "NAME 'monitorConnectionAuthzDN' "
421                         "DESC 'monitor connection authorization DN' "
422                         /* "SUP distinguishedName " */
423                         "EQUALITY distinguishedNameMatch "
424                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
425                         "NO-USER-MODIFICATION "
426                         "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
427                         offsetof(struct monitorinfo, mi_ad_monitorConnectionAuthzDN) },
428                 { "monitorConnectionLocalAddress", "( 1.3.6.1.4.1.4203.666.1.21 "
429                         "NAME 'monitorConnectionLocalAddress' "
430                         "DESC 'monitor connection local address' "
431                         "SUP monitoredInfo "
432                         "NO-USER-MODIFICATION "
433                         "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
434                         offsetof(struct monitorinfo, mi_ad_monitorConnectionLocalAddress) },
435                 { "monitorConnectionPeerAddress", "( 1.3.6.1.4.1.4203.666.1.22 "
436                         "NAME 'monitorConnectionPeerAddress' "
437                         "DESC 'monitor connection peer address' "
438                         "SUP monitoredInfo "
439                         "NO-USER-MODIFICATION "
440                         "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
441                         offsetof(struct monitorinfo, mi_ad_monitorConnectionPeerAddress) },
442                 { "monitorTimestamp", "( 1.3.6.1.4.1.4203.666.1.24 "
443                         "NAME 'monitorTimestamp' "
444                         "DESC 'monitor timestamp' "
445                         "EQUALITY generalizedTimeMatch "
446                         "ORDERING generalizedTimeOrderingMatch "
447                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 "
448                         "SINGLE-VALUE "
449                         "NO-USER-MODIFICATION "
450                         "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
451                         offsetof(struct monitorinfo, mi_ad_monitorTimestamp) },
452 #ifdef INTEGRATE_CORE_SCHEMA
453                 { NULL, NULL, 0, -1 },  /* description */
454                 { NULL, NULL, 0, -1 },  /* seeAlso */
455                 { NULL, NULL, 0, -1 },  /* l */
456 #endif /* INTEGRATE_CORE_SCHEMA */
457                 { NULL, NULL, 0, -1 }
458         }, mat_core[] = {
459                 { "description", "( 2.5.4.13 "
460                         "NAME 'description' "
461                         "DESC 'RFC2256: descriptive information' "
462                         "EQUALITY caseIgnoreMatch "
463                         "SUBSTR caseIgnoreSubstringsMatch "
464                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{1024} )", 0,
465                         offsetof(struct monitorinfo, mi_ad_description) },
466                 { "seeAlso", "( 2.5.4.34 "
467                         "NAME 'seeAlso' "
468                         "DESC 'RFC2256: DN of related object' "
469                         "SUP distinguishedName )", 0,
470                         offsetof(struct monitorinfo, mi_ad_seeAlso) },
471                 { "l", "( 2.5.4.7 "
472                         "NAME ( 'l' 'localityName' ) "
473                         "DESC 'RFC2256: locality which this object resides in' "
474                         "SUP name )", 0,
475                         offsetof(struct monitorinfo, mi_ad_l) },
476                 { NULL, NULL, 0, -1 }
477         };
478         
479         struct tm               *tms;
480         static char             tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
481
482         /*
483          * Start
484          */
485         ldap_pvt_thread_mutex_lock( &gmtime_mutex );
486 #ifdef HACK_LOCAL_TIME
487         tms = localtime( &starttime );
488         lutil_localtime( tmbuf, sizeof(tmbuf), tms, -timezone );
489 #else /* !HACK_LOCAL_TIME */
490         tms = gmtime( &starttime );
491         lutil_gentime( tmbuf, sizeof(tmbuf), tms );
492 #endif /* !HACK_LOCAL_TIME */
493         ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
494
495         mi->mi_startTime.bv_val = tmbuf;
496         mi->mi_startTime.bv_len = strlen( tmbuf );
497
498 #ifdef INTEGRATE_CORE_SCHEMA
499         /* prepare for schema integration */
500         for ( k = 0; mat[k].name != NULL; k++ );
501 #endif /* INTEGRATE_CORE_SCHEMA */
502
503         for ( i = 0; mat_core[i].name != NULL; i++ ) {
504                 AttributeDescription    **ad;
505                 const char              *text;
506
507                 ad = ((AttributeDescription **)&(((char *)mi)[mat_core[i].offset]));
508                 ad[0] = NULL;
509
510                 switch (slap_str2ad( mat_core[i].name, ad, &text ) ) {
511                 case LDAP_SUCCESS:
512                         break;
513
514 #ifdef INTEGRATE_CORE_SCHEMA
515                 case LDAP_UNDEFINED_TYPE:
516                         mat[k] = mat_core[i];
517                         k++;
518                         break;
519 #endif /* INTEGRATE_CORE_SCHEMA */
520
521                 default:
522 #ifdef NEW_LOGGING
523                         LDAP_LOG( OPERATION, CRIT,
524                                 "monitor_back_db_init: %s: %s\n",
525                                 mat_core[i].name, text, 0 );
526 #else
527                         Debug( LDAP_DEBUG_ANY,
528                                 "monitor_back_db_init: %s: %s\n",
529                                 mat_core[i].name, text, 0 );
530 #endif
531                         return( -1 );
532                 }
533         }
534
535         /* schema integration */
536         for ( i = 0; mat[i].name; i++ ) {
537                 LDAPAttributeType       *at;
538                 int                     code;
539                 const char              *err;
540                 AttributeDescription    **ad;
541
542                 at = ldap_str2attributetype( mat[i].schema, &code,
543                         &err, LDAP_SCHEMA_ALLOW_ALL );
544                 if ( !at ) {
545 #ifdef NEW_LOGGING
546                         LDAP_LOG( OPERATION, CRIT, "monitor_back_db_init: "
547                                 "in AttributeType '%s' %s before %s\n",
548                                 mat[i].name, ldap_scherr2str(code), err );
549 #else
550                         Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
551                                 "in AttributeType '%s' %s before %s\n",
552                                 mat[i].name, ldap_scherr2str(code), err );
553 #endif
554                         return -1;
555                 }
556
557                 if ( at->at_oid == NULL ) {
558 #ifdef NEW_LOGGING
559                         LDAP_LOG( OPERATION, CRIT, "monitor_back_db_init: "
560                                 "null OID for attributeType '%s'\n",
561                                 mat[i].name, 0, 0 );
562 #else
563                         Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
564                                 "null OID for attributeType '%s'\n",
565                                 mat[i].name, 0, 0 );
566 #endif
567                         return -1;
568                 }
569
570                 code = at_add(at, &err);
571                 if ( code ) {
572 #ifdef NEW_LOGGING
573                         LDAP_LOG( OPERATION, CRIT, "monitor_back_db_init: "
574                                 "%s in attributeType '%s'\n",
575                                 scherr2str(code), mat[i].name, 0 );
576 #else
577                         Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
578                                 "%s in attributeType '%s'\n",
579                                 scherr2str(code), mat[i].name, 0 );
580 #endif
581                         return -1;
582                 }
583                 ldap_memfree(at);
584
585                 ad = ((AttributeDescription **)&(((char *)mi)[mat[i].offset]));
586                 ad[0] = NULL;
587                 if ( slap_str2ad( mat[i].name, ad, &text ) ) {
588 #ifdef NEW_LOGGING
589                         LDAP_LOG( OPERATION, CRIT,
590                                 "monitor_back_db_init: %s\n", text, 0, 0 );
591 #else
592                         Debug( LDAP_DEBUG_ANY,
593                                 "monitor_back_db_init: %s\n", text, 0, 0 );
594 #endif
595                         return -1;
596                 }
597
598                 (*ad)->ad_type->sat_flags |= mat[i].flags;
599         }
600
601         for ( i = 0; moc[i].name; i++ ) {
602                 LDAPObjectClass         *oc;
603                 int                     code;
604                 const char              *err;
605                 ObjectClass             *Oc;
606
607                 oc = ldap_str2objectclass(moc[i].schema, &code, &err,
608                                 LDAP_SCHEMA_ALLOW_ALL );
609                 if ( !oc ) {
610 #ifdef NEW_LOGGING
611                         LDAP_LOG( OPERATION, CRIT,
612                                 "unable to parse monitor objectclass '%s': "
613                                 "%s before %s\n" , moc[i].name,
614                                 ldap_scherr2str(code), err );
615 #else
616                         Debug( LDAP_DEBUG_ANY,
617                                 "unable to parse monitor objectclass '%s': "
618                                 "%s before %s\n" , moc[i].name,
619                                 ldap_scherr2str(code), err );
620 #endif
621                         return -1;
622                 }
623
624                 if ( oc->oc_oid == NULL ) {
625 #ifdef NEW_LOGGING
626                         LDAP_LOG( OPERATION, CRIT,
627                                 "objectclass '%s' has no OID\n" ,
628                                 moc[i].name, 0, 0 );
629 #else
630                         Debug( LDAP_DEBUG_ANY,
631                                 "objectclass '%s' has no OID\n" ,
632                                 moc[i].name, 0, 0 );
633 #endif
634                         return -1;
635                 }
636
637                 code = oc_add(oc, 0, &err);
638                 if ( code ) {
639 #ifdef NEW_LOGGING
640                         LDAP_LOG( OPERATION, CRIT,
641                                 "objectclass '%s': %s \"%s\"\n" ,
642                                 moc[i].name, scherr2str(code), err );
643 #else
644                         Debug( LDAP_DEBUG_ANY,
645                                 "objectclass '%s': %s \"%s\"\n" ,
646                                 moc[i].name, scherr2str(code), err );
647 #endif
648                         return -1;
649                 }
650
651                 ldap_memfree(oc);
652
653                 Oc = oc_find( moc[i].name );
654                 if ( Oc == NULL ) {
655 #ifdef NEW_LOGGING
656                         LDAP_LOG( OPERATION, CRIT, "monitor_back_db_init: "
657                                         "unable to find objectClass %s "
658                                         "(just added)\n", moc[i].name, 0, 0 );
659 #else
660                         Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
661                                         "unable to find objectClass %s "
662                                         "(just added)\n", moc[i].name, 0, 0 );
663 #endif
664                         return -1;
665                 }
666
667                 Oc->soc_flags |= moc[i].flags;
668
669                 ((ObjectClass **)&(((char *)mi)[moc[i].offset]))[0] = Oc;
670         }
671
672         /*      
673          * Create all the subsystem specific entries
674          */
675         e_tmp = NULL;
676         for ( i = 0; monitor_subsys[ i ].mss_name != NULL; i++ ) {
677                 int             len = strlen( monitor_subsys[ i ].mss_name );
678                 struct berval   dn;
679                 int             rc;
680
681                 dn.bv_len = len + sizeof( "cn=" ) - 1;
682                 dn.bv_val = ch_calloc( sizeof( char ), dn.bv_len + 1 );
683                 strcpy( dn.bv_val, "cn=" );
684                 strcat( dn.bv_val, monitor_subsys[ i ].mss_name );
685                 rc = dnPretty( NULL, &dn, &monitor_subsys[ i ].mss_rdn, NULL );
686                 free( dn.bv_val );
687                 if ( rc != LDAP_SUCCESS ) {
688 #ifdef NEW_LOGGING
689                         LDAP_LOG( OPERATION, CRIT,
690                                 "monitor RDN \"%s\" is invalid\n", 
691                                 dn.bv_val, 0, 0 );
692 #else
693                         Debug( LDAP_DEBUG_ANY,
694                                 "monitor RDN \"%s\" is invalid\n", 
695                                 dn.bv_val, 0, 0 );
696 #endif
697                         return( -1 );
698                 }
699
700                 dn.bv_len += sizeof( SLAPD_MONITOR_DN ); /* 1 for the , */
701                 dn.bv_val = ch_malloc( dn.bv_len + 1 );
702                 strcpy( dn.bv_val , monitor_subsys[ i ].mss_rdn.bv_val );
703                 strcat( dn.bv_val, "," SLAPD_MONITOR_DN );
704                 rc = dnPrettyNormal( NULL, &dn, &monitor_subsys[ i ].mss_dn,
705                         &monitor_subsys[ i ].mss_ndn, NULL );
706                 free( dn.bv_val );
707                 if ( rc != LDAP_SUCCESS ) {
708 #ifdef NEW_LOGGING
709                         LDAP_LOG( OPERATION, CRIT,
710                                 "monitor DN \"%s\" is invalid\n", 
711                                 dn.bv_val, 0, 0 );
712 #else
713                         Debug( LDAP_DEBUG_ANY,
714                                 "monitor DN \"%s\" is invalid\n", 
715                                 dn.bv_val, 0, 0 );
716 #endif
717                         return( -1 );
718                 }
719
720                 snprintf( buf, sizeof( buf ),
721                                 "dn: %s\n"
722                                 "objectClass: %s\n"
723                                 "structuralObjectClass: %s\n"
724                                 "cn: %s\n"
725                                 "createTimestamp: %s\n"
726                                 "modifyTimestamp: %s\n",
727                                 monitor_subsys[ i ].mss_dn.bv_val,
728                                 mi->mi_oc_monitorContainer->soc_cname.bv_val,
729                                 mi->mi_oc_monitorContainer->soc_cname.bv_val,
730                                 monitor_subsys[ i ].mss_name,
731                                 mi->mi_startTime.bv_val,
732                                 mi->mi_startTime.bv_val );
733                 
734                 e = str2entry( buf );
735                 
736                 if ( e == NULL) {
737 #ifdef NEW_LOGGING
738                         LDAP_LOG( OPERATION, CRIT,
739                                 "unable to create '%s' entry\n", 
740                                 monitor_subsys[ i ].mss_dn.bv_val, 0, 0 );
741 #else
742                         Debug( LDAP_DEBUG_ANY,
743                                 "unable to create '%s' entry\n", 
744                                 monitor_subsys[ i ].mss_dn.bv_val, 0, 0 );
745 #endif
746                         return( -1 );
747                 }
748
749                 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
750                 e->e_private = ( void * )mp;
751                 mp->mp_info = &monitor_subsys[ i ];
752                 mp->mp_children = NULL;
753                 mp->mp_next = e_tmp;
754                 mp->mp_flags = monitor_subsys[ i ].mss_flags;
755
756                 if ( monitor_cache_add( mi, e ) ) {
757 #ifdef NEW_LOGGING
758                         LDAP_LOG( OPERATION, CRIT,
759                                 "unable to add entry '%s' to cache\n",
760                                 monitor_subsys[ i ].mss_dn.bv_val, 0, 0 );
761 #else
762                         Debug( LDAP_DEBUG_ANY,
763                                 "unable to add entry '%s' to cache\n",
764                                 monitor_subsys[ i ].mss_dn.bv_val, 0, 0 );
765 #endif
766                         return -1;
767                 }
768
769                 e_tmp = e;
770         }
771
772         /*
773          * creates the "cn=Monitor" entry 
774          */
775         snprintf( buf, sizeof( buf ), 
776                 "dn: %s\n"
777                 "objectClass: %s\n"
778                 "structuralObjectClass: %s\n"
779                 "cn: Monitor\n"
780                 "%s: This subtree contains monitoring/managing objects.\n"
781                 "%s: This object contains information about this server.\n"
782 #if 0
783                 "%s: createTimestamp reflects the time this server instance was created.\n"
784                 "%s: modifyTimestamp reflects the time this server instance was last accessed.\n"
785 #endif
786                 "createTimestamp: %s\n"
787                 "modifyTimestamp: %s\n",
788                 SLAPD_MONITOR_DN,
789                 mi->mi_oc_monitorServer->soc_cname.bv_val,
790                 mi->mi_oc_monitorServer->soc_cname.bv_val,
791                 mi->mi_ad_description->ad_cname.bv_val,
792                 mi->mi_ad_description->ad_cname.bv_val,
793 #if 0
794                 mi->mi_ad_description->ad_cname.bv_val,
795                 mi->mi_ad_description->ad_cname.bv_val,
796 #endif
797                 mi->mi_startTime.bv_val,
798                 mi->mi_startTime.bv_val );
799
800         e = str2entry( buf );
801         if ( e == NULL) {
802 #ifdef NEW_LOGGING
803                 LDAP_LOG( OPERATION, CRIT,
804                         "unable to create '%s' entry\n",
805                         SLAPD_MONITOR_DN, 0, 0 );
806 #else
807                 Debug( LDAP_DEBUG_ANY,
808                         "unable to create '%s' entry\n",
809                         SLAPD_MONITOR_DN, 0, 0 );
810 #endif
811                 return( -1 );
812         }
813
814         bv.bv_val = (char *) Versionstr;
815         end_of_line = strchr( Versionstr, '\n' );
816         if ( end_of_line ) {
817                 bv.bv_len = end_of_line - Versionstr;
818         } else {
819                 bv.bv_len = strlen( Versionstr );
820         }
821
822         if ( attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
823                                 &bv, NULL ) ) {
824 #ifdef NEW_LOGGING
825                 LDAP_LOG( OPERATION, CRIT,
826                         "unable to add monitoredInfo to '%s' entry\n",
827                         SLAPD_MONITOR_DN, 0, 0 );
828 #else
829                 Debug( LDAP_DEBUG_ANY,
830                         "unable to add monitoredInfo to '%s' entry\n",
831                         SLAPD_MONITOR_DN, 0, 0 );
832 #endif
833                 return( -1 );
834         }
835
836         if ( mi->mi_l.bv_len ) {
837                 if ( attr_merge_normalize_one( e, mi->mi_ad_l, &mi->mi_l, NULL ) ) {
838 #ifdef NEW_LOGGING
839                         LDAP_LOG( OPERATION, CRIT,
840                                 "unable to add locality to '%s' entry\n",
841                                 SLAPD_MONITOR_DN, 0, 0 );
842 #else
843                         Debug( LDAP_DEBUG_ANY,
844                                 "unable to add locality to '%s' entry\n",
845                                 SLAPD_MONITOR_DN, 0, 0 );
846 #endif
847                         return( -1 );
848                 }
849         }
850
851         mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
852         e->e_private = ( void * )mp;
853
854         mp->mp_info = NULL;
855         mp->mp_children = e_tmp;
856         mp->mp_next = NULL;
857
858         if ( monitor_cache_add( mi, e ) ) {
859 #ifdef NEW_LOGGING
860                 LDAP_LOG( OPERATION, CRIT,
861                         "unable to add entry '%s' to cache\n",
862                         SLAPD_MONITOR_DN, 0, 0 );
863 #else
864                 Debug( LDAP_DEBUG_ANY,
865                         "unable to add entry '%s' to cache\n",
866                         SLAPD_MONITOR_DN, 0, 0 );
867 #endif
868                 return -1;
869         }
870
871         be->be_private = mi;
872         
873         assert( be );
874
875         /*
876          * opens the monitor backend
877          */
878         for ( ms = monitor_subsys; ms->mss_name != NULL; ms++ ) {
879                 if ( ms->mss_init && ( *ms->mss_init )( be ) ) {
880                         return( -1 );
881                 }
882         }
883
884         return( 0 );
885 }
886
887 int
888 monitor_back_config(
889         BackendInfo     *bi,
890         const char      *fname,
891         int             lineno,
892         int             argc,
893         char            **argv
894 )
895 {
896         /*
897          * eventually, will hold backend specific configuration parameters
898          */
899         return 0;
900 }
901
902 int
903 monitor_back_db_config(
904         Backend     *be,
905         const char  *fname,
906         int         lineno,
907         int         argc,
908         char        **argv
909 )
910 {
911         struct monitorinfo *mi = (struct monitorinfo *)be->be_private;
912
913         /*
914          * eventually, will hold database specific configuration parameters
915          */
916         if ( strcasecmp( argv[ 0 ], "l" ) == 0 ) {
917                 if ( argc != 2 ) {
918                         return 1;
919                 }
920                 
921                 ber_str2bv( argv[ 1 ], 0, 1, &mi->mi_l );
922
923         } else {
924 #ifdef NEW_LOGGING
925                 LDAP_LOG( CONFIG, INFO,
926                         "line %d of file '%s' will be ignored\n",
927                         lineno, fname, 0 );
928 #else
929                 Debug( LDAP_DEBUG_CONFIG, 
930                         "line %d of file '%s' will be ignored\n",
931                         lineno, fname, 0 );
932 #endif
933         }
934
935         return( 0 );
936 }
937
938 int
939 monitor_back_db_destroy(
940         BackendDB       *be
941 )
942 {
943         /*
944          * FIXME: destroys all the data
945          */
946         return 0;
947 }
948