Back to index

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