Back to index

openldap  2.4.31
overlay.c
Go to the documentation of this file.
00001 /* overlay.c - deals with overlay subsystem */
00002 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00003  *
00004  * Copyright 2001-2012 The OpenLDAP Foundation.
00005  * Portions Copyright 2001-2003 Pierangelo Masarati.
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted only as authorized by the OpenLDAP
00010  * Public License.
00011  *
00012  * A copy of this license is available in file LICENSE in the
00013  * top-level directory of the distribution or, alternatively, at
00014  * <http://www.OpenLDAP.org/license.html>.
00015  */
00016 /* ACKNOWLEDGEMENTS:
00017  * This work was initially developed by Pierangelo Masarati for inclusion
00018  * in OpenLDAP Software.
00019  */
00020 
00021 
00022 #include "portable.h"
00023 
00024 #include <stdio.h>
00025 #include <ac/string.h>
00026 
00027 #include "slap.h"
00028 #include "back-monitor.h"
00029 
00030 /*
00031  * initializes overlay subentries
00032  */
00033 int
00034 monitor_subsys_overlay_init(
00035        BackendDB            *be,
00036        monitor_subsys_t     *ms
00037 )
00038 {
00039        monitor_info_t              *mi;
00040        Entry                *e_overlay, **ep;
00041        int                  i;
00042        monitor_entry_t             *mp;
00043        slap_overinst        *on;
00044        monitor_subsys_t     *ms_database;
00045 
00046        mi = ( monitor_info_t * )be->be_private;
00047 
00048        ms_database = monitor_back_get_subsys( SLAPD_MONITOR_DATABASE_NAME );
00049        if ( ms_database == NULL ) {
00050               Debug( LDAP_DEBUG_ANY,
00051                      "monitor_subsys_backend_init: "
00052                      "unable to get "
00053                      "\"" SLAPD_MONITOR_DATABASE_NAME "\" "
00054                      "subsystem\n",
00055                      0, 0, 0 );
00056               return -1;
00057        }
00058 
00059        if ( monitor_cache_get( mi, &ms->mss_ndn, &e_overlay ) ) {
00060               Debug( LDAP_DEBUG_ANY,
00061                      "monitor_subsys_overlay_init: "
00062                      "unable to get entry \"%s\"\n",
00063                      ms->mss_ndn.bv_val, 0, 0 );
00064               return( -1 );
00065        }
00066 
00067        mp = ( monitor_entry_t * )e_overlay->e_private;
00068        mp->mp_children = NULL;
00069        ep = &mp->mp_children;
00070 
00071        for ( on = overlay_next( NULL ), i = 0; on; on = overlay_next( on ), i++ ) {
00072               char          buf[ BACKMONITOR_BUFSIZE ];
00073               struct berval        bv;
00074               int           j;
00075               Entry         *e;
00076               BackendDB     *be;
00077 
00078               bv.bv_len = snprintf( buf, sizeof( buf ), "cn=Overlay %d", i );
00079               bv.bv_val = buf;
00080               e = monitor_entry_stub( &ms->mss_dn, &ms->mss_ndn, &bv,
00081                      mi->mi_oc_monitoredObject, mi, NULL, NULL );
00082               if ( e == NULL ) {
00083                      Debug( LDAP_DEBUG_ANY,
00084                             "monitor_subsys_overlay_init: "
00085                             "unable to create entry \"cn=Overlay %d,%s\"\n",
00086                             i, ms->mss_ndn.bv_val, 0 );
00087                      return( -1 );
00088               }
00089               ber_str2bv( on->on_bi.bi_type, 0, 0, &bv );
00090               attr_merge_normalize_one( e, mi->mi_ad_monitoredInfo, &bv, NULL );
00091               attr_merge_normalize_one( e, mi->mi_ad_monitorRuntimeConfig,
00092                      on->on_bi.bi_cf_ocs ? (struct berval *)&slap_true_bv :
00093                             (struct berval *)&slap_false_bv, NULL );
00094               
00095               attr_merge_normalize_one( e_overlay, mi->mi_ad_monitoredInfo,
00096                             &bv, NULL );
00097 
00098               j = -1;
00099               LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
00100                      char          buf[ SLAP_LDAPDN_MAXLEN ];
00101                      struct berval dn;
00102 
00103                      j++;
00104                      if ( !overlay_is_inst( be, on->on_bi.bi_type ) ) {
00105                             continue;
00106                      }
00107 
00108                      snprintf( buf, sizeof( buf ), "cn=Database %d,%s",
00109                                    j, ms_database->mss_dn.bv_val );
00110 
00111                      ber_str2bv( buf, 0, 0, &dn );
00112                      attr_merge_normalize_one( e, slap_schema.si_ad_seeAlso,
00113                                    &dn, NULL );
00114               }
00115               
00116               mp = monitor_entrypriv_create();
00117               if ( mp == NULL ) {
00118                      return -1;
00119               }
00120               e->e_private = ( void * )mp;
00121               mp->mp_info = ms;
00122               mp->mp_flags = ms->mss_flags
00123                      | MONITOR_F_SUB;
00124 
00125               if ( monitor_cache_add( mi, e ) ) {
00126                      Debug( LDAP_DEBUG_ANY,
00127                             "monitor_subsys_overlay_init: "
00128                             "unable to add entry \"cn=Overlay %d,%s\"\n",
00129                             i, ms->mss_ndn.bv_val, 0 );
00130                      return( -1 );
00131               }
00132 
00133               *ep = e;
00134               ep = &mp->mp_next;
00135        }
00136        
00137        monitor_cache_release( mi, e_overlay );
00138 
00139        return( 0 );
00140 }
00141