From: Kurt Zeilenga Date: Mon, 15 May 2000 20:04:36 +0000 (+0000) Subject: Relocate schema_init() call to main() X-Git-Tag: LDBM_PRE_GIANT_RWLOCK~2966 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=7b14e1304a4a494d7b1b310b784f42b82513d115;p=openldap Relocate schema_init() call to main() Add schema_prep() call to main() Similiar changes to slapcommon.c Add schema_prep() impl to schema_init.c Add slap_ad_entry and slap_ad_children globals. Add "entry" and "children" to openldap.schema (this likely should be added to schema via code, not configuration) --- diff --git a/servers/slapd/config.c b/servers/slapd/config.c index 66478d1725..b2412ad39d 100644 --- a/servers/slapd/config.c +++ b/servers/slapd/config.c @@ -76,13 +76,6 @@ read_config( const char *fname ) Debug( LDAP_DEBUG_CONFIG, "reading config file %s\n", fname, 0, 0 ); - if ( schema_init( ) != 0 ) { - Debug( LDAP_DEBUG_ANY, - "error initializing the schema\n", - 0, 0, 0 ); - return( 1 ); - } - fp_getline_init( &lineno ); while ( (line = fp_getline( fp, &lineno )) != NULL ) { diff --git a/servers/slapd/main.c b/servers/slapd/main.c index 24c56fb647..bc50274a1e 100644 --- a/servers/slapd/main.c +++ b/servers/slapd/main.c @@ -361,12 +361,26 @@ int main( int argc, char **argv ) goto destroy; } + if ( schema_init( ) != 0 ) { + Debug( LDAP_DEBUG_ANY, + "schema initialization error\n", + 0, 0, 0 ); + goto destroy; + } + if ( read_config( configfile ) != 0 ) { rc = 1; SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 19 ); goto destroy; } + if ( schema_prep( ) != 0 ) { + Debug( LDAP_DEBUG_ANY, + "schema prep error\n", + 0, 0, 0 ); + goto destroy; + } + #ifdef HAVE_TLS ldap_pvt_tls_init(); diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index a1e67e2235..08b5d4d437 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -11,6 +11,9 @@ LDAP_BEGIN_DECL #ifdef SLAPD_SCHEMA_NOT_COMPAT +LIBSLAPD_F( AttributeDescription * ) slap_ad_entry; +LIBSLAPD_F( AttributeDescription * ) slap_ad_children; + LIBSLAPD_F (int) slap_str2ad LDAP_P(( const char *, AttributeDescription **ad, @@ -611,6 +614,7 @@ LIBSLAPD_F (int) entry_schema_check LDAP_P(( * schema_init.c */ LIBSLAPD_F (int) schema_init LDAP_P((void)); +LIBSLAPD_F (int) schema_prep LDAP_P((void)); /* diff --git a/servers/slapd/result.c b/servers/slapd/result.c index b1b2ec294c..65b5f3d9c1 100644 --- a/servers/slapd/result.c +++ b/servers/slapd/result.c @@ -629,7 +629,7 @@ send_search_entry( int opattrs; #ifdef SLAPD_SCHEMA_NOT_COMPAT - static AttributeDescription *entry = NULL; + AttributeDescription *entry = slap_ad_entry; #else static const char *entry = "entry"; #endif diff --git a/servers/slapd/schema/openldap.schema b/servers/slapd/schema/openldap.schema index c4711fc589..04c1b485d9 100644 --- a/servers/slapd/schema/openldap.schema +++ b/servers/slapd/schema/openldap.schema @@ -18,3 +18,7 @@ # # other slapd items # +attributetype ( entryOID NAME 'entry' SUP name + SINGLE-VALUE NO-USER-MODIFICATION USAGE dSAOperation ) +attributetype ( childrenOID NAME 'children' SUP name + SINGLE-VALUE NO-USER-MODIFICATION USAGE dSAOperation ) diff --git a/servers/slapd/schema_init.c b/servers/slapd/schema_init.c index d29a0d4d03..7b971379ea 100644 --- a/servers/slapd/schema_init.c +++ b/servers/slapd/schema_init.c @@ -564,16 +564,16 @@ struct mrule_defs_rec mrule_defs[] = { {NULL, SLAP_MR_NONE, NULL, NULL, NULL} }; +static int schema_init_done = 0; + int schema_init( void ) { int res; int i; - static int schema_init_done = 0; - /* We are called from read_config that is recursive */ - if ( schema_init_done ) - return( 0 ); + /* we should only be called once (from main) */ + assert( schema_init_done == 0 ); for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) { res = register_syntax( syntax_defs[i].sd_desc, @@ -585,7 +585,7 @@ schema_init( void ) if ( res ) { fprintf( stderr, "schema_init: Error registering syntax %s\n", syntax_defs[i].sd_desc ); - exit( EXIT_FAILURE ); + return -1; } } @@ -610,9 +610,42 @@ schema_init( void ) fprintf( stderr, "schema_init: Error registering matching rule %s\n", mrule_defs[i].mrd_desc ); - exit( EXIT_FAILURE ); + return -1; } } schema_init_done = 1; return( 0 ); } + +#ifdef SLAPD_SCHEMA_NOT_COMPAT +AttributeDescription *slap_ad_entry = NULL; +AttributeDescription *slap_ad_children = NULL; +#endif + +int +schema_prep( void ) +{ +#ifdef SLAPD_SCHEMA_NOT_COMPAT + int rc; + char *text; +#endif + /* we should only be called once after schema_init() was called */ + assert( schema_init_done == 1 ); + +#ifdef SLAPD_SCHEMA_NOT_COMPAT + rc = slap_str2ad( "entry", &slap_ad_entry, &text); + if( rc != LDAP_SUCCESS ) { + fprintf( stderr, "No attribute \"entry\" defined in schema\n" ); + return rc; + } + + rc = slap_str2ad( "children", &slap_ad_children, &text); + if( rc != LDAP_SUCCESS ) { + fprintf( stderr, "No attribute \"children\" defined in schema\n" ); + return rc; + } +#endif + + ++schema_init_done; + return 0; +} diff --git a/servers/slapd/tools/slapcommon.c b/servers/slapd/tools/slapcommon.c index dd4095e74a..45ba63a2d8 100644 --- a/servers/slapd/tools/slapcommon.c +++ b/servers/slapd/tools/slapcommon.c @@ -188,6 +188,13 @@ slap_tool_init( exit( EXIT_FAILURE ); } + rc = schema_init(); + + if (rc != 0 ) { + fprintf( stderr, "%s: slap_schema_init failed!\n", progname ); + exit( EXIT_FAILURE ); + } + read_config( conffile ); if ( !nbackends ) { @@ -195,6 +202,13 @@ slap_tool_init( exit( EXIT_FAILURE ); } + rc = schema_prep(); + + if (rc != 0 ) { + fprintf( stderr, "%s: slap_schema_prep failed!\n", progname ); + exit( EXIT_FAILURE ); + } + if( base != NULL ) { char *tbase = ch_strdup( base );