3 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6 /* ad.c - routines for dealing with attribute descriptions */
14 #include <ac/socket.h>
15 #include <ac/string.h>
21 #ifdef SLAPD_SCHEMA_NOT_COMPAT
22 AttributeDescription *ad_dup(
23 AttributeDescription *desc )
25 AttributeDescription *ad;
31 ad = (AttributeDescription *) ch_malloc( sizeof(AttributeDescription) );
35 ad->ad_cname = ber_bvdup( ad->ad_cname );
36 ad->ad_lang = ch_strdup( ad->ad_lang );
42 ad_free( AttributeDescription *ad, int freeit )
44 if( ad == NULL ) return;
46 ber_bvfree( ad->ad_cname );
49 if( freeit ) free( ad );
52 static int ad_keystring(
57 if( !AD_CHAR( bv->bv_val[0] ) ) {
61 for( i=1; i<bv->bv_len; i++ ) {
62 if( !AD_CHAR( bv->bv_val[i] ) ) {
71 AttributeDescription **ad,
75 bv.bv_val = (char *) str;
76 bv.bv_len = strlen( str );
78 return slap_bv2ad( &bv, ad, text );
83 AttributeDescription **ad,
86 int rtn = LDAP_UNDEFINED_TYPE;
88 AttributeDescription desc;
91 assert( *ad != NULL );
92 assert( *text != NULL );
94 if( bv == NULL || bv->bv_len == 0 ) {
95 *text = "empty attribute description";
96 return LDAP_UNDEFINED_TYPE;
99 /* make sure description is IA5 */
100 if( ad_keystring( bv ) ) {
101 *text = "attribute description contains inappropriate characters";
102 return LDAP_UNDEFINED_TYPE;
105 tokens = str2charray( bv->bv_val, ";");
107 if( tokens == NULL || *tokens == NULL ) {
108 *text = "no attribute type";
112 desc.ad_type = at_find( *tokens );
114 if( desc.ad_type == NULL ) {
115 *text = "attribute type undefined";
119 desc.ad_flags = SLAP_DESC_NONE;
122 for( i=1; tokens[i] != NULL; i++ ) {
123 if( strcasecmp( tokens[i], "binary" ) == 0 ) {
124 if( desc.ad_flags & SLAP_DESC_BINARY ) {
125 *text = "option \"binary\" specified multiple times";
129 if(!( desc.ad_type->sat_syntax->ssyn_flags
130 & SLAP_SYNTAX_BINARY ))
132 /* not stored in binary, disallow option */
133 *text = "option \"binary\" with type not supported";
137 desc.ad_flags |= SLAP_DESC_BINARY;
139 } else if ( strncasecmp( tokens[i], "lang-",
140 sizeof("lang-")-1 ) == 0 && tokens[i][sizeof("lang-")-1] )
142 if( desc.ad_lang != NULL ) {
143 *text = "multiple language tag options specified";
146 desc.ad_lang = tokens[i];
148 /* normalize to all lower case, it's easy */
149 ldap_pvt_str2lower( desc.ad_lang );
152 *text = "unrecognized option";
157 desc.ad_cname = ch_malloc( sizeof( struct berval ) );
159 desc.ad_cname->bv_len = strlen( desc.ad_type->sat_cname );
160 if( desc.ad_flags & SLAP_DESC_BINARY ) {
161 desc.ad_cname->bv_len += sizeof("binary");
163 if( desc.ad_lang != NULL ) {
164 desc.ad_cname->bv_len += strlen( desc.ad_lang );
167 desc.ad_cname = ch_malloc( desc.ad_cname->bv_len + 1 );
169 strcpy( desc.ad_cname->bv_val, desc.ad_type->sat_cname );
170 strcat( desc.ad_cname->bv_val, ";binary" );
171 if( desc.ad_flags & SLAP_DESC_BINARY ) {
172 strcat( desc.ad_cname->bv_val, ";binary" );
175 if( desc.ad_lang != NULL ) {
176 strcat( desc.ad_cname->bv_val, ";" );
177 strcat( desc.ad_cname->bv_val, desc.ad_lang );
181 *ad = ch_malloc( sizeof( AttributeDescription ) );
189 charray_free( tokens );
194 AttributeDescription *sub,
195 AttributeDescription *super
198 if( !is_at_subtype( sub->ad_type, super->ad_type ) ) {
202 if( super->ad_flags && ( super->ad_flags == sub->ad_flags )) {
206 if( super->ad_lang != NULL && ( sub->ad_lang == NULL
207 || strcasecmp( super->ad_lang, sub->ad_lang )))
217 AttributeDescription *desc,
221 for( i=0; attrs[i] != NULL; i++ ) {
222 AttributeDescription *ad = NULL;
226 rc = slap_str2ad( attrs[i], &ad, &text );
228 if( rc != LDAP_SUCCESS ) continue;
230 rc = is_ad_subtype( desc, ad );