]> git.sur5r.net Git - openldap/blob - servers/slapd/back-monitor/init.c
remove dnNormalize2
[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 "slap.h"
40 #include "lber_pvt.h"
41 #include "back-monitor.h"
42
43 /*
44  * used by many functions to add description to entries
45  */
46 BackendDB *be_monitor = NULL;
47
48 /*
49  * subsystem data
50  */
51 struct monitorsubsys monitor_subsys[] = {
52         { 
53                 SLAPD_MONITOR_LISTENER, SLAPD_MONITOR_LISTENER_NAME,    
54                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
55                 MONITOR_F_PERSISTENT_CH,
56                 monitor_subsys_listener_init,
57                 NULL,   /* update */
58                 NULL,   /* create */
59                 NULL    /* modify */
60         }, { 
61                 SLAPD_MONITOR_DATABASE, SLAPD_MONITOR_DATABASE_NAME,    
62                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
63                 MONITOR_F_PERSISTENT_CH,
64                 monitor_subsys_database_init,
65                 NULL,   /* update */
66                 NULL,   /* create */
67                 NULL    /* modify */
68         }, { 
69                 SLAPD_MONITOR_BACKEND, SLAPD_MONITOR_BACKEND_NAME, 
70                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
71                 MONITOR_F_PERSISTENT_CH,
72                 monitor_subsys_backend_init,
73                 NULL,   /* update */
74                 NULL,   /* create */
75                 NULL    /* modify */
76         }, { 
77                 SLAPD_MONITOR_THREAD, SLAPD_MONITOR_THREAD_NAME,        
78                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
79                 MONITOR_F_NONE,
80                 monitor_subsys_thread_init,
81                 monitor_subsys_thread_update,
82                 NULL,   /* create */
83                 NULL    /* modify */
84         }, { 
85                 SLAPD_MONITOR_SASL, SLAPD_MONITOR_SASL_NAME,    
86                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
87                 MONITOR_F_NONE,
88                 NULL,   /* init */
89                 NULL,   /* update */
90                 NULL,   /* create */
91                 NULL    /* modify */
92         }, { 
93                 SLAPD_MONITOR_TLS, SLAPD_MONITOR_TLS_NAME,
94                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
95                 MONITOR_F_NONE,
96                 NULL,   /* init */
97                 NULL,   /* update */
98                 NULL,   /* create */
99                 NULL    /* modify */
100         }, { 
101                 SLAPD_MONITOR_CONN, SLAPD_MONITOR_CONN_NAME,
102                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
103                 MONITOR_F_VOLATILE_CH,
104                 monitor_subsys_conn_init,
105                 monitor_subsys_conn_update,
106                 monitor_subsys_conn_create,
107                 NULL    /* modify */
108         }, { 
109                 SLAPD_MONITOR_RWW, SLAPD_MONITOR_RWW_NAME,
110                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
111                 MONITOR_F_PERSISTENT_CH,
112                 monitor_subsys_rww_init,
113                 monitor_subsys_rww_update,
114                 NULL,   /* create */
115                 NULL    /* modify */
116         }, { 
117                 SLAPD_MONITOR_LOG, SLAPD_MONITOR_LOG_NAME,
118                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
119                 MONITOR_F_NONE,
120                 monitor_subsys_log_init,
121                 NULL,   /* update */
122                 NULL,   /* create */
123                 monitor_subsys_log_modify
124         }, { 
125                 SLAPD_MONITOR_OPS, SLAPD_MONITOR_OPS_NAME,
126                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
127                 MONITOR_F_PERSISTENT_CH,
128                 monitor_subsys_ops_init,
129                 monitor_subsys_ops_update,
130                 NULL,   /* create */
131                 NULL,   /* modify */
132         }, { 
133                 SLAPD_MONITOR_SENT, SLAPD_MONITOR_SENT_NAME,
134                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
135                 MONITOR_F_PERSISTENT_CH,
136                 monitor_subsys_sent_init,
137                 monitor_subsys_sent_update,
138                 NULL,   /* create */
139                 NULL,   /* modify */
140         }, { 
141                 SLAPD_MONITOR_TIME, SLAPD_MONITOR_TIME_NAME,
142                 BER_BVNULL, BER_BVNULL, BER_BVNULL,
143                 MONITOR_F_PERSISTENT_CH,
144                 monitor_subsys_time_init,
145                 monitor_subsys_time_update,
146                 NULL,   /* create */
147                 NULL,   /* modify */
148         }, { -1, NULL }
149 };
150
151 #ifdef SLAPD_MONITOR_DYNAMIC
152
153 int
154 back_monitor_LTX_init_module( int argc, char *argv[] )
155 {
156         BackendInfo bi;
157
158         memset( &bi, '\0', sizeof(bi) );
159         bi.bi_type = "monitor";
160         bi.bi_init = monitor_back_initialize;
161         backend_add( &bi );
162         return 0;
163 }
164
165 #endif /* SLAPD_MONITOR_DYNAMIC */
166
167 int
168 monitor_back_initialize(
169         BackendInfo     *bi
170 )
171 {
172         static char *controls[] = {
173                 LDAP_CONTROL_MANAGEDSAIT,
174                 LDAP_CONTROL_VALUESRETURNFILTER,
175                 NULL
176         };
177
178         bi->bi_controls = controls;
179
180         bi->bi_init = 0;
181         bi->bi_open = 0;
182         bi->bi_config = monitor_back_config;
183         bi->bi_close = 0;
184         bi->bi_destroy = 0;
185
186         bi->bi_db_init = monitor_back_db_init;
187         bi->bi_db_config = monitor_back_db_config;
188         bi->bi_db_open = monitor_back_db_open;
189         bi->bi_db_close = 0;
190         bi->bi_db_destroy = monitor_back_db_destroy;
191
192         bi->bi_op_bind = monitor_back_bind;
193         bi->bi_op_unbind = 0;
194         bi->bi_op_search = monitor_back_search;
195         bi->bi_op_compare = monitor_back_compare;
196         bi->bi_op_modify = monitor_back_modify;
197         bi->bi_op_modrdn = 0;
198         bi->bi_op_add = 0;
199         bi->bi_op_delete = 0;
200         bi->bi_op_abandon = 0;
201
202         bi->bi_extended = 0;
203
204         bi->bi_entry_release_rw = 0;
205         bi->bi_chk_referrals = 0;
206         bi->bi_operational = monitor_back_operational;
207
208         /*
209          * hooks for slap tools
210          */
211         bi->bi_tool_entry_open = 0;
212         bi->bi_tool_entry_close = 0;
213         bi->bi_tool_entry_first = 0;
214         bi->bi_tool_entry_next = 0;
215         bi->bi_tool_entry_get = 0;
216         bi->bi_tool_entry_put = 0;
217         bi->bi_tool_entry_reindex = 0;
218         bi->bi_tool_sync = 0;
219
220         bi->bi_connection_init = 0;
221         bi->bi_connection_destroy = 0;
222
223         return 0;
224 }
225
226 int
227 monitor_back_db_init(
228         BackendDB       *be
229 )
230 {
231         struct monitorinfo      *mi;
232         int                     rc;
233         struct berval           dn, ndn;
234         struct berval           bv;
235
236         /*
237          * database monitor can be defined once only
238          */
239         if ( be_monitor ) {
240 #ifdef NEW_LOGGING
241                 LDAP_LOG( OPERATION, CRIT,
242                         "only one monitor backend is allowed\n", 0, 0, 0);
243 #else
244                 Debug( LDAP_DEBUG_ANY,
245                         "only one monitor backend is allowed\n", 0, 0, 0 );
246 #endif
247                 return( -1 );
248         }
249         be_monitor = be;
250
251         /* indicate system schema supported */
252         be->be_flags |= SLAP_BFLAG_MONITOR;
253
254         dn.bv_val = SLAPD_MONITOR_DN;
255         dn.bv_len = sizeof( SLAPD_MONITOR_DN ) - 1;
256
257         rc = dnNormalize( 0, NULL, NULL, &dn, &ndn, NULL );
258         if( rc != LDAP_SUCCESS ) {
259 #ifdef NEW_LOGGING
260                 LDAP_LOG( OPERATION, CRIT,
261                         "unable to normalize monitor DN \"" SLAPD_MONITOR_DN
262                         "\"\n" , 0, 0, 0 );
263 #else
264                 Debug( LDAP_DEBUG_ANY,
265                         "unable to normalize monitor DN \"" SLAPD_MONITOR_DN
266                         "\"\n", 0, 0, 0 );
267 #endif
268                 return -1;
269         }
270
271         ber_dupbv( &bv, &dn );
272         ber_bvarray_add( &be->be_suffix, &bv );
273         ber_bvarray_add( &be->be_nsuffix, &ndn );
274
275         mi = ( struct monitorinfo * )ch_calloc( sizeof( struct monitorinfo ), 1 );
276         if ( mi == NULL ) {
277 #ifdef NEW_LOGGING
278                 LDAP_LOG( OPERATION, CRIT,
279                         "unable to initialize monitor backend\n", 0, 0, 0 );
280 #else
281                 Debug( LDAP_DEBUG_ANY,
282                         "unable to initialize monitor backend\n", 0, 0, 0 );
283 #endif
284                 return -1;
285         }
286
287         memset( mi, 0, sizeof( struct monitorinfo ) );
288
289         ldap_pvt_thread_mutex_init( &mi->mi_cache_mutex );
290
291         be->be_private = mi;
292         
293         return 0;
294 }
295
296 int
297 monitor_back_db_open(
298         BackendDB       *be
299 )
300 {
301         struct monitorinfo      *mi = (struct monitorinfo *)be->be_private;
302         struct monitorsubsys    *ms;
303         Entry                   *e, *e_tmp;
304         struct monitorentrypriv *mp;
305         int                     i;
306         char                    buf[ BACKMONITOR_BUFSIZE ], *end_of_line;
307         const char              *text;
308         struct berval           bv;
309         struct m_s {
310                 char    *name;
311                 char    *schema;
312                 int     offset;
313         } moc[] = {
314                 { "monitor", "( 1.3.6.1.4.1.4203.666.3.2 "
315                         "NAME 'monitor' "
316                         "DESC 'OpenLDAP system monitoring' "
317                         "SUP top STRUCTURAL "
318                         "MUST cn "
319                         "MAY ( "
320                                 "description "
321                                 "$ l "
322                                 "$ st "
323                                 "$ street "
324                                 "$ postalAddress "
325                                 "$ postalCode "
326                                 "$ seeAlso "
327                                 "$ monitoredInfo "
328                                 "$ managedInfo "
329                         ") )",
330                         offsetof(struct monitorinfo, oc_monitor) },
331                 { "monitorServer", "( 1.3.6.1.4.1.4203.666.3.7 "
332                         "NAME 'monitorServer' "
333                         "DESC 'Server monitoring root entry' "
334                         "SUP monitor STRUCTURAL )",
335                         offsetof(struct monitorinfo, oc_monitorServer) },
336                 { "monitorContainer", "( 1.3.6.1.4.1.4203.666.3.8 "
337                         "NAME 'monitorContainer' "
338                         "DESC 'monitor container class' "
339                         "SUP monitor STRUCTURAL )",
340                         offsetof(struct monitorinfo, oc_monitorContainer) },
341                 { "monitorCounterObject", "( 1.3.6.1.4.1.4203.666.3.9 "
342                         "NAME 'monitorCounterObject' "
343                         "DESC 'monitor counter class' "
344                         "SUP monitor STRUCTURAL )",
345                         offsetof(struct monitorinfo, oc_monitorCounterObject) },
346                 { "monitorOperation", "( 1.3.6.1.4.1.4203.666.3.10 "
347                         "NAME 'monitorOperation' "
348                         "DESC 'monitor operation class' "
349                         "SUP monitor STRUCTURAL )",
350                         offsetof(struct monitorinfo, oc_monitorOperation) },
351                 { "monitorConnection", "( 1.3.6.1.4.1.4203.666.3.11 "
352                         "NAME 'monitorConnection' "
353                         "DESC 'monitor connection class' "
354                         "SUP monitor STRUCTURAL )",
355                         offsetof(struct monitorinfo, oc_monitorConnection) },
356                 { "managedObject", "( 1.3.6.1.4.1.4203.666.3.12 "
357                         "NAME 'managedObject' "
358                         "DESC 'monitor managed entity class' "
359                         "SUP monitor STRUCTURAL )",
360                         offsetof(struct monitorinfo, oc_managedObject) },
361                 { "monitoredObject", "( 1.3.6.1.4.1.4203.666.3.13 "
362                         "NAME 'monitoredObject' "
363                         "DESC 'monitor monitored entity class' "
364                         "SUP monitor STRUCTURAL )",
365                         offsetof(struct monitorinfo, oc_monitoredObject) },
366                 { NULL, NULL, -1 }
367         }, mat[] = {
368                 { "monitoredInfo", "( 1.3.6.1.4.1.4203.666.1.14 "
369                         "NAME 'monitoredInfo' "
370                         "DESC 'monitored info' "
371                         /* "SUP name " */
372                         "EQUALITY caseIgnoreMatch "
373                         "SUBSTR caseIgnoreSubstringsMatch "
374                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} "
375                         "NO-USER-MODIFICATION "
376                         "USAGE directoryOperation )",
377                         offsetof(struct monitorinfo, ad_monitoredInfo) },
378                 { "managedInfo", "( 1.3.6.1.4.1.4203.666.1.15 "
379                         "NAME 'managedInfo' "
380                         "DESC 'monitor managed info' "
381                         "SUP name )",
382                         offsetof(struct monitorinfo, ad_managedInfo) },
383                 { "monitorCounter", "( 1.3.6.1.4.1.4203.666.1.16 "
384                         "NAME 'monitorCounter' "
385                         "DESC 'monitor counter' "
386                         "EQUALITY integerMatch "
387                         "ORDERING integerOrderingMatch "
388                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 "
389                         "NO-USER-MODIFICATION "
390                         "USAGE directoryOperation )",
391                         offsetof(struct monitorinfo, ad_monitorCounter) },
392                 { "monitorOpCompleted", "( 1.3.6.1.4.1.4203.666.1.17 "
393                         "NAME 'monitorOpCompleted' "
394                         "DESC 'monitor completed operations' "
395                         "SUP monitorCounter "
396                         "NO-USER-MODIFICATION "
397                         "USAGE directoryOperation )",
398                         offsetof(struct monitorinfo, ad_monitorOpCompleted) },
399                 { "monitorOpInitiated", "( 1.3.6.1.4.1.4203.666.1.18 "
400                         "NAME 'monitorOpInitiated' "
401                         "DESC 'monitor initiated operations' "
402                         "SUP monitorCounter "
403                         "NO-USER-MODIFICATION "
404                         "USAGE directoryOperation )",
405                         offsetof(struct monitorinfo, ad_monitorOpInitiated) },
406                 { "monitorConnectionNumber", "( 1.3.6.1.4.1.4203.666.1.19 "
407                         "NAME 'monitorConnectionNumber' "
408                         "DESC 'monitor connection number' "
409                         "SUP monitorCounter "
410                         "NO-USER-MODIFICATION "
411                         "USAGE directoryOperation )",
412                         offsetof(struct monitorinfo, ad_monitorConnectionNumber) },
413                 { "monitorConnectionAuthzDN", "( 1.3.6.1.4.1.4203.666.1.20 "
414                         "NAME 'monitorConnectionAuthzDN' "
415                         "DESC 'monitor connection authorization DN' "
416                         /* "SUP distinguishedName " */
417                         "EQUALITY distinguishedNameMatch "
418                         "SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 "
419                         "NO-USER-MODIFICATION "
420                         "USAGE directoryOperation )",
421                         offsetof(struct monitorinfo, ad_monitorConnectionAuthzDN) },
422                 { "monitorConnectionLocalAddress", "( 1.3.6.1.4.1.4203.666.1.21 "
423                         "NAME 'monitorConnectionLocalAddress' "
424                         "DESC 'monitor connection local address' "
425                         "SUP monitoredInfo "
426                         "NO-USER-MODIFICATION "
427                         "USAGE directoryOperation )",
428                         offsetof(struct monitorinfo, ad_monitorConnectionLocalAddress) },
429                 { "monitorConnectionPeerAddress", "( 1.3.6.1.4.1.4203.666.1.22 "
430                         "NAME 'monitorConnectionPeerAddress' "
431                         "DESC 'monitor connection peer address' "
432                         "SUP monitoredInfo "
433                         "NO-USER-MODIFICATION "
434                         "USAGE directoryOperation )",
435                         offsetof(struct monitorinfo, ad_monitorConnectionPeerAddress) },
436                 { NULL, NULL, -1 }
437         };
438
439         for ( i = 0; mat[i].name; i++ ) {
440                 LDAPAttributeType *at;
441                 int             code;
442                 const char      *err;
443                 AttributeDescription **ad;
444
445                 at = ldap_str2attributetype( mat[i].schema, &code,
446                                 &err, LDAP_SCHEMA_ALLOW_ALL );
447                 if ( !at ) {
448 #ifdef NEW_LOGGING
449                         LDAP_LOG( OPERATION, CRIT, "monitor_back_db_init: "
450                                 "in AttributeType '%s' %s before %s\n",
451                                 mat[i].name, ldap_scherr2str(code), err );
452 #else
453                         Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
454                                 "in AttributeType '%s' %s before %s\n",
455                                 mat[i].name, ldap_scherr2str(code), err );
456 #endif
457                         return -1;
458                 }
459
460                 if ( at->at_oid == NULL ) {
461 #ifdef NEW_LOGGING
462                         LDAP_LOG( OPERATION, CRIT, "monitor_back_db_init: "
463                                 "null OID for attributeType '%s'\n",
464                                 mat[i].name, 0, 0 );
465 #else
466                         Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
467                                 "null OID for attributeType '%s'\n",
468                                 mat[i].name, 0, 0 );
469 #endif
470                         return -1;
471                 }
472
473                 code = at_add(at, &err);
474                 if ( code ) {
475 #ifdef NEW_LOGGING
476                         LDAP_LOG( OPERATION, CRIT, "monitor_back_db_init: "
477                                 "%s in attributeType '%s'\n",
478                                 scherr2str(code), mat[i].name, 0 );
479 #else
480                         Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
481                                 "%s in attributeType '%s'\n",
482                                 scherr2str(code), mat[i].name, 0 );
483 #endif
484                         return -1;
485                 }
486                 ldap_memfree(at);
487
488                 ad = ((AttributeDescription **)&(((char *)mi)[mat[i].offset]));
489                 ad[0] = NULL;
490                 if ( slap_str2ad( mat[i].name, ad, &text ) ) {
491 #ifdef NEW_LOGGING
492                         LDAP_LOG( OPERATION, CRIT,
493                                 "monitor_back_db_init: %s\n", text, 0, 0 );
494 #else
495                         Debug( LDAP_DEBUG_ANY,
496                                 "monitor_back_db_init: %s\n", text, 0, 0 );
497 #endif
498                         return -1;
499                 }
500         }
501
502         if ( slap_str2ad( "description", &mi->ad_description, &text ) ) {
503 #ifdef NEW_LOGGING
504                 LDAP_LOG( OPERATION, CRIT,
505                         "monitor_back_db_init: description: %s\n", text, 0, 0 );
506 #else
507                 Debug( LDAP_DEBUG_ANY,
508                         "monitor_back_db_init: description: %s\n", text, 0, 0 );
509 #endif
510                 return( -1 );
511         }
512
513         if ( slap_str2ad( "seeAlso", &mi->ad_seeAlso, &text ) ) {
514 #ifdef NEW_LOGGING
515                 LDAP_LOG( OPERATION, CRIT,
516                         "monitor_back_db_init: seeAlso: %s\n", text, 0, 0 );
517 #else
518                 Debug( LDAP_DEBUG_ANY,
519                         "monitor_back_db_init: seeAlso: %s\n", text, 0, 0 );
520 #endif
521                 return( -1 );
522         }
523
524         for ( i = 0; moc[i].name; i++ ) {
525                 LDAPObjectClass         *oc;
526                 int                     code;
527                 const char              *err;
528                 ObjectClass             *Oc;
529
530                 oc = ldap_str2objectclass(moc[i].schema, &code, &err,
531                                 LDAP_SCHEMA_ALLOW_ALL );
532                 if ( !oc ) {
533 #ifdef NEW_LOGGING
534                         LDAP_LOG( OPERATION, CRIT,
535                                 "unable to parse monitor objectclass '%s': "
536                                 "%s before %s\n" , moc[i].name,
537                                 ldap_scherr2str(code), err );
538 #else
539                         Debug( LDAP_DEBUG_ANY,
540                                 "unable to parse monitor objectclass '%s': "
541                                 "%s before %s\n" , moc[i].name,
542                                 ldap_scherr2str(code), err );
543 #endif
544                         return -1;
545                 }
546
547                 if ( oc->oc_oid == NULL ) {
548 #ifdef NEW_LOGGING
549                         LDAP_LOG( OPERATION, CRIT,
550                                 "objectclass '%s' has no OID\n" ,
551                                 moc[i].name, 0, 0 );
552 #else
553                         Debug( LDAP_DEBUG_ANY,
554                                 "objectclass '%s' has no OID\n" ,
555                                 moc[i].name, 0, 0 );
556 #endif
557                         return -1;
558                 }
559
560                 code = oc_add(oc, 0, &err);
561                 if ( code ) {
562 #ifdef NEW_LOGGING
563                         LDAP_LOG( OPERATION, CRIT,
564                                 "objectclass '%s': %s \"%s\"\n" ,
565                                 moc[i].name, scherr2str(code), err );
566 #else
567                         Debug( LDAP_DEBUG_ANY,
568                                 "objectclass '%s': %s \"%s\"\n" ,
569                                 moc[i].name, scherr2str(code), err );
570 #endif
571                         return -1;
572                 }
573
574                 ldap_memfree(oc);
575
576                 Oc = oc_find( moc[i].name );
577                 if ( Oc == NULL ) {
578 #ifdef NEW_LOGGING
579                         LDAP_LOG( OPERATION, CRIT, "monitor_back_db_init: "
580                                         "unable to find objectClass %s "
581                                         "(just added)\n", moc[i].name, 0, 0 );
582 #else
583                         Debug( LDAP_DEBUG_ANY, "monitor_back_db_init: "
584                                         "unable to find objectClass %s "
585                                         "(just added)\n", moc[i].name, 0, 0 );
586 #endif
587                         return -1;
588                 }
589
590                 ((ObjectClass **)&(((char *)mi)[moc[i].offset]))[0] = Oc;
591         }
592
593         /*      
594          * Create all the subsystem specific entries
595          */
596         e_tmp = NULL;
597         for ( i = 0; monitor_subsys[ i ].mss_name != NULL; i++ ) {
598                 int             len = strlen( monitor_subsys[ i ].mss_name );
599                 struct berval   dn;
600                 int             rc;
601
602                 dn.bv_len = len + sizeof( "cn=" ) - 1;
603                 dn.bv_val = ch_calloc( sizeof( char ), dn.bv_len + 1 );
604                 strcpy( dn.bv_val, "cn=" );
605                 strcat( dn.bv_val, monitor_subsys[ i ].mss_name );
606                 rc = dnPretty( NULL, &dn, &monitor_subsys[ i ].mss_rdn, NULL );
607                 free( dn.bv_val );
608                 if ( rc != LDAP_SUCCESS ) {
609 #ifdef NEW_LOGGING
610                         LDAP_LOG( OPERATION, CRIT,
611                                 "monitor RDN \"%s\" is invalid\n", 
612                                 dn.bv_val, 0, 0 );
613 #else
614                         Debug( LDAP_DEBUG_ANY,
615                                 "monitor RDN \"%s\" is invalid\n", 
616                                 dn.bv_val, 0, 0 );
617 #endif
618                         return( -1 );
619                 }
620
621                 dn.bv_len += sizeof( SLAPD_MONITOR_DN ); /* 1 for the , */
622                 dn.bv_val = ch_malloc( dn.bv_len + 1 );
623                 strcpy( dn.bv_val , monitor_subsys[ i ].mss_rdn.bv_val );
624                 strcat( dn.bv_val, "," SLAPD_MONITOR_DN );
625                 rc = dnPrettyNormal( NULL, &dn, &monitor_subsys[ i ].mss_dn,
626                         &monitor_subsys[ i ].mss_ndn, NULL );
627                 free( dn.bv_val );
628                 if ( rc != LDAP_SUCCESS ) {
629 #ifdef NEW_LOGGING
630                         LDAP_LOG( OPERATION, CRIT,
631                                 "monitor DN \"%s\" is invalid\n", 
632                                 dn.bv_val, 0, 0 );
633 #else
634                         Debug( LDAP_DEBUG_ANY,
635                                 "monitor DN \"%s\" is invalid\n", 
636                                 dn.bv_val, 0, 0 );
637 #endif
638                         return( -1 );
639                 }
640
641                 snprintf( buf, sizeof( buf ),
642                                 "dn: %s\n"
643                                 "objectClass: %s\n"
644                                 "structuralObjectClass: %s\n"
645                                 "cn: %s\n",
646                                 monitor_subsys[ i ].mss_dn.bv_val,
647                                 mi->oc_monitorContainer->soc_cname.bv_val,
648                                 mi->oc_monitorContainer->soc_cname.bv_val,
649                                 monitor_subsys[ i ].mss_name );
650                 
651                 e = str2entry( buf );
652                 
653                 if ( e == NULL) {
654 #ifdef NEW_LOGGING
655                         LDAP_LOG( OPERATION, CRIT,
656                                 "unable to create '%s' entry\n", 
657                                 monitor_subsys[ i ].mss_dn.bv_val, 0, 0 );
658 #else
659                         Debug( LDAP_DEBUG_ANY,
660                                 "unable to create '%s' entry\n", 
661                                 monitor_subsys[ i ].mss_dn.bv_val, 0, 0 );
662 #endif
663                         return( -1 );
664                 }
665
666                 mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
667                 e->e_private = ( void * )mp;
668                 mp->mp_info = &monitor_subsys[ i ];
669                 mp->mp_children = NULL;
670                 mp->mp_next = e_tmp;
671                 mp->mp_flags = monitor_subsys[ i ].mss_flags;
672
673                 if ( monitor_cache_add( mi, e ) ) {
674 #ifdef NEW_LOGGING
675                         LDAP_LOG( OPERATION, CRIT,
676                                 "unable to add entry '%s' to cache\n",
677                                 monitor_subsys[ i ].mss_dn.bv_val, 0, 0 );
678 #else
679                         Debug( LDAP_DEBUG_ANY,
680                                 "unable to add entry '%s' to cache\n",
681                                 monitor_subsys[ i ].mss_dn.bv_val, 0, 0 );
682 #endif
683                         return -1;
684                 }
685
686                 e_tmp = e;
687         }
688
689         /*
690          * creates the "cn=Monitor" entry 
691          */
692         snprintf( buf, sizeof( buf ), 
693                 "dn: " SLAPD_MONITOR_DN "\n"
694                 "objectClass: %s\n"
695                 "structuralObjectClass: %s\n"
696                 "cn: Monitor\n"
697                 "%s: This subtree contains monitoring/managing objects.\n"
698                 "%s: This object contains information about this server.\n"
699                 "%s: createTimeStamp reflects the time this server instance was created.\n"
700                 "%s: modifyTimeStamp reflects the current time.\n",
701                 mi->oc_monitorServer->soc_cname.bv_val,
702                 mi->oc_monitorServer->soc_cname.bv_val,
703                 mi->ad_description->ad_cname.bv_val,
704                 mi->ad_description->ad_cname.bv_val,
705                 mi->ad_description->ad_cname.bv_val,
706                 mi->ad_description->ad_cname.bv_val );
707
708         e = str2entry( buf );
709         if ( e == NULL) {
710 #ifdef NEW_LOGGING
711                 LDAP_LOG( OPERATION, CRIT,
712                         "unable to create '%s' entry\n",
713                         SLAPD_MONITOR_DN, 0, 0 );
714 #else
715                 Debug( LDAP_DEBUG_ANY,
716                         "unable to create '%s' entry\n",
717                         SLAPD_MONITOR_DN, 0, 0 );
718 #endif
719                 return( -1 );
720         }
721
722         bv.bv_val = (char *) Versionstr;
723         end_of_line = strchr( Versionstr, '\n' );
724         if ( end_of_line ) {
725                 bv.bv_len = end_of_line - Versionstr;
726         } else {
727                 bv.bv_len = strlen( Versionstr );
728         }
729
730         if ( attr_merge_normalize_one( e, mi->ad_monitoredInfo,
731                                 &bv, NULL ) ) {
732 #ifdef NEW_LOGGING
733                 LDAP_LOG( OPERATION, CRIT,
734                         "unable to add monitoredInfo to '%s' entry\n",
735                         SLAPD_MONITOR_DN, 0, 0 );
736 #else
737                 Debug( LDAP_DEBUG_ANY,
738                         "unable to add monitoredInfo to '%s' entry\n",
739                         SLAPD_MONITOR_DN, 0, 0 );
740 #endif
741                 return( -1 );
742         }
743
744         if ( mi->l.bv_len ) {
745                 AttributeDescription    *ad = NULL;
746                 const char              *text = NULL;
747
748                 if ( slap_str2ad( "l", &ad, &text ) ) {
749 #ifdef NEW_LOGGING
750                         LDAP_LOG( OPERATION, CRIT, "unable to get 'l'\n",
751                                 SLAPD_MONITOR_DN, 0, 0 );
752 #else
753                         Debug( LDAP_DEBUG_ANY, "unable to get 'l'\n",
754                                 SLAPD_MONITOR_DN, 0, 0 );
755 #endif
756                         return( -1 );
757                 }
758                 
759                 if ( attr_merge_normalize_one( e, ad, &mi->l, NULL ) ) {
760 #ifdef NEW_LOGGING
761                         LDAP_LOG( OPERATION, CRIT,
762                                 "unable to add locality to '%s' entry\n",
763                                 SLAPD_MONITOR_DN, 0, 0 );
764 #else
765                         Debug( LDAP_DEBUG_ANY,
766                                 "unable to add locality to '%s' entry\n",
767                                 SLAPD_MONITOR_DN, 0, 0 );
768 #endif
769                         return( -1 );
770                 }
771         }
772
773         mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
774         e->e_private = ( void * )mp;
775
776         mp->mp_info = NULL;
777         mp->mp_children = e_tmp;
778         mp->mp_next = NULL;
779
780         if ( monitor_cache_add( mi, e ) ) {
781 #ifdef NEW_LOGGING
782                 LDAP_LOG( OPERATION, CRIT,
783                         "unable to add entry '%s' to cache\n",
784                         SLAPD_MONITOR_DN, 0, 0 );
785 #else
786                 Debug( LDAP_DEBUG_ANY,
787                         "unable to add entry '%s' to cache\n",
788                         SLAPD_MONITOR_DN, 0, 0 );
789 #endif
790                 return -1;
791         }
792
793         be->be_private = mi;
794         
795         assert( be );
796
797         /*
798          * opens the monitor backend
799          */
800         for ( ms = monitor_subsys; ms->mss_name != NULL; ms++ ) {
801                 if ( ms->mss_init && ( *ms->mss_init )( be ) ) {
802                         return( -1 );
803                 }
804         }
805
806         return( 0 );
807 }
808
809 int
810 monitor_back_config(
811         BackendInfo     *bi,
812         const char      *fname,
813         int             lineno,
814         int             argc,
815         char            **argv
816 )
817 {
818         /*
819          * eventually, will hold backend specific configuration parameters
820          */
821         return 0;
822 }
823
824 int
825 monitor_back_db_config(
826         Backend     *be,
827         const char  *fname,
828         int         lineno,
829         int         argc,
830         char        **argv
831 )
832 {
833         struct monitorinfo *mi = (struct monitorinfo *)be->be_private;
834
835         /*
836          * eventually, will hold database specific configuration parameters
837          */
838         if ( strcasecmp( argv[ 0 ], "l" ) == 0 ) {
839                 if ( argc != 2 ) {
840                         return 1;
841                 }
842                 
843                 ber_str2bv( argv[ 1 ], 0, 1, &mi->l );
844
845         } else {
846 #ifdef NEW_LOGGING
847                 LDAP_LOG( CONFIG, INFO,
848                         "line %d of file '%s' will be ignored\n",
849                         lineno, fname, 0 );
850 #else
851                 Debug( LDAP_DEBUG_CONFIG, 
852                         "line %d of file '%s' will be ignored\n",
853                         lineno, fname, 0 );
854 #endif
855         }
856
857         return( 0 );
858 }
859
860 int
861 monitor_back_db_destroy(
862         BackendDB       *be
863 )
864 {
865         /*
866          * FIXME: destroys all the data
867          */
868         return 0;
869 }
870