This is the skeleton of back-monitor, the slapd monitoring backend.

The old monitoring stuff has been removed; the new backend is
enabled by using --enable-monitor at configure time and requires

	database monitor

in slapd.conf to be activated.  At present it implements a subset
of the old monitoring options, and it should be extendable to
a number of different subsystems.  The search operation has been
implementd; it does not honor abandon or size/time limits, though.
The compare and the abandon operations are planned.

Copyright Pierangelo Masarati <ando@sys-net.it>; the code is provided
AS IS with NO GUARANTEE.  It can be used and distributed under the
conditions stated by the OpenLDAP Public License.
This commit is contained in:
Pierangelo Masarati 2001-07-14 17:34:24 +00:00
parent 4b22216d77
commit 5fdba27288
30 changed files with 3788 additions and 1621 deletions

2570
configure vendored

File diff suppressed because it is too large Load diff

View file

@ -183,6 +183,9 @@ OL_ARG_WITH(ldbm_type,[ --with-ldbm-type use LDBM type], auto,
OL_ARG_ENABLE(meta,[ --enable-meta enable metadirectory backend], no)dnl
OL_ARG_WITH(meta_module,[ --with-meta-module module type], static,
[static dynamic])
OL_ARG_ENABLE(monitor,[ --enable-monitor enable monitor backend], no)dnl
OL_ARG_WITH(monitor_module,[ --with-monitor-module module type], static,
[static dynamic])
OL_ARG_ENABLE(passwd,[ --enable-passwd enable passwd backend], no)dnl
OL_ARG_WITH(passwd_module,[ --with-passwd-module module type], static,
[static dynamic])
@ -231,6 +234,9 @@ if test $ol_enable_slapd = no ; then
if test $ol_enable_meta = yes ; then
AC_MSG_WARN([slapd disabled, ignoring --enable-meta argument])
fi
if test $ol_enable_module = yes ; then
AC_MSG_WARN([slapd disabled, ignoring --enable-monitor argument])
fi
if test $ol_enable_passwd = yes ; then
AC_MSG_WARN([slapd disabled, ignoring --enable-passwd argument])
fi
@ -285,6 +291,9 @@ dnl fi
if test $ol_with_meta_module != static ; then
AC_MSG_WARN([slapd disabled, ignoring --with-meta-module argument])
fi
if test $ol_with_monitor_module != static ; then
AC_MSG_WARN([slapd disabled, ignoring --with-monitor-module argument])
fi
if test $ol_with_passwd_module != static ; then
AC_MSG_WARN([slapd disabled, ignoring --with-passwd-module argument])
fi
@ -313,6 +322,7 @@ dnl fi
ol_enable_ldap=no
ol_enable_ldbm=no
ol_enable_meta=no
ol_enable_monitor=no
ol_enable_passwd=no
ol_enable_perl=no
ol_enable_shell=no
@ -335,6 +345,7 @@ dnl ol_enable_multimaster=no
ol_with_ldap_module=static
ol_with_ldbm_module=static
ol_with_meta_module=static
ol_with_monitor_module=static
ol_with_passwd_module=static
ol_with_perl_module=static
ol_with_shell_module=static
@ -365,6 +376,7 @@ elif test $ol_enable_ldbm = no ; then
$ol_enable_dnssrv = no -a \
$ol_enable_ldap = no -a \
$ol_enable_meta = no -a \
$ol_enable_monitor = no -a \
$ol_enable_passwd = no -a \
$ol_enable_perl = no -a \
$ol_enable_shell = no -a \
@ -448,6 +460,7 @@ BUILD_DNSSRV=no
BUILD_LDAP=no
BUILD_LDBM=no
BUILD_META=no
BUILD_MONITOR=no
BUILD_PASSWD=no
BUILD_PERL=no
BUILD_SHELL=no
@ -459,6 +472,7 @@ BUILD_DNSSRV_DYNAMIC=static
BUILD_LDAP_DYNAMIC=static
BUILD_LDBM_DYNAMIC=static
BUILD_META_DYNAMIC=static
BUILD_MONITOR_DYNAMIC=static
BUILD_PASSWD_DYNAMIC=static
BUILD_PERL_DYNAMIC=static
BUILD_SHELL_DYNAMIC=static
@ -673,6 +687,7 @@ else
ol_with_ldap_module=static
ol_with_ldbm_module=static
ol_with_meta_module=static
ol_with_monitor_module=static
ol_with_passwd_module=static
ol_with_perl_module=static
ol_with_shell_module=static
@ -2378,6 +2393,19 @@ if test "$ol_enable_meta" != no ; then
fi
fi
if test "$ol_enable_monitor" != no ; then
AC_DEFINE(SLAPD_MONITOR,1,[define to support cn=Monitor backend])
BUILD_SLAPD=yes
BUILD_MONITOR=yes
if test "$ol_with_monitor_module" != static ; then
AC_DEFINE(SLAPD_MONITOR_DYNAMIC,1,
[define to support dynamic cn=Monitor backend])
BUILD_MONITOR=mod
BUILD_MONITOR_DYNAMIC=shared
SLAPD_MODULES_LIST="$SLAPD_MODULES_LIST -dlopen \$(SLAP_DIR)back-monitor/back_monitor.la"
fi
fi
if test "$ol_enable_passwd" != no ; then
AC_DEFINE(SLAPD_PASSWD,1,[define to support PASSWD backend])
BUILD_SLAPD=yes
@ -2485,6 +2513,7 @@ AC_SUBST(BUILD_SLAPD)
AC_SUBST(BUILD_LDAP)
AC_SUBST(BUILD_LDBM)
AC_SUBST(BUILD_META)
AC_SUBST(BUILD_MONITOR)
AC_SUBST(BUILD_PASSWD)
AC_SUBST(BUILD_PERL)
AC_SUBST(BUILD_SHELL)
@ -2495,6 +2524,7 @@ AC_SUBST(BUILD_SLAPD)
AC_SUBST(BUILD_LDAP_DYNAMIC)
AC_SUBST(BUILD_LDBM_DYNAMIC)
AC_SUBST(BUILD_META_DYNAMIC)
AC_SUBST(BUILD_MONITOR_DYNAMIC)
AC_SUBST(BUILD_PASSWD_DYNAMIC)
AC_SUBST(BUILD_PERL_DYNAMIC)
AC_SUBST(BUILD_SHELL_DYNAMIC)
@ -2572,6 +2602,7 @@ servers/slapd/back-dnssrv/Makefile:build/top.mk:servers/slapd/back-dnssrv/Makefi
servers/slapd/back-ldap/Makefile:build/top.mk:servers/slapd/back-ldap/Makefile.in:build/mod.mk \
servers/slapd/back-ldbm/Makefile:build/top.mk:servers/slapd/back-ldbm/Makefile.in:build/mod.mk \
servers/slapd/back-meta/Makefile:build/top.mk:servers/slapd/back-meta/Makefile.in:build/mod.mk \
servers/slapd/back-monitor/Makefile:build/top.mk:servers/slapd/back-monitor/Makefile.in:build/mod.mk \
servers/slapd/back-passwd/Makefile:build/top.mk:servers/slapd/back-passwd/Makefile.in:build/mod.mk \
servers/slapd/back-perl/Makefile:build/top.mk:servers/slapd/back-perl/Makefile.in:build/mod.mk \
servers/slapd/back-shell/Makefile:build/top.mk:servers/slapd/back-shell/Makefile.in:build/mod.mk \

View file

@ -222,9 +222,10 @@ Please try again later.\r\n"
/* the following DNs must be normalized! */
/* dn of the default subschema subentry */
#define SLAPD_SCHEMA_DN "cn=Subschema"
#if 0
/* dn of the default "monitor" subentry */
#define SLAPD_MONITOR_DN "cn=Monitor"
#define SLAPD_MONITOR_NDN "CN=MONITOR"
#if 0
/* dn of the default "config" subentry */
#define SLAPD_CONFIG_DN "cn=Config"
#endif

View file

@ -928,6 +928,12 @@
/* define to support dynamic LDAP Metadirectory backend */
#undef SLAPD_META_DYNAMIC
/* define to support cn=Monitor backend */
#undef SLAPD_MONITOR
/* define to support dynamic cn=Monitor backend */
#undef SLAPD_MONITOR_DYNAMIC
/* define to support PASSWD backend */
#undef SLAPD_PASSWD

View file

@ -17,7 +17,7 @@ SRCS = main.c daemon.c connection.c search.c filter.c add.c charray.c \
repl.c lock.c controls.c extended.c kerberos.c passwd.c \
schema.c schema_check.c schema_init.c schema_prep.c \
schemaparse.c ad.c at.c mr.c syntax.c oc.c saslauthz.c \
monitor.c configinfo.c starttls.c index.c sets.c \
configinfo.c starttls.c index.c sets.c \
root_dse.c sasl.c module.c suffixalias.c mra.c mods.c \
$(@PLAT@_SRCS)
@ -29,7 +29,7 @@ OBJS = main.o daemon.o connection.o search.o filter.o add.o charray.o \
repl.o lock.o controls.o extended.o kerberos.o passwd.o \
schema.o schema_check.o schema_init.o schema_prep.o \
schemaparse.o ad.o at.o mr.o syntax.o oc.o saslauthz.o \
monitor.o configinfo.o starttls.o index.o sets.o \
configinfo.o starttls.o index.o sets.o \
root_dse.o sasl.o module.o suffixalias.o mra.o mods.o \
$(@PLAT@_OBJS)

View file

@ -0,0 +1,29 @@
Copyright 2001 The OpenLDAP Foundation, All Rights Reserved.
COPYING RESTRICTIONS APPLY, see COPYRIGHT file
Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
This work has beed deveolped for the OpenLDAP Foundation
in the hope that it may be useful to the Open Source community,
but WITHOUT ANY WARRANTY.
Permission is granted to anyone to use this software for any purpose
on any computer system, and to alter it and redistribute it, subject
to the following restrictions:
1. The author and SysNet s.n.c. are not responsible for the consequences
of use of this software, no matter how awful, even if they arise from
flaws in it.
2. The origin of this software must not be misrepresented, either by
explicit claim or by omission. Since few users ever read sources,
credits should appear in the documentation.
3. Altered versions must be plainly marked as such, and must not be
misrepresented as being the original software. Since few users
ever read sources, credits should appear in the documentation.
SysNet s.n.c. cannot be responsible for the consequences of the
alterations.
4. This notice may not be removed or altered.

View file

@ -0,0 +1,39 @@
# $OpenLDAP$
SRCS = init.c search.c compare.c abandon.c \
cache.c entry.c \
backend.c database.c thread.c conn.c rww.c \
dummy.c
OBJS = init.o search.o compare.o abandon.o \
cache.o entry.o \
backend.o database.o thread.o conn.o rww.o \
dummy.o
LDAP_INCDIR= ../../../include
LDAP_LIBDIR= ../../../libraries
BUILD_OPT = "--enable-monitor"
BUILD_MOD = @BUILD_MONITOR@
LINKAGE = @BUILD_MONITOR_DYNAMIC@
DYN_DEFS = -DLBER_DECL=dllimport -DLDAP_DECL=dllimport
# TODO
#NT_mod_DYN_MODDEFS =
#NT_mod_STAT_MODDEFS =
NT_yes_DYN_MODDEFS = $(DYN_DEFS)
NT_yes_STAT_MODDEFS =
MODDEFS = $(@PLAT@_@BUILD_MONITOR@_@LIB_LINKAGE@_MODDEFS)
LIBBASE = back_monitor
XINCPATH = -I.. -I$(srcdir)/..
XDEFS = $(MODULES_CPPFLAGS)
all-local-lib: ../.backend
../.backend: lib$(LIBBASE).a
@touch $@

View file

@ -0,0 +1,33 @@
back-monitor
Backend for monitoring the server's activity. It must be explicitly
enabled by configuring with `--enable-monitor' set; then it must be
activated by placing in slapd.conf the configure directive
database monitor
The suffix "cn=Monitor" is implicitly activated (it cannot be given
as a suffix of the database as usually done for conventional backends).
The backend root is "cn=Monitor"; the first level entries represent
the monitored subsystems. It is being implemented in a modular way,
to ease the addition of new subsystems.
All the subsystems get a default "cn" attribute, represented by the
subsystem's name, and they all have "top", "LDAPsubEntry" and
"monitorSubEntry" objectclasses (the latter has not been defined yet,
pending the design of the monitor schema and its registration under
OpenLDAP's OID).
Most of the sybsystems contain an additional depth level, represented
by detailed item monitoring.
All the entries undergo an update operation, if a related method is
defined, prior to being returned. Moreover, there's a mechanism to
allow volatile entries to be defined, and generated on the fly when
requested. As an instance, the connection statistics are updated
at each request, while each active connection data is created on the
fly.
This document is in a very early stage of maturity and will probably
be rewritten many times before the monitor backend is released.
Author: Pierangelo Masarati <ando@OpenLDAP.org>

View file

@ -0,0 +1,52 @@
/* abandon.c - monitor backend abandon routine */
/*
* Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
/*
* Copyright 2001 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*
* Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
*
* This work has beed deveolped for the OpenLDAP Foundation
* in the hope that it may be useful to the Open Source community,
* but WITHOUT ANY WARRANTY.
*
* Permission is granted to anyone to use this software for any purpose
* on any computer system, and to alter it and redistribute it, subject
* to the following restrictions:
*
* 1. The author and SysNet s.n.c. are not responsible for the consequences
* of use of this software, no matter how awful, even if they arise from
* flaws in it.
*
* 2. The origin of this software must not be misrepresented, either by
* explicit claim or by omission. Since few users ever read sources,
* credits should appear in the documentation.
*
* 3. Altered versions must be plainly marked as such, and must not be
* misrepresented as being the original software. Since few users
* ever read sources, credits should appear in the documentation.
* SysNet s.n.c. cannot be responsible for the consequences of the
* alterations.
*
* 4. This notice may not be removed or altered.
*/
#include "portable.h"
#include <slap.h>
#include "back-monitor.h"
int
monitor_back_abandon(
BackendDB *be,
struct slap_conn *c,
struct slap_op *o,
ber_int_t msgid
)
{
return( 0 );
}

View file

@ -0,0 +1,191 @@
/* back-monitor.h - ldap monitor back-end header file */
/*
* Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
/*
* Copyright 2001 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*
* Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
*
* This work has beed deveolped for the OpenLDAP Foundation
* in the hope that it may be useful to the Open Source community,
* but WITHOUT ANY WARRANTY.
*
* Permission is granted to anyone to use this software for any purpose
* on any computer system, and to alter it and redistribute it, subject
* to the following restrictions:
*
* 1. The author and SysNet s.n.c. are not responsible for the consequences
* of use of this software, no matter how awful, even if they arise from
* flaws in it.
*
* 2. The origin of this software must not be misrepresented, either by
* explicit claim or by omission. Since few users ever read sources,
* credits should appear in the documentation.
*
* 3. Altered versions must be plainly marked as such, and must not be
* misrepresented as being the original software. Since few users
* ever read sources, credits should appear in the documentation.
* SysNet s.n.c. cannot be responsible for the consequences of the
* alterations.
*
* 4. This notice may not be removed or altered.
*/
#ifndef _BACK_MONITOR_H_
#define _BACK_MONITOR_H_
#include <slap.h>
#include <avl.h>
#include <ldap_pvt.h>
#include <ldap_pvt_thread.h>
LDAP_BEGIN_DECL
/*
* The cache maps DNs to Entries.
* Each entry, on turn, holds the list of its children in the e_private field.
* This is used by search operation to perform onelevel and subtree candidate
* selection.
*/
struct monitorcache {
char *mc_ndn;
Entry *mc_e;
};
struct monitorentrypriv {
ldap_pvt_thread_mutex_t mp_mutex; /* entry mutex */
Entry *mp_next; /* pointer to next sibling */
Entry *mp_children; /* pointer to first child */
struct monitorsubsys *mp_info; /* subsystem info */
#define mp_type mp_info->mss_type
int mp_flags; /* flags */
#define MONITOR_F_NONE 0x00
#define MONITOR_F_SUB 0x01 /* subentry of subsystem */
#define MONITOR_F_PERSISTENT 0x10 /* persistent entry */
#define MONITOR_F_PERSISTENT_CH 0x20 /* subsystem generates
persistent entries */
#define MONITOR_F_VOLATILE 0x40 /* volatile entry */
#define MONITOR_F_VOLATILE_CH 0x80 /* subsystem generates
volatile entries */
};
struct monitorinfo {
Avlnode *mi_cache;
ldap_pvt_thread_mutex_t mi_cache_mutex;
};
/*
* DNs
*/
#define SLAPD_MONITOR_LISTENER 0
#define SLAPD_MONITOR_LISTENER_NAME "Listener"
#define SLAPD_MONITOR_LISTENER_RDN \
"cn=" SLAPD_MONITOR_LISTENER_NAME
#define SLAPD_MONITOR_LISTENER_DN \
SLAPD_MONITOR_LISTENER_RDN "," SLAPD_MONITOR_DN
#define SLAPD_MONITOR_DATABASE 1
#define SLAPD_MONITOR_DATABASE_NAME "Databases"
#define SLAPD_MONITOR_DATABASE_RDN \
"cn=" SLAPD_MONITOR_DATABASE_NAME
#define SLAPD_MONITOR_DATABASE_DN \
SLAPD_MONITOR_DATABASE_RDN "," SLAPD_MONITOR_DN
#define SLAPD_MONITOR_BACKEND 2
#define SLAPD_MONITOR_BACKEND_NAME "Backends"
#define SLAPD_MONITOR_BACKEND_RDN \
"cn=" SLAPD_MONITOR_BACKEND_NAME
#define SLAPD_MONITOR_BACKEND_DN \
SLAPD_MONITOR_BACKEND_RDN "," SLAPD_MONITOR_DN
#define SLAPD_MONITOR_THREAD 3
#define SLAPD_MONITOR_THREAD_NAME "Threads"
#define SLAPD_MONITOR_THREAD_RDN \
"cn=" SLAPD_MONITOR_THREAD_NAME
#define SLAPD_MONITOR_THREAD_DN \
SLAPD_MONITOR_THREAD_RDN "," SLAPD_MONITOR_DN
#define SLAPD_MONITOR_SASL 4
#define SLAPD_MONITOR_SASL_NAME "SASL"
#define SLAPD_MONITOR_SASL_RDN \
"cn=" SLAPD_MONITOR_SASL_NAME
#define SLAPD_MONITOR_SASL_DN \
SLAPD_MONITOR_SASL_RDN "," SLAPD_MONITOR_DN
#define SLAPD_MONITOR_TLS 5
#define SLAPD_MONITOR_TLS_NAME "TLS"
#define SLAPD_MONITOR_TLS_RDN \
"cn=" SLAPD_MONITOR_TLS_NAME
#define SLAPD_MONITOR_TLS_DN \
SLAPD_MONITOR_TLS_RDN "," SLAPD_MONITOR_DN
#define SLAPD_MONITOR_CONN 6
#define SLAPD_MONITOR_CONN_NAME "Connections"
#define SLAPD_MONITOR_CONN_RDN \
"cn=" SLAPD_MONITOR_CONN_NAME
#define SLAPD_MONITOR_CONN_DN \
SLAPD_MONITOR_CONN_RDN "," SLAPD_MONITOR_DN
#define SLAPD_MONITOR_READW 7
#define SLAPD_MONITOR_READW_NAME "Read Waiters"
#define SLAPD_MONITOR_READW_RDN \
"cn=" SLAPD_MONITOR_READW_NAME
#define SLAPD_MONITOR_READW_DN \
SLAPD_MONITOR_READW_RDN "," SLAPD_MONITOR_DN
#define SLAPD_MONITOR_WRITEW 8
#define SLAPD_MONITOR_WRITEW_NAME "Write Waiters"
#define SLAPD_MONITOR_WRITEW_RDN \
"cn=" SLAPD_MONITOR_WRITEW_NAME
#define SLAPD_MONITOR_WRITEW_DN \
SLAPD_MONITOR_WRITEW_RDN "," SLAPD_MONITOR_DN
struct monitorsubsys {
int mss_type;
char *mss_name;
char *mss_rdn;
char *mss_dn;
char *mss_ndn;
int mss_flags;
#define MONITOR_HAS_VOLATILE_CH( mp ) \
( ( mp )->mp_flags & MONITOR_F_VOLATILE_CH )
int ( *mss_init )( BackendDB * );
int ( *mss_update )( struct monitorinfo *, Entry * );
int ( *mss_create )( struct monitorinfo *, const char *ndn, Entry *, Entry ** );
};
extern struct monitorsubsys monitor_subsys[];
extern AttributeDescription *monitor_ad_desc;
/*
* cache
*/
extern int monitor_cache_cmp LDAP_P(( const void *c1, const void *c2 ));
extern int monitor_cache_dup LDAP_P(( void *c1, void *c2 ));
extern int monitor_cache_add LDAP_P(( struct monitorinfo *mi, Entry *e ));
extern int monitor_cache_get LDAP_P(( struct monitorinfo *mi, const char *ndn, Entry **ep ));
extern int monitor_cache_dn2entry LDAP_P(( struct monitorinfo *mi, const char *ndn, Entry **ep ));
extern int monitor_cache_lock LDAP_P(( Entry *e ));
extern int monitor_cache_release LDAP_P(( struct monitorinfo *mi, Entry *e ));
/*
* update
*/
extern int monitor_entry_update LDAP_P(( struct monitorinfo *mi, Entry *e ));
extern int monitor_entry_create LDAP_P(( struct monitorinfo *mi, const char *ndn, Entry *e_parent, Entry **ep ));
LDAP_END_DECL
#include "proto-back-monitor.h"
#endif /* _back_monitor_h_ */

View file

@ -0,0 +1,163 @@
/* backend.c - deals with backend subsystem */
/*
* Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
/*
* Copyright 2001 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*
* Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
*
* This work has beed deveolped for the OpenLDAP Foundation
* in the hope that it may be useful to the Open Source community,
* but WITHOUT ANY WARRANTY.
*
* Permission is granted to anyone to use this software for any purpose
* on any computer system, and to alter it and redistribute it, subject
* to the following restrictions:
*
* 1. The author and SysNet s.n.c. are not responsible for the consequences
* of use of this software, no matter how awful, even if they arise from
* flaws in it.
*
* 2. The origin of this software must not be misrepresented, either by
* explicit claim or by omission. Since few users ever read sources,
* credits should appear in the documentation.
*
* 3. Altered versions must be plainly marked as such, and must not be
* misrepresented as being the original software. Since few users
* ever read sources, credits should appear in the documentation.
* SysNet s.n.c. cannot be responsible for the consequences of the
* alterations.
*
* 4. This notice may not be removed or altered.
*/
#include "portable.h"
#include <stdio.h>
#include "slap.h"
#include "back-monitor.h"
/*
* initializes backend subentries
*/
int
monitor_subsys_backend_init(
BackendDB *be
)
{
struct monitorinfo *mi;
Entry *e, *e_backend, *e_tmp;
int i;
struct monitorentrypriv *mp;
struct berval *bv[2], val;
mi = ( struct monitorinfo * )be->be_private;
if ( monitor_cache_get( mi,
monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn,
&e_backend ) ) {
#ifdef NEW_LOGGING
LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
"monitor_subsys_backend_init: "
"unable to get entry '%s'\n",
monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn ));
#else
Debug( LDAP_DEBUG_ANY,
"monitor_subsys_backend_init: "
"unable to get entry '%s'\n%s%s",
monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn,
"", "" );
#endif
return( -1 );
}
bv[0] = &val;
bv[1] = NULL;
e_tmp = NULL;
for ( i = nBackendInfo; i--; ) {
char buf[1024];
BackendInfo *bi;
bi = &backendInfo[i];
snprintf( buf, sizeof( buf ),
"dn: cn=%d,%s\n"
"objectClass: top\n"
"objectClass: LDAPsubEntry\n"
#ifdef SLAPD_MONITORSUBENTRY
"objectClass: monitorSubEntry\n"
#else /* !SLAPD_MONITORSUBENTRY */
"objectClass: extensibleObject\n"
#endif /* !SLAPD_MONITORSUBENTRY */
"cn: %d\n",
i,
monitor_subsys[SLAPD_MONITOR_BACKEND].mss_dn,
i );
e = str2entry( buf );
if ( e == NULL ) {
#ifdef NEW_LOGGING
LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
"monitor_subsys_backend_init: "
"unable to create entry 'cn=%d,%s'\n",
i,
monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn ));
#else
Debug( LDAP_DEBUG_ANY,
"monitor_subsys_backend_init: "
"unable to create entry 'cn=%d,%s'\n%s",
i,
monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn,
"" );
#endif
return( -1 );
}
val.bv_val = bi->bi_type;
val.bv_len = strlen( val.bv_val );
attr_merge( e, monitor_ad_desc, bv );
attr_merge( e_backend, monitor_ad_desc, bv );
mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
e->e_private = ( void * )mp;
mp->mp_next = e_tmp;
mp->mp_children = NULL;
mp->mp_info = &monitor_subsys[SLAPD_MONITOR_BACKEND];
mp->mp_flags = monitor_subsys[SLAPD_MONITOR_BACKEND].mss_flags
| MONITOR_F_SUB;
if ( monitor_cache_add( mi, e ) ) {
#ifdef NEW_LOGGING
LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
"monitor_subsys_backend_init: "
"unable to add entry 'cn=%d,%s'\n",
i,
monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn ));
#else
Debug( LDAP_DEBUG_ANY,
"monitor_subsys_backend_init: "
"unable to add entry 'cn=%d,%s'\n%s",
i,
monitor_subsys[SLAPD_MONITOR_BACKEND].mss_ndn,
"" );
#endif
return( -1 );
}
e_tmp = e;
}
mp = ( struct monitorentrypriv * )e_backend->e_private;
mp->mp_children = e_tmp;
monitor_cache_release( mi, e_backend);
return( 0 );
}

View file

@ -0,0 +1,244 @@
/* cache.c - routines to maintain an in-core cache of entries */
/*
* Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
/*
* Copyright 2001 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*
* Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
*
* This work has beed deveolped for the OpenLDAP Foundation
* in the hope that it may be useful to the Open Source community,
* but WITHOUT ANY WARRANTY.
*
* Permission is granted to anyone to use this software for any purpose
* on any computer system, and to alter it and redistribute it, subject
* to the following restrictions:
*
* 1. The author and SysNet s.n.c. are not responsible for the consequences
* of use of this software, no matter how awful, even if they arise from
* flaws in it.
*
* 2. The origin of this software must not be misrepresented, either by
* explicit claim or by omission. Since few users ever read sources,
* credits should appear in the documentation.
*
* 3. Altered versions must be plainly marked as such, and must not be
* misrepresented as being the original software. Since few users
* ever read sources, credits should appear in the documentation.
* SysNet s.n.c. cannot be responsible for the consequences of the
* alterations.
*
* 4. This notice may not be removed or altered.
*/
#include "portable.h"
#include <stdio.h>
#include "slap.h"
#include "back-monitor.h"
/*
* compares entries based on the dn
*/
int
monitor_cache_cmp(
const void *c1,
const void *c2
)
{
struct monitorcache *cc1 = ( struct monitorcache * )c1;
struct monitorcache *cc2 = ( struct monitorcache * )c2;
/*
* case sensitive, because the dn MUST be normalized
*/
return strcmp( cc1->mc_ndn, cc2->mc_ndn );
}
/*
* checks for duplicate entries
*/
int
monitor_cache_dup(
void *c1,
void *c2
)
{
struct monitorcache *cc1 = ( struct monitorcache * )c1;
struct monitorcache *cc2 = ( struct monitorcache * )c2;
/*
* case sensitive, because the dn MUST be normalized
*/
return ( strcmp( cc1->mc_ndn, cc2->mc_ndn ) == 0 ) ? -1 : 0;
}
/*
* adds an entry to the cache and inits the mutex
*/
int
monitor_cache_add(
struct monitorinfo *mi,
Entry *e
)
{
struct monitorcache *mc;
struct monitorentrypriv *mp;
int rc;
assert( mi != NULL );
assert( e != NULL );
mp = ( struct monitorentrypriv *)e->e_private;
ldap_pvt_thread_mutex_init( &mp->mp_mutex );
mc = ( struct monitorcache * )ch_malloc( sizeof( struct monitorcache ) );
mc->mc_ndn = e->e_ndn;
mc->mc_e = e;
ldap_pvt_thread_mutex_lock( &mi->mi_cache_mutex );
rc = avl_insert( &mi->mi_cache, ( caddr_t )mc,
monitor_cache_cmp, monitor_cache_dup );
ldap_pvt_thread_mutex_unlock( &mi->mi_cache_mutex );
return rc;
}
/*
* locks the entry (no r/w)
*/
int
monitor_cache_lock(
Entry *e
)
{
struct monitorentrypriv *mp;
assert( e != NULL );
assert( e->e_private != NULL );
mp = ( struct monitorentrypriv * )e->e_private;
ldap_pvt_thread_mutex_lock( &mp->mp_mutex );
return( 0 );
}
/*
* gets an entry from the cache based on the normalized dn
* with mutex locked
*/
int
monitor_cache_get(
struct monitorinfo *mi,
const char *ndn,
Entry **ep
)
{
struct monitorcache tmp_mc, *mc;
assert( mi != NULL );
assert( ndn != NULL );
assert( ep != NULL );
tmp_mc.mc_ndn = ( char * )ndn;
ldap_pvt_thread_mutex_lock( &mi->mi_cache_mutex );
mc = ( struct monitorcache * )avl_find( mi->mi_cache,
( caddr_t )&tmp_mc, monitor_cache_cmp );
if ( mc != NULL ) {
/* entry is returned with mutex locked */
monitor_cache_lock( mc->mc_e );
ldap_pvt_thread_mutex_unlock( &mi->mi_cache_mutex );
*ep = mc->mc_e;
return( 0 );
}
ldap_pvt_thread_mutex_unlock( &mi->mi_cache_mutex );
*ep = NULL;
return( -1 );
}
/*
* If the entry exists in cache, it is returned in locked status;
* otherwise, if the parent exists, if it may generate volatile
* descendants an attempt to generate the required entry is
* performed and, if successful, the entry is returned
*/
int
monitor_cache_dn2entry(
struct monitorinfo *mi,
const char *ndn,
Entry **ep
)
{
int rc;
char *p_ndn;
Entry *e_parent;
struct monitorentrypriv *mp;
assert( mi != NULL );
assert( ndn != NULL );
assert( ep != NULL );
rc = monitor_cache_get( mi, ndn, ep );
if ( !rc && *ep != NULL ) {
return( 0 );
}
/* try with parent/ancestors */
p_ndn = dn_parent( NULL, ndn );
rc = monitor_cache_dn2entry( mi, p_ndn, &e_parent );
free( p_ndn );
if ( rc || e_parent == NULL) {
return( -1 );
}
mp = ( struct monitorentrypriv * )e_parent->e_private;
rc = -1;
if ( mp->mp_flags & MONITOR_F_VOLATILE_CH ) {
/* parent entry generates volatile children */
rc = monitor_entry_create( mi, ndn, e_parent, ep );
}
monitor_cache_release( mi, e_parent );
return( rc );
}
/*
* releases the lock of the entry; if it is marked as volatile, it is
* destroyed.
*/
int
monitor_cache_release(
struct monitorinfo *mi,
Entry *e
)
{
struct monitorentrypriv *mp;
assert( mi != NULL );
assert( e != NULL );
assert( e->e_private != NULL );
mp = ( struct monitorentrypriv * )e->e_private;
if ( mp->mp_flags & MONITOR_F_VOLATILE ) {
/* volatile entries do not return to cache */
ldap_pvt_thread_mutex_destroy( &mp->mp_mutex );
ch_free( mp );
e->e_private = NULL;
entry_free( e );
return( 0 );
}
ldap_pvt_thread_mutex_unlock( &mp->mp_mutex );
return( 0 );
}

View file

@ -0,0 +1,56 @@
/* compare.c - monitor backend compare routine */
/*
* Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
/*
* Copyright 2001 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*
* Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
*
* This work has beed deveolped for the OpenLDAP Foundation
* in the hope that it may be useful to the Open Source community,
* but WITHOUT ANY WARRANTY.
*
* Permission is granted to anyone to use this software for any purpose
* on any computer system, and to alter it and redistribute it, subject
* to the following restrictions:
*
* 1. The author and SysNet s.n.c. are not responsible for the consequences
* of use of this software, no matter how awful, even if they arise from
* flaws in it.
*
* 2. The origin of this software must not be misrepresented, either by
* explicit claim or by omission. Since few users ever read sources,
* credits should appear in the documentation.
*
* 3. Altered versions must be plainly marked as such, and must not be
* misrepresented as being the original software. Since few users
* ever read sources, credits should appear in the documentation.
* SysNet s.n.c. cannot be responsible for the consequences of the
* alterations.
*
* 4. This notice may not be removed or altered.
*/
#include "portable.h"
#include <stdio.h>
#include <slap.h>
#include "back-monitor.h"
int
monitor_back_compare(
Backend *be,
Connection *conn,
Operation *op,
const char *dn,
const char *ndn,
AttributeAssertion *ava
)
{
return( 0 );
}

View file

@ -0,0 +1,316 @@
/* conn.c - deal with connection subsystem */
/*
* Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
/*
* Copyright 2001 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*
* Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
*
* This work has beed deveolped for the OpenLDAP Foundation
* in the hope that it may be useful to the Open Source community,
* but WITHOUT ANY WARRANTY.
*
* Permission is granted to anyone to use this software for any purpose
* on any computer system, and to alter it and redistribute it, subject
* to the following restrictions:
*
* 1. The author and SysNet s.n.c. are not responsible for the consequences
* of use of this software, no matter how awful, even if they arise from
* flaws in it.
*
* 2. The origin of this software must not be misrepresented, either by
* explicit claim or by omission. Since few users ever read sources,
* credits should appear in the documentation.
*
* 3. Altered versions must be plainly marked as such, and must not be
* misrepresented as being the original software. Since few users
* ever read sources, credits should appear in the documentation.
* SysNet s.n.c. cannot be responsible for the consequences of the
* alterations.
*
* 4. This notice may not be removed or altered.
*/
#include "portable.h"
#include <stdio.h>
#include "slap.h"
#include "back-monitor.h"
int
monitor_subsys_conn_init(
BackendDB *be
)
{
struct monitorinfo *mi;
char buf[1024];
Entry *e;
struct berval *bv[2], val;
assert( be != NULL );
mi = ( struct monitorinfo * )be->be_private;
if ( monitor_cache_get( mi,
monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn, &e ) ) {
#ifdef NEW_LOGGING
LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
"monitor_subsys_conn_init: "
"unable to get entry '%s'\n",
monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn ));
#else
Debug( LDAP_DEBUG_ANY,
"monitor_subsys_conn_init: "
"unable to get entry '%s'\n%s%s",
monitor_subsys[SLAPD_MONITOR_CONN].mss_ndn,
"", "" );
#endif
return( -1 );
}
bv[0] = &val;
bv[1] = NULL;
monitor_cache_release( mi, e );
return( 0 );
}
int
monitor_subsys_conn_update(
struct monitorinfo *mi,
Entry *e
)
{
Connection *c;
int connindex;
int nconns, nwritewaiters, nreadwaiters;
Attribute *a;
struct berval *bv[2], val, **b = NULL;
char buf[1024];
assert( mi != NULL );
assert( e != NULL );
bv[0] = &val;
bv[1] = NULL;
nconns = nwritewaiters = nreadwaiters = 0;
for ( c = connection_first( &connindex );
c != NULL;
c = connection_next( c, &connindex ), nconns++ ) {
if ( c->c_writewaiter ) {
nwritewaiters++;
}
if ( c->c_currentber != NULL ) {
nreadwaiters++;
}
}
connection_done(c);
#if 0
snprintf( buf, sizeof( buf ), "readwaiters=%d", nreadwaiters );
if ( ( a = attr_find( e->e_attrs, monitor_ad_desc ) ) != NULL ) {
for ( b = a->a_vals; b[0] != NULL; b++ ) {
if ( strncmp( b[0]->bv_val, "readwaiters=",
sizeof( "readwaiters=" ) - 1 ) == 0 ) {
free( b[0]->bv_val );
b[0] = ber_bvstrdup( buf );
break;
}
}
}
if ( b == NULL || b[0] == NULL ) {
val.bv_val = buf;
val.bv_len = strlen( buf );
attr_merge( e, monitor_ad_desc, bv );
}
#endif
return( 0 );
}
static int
conn_create(
Connection *c,
Entry **ep
)
{
struct monitorentrypriv *mp;
struct tm *ltm;
char buf[1024];
char buf2[22];
char buf3[22];
struct berval *bv[2], val;
Entry *e;
assert( c != NULL );
assert( ep != NULL );
snprintf( buf, sizeof( buf ),
"dn: cn=%ld,%s\n"
"objectClass: top\n"
"objectClass: LDAPsubEntry\n"
#ifdef SLAPD_MONITORSUBENTRY
"objectClass: monitorSubEntry\n"
#else /* !SLAPD_MONITORSUBENTRY */
"objectClass: extensibleObject\n"
#endif /* !SLAPD_MONITORSUBENTRY */
"cn: %ld\n",
c->c_connid, monitor_subsys[SLAPD_MONITOR_CONN].mss_dn,
c->c_connid );
e = str2entry( buf );
if ( e == NULL) {
#ifdef NEW_LOGGING
LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
"monitor_subsys_conn_create: "
"unable to create entry "
"'cn=%ld,%s' entry\n",
c->c_connid,
monitor_subsys[SLAPD_MONITOR_CONN].mss_dn ));
#else
Debug( LDAP_DEBUG_ANY,
"monitor_subsys_conn_create: "
"unable to create entry "
"'cn=%ld,%s' entry\n%s",
c->c_connid,
monitor_subsys[SLAPD_MONITOR_CONN].mss_dn, "" );
#endif
return( -1 );
}
ldap_pvt_thread_mutex_lock( &gmtime_mutex );
ltm = gmtime( &c->c_starttime );
strftime( buf2, sizeof(buf2), "%Y%m%d%H%M%SZ", ltm );
ltm = gmtime( &c->c_activitytime );
strftime( buf3, sizeof(buf2), "%Y%m%d%H%M%SZ", ltm );
ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
sprintf( buf,
"%ld : %ld "
": %ld/%ld/%ld/%ld "
": %ld/%ld/%ld "
": %s%s%s%s%s%s "
": %s : %s : %s "
": %s : %s : %s : %s",
c->c_connid,
(long) c->c_protocol,
c->c_n_ops_received, c->c_n_ops_executing,
c->c_n_ops_pending, c->c_n_ops_completed,
/* add low-level counters here */
c->c_n_get, c->c_n_read, c->c_n_write,
c->c_currentber ? "r" : "",
c->c_writewaiter ? "w" : "",
c->c_ops != NULL ? "x" : "",
c->c_pending_ops != NULL ? "p" : "",
connection_state2str( c->c_conn_state ),
c->c_sasl_bind_in_progress ? "S" : "",
c->c_cdn ? c->c_cdn : SLAPD_ANONYMOUS,
c->c_listener_url,
c->c_peer_domain,
c->c_peer_name,
c->c_sock_name,
buf2,
buf3
);
bv[0] = &val;
bv[1] = NULL;
val.bv_val = buf;
val.bv_len = strlen( buf );
attr_merge( e, monitor_ad_desc, bv );
mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
e->e_private = ( void * )mp;
mp->mp_info = &monitor_subsys[ SLAPD_MONITOR_CONN ];
mp->mp_children = NULL;
mp->mp_flags = MONITOR_F_SUB | MONITOR_F_VOLATILE;
*ep = e;
return( 0 );
}
int
monitor_subsys_conn_create(
struct monitorinfo *mi,
const char *ndn,
Entry *e_parent,
Entry **ep
)
{
Connection *c;
int connindex;
struct monitorentrypriv *mp;
assert( mi != NULL );
assert( e_parent != NULL );
assert( ep != NULL );
*ep = NULL;
if ( ndn == NULL ) {
Entry *e, *e_tmp = NULL;
/* create all the children of e_parent */
for ( c = connection_first( &connindex );
c != NULL;
c = connection_next( c, &connindex )) {
if ( conn_create( c, &e ) || e == NULL ) {
// error
}
mp = ( struct monitorentrypriv * )e->e_private;
mp->mp_next = e_tmp;
e_tmp = e;
}
connection_done(c);
*ep = e;
} else {
/* create exactly the required entry */
char *rdn, *value;
unsigned long connid;
rdn = dn_rdn( NULL, ndn );
value = rdn_attr_value( rdn );
connid = atol( value );
free( value );
free( rdn );
for ( c = connection_first( &connindex );
c != NULL;
c = connection_next( c, &connindex )) {
if ( c->c_connid == connid ) {
if ( conn_create( c, ep ) || *ep == NULL ) {
// error
}
}
}
connection_done(c);
}
return( 0 );
}

View file

@ -0,0 +1,169 @@
/* database.c - deals with database subsystem */
/*
* Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
/*
* Copyright 2001 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*
* Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
*
* This work has beed deveolped for the OpenLDAP Foundation
* in the hope that it may be useful to the Open Source community,
* but WITHOUT ANY WARRANTY.
*
* Permission is granted to anyone to use this software for any purpose
* on any computer system, and to alter it and redistribute it, subject
* to the following restrictions:
*
* 1. The author and SysNet s.n.c. are not responsible for the consequences
* of use of this software, no matter how awful, even if they arise from
* flaws in it.
*
* 2. The origin of this software must not be misrepresented, either by
* explicit claim or by omission. Since few users ever read sources,
* credits should appear in the documentation.
*
* 3. Altered versions must be plainly marked as such, and must not be
* misrepresented as being the original software. Since few users
* ever read sources, credits should appear in the documentation.
* SysNet s.n.c. cannot be responsible for the consequences of the
* alterations.
*
* 4. This notice may not be removed or altered.
*/
#include "portable.h"
#include <stdio.h>
#include "slap.h"
#include "back-monitor.h"
int
monitor_subsys_database_init(
BackendDB *be
)
{
struct monitorinfo *mi;
Entry *e, *e_database, *e_tmp;
int i;
struct monitorentrypriv *mp;
AttributeDescription *ad_nc = slap_schema.si_ad_namingContexts;
struct berval *bv[2], val;
assert( be != NULL );
assert( monitor_ad_desc != NULL );
mi = ( struct monitorinfo * )be->be_private;
if ( monitor_cache_get( mi,
monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn,
&e_database ) ) {
#ifdef NEW_LOGGING
LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
"monitor_subsys_database_init: "
"unable to get entry '%s'\n",
monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn ));
#else
Debug( LDAP_DEBUG_ANY,
"monitor_subsys_database_init: "
"unable to get entry '%s'\n%s%s",
monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn,
"", "" );
#endif
return( -1 );
}
bv[0] = &val;
bv[1] = NULL;
e_tmp = NULL;
for ( i = nBackendDB; i--; ) {
char buf[1024];
int j;
be = &backendDB[i];
snprintf( buf, sizeof( buf ),
"dn: cn=%d,%s\n"
"objectClass: top\n"
"objectClass: LDAPsubEntry\n"
#ifdef SLAPD_MONITORSUBENTRY
"objectClass: monitorSubEntry\n"
#else /* !SLAPD_MONITORSUBENTRY */
"objectClass: extensibleObject\n"
#endif /* !SLAPD_MONITORSUBENTRY */
"cn: %d\n",
i,
monitor_subsys[SLAPD_MONITOR_DATABASE].mss_dn,
i );
e = str2entry( buf );
if ( e == NULL ) {
#ifdef NEW_LOGGING
LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
"monitor_subsys_database_init: "
"unable to create entry 'cn=%d,%s'\n",
i,
monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn ));
#else
Debug( LDAP_DEBUG_ANY,
"monitor_subsys_database_init: "
"unable to create entry 'cn=%d,%s'\n%s",
i,
monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn,
"" );
#endif
return( -1 );
}
val.bv_val = be->bd_info->bi_type;
val.bv_len = strlen( val.bv_val );
attr_merge( e, monitor_ad_desc, bv );
for ( j = 0; be->be_suffix[j]; j++ ) {
val.bv_val = be->be_suffix[j];
val.bv_len = strlen( val.bv_val );
attr_merge( e, ad_nc, bv );
attr_merge( e_database, ad_nc, bv );
}
mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
e->e_private = ( void * )mp;
mp->mp_next = e_tmp;
mp->mp_children = NULL;
mp->mp_info = &monitor_subsys[SLAPD_MONITOR_DATABASE];
mp->mp_flags = monitor_subsys[SLAPD_MONITOR_DATABASE].mss_flags
| MONITOR_F_SUB;
if ( monitor_cache_add( mi, e ) ) {
#ifdef NEW_LOGGING
LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
"monitor_subsys_database_init: "
"unable to add entry 'cn=%d,%s'\n",
i,
monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn ));
#else
Debug( LDAP_DEBUG_ANY,
"monitor_subsys_database_init: "
"unable to add entry 'cn=%d,%s'\n%s",
i,
monitor_subsys[SLAPD_MONITOR_DATABASE].mss_ndn,
"" );
#endif
return( -1 );
}
e_tmp = e;
}
mp = ( struct monitorentrypriv * )e_database->e_private;
mp->mp_children = e_tmp;
monitor_cache_release( mi, e_database );
return( 0 );
}

View file

@ -0,0 +1,51 @@
/* dummy.c - dummy functions for monitor backend */
/*
* Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
/*
* Copyright 2001 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*
* Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
*
* This work has beed deveolped for the OpenLDAP Foundation
* in the hope that it may be useful to the Open Source community,
* but WITHOUT ANY WARRANTY.
*
* Permission is granted to anyone to use this software for any purpose
* on any computer system, and to alter it and redistribute it, subject
* to the following restrictions:
*
* 1. The author and SysNet s.n.c. are not responsible for the consequences
* of use of this software, no matter how awful, even if they arise from
* flaws in it.
*
* 2. The origin of this software must not be misrepresented, either by
* explicit claim or by omission. Since few users ever read sources,
* credits should appear in the documentation.
*
* 3. Altered versions must be plainly marked as such, and must not be
* misrepresented as being the original software. Since few users
* ever read sources, credits should appear in the documentation.
* SysNet s.n.c. cannot be responsible for the consequences of the
* alterations.
*
* 4. This notice may not be removed or altered.
*/
#include "portable.h"
#include <stdio.h>
#include "slap.h"
#include "back-monitor.h"
int monitor_back_compare ( BackendDB *bd,
Connection *conn, Operation *op,
const char *dn, const char *ndn,
AttributeAssertion *ava )
{
return -1;
}

View file

@ -0,0 +1,98 @@
/* entry.c - monitor backend entry handling routines */
/*
* Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
/*
* Copyright 2001 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*
* Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
*
* This work has beed deveolped for the OpenLDAP Foundation
* in the hope that it may be useful to the Open Source community,
* but WITHOUT ANY WARRANTY.
*
* Permission is granted to anyone to use this software for any purpose
* on any computer system, and to alter it and redistribute it, subject
* to the following restrictions:
*
* 1. The author and SysNet s.n.c. are not responsible for the consequences
* of use of this software, no matter how awful, even if they arise from
* flaws in it.
*
* 2. The origin of this software must not be misrepresented, either by
* explicit claim or by omission. Since few users ever read sources,
* credits should appear in the documentation.
*
* 3. Altered versions must be plainly marked as such, and must not be
* misrepresented as being the original software. Since few users
* ever read sources, credits should appear in the documentation.
* SysNet s.n.c. cannot be responsible for the consequences of the
* alterations.
*
* 4. This notice may not be removed or altered.
*/
#include "portable.h"
#include <slap.h>
#include "back-monitor.h"
int
monitor_entry_update(
struct monitorinfo *mi,
Entry *e
)
{
struct monitorentrypriv *mp;
assert( mi != NULL );
assert( e != NULL );
assert( e->e_private != NULL );
mp = ( struct monitorentrypriv * )e->e_private;
if ( mp->mp_info && mp->mp_info->mss_update ) {
return ( *mp->mp_info->mss_update )( mi, e );
}
return( 0 );
}
int
monitor_entry_create(
struct monitorinfo *mi,
const char *ndn,
Entry *e_parent,
Entry **ep
)
{
struct monitorentrypriv *mp;
assert( mi != NULL );
assert( e_parent != NULL );
assert( e_parent->e_private != NULL );
assert( ep != NULL );
mp = ( struct monitorentrypriv * )e_parent->e_private;
if ( mp->mp_info && mp->mp_info->mss_create ) {
return ( *mp->mp_info->mss_create )( mi, ndn, e_parent, ep );
}
return( 0 );
}
int
monitor_entry_test_flags(
struct monitorentrypriv *mp,
int cond
)
{
assert( mp != NULL );
return( ( mp->mp_flags & cond ) || ( mp->mp_info->mss_flags & cond ) );
}

View file

@ -0,0 +1,69 @@
/*
* Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
/*
* Copyright 2001 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*
* Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
*
* This work has beed deveolped for the OpenLDAP Foundation
* in the hope that it may be useful to the Open Source community,
* but WITHOUT ANY WARRANTY.
*
* Permission is granted to anyone to use this software for any purpose
* on any computer system, and to alter it and redistribute it, subject
* to the following restrictions:
*
* 1. The author and SysNet s.n.c. are not responsible for the consequences
* of use of this software, no matter how awful, even if they arise from
* flaws in it.
*
* 2. The origin of this software must not be misrepresented, either by
* explicit claim or by omission. Since few users ever read sources,
* credits should appear in the documentation.
*
* 3. Altered versions must be plainly marked as such, and must not be
* misrepresented as being the original software. Since few users
* ever read sources, credits should appear in the documentation.
* SysNet s.n.c. cannot be responsible for the consequences of the
* alterations.
*
* 4. This notice may not be removed or altered.
*/
#ifndef _MONITOR_EXTERNAL_H
#define _MONITOR_EXTERNAL_H
LDAP_BEGIN_DECL
extern int monitor_back_initialize LDAP_P(( BackendInfo *bi ));
extern int monitor_back_db_init LDAP_P(( BackendDB *be ));
extern int monitor_back_open LDAP_P(( BackendInfo *bi ));
extern int monitor_back_config LDAP_P(( BackendInfo *bi,
const char *fname, int lineno, int argc, char **argv ));
extern int monitor_back_db_config LDAP_P(( Backend *be,
const char *fname, int lineno, int argc, char **argv ));
extern int monitor_back_db_destroy LDAP_P(( BackendDB *be ));
extern int monitor_back_search LDAP_P(( BackendDB *bd,
Connection *conn, Operation *op,
const char *base, const char *nbase,
int scope, int deref, int sizelimit, int timelimit,
Filter *filter, const char *filterstr,
char **attrs, int attrsonly ));
extern int monitor_back_compare LDAP_P(( BackendDB *bd,
Connection *conn, Operation *op,
const char *dn, const char *ndn,
AttributeAssertion *ava ));
extern int monitor_back_abandon LDAP_P(( BackendDB *bd,
Connection *conn, Operation *op, ber_int_t msgid ));
LDAP_END_DECL
#endif /* _MONITOR_EXTERNAL_H */

View file

@ -0,0 +1,430 @@
/* init.c - initialize monitor backend */
/*
* Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
/*
* Copyright 2001 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*
* Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
*
* This work has beed deveolped for the OpenLDAP Foundation
* in the hope that it may be useful to the Open Source community,
* but WITHOUT ANY WARRANTY.
*
* Permission is granted to anyone to use this software for any purpose
* on any computer system, and to alter it and redistribute it, subject
* to the following restrictions:
*
* 1. The author and SysNet s.n.c. are not responsible for the consequences
* of use of this software, no matter how awful, even if they arise from
* flaws in it.
*
* 2. The origin of this software must not be misrepresented, either by
* explicit claim or by omission. Since few users ever read sources,
* credits should appear in the documentation.
*
* 3. Altered versions must be plainly marked as such, and must not be
* misrepresented as being the original software. Since few users
* ever read sources, credits should appear in the documentation.
* SysNet s.n.c. cannot be responsible for the consequences of the
* alterations.
*
* 4. This notice may not be removed or altered.
*/
#include "portable.h"
#include <stdio.h>
#include "slap.h"
#include "back-monitor.h"
/*
* database monitor can be defined once only
*/
static int monitor_defined = 0;
/*
* used by many functions to add description to entries
*/
AttributeDescription *monitor_ad_desc = NULL;
/*
* subsystem data
*/
struct monitorsubsys monitor_subsys[] = {
{
SLAPD_MONITOR_LISTENER, SLAPD_MONITOR_LISTENER_NAME,
NULL, NULL, NULL,
MONITOR_F_NONE,
NULL, /* init */
NULL, /* update */
NULL /* create */
}, {
SLAPD_MONITOR_DATABASE, SLAPD_MONITOR_DATABASE_NAME,
NULL, NULL, NULL,
MONITOR_F_PERSISTENT_CH,
monitor_subsys_database_init,
NULL, /* update */
NULL /* create */
}, {
SLAPD_MONITOR_BACKEND, SLAPD_MONITOR_BACKEND_NAME,
NULL, NULL, NULL,
MONITOR_F_PERSISTENT_CH,
monitor_subsys_backend_init,
NULL, /* update */
NULL /* create */
}, {
SLAPD_MONITOR_THREAD, SLAPD_MONITOR_THREAD_NAME,
NULL, NULL, NULL,
MONITOR_F_NONE,
NULL, /* init */
monitor_subsys_thread_update,
NULL /* create */
}, {
SLAPD_MONITOR_SASL, SLAPD_MONITOR_SASL_NAME,
NULL, NULL, NULL,
MONITOR_F_NONE,
NULL, /* init */
NULL, /* update */
NULL /* create */
}, {
SLAPD_MONITOR_TLS, SLAPD_MONITOR_TLS_NAME,
NULL, NULL, NULL,
MONITOR_F_NONE,
NULL, /* init */
NULL, /* update */
NULL /* create */
}, {
SLAPD_MONITOR_CONN, SLAPD_MONITOR_CONN_NAME,
NULL, NULL, NULL,
MONITOR_F_VOLATILE_CH,
monitor_subsys_conn_init,
monitor_subsys_conn_update,
monitor_subsys_conn_create
}, {
SLAPD_MONITOR_READW, SLAPD_MONITOR_READW_NAME,
NULL, NULL, NULL,
MONITOR_F_NONE,
NULL, /* init */
monitor_subsys_readw_update,
NULL /* create */
}, {
SLAPD_MONITOR_WRITEW, SLAPD_MONITOR_WRITEW_NAME,
NULL, NULL, NULL,
MONITOR_F_NONE,
NULL, /* init */
monitor_subsys_writew_update,
NULL /* create */
}, { -1, NULL }
};
int
monitor_back_initialize(
BackendInfo *bi
)
{
static char *controls[] = {
LDAP_CONTROL_MANAGEDSAIT,
NULL
};
bi->bi_controls = controls;
bi->bi_init = NULL;
bi->bi_open = monitor_back_open;
bi->bi_config = monitor_back_config;
bi->bi_close = NULL;
bi->bi_destroy = NULL;
bi->bi_db_init = monitor_back_db_init;
bi->bi_db_config = monitor_back_db_config;
bi->bi_db_open = NULL;
bi->bi_db_close = NULL;
bi->bi_db_destroy = monitor_back_db_destroy;
bi->bi_op_bind = NULL;
bi->bi_op_unbind = NULL;
bi->bi_op_search = monitor_back_search;
bi->bi_op_compare = monitor_back_compare;
bi->bi_op_modify = NULL;
bi->bi_op_modrdn = NULL;
bi->bi_op_add = NULL;
bi->bi_op_delete = NULL;
bi->bi_op_abandon = monitor_back_abandon;
bi->bi_extended = NULL;
bi->bi_entry_release_rw = NULL;
bi->bi_acl_group = NULL;
bi->bi_acl_attribute = NULL;
bi->bi_chk_referrals = NULL;
/*
* hooks for slap tools
*/
bi->bi_tool_entry_open = NULL;
bi->bi_tool_entry_close = NULL;
bi->bi_tool_entry_first = NULL;
bi->bi_tool_entry_next = NULL;
bi->bi_tool_entry_get = NULL;
bi->bi_tool_entry_put = NULL;
bi->bi_tool_entry_reindex = NULL;
bi->bi_tool_sync = NULL;
bi->bi_connection_init = 0;
bi->bi_connection_destroy = 0;
return 0;
}
int
monitor_back_db_init(
BackendDB *be
)
{
struct monitorinfo *mi;
Entry *e, *e_tmp;
struct monitorentrypriv *mp;
int i;
char buf[1024];
const char *text;
if ( monitor_defined ) {
#ifdef NEW_LOGGING
LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
"only one monitor backend is allowed\n" ));
#else
Debug( LDAP_DEBUG_ANY,
"only one monitor backend is allowed\n%s%s%s",
"", "", "" );
#endif
return( -1 );
}
monitor_defined++;
charray_add( &be->be_suffix, SLAPD_MONITOR_DN );
charray_add( &be->be_nsuffix, SLAPD_MONITOR_NDN );
mi = ( struct monitorinfo * )ch_calloc( sizeof( struct monitorinfo ), 1 );
ldap_pvt_thread_mutex_init( &mi->mi_cache_mutex );
if ( slap_str2ad( "description", &monitor_ad_desc, &text ) ) {
#ifdef NEW_LOGGING
LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
"monitor_back_db_init: %s\n", text ));
#else
Debug( LDAP_DEBUG_ANY,
"monitor_subsys_backend_init: %s\n%s%s",
text, "", "" );
#endif
return( -1 );
}
e_tmp = NULL;
for ( i = 0; monitor_subsys[ i ].mss_name != NULL; i++ ) {
int len = strlen( monitor_subsys[ i ].mss_name );
monitor_subsys[ i ].mss_rdn = ch_calloc( sizeof( char ),
4 + len );
strcpy( monitor_subsys[ i ].mss_rdn, "cn=" );
strcat( monitor_subsys[ i ].mss_rdn,
monitor_subsys[ i ].mss_name );
monitor_subsys[ i ].mss_dn = ch_calloc( sizeof( char ),
4 + len + sizeof( SLAPD_MONITOR_DN ) );
strcpy( monitor_subsys[ i ].mss_dn,
monitor_subsys[ i ].mss_rdn );
strcat( monitor_subsys[ i ].mss_dn, "," );
strcat( monitor_subsys[ i ].mss_dn, SLAPD_MONITOR_DN );
monitor_subsys[ i ].mss_ndn
= ch_strdup( monitor_subsys[ i ].mss_dn );
dn_normalize( monitor_subsys[ i ].mss_ndn );
snprintf( buf, sizeof( buf ),
"dn: %s\n"
"objectClass: top\n"
"objectClass: LDAPsubEntry\n"
#ifdef SLAPD_MONITORSUBENTRY
"objectClass: monitorSubEntry\n"
#else /* !SLAPD_MONITORSUBENTRY */
"objectClass: extensibleObject\n"
#endif /* !SLAPD_MONITORSUBENTRY */
"cn: %s\n",
monitor_subsys[ i ].mss_dn,
monitor_subsys[ i ].mss_name );
e = str2entry( buf );
if ( e == NULL) {
#ifdef NEW_LOGGING
LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
"unable to create '%s' entry\n",
monitor_subsys[ i ].mss_dn ));
#else
Debug( LDAP_DEBUG_ANY,
"unable to create '%s' entry\n%s%s",
monitor_subsys[ i ].mss_dn, "", "" );
#endif
return( -1 );
}
mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
e->e_private = ( void * )mp;
mp->mp_info = &monitor_subsys[ i ];
mp->mp_children = NULL;
mp->mp_next = e_tmp;
mp->mp_flags = monitor_subsys[ i ].mss_flags;
if ( monitor_cache_add( mi, e ) ) {
#ifdef NEW_LOGGING
LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
"unable to add entry '%s' to cache\n",
monitor_subsys[ i ].mss_dn ));
#else
Debug( LDAP_DEBUG_ANY,
"unable to add entry '%s' to cache\n%s%s",
monitor_subsys[ i ].mss_dn, "", "" );
#endif
return -1;
}
e_tmp = e;
}
/*
* creates the "cn=Monitor" entry
* and all the subsystem specific entries
*/
snprintf( buf, sizeof( buf ),
"dn: %s\n"
"objectClass: top\n"
"objectClass: LDAPsubEntry\n"
#ifdef SLAPD_MONITORSUBENTRY
"objectClass: monitorSubEntry\n"
#else /* !SLAPD_MONITORSUBENTRY */
"objectClass: extensibleObject\n"
#endif /* !SLAPD_MONITORSUBENTRY */
"cn: Monitor\n"
"description: %s",
SLAPD_MONITOR_DN,
(char *) Versionstr
);
e = str2entry( buf );
if ( e == NULL) {
#ifdef NEW_LOGGING
LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
"unable to create '%s' entry\n",
SLAPD_MONITOR_DN ));
#else
Debug( LDAP_DEBUG_ANY,
"unable to create '%s' entry\n%s%s",
SLAPD_MONITOR_DN, "", "" );
#endif
return( -1 );
}
mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
e->e_private = ( void * )mp;
mp->mp_info = NULL;
mp->mp_children = e_tmp;
mp->mp_next = NULL;
if ( monitor_cache_add( mi, e ) ) {
#ifdef NEW_LOGGING
LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
"unable to add entry '%s' to cache\n",
SLAPD_MONITOR_DN ));
#else
Debug( LDAP_DEBUG_ANY,
"unable to add entry '%s' to cache\n%s%s",
SLAPD_MONITOR_DN, "", "" );
#endif
return -1;
}
be->be_private = mi;
return 0;
}
int
monitor_back_open(
BackendInfo *bi
)
{
BackendDB *be;
struct monitorsubsys *ms;
/*
* adds the monitor backend
*/
be = select_backend( SLAPD_MONITOR_NDN, 0 );
if ( be == NULL ) {
#ifdef NEW_LOGGING
LDAP_LOG(( "operation", LDAP_LEVEL_CRIT,
"unable to get monitor backend\n" ));
#else
Debug( LDAP_DEBUG_ANY,
"unable to get monitor backend\n%s%s%s", "", "", "" );
#endif
return( -1 );
}
for ( ms = monitor_subsys; ms->mss_name != NULL; ms++ ) {
if ( ms->mss_init && ( *ms->mss_init )( be ) ) {
return( -1 );
}
}
return( 0 );
}
int
monitor_back_config(
BackendInfo *bi,
const char *fname,
int lineno,
int argc,
char **argv
)
{
/*
* eventually, will hold backend specific configuration parameters
*/
return 0;
}
int
monitor_back_db_config(
Backend *be,
const char *fname,
int lineno,
int argc,
char **argv
)
{
#ifdef NEW_LOGGING
LDAP_LOG(( "config", LDAP_DEBUG_NOTICE,
"line %d of file '%s' will be ignored\n", lineno, fname ));
#else
Debug( LDAP_DEBUG_CONFIG,
"line %d of file '%s' will be ignored\n%s", lineno, fname, "" );
#endif
return( 0 );
}
int
monitor_back_db_destroy(
BackendDB *be
)
{
/*
* FIXME: destroys all the data
*/
return 0;
}

View file

@ -0,0 +1,83 @@
/*
* Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
/*
* Copyright 2001 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*
* Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
*
* This work has beed deveolped for the OpenLDAP Foundation
* in the hope that it may be useful to the Open Source community,
* but WITHOUT ANY WARRANTY.
*
* Permission is granted to anyone to use this software for any purpose
* on any computer system, and to alter it and redistribute it, subject
* to the following restrictions:
*
* 1. The author and SysNet s.n.c. are not responsible for the consequences
* of use of this software, no matter how awful, even if they arise from
* flaws in it.
*
* 2. The origin of this software must not be misrepresented, either by
* explicit claim or by omission. Since few users ever read sources,
* credits should appear in the documentation.
*
* 3. Altered versions must be plainly marked as such, and must not be
* misrepresented as being the original software. Since few users
* ever read sources, credits should appear in the documentation.
* SysNet s.n.c. cannot be responsible for the consequences of the
* alterations.
*
* 4. This notice may not be removed or altered.
*/
#ifndef _PROTO_BACK_LDBM
#define _PROTO_BACK_LDBM
#include <ldap_cdefs.h>
#include "external.h"
LDAP_BEGIN_DECL
/*
* entry
*/
int monitor_entry_test_flags LDAP_P(( struct monitorentrypriv *mp, int cond ));
/*
* backends
*/
int monitor_subsys_backend_init LDAP_P(( BackendDB *be ));
/*
* databases
*/
int monitor_subsys_database_init LDAP_P(( BackendDB *be ));
/*
* threads
*/
int monitor_subsys_thread_update LDAP_P(( struct monitorinfo *mi, Entry *e ));
/*
* connections
*/
int monitor_subsys_conn_init LDAP_P(( BackendDB *be ));
int monitor_subsys_conn_update LDAP_P(( struct monitorinfo *mi, Entry *e ));
int monitor_subsys_conn_create LDAP_P(( struct monitorinfo *mi, const char *ndn, Entry *e_parent, Entry **ep ));
/*
* read waiters
*/
int monitor_subsys_readw_update LDAP_P(( struct monitorinfo *mi, Entry *e ));
/*
* write waiters
*/
int monitor_subsys_writew_update LDAP_P(( struct monitorinfo *mi, Entry *e ));
LDAP_END_DECL
#endif

View file

@ -0,0 +1,134 @@
/* readw.c - deal with read waiters subsystem */
/*
* Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
/*
* Copyright 2001 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*
* Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
*
* This work has beed deveolped for the OpenLDAP Foundation
* in the hope that it may be useful to the Open Source community,
* but WITHOUT ANY WARRANTY.
*
* Permission is granted to anyone to use this software for any purpose
* on any computer system, and to alter it and redistribute it, subject
* to the following restrictions:
*
* 1. The author and SysNet s.n.c. are not responsible for the consequences
* of use of this software, no matter how awful, even if they arise from
* flaws in it.
*
* 2. The origin of this software must not be misrepresented, either by
* explicit claim or by omission. Since few users ever read sources,
* credits should appear in the documentation.
*
* 3. Altered versions must be plainly marked as such, and must not be
* misrepresented as being the original software. Since few users
* ever read sources, credits should appear in the documentation.
* SysNet s.n.c. cannot be responsible for the consequences of the
* alterations.
*
* 4. This notice may not be removed or altered.
*/
#include "portable.h"
#include <stdio.h>
#include "slap.h"
#include "back-monitor.h"
static int monitor_subsys_readw_update_internal( struct monitorinfo *mi, Entry *e, int rw );
int
monitor_subsys_readw_update(
struct monitorinfo *mi,
Entry *e
)
{
return monitor_subsys_readw_update_internal( mi, e, 0 );
}
int
monitor_subsys_writew_update(
struct monitorinfo *mi,
Entry *e
)
{
return monitor_subsys_readw_update_internal( mi, e, 1 );
}
static int
monitor_subsys_readw_update_internal(
struct monitorinfo *mi,
Entry *e,
int rw
)
{
Connection *c;
int connindex;
int nconns, nwritewaiters, nreadwaiters;
Attribute *a;
struct berval *bv[2], val, **b = NULL;
char buf[1024];
char *str = NULL;
int num = 0;
bv[0] = &val;
bv[1] = NULL;
assert( mi != NULL );
assert( e != NULL );
bv[0] = &val;
bv[1] = NULL;
nconns = nwritewaiters = nreadwaiters = 0;
for ( c = connection_first( &connindex );
c != NULL;
c = connection_next( c, &connindex ), nconns++ ) {
if ( c->c_writewaiter ) {
nwritewaiters++;
}
if ( c->c_currentber != NULL ) {
nreadwaiters++;
}
}
connection_done(c);
switch ( rw ) {
case 0:
str = "read waiters";
num = nreadwaiters;
break;
case 1:
str = "write waiters";
num = nwritewaiters;
break;
}
snprintf( buf, sizeof( buf ), "%s=%d", str, num );
if ( ( a = attr_find( e->e_attrs, monitor_ad_desc ) ) != NULL ) {
for ( b = a->a_vals; b[0] != NULL; b++ ) {
if ( strncmp( b[0]->bv_val, str, strlen( str ) ) == 0 ) {
free( b[0]->bv_val );
b[0] = ber_bvstrdup( buf );
break;
}
}
}
if ( b == NULL || b[0] == NULL ) {
val.bv_val = buf;
val.bv_len = strlen( buf );
attr_merge( e, monitor_ad_desc, bv );
}
return( 0 );
}

View file

@ -0,0 +1,195 @@
/* search.c - monitor backend search function */
/*
* Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
/*
* Copyright 2001 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*
* Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
*
* This work has beed deveolped for the OpenLDAP Foundation
* in the hope that it may be useful to the Open Source community,
* but WITHOUT ANY WARRANTY.
*
* Permission is granted to anyone to use this software for any purpose
* on any computer system, and to alter it and redistribute it, subject
* to the following restrictions:
*
* 1. The author and SysNet s.n.c. are not responsible for the consequences
* of use of this software, no matter how awful, even if they arise from
* flaws in it.
*
* 2. The origin of this software must not be misrepresented, either by
* explicit claim or by omission. Since few users ever read sources,
* credits should appear in the documentation.
*
* 3. Altered versions must be plainly marked as such, and must not be
* misrepresented as being the original software. Since few users
* ever read sources, credits should appear in the documentation.
* SysNet s.n.c. cannot be responsible for the consequences of the
* alterations.
*
* 4. This notice may not be removed or altered.
*/
#include "portable.h"
#include <stdio.h>
#include <ac/string.h>
#include <ac/socket.h>
#include "slap.h"
#include "back-monitor.h"
#include "proto-back-monitor.h"
static int
monitor_send_children(
Backend *be,
Connection *conn,
Operation *op,
Filter *filter,
char **attrs,
int attrsonly,
Entry *e_parent,
int sub,
int *nentriesp
)
{
struct monitorinfo *mi = (struct monitorinfo *) be->be_private;
Entry *e, *e_tmp;
struct monitorentrypriv *mp;
int rc;
mp = ( struct monitorentrypriv * )e_parent->e_private;
e = mp->mp_children;
if ( e == NULL && MONITOR_HAS_VOLATILE_CH( mp ) ) {
monitor_entry_create( mi, NULL, e_parent, &e );
if ( e != NULL) {
monitor_cache_lock( e );
}
}
monitor_cache_release( mi, e_parent );
for ( ; e != NULL; ) {
mp = ( struct monitorentrypriv * )e->e_private;
monitor_entry_update( mi, e );
rc = test_filter( be, conn, op, e, filter );
if ( rc == LDAP_COMPARE_TRUE ) {
send_search_entry( be, conn, op, e,
attrs, attrsonly, NULL );
*nentriesp++;
}
if ( ( mp->mp_children || MONITOR_HAS_VOLATILE_CH( mp ) )
&& sub ) {
rc = monitor_send_children( be, conn, op, filter,
attrs, attrsonly,
e, sub, nentriesp );
if ( rc ) {
return( rc );
}
}
e_tmp = mp->mp_next;
if ( e_tmp != NULL ) {
monitor_cache_lock( e_tmp );
}
monitor_cache_release( mi, e );
e = e_tmp;
}
return( 0 );
}
int
monitor_back_search(
Backend *be,
Connection *conn,
Operation *op,
const char *base,
const char *nbase,
int scope,
int deref,
int slimit,
int tlimit,
Filter *filter,
const char *filterstr,
char **attrs,
int attrsonly
)
{
struct monitorinfo *mi = (struct monitorinfo *) be->be_private;
int rc;
Entry *e;
int nentries = 0;
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
"monitor_back_search: enter\n" ));
#else
Debug(LDAP_DEBUG_TRACE, "=> monitor_back_search\n%s%s%s", "", "", "");
#endif
/* get entry with reader lock */
monitor_cache_dn2entry( mi, nbase, &e );
if ( e == NULL ) {
send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT,
NULL, NULL, NULL, NULL );
return( 0 );
}
nentries = 0;
switch ( scope ) {
case LDAP_SCOPE_BASE:
monitor_entry_update( mi, e );
rc = test_filter( be, conn, op, e, filter );
if ( rc == LDAP_COMPARE_TRUE ) {
send_search_entry( be, conn, op, e, attrs,
attrsonly, NULL );
nentries = 1;
}
monitor_cache_release( mi, e );
break;
case LDAP_SCOPE_ONELEVEL:
rc = monitor_send_children( be, conn, op, filter,
attrs, attrsonly,
e, 0, &nentries );
if ( rc ) {
// error
}
break;
case LDAP_SCOPE_SUBTREE:
monitor_entry_update( mi, e );
rc = test_filter( be, conn, op, e, filter );
if ( rc == LDAP_COMPARE_TRUE ) {
send_search_entry( be, conn, op, e, attrs,
attrsonly, NULL );
nentries++;
}
rc = monitor_send_children( be, conn, op, filter,
attrs, attrsonly,
e, 1, &nentries );
if ( rc ) {
// error
}
break;
}
send_search_result( conn, op, LDAP_SUCCESS,
NULL, NULL, NULL, NULL, nentries );
return( 0 );
}

View file

@ -0,0 +1,81 @@
/* thread.c - deal with thread subsystem */
/*
* Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
/*
* Copyright 2001 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*
* Copyright 2001, Pierangelo Masarati, All rights reserved. <ando@sys-net.it>
*
* This work has beed deveolped for the OpenLDAP Foundation
* in the hope that it may be useful to the Open Source community,
* but WITHOUT ANY WARRANTY.
*
* Permission is granted to anyone to use this software for any purpose
* on any computer system, and to alter it and redistribute it, subject
* to the following restrictions:
*
* 1. The author and SysNet s.n.c. are not responsible for the consequences
* of use of this software, no matter how awful, even if they arise from
* flaws in it.
*
* 2. The origin of this software must not be misrepresented, either by
* explicit claim or by omission. Since few users ever read sources,
* credits should appear in the documentation.
*
* 3. Altered versions must be plainly marked as such, and must not be
* misrepresented as being the original software. Since few users
* ever read sources, credits should appear in the documentation.
* SysNet s.n.c. cannot be responsible for the consequences of the
* alterations.
*
* 4. This notice may not be removed or altered.
*/
#include "portable.h"
#include <stdio.h>
#include "slap.h"
#include "back-monitor.h"
int
monitor_subsys_thread_update(
struct monitorinfo *mi,
Entry *e
)
{
Attribute *a;
struct berval *bv[2], val, **b = NULL;
char buf[1024];
bv[0] = &val;
bv[1] = NULL;
snprintf( buf, sizeof( buf ), "threads=%d",
ldap_pvt_thread_pool_backload( &connection_pool ) );
if ( ( a = attr_find( e->e_attrs, monitor_ad_desc ) ) != NULL ) {
for ( b = a->a_vals; b[0] != NULL; b++ ) {
if ( strncmp( b[0]->bv_val, "threads=",
sizeof( "threads=" ) - 1 ) == 0 ) {
free( b[0]->bv_val );
b[0] = ber_bvstrdup( buf );
break;
}
}
}
if ( b == NULL || b[0] == NULL ) {
val.bv_val = buf;
val.bv_len = strlen( buf );
attr_merge( e, monitor_ad_desc, bv );
}
return( 0 );
}

View file

@ -33,6 +33,9 @@
#ifdef SLAPD_META
#include "back-meta/external.h"
#endif
#ifdef SLAPD_MONITOR
#include "back-monitor/external.h"
#endif
#ifdef SLAPD_PASSWD
#include "back-passwd/external.h"
#endif
@ -68,6 +71,9 @@ static BackendInfo binfo[] = {
#if defined(SLAPD_META) && !defined(SLAPD_META_DYNAMIC)
{"meta", meta_back_initialize},
#endif
#if defined(SLAPD_MONITOR) && !defined(SLAPD_MONITOR_DYNAMIC)
{"monitor", monitor_back_initialize},
#endif
#if defined(SLAPD_PASSWD) && !defined(SLAPD_PASSWD_DYNAMIC)
{"passwd", passwd_back_initialize},
#endif

View file

@ -765,6 +765,21 @@ read_config( const char *fname )
fname, lineno, 0 );
#endif
#if defined(SLAPD_MONITOR_DN)
/* "cn=Monitor" is reserved for monitoring slap */
} else if ( strcasecmp( cargv[1], SLAPD_MONITOR_DN ) == 0 ) {
#ifdef NEW_LOGGING
LDAP_LOG(( "config", LDAP_LEVEL_CRIT,
"%s: line %d: \"%s\" is reserved for monitoring slapd\n",
SLAPD_MONITOR_DN, fname, lineno ));
#else
Debug( LDAP_DEBUG_ANY,
"%s: line %d: \"%s\" is reserved for monitoring slapd\n",
SLAPD_MONITOR_DN, fname, lineno );
#endif
return( 1 );
#endif /* SLAPD_MONITOR_DN */
} else if ( ( tmp_be = select_backend( cargv[1], 0 ) ) == be ) {
#ifdef NEW_LOGGING
LDAP_LOG(( "config", LDAP_LEVEL_INFO,

View file

@ -1,266 +0,0 @@
/* $OpenLDAP$ */
/*
* Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
/*
* Copyright (c) 1995 Regents of the University of Michigan.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that this notice is preserved and that due credit is given
* to the University of Michigan at Ann Arbor. The name of the University
* may not be used to endorse or promote products derived from this
* software without specific prior written permission. This software
* is provided ``as is'' without express or implied warranty.
*/
#include "portable.h"
#include <stdio.h>
#include <ac/socket.h>
#include <ac/string.h>
#include <ac/time.h>
#include "slap.h"
#if defined( SLAPD_MONITOR_DN )
int
monitor_info(
Entry **entry,
const char **text )
{
Entry *e;
char buf[BUFSIZ];
struct berval val;
struct berval *vals[2];
int nconns, nwritewaiters, nreadwaiters;
struct tm *ltm;
char *p;
char buf2[22];
char buf3[22];
Connection *c;
int connindex;
time_t currenttime;
vals[0] = &val;
vals[1] = NULL;
e = (Entry *) ch_calloc( 1, sizeof(Entry) );
e->e_attrs = NULL;
e->e_dn = ch_strdup( SLAPD_MONITOR_DN );
e->e_ndn = ch_strdup(SLAPD_MONITOR_DN);
(void) dn_normalize( e->e_ndn );
e->e_private = NULL;
val.bv_val = "top";
val.bv_len = sizeof("top")-1;
attr_merge( e, "objectClass", vals );
val.bv_val = "LDAPsubentry";
val.bv_len = sizeof("LDAPsubentry")-1;
attr_merge( e, "objectClass", vals );
val.bv_val = "extensibleObject";
val.bv_len = sizeof("extensibleObject")-1;
attr_merge( e, "objectClass", vals );
{
char *rdn = ch_strdup( SLAPD_MONITOR_DN );
val.bv_val = strchr( rdn, '=' );
if( val.bv_val != NULL ) {
*val.bv_val = '\0';
val.bv_len = strlen( ++val.bv_val );
attr_merge( e, rdn, vals );
}
free( rdn );
}
val.bv_val = (char *) Versionstr;
if (( p = strchr( Versionstr, '\n' )) == NULL ) {
val.bv_len = strlen( Versionstr );
} else {
val.bv_len = p - Versionstr;
}
attr_merge( e, "version", vals );
sprintf( buf, "%d",
ldap_pvt_thread_pool_backload( &connection_pool) );
val.bv_val = buf;
val.bv_len = strlen( buf );
attr_merge( e, "threads", vals );
nconns = 0;
nwritewaiters = 0;
nreadwaiters = 0;
/* loop through the connections */
for ( c = connection_first( &connindex );
c != NULL;
c = connection_next( c, &connindex ))
{
nconns++;
if ( c->c_writewaiter ) {
nwritewaiters++;
}
if ( c->c_currentber != NULL ) {
nreadwaiters++;
}
ldap_pvt_thread_mutex_lock( &gmtime_mutex );
ltm = gmtime( &c->c_starttime );
strftime( buf2, sizeof(buf2), "%Y%m%d%H%M%SZ", ltm );
ltm = gmtime( &c->c_activitytime );
strftime( buf3, sizeof(buf2), "%Y%m%d%H%M%SZ", ltm );
ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
sprintf( buf,
"%ld : %ld "
": %ld/%ld/%ld/%ld "
": %ld/%ld/%ld "
": %s%s%s%s%s%s "
": %s : %s : %s "
": %s : %s : %s : %s ",
c->c_connid,
(long) c->c_protocol,
c->c_n_ops_received, c->c_n_ops_executing,
c->c_n_ops_pending, c->c_n_ops_completed,
/* add low-level counters here */
c->c_n_get, c->c_n_read, c->c_n_write,
c->c_currentber ? "r" : "",
c->c_writewaiter ? "w" : "",
c->c_ops != NULL ? "x" : "",
c->c_pending_ops != NULL ? "p" : "",
connection_state2str( c->c_conn_state ),
c->c_sasl_bind_in_progress ? "S" : "",
c->c_cdn ? c->c_cdn : SLAPD_ANONYMOUS,
c->c_listener_url,
c->c_peer_domain,
c->c_peer_name,
c->c_sock_name,
buf2,
buf3
);
val.bv_val = buf;
val.bv_len = strlen( buf );
attr_merge( e, "connection", vals );
}
connection_done(c);
sprintf( buf, "%d", nconns );
val.bv_val = buf;
val.bv_len = strlen( buf );
attr_merge( e, "currentConnections", vals );
sprintf( buf, "%ld", connections_nextid() );
val.bv_val = buf;
val.bv_len = strlen( buf );
attr_merge( e, "totalConnections", vals );
sprintf( buf, "%ld", (long) dtblsize );
val.bv_val = buf;
val.bv_len = strlen( buf );
attr_merge( e, "dTableSize", vals );
sprintf( buf, "%d", nwritewaiters );
val.bv_val = buf;
val.bv_len = strlen( buf );
attr_merge( e, "writeWaiters", vals );
sprintf( buf, "%d", nreadwaiters );
val.bv_val = buf;
val.bv_len = strlen( buf );
attr_merge( e, "readWaiters", vals );
ldap_pvt_thread_mutex_lock(&num_ops_mutex);
sprintf( buf, "%ld", num_ops_initiated );
ldap_pvt_thread_mutex_unlock(&num_ops_mutex);
val.bv_val = buf;
val.bv_len = strlen( buf );
attr_merge( e, "opsInitiated", vals );
ldap_pvt_thread_mutex_lock(&num_ops_mutex);
sprintf( buf, "%ld", num_ops_completed );
ldap_pvt_thread_mutex_unlock(&num_ops_mutex);
val.bv_val = buf;
val.bv_len = strlen( buf );
attr_merge( e, "opsCompleted", vals );
ldap_pvt_thread_mutex_lock(&num_sent_mutex);
sprintf( buf, "%ld", num_entries_sent );
ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
val.bv_val = buf;
val.bv_len = strlen( buf );
attr_merge( e, "entriesSent", vals );
ldap_pvt_thread_mutex_lock(&num_sent_mutex);
sprintf( buf, "%ld", num_refs_sent );
ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
val.bv_val = buf;
val.bv_len = strlen( buf );
attr_merge( e, "referencesSent", vals );
ldap_pvt_thread_mutex_lock(&num_sent_mutex);
sprintf( buf, "%ld", num_pdu_sent );
ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
val.bv_val = buf;
val.bv_len = strlen( buf );
attr_merge( e, "pduSent", vals );
ldap_pvt_thread_mutex_lock(&num_sent_mutex);
sprintf( buf, "%ld", num_bytes_sent );
ldap_pvt_thread_mutex_unlock(&num_sent_mutex);
val.bv_val = buf;
val.bv_len = strlen( buf );
attr_merge( e, "bytesSent", vals );
currenttime = slap_get_time();
ldap_pvt_thread_mutex_lock( &gmtime_mutex );
ltm = gmtime( &currenttime );
strftime( buf, sizeof(buf), "%Y%m%d%H%M%SZ", ltm );
val.bv_val = buf;
val.bv_len = strlen( buf );
attr_merge( e, "currenttime", vals );
ltm = gmtime( &starttime );
strftime( buf, sizeof(buf), "%Y%m%d%H%M%SZ", ltm );
ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
val.bv_val = buf;
val.bv_len = strlen( buf );
attr_merge( e, "starttime", vals );
sprintf( buf, "%d", nbackends );
val.bv_val = buf;
val.bv_len = strlen( buf );
attr_merge( e, "nbackends", vals );
#ifdef HAVE_THREAD_CONCURRENCY
sprintf( buf, "%d", ldap_pvt_thread_get_concurrency() );
val.bv_val = buf;
val.bv_len = strlen( buf );
attr_merge( e, "concurrency", vals );
#endif
*entry = e;
return LDAP_SUCCESS;
}
#endif /* slapd_monitor_dn */

View file

@ -450,13 +450,10 @@ LDAP_SLAPD_F (void) *module_resolve LDAP_P((
#endif /* SLAPD_MODULES */
/*
* monitor.c
* controls.c
*/
LDAP_SLAPD_F (char *) supportedControls[];
LDAP_SLAPD_F (int) monitor_info LDAP_P((
Entry **entry, const char **text ));
/*
* mra.c
*/

View file

@ -676,3 +676,22 @@ objectclass ( 1.3.6.1.4.1.4203.666.3.1 NAME 'authPasswordObject'
DESC 'OpenLDAP authPassword mixin class'
MAY authPassword
AUXILIARY )
#
# Author: Ando <ando@OpenLDAP.org>
# Subject: Monitor schema items
# Date: 2001/07/09
# Status: Work in Progress
#
#
# monitorSubEntry
#
# Notes: in 'cn' (inherited from 'LDAPsubEntry') it holds the name
# of the subsystem it is monitoring
#
#objectclass ( 1.3.6.1.4.1.4203.666.X.Y.Z
# NAME 'monitorSubEntry'
# DESC 'OpenLDAP ancestor class for system monitoring'
# SUP LDAPsubEntry STRUCTURAL )

View file

@ -213,34 +213,6 @@ do_search(
rc = root_dse_info( conn, &entry, &text );
}
#if defined( SLAPD_MONITOR_DN )
else if ( strcasecmp( nbase, SLAPD_MONITOR_DN ) == 0 ) {
/* check restrictions */
rc = backend_check_restrictions( NULL, conn, op, NULL, &text ) ;
if( rc != LDAP_SUCCESS ) {
send_ldap_result( conn, op, rc,
NULL, text, NULL, NULL );
goto return_results;
}
rc = monitor_info( &entry, &text );
}
#endif
#if defined( SLAPD_CONFIG_DN )
else if ( strcasecmp( nbase, SLAPD_CONFIG_DN ) == 0 ) {
/* check restrictions */
rc = backend_check_restrictions( NULL, conn, op, NULL, &text ) ;
if( rc != LDAP_SUCCESS ) {
send_ldap_result( conn, op, rc,
NULL, text, NULL, NULL );
goto return_results;
}
rc = config_info( &entry, &text );
}
#endif
#if defined( SLAPD_SCHEMA_DN )
else if ( strcasecmp( nbase, SLAPD_SCHEMA_DN ) == 0 ) {
/* check restrictions */

View file

@ -17,6 +17,9 @@
time_t starttime;
#endif
/* because Versionstr is used in back-monitor */
const char Versionstr[] = "";
/* bogus ../results.c */
int str2result(
char* s,
@ -163,6 +166,26 @@ void connection2anonymous( Connection *c )
assert(0);
}
Connection * connection_first( ber_socket_t *b )
{
assert(0);
}
Connection * connection_next( Connection *c, ber_socket_t *b )
{
assert(0);
}
void connection_done( Connection *c )
{
assert(0);
}
const char * connection_state2str( int state )
{
assert(0);
}
void replog( Backend *be, Operation *op, char *dn, void *change)
{
assert(0);