From: Howard Chu Date: Sat, 10 Aug 2002 03:10:52 +0000 (+0000) Subject: ITS#1893, use "schemadn" to configure subschemasubentry DN. (diff was X-Git-Tag: NO_SLAP_OP_BLOCKS~1248 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=07ebdca237e239aeca47ff53b8f68d5f24ae4a7a;p=openldap ITS#1893, use "schemadn" to configure subschemasubentry DN. (diff was inaccessible, this is original code, not contributed.) --- diff --git a/servers/slapd/add.c b/servers/slapd/add.c index b43e781052..6e7cb7e443 100644 --- a/servers/slapd/add.c +++ b/servers/slapd/add.c @@ -189,7 +189,7 @@ do_add( Connection *conn, Operation *op ) goto done; #if defined( SLAPD_SCHEMA_DN ) - } else if ( strcasecmp( e->e_ndn, SLAPD_SCHEMA_DN ) == 0 ) { + } else if ( bvmatch( &e->e_nname, &global_schemandn ) ) { send_ldap_result( conn, op, rc = LDAP_ALREADY_EXISTS, NULL, "subschema subentry already exists", NULL, NULL ); diff --git a/servers/slapd/backend.c b/servers/slapd/backend.c index 133f9fd82e..a6237ec5db 100644 --- a/servers/slapd/backend.c +++ b/servers/slapd/backend.c @@ -1113,7 +1113,7 @@ Attribute *backend_operational( #ifdef SLAPD_SCHEMA_DN if ( opattrs || ( attrs && ad_inlist( slap_schema.si_ad_subschemaSubentry, attrs )) ) { - *ap = slap_operational_subschemaSubentry(); + *ap = slap_operational_subschemaSubentry( be ); ap = &(*ap)->a_next; } #endif diff --git a/servers/slapd/compare.c b/servers/slapd/compare.c index b62d69dc4a..61a8f6882e 100644 --- a/servers/slapd/compare.c +++ b/servers/slapd/compare.c @@ -169,7 +169,8 @@ do_compare( goto cleanup; } - } else if ( strcasecmp( ndn.bv_val, SLAPD_SCHEMA_DN ) == 0 ) { +#ifdef SLAPD_SCHEMA_DN + } else if ( bvmatch( &ndn, &global_schemandn ) ) { #ifdef NEW_LOGGING LDAP_LOG( OPERATION, ARGS, "do_compare: dn (%s) attr(%s) value (%s)\n", @@ -198,6 +199,7 @@ do_compare( rc = 0; goto cleanup; } +#endif /* SLAPD_SCHEMA_DN */ } if( entry ) { diff --git a/servers/slapd/config.c b/servers/slapd/config.c index 0046551709..f04c52f4d3 100644 --- a/servers/slapd/config.c +++ b/servers/slapd/config.c @@ -52,6 +52,10 @@ char **cargv; struct berval default_search_base = { 0, NULL }; struct berval default_search_nbase = { 0, NULL }; unsigned num_subordinates = 0; +#ifdef SLAPD_SCHEMA_DN +struct berval global_schemadn; +struct berval global_schemandn; +#endif ber_len_t sockbuf_max_incoming = SLAP_SB_MAX_INCOMING_DEFAULT; ber_len_t sockbuf_max_incoming_auth= SLAP_SB_MAX_INCOMING_AUTH; @@ -564,6 +568,42 @@ read_config( const char *fname, int depth ) return 1; #endif /* HAVE_CYRUS_SASL */ +#ifdef SLAPD_SCHEMA_DN + } else if ( strcasecmp( cargv[0], "schemadn" ) == 0 ) { + struct berval dn; + if ( cargc < 2 ) { +#ifdef NEW_LOGGING + LDAP_LOG( CONFIG, CRIT, + "%s: line %d: missing dn in " + "\"schemadn \" line.\n", fname, lineno, 0 ); +#else + Debug( LDAP_DEBUG_ANY, + "%s: line %d: missing dn in \"schemadn \" line\n", + fname, lineno, 0 ); +#endif + return 1 ; + } + ber_str2bv( cargv[1], 0, 0, &dn ); + if ( be ) { + rc = dnPrettyNormal( NULL, &dn, &be->be_schemadn, + &be->be_schemandn ); + } else { + rc = dnPrettyNormal( NULL, &dn, &global_schemadn, + &global_schemandn ); + } + if ( rc != LDAP_SUCCESS ) { +#ifdef NEW_LOGGING + LDAP_LOG( CONFIG, CRIT, + "%s: line %d: schemadn DN is invalid.\n", + fname, lineno , 0 ); +#else + Debug( LDAP_DEBUG_ANY, + "%s: line %d: schemadn DN is invalid\n", + fname, lineno, 0 ); +#endif + return 1; + } +#endif /* SLAPD_SCHEMA_DN */ /* set UCDATA path */ } else if ( strcasecmp( cargv[0], "ucdata-path" ) == 0 ) { int err; @@ -2261,6 +2301,14 @@ read_config( const char *fname, int depth ) if ( depth == 0 ) ch_free( cargv ); +#ifdef SLAPD_SCHEMA_DN + if ( !global_schemadn.bv_val ) { + ber_str2bv( SLAPD_SCHEMA_DN, sizeof(SLAPD_SCHEMA_DN)-1, 1, + &global_schemadn ); + dnNormalize2( NULL, &global_schemadn, &global_schemandn ); + } +#endif + if ( load_ucdata( NULL ) < 0 ) return 1; return( 0 ); } @@ -2480,6 +2528,10 @@ void config_destroy( ) { ucdata_unload( UCDATA_ALL ); +#ifdef SLAPD_SCHEMA_DN + free( global_schemandn.bv_val ); + free( global_schemadn.bv_val ); +#endif free( line ); if ( slapd_args_file ) free ( slapd_args_file ); diff --git a/servers/slapd/delete.c b/servers/slapd/delete.c index 89e405c43f..057206c269 100644 --- a/servers/slapd/delete.c +++ b/servers/slapd/delete.c @@ -104,7 +104,7 @@ do_delete( #ifdef SLAPD_SCHEMA_DN - } else if ( strcasecmp( ndn.bv_val, SLAPD_SCHEMA_DN ) == 0 ) { + } else if ( bvmatch( &ndn, &global_schemandn ) ) { #ifdef NEW_LOGGING LDAP_LOG( OPERATION, INFO, "do_delete: conn %d: " "Attempt to delete subschema subentry.\n", conn->c_connid, 0, 0 ); diff --git a/servers/slapd/modify.c b/servers/slapd/modify.c index 026678a9ad..f9d6181747 100644 --- a/servers/slapd/modify.c +++ b/servers/slapd/modify.c @@ -205,7 +205,7 @@ do_modify( goto cleanup; #if defined( SLAPD_SCHEMA_DN ) - } else if ( strcasecmp( ndn.bv_val, SLAPD_SCHEMA_DN ) == 0 ) { + } else if ( bvmatch( &ndn, &global_schemandn ) ) { #ifdef NEW_LOGGING LDAP_LOG( OPERATION, ERR, "do_modify: attempt to modify subschema subentry.\n" , 0, 0, 0 ); diff --git a/servers/slapd/modrdn.c b/servers/slapd/modrdn.c index 8cb8a2737d..07057d0407 100644 --- a/servers/slapd/modrdn.c +++ b/servers/slapd/modrdn.c @@ -202,7 +202,7 @@ do_modrdn( goto cleanup; #ifdef SLAPD_SCHEMA_DN - } else if ( strcasecmp( ndn.bv_val, SLAPD_SCHEMA_DN ) == 0 ) { + } else if ( bvmatch( &ndn, &global_schemandn ) == 0 ) { #ifdef NEW_LOGGING LDAP_LOG( OPERATION, ERR, "do_modrdn: attempt to modify subschema subentry\n", 0, 0, 0 ); diff --git a/servers/slapd/operational.c b/servers/slapd/operational.c index 8accbee425..b9396b2473 100644 --- a/servers/slapd/operational.c +++ b/servers/slapd/operational.c @@ -14,16 +14,19 @@ #ifdef SLAPD_SCHEMA_DN Attribute * -slap_operational_subschemaSubentry( void ) +slap_operational_subschemaSubentry( Backend *be ) { Attribute *a; + /* The backend wants to take care of it */ + if ( be && be->be_schemadn.bv_val ) + return NULL; + a = ch_malloc( sizeof( Attribute ) ); a->a_desc = slap_schema.si_ad_subschemaSubentry; - /* Should be backend specific */ a->a_vals = ch_malloc( 2 * sizeof( struct berval ) ); - ber_str2bv( SLAPD_SCHEMA_DN, sizeof(SLAPD_SCHEMA_DN)-1, 1, a->a_vals ); + ber_dupbv( a->a_vals, &global_schemadn ); a->a_vals[1].bv_val = NULL; a->a_next = NULL; diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index cb65f3fb92..6fd4487eaf 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -341,6 +341,7 @@ LDAP_SLAPD_F (void) slapd_clr_read LDAP_P((ber_socket_t s, int wake)); */ #define dn_match(dn1, dn2) ( ber_bvcmp((dn1), (dn2)) == 0 ) +#define bvmatch(bv1, bv2) ( ((bv1)->bv_len == (bv2)->bv_len) && memcmp((bv1)->bv_val, (bv2)->bv_val, (bv1)->bv_len) == 0 ) LDAP_SLAPD_V( const struct berval ) slap_empty_bv; @@ -677,7 +678,7 @@ LDAP_SLAPD_F (Operation *) slap_op_pop LDAP_P(( Operation **olist )); /* * operational.c */ -LDAP_SLAPD_F (Attribute *) slap_operational_subschemaSubentry( void ); +LDAP_SLAPD_F (Attribute *) slap_operational_subschemaSubentry( Backend *be ); LDAP_SLAPD_F (Attribute *) slap_operational_hasSubordinate( int has ); /* @@ -1045,6 +1046,11 @@ LDAP_SLAPD_V (int) ldap_syslog; LDAP_SLAPD_V (struct berval) default_search_base; LDAP_SLAPD_V (struct berval) default_search_nbase; +#ifdef SLAPD_SCHEMA_DN +LDAP_SLAPD_V (struct berval) global_schemadn; +LDAP_SLAPD_V (struct berval) global_schemandn; +#endif + LDAP_SLAPD_V (ldap_pvt_thread_mutex_t) num_sent_mutex; LDAP_SLAPD_V (unsigned long) num_bytes_sent; LDAP_SLAPD_V (unsigned long) num_pdu_sent; diff --git a/servers/slapd/schema.c b/servers/slapd/schema.c index 4be9256d06..725995150f 100644 --- a/servers/slapd/schema.c +++ b/servers/slapd/schema.c @@ -35,8 +35,11 @@ schema_info( Entry **entry, const char **text ) e = (Entry *) ch_calloc( 1, sizeof(Entry) ); e->e_attrs = NULL; - ber_str2bv( SLAPD_SCHEMA_DN, sizeof(SLAPD_SCHEMA_DN)-1, 1, &e->e_name); - (void) dnNormalize2( NULL, &e->e_name, &e->e_nname ); + /* backend-specific schema info should be created by the + * backend itself + */ + ber_dupbv( &e->e_name, &global_schemadn ); + ber_dupbv( &e->e_nname, &global_schemandn ); e->e_private = NULL; vals[0].bv_val = "subentry"; @@ -62,8 +65,7 @@ schema_info( Entry **entry, const char **text ) { int rc; AttributeDescription *desc = NULL; - struct berval rdn = { sizeof(SLAPD_SCHEMA_DN)-1, - SLAPD_SCHEMA_DN }; + struct berval rdn = global_schemadn; vals[0].bv_val = strchr( rdn.bv_val, '=' ); if( vals[0].bv_val == NULL ) { diff --git a/servers/slapd/search.c b/servers/slapd/search.c index 7e36a3d748..90cb1927cc 100644 --- a/servers/slapd/search.c +++ b/servers/slapd/search.c @@ -239,7 +239,7 @@ do_search( } #if defined( SLAPD_SCHEMA_DN ) - else if ( strcasecmp( nbase.bv_val, SLAPD_SCHEMA_DN ) == 0 ) { + else if ( bvmatch( &nbase, &global_schemandn ) ) { /* check restrictions */ rc = backend_check_restrictions( NULL, conn, op, NULL, &text ) ; if( rc != LDAP_SUCCESS ) { diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index 83456e3ecb..fadc1a8431 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -1197,6 +1197,10 @@ struct slap_backend_db { BerVarray be_suffix; /* the DN suffixes of data in this backend */ BerVarray be_nsuffix; /* the normalized DN suffixes in this backend */ BerVarray be_suffixAlias; /* pairs of DN suffix aliases and deref values */ +#ifdef SLAPD_SCHEMA_DN + struct berval be_schemadn; /* per-backend subschema subentry DN */ + struct berval be_schemandn; /* normalized subschema DN */ +#endif struct berval be_rootdn; /* the magic "root" name (DN) for this db */ struct berval be_rootndn; /* the magic "root" normalized name (DN) for this db */ struct berval be_rootpw; /* the magic "root" password for this db */ diff --git a/servers/slapd/tools/mimic.c b/servers/slapd/tools/mimic.c index a6c9ebb3ae..4a88f833c8 100644 --- a/servers/slapd/tools/mimic.c +++ b/servers/slapd/tools/mimic.c @@ -239,7 +239,7 @@ int read_root_dse_file ( const char *file ) } Attribute * -slap_operational_subschemaSubentry( void ) +slap_operational_subschemaSubentry( Backend *be ) { return NULL; }