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( *ad == NULL ); /* temporary */
101 assert( *text != NULL );
103 if( bv == NULL || bv->bv_len == 0 ) {
104 *text = "empty attribute description";
108 /* make sure description is IA5 */
109 if( ad_keystring( bv ) ) {
110 *text = "attribute description contains inappropriate characters";
114 tokens = str2charray( bv->bv_val, ";");
116 if( tokens == NULL || *tokens == NULL ) {
117 *text = "no attribute type";
121 desc.ad_type = at_find( *tokens );
123 if( desc.ad_type == NULL ) {
124 *text = "attribute type undefined";
128 desc.ad_flags = SLAP_DESC_NONE;
131 for( i=1; tokens[i] != NULL; i++ ) {
132 if( strcasecmp( tokens[i], "binary" ) == 0 ) {
133 if( slap_ad_is_binary( &desc ) ) {
134 *text = "option \"binary\" specified multiple times";
138 if( !slap_syntax_is_binary( desc.ad_type->sat_syntax )) {
139 /* not stored in binary, disallow option */
140 *text = "option \"binary\" with type not supported";
144 desc.ad_flags |= SLAP_DESC_BINARY;
146 } else if ( strncasecmp( tokens[i], "lang-",
147 sizeof("lang-")-1 ) == 0 && tokens[i][sizeof("lang-")-1] )
149 if( desc.ad_lang != NULL ) {
150 *text = "multiple language tag options specified";
153 desc.ad_lang = tokens[i];
155 /* normalize to all lower case, it's easy */
156 ldap_pvt_str2lower( desc.ad_lang );
159 *text = "unrecognized option";
164 desc.ad_cname = ch_malloc( sizeof( struct berval ) );
166 desc.ad_cname->bv_len = strlen( desc.ad_type->sat_cname );
167 if( slap_ad_is_binary( &desc ) ) {
168 desc.ad_cname->bv_len += sizeof("binary");
170 if( desc.ad_lang != NULL ) {
171 desc.ad_cname->bv_len += 1 + strlen( desc.ad_lang );
174 desc.ad_cname->bv_val = ch_malloc( desc.ad_cname->bv_len + 1 );
176 strcpy( desc.ad_cname->bv_val, desc.ad_type->sat_cname );
177 if( slap_ad_is_binary( &desc ) ) {
178 strcat( desc.ad_cname->bv_val, ";binary" );
181 if( desc.ad_lang != NULL ) {
182 strcat( desc.ad_cname->bv_val, ";" );
183 strcat( desc.ad_cname->bv_val, desc.ad_lang );
187 *ad = ch_malloc( sizeof( AttributeDescription ) );
195 charray_free( tokens );
200 AttributeDescription *sub,
201 AttributeDescription *super
204 if( !is_at_subtype( sub->ad_type, super->ad_type ) ) {
208 if( super->ad_flags && ( super->ad_flags == sub->ad_flags )) {
212 if( super->ad_lang != NULL && ( sub->ad_lang == NULL
213 || strcasecmp( super->ad_lang, sub->ad_lang )))
223 AttributeDescription *desc,
227 for( i=0; attrs[i] != NULL; i++ ) {
228 AttributeDescription *ad = NULL;
232 rc = slap_str2ad( attrs[i], &ad, &text );
234 if( rc != LDAP_SUCCESS ) continue;
236 rc = is_ad_subtype( desc, ad );