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 if( ad->ad_cname != NULL ) {
36 ad->ad_cname = ber_bvdup( ad->ad_cname );
39 if( ad->ad_lang != NULL ) {
40 ad->ad_lang = ch_strdup( ad->ad_lang );
47 ad_free( AttributeDescription *ad, int freeit )
49 if( ad == NULL ) return;
51 if( ad->ad_cname != NULL ) {
52 ber_bvfree( ad->ad_cname );
57 if( freeit ) free( ad );
60 static int ad_keystring(
65 if( !AD_CHAR( bv->bv_val[0] ) ) {
69 for( i=1; i<bv->bv_len; i++ ) {
70 if( !AD_CHAR( bv->bv_val[i] ) ) {
79 AttributeDescription **ad,
83 bv.bv_val = (char *) str;
84 bv.bv_len = strlen( str );
86 return slap_bv2ad( &bv, ad, text );
91 AttributeDescription **ad,
94 int rtn = LDAP_UNDEFINED_TYPE;
96 AttributeDescription desc;
100 assert( *text != NULL );
102 if( bv == NULL || bv->bv_len == 0 ) {
103 *text = "empty attribute description";
107 /* make sure description is IA5 */
108 if( ad_keystring( bv ) ) {
109 *text = "attribute description contains inappropriate characters";
113 tokens = str2charray( bv->bv_val, ";");
115 if( tokens == NULL || *tokens == NULL ) {
116 *text = "no attribute type";
120 desc.ad_type = at_find( *tokens );
122 if( desc.ad_type == NULL ) {
123 *text = "attribute type undefined";
127 desc.ad_flags = SLAP_DESC_NONE;
130 for( i=1; tokens[i] != NULL; i++ ) {
131 if( strcasecmp( tokens[i], "binary" ) == 0 ) {
132 if( desc.ad_flags & SLAP_DESC_BINARY ) {
133 *text = "option \"binary\" specified multiple times";
137 if(!( desc.ad_type->sat_syntax->ssyn_flags
138 & SLAP_SYNTAX_BINARY ))
140 /* not stored in binary, disallow option */
141 *text = "option \"binary\" with type not supported";
145 desc.ad_flags |= SLAP_DESC_BINARY;
147 } else if ( strncasecmp( tokens[i], "lang-",
148 sizeof("lang-")-1 ) == 0 && tokens[i][sizeof("lang-")-1] )
150 if( desc.ad_lang != NULL ) {
151 *text = "multiple language tag options specified";
154 desc.ad_lang = tokens[i];
156 /* normalize to all lower case, it's easy */
157 ldap_pvt_str2lower( desc.ad_lang );
160 *text = "unrecognized option";
165 desc.ad_cname = ch_malloc( sizeof( struct berval ) );
167 desc.ad_cname->bv_len = strlen( desc.ad_type->sat_cname );
168 if( desc.ad_flags & SLAP_DESC_BINARY ) {
169 desc.ad_cname->bv_len += sizeof("binary");
171 if( desc.ad_lang != NULL ) {
172 desc.ad_cname->bv_len += 1 + strlen( desc.ad_lang );
175 desc.ad_cname->bv_val = ch_malloc( desc.ad_cname->bv_len + 1 );
177 strcpy( desc.ad_cname->bv_val, desc.ad_type->sat_cname );
178 if( desc.ad_flags & SLAP_DESC_BINARY ) {
179 strcat( desc.ad_cname->bv_val, ";binary" );
182 if( desc.ad_lang != NULL ) {
183 strcat( desc.ad_cname->bv_val, ";" );
184 strcat( desc.ad_cname->bv_val, desc.ad_lang );
188 *ad = ch_malloc( sizeof( AttributeDescription ) );
196 charray_free( tokens );
201 AttributeDescription *sub,
202 AttributeDescription *super
205 if( !is_at_subtype( sub->ad_type, super->ad_type ) ) {
209 if( super->ad_flags && ( super->ad_flags == sub->ad_flags )) {
213 if( super->ad_lang != NULL && ( sub->ad_lang == NULL
214 || strcasecmp( super->ad_lang, sub->ad_lang )))
224 AttributeDescription *desc,
228 for( i=0; attrs[i] != NULL; i++ ) {
229 AttributeDescription *ad = NULL;
233 rc = slap_str2ad( attrs[i], &ad, &text );
235 if( rc != LDAP_SUCCESS ) continue;
237 rc = is_ad_subtype( desc, ad );