1 /* backend.c - deals with backend subsystem */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2001-2005 The OpenLDAP Foundation.
6 * Portions Copyright 2001-2003 Pierangelo Masarati.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
18 * This work was initially developed by Pierangelo Masarati for inclusion
19 * in OpenLDAP Software.
26 #include <ac/string.h>
29 #include "back-monitor.h"
32 * initializes backend subentries
35 monitor_subsys_backend_init(
41 Entry *e_backend, **ep;
44 monitor_subsys_t *ms_database;
47 mi = ( monitor_info_t * )be->be_private;
49 ms_database = monitor_back_get_subsys( SLAPD_MONITOR_DATABASE_NAME );
50 if ( ms_database == NULL ) {
51 Debug( LDAP_DEBUG_ANY,
52 "monitor_subsys_backend_init: "
54 "\"" SLAPD_MONITOR_DATABASE_NAME "\" "
60 if ( monitor_cache_get( mi, &ms->mss_ndn, &e_backend ) )
62 Debug( LDAP_DEBUG_ANY,
63 "monitor_subsys_backend_init: "
64 "unable to get entry \"%s\"\n",
65 ms->mss_ndn.bv_val, 0, 0 );
69 mp = ( monitor_entry_t * )e_backend->e_private;
70 mp->mp_children = NULL;
71 ep = &mp->mp_children;
74 LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next ) {
75 char buf[ BACKMONITOR_BUFSIZE ];
83 snprintf( buf, sizeof( buf ),
84 "dn: cn=Backend %d,%s\n"
86 "structuralObjectClass: %s\n"
90 "createTimestamp: %s\n"
91 "modifyTimestamp: %s\n",
94 mi->mi_oc_monitoredObject->soc_cname.bv_val,
95 mi->mi_oc_monitoredObject->soc_cname.bv_val,
97 mi->mi_creatorsName.bv_val,
98 mi->mi_creatorsName.bv_val,
99 mi->mi_startTime.bv_val,
100 mi->mi_startTime.bv_val );
102 e = str2entry( buf );
104 Debug( LDAP_DEBUG_ANY,
105 "monitor_subsys_backend_init: "
106 "unable to create entry \"cn=Backend %d,%s\"\n",
107 i, ms->mss_ndn.bv_val, 0 );
111 bv.bv_val = bi->bi_type;
112 bv.bv_len = strlen( bv.bv_val );
114 attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
116 attr_merge_normalize_one( e_backend, mi->mi_ad_monitoredInfo,
119 if ( bi->bi_controls ) {
122 for ( j = 0; bi->bi_controls[ j ]; j++ ) {
123 bv.bv_val = bi->bi_controls[ j ];
124 bv.bv_len = strlen( bv.bv_val );
125 attr_merge_one( e, slap_schema.si_ad_supportedControl, &bv, NULL );
130 LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
131 char buf[ SLAP_LDAPDN_MAXLEN ];
136 if ( be->bd_info != bi ) {
140 snprintf( buf, sizeof( buf ), "cn=Database %d,%s",
141 j, ms_database->mss_dn.bv_val );
143 dn.bv_len = strlen( buf );
145 attr_merge_normalize_one( e, mi->mi_ad_seeAlso,
149 mp = monitor_entrypriv_create();
153 e->e_private = ( void * )mp;
155 mp->mp_flags = ms->mss_flags | MONITOR_F_SUB;
157 if ( monitor_cache_add( mi, e ) ) {
158 Debug( LDAP_DEBUG_ANY,
159 "monitor_subsys_backend_init: "
160 "unable to add entry \"cn=Backend %d,%s\"\n",
162 ms->mss_ndn.bv_val, 0 );
170 monitor_cache_release( mi, e_backend );