Home | History | Annotate | Line # | Download | only in back-monitor
backend.c revision 1.1.1.3
      1 /*	$NetBSD: backend.c,v 1.1.1.3 2010/12/12 15:23:13 adam Exp $	*/
      2 
      3 /* backend.c - deals with backend subsystem */
      4 /* OpenLDAP: pkg/ldap/servers/slapd/back-monitor/backend.c,v 1.41.2.5 2010/04/13 20:23:32 kurt Exp */
      5 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
      6  *
      7  * Copyright 2001-2010 The OpenLDAP Foundation.
      8  * Portions Copyright 2001-2003 Pierangelo Masarati.
      9  * All rights reserved.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted only as authorized by the OpenLDAP
     13  * Public License.
     14  *
     15  * A copy of this license is available in file LICENSE in the
     16  * top-level directory of the distribution or, alternatively, at
     17  * <http://www.OpenLDAP.org/license.html>.
     18  */
     19 /* ACKNOWLEDGEMENTS:
     20  * This work was initially developed by Pierangelo Masarati for inclusion
     21  * in OpenLDAP Software.
     22  */
     23 
     24 
     25 #include "portable.h"
     26 
     27 #include <stdio.h>
     28 #include <ac/string.h>
     29 
     30 #include "slap.h"
     31 #include "back-monitor.h"
     32 
     33 /*
     34  * initializes backend subentries
     35  */
     36 int
     37 monitor_subsys_backend_init(
     38 	BackendDB		*be,
     39 	monitor_subsys_t	*ms
     40 )
     41 {
     42 	monitor_info_t		*mi;
     43 	Entry			*e_backend, **ep;
     44 	int			i;
     45 	monitor_entry_t		*mp;
     46 	monitor_subsys_t	*ms_database;
     47 	BackendInfo			*bi;
     48 
     49 	mi = ( monitor_info_t * )be->be_private;
     50 
     51 	ms_database = monitor_back_get_subsys( SLAPD_MONITOR_DATABASE_NAME );
     52 	if ( ms_database == NULL ) {
     53 		Debug( LDAP_DEBUG_ANY,
     54 			"monitor_subsys_backend_init: "
     55 			"unable to get "
     56 			"\"" SLAPD_MONITOR_DATABASE_NAME "\" "
     57 			"subsystem\n",
     58 			0, 0, 0 );
     59 		return -1;
     60 	}
     61 
     62 	if ( monitor_cache_get( mi, &ms->mss_ndn, &e_backend ) ) {
     63 		Debug( LDAP_DEBUG_ANY,
     64 			"monitor_subsys_backend_init: "
     65 			"unable to get entry \"%s\"\n",
     66 			ms->mss_ndn.bv_val, 0, 0 );
     67 		return( -1 );
     68 	}
     69 
     70 	mp = ( monitor_entry_t * )e_backend->e_private;
     71 	mp->mp_children = NULL;
     72 	ep = &mp->mp_children;
     73 
     74 	i = -1;
     75 	LDAP_STAILQ_FOREACH( bi, &backendInfo, bi_next ) {
     76 		char 		buf[ BACKMONITOR_BUFSIZE ];
     77 		BackendDB	*be;
     78 		struct berval 	bv;
     79 		int		j;
     80 		Entry		*e;
     81 
     82 		i++;
     83 
     84 		bv.bv_len = snprintf( buf, sizeof( buf ), "cn=Backend %d", i );
     85 		bv.bv_val = buf;
     86 
     87 		e = monitor_entry_stub( &ms->mss_dn, &ms->mss_ndn, &bv,
     88 			mi->mi_oc_monitoredObject, mi, NULL, NULL );
     89 
     90 		if ( e == NULL ) {
     91 			Debug( LDAP_DEBUG_ANY,
     92 				"monitor_subsys_backend_init: "
     93 				"unable to create entry \"cn=Backend %d,%s\"\n",
     94 				i, ms->mss_ndn.bv_val, 0 );
     95 			return( -1 );
     96 		}
     97 
     98 		ber_str2bv( bi->bi_type, 0, 0, &bv );
     99 		attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo,
    100 				&bv, NULL );
    101 		attr_merge_normalize_one( e_backend, mi->mi_ad_monitoredInfo,
    102 				&bv, NULL );
    103 
    104 		attr_merge_normalize_one( e, mi->mi_ad_monitorRuntimeConfig,
    105 			bi->bi_cf_ocs == NULL ? (struct berval *)&slap_false_bv :
    106 				(struct berval *)&slap_true_bv, NULL );
    107 
    108 		if ( bi->bi_controls ) {
    109 			int j;
    110 
    111 			for ( j = 0; bi->bi_controls[ j ]; j++ ) {
    112 				ber_str2bv( bi->bi_controls[ j ], 0, 0, &bv );
    113 				attr_merge_one( e, slap_schema.si_ad_supportedControl,
    114 						&bv, &bv );
    115 			}
    116 		}
    117 
    118 		j = -1;
    119 		LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
    120 			char		buf[ SLAP_LDAPDN_MAXLEN ];
    121 			struct berval	dn;
    122 
    123 			j++;
    124 
    125 			if ( be->bd_info != bi ) {
    126 				continue;
    127 			}
    128 
    129 			snprintf( buf, sizeof( buf ), "cn=Database %d,%s",
    130 					j, ms_database->mss_dn.bv_val );
    131 
    132 			ber_str2bv( buf, 0, 0, &dn );
    133 			attr_merge_normalize_one( e, slap_schema.si_ad_seeAlso,
    134 					&dn, NULL );
    135 		}
    136 
    137 		mp = monitor_entrypriv_create();
    138 		if ( mp == NULL ) {
    139 			return -1;
    140 		}
    141 		e->e_private = ( void * )mp;
    142 		mp->mp_info = ms;
    143 		mp->mp_flags = ms->mss_flags | MONITOR_F_SUB;
    144 
    145 		if ( monitor_cache_add( mi, e ) ) {
    146 			Debug( LDAP_DEBUG_ANY,
    147 				"monitor_subsys_backend_init: "
    148 				"unable to add entry \"cn=Backend %d,%s\"\n",
    149 				i,
    150 			       	ms->mss_ndn.bv_val, 0 );
    151 			return( -1 );
    152 		}
    153 
    154 		*ep = e;
    155 		ep = &mp->mp_next;
    156 	}
    157 
    158 	monitor_cache_release( mi, e_backend );
    159 
    160 	return( 0 );
    161 }
    162 
    163