📄 init.c
字号:
/* init.c - initialize monitor backend *//* $OpenLDAP: pkg/ldap/servers/slapd/back-monitor/init.c,v 1.89.2.18 2007/01/25 12:42:38 hyc Exp $ *//* This work is part of OpenLDAP Software <http://www.openldap.org/>. * * Copyright 2001-2007 The OpenLDAP Foundation. * Portions Copyright 2001-2003 Pierangelo Masarati. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted only as authorized by the OpenLDAP * Public License. * * A copy of this license is available in file LICENSE in the * top-level directory of the distribution or, alternatively, at * <http://www.OpenLDAP.org/license.html>. *//* ACKNOWLEDGEMENTS: * This work was initially developed by Pierangelo Masarati for inclusion * in OpenLDAP Software. */#include "portable.h"#include <stdio.h>#include <ac/string.h>#include <lutil.h>#include "slap.h"#include "config.h"#include "lber_pvt.h"#include "back-monitor.h"#undef INTEGRATE_CORE_SCHEMA/* * used by many functions to add description to entries * * WARNING: be_monitor may change as new databases are added, * so it should not be used outside monitor_back_db_init() * until monitor_back_db_open is called. */BackendDB *be_monitor;static struct monitor_subsys_t **monitor_subsys;static int monitor_subsys_opened;static monitor_info_t monitor_info;/* * subsystem data * * the known subsystems are added to the subsystems * array at backend initialization; other subsystems * may be added by calling monitor_back_register_subsys() * before the database is opened (e.g. by other backends * or by overlays or modules). */static struct monitor_subsys_t known_monitor_subsys[] = { { SLAPD_MONITOR_BACKEND_NAME, BER_BVNULL, BER_BVNULL, BER_BVNULL, { BER_BVC( "This subsystem contains information about available backends." ), BER_BVNULL }, MONITOR_F_PERSISTENT_CH, monitor_subsys_backend_init, NULL, /* destroy */ NULL, /* update */ NULL, /* create */ NULL /* modify */ }, { SLAPD_MONITOR_CONN_NAME, BER_BVNULL, BER_BVNULL, BER_BVNULL, { BER_BVC( "This subsystem contains information about connections." ), BER_BVNULL }, MONITOR_F_VOLATILE_CH, monitor_subsys_conn_init, NULL, /* destroy */ NULL, /* update */ NULL, /* create */ NULL /* modify */ }, { SLAPD_MONITOR_DATABASE_NAME, BER_BVNULL, BER_BVNULL, BER_BVNULL, { BER_BVC( "This subsystem contains information about configured databases." ), BER_BVNULL }, MONITOR_F_PERSISTENT_CH, monitor_subsys_database_init, NULL, /* destroy */ NULL, /* update */ NULL, /* create */ NULL /* modify */ }, { SLAPD_MONITOR_LISTENER_NAME, BER_BVNULL, BER_BVNULL, BER_BVNULL, { BER_BVC( "This subsystem contains information about active listeners." ), BER_BVNULL }, MONITOR_F_PERSISTENT_CH, monitor_subsys_listener_init, NULL, /* destroy */ NULL, /* update */ NULL, /* create */ NULL /* modify */ }, { SLAPD_MONITOR_LOG_NAME, BER_BVNULL, BER_BVNULL, BER_BVNULL, { BER_BVC( "This subsystem contains information about logging." ), BER_BVC( "Set the attribute \"managedInfo\" to the desired log levels." ), BER_BVNULL }, MONITOR_F_NONE, monitor_subsys_log_init, NULL, /* destroy */ NULL, /* update */ NULL, /* create */ NULL, /* modify */ }, { SLAPD_MONITOR_OPS_NAME, BER_BVNULL, BER_BVNULL, BER_BVNULL, { BER_BVC( "This subsystem contains information about performed operations." ), BER_BVNULL }, MONITOR_F_PERSISTENT_CH, monitor_subsys_ops_init, NULL, /* destroy */ NULL, /* update */ NULL, /* create */ NULL, /* modify */ }, { SLAPD_MONITOR_OVERLAY_NAME, BER_BVNULL, BER_BVNULL, BER_BVNULL, { BER_BVC( "This subsystem contains information about available overlays." ), BER_BVNULL }, MONITOR_F_PERSISTENT_CH, monitor_subsys_overlay_init, NULL, /* destroy */ NULL, /* update */ NULL, /* create */ NULL, /* modify */ }, { SLAPD_MONITOR_SASL_NAME, BER_BVNULL, BER_BVNULL, BER_BVNULL, { BER_BVC( "This subsystem contains information about SASL." ), BER_BVNULL }, MONITOR_F_NONE, NULL, /* init */ NULL, /* destroy */ NULL, /* update */ NULL, /* create */ NULL /* modify */ }, { SLAPD_MONITOR_SENT_NAME, BER_BVNULL, BER_BVNULL, BER_BVNULL, { BER_BVC( "This subsystem contains statistics." ), BER_BVNULL }, MONITOR_F_PERSISTENT_CH, monitor_subsys_sent_init, NULL, /* destroy */ NULL, /* update */ NULL, /* create */ NULL, /* modify */ }, { SLAPD_MONITOR_THREAD_NAME, BER_BVNULL, BER_BVNULL, BER_BVNULL, { BER_BVC( "This subsystem contains information about threads." ), BER_BVNULL }, MONITOR_F_PERSISTENT_CH, monitor_subsys_thread_init, NULL, /* destroy */ NULL, /* update */ NULL, /* create */ NULL /* modify */ }, { SLAPD_MONITOR_TIME_NAME, BER_BVNULL, BER_BVNULL, BER_BVNULL, { BER_BVC( "This subsystem contains information about time." ), BER_BVNULL }, MONITOR_F_PERSISTENT_CH, monitor_subsys_time_init, NULL, /* destroy */ NULL, /* update */ NULL, /* create */ NULL, /* modify */ }, { SLAPD_MONITOR_TLS_NAME, BER_BVNULL, BER_BVNULL, BER_BVNULL, { BER_BVC( "This subsystem contains information about TLS." ), BER_BVNULL }, MONITOR_F_NONE, NULL, /* init */ NULL, /* destroy */ NULL, /* update */ NULL, /* create */ NULL /* modify */ }, { SLAPD_MONITOR_RWW_NAME, BER_BVNULL, BER_BVNULL, BER_BVNULL, { BER_BVC( "This subsystem contains information about read/write waiters." ), BER_BVNULL }, MONITOR_F_PERSISTENT_CH, monitor_subsys_rww_init, NULL, /* destroy */ NULL, /* update */ NULL, /* create */ NULL /* modify */ }, { NULL }};intmonitor_back_register_subsys( monitor_subsys_t *ms ){ int i = 0; if ( monitor_subsys ) { for ( ; monitor_subsys[ i ] != NULL; i++ ) /* just count'em */ ; } monitor_subsys = ch_realloc( monitor_subsys, ( 2 + i ) * sizeof( monitor_subsys_t * ) ); if ( monitor_subsys == NULL ) { return -1; } monitor_subsys[ i ] = ms; monitor_subsys[ i + 1 ] = NULL; /* if a subsystem is registered __AFTER__ subsystem * initialization (depending on the sequence the databases * are listed in slapd.conf), init it */ if ( monitor_subsys_opened ) { /* FIXME: this should only be possible * if be_monitor is already initialized */ assert( be_monitor != NULL ); if ( ms->mss_open && ( *ms->mss_open )( be_monitor, ms ) ) { return -1; } ms->mss_flags |= MONITOR_F_OPENED; } return 0;}enum { LIMBO_ENTRY, LIMBO_ENTRY_PARENT, LIMBO_ATTRS, LIMBO_CB};typedef struct entry_limbo_t { int el_type; Entry *el_e; Attribute *el_a; struct berval el_ndn; struct berval el_base; int el_scope; struct berval el_filter; monitor_callback_t *el_cb; struct entry_limbo_t *el_next;} entry_limbo_t;intmonitor_back_is_configured( void ){ return be_monitor != NULL;}intmonitor_back_register_entry( Entry *e, monitor_callback_t *cb ){ monitor_info_t *mi; if ( be_monitor == NULL ) { Debug( LDAP_DEBUG_ANY, "monitor_back_register_entry(\"%s\"): " "monitor database not configured.\n", e->e_name.bv_val, 0, 0 ); return -1; } mi = ( monitor_info_t * )be_monitor->be_private; assert( mi != NULL ); assert( e != NULL ); assert( e->e_private == NULL ); if ( monitor_subsys_opened ) { Entry *e_parent = NULL, *e_new = NULL, **ep = NULL; struct berval pdn = BER_BVNULL; monitor_entry_t *mp = NULL, *mp_parent = NULL; int rc = 0; if ( monitor_cache_get( mi, &e->e_nname, &e_parent ) == 0 ) { /* entry exists */ Debug( LDAP_DEBUG_ANY, "monitor_back_register_entry(\"%s\"): " "entry exists\n", e->e_name.bv_val, 0, 0 ); monitor_cache_release( mi, e_parent ); return -1; } dnParent( &e->e_nname, &pdn ); if ( monitor_cache_get( mi, &pdn, &e_parent ) != 0 ) { /* parent does not exist */ Debug( LDAP_DEBUG_ANY, "monitor_back_register_entry(\"%s\"): " "parent \"%s\" not found\n", e->e_name.bv_val, pdn.bv_val, 0 ); return -1; } assert( e_parent->e_private != NULL ); mp_parent = ( monitor_entry_t * )e_parent->e_private; if ( mp_parent->mp_flags & MONITOR_F_VOLATILE ) { /* entry is volatile; cannot append children */ Debug( LDAP_DEBUG_ANY, "monitor_back_register_entry(\"%s\"): " "parent \"%s\" is volatile\n", e->e_name.bv_val, e_parent->e_name.bv_val, 0 ); rc = -1; goto done; } mp = monitor_entrypriv_create(); if ( mp == NULL ) { Debug( LDAP_DEBUG_ANY, "monitor_back_register_entry(\"%s\"): " "monitor_entrypriv_create() failed\n", e->e_name.bv_val, 0, 0 ); rc = -1; goto done; } e_new = entry_dup( e ); if ( e_new == NULL ) { Debug( LDAP_DEBUG_ANY, "monitor_back_register_entry(\"%s\"): " "entry_dup() failed\n", e->e_name.bv_val, 0, 0 ); rc = -1; goto done; } e_new->e_private = ( void * )mp; mp->mp_info = mp_parent->mp_info; mp->mp_flags = mp_parent->mp_flags | MONITOR_F_SUB; mp->mp_cb = cb; ep = &mp_parent->mp_children; for ( ; *ep; ) { mp_parent = ( monitor_entry_t * )(*ep)->e_private; ep = &mp_parent->mp_next; } *ep = e_new; if ( monitor_cache_add( mi, e_new ) ) { Debug( LDAP_DEBUG_ANY, "monitor_back_register_entry(\"%s\"): " "unable to add entry\n", e->e_name.bv_val, 0, 0 ); rc = -1; goto done; }done:; if ( rc ) { if ( mp ) { ch_free( mp ); } if ( e_new ) { e_new->e_private = NULL; entry_free( e_new ); } } if ( e_parent ) { monitor_cache_release( mi, e_parent ); } } else { entry_limbo_t **elpp, el = { 0 }; el.el_type = LIMBO_ENTRY; el.el_e = entry_dup( e ); if ( el.el_e == NULL ) { Debug( LDAP_DEBUG_ANY, "monitor_back_register_entry(\"%s\"): " "entry_dup() failed\n", e->e_name.bv_val, 0, 0 ); return -1; } el.el_cb = cb; for ( elpp = (entry_limbo_t **)&mi->mi_entry_limbo; *elpp; elpp = &(*elpp)->el_next ) /* go to last */; *elpp = (entry_limbo_t *)ch_malloc( sizeof( entry_limbo_t ) ); if ( *elpp == NULL ) { el.el_e->e_private = NULL; entry_free( el.el_e ); return -1; } el.el_next = NULL; **elpp = el; } return 0;}intmonitor_back_register_entry_parent( Entry *e, monitor_callback_t *cb, struct berval *base, int scope, struct berval *filter ){ monitor_info_t *mi; struct berval ndn = BER_BVNULL; if ( be_monitor == NULL ) { Debug( LDAP_DEBUG_ANY, "monitor_back_register_entry_parent(base=\"%s\" scope=%s filter=\"%s\"): " "monitor database not configured.\n", BER_BVISNULL( base ) ? "" : base->bv_val, scope == LDAP_SCOPE_BASE ? "base" : ( scope == LDAP_SCOPE_ONELEVEL ? "one" : "subtree" ), BER_BVISNULL( filter ) ? "" : filter->bv_val ); return -1; } mi = ( monitor_info_t * )be_monitor->be_private; assert( mi != NULL ); assert( e != NULL ); assert( e->e_private == NULL ); if ( BER_BVISNULL( filter ) ) { /* need a filter */ Debug( LDAP_DEBUG_ANY, "monitor_back_register_entry_parent(\"\"): " "need a valid filter\n", 0, 0, 0 ); return -1; } if ( monitor_subsys_opened ) { Entry *e_parent = NULL, *e_new = NULL, **ep = NULL; struct berval e_name = BER_BVNULL, e_nname = BER_BVNULL; monitor_entry_t *mp = NULL, *mp_parent = NULL; int rc = 0; if ( monitor_filter2ndn( base, scope, filter, &ndn ) ) { /* entry does not exist */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -