add new schema stuff (no #ifdef, too heavy)

This commit is contained in:
Pierangelo Masarati 2003-04-12 00:30:47 +00:00
parent 805894be1d
commit 576089061d
11 changed files with 269 additions and 43 deletions

View File

@ -41,6 +41,8 @@
LDAP_BEGIN_DECL
#define MONITOR_DEVEL
/*
* The cache maps DNs to Entries.
* Each entry, on turn, holds the list of its children in the e_private field.
@ -73,6 +75,26 @@ struct monitorentrypriv {
struct monitorinfo {
Avlnode *mi_cache;
ldap_pvt_thread_mutex_t mi_cache_mutex;
ObjectClass *monitor_oc_monitorServer;
ObjectClass *monitor_oc_monitorContainer;
ObjectClass *monitor_oc_monitorCounter;
ObjectClass *monitor_oc_monitorOperation;
ObjectClass *monitor_oc_monitorConnection;
ObjectClass *monitor_oc_managedObject;
ObjectClass *monitor_oc_monitoredObject;
AttributeDescription *monitor_ad_monitoredInfo;
AttributeDescription *monitor_ad_managedInfo;
AttributeDescription *monitor_ad_monitorCounter;
AttributeDescription *monitor_ad_monitorOpCompleted;
AttributeDescription *monitor_ad_monitorOpInitiated;
AttributeDescription *monitor_ad_monitorConnectionNumber;
AttributeDescription *monitor_ad_monitorConnectionAuthzDN;
AttributeDescription *monitor_ad_monitorConnectionLocalAddress;
AttributeDescription *monitor_ad_monitorConnectionPeerAddress;
AttributeDescription *monitor_ad_description;
};
/*
@ -202,7 +224,6 @@ struct monitorsubsys {
extern struct monitorsubsys monitor_subsys[];
extern AttributeDescription *monitor_ad_desc;
extern BackendDB *be_monitor;
/*

View File

@ -109,8 +109,10 @@ monitor_subsys_backend_init(
bv.bv_val = bi->bi_type;
bv.bv_len = strlen( bv.bv_val );
attr_merge_normalize_one( e, monitor_ad_desc, &bv, NULL );
attr_merge_normalize_one( e_backend, monitor_ad_desc, &bv, NULL );
attr_merge_normalize_one( e, mi->monitor_ad_description,
&bv, NULL );
attr_merge_normalize_one( e_backend, mi->monitor_ad_description,
&bv, NULL );
if ( bi->bi_controls ) {
int j;

View File

@ -104,7 +104,7 @@ monitor_subsys_conn_init(
bv.bv_val = "0";
bv.bv_len = 1;
attr_merge_one( e, monitor_ad_desc, &bv, NULL );
attr_merge_one( e, mi->monitor_ad_description, &bv, NULL );
mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
e->e_private = ( void * )mp;
@ -161,7 +161,7 @@ monitor_subsys_conn_init(
bv.bv_val = "0";
bv.bv_len = 1;
attr_merge_one( e, monitor_ad_desc, &bv, NULL );
attr_merge_one( e, mi->monitor_ad_description, &bv, NULL );
mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
e->e_private = ( void * )mp;
@ -231,7 +231,7 @@ monitor_subsys_conn_update(
Attribute *a;
char buf[16];
a = attr_find( e->e_attrs, monitor_ad_desc );
a = attr_find( e->e_attrs, mi->monitor_ad_description );
if ( a == NULL ) {
return( -1 );
}
@ -246,6 +246,7 @@ monitor_subsys_conn_update(
static int
conn_create(
struct monitorinfo *mi,
Connection *c,
Entry **ep
)
@ -334,7 +335,7 @@ conn_create(
bv.bv_val = buf;
bv.bv_len = strlen( buf );
attr_merge_one( e, monitor_ad_desc, &bv, NULL );
attr_merge_one( e, mi->monitor_ad_description, &bv, NULL );
mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
e->e_private = ( void * )mp;
@ -373,7 +374,7 @@ monitor_subsys_conn_create(
for ( c = connection_first( &connindex );
c != NULL;
c = connection_next( c, &connindex )) {
if ( conn_create( c, &e ) || e == NULL ) {
if ( conn_create( mi, c, &e ) || e == NULL ) {
connection_done(c);
for ( ; e_tmp != NULL; ) {
mp = ( struct monitorentrypriv * )e_tmp->e_private;
@ -420,7 +421,7 @@ monitor_subsys_conn_create(
c != NULL;
c = connection_next( c, &connindex )) {
if ( c->c_connid == connid ) {
if ( conn_create( c, ep ) || *ep == NULL ) {
if ( conn_create( mi, c, ep ) || *ep == NULL ) {
connection_done(c);
return( -1 );
}

View File

@ -58,7 +58,6 @@ monitor_subsys_database_init(
const char *text = NULL;
assert( be != NULL );
assert( monitor_ad_desc != NULL );
mi = ( struct monitorinfo * )be->be_private;
@ -205,6 +204,7 @@ monitor_back_add_plugin( Backend *be, Entry *e_database )
{
Slapi_PBlock *pCurrentPB;
int i, rc = LDAP_SUCCESS;
struct monitorinfo *mi = ( struct monitorinfo * )be->be_private;
if ( slapi_x_pblock_get_first( be, &pCurrentPB ) != LDAP_SUCCESS ) {
/*
@ -239,7 +239,8 @@ monitor_back_add_plugin( Backend *be, Entry *e_database )
bv.bv_val = buf;
bv.bv_len = strlen( buf );
attr_merge_normalize_one( e_database, monitor_ad_desc, &bv, NULL );
attr_merge_normalize_one( e_database,
mi->monitor_ad_description, &bv, NULL );
i++;

View File

@ -245,6 +245,96 @@ monitor_back_db_init(
struct berval dn, ndn;
const char *text;
struct berval bv;
struct m_s {
char *name;
char *schema;
int offset;
} moc[] = {
{ "monitorServer", "( 1.3.6.1.4.1.4203.666.XXX "
"NAME 'monitorServer' "
"DESC 'Server monitoring root entry' "
"SUP monitor STRUCTURAL)",
offsetof(struct monitorinfo, monitor_oc_monitorServer) },
{ "monitorContainer", "( 1.3.6.1.4.1.4203.666.XXX "
"NAME 'monitorContainer' "
"DESC 'monitor container class' "
"SUP monitor STRUCTURAL)",
offsetof(struct monitorinfo, monitor_oc_monitorContainer) },
{ "monitorCounter", "( 1.3.6.1.4.1.4203.666.XXX "
"NAME 'monitorCounter' "
"DESC 'monitor counter class' "
"SUP monitor STRUCTURAL)",
offsetof(struct monitorinfo, monitor_oc_monitorCounter) },
{ "monitorOperation", "( 1.3.6.1.4.1.4203.666.XXX "
"NAME 'monitorOperation' "
"DESC 'monitor operation class' "
"SUP monitor STRUCTURAL)",
offsetof(struct monitorinfo, monitor_oc_monitorOperation) },
{ "monitorConnection", "( 1.3.6.1.4.1.4203.666.XXX "
"NAME 'monitorConnection' "
"DESC 'monitor connection class' "
"SUP monitor STRUCTURAL)",
offsetof(struct monitorinfo, monitor_oc_monitorConnection) },
{ "managedObject", "( 1.3.6.1.4.1.4203.666.XXX "
"NAME 'managedObject' "
"DESC 'monitor managed entity class' "
"SUP monitor STRUCTURAL)",
offsetof(struct monitorinfo, monitor_oc_managedObject) },
{ "monitoredObject", "( 1.3.6.1.4.1.4203.666.XXX "
"NAME 'monitoredObject' "
"DESC 'monitor monitored entity class' "
"SUP monitor STRUCTURAL)",
offsetof(struct monitorinfo, monitor_oc_monitoredObject) },
{ NULL, NULL, -1 }
}, mat[] = {
{ "monitoredInfo", "( 1.3.6.1.4.1.4203.666.XXX"
"NAME 'monitoredInfo' "
"DESC 'monitored info' "
"SUP name )",
offsetof(struct monitorinfo, monitor_ad_monitoredInfo) },
{ "managedInfo", "( 1.3.6.1.4.1.4203.666.XXX"
"NAME 'managedInfo' "
"DESC 'monitor managed info' "
"SUP name )",
offsetof(struct monitorinfo, monitor_ad_managedInfo) },
{ "monitorCounter", "( 1.3.6.1.4.1.4203.666.XXX"
"NAME 'monitorCounter' "
"DESC 'monitor counter' "
"EQUALITY integerMatch "
"SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )",
offsetof(struct monitorinfo, monitor_ad_monitorCounter) },
{ "monitorOpCompleted", "( 1.3.6.1.4.1.4203.666.XXX"
"NAME 'monitorOpCompleted' "
"DESC 'monitor completed operations' "
"SUP monitorCounter )",
offsetof(struct monitorinfo, monitor_ad_monitorOpCompleted) },
{ "monitorOpInitiated", "( 1.3.6.1.4.1.4203.666.XXX"
"NAME 'monitorOpInitiated' "
"DESC 'monitor initiated operations' "
"SUP monitorCounter )",
offsetof(struct monitorinfo, monitor_ad_monitorOpInitiated) },
{ "monitorConnectionNumber", "( 1.3.6.1.4.1.4203.666.XXX"
"NAME 'monitorConnectionNumber' "
"DESC 'monitor connection number' "
"SUP monitorCounter )",
offsetof(struct monitorinfo, monitor_ad_monitorConnectionNumber) },
{ "monitorConnectionAuthzDN", "( 1.3.6.1.4.1.4203.666.XXX"
"NAME 'monitorConnectionAuthzDN' "
"DESC 'monitor connection authorization DN' "
"SUP distinguishedName)",
offsetof(struct monitorinfo, monitor_ad_monitorConnectionAuthzDN) },
{ "monitorConnectionLocalAddress", "( 1.3.6.1.4.1.4203.666.XXX"
"NAME 'monitorConnectionLocalAddress' "
"DESC 'monitor connection local address' "
"SUP monitoredInfo)",
offsetof(struct monitorinfo, monitor_ad_monitorConnectionLocalAddress) },
{ "monitorConnectionPeerAddress", "( 1.3.6.1.4.1.4203.666.XXX"
"NAME 'monitorConnectionPeerAddress' "
"DESC 'monitor connection peer address' "
"SUP monitoredInfo)",
offsetof(struct monitorinfo, monitor_ad_monitorConnectionPeerAddress) },
{ NULL, NULL, -1 }
};
/*
* database monitor can be defined once only
@ -252,11 +342,10 @@ monitor_back_db_init(
if ( be_monitor ) {
#ifdef NEW_LOGGING
LDAP_LOG( OPERATION, CRIT,
"only one monitor backend is allowed\n" , 0, 0, 0);
"only one monitor backend is allowed\n", 0, 0, 0);
#else
Debug( LDAP_DEBUG_ANY,
"only one monitor backend is allowed\n%s%s%s",
"", "", "" );
"only one monitor backend is allowed\n", 0, 0, 0 );
#endif
return( -1 );
}
@ -272,11 +361,12 @@ monitor_back_db_init(
if( rc != LDAP_SUCCESS ) {
#ifdef NEW_LOGGING
LDAP_LOG( OPERATION, CRIT,
"monitor DN \"" SLAPD_MONITOR_DN "\" backend is allowed\n" , 0, 0, 0 );
"unable to normalize monitor DN \"" SLAPD_MONITOR_DN
"\"\n" , 0, 0, 0 );
#else
Debug( LDAP_DEBUG_ANY,
"monitor DN \"" SLAPD_MONITOR_DN "\" backend is allowed\n",
0, 0, 0 );
"unable to normalize monitor DN \"" SLAPD_MONITOR_DN
"\"\n", 0, 0, 0 );
#endif
return -1;
}
@ -286,9 +376,117 @@ monitor_back_db_init(
ber_bvarray_add( &be->be_nsuffix, &ndn );
mi = ( struct monitorinfo * )ch_calloc( sizeof( struct monitorinfo ), 1 );
if ( mi == NULL ) {
return -1;
}
ldap_pvt_thread_mutex_init( &mi->mi_cache_mutex );
if ( slap_str2ad( "description", &monitor_ad_desc, &text ) ) {
for ( i = 0; moc[i].name; i++ ) {
LDAPObjectClass *oc;
int code;
const char *err;
ObjectClass *Oc;
oc = ldap_str2objectclass(moc[i].schema, &code, &err,
LDAP_SCHEMA_ALLOW_ALL );
if ( !oc ) {
#ifdef NEW_LOGGING
LDAP_LOG( OPERATION, CRIT,
"unable to parse monitor objectclass '%s' "
"(%s before %s)\n" , moc[i].name,
ldap_scherr2str(code), err );
#else
Debug( LDAP_DEBUG_ANY,
"unable to parse monitor objectclass '%s' "
"(%s before %s)\n" , moc[i].name,
ldap_scherr2str(code), err );
#endif
return -1;
}
if ( oc->oc_oid == NULL ) {
#ifdef NEW_LOGGING
LDAP_LOG( OPERATION, CRIT,
"objectclass '%s' has no OID\n" ,
moc[i].name, 0, 0 );
#else
Debug( LDAP_DEBUG_ANY,
"objectclass '%s' has no OID\n" ,
moc[i].name, 0, 0 );
#endif
return -1;
}
code = oc_add(oc,1,&err);
if ( code ) {
#ifdef NEW_LOGGING
LDAP_LOG( OPERATION, CRIT,
"objectclass '%s' (%s before %s)\n" ,
moc[i].name, scherr2str(code), err );
#else
Debug( LDAP_DEBUG_ANY,
"objectclass '%s' (%s before %s)\n" ,
moc[i].name, scherr2str(code), err );
#endif
return -1;
}
ldap_memfree(oc);
Oc = oc_find( moc[i].name );
if ( Oc == NULL ) {
return -1;
}
((ObjectClass **)&(((char *)mi)[moc[i].offset]))[0] = Oc;
}
for ( i = 0; mat[i].name; i++ ) {
LDAPAttributeType *at;
int code;
const char *err;
AttributeDescription **ad;
at = ldap_str2attributetype( mat[i].schema, &code,
&err, LDAP_SCHEMA_ALLOW_ALL );
if ( !at ) {
return 1;
}
if ( at->at_oid == NULL ) {
return 1;
}
/* operational attributes should be defined internally
if ( at->at_usage ) {
fprintf( stderr, "%s: line %d: attribute type \"%s\" is operational\n",
fname, lineno, at->at_oid );
return 1;
} */
code = at_add(at,&err);
if ( code ) {
return 1;
}
ldap_memfree(at);
ad = ((AttributeDescription **)&(((char *)mi)[mat[i].offset]));
ad[0] = NULL;
if ( slap_str2ad( mat[i].name, ad, &text ) ) {
#ifdef NEW_LOGGING
LDAP_LOG( OPERATION, CRIT,
"monitor_back_db_init: %s\n", text, 0, 0 );
#else
Debug( LDAP_DEBUG_ANY,
"monitor_subsys_backend_init: %s\n%s%s",
text, "", "" );
#endif
return -1;
}
}
if ( slap_str2ad( "description", &mi->monitor_ad_description, &text ) ) {
#ifdef NEW_LOGGING
LDAP_LOG( OPERATION, CRIT,
"monitor_back_db_init: %s\n", text, 0, 0 );

View File

@ -50,7 +50,6 @@ monitor_subsys_listener_init(
Listener **l;
assert( be != NULL );
assert( monitor_ad_desc != NULL );
mi = ( struct monitorinfo * )be->be_private;
@ -127,7 +126,7 @@ monitor_subsys_listener_init(
bv.bv_val = "TLS";
bv.bv_len = sizeof("TLS")-1;
attr_merge_normalize_one( e, monitor_ad_desc, &bv, NULL );
attr_merge_normalize_one( e, mi->monitor_ad_description, &bv, NULL );
}
#endif /* HAVE_TLS */
#ifdef LDAP_CONNECTIONLESS
@ -137,7 +136,7 @@ monitor_subsys_listener_init(
bv.bv_val = "UDP";
bv.bv_len = sizeof("UDP")-1;
attr_merge_normalize_one( e, monitor_ad_desc, &bv, NULL );
attr_merge_normalize_one( e, mi->monitor_ad_description, &bv, NULL );
}
#endif /* HAVE_TLS */

View File

@ -116,13 +116,13 @@ monitor_subsys_log_init(
/* initialize the debug level(s) */
for ( i = 0; int_2_level[ i ].i != 0; i++ ) {
if ( monitor_ad_desc->ad_type->sat_equality->smr_normalize ) {
if ( mi->monitor_ad_description->ad_type->sat_equality->smr_normalize ) {
int rc;
rc = (*monitor_ad_desc->ad_type->sat_equality->smr_normalize)(
rc = (*mi->monitor_ad_description->ad_type->sat_equality->smr_normalize)(
0,
monitor_ad_desc->ad_type->sat_syntax,
monitor_ad_desc->ad_type->sat_equality,
mi->monitor_ad_description->ad_type->sat_syntax,
mi->monitor_ad_description->ad_type->sat_equality,
&int_2_level[ i ].s,
&int_2_level[ i ].n, NULL );
if ( rc ) {
@ -131,7 +131,7 @@ monitor_subsys_log_init(
}
if ( int_2_level[ i ].i & ldap_syslog ) {
attr_merge_one( e, monitor_ad_desc,
attr_merge_one( e, mi->monitor_ad_description,
&int_2_level[ i ].s,
&int_2_level[ i ].n );
}
@ -149,6 +149,7 @@ monitor_subsys_log_modify(
Modifications *modlist
)
{
struct monitorinfo *mi = (struct monitorinfo *)op->o_bd->be_private;
int rc = LDAP_OTHER;
int newlevel = ldap_syslog;
Attribute *save_attrs;
@ -178,7 +179,7 @@ monitor_subsys_log_modify(
/*
* only the monitor description attribute can be modified
*/
} else if ( mod->sm_desc != monitor_ad_desc ) {
} else if ( mod->sm_desc != mi->monitor_ad_description ) {
rc = LDAP_UNWILLING_TO_PERFORM;
break;
}

View File

@ -123,7 +123,7 @@ monitor_subsys_ops_init(
bv.bv_val = "0";
bv.bv_len = 1;
attr_merge_one( e, monitor_ad_desc, &bv, NULL );
attr_merge_one( e, mi->monitor_ad_description, &bv, NULL );
mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
e->e_private = ( void * )mp;
@ -190,7 +190,7 @@ monitor_subsys_ops_init(
bv.bv_val = "0";
bv.bv_len = 1;
attr_merge_one( e, monitor_ad_desc, &bv, NULL );
attr_merge_one( e, mi->monitor_ad_description, &bv, NULL );
mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
e->e_private = ( void * )mp;
@ -257,7 +257,7 @@ monitor_subsys_ops_init(
bv.bv_val = "0";
bv.bv_len = 1;
attr_merge_one( e, monitor_ad_desc, &bv, NULL );
attr_merge_one( e, mi->monitor_ad_description, &bv, NULL );
mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
e->e_private = ( void * )mp;
@ -324,7 +324,7 @@ monitor_subsys_ops_init(
bv.bv_val = "0";
bv.bv_len = 1;
attr_merge_one( e, monitor_ad_desc, &bv, NULL );
attr_merge_one( e, mi->monitor_ad_description, &bv, NULL );
mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
e->e_private = ( void * )mp;
@ -433,7 +433,7 @@ monitor_subsys_ops_update(
Attribute *a;
char buf[16];
a = attr_find( e->e_attrs, monitor_ad_desc );
a = attr_find( e->e_attrs, mi->monitor_ad_description );
if ( a == NULL ) {
return( -1 );
}

View File

@ -105,7 +105,8 @@ monitor_subsys_readw_update_internal(
}
snprintf( buf, sizeof( buf ), "%s=%d", str, num );
if ( ( a = attr_find( e->e_attrs, monitor_ad_desc ) ) != NULL ) {
a = attr_find( e->e_attrs, mi->monitor_ad_description );
if ( a != NULL ) {
for ( b = a->a_vals; b[0].bv_val != NULL; b++ ) {
if ( strncmp( b[0].bv_val, str, strlen( str ) ) == 0 ) {
free( b[0].bv_val );
@ -121,7 +122,8 @@ monitor_subsys_readw_update_internal(
bv.bv_val = buf;
bv.bv_len = strlen( buf );
attr_merge_normalize_one( e, monitor_ad_desc, &bv, NULL );
attr_merge_normalize_one( e, mi->monitor_ad_description,
&bv, NULL );
}
return( 0 );

View File

@ -101,7 +101,7 @@ monitor_subsys_sent_init(
bv.bv_val = "0";
bv.bv_len = 1;
attr_merge_one( e, monitor_ad_desc, &bv, NULL );
attr_merge_one( e, mi->monitor_ad_description, &bv, NULL );
mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
e->e_private = ( void * )mp;
@ -157,7 +157,7 @@ monitor_subsys_sent_init(
bv.bv_val = "0";
bv.bv_len = 1;
attr_merge_one( e, monitor_ad_desc, &bv, NULL );
attr_merge_one( e, mi->monitor_ad_description, &bv, NULL );
mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
e->e_private = ( void * )mp;
@ -213,7 +213,7 @@ monitor_subsys_sent_init(
bv.bv_val = "0";
bv.bv_len = 1;
attr_merge_one( e, monitor_ad_desc, &bv, NULL );
attr_merge_one( e, mi->monitor_ad_description, &bv, NULL );
mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
e->e_private = ( void * )mp;
@ -269,7 +269,7 @@ monitor_subsys_sent_init(
bv.bv_val = "0";
bv.bv_len = 1;
attr_merge_one( e, monitor_ad_desc, &bv, NULL );
attr_merge_one( e, mi->monitor_ad_description, &bv, NULL );
mp = ( struct monitorentrypriv * )ch_calloc( sizeof( struct monitorentrypriv ), 1 );
e->e_private = ( void * )mp;
@ -346,7 +346,7 @@ monitor_subsys_sent_update(
Attribute *a;
char buf[16];
a = attr_find( e->e_attrs, monitor_ad_desc );
a = attr_find( e->e_attrs, mi->monitor_ad_description );
if ( a == NULL ) {
return( -1 );
}

View File

@ -75,7 +75,7 @@ monitor_subsys_thread_init(
bv.bv_val = buf;
bv.bv_len = strlen( bv.bv_val );
attr_merge_normalize_one( e, monitor_ad_desc, &bv, NULL );
attr_merge_normalize_one( e, mi->monitor_ad_description, &bv, NULL );
monitor_cache_release( mi, e );
@ -98,8 +98,8 @@ monitor_subsys_thread_update(
snprintf( buf, sizeof( buf ), "backload=%d",
ldap_pvt_thread_pool_backload( &connection_pool ) );
if ( ( a = attr_find( e->e_attrs, monitor_ad_desc ) ) != NULL ) {
a = attr_find( e->e_attrs, mi->monitor_ad_description );
if ( a != NULL ) {
for ( b = a->a_vals; b[0].bv_val != NULL; b++ ) {
if ( strncmp( b[0].bv_val, "backload=",
sizeof( "backload=" ) - 1 ) == 0 ) {
@ -115,7 +115,8 @@ monitor_subsys_thread_update(
bv.bv_val = buf;
bv.bv_len = strlen( buf );
attr_merge_normalize_one( e, monitor_ad_desc, &bv, NULL );
attr_merge_normalize_one( e, mi->monitor_ad_description,
&bv, NULL );
}
return( 0 );