2001-07-15 01:34:24 +08:00
|
|
|
/* conn.c - deal with connection subsystem */
|
2003-11-27 10:35:20 +08:00
|
|
|
/* $OpenLDAP$ */
|
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2006-01-04 07:11:52 +08:00
|
|
|
* Copyright 2001-2006 The OpenLDAP Foundation.
|
2003-12-09 01:41:40 +08:00
|
|
|
* Portions Copyright 2001-2003 Pierangelo Masarati.
|
2003-11-27 10:35:20 +08:00
|
|
|
* 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.
|
|
|
|
*/
|
2001-07-15 01:34:24 +08:00
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2003-05-15 05:36:34 +08:00
|
|
|
#include <ac/string.h>
|
2001-07-15 01:34:24 +08:00
|
|
|
|
|
|
|
#include "slap.h"
|
2003-03-11 20:26:05 +08:00
|
|
|
#include "lutil.h"
|
2001-07-15 01:34:24 +08:00
|
|
|
#include "back-monitor.h"
|
|
|
|
|
2005-04-28 02:33:22 +08:00
|
|
|
#ifndef LDAP_DEVEL
|
|
|
|
#define MONITOR_LEGACY_CONN
|
|
|
|
#endif
|
|
|
|
|
2005-08-09 04:45:10 +08:00
|
|
|
static int
|
|
|
|
monitor_subsys_conn_update(
|
|
|
|
Operation *op,
|
|
|
|
SlapReply *rs,
|
|
|
|
Entry *e );
|
|
|
|
|
|
|
|
static int
|
|
|
|
monitor_subsys_conn_create(
|
|
|
|
Operation *op,
|
|
|
|
SlapReply *rs,
|
|
|
|
struct berval *ndn,
|
|
|
|
Entry *e_parent,
|
|
|
|
Entry **ep );
|
|
|
|
|
2001-07-15 01:34:24 +08:00
|
|
|
int
|
|
|
|
monitor_subsys_conn_init(
|
2004-11-08 18:10:15 +08:00
|
|
|
BackendDB *be,
|
2005-07-18 06:18:45 +08:00
|
|
|
monitor_subsys_t *ms )
|
2001-07-15 01:34:24 +08:00
|
|
|
{
|
2004-11-09 02:52:27 +08:00
|
|
|
monitor_info_t *mi;
|
|
|
|
Entry *e, **ep, *e_conn;
|
|
|
|
monitor_entry_t *mp;
|
|
|
|
char buf[ BACKMONITOR_BUFSIZE ];
|
|
|
|
struct berval bv;
|
2001-07-15 01:34:24 +08:00
|
|
|
|
|
|
|
assert( be != NULL );
|
|
|
|
|
2005-08-09 04:45:10 +08:00
|
|
|
ms->mss_update = monitor_subsys_conn_update;
|
|
|
|
ms->mss_create = monitor_subsys_conn_create;
|
|
|
|
|
2004-11-09 02:52:27 +08:00
|
|
|
mi = ( monitor_info_t * )be->be_private;
|
2001-07-15 01:34:24 +08:00
|
|
|
|
2004-11-08 18:10:15 +08:00
|
|
|
if ( monitor_cache_get( mi, &ms->mss_ndn, &e_conn ) ) {
|
2001-07-15 01:34:24 +08:00
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
"monitor_subsys_conn_init: "
|
2004-09-13 06:12:58 +08:00
|
|
|
"unable to get entry \"%s\"\n",
|
2004-11-08 18:10:15 +08:00
|
|
|
ms->mss_ndn.bv_val, 0, 0 );
|
2001-07-15 01:34:24 +08:00
|
|
|
return( -1 );
|
|
|
|
}
|
|
|
|
|
2004-11-09 02:52:27 +08:00
|
|
|
mp = ( monitor_entry_t * )e_conn->e_private;
|
2004-09-13 06:12:58 +08:00
|
|
|
mp->mp_children = NULL;
|
|
|
|
ep = &mp->mp_children;
|
2001-12-23 03:14:10 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Total conns
|
|
|
|
*/
|
|
|
|
snprintf( buf, sizeof( buf ),
|
|
|
|
"dn: cn=Total,%s\n"
|
2003-04-13 01:41:49 +08:00
|
|
|
"objectClass: %s\n"
|
|
|
|
"structuralObjectClass: %s\n"
|
2003-05-15 09:19:30 +08:00
|
|
|
"cn: Total\n"
|
2004-07-20 05:42:11 +08:00
|
|
|
"creatorsName: %s\n"
|
|
|
|
"modifiersName: %s\n"
|
2003-05-15 09:19:30 +08:00
|
|
|
"createTimestamp: %s\n"
|
|
|
|
"modifyTimestamp: %s\n",
|
2004-11-08 18:10:15 +08:00
|
|
|
ms->mss_dn.bv_val,
|
2003-05-18 01:19:16 +08:00
|
|
|
mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
|
|
|
|
mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
|
2004-07-20 05:42:11 +08:00
|
|
|
mi->mi_creatorsName.bv_val,
|
|
|
|
mi->mi_creatorsName.bv_val,
|
2003-05-15 09:19:30 +08:00
|
|
|
mi->mi_startTime.bv_val,
|
|
|
|
mi->mi_startTime.bv_val );
|
2001-12-23 03:14:10 +08:00
|
|
|
|
|
|
|
e = str2entry( buf );
|
|
|
|
if ( e == NULL ) {
|
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
"monitor_subsys_conn_init: "
|
2004-09-13 06:12:58 +08:00
|
|
|
"unable to create entry \"cn=Total,%s\"\n",
|
2004-11-08 18:10:15 +08:00
|
|
|
ms->mss_ndn.bv_val, 0, 0 );
|
2001-12-23 03:14:10 +08:00
|
|
|
return( -1 );
|
|
|
|
}
|
|
|
|
|
2004-09-13 06:12:58 +08:00
|
|
|
BER_BVSTR( &bv, "0" );
|
2005-04-22 05:05:38 +08:00
|
|
|
attr_merge_one( e, mi->mi_ad_monitorCounter, &bv, &bv );
|
2001-12-23 03:14:10 +08:00
|
|
|
|
2004-11-08 18:55:33 +08:00
|
|
|
mp = monitor_entrypriv_create();
|
|
|
|
if ( mp == NULL ) {
|
|
|
|
return -1;
|
|
|
|
}
|
2001-12-23 03:14:10 +08:00
|
|
|
e->e_private = ( void * )mp;
|
2004-11-08 18:10:15 +08:00
|
|
|
mp->mp_info = ms;
|
|
|
|
mp->mp_flags = ms->mss_flags \
|
2001-12-23 03:14:10 +08:00
|
|
|
| MONITOR_F_SUB | MONITOR_F_PERSISTENT;
|
|
|
|
mp->mp_flags &= ~MONITOR_F_VOLATILE_CH;
|
|
|
|
|
|
|
|
if ( monitor_cache_add( mi, e ) ) {
|
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
"monitor_subsys_conn_init: "
|
2004-09-13 06:12:58 +08:00
|
|
|
"unable to add entry \"cn=Total,%s\"\n",
|
2004-11-08 18:10:15 +08:00
|
|
|
ms->mss_ndn.bv_val, 0, 0 );
|
2001-12-23 03:14:10 +08:00
|
|
|
return( -1 );
|
|
|
|
}
|
|
|
|
|
2004-09-13 06:12:58 +08:00
|
|
|
*ep = e;
|
|
|
|
ep = &mp->mp_next;
|
|
|
|
|
2001-12-23 03:14:10 +08:00
|
|
|
/*
|
|
|
|
* Current conns
|
|
|
|
*/
|
|
|
|
snprintf( buf, sizeof( buf ),
|
|
|
|
"dn: cn=Current,%s\n"
|
2003-04-13 01:41:49 +08:00
|
|
|
"objectClass: %s\n"
|
|
|
|
"structuralObjectClass: %s\n"
|
2003-05-15 09:19:30 +08:00
|
|
|
"cn: Current\n"
|
2004-07-20 05:42:11 +08:00
|
|
|
"creatorsName: %s\n"
|
|
|
|
"modifiersName: %s\n"
|
2003-05-15 09:19:30 +08:00
|
|
|
"createTimestamp: %s\n"
|
|
|
|
"modifyTimestamp: %s\n",
|
2004-11-08 18:10:15 +08:00
|
|
|
ms->mss_dn.bv_val,
|
2003-05-18 01:19:16 +08:00
|
|
|
mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
|
|
|
|
mi->mi_oc_monitorCounterObject->soc_cname.bv_val,
|
2004-07-20 05:42:11 +08:00
|
|
|
mi->mi_creatorsName.bv_val,
|
|
|
|
mi->mi_creatorsName.bv_val,
|
2003-05-15 09:19:30 +08:00
|
|
|
mi->mi_startTime.bv_val,
|
|
|
|
mi->mi_startTime.bv_val );
|
2001-12-23 03:14:10 +08:00
|
|
|
|
|
|
|
e = str2entry( buf );
|
|
|
|
if ( e == NULL ) {
|
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
"monitor_subsys_conn_init: "
|
2004-09-13 06:12:58 +08:00
|
|
|
"unable to create entry \"cn=Current,%s\"\n",
|
2004-11-08 18:10:15 +08:00
|
|
|
ms->mss_ndn.bv_val, 0, 0 );
|
2001-12-23 03:14:10 +08:00
|
|
|
return( -1 );
|
|
|
|
}
|
|
|
|
|
2004-09-13 06:12:58 +08:00
|
|
|
BER_BVSTR( &bv, "0" );
|
2005-04-22 05:05:38 +08:00
|
|
|
attr_merge_one( e, mi->mi_ad_monitorCounter, &bv, &bv );
|
2002-04-03 23:42:54 +08:00
|
|
|
|
2004-11-08 18:55:33 +08:00
|
|
|
mp = monitor_entrypriv_create();
|
|
|
|
if ( mp == NULL ) {
|
|
|
|
return -1;
|
|
|
|
}
|
2001-12-23 03:14:10 +08:00
|
|
|
e->e_private = ( void * )mp;
|
2004-11-08 18:10:15 +08:00
|
|
|
mp->mp_info = ms;
|
|
|
|
mp->mp_flags = ms->mss_flags \
|
2001-12-23 03:14:10 +08:00
|
|
|
| MONITOR_F_SUB | MONITOR_F_PERSISTENT;
|
|
|
|
mp->mp_flags &= ~MONITOR_F_VOLATILE_CH;
|
|
|
|
|
|
|
|
if ( monitor_cache_add( mi, e ) ) {
|
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
"monitor_subsys_conn_init: "
|
2004-09-13 06:12:58 +08:00
|
|
|
"unable to add entry \"cn=Current,%s\"\n",
|
2004-11-08 18:10:15 +08:00
|
|
|
ms->mss_ndn.bv_val, 0, 0 );
|
2001-12-23 03:14:10 +08:00
|
|
|
return( -1 );
|
|
|
|
}
|
|
|
|
|
2004-09-13 06:12:58 +08:00
|
|
|
*ep = e;
|
|
|
|
ep = &mp->mp_next;
|
2001-07-15 01:34:24 +08:00
|
|
|
|
2001-12-23 03:14:10 +08:00
|
|
|
monitor_cache_release( mi, e_conn );
|
2001-07-15 01:34:24 +08:00
|
|
|
|
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
|
2005-08-09 04:45:10 +08:00
|
|
|
static int
|
2001-07-15 01:34:24 +08:00
|
|
|
monitor_subsys_conn_update(
|
2003-04-12 07:08:16 +08:00
|
|
|
Operation *op,
|
2005-04-28 05:30:35 +08:00
|
|
|
SlapReply *rs,
|
2005-07-18 06:18:45 +08:00
|
|
|
Entry *e )
|
2001-07-15 01:34:24 +08:00
|
|
|
{
|
2004-11-09 02:52:27 +08:00
|
|
|
monitor_info_t *mi = ( monitor_info_t * )op->o_bd->be_private;
|
2004-09-13 06:12:58 +08:00
|
|
|
|
|
|
|
long n = -1;
|
|
|
|
static struct berval total_bv = BER_BVC( "cn=total" ),
|
|
|
|
current_bv = BER_BVC( "cn=current" );
|
|
|
|
struct berval rdn;
|
2001-07-15 01:34:24 +08:00
|
|
|
|
2005-07-18 14:22:33 +08:00
|
|
|
assert( mi != NULL );
|
|
|
|
assert( e != NULL );
|
2004-09-13 06:12:58 +08:00
|
|
|
|
|
|
|
dnRdn( &e->e_nname, &rdn );
|
2001-07-15 01:34:24 +08:00
|
|
|
|
2004-09-13 06:12:58 +08:00
|
|
|
if ( dn_match( &rdn, &total_bv ) ) {
|
2001-12-23 03:14:10 +08:00
|
|
|
n = connections_nextid();
|
|
|
|
|
2004-09-13 06:12:58 +08:00
|
|
|
} else if ( dn_match( &rdn, ¤t_bv ) ) {
|
2001-12-23 03:14:10 +08:00
|
|
|
Connection *c;
|
|
|
|
int connindex;
|
|
|
|
|
|
|
|
for ( n = 0, c = connection_first( &connindex );
|
|
|
|
c != NULL;
|
|
|
|
n++, c = connection_next( c, &connindex ) ) {
|
|
|
|
/* No Op */ ;
|
2001-07-15 01:34:24 +08:00
|
|
|
}
|
2004-09-13 06:12:58 +08:00
|
|
|
connection_done( c );
|
2001-07-15 01:34:24 +08:00
|
|
|
}
|
2001-12-23 03:14:10 +08:00
|
|
|
|
|
|
|
if ( n != -1 ) {
|
|
|
|
Attribute *a;
|
2003-04-19 01:17:18 +08:00
|
|
|
char buf[] = "+9223372036854775807L";
|
2004-09-13 06:12:58 +08:00
|
|
|
ber_len_t len;
|
2001-12-23 03:14:10 +08:00
|
|
|
|
2003-05-18 01:19:16 +08:00
|
|
|
a = attr_find( e->e_attrs, mi->mi_ad_monitorCounter );
|
2001-12-23 03:14:10 +08:00
|
|
|
if ( a == NULL ) {
|
|
|
|
return( -1 );
|
2001-07-15 01:34:24 +08:00
|
|
|
}
|
2001-12-23 03:14:10 +08:00
|
|
|
|
|
|
|
snprintf( buf, sizeof( buf ), "%ld", n );
|
2004-09-13 06:12:58 +08:00
|
|
|
len = strlen( buf );
|
|
|
|
if ( len > a->a_vals[ 0 ].bv_len ) {
|
|
|
|
a->a_vals[ 0 ].bv_val = ber_memrealloc( a->a_vals[ 0 ].bv_val, len + 1 );
|
|
|
|
}
|
|
|
|
a->a_vals[ 0 ].bv_len = len;
|
|
|
|
AC_MEMCPY( a->a_vals[ 0 ].bv_val, buf, len + 1 );
|
2005-01-18 17:48:53 +08:00
|
|
|
|
|
|
|
/* FIXME: touch modifyTimestamp? */
|
2001-07-15 01:34:24 +08:00
|
|
|
}
|
|
|
|
|
2005-04-28 05:30:35 +08:00
|
|
|
return SLAP_CB_CONTINUE;
|
2001-07-15 01:34:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
conn_create(
|
2004-11-09 02:52:27 +08:00
|
|
|
monitor_info_t *mi,
|
2001-07-15 01:34:24 +08:00
|
|
|
Connection *c,
|
2004-11-08 18:10:15 +08:00
|
|
|
Entry **ep,
|
2005-07-18 06:18:45 +08:00
|
|
|
monitor_subsys_t *ms )
|
2001-07-15 01:34:24 +08:00
|
|
|
{
|
2004-11-09 02:52:27 +08:00
|
|
|
monitor_entry_t *mp;
|
2005-04-28 05:30:35 +08:00
|
|
|
struct tm *ltm;
|
|
|
|
char buf[ BACKMONITOR_BUFSIZE ];
|
|
|
|
char buf2[ LDAP_LUTIL_GENTIME_BUFSIZE ];
|
|
|
|
char buf3[ LDAP_LUTIL_GENTIME_BUFSIZE ];
|
2001-07-15 01:34:24 +08:00
|
|
|
|
2005-04-28 05:30:35 +08:00
|
|
|
Entry *e;
|
2001-07-15 01:34:24 +08:00
|
|
|
|
2003-05-15 09:19:30 +08:00
|
|
|
struct tm *ctm;
|
|
|
|
char ctmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
|
|
|
|
struct tm *mtm;
|
|
|
|
char mtmbuf[ LDAP_LUTIL_GENTIME_BUFSIZE ];
|
2003-12-06 13:50:47 +08:00
|
|
|
#ifdef HAVE_GMTIME_R
|
|
|
|
struct tm tm_buf;
|
|
|
|
#endif /* HAVE_GMTIME_R */
|
2003-05-15 09:19:30 +08:00
|
|
|
|
2001-07-15 01:34:24 +08:00
|
|
|
assert( c != NULL );
|
|
|
|
assert( ep != NULL );
|
|
|
|
|
2003-12-06 13:50:47 +08:00
|
|
|
#ifndef HAVE_GMTIME_R
|
2004-10-06 13:51:38 +08:00
|
|
|
ldap_pvt_thread_mutex_lock( &gmtime_mutex );
|
2003-12-06 13:50:47 +08:00
|
|
|
#endif
|
2003-05-15 09:19:30 +08:00
|
|
|
#ifdef HACK_LOCAL_TIME
|
2003-12-06 13:50:47 +08:00
|
|
|
# ifdef HAVE_LOCALTIME_R
|
|
|
|
ctm = localtime_r( &c->c_starttime, &tm_buf );
|
|
|
|
lutil_localtime( ctmbuf, sizeof( ctmbuf ), ctm, -timezone );
|
|
|
|
mtm = localtime_r( &c->c_activitytime, &tm_buf );
|
|
|
|
lutil_localtime( mtmbuf, sizeof( mtmbuf ), mtm, -timezone );
|
|
|
|
# else
|
2003-05-15 09:19:30 +08:00
|
|
|
ctm = localtime( &c->c_starttime );
|
|
|
|
lutil_localtime( ctmbuf, sizeof( ctmbuf ), ctm, -timezone );
|
|
|
|
mtm = localtime( &c->c_activitytime );
|
|
|
|
lutil_localtime( mtmbuf, sizeof( mtmbuf ), mtm, -timezone );
|
2003-12-06 13:50:47 +08:00
|
|
|
# endif /* HAVE_LOCALTIME_R */
|
2003-05-15 09:19:30 +08:00
|
|
|
#else /* !HACK_LOCAL_TIME */
|
2003-12-06 13:50:47 +08:00
|
|
|
# ifdef HAVE_GMTIME_R
|
|
|
|
ctm = gmtime_r( &c->c_starttime, &tm_buf );
|
|
|
|
lutil_gentime( ctmbuf, sizeof( ctmbuf ), ctm );
|
|
|
|
mtm = gmtime_r( &c->c_activitytime, &tm_buf );
|
|
|
|
lutil_gentime( mtmbuf, sizeof( mtmbuf ), mtm );
|
|
|
|
# else
|
2003-05-15 09:19:30 +08:00
|
|
|
ctm = gmtime( &c->c_starttime );
|
|
|
|
lutil_gentime( ctmbuf, sizeof( ctmbuf ), ctm );
|
|
|
|
mtm = gmtime( &c->c_activitytime );
|
|
|
|
lutil_gentime( mtmbuf, sizeof( mtmbuf ), mtm );
|
2003-12-06 13:50:47 +08:00
|
|
|
# endif /* HAVE_GMTIME_R */
|
2003-05-15 09:19:30 +08:00
|
|
|
#endif /* !HACK_LOCAL_TIME */
|
2003-12-06 13:50:47 +08:00
|
|
|
#ifndef HAVE_GMTIME_R
|
2004-10-06 13:51:38 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
|
2003-12-06 13:50:47 +08:00
|
|
|
#endif
|
2003-05-15 09:19:30 +08:00
|
|
|
|
2005-04-28 01:51:54 +08:00
|
|
|
#ifndef HAVE_GMTIME_R
|
|
|
|
ldap_pvt_thread_mutex_lock( &gmtime_mutex );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_GMTIME_R
|
|
|
|
ltm = gmtime_r( &c->c_starttime, &tm_buf );
|
|
|
|
#else
|
|
|
|
ltm = gmtime( &c->c_starttime );
|
|
|
|
#endif
|
|
|
|
lutil_gentime( buf2, sizeof( buf2 ), ltm );
|
|
|
|
|
|
|
|
#ifdef HAVE_GMTIME_R
|
|
|
|
ltm = gmtime_r( &c->c_activitytime, &tm_buf );
|
|
|
|
#else
|
|
|
|
ltm = gmtime( &c->c_activitytime );
|
|
|
|
#endif
|
|
|
|
lutil_gentime( buf3, sizeof( buf3 ), ltm );
|
|
|
|
|
|
|
|
#ifndef HAVE_GMTIME_R
|
|
|
|
ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
|
|
|
|
#endif /* HAVE_GMTIME_R */
|
|
|
|
|
2001-07-15 01:34:24 +08:00
|
|
|
snprintf( buf, sizeof( buf ),
|
2004-09-13 06:12:58 +08:00
|
|
|
"dn: cn=Connection %ld,%s\n"
|
2003-04-13 01:41:49 +08:00
|
|
|
"objectClass: %s\n"
|
|
|
|
"structuralObjectClass: %s\n"
|
2004-09-13 06:12:58 +08:00
|
|
|
"cn: Connection %ld\n"
|
2005-04-28 02:33:22 +08:00
|
|
|
|
|
|
|
#ifdef MONITOR_LEGACY_CONN
|
2005-04-28 01:51:54 +08:00
|
|
|
/* NOTE: this will disappear, as the exploded data
|
|
|
|
* has been moved to dedicated attributes */
|
|
|
|
"%s: "
|
|
|
|
"%ld "
|
|
|
|
": %ld "
|
|
|
|
": %ld/%ld/%ld/%ld "
|
|
|
|
": %ld/%ld/%ld "
|
|
|
|
": %s%s%s%s%s%s "
|
|
|
|
": %s "
|
|
|
|
": %s "
|
|
|
|
": %s "
|
|
|
|
": %s "
|
|
|
|
": %s "
|
|
|
|
": %s "
|
|
|
|
": %s\n"
|
2005-04-28 02:33:22 +08:00
|
|
|
#endif /* MONITOR_LEGACY_CONN */
|
2005-04-28 01:51:54 +08:00
|
|
|
|
|
|
|
"%s: %lu\n"
|
|
|
|
"%s: %ld\n"
|
|
|
|
|
|
|
|
"%s: %ld\n"
|
|
|
|
"%s: %ld\n"
|
|
|
|
"%s: %ld\n"
|
|
|
|
"%s: %ld\n"
|
|
|
|
|
|
|
|
"%s: %ld\n"
|
|
|
|
"%s: %ld\n"
|
|
|
|
"%s: %ld\n"
|
|
|
|
|
|
|
|
"%s: %s%s%s%s%s%s\n"
|
|
|
|
|
|
|
|
"%s: %s\n"
|
|
|
|
|
|
|
|
"%s: %s\n"
|
|
|
|
"%s: %s\n"
|
|
|
|
"%s: %s\n"
|
|
|
|
"%s: %s\n"
|
|
|
|
|
|
|
|
"%s: %s\n"
|
|
|
|
"%s: %s\n"
|
|
|
|
|
2004-07-20 05:42:11 +08:00
|
|
|
"creatorsName: %s\n"
|
|
|
|
"modifiersName: %s\n"
|
2003-05-15 09:19:30 +08:00
|
|
|
"createTimestamp: %s\n"
|
|
|
|
"modifyTimestamp: %s\n",
|
2004-11-08 18:10:15 +08:00
|
|
|
c->c_connid, ms->mss_dn.bv_val,
|
2003-05-18 01:19:16 +08:00
|
|
|
mi->mi_oc_monitorConnection->soc_cname.bv_val,
|
|
|
|
mi->mi_oc_monitorConnection->soc_cname.bv_val,
|
2003-05-15 09:19:30 +08:00
|
|
|
c->c_connid,
|
2005-04-28 01:51:54 +08:00
|
|
|
|
2005-04-28 02:33:22 +08:00
|
|
|
#ifdef MONITOR_LEGACY_CONN
|
2005-04-28 01:51:54 +08:00
|
|
|
mi->mi_ad_monitoredInfo->ad_cname.bv_val,
|
|
|
|
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" : "",
|
|
|
|
LDAP_STAILQ_EMPTY( &c->c_ops ) ? "" : "x",
|
|
|
|
LDAP_STAILQ_EMPTY( &c->c_pending_ops ) ? "" : "p",
|
|
|
|
connection_state2str( c->c_conn_state ),
|
|
|
|
c->c_sasl_bind_in_progress ? "S" : "",
|
|
|
|
|
|
|
|
c->c_dn.bv_len ? c->c_dn.bv_val : SLAPD_ANONYMOUS,
|
|
|
|
|
|
|
|
c->c_listener_url.bv_val,
|
|
|
|
c->c_peer_domain.bv_val,
|
|
|
|
c->c_peer_name.bv_val,
|
|
|
|
c->c_sock_name.bv_val,
|
|
|
|
|
|
|
|
buf2,
|
|
|
|
buf3,
|
2005-04-28 02:33:22 +08:00
|
|
|
#endif /* MONITOR_LEGACY_CONN */
|
2005-04-28 01:51:54 +08:00
|
|
|
|
|
|
|
mi->mi_ad_monitorConnectionNumber->ad_cname.bv_val,
|
|
|
|
c->c_connid,
|
|
|
|
mi->mi_ad_monitorConnectionProtocol->ad_cname.bv_val,
|
|
|
|
(long)c->c_protocol,
|
|
|
|
|
|
|
|
mi->mi_ad_monitorConnectionOpsReceived->ad_cname.bv_val,
|
|
|
|
c->c_n_ops_received,
|
|
|
|
mi->mi_ad_monitorConnectionOpsExecuting->ad_cname.bv_val,
|
|
|
|
c->c_n_ops_executing,
|
|
|
|
mi->mi_ad_monitorConnectionOpsPending->ad_cname.bv_val,
|
|
|
|
c->c_n_ops_pending,
|
|
|
|
mi->mi_ad_monitorConnectionOpsCompleted->ad_cname.bv_val,
|
|
|
|
c->c_n_ops_completed,
|
|
|
|
|
|
|
|
mi->mi_ad_monitorConnectionGet->ad_cname.bv_val,
|
|
|
|
c->c_n_get,
|
|
|
|
mi->mi_ad_monitorConnectionRead->ad_cname.bv_val,
|
|
|
|
c->c_n_read,
|
|
|
|
mi->mi_ad_monitorConnectionWrite->ad_cname.bv_val,
|
|
|
|
c->c_n_write,
|
|
|
|
|
|
|
|
mi->mi_ad_monitorConnectionMask->ad_cname.bv_val,
|
|
|
|
c->c_currentber ? "r" : "",
|
|
|
|
c->c_writewaiter ? "w" : "",
|
|
|
|
LDAP_STAILQ_EMPTY( &c->c_ops ) ? "" : "x",
|
|
|
|
LDAP_STAILQ_EMPTY( &c->c_pending_ops ) ? "" : "p",
|
|
|
|
connection_state2str( c->c_conn_state ),
|
|
|
|
c->c_sasl_bind_in_progress ? "S" : "",
|
|
|
|
|
|
|
|
mi->mi_ad_monitorConnectionAuthzDN->ad_cname.bv_val,
|
|
|
|
c->c_dn.bv_len ? c->c_dn.bv_val : SLAPD_ANONYMOUS,
|
|
|
|
|
2005-07-20 08:49:33 +08:00
|
|
|
/* NOTE: client connections leave the c_peer_* fields NULL */
|
2005-04-28 01:51:54 +08:00
|
|
|
mi->mi_ad_monitorConnectionListener->ad_cname.bv_val,
|
|
|
|
c->c_listener_url.bv_val,
|
|
|
|
mi->mi_ad_monitorConnectionPeerDomain->ad_cname.bv_val,
|
2005-07-20 08:49:33 +08:00
|
|
|
BER_BVISNULL( &c->c_peer_domain ) ? "unknown" : c->c_peer_domain.bv_val,
|
2005-04-28 01:51:54 +08:00
|
|
|
mi->mi_ad_monitorConnectionLocalAddress->ad_cname.bv_val,
|
2005-07-20 08:49:33 +08:00
|
|
|
BER_BVISNULL( &c->c_peer_name ) ? "unknown" : c->c_peer_name.bv_val,
|
2005-04-28 01:51:54 +08:00
|
|
|
mi->mi_ad_monitorConnectionPeerAddress->ad_cname.bv_val,
|
|
|
|
c->c_sock_name.bv_val,
|
|
|
|
|
|
|
|
mi->mi_ad_monitorConnectionStartTime->ad_cname.bv_val,
|
|
|
|
buf2,
|
|
|
|
mi->mi_ad_monitorConnectionActivityTime->ad_cname.bv_val,
|
|
|
|
buf3,
|
|
|
|
|
2004-07-20 05:42:11 +08:00
|
|
|
mi->mi_creatorsName.bv_val,
|
|
|
|
mi->mi_creatorsName.bv_val,
|
|
|
|
ctmbuf,
|
|
|
|
mtmbuf );
|
2003-05-15 09:19:30 +08:00
|
|
|
|
2001-07-15 01:34:24 +08:00
|
|
|
e = str2entry( buf );
|
|
|
|
|
|
|
|
if ( e == NULL) {
|
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
"monitor_subsys_conn_create: "
|
|
|
|
"unable to create entry "
|
2004-09-13 06:12:58 +08:00
|
|
|
"\"cn=Connection %ld,%s\" entry\n",
|
2001-07-15 01:34:24 +08:00
|
|
|
c->c_connid,
|
2004-11-08 18:10:15 +08:00
|
|
|
ms->mss_dn.bv_val, 0 );
|
2001-07-15 01:34:24 +08:00
|
|
|
return( -1 );
|
|
|
|
}
|
|
|
|
|
2004-11-08 18:55:33 +08:00
|
|
|
mp = monitor_entrypriv_create();
|
|
|
|
if ( mp == NULL ) {
|
2005-04-28 05:30:35 +08:00
|
|
|
return LDAP_OTHER;
|
2004-11-08 18:55:33 +08:00
|
|
|
}
|
2001-07-15 01:34:24 +08:00
|
|
|
e->e_private = ( void * )mp;
|
2004-11-08 18:10:15 +08:00
|
|
|
mp->mp_info = ms;
|
2001-07-15 01:34:24 +08:00
|
|
|
mp->mp_flags = MONITOR_F_SUB | MONITOR_F_VOLATILE;
|
|
|
|
|
|
|
|
*ep = e;
|
|
|
|
|
2005-04-28 05:30:35 +08:00
|
|
|
return SLAP_CB_CONTINUE;
|
2001-07-15 01:34:24 +08:00
|
|
|
}
|
|
|
|
|
2005-08-09 04:45:10 +08:00
|
|
|
static int
|
2001-07-15 01:34:24 +08:00
|
|
|
monitor_subsys_conn_create(
|
2003-04-12 07:08:16 +08:00
|
|
|
Operation *op,
|
2005-04-28 05:30:35 +08:00
|
|
|
SlapReply *rs,
|
2001-12-27 23:16:12 +08:00
|
|
|
struct berval *ndn,
|
2001-07-15 01:34:24 +08:00
|
|
|
Entry *e_parent,
|
2005-07-18 06:18:45 +08:00
|
|
|
Entry **ep )
|
2001-07-15 01:34:24 +08:00
|
|
|
{
|
2004-11-09 02:52:27 +08:00
|
|
|
monitor_info_t *mi = ( monitor_info_t * )op->o_bd->be_private;
|
2004-09-13 06:12:58 +08:00
|
|
|
|
2001-07-15 01:34:24 +08:00
|
|
|
Connection *c;
|
|
|
|
int connindex;
|
2004-11-09 02:52:27 +08:00
|
|
|
monitor_entry_t *mp;
|
2005-04-28 05:30:35 +08:00
|
|
|
int rc = SLAP_CB_CONTINUE;
|
2004-11-09 02:52:27 +08:00
|
|
|
monitor_subsys_t *ms;
|
2001-07-15 01:34:24 +08:00
|
|
|
|
|
|
|
assert( mi != NULL );
|
|
|
|
assert( e_parent != NULL );
|
|
|
|
assert( ep != NULL );
|
|
|
|
|
2004-11-09 02:52:27 +08:00
|
|
|
ms = (( monitor_entry_t *)e_parent->e_private)->mp_info;
|
2004-11-08 18:10:15 +08:00
|
|
|
|
2001-07-15 01:34:24 +08:00
|
|
|
*ep = NULL;
|
|
|
|
|
|
|
|
if ( ndn == NULL ) {
|
2004-09-13 06:12:58 +08:00
|
|
|
Entry *e = NULL,
|
|
|
|
*e_tmp = NULL;
|
2001-07-15 01:34:24 +08:00
|
|
|
|
|
|
|
/* create all the children of e_parent */
|
|
|
|
for ( c = connection_first( &connindex );
|
|
|
|
c != NULL;
|
2005-07-18 06:18:45 +08:00
|
|
|
c = connection_next( c, &connindex ) )
|
2004-11-09 02:52:27 +08:00
|
|
|
{
|
2005-07-18 06:18:45 +08:00
|
|
|
if ( conn_create( mi, c, &e, ms ) != SLAP_CB_CONTINUE
|
|
|
|
|| e == NULL )
|
|
|
|
{
|
2002-04-02 20:27:06 +08:00
|
|
|
for ( ; e_tmp != NULL; ) {
|
2004-11-09 02:52:27 +08:00
|
|
|
mp = ( monitor_entry_t * )e_tmp->e_private;
|
2002-04-02 20:27:06 +08:00
|
|
|
e = mp->mp_next;
|
|
|
|
|
|
|
|
ch_free( mp );
|
|
|
|
e_tmp->e_private = NULL;
|
|
|
|
entry_free( e_tmp );
|
|
|
|
|
|
|
|
e_tmp = e;
|
|
|
|
}
|
2005-04-28 05:30:35 +08:00
|
|
|
rc = rs->sr_err = LDAP_OTHER;
|
2004-09-13 06:12:58 +08:00
|
|
|
break;
|
2001-07-15 01:34:24 +08:00
|
|
|
}
|
2004-11-09 02:52:27 +08:00
|
|
|
mp = ( monitor_entry_t * )e->e_private;
|
2001-07-15 01:34:24 +08:00
|
|
|
mp->mp_next = e_tmp;
|
|
|
|
e_tmp = e;
|
|
|
|
}
|
2005-07-18 06:18:45 +08:00
|
|
|
connection_done( c );
|
2001-07-15 01:34:24 +08:00
|
|
|
*ep = e;
|
2001-12-27 23:16:12 +08:00
|
|
|
|
2001-07-15 01:34:24 +08:00
|
|
|
} else {
|
2004-09-13 06:12:58 +08:00
|
|
|
unsigned long connid;
|
|
|
|
char *next = NULL;
|
|
|
|
static struct berval nconn_bv = BER_BVC( "cn=connection " );
|
2001-12-27 23:16:12 +08:00
|
|
|
|
2004-09-13 06:12:58 +08:00
|
|
|
|
|
|
|
/* create exactly the required entry;
|
|
|
|
* the normalized DN must start with "cn=connection ",
|
|
|
|
* followed by the connection id, followed by
|
|
|
|
* the RDN separator "," */
|
|
|
|
if ( ndn->bv_len <= nconn_bv.bv_len
|
|
|
|
|| strncmp( ndn->bv_val, nconn_bv.bv_val, nconn_bv.bv_len ) != 0 )
|
2002-01-09 14:30:23 +08:00
|
|
|
{
|
2004-09-13 06:12:58 +08:00
|
|
|
return -1;
|
2001-12-27 23:16:12 +08:00
|
|
|
}
|
2001-12-28 23:58:51 +08:00
|
|
|
|
2004-09-13 06:12:58 +08:00
|
|
|
connid = strtol( &ndn->bv_val[ nconn_bv.bv_len ], &next, 10 );
|
|
|
|
if ( next[ 0 ] != ',' ) {
|
2005-04-28 05:30:35 +08:00
|
|
|
return ( rs->sr_err = LDAP_OTHER );
|
2004-09-13 06:12:58 +08:00
|
|
|
}
|
2001-07-15 01:34:24 +08:00
|
|
|
|
|
|
|
for ( c = connection_first( &connindex );
|
|
|
|
c != NULL;
|
2005-04-28 05:30:35 +08:00
|
|
|
c = connection_next( c, &connindex ) )
|
|
|
|
{
|
2001-07-15 01:34:24 +08:00
|
|
|
if ( c->c_connid == connid ) {
|
2005-04-28 05:30:35 +08:00
|
|
|
rc = conn_create( mi, c, ep, ms );
|
|
|
|
if ( rc != SLAP_CB_CONTINUE ) {
|
|
|
|
rs->sr_err = rc;
|
|
|
|
|
|
|
|
} else if ( *ep == NULL ) {
|
|
|
|
rc = rs->sr_err = LDAP_OTHER;
|
2001-07-15 01:34:24 +08:00
|
|
|
}
|
2002-04-02 21:44:30 +08:00
|
|
|
|
|
|
|
break;
|
2001-07-15 01:34:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-28 05:30:35 +08:00
|
|
|
connection_done( c );
|
2001-07-15 01:34:24 +08:00
|
|
|
}
|
|
|
|
|
2004-09-13 06:12:58 +08:00
|
|
|
return rc;
|
2001-07-15 01:34:24 +08:00
|
|
|
}
|
|
|
|
|