extern struct monitorsubsys monitor_subsys[];
extern AttributeDescription *monitor_ad_desc;
+extern slap_mr_normalize_func *monitor_ad_normalize;
extern BackendDB *be_monitor;
/*
for ( i = nBackendInfo; i--; ) {
char buf[1024];
BackendInfo *bi;
- struct berval bv[ 2 ];
+ struct berval bv, nbv;
+ int rc;
bi = &backendInfo[i];
return( -1 );
}
- bv[0].bv_val = bi->bi_type;
- bv[0].bv_len = strlen( bv[0].bv_val );
- bv[1].bv_val = NULL;
+ bv.bv_val = bi->bi_type;
+ bv.bv_len = strlen( bv.bv_val );
+
+ nbv.bv_val = NULL;
+ if ( monitor_ad_normalize ) {
+ rc = monitor_ad_normalize(
+ 0,
+ monitor_ad_desc->ad_type->sat_syntax,
+ monitor_ad_desc->ad_type->sat_equality,
+ &bv, &nbv );
+ if ( rc ) {
+ return( -1 );
+ }
+ }
- attr_mergeit( e, monitor_ad_desc, bv );
- attr_mergeit( e_backend, monitor_ad_desc, bv );
+ attr_merge_one( e, monitor_ad_desc, &bv,
+ nbv.bv_val ? &nbv : NULL );
+ attr_merge_one( e_backend, monitor_ad_desc, &bv,
+ nbv.bv_val ? &nbv : NULL );
+ ch_free( nbv.bv_val );
if ( bi->bi_controls ) {
int j;
for ( j = 0; bi->bi_controls[ j ]; j++ ) {
- bv[0].bv_val = bi->bi_controls[ j ];
- bv[0].bv_len = strlen( bv[0].bv_val );
- attr_mergeit( e, slap_schema.si_ad_supportedControl, bv );
+ bv.bv_val = bi->bi_controls[ j ];
+ bv.bv_len = strlen( bv.bv_val );
+ attr_merge_one( e, slap_schema.si_ad_supportedControl, &bv, NULL );
}
}
/* get entry with reader lock */
monitor_cache_dn2entry( mi, &op->o_req_ndn, &e, &matched );
if ( e == NULL ) {
+ rs->sr_err = LDAP_NO_SUCH_OBJECT;
if ( matched ) {
- rs->sr_matched = ch_strdup( matched->e_dn );
- monitor_cache_release( mi, matched );
+ rs->sr_matched = matched->e_dn;
}
- rs->sr_err = LDAP_NO_SUCH_OBJECT;
-
send_ldap_result( op, rs );
-
- rs->sr_matched = NULL;
+ if ( matched ) {
+ monitor_cache_release( mi, matched );
+ rs->sr_matched = NULL;
+ }
return( 0 );
}
Entry *e, *e_tmp, *e_conn;
struct monitorentrypriv *mp;
char buf[1024];
- struct berval bv[2];
+ struct berval bv;
assert( be != NULL );
return( -1 );
}
- bv[1].bv_val = NULL;
- bv[0].bv_val = "0";
- bv[0].bv_len = 1;
- attr_mergeit( e, monitor_ad_desc, bv );
+ bv.bv_val = "0";
+ bv.bv_len = 1;
+ attr_merge_one( e, monitor_ad_desc, &bv, NULL );
mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
e->e_private = ( void * )mp;
return( -1 );
}
- bv[1].bv_val = NULL;
- bv[0].bv_val = "0";
- bv[0].bv_len = 1;
- attr_mergeit( e, monitor_ad_desc, bv );
+ bv.bv_val = "0";
+ bv.bv_len = 1;
+ attr_merge_one( e, monitor_ad_desc, &bv, NULL );
mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
e->e_private = ( void * )mp;
char buf2[ LDAP_LUTIL_GENTIME_BUFSIZE ];
char buf3[ LDAP_LUTIL_GENTIME_BUFSIZE ];
- struct berval bv[2];
+ struct berval bv;
Entry *e;
buf3
);
- bv[1].bv_val = NULL;
- bv[0].bv_val = buf;
- bv[0].bv_len = strlen( buf );
- attr_mergeit( e, monitor_ad_desc, bv );
+ bv.bv_val = buf;
+ bv.bv_len = strlen( buf );
+ attr_merge_one( e, monitor_ad_desc, &bv, NULL );
mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
e->e_private = ( void * )mp;
}
if ( be->be_flags & SLAP_BFLAG_MONITOR ) {
- attr_mergeit( e, ad_mc, be->be_suffix );
- attr_mergeit( e_database, ad_mc, be->be_suffix );
+ attr_merge( e, ad_mc, be->be_suffix, be->be_nsuffix );
+ attr_merge( e_database, ad_mc, be->be_suffix, be->be_nsuffix );
} else {
- attr_mergeit( e, ad_nc, be->be_suffix );
- attr_mergeit( e_database, ad_nc, be->be_suffix );
+ attr_merge( e, ad_nc, be->be_suffix, be->be_nsuffix );
+ attr_merge( e_database, ad_nc, be->be_suffix, be->be_nsuffix );
}
for ( j = nBackendInfo; j--; ) {
* used by many functions to add description to entries
*/
AttributeDescription *monitor_ad_desc = NULL;
+slap_mr_normalize_func *monitor_ad_normalize = NULL;
BackendDB *be_monitor = NULL;
/*
char buf[1024], *end_of_line;
struct berval dn, ndn;
const char *text;
- struct berval bv[2];
+ struct berval bv;
/*
* database monitor can be defined once only
return -1;
}
- ber_dupbv( &bv[0], &dn );
- ber_bvarray_add( &be->be_suffix, &bv[0] );
+ ber_dupbv( &bv, &dn );
+ ber_bvarray_add( &be->be_suffix, &bv );
ber_bvarray_add( &be->be_nsuffix, &ndn );
mi = ( struct monitorinfo * )ch_calloc( sizeof( struct monitorinfo ), 1 );
return( -1 );
}
+ if ( monitor_ad_desc->ad_type->sat_equality ) {
+ monitor_ad_normalize = monitor_ad_desc->ad_type->sat_equality->smr_normalize;
+ }
+
/*
* Create all the subsystem specific entries
*/
#endif
return( -1 );
}
- bv[1].bv_val = NULL;
- bv[0].bv_val = (char *) Versionstr;
+ bv.bv_val = (char *) Versionstr;
end_of_line = strchr( Versionstr, '\n' );
if ( end_of_line ) {
- bv[0].bv_len = end_of_line - Versionstr;
+ bv.bv_len = end_of_line - Versionstr;
} else {
- bv[0].bv_len = strlen( Versionstr );
+ bv.bv_len = strlen( Versionstr );
}
- if ( attr_mergeit( e, monitor_ad_desc, bv ) ) {
+ if ( attr_merge_one( e, monitor_ad_desc, &bv, NULL ) ) {
#ifdef NEW_LOGGING
LDAP_LOG( OPERATION, CRIT,
"unable to add description to '%s' entry\n",
#ifdef HAVE_TLS
if ( l[i]->sl_is_tls ) {
- struct berval bv[2];
- bv[1].bv_val = NULL;
- bv[0].bv_val = "TLS";
- bv[0].bv_len = sizeof("TLS")-1;
- attr_mergeit( e, monitor_ad_desc, bv );
+ struct berval bv, nbv;
+
+ bv.bv_val = "TLS";
+ bv.bv_len = sizeof("TLS")-1;
+
+ nbv.bv_val = NULL;
+ if ( monitor_ad_normalize ) {
+ int rc;
+
+ rc = monitor_ad_normalize(
+ 0,
+ monitor_ad_desc->ad_type->sat_syntax,
+ monitor_ad_desc->ad_type->sat_equality,
+ &bv, &nbv );
+ if ( rc ) {
+ return( -1 );
+ }
+ }
+
+ attr_merge_one( e, monitor_ad_desc, &bv,
+ nbv.bv_val ? &nbv : NULL );
+ ch_free( nbv.bv_val );
}
#endif /* HAVE_TLS */
#ifdef LDAP_CONNECTIONLESS
if ( l[i]->sl_is_udp ) {
- struct berval bv[2];
- bv[1].bv_val = NULL;
- bv[0].bv_val = "UDP";
- bv[0].bv_len = sizeof("UDP")-1;
- attr_mergeit( e, monitor_ad_desc, bv );
+ struct berval bv, nbv;
+
+ bv.bv_val = "UDP";
+ bv.bv_len = sizeof("UDP")-1;
+
+ nbv.bv_val = NULL;
+ if ( monitor_ad_normalize ) {
+ int rc;
+
+ rc = monitor_ad_normalize(
+ 0,
+ monitor_ad_desc->ad_type->sat_syntax,
+ monitor_ad_desc->ad_type->sat_equality,
+ &bv, &nbv );
+ if ( rc ) {
+ return( -1 );
+ }
+ }
+
+ attr_merge_one( e, monitor_ad_desc, &bv,
+ nbv.bv_val ? &nbv : NULL );
+ ch_free( nbv.bv_val );
}
#endif /* HAVE_TLS */
#include <ac/string.h>
#include "slap.h"
+#include <lber_pvt.h>
#include "lutil.h"
#include "ldif.h"
#include "back-monitor.h"
static struct {
int i;
- const char *s;
+ struct berval s;
+ struct berval n;
} int_2_level[] = {
- { LDAP_DEBUG_TRACE, "Trace" },
- { LDAP_DEBUG_PACKETS, "Packets" },
- { LDAP_DEBUG_ARGS, "Args" },
- { LDAP_DEBUG_CONNS, "Conns" },
- { LDAP_DEBUG_BER, "BER" },
- { LDAP_DEBUG_FILTER, "Filter" },
- { LDAP_DEBUG_CONFIG, "Config" }, /* useless */
- { LDAP_DEBUG_ACL, "ACL" },
- { LDAP_DEBUG_STATS, "Stats" },
- { LDAP_DEBUG_STATS2, "Stats2" },
- { LDAP_DEBUG_SHELL, "Shell" },
- { LDAP_DEBUG_PARSE, "Parse" },
- { LDAP_DEBUG_CACHE, "Cache" },
- { LDAP_DEBUG_INDEX, "Index" },
- { 0, NULL }
+ { LDAP_DEBUG_TRACE, BER_BVC("Trace"), { 0, NULL } },
+ { LDAP_DEBUG_PACKETS, BER_BVC("Packets"), { 0, NULL } },
+ { LDAP_DEBUG_ARGS, BER_BVC("Args"), { 0, NULL } },
+ { LDAP_DEBUG_CONNS, BER_BVC("Conns"), { 0, NULL } },
+ { LDAP_DEBUG_BER, BER_BVC("BER"), { 0, NULL } },
+ { LDAP_DEBUG_FILTER, BER_BVC("Filter"), { 0, NULL } },
+ { LDAP_DEBUG_CONFIG, BER_BVC("Config"), { 0, NULL } }, /* useless */
+ { LDAP_DEBUG_ACL, BER_BVC("ACL"), { 0, NULL } },
+ { LDAP_DEBUG_STATS, BER_BVC("Stats"), { 0, NULL } },
+ { LDAP_DEBUG_STATS2, BER_BVC("Stats2"), { 0, NULL } },
+ { LDAP_DEBUG_SHELL, BER_BVC("Shell"), { 0, NULL } },
+ { LDAP_DEBUG_PARSE, BER_BVC("Parse"), { 0, NULL } },
+ { LDAP_DEBUG_CACHE, BER_BVC("Cache"), { 0, NULL } },
+ { LDAP_DEBUG_INDEX, BER_BVC("Index"), { 0, NULL } },
+ { 0, { 0, NULL }, { 0, NULL } }
};
-static int loglevel2int( const char *str );
-static const char * int2loglevel( int n );
+static int loglevel2int( struct berval *l );
+static int int2loglevel( int n );
static int add_values( Entry *e, Modification *mod, int *newlevel );
static int delete_values( Entry *e, Modification *mod, int *newlevel );
bv[1].bv_val = NULL;
- /* initialize the debug level */
+ /* initialize the debug level(s) */
for ( i = 0; int_2_level[ i ].i != 0; i++ ) {
- if ( int_2_level[ i ].i & ldap_syslog ) {
- bv[0].bv_val = ( char * )int_2_level[ i ].s;
- bv[0].bv_len = strlen( bv[0].bv_val );
- attr_mergeit( e, monitor_ad_desc, bv );
+ if ( monitor_ad_normalize ) {
+ int rc;
+
+ rc = monitor_ad_normalize(
+ 0,
+ monitor_ad_desc->ad_type->sat_syntax,
+ monitor_ad_desc->ad_type->sat_equality,
+ &int_2_level[ i ].s,
+ &int_2_level[ i ].n );
+ if ( rc ) {
+ return( -1 );
+ }
+ }
+
+ if ( int_2_level[ i ].i & ldap_syslog ) {
+ attr_merge_one( e, monitor_ad_desc,
+ &int_2_level[ i ].s,
+ &int_2_level[ i ].n );
}
}
}
static int
-loglevel2int( const char *str )
+loglevel2int( struct berval *l )
{
int i;
for ( i = 0; int_2_level[ i ].i != 0; i++ ) {
- if ( strcasecmp( str, int_2_level[ i ].s ) == 0 ) {
+ if ( l->bv_len != int_2_level[ i ].s.bv_len ) {
+ continue;
+ }
+
+ if ( strcasecmp( l->bv_val, int_2_level[ i ].s.bv_val ) == 0 ) {
return int_2_level[ i ].i;
}
}
return 0;
}
-static const char *
+static int
int2loglevel( int n )
{
int i;
for ( i = 0; int_2_level[ i ].i != 0; i++ ) {
if ( int_2_level[ i ].i == n ) {
- return int_2_level[ i ].s;
+ return i;
}
}
- return NULL;
+ return -1;
}
static int
int i;
for ( i = 0; mod->sm_bvalues && mod->sm_bvalues[i].bv_val != NULL; i++ ) {
- int l;
- const char *s;
- ber_len_t len;
+ int l;
- l = loglevel2int( mod->sm_bvalues[i].bv_val );
+ l = loglevel2int( &mod->sm_bvalues[i] );
if ( !l ) {
return LDAP_CONSTRAINT_VIOLATION;
}
- s = int2loglevel( l );
- len = strlen( s );
- assert( len == mod->sm_bvalues[i].bv_len );
+ if ( ( l = int2loglevel( l ) ) == -1 ) {
+ return LDAP_OTHER;
+ }
+
+ assert( int_2_level[ l ].s.bv_len
+ == mod->sm_bvalues[i].bv_len );
- AC_MEMCPY( mod->sm_bvalues[i].bv_val, s, len );
+ AC_MEMCPY( mod->sm_bvalues[i].bv_val,
+ int_2_level[ l ].s.bv_val,
+ int_2_level[ l ].s.bv_len );
+
+ AC_MEMCPY( mod->sm_nvalues[i].bv_val,
+ int_2_level[ l ].n.bv_val,
+ int_2_level[ l ].n.bv_len );
*newlevel |= l;
}
}
/* no - add them */
- if ( attr_mergeit( e, mod->sm_desc, mod->sm_bvalues ) != 0 ) {
+ if ( attr_merge( e, mod->sm_desc, mod->sm_bvalues,
+ mod->sm_nvalues ) != 0 ) {
/* this should return result of attr_mergeit */
return LDAP_OTHER;
}
}
if ( mod->sm_bvalues != NULL &&
- attr_mergeit( e, mod->sm_desc, mod->sm_bvalues ) != 0 ) {
+ attr_merge( e, mod->sm_desc, mod->sm_bvalues,
+ mod->sm_nvalues ) != 0 ) {
return LDAP_OTHER;
}
if ( matched != NULL ) {
rs->sr_matched = NULL;
monitor_cache_release( mi, matched );
- return( 0 );
}
+ return( 0 );
}
if ( !acl_check_modlist( op, e, op->oq_modify.rs_modlist )) {
Entry *e, *e_tmp, *e_op, *e_children;
struct monitorentrypriv *mp;
char buf[1024];
- struct berval bv[2];
+ struct berval bv;
int i;
assert( be != NULL );
return( -1 );
}
- bv[1].bv_val = NULL;
- bv[0].bv_val = "0";
- bv[0].bv_len = 1;
- attr_mergeit( e, monitor_ad_desc, bv );
+ bv.bv_val = "0";
+ bv.bv_len = 1;
+ attr_merge_one( e, monitor_ad_desc, &bv, NULL );
mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
e->e_private = ( void * )mp;
return( -1 );
}
- bv[1].bv_val = NULL;
- bv[0].bv_val = "0";
- bv[0].bv_len = 1;
- attr_mergeit( e, monitor_ad_desc, bv );
+ bv.bv_val = "0";
+ bv.bv_len = 1;
+ attr_merge_one( e, monitor_ad_desc, &bv, NULL );
mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
e->e_private = ( void * )mp;
return( -1 );
}
- bv[0].bv_val = "0";
- bv[0].bv_len = 1;
- attr_mergeit( e, monitor_ad_desc, bv );
+ bv.bv_val = "0";
+ bv.bv_len = 1;
+ attr_merge_one( e, monitor_ad_desc, &bv, NULL );
mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
e->e_private = ( void * )mp;
return( -1 );
}
- bv[0].bv_val = "0";
- bv[0].bv_len = 1;
- attr_mergeit( e, monitor_ad_desc, bv );
+ bv.bv_val = "0";
+ bv.bv_len = 1;
+ attr_merge_one( e, monitor_ad_desc, &bv, NULL );
mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
e->e_private = ( void * )mp;
int nconns, nwritewaiters, nreadwaiters;
Attribute *a;
- struct berval bv[2], *b = NULL;
+ struct berval *b = NULL;
char buf[1024];
char *str = NULL;
assert( mi != NULL );
assert( e != NULL );
- bv[1].bv_val = NULL;
-
nconns = nwritewaiters = nreadwaiters = 0;
for ( c = connection_first( &connindex );
c != NULL;
}
if ( b == NULL || b[0].bv_val == NULL ) {
- bv[0].bv_val = buf;
- bv[0].bv_len = strlen( buf );
- attr_mergeit( e, monitor_ad_desc, bv );
+ struct berval bv, nbv;
+
+ bv.bv_val = buf;
+ bv.bv_len = strlen( buf );
+
+ nbv.bv_val = NULL;
+ if ( monitor_ad_normalize ) {
+ int rc;
+
+ rc = monitor_ad_normalize(
+ 0,
+ monitor_ad_desc->ad_type->sat_syntax,
+ monitor_ad_desc->ad_type->sat_equality,
+ &bv, &nbv );
+ if ( rc ) {
+ return( -1 );
+ }
+ }
+
+ attr_merge_one( e, monitor_ad_desc, &bv,
+ nbv.bv_val ? &nbv : NULL );
+ ch_free( nbv.bv_val );
}
return( 0 );
if ( e == NULL ) {
rs->sr_err = LDAP_NO_SUCH_OBJECT;
if ( matched ) {
- rs->sr_matched = ch_strdup( matched->e_dn );
- monitor_cache_release( mi, matched );
+ rs->sr_matched = matched->e_dn;
}
send_ldap_result( op, rs );
- rs->sr_matched = NULL;
+ if ( matched ) {
+ monitor_cache_release( mi, matched );
+ rs->sr_matched = NULL;
+ }
return( 0 );
}
Entry *e, *e_tmp, *e_sent;
struct monitorentrypriv *mp;
char buf[1024];
- struct berval bv[2];
+ struct berval bv;
assert( be != NULL );
return( -1 );
}
- bv[1].bv_val = NULL;
- bv[0].bv_val = "0";
- bv[0].bv_len = 1;
- attr_mergeit( e, monitor_ad_desc, bv );
+ bv.bv_val = "0";
+ bv.bv_len = 1;
+ attr_merge_one( e, monitor_ad_desc, &bv, NULL );
mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
e->e_private = ( void * )mp;
return( -1 );
}
- bv[0].bv_val = "0";
- bv[0].bv_len = 1;
- attr_mergeit( e, monitor_ad_desc, bv );
+ bv.bv_val = "0";
+ bv.bv_len = 1;
+ attr_merge_one( e, monitor_ad_desc, &bv, NULL );
mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
e->e_private = ( void * )mp;
return( -1 );
}
- bv[0].bv_val = "0";
- bv[0].bv_len = 1;
- attr_mergeit( e, monitor_ad_desc, bv );
+ bv.bv_val = "0";
+ bv.bv_len = 1;
+ attr_merge_one( e, monitor_ad_desc, &bv, NULL );
mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
e->e_private = ( void * )mp;
return( -1 );
}
- bv[0].bv_val = "0";
- bv[0].bv_len = 1;
- attr_mergeit( e, monitor_ad_desc, bv );
+ bv.bv_val = "0";
+ bv.bv_len = 1;
+ attr_merge_one( e, monitor_ad_desc, &bv, NULL );
mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
e->e_private = ( void * )mp;
{
struct monitorinfo *mi;
Entry *e;
- struct berval bv[2];
static char buf[1024];
+ struct berval bv;
mi = ( struct monitorinfo * )be->be_private;
/* initialize the thread number */
snprintf( buf, sizeof( buf ), "max=%d", connection_pool_max );
- bv[1].bv_val = NULL;
- bv[0].bv_val = buf;
- bv[0].bv_len = strlen( bv[0].bv_val );
+ bv.bv_val = buf;
+ bv.bv_len = strlen( bv.bv_val );
- attr_mergeit( e, monitor_ad_desc, bv );
+ attr_merge_one( e, monitor_ad_desc, &bv, NULL );
monitor_cache_release( mi, e );
)
{
Attribute *a;
- struct berval bv[2], *b = NULL;
+ struct berval *b = NULL;
char buf[1024];
- bv[1].bv_val = NULL;
-
snprintf( buf, sizeof( buf ), "backload=%d",
ldap_pvt_thread_pool_backload( &connection_pool ) );
}
if ( b == NULL || b[0].bv_val == NULL ) {
- bv[0].bv_val = buf;
- bv[0].bv_len = strlen( buf );
- attr_mergeit( e, monitor_ad_desc, bv );
+ struct berval bv;
+
+ bv.bv_val = buf;
+ bv.bv_len = strlen( buf );
+ attr_merge_one( e, monitor_ad_desc, &bv, NULL );
}
return( 0 );