From: Pierangelo Masarati Date: Wed, 16 May 2007 09:13:14 +0000 (+0000) Subject: allow array of more generic syntaxes X-Git-Tag: OPENLDAP_REL_ENG_2_4_MP~473 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=978c3609e0ff55dfec7e16989d7a58f42ea6459d;p=openldap allow array of more generic syntaxes --- diff --git a/servers/slapd/at.c b/servers/slapd/at.c index afb34894c2..e70f10e969 100644 --- a/servers/slapd/at.c +++ b/servers/slapd/at.c @@ -755,12 +755,8 @@ at_add( } if ( sat->sat_syntax != NULL && sat->sat_syntax != syn ) { - Syntax *supsyn = syn->ssyn_sup; - - for ( ; supsyn && supsyn != sat->sat_syntax; - supsyn = supsyn->ssyn_sup ) - ; - if ( supsyn == NULL ) { + /* BEWARE: no loop detection! */ + if ( syn_is_sup( sat->sat_syntax, syn ) ) { code = SLAP_SCHERR_ATTR_BAD_SUP; goto error_return; } diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index 83f68c3a70..db194b0ce6 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -1674,6 +1674,9 @@ LDAP_SLAPD_F (int) syncrepl_add_glue LDAP_P(( LDAP_SLAPD_F (void) syncinfo_free LDAP_P(( struct syncinfo_s *, int all )); /* syntax.c */ +LDAP_SLAPD_F (int) syn_is_sup LDAP_P(( + Syntax *syn, + Syntax *sup )); LDAP_SLAPD_F (Syntax *) syn_find LDAP_P(( const char *synname )); LDAP_SLAPD_F (Syntax *) syn_find_desc LDAP_P(( diff --git a/servers/slapd/schema_init.c b/servers/slapd/schema_init.c index afa686eb1b..12ec8a8e1d 100644 --- a/servers/slapd/schema_init.c +++ b/servers/slapd/schema_init.c @@ -4005,6 +4005,12 @@ firstComponentNormalize( return rc; } +static char *country_gen_syn[] = { + "1.3.6.1.4.1.1466.115.121.1.15", + "1.3.6.1.4.1.1466.115.121.1.26", + "1.3.6.1.4.1.1466.115.121.1.44", + NULL +}; #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' " #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' " @@ -4115,12 +4121,11 @@ static slap_syntax_defs_rec syntax_defs[] = { {"( 1.3.6.1.4.1.1466.115.121.1.43 DESC 'Presentation Address' )", 0, NULL, NULL, NULL}, {"( 1.3.6.1.4.1.1466.115.121.1.44 DESC 'Printable String' )", - 0, "1.3.6.1.4.1.1466.115.121.1.15", - printableStringValidate, NULL}, - /* moved here because now depends on printable string */ + 0, NULL, printableStringValidate, NULL}, + /* moved here because now depends on Directory String, IA5 String + * and Printable String */ {"( 1.3.6.1.4.1.1466.115.121.1.11 DESC 'Country String' )", - 0, "1.3.6.1.4.1.1466.115.121.1.44", - countryStringValidate, NULL}, + 0, country_gen_syn, countryStringValidate, NULL}, {"( 1.3.6.1.4.1.1466.115.121.1.45 DESC 'SubtreeSpecification' )", #define subtreeSpecificationValidate UTF8StringValidate /* FIXME */ 0, NULL, subtreeSpecificationValidate, NULL}, diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index 0ba6f6bb65..4a37dd4d02 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -409,7 +409,7 @@ struct Syntax { #define SLAP_SYNTAX_HIDE 0x8000U /* hide (do not publish) */ #endif - Syntax *ssyn_sup; + Syntax **ssyn_sups; slap_syntax_validate_func *ssyn_validate; slap_syntax_transform_func *ssyn_pretty; @@ -436,7 +436,7 @@ struct Syntax { typedef struct slap_syntax_defs_rec { char *sd_desc; int sd_flags; - char *sd_sup; + char **sd_sups; slap_syntax_validate_func *sd_validate; slap_syntax_transform_func *sd_pretty; #ifdef SLAPD_BINARY_CONVERSION diff --git a/servers/slapd/syntax.c b/servers/slapd/syntax.c index ab18b18795..b289dd1f65 100644 --- a/servers/slapd/syntax.c +++ b/servers/slapd/syntax.c @@ -76,6 +76,35 @@ syn_find_desc( const char *syndesc, int *len ) return( NULL ); } +int +syn_is_sup( Syntax *syn, Syntax *sup ) +{ + int i; + + assert( syn != NULL ); + assert( sup != NULL ); + + if ( syn == sup ) { + return 1; + } + + if ( syn->ssyn_sups == NULL ) { + return 0; + } + + for ( i = 0; syn->ssyn_sups[i]; i++ ) { + if ( syn->ssyn_sups[i] == sup ) { + return 1; + } + + if ( syn_is_sup( syn->ssyn_sups[i], sup ) ) { + return 1; + } + } + + return 0; +} + void syn_destroy( void ) { @@ -156,16 +185,26 @@ syn_add( ssyn->ssyn_str2ber = def->sd_str2ber; #endif - if ( def->sd_sup != NULL ) { - ssyn->ssyn_sup = syn_find( def->sd_sup ); - if ( ssyn->ssyn_sup == NULL ) { - *err = def->sd_sup; - code = SLAP_SCHERR_SYN_SUP_NOT_FOUND; + if ( def->sd_sups != NULL ) { + int cnt; + + for ( cnt = 0; def->sd_sups[cnt] != NULL; cnt++ ) + ; + + ssyn->ssyn_sups = (Syntax **)SLAP_CALLOC( cnt + 1, + sizeof(Syntax) ); + + for ( cnt = 0; def->sd_sups[cnt] != NULL; cnt++ ) { + ssyn->ssyn_sups[cnt] = syn_find( def->sd_sups[cnt] ); + if ( ssyn->ssyn_sups[cnt] == NULL ) { + *err = def->sd_sups[cnt]; + code = SLAP_SCHERR_SYN_SUP_NOT_FOUND; + } } } if ( code == 0 ) { - code = syn_insert(ssyn, err); + code = syn_insert( ssyn, err ); } return code;