]> git.sur5r.net Git - openldap/blob - servers/slapd/back-monitor/init.c
slaptool update for LDAP Sync replication
[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 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         bi->bi_tool_dn2id_get = 0;
223         bi->bi_tool_id2entry_get = 0;
224         bi->bi_tool_entry_modify = 0;
225
226         bi->bi_connection_init = 0;
227         bi->bi_connection_destroy = 0;
228
229         return 0;
230 }
231
232 int
233 monitor_back_db_init(
234         BackendDB       *be
235 )
236 {
237         struct monitorinfo      *mi;
238         int                     rc;
239         struct berval           dn, ndn;
240         struct berval           bv;
241
242         /*
243          * database monitor can be defined once only
244          */
245         if ( be_monitor ) {
246 #ifdef NEW_LOGGING
247                 LDAP_LOG( OPERATION, CRIT,
248                         "only one monitor backend is allowed\n", 0, 0, 0);
249 #else
250                 Debug( LDAP_DEBUG_ANY,
251                         "only one monitor backend is allowed\n", 0, 0, 0 );
252 #endif
253                 return( -1 );
254         }
255         be_monitor = be;
256
257         /* indicate system schema supported */
258         be->be_flags |= SLAP_BFLAG_MONITOR;
259
260         dn.bv_val = SLAPD_MONITOR_DN;
261         dn.bv_len = sizeof( SLAPD_MONITOR_DN ) - 1;
262
263         rc = dnNormalize( 0, NULL, NULL, &dn, &ndn, NULL );
264         if( rc != LDAP_SUCCESS ) {
265 #ifdef NEW_LOGGING
266                 LDAP_LOG( OPERATION, CRIT,
267                         "unable to normalize monitor DN \"%s\"\n",
268                         SLAPD_MONITOR_DN, 0, 0 );
269 #else
270                 Debug( LDAP_DEBUG_ANY,
271                         "unable to normalize monitor DN \"%s\"\n",
272                         SLAPD_MONITOR_DN, 0, 0 );
273 #endif
274                 return -1;
275         }
276
277         ber_dupbv( &bv, &dn );
278         ber_bvarray_add( &be->be_suffix, &bv );
279         ber_bvarray_add( &be->be_nsuffix, &ndn );
280
281         mi = ( struct monitorinfo * )ch_calloc( sizeof( struct monitorinfo ), 1 );
282         if ( mi == NULL ) {
283 #ifdef NEW_LOGGING
284                 LDAP_LOG( OPERATION, CRIT,
285                         "unable to initialize monitor backend\n", 0, 0, 0 );
286 #else
287                 Debug( LDAP_DEBUG_ANY,
288                         "unable to initialize monitor backend\n", 0, 0, 0 );
289 #endif
290                 return -1;
291         }
292
293         memset( mi, 0, sizeof( struct monitorinfo ) );
294
295         ldap_pvt_thread_mutex_init( &mi->mi_cache_mutex );
296
297         be->be_private = mi;
298         
299         return 0;
300 }
301
302 int
303 monitor_back_db_open(
304         BackendDB       *be
305 )
306 {
307         struct monitorinfo      *mi = (struct monitorinfo *)be->be_private;
308         struct monitorsubsys    *ms;
309         Entry                   *e, *e_tmp;
310         struct monitorentrypriv *mp;
311         int                     i, k;
312         char                    buf[ BACKMONITOR_BUFSIZE ], *end_of_line;
313         const char              *text;
314         struct berval           bv;
315         struct m_s {
316                 char    *name;
317                 char    *schema;
318                 slap_mask_t flags;
319                 int     offset;
320         } moc[] = {
321                 { "monitor", "( 1.3.6.1.4.1.4203.666.3.2 "
322                         "NAME 'monitor' "
323                         "DESC 'OpenLDAP system monitoring' "
324                         "SUP top STRUCTURAL "
325                         "MUST cn "
326                         "MAY ( "
327                                 "description "
328                                 "$ l "
329 #if 0   /* temporarily disabled */
330                                 "$ st "
331                                 "$ street "
332                                 "$ postalAddress "
333                                 "$ postalCode "
334 #endif
335                                 "$ seeAlso "
336                                 "$ monitoredInfo "
337                                 "$ managedInfo "
338                         ") )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
339                         offsetof(struct monitorinfo, mi_oc_monitor) },
340                 { "monitorServer", "( 1.3.6.1.4.1.4203.666.3.7 "
341                         "NAME 'monitorServer' "
342                         "DESC 'Server monitoring root entry' "
343                         "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
344                         offsetof(struct monitorinfo, mi_oc_monitorServer) },
345                 { "monitorContainer", "( 1.3.6.1.4.1.4203.666.3.8 "
346                         "NAME 'monitorContainer' "
347                         "DESC 'monitor container class' "
348                         "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
349                         offsetof(struct monitorinfo, mi_oc_monitorContainer) },
350                 { "monitorCounterObject", "( 1.3.6.1.4.1.4203.666.3.9 "
351                         "NAME 'monitorCounterObject' "
352                         "DESC 'monitor counter class' "
353                         "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
354                         offsetof(struct monitorinfo, mi_oc_monitorCounterObject) },
355                 { "monitorOperation", "( 1.3.6.1.4.1.4203.666.3.10 "
356                         "NAME 'monitorOperation' "
357                         "DESC 'monitor operation class' "
358                         "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
359                         offsetof(struct monitorinfo, mi_oc_monitorOperation) },
360                 { "monitorConnection", "( 1.3.6.1.4.1.4203.666.3.11 "
361                         "NAME 'monitorConnection' "
362                         "DESC 'monitor connection class' "
363                         "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
364                         offsetof(struct monitorinfo, mi_oc_monitorConnection) },
365                 { "managedObject", "( 1.3.6.1.4.1.4203.666.3.12 "
366                         "NAME 'managedObject' "
367                         "DESC 'monitor managed entity class' "
368                         "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
369                         offsetof(struct monitorinfo, mi_oc_managedObject) },
370                 { "monitoredObject", "( 1.3.6.1.4.1.4203.666.3.13 "
371                         "NAME 'monitoredObject' "
372                         "DESC 'monitor monitored entity class' "
373                         "SUP monitor STRUCTURAL )", SLAP_OC_OPERATIONAL|SLAP_OC_HIDE,
374                         offsetof(struct monitorinfo, mi_oc_monitoredObject) },
375                 { NULL, NULL, 0, -1 }
376         }, mat[] = {
377                 { "monitoredInfo", "( 1.3.6.1.4.1.4203.666.1.14 "
378                         "NAME 'monitoredInfo' "
379                         "DESC 'monitored info' "
380                         /* "SUP name " */
381                         "EQUALITY caseIgnoreMatch "
382                         "SUBSTR caseIgnoreSubstringsMatch "
383                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} "
384                         "NO-USER-MODIFICATION "
385                         "USAGE directoryOperation )", SLAP_AT_HIDE,
386                         offsetof(struct monitorinfo, mi_ad_monitoredInfo) },
387                 { "managedInfo", "( 1.3.6.1.4.1.4203.666.1.15 "
388                         "NAME 'managedInfo' "
389                         "DESC 'monitor managed info' "
390                         "SUP name )", SLAP_AT_HIDE,
391                         offsetof(struct monitorinfo, mi_ad_managedInfo) },
392                 { "monitorCounter", "( 1.3.6.1.4.1.4203.666.1.16 "
393                         "NAME 'monitorCounter' "
394                         "DESC 'monitor counter' "
395                         "EQUALITY integerMatch "
396                         "ORDERING integerOrderingMatch "
397                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 "
398                         "NO-USER-MODIFICATION "
399                         "USAGE directoryOperation )", SLAP_AT_HIDE,
400                         offsetof(struct monitorinfo, mi_ad_monitorCounter) },
401                 { "monitorOpCompleted", "( 1.3.6.1.4.1.4203.666.1.17 "
402                         "NAME 'monitorOpCompleted' "
403                         "DESC 'monitor completed operations' "
404                         "SUP monitorCounter "
405                         "NO-USER-MODIFICATION "
406                         "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
407                         offsetof(struct monitorinfo, mi_ad_monitorOpCompleted) },
408                 { "monitorOpInitiated", "( 1.3.6.1.4.1.4203.666.1.18 "
409                         "NAME 'monitorOpInitiated' "
410                         "DESC 'monitor initiated operations' "
411                         "SUP monitorCounter "
412                         "NO-USER-MODIFICATION "
413                         "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
414                         offsetof(struct monitorinfo, mi_ad_monitorOpInitiated) },
415                 { "monitorConnectionNumber", "( 1.3.6.1.4.1.4203.666.1.19 "
416                         "NAME 'monitorConnectionNumber' "
417                         "DESC 'monitor connection number' "
418                         "SUP monitorCounter "
419                         "NO-USER-MODIFICATION "
420                         "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
421                         offsetof(struct monitorinfo, mi_ad_monitorConnectionNumber) },
422                 { "monitorConnectionAuthzDN", "( 1.3.6.1.4.1.4203.666.1.20 "
423                         "NAME 'monitorConnectionAuthzDN' "
424                         "DESC 'monitor connection authorization DN' "
425                         /* "SUP distinguishedName " */
426                         "EQUALITY distinguishedNameMatch "
427                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
428                         "NO-USER-MODIFICATION "
429                         "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
430                         offsetof(struct monitorinfo, mi_ad_monitorConnectionAuthzDN) },
431                 { "monitorConnectionLocalAddress", "( 1.3.6.1.4.1.4203.666.1.21 "
432                         "NAME 'monitorConnectionLocalAddress' "
433                         "DESC 'monitor connection local address' "
434                         "SUP monitoredInfo "
435                         "NO-USER-MODIFICATION "
436                         "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
437                         offsetof(struct monitorinfo, mi_ad_monitorConnectionLocalAddress) },
438                 { "monitorConnectionPeerAddress", "( 1.3.6.1.4.1.4203.666.1.22 "
439                         "NAME 'monitorConnectionPeerAddress' "
440                         "DESC 'monitor connection peer address' "
441                         "SUP monitoredInfo "
442                         "NO-USER-MODIFICATION "
443                         "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
444                         offsetof(struct monitorinfo, mi_ad_monitorConnectionPeerAddress) },
445                 { "monitorTimestamp", "( 1.3.6.1.4.1.4203.666.1.24 "
446                         "NAME 'monitorTimestamp' "
447                         "DESC 'monitor timestamp' "
448                         "EQUALITY generalizedTimeMatch "
449                         "ORDERING generalizedTimeOrderingMatch "
450                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 "
451                         "SINGLE-VALUE "
452                         "NO-USER-MODIFICATION "
453                         "USAGE directoryOperation )", SLAP_AT_FINAL|SLAP_AT_HIDE,
454                         offsetof(struct monitorinfo, mi_ad_monitorTimestamp) },
455 #ifdef INTEGRATE_CORE_SCHEMA
456                 { NULL, NULL, 0, -1 },  /* description */
457                 { NULL, NULL, 0, -1 },  /* seeAlso */
458                 { NULL, NULL, 0, -1 },  /* l */
459 #endif /* INTEGRATE_CORE_SCHEMA */
460                 { NULL, NULL, 0, -1 }
461         }, mat_core[] = {
462                 { "description", "( 2.5.4.13 "
463                         "NAME 'description' "
464                         "DESC 'RFC2256: descriptive information' "
465                         "EQUALITY caseIgnoreMatch "
466                         "SUBSTR caseIgnoreSubstringsMatch "
467                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{1024} )", 0,
468                         offsetof(struct monitorinfo, mi_ad_description) },
469                 { "seeAlso", "( 2.5.4.34 "
470                         "NAME 'seeAlso' "
471                         "DESC 'RFC2256: DN of related object' "
472                         "SUP distinguishedName )", 0,
473                         offsetof(struct monitorinfo, mi_ad_seeAlso) },
474                 { "l", "( 2.5.4.7 "
475                         "NAME ( 'l' 'localityName' ) "
476                         "DESC 'RFC2256: locality which this object resides in' "
477                         "SUP name )", 0,
478                         offsetof(struct monitorinfo, mi_ad_l) },
479                 { NULL, NULL, 0, -1 }
480         };
481         
482         struct tm               *tms;
483         static char             tmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
484
485         /*
486          * Start
487          */
488         ldap_pvt_thread_mutex_lock( &gmtime_mutex );
489 #ifdef HACK_LOCAL_TIME
490         tms = localtime( &starttime );
491         lutil_localtime( tmbuf, sizeof(tmbuf), tms, -timezone );
492 #else /* !HACK_LOCAL_TIME */
493         tms = gmtime( &starttime );
494         lutil_gentime( tmbuf, sizeof(tmbuf), tms );
495 #endif /* !HACK_LOCAL_TIME */
496         ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
497
498         mi->mi_startTime.bv_val = tmbuf;
499         mi->mi_startTime.bv_len = strlen( tmbuf );
500
501 #ifdef INTEGRATE_CORE_SCHEMA
502         /* prepare for schema integration */
503         for ( k = 0; mat[k].name != NULL; k++ );
504 #endif /* INTEGRATE_CORE_SCHEMA */
505
506         for ( i = 0; mat_core[i].name != NULL; i++ ) {
507                 AttributeDescription    **ad;
508                 const char              *text;
509
510                 ad = ((AttributeDescription **)&(((char *)mi)[mat_core[i].offset]));
511                 ad[0] = NULL;
512
513                 switch (slap_str2ad( mat_core[i].name, ad, &text ) ) {
514                 case LDAP_SUCCESS:
515                         break;
516
517 #ifdef INTEGRATE_CORE_SCHEMA
518                 case LDAP_UNDEFINED_TYPE:
519                         mat[k] = mat_core[i];
520                         k++;
521                         break;
522 #endif /* INTEGRATE_CORE_SCHEMA */
523
524                 default:
525 #ifdef NEW_LOGGING
526                         LDAP_LOG( OPERATION, CRIT,
527                                 "monitor_back_db_init: %s: %s\n",
528                                 mat_core[i].name, text, 0 );
529 #else
530                         Debug( LDAP_DEBUG_ANY,
531                                 "monitor_back_db_init: %s: %s\n",
532                                 mat_core[i].name, text, 0 );
533 #endif
534                         return( -1 );
535                 }
536         }
537
538         /* schema integration */
539         for ( i = 0; mat[i].name; i++ ) {
540                 LDAPAttributeType       *at;
541                 int                     code;
542                 const char              *err;
543                 AttributeDescription    **ad;
544
545                 at = ldap_str2attributetype( mat[i].schema, &code,
546                         &err, LDAP_SCHEMA_ALLOW_ALL );
547                 if ( !at ) {
548 #ifdef NEW_LOGGING
549                         LDAP_LOG( OPERATION, CRIT, "monitor_back_db_init: "
550                                 "in AttributeType '%s' %s before %s\n",
551                                 mat[i].name, ldap_scherr2str(code), err );
552 #else
553                         Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
554                                 "in AttributeType '%s' %s before %s\n",
555                                 mat[i].name, ldap_scherr2str(code), err );
556 #endif
557                         return -1;
558                 }
559
560                 if ( at->at_oid == NULL ) {
561 #ifdef NEW_LOGGING
562                         LDAP_LOG( OPERATION, CRIT, "monitor_back_db_init: "
563                                 "null OID for attributeType '%s'\n",
564                                 mat[i].name, 0, 0 );
565 #else
566                         Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
567                                 "null OID for attributeType '%s'\n",
568                                 mat[i].name, 0, 0 );
569 #endif
570                         return -1;
571                 }
572
573                 code = at_add(at, &err);
574                 if ( code ) {
575 #ifdef NEW_LOGGING
576                         LDAP_LOG( OPERATION, CRIT, "monitor_back_db_init: "
577                                 "%s in attributeType '%s'\n",
578                                 scherr2str(code), mat[i].name, 0 );
579 #else
580                         Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
581                                 "%s in attributeType '%s'\n",
582                                 scherr2str(code), mat[i].name, 0 );
583 #endif
584                         return -1;
585                 }
586                 ldap_memfree(at);
587
588                 ad = ((AttributeDescription **)&(((char *)mi)[mat[i].offset]));
589                 ad[0] = NULL;
590                 if ( slap_str2ad( mat[i].name, ad, &text ) ) {
591 #ifdef NEW_LOGGING
592                         LDAP_LOG( OPERATION, CRIT,
593                                 "monitor_back_db_init: %s\n", text, 0, 0 );
594 #else
595                         Debug( LDAP_DEBUG_ANY,
596                                 "monitor_back_db_init: %s\n", text, 0, 0 );
597 #endif
598                         return -1;
599                 }
600
601                 (*ad)->ad_type->sat_flags |= mat[i].flags;
602         }
603
604         for ( i = 0; moc[i].name; i++ ) {
605                 LDAPObjectClass         *oc;
606                 int                     code;
607                 const char              *err;
608                 ObjectClass             *Oc;
609
610                 oc = ldap_str2objectclass(moc[i].schema, &code, &err,
611                                 LDAP_SCHEMA_ALLOW_ALL );
612                 if ( !oc ) {
613 #ifdef NEW_LOGGING
614                         LDAP_LOG( OPERATION, CRIT,
615                                 "unable to parse monitor objectclass '%s': "
616                                 "%s before %s\n" , moc[i].name,
617                                 ldap_scherr2str(code), err );
618 #else
619                         Debug( LDAP_DEBUG_ANY,
620                                 "unable to parse monitor objectclass '%s': "
621                                 "%s before %s\n" , moc[i].name,
622                                 ldap_scherr2str(code), err );
623 #endif
624                         return -1;
625                 }
626
627                 if ( oc->oc_oid == NULL ) {
628 #ifdef NEW_LOGGING
629                         LDAP_LOG( OPERATION, CRIT,
630                                 "objectclass '%s' has no OID\n" ,
631                                 moc[i].name, 0, 0 );
632 #else
633                         Debug( LDAP_DEBUG_ANY,
634                                 "objectclass '%s' has no OID\n" ,
635                                 moc[i].name, 0, 0 );
636 #endif
637                         return -1;
638                 }
639
640                 code = oc_add(oc, 0, &err);
641                 if ( code ) {
642 #ifdef NEW_LOGGING
643                         LDAP_LOG( OPERATION, CRIT,
644                                 "objectclass '%s': %s \"%s\"\n" ,
645                                 moc[i].name, scherr2str(code), err );
646 #else
647                         Debug( LDAP_DEBUG_ANY,
648                                 "objectclass '%s': %s \"%s\"\n" ,
649                                 moc[i].name, scherr2str(code), err );
650 #endif
651                         return -1;
652                 }
653
654                 ldap_memfree(oc);
655
656                 Oc = oc_find( moc[i].name );
657                 if ( Oc == NULL ) {
658 #ifdef NEW_LOGGING
659                         LDAP_LOG( OPERATION, CRIT, "monitor_back_db_init: "
660                                         "unable to find objectClass %s "
661                                         "(just added)\n", moc[i].name, 0, 0 );
662 #else
663                         Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
664                                         "unable to find objectClass %s "
665                                         "(just added)\n", moc[i].name, 0, 0 );
666 #endif
667                         return -1;
668                 }
669
670                 Oc->soc_flags |= moc[i].flags;
671
672                 ((ObjectClass **)&(((char *)mi)[moc[i].offset]))[0] = Oc;
673         }
674
675         /*      
676          * Create all the subsystem specific entries
677          */
678         e_tmp = NULL;
679         for ( i = 0; monitor_subsys[ i ].mss_name != NULL; i++ ) {
680                 int             len = strlen( monitor_subsys[ i ].mss_name );
681                 struct berval   dn;
682                 int             rc;
683
684                 dn.bv_len = len + sizeof( "cn=" ) - 1;
685                 dn.bv_val = ch_calloc( sizeof( char ), dn.bv_len + 1 );
686                 strcpy( dn.bv_val, "cn=" );
687                 strcat( dn.bv_val, monitor_subsys[ i ].mss_name );
688                 rc = dnPretty( NULL, &dn, &monitor_subsys[ i ].mss_rdn, NULL );
689                 free( dn.bv_val );
690                 if ( rc != LDAP_SUCCESS ) {
691 #ifdef NEW_LOGGING
692                         LDAP_LOG( OPERATION, CRIT,
693                                 "monitor RDN \"%s\" is invalid\n", 
694                                 dn.bv_val, 0, 0 );
695 #else
696                         Debug( LDAP_DEBUG_ANY,
697                                 "monitor RDN \"%s\" is invalid\n", 
698                                 dn.bv_val, 0, 0 );
699 #endif
700                         return( -1 );
701                 }
702
703                 dn.bv_len += sizeof( SLAPD_MONITOR_DN ); /* 1 for the , */
704                 dn.bv_val = ch_malloc( dn.bv_len + 1 );
705                 strcpy( dn.bv_val , monitor_subsys[ i ].mss_rdn.bv_val );
706                 strcat( dn.bv_val, "," SLAPD_MONITOR_DN );
707                 rc = dnPrettyNormal( NULL, &dn, &monitor_subsys[ i ].mss_dn,
708                         &monitor_subsys[ i ].mss_ndn, NULL );
709                 free( dn.bv_val );
710                 if ( rc != LDAP_SUCCESS ) {
711 #ifdef NEW_LOGGING
712                         LDAP_LOG( OPERATION, CRIT,
713                                 "monitor DN \"%s\" is invalid\n", 
714                                 dn.bv_val, 0, 0 );
715 #else
716                         Debug( LDAP_DEBUG_ANY,
717                                 "monitor DN \"%s\" is invalid\n", 
718                                 dn.bv_val, 0, 0 );
719 #endif
720                         return( -1 );
721                 }
722
723                 snprintf( buf, sizeof( buf ),
724                                 "dn: %s\n"
725                                 "objectClass: %s\n"
726                                 "structuralObjectClass: %s\n"
727                                 "cn: %s\n"
728                                 "createTimestamp: %s\n"
729                                 "modifyTimestamp: %s\n",
730                                 monitor_subsys[ i ].mss_dn.bv_val,
731                                 mi->mi_oc_monitorContainer->soc_cname.bv_val,
732                                 mi->mi_oc_monitorContainer->soc_cname.bv_val,
733                                 monitor_subsys[ i ].mss_name,
734                                 mi->mi_startTime.bv_val,
735                                 mi->mi_startTime.bv_val );
736                 
737                 e = str2entry( buf );
738                 
739                 if ( e == NULL) {
740 #ifdef NEW_LOGGING
741                         LDAP_LOG( OPERATION, CRIT,
742                                 "unable to create '%s' entry\n", 
743                                 monitor_subsys[ i ].mss_dn.bv_val, 0, 0 );
744 #else
745                         Debug( LDAP_DEBUG_ANY,
746                                 "unable to create '%s' entry\n", 
747                                 monitor_subsys[ i ].mss_dn.bv_val, 0, 0 );
748 #endif
749                         return( -1 );
750                 }
751
752                 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
753                 e->e_private = ( void * )mp;
754                 mp->mp_info = &monitor_subsys[ i ];
755                 mp->mp_children = NULL;
756                 mp->mp_next = e_tmp;
757                 mp->mp_flags = monitor_subsys[ i ].mss_flags;
758
759                 if ( monitor_cache_add( mi, e ) ) {
760 #ifdef NEW_LOGGING
761                         LDAP_LOG( OPERATION, CRIT,
762                                 "unable to add entry '%s' to cache\n",
763                                 monitor_subsys[ i ].mss_dn.bv_val, 0, 0 );
764 #else
765                         Debug( LDAP_DEBUG_ANY,
766                                 "unable to add entry '%s' to cache\n",
767                                 monitor_subsys[ i ].mss_dn.bv_val, 0, 0 );
768 #endif
769                         return -1;
770                 }
771
772                 e_tmp = e;
773         }
774
775         /*
776          * creates the "cn=Monitor" entry 
777          */
778         snprintf( buf, sizeof( buf ), 
779                 "dn: %s\n"
780                 "objectClass: %s\n"
781                 "structuralObjectClass: %s\n"
782                 "cn: Monitor\n"
783                 "%s: This subtree contains monitoring/managing objects.\n"
784                 "%s: This object contains information about this server.\n"
785 #if 0
786                 "%s: createTimestamp reflects the time this server instance was created.\n"
787                 "%s: modifyTimestamp reflects the time this server instance was last accessed.\n"
788 #endif
789                 "createTimestamp: %s\n"
790                 "modifyTimestamp: %s\n",
791                 SLAPD_MONITOR_DN,
792                 mi->mi_oc_monitorServer->soc_cname.bv_val,
793                 mi->mi_oc_monitorServer->soc_cname.bv_val,
794                 mi->mi_ad_description->ad_cname.bv_val,
795                 mi->mi_ad_description->ad_cname.bv_val,
796 #if 0
797                 mi->mi_ad_description->ad_cname.bv_val,
798                 mi->mi_ad_description->ad_cname.bv_val,
799 #endif
800                 mi->mi_startTime.bv_val,
801                 mi->mi_startTime.bv_val );
802
803         e = str2entry( buf );
804         if ( e == NULL) {
805 #ifdef NEW_LOGGING
806                 LDAP_LOG( OPERATION, CRIT,
807                         "unable to create '%s' entry\n",
808                         SLAPD_MONITOR_DN, 0, 0 );
809 #else
810                 Debug( LDAP_DEBUG_ANY,
811                         "unable to create '%s' entry\n",
812                         SLAPD_MONITOR_DN, 0, 0 );
813 #endif
814                 return( -1 );
815         }
816
817         bv.bv_val = (char *) Versionstr;
818         end_of_line = strchr( Versionstr, '\n' );
819         if ( end_of_line ) {
820                 bv.bv_len = end_of_line - Versionstr;
821         } else {
822                 bv.bv_len = strlen( Versionstr );
823         }
824
825         if ( attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
826                                 &bv, NULL ) ) {
827 #ifdef NEW_LOGGING
828                 LDAP_LOG( OPERATION, CRIT,
829                         "unable to add monitoredInfo to '%s' entry\n",
830                         SLAPD_MONITOR_DN, 0, 0 );
831 #else
832                 Debug( LDAP_DEBUG_ANY,
833                         "unable to add monitoredInfo to '%s' entry\n",
834                         SLAPD_MONITOR_DN, 0, 0 );
835 #endif
836                 return( -1 );
837         }
838
839         if ( mi->mi_l.bv_len ) {
840                 if ( attr_merge_normalize_one( e, mi->mi_ad_l, &mi->mi_l, NULL ) ) {
841 #ifdef NEW_LOGGING
842                         LDAP_LOG( OPERATION, CRIT,
843                                 "unable to add locality to '%s' entry\n",
844                                 SLAPD_MONITOR_DN, 0, 0 );
845 #else
846                         Debug( LDAP_DEBUG_ANY,
847                                 "unable to add locality to '%s' entry\n",
848                                 SLAPD_MONITOR_DN, 0, 0 );
849 #endif
850                         return( -1 );
851                 }
852         }
853
854         mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
855         e->e_private = ( void * )mp;
856
857         mp->mp_info = NULL;
858         mp->mp_children = e_tmp;
859         mp->mp_next = NULL;
860
861         if ( monitor_cache_add( mi, e ) ) {
862 #ifdef NEW_LOGGING
863                 LDAP_LOG( OPERATION, CRIT,
864                         "unable to add entry '%s' to cache\n",
865                         SLAPD_MONITOR_DN, 0, 0 );
866 #else
867                 Debug( LDAP_DEBUG_ANY,
868                         "unable to add entry '%s' to cache\n",
869                         SLAPD_MONITOR_DN, 0, 0 );
870 #endif
871                 return -1;
872         }
873
874         be->be_private = mi;
875         
876         assert( be );
877
878         /*
879          * opens the monitor backend
880          */
881         for ( ms = monitor_subsys; ms->mss_name != NULL; ms++ ) {
882                 if ( ms->mss_init && ( *ms->mss_init )( be ) ) {
883                         return( -1 );
884                 }
885         }
886
887         return( 0 );
888 }
889
890 int
891 monitor_back_config(
892         BackendInfo     *bi,
893         const char      *fname,
894         int             lineno,
895         int             argc,
896         char            **argv
897 )
898 {
899         /*
900          * eventually, will hold backend specific configuration parameters
901          */
902         return 0;
903 }
904
905 int
906 monitor_back_db_config(
907         Backend     *be,
908         const char  *fname,
909         int         lineno,
910         int         argc,
911         char        **argv
912 )
913 {
914         struct monitorinfo *mi = (struct monitorinfo *)be->be_private;
915
916         /*
917          * eventually, will hold database specific configuration parameters
918          */
919         if ( strcasecmp( argv[ 0 ], "l" ) == 0 ) {
920                 if ( argc != 2 ) {
921                         return 1;
922                 }
923                 
924                 ber_str2bv( argv[ 1 ], 0, 1, &mi->mi_l );
925
926         } else {
927 #ifdef NEW_LOGGING
928                 LDAP_LOG( CONFIG, INFO,
929                         "line %d of file '%s' will be ignored\n",
930                         lineno, fname, 0 );
931 #else
932                 Debug( LDAP_DEBUG_CONFIG, 
933                         "line %d of file '%s' will be ignored\n",
934                         lineno, fname, 0 );
935 #endif
936         }
937
938         return( 0 );
939 }
940
941 int
942 monitor_back_db_destroy(
943         BackendDB       *be
944 )
945 {
946         /*
947          * FIXME: destroys all the data
948          */
949         return 0;
950 }
951